update the header for Doxygen
[platform/framework/native/bluetooth.git] / src / FNetBt_BluetoothHdpSystemAdapter.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 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  * @file    FNetBt_BluetoothHdpSystemAdapter.h
19  * @brief   This is the header file for the _BluetoothHdpSystemAdapter class.
20  *
21  * This header file contains the declaration of the _BluetoothHdpSystemAdapter class.
22  */
23 #ifndef _FNET_BT_INTERNAL_BLUETOOTH_HDP_SYSTEM_ADAPTER_H_
24 #define _FNET_BT_INTERNAL_BLUETOOTH_HDP_SYSTEM_ADAPTER_H_
25
26 #include <unique_ptr.h>
27 #include <bluetooth.h>
28 #include <FBaseObject.h>
29 #include <FBaseResult.h>
30
31 // forward declarations
32 namespace Tizen { namespace Base {
33 class ByteBuffer;
34
35 namespace Collection {
36 template<class keyType, class valueType> class HashMapT;
37 }
38 } }
39
40 namespace Tizen { namespace Net { namespace Bluetooth
41 {
42
43 // Forward declarations
44 class BluetoothDevice;
45 class _BluetoothHealthImpl;
46
47 /**
48  * @class   _BluetoothHdpSystemAdapter
49  * @brief   This class provides functions related to HDP (Health Device Profile) and have a role of adaptation OSP classes and
50  *                      the underlying subsystem. This class is a type of singleton, therefore only one instance should be allowed.
51  */
52 class _BluetoothHdpSystemAdapter
53         : public Tizen::Base::Object
54 {
55 public:
56         /**
57          * Creates an instance of this class if there is no instance in this application context.
58          * Gets the exist instance because this class is a singleton, otherwise.
59          *
60          * @return      the instance of this class
61          */
62         static _BluetoothHdpSystemAdapter* GetInstance(void);
63
64         /**
65          * Create and initialize a sink service, and start to listen the health events. @n
66          * An instance of _BluetoothHealthImpl class is registered internally.
67          *
68          * @return      An error code
69          * @param[in]   dataType                The type of data used in communication, refer to ISO/IEEE 11073-20601 for data types
70          * @param[in]   implListener            The instance of _BluetoothHealthImpl to be registered in map
71          * @param[out]  pAppId                  The application ID
72          * @exception   E_SUCCESS               The method is successful.
73          * @exception   E_SERVICE_UNAVAILABLE   The HDP service with the specified data type is unavailable.
74          * @exception   E_OPERATION_FAILED      The method has failed.
75          */
76         result StartSinkService(int dataType, _BluetoothHealthImpl& implListener, char** pAppId);
77
78         /**
79          * Close the specified sink service. @n
80          *
81          * @return      An error code
82          * @param[in]   pAppId                          The application ID
83          * @exception   E_SUCCESS               The method is successful.
84          * @exception   E_OPERATION_FAILED      The method has failed.
85          */
86         result StopService(const char* pAppId);
87
88         /**
89          * Sets up a new connection (channel) with a remote health device which has source role. @n
90          *
91          * @return      An error code
92          * @param[in]   sourceAddress           The address of the source device
93          * @param[in]   pAppId                          The application ID
94          * @exception   E_SUCCESS               The method is successful.
95          * @exception   E_OPERATION_FAILED      The method has failed.
96          */
97         result ConnectToSource(const Tizen::Base::ByteBuffer& sourceAddress, const char* pAppId);
98
99         /**
100          * Close the connection with the remote HDP source device.
101          *
102          * @return      An error code
103          * @param[in]   channelId               The ID of the specified channel to be disconnected
104          * @exception   E_SUCCESS               The method is successful.
105          * @exception   E_OPERATION_FAILED      The method has failed.
106          */
107         result Disconnect(int channelId);
108
109         /**
110          * Sends the specified data on the specified HDP channel.
111          *
112          * @return      An error code
113          * @param[in]   channelId               The ID of the specified channel to send data on
114          * @param[in]   data                    The health data to be sent over the connected channel
115          * @exception   E_SUCCESS               The method is successful.
116          * @exception   E_OPERATION_FAILED      The method has failed.
117          */
118         result SendData(int channelId, const Tizen::Base::ByteBuffer& buffer);
119
120
121         //-----------------------------------------------------------------------------------------------------------------
122         // Callback methods for the HDP events
123         //-----------------------------------------------------------------------------------------------------------------
124
125         /**
126          * Callback called by the underlying system to notify that an HDP connection is established.
127          */
128         static void OnHdpConnected(int status, const char* pRemoteAddress, const char* appId, bt_hdp_channel_type_e channelType,
129                         unsigned int channelId, void* pUserData);
130
131         /**
132          * Callback called by the underlying system to notify that the specific HDP connection is disconnected.
133          */
134         static void OnHdpDisconnected(int status, const char* pRemoteAddress, unsigned int channelId, void* pUserData);
135
136         /**
137          * Callback used by the underlying system to notify that data is received on the established HDP connection.
138          */
139         static void OnHdpDataReceived(unsigned int channelId, const char* pData, unsigned int dataSize, void* pUserData);
140
141 private:
142         _BluetoothHdpSystemAdapter(void);
143         ~_BluetoothHdpSystemAdapter(void);
144
145         _BluetoothHdpSystemAdapter(const _BluetoothHdpSystemAdapter& value);
146         _BluetoothHdpSystemAdapter& operator =(const _BluetoothHdpSystemAdapter& value);
147
148         bool Construct(void);
149
150         static void InitSingleton(void);
151
152 private:
153         // hash map of HDP applications and the _BluetoothHealthImpl
154         std::unique_ptr<Tizen::Base::Collection::HashMapT< Tizen::Base::String, _BluetoothHealthImpl*> > __pAppHealthMap;
155         // hash map of HDP channel Ids and the _BluetoothHealthImpl
156         std::unique_ptr<Tizen::Base::Collection::HashMapT< int, _BluetoothHealthImpl*> > __pChannelHealthMap;
157         // hash map of HDP channel Ids and the connected device address
158         std::unique_ptr<Tizen::Base::Collection::HashMapT< int, Tizen::Base::String> > __pChannelAddressMap;
159         static _BluetoothHdpSystemAdapter* __pInstance;
160
161 }; // _BluetoothHdpSystemAdapter
162
163 } } }
164 #endif // _FNET_BT_INTERNAL_BLUETOOTH_HDP_SYSTEM_ADAPTER_H_