Enabling recovery code.
authorHokwon Song <hokwon.song@samsung.com>
Wed, 7 Aug 2013 05:16:37 +0000 (14:16 +0900)
committerHokwon Song <hokwon.song@samsung.com>
Thu, 8 Aug 2013 00:11:45 +0000 (09:11 +0900)
Change-Id: Ic42c6f06e6b6800af4c002522789d2eb2e3484d8
Signed-off-by: Hokwon Song <hokwon.song@samsung.com>
src/CommonService.cpp
src/system/FSys_DeviceManagerStub.cpp
src/system/FSys_DeviceManagerStub.h
src/system/FSys_PowerManagerStub.cpp
src/system/FSys_PowerManagerStub.h

index 65090e0..e08e5ab 100644 (file)
@@ -105,11 +105,7 @@ CommonService::InitializeServices(void)
        __pSystemInfoService = _SystemInfoService::GetInstance();
        __pSettingService = _SettingService::GetInstance();
        __pRuntimeInfoStub = _RuntimeInfoStub::GetInstance();
-
-       if(Tizen::Io::File::IsFileExist(L"/opt/usr/etc/common_service_for_devicemanager") == true)
-       {
-               __pDeviceManagerStub = _DeviceManagerStub::GetInstance();
-       }
+       __pDeviceManagerStub = _DeviceManagerStub::GetInstance();
        __pPowerManagerStub = _PowerManagerStub::GetInstance();
 
        __pMessagingIpcStub.reset(new (std::nothrow) Tizen::Messaging::_MessagingIpcStub());
index 491dae8..a9b7d6b 100644 (file)
@@ -43,6 +43,8 @@ const static wchar_t* DEVICE_MANAGER_COMMAND_CLOSE = L"osp.devicemanager.command
 const static wchar_t* DEVICE_MANAGER_COMMAND_STATUS= L"osp.devicemanager.command.status";
 const static wchar_t* DEVICE_MANAGER_COMMAND_EVENT = L"osp.devicemanager.command.event";
 const static wchar_t* DEVICE_MANAGER_BLUETOOTH = L"osp.devicemanager.bluetooth";
+const static wchar_t* DEVICE_MANAGER_REGISTRY_NAME = L"/tmp/sys.devicemanager.ini";
+const static wchar_t* DEVICE_MANAGER_REGISTRY_SECTION = L"DeviceManagerPid";
 
 const static wchar_t* BLUETOOTH_A2DP_CONNECTED = L"Connected";
 const static wchar_t* BLUETOOTH_A2DP_DISCONNECTED = L"Disconnected";
@@ -54,16 +56,17 @@ _DeviceManagerStub::_DeviceManagerStub(void)
        , __pDeviceManager(null)
        , __pDeviceManagerServiceIpcEventForAsync(null)
        , __IsInitializedDevice(false)
+       , __pRegistry(null)
 {
        result r = E_SUCCESS;
        r = __Mutex.Create(DEVIVE_MANAGER_SERVICE_MUTEX_ID);
        SysTryReturn(NID_SYS, r == E_SUCCESS, , r, "It is failed to create mutex. [%s] Propaged.", GetErrorMessage(r));
-       r = __interestedPidList.Construct();
-       SysTryReturn(NID_SYS, r == E_SUCCESS, , r, "It is failed to initiate bluetooth headset application list.");
 }
 
 _DeviceManagerStub::~_DeviceManagerStub(void)
 {
+       __pDeviceManager->UnregisterListner(*this);
+
        if (__pIpcServer)
        {
                __pIpcServer->Stop();
@@ -73,7 +76,6 @@ _DeviceManagerStub::~_DeviceManagerStub(void)
        {
                delete __pDeviceManagerServiceIpcEventForAsync;
        }
-       __interestedPidList.RemoveAll();
        __Mutex.Release();
 }
 
@@ -131,11 +133,22 @@ _DeviceManagerStub::Construct(void)
                 __IsInitializedDevice = true;
         }
 
+        __pRegistry = new (std::nothrow) Registry();
+        SysTryReturn(NID_SYS, __pRegistry, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,"Memory is insufficient.");
+
+        r = __pRegistry->Construct(DEVICE_MANAGER_REGISTRY_NAME, "a+");
+        SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "It is failed to open power manager registry.[%s]", GetErrorMessage(r));
+
+        __pRegistry->AddSection(DEVICE_MANAGER_REGISTRY_SECTION);
+       __pRegistry->Flush();
+
        __pIpcServer = move(pIpcServer);
 
        _AppManagerImpl* pAppManagerImpl = Tizen::App::_AppManagerImpl::GetInstance();
        pAppManagerImpl->AddAppEventListener(*this);
 
