2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <JavaScriptCore/JavaScript.h>
18 #include <dpl/log/log.h>
19 #include <dpl/shared_ptr.h>
20 #include <CommonsJavaScript/PrivateObject.h>
21 #include <CommonsJavaScript/JSCallbackManager.h>
22 #include <CommonsJavaScript/Converter.h>
23 #include <Commons/IEvent.h>
24 #include <Tizen/Common/JSTizenExceptionFactory.h>
25 #include <Tizen/Common/JSTizenException.h>
26 #include "BluetoothDeviceManagerListener.h"
27 #include "JSBluetoothSocket.h"
29 using namespace TizenApis::Commons;
34 BluetoothDeviceManagerListener::~BluetoothDeviceManagerListener()
38 BluetoothDeviceManagerListener::BluetoothDeviceManagerListener() :
39 EventBTConnectedAnswerReceiver(ThreadEnum::NULL_THREAD)
45 BluetoothDeviceManagerListener& BluetoothDeviceManagerListener::getInstance()
47 static BluetoothDeviceManagerListener instance;
51 void BluetoothDeviceManagerListener::OnAnswerReceived(const EventBTConnectToServiceByUUIDPtr& event)
54 JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager > (event->getPrivateData());
56 if (event->getExceptionCode() == ExceptionCodes::None)
58 BluetoothSocketData socketData = event->getSocketData();
59 socketData = event->getSocketData();
60 JSObjectRef adapterObject = JSBluetoothSocket::createJSObject(callbackManager->getContext(), socketData);
61 callbackManager->callOnSuccess(adapterObject);
66 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(callbackManager->getContext(),
67 JSTizenException::UNKNOWN_ERROR, "unknown error"));