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 "BluetoothSocketListener.h"
27 #include "BluetoothMultiCallback.h"
28 #include "JSBluetoothSocket.h"
30 using namespace TizenApis::Commons;
35 BluetoothSocketListener::~BluetoothSocketListener()
39 BluetoothSocketListener::BluetoothSocketListener() :
40 EventBTSocketNotificationListener(ThreadEnum::NULL_THREAD)
46 BluetoothSocketListener& BluetoothSocketListener::getInstance()
48 static BluetoothSocketListener instance;
53 void BluetoothSocketListener::onAnswerReceived(const EventBTSocketNotificationPtr& event)
55 LogDebug("Enter-Socket notification");
57 BluetoothSocketNotifierPrivateDataPtr multiCallbacks =
58 DPL::DynamicPointerCast<BluetoothSocketNotifierPrivateData>(event->getPrivateData());
60 switch(event->getConnectionState())
62 case EventBTSocketNotification::DISCONNECTED:
63 multiCallbacks->getOnClose()->callOnSuccess();
65 case EventBTSocketNotification::DATARECEIVED:
67 EventBTReadDataType readData;
68 JSBluetoothSocketPriv *priv =
69 static_cast<JSBluetoothSocketPriv*>(JSObjectGetPrivate(multiCallbacks->getObject()));
70 IBluetoothSocketManagerPtr BluetoothSocketManager(priv->getObject());
72 readData = event->getReadData();
73 LogDebug("Size" << readData.size());
74 BluetoothSocketManager->setReadData(readData);
75 multiCallbacks->getOnMessage()->callOnSuccess();
78 case EventBTSocketNotification::SOCKETERROR:
80 multiCallbacks->getOnError()->callOnSuccess(JSTizenExceptionFactory::makeErrorObject(multiCallbacks->getOnError()->getContext(),
81 JSTizenException::UNKNOWN_ERROR, "unknown error"));