2 # ==================================================================================
3 # Copyright (c) 2020 HCL Technologies Limited.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 # ==================================================================================
18 #ifndef _pistacheserver_h
19 #define _pistacheserver_h
20 #include <pistache/endpoint.h>
21 #include <pistache/http.h>
22 #include <pistache/router.h>
23 #include <pistache/http_headers.h>
29 #include<unordered_set>
32 #include<unordered_map>
35 using usr_callback=void(*)(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response);
39 std::shared_ptr<Pistache::Http::Endpoint> httpEndpoint;
40 Pistache::Rest::Router router;
41 void setupRoutes_get(int index);
42 void setupRoutes_post(int index);
43 void setupRoutes_del(int index);
45 std::vector<std::string> method;
46 std::vector< bool> static_routing;
47 std::vector<bool> dynamic_routing;
48 std::unordered_map<int,std::string> route_static;
49 std::unordered_map<int,std::string> route_dynamic;
50 std::unordered_map<int,usr_callback> cb_static;
51 std::unordered_map<int,usr_callback> cb_dynamic;
53 std::string base = "/ric/v1";
54 std::string dynamic_id="/:Id";
62 pistacheserver(Pistache::Address addr,std::vector<std::string> method,std::vector<bool> static_routing,std::vector<bool> dynamic_routing);
63 virtual ~pistacheserver(){};
64 virtual void default_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response)
66 response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist");
69 void init(size_t thr);
70 void setup_base_url(std::string base);
71 void setup_static_route(std::unordered_map<int,std::string> route);//routing path
72 void setup_dynamic_route(std::unordered_map<int,std::string> route);
73 void add_static_cb(std::unordered_map<int,usr_callback> cb);
74 void add_dynamic_cb(std::unordered_map<int,usr_callback> cb);