From 03744682e5cc57889a59f57bda949f155ac09b02 Mon Sep 17 00:00:00 2001 From: Sunwook Bae Date: Tue, 16 Apr 2013 10:43:56 +0900 Subject: [PATCH] Add an OnIpcServerDisconnected in IpcClient Change-Id: I13ae30dfdec7dea7435631b5746d09a6f3ce841b Signed-off-by: Sunwook Bae --- src/IIpcClientEventListener.h | 7 +++++++ src/IpcClient.cpp | 29 ++++++++++++++++++++++++++++- src/IpcClient.h | 7 +++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/IIpcClientEventListener.h b/src/IIpcClientEventListener.h index f34f813..6a321ee 100644 --- a/src/IIpcClientEventListener.h +++ b/src/IIpcClientEventListener.h @@ -49,6 +49,13 @@ public: * @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 #endif //_IIPC_CLIENT_EVENT_LISTENER_H_ diff --git a/src/IpcClient.cpp b/src/IpcClient.cpp index fe68374..22bafab 100644 --- a/src/IpcClient.cpp +++ b/src/IpcClient.cpp @@ -104,6 +104,12 @@ IpcClient::Construct(const string& serverName, const IIpcClientEventListener* pL } +string +IpcClient::GetName(void) const +{ + return __name; +} + struct HelloMessage { int pid; @@ -303,10 +309,17 @@ IpcClient::HandleReceivedMessage(GIOChannel* source, GIOCondition condition) if (condition & G_IO_HUP) { + _LOGD("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) @@ -320,8 +333,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) + { + _LOGD("G_IO_STATUS_EOF, the connection is closed."); + } + else + { + _LOGD("G_IO_STATUS_ERROR, the connection is closed."); + } + pGError = NULL; g_io_channel_shutdown(source, FALSE, &pGError); @@ -330,6 +352,11 @@ IpcClient::HandleReceivedMessage(GIOChannel* source, GIOCondition condition) g_source_unref(__pReverseSource); __pReverseSource = NULL; + if (__pListener) + { + __pListener->OnIpcServerDisconnected(*this); + } + return FALSE; } diff --git a/src/IpcClient.h b/src/IpcClient.h index ac849ee..f3c74bd 100644 --- a/src/IpcClient.h +++ b/src/IpcClient.h @@ -72,6 +72,13 @@ public: int Construct(const std::string& serverName, const IIpcClientEventListener* pListener = NULL); /** + * Returns the name of the IPC server. + * + * @return The name of the IPC server. + */ + std::string GetName(void) const; + + /** * Sends a request message to an IPC server. * * @code -- 2.7.4