add source for ces2019
[apps/agl-service-windowmanager-2017.git] / src / wm_connection.hpp
1 /*
2  * Insert Copyright if needed.
3  */
4
5 #ifndef WM_CONNECTION_HPP
6 #define WM_CONNECTION_HPP
7
8 #include <functional>
9
10 struct json_object;
11
12 namespace wm
13 {
14
15 class WMConnection
16 {
17   public:
18     WMConnection();
19     ~WMConnection() = default;
20
21     using ReceivedHandler = std::function<void(json_object* j_out)>;
22
23     int initialize();
24     void registerCallback(ReceivedHandler on_received);
25     int sendRequest(char const *req, char const *appid,
26                     char const *drawing_name, char const *drawing_area);
27     bool isMasterMode();
28     bool isMasterArea(const char* area);
29     bool isConnecting();
30     std::string parseMasterArea(const char* area);
31     bool isSyncDrawingForRemote(const char* role);
32     void startSyncDrawForRemote(const char* role);
33     void finishSyncDrawForRemote(const char* role);
34     int getMySocket();
35     int getConnectedSocket();
36     void setConnectedSocket(int connected_socket);
37     std::string getEcuName();
38     void callOnReceivedHandler(json_object *j_out);
39     int connectToMaster();
40
41     int receive(json_object** j_out);
42
43   private:
44     std::string mode;
45     std::string ip;
46     int port;
47     int my_socket = -1;
48     int connected_socket = -1;
49     ReceivedHandler onReceived;
50     std::string syndDrawingAppId;
51
52     std::string ecu_name;
53
54     int initializeMaster();
55     int initializeSlave();
56     int loadConnectionConfigFile();
57
58     int send(json_object* j_in);
59 };
60
61 } // namespace wm
62
63 #endif // WM_CONNECTION_HPP
64