wrt-plugins-tizen_0.4.23
[framework/web/wrt-plugins-tizen.git] / src / Bluetooth / BluetoothClassDeviceService.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
20 #include "BluetoothClassDeviceService.h"
21
22 #include <Logger.h>
23
24 namespace DeviceAPI {
25 namespace Bluetooth {
26
27 BluetoothClassDeviceService::BluetoothClassDeviceService()
28 {
29     LoggerD("Enter");
30     
31     mServiceStringMap.insert(std::pair<std::string, unsigned long>("LIMITED_DISCOVERABILITY", 0x0001));
32     mServiceStringMap.insert(std::pair<std::string, unsigned long>("POSITIONING", 0x0008)); 
33     mServiceStringMap.insert(std::pair<std::string, unsigned long>("NETWORKING", 0x0010)); 
34     mServiceStringMap.insert(std::pair<std::string, unsigned long>("RENDERING", 0x0020)); 
35     mServiceStringMap.insert(std::pair<std::string, unsigned long>("CAPTURING", 0x0040));
36     mServiceStringMap.insert(std::pair<std::string, unsigned long>("OBJECT_TRANSFER", 0x0080)); 
37     mServiceStringMap.insert(std::pair<std::string, unsigned long>("AUDIO", 0x0100));
38     mServiceStringMap.insert(std::pair<std::string, unsigned long>("TELEPHONY", 0x0200));
39     mServiceStringMap.insert(std::pair<std::string, unsigned long>("INFORMATION", 0x0400));
40
41     mServiceEnumMap.insert(std::pair<bt_major_service_class_e, unsigned long>(BT_MAJOR_SERVICE_CLASS_LIMITED_DISCOVERABLE_MODE, 0x0001));
42     mServiceEnumMap.insert(std::pair<bt_major_service_class_e, unsigned long>(BT_MAJOR_SERVICE_CLASS_POSITIONING, 0x0008));
43     mServiceEnumMap.insert(std::pair<bt_major_service_class_e, unsigned long>(BT_MAJOR_SERVICE_CLASS_NETWORKING, 0x0010));
44     mServiceEnumMap.insert(std::pair<bt_major_service_class_e, unsigned long>(BT_MAJOR_SERVICE_CLASS_RENDERING, 0x0020));
45     mServiceEnumMap.insert(std::pair<bt_major_service_class_e, unsigned long>(BT_MAJOR_SERVICE_CLASS_CAPTURING, 0x0040));
46     mServiceEnumMap.insert(std::pair<bt_major_service_class_e, unsigned long>(BT_MAJOR_SERVICE_CLASS_OBJECT_TRANSFER, 0x0080));
47     mServiceEnumMap.insert(std::pair<bt_major_service_class_e, unsigned long>(BT_MAJOR_SERVICE_CLASS_AUDIO, 0x0100));
48     mServiceEnumMap.insert(std::pair<bt_major_service_class_e, unsigned long>(BT_MAJOR_SERVICE_CLASS_TELEPHONY, 0x0200));
49     mServiceEnumMap.insert(std::pair<bt_major_service_class_e, unsigned long>(BT_MAJOR_SERVICE_CLASS_INFORMATION, 0x0400));  
50 }
51
52 BluetoothClassDeviceService::~BluetoothClassDeviceService()
53 {
54     LoggerD("Enter");
55 }
56
57 BluetoothClassDeviceService* BluetoothClassDeviceService::getInstance()
58 {
59     LoggerD("Enter");
60     static BluetoothClassDeviceService instance;
61     return &instance;
62 }
63
64 unsigned long BluetoothClassDeviceService::getServiceValue(std::string service)
65 {
66     LoggerD("Enter");
67     return mServiceStringMap.find(service)->second;
68 }
69
70 unsigned long BluetoothClassDeviceService::getServiceValue(bt_major_service_class_e service)
71 {
72     LoggerD("Enter");
73     return mServiceEnumMap.find(service)->second;
74 }
75
76 std::vector<unsigned long> BluetoothClassDeviceService::getServiceValues(int serviceMask)
77 {
78     LoggerD("Enter");
79
80     std::vector<unsigned long> ret;
81     for(std::map<bt_major_service_class_e, unsigned long>::iterator iter = mServiceEnumMap.begin(); iter != mServiceEnumMap.end(); iter++) {
82         if(iter->first & serviceMask) {
83             ret.push_back(iter->second);
84         }
85     }
86
87     return ret;
88 }
89
90
91 } // Bluetooth
92 } // DeviceAPI