Get appid from pid in ipc
authorSunwook Bae <sunwook45.bae@samsung.com>
Mon, 22 Apr 2013 06:37:27 +0000 (15:37 +0900)
committerSunwook Bae <sunwook45.bae@samsung.com>
Tue, 23 Apr 2013 07:54:46 +0000 (16:54 +0900)
Change-Id: I4d1500bd82a09d9395feda60447224206b2a25f7
Signed-off-by: Sunwook Bae <sunwook45.bae@samsung.com>
src/io/FIo_IpcClient.cpp
src/io/inc/FIo_IpcClient.h
src/server/inc/FIo_IpcServer.h
src/server/io/FIo_IpcServer.cpp

index ac6fa91..62449ed 100644 (file)
@@ -57,7 +57,6 @@ namespace Tizen { namespace Io
 
 _IpcClient::_IpcClient(void)
        : __pReverseSource(null)
-       , __fdCount(0)
        , __pFdLock(null)
        , __pListener(null)
 {
@@ -135,8 +134,6 @@ struct HelloMessage
 {
        int pid;
        bool reverse;
-       char pkgId[256];
-       char appExecutableName[256];
 };
 
 result
@@ -168,34 +165,6 @@ _IpcClient::MakeConnection(bool forReverse)
        socketNameLength = socketName.size() + 1;
        SysTryReturnResult(NID_IO, socketNameLength < 108, E_INVALID_ARG, "Server name is too long.");
 
-       if (__fdCount == 0)
-       {
-               // Set an pkgId
-               String pkgId = _AppInfo::GetPackageId();
-               int length = (pkgId.GetLength() + 1) * sizeof(wchar_t);
-               if (length > 255)
-               {
-                       length = 255;
-               }
-
-               SysTryReturnResult(NID_IO, pkgId.GetLength() > 0, E_SYSTEM, "AppId dose not exist.");
-
-               memcpy(helloMessage.pkgId, pkgId.GetPointer(), length);
-
-               // Set an executableName
-               String appExecutableName = _AppInfo::GetAppExecutableName();
-               length = (appExecutableName.GetLength() + 1) * sizeof(wchar_t);
-               if (length > 255)
-               {
-                       length = 255;
-               }
-
-               if (appExecutableName.GetLength() != 0)
-               {
-                       memcpy(helloMessage.appExecutableName, appExecutableName.GetPointer(), length);
-               }
-       }
-
        client = socket(AF_UNIX, SOCK_STREAM, 0);
        SysTryCatch(NID_IO, client != -1, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to create a socket : %s.", strerror(errno));
 
@@ -291,8 +260,6 @@ _IpcClient::MakeConnection(bool forReverse)
        }
        else
        {
-               ++__fdCount;
-
                ReleaseFd(client);
        }
 
index ef48ac5..60c2c85 100644 (file)
@@ -137,7 +137,6 @@ private:
        GSource* __pReverseSource;
 
        std::vector <int> __fds;
-       int __fdCount;
        Tizen::Base::Runtime::Mutex* __pFdLock;
        Tizen::Base::String __name;
        _IIpcClientEventListener* __pListener;
index df1530c..758237d 100644 (file)
@@ -190,8 +190,7 @@ private:
                _IpcServer* pIpcServer;                    /**< the pointer to an _ IpcServer */
                GIOChannel* pReverseChannel;               /**< the channel for sending reverse message */
                std::vector <struct _ChannelInfo*> channels;   /**< the set of channels associated with a client */
-               Tizen::Base::String pkgId;
-               Tizen::Base::String appExecutableName;
+               Tizen::Base::String appId;
        };
 
        Tizen::Base::String __name;
index ca7ab0a..7f6a4bd 100644 (file)
@@ -36,6 +36,8 @@
 
 #include <ipc/ipc_message.h>
 
+#include <app_manager.h>
+
 #include <FBaseRtMutex.h>
 #include <FBaseSysLog.h>
 #include <FBase_StringConverter.h>
@@ -278,8 +280,6 @@ struct HelloMessage
 {
        int pid;
        bool reverse;  // true if the connection is for reverse message
-       char pkgId[256];
-       char appExecutableName[256];
 };
 
 gboolean
@@ -304,11 +304,9 @@ _IpcServer::OnConnectionRequest(GIOChannel* source, GIOCondition condition, gpoi
        server = g_io_channel_unix_get_fd(source);
 
        client = accept(server, (struct sockaddr*) &clientAddress, &clientLen);
-       SysTryCatch(NID_IO, client != -1, , E_SYSTEM, "[E_SYSTEM] Accept failed.");
+       SysTryCatch(NID_IO, client != -1, ,E_SYSTEM, "[E_SYSTEM] Accept failed.");
 
        read(client, &helloMessage, sizeof(helloMessage));
-       helloMessage.pkgId[255] = '\0';
-       helloMessage.appExecutableName[255] = '\0';
 
        pChannel = g_io_channel_unix_new(client);
        SysTryCatch(NID_IO, pChannel != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Not enough memory.");
@@ -327,12 +325,17 @@ _IpcServer::OnConnectionRequest(GIOChannel* source, GIOCondition condition, gpoi
 
                pClientInfo->pIpcServer = pIpcServer;
                pClientInfo->clientId = helloMessage.pid;
-               pClientInfo->pkgId.Append((wchar_t*) helloMessage.pkgId);
-               pClientInfo->appExecutableName.Append((wchar_t*) helloMessage.appExecutableName);
+
+               char* pAppId = NULL;
+               int ret = app_manager_get_app_id(helloMessage.pid, &pAppId);
+               SysTryCatch(NID_IO, ret >= 0, ,E_SYSTEM, "[E_SYSTEM] Failed to get_app_id: %d", ret);
+
+               pClientInfo->appId = pAppId;
+               free(pAppId);
+
                pClientInfo->pReverseChannel = null;
 
                pIpcServer->__clients[helloMessage.pid] = pClientInfo;
-
                pIpcServer->__pCurrentClientInfo = pClientInfo;
                pIpcServer->__pListener->OnIpcClientConnected(*pIpcServer, helloMessage.pid);
                pIpcServer->__pCurrentClientInfo = null;
@@ -403,7 +406,10 @@ _IpcServer::GetClientAppId(void) const
 
        if (__pCurrentClientInfo)
        {
-               return __pCurrentClientInfo->pkgId;
+               String pkgId;
+               __pCurrentClientInfo->appId.SubString(0, 10, pkgId);
+
+               return pkgId;
        }
 
        return nullString;
@@ -416,7 +422,10 @@ _IpcServer::GetClientAppExecutableName(void) const
 
        if (__pCurrentClientInfo)
        {
-               return __pCurrentClientInfo->appExecutableName;
+               String appName;
+               __pCurrentClientInfo->appId.SubString(11, appName);
+
+               return appName;
        }
 
        return nullString;
@@ -429,7 +438,10 @@ _IpcServer::GetClientPackageId(void) const
 
        if (__pCurrentClientInfo)
        {
-               return __pCurrentClientInfo->pkgId;
+               String pkgId;
+               __pCurrentClientInfo->appId.SubString(0, 10, pkgId);
+
+               return pkgId;
        }
 
        return nullString;
@@ -442,11 +454,7 @@ _IpcServer::GetClientApplicationId(void) const
 
        if (__pCurrentClientInfo)
        {
-               String appId(__pCurrentClientInfo->pkgId);
-               appId.Append(L'.');
-               appId.Append(__pCurrentClientInfo->appExecutableName);
-
-               return appId;
+               return __pCurrentClientInfo->appId;
        }
 
        return nullString;