2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/window-system/common/ecore-server-connection.h>
22 // Ecore is littered with C style cast
23 #pragma GCC diagnostic push
24 #pragma GCC diagnostic ignored "-Wold-style-cast"
27 #include <dali/integration-api/debug.h>
33 // Copied from ecore_evas_extn_engine.h
34 // procotol version - change this as needed
35 const int MAJOR( 0x2011 );
45 #if defined(DEBUG_ENABLED)
46 Debug::Filter* gServerConnectionLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_SERVER_CONNECTION");
49 ServerConnection::ServerConnection(
50 const char* serviceName,
53 ServerConnection::Observer* observer)
58 Ecore_Ipc_Type ipctype = ECORE_IPC_LOCAL_USER;
61 mService.name = eina_stringshare_add(serviceName);
62 mService.num = serviceNumber;
63 mService.isSystem = isSystem;
65 if( mService.isSystem )
67 ipctype = ECORE_IPC_LOCAL_SYSTEM;
70 DALI_LOG_INFO( gServerConnectionLogFilter, Debug::General, "ServerConnection: Connecting to %s %d\n", mService.name, mService.num );
72 mIpcServer = ecore_ipc_server_connect( ipctype, (char *)mService.name, mService.num, this );
76 DALI_LOG_INFO( gServerConnectionLogFilter, Debug::General, "mIpcServer is null\n" );
81 mIpcHandlers.push_back( ecore_event_handler_add( ECORE_IPC_EVENT_SERVER_ADD,
82 &ServerConnection::IpcServerAdd,
85 mIpcHandlers.push_back( ecore_event_handler_add( ECORE_IPC_EVENT_SERVER_DEL,
86 &ServerConnection::IpcServerDel,
89 mIpcHandlers.push_back( ecore_event_handler_add( ECORE_IPC_EVENT_SERVER_DATA,
90 &ServerConnection::IpcServerData,
97 ServerConnection::~ServerConnection()
101 if( mService.name != NULL )
103 eina_stringshare_del(mService.name);
106 for( Handlers::iterator iter = mIpcHandlers.begin(); iter != mIpcHandlers.end(); ++iter )
108 ecore_event_handler_del(*iter);
110 mIpcHandlers.clear();
113 bool ServerConnection::IsConnected()
118 void ServerConnection::OnDisconnect()
122 ecore_ipc_shutdown();
125 mObserver->ConnectionClosed();
129 bool ServerConnection::SendEvent( int event, const void *data, int size )
131 return SendEvent(event, 0, 0, data, size);
134 bool ServerConnection::SendEvent( int event, int ref, int ref_to, const void *data, int size )
136 if( mIpcServer != NULL && ecore_ipc_server_send(mIpcServer, MAJOR, event, ref, ref_to, 0, data, size) )
146 Eina_Bool ServerConnection::IpcServerAdd( void *data, int /*type*/, void *event )
148 DALI_LOG_INFO(gServerConnectionLogFilter, Debug::General, "ServerConnection: IpcServerAdd\n" );
150 return ECORE_CALLBACK_PASS_ON;
153 Eina_Bool ServerConnection::IpcServerDel( void *data, int /*type*/, void *event )
155 DALI_LOG_INFO( gServerConnectionLogFilter, Debug::General, "ServerConnection: IpcServerDel\n" );
157 Ecore_Ipc_Event_Server_Del *e = static_cast<Ecore_Ipc_Event_Server_Del *>( event );
158 ServerConnection* connection = static_cast<ServerConnection*>( data );
160 if( connection != NULL )
162 if( connection->mIpcServer == e->server)
164 // No longer have a server connection
165 connection->OnDisconnect();
169 return ECORE_CALLBACK_PASS_ON;
172 Eina_Bool ServerConnection::IpcServerData( void *data, int /*type*/, void *event )
174 DALI_LOG_INFO( gServerConnectionLogFilter, Debug::General, "ServerConnection: IpcServerData\n" );
176 Ecore_Ipc_Event_Server_Data *e = static_cast<Ecore_Ipc_Event_Server_Data *>( event );
177 ServerConnection* connection = static_cast<ServerConnection*>( data );
179 if( connection != NULL )
181 if( connection != ecore_ipc_server_data_get( e->server ) )
183 return ECORE_CALLBACK_PASS_ON;
186 if( e->major != MAJOR )
188 return ECORE_CALLBACK_PASS_ON;
191 if( connection->mObserver )
193 connection->mObserver->DataReceived( event );
196 return ECORE_CALLBACK_PASS_ON;
199 void ServerConnection::CloseConnection()
203 DALI_LOG_INFO( gServerConnectionLogFilter, Debug::General, "ServerConnection: CloseConnection\n" );
207 ecore_ipc_server_del( mIpcServer );
211 ecore_ipc_shutdown();
222 #pragma GCC diagnostic pop