X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Frest-server%2Fpistacheserver.h;fp=src%2Frest-server%2Fpistacheserver.h;h=75fb9b874d4df14467ddb001998d8b9f397cac79;hb=e64778dac480d66d93449efd3e9767cea4f980f9;hp=0000000000000000000000000000000000000000;hpb=56044b79a2282e50a8c271b36289b1724cb40cd8;p=ric-plt%2Fxapp-frame-cpp.git diff --git a/src/rest-server/pistacheserver.h b/src/rest-server/pistacheserver.h new file mode 100644 index 0000000..75fb9b8 --- /dev/null +++ b/src/rest-server/pistacheserver.h @@ -0,0 +1,80 @@ +/* +# ================================================================================== +# Copyright (c) 2020 HCL Technologies Limited. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ================================================================================== +*/ +#ifndef _pistacheserver_h +#define _pistacheserver_h +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +namespace xapp +{ + using usr_callback=void(*)(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response); + class pistacheserver + { + private: + std::shared_ptr httpEndpoint; + Pistache::Rest::Router router; + void setupRoutes_get(int index); + void setupRoutes_post(int index); + void setupRoutes_del(int index); + + std::vector method; + std::vector< bool> static_routing; + std::vector dynamic_routing; + std::unordered_map route_static; + std::unordered_map route_dynamic; + std::unordered_map cb_static; + std::unordered_map cb_dynamic; + + std::string base = "/ric/v1"; + std::string dynamic_id="/:Id"; + int stat_sz=0; + int dyn_sz=0; + int cal_stat_size(); + int cal_dyn_size(); + std::thread **t; + public: + void thread_start(); + pistacheserver(Pistache::Address addr,std::vector method,std::vector static_routing,std::vector dynamic_routing); + virtual ~pistacheserver(){}; + virtual void default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) + { + response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist"); + } + + void init(size_t thr); + void setup_base_url(std::string base); + void setup_static_route(std::unordered_map route);//routing path + void setup_dynamic_route(std::unordered_map route); + void add_static_cb(std::unordered_map cb); + void add_dynamic_cb(std::unordered_map cb); + void start(); + void shutdown(); + }; +} +#endif +