Get appid from pid 2.1b_release accepted/tizen_2.1/20130425.035438 submit/tizen_2.1/20130424.230850
authorSunwook Bae <sunwook45.bae@samsung.com>
Mon, 22 Apr 2013 10:37:35 +0000 (19:37 +0900)
committerSunwook Bae <sunwook45.bae@samsung.com>
Tue, 23 Apr 2013 05:32:10 +0000 (14:32 +0900)
Change-Id: I573c23cbdfd9b29239eb7b72cbd9c8f4ba9e1292
Signed-off-by: Sunwook Bae <sunwook45.bae@samsung.com>
src/IpcClient.cpp
src/IpcClient.h
src/MessagePortProxy.cpp

index 22bafab..e5f758b 100644 (file)
@@ -37,8 +37,6 @@
 #include <queue>
 #include <map>
 
-#include <app_manager.h>
-
 #include "message-port-log.h"
 
 #include "IpcClient.h"
@@ -50,8 +48,7 @@ using namespace std;
 
 IpcClient::IpcClient(void)
        : __pReverseSource(NULL)
-       , __fdCount(0)
-       //, __pFdLock(NULL)
+       , __pMutex(NULL)
        , __pListener(NULL)
 {
        __messageBuffer[0] = '\0';
@@ -76,7 +73,7 @@ IpcClient::~IpcClient(void)
                close(fd);
        }
 
-       //delete __pFdLock;
+       pthread_mutex_destroy(__pMutex);
 }
 
 int
@@ -85,6 +82,16 @@ IpcClient::Construct(const string& serverName, const IIpcClientEventListener* pL
        __name = serverName;
        __pListener = const_cast <IIpcClientEventListener*>(pListener);
 
+       pthread_mutex_t* pMutex = (pthread_mutex_t*) malloc(sizeof(pthread_mutex_t));
+       if (pMutex == NULL)
+       {
+               return -2;
+       }
+
+       pthread_mutex_init(pMutex, NULL);
+
+       __pMutex = pMutex;
+
        int ret = MakeConnection();
        if (ret != 0)
        {
@@ -114,7 +121,6 @@ struct HelloMessage
 {
        int pid;
        bool reverse;
-       char appId[256];
 };
 
 int
@@ -135,27 +141,6 @@ IpcClient::MakeConnection(bool forReverse)
        helloMessage.pid = getpid();
        helloMessage.reverse = forReverse;
 
-       if (__fdCount == 0)
-       {
-               char* pAppId = NULL;
-               ret = app_manager_get_app_id(helloMessage.pid, &pAppId);
-               _LOGD("app_id: %s", pAppId);
-
-               if (ret < 0)
-               {
-                       _LOGE("Failed to get_app_id: %d", ret);
-                       return -1;
-               }
-
-               strncpy(helloMessage.appId, pAppId, 255);
-
-               _LOGD("app_id: %s", helloMessage.appId);
-
-               __appId = pAppId;
-
-               free(pAppId);
-       }
-
        struct sockaddr_un server;
 
        bzero(&server, sizeof(server));
@@ -197,7 +182,7 @@ 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;
 
                while (true)
@@ -275,8 +260,6 @@ IpcClient::MakeConnection(bool forReverse)
        }
        else
        {
-               ++__fdCount;
-
                ReleaseFd(client);
        }
 
@@ -420,10 +403,10 @@ IpcClient::AcquireFd(void)
 
        while (fd == -1)
        {
-               //__pFdLock->Acquire();
+               pthread_mutex_lock(__pMutex);
                if (__fds.size() == 0)
                {
-                       //__pFdLock->Release();
+                       pthread_mutex_unlock(__pMutex);
                        ret = MakeConnection(false);
                        if (ret < 0)
                        {
@@ -437,7 +420,7 @@ IpcClient::AcquireFd(void)
                fd = __fds.back();
                __fds.pop_back();
 
-               //__pFdLock->Release();
+               pthread_mutex_unlock(__pMutex);
        }
 
        return fd;
@@ -446,11 +429,11 @@ IpcClient::AcquireFd(void)
 void
 IpcClient::ReleaseFd(int fd)
 {
-       //__pFdLock->Acquire();
+       pthread_mutex_lock(__pMutex);
 
        __fds.push_back(fd);
 
-       //__pFdLock->Release();
+       pthread_mutex_unlock(__pMutex);
 }
 
 int
@@ -603,8 +586,3 @@ IpcClient::SendRequest(const IPC::Message& message)
        return ret;
 }
 
-string 
-IpcClient::GetAppId(void)
-{
-       return __appId;
-}
index f3c74bd..716ed5d 100644 (file)
@@ -109,8 +109,6 @@ public:
 
        int SendRequest(IPC::Message* pMessage);
 
-       std::string GetAppId(void);
-
 private:
        IpcClient(const IpcClient& value);
 
@@ -134,9 +132,9 @@ private:
 
 private:
        GSource* __pReverseSource;
+       pthread_mutex_t* __pMutex;
 
        std::vector <int> __fds;
-       int __fdCount;
        //Tizen::Base::Runtime::Mutex* __pFdLock;
        std::string __name;
        std::string __appId;
index c0b854d..59801fd 100644 (file)
@@ -26,6 +26,8 @@
 #include <unistd.h>
 #include <sstream>
 
+#include <app_manager.h>
+
 #include "message-port.h"
 #include "message-port-messages.h"
 #include "message-port-log.h"
@@ -88,7 +90,20 @@ MessagePortProxy::Construct(void)
 
        __pMutex = pMutex;
        __pIpcClient = pIpcClient;
-       __appId = pIpcClient->GetAppId();
+
+       int pid = getpid();
+       char* pAppId = NULL;
+       ret = app_manager_get_app_id(pid, &pAppId);
+       if (ret < 0)
+       {
+               _LOGE("Failed to get_app_id: %d", ret);
+
+               return MESSAGEPORT_ERROR_IO_ERROR;
+       }
+
+       __appId = pAppId;
+
+       free(pAppId);
 
        return 0;
 }