Add an OnIpcServerDisconnected in IpcClient
authorSunwook Bae <sunwook45.bae@samsung.com>
Sat, 13 Apr 2013 02:01:02 +0000 (11:01 +0900)
committerSunwook Bae <sunwook45.bae@samsung.com>
Tue, 16 Apr 2013 01:07:41 +0000 (10:07 +0900)
Change-Id: Id736b792769ec3b617efc9c8b41f41e6aef20694
Signed-off-by: Sunwook Bae <sunwook45.bae@samsung.com>
src/io/FIo_IpcClient.cpp
src/io/inc/FIo_IIpcClientEventListener.h
src/io/inc/FIo_IIpcServerEventListener.h
src/io/inc/FIo_IpcClient.h
src/server/io/FIo_IpcServer.cpp

index a8ac658..ac6fa91 100644 (file)
@@ -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;
                        }
 
index 67ae9ed..0b479d6 100644 (file)
@@ -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
 
 
index 9f88a13..1b09897 100644 (file)
@@ -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
index cde5d39..ef48ac5 100644 (file)
@@ -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
index f6f9f83..ca7ab0a 100644 (file)
@@ -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);