+++ /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_DeviceManagerService.h
- * @brief This is the header file of the _DeviceManagerService class.
- *
- * This header file contains the declarations of the _DeviceManagerService class.
- */
-#include <FApp.h>
-#include <FBase.h>
-#include <FSys_IDeviceManagerEventListener.h>
-#include "FApp_ICommunicationRequestListener.h"
-
-#ifndef _FSYS_INTERNAL_DEVICE_MANAGER_SERVICE_H_
-#define _FSYS_INTERNAL_DEVICE_MANAGER_SERVICE_H_
-
-namespace Tizen { namespace System {
-
-/**
- * @class _DeviceManagerService
- * @brief This class contains implementaion of device control.
- * @since 2.1
- */
-class _DeviceManagerService
- : public Tizen::App::_ICommunicationRequestListener
-{
-private:
- _DeviceManagerService(void);
- virtual ~_DeviceManagerService(void);
-public:
- virtual Tizen::Base::String GetId(void);
- void OnRequestOccured(Tizen::App::AppId appId, int pid, Tizen::Base::Collection::ArrayList* request, Tizen::Base::Collection::ArrayList* response);
- void OnApplicationTerminated(const Tizen::App::AppId& appId, int pid);
- void SendEvent(Tizen::Base::String event);
- void SetBluetoothStatus(bool status);
- bool GetBluetoothStatus(void);
- static _DeviceManagerService* GetInstance(void);
-
-private:
- static _DeviceManagerService* __pDeviceManagerService;
- Tizen::App::_CommunicationDispatcher* __pCommunicationDispatcher;
- bool isBluetoothHeadSetConnected;
- bool isInitBluetooth;
- Tizen::Base::Collection::ArrayList __interestedPidList;
-
-private:
- void AddInterestedApp(int pid);
- void RemoveInterestedApp(int pid);
-
-}; //_DeviceManagerService
-
-}} //Tizen::System
-#endif /* _FSYS_INTERNAL_DEVICE_MANAGER_SERVICE_H_ */
+++ /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_DeviceManagerService.cpp
- * @brief This is the implementation file for _DeviceManagerService class.
- */
-
-#include <new>
-#include <system/media_key.h>
-#include <bluetooth.h>
-
-#include <FBaseSysLog.h>
-#include <FSys_DeviceManagerEventProvider.h>
-
-#include "FApp_CommunicationDispatcher.h"
-#include "FSys_DeviceManagerService.h"
-
-using namespace Tizen::App;
-using namespace Tizen::Io;
-using namespace Tizen::System;
-using namespace Tizen::Base;
-using namespace Tizen::Base::Collection;
-
-namespace {
- const String DEVICE_MANAGER_SERVICE_ID = L"osp.devicemanager.service";
- const String DEVICE_MANAGER_COMMAND_OPEN = L"osp.devicemanager.command.open";
- const String DEVICE_MANAGER_COMMAND_CLOSE = L"osp.devicemanager.command.close";
- const String DEVICE_MANAGER_COMMAND_STATUS= L"osp.devicemanager.command.status";
- const String DEVICE_MANAGER_COMMAND_EVENT = L"osp.devicemanager.command.event";
- const String DEVICE_MANAGER_BLUETOOTH = L"osp.devicemanager.bluetooth";
-
- const String BLUETOOTH_A2DP_CONNECTED = L"Connected";
- const String BLUETOOTH_A2DP_DISCONNECTED = L"Disconnected";
- const String BLUETOOTH_A2DP_PLAY = L"Play";
- const String BLUETOOTH_A2DP_STOP = L"Stop";
- const String BLUETOOTH_A2DP_PAUSE = L"Pause";
- const String BLUETOOTH_A2DP_RESUME = L"Resume";
- const String BLUETOOTH_A2DP_FORWARD = L"Forward";
- const String BLUETOOTH_A2DP_FASTFORWARD = L"FastForward";
- const String BLUETOOTH_A2DP_BACKWARD = L"Backward";
- const String BLUETOOTH_A2DP_REWIND = L"Rewind";
-}
-
-Tizen::System::_DeviceManagerService* Tizen::System::_DeviceManagerService::__pDeviceManagerService = 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;
- _DeviceManagerService* pDeviceManagerService = _DeviceManagerService::GetInstance();
-
- if(pDeviceManagerService != null)
- {
- if(pDeviceManagerService->GetBluetoothStatus() != connected)
- {
- if(connected == true)
- {
- bt_event = BLUETOOTH_A2DP_CONNECTED;
- }
- else
- {
- bt_event = BLUETOOTH_A2DP_DISCONNECTED;
- }
- pDeviceManagerService->SendEvent(bt_event);
- }
- pDeviceManagerService->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);
- _DeviceManagerService* pDeviceManagerService = _DeviceManagerService::GetInstance();
- if(pDeviceManagerService != null)
- {
- 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;
- }
- pDeviceManagerService->SendEvent(event);
- }
- }
-}
-
-_DeviceManagerService::_DeviceManagerService()
- : _ICommunicationRequestListener()
- , __pCommunicationDispatcher(null)
- , isBluetoothHeadSetConnected(false)
- , isInitBluetooth(false)
-{
- result r = E_SUCCESS;
-
- __pCommunicationDispatcher = _CommunicationDispatcher::GetInstance();
- SysTryCatch(NID_SYS, __pCommunicationDispatcher != null, r = E_SYSTEM, E_SYSTEM, "_CommunicationDispatcher initiate is failed.");
-
- r = __pCommunicationDispatcher->AddCommunicationEventListener(*this);
- SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "It is failed to add event listener.");
-
- r = __interestedPidList.Construct();
- SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "It is failed to initiate bluetooth headset application list.");
-CATCH:
- SetLastResult(r);
-}
-
-_DeviceManagerService::~_DeviceManagerService()
-{
- result r = E_SUCCESS;
-
-
- 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;
- }
-
- SysTryCatch(NID_SYS, __pCommunicationDispatcher != null, r = E_SYSTEM, E_SYSTEM, "_CommunicationDispatcher is not ready");
-
- r = __pCommunicationDispatcher->RemoveCommunicationEventListener(*this);
- SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "It is failed to remove event listener");
-
-CATCH:
- SetLastResult(r);
-}
-
-_DeviceManagerService*
-_DeviceManagerService::GetInstance(void)
-{
- if(__pDeviceManagerService == null)
- {
- __pDeviceManagerService = new (std::nothrow) _DeviceManagerService();
- }
- return __pDeviceManagerService;
-}
-
-String
-_DeviceManagerService::GetId(void)
-{
- return DEVICE_MANAGER_SERVICE_ID;
-}
-
-void
-_DeviceManagerService::SendEvent(String event)
-{
- if(__interestedPidList.GetCount() > 0)
- {
- int count = 0;
- Integer* pPid = null;
- ArrayList* data = null;
-
- for(count = 0 ; count < __interestedPidList.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
- {
- data = new (std::nothrow) ArrayList(SingleObjectDeleter);
- data->Construct();
- data->Add(new (std::nothrow) String(DEVICE_MANAGER_SERVICE_ID));
- data->Add(new (std::nothrow) String(DEVICE_MANAGER_COMMAND_EVENT));
- data->Add(new (std::nothrow) String(DEVICE_MANAGER_BLUETOOTH));
- data->Add(new (std::nothrow) String(event));
-
- __pCommunicationDispatcher->SendData(pPid->value, data);
- SysLog(NID_SYS, "Bluetooth headset event is sended to %d.", pPid->value);
- }
- }
- }
- else
- {
- SysLog(NID_SYS, "Bluetooth Headset Event is not required by any application.");
- }
-}
-
-void
-_DeviceManagerService::AddInterestedApp(int pid)
-{
- int count = 0;
- for(count = 0; count < __interestedPidList.GetCount(); count++)
- {
- Integer* pPid = (Integer*)__interestedPidList.GetAt(count);
- if(pPid->value == pid)
- {
- return;
- }
- }
-
- if(isInitBluetooth == false)
- {
- SysLog(NID_SYS, "Bluetooth headset event is reserved.");
-
- int btResult = 0;
- btResult = bt_initialize();
-
- SysTryReturnVoidResult(NID_SYS, btResult == BT_ERROR_NONE, E_SYSTEM, "It is failed to init bluetooth module");
-
- btResult = bt_audio_initialize();
- SysTryReturnVoidResult(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);
- SysTryReturnVoidResult(NID_SYS, btResult == BT_ERROR_NONE, E_SYSTEM, "It is failed to register bluetooth audio event");
-
- isInitBluetooth = true;
- }
-
- Integer* pPid = new (std::nothrow) Integer(pid);
- __interestedPidList.Add(*pPid);
-
- if(__interestedPidList.GetCount() > 0)
- {
- media_key_reserve(app_media_key_handler, null);
- }
-}
-
-void
-_DeviceManagerService::RemoveInterestedApp(int pid)
-{
- int count = 0;
- for(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)
- {
- media_key_release();
- }
-}
-
-void
-_DeviceManagerService::OnRequestOccured(AppId appId, int pid, ArrayList* request, ArrayList* response)
-{
- StringComparer strComparer;
- int cmp = 0;
- result r = E_SUCCESS;
- String* command = null;
- String* device = null;
-
- SysLog(NID_APP, "Request is forwarded to _DeviceManagerService");
- SysTryCatch(NID_SYS, request != null && response != null, r = E_INVALID_ARG, E_INVALID_ARG, "Parameters are null");
-
- command = (String*)request->GetAt(1);
- device = (String*)request->GetAt(2);
- SysTryCatch(NID_SYS, command!= null && device != null, r = E_INVALID_ARG, E_INVALID_ARG, "Parameters has no command %x, %x", command, device);
-
- SysLog(NID_SYS, "command is %ls, device is %ls", command->GetPointer(), device->GetPointer());
-
- strComparer.Compare(*command, DEVICE_MANAGER_COMMAND_OPEN, cmp);
- if(cmp == 0)
- {
- strComparer.Compare(*device, DEVICE_MANAGER_BLUETOOTH, cmp);
- if(cmp == 0)
- {
- SysLog(NID_SYS, "Bluetooth headset event is required");
- AddInterestedApp(pid);
- }
- }
-
- strComparer.Compare(*command, DEVICE_MANAGER_COMMAND_CLOSE, cmp);
- if(cmp == 0)
- {
- strComparer.Compare(*device, DEVICE_MANAGER_BLUETOOTH, cmp);
- if(cmp == 0)
- {
- RemoveInterestedApp(pid);
- }
- }
-
- strComparer.Compare(*command, DEVICE_MANAGER_COMMAND_STATUS, cmp);
- if(cmp == 0)
- {
- strComparer.Compare(*device, DEVICE_MANAGER_BLUETOOTH, cmp);
- if(cmp == 0)
- {
-
- SysLog(NID_SYS, "Bluetooth headset status is %d", isBluetoothHeadSetConnected);
- if(response != null)
- {
- String* serviceId = new (std::nothrow) String(DEVICE_MANAGER_SERVICE_ID);
- String* commandId = new (std::nothrow) String(DEVICE_MANAGER_COMMAND_STATUS);
- String* deviceId = new (std::nothrow) String(DEVICE_MANAGER_BLUETOOTH);
- String* status = null;
- if(isBluetoothHeadSetConnected == true)
- {
- status = new (std::nothrow) String(BLUETOOTH_A2DP_CONNECTED);
- }
- else
- {
- status = new (std::nothrow) String(BLUETOOTH_A2DP_DISCONNECTED);
- }
- response->Add(*serviceId);
- response->Add(*commandId);
- response->Add(*deviceId);
- response->Add(*status);
- }
- }
- }
-
-CATCH:
- SetLastResult(r);
-}
-
-void
-_DeviceManagerService::OnApplicationTerminated(const AppId& appId, int pid)
-{
- RemoveInterestedApp(pid);
-}
-
-bool
-_DeviceManagerService::GetBluetoothStatus(void)
-{
- return isBluetoothHeadSetConnected;
-}
-void
-_DeviceManagerService::SetBluetoothStatus(bool status)
-{
- isBluetoothHeadSetConnected = status;
-}
-