--- /dev/null
+//
+// 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 <new>
+#include <system/media_key.h>
+#include <bluetooth.h>
+
+#include <FBaseSysLog.h>
+#include <FSys_DeviceManagerEventProvider.h>
+#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;
+}
--- /dev/null
+//
+// 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 <FApp.h>
+#include <FBase.h>
+#include <FSys_IDeviceManagerEventListener.h>
+#include <FSysIDeviceEventListener.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
+{
+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_ */
#include <FBaseStringComparer.h>
#include <FBaseSysLog.h>
#include <FSysIDeviceEventListener.h>
+#include <FIo.h>
#include <FApp_AppInfo.h>
#include <FBase_NativeError.h>
#include "FSys_CommunicationDispatcherClient.h"
#include "FSys_DeviceManagerImpl.h"
+#include "FSys_SystemServiceMessageClient.h"
#define VCONFKEY_APPSERVICE_MMC_STATUS "memory/appservice/mmc"
{
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";
: __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");
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);
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)
{