tizen 2.3.1 release
[framework/web/wearable/wrt-plugins-tizen.git] / src / Bluetooth / BluetoothGATTCharacteristic.h
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 #ifndef __TIZEN_JS_BLUETOOTH_LOW_ENERGY_GATT_CHARACTERISTIC_H__
18 #define __TIZEN_JS_BLUETOOTH_LOW_ENERGY_GATT_CHARACTERISTIC_H__
19
20 #include <bluetooth.h>
21 #include <memory>
22 #include "BluetoothGATTBase.h"
23 #include "BluetoothGattClientWrapper.h"
24 #include <vector>
25 #include <map>
26 #include <PropertyBag.h>
27 #include <JavaScriptCore/JavaScript.h>
28
29 namespace DeviceAPI {
30 namespace Common {
31     class MultiCallbackUserData;
32 }
33
34 namespace Bluetooth {
35
36 class BluetoothGATTCharacteristic : public BluetoothGATTBase {
37 public:
38     BluetoothGATTCharacteristic(const BluetoothGattClientWrapper &wrapper,
39         bt_gatt_h _handler, JSContextRef context);
40     JSValueRef getIsBroadCast(JSContextRef context);
41     JSValueRef getIsHasExtended(JSContextRef context);
42     JSValueRef getIsNotify(JSContextRef context);
43     JSValueRef getIsIndie(JSContextRef context);
44     JSValueRef getIsRead(JSContextRef context);
45     JSValueRef getIsSignedWrite(JSContextRef context);
46     JSValueRef getIsWrite(JSContextRef context);
47     JSValueRef getIsWriteNoResponse(JSContextRef context);
48     JSValueRef getDescriptors(JSContextRef context);
49
50     long addValueChangeListener(std::shared_ptr<Common::MultiCallbackUserData> _pCallback);
51     void removeValueChangeListener(long _id);
52
53     virtual ~BluetoothGATTCharacteristic();
54 private:
55     BluetoothGattClientWrapper m_wrapper;
56     Common::PropertyBag m_localProperty;
57     void setProperty( int _propertyBits, const char* _propertyName,
58         bt_gatt_property_e _property, JSContextRef _ctx);
59
60     static bool descriptorsNativeCallback(int total, int index, bt_gatt_h gatt_handle,
61                         void *user_data);
62     static void onCharacteristicChangeNativeCallback(bt_gatt_h characteristic,
63                 char *value, int len, void *user_data);
64
65     std::vector<BluetoothGATTBasePtr> m_descriptors;
66     std::map<int, std::shared_ptr<Common::MultiCallbackUserData>> m_pCallbacks;
67
68     static int m_listenerId;
69 };
70
71 typedef std::shared_ptr<BluetoothGATTCharacteristic> BluetoothGATTCharacteristicPtr;
72
73 } // namespace Bluetooth
74 } // namespace DeviceAPI
75
76 #endif /* SRC_BLUETOOTH_BLUETOOTHGATTCHARACTERISTC_H_ */