2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FNetBt_BluetoothHdpSystemAdapter.h
19 * @brief This is the header file for the _BluetoothHdpSystemAdapter class.
21 * This header file contains the declaration of the _BluetoothHdpSystemAdapter class.
23 #ifndef _FNET_BT_INTERNAL_BLUETOOTH_HDP_SYSTEM_ADAPTER_H_
24 #define _FNET_BT_INTERNAL_BLUETOOTH_HDP_SYSTEM_ADAPTER_H_
26 #include <unique_ptr.h>
27 #include <bluetooth.h>
28 #include <FBaseObject.h>
29 #include <FBaseResult.h>
31 // forward declarations
32 namespace Tizen { namespace Base {
35 namespace Collection {
36 template<class keyType, class valueType> class HashMapT;
40 namespace Tizen { namespace Net { namespace Bluetooth
43 // Forward declarations
44 class BluetoothDevice;
45 class _BluetoothHealthImpl;
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.
52 class _BluetoothHdpSystemAdapter
53 : public Tizen::Base::Object
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.
60 * @return the instance of this class
62 static _BluetoothHdpSystemAdapter* GetInstance(void);
65 * Create and initialize a sink service, and start to listen the health events. @n
66 * An instance of _BluetoothHealthImpl class is registered internally.
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.
76 result StartSinkService(int dataType, _BluetoothHealthImpl& implListener, char** pAppId);
79 * Close the specified sink service. @n
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.
86 result StopService(const char* pAppId);
89 * Sets up a new connection (channel) with a remote health device which has source role. @n
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.
97 result ConnectToSource(const Tizen::Base::ByteBuffer& sourceAddress, const char* pAppId);
100 * Close the connection with the remote HDP source device.
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.
107 result Disconnect(int channelId);
110 * Sends the specified data on the specified HDP channel.
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.
118 result SendData(int channelId, const Tizen::Base::ByteBuffer& buffer);
121 //-----------------------------------------------------------------------------------------------------------------
122 // Callback methods for the HDP events
123 //-----------------------------------------------------------------------------------------------------------------
126 * Callback called by the underlying system to notify that an HDP connection is established.
128 static void OnHdpConnected(int status, const char* pRemoteAddress, const char* appId, bt_hdp_channel_type_e channelType,
129 unsigned int channelId, void* pUserData);
132 * Callback called by the underlying system to notify that the specific HDP connection is disconnected.
134 static void OnHdpDisconnected(int status, const char* pRemoteAddress, unsigned int channelId, void* pUserData);
137 * Callback used by the underlying system to notify that data is received on the established HDP connection.
139 static void OnHdpDataReceived(unsigned int channelId, const char* pData, unsigned int dataSize, void* pUserData);
142 _BluetoothHdpSystemAdapter(void);
143 ~_BluetoothHdpSystemAdapter(void);
145 _BluetoothHdpSystemAdapter(const _BluetoothHdpSystemAdapter& value);
146 _BluetoothHdpSystemAdapter& operator =(const _BluetoothHdpSystemAdapter& value);
148 bool Construct(void);
150 static void InitSingleton(void);
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;
161 }; // _BluetoothHdpSystemAdapter
164 #endif // _FNET_BT_INTERNAL_BLUETOOTH_HDP_SYSTEM_ADAPTER_H_