add autobuild tree
[apps/agl-service-navigation.git] / libnavi / include / RequestManage.h
1 // Copyright 2017 AISIN AW CO.,LTD
2
3 #pragma once
4
5 #include <stdint.h>
6 #include <string>
7 #include <pthread.h>
8
9 extern "C" {
10         #include <afb/afb-wsj1.h>
11         #include <afb/afb-ws-client.h>
12 }
13
14 #include "RequestManageListener.h"
15
16 /**
17 *  @brief Class for request
18 */
19 class RequestManage
20 {
21 public:
22         pthread_cond_t cond;
23         pthread_mutex_t mutex;
24
25         struct afb_wsj1* wsj1;
26         std::string* requestURL;
27         struct afb_wsj1_itf wsj1_itf;
28
29 private:
30         RequestManageListener* listener;
31         int request_cnt;
32         uint32_t sessionHandle;
33         uint32_t routeHandle;
34
35         // Function called from thread
36         static void* BinderThread(void* param);
37
38         // Callback function
39         void OnReply(struct afb_wsj1_msg *msg);
40         void OnHangup(struct afb_wsj1 *wsj1);
41         void OnCallStatic(const char *api, const char *verb, struct afb_wsj1_msg *msg);
42         void OnEventStatic(const char *event, struct afb_wsj1_msg *msg);
43
44         static void OnReplyStatic(void *closure, struct afb_wsj1_msg *msg);
45         static void OnHangupStatic(void *closure, struct afb_wsj1 *wsj1);
46         static void OnCallStatic(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg);
47         static void OnEventStatic(void *closure, const char *event, struct afb_wsj1_msg *msg);
48   
49 // ==================================================================================================
50 // public
51 // ==================================================================================================
52 public:
53         RequestManage();
54         ~RequestManage();
55     
56         bool Connect(const char* api_url, RequestManageListener* listener);
57         bool IsConnect();
58         bool CallBinderAPI(const char *api, const char *verb, const char *object);
59         void SetSessionHandle(uint32_t session);
60         uint32_t GetSessionHandle();
61         void SetRouteHandle(uint32_t route);
62         uint32_t GetRouteHandle();
63 };
64