Fix the reserved media_key issue.
authorHokwon Song <hokwon.song@samsung.com>
Fri, 30 Aug 2013 01:04:44 +0000 (10:04 +0900)
committerHokwon Song <hokwon.song@samsung.com>
Fri, 30 Aug 2013 02:10:26 +0000 (11:10 +0900)
Change-Id: I3caad05f41e875d395c81e33d581acde435ae554
Signed-off-by: Hokwon Song <hokwon.song@samsung.com>
src/system/FSys_DeviceManagerStub.cpp

index a9b7d6b..c01264e 100644 (file)
@@ -126,13 +126,6 @@ _DeviceManagerStub::Construct(void)
        __pDeviceManager = _DeviceManager::GetInstance();
        SysTryReturn(NID_SYS, __pDeviceManager, E_SYSTEM, E_SYSTEM,"It is failed to create DeviceManager instance.");
 
-       if (__IsInitializedDevice == false)
-        {
-                r = __pDeviceManager->InitializeDevice();
-                SysTryReturn(NID_SYS, !IsFailed(r), false, E_SYSTEM, "It is failed to init device");
-                __IsInitializedDevice = true;
-        }
-
         __pRegistry = new (std::nothrow) Registry();
         SysTryReturn(NID_SYS, __pRegistry, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,"Memory is insufficient.");
 
@@ -186,7 +179,16 @@ CATCH:
 void
 _DeviceManagerStub::AddInterestedApp(AppId appId, int pid)
 {
-       result r = __pRegistry->AddValue(DEVICE_MANAGER_REGISTRY_SECTION, (String) appId, pid);
+       result r = E_SUCCESS;
+
+       if (__IsInitializedDevice == false)
+        {
+                r = __pDeviceManager->InitializeDevice();
+                SysTryReturn(NID_SYS, !IsFailed(r), , E_SYSTEM, "It is failed to init device");
+                __IsInitializedDevice = true;
+               SysLog(NID_SYS, "InitializeDevice for BT");
+        }
+       r = __pRegistry->AddValue(DEVICE_MANAGER_REGISTRY_SECTION, (String) appId, pid);
        SysLog(NID_SYS, "The result of adding pid is [%s]", GetErrorMessage(r));
        __pRegistry->Flush();
 }
@@ -195,9 +197,24 @@ _DeviceManagerStub::AddInterestedApp(AppId appId, int pid)
 void
 _DeviceManagerStub::RemoveInterestedApp(AppId appId, int pid)
 {
+       if (__IsInitializedDevice == false)
+       {
+               return;
+       }
        result r = __pRegistry->RemoveValue(DEVICE_MANAGER_REGISTRY_SECTION, (String) appId);
        SysLog(NID_SYS, "The result of removing pid is [%s]", GetErrorMessage(r));
        __pRegistry->Flush();
+
+       IList* pInterestList = __pRegistry->GetAllEntryNamesN(DEVICE_MANAGER_REGISTRY_SECTION);
+       SysTryReturn(NID_SYS, pInterestList, , E_SYSTEM, "It is failed to get registry.");
+
+       if (pInterestList->GetCount() == 0)
+       {
+               __pDeviceManager->DeinitializeDevice();
+               __IsInitializedDevice = false;
+               SysLog(NID_SYS, "DeinitializeDevice for BT");
+       }
+       delete pInterestList;
 }
 
 
@@ -255,8 +272,6 @@ bool
 _DeviceManagerStub::OnRequestOccured(const ArrayList& request, ArrayList* response)
 {
        int cmp = 0;
-       result r = E_SUCCESS;
-       bool isSuccess = false;
        StringComparer strComparer;
 
        __command = *(String*)request.GetAt(1);
@@ -315,17 +330,14 @@ _DeviceManagerStub::OnRequestOccured(const ArrayList& request, ArrayList* respon
                }
        }
 
-       isSuccess = true;
-CATCH:
        ArrayList* temp = const_cast<ArrayList*>(&request);
        temp->RemoveAll(true);
-       return isSuccess;
+       return true;
 }
 
 
 void
 _DeviceManagerStub::OnApplicationTerminated(const AppId& appId, int pid)
 {
-       //SysLog(NID_SYS, "OnApplicationTerminated %ls, %d", appId.GetPointer(), pid);
        RemoveInterestedApp(appId, pid);
 }