From 71194cfbf7b4066f737b7399f767d228b5b5f316 Mon Sep 17 00:00:00 2001 From: Hokwon Song Date: Fri, 14 Jun 2013 14:33:00 +0900 Subject: [PATCH] Add to start DeviceManagerService. Change-Id: Ie59b177c46f8b480a7d4b0fe19a60e2f09d48bf6 Signed-off-by: Hokwon Song --- CMakeLists.txt | 5 + inc/CommonService.h | 5 + inc/FSys_DeviceManagerServiceIpcEventForAsync.h | 53 +++ inc/FSys_DeviceManagerStub.h | 88 +++++ inc/FSys_IDeviceManager.h | 50 +++ src/CommonService.cpp | 7 + src/FSys_DeviceManagerServiceIpcEventForAsync.cpp | 69 ++++ src/FSys_DeviceManagerStub.cpp | 372 ++++++++++++++++++++++ 8 files changed, 649 insertions(+) create mode 100644 inc/FSys_DeviceManagerServiceIpcEventForAsync.h create mode 100644 inc/FSys_DeviceManagerStub.h create mode 100644 inc/FSys_IDeviceManager.h create mode 100644 src/FSys_DeviceManagerServiceIpcEventForAsync.cpp create mode 100644 src/FSys_DeviceManagerStub.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7162cc8..1843966 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ INCLUDE_DIRECTORIES ( /usr/include/osp/ui /usr/include/osp/server /usr/include/chromium + /usr/include/osp/system-service/inc inc ) @@ -30,6 +31,8 @@ SET (${this_target}_SOURCE_FILES src/FUi_UiManagerStub.cpp src/CommonService.cpp src/CommonServiceEntry.cpp + src/FSys_DeviceManagerStub.cpp + src/FSys_DeviceManagerServiceIpcEventForAsync.cpp ) ## SET EXTRA COMPILER FLAGS @@ -57,6 +60,8 @@ TARGET_LINK_LIBRARIES(${this_target} "-L/usr/lib/osp -losp-uifw" ) TARGET_LINK_LIBRARIES(${this_target} "-lutilX" ) TARGET_LINK_LIBRARIES(${this_target} "-lecore_x" ) TARGET_LINK_LIBRARIES(${this_target} "-L/usr/lib/osp-server -losp-appfw-server") +TARGET_LINK_LIBRARIES(${this_target} "-L/usr/lib/osp-server -losp-system-server") +TARGET_LINK_LIBRARIES(${this_target} "-ldl") INSTALL(TARGETS ${this_target} DESTINATION ../usr/apps/${APPID}/bin) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/manifest.xml DESTINATION ../usr/apps/${APPID}/info) diff --git a/inc/CommonService.h b/inc/CommonService.h index cd29365..2a803da 100644 --- a/inc/CommonService.h +++ b/inc/CommonService.h @@ -33,6 +33,10 @@ namespace Tizen { namespace Ui class _UiManagerStub; }} // Tizen::Ui +namespace Tizen { namespace System +{ +class _DeviceManagerStub; +}} /** * @class CommonService * @brief @@ -58,6 +62,7 @@ private: Tizen::App::_PackageManagerStub* __pPackageManagerStub; std::unique_ptr __pUiManagerStub; + Tizen::System::_DeviceManagerStub* __pDeviceManagerStub; }; #endif // _COMMON_SERVICE_H_ diff --git a/inc/FSys_DeviceManagerServiceIpcEventForAsync.h b/inc/FSys_DeviceManagerServiceIpcEventForAsync.h new file mode 100644 index 0000000..faf8fc4 --- /dev/null +++ b/inc/FSys_DeviceManagerServiceIpcEventForAsync.h @@ -0,0 +1,53 @@ +// +// 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_DeviceManagerServiceIpcEventForAsync.h + * @brief This is the header file for the %_DeviceManagerServiceIpcEventForAsync class. + * + * This header file contains the declarations of the %_DeviceManagerServiceIpcEventForAsync class. + */ + +#ifndef _FSYS_DEVICE_MANAGER_SERVICE_EVENT_FOR_ASYNC_H_ +#define _FSYS_DEVICE_MANAGER_SERVICE_EVENT_FOR_ASYNC_H_ + +#include +#include +#include + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Io; + +namespace Tizen { namespace System { +class _OSP_EXPORT_ _DeviceManagerServiceIpcEventForAsync + : public Tizen::Base::Runtime::EventDrivenThread +{ +public: + _DeviceManagerServiceIpcEventForAsync(_IpcServer *pIpcServer); + + result Construct(long stackSize, Tizen::Base::Runtime::ThreadPriority priority); + bool OnStart(void); + void OnStop(void); + void OnUserEventReceivedN(RequestId requestId, IList *pArgs); +private: + _IpcServer* __pIpcServer; +}; +}} //Tizen::System + + +#endif // _FSYS_DEVICE_MANAGER_SERVICE_EVENT_FOR_ASYNC_H_ + diff --git a/inc/FSys_DeviceManagerStub.h b/inc/FSys_DeviceManagerStub.h new file mode 100644 index 0000000..1ca9665 --- /dev/null +++ b/inc/FSys_DeviceManagerStub.h @@ -0,0 +1,88 @@ +// +// Open Service Platform +// 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_DeviceManagerStub.h + * @brief This is the header file of the _DeviceManagerStub class. + * + * This header file contains the declarations of the _DeviceManagerStub class. + */ + +#ifndef _FSYS_DEVICE_MANAGER_STUB_H_ +#define _FSYS_DEVICE_MANAGER_STUB_H_ + +#include +#include +#include +#include +#include "FApp_IAppEventListener.h" +#include "FSys_DeviceManagerServiceIpcEventForAsync.h" + +namespace Tizen { namespace System +{ + +class _IDeviceManager; + +class _OSP_EXPORT_ _DeviceManagerStub + : public Tizen::Base::Object + , public Tizen::Io::_IIpcServerEventListener + , public Tizen::System::IDeviceEventListener + , public Tizen::App::_IAppEventListener +{ +public: + static _DeviceManagerStub* CreateInstanceN(void); + + virtual ~_DeviceManagerStub(void); + result SendData(const int pid, Tizen::Base::Collection::ArrayList* data); + virtual void OnDeviceStateChanged (DeviceType deviceType, const Tizen::Base::String &state); +private: + _DeviceManagerStub(void); + result Construct(void); + + _DeviceManagerStub(const _DeviceManagerStub& rhs); + _DeviceManagerStub& operator =(const _DeviceManagerStub& rhs); + + void AddInterestedApp(int pid); + void RemoveInterestedApp(int pid); + + bool OnRequestOccured(const Tizen::Base::Collection::ArrayList& request, Tizen::Base::Collection::ArrayList* response); + + virtual void OnIpcServerStarted(const Tizen::Io::_IpcServer& server); + virtual void OnIpcServerStopped(const Tizen::Io::_IpcServer& server); + virtual void OnIpcClientConnected(const Tizen::Io::_IpcServer& server, int clientId); + virtual void OnIpcClientDisconnected(const Tizen::Io::_IpcServer&server, int clientId); + virtual void OnIpcRequestReceived(Tizen::Io::_IpcServer& server, const IPC::Message& message); + + virtual void OnApplicationLaunched(const Tizen::App::AppId& appId, int pid); + virtual void OnApplicationTerminated(const Tizen::App::AppId& appId, int pid); + +private: + std::unique_ptr __pIpcServer; + static _DeviceManagerStub* __pDeviceManagerStub; + Tizen::Base::Runtime::Mutex __Mutex; + Tizen::App::AppId __currentPkgId; + int __currentPid; + + void* __pSystemServiceDllHandle; + _IDeviceManager* __pIDeviceManager; + Tizen::Base::Collection::ArrayList __interestedPidList; + static _DeviceManagerServiceIpcEventForAsync* __pDeviceManagerServiceIpcEventForAsync; +}; // _DeviceManagerStub + +}} // Tizen::System + +#endif // _FSYS_DEVICE_MANAGER_STUB_H_ diff --git a/inc/FSys_IDeviceManager.h b/inc/FSys_IDeviceManager.h new file mode 100644 index 0000000..139d502 --- /dev/null +++ b/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/CommonService.cpp b/src/CommonService.cpp index 3929809..92c8f0d 100644 --- a/src/CommonService.cpp +++ b/src/CommonService.cpp @@ -17,6 +17,8 @@ #include #include "CommonService.h" + +#include "FSys_DeviceManagerStub.h" #include "FApp_PackageManagerStub.h" #include "FUi_UiManagerStub.h" @@ -28,6 +30,7 @@ using namespace Tizen::Ui; CommonService::CommonService(void) : __pPackageManagerStub(null) + , __pDeviceManagerStub(null) { } @@ -35,6 +38,7 @@ CommonService::CommonService(void) CommonService::~CommonService(void) { delete __pPackageManagerStub; + delete __pDeviceManagerStub; } ServiceApp* @@ -119,4 +123,7 @@ CommonService::InitializeServices(void) SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "Propagating."); __pUiManagerStub = move(pUiManagerStub); + + __pDeviceManagerStub = _DeviceManagerStub::CreateInstanceN(); + SysTryReturnVoidResult(NID_UI, __pDeviceManagerStub, r, "[%s] Propagating.", GetErrorMessage(r)); } diff --git a/src/FSys_DeviceManagerServiceIpcEventForAsync.cpp b/src/FSys_DeviceManagerServiceIpcEventForAsync.cpp new file mode 100644 index 0000000..51f730e --- /dev/null +++ b/src/FSys_DeviceManagerServiceIpcEventForAsync.cpp @@ -0,0 +1,69 @@ +// +// 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_DeviceManagerServiceIpcEventForAsync.cpp + * @brief This is the header file for the %_DeviceManagerServiceIpcEventForAsync class. + * + * This header file contains the declarations of the %_DeviceManagerServiceIpcEventForAsync class. + */ + +#include +#include "FSys_DeviceManagerServiceIpcEventForAsync.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Base::Runtime; +using namespace Tizen::Io; + +namespace Tizen{ namespace System { + +_DeviceManagerServiceIpcEventForAsync::_DeviceManagerServiceIpcEventForAsync(_IpcServer *pIpcServer) +{ + __pIpcServer = pIpcServer; +} + +result +_DeviceManagerServiceIpcEventForAsync::Construct(long stackSize, ThreadPriority priority) +{ + return EventDrivenThread::Construct(stackSize, priority); +} + +bool +_DeviceManagerServiceIpcEventForAsync::OnStart(void) +{ + return true; +} + +void +_DeviceManagerServiceIpcEventForAsync::OnStop(void) +{ +} + +void +_DeviceManagerServiceIpcEventForAsync::OnUserEventReceivedN(RequestId requestId, IList *pArgs) +{ + if(pArgs != null) + { + ArrayList* data = (ArrayList*)pArgs; + result r = __pIpcServer->SendResponse((int)requestId, new (std::nothrow) IoService_Data(*data)); + delete pArgs; + SysTryReturnVoidResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, + "It is failed to send IPC message to %d. [%s]", (int)requestId, GetErrorMessage(r)); + } +} + +}} diff --git a/src/FSys_DeviceManagerStub.cpp b/src/FSys_DeviceManagerStub.cpp new file mode 100644 index 0000000..7cd0e9d --- /dev/null +++ b/src/FSys_DeviceManagerStub.cpp @@ -0,0 +1,372 @@ +// +// Open Service Platform +// 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_DeviceManagerStub.cpp + * @brief This is the implementation for the _DeviceManagerStub class. + */ +#include +#include +#include +#include +#include + +#include "FApp_AppManagerImpl.h" +#include "FSys_IDeviceManager.h" +#include "FSys_DeviceManagerStub.h" + +using namespace std; +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Io; +using namespace Tizen::System; +using namespace Tizen::App; + +const static wchar_t* DEVICE_MANAGER_SERVICE_ID = L"osp.sys.ipcserver.devicemanager"; +const static wchar_t* DEVIVE_MANAGER_SERVICE_MUTEX_ID = L"osp.sys.ipcserver.devicemanager"; +const static wchar_t* DEVICE_MANAGER_COMMAND_OPEN = L"osp.devicemanager.command.open"; +const static wchar_t* DEVICE_MANAGER_COMMAND_CLOSE = L"osp.devicemanager.command.close"; +const static wchar_t* DEVICE_MANAGER_COMMAND_STATUS= L"osp.devicemanager.command.status"; +const static wchar_t* DEVICE_MANAGER_COMMAND_EVENT = L"osp.devicemanager.command.event"; +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"; + +_DeviceManagerServiceIpcEventForAsync* _DeviceManagerStub::__pDeviceManagerServiceIpcEventForAsync = null; +_DeviceManagerStub* _DeviceManagerStub::__pDeviceManagerStub = null; + +_DeviceManagerStub::_DeviceManagerStub(void) + : __pSystemServiceDllHandle(null) + , __pIpcServer(null) + , __pIDeviceManager(null) +{ + result r = E_SUCCESS; + r = __Mutex.Create(DEVIVE_MANAGER_SERVICE_MUTEX_ID); + SysTryReturn(NID_SYS, r == E_SUCCESS, , r, "It is failed to create mutex. [%s] Propaged.", r); + r = __interestedPidList.Construct(); + SysTryReturn(NID_SYS, r == E_SUCCESS, , r, "It is failed to initiate bluetooth headset application list."); +} + +_DeviceManagerStub::~_DeviceManagerStub(void) +{ + if (__pIpcServer) + { + __pIpcServer->Stop(); + } + + if (__pSystemServiceDllHandle) + { + dlclose(__pSystemServiceDllHandle); + } + + if (__pDeviceManagerServiceIpcEventForAsync) + { + delete __pDeviceManagerServiceIpcEventForAsync; + } + __interestedPidList.RemoveAll(); + result r = __Mutex.Release(); + SysTryReturn(NID_SYS, r == E_SUCCESS, , r, "It is failed to release mutex. [%s] Propaged.", r); +} + +_DeviceManagerStub* +_DeviceManagerStub::CreateInstanceN() +{ + if (__pDeviceManagerStub == null) + { + __pDeviceManagerStub = new (std::nothrow) _DeviceManagerStub(); + result r = __pDeviceManagerStub->Construct(); + SysTryReturn(NID_SYS, !IsFailed(r), null, r, "[%s] It is failed to get DeviceManagerCommunicationStub.", GetErrorMessage(r)); + } + return __pDeviceManagerStub; +} + +result +_DeviceManagerStub::Construct(void) +{ + unique_ptr<_IpcServer> pIpcServer(new (std::nothrow) _IpcServer()); + SysTryReturnResult(NID_SYS, pIpcServer, E_OUT_OF_MEMORY, "Memory is insufficient."); + + result r = pIpcServer->Construct(String(DEVICE_MANAGER_SERVICE_ID), *this, true); + SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to construct."); + + r = pIpcServer->Start(); + SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to start."); + + __pIpcServer = move(pIpcServer); + + __pSystemServiceDllHandle = dlopen("libosp-system-server.so", RTLD_LAZY); + + if (!__pSystemServiceDllHandle) + { + SysLog(NID_SYS, "It is failed to load system service (%s).", dlerror()); + return E_SYSTEM; + } + + _IDeviceManager* (*pFnDeviceManager_CreateInstance)(void) = null; + pFnDeviceManager_CreateInstance = reinterpret_cast< _IDeviceManager* (*)(void) >(dlsym(__pSystemServiceDllHandle, "DeviceManager_CreateInstance")); + SysTryReturn(NID_SYS, pFnDeviceManager_CreateInstance, E_SYSTEM, E_SYSTEM, "It is failed to find DeviceManager_CreateInstance."); + + __pIDeviceManager = pFnDeviceManager_CreateInstance(); + SysTryReturn(NID_SYS, __pIDeviceManager, E_SYSTEM, E_SYSTEM,"It is failed to create DeviceManager instance."); + + r = __pIDeviceManager->InitializeDevice(); + SysTryReturn(NID_SYS, !IsFailed(r), E_SYSTEM, E_SYSTEM, "It is failed to init device"); + return E_SUCCESS; +} + + + +result +_DeviceManagerStub::SendData(const int pid, Tizen::Base::Collection::ArrayList* data) +{ + result r = E_SUCCESS; + + SysTryCatch(NID_SYS, __pIpcServer != null, r = E_SYSTEM, E_SYSTEM, "IPC server is not ready."); + SysTryCatch(NID_SYS, data != null, r = E_SYSTEM, E_SYSTEM, "There is no data."); + + if(__pDeviceManagerServiceIpcEventForAsync == null) + { + __pDeviceManagerServiceIpcEventForAsync = new (std::nothrow) _DeviceManagerServiceIpcEventForAsync(__pIpcServer.get()); + __pDeviceManagerServiceIpcEventForAsync->Construct(1048576, Tizen::Base::Runtime::THREAD_PRIORITY_MID); + __pDeviceManagerServiceIpcEventForAsync->Start(); + } + SysTryCatch(NID_SYS, __pDeviceManagerServiceIpcEventForAsync != null, r = E_SYSTEM, E_SYSTEM, "Event thread is not ready."); + + r = __pDeviceManagerServiceIpcEventForAsync->SendUserEvent((RequestId)pid, (IList*)data); + SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "Message is failed to add on event thread."); + +CATCH: + if(r != E_SUCCESS) + { + delete data; + } + + return r; +} + +void +_DeviceManagerStub::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 (__interestedPidList.GetCount() == 0) + { + __pIDeviceManager->RegisterListner(*this); + _AppManagerImpl* pAppManagerImpl = Tizen::App::_AppManagerImpl::GetInstance(); + pAppManagerImpl->AddAppEventListener(*this); + } + + std::unique_ptr< Integer > pPid(new (std::nothrow) Integer(pid)); + SysTryReturnVoidResult(NID_SYS, pPid, E_OUT_OF_MEMORY, "It is not enough memory."); + + result r = __interestedPidList.Add(pPid.get()); + SysTryReturnVoidResult(NID_SYS, !IsFailed(r), r, "It is failed to add pid"); + pPid.release(); +} + + +void +_DeviceManagerStub::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) + { + __pIDeviceManager->DeinitializeDevice(); + __pIDeviceManager->UnregisterListner(*this); + _AppManagerImpl* pAppManagerImpl = Tizen::App::_AppManagerImpl::GetInstance(); + pAppManagerImpl->RemoveAppEventListener(*this); + } +} + + +void +_DeviceManagerStub::OnDeviceStateChanged (DeviceType deviceType, const Tizen::Base::String &state) +{ + 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(state)); + + SendData(pPid->value, data); + SysLog(NID_SYS, "Bluetooth headset event is sent to %d [%ls].", pPid->value, state.GetPointer()); + } + } + } + else + { + SysLog(NID_SYS, "Bluetooth Headset Event is not required by any application."); + } +} + +void +_DeviceManagerStub::OnIpcRequestReceived(_IpcServer& server, const IPC::Message& message) +{ + SysLog(NID_SYS, "Recevied"); + __Mutex.Acquire(); + __currentPkgId = server.GetClientPackageId(); + __currentPid = server.GetClientId(); + IPC_BEGIN_MESSAGE_MAP(_DeviceManagerStub, message) + IPC_MESSAGE_HANDLER_EX(IoService_Request, &server, OnRequestOccured) + IPC_END_MESSAGE_MAP_EX() + __Mutex.Release(); +} + +bool +_DeviceManagerStub::OnRequestOccured(const ArrayList& request, ArrayList* response) +{ + SysLog(NID_SYS, "OnRequestOccured"); + + StringComparer strComparer; + int cmp = 0; + result r = E_SUCCESS; + bool isSuccess = false; + String* command = null; + String* device = 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, String(DEVICE_MANAGER_COMMAND_OPEN), cmp); + if(cmp == 0) + { + strComparer.Compare(*device, String(DEVICE_MANAGER_BLUETOOTH), cmp); + if(cmp == 0) + { + SysLog(NID_SYS, "Bluetooth headset event is required"); + AddInterestedApp(__currentPid); + } + } + + strComparer.Compare(*command, String(DEVICE_MANAGER_COMMAND_CLOSE), cmp); + if(cmp == 0) + { + strComparer.Compare(*device, String(DEVICE_MANAGER_BLUETOOTH), cmp); + if(cmp == 0) + { + RemoveInterestedApp(__currentPid); + } + } + strComparer.Compare(*command, String(DEVICE_MANAGER_COMMAND_STATUS), cmp); + if(cmp == 0) + { + strComparer.Compare(*device, String(DEVICE_MANAGER_BLUETOOTH), cmp); + if(cmp == 0) + { + bool isBluetoothHeadSetConnected = __pIDeviceManager->GetBluetoothStatus(); + 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); + } + } + } + + isSuccess = true; +CATCH: + ArrayList* temp = const_cast(&request); + temp->RemoveAll(true); + return isSuccess; +} +void +_DeviceManagerStub::OnIpcServerStarted(const _IpcServer& server) +{ + SysLog(NID_SYS, "Started"); +} + +void +_DeviceManagerStub::OnIpcServerStopped(const _IpcServer& server) +{ + SysLog(NID_SYS, "Stop"); +} + +void +_DeviceManagerStub::OnIpcClientConnected(const _IpcServer& server, int clientId) +{ + SysLog(NID_SYS, "Connected"); +} + +void +_DeviceManagerStub::OnIpcClientDisconnected(const _IpcServer&server, int clientId) +{ + SysLog(NID_SYS, "Disconnected"); +} + +void +_DeviceManagerStub::OnApplicationLaunched(const AppId& appId, int pid) +{ + //dummy +} +void +_DeviceManagerStub::OnApplicationTerminated(const AppId& appId, int pid) +{ + RemoveInterestedApp(pid); +} -- 2.7.4