2 * Copyright (c) 2014 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 "server-connection.h"
24 #include <dali/integration-api/debug.h>
30 // Copied from ecore_evas_extn.c
31 // procotol version - change this as needed
32 const int MAJOR( 0x1011 );
42 #if defined(DEBUG_ENABLED)
43 extern Debug::Filter* gIndicatorLogFilter;
46 ServerConnection::~ServerConnection()
50 if( mService.name != NULL )
52 eina_stringshare_del(mService.name);
55 for( Handlers::iterator iter = mIpcHandlers.begin(); iter != mIpcHandlers.end(); ++iter )
57 ecore_event_handler_del(*iter);
62 bool ServerConnection::IsConnected()
67 void ServerConnection::OnDisconnect()
74 mObserver->ConnectionClosed();
78 bool ServerConnection::SendEvent( int event, const void *data, int size )
80 return SendEvent(event, 0, 0, data, size);
83 bool ServerConnection::SendEvent( int event, int ref, int ref_to, const void *data, int size )
85 if( mIpcServer != NULL && ecore_ipc_server_send(mIpcServer, MAJOR, event, ref, ref_to, 0, data, size) )
95 Eina_Bool ServerConnection::IpcServerAdd( void *data, int /*type*/, void *event )
97 DALI_LOG_INFO(gIndicatorLogFilter, Debug::General, "ServerConnection: IpcServerAdd\n" );
99 return ECORE_CALLBACK_PASS_ON;
102 Eina_Bool ServerConnection::IpcServerDel( void *data, int /*type*/, void *event )
104 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "ServerConnection: IpcServerDel\n" );
106 Ecore_Ipc_Event_Server_Del *e = static_cast<Ecore_Ipc_Event_Server_Del *>( event );
107 ServerConnection* connection = static_cast<ServerConnection*>( data );
109 if( connection != NULL )
111 if( connection->mIpcServer == e->server)
113 // No longer have a server connection
114 connection->OnDisconnect();
118 return ECORE_CALLBACK_PASS_ON;
121 Eina_Bool ServerConnection::IpcServerData( void *data, int /*type*/, void *event )
123 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "ServerConnection: IpcServerData\n" );
125 Ecore_Ipc_Event_Server_Data *e = static_cast<Ecore_Ipc_Event_Server_Data *>( event );
126 ServerConnection* connection = static_cast<ServerConnection*>( data );
128 if( connection != NULL )
130 if( connection != ecore_ipc_server_data_get( e->server ) )
132 return ECORE_CALLBACK_PASS_ON;
135 if( e->major != MAJOR )
137 return ECORE_CALLBACK_PASS_ON;
140 if( connection->mObserver )
142 connection->mObserver->DataReceived( event );
145 return ECORE_CALLBACK_PASS_ON;
148 void ServerConnection::CloseConnection()
152 DALI_LOG_INFO( gIndicatorLogFilter, Debug::General, "ServerConnection: CloseConnection\n" );
156 ecore_ipc_server_del( mIpcServer );
160 ecore_ipc_shutdown();