+       __pDeviceManager->RegisterListner(*this);
+
        return E_SUCCESS;
 }
 
@@ -171,86 +184,55 @@ CATCH:
 }
 
 void
-_DeviceManagerStub::AddInterestedApp(int pid)
+_DeviceManagerStub::AddInterestedApp(AppId appId, int pid)
 {
-       int count = 0;
-       for(count = 0; count < __interestedPidList.GetCount(); count++)
-       {
-               Integer* pPid = (Integer*)__interestedPidList.GetAt(count);
-               if(pPid->value == pid)
-               {
-                       return;
-               }
-       }
-
-       if (__interestedPidList.GetCount() == 0)
-       {
-               __pDeviceManager->RegisterListner(*this);
-       }
-
-       std::unique_ptr< Integer > pPid(new (std::nothrow) Integer(pid));
-       SysTryReturnVoidResult(NID_SYS, pPid, E_OUT_OF_MEMORY, "It is not enough memory.");
-
-       result r = __interestedPidList.Add(pPid.get());
-       SysTryReturnVoidResult(NID_SYS, !IsFailed(r), r, "It is failed to add pid");
-       pPid.release();
+       result r = __pRegistry->AddValue(DEVICE_MANAGER_REGISTRY_SECTION, (String) appId, pid);
+       SysLog(NID_SYS, "The result of adding pid is [%s]", GetErrorMessage(r));
+       __pRegistry->Flush();
 }
 
 
 void
