From 710b23a23985b6b93ae8d61059b885ee1fcb8008 Mon Sep 17 00:00:00 2001 From: Hokwon Song Date: Wed, 24 Jul 2013 09:55:09 +0900 Subject: [PATCH] Update DeviceManager [dep:osp-common-service, osp-app-service] Change-Id: I4fb7c742667a1cb68e51f5a2368b3d8100f5a06f Signed-off-by: Hokwon Song --- src/system-server/CMakeLists.txt | 2 + src/system-server/device/FSys_DeviceManager.cpp | 254 ++++++++++++++++++++++++ src/system-server/inc/FSys_DeviceManager.h | 65 ++++++ src/system/FSys_DeviceManagerImpl.cpp | 55 ++++- src/system/FSys_DeviceManagerImpl.h | 2 + 5 files changed, 367 insertions(+), 11 deletions(-) create mode 100644 src/system-server/device/FSys_DeviceManager.cpp create mode 100644 src/system-server/inc/FSys_DeviceManager.h diff --git a/src/system-server/CMakeLists.txt b/src/system-server/CMakeLists.txt index e3ef90c..4c3a936 100644 --- a/src/system-server/CMakeLists.txt +++ b/src/system-server/CMakeLists.txt @@ -28,11 +28,13 @@ SET (${this_target}_SOURCE_FILES setting/providers/FSys_SettingStorageProvider.cpp setting/providers/FSys_SettingVibrationProvider.cpp runtime/FSys_RuntimeInfo.cpp + device/FSys_DeviceManager.cpp ) INCLUDE(FindPkgConfig) pkg_check_modules(system_pkgs REQUIRED capi-media-sound-manager + capi-system-media-key capi-network-bluetooth capi-network-wifi capi-network-tethering diff --git a/src/system-server/device/FSys_DeviceManager.cpp b/src/system-server/device/FSys_DeviceManager.cpp new file mode 100644 index 0000000..5108859 --- /dev/null +++ b/src/system-server/device/FSys_DeviceManager.cpp @@ -0,0 +1,254 @@ +// +// 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); + 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) +{ + 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; + 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) +{ + static pthread_once_t onceBlock = PTHREAD_ONCE_INIT; + if(__pDeviceManager == null) + { + pthread_once(&onceBlock, InitSingleton); + } + return __pDeviceManager; +} + +void +_DeviceManager::InitSingleton(void) +{ + SysLog(NID_SYS,"InitSingleton"); + __pDeviceManager = new (std::nothrow) _DeviceManager(); + SysTryReturn(NID_SYS, __pDeviceManager, , E_OUT_OF_MEMORY, "It is not enough memory."); + atexit(DestroySingleton); +} + + +void +_DeviceManager::DestroySingleton(void) +{ + SysLog(NID_SYS,"DestorySingleton"); + if (__pDeviceManager) + { + delete __pDeviceManager; + __pDeviceManager = null; + } +} +result +_DeviceManager::InitializeDevice(void) +{ + result r = E_SUCCESS; + + if(isInitBluetooth == false) + { + 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); + SysLog(NID_SYS,"It is success."); + return r; +} + + +result +_DeviceManager::DeinitializeDevice(void) +{ + SysLog(NID_SYS,"It is success DeinitializeDevice."); + result r = E_SUCCESS; + media_key_release(); + return r; +} + + +result +_DeviceManager::RegisterListner(IDeviceEventListener &listener) +{ + SysLog(NID_SYS,"RegisterListner 0x%x.", &listener); + __pDeviceManagerListener = &listener; + return E_SUCCESS; +} + +result +_DeviceManager::UnregisterListner(IDeviceEventListener &listener) +{ + SysLog(NID_SYS,"UnregisterListner 0x%x.", &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; +} diff --git a/src/system-server/inc/FSys_DeviceManager.h b/src/system-server/inc/FSys_DeviceManager.h new file mode 100644 index 0000000..aac5aaa --- /dev/null +++ b/src/system-server/inc/FSys_DeviceManager.h @@ -0,0 +1,65 @@ +// +// 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 + +#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 +{ +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 void InitSingleton(void); + static void DestroySingleton(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/FSys_DeviceManagerImpl.cpp b/src/system/FSys_DeviceManagerImpl.cpp index ed1f03f..37a88c5 100644 --- a/src/system/FSys_DeviceManagerImpl.cpp +++ b/src/system/FSys_DeviceManagerImpl.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -42,6 +43,7 @@ #include "FSys_CommunicationDispatcherClient.h" #include "FSys_DeviceManagerImpl.h" +#include "FSys_SystemServiceMessageClient.h" #define VCONFKEY_APPSERVICE_MMC_STATUS "memory/appservice/mmc" @@ -57,6 +59,7 @@ namespace Tizen { namespace System { static const wchar_t* _DEVICE_MANAGER_SERVICE_ID = L"osp.devicemanager.service"; +static const wchar_t* _DEVICE_MANAGER_SERVICE_ID_EX = 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"; @@ -146,19 +149,36 @@ _DeviceManagerImpl::_DeviceManagerImpl() : __pIpcClient(null) , __headSetType(DEVICE_TYPE_WIRED_HEADPHONE) , __bluetoothReferenceCount(0) + , __pSystemServiceMessageClient(null) { result r = E_SUCCESS; int headsetState = 0; 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."); + if(Tizen::Io::File::IsFileExist(L"/opt/usr/etc/common_service_for_devicemanager") == true) + { + SysLog(NID_SYS, "Device Manager is service 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."); + _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."); + 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(); + __pIpcClient = pCommunicationDispatcherClient->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"); @@ -238,13 +258,21 @@ _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 (__pSystemServiceMessageClient) + { + delete __pSystemServiceMessageClient; + } + } + else + { + pCommunicationDispatcherClient = _CommunicationDispatcherClient::GetInstance(); + SysTryCatch(NID_SYS, pCommunicationDispatcherClient != null, r = E_SYSTEM, r, "It is failed to get CommunicationDispatcherClient."); - 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 = 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); @@ -1438,6 +1466,11 @@ _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) + { + serviceId = _DEVICE_MANAGER_SERVICE_ID_EX; + } + stringComparer.Compare(*pServiceId, serviceId, cmp); if (cmp == 0) { diff --git a/src/system/FSys_DeviceManagerImpl.h b/src/system/FSys_DeviceManagerImpl.h index 7f1185b..858e817 100644 --- a/src/system/FSys_DeviceManagerImpl.h +++ b/src/system/FSys_DeviceManagerImpl.h @@ -50,6 +50,7 @@ class _IpcClient; namespace Tizen { namespace System { +class _SystemServiceMessageClient; class _DeviceManagerImpl : public Tizen::System::_ICommunicationDispatcherListener @@ -106,6 +107,7 @@ private: Tizen::Base::Collection::ArrayListT<_DeviceEventListenerContainer*> __deviceEventList; static _DeviceManagerImpl* __pDeviceManagerImpl; + _SystemServiceMessageClient* __pSystemServiceMessageClient; }; }} // Tizen::System -- 2.7.4