2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FSys_AccessoryManagerService.cpp
20 * @brief This is the implementation file for _AccessoryManagerService class.
24 #include <FBaseSysLog.h>
25 #include <FBaseRtLibrary.h>
27 #include "FSys_AccessoryManagerService.h"
28 #include "FApp_CommunicationDispatcher.h"
30 using namespace Tizen::App;
31 using namespace Tizen::Io;
32 using namespace Tizen::System;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Base::Runtime;
38 const String ACCESSORY_MANAGER_SERVICE_ID = L"osp.accessorymanager.service";
39 const String ACCESSORY_PLUGIN_LIBRARY_PATH = L"/opt/apps/aospd00043/lib/libosp-cond-accessory.so";
42 typedef result (*SendDataFunction)(Tizen::App::AppId appId, Tizen::Base::Collection::ArrayList* data);
43 typedef void (*RegisterSendDataFunction)(SendDataFunction function);
45 _AccessoryManagerService* gpAccessoryManagerService = null;
48 SendDataFunc(AppId appId, ArrayList* data)
50 SysLog(NID_SYS, "Request to send data");
51 SysTryReturnResult(NID_SYS, gpAccessoryManagerService != null, E_SYSTEM, "AccessoryManagerService is not ready");
52 return gpAccessoryManagerService->SendData(appId, data);
55 _AccessoryManagerService*
56 _AccessoryManagerService::GetInstance()
58 if(gpAccessoryManagerService == null)
60 gpAccessoryManagerService = new (std::nothrow) _AccessoryManagerService();
62 return gpAccessoryManagerService;
65 _AccessoryManagerService::_AccessoryManagerService()
66 : _ICommunicationRequestListener()
68 , __pCommunicationDispatcher(null)
69 , __pOnRequestOccuredFunction(null)
70 , __pRemoveOwnerApplicationFunction(null)
73 RegisterSendDataFunction pRegisterSendDataFunction;
75 __pCommunicationDispatcher = _CommunicationDispatcher::GetInstance();
76 SysTryCatch(NID_SYS, __pCommunicationDispatcher != null, r = E_SYSTEM, E_SYSTEM, "Failed to get _CommunicationDispatcher");
78 r = __pCommunicationDispatcher->AddCommunicationEventListener(*this);
79 SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "Failed to add event listener on _CommunicationDispatcher");
81 __pLib = new Library();
82 r = __pLib->Construct(ACCESSORY_PLUGIN_LIBRARY_PATH);
83 SysTryCatch(NID_APP, !IsFailed(r),, r, "dlopen fails (%s)", GetErrorMessage(r));
85 pRegisterSendDataFunction = (RegisterSendDataFunction)__pLib->GetProcAddress(L"RegisterSendData");
86 SysTryCatch(NID_APP, pRegisterSendDataFunction != null, r = E_SYSTEM, E_SYSTEM, "Failed to find RegisterSendDataFunction");
88 __pOnRequestOccuredFunction = (OnRequestOccuredFunction)__pLib->GetProcAddress(L"OnRequestOccured");
89 SysTryCatch(NID_APP, __pOnRequestOccuredFunction != null, r = E_SYSTEM, E_SYSTEM, "Failed to find OnRequestOccuredFunction");
91 __pRemoveOwnerApplicationFunction = (RemoveOwnerApplicationFunction)__pLib->GetProcAddress(L"RemoveOwnerApplication");
92 SysTryCatch(NID_APP, __pRemoveOwnerApplicationFunction != null, r = E_SYSTEM, E_SYSTEM, "Failed to find OnRequestOccuredFunction");
94 pRegisterSendDataFunction(SendDataFunc);
100 _AccessoryManagerService::~_AccessoryManagerService()
102 result r = E_SUCCESS;
104 SysTryCatch(NID_SYS, __pCommunicationDispatcher != null, r = E_SYSTEM, E_SYSTEM, "_CommunicationDispatcher is not initiated.");
106 r = __pCommunicationDispatcher->RemoveCommunicationEventListener(*this);
107 SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "Failed to remove event listener on _CommunicationDispatcher");
115 _AccessoryManagerService::SendData(AppId appId, ArrayList* data)
117 SysTryReturnResult(NID_SYS, __pCommunicationDispatcher != null, E_SYSTEM, "_CommunicationDispatcher is not initiated.");
119 return __pCommunicationDispatcher->SendData(appId, *data);
123 _AccessoryManagerService::GetId(void)
125 return ACCESSORY_MANAGER_SERVICE_ID;
129 _AccessoryManagerService::OnRequestOccured(AppId appId, ArrayList* request, ArrayList* response)
131 result r = E_SUCCESS;
132 SysTryCatch(NID_SYS, __pOnRequestOccuredFunction != null, r = E_SYSTEM, E_SYSTEM, "There is no OnRequestOccuredFunction");
134 SysLog(NID_SYS, "AppId is [%ls]", appId.GetPointer());
135 __pOnRequestOccuredFunction(appId, request, response);
142 _AccessoryManagerService::OnApplicationTerminated(const AppId& appId, _AppType type)
144 result r = E_SUCCESS;
145 SysTryCatch(NID_SYS, __pRemoveOwnerApplicationFunction != null, r = E_SYSTEM, E_SYSTEM, "There is no RemoveOwnerApplicationFunction");
147 __pRemoveOwnerApplicationFunction(appId, L"");