-_DeviceManagerStub::RemoveInterestedApp(int pid)
+_DeviceManagerStub::RemoveInterestedApp(AppId appId, int pid)
 {
-       for(int count = 0; count < __interestedPidList.GetCount(); count++)
-       {
-               Integer* pPid = (Integer*)__interestedPidList.GetAt(count);
-               SysTryReturnVoidResult(NID_SYS, pPid != null, E_SYSTEM, "It is failed to get integerested PID.");
-               if(pPid->value == pid)
-               {
-                       __interestedPidList.RemoveAt(count, true);
-                       break;
-               }
-       }
-
-       if(__interestedPidList.GetCount() == 0)
-       {
-               __pDeviceManager->UnregisterListner(*this);
-       }
+       result r = __pRegistry->RemoveValue(DEVICE_MANAGER_REGISTRY_SECTION, (String) appId);
+       SysLog(NID_SYS, "The result of removing pid is [%s]", GetErrorMessage(r));
+       __pRegistry->Flush();
 }
 
 
 void
 _DeviceManagerStub::OnDeviceStateChanged (DeviceType deviceType, const Tizen::Base::String &state)
 {
-       if(__interestedPidList.GetCount() > 0)
-       {
-               int count = 0;
-               Integer* pPid = null;
-               ArrayList* data = null;
+       std::unique_ptr< Tizen::Base::Collection::IList> pInterestedPidList(__pRegistry->GetAllEntryNamesN(DEVICE_MANAGER_REGISTRY_SECTION));
+       SysTryReturn(NID_SYS, pInterestedPidList, , E_SYSTEM, "It is failed to get list from registry.");
 
-               for(count = 0 ; count < __interestedPidList.GetCount() ; count++)
+       if(pInterestedPidList->GetCount() > 0)
+       {
+               for ( int count = 0; count < pInterestedPidList->GetCount() ; count++)
                {
-                       pPid = (Integer*)__interestedPidList.GetAt(count);
-                       if(pPid == null)
-                       {
-                               SysLogException(NID_SYS, E_SYSTEM, "It is failed to get appid from bluetooth headset app list");
-                       }
-                       else
-                       {
-                               __serviceId = DEVICE_MANAGER_SERVICE_ID;
-                               __command = DEVICE_MANAGER_COMMAND_EVENT;
-                               __deviceType = DEVICE_MANAGER_BLUETOOTH;
-                               __result = state;
-
-                               data = new (std::nothrow) ArrayList();
-                               data->Construct();
-                               data->Add(__serviceId);
-                               data->Add(__command);
-                               data->Add(__deviceType);
-                               data->Add(__result);
-
-                               SendData(pPid->value, data);
-                               SysLog(NID_SYS, "Bluetooth headset event is sent to %d [%ls].", pPid->value, state.GetPointer());
-                       }
+                       int pid = -1;
+                       String* pAppId = (String*)pInterestedPidList->GetAt(count);
+                       result r = __pRegistry->GetValue(DEVICE_MANAGER_REGISTRY_SECTION, *pAppId, pid);
+                       SysTryReturn(NID_SYS, r == E_SUCCESS, , E_SYSTEM, "It is failed to get pid [%s].", GetErrorMessage(r));
+                       SysLog(NID_SYS, "Device interest id [%ls] [%d]", pAppId->GetPointer(), pid);
+
+                       ArrayList* data = null;
+
+                       __serviceId = DEVICE_MANAGER_SERVICE_ID;
+                       __command = DEVICE_MANAGER_COMMAND_EVENT;
+                       __deviceType = DEVICE_MANAGER_BLUETOOTH;
+                       __result = state;
+
+                       data = new (std::nothrow) ArrayList();
+                       data->Construct();
+                       data->Add(__serviceId);
+                       data->Add(__command);
+                       data->Add(__deviceType);
+                       data->Add(__result);
+
+                       SendData(pid, data);
+                       SysLog(NID_SYS, "Bluetooth headset event is sent to %d [%ls].", pid, state.GetPointer());
                }
        }
        else
@@ -262,7 +244,6 @@ _DeviceManagerStub::OnDeviceStateChanged (DeviceType deviceType, const Tizen::Ba
 void
 _DeviceManagerStub::OnIpcRequestReceived(_IpcServer& server, const IPC::Message& message)
 {
-       SysLog(NID_SYS, "Recevied");
        __currentPkgId = server.GetClientPackageId();
        __currentPid = server.GetClientId();
        IPC_BEGIN_MESSAGE_MAP(_DeviceManagerStub, message)
@@ -273,8 +254,6 @@ _DeviceManagerStub::OnIpcRequestReceived(_IpcServer& server, const IPC::Message&
 bool
 _DeviceManagerStub::OnRequestOccured(const ArrayList& request, ArrayList* response)
 {
-       SysLog(NID_SYS, "OnRequestOccured");
-
        int cmp = 0;
        result r = E_SUCCESS;
        bool isSuccess = false;
@@ -292,7 +271,7 @@ _DeviceManagerStub::OnRequestOccured(const ArrayList& request, ArrayList* respon
                if(cmp == 0)
                {
                        SysLog(NID_SYS, "Bluetooth headset event is required");
-                       AddInterestedApp(__currentPid);
+                       AddInterestedApp(__currentPkgId, __currentPid);
                }
        }
 
@@ -302,7 +281,7 @@ _DeviceManagerStub::OnRequestOccured(const ArrayList& request, ArrayList* respon
                strComparer.Compare(__deviceType, String(DEVICE_MANAGER_BLUETOOTH), cmp);
                if(cmp == 0)
                {
-                       RemoveInterestedApp(__currentPid);
+                       RemoveInterestedApp(__currentPkgId, __currentPid);
                }
        }
        strComparer.Compare(__command, String(DEVICE_MANAGER_COMMAND_STATUS), cmp);
@@ -347,6 +326,6 @@ CATCH:
 void
 _DeviceManagerStub::OnApplicationTerminated(const AppId& appId, int pid)
 {
-       SysLog(NID_SYS, "OnApplicationTerminated %ls, %d", appId.GetPointer(), pid);
-       RemoveInterestedApp(pid);
+       //SysLog(NID_SYS, "OnApplicationTerminated %ls, %d", appId.GetPointer(), pid);
+       RemoveInterestedApp(appId, pid);
 }
index 803adb3..e5f4726 100644 (file)
@@ -57,8 +57,8 @@ private:
        _DeviceManagerStub(const _DeviceManagerStub& rhs);
        _DeviceManagerStub& operator =(const _DeviceManagerStub& rhs);
 
-       void AddInterestedApp(int pid);
-       void RemoveInterestedApp(int pid);
+       void AddInterestedApp(Tizen::App::AppId appId, int pid);
+       void RemoveInterestedApp(Tizen::App::AppId appId, int pid);
 
        bool OnRequestOccured(const Tizen::Base::Collection::ArrayList& request, Tizen::Base::Collection::ArrayList* response);
        virtual void OnIpcRequestReceived(Tizen::Io::_IpcServer& server, const IPC::Message& message);
@@ -83,9 +83,9 @@ private:
        Tizen::Base::String __deviceType;
        Tizen::Base::String __result;
 
-       Tizen::Base::Collection::ArrayList __interestedPidList;
        _SystemServiceIpcEventForAsync* __pDeviceManagerServiceIpcEventForAsync;
        bool __IsInitializedDevice;
+       Tizen::Io::Registry* __pRegistry;
 }; // _DeviceManagerStub
 
 }} // Tizen::System
index dcc162a..a868704 100644 (file)
@@ -22,7 +22,7 @@
 #include <FBaseSysLog.h>
 #include <FIo_IpcServer.h>
 #include <FIo_AppServiceIpcMessages.h>
-#include <FSystem.h>
+#include <FIoRegistry.h>
 
 #include "FApp_AppManagerImpl.h"
 #include "FSys_PowerManagerStub.h"
@@ -43,6 +43,9 @@ namespace {
        static const int _POWER_COMMAND_ID = 1;
        static const wchar_t* _POWER_OK = L"osp.system.result.ok";
        static const wchar_t* _POWER_ERROR = L"osp.system.result.error";
+       static const wchar_t* _POWER_MANAGER_REGISTRY_NAME = L"/tmp/sys.powermanager.ini";
+       static const wchar_t* _POWER_MANAGER_REGISTRY_BRIGHTNESS_SECTION = L"Brightness";
+       static const wchar_t* _POWER_MANAGER_REGISTRY_ACTIVE_ID = L"ActiveId";
 }
 
 _PowerManagerStub* _PowerManagerStub::__pPowerManagerStub = null;
@@ -50,9 +53,8 @@ _PowerManagerStub* _PowerManagerStub::__pPowerManagerStub = null;
 _PowerManagerStub::_PowerManagerStub(void)
        : __pIpcServer(null)
        , __serviceId(POWER_MANAGER_SERVICE_ID)
+       , __pRegistry(null)
 {
-       result r = __appBrightnessList.Construct();
-       SysTryReturn(NID_SYS, r == E_SUCCESS, , r, "It is failed to initiate power manager app list.");
 }
 
 _PowerManagerStub::~_PowerManagerStub(void)
@@ -62,7 +64,7 @@ _PowerManagerStub::~_PowerManagerStub(void)
                __pIpcServer->Stop();
        }
 
-       __appBrightnessList.RemoveAll();
+       __pRegistry->Flush();
 }
 
 _PowerManagerStub*
@@ -117,6 +119,14 @@ _PowerManagerStub::Construct(void)
        r = pAppManagerImpl->AddAppEventListener(*this);
        SysTryReturn(NID_SYS, r == E_SUCCESS || r == E_OBJ_ALREADY_EXIST, E_SYSTEM, E_SYSTEM, "It is failed to add app event listener");
 
+       __pRegistry = new (std::nothrow) Registry();
+       SysTryReturn(NID_SYS, __pRegistry, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,"Memory is insufficient.");
+
+       r = __pRegistry->Construct(_POWER_MANAGER_REGISTRY_NAME, "a+");
+       SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "It is failed to open power manager registry.[%s]", GetErrorMessage(r));
+
+       __pRegistry->AddSection(_POWER_MANAGER_REGISTRY_BRIGHTNESS_SECTION);
+
        __pIpcServer = move(pIpcServer);
 
        return E_SUCCESS;
