1 /* 2 * Copyright (C) 2021 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_STATE_MACHINE_H 17 #define AVRCP_CT_STATE_MACHINE_H 18 19 #include "avrcp_ct_connection.h" 20 #include "message.h" 21 #include "raw_address.h" 22 #include "state_machine.h" 23 24 namespace OHOS { 25 namespace bluetooth { 26 /** 27 * @brief This enumeration declares the events for sending to the state machine. 28 */ 29 enum AvrcCtSmEvent { 30 // Invalid message. 31 AVRC_CT_SM_EVENT_INVALID = 0x00, 32 // Transits to the "CONNECTED" state. 33 AVRC_CT_SM_EVENT_TO_CONNECTED_STATE, 34 // Transits to the "DISCONNECTING" state. 35 AVRC_CT_SM_EVENT_TO_DISCONNECTING_STATE, 36 // Transits to the "DISABLE" state. 37 AVRC_CT_SM_EVENT_TO_DISABLE_STATE, 38 // Send the command of the <b>PASS THROUGH</b>. 39 AVRC_CT_SM_EVENT_PASS_THROUGH, 40 // Send the command of the <b>UNIT INFO"</b>. 41 AVRC_CT_SM_EVENT_UNIT_INFO, 42 // Send the command of the <b>SUB UNIT INFO</b>. 43 AVRC_CT_SM_EVENT_SUB_UNIT_INFO, 44 // Send the command of the <b>GetCapabilities"</b>. 45 AVRC_CT_SM_EVENT_GET_CAPABILITIES = AVRC_CT_PDU_ID_GET_CAPABILITIES, 46 // Send the command of the <b>ListPlayerApplicationSettingAttributes"</b>. 47 AVRC_CT_SM_EVENT_LIST_PLAYER_APPLICATION_SETTING_ATTRIBUTES, 48 // Send the command of the <b>ListPlayerApplicationSettingValues"</b>. 49 AVRC_CT_SM_EVENT_LIST_PLAYER_APPLICATION_SETTING_VALUES = AVRC_CT_PDU_ID_LIST_PLAYER_APPLICATION_SETTING_VALUES, 50 // Send the command of the <b>GetCurrentPlayerApplicationSettingValue"</b>. 51 AVRC_CT_SM_EVENT_GET_CURRENT_PLAYER_APPLICATION_SETTING_VALUE = 52 AVRC_CT_PDU_ID_GET_CURRENT_PLAYER_APPLICATION_SETTING_VALUE, 53 // Send the command of the <b>SetPlayerApplicationSettingValue"</b>. 54 AVRC_CT_SM_EVENT_SET_PLAYER_APPLICATION_SETTING_VALUE = AVRC_CT_PDU_ID_SET_PLAYER_APPLICATION_SETTING_VALUE, 55 // Send the command of the <b>GetPlayerApplicationSettingAttributeText"</b>. 56 AVRC_CT_SM_EVENT_GET_PLAYER_APPLICATION_SETTING_ATTRIBUTE_TEXT = 57 AVRC_CT_PDU_ID_GET_PLAYER_APPLICATION_SETTING_ATTRIBUTE_TEXT, 58 // Send the command of the <b>GetPlayerApplicationSettingValueText"</b>. 59 AVRC_CT_SM_EVENT_GET_PLAYER_APPLICATION_SETTING_VALUE_TEXT = 60 AVRC_CT_PDU_ID_GET_PLAYER_APPLICATION_SETTING_VALUE_TEXT, 61 // Send the command of the <b>GetElementAttributes"</b>. 62 AVRC_CT_SM_EVENT_GET_ELEMENT_ATTRIBUTES = AVRC_CT_PDU_ID_GET_ELEMENT_ATTRIBUTES, 63 // Send the command of the <b>GetPlayStatus"</b>. 64 AVRC_CT_SM_EVENT_GET_PLAY_STATUS = AVRC_CT_PDU_ID_GET_PLAY_STATUS, 65 // Send the command of the <b>RequestContinuingResponse"</b>. 66 AVRC_CT_SM_EVENT_REQUEST_CONTINUING_RESPONSE = AVRC_CT_PDU_ID_REQUEST_CONTINUING_RESPONSE, 67 // Send the command of the <b>AbortContinuingResponse"</b>. 68 AVRC_CT_SM_EVENT_ABORT_CONTINUING_RESPONSE = AVRC_CT_PDU_ID_ABORT_CONTINUING_RESPONSE, 69 // Send the command of the <b>SetAddressedPlayer"</b>. 70 AVRC_CT_SM_EVENT_SET_ADDRESSED_PLAYER = AVRC_CT_PDU_ID_SET_ADDRESSED_PLAYER, 71 // Send the command of the <b>SetBrowsedPlayer"</b>. 72 AVRC_CT_SM_EVENT_SET_BROWSED_PLAYER = AVRC_CT_PDU_ID_SET_BROWSED_PLAYER, 73 // Send the command of the <b>ChangePath"</b>. 74 AVRC_CT_SM_EVENT_CHANGE_PATH = AVRC_CT_PDU_ID_CHANGE_PATH, 75 // Send the command of the <b>GetFolderItems"</b>. 76 AVRC_CT_SM_EVENT_GET_FOLDER_ITEMS = AVRC_CT_PDU_ID_GET_FOLDER_ITEMS, 77 // Send the command of the <b>GetItemAttributes"</b>. 78 AVRC_CT_SM_EVENT_GET_ITEM_ATTRIBUTES = AVRC_CT_PDU_ID_GET_ITEM_ATTRIBUTES, 79 // Send the command of the <b>GetTotalNumberOfItems"</b>. 80 AVRC_CT_SM_EVENT_GET_TOTAL_NUMBER_OF_ITEMS = AVRC_CT_PDU_ID_GET_TOTAL_NUMBER_OF_ITEMS, 81 // Send the command of the <b>PlayItem"</b>. 82 AVRC_CT_SM_EVENT_PLAY_ITEM = AVRC_CT_PDU_ID_PLAY_ITEM, 83 // Send the command of the <b>AddToNowPlaying"</b>. 84 AVRC_CT_SM_EVENT_ADD_TO_NOW_PLAYING = AVRC_CT_PDU_ID_ADD_TO_NOW_PLAYING, 85 // Send the command of the <b>SetAbsoluteVolume"</b>. 86 AVRC_CT_SM_EVENT_SET_ABSOLUTE_VOLUME = AVRC_CT_PDU_ID_SET_ABSOLUTE_VOLUME, 87 // Send the command of the <b>RegisterNotification"</b>. 88 AVRC_CT_SM_EVENT_REGISTER_NOTIFICATION = AVRC_CT_PDU_ID_REGISTER_NOTIFICATION, 89 }; 90 91 /** 92 * @brief This class provides a set of methods for adding/deleting the state machine and forwarding the 93 * messages to the state machine. 94 * 95 * @detail There are two link(the control link and the browse link) of each bluetooth device. Each link has a state 96 * machine for processing the state. 97 * 1. The control state machine of the control link. 98 * 2. The browse state machine of the browse link. 99 * 100 * The state in the control state machine: 101 * CONNECTING 102 * | 103 * CONNECTED 104 * / / \ \ \ 105 * DISCONNECTING PENDING BUSY CONTINUATION DISABLE 106 * The state transaction in the control state machine: 107 * CONNECTING CONNECTED DISCONNECTING PENDING BUSY CONTINUATION SHUTDOWN 108 * 1. CONNECTING - O X X X X O 109 * 2. CONNECTED X - O O O O O 110 * 3. DISCONNECTING X X - X X X O 111 * 4. PENDING X O O - O X O 112 * 5. BUSY X O O X - X O 113 * 6. CONTINUATION X O O X O - O 114 * 7. DISABLE X X X X X X - 115 * 116 * The state in the browse state machine: 117 * CONNECTING 118 * | 119 * CONNECTED 120 * / | \ 121 * DISCONNECTING PENDING BUSY 122 * The state transaction in the browse state machine: 123 * CONNECTING CONNECTED DISCONNECTING PENDING BUSY 124 * 1. CONNECTING - O X X X 125 * 2. CONNECTED X - O O O 126 * 3. DISCONNECTING X X - X X 127 * 4. PENDING X O O - O 128 * 5. BUSY X O O X - 129 */ 130 class AvrcCtStateMachineManager { 131 public: 132 /** 133 * @brief A destructor used to delete the <b>AvrcCtStateMachineManager</b> instance. 134 */ 135 ~AvrcCtStateMachineManager(); 136 137 /** 138 * @brief Gets the instance of the <b>AvrcCtStateMachineManager</b> class. 139 * 140 * @return The instance of the AvrcCtStateMachineManager. 141 */ 142 static AvrcCtStateMachineManager *GetInstance(void); 143 144 /** 145 * @brief Shut down the all statmachine 146 */ 147 void ShutDown(void); 148 149 /** 150 * @brief Adds the control state machine of the specified bluetooth address. 151 * 152 * @param[in] rawAddr The address of the bluetooth device. 153 * @return The result of the method execution. 154 * @retval BT_SUCCESS Execute success. 155 * @retval RET_BAD_PARAM Execute failure. 156 */ 157 int AddControlStateMachine(const RawAddress &rawAddr); 158 159 /** 160 * @brief Adds the browse state machine of the specified bluetooth address. 161 * 162 * @param[in] rawAddr The address of the bluetooth device. 163 * @return The result of the method execution. 164 * @retval BT_SUCCESS Execute success. 165 * @retval RET_BAD_PARAM Execute failure. 166 */ 167 int AddBrowseStateMachine(const RawAddress &rawAddr); 168 169 /** 170 * @brief Deletes the pair of state machines of the specified bluetooth address. 171 * 172 * @param[in] rawAddr The address of the bluetooth device. 173 */ 174 void DeletePairOfStateMachine(const RawAddress &rawAddr); 175 176 /** 177 * @brief Deletes the browse state machine of the specified bluetooth address. 178 * 179 * @param[in] rawAddr The address of the bluetooth device. 180 */ 181 void DeleteBrowseStateMachine(const RawAddress &rawAddr); 182 183 /** 184 * @brief Sends the message to the control state machine of the specified bluetooth address. 185 * 186 * @param[in] rawAddr The address of the bluetooth device. 187 * @param[in] msg The message that need to be sent. 188 * @return The result of the method execution. 189 * @retval true The message is processed. 190 * @retval false The message is not processed. 191 */ 192 bool SendMessageToControlStateMachine(const RawAddress &rawAddr, const utility::Message &msg); 193 194 /** 195 * @brief Sends messages to all of the control state machine. 196 * 197 * @param[in] msg The message that need to be sent. 198 */ 199 void SendMessageToAllControlStateMachine(const utility::Message &msg); 200 201 /** 202 * @brief Sends messages to the browse state machine. 203 * 204 * @param[in] rawAddr The address of the bluetooth device. 205 * @param[in] msg The message that need to be sent. 206 * @return The result of the method execution. 207 * @retval true The message is processed. 208 * @retval false The message is not processed. 209 */ 210 bool SendMessageToBrowseStateMachine(const RawAddress &rawAddr, const utility::Message &msg); 211 212 /** 213 * @brief Sends messages to all of the browse state machine. 214 * 215 * @param[in] msg The message that need to be sent. 216 */ 217 void SendMessageToAllBrowseStateMachine(const utility::Message &msg); 218 219 /** 220 * @brief Checks the current state is "CONNECTING" or not. 221 * 222 * @param[in] rawAddr The address of the bluetooth device. 223 * @return The result of the method execution. 224 * @retval true Current state is "CONNECTING". 225 * @retval false Current state is not "CONNECTING". 226 */ 227 bool IsControlConnectingState(const RawAddress &rawAddr); 228 229 /** 230 * @brief Checks the current state is "CONNECTED" or not. 231 * 232 * @param[in] rawAddr The address of the bluetooth device. 233 * @return The result of the method execution. 234 * @retval true Current state is "CONNECTED". 235 * @retval false Current state is not "CONNECTED". 236 */ 237 bool IsControlConnectedState(const RawAddress &rawAddr); 238 239 /** 240 * @brief Checks the current state is "DISCONNECTING" or not. 241 * 242 * @param[in] rawAddr The address of the bluetooth device. 243 * @return The result of the method execution. 244 * @retval true Current state is "DISCONNECTING". 245 * @retval false Current state is not "DISCONNECTING". 246 */ 247 bool IsControlDisconnectingState(const RawAddress &rawAddr); 248 249 /** 250 * @brief Checks the current state is "PENDING" or not. 251 * 252 * @param[in] rawAddr The address of the bluetooth device. 253 * @return The result of the method execution. 254 * @retval true Current state is "PENDING". 255 * @retval false Current state is not "PENDING". 256 */ 257 bool IsControlPendingState(const RawAddress &rawAddr); 258 259 /** 260 * @brief Checks the current state is "PENDING" or not. 261 * 262 * @param[in] rawAddr The address of the bluetooth device. 263 * @return The result of the method execution. 264 * @retval true Current state is "PENDING". 265 * @retval false Current state is not "PENDING". 266 */ 267 bool IsBrowsePendingState(const RawAddress &rawAddr); 268 269 /** 270 * @brief Checks the current state is "CONTINUATION" or not.. 271 * 272 * @param[in] rawAddr The address of the bluetooth device. 273 * @return The result of the method execution. 274 * @retval true Current state is "CONTINUATION". 275 * @retval false Current state is not "CONTINUATION". 276 */ 277 bool IsControlContinuationState(const RawAddress &rawAddr); 278 279 /** 280 * @brief Checks the current state is "DISABLE" or not. 281 * 282 * @param[in] rawAddr The address of the bluetooth device. 283 * @return The result of the method execution. 284 * @retval true Current state is "DISABLE". 285 * @retval false Current state is not "DISABLE". 286 */ 287 bool IsControlDisableState(const RawAddress &rawAddr); 288 289 private: 290 /** 291 * @brief This class provides a set of methods for adding/deleting/transiting the state and processing the 292 * messages that are sent to the state machine. 293 */ 294 class StateMachine : public utility::StateMachine { 295 public: 296 /** 297 * @brief This enumeration declares types that are used to distinguish between the control state machine and the 298 * browse state machine. 299 */ 300 enum class Type { 301 AVRC_CT_SM_TYPE_CONTROL, // The control state machine. 302 AVRC_CT_SM_TYPE_BROWSE, // The browse state machine. 303 }; 304 305 /** 306 * @brief A constructor used to create an <b>StateMachine</b> instance. 307 */ 308 StateMachine(Type type, const RawAddress &rawAddr); 309 310 /** 311 * @brief A destructor used to delete the <b>StateMachine</b> instance. 312 */ 313 ~StateMachine() = default; 314 315 /** 316 * @brief Initializes the states. 317 */ 318 void AddStates(void); 319 320 private: 321 // The type of the state machine. 322 Type type_; 323 // The address of the bluetooth device. 324 RawAddress rawAddr_; 325 /** 326 * @brief A constructor used to create an <b>StateMachine</b> instance. 327 */ 328 StateMachine() = delete; 329 330 class State : public utility::StateMachine::State { 331 public: 332 explicit State(const std::string &name, utility::StateMachine &sm, const RawAddress &rawAddr); 333 explicit State(const std::string &name, utility::StateMachine &sm, const RawAddress &rawAddr, 334 utility::StateMachine::State &parent); 335 virtual ~State(); 336 337 protected: 338 // The address of the bluetooth device. 339 RawAddress rawAddr_; 340 341 private: 342 State() = delete; 343 }; 344 345 /** 346 * @brief This class provides a set of methods for entry/exit the "CONNECTING" state of the control state 347 * machine and processing messages that are sent to the state. 348 */ 349 class CtConnecting : public State { 350 public: 351 /** 352 * @brief A constructor used to create an <b>CtConnecting</b> instance. 353 */ 354 CtConnecting(const std::string &name, utility::StateMachine &sm, const RawAddress &rawAddr); 355 356 /** 357 * @brief A destructor used to delete the <b>CtConnecting</b> instance. 358 */ 359 ~CtConnecting(void) override = default; 360 361 /** 362 * @brief Enters the state. 363 */ 364 void Entry(void) override; 365 366 /** 367 * @brief Exits the state. 368 */ 369 void Exit(void) override; 370 371 /** 372 * @brief Processes the required messages and send the unwanted to the parent state. 373 * 374 * @param[in] msg The message that need to be sent. 375 * @return The result of the method execution. 376 * @retval true The message is processed. 377 * @retval false The message is not processed. 378 */ 379 bool Dispatch(const utility::Message &msg) override; 380 381 private: 382 /** 383 * @brief A deleted default constructor. 384 */ 385 CtConnecting(void) = delete; 386 }; 387 388 /** 389 * @brief This class provides a set of methods for entry/exit the "CONNECTED" state of the control state 390 * machine and processing messages that are sent to the state. 391 */ 392 class CtConnected : public State { 393 public: 394 /** 395 * @brief A constructor used to create an <b>CtConnected</b> instance. 396 */ 397 CtConnected(const std::string &name, utility::StateMachine &sm, const RawAddress &rawAddr, 398 utility::StateMachine::State &parent); 399 400 /** 401 * @brief A destructor used to delete the <b>CtConnected</b> instance. 402 */ 403 ~CtConnected(void) override = default; 404 405 /** 406 * @brief Enters the state. 407 */ 408 void Entry(void) override; 409 410 /** 411 * @brief Exits the state. 412 */ 413 void Exit(void) override; 414 415 /** 416 * @brief Processes required messages and send unwanted messages to the parent state. 417 * 418 * @param[in] msg The message that need to be sent. 419 * @return The result of the method execution. 420 * @retval true The message is processed. 421 * @retval false The message is not processed. 422 */ 423 bool Dispatch(const utility::Message &msg) override; 424 425 private: 426 /** 427 * @brief A deleted default constructor. 428 */ 429 CtConnected(void) = delete; 430 }; 431 432 /** 433 * @brief This class provides a set of methods for entry/exit the "DISCONNECTING" state of the control state 434 * machine and processing messages that are sent to the state. 435 */ 436 class CtDisconnecting : public State { 437 public: 438 /** 439 * @brief A constructor used to create an <b>CtDisconnecting</b> instance. 440 */ 441 CtDisconnecting(const std::string &name, utility::StateMachine &sm, const RawAddress &rawAddr, 442 utility::StateMachine::State &parent); 443 444 /** 445 * @brief A destructor used to delete the <b>CtDisconnecting</b> instance. 446 */ 447 ~CtDisconnecting(void) override = default; 448 449 /** 450 * @brief Enters the state. 451 */ 452 void Entry(void) override; 453 454 /** 455 * @brief Exits the state. 456 */ 457 void Exit(void) override; 458 459 /** 460 * @brief Processes required messages and send unwanted messages to the parent state. 461 * 462 * @param[in] msg The message from the control state machine. 463 * @return The result of the method execution. 464 * @retval true The message is processed. 465 * @retval false The message is not processed. 466 */ 467 bool Dispatch(const utility::Message &msg) override; 468 469 private: 470 /** 471 * @brief A deleted default constructor. 472 */ 473 CtDisconnecting(void) = delete; 474 }; 475 476 /** 477 * @brief This class provides a set of methods for entry/exit the "CONTINUATION" state of the control state 478 * machine and processing messages that are sent to the state. 479 */ 480 class CtContinuation : public State { 481 public: 482 /** 483 * @brief A constructor used to create an <b>CtContinuation</b> instance. 484 */ 485 CtContinuation(const std::string &name, utility::StateMachine &sm, const RawAddress &rawAddr, 486 utility::StateMachine::State &parent); 487 488 /** 489 * @brief A destructor used to delete the <b>CtContinuation</b> instance. 490 */ 491 ~CtContinuation(void) override = default; 492 493 /** 494 * @brief Enters the state. 495 */ 496 void Entry(void) override; 497 498 /** 499 * @brief Exits the state. 500 */ 501 void Exit(void) override; 502 503 /** 504 * @brief Processes required messages and send unwanted messages to the parent state. 505 * 506 * @param[in] msg The message from the control state machine. 507 * @return The result of the method execution. 508 * @retval true The message is processed. 509 * @retval false The message is not processed. 510 */ 511 bool Dispatch(const utility::Message &msg) override; 512 513 private: 514 /** 515 * @brief A deleted default constructor. 516 */ 517 CtContinuation(void) = delete; 518 }; 519 520 /** 521 * @brief This class provides a set of methods for entry/exit the "DISABLE" state of the control state 522 * machine and processing messages that are sent to the state. 523 */ 524 class CtDisable : public State { 525 public: 526 /** 527 * @brief A constructor used to create an <b>CtDisable</b> instance. 528 */ 529 CtDisable(const std::string &name, utility::StateMachine &sm, const RawAddress &rawAddr, 530 utility::StateMachine::State &parent); 531 532 /** 533 * @brief A destructor used to delete the <b>CtDisable</b> instance. 534 */ 535 ~CtDisable(void) override = default; 536 537 /** 538 * @brief Enters the state. 539 */ 540 void Entry(void) override; 541 542 /** 543 * @brief Exits the state. 544 */ 545 void Exit(void) override; 546 547 /** 548 * @brief Processes required messages and send unwanted messages to the parent state. 549 * 550 * @param[in] msg The message from the control state machine. 551 * @return The result of the method execution. 552 * @retval true The message is processed. 553 * @retval false The message is not processed. 554 */ 555 bool Dispatch(const utility::Message &msg) override; 556 557 private: 558 /** 559 * @brief A deleted default constructor. 560 */ 561 CtDisable(void) = delete; 562 }; 563 564 /** 565 * @brief This class provides a set of methods for entry/exit the "PENDING" state of the control state 566 * machine and processing messages that are sent to the state. 567 */ 568 class CtPending : public State { 569 public: 570 /** 571 * @brief A constructor used to create an <b>CtPending</b> instance. 572 */ 573 CtPending(const std::string &name, utility::StateMachine &sm, const RawAddress &rawAddr, 574 utility::StateMachine::State &parent); 575 576 /** 577 * @brief A destructor used to delete the <b>CtPending</b> instance. 578 */ 579 ~CtPending(void) override = default; 580 581 /** 582 * @brief Enters the state. 583 */ 584 void Entry(void) override; 585 586 /** 587 * @brief Exits the state. 588 */ 589 void Exit(void) override; 590 591 /** 592 * @brief Processes required messages and send unwanted messages to the parent state. 593 * 594 * @param[in] msg The message that need to be sent. 595 * @return The result of the method execution. 596 * @retval true The message is processed. 597 * @retval false The message is not processed. 598 */ 599 bool Dispatch(const utility::Message &msg) override; 600 601 private: 602 /** 603 * @brief A deleted default constructor. 604 */ 605 CtPending(void) = delete; 606 }; 607 608 /** 609 * @brief This class provides a set of methods for entry/exit the "CONNECTING" state of the browse state 610 * machine and processing messages that are sent to the state. 611 */ 612 class BrConnecting : public State { 613 public: 614 /** 615 * @brief A constructor used to create an <b>BrConnecting</b> instance. 616 */ 617 BrConnecting(const std::string &name, utility::StateMachine &sm, const RawAddress &rawAddr); 618 619 /** 620 * @brief A destructor used to delete the <b>BrConnecting</b> instance. 621 */ 622 ~BrConnecting(void) override = default; 623 624 /** 625 * @brief Enters the state. 626 */ 627 void Entry(void) override; 628 629 /** 630 * @brief Exits the state. 631 */ 632 void Exit(void) override; 633 634 /** 635 * @brief Processes required messages and send unwanted messages to the parent state. 636 * 637 * @param[in] msg The message from the browse state machine. 638 * @return The result of the method execution. 639 * @retval true The message is processed. 640 * @retval false The message is not processed. 641 */ 642 bool Dispatch(const utility::Message &msg) override; 643 644 private: 645 /** 646 * @brief A deleted default constructor. 647 */ 648 BrConnecting(void) = delete; 649 }; 650 651 /** 652 * @brief This class provides a set of methods for entry/exit the "CONNECTED" state of the browse state 653 * machine and processing messages that are sent to the state. 654 */ 655 class BrConnected : public State { 656 public: 657 /** 658 * @brief A constructor used to create an <b>BrConnected</b> instance. 659 */ 660 BrConnected(const std::string &name, utility::StateMachine &sm, const RawAddress &rawAddr, 661 utility::StateMachine::State &parent); 662 663 /** 664 * @brief A destructor used to delete the <b>BrConnected</b> instance. 665 */ 666 ~BrConnected(void) override = default; 667 668 /** 669 * @brief Enters the state. 670 */ 671 void Entry(void) override; 672 673 /** 674 * @brief Exits the state. 675 */ 676 void Exit(void) override; 677 678 /** 679 * @brief Processes required messages and send unwanted messages to the parent state. 680 * 681 * @param[in] msg The message from the browse state machine. 682 * @return The result of the method execution. 683 * @retval true The message is processed. 684 * @retval false The message is not processed. 685 */ 686 bool Dispatch(const utility::Message &msg) override; 687 688 private: 689 /** 690 * @brief A deleted default constructor. 691 */ 692 BrConnected(void) = delete; 693 }; 694 695 /** 696 * @brief This class provides a set of methods for entry/exit the "DISCONNECTING" state of the browse state 697 * machine and processing messages that are sent to the state. 698 */ 699 class BrDisconnecting : public State { 700 public: 701 /** 702 * @brief A constructor used to create an <b>BrDisconnecting</b> instance. 703 */ 704 BrDisconnecting(const std::string &name, utility::StateMachine &sm, const RawAddress &rawAddr, 705 utility::StateMachine::State &parent); 706 707 /** 708 * @brief A destructor used to delete the <b>BrDisconnecting</b> instance. 709 */ 710 ~BrDisconnecting(void) override = default; 711 712 /** 713 * @brief Enters the state. 714 */ 715 void Entry(void) override; 716 717 /** 718 * @brief Exits the state. 719 */ 720 void Exit(void) override; 721 722 /** 723 * @brief Processes required messages and send unwanted messages to the parent state. 724 * 725 * @param[in] msg The message from the browse state machine. 726 * @return The result of the method execution. 727 * @retval true The message is processed. 728 * @retval false The message is not processed. 729 */ 730 bool Dispatch(const utility::Message &msg) override; 731 732 private: 733 /** 734 * @brief A deleted default constructor. 735 */ 736 BrDisconnecting(void) = delete; 737 }; 738 739 /** 740 * @brief This class provides a set of methods for entry/exit the "PENDING" state of the browse state 741 * machine and processing messages that are sent to the state. 742 */ 743 class BrPending : public State { 744 public: 745 /** 746 * @brief A constructor used to create an <b>BrPending</b> instance. 747 */ 748 BrPending(const std::string &name, utility::StateMachine &sm, const RawAddress &rawAddr, 749 utility::StateMachine::State &parent); 750 751 /** 752 * @brief A destructor used to delete the <b>BrPending</b> instance. 753 */ 754 ~BrPending(void) override = default; 755 756 /** 757 * @brief Enters the state. 758 */ 759 void Entry(void) override; 760 761 /** 762 * @brief Exits the state. 763 */ 764 void Exit(void) override; 765 766 /** 767 * @brief Processes required messages and send unwanted messages to the parent state. 768 * 769 * @param[in] msg The message from the browse state machine. 770 * @return The result of the method execution. 771 * @retval true The message is processed. 772 * @retval false The message is not processed. 773 */ 774 bool Dispatch(const utility::Message &msg) override; 775 776 private: 777 /** 778 * @brief A deleted default constructor. 779 */ 780 BrPending(void) = delete; 781 }; 782 }; 783 784 // This type indicates the pair of the state machine. 785 using StateMachinePair = std::pair<std::unique_ptr<StateMachine>, std::unique_ptr<StateMachine>>; 786 787 // Saves the state machines of the different devices. 788 std::map<std::string, StateMachinePair> stateMachines_ {}; 789 // using a local lock_guard to lock mutex guarantees unlocking on destruction / exception: 790 std::recursive_mutex mutex_ {}; 791 792 /** 793 * @brief A constructor used to create an <b>AvrcCtStateMachineManager</b> instance. 794 */ 795 AvrcCtStateMachineManager(); 796 797 /** 798 * @brief Gets the pair of state machines of the specified bluetooth address. 799 * 800 * @param[in] addr The address of the bluetooth device. 801 * @return The pair of state machines of the specified bluetooth address.. 802 */ 803 StateMachinePair *GetPairOfStateMachine(const std::string &addr); 804 805 /** 806 * @brief Checks the current state is specified state or not. 807 * 808 * @param[in] rawAddr The address of the bluetooth device. 809 * @return The result of the method execution. 810 * @retval true Current state is the specified state. 811 * @retval false Current state is not the specified state. 812 */ 813 bool IsControlSpecifiedState(const std::string &addr, std::string stateName); 814 815 /** 816 * @brief Checks the current state is specified state. 817 * 818 * @param[in] rawAddr The address of the bluetooth device. 819 * @param[in] stateName The name of the specified state. 820 * @return The result of the method execution. 821 * @retval true Current state is the specified state. 822 * @retval false Current state is not the specified state. 823 */ 824 bool IsBrowseSpecifiedState(const std::string &addr, std::string stateName); 825 }; 826 } // namespace bluetooth 827 } // namespace OHOS 828 829 #endif // !AVRCP_CT_STATE_MACHINE_H 830