'bluetooth_health_profile_handler.h',
'bluetooth_instance.cc',
'bluetooth_instance.h',
+ 'bluetooth_privilege.cc',
'bluetooth_privilege.h',
'bluetooth_service_handler.cc',
'bluetooth_service_handler.h',
void BluetoothAdapter::SetName(const picojson::value& data, picojson::object& out) {
LoggerD("Entered");
- util::CheckAccess(Privilege::kBluetoothAdmin);
+ CHECK_PRIVILEGE_ACCESS(Privilege::kBluetoothAdmin, &out);
const auto callback_handle = util::GetAsyncCallbackHandle(data);
const auto& args = util::GetArguments(data);
void BluetoothAdapter::SetPowered(const picojson::value& data, picojson::object& out) {
LoggerD("Entered");
- util::CheckAccess(Privilege::kBluetoothAdmin);
+ CHECK_PRIVILEGE_ACCESS(Privilege::kBluetoothAdmin, &out);
const auto callback_handle = util::GetAsyncCallbackHandle(data);
const auto& args = util::GetArguments(data);
void BluetoothAdapter::SetVisible(const picojson::value& data, picojson::object& out) {
LoggerD("Entered");
- util::CheckAccess(Privilege::kBluetoothManager);
+ CHECK_PRIVILEGE_ACCESS(Privilege::kBluetoothManager, &out);
const auto callback_handle = util::GetAsyncCallbackHandle(data);
const auto& args = util::GetArguments(data);
void BluetoothAdapter::DiscoverDevices(const picojson::value& /* data */, picojson::object& out) {
LoggerD("Entered");
- util::CheckAccess(Privilege::kBluetoothGap);
+ CHECK_PRIVILEGE_ACCESS(Privilege::kBluetoothGap, &out);
PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
void BluetoothAdapter::StopDiscovery(const picojson::value& data, picojson::object& out) {
LoggerD("Entered");
- util::CheckAccess(Privilege::kBluetoothGap);
+ CHECK_PRIVILEGE_ACCESS(Privilege::kBluetoothGap, &out);
const auto callback_handle = util::GetAsyncCallbackHandle(data);
void BluetoothAdapter::GetKnownDevices(const picojson::value& data, picojson::object& out) {
LoggerD("Entered");
- util::CheckAccess(Privilege::kBluetoothGap);
+ CHECK_PRIVILEGE_ACCESS(Privilege::kBluetoothGap, &out);
const auto callback_handle = util::GetAsyncCallbackHandle(data);
void BluetoothAdapter::GetDevice(const picojson::value& data, picojson::object& out) {
LoggerD("Entered");
- util::CheckAccess(Privilege::kBluetoothGap);
+ CHECK_PRIVILEGE_ACCESS(Privilege::kBluetoothGap, &out);
const auto callback_handle = util::GetAsyncCallbackHandle(data);
const auto& args = util::GetArguments(data);
void BluetoothAdapter::CreateBonding(const picojson::value& data, picojson::object& out) {
LoggerD("Entered");
- util::CheckAccess(Privilege::kBluetoothGap);
+ CHECK_PRIVILEGE_ACCESS(Privilege::kBluetoothGap, &out);
const auto callback_handle = util::GetAsyncCallbackHandle(data);
const auto& args = util::GetArguments(data);
{
LoggerD("Entered");
- util::CheckAccess(Privilege::kBluetoothGap);
+ CHECK_PRIVILEGE_ACCESS(Privilege::kBluetoothGap, &out);
const auto callback_handle = util::GetAsyncCallbackHandle(data);
const auto& args = util::GetArguments(data);
void BluetoothAdapter::RegisterRFCOMMServiceByUUID(const picojson::value& data, picojson::object& out) {
LoggerD("Entered");
- util::CheckAccess(Privilege::kBluetoothSpp);
+ CHECK_PRIVILEGE_ACCESS(Privilege::kBluetoothSpp, &out);
const auto callback_handle = util::GetAsyncCallbackHandle(data);
const auto& args = util::GetArguments(data);
BluetoothClass.prototype.hasService = function() {
console.log('Entered BluetoothClass.hasService()');
- var result = native.callSync('Bluetooth_checkPrivilege', {privilege : _PRIVILEGE_BLUETOOTH_GAP});
+ xwalk.utils.checkPrivilegeAccess(_PRIVILEGE_BLUETOOTH_GAP);
- if (native.isFailure(result)) {
- throw native.getErrorObject(result);
- } else {
- var args = AV.validateMethod(arguments, [
- {
- name : 'service',
- type : AV.Types.UNSIGNED_LONG
- }
- ]);
+ var args = AV.validateMethod(arguments, [
+ {
+ name : 'service',
+ type : AV.Types.UNSIGNED_LONG
+ }
+ ]);
- var size = this.services.length;
- for (var i = 0; i < size; i++) {
- if (this.services[i] === args.service) {
- return true;
- }
+ var size = this.services.length;
+ for (var i = 0; i < size; i++) {
+ if (this.services[i] === args.service) {
+ return true;
}
- return false;
}
+ return false;
};
// class BluetoothSocket ////////////////////////////////////////////////////
}
]);
- var result = native.callSync('Bluetooth_checkPrivilege', {privilege : _PRIVILEGE_BLUETOOTH_HEALTH});
+ xwalk.utils.checkPrivilegeAccess(_PRIVILEGE_BLUETOOTH_HEALTH);
- if (native.isFailure(result)) {
- throw native.getErrorObject(result);
- } else {
- if (T.isEmptyObject(_healthListeners)) {
- native.addListener('BluetoothHealthChannelChangeCallback',
- _BluetoothHealthChannelChangeCallback);
- }
- _healthListeners[this._id] = args.changeCallback;
+ if (T.isEmptyObject(_healthListeners)) {
+ native.addListener('BluetoothHealthChannelChangeCallback',
+ _BluetoothHealthChannelChangeCallback);
}
+ _healthListeners[this._id] = args.changeCallback;
};
BluetoothHealthChannel.prototype.unsetListener = function() {
console.log('Entered BluetoothHealthChannel.unsetListener ()');
- var result = native.callSync('Bluetooth_checkPrivilege', {privilege : _PRIVILEGE_BLUETOOTH_HEALTH});
+ xwalk.utils.checkPrivilegeAccess(_PRIVILEGE_BLUETOOTH_HEALTH);
- if (native.isFailure(result)) {
- throw native.getErrorObject(result);
- } else {
- delete _healthListeners[this._id];
+ delete _healthListeners[this._id];
- if (T.isEmptyObject(_healthListeners)) {
- native.removeListener('BluetoothHealthChannelChangeCallback',
- _BluetoothHealthChannelChangeCallback);
- }
+ if (T.isEmptyObject(_healthListeners)) {
+ native.removeListener('BluetoothHealthChannelChangeCallback',
+ _BluetoothHealthChannelChangeCallback);
}
};
BluetoothManager.prototype.getDefaultAdapter = function() {
console.log('Entered BluetoothManager.getDefaultAdapter()');
- var result = native.callSync('Bluetooth_checkPrivilege', {privilege : _PRIVILEGE_BLUETOOTH_GAP});
+ xwalk.utils.checkPrivilegeAccess(_PRIVILEGE_BLUETOOTH_GAP);
- if (native.isFailure(result)) {
- throw native.getErrorObject(result);
- } else {
- return new BluetoothAdapter();
- }
+ return new BluetoothAdapter();
};
// exports ///////////////////////////////////////////////////////////////////
void BluetoothDevice::ConnectToServiceByUUID(const picojson::value& data, picojson::object& out) {
LoggerD("Entered");
- util::CheckAccess(Privilege::kBluetoothSpp);
+ CHECK_PRIVILEGE_ACCESS(Privilege::kBluetoothSpp, &out);
const auto& args = util::GetArguments(data);
void BluetoothHealthApplication::Unregister(const picojson::value& data, picojson::object& out) {
LoggerD("Entered");
- util::CheckAccess(Privilege::kBluetoothHealth);
+ CHECK_PRIVILEGE_ACCESS(Privilege::kBluetoothHealth, &out);
const auto& args = util::GetArguments(data);
void BluetoothHealthChannel::Close(const picojson::value& data , picojson::object& out) {
LoggerD("Entered");
- util::CheckAccess(Privilege::kBluetoothHealth);
+ CHECK_PRIVILEGE_ACCESS(Privilege::kBluetoothHealth, &out);
const auto& args = util::GetArguments(data);
void BluetoothHealthChannel::SendData(const picojson::value& data, picojson::object& out) {
LoggerD("Entered");
- util::CheckAccess(Privilege::kBluetoothHealth);
+ CHECK_PRIVILEGE_ACCESS(Privilege::kBluetoothHealth, &out);
const auto& args = util::GetArguments(data);
void BluetoothHealthProfileHandler::RegisterSinkApp(const picojson::value& data, picojson::object& out) {
LoggerD("Entered");
- util::CheckAccess(Privilege::kBluetoothHealth);
+ CHECK_PRIVILEGE_ACCESS(Privilege::kBluetoothHealth, &out);
const auto& args = util::GetArguments(data);
const auto data_type = static_cast<short>(FromJson<double>(args, "dataType"));
void BluetoothHealthProfileHandler::ConnectToSource(const picojson::value& data, picojson::object& out) {
LoggerD("Entered");
- util::CheckAccess(Privilege::kBluetoothHealth);
+ CHECK_PRIVILEGE_ACCESS(Privilege::kBluetoothHealth, &out);
const auto& args = util::GetArguments(data);
const auto& address = FromJson<std::string>(args, "address");
BluetoothServiceHandler bluetooth_service_handler;
BluetoothSocket bluetooth_socket;
-void CheckPrivilege(const picojson::value& data, picojson::object& out)
-{
- const auto& args = util::GetArguments(data);
- const auto& privilege = FromJson<std::string>(args, "privilege");
- util::CheckAccess(privilege);
-
- tools::ReportSuccess(out);
-}
-
} // namespace
BluetoothInstance& BluetoothInstance::GetInstance()
REGISTER_SYNC("BluetoothSocket_close",
std::bind(&BluetoothSocket::Close, &bluetooth_socket, _1, _2));
- // other
- REGISTER_SYNC("Bluetooth_checkPrivilege", CheckPrivilege);
-
#undef REGISTER_ASYNC
#undef REGISTER_SYNC
}
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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.
+ */
+
+#include "bluetooth_privilege.h"
+
+namespace extension {
+namespace bluetooth {
+
+namespace Privilege {
+const std::string kBluetoothAdmin = "http://tizen.org/privilege/bluetooth.admin";
+const std::string kBluetoothManager = "http://tizen.org/privilege/bluetoothmanager";
+const std::string kBluetoothGap = "http://tizen.org/privilege/bluetooth.gap";
+const std::string kBluetoothSpp = "http://tizen.org/privilege/bluetooth.spp";
+const std::string kBluetoothHealth = "http://tizen.org/privilege/bluetooth.health";
+} // namespace Privilege
+
+} // namespace bluetooth
+} // namespace extension
namespace bluetooth {
namespace Privilege {
-const std::string kBluetoothAdmin = "http://tizen.org/privilege/bluetooth.admin";
-const std::string kBluetoothManager = "http://tizen.org/privilege/bluetoothmanager";
-const std::string kBluetoothGap = "http://tizen.org/privilege/bluetooth.gap";
-const std::string kBluetoothSpp = "http://tizen.org/privilege/bluetooth.spp";
-const std::string kBluetoothHealth = "http://tizen.org/privilege/bluetooth.health";
+
+extern const std::string kBluetoothAdmin;
+extern const std::string kBluetoothManager;
+extern const std::string kBluetoothGap;
+extern const std::string kBluetoothSpp;
+extern const std::string kBluetoothHealth;
+
} // namespace Privilege
} // namespace bluetooth
void BluetoothServiceHandler::Unregister(const picojson::value& data, picojson::object& out) {
LoggerD("Entered");
- util::CheckAccess(Privilege::kBluetoothSpp);
+ CHECK_PRIVILEGE_ACCESS(Privilege::kBluetoothSpp, &out);
const auto& args = util::GetArguments(data);
void BluetoothSocket::WriteData(const picojson::value& data, picojson::object& out) {
LoggerD("Enter");
- util::CheckAccess(Privilege::kBluetoothSpp);
+ CHECK_PRIVILEGE_ACCESS(Privilege::kBluetoothSpp, &out);
const auto& args = util::GetArguments(data);
void BluetoothSocket::ReadData(const picojson::value& data, picojson::object& out) {
LoggerD("Enter");
- util::CheckAccess(Privilege::kBluetoothSpp);
+ CHECK_PRIVILEGE_ACCESS(Privilege::kBluetoothSpp, &out);
const auto& args = util::GetArguments(data);
void BluetoothSocket::Close(const picojson::value& data, picojson::object& out) {
LoggerD("Enter");
- util::CheckAccess(Privilege::kBluetoothSpp);
+ CHECK_PRIVILEGE_ACCESS(Privilege::kBluetoothSpp, &out);
const auto& args = util::GetArguments(data);
const char* JSON_DATA = "args";
} // namespace
-
-void CheckAccess(const std::string& privilege) {
- // TODO: check access to privilege, throw exception on failure
-}
-
void AsyncResponse(double callback_handle, const std::shared_ptr<picojson::value>& response) {
common::TaskQueue::GetInstance().Async<picojson::value>([callback_handle](const std::shared_ptr<picojson::value>& response) {
SyncResponse(callback_handle, response);
namespace bluetooth {
namespace util {
-void CheckAccess(const std::string& privilege);
-
void AsyncResponse(double callback_handle, const std::shared_ptr<picojson::value>& response);
void AsyncResponse(double callback_handle, const common::PlatformResult& result);
void SyncResponse(double callback_handle, const std::shared_ptr<picojson::value>& response);