// // Open Service Platform // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. // // Licensed under the Apache License, Version 2.0 (the License); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // /** * @file FNetBt_BluetoothHdpSystemAdapter.h * @brief This is the header file for the _BluetoothHdpSystemAdapter class. * * This header file contains the declaration of the _BluetoothHdpSystemAdapter class. */ #ifndef _FNET_BT_INTERNAL_BLUETOOTH_HDP_SYSTEM_ADAPTER_H_ #define _FNET_BT_INTERNAL_BLUETOOTH_HDP_SYSTEM_ADAPTER_H_ #include #include #include #include // forward declarations namespace Tizen { namespace Base { class ByteBuffer; namespace Collection { template class HashMapT; } } } namespace Tizen { namespace Net { namespace Bluetooth { // Forward declarations class BluetoothDevice; class _BluetoothHealthImpl; /** * @class _BluetoothHdpSystemAdapter * @brief This class provides functions related to HDP (Health Device Profile) and have a role of adaptation OSP classes and * the underlying subsystem. This class is a type of singleton, therefore only one instance should be allowed. */ class _BluetoothHdpSystemAdapter : public Tizen::Base::Object { public: /** * Creates an instance of this class if there is no instance in this application context. * Gets the exist instance because this class is a singleton, otherwise. * * @return the instance of this class */ static _BluetoothHdpSystemAdapter* GetInstance(void); /** * Create and initialize a sink service, and start to listen the health events. @n * An instance of _BluetoothHealthImpl class is registered internally. * * @return An error code * @param[in] dataType The type of data used in communication, refer to ISO/IEEE 11073-20601 for data types * @param[in] implListener The instance of _BluetoothHealthImpl to be registered in map * @param[out] pAppId The application ID * @exception E_SUCCESS The method is successful. * @exception E_SERVICE_UNAVAILABLE The HDP service with the specified data type is unavailable. * @exception E_OPERATION_FAILED The method has failed. */ result StartSinkService(int dataType, _BluetoothHealthImpl& implListener, char** pAppId); /** * Close the specified sink service. @n * * @return An error code * @param[in] pAppId The application ID * @exception E_SUCCESS The method is successful. * @exception E_OPERATION_FAILED The method has failed. */ result StopService(const char* pAppId); /** * Sets up a new connection (channel) with a remote health device which has source role. @n * * @return An error code * @param[in] sourceAddress The address of the source device * @param[in] pAppId The application ID * @exception E_SUCCESS The method is successful. * @exception E_OPERATION_FAILED The method has failed. */ result ConnectToSource(const Tizen::Base::ByteBuffer& sourceAddress, const char* pAppId); /** * Close the connection with the remote HDP source device. * * @return An error code * @param[in] channelId The ID of the specified channel to be disconnected * @exception E_SUCCESS The method is successful. * @exception E_OPERATION_FAILED The method has failed. */ result Disconnect(int channelId); /** * Sends the specified data on the specified HDP channel. * * @return An error code * @param[in] channelId The ID of the specified channel to send data on * @param[in] data The health data to be sent over the connected channel * @exception E_SUCCESS The method is successful. * @exception E_OPERATION_FAILED The method has failed. */ result SendData(int channelId, const Tizen::Base::ByteBuffer& buffer); //----------------------------------------------------------------------------------------------------------------- // Callback methods for the HDP events //----------------------------------------------------------------------------------------------------------------- /** * Callback called by the underlying system to notify that an HDP connection is established. */ static void OnHdpConnected(int status, const char* pRemoteAddress, const char* appId, bt_hdp_channel_type_e channelType, unsigned int channelId, void* pUserData); /** * Callback called by the underlying system to notify that the specific HDP connection is disconnected. */ static void OnHdpDisconnected(int status, const char* pRemoteAddress, unsigned int channelId, void* pUserData); /** * Callback used by the underlying system to notify that data is received on the established HDP connection. */ static void OnHdpDataReceived(unsigned int channelId, const char* pData, unsigned int dataSize, void* pUserData); private: _BluetoothHdpSystemAdapter(void); ~_BluetoothHdpSystemAdapter(void); _BluetoothHdpSystemAdapter(const _BluetoothHdpSystemAdapter& value); _BluetoothHdpSystemAdapter& operator =(const _BluetoothHdpSystemAdapter& value); bool Construct(void); static void InitSingleton(void); static void DeinitializeSingleton(void); private: // hash map of HDP applications and the _BluetoothHealthImpl std::unique_ptr > __pAppHealthMap; // hash map of HDP channel Ids and the _BluetoothHealthImpl std::unique_ptr > __pChannelHealthMap; // hash map of HDP channel Ids and the connected device address std::unique_ptr > __pChannelAddressMap; static _BluetoothHdpSystemAdapter* __pInstance; friend class std::default_delete<_BluetoothHdpSystemAdapter>; }; // _BluetoothHdpSystemAdapter } } } #endif // _FNET_BT_INTERNAL_BLUETOOTH_HDP_SYSTEM_ADAPTER_H_