1 /* 2 * Copyright (C) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef AVRCP_CT_PROFILE_H 17 #define AVRCP_CT_PROFILE_H 18 19 #include "avrcp_ct_internal.h" 20 #include "avrcp_ct_notification.h" 21 #include "avrcp_ct_state_machine.h" 22 #include "dispatcher.h" 23 /** 24 * @brief The bluetooth subsystem. 25 */ 26 namespace OHOS { 27 namespace bluetooth { 28 /** 29 * @brief This class provides a set of methods related to the role of the controller described in the Audio/Video Remote 30 * Control profile. 31 */ 32 class AvrcCtProfile { 33 public: 34 /** 35 * @brief This struct provides a set of pointers for informing the state change. 36 */ 37 struct Observer { 38 public: 39 /** 40 * @brief Informs that the AVRCP TG profile is disabled. 41 */ 42 std::function<void(void)> onDisabled; 43 44 /** 45 * @brief Informs that the connection state is changed. 46 * 47 * @param[in] rawAddr The address of the bluetooth device. 48 * @param[in] state The connection state. Refer to <b>BTConnectState</b>. 49 */ 50 std::function<void(const RawAddress &rawAddr, int state)> onConnectionStateChanged; 51 52 /** 53 * @brief Responds the data of the <b>PressButton</b>. 54 * 55 * @param[in] rawAddr The address of the bluetooth device. 56 * @param[in] button The code of the button released. 57 * @param[in] result The result of the execution.<br> 58 * @a BT_SUCCESS : Execute success.<br> 59 * @a RET_NO_SUPPORT : Not support.<br> 60 * @a RET_BAD_STATUS : Execute failure. 61 */ 62 std::function<void(const RawAddress &rawAddr, uint8_t button, int result)> onButtonPressed; 63 64 /** 65 * @brief Responds the data of the <b>ReleaseButton</b>. 66 * 67 * @param[in] rawAddr The address of the bluetooth device. 68 * @param[in] button The code of the button released. 69 * @param[in] result The result of the execution.<br> 70 * @a BT_SUCCESS : Execute success.<br> 71 * @a RET_NO_SUPPORT : Not support.<br> 72 * @a RET_BAD_STATUS : Execute failure. 73 */ 74 std::function<void(const RawAddress &rawAddr, uint8_t button, int result)> onButtonReleased; 75 76 /** 77 * @brief Responds the data of the <b>GetCapabilities</b>. 78 * 79 * @param[in] rawAddr The address of the bluetooth device. 80 * @param[in] companies The list of CompanyId. 81 * @param[in] events The list of EventId. 82 * @param[in] result The result of the execution.<br> 83 * @a BT_SUCCESS : Execute success.<br> 84 * @a RET_NO_SUPPORT : Not support.<br> 85 * @a RET_BAD_STATUS : Execute failure. 86 */ 87 std::function<void(const RawAddress &rawAddr, const std::vector<uint32_t> &companies, 88 const std::vector<uint8_t> &events, int result)> 89 onGetCapabilities; 90 91 /** 92 * @brief Responds the data of the <b>ListPlayerApplicationSettingAttributes</b>. 93 * 94 * @param[in] rawAddr The address of the bluetooth device. 95 * @param[in] attribute The attribute of the player application setting. Refer to <b>AvrcPlayerAttribute</b>. 96 * @param[in] result The result of the execution.<br> 97 * @a BT_SUCCESS : Execute success.<br> 98 * @a RET_NO_SUPPORT : Not support.<br> 99 * @a RET_BAD_STATUS : Execute failure. 100 */ 101 std::function<void(const RawAddress &rawAddr, const std::vector<uint8_t> &attributes, int result)> 102 onListPlayerApplicationSettingAttributes; 103 104 /** 105 * @brief Responds the data of the <b>ListPlayerApplicationSettingValues</b>. 106 * 107 * @param[in] rawAddr The address of the bluetooth device. 108 * @param[in] attribute The attribute of the player application setting. Refer to <b>AvrcPlayerAttribute</b>. 109 * @param[in] values The values associated witch the attribute. 110 * @param[in] result The result of the execution.<br> 111 * @a BT_SUCCESS : Execute success.<br> 112 * @a RET_NO_SUPPORT : Not support.<br> 113 * @a RET_BAD_STATUS : Execute failure. 114 */ 115 std::function<void( 116 const RawAddress &rawAddr, uint8_t attribute, const std::vector<uint8_t> &values, int result)> 117 onListPlayerApplicationSettingValues; 118 119 /** 120 * @brief Responds the data of the <b>GetCurrentPlayerApplicationSettingValue</b>. 121 * 122 * @param[in] rawAddr The address of the bluetooth device. 123 * @param[in] attributes The attribute of the player application settings. Refer to <b>AvrcPlayerAttribute</b>. 124 * @param[in] values The values associated witch the attribute. 125 * @param[in] result The result of the execution.<br> 126 * @a BT_SUCCESS : Execute success.<br> 127 * @a RET_NO_SUPPORT : Not support.<br> 128 * @a RET_BAD_STATUS : Execute failure. 129 */ 130 std::function<void(const RawAddress &rawAddr, const std::vector<uint8_t> &attribute, 131 const std::vector<uint8_t> &values, int result)> 132 onGetCurrentPlayerApplicationSettingValue; 133 134 /** 135 * @brief Responds the data of the <b>SetPlayerApplicationSettingValue</b>. 136 * 137 * @param[in] rawAddr The address of the bluetooth device. 138 * @param[in] result The result of the execution.<br> 139 * @a BT_SUCCESS : Execute success.<br> 140 * @a RET_NO_SUPPORT : Not support.<br> 141 * @a RET_BAD_STATUS : Execute failure. 142 */ 143 std::function<void(const RawAddress &rawAddr, int result)> onSetPlayerApplicationSettingValue; 144 145 /** 146 * @brief Responds the data of the <b>GetPlayerApplicationSettingAttributeText</b>. 147 * 148 * @param[in] rawAddr The address of the bluetooth device. 149 * @param[in] attributes The attribute of the player application settings. 150 * @param[in] attrStr The values associated witch the attribute. 151 * @param[in] result The result of the execution.<br> 152 * @a BT_SUCCESS : Execute success.<br> 153 * @a RET_NO_SUPPORT : Not support.<br> 154 * @a RET_BAD_STATUS : Execute failure. 155 */ 156 std::function<void(const RawAddress &rawAddr, const std::vector<uint8_t> &attributes, 157 const std::vector<std::string> &attrStr, int result)> 158 onGetPlayerApplicationSettingAttributeText; 159 160 /** 161 * @brief Responds the data of the <b>GetPlayerApplicationSettingValueText</b>. 162 * 163 * @param[in] rawAddr The address of the bluetooth device. 164 * @param[in] values Player application setting value ID. 165 * @param[in] valueStr Specifies the value string of player application setting value. 166 * @param[in] result The result of the execution.<br> 167 * @a BT_SUCCESS : Execute success.<br> 168 * @a RET_NO_SUPPORT : Not support.<br> 169 * @a RET_BAD_STATUS : Execute failure. 170 */ 171 std::function<void(const RawAddress &rawAddr, const std::vector<uint8_t> &values, 172 const std::vector<std::string> &valueStr, int result)> 173 onGetPlayerApplicationSettingValueText; 174 175 /** 176 * @brief Responds the data of the <b>GetElementAttributes</b>. 177 * 178 * @param[in] rawAddr The address of the bluetooth device. 179 * @param[in] attributes The attribute of the player application setting. 180 * @param[in] values The values associated witch the attribute. 181 * @param[in] result The result of the execution.<br> 182 * @a BT_SUCCESS : Execute success.<br> 183 * @a RET_NO_SUPPORT : Not support.<br> 184 * @a RET_BAD_STATUS : Execute failure. 185 */ 186 std::function<void(const RawAddress &rawAddr, const std::vector<uint32_t> &attributes, 187 const std::vector<std::string> &values, int result)> 188 onGetElementAttributes; 189 190 /** 191 * @brief Responds the data of the <b>GetPlayStatus</b>. 192 * 193 * @param[in] rawAddr The address of the bluetooth device. 194 * @param[in] songLength The total length of the playing song in milliseconds. 195 * @param[in] songPosition The current position of the playing in milliseconds elapsed. 196 * @param[in] playStatus The current status of playing. Refer to <b>AvrcPlayStatus</b>. 197 * @param[in] result The result of the execution.<br> 198 * @a BT_SUCCESS : Execute success.<br> 199 * @a RET_NO_SUPPORT : Not support.<br> 200 * @a RET_BAD_STATUS : Execute failure. 201 */ 202 std::function<void( 203 const RawAddress &rawAddr, uint32_t songLength, uint32_t songPosition, uint8_t playStatus, int status)> 204 onGetPlayStatus; 205 206 /** 207 * @brief Responds the data of the <b>SetAddressedPlayer</b>. 208 * 209 * @param[in] rawAddr The address of the bluetooth device. 210 * @param[in] result The result of the execution.<br> 211 * @a BT_SUCCESS : Execute success.<br> 212 * @a RET_NO_SUPPORT : Not support.<br> 213 * @a RET_BAD_STATUS : Execute failure. 214 * @param[in] detail The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 215 * @a AVRC_ES_CODE_NO_ERROR<br> 216 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 217 * @a AVRC_ES_CODE_UID_CHANGED<br> 218 * @a AVRC_ES_CODE_INVALID_PLAYER_ID<br> 219 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 220 */ 221 std::function<void(const RawAddress &rawAddr, int result, int detail)> onSetAddressedPlayer; 222 223 /** 224 * @brief Responds the data of the <b>SetBrowsedPlayer</b>. 225 * 226 * @param[in] rawAddr The address of the bluetooth device. 227 * @param[in] uidCounter The value of the uid counter. 228 * @param[in] numOfItems The number of items in the directory. 229 * @param[in] folderNames The current browsed path of the player. The first element in folderNames is the parent 230 * folder. The root folder has no name. The names are in UTF-8. 231 * @param[in] result The result of the execution.<br> 232 * @a BT_SUCCESS : Execute success.<br> 233 * @a RET_NO_SUPPORT : Not support.<br> 234 * @a RET_BAD_STATUS : Execute failure. 235 * @param[in] detail The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 236 * @a AVRC_ES_CODE_NO_ERROR<br> 237 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 238 * @a AVRC_ES_CODE_UID_CHANGED<br> 239 * @a AVRC_ES_CODE_INVALID_PLAYER_ID<br> 240 * @a AVRC_ES_CODE_PLAYER_NOT_BROWSABLE<br> 241 * @a AVRC_ES_CODE_PLAYER_NOT_ADDRESSED<br> 242 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 243 */ 244 std::function<void(const RawAddress &rawAddr, uint16_t uidCounter, uint32_t numOfItems, 245 const std::vector<std::string> &folderNames, int result, int detail)> 246 onSetBrowsedPlayer; 247 248 /** 249 * @brief Responds the data of the <b>ChangePath</b>. 250 * 251 * @param[in] rawAddr The address of the bluetooth device. 252 * @param[in] numOfItems The number of items in the directory. 253 * @param[in] result The result of the execution.<br> 254 * @a BT_SUCCESS : Execute success.<br> 255 * @a RET_NO_SUPPORT : Not support.<br> 256 * @a RET_BAD_STATUS : Execute failure. 257 * @param[in] detail The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 258 * @a AVRC_ES_CODE_NO_ERROR<br> 259 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 260 * @a AVRC_ES_CODE_UID_CHANGED<br> 261 * @a AVRC_ES_CODE_INVALID_DIRECTION<br> 262 * @a AVRC_ES_CODE_NOT_A_DIRECTORY<br> 263 * @a AVRC_ES_CODE_DOES_NOT_EXIST<br> 264 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 265 */ 266 std::function<void(const RawAddress &rawAddr, uint32_t numOfItems, int result, int detail)> onChangePath; 267 268 /** 269 * @brief Responds the data of the <b>GetFolderItems</b>. 270 * 271 * @param[in] rawAddr The address of the bluetooth device. 272 * @param[in] scope The scope in which media content navigation may take place. Refer to 273 * <b>AvrcMediaScope</b>. 274 * @param[in] uidCounter The UID Counter. 275 * @param[in] mpItems The list of <b>AvrcCtMpItem</b> class. 276 * @param[in] meItems The list of <b>AvrcCtMeItem</b> class. 277 * @param[in] result The result of the execution.<br> 278 * @a BT_SUCCESS : Execute success.<br> 279 * @a RET_NO_SUPPORT : Not support.<br> 280 * @a RET_BAD_STATUS : Execute failure. 281 * @param[in] detail The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 282 * @a AVRC_ES_CODE_NO_ERROR<br> 283 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 284 * @a AVRC_ES_CODE_UID_CHANGED<br> 285 * @a AVRC_ES_CODE_INVALID_SCOPE<br> 286 * @a AVRC_ES_CODE_RANGE_OUT_OF_BOUNDS<br> 287 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 288 */ 289 std::function<void(const RawAddress &rawAddr, uint8_t scope, uint16_t uidCounter, 290 const std::vector<AvrcMpItem> &mpItems, const std::vector<AvrcMeItem> &meItems, int result, int detail)> 291 onGetFolderItems; 292 293 /** 294 * @brief Responds the data of the <b>GetItemAttributes</b>. 295 * 296 * @param[in] rawAddr The address of the bluetooth device. 297 * @param[in] attributes The list of media attributes. 298 * @param[in] values The list of the value of this attribute. 299 * @param[in] result The result of the execution.<br> 300 * @a BT_SUCCESS : Execute success.<br> 301 * @a RET_NO_SUPPORT : Not support.<br> 302 * @a RET_BAD_STATUS : Execute failure. 303 * @param[in] detail The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 304 * @a AVRC_ES_CODE_NO_ERROR<br> 305 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 306 * @a AVRC_ES_CODE_UID_CHANGED<br> 307 * @a AVRC_ES_CODE_DOES_NOT_EXIST<br> 308 * @a AVRC_ES_CODE_INVALID_SCOPE<br> 309 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 310 */ 311 std::function<void(const RawAddress &rawAddr, const std::vector<uint32_t> &attributes, 312 const std::vector<std::string> &values, int result, int detail)> 313 onGetItemAttributes; 314 315 /** 316 * @brief Responds the data of the <b>GetTotalNumberOfItems</b>. 317 * 318 * @param[in] rawAddr The address of the bluetooth device. 319 * @param[in] uidCounter The value of the uid counter. 320 * @param[in] numOfItems The number of items in the directory. 321 * @param[in] result The result of the execution.<br> 322 * @a BT_SUCCESS : Execute success.<br> 323 * @a RET_NO_SUPPORT : Not support.<br> 324 * @a RET_BAD_STATUS : Execute failure. 325 * @param[in] detail The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 326 * @a AVRC_ES_CODE_NO_ERROR<br> 327 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 328 * @a AVRC_ES_CODE_UID_CHANGED<br> 329 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 330 */ 331 std::function<void(const RawAddress &rawAddr, uint16_t uidCounter, uint32_t numOfItems, int result, int detail)> 332 onGetTotalNumberOfItems; 333 334 /** 335 * @brief Informs that receive the command of the <b>PlayItem</b>. 336 * 337 * @param[in] rawAddr The address of the bluetooth device. 338 * @param[in] status The current status of playing. Refer to <b>PlayItem</b> 339 * @param[in] result The result of the execution.<br> 340 * @a BT_SUCCESS : Execute success.<br> 341 * @a RET_NO_SUPPORT : Not support.<br> 342 * @a RET_BAD_STATUS : Execute failure. 343 * @param[in] detail The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 344 * @a AVRC_ES_CODE_INVALID_COMMAND<br> 345 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 346 * @a AVRC_ES_CODE_INVALID_PARAMETER<br> 347 * @a AVRC_ES_CODE_PARAMETER_CONTENT_ERROR<br> 348 * @a AVRC_ES_CODE_NO_ERROR<br> 349 * @a AVRC_ES_CODE_UID_CHANGED<br> 350 * @a AVRC_ES_CODE_RESERVED<br> 351 * @a AVRC_ES_CODE_DOES_NOT_EXIST<br> 352 * @a AVRC_ES_CODE_INVALID_SCOPE 353 * @a AVRC_ES_CODE_FOLDER_ITEM_IS_NOT_PLAYABLE 354 * @a AVRC_ES_CODE_MEDIA_IN_USE 355 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 356 * @a AVRC_ES_CODE_FOLDER_ITEM_IS_NOT_PLAYABLE 357 */ 358 std::function<void(const RawAddress &rawAddr, int result, int detail)> onPlayItem; 359 360 /** 361 * @brief Responds the data of the <b>AddToNowPlaying</b>. 362 * 363 * @param[in] rawAddr The address of the bluetooth device. 364 * @param[in] result The result of the execution.<br> 365 * @a BT_SUCCESS : Execute success.<br> 366 * @a RET_NO_SUPPORT : Not support.<br> 367 * @a RET_BAD_STATUS : Execute failure. 368 * @param[in] detail The detail result of the execution. Refer to <b>AvrcEsCode</b>.<br> 369 * @a AVRC_ES_CODE_NO_ERROR<br> 370 * @a AVRC_ES_CODE_INTERNAL_ERROR<br> 371 * @a AVRC_ES_CODE_UID_CHANGED<br> 372 * @a AVRC_ES_CODE_DOES_NOT_EXIST<br> 373 * @a AVRC_ES_CODE_INVALID_SCOPE<br> 374 * @a AVRC_ES_CODE_FOLDER_ITEM_IS_NOT_PLAYABLE<br> 375 * @a AVRC_ES_CODE_MEDIA_IN_USE<br> 376 * @a AVRC_ES_CODE_NOW_PLAYING_LIST_FULL<br> 377 * @a AVRC_ES_CODE_NO_AVAILABLE_PLAYERS 378 */ 379 std::function<void(const RawAddress &rawAddr, int result, int detail)> onAddToNowPlaying; 380 381 /** 382 * @brief Responds the data of the <b>SetAbsoluteVolume</b>. 383 * 384 * @param[in] rawAddr The address of the bluetooth device. 385 * @param[in] volume The percentage of the absolute volume. Refer to <b>AvrcAbsoluteVolume</b>. 386 * @param[in] result The result of the execution.<br> 387 * @a BT_SUCCESS : Execute success.<br> 388 * @a RET_NO_SUPPORT : Not support.<br> 389 * @a RET_BAD_STATUS : Execute failure. 390 */ 391 std::function<void(const RawAddress &rawAddr, uint8_t volume, int result)> onSetAbsoluteVolume; 392 393 /** 394 * @brief Responds the data of the notification <b>AVRC_CT_EVENT_ID_PLAYBACK_STATUS_CHANGED</b>. 395 * 396 * @param[in] rawAddr The address of the bluetooth device. 397 * @param[in] playStatus The current status of playing. Refer to <b>AvrcPlayStatus</b>. 398 * @param[in] result The result of the execution.<br> 399 * @a AVRC_ES_CODE_NO_ERROR : Execute success.<br> 400 * @a AVRC_ES_CODE_NOTIFICATION_CHANGED : Registered notification changed<br> 401 */ 402 std::function<void(const RawAddress &rawAddr, uint8_t playStatus, int result)> onPlaybackStatusChanged; 403 404 /** 405 * @brief Responds the data of the notification <b>AVRC_CT_EVENT_ID_TRACK_CHANGED</b>. 406 * 407 * @param[in] rawAddr The address of the bluetooth device. 408 * @param[in] uid The unique ID of media item. 409 * @param[in] result The result of the execution.<br> 410 * @a AVRC_ES_CODE_NO_ERROR : Execute success.<br> 411 * @a AVRC_ES_CODE_NOTIFICATION_CHANGED : Registered notification changed<br> 412 */ 413 std::function<void(const RawAddress &rawAddr, uint64_t uid, int result)> onTrackChanged; 414 415 /** 416 * @brief Responds the data of the notification <b>AVRC_CT_EVENT_ID_TRACK_REACHED_END</b>. 417 * 418 * @param[in] rawAddr The address of the bluetooth device. 419 * @param[in] result The result of the execution.<br> 420 * @a AVRC_ES_CODE_NO_ERROR : Execute success.<br> 421 * @a AVRC_ES_CODE_NOTIFICATION_CHANGED : Registered notification changed<br> 422 */ 423 std::function<void(const RawAddress &rawAddr, int result)> onTrackReachedEnd; 424 425 /** 426 * @brief Responds the data of the notification <b>AVRC_CT_EVENT_ID_TRACK_REACHED_START</b>. 427 * 428 * @param[in] rawAddr The address of the bluetooth device. 429 * @param[in] result The result of the execution.<br> 430 * @a AVRC_ES_CODE_NO_ERROR : Execute success.<br> 431 * @a AVRC_ES_CODE_NOTIFICATION_CHANGED : Registered notification changed<br> 432 */ 433 std::function<void(const RawAddress &rawAddr, int result)> onTrackReachedStart; 434 435 /** 436 * @brief Responds the data of the notification <b>AVRC_CT_EVENT_ID_PLAYBACK_POS_CHANGED</b>. 437 * 438 * @param[in] rawAddr The address of the bluetooth device. 439 * @param[in] playbackPos Current playback position in millisecond. 440 * @param[in] result The result of the execution.<br> 441 * @a AVRC_ES_CODE_NO_ERROR : Execute success.<br> 442 * @a AVRC_ES_CODE_NOTIFICATION_CHANGED : Registered notification changed<br> 443 */ 444 std::function<void(const RawAddress &rawAddr, uint32_t playbackPos, int result)> onPlaybackPosChanged; 445 446 /** 447 * @brief Responds the data of the notification <b>AVRC_CT_EVENT_ID_PLAYER_APPLICATION_SETTING_CHANGED</b>. 448 * 449 * @param[in] rawAddr The address of the bluetooth device. 450 * @param[in] attribute The attribute of the player application setting. Refer to <b>AvrcPlayerAttribute</b>. 451 * @param[in] values The values associated witch the attribute. 452 * @param[in] result The result of the execution.<br> 453 * @a AVRC_ES_CODE_NO_ERROR : Execute success.<br> 454 * @a AVRC_ES_CODE_NOTIFICATION_CHANGED : Registered notification changed<br> 455 */ 456 std::function<void(const RawAddress &rawAddr, const std::vector<uint8_t> &attributes, 457 const std::vector<uint8_t> &values, int result)> 458 onPlayerApplicationSettingChanged; 459 460 /** 461 * @brief Responds the data of the notification <b>AVRC_CT_EVENT_ID_NOW_PLAYING_CONTENT_CHANGED</b>. 462 * 463 * @param[in] rawAddr The address of the bluetooth device. 464 * @param[in] result The result of the execution.<br> 465 * @a AVRC_ES_CODE_NO_ERROR : Execute success.<br> 466 * @a AVRC_ES_CODE_NOTIFICATION_CHANGED : Registered notification changed<br> 467 */ 468 std::function<void(const RawAddress &rawAddr, int result)> onNowPlayingContentChanged; 469 470 /** 471 * @brief Responds the data of the notification <b>AVRC_CT_EVENT_ID_AVAILABLE_PLAYERS_CHANGED</b>. 472 * 473 * @param[in] rawAddr The address of the bluetooth device. 474 * @param[in] result The result of the execution.<br> 475 * @a AVRC_ES_CODE_NO_ERROR : Execute success.<br> 476 * @a AVRC_ES_CODE_NOTIFICATION_CHANGED : Registered notification changed<br> 477 */ 478 std::function<void(const RawAddress &rawAddr, int result)> onAvailablePlayersChanged; 479 480 /** 481 * @brief Responds the data of the notification <b>AVRC_CT_EVENT_ID_ADDRESSED_PLAYER_CHANGED</b>. 482 * 483 * @param[in] rawAddr The address of the bluetooth device. 484 * @param[in] playerId The unique media player id. 485 * @param[in] uidCounter The UID counter shall be incremented every time the TG makes an update. 486 * @param[in] result The result of the execution.<br> 487 * @a AVRC_ES_CODE_NO_ERROR : Execute success.<br> 488 * @a AVRC_ES_CODE_NOTIFICATION_CHANGED : Registered notification changed<br> 489 */ 490 std::function<void(const RawAddress &rawAddr, uint16_t playerId, uint16_t uidCounter, int result)> 491 onAddressedPlayerChanged; 492 493 /** 494 * @brief Responds the data of the notification <b>AVRC_CT_EVENT_ID_UIDS_CHANGED</b>. 495 * 496 * @param[in] rawAddr The address of the bluetooth device. 497 * @param[in] uidCounter The UID counter shall be incremented every time the TG makes an update. 498 * @param[in] result The result of the execution.<br> 499 * @a AVRC_ES_CODE_NO_ERROR : Execute success.<br> 500 * @a AVRC_ES_CODE_NOTIFICATION_CHANGED : Registered notification changed<br> 501 */ 502 std::function<void(const RawAddress &rawAddr, uint16_t uidCounter, int result)> onUidChanged; 503 504 /** 505 * @brief Responds the data of the notification <b>AVRC_CT_EVENT_ID_VOLUME_CHANGED</b>. 506 * 507 * @param[in] rawAddr The address of the bluetooth device. 508 * @param[in] volume The percentage of the absolute volume. Refer to <b>AvrcAbsoluteVolume</b>. 509 * @param[in] result The result of the execution.<br> 510 * @a AVRC_ES_CODE_NO_ERROR : Execute success.<br> 511 * @a AVRC_ES_CODE_NOTIFICATION_CHANGED : Registered notification changed<br> 512 */ 513 std::function<void(const RawAddress &rawAddr, uint8_t volume, int result)> onVolumeChanged; 514 }; 515 516 /** 517 * @brief A constructor used to create an <b>AvrcCtProfile</b> instance. 518 */ 519 AvrcCtProfile(uint16_t features, uint32_t companyId, uint16_t controlMtu, uint16_t browseMtu, uint8_t maxFragments, 520 utility::Dispatcher *dispatcher, AvctChannelEventCallback eventCallback, AvctMsgCallback msgCallback); 521 522 /** 523 * @brief A destructor used to delete the <b>AvrcCtProfile</b> instance. 524 */ 525 ~AvrcCtProfile(); 526 527 /****************************************************************** 528 * REGISTER / UNREGISTER OBSERVER * 529 ******************************************************************/ 530 531 /** 532 * @brief Registers the observer. 533 * 534 * @param observer The pointer to the instance of the <b>AvrcCtProfile::Observer</b> struct. 535 */ 536 void RegisterObserver(AvrcCtProfile::Observer *observer); 537 538 /** 539 * @brief Unregisters the observer. 540 */ 541 void UnregisterObserver(void); 542 543 /****************************************************************** 544 * ENABLE / DISABLE * 545 ******************************************************************/ 546 547 /** 548 * @brief Enables the AVRCP CT profile. 549 * 550 * @param[in] isTgEnabled The config of the TG is true or not. 551 * 552 * @return The result of the method execution. 553 * @retval BT_SUCCESS Execute success. 554 * @retval RET_BAD_STATUS Execute failure. 555 */ 556 int Enable(bool isTgEnabled); 557 558 /** 559 * @brief Disables the AVRCP CT profile. 560 * 561 * @return The result of the method execution. 562 * @retval BT_SUCCESS Execute success. 563 * @retval RET_BAD_STATUS Execute failure. 564 */ 565 int Disable(void); 566 567 /** 568 * @brief Sets the flag of the profile enabled or not. 569 * 570 * @param[in] isEnabled The service is enabled or not. 571 * @a true : The service is enabled.<br> 572 * @a false : The service is disabled.<br> 573 */ 574 static void SetEnableFlag(bool isEnabled); 575 576 /****************************************************************** 577 * CONNECTION * 578 ******************************************************************/ 579 580 /** 581 * @brief Gets the connected devices. 582 * 583 * @return The list of the instance of the <b>RawAddress</b> class. 584 */ 585 std::vector<RawAddress> GetConnectedDevices(void); 586 587 /** 588 * @brief Gets the devices of the specified states. 589 * 590 * @param[in] states The connection states. Refer to <b>BTConnectState</b>. 591 * @return The list of the instance of the <b>RawAddress</b> class. 592 */ 593 std::vector<RawAddress> GetDevicesByStates(const std::vector<int> &states); 594 595 /** 596 * @brief Gets the connection state of the specified bluetooth device. 597 * 598 * @param[in] rawAddr The address of the bluetooth device. 599 * @return The connection state. Refer to <b>BTConnectState</b>. 600 */ 601 int GetDeviceState(const RawAddress &rawAddr); 602 603 /** 604 * @brief Gets the maximum number of connections. 605 * 606 * @return The maximum number of connections. 607 */ 608 int GetMaxConnectNum(void); 609 610 /** 611 * @brief Connects to the connection of the control channel. 612 * 613 * @param[in] rawAddr The address of the bluetooth device. 614 * @return The result of the method execution. 615 * @retval BT_SUCCESS Execute success. 616 * @retval RET_BAD_STATUS Execute failure. 617 */ 618 int Connect(const RawAddress &rawAddr) const; 619 620 /** 621 * @brief Disconnects the connection of the control channel. 622 * 623 * @param[in] rawAddr The address of the bluetooth device. 624 * @return The result of the method execution. 625 * @retval BT_SUCCESS Execute success. 626 * @retval RET_BAD_STATUS Execute failure. 627 */ 628 int Disconnect(const RawAddress &rawAddr) const; 629 630 /** 631 * @brief Connects to the connection of the browse channel. 632 * 633 * @param[in] rawAddr The address of the bluetooth device. 634 * @return The result of the method execution. 635 * @retval BT_SUCCESS Execute success. 636 * @retval RET_BAD_STATUS Execute failure. 637 */ 638 static int ConnectBr(const RawAddress &rawAddr); 639 640 /** 641 * @brief Disconnects the connection of the browse channel. 642 * 643 * @param[in] rawAddr The address of the bluetooth device. 644 * @return The result of the method execution. 645 * @retval BT_SUCCESS Execute success. 646 * @retval RET_BAD_STATUS Execute failure. 647 */ 648 static int DisconnectBr(const RawAddress &rawAddr); 649 650 /** 651 * @brief Gets the connection states. 652 * 653 * @return The connection states. The values are in bits. 654 */ 655 int GetConnectState(void); 656 657 /****************************************************************** 658 * PASS THROUGH COMMAND * 659 ******************************************************************/ 660 661 /** 662 * @brief Sends the press command of the <b>PASS THROUGH</b>. 663 * 664 * @param[in] rawAddr The address of the bluetooth device. 665 * @param[in] button The value of the key operation. Refer to <b>AvrcKeyOperation</b>. 666 */ 667 void SendPressButtonCmd(const RawAddress &rawAddr, uint8_t button); 668 669 /** 670 * @brief Sends the release command of the <b>PASS THROUGH</b>. 671 * 672 * @param[in] rawAddr The address of the bluetooth device. 673 * @param[in] button The value of the key operation. Refer to <b>AvrcKeyOperation</b>. 674 */ 675 void SendReleaseButtonCmd(const RawAddress &rawAddr, uint8_t button); 676 677 /** 678 * @brief Gets the size of the <b>PASS THROUGH</b> command queue. 679 * 680 * @param[in] rawAddr The address of the bluetooth device. 681 * @return The result of the method execution. 682 * @retval true The command queue is full. 683 * @retval false The command queue is not full. 684 */ 685 bool IsPassQueueFull(const RawAddress &rawAddr); 686 687 /****************************************************************** 688 * UNIT INFO / SUB UNIT INFO COMMAND * 689 ******************************************************************/ 690 691 /** 692 * @brief Sends the command of the <b>UNIT INFO</b>. 693 * 694 * @param[in] rawAddr The address of the bluetooth device. 695 */ 696 void SendUnitCmd(const RawAddress &rawAddr); 697 698 /** 699 * @brief Sends the command of the <b>SUB UNIT INFO</b>. 700 * 701 * @param[in] rawAddr The address of the bluetooth device. 702 */ 703 void SendSubUnitCmd(const RawAddress &rawAddr); 704 705 /** 706 * @brief Gets the size of the <b>UNIT INFO</b> and <b>SUB UNIT INFO</b> command queue. 707 * 708 * @param[in] rawAddr The address of the bluetooth device. 709 * @return The result of the method execution. 710 * @retval true The command queue is full. 711 * @retval false The command queue is not full. 712 */ 713 static bool IsUnitQueueFull(const RawAddress &rawAddr); 714 715 /****************************************************************** 716 * VENDOR COMMAND * 717 ******************************************************************/ 718 719 /** 720 * @brief Sends the command of the <b>GetCapabilities</b>. 721 * 722 * @details This is sent by CT to get the capabilities of the peer device 723 * 724 * @param[in] rawAddr The address of the bluetooth device. 725 * @param[in] capabilityId Specific capability requested 726 */ 727 void SendGetCapabilitiesCmd(const RawAddress &rawAddr, uint8_t capabilityId); 728 729 /** 730 * @brief Sends the command of the <b>ListPlayerApplicationSettingAttributes</b>. 731 * 732 * @param[in] rawAddr The address of the bluetooth device. 733 */ 734 void SendListPlayerApplicationSettingAttributesCmd(const RawAddress &rawAddr); 735 736 /** 737 * @brief Sends the command of the <b>ListPlayerApplicationSettingValues</b>. 738 * 739 * @param[in] rawAddr The address of the bluetooth device. 740 * @param[in] attribute The attribute of the player application setting. 741 */ 742 void SendListPlayerApplicationSettingValuesCmd(const RawAddress &rawAddr, uint8_t attribute); 743 744 /** 745 * @brief Sends the command of the <b>GetCurrentPlayerApplicationSettingValue</b>. 746 * 747 * @param[in] rawAddr The address of the bluetooth device. 748 * @param[in] attributes The attribute of the player application settings. 749 */ 750 void SendGetCurrentPlayerApplicationSettingValueCmd( 751 const RawAddress &rawAddr, const std::vector<uint8_t> &attributes); 752 753 /** 754 * @brief Sends the command of the <b>SetPlayerApplicationSettingValue</b>. 755 * 756 * @param[in] rawAddr The address of the bluetooth device. 757 * @param[in] attributes The attribute of the player application settings. 758 * @param[in] values The value of the player application setting attributes. 759 */ 760 void SendSetPlayerApplicationSettingValueCmd( 761 const RawAddress &rawAddr, const std::vector<uint8_t> &attributes, const std::vector<uint8_t> &values); 762 763 /** 764 * @brief Sends the command of the <b>GetPlayerApplicationSettingAttributeText</b>. 765 * 766 * @details Switch to the thread of the AVRCP CT service in this method. 767 * @param[in] rawAddr The address of the bluetooth device. 768 * @param[in] attributes The attribute of the player application settings. 769 */ 770 void SendGetPlayerApplicationSettingAttributeTextCmd( 771 const RawAddress &rawAddr, const std::vector<uint8_t> &attributes); 772 773 /** 774 * @brief Sends the command of the <b>GetPlayerApplicationSettingValueText</b>. 775 * 776 * @details Switch to the thread of the AVRCP CT service in this method. 777 * @param[in] rawAddr The address of the bluetooth device. 778 * @param[in] attributeId Player application setting attribute ID. 779 * @param[in] values Player application setting value ID. 780 */ 781 void SendGetPlayerApplicationSettingValueTextCmd( 782 const RawAddress &rawAddr, uint8_t attributeId, const std::vector<uint8_t> &values); 783 784 /** 785 * @brief Sends the command of the <b>GetElementAttributes</b>. 786 * 787 * @details Switch to the thread of the AVRCP CT service in this function. 788 * @param[in] rawAddr The address of the attribute. 789 * @param[in] identifier Unique identifier to identify an element on TG 790 * @param[in] attributes Specifies the attribute ID for the attributes to be retrieved 791 */ 792 void SendGetElementAttributesCmd( 793 const RawAddress &rawAddr, uint64_t identifier, const std::vector<uint32_t> &attributes); 794 795 /** 796 * @brief Sends the command of the <b>GetPlayStatus</b>. 797 * 798 * @param[in] rawAddr The address of the bluetooth device. 799 */ 800 void SendGetPlayStatusCmd(const RawAddress &rawAddr); 801 802 /** 803 * @brief Sends the command of the <b>RequestContinuingResponse</b>. 804 * 805 * @param[in] rawAddr The address of the bluetooth device. 806 * @param[in] pduId The PDU ID which wants to request. 807 */ 808 void SendRequestContinuingResponseCmd(const RawAddress &rawAddr, uint8_t pduId); 809 810 /** 811 * @brief Sends the command of the <b>AbortContinuingResponse</b>. 812 * 813 * @details Switch to the thread of the AVRCP CT service in this method. 814 * @param[in] rawAddr The address of the bluetooth device. 815 * @param[in] pduId The PDU ID which wants to abort. 816 */ 817 void SendAbortContinuingResponseCmd(const RawAddress &rawAddr, uint8_t pduId); 818 819 /** 820 * @brief Sends the command of the <b>SetAddressedPlayer</b>. 821 * 822 * @param[in] rawAddr The address of the bluetooth device. 823 * @param[in] playerId The unique media player id. 824 */ 825 void SendSetAddressedPlayerCmd(const RawAddress &rawAddr, uint16_t playerId); 826 827 /** 828 * @brief Sends the command of the <b>PlayItem</b>. 829 * 830 * @param[in] rawAddr The address of the bluetooth device. 831 * @param[in] scope The scope in which media content navigation may take place. Refer to <b>AvrcMediaScope</b>. 832 * @param[in] uid The unique ID of media item. 833 * @param[in] uidCounter The UID counter shall be incremented every time the TG makes an update. 834 */ 835 void SendPlayItemCmd(const RawAddress &rawAddr, uint8_t scope, uint64_t uid, uint16_t uidCounter); 836 837 /** 838 * @brief Sends the command of the <b>AddToNowPlaying</b>. 839 * 840 * @param[in] rawAddr The address of the bluetooth device. 841 * @param[in] scope The scope in which media content navigation may take place. Refer to <b>AvrcMediaScope</b>. 842 * @param[in] uid The UID of the media element item or folder item. 843 * @param[in] uidCounter The UID Counter. 844 */ 845 void SendAddToNowPlayingCmd(const RawAddress &rawAddr, uint8_t scope, uint64_t uid, uint16_t uidCounter); 846 847 /** 848 * @brief Sends the command of the <b>SetAbsoluteVolume</b>. 849 * 850 * @param[in] rawAddr The address of the bluetooth device. 851 * @param[in] volume The percentage of the absolute volume. Refer to <b>AvrcAbsoluteVolume</b>. 852 */ 853 void SendSetAbsoluteVolumeCmd(const RawAddress &rawAddr, uint8_t volume); 854 855 /** 856 * @brief Sends the command of the <b>RegisterNotification</b>. 857 * 858 * @param[in] rawAddr The address of the bluetooth device. 859 * @param[in] eventId The event for which the requires notification. Refer to <b>events</b>. 860 * @param[in] interval The specifies the time interval (in seconds) at which the change in playback position will be 861 * notified. 862 */ 863 void EnableNotification(const RawAddress &rawAddr, const std::vector<uint8_t> &events, 864 uint32_t interval = AVRC_PLAYBACK_INTERVAL_1_SEC); 865 866 /** 867 * @brief Sends the command of the <b>RegisterNotification</b>. 868 * 869 * @param[in] rawAddr The address of the bluetooth device. 870 * @param[in] events The event for which the requires notification. Refer to <b>events</b>. 871 */ 872 static void DisableNotification(const RawAddress &rawAddr, const std::vector<uint8_t> &events); 873 874 /** 875 * @brief Gets the size of the <b>VENDOR DEPENDENT</b> command queue. 876 * 877 * @param[in] rawAddr The address of the bluetooth device. 878 * @return The result of the method execution. 879 * @retval true The command queue is full. 880 * @retval false The command queue is not full. 881 */ 882 bool IsVendorQueueFull(const RawAddress &rawAddr); 883 884 /****************************************************************** 885 * BROWSING COMMAND * 886 ******************************************************************/ 887 888 /** 889 * @brief Sends the command of the <b>SetBrowsedPlayer</b>. 890 * 891 * @param[in] rawAddr The address of the bluetooth device. 892 * @param[in] playerId The unique media player id. 893 */ 894 void SendSetBrowsedPlayerCmd(const RawAddress &rawAddr, uint16_t playerId); 895 896 /** 897 * @brief Sends the command of the <b>ChangePath</b>. 898 * 899 * @param[in] rawAddr The address of the bluetooth device. 900 * @param[in] uidCounter The value of the uid counter. 901 * @param[in] direction The flag of the navigation. Refer to <b>AvrcFolderDirection</b>. 902 * @param[in] folderUid The UID of the folder to navigate to. This may be retrieved via a GetFolderItems command. 903 * If the navigation command is Folder Up this field is reserved. 904 */ 905 void SendChangePathCmd(const RawAddress &rawAddr, uint16_t uidCounter, uint8_t direction, uint64_t folderUid); 906 907 /** 908 * @brief Sends the command of the <b>GetFolderItems</b>. 909 * 910 * @param[in] rawAddr The address of the bluetooth device. 911 * @param[in] scope The scope in which media content navigation may take place. Refer to <b>AvrcMediaScope</b>. 912 * @param[in] startItem The offset within the listing of the item, which should be the first returned item. The 913 * first element in the listing is at offset 0. 914 * @param[in] endItem The offset within the listing of the item which should be the final returned item. If this 915 * is set to a value beyond what is available, the TG shall return items from the provided Start Item index to the 916 * index of the final item. If the End Item index is smaller than the Start Item index, the TG shall return an 917 * error. If CT requests too many items, TG can respond with a sub-set of the requested items. 918 * @param[in] attributes The list of media attributes. 919 */ 920 void SendGetFolderItemsCmd(const RawAddress &rawAddr, uint8_t scope, uint32_t startItem, uint32_t endItem, 921 const std::vector<uint32_t> &attributes); 922 923 /** 924 * @brief Sends the command of the <b>GetItemAttributes</b>. 925 * 926 * @param[in] rawAddr The address of the bluetooth device. 927 * @param[in] scope The scope in which media content navigation may take place. Refer to <b>AvrcMediaScope</b>. 928 * @param[in] uid The UID of the media element item or folder item. 929 * @param[in] uidCounter The UID Counter. 930 * @param[in] attributes The list of media attributes. 931 */ 932 void SendGetItemAttributesCmd(const RawAddress &rawAddr, uint8_t scope, uint64_t uid, uint16_t uidCounter, 933 const std::vector<uint32_t> &attributes); 934 935 /** 936 * @brief Sends the command of the <b>GetTotalNumberOfItems</b>. 937 * 938 * @param[in] rawAddr The address of the bluetooth device. 939 * @param[in] scope The scope in which media content navigation may take place. Refer to <b>AvrcMediaScope</b>. 940 */ 941 void SendGetTotalNumberOfItemsCmd(const RawAddress &rawAddr, uint8_t scope); 942 943 /** 944 * @brief Gets the size of the <b>BROWSING</b> command queue. 945 * 946 * @param[in] rawAddr The address of the bluetooth device. 947 * @return The result of the method execution. 948 * @retval true The command queue is full. 949 * @retval false The command queue is not full. 950 */ 951 bool IsBrowseQueueFull(const RawAddress &rawAddr); 952 953 /** 954 * @brief Whether peerAddr support absolute volume command. 955 * 956 * @param[in] rawAddr The address of the bluetooth device. 957 * @return The result of compatibility. 958 */ 959 bool IsDisableAbsoluteVolume(const RawAddress &rawAddr); 960 961 /** 962 * @brief Whether the browse channel connected. 963 * 964 * @param[in] rawAddr The address of the bluetooth device. 965 * @return The result. 966 */ 967 bool IsBrowsingConnected(const RawAddress &rawAddr); 968 969 /** 970 * @brief Processes events received from the AVCTP. 971 * 972 * @param[in] rawAddr The address of the bluetooth device. 973 * @param[in] connectId The ID of the connection. 974 * @param[in] event The event from the underlying module. 975 * @param[in] result The result of the event. 976 * @param[in] context The context is used to send the event in the callback. 977 */ 978 void ProcessChannelEvent( 979 const RawAddress &rawAddr, uint8_t connectId, uint8_t event, uint16_t result, void *context) const; 980 981 void ProcessChannelEventConnectIndEvt( 982 const RawAddress &rawAddr, uint8_t connectId, uint8_t event, uint16_t result, void *context) const; 983 void ProcessChannelEventConnectCfmEvt( 984 const RawAddress &rawAddr, uint8_t connectId, uint8_t event, uint16_t result, void *context) const; 985 void ProcessChannelEventDisconnectIndEvt( 986 const RawAddress &rawAddr, uint8_t connectId, uint8_t event, uint16_t result, void *context) const; 987 void ProcessChannelEventDisconnectCfmEvt( 988 const RawAddress &rawAddr, uint8_t connectId, uint8_t event, uint16_t result, void *context) const; 989 990 void ProcessChannelEventBrConnectIndEvt( 991 const RawAddress &rawAddr, uint8_t connectId, uint8_t event, uint16_t result, void *context) const; 992 void ProcessChannelEventBrConnectCfmEvt( 993 const RawAddress &rawAddr, uint8_t connectId, uint8_t event, uint16_t result, void *context) const; 994 995 /** 996 * @brief Processes messages received from the AVCTP. 997 * 998 * @param[in] connectId The ID of the connection. 999 * @param[in] crType The type used to distinguish between the command frame and the response frame. 1000 * @param[in] chType The type used to distinguish the message returned from the control channel or the browse 1001 * channel. 1002 * @param[in] pkt The message sent by the peer bluetooth device. 1003 * @param[in] context The context is used to send the message in the callback. 1004 */ 1005 void ProcessChannelMessage( 1006 uint8_t connectId, uint8_t label, uint8_t crType, uint8_t chType, Packet *pkt, void *context); 1007 1008 private: 1009 /// The flag is used to indicate that the AVRCP CT profile is enabled or not. 1010 static bool g_isEnabled; 1011 /// The features supported by the AVRCP CT profile. 1012 uint32_t features_; 1013 /// The SIG company ID. 1014 uint32_t companyId_; 1015 /// The max MTU size of the control channel. 1016 uint16_t controlMtu_; 1017 /// The max MTU size of the browse channel. 1018 uint16_t browseMtu_; 1019 /// The max fragments of the control channel. 1020 uint8_t maxFragments_; 1021 /// The dispatcher that is used to switch to the thread of the AVRCP CT service. 1022 utility::Dispatcher *dispatcher_ {nullptr}; 1023 /// The connect id of the passive connection. 1024 uint8_t connectId_; 1025 /// The pointer to the observer of the <b>AvrcCtProfile</b> class. 1026 AvrcCtProfile::Observer *myObserver_ {nullptr}; 1027 /// The callback function, which registers into the AVCTP for receiving the events. 1028 AvctChannelEventCallback eventCallback_ {nullptr}; 1029 /// The callback function, which registers into the AVCTP for receiving the messages. 1030 AvctMsgCallback msgCallback_ {nullptr}; 1031 // Locks the local variable in a multi-threaded environment. 1032 std::recursive_mutex mutex_ {}; 1033 1034 /** 1035 * @brief A deleted default constructor. 1036 */ 1037 AvrcCtProfile() = delete; 1038 1039 /****************************************************************** 1040 * ENABLE / DISABLE * 1041 ******************************************************************/ 1042 1043 /** 1044 * @brief Checks whether the AVRCP TG profile is enabled. 1045 * 1046 * @return The result of the method execution. 1047 * @retval true The profile is enabled. 1048 * @retval false The profile is disabled. 1049 */ 1050 static bool IsEnabled(void); 1051 1052 /****************************************************************** 1053 * PASS THROUGH COMMAND * 1054 ******************************************************************/ 1055 1056 /** 1057 * @brief Sends the command of the <b>PASS THROUGH</b>. 1058 * 1059 * @param[in] rawAddr The address of the bluetooth device. 1060 * @param[in] pkt The reference of the shared pointer to the instance of the <b>AvrcCtPassPacket</b> class. 1061 */ 1062 void SendPassCmd(const RawAddress &rawAddr, const std::shared_ptr<AvrcCtPassPacket> &pkt); 1063 1064 /** 1065 * @brief Sends the next command of the <b>PASS THROUGH</b> in the cache queue. 1066 * 1067 * @param[in] rawAddr The address of the bluetooth device. 1068 */ 1069 void SendNextPassCmd(const RawAddress &rawAddr); 1070 1071 /** 1072 * @brief Receives the response of the <b>PASS THROUGH</b>. 1073 * 1074 * @param[in] rawAddr The address of the bluetooth device. 1075 * @param[in] pkt The frame packet. 1076 */ 1077 void ReceivePassRsp(const RawAddress &rawAddr, Packet *pkt); 1078 1079 /** 1080 * @brief Informs that revive the button operation. 1081 * 1082 * @param[in] rawAddr The address of the bluetooth device. 1083 * @param[in] button The value of the key operation. 1084 * @param[in] state The value of the key state. 1085 * @param[in] result The result of the method execution. 1086 * @a BT_SUCCESS : Execute success. 1087 * @a RET_NO_SUPPORT : Not support. 1088 * @a RET_BAD_STATUS : Execute failure. 1089 */ 1090 void InformPassRsp(const RawAddress &rawAddr, uint8_t button, uint8_t state, int result) const; 1091 1092 /** 1093 * @brief Processes the timeout of command of the <b>PASS THROUGH</b>. 1094 * 1095 * @param[in] rawAddr The address of the bluetooth device. 1096 */ 1097 void ProcessPassTimeout(RawAddress rawAddr, uint8_t key, uint8_t state); 1098 1099 /** 1100 * @brief The callback function, which registers into the <b>utility::Timer</b>. 1101 * 1102 * @details This function switches to the thread of the AVRCP TG service firstly, then processes the timeout. 1103 * @param[in] rawAddr The address of the bluetooth device. 1104 */ 1105 void PassTimeoutCallback(const RawAddress &rawAddr, uint8_t key, uint8_t state); 1106 1107 /****************************************************************** 1108 * UNIT INFO / SUB UNIT INFO COMMAND * 1109 ******************************************************************/ 1110 1111 /** 1112 * @brief Sends the command of the <b>UNIT INFO</b> or <b>SUB UNIT INFO</b>. 1113 * 1114 * @param[in] rawAddr The address of the bluetooth device. 1115 */ 1116 void SendNextUnitCmd(const RawAddress &rawAddr); 1117 1118 /** 1119 * @brief Receives the response of the <b>UNIT INFO</b>. 1120 * 1121 * @param[in] rawAddr The address of the bluetooth device. 1122 * @param[in] pkt The frame packet. 1123 */ 1124 void ReceiveUnitRsp(const RawAddress &rawAddr, Packet *pkt); 1125 1126 /** 1127 * @brief Receives the response of the <b>SUB UNIT INFO</b>. 1128 * 1129 * @param[in] rawAddr The address of the bluetooth device. 1130 * @param[in] pkt The frame packet. 1131 */ 1132 void ReceiveSubUnitRsp(const RawAddress &rawAddr, Packet *pkt); 1133 1134 /** 1135 * @brief Processes the timeout of command of the <b>UNIT INFO</b> or <b>SUB UNIT INFO</b>. 1136 * 1137 * @param[in] rawAddr The address of the bluetooth device. 1138 */ 1139 void ProcessUnitTimeout(RawAddress rawAddr); 1140 1141 /** 1142 * @brief The callback function, which registers into the <b>utility::Timer</b>. 1143 * 1144 * @details This function switches to the thread of the AVRCP TG service firstly, then processes the timeout. 1145 * @param[in] rawAddr The address of the bluetooth device. 1146 */ 1147 void UnitTimeoutCallback(const RawAddress &rawAddr); 1148 1149 /****************************************************************** 1150 * VENDOR COMMAND * 1151 ******************************************************************/ 1152 1153 /** 1154 * @brief Sends the command of the <b>VENDOR DEPENDENT</b>. 1155 * 1156 * @param[in] rawAddr The address of the bluetooth device. 1157 * @param[in] pkt The frame packet. 1158 */ 1159 void SendVendorCmd(const RawAddress &rawAddr, const std::shared_ptr<AvrcCtVendorPacket> &pkt, AvrcCtSmEvent event); 1160 1161 /** 1162 * @brief Sends the next command of the <b>VENDOR DEPENDENT</b> in the cache queue. 1163 * 1164 * @param[in] rawAddr The address of the bluetooth device. 1165 */ 1166 void SendNextVendorCmd(const RawAddress &rawAddr); 1167 1168 /** 1169 * @brief Sends the command of the <b>RequestContinuingResponse</b>. 1170 * 1171 * @param[in] rawAddr The address of the bluetooth device. 1172 * @param[in] pduId The unique ID of the command. 1173 */ 1174 void SendVendorContinueCmd(const RawAddress &rawAddr, uint8_t pduId); 1175 1176 /** 1177 * @brief Sends the command of the <b>AbortContinuingResponse</b>. 1178 * 1179 * @param[in] rawAddr The address of the bluetooth device. 1180 * @param[in] pduId The unique ID of the command. 1181 */ 1182 void SendVendorAbortCmd(const RawAddress &rawAddr, uint8_t pduId) const; 1183 1184 /** 1185 * @brief Receives the response of the <b>GetCapabilities</b>. 1186 * 1187 * @param[in] rawAddr The address of the bluetooth device. 1188 * @param[in] pkt The frame packet. 1189 */ 1190 void ReceiveGetCapabilitiesRsp(const RawAddress &rawAddr, Packet *pkt); 1191 1192 /** 1193 * @brief Receives the response of the <b>ListPlayerApplicationSettingAttributes</b>. 1194 * 1195 * @param[in] rawAddr The address of the bluetooth device. 1196 * @param[in] pkt The frame packet. 1197 */ 1198 void ReceiveListPlayerApplicationSettingAttributesRsp(const RawAddress &rawAddr, Packet *pkt); 1199 1200 /** 1201 * @brief Receives the response of the <b>ListPlayerApplicationSettingValues</b>. 1202 * 1203 * @param[in] rawAddr The address of the bluetooth device. 1204 * @param[in] pkt The frame packet. 1205 */ 1206 void ReceiveListPlayerApplicationSettingValuesRsp(const RawAddress &rawAddr, Packet *pkt); 1207 1208 /** 1209 * @brief Receives the response of the <b>GetCurrentPlayerApplicationSettingValue</b>. 1210 * 1211 * @param[in] rawAddr The address of the bluetooth device. 1212 * @param[in] pkt The frame packet. 1213 */ 1214 void ReceiveGetCurrentPlayerApplicationSettingValueRsp(const RawAddress &rawAddr, Packet *pkt); 1215 1216 /** 1217 * @brief Receives the response of the <b>SetPlayerApplicationSettingValue</b>. 1218 * 1219 * @param[in] rawAddr The address of the bluetooth device. 1220 * @param[in] pkt The frame packet. 1221 */ 1222 void ReceiveSetPlayerApplicationSettingValueRsp(const RawAddress &rawAddr, Packet *pkt); 1223 1224 /** 1225 * @brief Receives the response of the <b>GetPlayerApplicationSettingAttributeText</b>. 1226 * 1227 * @param[in] rawAddr The address of the bluetooth device. 1228 * @param[in] pkt The frame packet. 1229 */ 1230 void ReceiveGetPlayerApplicationSettingAttributeTextRsp(const RawAddress &rawAddr, Packet *pkt); 1231 1232 /** 1233 * @brief Receives the response of the <b>GetPlayerApplicationSettingValueText</b>. 1234 * 1235 * @param[in] rawAddr The address of the bluetooth device. 1236 * @param[in] pkt The frame packet. 1237 */ 1238 void ReceiveGetPlayerApplicationSettingValueTextRsp(const RawAddress &rawAddr, Packet *pkt); 1239 1240 /** 1241 * @brief Receives the response of the <b>GetElementAttributes</b>. 1242 * 1243 * @param[in] rawAddr The address of the bluetooth device. 1244 * @param[in] pkt The packet of the frame. 1245 */ 1246 void ReceiveGetElementAttributesRsp(const RawAddress &rawAddr, Packet *pkt); 1247 1248 /** 1249 * @brief Receives the response of the <b>GetPlayStatus</b>. 1250 * 1251 * @param[in] rawAddr The address of the bluetooth device. 1252 * @param[in] pkt The packet of the frame. 1253 */ 1254 void ReceiveGetPlayStatusRsp(const RawAddress &rawAddr, Packet *pkt); 1255 1256 /** 1257 * @brief Receives the response of the <b>AbortContinuingResponse</b>. 1258 * 1259 * @param[in] rawAddr The address of the bluetooth device. 1260 * @param[in] pkt The frame packet. 1261 */ 1262 void ReceiveAbortContinuingResponseRsp(const RawAddress &rawAddr, Packet *pkt); 1263 1264 /** 1265 * @brief Receives the response of the <b>SetAddressedPlayer</b>. 1266 * 1267 * @param[in] rawAddr The address of the bluetooth device. 1268 * @param[in] pkt The packet of the frame. 1269 */ 1270 void ReceiveSetAddressedPlayerRsp(const RawAddress &rawAddr, Packet *pkt); 1271 1272 /** 1273 * @brief Receives the response of the <b>PlayItem</b>. 1274 * 1275 * @param[in] rawAddr The address of the bluetooth device. 1276 * @param[in] pkt The frame packet. 1277 */ 1278 void ReceivePlayItemRsp(const RawAddress &rawAddr, Packet *pkt); 1279 1280 /** 1281 * @brief Receives the response of the <b>AddToNowPlaying</b>. 1282 * 1283 * @param[in] rawAddr The address of the bluetooth device. 1284 * @param[in] pkt The packet of the frame. 1285 */ 1286 void ReceiveAddToNowPlayingRsp(const RawAddress &rawAddr, Packet *pkt); 1287 1288 /** 1289 * @brief Receives the response of the <b>SetAbsoluteVolume</b>. 1290 * 1291 * @param[in] rawAddr The address of the bluetooth device. 1292 * @param[in] pkt The packet of the frame. 1293 */ 1294 void ReceiveSetAbsoluteVolumeRsp(const RawAddress &rawAddr, Packet *pkt); 1295 1296 /** 1297 * @brief Receives the response of the <b>RegisterNotification</b>. 1298 * 1299 * @param[in] rawAddr The address of the bluetooth device. 1300 * @param[in] pkt The packet of the frame. 1301 */ 1302 void ReceiveRegisterNotificationRsp(const RawAddress &rawAddr, Packet *pkt); 1303 1304 /** 1305 * @brief Inform the notification changed. 1306 * 1307 * @param[in] event The event of the notification. 1308 */ 1309 void InformNotificationChanged( 1310 const RawAddress &rawAddr, const std::shared_ptr<AvrcCtNotifyPacket> ¬ifyPkt, int result); 1311 1312 /** 1313 * @brief Inform the notification changed. 1314 * 1315 * @param[in] event The event of the notification. 1316 */ 1317 void InformPlayerApplicationSettingChanged( 1318 const RawAddress &rawAddr, const std::shared_ptr<AvrcCtNotifyPacket> ¬ifyPkt, int result); 1319 1320 /** 1321 * @brief Receives the response of the <b>VENDOR DEPENDENT AV/C Status</b>. 1322 * 1323 * @param[in] rawAddr The address of the bluetooth device. 1324 * @param[in] pkt The frame packet. 1325 */ 1326 void ReceiveVendorRspAvcStatus(const RawAddress &rawAddr, Packet *pkt); 1327 1328 /** 1329 * @brief Receives the response of the <b>VENDOR DEPENDENT AV/C Control</b>. 1330 * 1331 * @param[in] rawAddr The address of the bluetooth device. 1332 * @param[in] pkt The frame packet. 1333 */ 1334 void ReceiveVendorRspAvcControl(const RawAddress &rawAddr, Packet *pkt); 1335 1336 /** 1337 * @brief Receives the response of the <b>VENDOR DEPENDENT</b>. 1338 * 1339 * @param[in] rawAddr The address of the bluetooth device. 1340 * @param[in] pkt The frame packet. 1341 */ 1342 void ReceiveVendorRsp(const RawAddress &rawAddr, Packet *pkt); 1343 1344 /** 1345 * @brief Processes the timeout of notification command of the <b>VENDOR DEPENDENT</b>. 1346 * 1347 * @param[in] rawAddr The address of the bluetooth device. 1348 */ 1349 void ProcessVendorNotificationTimeout(RawAddress rawAddr); 1350 1351 /** 1352 * @brief Processes the timeout of command of the <b>VENDOR DEPENDENT AV/C Control</b>. 1353 * 1354 * @param[in] rawAddr The address of the bluetooth device. 1355 * @param[in] packet The packet of the AV/C Control 1356 */ 1357 void ProcessVendorAvcControlTimeout(RawAddress rawAddr, const std::shared_ptr<AvrcCtVendorPacket> &packet); 1358 1359 /** 1360 * @brief Processes the timeout of command of the <b>VENDOR DEPENDENT AV/C Status</b>. 1361 * 1362 * @param[in] rawAddr The address of the bluetooth device. 1363 * @param[in] packet The packet of the AV/C Status1 1364 */ 1365 void ProcessVendorAvcStatus1Timeout(RawAddress rawAddr, const std::shared_ptr<AvrcCtVendorPacket> &packet); 1366 1367 /** 1368 * @brief Processes the timeout of command of the <b>VENDOR DEPENDENT AV/C Status</b>. 1369 * 1370 * @param[in] rawAddr The address of the bluetooth device. 1371 * @param[in] packet The packet of the AV/C Status2 1372 */ 1373 void ProcessVendorAvcStatus2Timeout(RawAddress rawAddr, const std::shared_ptr<AvrcCtVendorPacket> &packet); 1374 1375 /** 1376 * @brief Processes the timeout of command of the <b>VENDOR DEPENDENT</b>. 1377 * 1378 * @param[in] rawAddr The address of the bluetooth device. 1379 */ 1380 void ProcessVendorTimeout(RawAddress rawAddr); 1381 1382 /** 1383 * @brief The callback function, which registers into the <b>utility::Timer</b>. 1384 * 1385 * @details This function switches to the thread of the AVRCP CT service firstly, then processes the timeout. 1386 * @param[in] rawAddr The address of the bluetooth device. 1387 */ 1388 void VendorTimeoutCallback(const RawAddress &rawAddr); 1389 1390 /****************************************************************** 1391 * BROWSING COMMAND * 1392 ******************************************************************/ 1393 1394 /** 1395 * @brief Sends the BROWSING command. 1396 * 1397 * @param[in] rawAddr The address of the bluetooth device. 1398 * @param[in] pkt The frame packet. 1399 */ 1400 void SendBrowseCmd(const RawAddress &rawAddr, const std::shared_ptr<AvrcCtBrowsePacket> &pkt, AvrcCtSmEvent event); 1401 1402 /** 1403 * @brief Sends the next BROWSING command saved in the cache queue. 1404 * 1405 * @param[in] rawAddr The address of the bluetooth device. 1406 */ 1407 void SendNextBrowseCmd(const RawAddress &rawAddr); 1408 1409 /** 1410 * @brief Receives the response of the "SetBrowsedPlayer". 1411 * 1412 * @param[in] rawAddr The address of the bluetooth device. 1413 * @param[in] pkt The frame packet. 1414 */ 1415 void ReceiveSetBrowsedPlayerRsp(const RawAddress &rawAddr, Packet *pkt) const; 1416 1417 /** 1418 * @brief Receives the response of the "ChangePath". 1419 * 1420 * @param[in] rawAddr The address of the bluetooth device. 1421 * @param[in] pkt The frame packet. 1422 */ 1423 void ReceiveChangePathRsp(const RawAddress &rawAddr, Packet *pkt) const; 1424 1425 /** 1426 * @brief Receives the response of the "GetFolderItems". 1427 * 1428 * @param[in] rawAddr The address of the bluetooth device. 1429 * @param[in] pkt The frame packet. 1430 */ 1431 void ReceiveGetFolderItemsRsp(const RawAddress &rawAddr, Packet *pkt) const; 1432 1433 /** 1434 * @brief Receives the response of the "GetItemAttributes". 1435 * 1436 * @param[in] rawAddr The address of the bluetooth device. 1437 * @param[in] pkt The frame packet. 1438 */ 1439 void ReceiveGetItemAttributesRsp(const RawAddress &rawAddr, Packet *pkt) const; 1440 1441 /** 1442 * @brief Receives the response of the "GetTotalNumberOfItems". 1443 * 1444 * @param[in] rawAddr The address of the bluetooth device. 1445 * @param[in] pkt The frame packet. 1446 */ 1447 void ReceiveGetTotalNumberOfItemsRsp(const RawAddress &rawAddr, Packet *pkt) const; 1448 1449 /** 1450 * @brief Receives the response of the <b>BROWSING</b>. 1451 * 1452 * @param[in] rawAddr The address of the bluetooth device. 1453 * @param[in] pkt The frame packet. 1454 */ 1455 void ReceiveBrowseRsp(const RawAddress &rawAddr, Packet *pkt); 1456 1457 /** 1458 * @brief Processes the timeout of command of the <b>BROWSING</b>. 1459 * 1460 * @param[in] rawAddr The address of the bluetooth device. 1461 */ 1462 void ProcessBrowseTimeout(RawAddress rawAddr); 1463 1464 /** 1465 * @brief The callback function, which registers into the <b>utility::Timer</b>. 1466 * 1467 * @details Switch to the thread of the AVRCP CT service in this method. 1468 * @param[in] rawAddr The address of the bluetooth device. 1469 */ 1470 void BrowseTimeoutCallback(const RawAddress &rawAddr); 1471 1472 /** 1473 * @brief Deletes all the data of the specified device, include the connection information and the state machines. 1474 * 1475 * @param[in] rawAddr The address of the bluetooth device. 1476 */ 1477 static void DeleteResource(const RawAddress &rawAddr); 1478 1479 /** 1480 * @brief Deletes the browse state machine. 1481 * 1482 * @param[in] rawAddr The address of the bluetooth device. 1483 */ 1484 static void DeleteBrowseStateMachine(const RawAddress &rawAddr); 1485 1486 /** 1487 * @briefs Checks the browsing channel is supported or not. 1488 * 1489 * @return The result of the method execution. 1490 * @retval true Supported. 1491 * @retval false Unsupported. 1492 */ IsSupportedBrowsing(void)1493 bool IsSupportedBrowsing(void) const 1494 { 1495 return ((features_ & AVRC_CT_FEATURE_BROWSING) == AVRC_CT_FEATURE_BROWSING); 1496 } 1497 1498 /** 1499 * @brief Explains the response of the <b>AVCTP</b> function to the result. 1500 * 1501 * @param avctRet The response code. 1502 * @return The requested result. 1503 */ 1504 static int ExpainAvctResult(uint16_t avctRet); 1505 1506 /** 1507 * @brief Explains the response of the <b>PASS THROUGH</b> command to the result. 1508 * 1509 * @param code The response code. 1510 * @return The requested result. 1511 */ 1512 static int ExpainPassCrCodeToResult(uint8_t code); 1513 1514 /** 1515 * @briefs Explains the "crCode" of the <b>STATUS</b> command to the response. 1516 * 1517 * @return The value of the "response". 1518 */ 1519 static int ExplainCrCodeToResult(uint8_t crCode); 1520 1521 /** 1522 * @briefs Get the name of the event 1523 * 1524 * @param event The event 1525 * @return The name of the event 1526 */ 1527 static std::string GetEventName(uint8_t event); 1528 1529 BT_DISALLOW_COPY_AND_ASSIGN(AvrcCtProfile); 1530 }; 1531 } // namespace bluetooth 1532 } // namespace OHOS 1533 1534 #endif // !AVRCP_CT_PROFILE_H 1535