Resolve Serial Condition failure issue
authorJoohyun Kim <joohyune.kim@samsung.com>
Fri, 26 Oct 2012 02:50:30 +0000 (11:50 +0900)
committerJoohyun Kim <joohyune.kim@samsung.com>
Fri, 26 Oct 2012 02:50:30 +0000 (11:50 +0900)
Change-Id: I4d166cf9bcd7294053f7eae9c56530506ef1647f

plugins/accessory-condition-handler/AccessoryConditionHandler.cpp
plugins/accessory-condition-handler/AccessoryMonitor.cpp

index d84c319..570c9c6 100644 (file)
@@ -76,9 +76,15 @@ AccessoryConditionHandler::~AccessoryConditionHandler()
 result
 AccessoryConditionHandler::Register(_AppLaunchCondition& operation)
 {
-       SysLog(NID_SYS, "Request to register accessory process");
-       __appConditionList.Remove(operation.GetAppId());
-       __appConditionList.Add(operation.GetAppId(), operation.GetConditionString());
+       SysLog(NID_SYS, "Request to register accessory process, [%S][%S]", operation.GetAppId().GetPointer(), operation.GetConditionString().GetPointer());
+
+       AppId* pAppId = new (std::nothrow) AppId(operation.GetAppId());
+       String* pCondition = new (std::nothrow) String(operation.GetConditionString());
+
+       __appConditionList.Remove(operation.GetAppId(), true);
+       __appConditionList.Add(*pAppId, *pCondition);
+       //__appConditionList.Add(operation.GetAppId(), operation.GetConditionString());
+
        return E_SUCCESS;
 }
 
@@ -86,7 +92,7 @@ result
 AccessoryConditionHandler::Unregister(_AppLaunchCondition& operation)
 {
        SysLog(NID_SYS, "Request to unregister accessory process");
-       __appConditionList.Remove(operation.GetAppId());
+       __appConditionList.Remove(operation.GetAppId(), true);
        return E_SUCCESS;
 }
 
@@ -180,8 +186,6 @@ AccessoryConditionHandler::RequestCommandHandle(const char* command, int length)
 
        SysTryCatch(NID_IO, commandValue != null, resultValue = false, E_SYSTEM, "[E_SYSTEM] there is no message command");
 
-       SysLog(NID_IO, "Request command is [%s]", commandValue);
-
        pMapEnum = __appConditionList.GetMapEnumeratorN();
 
        SysTryCatch(NID_IO, pMapEnum != null, resultValue = false, E_SYSTEM, "[E_SYSTEM] There is wrong app list");
@@ -199,7 +203,16 @@ AccessoryConditionHandler::RequestCommandHandle(const char* command, int length)
                if (strcmp(commandValue, executionCondition) == 0)
                {
                        //Launch applicaiton.
-                       r = _AppManagerImpl::GetInstance()->LaunchApplication(*pAppId, null, null, AppManager::LAUNCH_OPTION_DEFAULT);
+                       _AppManagerImpl* pAppManagerImpl = _AppManagerImpl::GetInstance();
+
+                       if(pAppManagerImpl == null)
+                       {
+                               SysLog(NID_IO, "Not found AppManager instance");
+                               executed = false;
+                               break;
+                       }
+                       r = pAppManagerImpl->LaunchApplication(*pAppId, null, null, AppManager::LAUNCH_OPTION_DEFAULT);
+                       SysLog(NID_IO, "Application[%S] launch is requested.", pAppId->GetPointer());
 
                        if (r != E_SUCCESS)
                        {
@@ -220,7 +233,8 @@ AccessoryConditionHandler::RequestCommandHandle(const char* command, int length)
 
        if (executed == true)
        {
-               int responseLength = strlen(ACCESSORY_SERIAL_COMMAND_RESPONSE) + strlen(ACCESSORY_SERIAL_COMMAND_SUCCESS) + 5;
+
+               int responseLength = strlen(ACCESSORY_SERIAL_COMMAND_RESPONSE) + strlen(ACCESSORY_SERIAL_COMMAND_SUCCESS) + 6;
                response = new (std::nothrow) char[responseLength];
                memset(response, 0, responseLength);
 
@@ -231,7 +245,7 @@ AccessoryConditionHandler::RequestCommandHandle(const char* command, int length)
        }
        else
        {
-               int responseLength = strlen(ACCESSORY_SERIAL_COMMAND_RESPONSE) + strlen(ACCESSORY_SERIAL_COMMAND_FAIL) + 5;
+               int responseLength = strlen(ACCESSORY_SERIAL_COMMAND_RESPONSE) + strlen(ACCESSORY_SERIAL_COMMAND_FAIL) + 6;
                response = new (std::nothrow) char[responseLength];
                memset(response, 0, responseLength);
 
@@ -245,11 +259,26 @@ AccessoryConditionHandler::RequestCommandHandle(const char* command, int length)
        SysTryCatch(NID_IO, r == E_SUCCESS, resultValue = true, E_SYSTEM, "[%s] Fail to send data");
 
 CATCH:
-       delete [] commandValue;
-       delete [] registered;
-       delete [] executionCondition;
-       delete [] response;
-       delete pMapEnum;
+       if(commandValue != null)
+       {
+               delete [] commandValue;
+       }
+       if(registered != null)
+       {
+               delete [] registered;
+       }
+       if(executionCondition != null)
+       {
+               delete [] executionCondition;
+       }
+       if(response != null)
+       {
+               delete [] response;
+       }
+       if(pMapEnum != null)
+       {
+               delete pMapEnum;
+       }
 
        return resultValue;
 }
index 827484b..a851918 100644 (file)
@@ -274,7 +274,7 @@ OnRequestOccured(AppId appId, ArrayList* pRequest, ArrayList* pResponse)
                else if(pCommand->Equals(SERIAL_COMMAND_CLOSE, true))
                {
                        SysLog(NID_IO, "Serial close is required");
-                       gpAccessoryMonitor->SetClientId(L"");
+                       gpAccessoryMonitor->RemoveClientId(appId);
                }
                else
                {