@@ -126,21 +136,19 @@ result
 _PowerManagerStub::ChangeBrightness()
 {
        result r = E_FAILURE;
+       int brightness = -1;
+
+       r = __pRegistry->GetValue(_POWER_MANAGER_REGISTRY_BRIGHTNESS_SECTION, (String)__activeAppId, brightness);
+       if (r == E_SUCCESS)
+       {
+               r = _PowerManager::ChangeBrightness(brightness);
+               SysLog(NID_SYS, "change brightness %d", brightness);
+       }
 
-        if(__appBrightnessList.GetCount() > 0)
-        {
-                Integer* brightness = (Integer*)__appBrightnessList.GetValue(__activeAppId);
-
-                if(brightness != null)
-                {
-                        r = _PowerManager::ChangeBrightness(brightness->ToInt());
-                       SysLog(NID_SYS, "change brightness %d", brightness->ToInt());
-                }
-        }
-       if (IsFailed(r))
+       if (r != E_SUCCESS)
        {
                r = _PowerManager::ChangeBrightness(0);
-               SysLog(NID_SYS, "change brightness system value.");
+                SysLog(NID_SYS, "change brightness system value.");
        }
 
        return r;
@@ -162,6 +170,12 @@ _PowerManagerStub::OnRequestOccured(const ArrayList& request, ArrayList* respons
 
        __command = *((String*)request.GetAt(_POWER_COMMAND_ID));
 
+       if (__activeAppId.IsEmpty())
+       {
+               __pRegistry->GetValue(_POWER_MANAGER_REGISTRY_BRIGHTNESS_SECTION, _POWER_MANAGER_REGISTRY_ACTIVE_ID, __activeAppId);
+               SysLog(NID_SYS, "Get the active id from registry [%ls].", __activeAppId.GetPointer());
+       }
+
        if (__command == _POWER_BRIGHTNESS_CHANGE)
        {
                SysTryCatch(NID_SYS, __activeAppId == __currentAppId, r = E_SUCCESS, r,
@@ -170,22 +184,17 @@ _PowerManagerStub::OnRequestOccured(const ArrayList& request, ArrayList* respons
                String* brightnessBuffer = (String*)request.GetAt(_POWER_COMMAND_ID + 1);
                Integer::Parse(*brightnessBuffer, brightness);
 
-               __appBrightnessList.Remove(__currentAppId, true);
+               __pRegistry->RemoveValue(_POWER_MANAGER_REGISTRY_BRIGHTNESS_SECTION, (String)__currentAppId);
 
-               unique_ptr<Integer> pBrightness(new (std::nothrow) Integer(brightness));
-               unique_ptr<String> pAppId(new (std::nothrow) String(__currentAppId));
-
-               r = __appBrightnessList.Add(*pAppId, *pBrightness);
+               r = __pRegistry->AddValue(_POWER_MANAGER_REGISTRY_BRIGHTNESS_SECTION, __currentAppId, brightness);
                SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r,
-                       "It is failed to add requested App Id(%ls) and Brightness(%d) on the managed app list.", pAppId->GetPointer(), pBrightness->ToInt());
-               pAppId.release();
-               pBrightness.release();
+                       "It is failed to add requested App Id(%ls) and Brightness(%d) on the managed app list.", __currentAppId.GetPointer(), brightness);
                r = ChangeBrightness();
        }
        else if(__command == _POWER_BRIGHTNESS_RESTORE)
        {
                SysLog(NID_SYS, "Request bright restore");
-               __appBrightnessList.Remove(__currentAppId, true);
+               __pRegistry->RemoveValue(_POWER_MANAGER_REGISTRY_BRIGHTNESS_SECTION, (String)__currentAppId);
                r = ChangeBrightness();
        }
        else
@@ -211,6 +220,8 @@ CATCH:
 
        ArrayList* temp = const_cast<ArrayList*>(&request);
        temp->RemoveAll(true);
+
+       __pRegistry->Flush();
        return isSuccess;
 }
 
@@ -220,7 +231,8 @@ _PowerManagerStub::OnApplicationTerminated(const AppId& appId, int pid)
        SysLog(NID_SYS, "Terminated app [%ls]", appId.GetPointer());
        String requiredAppId;
        appId.SubString(0, 10, requiredAppId);
-       __appBrightnessList.Remove(requiredAppId, true);
+       __pRegistry->RemoveValue(_POWER_MANAGER_REGISTRY_BRIGHTNESS_SECTION, (String)requiredAppId);
+       __pRegistry->Flush();
        ChangeBrightness();
 }
 
