#include <queue>
#include <map>
-#include <app_manager.h>
-
#include "message-port-log.h"
#include "IpcClient.h"
IpcClient::IpcClient(void)
: __pReverseSource(NULL)
- , __fdCount(0)
- //, __pFdLock(NULL)
+ , __pMutex(NULL)
, __pListener(NULL)
{
__messageBuffer[0] = '\0';
close(fd);
}
- //delete __pFdLock;
+ pthread_mutex_destroy(__pMutex);
}
int
__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)
{
{
int pid;
bool reverse;
- char appId[256];
};
int
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));
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)
}
else
{
- ++__fdCount;
-
ReleaseFd(client);
}
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)
{
fd = __fds.back();
__fds.pop_back();
- //__pFdLock->Release();
+ pthread_mutex_unlock(__pMutex);
}
return fd;
void
IpcClient::ReleaseFd(int fd)
{
- //__pFdLock->Acquire();
+ pthread_mutex_lock(__pMutex);
__fds.push_back(fd);
- //__pFdLock->Release();
+ pthread_mutex_unlock(__pMutex);
}
int
return ret;
}
-string
-IpcClient::GetAppId(void)
-{
- return __appId;
-}
int SendRequest(IPC::Message* pMessage);
- std::string GetAppId(void);
-
private:
IpcClient(const IpcClient& value);
private:
GSource* __pReverseSource;
+ pthread_mutex_t* __pMutex;
std::vector <int> __fds;
- int __fdCount;
//Tizen::Base::Runtime::Mutex* __pFdLock;
std::string __name;
std::string __appId;
#include <unistd.h>
#include <sstream>
+#include <app_manager.h>
+
#include "message-port.h"
#include "message-port-messages.h"
#include "message-port-log.h"
__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;
}