tizen 2.3.1 release
[framework/web/mobile/wrt-plugins-tizen.git] / src / Bluetooth / BluetoothLEAdvertiseData.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 "BluetoothLEAdvertiseData.h"
19 #include <Logger.h>
20 #include <JSUtil.h>
21 #include "plugin_config_impl.h"
22
23 namespace DeviceAPI {
24 namespace Bluetooth {
25
26 BluetoothLEAdvertiseData::BluetoothLEAdvertiseData() : m_includeName(false), m_includeTxPowerLevel(false) {
27     // TODO Auto-generated constructor stub
28     m_serviceData = new BluetoothLEServiceData();
29     m_manufacturerData = new BluetoothLEManufacturerData();
30 }
31
32 BluetoothLEAdvertiseData::~BluetoothLEAdvertiseData() {
33     // TODO Auto-generated destructor stub
34 }
35
36 void BluetoothLEAdvertiseData::setName(const bool includeName)
37 {
38     m_includeName = includeName;
39 }
40
41 bool BluetoothLEAdvertiseData::getName() const
42 {
43     return m_includeName;
44 }
45
46 void BluetoothLEAdvertiseData::setServiceUuids(
47     const std::vector<std::string> &uuids)
48 {
49     m_uuids = uuids;
50 }
51
52 std::vector<std::string> BluetoothLEAdvertiseData::getServiceUuids() const
53 {
54     return m_uuids;
55 }
56
57 void BluetoothLEAdvertiseData::setSolicitationUuids(
58     const std::vector<std::string> &solicitationeuuids)
59 {
60     m_solicitationeuuids = solicitationeuuids;
61 }
62
63 std::vector<std::string> BluetoothLEAdvertiseData::getSolicitationUuids() const
64 {
65     return m_solicitationeuuids;
66 }
67
68 void BluetoothLEAdvertiseData::setAppearance(const unsigned long appearance)
69 {
70     m_appearance = appearance;
71 }
72
73 unsigned long BluetoothLEAdvertiseData::getAppearance() const
74 {
75     return m_appearance;
76 }
77
78 void BluetoothLEAdvertiseData::setTxPowerLevel(const bool includeTxPowerLevel)
79 {
80     m_includeTxPowerLevel = includeTxPowerLevel;
81 }
82
83 bool BluetoothLEAdvertiseData::getTxPowerLevel() const
84 {
85     return m_includeTxPowerLevel;
86 }
87
88 BluetoothLEServiceData* BluetoothLEAdvertiseData::getServiceData() const
89 {
90     return m_serviceData;
91 }
92
93 void BluetoothLEAdvertiseData::setServiceData(BluetoothLEServiceData* serviceData)
94 {
95     m_serviceData = serviceData;
96 }
97
98 JSValueRef BluetoothLEAdvertiseData::getServiceDataJSValueRef(JSContextRef ctx) const {
99     LOGD("Entered");
100     JSObjectRef jsobject = JSObjectMake(ctx, NULL, NULL );
101     if (!m_serviceData) {
102         LOGD("m_serviceData is null");
103         return jsobject;
104     }
105     Common::JSUtil::setProperty(ctx , jsobject, BLUETOOTH_LE_SERVICE_DATA_UUID,
106         Common::JSUtil::toJSValueRef(ctx, m_serviceData->getUuid()), kJSPropertyAttributeNone, NULL);
107     Common::JSUtil::setProperty(ctx , jsobject, BLUETOOTH_LE_SERVICE_DATA_DATA,
108         Common::JSUtil::toJSValueRef(ctx, m_serviceData->getData()), kJSPropertyAttributeNone, NULL);
109     return jsobject;
110 }
111
112 void BluetoothLEAdvertiseData::setManufacturerData(BluetoothLEManufacturerData* manufacturerData)
113 {
114     m_manufacturerData = manufacturerData;
115 }
116
117 BluetoothLEManufacturerData* BluetoothLEAdvertiseData::getManufacturerData() const
118 {
119     return m_manufacturerData;
120 }
121
122 JSValueRef BluetoothLEAdvertiseData::getManufacturerJSValueRef(JSContextRef ctx) const {
123     LOGD("Entered");
124     JSObjectRef jsobject = JSObjectMake(ctx, NULL, NULL );
125     if (!m_manufacturerData) {
126         LOGD("m_manufacturerData is null");
127         return jsobject;
128     }
129     Common::JSUtil::setProperty(ctx , jsobject, BLUETOOTH_LE_MANUFACTURER_DATA_ID,
130         Common::JSUtil::toJSValueRef(ctx, m_manufacturerData->getId()), kJSPropertyAttributeNone, NULL);
131     Common::JSUtil::setProperty(ctx , jsobject, BLUETOOTH_LE_MANUFACTURER_DATA_DATA,
132         Common::JSUtil::toJSValueRef(ctx, m_manufacturerData->getData()), kJSPropertyAttributeNone, NULL);
133     return jsobject;
134 }
135
136 void BluetoothLEAdvertiseData::setAppearanceNull(bool value) {
137     m_appearance_null = value;
138 }
139
140 bool BluetoothLEAdvertiseData::getAppearanceNull() {
141     return m_appearance_null;
142 }
143
144 void BluetoothLEAdvertiseData::setUuidsNull(bool value) {
145     m_uuids_null = value;
146 }
147
148 bool BluetoothLEAdvertiseData::getUuidsNull() {
149     return m_uuids_null;
150 }
151
152 void BluetoothLEAdvertiseData::setSolicitationUuidsNull(bool value) {
153     m_solicitationuuids_null = value;
154 }
155
156 bool BluetoothLEAdvertiseData::getSolicitationUuidsNull() {
157     return m_solicitationuuids_null;
158 }
159
160 void BluetoothLEAdvertiseData::setServiceDataNull(bool value) {
161     m_serviceData_null = value;
162 }
163
164 bool BluetoothLEAdvertiseData::getServiceDataNull() {
165     return m_serviceData_null;
166 }
167
168 void BluetoothLEAdvertiseData::setManufacturerDataNull(bool value) {
169     m_manufacturerData_null = value;
170 }
171
172 bool BluetoothLEAdvertiseData::getManufacturerDataNull() {
173     return m_manufacturerData_null;
174 }
175
176 } // namespace Bluetooth
177 } // namespace DeviceAPI
178