Fix IPC Lock Issue
authorJoohyun Kim <joohyune.kim@samsung.com>
Mon, 27 May 2013 07:24:16 +0000 (16:24 +0900)
committerJoohyun Kim <joohyune.kim@samsung.com>
Mon, 27 May 2013 07:42:55 +0000 (16:42 +0900)
Change-Id: I29fcbacfaaba8d17ef0d778060ad4ed8a47d7bc8
Signed-off-by: Joohyun Kim <joohyune.kim@samsung.com>
inc/FApp_CommunicationDispatcher.h
inc/FSys_DeviceManagerService.h
plugins/accessory-condition-handler/AccessoryMonitor.cpp
plugins/alarm-condition-handler/AlarmConditionHandler.cpp
src/FApp_CommunicationDispatcher.cpp
src/FSys_AccessoryManagerService.cpp
src/FSys_DeviceManagerService.cpp
src/FSys_SettingService.cpp
src/FSys_SystemService.cpp
src/system/FSys_RuntimeInfo.cpp

index a83a644..1154b95 100644 (file)
@@ -59,7 +59,7 @@ namespace Tizen { namespace App {
 class _CommunicationDispatcher
        : public Tizen::Io::_IIpcServerEventListener
        , public _IAppEventListener
-       , virtual public Tizen::Base::Runtime::IEventListener
+       , public Tizen::Base::Runtime::IEventListener
 {
 private:
        _CommunicationDispatcher(void);
@@ -81,7 +81,7 @@ public:
        virtual void OnApplicationTerminated(const AppId& appId, int pid);
 
        bool OnRequestOccured(const Tizen::Base::Collection::ArrayList& request, Tizen::Base::Collection::ArrayList* response);
-       result SendData(const int pid, Tizen::Base::Collection::ArrayList& data);
+       result SendData(const int pid, Tizen::Base::Collection::ArrayList* data);
 
 private:
        Tizen::Io::_IpcServer*                  __pIpcServer;
index ecd388f..ced994e 100644 (file)
@@ -37,7 +37,6 @@ namespace Tizen { namespace System {
  */
 class _DeviceManagerService
        : public Tizen::App::_ICommunicationRequestListener
-       , public Tizen::System::_IDeviceManagerEventListener
 {
 private:
        _DeviceManagerService(void);
@@ -46,7 +45,6 @@ public:
        virtual Tizen::Base::String GetId(void);
        void OnRequestOccured(Tizen::App::AppId appId, int pid, Tizen::Base::Collection::ArrayList* request, Tizen::Base::Collection::ArrayList* response);
        void OnApplicationTerminated(const Tizen::App::AppId& appId, int pid);
-       void OnBluetoothEventOccured(int code);
        void SendEvent(Tizen::Base::String event);
        void SetBluetoothStatus(bool status);
        bool GetBluetoothStatus(void);
index c48172a..efe1d6a 100644 (file)
@@ -109,9 +109,9 @@ AccessoryMonitor::ReleaseInstance(void)
 void
 AccessoryMonitor::OnDataRouterDataReceivedN(const char* buffer, int length)
 {
-       //result r = E_SUCCESS;
        SysLog(NID_SYS, "serial data is forwarded to AccessoryMonitor class");
        SysTryReturnVoidResult(NID_SYS, buffer != null, E_INVALID_ARG, "[E_INVALID_ARG] buffer should not be null.");
+       SysTryReturnVoidResult(NID_SYS, sendFunction != null, E_SYSTEM, "IPC Server is not ready.");
 
        bool primitiveCommand = false;
        if(__pAccessoryConditionHandler != null)
@@ -124,39 +124,29 @@ AccessoryMonitor::OnDataRouterDataReceivedN(const char* buffer, int length)
                SysLog(NID_SYS, "Requested data is not command. it will be forwarded to current application[%d]", __currentPid);
                if(__currentPid > 0)
                {
-                       ArrayList* pDataList = new (std::nothrow) ArrayList();
+                       ArrayList* pDataList = new (std::nothrow) ArrayList(SingleObjectDeleter);
                        ByteBuffer* pByteBuffer = new (std::nothrow) ByteBuffer();
 
                        String* pCommand = new (std::nothrow) String(SERIAL_COMMAND_DATA);
                        String* pComponentId= new (std::nothrow) String(ACCESSORY_COMPONENT_ID);
                        char* pIterator = const_cast<char*>(buffer);
 
+                       SysLog(NID_SYS, "Required buffer length is %d.", length);
                        pByteBuffer->Construct(length);
 
-                       for(int i = 0; i < length; i++)
+                       for(int i=0;i<length;i++)
                        {
-                               pByteBuffer->SetByte((byte)(*pIterator));
-                               pIterator++;
+                               SysLog(NID_SYS, "TEST: %c", buffer[i]);
                        }
 
-                       pDataList->Construct();
-                       pDataList->Add(*pComponentId);
-                       pDataList->Add(*pCommand);
-                       pDataList->Add(*pByteBuffer);
-
+                       pByteBuffer->SetArray((byte*)pIterator, 0, length);
 
-                       if(sendFunction!=null)
-                       {
-                               SysLog(NID_SYS, "Data is forwarded to [%d]", __currentPid);
-                               sendFunction(__currentPid, pDataList);
-                       }
-                       else
-                       {
-                               SysLog(NID_SYS, "sendFunction is empty.");
-                       }
+                       pDataList->Construct();
+                       pDataList->Add(pComponentId);
+                       pDataList->Add(pCommand);
+                       pDataList->Add(pByteBuffer);
 
-                       pDataList->RemoveAll(true);
-                       delete(pDataList);
+                       sendFunction(__currentPid, pDataList);
                }
        }
 }
index 5e6287f..4245318 100644 (file)
@@ -481,7 +481,7 @@ OnAlarmForLaunch(int alarmId)
        _AppLaunchCondition* pAppLaunchCondition = null;
        _AlarmConditionHandler* pAlarmConditionHandler = _AlarmConditionHandler::GetInstance();
        pAppLaunchCondition = pAlarmConditionHandler->GetAppLaunchCondition(alarmId);
-               if(pAppLaunchCondition != null)
+       if(pAppLaunchCondition != null)
        {
                SysLog(NID_SYS, "Launch Request");
                pAlarmConditionHandler->Launch(*pAppLaunchCondition);
index 6f45be9..a087fed 100644 (file)
@@ -26,6 +26,7 @@
 #include <FIo_AppServiceIpcMessages.h>
 #include "FApp_CommunicationDispatcher.h"
 
+using namespace Tizen::Base::Runtime;
 using namespace Tizen::Io;
 using namespace Tizen::App;
 using namespace Tizen::Base;
@@ -97,12 +98,69 @@ _CommunicationDispatcher::GetInstance()
        return __pCommunicationDispatcher;
 }
 
+class _IpcEventThreadForAsync
+       : public EventDrivenThread
+{
+public:
+       _IpcEventThreadForAsync(_IpcServer *pIpcServer)
+       : __pIpcServer(pIpcServer)
+       {
+       }
+
+       result Construct(long stackSize, ThreadPriority priority)
+       {
+               return EventDrivenThread::Construct(stackSize, priority);
+       }
+
+       bool OnStart(void)
+       {
+               return true;
+       }
+
+       void OnStop(void)
+       {
+       }
+
+       void OnUserEventReceivedN(RequestId requestId, IList *pArgs)
+       {
+               if(pArgs != null)
+               {
+                       ArrayList* data = (ArrayList*)pArgs;
+                       result r = __pIpcServer->SendResponse((int)requestId, new (std::nothrow) IoService_Data(*data));
+                       delete pArgs;
+                       SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send IPC message to %d. [%s]", (int)requestId, GetErrorMessage(r));
+               }
+       }
+private:
+       _IpcServer*     __pIpcServer;
+};
+
+_IpcEventThreadForAsync* pIpcEventThreadForAsync = null;
+
 result
-_CommunicationDispatcher::SendData(const int pid, ArrayList& data)
+_CommunicationDispatcher::SendData(const int pid, ArrayList* data)
 {
        result r = E_SUCCESS;
-       SysTryReturnResult(NID_SYS, __pIpcServer != null, E_SYSTEM, "IPC server is not ready.");
-       r = __pIpcServer->SendResponse(pid, new (std::nothrow) IoService_Data(data));
+
+       SysTryCatch(NID_SYS, __pIpcServer != null, r = E_SYSTEM, E_SYSTEM, "IPC server is not ready.");
+       SysTryCatch(NID_SYS, data != null, r = E_SYSTEM, E_SYSTEM, "There is no data.");
+
+       if(pIpcEventThreadForAsync == null)
+       {
+               pIpcEventThreadForAsync = new (std::nothrow) _IpcEventThreadForAsync(__pIpcServer);
+               pIpcEventThreadForAsync->Construct(1048576, THREAD_PRIORITY_MID);
+               pIpcEventThreadForAsync->Start();
+       }
+       SysTryCatch(NID_SYS, pIpcEventThreadForAsync != null, r = E_SYSTEM, E_SYSTEM, "Event thread is not ready.");
+
+       r = pIpcEventThreadForAsync->SendUserEvent((RequestId)pid, (IList*)data);
+       SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "Message is failed to add on event thread.");
+
+CATCH:
+       if(r != E_SUCCESS)
+       {
+               delete data;
+       }
 
        return r;
 }
index 191956b..aba77af 100644 (file)
@@ -46,7 +46,7 @@ _AccessoryManagerService* _AccessoryManagerService::__pAccessoryManagerService =
 result
 _AccessoryManagerService::SendDataFunc(int pid, ArrayList* data)
 {
-       SysLog(NID_SYS, "Request to send data");
+       SysLog(NID_SYS, "Request to send data to %d.", pid);
        SysTryReturnResult(NID_SYS, __pAccessoryManagerService != null, E_SYSTEM, "AccessoryManagerService is not ready");
        return __pAccessoryManagerService->SendData(pid, data);
 }
@@ -117,7 +117,7 @@ _AccessoryManagerService::SendData(int pid, ArrayList* data)
 {
        SysTryReturnResult(NID_SYS, __pCommunicationDispatcher != null, E_SYSTEM, "_CommunicationDispatcher is not initiated.");
 
-       return __pCommunicationDispatcher->SendData(pid, *data);
+       return __pCommunicationDispatcher->SendData(pid, data);
 }
 
 String
index cf27f5d..497f2bd 100644 (file)
@@ -196,17 +196,7 @@ _DeviceManagerService::SendEvent(String event)
        {
                int count = 0;
                Integer* pPid = null;
-               ArrayList data;
-               String serviceId(DEVICE_MANAGER_SERVICE_ID);
-               String commandId(DEVICE_MANAGER_COMMAND_EVENT);
-               String deviceId(DEVICE_MANAGER_BLUETOOTH);
-               String eventId(event);
-
-               data.Construct();
-               data.Add(serviceId);
-               data.Add(commandId);
-               data.Add(deviceId);
-               data.Add(eventId);
+               ArrayList* data = null;
 
                for(count = 0 ; count < __interestedPidList.GetCount() ; count++)
                {
@@ -214,13 +204,20 @@ _DeviceManagerService::SendEvent(String event)
                        if(pPid == null)
                        {
                                SysLogException(NID_SYS, E_SYSTEM, "It is failed to get appid from bluetooth headset app list");
-                               return;
                        }
-
-                       __pCommunicationDispatcher->SendData(pPid->value, data);
-                       SysLog(NID_SYS, "Bluetooth headset event is sended to %d.", pPid->value);
+                       else
+                       {
+                               data = new (std::nothrow) ArrayList(SingleObjectDeleter);
+                               data->Construct();
+                               data->Add(new (std::nothrow) String(DEVICE_MANAGER_SERVICE_ID));
+                               data->Add(new (std::nothrow) String(DEVICE_MANAGER_COMMAND_EVENT));
+                               data->Add(new (std::nothrow) String(DEVICE_MANAGER_BLUETOOTH));
+                               data->Add(new (std::nothrow) String(event));
+
+                               __pCommunicationDispatcher->SendData(pPid->value, data);
+                               SysLog(NID_SYS, "Bluetooth headset event is sended to %d.", pPid->value);
+                       }
                }
-
        }
        else
        {
@@ -229,48 +226,6 @@ _DeviceManagerService::SendEvent(String event)
 }
 
 void
-_DeviceManagerService::OnBluetoothEventOccured(int code)
-{
-       int count = 0;
-       Integer* pPid = null;
-
-       String command = DEVICE_MANAGER_COMMAND_EVENT;
-       String device = DEVICE_MANAGER_BLUETOOTH;
-       String event = L"event test";
-
-       result r = E_SUCCESS;
-
-       if(__interestedPidList.GetCount() == 0)
-       {
-               SysLog(NID_SYS, "Bluetooth Headset Event is not required by any application.");
-               return;
-       }
-
-       ArrayList eventData;
-       r = eventData.Construct();
-       SysTryCatch(NID_SYS, r == E_SUCCESS, , E_SYSTEM, "It is failed to create eventData, [%s] Propagated.", GetErrorMessage(r));
-
-       eventData.Add(command);
-       eventData.Add(device);
-       eventData.Add(event);
-
-       for(count = 0 ; count < __interestedPidList.GetCount() ; count++)
-       {
-               pPid = (Integer*)__interestedPidList.GetAt(count);
-               SysTryReturnVoidResult(NID_SYS, pPid != null, E_SYSTEM, "It is failed to get appid from bluetooth headset app list.");
-
-               r = __pCommunicationDispatcher->SendData(pPid->value, eventData);
-               if(r != E_SUCCESS)
-               {
-                       SysLogException(NID_SYS, E_SYSTEM, "It is failed to send bluetooth event data.");
-               }
-       }
-
-CATCH:
-       SetLastResult(r);
-}
-
-void
 _DeviceManagerService::AddInterestedApp(int pid)
 {
        int count = 0;
index 312bbc3..e24f164 100644 (file)
@@ -602,15 +602,12 @@ _SettingService::SendEvent(String key)
                Integer* pProcessId = (Integer*)pEnum->GetCurrent();
                SysTryReturnResult(NID_SYS, pProcessId != null, E_SYSTEM, "There is no listener id.");
 
-               String serviceId(_SETTING_SERVICE_ID);
-               String eventId(_SETTING_SERVICE_TYPE_EVENT);
-
-               ArrayList data;
-               data.Construct();
-               data.Add(serviceId);
-               data.Add(eventId);
-               data.Add(key);
-               r = __pCommunicationDispatcher->SendData(pProcessId->value, data);
+               ArrayList* data = new (std::nothrow) ArrayList(SingleObjectDeleter);
+               data->Construct();
+               data->Add(new (std::nothrow) String(_SETTING_SERVICE_ID));
+               data->Add(new (std::nothrow) String(_SETTING_SERVICE_TYPE_EVENT));
+               data->Add(new (std::nothrow) String(key));
+               r = __pCommunicationDispatcher->SendData(pProcessId->value, data); // Ownership is transfered.
                if(r != E_SUCCESS)
                {
                        SysLog(NID_SYS, "Required Key[%ls] is failed to delivered to application[%d]. [%s]", key.GetPointer(), pProcessId->value, GetErrorMessage(r));
@@ -640,15 +637,13 @@ _SettingService::SendEventForInternal(String key)
                Integer* pProcessId = (Integer*)pEnum->GetCurrent();
                SysTryReturnResult(NID_SYS, pProcessId != null, E_SYSTEM, "There is no listener id.");
 
-               String serviceId(_SETTING_SERVICE_ID);
-               String eventId(_SETTING_SERVICE_TYPE_EVENT);
+               ArrayList* data = new (std::nothrow) ArrayList(SingleObjectDeleter);
+               data->Construct();
+               data->Add(new (std::nothrow) String(_SETTING_SERVICE_ID));
+               data->Add(new (std::nothrow) String(_SETTING_SERVICE_TYPE_EVENT_INTERNAL));
+               data->Add(new (std::nothrow) String(key));
 
-               ArrayList data;
-               data.Construct();
-               data.Add(serviceId);
-               data.Add(eventId);
-               data.Add(key);
-               r = __pCommunicationDispatcher->SendData(pProcessId->value, data);
+               r = __pCommunicationDispatcher->SendData(pProcessId->value, data); // Ownership is transfered.
                if(r != E_SUCCESS)
                {
                        SysLog(NID_SYS, "Required Key[%ls] is failed to delivered to application[%d]. [%s]", key.GetPointer(), pProcessId->value, GetErrorMessage(r));
@@ -669,12 +664,12 @@ _SettingService::SendResponse(int pid, String responseId, String key, String val
 
        String serviceId(_SETTING_SERVICE_ID);
 
-       ArrayList data;
-       data.Construct();
-       data.Add(serviceId);
-       data.Add(responseId);
-       data.Add(key);
-       data.Add(value);
+       ArrayList* data = new (std::nothrow) ArrayList(SingleObjectDeleter);
+       data->Construct();
+       data->Add(new (std::nothrow) String(_SETTING_SERVICE_ID));
+       data->Add(new (std::nothrow) String(responseId));
+       data->Add(new (std::nothrow) String(key));
+       data->Add(new (std::nothrow) String(value));
 
        return __pCommunicationDispatcher->SendData(pid, data);
 }
index 13bf7f6..b2fc822 100644 (file)
@@ -205,17 +205,27 @@ _SystemService::OnRequestOccured(AppId appId, int pid, ArrayList* request, Array
                        }
                        else
                        {
-                               char* pImei = null;
-                               ret = system_info_get_value_string(SYSTEM_INFO_KEY_MOBILE_DEVICE_ID, &pImei);
-                               if(ret != SYSTEM_INFO_ERROR_NONE || pImei == null)
+                               bool supported = false;
+                               r = __systemInfo.GetValue(L"http://tizen.org/feature/telephony", supported);
+                               if(r != E_SUCCESS || supported == false)
                                {
-                                       SysLogException(NID_SYS, E_SYSTEM, "It is failed to get IMEI.");
+                                       SysLogException(NID_SYS, E_SYSTEM, "Current device does not support telephony feature.");
                                        resultId = new (std::nothrow) String(_SYSTEM_RESULT_ERROR);
                                }
                                else
                                {
-                                       resultId = new (std::nothrow) String(_SYSTEM_RESULT_OK);
-                                       returnValue = new (std::nothrow) String(pImei);
+                                       char* pImei = null;
+                                       ret = system_info_get_value_string(SYSTEM_INFO_KEY_MOBILE_DEVICE_ID, &pImei);
+                                       if(ret != SYSTEM_INFO_ERROR_NONE || pImei == null)
+                                       {
+                                               SysLogException(NID_SYS, E_SYSTEM, "It is failed to get IMEI.");
+                                               resultId = new (std::nothrow) String(_SYSTEM_RESULT_ERROR);
+                                       }
+                                       else
+                                       {
+                                               resultId = new (std::nothrow) String(_SYSTEM_RESULT_OK);
+                                               returnValue = new (std::nothrow) String(pImei);
+                                       }
                                }
                        }
                }
index 0d5e97e..17953ec 100644 (file)
@@ -203,40 +203,35 @@ _RuntimeInfo::SendResponse(int pid, int msg_id, long long size, result rcode)
        result r = E_SUCCESS;
        pthread_mutex_lock(&send_msg_lock);
 
-       ArrayList data;
-       String serviceId(_RUNTIME_SERVICE_ID);
-       String responseId(_RUNTIME_GET_SIZE);
-       String messageId;
-       String value;
-       String resultCode;
+       ArrayList* data = null;
+       String* value = null;
 
-       SysLog(NID_SYS, "Send Result");
+       SysLog(NID_SYS, "It sends asynchronous result.");
 
        _CommunicationDispatcher* pCommunicationDispatcher = _CommunicationDispatcher::GetInstance();
        SysTryCatch(NID_SYS, pCommunicationDispatcher != null, r = E_SYSTEM, r, "Communication Dispatcher is not ready.");
 
-       messageId.Append(msg_id);
-       value.Append(size);
+       data = new (std::nothrow) ArrayList(SingleObjectDeleter);
+       data->Construct();
+       data->Add(new (std::nothrow) String(_RUNTIME_SERVICE_ID));
+       data->Add(new (std::nothrow) String(_RUNTIME_GET_SIZE));
+       data->Add(new (std::nothrow) String(msg_id));
+       value = new String();
+       value->Append(size);
+       data->Add(*value);
+
+       data->Add(value);
 
        if(rcode == E_SUCCESS)
        {
-               resultCode.Append(_RUNTIME_RESULT_SUCCESS);
+               data->Add(new (std::nothrow) String(_RUNTIME_RESULT_SUCCESS));
        }
        else
        {
-               resultCode.Append(_RUNTIME_RESULT_SYSTEM);
+               data->Add(new (std::nothrow) String(_RUNTIME_RESULT_SYSTEM));
        }
 
-       data.Construct();
-       data.Add(serviceId);
-       data.Add(responseId);
-       data.Add(messageId);
-       data.Add(value);
-       data.Add(resultCode);
-
-       r = pCommunicationDispatcher->SendData(pid, data);
-       SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to deliver directory size[%lld] result to [%d].", size, pid);
-       SysLog(NID_SYS, "Result is delivered.");
+       pCommunicationDispatcher->SendData(pid, data);
 CATCH:
        pthread_mutex_unlock(&send_msg_lock);
 }