@@ -229,10 +241,16 @@ _PowerManagerStub::OnActiveAppChanged(const AppId& appId)
 {
        AppId smallAppId;
        appId.SubString(0, 10, smallAppId);
-       SysLog(NID_SYS, "Active app [%ls]", appId.GetPointer());
+       SysLog(NID_SYS, "Active app [%ls], current [%ls] ", smallAppId.GetPointer(), __activeAppId.GetPointer());
        if(__activeAppId != smallAppId)
        {
                __activeAppId = smallAppId;
+               result r = __pRegistry->AddValue(_POWER_MANAGER_REGISTRY_BRIGHTNESS_SECTION, _POWER_MANAGER_REGISTRY_ACTIVE_ID, (String)__activeAppId);
+               if (r == E_KEY_ALREADY_EXIST)
+               {
+                       __pRegistry->SetValue(_POWER_MANAGER_REGISTRY_BRIGHTNESS_SECTION, _POWER_MANAGER_REGISTRY_ACTIVE_ID, (String)__activeAppId);
+               }
+               __pRegistry->Flush();
                ChangeBrightness();
        }
        else
index d515854..28e3494 100644 (file)
@@ -28,6 +28,7 @@
 #include <unique_ptr.h>
 #include <FBase.h>
 #include <FSystem.h>
+
 #include <FIo_IIpcServerEventListener.h>
 #include <FAppIActiveAppEventListener.h>
 #include "FApp_IAppEventListener.h"
@@ -74,10 +75,10 @@ private:
        Tizen::Base::Runtime::Mutex             __Mutex;
        Tizen::App::AppId                       __activeAppId;
        Tizen::App::AppId                       __currentAppId;
-       Tizen::Base::Collection::HashMap        __appBrightnessList;
        Tizen::Base::String     __serviceId;
        Tizen::Base::String     __command;
        Tizen::Base::String     __result;
+       Tizen::Io::Registry* __pRegistry;
 }; // _PowerManagerStub
 
 }} // Tizen::System