From: Hokwon Song Date: Wed, 7 Aug 2013 05:16:05 +0000 (+0900) Subject: Enabling recovery from common-service restart. X-Git-Tag: submit/tizen/20131210.080830^2^2~193 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d57c1e916f1a4cb52db3e6eaf02bc8219b58cef1;p=platform%2Fframework%2Fnative%2Fappfw.git Enabling recovery from common-service restart. Change-Id: I4228ef2d7ecfaf8fac04f38dc552a04e510e88e2 Signed-off-by: Hokwon Song --- diff --git a/src/system-server/device/FSys_DeviceManager.cpp b/src/system-server/device/FSys_DeviceManager.cpp index 5108859..b689d3c 100644 --- a/src/system-server/device/FSys_DeviceManager.cpp +++ b/src/system-server/device/FSys_DeviceManager.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -60,7 +61,7 @@ void bluetooth_connection_state_changed(int result, bool connected, const char* IDeviceEventListener* pDeviceEventListener = pDeviceManager->GetEventListener(); - if(pDeviceManager->GetBluetoothStatus() != connected && pDeviceEventListener) + if(pDeviceEventListener) { if(connected == true) { @@ -74,7 +75,6 @@ void bluetooth_connection_state_changed(int result, bool connected, const char* pDeviceEventListener->OnDeviceStateChanged(DEVICE_TYPE_BLUETOOTH_HEADSET, bt_event); } pDeviceManager->SetBluetoothStatus(connected); - SysLog(NID_SYS, "It is success to call OnDeviceStateChanged 0x%x.", pDeviceEventListener); } void app_media_key_handler(media_key_e key, media_key_event_e status, void* pUserData) @@ -199,7 +199,6 @@ _DeviceManager::InitializeDevice(void) } media_key_reserve(app_media_key_handler, null); - SysLog(NID_SYS,"It is success."); return r; } @@ -207,7 +206,6 @@ _DeviceManager::InitializeDevice(void) result _DeviceManager::DeinitializeDevice(void) { - SysLog(NID_SYS,"It is success DeinitializeDevice."); result r = E_SUCCESS; media_key_release(); return r; @@ -217,7 +215,6 @@ _DeviceManager::DeinitializeDevice(void) result _DeviceManager::RegisterListner(IDeviceEventListener &listener) { - SysLog(NID_SYS,"RegisterListner 0x%x.", &listener); __pDeviceManagerListener = &listener; return E_SUCCESS; } @@ -225,7 +222,6 @@ _DeviceManager::RegisterListner(IDeviceEventListener &listener) result _DeviceManager::UnregisterListner(IDeviceEventListener &listener) { - SysLog(NID_SYS,"UnregisterListner 0x%x.", &listener); __pDeviceManagerListener = null; return E_SUCCESS; } @@ -245,6 +241,18 @@ _DeviceManager::GetId(void) bool _DeviceManager::GetBluetoothStatus(void) { + int ret = -1; + int errorCode = vconf_get_int(VCONFKEY_BT_DEVICE, &ret); + SysTryReturn(NID_SYS, errorCode == 0, isBluetoothHeadSetConnected, E_SYSTEM, "It is failed to get bt status. errorCode [%d]", errorCode); + + if (ret & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED || ret & VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED) + { + isBluetoothHeadSetConnected = true; + } + else + { + isBluetoothHeadSetConnected = false; + } return isBluetoothHeadSetConnected; } void diff --git a/src/system/FSys_DeviceManagerImpl.cpp b/src/system/FSys_DeviceManagerImpl.cpp index 37a88c5..7a946c6 100644 --- a/src/system/FSys_DeviceManagerImpl.cpp +++ b/src/system/FSys_DeviceManagerImpl.cpp @@ -150,27 +150,32 @@ _DeviceManagerImpl::_DeviceManagerImpl() , __headSetType(DEVICE_TYPE_WIRED_HEADPHONE) , __bluetoothReferenceCount(0) , __pSystemServiceMessageClient(null) + , __isCommonService(true) { result r = E_SUCCESS; int headsetState = 0; int ret = 0; static String DEVICE_MANAGER_SERVICE_ID(_DEVICE_MANAGER_SERVICE_ID); - if(Tizen::Io::File::IsFileExist(L"/opt/usr/etc/common_service_for_devicemanager") == true) + if (Tizen::Io::File::IsFileExist(L"/opt/usr/etc/common_service_for_devicemanager") == true) { - SysLog(NID_SYS, "Device Manager is service by common-service."); + __isCommonService = true; + } + + if (__isCommonService == true) + { + SysLog(NID_SYS, "Device Manager is serviced by common-service."); _SystemServiceMessageClient* pSystemServiceMessageClient = _SystemServiceMessageClient::CreateInstance(_DEVICE_MANAGER_SERVICE_ID_EX); SysTryCatch(NID_SYS, pSystemServiceMessageClient, r = E_SYSTEM, r, "It is failed to get system service message client."); r = pSystemServiceMessageClient->RegisterListener(_DEVICE_MANAGER_SERVICE_ID_EX, *this); SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to register on Listener."); - SysLog(NID_SYS, "Device listner 0x%x", this); __pSystemServiceMessageClient = pSystemServiceMessageClient; __pIpcClient = __pSystemServiceMessageClient->GetIpcClient(); } else { - SysLog(NID_SYS, "Device Manager is service by app-service."); + SysLog(NID_SYS, "Device Manager is serviced by app-service."); _CommunicationDispatcherClient* pCommunicationDispatcherClient = _CommunicationDispatcherClient::GetInstance(); SysTryCatch(NID_SYS, pCommunicationDispatcherClient != null, r = E_SYSTEM, r, "It is failed to get CommunicationDispatcherClient."); @@ -258,7 +263,7 @@ _DeviceManagerImpl::~_DeviceManagerImpl() ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_HDMI, DeviceEventVConfCallBack); SysTryCatch(NID_SYS, ret == RUNTIME_INFO_ERROR_NONE, r = E_SYSTEM, r, "It is failed to unregister HDMI event"); - if(Tizen::Io::File::IsFileExist(L"/opt/usr/etc/common_service_for_devicemanager") == true) + if (__isCommonService == true) { if (__pSystemServiceMessageClient) { @@ -273,6 +278,7 @@ _DeviceManagerImpl::~_DeviceManagerImpl() r = pCommunicationDispatcherClient->UnregisterCommunicationListener(key); SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to register on CommunicationDispatcherClient."); } + __pIpcClient = null; CATCH: SetLastResult(r); @@ -459,7 +465,7 @@ _DeviceManagerImpl::RequireBluetoothEvent(void) { result r = E_SUCCESS; - SysTryReturnResult(NID_SYS, __pIpcClient != null, E_SYSTEM, "Ipc Client is not ready"); + SysTryReturnResult(NID_SYS, GetIpcClient() != null, E_SYSTEM, "Ipc Client is not ready"); __bluetoothReferenceCount ++; @@ -488,7 +494,7 @@ _DeviceManagerImpl::RequireBluetoothEvent(void) unique_ptr pRequest(new (std::nothrow) IoService_Request(requestMessages, &responseMessages)); SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send bluetooth event subscribe by IPC"); - r = __pIpcClient->SendRequest(pRequest.get()); + r = GetIpcClient()->SendRequest(pRequest.get()); SysTryReturnResult(NID_SYS, r == E_SUCCESS,E_SYSTEM, "It is failed to add bluetooth id"); SysLog(NID_SYS, "It sent %ls", _DEVICE_MANAGER_COMMAND_OPEN); @@ -501,7 +507,7 @@ result _DeviceManagerImpl::ReleaseBluetoothEvent(void) { result r = E_SUCCESS; - SysTryReturnResult(NID_SYS, __pIpcClient != null, E_SYSTEM, "Ipc Client is not ready"); + SysTryReturnResult(NID_SYS, GetIpcClient() != null, E_SYSTEM, "Ipc Client is not ready"); __bluetoothReferenceCount --; SysTryReturnResult(NID_SYS, __bluetoothReferenceCount >= 0, E_SYSTEM, "Fail to manage reference count"); @@ -530,7 +536,7 @@ _DeviceManagerImpl::ReleaseBluetoothEvent(void) unique_ptr pRequest(new (std::nothrow) IoService_Request(requestMessages, &responseMessages)); SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send bluetooth event subscribe by IPC"); - r = __pIpcClient->SendRequest(pRequest.get()); + r = GetIpcClient()->SendRequest(pRequest.get()); SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to add bluetooth id"); responseMessages.RemoveAll(true); @@ -538,6 +544,18 @@ _DeviceManagerImpl::ReleaseBluetoothEvent(void) return r; } + +_IpcClient* +_DeviceManagerImpl::GetIpcClient(void) +{ + if (__isCommonService == true) + { + return __pSystemServiceMessageClient->GetIpcClient(); + } + return __pIpcClient; +} + + result _DeviceManagerImpl::AddOnExistedListener(DeviceType deviceType, const IDeviceEventListener* pListener) { @@ -1228,7 +1246,7 @@ _DeviceManagerImpl::GetState(DeviceType deviceType, String& state) int value = 0; int ret = 0; - SysTryReturnResult(NID_SYS, __pIpcClient != null, E_SYSTEM, "GetDeviceState Failed"); + SysTryReturnResult(NID_SYS, GetIpcClient() != null, E_SYSTEM, "GetDeviceState Failed"); switch (deviceType) { @@ -1266,7 +1284,7 @@ _DeviceManagerImpl::GetState(DeviceType deviceType, String& state) unique_ptr pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages)); - r = __pIpcClient->SendRequest(*(pMsg.get())); + r = GetIpcClient()->SendRequest(*(pMsg.get())); String* pMessageData = (String*)responseMessages.GetAt(_OSP_APP_SERVICE_IPC_MESSAGE_DATA); if (pMessageData != null) @@ -1466,7 +1484,7 @@ _DeviceManagerImpl::OnDataReceived(const ArrayList& data) SysTryReturnVoidResult(NID_SYS, pServiceId != null && pCommandId != null && pDeviceId != null && pEventId != null, E_SYSTEM, "There is no device data."); - if(Tizen::Io::File::IsFileExist(L"/opt/usr/etc/common_service_for_devicemanager") == true) + if (__isCommonService == true) { serviceId = _DEVICE_MANAGER_SERVICE_ID_EX; } diff --git a/src/system/FSys_DeviceManagerImpl.h b/src/system/FSys_DeviceManagerImpl.h index 858e817..88be2d0 100644 --- a/src/system/FSys_DeviceManagerImpl.h +++ b/src/system/FSys_DeviceManagerImpl.h @@ -89,6 +89,8 @@ private: result ReleaseBluetoothEvent(void); + Tizen::Io::_IpcClient* GetIpcClient(void); + static void OnDeviceStateChanged(runtime_info_key_e key, void* pData); static void DeviceEventVConfCallBack(keynode_t* node, void* userData); @@ -99,15 +101,12 @@ private: private: Tizen::Io::_IpcClient* __pIpcClient; - DeviceType __headSetType; - int __bluetoothReferenceCount; - Tizen::Base::Collection::ArrayListT<_DeviceEventListenerContainer*> __deviceEventList; - static _DeviceManagerImpl* __pDeviceManagerImpl; _SystemServiceMessageClient* __pSystemServiceMessageClient; + bool __isCommonService; }; }} // Tizen::System diff --git a/src/system/FSys_PowerManagerImpl.cpp b/src/system/FSys_PowerManagerImpl.cpp index fbeb815..220e82f 100644 --- a/src/system/FSys_PowerManagerImpl.cpp +++ b/src/system/FSys_PowerManagerImpl.cpp @@ -477,15 +477,16 @@ _PowerManagerImpl::RestoreScreenBrightness(void) unique_ptr<_IpcClient> pIpcClient (new (std::nothrow) _IpcClient()); SysTryReturn(NID_SYS, pIpcClient != null, E_OUT_OF_MEMORY, r, "It is failed to create IPC instance."); - if(Tizen::Io::File::IsFileExist(L"/opt/usr/etc/common_service_for_powermanager") == true) +// if(Tizen::Io::File::IsFileExist(L"/opt/usr/etc/common_service_for_powermanager") == true) { SysLog(NID_SYS, "PowerManager is serviced by common-service"); r = pIpcClient->Construct(POWER_MANAGER_SERVICE_ID); } - else +/* else { r = pIpcClient->Construct(_COMMUNICATION_DISPATCHER_IPC_ID); } +*/ SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "[%s] It failed to create IpcClient", GetErrorMessage(r)); requestMessage.Construct(); @@ -536,15 +537,16 @@ _PowerManagerImpl::SetScreenBrightness(int brightness) unique_ptr<_IpcClient> pIpcClient (new (std::nothrow) _IpcClient()); SysTryReturn(NID_SYS, pIpcClient != null, E_OUT_OF_MEMORY, r, "It is failed to create IPC instance."); - if(Tizen::Io::File::IsFileExist(L"/opt/usr/etc/common_service_for_powermanager") == true) +// if(Tizen::Io::File::IsFileExist(L"/opt/usr/etc/common_service_for_powermanager") == true) { SysLog(NID_SYS, "PowerManager is serviced by common-service"); r = pIpcClient->Construct(POWER_MANAGER_SERVICE_ID); } - else +/* else { r = pIpcClient->Construct(_COMMUNICATION_DISPATCHER_IPC_ID); } +*/ SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "[%s] It failed to create IpcClient", GetErrorMessage(r)); requestMessage.Construct(); diff --git a/src/system/FSys_RuntimeClientEx.cpp b/src/system/FSys_RuntimeClientEx.cpp index 9733ef1..a50bb52 100644 --- a/src/system/FSys_RuntimeClientEx.cpp +++ b/src/system/FSys_RuntimeClientEx.cpp @@ -87,7 +87,6 @@ _RuntimeClientEx::GetInstance(void) _RuntimeClientEx::_RuntimeClientEx() : __msgCount(0) - , __pIpcClient(null) , __pMessageClient(null) { result r = E_SUCCESS; @@ -99,8 +98,6 @@ _RuntimeClientEx::_RuntimeClientEx() r = __pMessageClient->RegisterListener(RUNTIME_SERVICE_ID, *this); SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to register on MessageClient."); - __pIpcClient = __pMessageClient->GetIpcClient(); - __asyncEventList.Construct(); CATCH: SetLastResult(r); @@ -114,7 +111,6 @@ _RuntimeClientEx::~_RuntimeClientEx() SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to register on MessageClient."); __asyncEventList.RemoveAll(true); - __pIpcClient = null; delete __pMessageClient; CATCH: SetLastResult(r); @@ -142,7 +138,7 @@ _RuntimeClientEx::GetDirectorySizeValueAsync(const String& path, IRuntimeInfoGet requestMessages.Add(messageId); unique_ptr pMsg(new (std::nothrow) IoService_Request(requestMessages, &responseMessages)); - r = __pIpcClient->SendRequest(*pMsg); + r = __pMessageClient->GetIpcClient()->SendRequest(*pMsg); SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to send request by IPC [%s]", GetErrorMessage(r)); String* pResult = (String*)responseMessages.GetAt(2); diff --git a/src/system/FSys_RuntimeClientEx.h b/src/system/FSys_RuntimeClientEx.h index 969d524..a142856 100644 --- a/src/system/FSys_RuntimeClientEx.h +++ b/src/system/FSys_RuntimeClientEx.h @@ -54,7 +54,6 @@ private: private: Tizen::Base::Collection::HashMap __asyncEventList; int __msgCount; - Tizen::Io::_IpcClient* __pIpcClient; _SystemServiceMessageClient* __pMessageClient; static _RuntimeClientEx* __pRuntimeClientEx; }; diff --git a/src/system/FSys_RuntimeInfoImpl.cpp b/src/system/FSys_RuntimeInfoImpl.cpp index 3dd5a30..a1e4d88 100644 --- a/src/system/FSys_RuntimeInfoImpl.cpp +++ b/src/system/FSys_RuntimeInfoImpl.cpp @@ -793,18 +793,19 @@ _RuntimeInfoImpl::GetValueAsync(const String& key, IRuntimeInfoGetLonglongAsyncR SysLog(NID_SYS, "%ls", directoryPath.GetPointer()); if(r == E_SUCCESS) { - if(Tizen::Io::File::IsFileExist(L"/opt/usr/etc/common_service_for_runtime") == true) +// if(Tizen::Io::File::IsFileExist(L"/opt/usr/etc/common_service_for_runtime") == true) { SysLog(NID_SYS, "Runtime is serviced by common-service."); _RuntimeClientEx* pRuntimeClientEx = _RuntimeClientEx::GetInstance(); pRuntimeClientEx->GetDirectorySizeValueAsync(directoryPath, listener); } - else +/* else { SysLog(NID_SYS, "Runtime is serviced by app-service."); _RuntimeClient* pRuntimeClient = _RuntimeClient::GetInstance(); pRuntimeClient->GetDirectorySizeValueAsync(directoryPath, listener); } +*/ } return r; diff --git a/src/system/FSys_SystemServiceMessageClient.cpp b/src/system/FSys_SystemServiceMessageClient.cpp index 524f8ad..b733c6c 100644 --- a/src/system/FSys_SystemServiceMessageClient.cpp +++ b/src/system/FSys_SystemServiceMessageClient.cpp @@ -18,11 +18,12 @@ * @file FSys_SystemServiceMessageClient.cpp * @brief This is the implementation file for _SystemServiceMessageClient class. */ +#include +#include #include #include -#include -#include +#include #include #include "FSys_SystemServiceMessageClient.h" @@ -118,4 +119,25 @@ _SystemServiceMessageClient::OnDataReceived(const ArrayList& data) temp->RemoveAll(true); } +void +_SystemServiceMessageClient::OnIpcServerDisconnected(_IpcClient& client) +{ + SysLogException(NID_SYS, E_SYSTEM, "The IpcServer was disconnected. [%ls].", client.GetName().GetPointer()); + result r = E_SUCCESS; + std::unique_ptr< _IpcClient > pIpcClient(new (std::nothrow) _IpcClient()); + SysTryReturn(NID_SYS, pIpcClient != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] It is failed to create IPC client"); + + int retry = 0; + do + { + r = pIpcClient->Construct(client.GetName(), this); + retry++; + Tizen::Base::Runtime::Thread::Sleep(1000); + }while (r != E_SUCCESS && retry < 10); + + SysTryReturn(NID_SYS, r == E_SUCCESS, , r, "Propagated. [%s]", GetErrorMessage(r)); + + __pIpcClient.reset(pIpcClient.release()); +} + }} diff --git a/src/system/FSys_SystemServiceMessageClient.h b/src/system/FSys_SystemServiceMessageClient.h index f80a9c1..4f34287 100644 --- a/src/system/FSys_SystemServiceMessageClient.h +++ b/src/system/FSys_SystemServiceMessageClient.h @@ -47,6 +47,7 @@ public: result UnregisterListener(const Tizen::Base::String key); void OnIpcResponseReceived(Tizen::Io::_IpcClient& client, const IPC::Message& message); void OnDataReceived(const Tizen::Base::Collection::ArrayList& data); + void OnIpcServerDisconnected(Tizen::Io::_IpcClient& client); Tizen::Io::_IpcClient* GetIpcClient(void); static _SystemServiceMessageClient* CreateInstance(const Tizen::Base::String id);