From: Hokwon Song Date: Fri, 14 Jun 2013 05:42:33 +0000 (+0900) Subject: Seperate DeviceManagerService into System-service so. X-Git-Tag: accepted/tizen/20130912.081851^2~215 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fecd2da6ec0e3f66f315d6d38c6b0f905af3d734;p=platform%2Fframework%2Fnative%2Fappfw.git Seperate DeviceManagerService into System-service so. Change-Id: I9b999933199bf2b0935f9853f9177ee74200a981 Signed-off-by: Hokwon Song --- diff --git a/src/system-server/CMakeLists.txt b/src/system-server/CMakeLists.txt index f87305a..c9cae01 100644 --- a/src/system-server/CMakeLists.txt +++ b/src/system-server/CMakeLists.txt @@ -5,12 +5,30 @@ INCLUDE_DIRECTORIES ( ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/inc ${CMAKE_SOURCE_DIR}/src/system-server/inc + ${CMAKE_SOURCE_DIR}/src/io/inc + ${CMAKE_SOURCE_DIR}/src/server/inc + ${CMAKE_SOURCE_DIR}/src/system/inc ) SET (${this_target}_SOURCE_FILES system/FSys_SystemInfo.cpp + dev/FSys_DeviceManager.cpp ) +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED + capi-system-media-key + capi-network-bluetooth +) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +FOREACH(ldflag ${pkgs_LDFLAGS}) + SET(EXTRA_LDFLAGS "${EXTRA_LDFLAGS} ${flag}") +ENDFOREACH(ldflag) + ## SET EXTRA COMPILER FLAGS SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIC -Wall" ) @@ -25,6 +43,8 @@ SET(CMAKE_CXX_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EX ADD_LIBRARY (${this_target} SHARED ${${this_target}_SOURCE_FILES}) TARGET_LINK_LIBRARIES(${this_target} osp-appfw) +TARGET_LINK_LIBRARIES(${this_target} capi-network-bluetooth) +TARGET_LINK_LIBRARIES(${this_target} capi-system-media-key) SET_TARGET_PROPERTIES(${this_target} PROPERTIES diff --git a/src/system-server/dev/FSys_DeviceManager.cpp b/src/system-server/dev/FSys_DeviceManager.cpp new file mode 100644 index 0000000..9e31407 --- /dev/null +++ b/src/system-server/dev/FSys_DeviceManager.cpp @@ -0,0 +1,238 @@ +// +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FSys_DeviceManager.cpp + * @brief This is the implementation file for _DeviceManager class. + */ + +#include +#include +#include + +#include +#include +#include "FSys_DeviceManager.h" + +using namespace Tizen::App; +using namespace Tizen::Io; +using namespace Tizen::System; +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; + +namespace { + const static wchar_t* DEVICE_MANAGER_SERVICE_ID = L"osp.devicemanager.service"; + const static wchar_t* DEVICE_MANAGER_BLUETOOTH = L"osp.devicemanager.bluetooth"; + + const static wchar_t* BLUETOOTH_A2DP_CONNECTED = L"Connected"; + const static wchar_t* BLUETOOTH_A2DP_DISCONNECTED = L"Disconnected"; + const static wchar_t* BLUETOOTH_A2DP_PLAY = L"Play"; + const static wchar_t* BLUETOOTH_A2DP_STOP = L"Stop"; + const static wchar_t* BLUETOOTH_A2DP_PAUSE = L"Pause"; + const static wchar_t* BLUETOOTH_A2DP_RESUME = L"Resume"; + const static wchar_t* BLUETOOTH_A2DP_FORWARD = L"Forward"; + const static wchar_t* BLUETOOTH_A2DP_FASTFORWARD = L"FastForward"; + const static wchar_t* BLUETOOTH_A2DP_BACKWARD = L"Backward"; + const static wchar_t* BLUETOOTH_A2DP_REWIND = L"Rewind"; +} + +Tizen::System::_DeviceManager* Tizen::System::_DeviceManager::__pDeviceManager = null; + +void bluetooth_connection_state_changed(int result, bool connected, const char* remote_address, bt_audio_profile_type_e type, void* user_data) +{ + SysLog(NID_SYS, "Bluetooth headset[%s] connection[%d] event", remote_address, connected); + String bt_event; + _DeviceManager* pDeviceManager = _DeviceManager::GetInstance(); + SysTryReturn(NID_SYS, pDeviceManager, ,E_SYSTEM, "DeviceManager is not created"); + + IDeviceEventListener* pDeviceEventListener = pDeviceManager->GetEventListener(); + + if(pDeviceManager->GetBluetoothStatus() != connected && pDeviceEventListener) + { + if(connected == true) + { + bt_event = BLUETOOTH_A2DP_CONNECTED; + } + else + { + bt_event = BLUETOOTH_A2DP_DISCONNECTED; + } + + pDeviceEventListener->OnDeviceStateChanged(DEVICE_TYPE_BLUETOOTH_HEADSET, bt_event); + } + pDeviceManager->SetBluetoothStatus(connected); +} + +void app_media_key_handler(media_key_e key, media_key_event_e status, void* pUserData) +{ + String event; + SysLog(NID_SYS, "Bluetooth headset event is occured %d, %d", (int)key, (int)status); + _DeviceManager* pDeviceManager = _DeviceManager::GetInstance(); + SysTryReturn(NID_SYS, pDeviceManager, ,E_SYSTEM, "DeviceManager is not created"); + + if(status == MEDIA_KEY_STATUS_RELEASED) + { + switch(key) + { + case MEDIA_KEY_PLAY: + event = BLUETOOTH_A2DP_PLAY; + break; + case MEDIA_KEY_STOP: + event = BLUETOOTH_A2DP_STOP; + break; + case MEDIA_KEY_PAUSE: + event = BLUETOOTH_A2DP_PAUSE; + break; + case MEDIA_KEY_PREVIOUS: + event = BLUETOOTH_A2DP_BACKWARD; + break; + case MEDIA_KEY_NEXT: + event = BLUETOOTH_A2DP_FORWARD; + break; + case MEDIA_KEY_FASTFORWARD: + event = BLUETOOTH_A2DP_FASTFORWARD; + break; + case MEDIA_KEY_REWIND: + event = BLUETOOTH_A2DP_REWIND; + break; + case MEDIA_KEY_UNKNOWN: + default: + SysLog(NID_SYS, "Unsupported key[%d] is occured.", key); + return; + } + + IDeviceEventListener* pDeviceEventListener = pDeviceManager->GetEventListener(); + if (pDeviceEventListener) + { + pDeviceEventListener->OnDeviceStateChanged(DEVICE_TYPE_BLUETOOTH_HEADSET, event); + } + } +} + +_DeviceManager::_DeviceManager() + : isBluetoothHeadSetConnected(false) + , isInitBluetooth(false) + , __pDeviceManagerListener(null) +{ +} + +_DeviceManager::~_DeviceManager() +{ + if(isInitBluetooth == true) + { + int btResult = 0; + SysLog(NID_SYS, "Bluetooth headset event is released."); + media_key_release(); + btResult = bt_audio_unset_connection_state_changed_cb(); + SysTryReturnVoidResult(NID_SYS, btResult == BT_ERROR_NONE, E_SYSTEM, "It is failed to unregister bluetooth headset connection event"); + + btResult = bt_audio_deinitialize(); + SysTryReturnVoidResult(NID_SYS, btResult == BT_ERROR_NONE, E_SYSTEM, "It is failed to close bluetooth"); + + btResult = bt_deinitialize(); + SysTryReturnVoidResult(NID_SYS, btResult == BT_ERROR_NONE, E_SYSTEM, "It is failed to init bluetooth module"); + isInitBluetooth = false; + } +} + +_DeviceManager* +_DeviceManager::GetInstance(void) +{ + if(__pDeviceManager == null) + { + __pDeviceManager = new (std::nothrow) _DeviceManager(); + } + return __pDeviceManager; +} + +result +_DeviceManager::InitializeDevice(void) +{ + result r = E_SUCCESS; + + if(isInitBluetooth == false) + { + SysLog(NID_SYS, "Bluetooth headset event is reserved."); + + int btResult = 0; + btResult = bt_initialize(); + + SysTryReturnResult(NID_SYS, btResult == BT_ERROR_NONE, E_SYSTEM, "It is failed to init bluetooth module"); + + btResult = bt_audio_initialize(); + SysTryReturnResult(NID_SYS, btResult == BT_ERROR_NONE, E_SYSTEM, "It is failed to init bluetooth audio module"); + + btResult = bt_audio_set_connection_state_changed_cb(bluetooth_connection_state_changed, null); + SysTryReturnResult(NID_SYS, btResult == BT_ERROR_NONE, E_SYSTEM, "It is failed to register bluetooth audio event"); + + isInitBluetooth = true; + } + media_key_reserve(app_media_key_handler, null); + + return r; +} + + +result +_DeviceManager::DeinitializeDevice(void) +{ + result r = E_SUCCESS; + media_key_release(); + return r; +} + + +result +_DeviceManager::RegisterListner(IDeviceEventListener &listener) +{ + __pDeviceManagerListener = &listener; + return E_SUCCESS; +} + +result +_DeviceManager::UnregisterListner(IDeviceEventListener &listener) +{ + __pDeviceManagerListener = null; + return E_SUCCESS; +} + +IDeviceEventListener* +_DeviceManager::GetEventListener() +{ + return __pDeviceManagerListener; +} + +String +_DeviceManager::GetId(void) +{ + return DEVICE_MANAGER_SERVICE_ID; +} + +bool +_DeviceManager::GetBluetoothStatus(void) +{ + return isBluetoothHeadSetConnected; +} +void +_DeviceManager::SetBluetoothStatus(bool status) +{ + isBluetoothHeadSetConnected = status; +} + +extern "C" _OSP_EXPORT_ _IDeviceManager* DeviceManager_CreateInstance() +{ + return _DeviceManager::GetInstance(); +} diff --git a/src/system-server/inc/FSys_DeviceManager.h b/src/system-server/inc/FSys_DeviceManager.h new file mode 100644 index 0000000..1b96fde --- /dev/null +++ b/src/system-server/inc/FSys_DeviceManager.h @@ -0,0 +1,64 @@ +// +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FSys_DeviceManager.h + * @brief This is the header file of the _DeviceManager class. + * + * This header file contains the declarations of the _DeviceManager class. + */ +#include +#include +#include +#include "FSys_IDeviceManager.h" + +#ifndef _FSYS_INTERNAL_DEVICE_MANAGER_H_ +#define _FSYS_INTERNAL_DEVICE_MANAGER_H_ + +namespace Tizen { namespace System { + +/** + * @class _DeviceManager + * @brief This class contains implementaion of device control. + * @since 2.1 + */ +class _OSP_EXPORT_ _DeviceManager + : public _IDeviceManager +{ +private: + _DeviceManager(void); + virtual ~_DeviceManager(void); +public: + virtual result InitializeDevice(void); + virtual result DeinitializeDevice(void); + virtual result RegisterListner(IDeviceEventListener &listener); + virtual result UnregisterListner(IDeviceEventListener &listener); + IDeviceEventListener* GetEventListener(); + + virtual Tizen::Base::String GetId(void); + void SetBluetoothStatus(bool status); + virtual bool GetBluetoothStatus(void); + static _DeviceManager* GetInstance(void); + +private: + static _DeviceManager* __pDeviceManager; + bool isBluetoothHeadSetConnected; + bool isInitBluetooth; + IDeviceEventListener* __pDeviceManagerListener; +}; //_DeviceManager + +}} //Tizen::System +#endif /* _FSYS_INTERNAL_DEVICE_MANAGER_H_ */ diff --git a/src/system-server/inc/FSys_IDeviceManager.h b/src/system-server/inc/FSys_IDeviceManager.h new file mode 100644 index 0000000..139d502 --- /dev/null +++ b/src/system-server/inc/FSys_IDeviceManager.h @@ -0,0 +1,50 @@ +// +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FSys_IDeviceManager.h + * @brief This is the header file of the _IDeviceManager class. + * + * This header file contains the declarations of the _IDeviceManager class. + */ +#include +#include + +#ifndef _FSYS_INTERNAL_IDEVICE_MANAGER_H_ +#define _FSYS_INTERNAL_IDEVICE_MANAGER_H_ + +namespace Tizen { namespace System { + +/** + * @class _IDeviceManager + * @brief This class contains implementaion of device control. + * @since 2.1 + */ +class _OSP_EXPORT_ _IDeviceManager +{ +protected: + _IDeviceManager(void) {}; + virtual ~_IDeviceManager(void) {}; +public: + virtual result InitializeDevice(void) = 0; + virtual result DeinitializeDevice(void) = 0; + virtual bool GetBluetoothStatus(void) = 0; + virtual result RegisterListner(IDeviceEventListener &listener) = 0; + virtual result UnregisterListner(IDeviceEventListener &listener) = 0; +}; //_IDeviceManager + +}} //Tizen::System +#endif /* _FSYS_INTERNAL_IDEVICE_MANAGER_H_ */ diff --git a/src/system/CMakeLists.txt b/src/system/CMakeLists.txt index da0b937..0b14814 100755 --- a/src/system/CMakeLists.txt +++ b/src/system/CMakeLists.txt @@ -42,6 +42,7 @@ SET (${this_target}_SOURCE_FILES FSys_DeviceEventListenerContainer.cpp FSys_SettingClient.cpp FSys_SystemClient.cpp + FSys_DeviceManagerMsgClient.cpp ) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") diff --git a/src/system/FSys_DeviceManagerImpl.cpp b/src/system/FSys_DeviceManagerImpl.cpp index ff7ca7d..cf68558 100644 --- a/src/system/FSys_DeviceManagerImpl.cpp +++ b/src/system/FSys_DeviceManagerImpl.cpp @@ -42,6 +42,7 @@ #include "FSys_CommunicationDispatcherClient.h" #include "FSys_DeviceManagerImpl.h" +#include "FSys_DeviceManagerMsgClient.h" #define VCONFKEY_APPSERVICE_MMC_STATUS "memory/appservice/mmc" @@ -56,7 +57,7 @@ using namespace Tizen::Io; namespace Tizen { namespace System { -static const wchar_t* _DEVICE_MANAGER_SERVICE_ID = L"osp.devicemanager.service"; +static const wchar_t* _DEVICE_MANAGER_SERVICE_ID = L"osp.sys.ipcserver.devicemanager"; static const wchar_t* _DEVICE_MANAGER_COMMAND_OPEN = L"osp.devicemanager.command.open"; static const wchar_t* _DEVICE_MANAGER_COMMAND_CLOSE = L"osp.devicemanager.command.close"; static const wchar_t* _DEVICE_MANAGER_COMMAND_STATUS = L"osp.devicemanager.command.status"; @@ -152,13 +153,11 @@ _DeviceManagerImpl::_DeviceManagerImpl() int ret = 0; static String DEVICE_MANAGER_SERVICE_ID(_DEVICE_MANAGER_SERVICE_ID); - _CommunicationDispatcherClient* pCommunicationDispatcherClient = _CommunicationDispatcherClient::GetInstance(); - SysTryCatch(NID_SYS, pCommunicationDispatcherClient != null, r = E_SYSTEM, r, "It is failed to get CommunicationDispatcherClient."); - - r = pCommunicationDispatcherClient->RegisterCommunicationListener(DEVICE_MANAGER_SERVICE_ID, *this); - SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to register on CommunicationDispatcherClient."); - - __pIpcClient = pCommunicationDispatcherClient->GetIpcClient(); + _DeviceManagerMsgClient* pDeviceManagerMsgClient = _DeviceManagerMsgClient::GetInstance(); + SysTryCatch(NID_SYS, pDeviceManagerMsgClient != null, r = E_SYSTEM, r, "It is failed to get DeviceManagerMsgClient."); + r = pDeviceManagerMsgClient->RegisterListener(_DEVICE_MANAGER_SERVICE_ID,*this); + SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to register on DeviceManagerMsgClient."); + __pIpcClient = pDeviceManagerMsgClient->GetIpcClient(); ret = runtime_info_set_changed_cb(RUNTIME_INFO_KEY_USB_CONNECTED, OnDeviceStateChanged, null); SysTryCatch(NID_SYS, ret == RUNTIME_INFO_ERROR_NONE, r = E_SYSTEM, r, "It is failed to register USB event"); @@ -210,7 +209,7 @@ _DeviceManagerImpl::~_DeviceManagerImpl() { result r = E_SUCCESS; int ret = 0; - _CommunicationDispatcherClient* pCommunicationDispatcherClient = null; + _DeviceManagerMsgClient* pDeviceManagerMsgClient = null; String key(_DEVICE_MANAGER_SERVICE_ID); ret = runtime_info_unset_changed_cb(RUNTIME_INFO_KEY_USB_CONNECTED); @@ -238,15 +237,13 @@ _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"); + pDeviceManagerMsgClient = _DeviceManagerMsgClient::GetInstance(); + SysTryCatch(NID_SYS, pDeviceManagerMsgClient != null, r = E_SYSTEM, r, "It is failed to get DeviceManagerMsgClient."); - pCommunicationDispatcherClient = _CommunicationDispatcherClient::GetInstance(); - SysTryCatch(NID_SYS, pCommunicationDispatcherClient != null, r = E_SYSTEM, r, "It is failed to get CommunicationDispatcherClient."); - - r = pCommunicationDispatcherClient->UnregisterCommunicationListener(key); - SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to register on CommunicationDispatcherClient."); + r = pDeviceManagerMsgClient->UnregisterListener(_DEVICE_MANAGER_SERVICE_ID); + SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to register on DeviceManagerMsgClient."); __pIpcClient = null; - CATCH: SetLastResult(r); } @@ -463,7 +460,8 @@ _DeviceManagerImpl::RequireBluetoothEvent(void) r = __pIpcClient->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); + responseMessages.RemoveAll(true); } return r; diff --git a/src/system/FSys_DeviceManagerMsgClient.cpp b/src/system/FSys_DeviceManagerMsgClient.cpp new file mode 100644 index 0000000..3608023 --- /dev/null +++ b/src/system/FSys_DeviceManagerMsgClient.cpp @@ -0,0 +1,122 @@ +// +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FSys_DeviceManagerMsgClient.cpp + * @brief This is the implementation file for _DeviceManagerMsgClient class. + */ + +#include +#include +#include +#include +#include +#include "FSys_DeviceManagerMsgClient.h" + +using namespace Tizen::App; +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Io; + +namespace Tizen { namespace System +{ +static const wchar_t* _DEVICE_MANAGER_MESSAGE_IPC_ID = L"osp.sys.ipcserver.devicemanager"; + +_DeviceManagerMsgClient* _DeviceManagerMsgClient::__pDeviceManagerMsgClient = null; + +_DeviceManagerMsgClient::_DeviceManagerMsgClient() + : __pIpcClient(null), + __pDeviceManagerMsgListener(null) +{ + result r = E_SUCCESS; + + __pIpcClient.reset(new (std::nothrow) _IpcClient()); + SysTryReturn(NID_SYS, __pIpcClient != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] It is failed to create IPC client"); + + r = __pIpcClient->Construct(_DEVICE_MANAGER_MESSAGE_IPC_ID, this); + + SysTryReturn(NID_SYS, r == E_SUCCESS, , r, "Propagated. [%s]", GetErrorMessage(r)); + SetLastResult(r); +} + +_DeviceManagerMsgClient::~_DeviceManagerMsgClient() +{ +} + +_DeviceManagerMsgClient* +_DeviceManagerMsgClient::GetInstance() +{ + if(__pDeviceManagerMsgClient == null) + { + __pDeviceManagerMsgClient = new (std::nothrow) _DeviceManagerMsgClient(); + SysTryReturn(NID_SYS, __pDeviceManagerMsgClient, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] It is not enough memory."); + } + return __pDeviceManagerMsgClient; +} + +_IpcClient* +_DeviceManagerMsgClient::GetIpcClient() +{ + return __pIpcClient.get(); +} + +result +_DeviceManagerMsgClient::RegisterListener(const String key, _ICommunicationDispatcherListener& listener) +{ + SysLog(NID_SYS, "Enter."); + SysTryReturnResult(NID_SYS, !__pDeviceManagerMsgListener, E_OBJ_ALREADY_EXIST, "DeviceManager listener was set already."); + __pDeviceManagerMsgListener = &listener; + SysLog(NID_SYS, "Exit."); + return E_SUCCESS; +} + +result +_DeviceManagerMsgClient::UnregisterListener(const String key) +{ + SysTryReturnResult(NID_SYS, __pDeviceManagerMsgListener, E_OBJ_NOT_FOUND, "DeviceManager listener is not set."); + __pDeviceManagerMsgListener = null; + return E_SUCCESS; +} + +void +_DeviceManagerMsgClient::OnIpcResponseReceived(_IpcClient& client, const IPC::Message& message) +{ + SysLog(NID_SYS, "Enter."); + IPC_BEGIN_MESSAGE_MAP(_DeviceManagerMsgClient, message) + IPC_MESSAGE_HANDLER_EX(IoService_Data, &client, OnDataReceived) + IPC_END_MESSAGE_MAP_EX() + SysLog(NID_SYS, "Exit."); +} + +void +_DeviceManagerMsgClient::OnDataReceived(const ArrayList& data) +{ + result r = E_SUCCESS; + String* pServiceId = (String*) data.GetAt(0); + + SysTryReturnVoidResult(NID_SYS, pServiceId != null, E_SYSTEM, "There is no service id."); + SysLog(NID_SYS, "Service id = %ls", pServiceId->GetPointer()); + + SysTryReturnVoidResult(NID_SYS, __pDeviceManagerMsgListener, E_SYSTEM, "Service[%ls] is available, but listener does not exist. [%s]", pServiceId->GetPointer(), GetErrorMessage(r)); + + __pDeviceManagerMsgListener->OnDataReceived(data); + + SysLog(NID_SYS, "Message is delivered to \"%ls\"[%x]", pServiceId->GetPointer(), __pDeviceManagerMsgListener); + ArrayList* temp = const_cast< ArrayList *> (&data); + temp->RemoveAll(true); +} + +}} diff --git a/src/system/FSys_DeviceManagerMsgClient.h b/src/system/FSys_DeviceManagerMsgClient.h new file mode 100644 index 0000000..7c2367f --- /dev/null +++ b/src/system/FSys_DeviceManagerMsgClient.h @@ -0,0 +1,63 @@ +// +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FSys_DeviceManagerMsgClient.h + * @brief This is the header file for the _DeviceManagerMsgClient class. + */ + +#ifndef _FSYS_INTERNAL_DEVICE_MANAGER_MESSAGE_CLIENT_IMPL_H_ +#define _FSYS_INTERNAL_DEVICE_MANAGER_MESSAGE_CLIENT_IMPL_H_ + +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace Tizen { namespace System +{ + +class _DeviceManagerMsgClient + : public Tizen::Io::_IIpcClientEventListener +{ +private: + _DeviceManagerMsgClient(); + ~_DeviceManagerMsgClient(); + +public: + result RegisterListener(const Tizen::Base::String key, _ICommunicationDispatcherListener& listener); + 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); + + Tizen::Io::_IpcClient* GetIpcClient(void); + static _DeviceManagerMsgClient* GetInstance(void); + +private: + std::unique_ptr< Tizen::Io::_IpcClient > __pIpcClient; + _ICommunicationDispatcherListener* __pDeviceManagerMsgListener; +private: + static _DeviceManagerMsgClient* __pDeviceManagerMsgClient; +}; + +}} // Tizen::System + +#endif //_FSYS_INTERNAL_DEVICE_MANAGER_MESSAGE_CLIENT_IMPL_H_