wrt-plugins-tizen_0.4.23
[framework/web/wrt-plugins-tizen.git] / src / Bluetooth / BluetoothClass.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 #include <PlatformException.h>
19 #include <JSUtil.h>
20
21 #include "plugin_config.h"
22 #include "BluetoothClass.h"
23 #include "BluetoothClassDeviceMajor.h"
24 #include "BluetoothClassDeviceMinor.h"
25 #include "BluetoothClassDeviceService.h"
26 #include "JSBluetoothClassDeviceService.h"
27
28 #include <Logger.h>
29
30 using namespace DeviceAPI::Common;
31
32 namespace DeviceAPI {
33 namespace Bluetooth {
34
35 BluetoothClass::BluetoothClass(bt_class_s bluetoothClass)    
36 {
37     LoggerD("Enter");
38     mMajor = BluetoothClassDeviceMajor::getInstance()->getMajorValue(bluetoothClass.major_device_class);
39     mMinor = BluetoothClassDeviceMinor::getInstance()->getMinorValue(bluetoothClass.minor_device_class);
40     mServices= BluetoothClassDeviceService::getInstance()->getServiceValues(bluetoothClass.major_service_class_mask);
41 }
42
43 BluetoothClass::~BluetoothClass()
44 {
45     LoggerD("Enter");
46 }
47
48 unsigned long BluetoothClass::getMajor() const
49 {
50     LoggerD("Enter");
51     return mMajor;
52 }
53
54 unsigned long BluetoothClass::getMinor() const
55 {
56     LoggerD("Enter");
57     return mMinor;
58 }
59
60 JSValueRef BluetoothClass::getServices(JSContextRef context)
61 {
62     LoggerD("Enter");
63 /*   
64     JSValueRef service = mLocalProperty.getProperty(context, BLUETOOTH_CLASS_SERVICES);
65     if(service == NULL) {
66         service = JSUtil::toJSValueRef_(context, mServices);
67         mLocalProperty.setProperty(context, BLUETOOTH_CLASS_SERVICES, service);
68     }
69
70     return service;
71 */
72     return JSUtil::toJSValueRef_(context, mServices);
73 }
74
75 bool BluetoothClass::hasService(unsigned long service)
76 {
77     LoggerD("Enter");
78
79     for(std::vector<unsigned long>::iterator iter = mServices.begin(); iter != mServices.end(); ++iter) {
80         if((*iter) == service) {
81             return true;
82         }
83     }
84     return false;
85 }
86
87
88 } // Bluetooth
89 } // DeviceAPI