Add an OnIpcServerDisconnected in IpcClient
authorSunwook Bae <sunwook45.bae@samsung.com>
Tue, 16 Apr 2013 01:43:56 +0000 (10:43 +0900)
committerSunwook Bae <sunwook45.bae@samsung.com>
Tue, 16 Apr 2013 01:43:56 +0000 (10:43 +0900)
Change-Id: I13ae30dfdec7dea7435631b5746d09a6f3ce841b
Signed-off-by: Sunwook Bae <sunwook45.bae@samsung.com>
src/IIpcClientEventListener.h
src/IpcClient.cpp
src/IpcClient.h

index f34f813..6a321ee 100644 (file)
@@ -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_
index fe68374..22bafab 100644 (file)
@@ -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;
                        }
 
index ac849ee..f3c74bd 100644 (file)
@@ -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