Adapt the AIL filter used to new ones
[profile/ivi/ico-uxf-homescreen.git] / lib / system-controller / CicoSCServer.h
1 /*
2  * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
3  *
4  * This program is licensed under the terms and conditions of the
5  * Apache License, version 2.0.  The full text of the Apache License is at
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  */
9
10 //==========================================================================
11 /**
12  *  @file   CicoSCServer.h
13  *
14  *  @brief  This file is definition of CicoSCServer class
15  */
16 //==========================================================================
17 #ifndef __CICO_SC_SERVER_H__
18 #define __CICO_SC_SERVER_H__
19
20 #include <list>
21 #include <string>
22
23 #include <Ecore.h>
24 #include <Eina.h>
25
26 #include <ico_uws.h>
27
28 //==========================================================================
29 //  forward declaration
30 //==========================================================================
31 class CicoSCUwsHandler;
32 class CicoSCMessage;
33 class CicoSCCommand;
34 class CicoSCWindowController;
35 class CicoSCInputController;
36 class CicoSCUserManager;
37 class CicoSCResourceManager;
38 class CicoSCPolicyManager;
39
40 //==========================================================================
41 /**
42  *  @brief  This class has function of interprocess message server
43  */
44 //==========================================================================
45 class CicoSCServer
46 {
47 public:
48     // get CicoSCServer instance
49     static CicoSCServer* getInstance();
50
51     // set window controller instance
52     void setWindowCtrl(CicoSCWindowController* windowCtrl);
53
54     // set input controller instance
55     void setInputCtrl(CicoSCInputController* inputCtrl);
56
57     // set input controller instance
58     void setUserMgr(CicoSCUserManager* userMgr);
59
60     // set resource manager instance
61     void setResourceMgr(CicoSCResourceManager* resourceMgr);
62
63     // set resource manager instance
64     void setPolicyMgr(CicoSCPolicyManager* policyMgr);
65
66     // startup server
67     int startup(int port, const char *protocol);
68
69     // startup server
70     void teardown(void);
71
72     // send message to application client
73     int sendMessage(const std::string & appid, CicoSCMessage* msg);
74
75     // send message to homescreen
76     int sendMessageToHomeScreen(CicoSCMessage* msg);
77
78     // websocket callback function
79     void receiveEventCB(const struct ico_uws_context *context,
80                         const ico_uws_evt_e          event,
81                         const void                   *id,
82                         const ico_uws_detail         *detail,
83                         void                         *user_data);
84
85     // clear receive command queue
86     void clearRecvCmdQueue(const std::string & appid);
87
88     // clear send message queue
89     void clearSendMsgQueue(const std::string & appid);
90
91 private:
92     // default constructor
93     CicoSCServer();
94
95     // destructor
96     ~CicoSCServer();
97
98     // assignment operator
99     CicoSCServer& operator=(const CicoSCServer &object);
100
101     // copy constructor
102     CicoSCServer(const CicoSCServer &object);
103
104     // websocket utility callback function
105     static void uwsReceiveEventCB(const struct ico_uws_context *context,
106                                   const ico_uws_evt_e event,
107                                   const void *id,
108                                   const ico_uws_detail *detail,
109                                   void *user_data);
110
111     // ecore file destructor callback fucntion
112     static Eina_Bool ecoreFdCallback(void *data,
113                                           Ecore_Fd_Handler *handler);
114
115     // add poll websocket file destructor
116     void addPollFd(CicoSCUwsHandler *handler);
117
118     // delete poll websocket file destructor
119     void delPollFd(CicoSCUwsHandler *handler);
120
121     // dispatch receive message process and send message process
122     void dispatch(const CicoSCUwsHandler *handler);
123
124     // find websocket handle by context and id
125     CicoSCUwsHandler* findUwsHandler(const struct ico_uws_context *context,
126                                      const void *id);
127
128     // find websocket handle by ecore file destructor handler
129     CicoSCUwsHandler* findUwsHandler(const Ecore_Fd_Handler *ecoreFdHandler);
130
131     // find websocket handle by appid
132     CicoSCUwsHandler* findUwsHandler(const std::string & appid);
133
134     // query whether the handler exists
135     bool isExistUwsHandler(const CicoSCUwsHandler *handler);
136
137     // notify connected appilication
138     void notifyConnected(const std::string & appid);
139
140 private:
141     static CicoSCServer*    ms_myInstance;   ///< this class instance
142
143     struct ico_uws_context  *m_uwsContext;   ///< websocket utility context
144
145     CicoSCWindowController  *m_windowCtrl;   ///< window controller instance
146     CicoSCInputController   *m_inputCtrl;    ///< input controller instance
147     CicoSCUserManager       *m_userMgr;      ///< user manager instance
148     CicoSCResourceManager   *m_resourceMgr;  ///< resource manager instance
149     CicoSCPolicyManager     *m_policyMgr;    ///< policy manager instance
150
151     bool m_dispatchProcessing;
152
153     /// websocket handler list
154     std::list<CicoSCUwsHandler*> m_uwsHandlerList;
155
156     /// send message queue
157     std::list<CicoSCMessage*> m_sendMsgQueue;
158
159     /// recieve message queue
160     std::list<CicoSCCommand*> m_recvCmdQueue;
161 };
162 #endif  // __CICO_SC_SERVER_H__
163 // vim:set expandtab ts=4 sw=4: