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 /** 1009 * @brief set the features for connected device. 1010 */ 1011 void SetFeatures(const RawAddress &rawAddr, uint32_t features); 1012 1013 /** 1014 * @brief Checks the AVRCP Device is Connected or not. 1015 * 1016 * @return The result of the method execution. 1017 * @retval true The Device is Connected. 1018 * @retval false The Device is Disconnected. 1019 */ 1020 bool IsDeviceConnected(const RawAddress &rawAddr) const; 1021 1022 private: 1023 /// The flag is used to indicate that the AVRCP CT profile is enabled or not. 1024 static bool g_isEnabled; 1025 /// The features supported by the AVRCP CT profile. 1026 uint32_t features_; 1027 /// The SIG company ID. 1028 uint32_t companyId_; 1029 /// The max MTU size of the control channel. 1030 uint16_t controlMtu_; 1031 /// The max MTU size of the browse channel. 1032 uint16_t browseMtu_; 1033 /// The max fragments of the control channel. 1034 uint8_t maxFragments_; 1035 /// The dispatcher that is used to switch to the thread of the AVRCP CT service. 1036 utility::Dispatcher *dispatcher_ {nullptr}; 1037 /// The connect id of the passive connection. 1038 uint8_t connectId_; 1039 /// The pointer to the observer of the <b>AvrcCtProfile</b> class. 1040 AvrcCtProfile::Observer *myObserver_ {nullptr}; 1041 /// The callback function, which registers into the AVCTP for receiving the events. 1042 AvctChannelEventCallback eventCallback_ {nullptr}; 1043 /// The callback function, which registers into the AVCTP for receiving the messages. 1044 AvctMsgCallback msgCallback_ {nullptr}; 1045 // Locks the local variable in a multi-threaded environment. 1046 std::recursive_mutex mutex_ {}; 1047 1048 /** 1049 * @brief A deleted default constructor. 1050 */ 1051 AvrcCtProfile() = delete; 1052 1053 /****************************************************************** 1054 * ENABLE / DISABLE * 1055 ******************************************************************/ 1056 1057 /** 1058 * @brief Checks whether the AVRCP TG profile is enabled. 1059 * 1060 * @return The result of the method execution. 1061 * @retval true The profile is enabled. 1062 * @retval false The profile is disabled. 1063 */ 1064 static bool IsEnabled(void); 1065 1066 /****************************************************************** 1067 * PASS THROUGH COMMAND * 1068 ******************************************************************/ 1069 1070 /** 1071 * @brief Sends the command of the <b>PASS THROUGH</b>. 1072 * 1073 * @param[in] rawAddr The address of the bluetooth device. 1074 * @param[in] pkt The reference of the shared pointer to the instance of the <b>AvrcCtPassPacket</b> class. 1075 */ 1076 void SendPassCmd(const RawAddress &rawAddr, const std::shared_ptr<AvrcCtPassPacket> &pkt); 1077 1078 /** 1079 * @brief Sends the next command of the <b>PASS THROUGH</b> in the cache queue. 1080 * 1081 * @param[in] rawAddr The address of the bluetooth device. 1082 */ 1083 void SendNextPassCmd(const RawAddress &rawAddr); 1084 1085 /** 1086 * @brief Receives the response of the <b>PASS THROUGH</b>. 1087 * 1088 * @param[in] rawAddr The address of the bluetooth device. 1089 * @param[in] pkt The frame packet. 1090 */ 1091 void ReceivePassRsp(const RawAddress &rawAddr, Packet *pkt); 1092 1093 /** 1094 * @brief Informs that revive the button operation. 1095 * 1096 * @param[in] rawAddr The address of the bluetooth device. 1097 * @param[in] button The value of the key operation. 1098 * @param[in] state The value of the key state. 1099 * @param[in] result The result of the method execution. 1100 * @a BT_SUCCESS : Execute success. 1101 * @a RET_NO_SUPPORT : Not support. 1102 * @a RET_BAD_STATUS : Execute failure. 1103 */ 1104 void InformPassRsp(const RawAddress &rawAddr, uint8_t button, uint8_t state, int result) const; 1105 1106 /** 1107 * @brief Processes the timeout of command of the <b>PASS THROUGH</b>. 1108 * 1109 * @param[in] rawAddr The address of the bluetooth device. 1110 */ 1111 void ProcessPassTimeout(RawAddress rawAddr, uint8_t key, uint8_t state); 1112 1113 /** 1114 * @brief The callback function, which registers into the <b>utility::Timer</b>. 1115 * 1116 * @details This function switches to the thread of the AVRCP TG service firstly, then processes the timeout. 1117 * @param[in] rawAddr The address of the bluetooth device. 1118 */ 1119 void PassTimeoutCallback(const RawAddress &rawAddr, uint8_t key, uint8_t state); 1120 1121 /****************************************************************** 1122 * UNIT INFO / SUB UNIT INFO COMMAND * 1123 ******************************************************************/ 1124 1125 /** 1126 * @brief Sends the command of the <b>UNIT INFO</b> or <b>SUB UNIT INFO</b>. 1127 * 1128 * @param[in] rawAddr The address of the bluetooth device. 1129 */ 1130 void SendNextUnitCmd(const RawAddress &rawAddr); 1131 1132 /** 1133 * @brief Receives the response of the <b>UNIT INFO</b>. 1134 * 1135 * @param[in] rawAddr The address of the bluetooth device. 1136 * @param[in] pkt The frame packet. 1137 */ 1138 void ReceiveUnitRsp(const RawAddress &rawAddr, Packet *pkt); 1139 1140 /** 1141 * @brief Receives the response of the <b>SUB UNIT INFO</b>. 1142 * 1143 * @param[in] rawAddr The address of the bluetooth device. 1144 * @param[in] pkt The frame packet. 1145 */ 1146 void ReceiveSubUnitRsp(const RawAddress &rawAddr, Packet *pkt); 1147 1148 /** 1149 * @brief Processes the timeout of command of the <b>UNIT INFO</b> or <b>SUB UNIT INFO</b>. 1150 * 1151 * @param[in] rawAddr The address of the bluetooth device. 1152 */ 1153 void ProcessUnitTimeout(RawAddress rawAddr); 1154 1155 /** 1156 * @brief The callback function, which registers into the <b>utility::Timer</b>. 1157 * 1158 * @details This function switches to the thread of the AVRCP TG service firstly, then processes the timeout. 1159 * @param[in] rawAddr The address of the bluetooth device. 1160 */ 1161 void UnitTimeoutCallback(const RawAddress &rawAddr); 1162 1163 /****************************************************************** 1164 * VENDOR COMMAND * 1165 ******************************************************************/ 1166 1167 /** 1168 * @brief Sends the command of the <b>VENDOR DEPENDENT</b>. 1169 * 1170 * @param[in] rawAddr The address of the bluetooth device. 1171 * @param[in] pkt The frame packet. 1172 */ 1173 void SendVendorCmd(const RawAddress &rawAddr, const std::shared_ptr<AvrcCtVendorPacket> &pkt, AvrcCtSmEvent event); 1174 1175 /** 1176 * @brief Sends the next command of the <b>VENDOR DEPENDENT</b> in the cache queue. 1177 * 1178 * @param[in] rawAddr The address of the bluetooth device. 1179 */ 1180 void SendNextVendorCmd(const RawAddress &rawAddr); 1181 1182 /** 1183 * @brief Sends the command of the <b>RequestContinuingResponse</b>. 1184 * 1185 * @param[in] rawAddr The address of the bluetooth device. 1186 * @param[in] pduId The unique ID of the command. 1187 */ 1188 void SendVendorContinueCmd(const RawAddress &rawAddr, uint8_t pduId); 1189 1190 /** 1191 * @brief Sends the command of the <b>AbortContinuingResponse</b>. 1192 * 1193 * @param[in] rawAddr The address of the bluetooth device. 1194 * @param[in] pduId The unique ID of the command. 1195 */ 1196 void SendVendorAbortCmd(const RawAddress &rawAddr, uint8_t pduId) const; 1197 1198 /** 1199 * @brief Receives the response of the <b>GetCapabilities</b>. 1200 * 1201 * @param[in] rawAddr The address of the bluetooth device. 1202 * @param[in] pkt The frame packet. 1203 */ 1204 void ReceiveGetCapabilitiesRsp(const RawAddress &rawAddr, Packet *pkt); 1205 1206 /** 1207 * @brief Receives the response of the <b>ListPlayerApplicationSettingAttributes</b>. 1208 * 1209 * @param[in] rawAddr The address of the bluetooth device. 1210 * @param[in] pkt The frame packet. 1211 */ 1212 void ReceiveListPlayerApplicationSettingAttributesRsp(const RawAddress &rawAddr, Packet *pkt); 1213 1214 /** 1215 * @brief Receives the response of the <b>ListPlayerApplicationSettingValues</b>. 1216 * 1217 * @param[in] rawAddr The address of the bluetooth device. 1218 * @param[in] pkt The frame packet. 1219 */ 1220 void ReceiveListPlayerApplicationSettingValuesRsp(const RawAddress &rawAddr, Packet *pkt); 1221 1222 /** 1223 * @brief Receives the response of the <b>GetCurrentPlayerApplicationSettingValue</b>. 1224 * 1225 * @param[in] rawAddr The address of the bluetooth device. 1226 * @param[in] pkt The frame packet. 1227 */ 1228 void ReceiveGetCurrentPlayerApplicationSettingValueRsp(const RawAddress &rawAddr, Packet *pkt); 1229 1230 /** 1231 * @brief Receives the response of the <b>SetPlayerApplicationSettingValue</b>. 1232 * 1233 * @param[in] rawAddr The address of the bluetooth device. 1234 * @param[in] pkt The frame packet. 1235 */ 1236 void ReceiveSetPlayerApplicationSettingValueRsp(const RawAddress &rawAddr, Packet *pkt); 1237 1238 /** 1239 * @brief Receives the response of the <b>GetPlayerApplicationSettingAttributeText</b>. 1240 * 1241 * @param[in] rawAddr The address of the bluetooth device. 1242 * @param[in] pkt The frame packet. 1243 */ 1244 void ReceiveGetPlayerApplicationSettingAttributeTextRsp(const RawAddress &rawAddr, Packet *pkt); 1245 1246 /** 1247 * @brief Receives the response of the <b>GetPlayerApplicationSettingValueText</b>. 1248 * 1249 * @param[in] rawAddr The address of the bluetooth device. 1250 * @param[in] pkt The frame packet. 1251 */ 1252 void ReceiveGetPlayerApplicationSettingValueTextRsp(const RawAddress &rawAddr, Packet *pkt); 1253 1254 /** 1255 * @brief Receives the response of the <b>GetElementAttributes</b>. 1256 * 1257 * @param[in] rawAddr The address of the bluetooth device. 1258 * @param[in] pkt The packet of the frame. 1259 */ 1260 void ReceiveGetElementAttributesRsp(const RawAddress &rawAddr, Packet *pkt); 1261 1262 /** 1263 * @brief Receives the response of the <b>GetPlayStatus</b>. 1264 * 1265 * @param[in] rawAddr The address of the bluetooth device. 1266 * @param[in] pkt The packet of the frame. 1267 */ 1268 void ReceiveGetPlayStatusRsp(const RawAddress &rawAddr, Packet *pkt); 1269 1270 /** 1271 * @brief Receives the response of the <b>AbortContinuingResponse</b>. 1272 * 1273 * @param[in] rawAddr The address of the bluetooth device. 1274 * @param[in] pkt The frame packet. 1275 */ 1276 void ReceiveAbortContinuingResponseRsp(const RawAddress &rawAddr, Packet *pkt); 1277 1278 /** 1279 * @brief Receives the response of the <b>SetAddressedPlayer</b>. 1280 * 1281 * @param[in] rawAddr The address of the bluetooth device. 1282 * @param[in] pkt The packet of the frame. 1283 */ 1284 void ReceiveSetAddressedPlayerRsp(const RawAddress &rawAddr, Packet *pkt); 1285 1286 /** 1287 * @brief Receives the response of the <b>PlayItem</b>. 1288 * 1289 * @param[in] rawAddr The address of the bluetooth device. 1290 * @param[in] pkt The frame packet. 1291 */ 1292 void ReceivePlayItemRsp(const RawAddress &rawAddr, Packet *pkt); 1293 1294 /** 1295 * @brief Receives the response of the <b>AddToNowPlaying</b>. 1296 * 1297 * @param[in] rawAddr The address of the bluetooth device. 1298 * @param[in] pkt The packet of the frame. 1299 */ 1300 void ReceiveAddToNowPlayingRsp(const RawAddress &rawAddr, Packet *pkt); 1301 1302 /** 1303 * @brief Receives the response of the <b>SetAbsoluteVolume</b>. 1304 * 1305 * @param[in] rawAddr The address of the bluetooth device. 1306 * @param[in] pkt The packet of the frame. 1307 */ 1308 void ReceiveSetAbsoluteVolumeRsp(const RawAddress &rawAddr, Packet *pkt); 1309 1310 /** 1311 * @brief Receives the response of the <b>RegisterNotification</b>. 1312 * 1313 * @param[in] rawAddr The address of the bluetooth device. 1314 * @param[in] pkt The packet of the frame. 1315 */ 1316 void ReceiveRegisterNotificationRsp(const RawAddress &rawAddr, Packet *pkt); 1317 1318 /** 1319 * @brief Inform the notification changed. 1320 * 1321 * @param[in] event The event of the notification. 1322 */ 1323 void InformNotificationChanged( 1324 const RawAddress &rawAddr, const std::shared_ptr<AvrcCtNotifyPacket> ¬ifyPkt, int result); 1325 1326 /** 1327 * @brief Inform the notification changed. 1328 * 1329 * @param[in] event The event of the notification. 1330 */ 1331 void InformPlayerApplicationSettingChanged( 1332 const RawAddress &rawAddr, const std::shared_ptr<AvrcCtNotifyPacket> ¬ifyPkt, int result); 1333 1334 /** 1335 * @brief Receives the response of the <b>VENDOR DEPENDENT AV/C Status</b>. 1336 * 1337 * @param[in] rawAddr The address of the bluetooth device. 1338 * @param[in] pkt The frame packet. 1339 */ 1340 void ReceiveVendorRspAvcStatus(const RawAddress &rawAddr, Packet *pkt); 1341 1342 /** 1343 * @brief Receives the response of the <b>VENDOR DEPENDENT AV/C Control</b>. 1344 * 1345 * @param[in] rawAddr The address of the bluetooth device. 1346 * @param[in] pkt The frame packet. 1347 */ 1348 void ReceiveVendorRspAvcControl(const RawAddress &rawAddr, Packet *pkt); 1349 1350 /** 1351 * @brief Receives the response of the <b>VENDOR DEPENDENT</b>. 1352 * 1353 * @param[in] rawAddr The address of the bluetooth device. 1354 * @param[in] pkt The frame packet. 1355 */ 1356 void ReceiveVendorRsp(const RawAddress &rawAddr, Packet *pkt); 1357 1358 /** 1359 * @brief Processes the timeout of notification command of the <b>VENDOR DEPENDENT</b>. 1360 * 1361 * @param[in] rawAddr The address of the bluetooth device. 1362 */ 1363 void ProcessVendorNotificationTimeout(RawAddress rawAddr); 1364 1365 /** 1366 * @brief Processes the timeout of command of the <b>VENDOR DEPENDENT AV/C Control</b>. 1367 * 1368 * @param[in] rawAddr The address of the bluetooth device. 1369 * @param[in] packet The packet of the AV/C Control 1370 */ 1371 void ProcessVendorAvcControlTimeout(RawAddress rawAddr, const std::shared_ptr<AvrcCtVendorPacket> &packet); 1372 1373 /** 1374 * @brief Processes the timeout of command of the <b>VENDOR DEPENDENT AV/C Status</b>. 1375 * 1376 * @param[in] rawAddr The address of the bluetooth device. 1377 * @param[in] packet The packet of the AV/C Status1 1378 */ 1379 void ProcessVendorAvcStatus1Timeout(RawAddress rawAddr, const std::shared_ptr<AvrcCtVendorPacket> &packet); 1380 1381 /** 1382 * @brief Processes the timeout of command of the <b>VENDOR DEPENDENT AV/C Status</b>. 1383 * 1384 * @param[in] rawAddr The address of the bluetooth device. 1385 * @param[in] packet The packet of the AV/C Status2 1386 */ 1387 void ProcessVendorAvcStatus2Timeout(RawAddress rawAddr, const std::shared_ptr<AvrcCtVendorPacket> &packet); 1388 1389 /** 1390 * @brief Processes the timeout of command of the <b>VENDOR DEPENDENT</b>. 1391 * 1392 * @param[in] rawAddr The address of the bluetooth device. 1393 */ 1394 void ProcessVendorTimeout(RawAddress rawAddr); 1395 1396 /** 1397 * @brief The callback function, which registers into the <b>utility::Timer</b>. 1398 * 1399 * @details This function switches to the thread of the AVRCP CT service firstly, then processes the timeout. 1400 * @param[in] rawAddr The address of the bluetooth device. 1401 */ 1402 void VendorTimeoutCallback(const RawAddress &rawAddr); 1403 1404 /****************************************************************** 1405 * BROWSING COMMAND * 1406 ******************************************************************/ 1407 1408 /** 1409 * @brief Sends the BROWSING command. 1410 * 1411 * @param[in] rawAddr The address of the bluetooth device. 1412 * @param[in] pkt The frame packet. 1413 */ 1414 void SendBrowseCmd(const RawAddress &rawAddr, const std::shared_ptr<AvrcCtBrowsePacket> &pkt, AvrcCtSmEvent event); 1415 1416 /** 1417 * @brief Sends the next BROWSING command saved in the cache queue. 1418 * 1419 * @param[in] rawAddr The address of the bluetooth device. 1420 */ 1421 void SendNextBrowseCmd(const RawAddress &rawAddr); 1422 1423 /** 1424 * @brief Receives the response of the "SetBrowsedPlayer". 1425 * 1426 * @param[in] rawAddr The address of the bluetooth device. 1427 * @param[in] pkt The frame packet. 1428 */ 1429 void ReceiveSetBrowsedPlayerRsp(const RawAddress &rawAddr, Packet *pkt) const; 1430 1431 /** 1432 * @brief Receives the response of the "ChangePath". 1433 * 1434 * @param[in] rawAddr The address of the bluetooth device. 1435 * @param[in] pkt The frame packet. 1436 */ 1437 void ReceiveChangePathRsp(const RawAddress &rawAddr, Packet *pkt) const; 1438 1439 /** 1440 * @brief Receives the response of the "GetFolderItems". 1441 * 1442 * @param[in] rawAddr The address of the bluetooth device. 1443 * @param[in] pkt The frame packet. 1444 */ 1445 void ReceiveGetFolderItemsRsp(const RawAddress &rawAddr, Packet *pkt) const; 1446 1447 /** 1448 * @brief Receives the response of the "GetItemAttributes". 1449 * 1450 * @param[in] rawAddr The address of the bluetooth device. 1451 * @param[in] pkt The frame packet. 1452 */ 1453 void ReceiveGetItemAttributesRsp(const RawAddress &rawAddr, Packet *pkt) const; 1454 1455 /** 1456 * @brief Receives the response of the "GetTotalNumberOfItems". 1457 * 1458 * @param[in] rawAddr The address of the bluetooth device. 1459 * @param[in] pkt The frame packet. 1460 */ 1461 void ReceiveGetTotalNumberOfItemsRsp(const RawAddress &rawAddr, Packet *pkt) const; 1462 1463 /** 1464 * @brief Receives the response of the <b>BROWSING</b>. 1465 * 1466 * @param[in] rawAddr The address of the bluetooth device. 1467 * @param[in] pkt The frame packet. 1468 */ 1469 void ReceiveBrowseRsp(const RawAddress &rawAddr, Packet *pkt); 1470 1471 /** 1472 * @brief Processes the timeout of command of the <b>BROWSING</b>. 1473 * 1474 * @param[in] rawAddr The address of the bluetooth device. 1475 */ 1476 void ProcessBrowseTimeout(RawAddress rawAddr); 1477 1478 /** 1479 * @brief The callback function, which registers into the <b>utility::Timer</b>. 1480 * 1481 * @details Switch to the thread of the AVRCP CT service in this method. 1482 * @param[in] rawAddr The address of the bluetooth device. 1483 */ 1484 void BrowseTimeoutCallback(const RawAddress &rawAddr); 1485 1486 /** 1487 * @brief Deletes all the data of the specified device, include the connection information and the state machines. 1488 * 1489 * @param[in] rawAddr The address of the bluetooth device. 1490 */ 1491 static void DeleteResource(const RawAddress &rawAddr); 1492 1493 /** 1494 * @brief Deletes the browse state machine. 1495 * 1496 * @param[in] rawAddr The address of the bluetooth device. 1497 */ 1498 static void DeleteBrowseStateMachine(const RawAddress &rawAddr); 1499 1500 /** 1501 * @briefs Checks the browsing channel is supported or not. 1502 * 1503 * @return The result of the method execution. 1504 * @retval true Supported. 1505 * @retval false Unsupported. 1506 */ IsSupportedBrowsing(void)1507 bool IsSupportedBrowsing(void) const 1508 { 1509 return ((features_ & AVRC_CT_FEATURE_BROWSING) == AVRC_CT_FEATURE_BROWSING); 1510 } 1511 1512 /** 1513 * @brief Explains the response of the <b>AVCTP</b> function to the result. 1514 * 1515 * @param avctRet The response code. 1516 * @return The requested result. 1517 */ 1518 static int ExpainAvctResult(uint16_t avctRet); 1519 1520 /** 1521 * @brief Explains the response of the <b>PASS THROUGH</b> command to the result. 1522 * 1523 * @param code The response code. 1524 * @return The requested result. 1525 */ 1526 static int ExpainPassCrCodeToResult(uint8_t code); 1527 1528 /** 1529 * @briefs Explains the "crCode" of the <b>STATUS</b> command to the response. 1530 * 1531 * @return The value of the "response". 1532 */ 1533 static int ExplainCrCodeToResult(uint8_t crCode); 1534 1535 /** 1536 * @briefs Get the name of the event 1537 * 1538 * @param event The event 1539 * @return The name of the event 1540 */ 1541 static std::string GetEventName(uint8_t event); 1542 1543 BT_DISALLOW_COPY_AND_ASSIGN(AvrcCtProfile); 1544 }; 1545 } // namespace bluetooth 1546 } // namespace OHOS 1547 1548 #endif // !AVRCP_CT_PROFILE_H 1549