2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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 BluetoothAppControlDllEntry.cpp
20 * @brief This is the implementation for the BluetoothAppControlDllEntry.cpp class.
23 #include <appsvc/appsvc.h>
25 #include <FBaseSysLog.h>
26 #include <FBaseInteger.h>
27 #include <FBaseLong.h>
28 #include <FAppAppControl.h>
29 #include <FBaseColHashMap.h>
31 #include <FBase_StringConverter.h>
32 #include <FApp_AppControlManager.h>
33 #include <FApp_AppMessageImpl.h>
34 #include <FNetBt_BluetoothAdapterUtility.h>
35 #include <FSys_SystemInfoImpl.h>
39 using namespace Tizen::App;
40 using namespace Tizen::Base;
41 using namespace Tizen::Base::Collection;
42 using namespace Tizen::Net::Bluetooth;
50 result _OSP_EXPORT_ StartAppControl(int req, const String&, const String&, const String*, const String*, const IMap*);
51 result _OSP_EXPORT_ TerminateAppControl(int req);
52 void OnAppControlResult(void*, int, service_result_e, void*);
54 static int __req = -1;
55 static int __processId = -1;
57 static const wchar_t __allowedAppControlTable[][2][64] =
59 {L"osp.appcontrol.BT", L"osp.appcontrol.operation.PICK"},
60 {L"osp.appcontrol.provider.bluetooth", L"osp.appcontrol.operation.pick"},
61 {L"http://tizen.org/appcontrol/provider/bluetooth", L"http://tizen.org/appcontrol/operation/pick"},
62 {L"tizen.bluetooth", L"http://tizen.org/appcontrol/operation/pick"},
67 StartAppControl(int req, const String& aId, const String& oId, const String* pUri, const String* pMime, const IMap* pMap)
69 SysLog(NID_APP, "StartAppControl: Entry to Bluetooth AppControl");
72 bool isBtSupported = false;
75 r = Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/network.bluetooth", isBtSupported);
76 SysTryReturnResult(NID_APP, (r == E_SUCCESS) && (isBtSupported == true), E_SYSTEM, "[%s] Bluetooth is not supported.", GetErrorMessage(r));
78 const bool isAllowed = _AppControlManager::IsAllowedAppControl(__allowedAppControlTable, 4, aId, oId);
79 SysTryReturnResult(NID_APP, isAllowed, E_SYSTEM, "Invalid AppControl entry for (%ls, %ls).", aId.GetPointer(), oId.GetPointer());
81 SysLog(NID_APP, "Bluetooth AppControl.");
84 msg.AddData(L"launch-type", L"pick");
86 __processId = _AppControlManager::GetInstance()->Launch(msg, "ug-bluetooth-efl", APPSVC_OPERATION_PICK, NULL, NULL, OnAppControlResult, 0);
88 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Bluetooth AppControl is failed.");
89 SysLog(NID_APP, "StartAppControl: Launching Bluetooth AppControl succeeded.");
97 TerminateAppControl(int req)
101 _Aul::TerminateApplicationByPid(__processId);
107 OnAppControlResult(void* b, int requestCode, service_result_e res, void* userData)
110 bundle* pBundle = static_cast<bundle*>(b);
112 int majClassType = 0;
113 int minClassType = 0;
114 int svcClassType = 0;
115 unsigned long svcType = 0;
116 int result = SERVICE_RESULT_SUCCEEDED;
119 HashMap* pResult = new (std::nothrow) HashMap();
120 SysTryCatch(NID_APP, pResult != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
122 r = pResult->Construct();
124 pBuf = appsvc_get_data(pBundle, "result");
125 if (strcmp(pBuf, "success") == 0)
127 result = SERVICE_RESULT_SUCCEEDED;
131 result = SERVICE_RESULT_FAILED;
136 case SERVICE_RESULT_SUCCEEDED:
138 pBuf = appsvc_get_data(pBundle, "address");
141 pResult->Add(new (std::nothrow) String(L"http://tizen.org/appcontrol/data/bluetooth/address"), new (std::nothrow) String(pBuf));
144 pBuf = appsvc_get_data(pBundle, "name");
147 pResult->Add(new (std::nothrow) String(L"http://tizen.org/appcontrol/data/bluetooth/name"), new (std::nothrow) String(pBuf));
150 pBuf = appsvc_get_data(pBundle, "rssi");
153 pResult->Add(new (std::nothrow) String(L"http://tizen.org/appcontrol/data/bluetooth/rssi"), new (std::nothrow) String(pBuf));
156 pBuf = appsvc_get_data(pBundle, "is_bonded");
167 pResult->Add(new (std::nothrow) String(L"http://tizen.org/appcontrol/data/bluetooth/is_paired"), new (std::nothrow) String(pBuf));
170 pBuf = appsvc_get_data(pBundle, "major_class");
173 Integer::Decode(String(pBuf), majClassType);
174 majClassType = (int)_BluetoothAdapterUtility::ConvertToMajorDeviceClassType((bt_major_device_class_e)majClassType);
176 pResult->Add(new (std::nothrow) String(L"http://tizen.org/appcontrol/data/bluetooth/major_class"), new (std::nothrow) String(Integer::ToString(majClassType)));
179 pBuf = appsvc_get_data(pBundle, "minor_class");
182 Integer::Decode(String(pBuf), minClassType);
183 minClassType = (int)_BluetoothAdapterUtility::ConvertToMinorDeviceClassType((bt_major_device_class_e)majClassType, (bt_minor_device_class_e)minClassType);
185 pResult->Add(new (std::nothrow) String(L"http://tizen.org/appcontrol/data/bluetooth/minor_class"), new (std::nothrow) String(Integer::ToString(minClassType)));
188 pBuf = appsvc_get_data(pBundle, "service_class");
191 Integer::Decode(String(pBuf), svcClassType);
192 svcClassType = (int)_BluetoothAdapterUtility::ConvertToServiceClassList(svcClassType);
194 pResult->Add(new (std::nothrow) String(L"http://tizen.org/appcontrol/data/bluetooth/service_class"), new (std::nothrow) String(Integer::ToString(svcClassType)));
198 char** ppArrayBuf = (char**)appsvc_get_data_array(pBundle, "uuids", &len);
200 // TODO: Parsing routine for uuid_list should be added.
201 if (len > 0 && ppArrayBuf != null)
203 svcType = _BluetoothAdapterUtility::ConvertToServiceList(ppArrayBuf, len);
204 for (int i = 0; i < len; i++)
214 // TODO: the uuid_list value should be added to pResult.
215 pResult->Add(new (std::nothrow) String(L"http://tizen.org/appcontrol/data/bluetooth/service_type"), new (std::nothrow) String(Long::ToString(svcType)));
218 case SERVICE_RESULT_FAILED:
220 case SERVICE_RESULT_CANCELED:
226 _AppControlManager::GetInstance()->FinishAppControl(__req, result, pResult);