From: Sunwook Bae Date: Sat, 13 Apr 2013 02:01:02 +0000 (+0900) Subject: Add an OnIpcServerDisconnected in IpcClient X-Git-Tag: accepted/tizen_2.1/20130425.034849~57 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c32a3a47efa8f8e48a68d0de0a03af78aa72c5eb;p=framework%2Fosp%2Fappfw.git Add an OnIpcServerDisconnected in IpcClient Change-Id: Id736b792769ec3b617efc9c8b41f41e6aef20694 Signed-off-by: Sunwook Bae --- diff --git a/src/io/FIo_IpcClient.cpp b/src/io/FIo_IpcClient.cpp index a8ac658..ac6fa91 100644 --- a/src/io/FIo_IpcClient.cpp +++ b/src/io/FIo_IpcClient.cpp @@ -59,7 +59,6 @@ _IpcClient::_IpcClient(void) : __pReverseSource(null) , __fdCount(0) , __pFdLock(null) - , __name("") , __pListener(null) { __messageBuffer[0] = '\0'; @@ -117,7 +116,7 @@ _IpcClient::Construct(const String& name, const _IIpcClientEventListener* pListe return E_SUCCESS; CATCH: - __name = ""; + __name.Clear(); __pListener = null; __pFdLock = null; @@ -126,6 +125,12 @@ CATCH: return r; } +String +_IpcClient::GetName(void) const +{ + return __name; +} + struct HelloMessage { int pid; @@ -220,11 +225,9 @@ _IpcClient::MakeConnection(bool forReverse) FD_ZERO(&rset); FD_SET(client, &rset); wset = rset; - timeout.tv_sec = 10; // FIXME: replace 10 with const int + timeout.tv_sec = 10; timeout.tv_usec = 0; - // FIXME: - // replace select with poll while (true) { ret = select(client+1, &rset, &wset, NULL, &timeout); @@ -322,10 +325,17 @@ _IpcClient::HandleReceivedMessage(GIOChannel* source, GIOCondition condition) if (condition & G_IO_HUP) { + SysLog(NID_IO, "G_IO_HUP, the connection is closed."); + g_source_destroy(__pReverseSource); g_source_unref(__pReverseSource); __pReverseSource = null; + if (__pListener) + { + __pListener->OnIpcServerDisconnected(*this); + } + return FALSE; } else if (condition & G_IO_IN) @@ -339,8 +349,17 @@ _IpcClient::HandleReceivedMessage(GIOChannel* source, GIOCondition condition) { pGError = null; status = g_io_channel_read_chars(source, (char*) __messageBuffer, __MAX_MESSAGE_BUFFER_SIZE, &readSize, &pGError); - if (status == G_IO_STATUS_EOF) + if (status == G_IO_STATUS_EOF || status == G_IO_STATUS_ERROR) { + if (status == G_IO_STATUS_EOF) + { + SysLog(NID_IO, "G_IO_STATUS_EOF, the connection is closed."); + } + else + { + SysLog(NID_IO, "G_IO_STATUS_ERROR, the connection is closed. "); + } + pGError = null; g_io_channel_shutdown(source, FALSE, &pGError); @@ -349,6 +368,11 @@ _IpcClient::HandleReceivedMessage(GIOChannel* source, GIOCondition condition) g_source_unref(__pReverseSource); __pReverseSource = null; + if (__pListener) + { + __pListener->OnIpcServerDisconnected(*this); + } + return FALSE; } diff --git a/src/io/inc/FIo_IIpcClientEventListener.h b/src/io/inc/FIo_IIpcClientEventListener.h index 67ae9ed..0b479d6 100644 --- a/src/io/inc/FIo_IIpcClientEventListener.h +++ b/src/io/inc/FIo_IIpcClientEventListener.h @@ -37,7 +37,6 @@ class _IpcClient; /** * @interface _IIpcClientEventListener * @brief This interface provides the listener method for the response from IPC server. - * since 3.0 */ class _OSP_EXPORT_ _IIpcClientEventListener : Tizen::Base::Runtime::IEventListener @@ -47,18 +46,23 @@ public: /** * This is the destructor for this class. * - * @since 2.1 */ virtual ~_IIpcClientEventListener(void); /** * Called when an IPC response message received. * - * @since 2.1 * @param[in] client The IPC client * @param[in] message The response message */ virtual void OnIpcResponseReceived(_IpcClient& client, const IPC::Message& message) = 0; + + /** + * Called when an IPC server disconnected. + * + * @param[in] client The IPC client + */ + virtual void OnIpcServerDisconnected(_IpcClient& client) {} }; // _IIpcClientEventListener diff --git a/src/io/inc/FIo_IIpcServerEventListener.h b/src/io/inc/FIo_IIpcServerEventListener.h index 9f88a13..1b09897 100644 --- a/src/io/inc/FIo_IIpcServerEventListener.h +++ b/src/io/inc/FIo_IIpcServerEventListener.h @@ -37,7 +37,6 @@ class _IpcServer; /** * @interface _IIpcServerEventListener * @brief This interface provides listener method for the request event from an IPC client. - * since 3.0 */ class _OSP_EXPORT_ _IIpcServerEventListener : virtual Tizen::Base::Runtime::IEventListener @@ -45,15 +44,12 @@ class _OSP_EXPORT_ _IIpcServerEventListener public: /** * This is the destructor for this class. - * - * @since 2.1 */ virtual ~_IIpcServerEventListener(void); /** * Called when an IPC server started. * - * @since 2.1 * @param[in] server The IPC server */ virtual void OnIpcServerStarted(const _IpcServer& server) = 0; @@ -61,7 +57,6 @@ public: /** * Called when an IPC server stopped. * - * @since 2.1 * @param[in] server The IPC server */ virtual void OnIpcServerStopped(const _IpcServer& server) = 0; @@ -69,7 +64,6 @@ public: /** * Called when an IPC client connected. * - * @since 2.1 * @param[in] server The IPC server */ virtual void OnIpcClientConnected(const _IpcServer& server, int clientId) = 0; @@ -77,7 +71,6 @@ public: /** * Called when an IPC client disconnected. * - * @since 2.1 * @param[in] server The IPC server * @param[in] clientId The id of the connected IPC client */ @@ -86,7 +79,6 @@ public: /** * Called when an IPC request message received. * - * @since 2.1 * @code * * bool diff --git a/src/io/inc/FIo_IpcClient.h b/src/io/inc/FIo_IpcClient.h index cde5d39..ef48ac5 100644 --- a/src/io/inc/FIo_IpcClient.h +++ b/src/io/inc/FIo_IpcClient.h @@ -76,6 +76,13 @@ public: result Construct(const Tizen::Base::String& serverName, const _IIpcClientEventListener* pListener = null); /** + * Returns the name of the IPC server. + * + * @return The name of the IPC server. + */ + Tizen::Base::String GetName(void) const; + + /** * Sends a request message to an IPC server. * * @code diff --git a/src/server/io/FIo_IpcServer.cpp b/src/server/io/FIo_IpcServer.cpp index f6f9f83..ca7ab0a 100644 --- a/src/server/io/FIo_IpcServer.cpp +++ b/src/server/io/FIo_IpcServer.cpp @@ -99,8 +99,7 @@ _IpcServer::_ClientInfo::~_ClientInfo(void) } _IpcServer::_IpcServer(void) - : __name("") - , __runOnCallerThread(false) + : __runOnCallerThread(false) , __pEventDispatcher(null) , __pListener(null) , __handlerThread(0) @@ -254,6 +253,8 @@ _IpcServer::Construct(const String& name, const _IIpcServerEventListener& listen return E_SUCCESS; CATCH: + __name.Clear(); + if (pGIOChannel != null) { g_io_channel_unref(pGIOChannel); @@ -462,7 +463,8 @@ _IpcServer::HandleReceivedMessage(GIOChannel* source, GIOCondition condition, gp if (condition & G_IO_HUP) { - SysLog(NID_IO, "Connection closed"); + SysLog(NID_IO, "G_IO_HUP, the connection is closed."); + int clientId = pClientInfo->clientId; g_io_channel_shutdown(source, FALSE, &pGError);