diff options
Diffstat (limited to 'src/FNetBt_BluetoothAdapterUtility.cpp')
-rwxr-xr-x | src/FNetBt_BluetoothAdapterUtility.cpp | 911 |
1 files changed, 911 insertions, 0 deletions
diff --git a/src/FNetBt_BluetoothAdapterUtility.cpp b/src/FNetBt_BluetoothAdapterUtility.cpp new file mode 100755 index 0000000..6a0f958 --- /dev/null +++ b/src/FNetBt_BluetoothAdapterUtility.cpp @@ -0,0 +1,911 @@ +// +// 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_BluetoothAdapterUtility.cpp +// @brief This is the implementation file for the _BluetoothAdapterUtility class. +// + +#include <unique_ptr.h> +#include <FBaseColAllElementsDeleter.h> +#include <FBaseByteBuffer.h> +#include <FBaseUuId.h> +#include <FBaseInteger.h> +#include <FBaseSysLog.h> +#include <FBaseLong.h> +#include <FBaseColHashMap.h> +#include <FBaseUtilStringUtil.h> +#include <FNetBtBluetoothDevice.h> +#include <FNetBtBluetoothTypes.h> +#include <FNetBtBluetoothDevice.h> +#include <FBase_StringConverter.h> +#include <FNetBt_BluetoothDeviceImpl.h> +#include "FNetBt_BluetoothAdapterUtility.h" + +using namespace std; +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Base::Utility; + + +namespace Tizen { namespace Net { namespace Bluetooth +{ +class _BluetoothUuidMap; + +static _BluetoothUuidMap* pMapSingleton = null; + +/* + * @class _BluetoothUuidMap + * @brief The _BluetoothUuidMap class provides the method which converts UUID string to the long type value of + * BluetoothServiceType defined "FNetBtBluetoothTypes.h". + */ +class _BluetoothUuidMap + : public Tizen::Base::Object +{ +public: + _BluetoothUuidMap(void) {} + + virtual ~_BluetoothUuidMap(void) + { + //Clear all entries in the map + (void) __uuidMap.RemoveAll(true); + } + + static _BluetoothUuidMap* GetInstance(void) + { + static _BluetoothUuidMap uuidMap; + + // TODO: this singleton pattern to use a local static instance is not thread-safe. + if (!pMapSingleton) + { + if (uuidMap.Initialise() == E_SUCCESS) + { + pMapSingleton = &uuidMap; + } + } + + return pMapSingleton; + } + + long GetUuidLong(const Tizen::Base::String& uuidString) const + { + UuId uuid; + UuId::Parse(uuidString, uuid); + const Long* pUuidLongValue = null; + + pUuidLongValue = dynamic_cast<const Long*> (__uuidMap.GetValue(uuid)); + SysTryReturn(NID_NET_BT, pUuidLongValue != null, 0, E_SYSTEM, + "Getting UUID(%ls) value from <UUID string, UUID enum type> map has failed.", uuidString.GetPointer()); + + return pUuidLongValue->ToLong(); + } + +private: + _BluetoothUuidMap(const _BluetoothUuidMap& value); + _BluetoothUuidMap& operator =(const _BluetoothUuidMap& value); + + result Initialise(void) + { + result r = E_SUCCESS; + + r = __uuidMap.Construct(); + SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_SYSTEM, "Construction of <UUID string, UUID enum type> map has failed."); + + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_SPP)), *(new Long((long)(BT_SVC_SPP_SERVICE)))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_LAP)), *(new Long((long) BT_SVC_LAP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_DUN)), *(new Long((long) BT_SVC_DUN_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_SYNC)), *(new Long((long) BT_SVC_SYNC_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_OPP)), *(new Long((long) BT_SVC_OPP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_FTP)), *(new Long((long) BT_SVC_FTP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_SYNC_COMMAND)), *(new Long((long) BT_SVC_SYNC_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_HSP)), *(new Long((long) BT_SVC_HSP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_CTP)), *(new Long((long) BT_SVC_CTP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_A2DP_SOURCE)), *(new Long((long) BT_SVC_A2DP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_A2DP_SINK)), *(new Long((long) BT_SVC_A2DP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_AVRCP_TARGET)), *(new Long((long) BT_SVC_AVRCP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_A2DP)), *(new Long((long) BT_SVC_A2DP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_AVRCP)), *(new Long((long) BT_SVC_AVRCP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_AVRCP_CONTROLLER)), *(new Long((long) BT_SVC_AVRCP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_ICP)), *(new Long((long) BT_SVC_ICP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_FAX)), *(new Long((long) BT_SVC_FAX_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_HSP_AG)), *(new Long((long) BT_SVC_HSP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_PAN_PANU)), *(new Long((long) BT_SVC_PANU_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_PAN_NAP)), *(new Long((long) BT_SVC_NAP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_PAN_GN)), *(new Long((long) BT_SVC_GN_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_BPP_DIRECT_PRINTING)), *(new Long((long) BT_SVC_BPP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_BPP_REFERENCE_PRINTING)), *(new Long((long) BT_SVC_BPP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_BIP)), *(new Long((long) BT_SVC_BIP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_BIP_RESPONDER)), *(new Long((long) BT_SVC_BIP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_BIP_AUTOMATIC_ARCHIVE)), *(new Long((long) BT_SVC_BIP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_BIP_REFERENCED_OBJECTS)), *(new Long((long) BT_SVC_BIP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_HFP)), *(new Long((long) BT_SVC_HFP_HS_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_HFP_AG)), *(new Long((long) BT_SVC_HFP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_BPP_DIRECT_PRINTING_RO)), *(new Long((long) BT_SVC_BPP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_BPP_REFLECTED_UI)), *(new Long((long) BT_SVC_BPP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_BPP_BASIC_PRINTING)), *(new Long((long) BT_SVC_BPP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_BPP_PRINTING_STATUS)), *(new Long((long) BT_SVC_BPP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_HID)), *(new Long((long) BT_SVC_HID_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_HCRP)), *(new Long((long) BT_SVC_HCRP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_HCRP_PRINT)), *(new Long((long) BT_SVC_HCRP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_HCRP_SCAN)), *(new Long((long) BT_SVC_HCRP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_SAP)), *(new Long((long) BT_SVC_SAP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_PBAP_PCE)), *(new Long((long) BT_SVC_PBAP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_PBAP_PSE)), *(new Long((long) BT_SVC_PBAP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_PBAP)), *(new Long((long) BT_SVC_PBAP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_HSP_HS)), *(new Long((long) BT_SVC_HSP_HS_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_MAP_ACCESS_SERVER)), *(new Long((long) BT_SVC_MAP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_MAP_NOTIFICATION_SERVER)), *(new Long((long) BT_SVC_MAP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_MAP_ACCESS_PROFILE)), *(new Long((long) BT_SVC_MAP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_DID_PNP_INFORMATION)), *(new Long((long) BT_SVC_DID_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_GENERIC_NETWORKING)), *(new Long((long) BT_SVC_NONE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_GENERIC_FILE_TRANSFER)), *(new Long((long) BT_SVC_NONE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_GENERIC_AUDIO)), *(new Long((long) BT_SVC_NONE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_GENERIC_TELEPHONY)), *(new Long((long) BT_SVC_NONE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_VDP_SOURCE)), *(new Long((long) BT_SVC_VDP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_VDP_SINK)), *(new Long((long) BT_SVC_VDP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_VDP_DISTRIBUTION)), *(new Long((long) BT_SVC_VDP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_HDP)), *(new Long((long) BT_SVC_HDP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_HDP_SOURCE)), *(new Long((long) BT_SVC_HDP_SERVICE))); + __uuidMap.Add(*(new Tizen::Base::UuId(BT_SVC_UUID_HDP_SINK)), *(new Long((long) BT_SVC_HDP_SERVICE))); + + return E_SUCCESS; + } + +private: + Tizen::Base::Collection::HashMap __uuidMap; + +}; //_BluetoothUuidMap + +// defines local methods +void PrintMajorDeviceClass(BluetoothMajorDeviceClassType type); +void PrintMinorDeviceClass(BluetoothMajorDeviceClassType majType, BluetoothMinorDeviceClassType minType); +void PrintServiceClassList(unsigned long type); + + +_BluetoothAdapterUtility::_BluetoothAdapterUtility(void) +{ +} + +_BluetoothAdapterUtility::~_BluetoothAdapterUtility(void) +{ +} + + +BluetoothMajorDeviceClassType +_BluetoothAdapterUtility::ConvertToMajorDeviceClassType(bt_major_device_class_e majorClass) +{ + BluetoothMajorDeviceClassType convertedType = BT_COD_MAJ_DEV_CLS_UNCLASSIFIED; + + switch (majorClass) + { + case BT_MAJOR_DEVICE_CLASS_MISC: + convertedType = BT_COD_MAJ_DEV_CLS_MISC; + break; + + case BT_MAJOR_DEVICE_CLASS_COMPUTER: + convertedType = BT_COD_MAJ_DEV_CLS_COMPUTER; + break; + + case BT_MAJOR_DEVICE_CLASS_PHONE: + convertedType = BT_COD_MAJ_DEV_CLS_PHONE; + break; + + case BT_MAJOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT: + convertedType = BT_COD_MAJ_DEV_CLS_LAN_ACCESS_POINT; + break; + + case BT_MAJOR_DEVICE_CLASS_AUDIO_VIDEO: + convertedType = BT_COD_MAJ_DEV_CLS_AUDIO; + break; + + case BT_MAJOR_DEVICE_CLASS_PERIPHERAL: + convertedType = BT_COD_MAJ_DEV_CLS_PERIPHERAL; + break; + + case BT_MAJOR_DEVICE_CLASS_IMAGING: + convertedType = BT_COD_MAJ_DEV_CLS_IMAGING; + break; + + case BT_MAJOR_DEVICE_CLASS_WEARABLE: + case BT_MAJOR_DEVICE_CLASS_TOY: + case BT_MAJOR_DEVICE_CLASS_HEALTH: + case BT_MAJOR_DEVICE_CLASS_UNCATEGORIZED: + default: + convertedType = BT_COD_MAJ_DEV_CLS_UNCLASSIFIED; + break; + } + + return convertedType; +} + +BluetoothMinorDeviceClassType +_BluetoothAdapterUtility::ConvertToMinorDeviceClassType(bt_major_device_class_e majorClass, bt_minor_device_class_e minorClass) +{ + BluetoothMinorDeviceClassType convertedType = BT_COD_MIN_DEV_CLS_UNCLASSIFIED; + + if (majorClass == BT_MAJOR_DEVICE_CLASS_COMPUTER) + { + switch (minorClass) + { + case BT_MINOR_DEVICE_CLASS_COMPUTER_DESKTOP_WORKSTATION: + convertedType = BT_COD_MIN_DEV_CLS_DESKTOP_WORKSTATION; + break; + + case BT_MINOR_DEVICE_CLASS_COMPUTER_SERVER_CLASS: + convertedType = BT_COD_MIN_DEV_CLS_SERVER_CLASS_COMPUTER; + break; + + case BT_MINOR_DEVICE_CLASS_COMPUTER_LAPTOP: + convertedType = BT_COD_MIN_DEV_CLS_LAPTOP; + break; + + case BT_MINOR_DEVICE_CLASS_COMPUTER_HANDHELD_PC_OR_PDA: + convertedType = BT_COD_MIN_DEV_CLS_HANDHELD_PC_OR_PDA; + break; + + case BT_MINOR_DEVICE_CLASS_COMPUTER_PALM_SIZED_PC_OR_PDA: + convertedType = BT_COD_MIN_DEV_CLS_PALM_SIZED_PC_OR_PDA; + break; + + case BT_MINOR_DEVICE_CLASS_COMPUTER_WEARABLE_COMPUTER: + convertedType = BT_COD_MIN_DEV_CLS_WEARABLE_COMPUTER; + break; + + default: + convertedType = BT_COD_MIN_DEV_CLS_UNCLASSIFIED; + break; + } + } + else if (majorClass == BT_MAJOR_DEVICE_CLASS_PHONE) + { + switch (minorClass) + { + case BT_MINOR_DEVICE_CLASS_PHONE_CELLULAR: + convertedType = BT_COD_MIN_DEV_CLS_CELLULAR; + break; + + case BT_MINOR_DEVICE_CLASS_PHONE_CORDLESS: + convertedType = BT_COD_MIN_DEV_CLS_CORDLESS; + break; + + case BT_MINOR_DEVICE_CLASS_PHONE_SMART_PHONE: + convertedType = BT_COD_MIN_DEV_CLS_SMART_PHONE; + break; + + case BT_MINOR_DEVICE_CLASS_PHONE_WIRED_MODEM_OR_VOICE_GATEWAY: + convertedType = BT_COD_MIN_DEV_CLS_WIRED_MODEM_OR_VOICE_GATEWAY; + break; + + case BT_MINOR_DEVICE_CLASS_PHONE_COMMON_ISDN_ACCESS: + convertedType = BT_COD_MIN_DEV_CLS_COMMON_ISDN_ACCESS; + break; + + default: + convertedType = BT_COD_MIN_DEV_CLS_UNCLASSIFIED; + break; + } + } + else if (majorClass == BT_MAJOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT) + { + switch (minorClass) + { + case BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_FULLY_AVAILABLE: + convertedType = BT_COD_MIN_DEV_CLS_FULLY_AVAILABLE; + break; + + case BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_1_TO_17_PERCENT_UTILIZED: + convertedType = BT_COD_MIN_DEV_CLS_1_TO_17_PERCENT_UTILIZED; + break; + + case BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_17_TO_33_PERCENT_UTILIZED: + convertedType = BT_COD_MIN_DEV_CLS_17_TO_33_PERCENT_UTILIZED; + break; + + case BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_33_TO_50_PERCENT_UTILIZED : + convertedType = BT_COD_MIN_DEV_CLS_33_TO_50_PERCENT_UTILIZED; + break; + + case BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_50_to_67_PERCENT_UTILIZED: + convertedType = BT_COD_MIN_DEV_CLS_50_to_67_PERCENT_UTILIZED; + break; + + case BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_67_TO_83_PERCENT_UTILIZED: + convertedType = BT_COD_MIN_DEV_CLS_67_TO_83_PERCENT_UTILIZED; + break; + + case BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_83_TO_99_PERCENT_UTILIZED: + convertedType = BT_COD_MIN_DEV_CLS_83_TO_99_PERCENT_UTILIZED; + break; + + case BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_NO_SERVICE_AVAILABLE : + convertedType = BT_COD_MIN_DEV_CLS_NO_SERVICE_AVAILABLE; + break; + + default: + convertedType = BT_COD_MIN_DEV_CLS_UNCLASSIFIED; + break; + } + } + else if (majorClass == BT_MAJOR_DEVICE_CLASS_AUDIO_VIDEO) + { + switch (minorClass) + { + case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_WEARABLE_HEADSET: + convertedType = BT_COD_MIN_DEV_CLS_HEADSET_PROFILE; + break; + + case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_HANDS_FREE : + convertedType = BT_COD_MIN_DEV_CLS_HANDSFREE; + break; + + case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_MICROPHONE: + case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_LOUDSPEAKER: + case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_HEADPHONES: + case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_PORTABLE_AUDIO: + case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_CAR_AUDIO: + case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_SET_TOP_BOX: + case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_HIFI_AUDIO_DEVICE: + case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VCR: + case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_CAMERA: + case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_CAMCORDER : + case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_MONITOR: + case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_DISPLAY_LOUDSPEAKER: + case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_CONFERENCING: + case BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_GAMING_TOY: + default: + convertedType = BT_COD_MIN_DEV_CLS_UNCLASSIFIED; + break; + } + } + else if (majorClass == BT_MAJOR_DEVICE_CLASS_PERIPHERAL) + { + switch (minorClass) + { + case BT_MINOR_DEVICE_CLASS_PERIPHERAL_KEY_BOARD: + case BT_MINOR_DEVICE_CLASS_PERIPHERAL_POINTING_DEVICE: + case BT_MINOR_DEVICE_CLASS_PERIPHERAL_COMBO_KEYBOARD_POINTING_DEVICE : + case BT_MINOR_DEVICE_CLASS_PERIPHERAL_JOYSTICK: + case BT_MINOR_DEVICE_CLASS_PERIPHERAL_GAME_PAD: + case BT_MINOR_DEVICE_CLASS_PERIPHERAL_REMOTE_CONTROL: + case BT_MINOR_DEVICE_CLASS_PERIPHERAL_SENSING_DEVICE: + case BT_MINOR_DEVICE_CLASS_PERIPHERAL_DIGITIZER_TABLET: + case BT_MINOR_DEVICE_CLASS_PERIPHERAL_CARD_READER: + convertedType = BT_COD_MIN_DEV_CLS_SIM_CARD_READER; + break; + + case BT_MINOR_DEVICE_CLASS_PERIPHERAL_DIGITAL_PEN: + case BT_MINOR_DEVICE_CLASS_PERIPHERAL_HANDHELD_SCANNER: + case BT_MINOR_DEVICE_CLASS_PERIPHERAL_HANDHELD_GESTURAL_INPUT_DEVICE : + default: + convertedType = BT_COD_MIN_DEV_CLS_UNCLASSIFIED; + break; + } + } + else if (majorClass == BT_MAJOR_DEVICE_CLASS_IMAGING) + { + switch (minorClass) + { + case BT_MINOR_DEVICE_CLASS_IMAGING_DISPLAY: + case BT_MINOR_DEVICE_CLASS_IMAGING_CAMERA: + case BT_MINOR_DEVICE_CLASS_IMAGING_SCANNER: + case BT_MINOR_DEVICE_CLASS_IMAGING_PRINTER: + default: + convertedType = BT_COD_MIN_DEV_CLS_UNCLASSIFIED; + break; + } + } + else if (majorClass == BT_MAJOR_DEVICE_CLASS_WEARABLE) + { + switch (minorClass) + { + case BT_MINOR_DEVICE_CLASS_WEARABLE_WRIST_WATCH: + case BT_MINOR_DEVICE_CLASS_WEARABLE_PAGER: + case BT_MINOR_DEVICE_CLASS_WEARABLE_JACKET: + case BT_MINOR_DEVICE_CLASS_WEARABLE_HELMET: + case BT_MINOR_DEVICE_CLASS_WEARABLE_GLASSES: + default: + convertedType = BT_COD_MIN_DEV_CLS_UNCLASSIFIED; + break; + } + } + else if (majorClass == BT_MAJOR_DEVICE_CLASS_TOY) + { + switch (minorClass) + { + case BT_MINOR_DEVICE_CLASS_TOY_ROBOT: + case BT_MINOR_DEVICE_CLASS_TOY_VEHICLE: + case BT_MINOR_DEVICE_CLASS_TOY_DOLL_ACTION: + case BT_MINOR_DEVICE_CLASS_TOY_CONTROLLER: + case BT_MINOR_DEVICE_CLASS_TOY_GAME: + default: + convertedType = BT_COD_MIN_DEV_CLS_UNCLASSIFIED; + break; + } + } + else if (majorClass == BT_MAJOR_DEVICE_CLASS_HEALTH) + { + switch (minorClass) + { + case BT_MINOR_DEVICE_CLASS_HEATH_BLOOD_PRESSURE_MONITOR: + case BT_MINOR_DEVICE_CLASS_HEATH_THERMOMETER : + case BT_MINOR_DEVICE_CLASS_HEATH_WEIGHING_SCALE: + case BT_MINOR_DEVICE_CLASS_HEATH_GLUCOSE_METER: + case BT_MINOR_DEVICE_CLASS_HEATH_PULSE_OXIMETER: + case BT_MINOR_DEVICE_CLASS_HEATH_HEART_PULSE_RATE_MONITOR: + case BT_MINOR_DEVICE_CLASS_HEATH_DATA_DISPLAY: + case BT_MINOR_DEVICE_CLASS_HEATH_STEP_COUNTER: + case BT_MINOR_DEVICE_CLASS_HEATH_BODY_COMPOSITION_ANALYZER: + case BT_MINOR_DEVICE_CLASS_HEATH_PEAK_FLOW_MONITOR: + case BT_MINOR_DEVICE_CLASS_HEATH_MEDICATION_MONITOR : + case BT_MINOR_DEVICE_CLASS_HEATH_KNEE_PROSTHESIS: + case BT_MINOR_DEVICE_CLASS_HEATH_ANKLE_PROSTHESIS: + default: + convertedType = BT_COD_MIN_DEV_CLS_UNCLASSIFIED; + break; + } + } + else + { + convertedType = BT_COD_MIN_DEV_CLS_UNCLASSIFIED; + } + + return convertedType; +} + +unsigned long +_BluetoothAdapterUtility::ConvertToServiceClassList(int serviceClass) +{ + unsigned long serviceClassMask = 0; + + bt_major_service_class_e origianlClassList[] = + { + BT_MAJOR_SERVICE_CLASS_INFORMATION, + BT_MAJOR_SERVICE_CLASS_TELEPHONY, + BT_MAJOR_SERVICE_CLASS_AUDIO, + BT_MAJOR_SERVICE_CLASS_OBJECT_TRANSFER, + BT_MAJOR_SERVICE_CLASS_CAPTURING, + BT_MAJOR_SERVICE_CLASS_RENDERING, + BT_MAJOR_SERVICE_CLASS_NETWORKING, + BT_MAJOR_SERVICE_CLASS_POSITIONING, + BT_MAJOR_SERVICE_CLASS_LIMITED_DISCOVERABLE_MODE + }; + + BluetoothServiceClassType convertedClassList[] = + { + BT_COD_SVC_INFORMATION, + BT_COD_SVC_TELEPHONY, + BT_COD_SVC_AUDIO, + BT_COD_SVC_OBJECT_TRANSFER, + BT_COD_SVC_CAPTURING, + BT_COD_SVC_RENDERING, + BT_COD_SVC_NETWORKING, + BT_COD_SVC_POSITIONING, + BT_COD_SVC_LIMITED_DISCOVERABLE_MODE + }; + + for (int i = 0; i < 9; i++) + { + // checks the input value, 'serviceClass', has each value of the class list using bit masking + if (origianlClassList[i] == (serviceClass & origianlClassList[i])) + { + serviceClassMask += convertedClassList[i]; + } + } + + return serviceClassMask; +} + +unsigned long +_BluetoothAdapterUtility::ConvertToServiceList(char** pServiceUuid, int& serviceUuidCount) +{ + unsigned long serviceListMask = 0; + _BluetoothUuidMap* pMap = null; + + pMap = _BluetoothUuidMap::GetInstance(); + SysTryReturn(NID_NET_BT, pMap != null, 0, E_SYSTEM, "Converting UUID strings to a masked BluetoothServiceType value faild."); + + for (int i = 0; i < serviceUuidCount; i++) + { + String uuidString(pServiceUuid[i]); + long uuidLongValue = pMap->GetUuidLong(uuidString); + + serviceListMask |= uuidLongValue; + } + + return serviceListMask; +} + +Tizen::Base::Collection::IList* +_BluetoothAdapterUtility::ConvertServiceUuidListN(char** pServiceUuid, int& serviceUuidCount) +{ + unique_ptr<ArrayList, AllElementsDeleter> pList; + UuId* pUuid = null; + + pList.reset(new (std::nothrow) ArrayList()); + SysTryReturn(NID_NET_BT, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); + + for (int i = 0; i < serviceUuidCount; i++) + { + String uuidString(pServiceUuid[i]); + pUuid = new (std::nothrow) UuId(); + SysTryReturn(NID_NET_BT, pUuid != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); + uuidString.ToUpperCase(); + UuId::Parse(uuidString, *pUuid); + + pList->Add(*pUuid); + } + + return pList.release(); +} + +void +_BluetoothAdapterUtility::PrintDeviceInfo(const BluetoothDevice& device) +{ + SysLog(NID_NET_BT, "Bluetooth Device Information ============="); + SysLog(NID_NET_BT, "+ Address: [%ls]", _BluetoothDeviceImpl::GetAddressString(*(device.GetAddress())).GetPointer()); + SysLog(NID_NET_BT, "+ Name: %ls", device.GetName().GetPointer()); + SysLog(NID_NET_BT, "+ %s", device.IsPaired() ? "Paired" : "Not Paired"); + SysLog(NID_NET_BT, "+ RSSI: %d", device.GetRssi()); + PrintMajorDeviceClass(device.GetMajorDeviceClassType()); + PrintMinorDeviceClass(device.GetMajorDeviceClassType(), device.GetMinorDeviceClassType()); + PrintServiceClassList(device.GetServiceClassList()); + PrintServiceList(device.GetServiceList()); + PrintServiceUuidList(device.GetServiceUuidList()); +} + +void +_BluetoothAdapterUtility::PrintServiceList(unsigned long type) +{ + int index = 0; + unsigned long typeList[] = + { + BT_SVC_MAP_SERVICE, + BT_SVC_HDP_SERVICE, + BT_SVC_DID_SERVICE, + BT_SVC_HCRP_SERVICE, + BT_SVC_HFP_HS_SERVICE, + BT_SVC_HSP_HS_SERVICE, + BT_SVC_PBAP_SERVICE, + BT_SVC_VDP_SERVICE, + BT_SVC_HID_SERVICE, + BT_SVC_AVRCP_SERVICE, + BT_SVC_A2DP_SERVICE, + BT_SVC_SAP_SERVICE, + BT_SVC_GN_SERVICE, + BT_SVC_NAP_SERVICE, + BT_SVC_PANU_SERVICE, + BT_SVC_BIP_SERVICE, + BT_SVC_BPP_SERVICE, + BT_SVC_SYNC_SERVICE, + BT_SVC_ICP_SERVICE, + BT_SVC_CTP_SERVICE, + BT_SVC_FTP_SERVICE, + BT_SVC_OPP_SERVICE, + BT_SVC_HFP_SERVICE, + BT_SVC_HSP_SERVICE, + BT_SVC_LAP_SERVICE, + BT_SVC_FAX_SERVICE, + BT_SVC_DUN_SERVICE, + BT_SVC_SPP_SERVICE, + BT_SVC_RES_SERVICE + }; + const char* typeStrList[] = + { + "BT_SVC_MAP_SERVICE", + "BT_SVC_HDP_SERVICE", + "BT_SVC_DID_SERVICE", + "BT_SVC_HCRP_SERVICE", + "BT_SVC_HFP_HS_SERVICE", + "BT_SVC_HSP_HS_SERVICE", + "BT_SVC_PBAP_SERVICE", + "BT_SVC_VDP_SERVICE", + "BT_SVC_HID_SERVICE", + "BT_SVC_AVRCP_SERVICE", + "BT_SVC_A2DP_SERVICE", + "BT_SVC_SAP_SERVICE", + "BT_SVC_GN_SERVICE", + "BT_SVC_NAP_SERVICE", + "BT_SVC_PANU_SERVICE", + "BT_SVC_BIP_SERVICE", + "BT_SVC_BPP_SERVICE", + "BT_SVC_SYNC_SERVICE", + "BT_SVC_ICP_SERVICE", + "BT_SVC_CTP_SERVICE", + "BT_SVC_FTP_SERVICE", + "BT_SVC_OPP_SERVICE", + "BT_SVC_HFP_SERVICE", + "BT_SVC_HSP_SERVICE", + "BT_SVC_LAP_SERVICE", + "BT_SVC_FAX_SERVICE", + "BT_SVC_DUN_SERVICE", + "BT_SVC_SPP_SERVICE", + "BT_SVC_RES_SERVICE" + }; + + for (int i = 0; i < 29; i++) + { + // checks the input value, 'type', has each value of the service list using bit masking + if (typeList[i] == (type & typeList[i])) + { + SysLog(NID_NET_BT, "+ Service List[%d]: %s", index++, typeStrList[i]); + } + } +} + +void +_BluetoothAdapterUtility::PrintServiceUuidList(const Tizen::Base::Collection::IList* pList) +{ + int count = 0; + const UuId* pUuid = null; + + if (pList == null) + { + SysLog(NID_NET_BT, "+ No Service UUID (with error)"); + } + else + { + count = pList->GetCount(); + + if (count == 0) + { + SysLog(NID_NET_BT, "+ No Service UUID"); + } + + for (int i = 0; i < count; i++) + { + pUuid = dynamic_cast<const UuId*>(pList->GetAt(i)); + if (pUuid != null) + { + SysLog(NID_NET_BT, "+ Service UUID[%d]: %ls", i, pUuid->ToString().GetPointer()); + } + } + } +} + +void PrintMajorDeviceClass(BluetoothMajorDeviceClassType type) +{ + const char* pTypeString = null; + + switch (type) + { + case BT_COD_MAJ_DEV_CLS_MISC: + pTypeString = "BT_COD_MAJ_DEV_CLS_MISC"; + break; + + case BT_COD_MAJ_DEV_CLS_COMPUTER: + pTypeString = "BT_COD_MAJ_DEV_CLS_COMPUTER"; + break; + + case BT_COD_MAJ_DEV_CLS_PHONE: + pTypeString = "BT_COD_MAJ_DEV_CLS_PHONE"; + break; + + case BT_COD_MAJ_DEV_CLS_LAN_ACCESS_POINT: + pTypeString = "BT_COD_MAJ_DEV_CLS_LAN_ACCESS_POINT"; + break; + + case BT_COD_MAJ_DEV_CLS_AUDIO: + pTypeString = "BT_COD_MAJ_DEV_CLS_AUDIO"; + break; + + case BT_COD_MAJ_DEV_CLS_PERIPHERAL: + pTypeString = "BT_COD_MAJ_DEV_CLS_PERIPHERAL"; + break; + + case BT_COD_MAJ_DEV_CLS_IMAGING: + pTypeString = "BT_COD_MAJ_DEV_CLS_IMAGING"; + break; + + case BT_COD_MAJ_DEV_CLS_UNCLASSIFIED: + pTypeString = "BT_COD_MAJ_DEV_CLS_UNCLASSIFIED"; + break; + + default: + pTypeString = "Unknown"; + break; + } + + SysLog(NID_NET_BT, "+ Major Device Type: %s", pTypeString); +} + +void PrintMinorDeviceClass(BluetoothMajorDeviceClassType majType, BluetoothMinorDeviceClassType minType) +{ + const char* pTypeString = null; + + switch (majType) + { + case BT_COD_MAJ_DEV_CLS_COMPUTER: + switch (minType) + { + case BT_COD_MIN_DEV_CLS_DESKTOP_WORKSTATION: + pTypeString = "BT_COD_MIN_DEV_CLS_DESKTOP_WORKSTATION"; + break; + + case BT_COD_MIN_DEV_CLS_SERVER_CLASS_COMPUTER: + pTypeString = "BT_COD_MIN_DEV_CLS_SERVER_CLASS_COMPUTER"; + break; + + case BT_COD_MIN_DEV_CLS_LAPTOP: + pTypeString = "BT_COD_MIN_DEV_CLS_LAPTOP"; + break; + + case BT_COD_MIN_DEV_CLS_HANDHELD_PC_OR_PDA: + pTypeString = "BT_COD_MIN_DEV_CLS_HANDHELD_PC_OR_PDA"; + break; + + case BT_COD_MIN_DEV_CLS_PALM_SIZED_PC_OR_PDA: + pTypeString = "BT_COD_MIN_DEV_CLS_PALM_SIZED_PC_OR_PDA"; + break; + + case BT_COD_MIN_DEV_CLS_WEARABLE_COMPUTER: + pTypeString = "BT_COD_MIN_DEV_CLS_WEARABLE_COMPUTER"; + break; + + default: + pTypeString = "Unclassified"; + break; + } + break; + + case BT_COD_MAJ_DEV_CLS_PHONE: + switch (minType) + { + case BT_COD_MIN_DEV_CLS_CELLULAR: + pTypeString = "BT_COD_MIN_DEV_CLS_CELLULAR"; + break; + + case BT_COD_MIN_DEV_CLS_CORDLESS: + pTypeString = "BT_COD_MIN_DEV_CLS_CORDLESS"; + break; + + case BT_COD_MIN_DEV_CLS_SMART_PHONE: + pTypeString = "BT_COD_MIN_DEV_CLS_SMART_PHONE"; + break; + + case BT_COD_MIN_DEV_CLS_WIRED_MODEM_OR_VOICE_GATEWAY: + pTypeString = "BT_COD_MIN_DEV_CLS_WIRED_MODEM_OR_VOICE_GATEWAY"; + break; + + case BT_COD_MIN_DEV_CLS_COMMON_ISDN_ACCESS: + pTypeString = "BT_COD_MIN_DEV_CLS_COMMON_ISDN_ACCESS"; + break; + + default: + pTypeString = "Unclassified"; + break; + } + break; + + case BT_COD_MAJ_DEV_CLS_LAN_ACCESS_POINT: + switch (minType) + { + case BT_COD_MIN_DEV_CLS_FULLY_AVAILABLE: + pTypeString = "BT_COD_MAJ_DEV_CLS_LAN_ACCESS_POINT"; + break; + + case BT_COD_MIN_DEV_CLS_1_TO_17_PERCENT_UTILIZED: + pTypeString = "BT_COD_MIN_DEV_CLS_1_TO_17_PERCENT_UTILIZED"; + break; + + case BT_COD_MIN_DEV_CLS_17_TO_33_PERCENT_UTILIZED: + pTypeString = "BT_COD_MIN_DEV_CLS_17_TO_33_PERCENT_UTILIZED"; + break; + + case BT_COD_MIN_DEV_CLS_33_TO_50_PERCENT_UTILIZED: + pTypeString = "BT_COD_MIN_DEV_CLS_33_TO_50_PERCENT_UTILIZED"; + break; + + case BT_COD_MIN_DEV_CLS_50_to_67_PERCENT_UTILIZED: + pTypeString = "BT_COD_MIN_DEV_CLS_50_to_67_PERCENT_UTILIZED"; + break; + + case BT_COD_MIN_DEV_CLS_67_TO_83_PERCENT_UTILIZED: + pTypeString = "BT_COD_MIN_DEV_CLS_67_TO_83_PERCENT_UTILIZED"; + break; + + case BT_COD_MIN_DEV_CLS_83_TO_99_PERCENT_UTILIZED: + pTypeString = "BT_COD_MIN_DEV_CLS_83_TO_99_PERCENT_UTILIZED"; + break; + + case BT_COD_MIN_DEV_CLS_NO_SERVICE_AVAILABLE: + pTypeString = "BT_COD_MIN_DEV_CLS_NO_SERVICE_AVAILABLE"; + break; + + default: + pTypeString = "Unclassified"; + break; + } + break; + + case BT_COD_MAJ_DEV_CLS_AUDIO: + switch (minType) + { + case BT_COD_MIN_DEV_CLS_HEADSET_PROFILE: + pTypeString = "BT_COD_MIN_DEV_CLS_HEADSET_PROFILE"; + break; + + case BT_COD_MIN_DEV_CLS_HANDSFREE: + pTypeString = "BT_COD_MIN_DEV_CLS_HANDSFREE"; + break; + + default: + pTypeString = "Unclassified"; + break; + } + break; + + case BT_COD_MAJ_DEV_CLS_PERIPHERAL: + switch (minType) + { + case BT_COD_MIN_DEV_CLS_SIM_CARD_READER: + pTypeString = "BT_COD_MIN_DEV_CLS_SIM_CARD_READER"; + break; + + default: + pTypeString = "Unclassified"; + break; + } + break; + + case BT_COD_MAJ_DEV_CLS_IMAGING: + case BT_COD_MAJ_DEV_CLS_MISC: + case BT_COD_MAJ_DEV_CLS_UNCLASSIFIED: + default: + pTypeString = "Unclassified"; + break; + } + + SysLog(NID_NET_BT, "+ Minor Device Type: %s", pTypeString); +} + +void PrintServiceClassList(unsigned long type) +{ + int index = 0; + unsigned long typeList[] = + { + BT_COD_SVC_INFORMATION, + BT_COD_SVC_TELEPHONY, + BT_COD_SVC_AUDIO, + BT_COD_SVC_OBJECT_TRANSFER, + BT_COD_SVC_CAPTURING, + BT_COD_SVC_RENDERING, + BT_COD_SVC_NETWORKING, + BT_COD_SVC_POSITIONING, + BT_COD_SVC_LIMITED_DISCOVERABLE_MODE + }; + const char* typeStrList[] = + { + "BT_COD_SVC_INFORMATION", + "BT_COD_SVC_TELEPHONY", + "BT_COD_SVC_AUDIO", + "BT_COD_SVC_OBJECT_TRANSFER", + "BT_COD_SVC_CAPTURING", + "BT_COD_SVC_RENDERING", + "BT_COD_SVC_NETWORKING", + "BT_COD_SVC_POSITIONING", + "BT_COD_SVC_LIMITED_DISCOVERABLE_MODE" + }; + + for (int i = 0; i < 9; i++) + { + if (typeList[i] == (type & typeList[i])) + { + // checks the input value, 'type', has each value of the service class list using bit masking + SysLog(NID_NET_BT, "+ Service Class List[%d]: %s", index++, typeStrList[i]); + } + } +} + +} } } // Tizen::Net::Bluetooth |