Additional functions of policy and resource management.
[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 using namespace std;
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <unistd.h>
26 #include <signal.h>
27 #include <string.h>
28 #include <math.h>
29 #include <stdbool.h>
30 #include <sys/epoll.h>
31
32 #include <getopt.h>
33
34 #include <Ecore.h>
35 #include <Eina.h>
36
37 #include <ico_uws.h>
38
39 //==========================================================================
40 //  forward declaration
41 //==========================================================================
42 class CicoSCUwsHandler;
43 class CicoSCMessage;
44 class CicoSCCommand;
45 class CicoSCWindowController;
46 class CicoSCInputController;
47 class CicoSCUserManager;
48 class CicoSCResourceManager;
49
50 //==========================================================================
51 /**
52  *  @brief  This class has function of interprocess message server
53  */
54 //==========================================================================
55 class CicoSCServer
56 {
57 public:
58     // get CicoSCServer instance
59     static CicoSCServer* getInstance();
60
61     // set window controller instance
62     void setWindowCtrl(CicoSCWindowController* windowCtrl);
63
64     // set input controller instance
65     void setInputCtrl(CicoSCInputController* inputCtrl);
66
67     // set input controller instance
68     void setUserMgr(CicoSCUserManager* userMgr);
69
70     // set resource manager instance
71     void setResourceMgr(CicoSCResourceManager* resourceMgr);
72
73     // startup server
74     int startup(int port, const char *protocol);
75
76     // send message to application client
77     int sendMessage(const string & appid, CicoSCMessage* msg);
78
79     // send message to homescreen
80     int sendMessageToHomeScreen(CicoSCMessage* msg);
81
82     // websocket callback function
83     void receiveEventCB(const struct ico_uws_context *context,
84                         const ico_uws_evt_e          event,
85                         const void                   *id,
86                         const ico_uws_detail         *detail,
87                         void                         *user_data);
88
89 private:
90     // default constructor
91     CicoSCServer();
92
93     // destructor
94     ~CicoSCServer();
95
96     // assignment operator
97     CicoSCServer& operator=(const CicoSCServer &object);
98
99     // copy constructor
100     CicoSCServer(const CicoSCServer &object);
101
102     // websocket utility callback function
103     static void uwsReceiveEventCB(const struct ico_uws_context *context,
104                                   const ico_uws_evt_e event,
105                                   const void *id,
106                                   const ico_uws_detail *detail,
107                                   void *user_data);
108
109     // ecore file destructor callback fucntion
110     static Eina_Bool ecoreFdCallback(void *data,
111                                           Ecore_Fd_Handler *handler);
112
113     // add poll websocket file destructor
114     void addPollFd(CicoSCUwsHandler *handler);
115
116     // delete poll websocket file destructor
117     void delPollFd(CicoSCUwsHandler *handler);
118
119     // dispatch receive message process and send message process
120     void dispatch(const CicoSCUwsHandler *handler);
121
122     // find websocket handle by context and id
123     CicoSCUwsHandler* findUwsHandler(const struct ico_uws_context *context,
124                                      const void *id);
125
126     // find websocket handle by ecore file destructor handler
127     CicoSCUwsHandler* findUwsHandler(const Ecore_Fd_Handler *ecoreFdHandler);
128
129     // find websocket handle by appid
130     CicoSCUwsHandler* findUwsHandler(const string & appid);
131
132     // query whether the handler exists
133     bool isExistUwsHandler(const CicoSCUwsHandler *handler);
134
135 private:
136     static CicoSCServer*    ms_myInstance;   ///< this class instance
137
138     struct ico_uws_context  *m_uwsContext;   ///< websocket utility context
139
140     CicoSCWindowController  *m_windowCtrl;   ///< window controller instance
141     CicoSCInputController   *m_inputCtrl;    ///< input controller instance
142     CicoSCUserManager       *m_userMgr;      ///< user manager instance
143     CicoSCResourceManager   *m_resourceMgr;  ///< resource manager instance
144
145     list<CicoSCUwsHandler*> m_uwsHandlerList;///< websocket handler list
146     list<CicoSCMessage*>    m_sendMsgQueue;  ///< send message queue
147     list<CicoSCCommand*>    m_recvCmdQueue;  ///< recieve message queue
148 };
149 #endif  // __CICO_SC_SERVER_H__
150 // vim:set expandtab ts=4 sw=4: