Merge "Deprecate Application::ReplaceWindow" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / common / ecore-server-connection.h
1 #ifndef __DALI_INTERNAL_ADAPTOR_ECORE_SERVER_CONNECTION_H_
2 #define __DALI_INTERNAL_ADAPTOR_ECORE_SERVER_CONNECTION_H_
3
4 /*
5  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <Ecore.h>
23 #include <Ecore_Ipc.h>
24
25 #include <dali/public-api/common/vector-wrapper.h>
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31 namespace Adaptor
32 {
33
34 /**
35  * Makes a connection to a given service as a client
36  */
37 class ServerConnection
38 {
39 public:
40   /**
41    * Observes the connection for data and connection closure
42    */
43   class Observer
44   {
45   public:
46     /**
47      * Inform that data has been received on the connection
48      * @param[in] event The event that has been received
49      */
50     virtual void DataReceived(void* event) = 0;
51
52     /**
53      * Inform the observer that the connection has closed
54      */
55     virtual void ConnectionClosed() = 0;
56   };
57
58 public:
59   /**
60    * Constructor
61    * @param[in] serviceName The name of the service
62    * @param[in] serviceNumber The number of the service
63    * @param[in] isSystem Whether to connect as local user or system user
64    * @param[in] observer The connection observer
65    */
66   ServerConnection(const char *serviceName, int serviceNumber, bool isSystem, Observer* observer);
67
68   /**
69    * Destructor
70    */
71   ~ServerConnection();
72
73   /**
74    * Test if the connection is still alive
75    * @return True if the connection is still alive
76    */
77   bool IsConnected();
78
79   /**
80    * Disconnect from the server. Will trigger ConnectionClosed() observer callback
81    */
82   void OnDisconnect();
83
84   /**
85    * Send an event to the server.
86    * @param[in] event Event id
87    * @param[in] data  Pointer to the event data
88    * @param[in] size  Size of the event data
89    * @return whether the event is sent successfully or not
90    */
91   bool SendEvent( int event, const void *data, int size );
92
93   /**
94    * Send an event to the server.
95    * @param[in] event Event id
96    * @param[in] ref   Message Reference number
97    * @param[in] refTo Reference number of the message this refers to
98    * @param[in] data  Pointer to the event data
99    * @param[in] size  Size of the event data
100    * @return whether the event is sent successfully or not
101    */
102   bool SendEvent( int event, int ref, int refTo, const void *data, int size );
103
104 private: // Class callbacks
105   /**
106    * Callback when server added
107    */
108   static Eina_Bool IpcServerAdd(void *data, int type, void *event);
109
110   /**
111    * Callback when server deleted
112    */
113   static Eina_Bool IpcServerDel(void *data, int type, void *event);
114
115   /**
116    * Callback when data available from server
117    */
118   static Eina_Bool IpcServerData(void *data, int type, void *event);
119
120 private:
121
122   ServerConnection( const ServerConnection& ); ///< Undefined
123   ServerConnection& operator=( const ServerConnection& ); ///< Undefined
124
125   void CloseConnection();
126
127 private:
128   typedef std::vector<Ecore_Event_Handler *> Handlers;
129
130   struct Service
131   {
132     const char *name;
133     int         num;
134     bool        isSystem;
135   };
136
137   Service           mService;
138   bool              mConnected;
139   Observer*         mObserver;
140   Ecore_Ipc_Server* mIpcServer;
141   Handlers          mIpcHandlers;
142 };
143
144 } // Adaptor
145 } // Internal
146 } // Dali
147
148 #endif // __DALI_INTERNAL_ADAPTOR_ECORE_SERVER_CONNECTION_H_