5G-MAG Reference Tools - MBMS Middleware
RpRestClient.cpp
Go to the documentation of this file.
1 // 5G-MAG Reference Tools
2 // MBMS Middleware Process
3 //
4 // Copyright (C) 2021 Klaus Kühnhammer (Österreichische Rundfunksender GmbH & Co KG)
5 //
6 // Licensed under the License terms and conditions for use, reproduction, and
7 // distribution of 5G-MAG software (the “License”). You may not use this file
8 // except in compliance with the License. You may obtain a copy of the License at
9 // https://www.5g-mag.com/reference-tools. Unless required by applicable law or
10 // agreed to in writing, software distributed under the License is distributed on
11 // an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12 // or implied.
13 //
14 // See the License for the specific language governing permissions and limitations
15 // under the License.
16 //
17 
18 #include "RpRestClient.h"
19 
20 #include "spdlog/spdlog.h"
21 
22 using web::http::client::http_client;
23 using web::http::status_codes;
24 using web::http::methods;
25 using web::http::http_response;
26 
27 MBMS_RT::RpRestClient::RpRestClient(const libconfig::Config& cfg)
28 {
29  std::string url = "http://localhost:3010/modem-api/";
30  cfg.lookupValue("modem.restful_api.uri", url);
31  _client = std::make_unique<http_client>(url);
32 }
33 
34 auto MBMS_RT::RpRestClient::getMchInfo() -> web::json::value
35 {
36  auto res = web::json::value::array();
37  try {
38  _client->request(methods::GET, "mch_info")
39  .then([&res](http_response response) { // NOLINT
40  if (response.status_code() == status_codes::OK) {
41  res = response.extract_json().get();
42  }
43  }).wait();
44  } catch (web::http::http_exception ex) { }
45  return res;
46 }
47 
48 auto MBMS_RT::RpRestClient::getStatus() -> web::json::value
49 {
50  auto res = web::json::value::array();
51  try {
52  _client->request(methods::GET, "status")
53  .then([&res](http_response response) { // NOLINT
54  if (response.status_code() == status_codes::OK) {
55  res = response.extract_json().get();
56  }
57  }).wait();
58  } catch (web::http::http_exception ex) { }
59  return res;
60 }
std::unique_ptr< web::http::client::http_client > _client
Definition: RpRestClient.h:34
web::json::value getMchInfo()
web::json::value getStatus()
RpRestClient(const libconfig::Config &cfg)
static Config cfg
Global configuration object.
Definition: main.cpp:111