// // 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_BluetoothGapSystemAdapter.h * @brief This is the header file for the _BluetoothGapSystemAdapter class. * * This header file contains the declaration of the _BluetoothGapSystemAdapter class. */ #ifndef _FNET_BT_INTERNAL_BLUETOOTH_GAP_SYSTEM_ADAPTER_H_ #define _FNET_BT_INTERNAL_BLUETOOTH_GAP_SYSTEM_ADAPTER_H_ #include #include #include #include #include #include static const int _BT_ADDRESS_LENGTH = 6; // forward declarations namespace Tizen { namespace Base { namespace Collection { class IList; } } } namespace Tizen { namespace Net { namespace Bluetooth { // forward declarations class BluetoothDevice; class _IBluetoothDeviceEventListener; class _IBluetoothManagerEventListener; class _BluetoothIpcProxy; /** * @class _BluetoothGapSystemAdapter * @brief This class provides functions related to deliver the system events to the listeners such as * _BluetoothManagerImpl. This class is a type of singleton, therefore only one instance should be allowed. */ class _BluetoothGapSystemAdapter : 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 _BluetoothGapSystemAdapter* GetInstance(void); /** * Register an instance of _IBluetoothManagerEventListener interface into the internal list. * * @return An error code * @param[in] listener The instance of _IBluetoothManagerEventListener to be registered * @param[in] isHighPriority Set to @c true to register with the high priority, @n * else @c false * @exception E_SUCCESS The method is successful. * @exception E_OUT_OF_MEMORY The memory is insufficient. */ result RegisterManagerEventListener(const _IBluetoothManagerEventListener& listener, bool isHighPriority); /** * Unregister an instance of _IBluetoothManagerEventListener interface from the internal list. * * @return An error code * @param[in] listener The instance of _IBluetoothManagerEventListener to be unregistered * @exception E_SUCCESS The method is successful. * @exception E_OBJ_NOT_FOUND The input instance is not registered. */ result UnregisterManagerEventListener(const _IBluetoothManagerEventListener& listener); /** * Register an instance of _IBluetoothDeviceEventListener interface into the internal list. * * @return An error code * @param[in] listener The instance of _IBluetoothDeviceEventListener to be registered * @exception E_SUCCESS The method is successful. * @exception E_OUT_OF_MEMORY The memory is insufficient. */ result RegisterDeviceEventListener(const _IBluetoothDeviceEventListener& listener); /** * Unregister an instance of _IBluetoothDeviceEventListener interface from the internal list. * * @return An error code * @param[in] listener The instance of _IBluetoothDeviceEventListener to be unregistered * @exception E_SUCCESS The method is successful. * @exception E_OBJ_NOT_FOUND The input instance is not registered. */ result UnregisterDeviceEventListener(const _IBluetoothDeviceEventListener& listener); /** * Activates %Bluetooth module. * * @return An error code * @exception E_SUCCESS The method is successful. * @exception E_FAILURE The method failed. */ result Activate(void); /** * Deactivates %Bluetooth module. * * @return An error code * @exception E_SUCCESS The method is successful. * @exception E_FAILURE The method failed. */ result Deactivate(void); /** * Checks whether the %Bluetooth is activated or not. * * @return @c true, if activated @n * @c false, otherwise */ bool IsActivated(void) const; /** * Checks if the Bluetooth-specific profile is available. * * @return @c true if connection is available @n * @c false, otherwise * @param[in] type The connection type to check availability */ bool IsAvailable(BluetoothConnectionType type) const; /** * Gets the local %Bluetooth device address. * * @return The local %Bluetooth device address */ Tizen::Base::String GetLocalDeviceAddress(void) const; /** * Gets the discoverable mode of the local device. * * @return The discoverable mode of the local device */ BluetoothDiscoverableMode GetDiscoverableMode(void) const; /** * Gets the remaining time, in seconds, until the local device is not discoverable. * * @return The remaining time, in seconds, until the local device to be not discoverable. */ int GetRemainingTimeAsDiscoverable(void) const; /** * Gets all Paired Device list. * * @return Pointer to the paired device list on success @n * @c null, otherwise. * @remarks It is caller's responsibility that deletes the result list. */ Tizen::Base::Collection::IList* GetAllPairedDeviceListN(void) const; /** * Pairs(Bonds) with the specified remote device. * * @return An error code * @param[in] deviceAddress The address of a remote device to pair with * @exception E_SUCCESS The method is successful. * @exception E_SYSTEM A system error occurred. */ result Pair(const Tizen::Base::ByteBuffer& deviceAddress); /** * Cancels the pairing in progress. * * @return An error code * @exception E_SUCCESS The method is successful. * @exception E_SYSTEM A system error occurred. */ result CancelPair(void); /** * Unpairs(Unbonds) with the specified paired device. * * @return An error code * @param[in] deviceAddress The address of the paired device to unpair with * @exception E_SUCCESS The method is successful. * @exception E_SYSTEM A system error occurred. */ result Unpair(const Tizen::Base::ByteBuffer& deviceAddress); /** * Checks if this device is paired with the specified remote device. * * @return @c true if the device is paired @n * @c false, otherwise * @param[in] deviceAddress The address of a remote device to check * @exception E_SUCCESS The method is successful. * @exception E_SYSTEM A system error occurred. */ bool IsPaired(const Tizen::Base::ByteBuffer& deviceAddress) const; /** * Starts a device discovery process. * * @return An error code * @exception E_SUCCESS The method is successful. * @exception E_SYSTEM A system error occurred. */ result StartDiscovery(void); /** * Stops the discovery in progress. * * @return An error code * @exception E_SUCCESS The method is successful. * @exception E_SYSTEM A system error occurred. */ result CancelDiscovery(void); /** * Checks whether the device discovery is in progress or not. * * @return @c true, if in progress @n * @c false, otherwise */ bool IsDiscoveryInProgress(void) const; /** * Retrieves the service list from a remote device. * * @return An error code * @param[in] deviceAddress The address of a remote device which the service list is retrieved from * @exception E_SUCCESS The method is successful. * @exception E_SYSTEM A system error occurred. */ result RetrieveServiceList(const Tizen::Base::ByteBuffer& deviceAddress); /** * Gets the information of the specified paired device. * * @return An error code * @param[in] address The address of a paired device * @param[out] pairedDevice The remote device instance whose information to be filled in * @exception E_SUCCESS The method is successful. * @exception E_SYSTEM A system error occurred. */ static result GetPairedDevice(const Tizen::Base::ByteBuffer& address, BluetoothDevice& pairedDevice); /** * Callback to notify the change in the state of Bluetooth adapter. */ static void OnAdapterStateChanged(int status, bt_adapter_state_e adapterState, void* pUserdata); /** * Callback to notify the change in the visibility mode of Bluetooth adapter. */ static void OnVisibilityModeChanged(int result, bt_adapter_visibility_mode_e mode, void* pUserdata); /** * Callback to notify when you get bonded devices repeatedly. */ static bool OnPairedDeviceFound(bt_device_info_s* pDeviceInfo, void* pUserdata); /** * Callback to notify when the state of the device discovery changes. */ static void OnDeviceDiscoveryStateChanged(int status, bt_adapter_device_discovery_state_e discoveryState, bt_adapter_device_discovery_info_s* pDiscoveryInfo, void* pUserdata); /** * Callback to notify when the process of service discovery is completed. */ static void OnServiceDiscoveryCompleted(int status, bt_device_sdp_info_s* pSdpInfo, void* pUserdata); /** * Callback to notify that a new remote device is paired with this local device. */ static void OnPairingCompleted(int status, bt_device_info_s* pDeviceInfo, void* pUserdata); /** * Callback to notify that the already paired device is unpaired with this local device. */ static void OnPairedDeviceRemoved(int status, char* pRemoteAddress, void* pUserdata); /** * Callback to notify when the state of the device connection changes. */ static void OnConnectionStateChanged(bool isConnected, const char* pRemoteAddress, void* pUserdata); private: _BluetoothGapSystemAdapter(void); ~_BluetoothGapSystemAdapter(void); _BluetoothGapSystemAdapter(const _BluetoothGapSystemAdapter& value); _BluetoothGapSystemAdapter& operator =(const _BluetoothGapSystemAdapter& value); bool Construct(void); static void InitSingleton(void); static void DeinitializeSingleton(void); private: Tizen::Base::Collection::LinkedListT<_IBluetoothManagerEventListener*> __mgrEvtListenerList; Tizen::Base::Collection::LinkedListT<_IBluetoothDeviceEventListener*> __devEvtListenerList; static _BluetoothGapSystemAdapter* __pInstance; friend class std::default_delete<_BluetoothGapSystemAdapter>; }; // _BluetoothGapSystemAdapter } } } #endif // _FNET_BT_INTERNAL_BLUETOOTH_GAP_SYSTEM_ADAPTER_H_