| 132 | } |
| 133 | |
| 134 | std::pair<std::string, int> SocketBluetooth::discover (char *selector) |
| 135 | { |
| 136 | HBLUETOOTH_DEVICE_FIND founded_device; |
| 137 | BLUETOOTH_DEVICE_INFO device_info; |
| 138 | device_info.dwSize = sizeof (device_info); |
| 139 | |
| 140 | BLUETOOTH_DEVICE_SEARCH_PARAMS search_criteria; |
| 141 | search_criteria.dwSize = sizeof (BLUETOOTH_DEVICE_SEARCH_PARAMS); |
| 142 | search_criteria.fReturnAuthenticated = TRUE; |
| 143 | search_criteria.fReturnRemembered = FALSE; |
| 144 | search_criteria.fReturnConnected = FALSE; |
| 145 | search_criteria.fReturnUnknown = FALSE; |
| 146 | search_criteria.fIssueInquiry = FALSE; |
| 147 | search_criteria.cTimeoutMultiplier = 0; |
| 148 | |
| 149 | founded_device = BluetoothFindFirstDevice (&search_criteria, &device_info); |
| 150 | if (founded_device == NULL) |
| 151 | { |
| 152 | return std::make_pair<std::string, int> ( |
| 153 | "", (int)SocketBluetoothReturnCodes::DEVICE_IS_NOT_CREATED_ERROR); |
| 154 | } |
| 155 | |
| 156 | do |
| 157 | { |
| 158 | std::wstring device_name_w = std::wstring (device_info.szName); |
| 159 | // setup converter |
| 160 | using convert_type = std::codecvt_utf8<wchar_t>; |
| 161 | std::wstring_convert<convert_type, wchar_t> converter; |
| 162 | // use converter (.to_bytes: wstr->str, .from_bytes: str->wstr) |
| 163 | std::string device_name = converter.to_bytes (device_name_w); |
| 164 | if (device_name.find (std::string (selector)) != device_name.npos) |
| 165 | { |
| 166 | std::string address_string = ""; |
| 167 | BLUETOOTH_ADDRESS addr = device_info.Address; |
| 168 | for (int i = 0; i < 6; i++) |
| 169 | { |
| 170 | address_string += uchar2hex (addr.rgBytes[5 - i]); |
| 171 | if (i != 5) |
| 172 | { |
| 173 | address_string += ":"; |
| 174 | } |
| 175 | } |
| 176 | std::pair<std::string, int> res = std::pair<std::string, int> ( |
| 177 | address_string, (int)SocketBluetoothReturnCodes::STATUS_OK); |
| 178 | return res; |
| 179 | } |
| 180 | |
| 181 | } while (BluetoothFindNextDevice (founded_device, &device_info)); |
| 182 | return std::make_pair<std::string, int> ( |
| 183 | "", (int)SocketBluetoothReturnCodes::DEVICE_IS_NOT_DISCOVERABLE); |
| 184 | } |
nothing calls this directly
no test coverage detected