Beta merge 2
[profile/ivi/wrt-plugins-tizen.git] / src / standards / Tizen / Bluetooth / BluetoothDeviceManagerListener.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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. 
15  */
16
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"
28
29 using namespace TizenApis::Commons;
30
31 namespace TizenApis {
32 namespace Tizen1_0 {
33
34 BluetoothDeviceManagerListener::~BluetoothDeviceManagerListener() 
35 {
36         LogDebug("entered");
37 }
38 BluetoothDeviceManagerListener::BluetoothDeviceManagerListener() :
39         EventBTConnectedAnswerReceiver(ThreadEnum::NULL_THREAD)
40 {
41         LogDebug("entered");
42 }
43
44
45 BluetoothDeviceManagerListener& BluetoothDeviceManagerListener::getInstance()
46 {
47         static BluetoothDeviceManagerListener instance;
48         return instance;
49 }
50
51 void BluetoothDeviceManagerListener::OnAnswerReceived(const EventBTConnectToServiceByUUIDPtr& event)
52 {
53         LogDebug("Enter");
54         JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager > (event->getPrivateData());
55
56         if (event->getExceptionCode() == ExceptionCodes::None)
57         {
58                 BluetoothSocketData socketData = event->getSocketData();
59                 socketData = event->getSocketData();
60                 JSObjectRef adapterObject = JSBluetoothSocket::createJSObject(callbackManager->getContext(), socketData);
61                 callbackManager->callOnSuccess(adapterObject);
62         }
63         else
64         {
65         
66                 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(callbackManager->getContext(), 
67                         JSTizenException::UNKNOWN_ERROR, "unknown error"));
68         }
69 }
70
71 }
72 }
73