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_TG_STATE_MACHINE_H 17 #define AVRCP_TG_STATE_MACHINE_H 18 19 #include "avrcp_tg_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 AvrcTgSmEvent { 30 // Invalid message. 31 AVRC_TG_SM_EVENT_INVALID = 0x00, 32 // Transits to the "CONNECTED" state. 33 AVRC_TG_SM_EVENT_TO_CONNECTED_STATE, 34 // Transits to the "DISCONNECTING" state. 35 AVRC_TG_SM_EVENT_TO_DISCONNECTING_STATE, 36 // Transits to the "DISABLE" state. 37 AVRC_TG_SM_EVENT_TO_DISABLE_STATE, 38 // Send the response of the <b>PASS THROUGH</b>. 39 AVRC_TG_SM_EVENT_PASS_THROUGH, 40 // Send the response of the <b>UNIT INFO"</b>. 41 AVRC_TG_SM_EVENT_UNIT_INFO, 42 // Send the response of the <b>SUB UNIT INFO</b>. 43 AVRC_TG_SM_EVENT_SUB_UNIT_INFO, 44 // Send the response of the <b>GetCapabilities</b>. 45 AVRC_TG_SM_EVENT_GET_CAPABILITIES, 46 // Send the response of the <b>ListPlayerApplicationSettingAttributes</b>. 47 AVRC_TG_SM_EVENT_LIST_PLAYER_APPLICATION_SETTING_ATTRIBUTES, 48 // Send the response of the <b>ListPlayerApplicationSettingValues</b>. 49 AVRC_TG_SM_EVENT_LIST_PLAYER_APPLICATION_SETTING_VALUES = AVRC_TG_PDU_ID_LIST_PLAYER_APPLICATION_SETTING_VALUES, 50 // Send the response of the <b>GetCurrentPlayerApplicationSettingValue</b>. 51 AVRC_TG_SM_EVENT_GET_CURRENT_PLAYER_APPLICATION_SETTING_VALUE = 52 AVRC_TG_PDU_ID_GET_CURRENT_PLAYER_APPLICATION_SETTING_VALUE, 53 // Send the response of the <b>SetPlayerApplicationSettingValue</b>. 54 AVRC_TG_SM_EVENT_SET_PLAYER_APPLICATION_SETTING_VALUE = AVRC_TG_PDU_ID_SET_PLAYER_APPLICATION_SETTING_VALUE, 55 // Send the command of the <b>GetPlayerApplicationSettingAttributeText"</b>. 56 AVRC_TG_SM_EVENT_GET_PLAYER_APPLICATION_SETTING_ATTRIBUTE_TEXT, 57 // Send the command of the <b>GetPlayerApplicationSettingValueText"</b>. 58 AVRC_TG_SM_EVENT_GET_PLAYER_APPLICATION_SETTING_VALUE_TEXT, 59 // Send the response of the <b>GetElementAttributes"</b>. 60 AVRC_TG_SM_EVENT_GET_ELEMENT_ATTRIBTUES, 61 // Send the response of the <b>GetPlayStatus"</b>. 62 AVRC_TG_SM_EVENT_GET_PLAY_STATUS = AVRC_TG_PDU_ID_GET_PLAY_STATUS, 63 // Send the response of the <b>RequestContinuingResponse</b>. 64 AVRC_TG_SM_EVENT_REQUEST_CONTINUING_RESPONSE = AVRC_TG_PDU_ID_REQUEST_CONTINUING_RESPONSE, 65 // Send the response of the <b>AbortContinuingResponse</b>. 66 AVRC_TG_SM_EVENT_ABORT_CONTINUING_RESPONSE = AVRC_TG_PDU_ID_ABORT_CONTINUING_RESPONSE, 67 // Send the response of the <b>SetAddressedPlayer</b>. 68 AVRC_TG_SM_EVENT_SET_ADDRESSED_PLAYER = AVRC_TG_PDU_ID_SET_ADDRESSED_PLAYER, 69 // Send the response of the <b>SetBrowsedPlayer</b>. 70 AVRC_TG_SM_EVENT_SET_BROWSED_PLAYER = AVRC_TG_PDU_ID_SET_BROWSED_PLAYER, 71 // Send the response of the <b>ChangePath</b>. 72 AVRC_TG_SM_EVENT_CHANGE_PATH = AVRC_TG_PDU_ID_CHANGE_PATH, 73 // Send the response of the <b>GetFolderItems</b>. 74 AVRC_TG_SM_EVENT_GET_FOLDER_ITEMS = AVRC_TG_PDU_ID_GET_FOLDER_ITEMS, 75 // Send the response of the <b>GetItemAttributes</b>. 76 AVRC_TG_SM_EVENT_GET_ITEM_ATTRIBUTES = AVRC_TG_PDU_ID_GET_ITEM_ATTRIBUTES, 77 // Send the response of the <b>GetTotalNumberOfItems</b>. 78 AVRC_TG_SM_EVENT_GET_TOTAL_NUMBER_OF_ITEMS = AVRC_TG_PDU_ID_GET_TOTAL_NUMBER_OF_ITEMS, 79 // Send the response of the <b>PlayItem</b>. 80 AVRC_TG_SM_EVENT_PLAY_ITEM = AVRC_TG_PDU_ID_PLAY_ITEM, 81 // Send the response of the <b>AddToNowPlaying</b>. 82 AVRC_TG_SM_EVENT_ADD_TO_NOW_PLAYING = AVRC_TG_PDU_ID_ADD_TO_NOW_PLAYING, 83 // Send the response of the <b>SetAbsoluteVolume</b>. 84 AVRC_TG_SM_EVENT_SET_ABSOLUTE_VOLUME = AVRC_TG_PDU_ID_SET_ABSOLUTE_VOLUME, 85 // Send the response of the <b>RegisterNotification"</b>. 86 AVRC_TG_SM_EVENT_REGISTER_NOTIFICATION = AVRC_TG_PDU_ID_REGISTER_NOTIFICATION, 87 // Send the response of the <b>GENERAL REJECT"</b>. 88 AVRC_TG_SM_EVENT_GENERAL_REJECT = AVRC_TG_PDU_ID_GENERAL_REJECT, 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 SHUTDOWN 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 AvrcTgStateMachineManager { 131 public: 132 /** 133 * @brief A destructor used to delete the <b>AvrcTgStateMachineManager</b> instance. 134 */ 135 ~AvrcTgStateMachineManager(); 136 137 /** 138 * @brief Gets the instance of the <b>AvrcTgStateMachineManager</b> class. 139 * 140 * @return The instance of the <b>AvrcTgStateMachineManager</b> class. 141 */ 142 static AvrcTgStateMachineManager *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 "CONTINUATION" 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 "CONTINUATION". 255 * @retval false Current state is not "CONTINUATION". 256 */ 257 bool IsControlContinuationState(const RawAddress &rawAddr); 258 259 /** 260 * @brief Checks the current state is "DISABLE" 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 "DISABLE". 265 * @retval false Current state is not "DISABLE". 266 */ 267 bool IsControlDisableState(const RawAddress &rawAddr); 268 269 private: 270 /** 271 * @brief This class provides a set of methods for adding/deleting/transiting the state and processing the 272 * messages that are sent to the state machine. 273 */ 274 class StateMachine : public utility::StateMachine { 275 public: 276 /** 277 * @brief This enumeration declares types that are used to distinguish between the control state machine and the 278 * browse state machine. 279 */ 280 enum class Type { 281 AVRC_TG_SM_TYPE_CONTROL, // The control state machine. 282 AVRC_TG_SM_TYPE_BROWSE, // The browse state machine. 283 }; 284 285 /** 286 * @brief A constructor used to create an <b>StateMachine</b> instance. 287 */ 288 StateMachine(Type type, const RawAddress &rawAddr); 289 290 /** 291 * @brief A destructor used to delete the <b>StateMachine</b> instance. 292 */ 293 ~StateMachine() = default; 294 295 /** 296 * @brief Initializes the states. 297 */ 298 void AddStates(void); 299 300 private: 301 // The type of the state machine. 302 Type type_; 303 // The address of the bluetooth device. 304 RawAddress rawAddr_; 305 306 /** 307 * @brief A constructor used to create an <b>StateMachine</b> instance. 308 */ 309 StateMachine() = delete; 310 311 class State : public utility::StateMachine::State { 312 public: 313 explicit State(const std::string &name, utility::StateMachine &stateMachine, const RawAddress &rawAddr); 314 explicit State(const std::string &name, utility::StateMachine &stateMachine, const RawAddress &rawAddr, 315 utility::StateMachine::State &parent); 316 virtual ~State(); 317 318 protected: 319 // The address of the bluetooth device. 320 RawAddress rawAddr_; 321 322 private: 323 State() = delete; 324 }; 325 326 /** 327 * @brief This class provides a set of methods for entry/exit the "CONNECTING" state of the control state 328 * machine and processing messages that are sent to the state. 329 */ 330 class CtConnecting : public State { 331 public: 332 /** 333 * @brief A constructor used to create an <b>CtConnecting</b> instance. 334 */ 335 CtConnecting(const std::string &name, utility::StateMachine &stateMachine, const RawAddress &rawAddr); 336 337 /** 338 * @brief A destructor used to delete the <b>CtConnecting</b> instance. 339 */ 340 ~CtConnecting(void) override = default; 341 342 /** 343 * @brief Enters the state. 344 */ 345 void Entry(void) override; 346 347 /** 348 * @brief Exits the state. 349 */ 350 void Exit(void) override; 351 352 /** 353 * @brief Processes the required messages and send the unwanted to the parent state. 354 * 355 * @param[in] msg The message that need to be sent. 356 * @return The result of the method execution. 357 * @retval true The message is processed. 358 * @retval false The message is not processed. 359 */ 360 bool Dispatch(const utility::Message &msg) override; 361 362 private: 363 /** 364 * @brief A deleted default constructor. 365 */ 366 CtConnecting(void) = delete; 367 }; 368 369 /** 370 * @brief This class provides a set of methods for entry/exit the "CONNECTED" state of the control state 371 * machine and processing messages that are sent to the state. 372 */ 373 class CtConnected : public State { 374 public: 375 /** 376 * @brief A constructor used to create an <b>CtConnected</b> instance. 377 */ 378 CtConnected(const std::string &name, utility::StateMachine &stateMachine, const RawAddress &rawAddr, 379 utility::StateMachine::State &parent); 380 381 /** 382 * @brief A destructor used to delete the <b>CtConnected</b> instance. 383 */ 384 ~CtConnected(void) override = default; 385 386 /** 387 * @brief Enters the state. 388 */ 389 void Entry(void) override; 390 391 /** 392 * @brief Exits the state. 393 */ 394 void Exit(void) override; 395 396 /** 397 * @brief Processes required messages and send unwanted messages to the parent state. 398 * 399 * @param[in] msg The message that need to be sent. 400 * @return The result of the method execution. 401 * @retval true The message is processed. 402 * @retval false The message is not processed. 403 */ 404 bool Dispatch(const utility::Message &msg) override; 405 406 private: 407 /** 408 * @brief A deleted default constructor. 409 */ 410 CtConnected(void) = delete; 411 412 /** 413 * @brief Processes events sent by profile. 414 */ 415 void ToPassThroughEvent(); 416 void ToUnitInfoEvent(); 417 void ToCommonEvent(); 418 void ToAbortContinuingEvent(); 419 }; 420 421 /** 422 * @brief This class provides a set of methods for entry/exit the "DISCONNECTING" state of the control state 423 * machine and processing messages that are sent to the state. 424 */ 425 class CtDisconnecting : public State { 426 public: 427 /** 428 * @brief A constructor used to create an <b>CtDisconnecting</b> instance. 429 */ 430 CtDisconnecting(const std::string &name, utility::StateMachine &stateMachine, const RawAddress &rawAddr, 431 utility::StateMachine::State &parent); 432 433 /** 434 * @brief A destructor used to delete the <b>CtDisconnecting</b> instance. 435 */ 436 ~CtDisconnecting(void) override = default; 437 438 /** 439 * @brief Enters the state. 440 */ 441 void Entry(void) override; 442 443 /** 444 * @brief Exits the state. 445 */ 446 void Exit(void) override; 447 448 /** 449 * @brief Processes required messages and send unwanted messages to the parent state. 450 * 451 * @param[in] msg The message from the control state machine. 452 * @return The result of the method execution. 453 * @retval true The message is processed. 454 * @retval false The message is not processed. 455 */ 456 bool Dispatch(const utility::Message &msg) override; 457 458 private: 459 /** 460 * @brief A deleted default constructor. 461 */ 462 CtDisconnecting(void) = delete; 463 }; 464 465 /** 466 * @brief This class provides a set of methods for entry/exit the "CONTINUATION" state of the control state 467 * machine and processing messages that are sent to the state. 468 */ 469 class CtContinuation : public State { 470 public: 471 /** 472 * @brief A constructor used to create an <b>CtContinuation</b> instance. 473 */ 474 CtContinuation(const std::string &name, utility::StateMachine &stateMachine, const RawAddress &rawAddr, 475 utility::StateMachine::State &parent); 476 477 /** 478 * @brief A destructor used to delete the <b>CtContinuation</b> instance. 479 */ 480 ~CtContinuation(void) override = default; 481 482 /** 483 * @brief Enters the state. 484 */ 485 void Entry(void) override; 486 487 /** 488 * @brief Exits the state. 489 */ 490 void Exit(void) override; 491 492 /** 493 * @brief Processes required messages and send unwanted messages to the parent state. 494 * 495 * @param[in] msg The message from the control state machine. 496 * @return The result of the method execution. 497 * @retval true The message is processed. 498 * @retval false The message is not processed. 499 */ 500 bool Dispatch(const utility::Message &msg) override; 501 502 private: 503 /** 504 * @brief A deleted default constructor. 505 */ 506 CtContinuation(void) = delete; 507 }; 508 509 /** 510 * @brief This class provides a set of methods for entry/exit the "DISABLE" state of the control state 511 * machine and processing messages that are sent to the state. 512 */ 513 class CtDisable : public State { 514 public: 515 /** 516 * @brief A constructor used to create an <b>CtDisable</b> instance. 517 */ 518 CtDisable(const std::string &name, utility::StateMachine &stateMachine, const RawAddress &rawAddr, 519 utility::StateMachine::State &parent); 520 521 /** 522 * @brief A destructor used to delete the <b>CtDisable</b> instance. 523 */ 524 ~CtDisable(void) override = default; 525 526 /** 527 * @brief Enters the state. 528 */ 529 void Entry(void) override; 530 531 /** 532 * @brief Exits the state. 533 */ 534 void Exit(void) override; 535 536 /** 537 * @brief Processes required messages and send unwanted messages to the parent state. 538 * 539 * @param[in] msg The message from the control state machine. 540 * @return The result of the method execution. 541 * @retval true The message is processed. 542 * @retval false The message is not processed. 543 */ 544 bool Dispatch(const utility::Message &msg) override; 545 546 private: 547 /** 548 * @brief A deleted default constructor. 549 */ 550 CtDisable(void) = delete; 551 }; 552 553 /** 554 * @brief This class provides a set of methods for entry/exit the "CONNECTING" state of the browse state 555 * machine and processing messages that are sent to the state. 556 */ 557 class BrConnecting : public State { 558 public: 559 /** 560 * @brief A constructor used to create an <b>BrConnecting</b> instance. 561 */ 562 BrConnecting(const std::string &name, utility::StateMachine &stateMachine, const RawAddress &rawAddr); 563 564 /** 565 * @brief A destructor used to delete the <b>BrConnecting</b> instance. 566 */ 567 ~BrConnecting(void) override = default; 568 569 /** 570 * @brief Enters the state. 571 */ 572 void Entry(void) override; 573 574 /** 575 * @brief Exits the state. 576 */ 577 void Exit(void) override; 578 579 /** 580 * @brief Processes required messages and send unwanted messages to the parent state. 581 * 582 * @param[in] msg The message from the browse state machine. 583 * @return The result of the method execution. 584 * @retval true The message is processed. 585 * @retval false The message is not processed. 586 */ 587 bool Dispatch(const utility::Message &msg) override; 588 589 private: 590 /** 591 * @brief A deleted default constructor. 592 */ 593 BrConnecting(void) = delete; 594 }; 595 596 /** 597 * @brief This class provides a set of methods for entry/exit the "CONNECTED" state of the browse state 598 * machine and processing messages that are sent to the state. 599 */ 600 class BrConnected : public State { 601 public: 602 /** 603 * @brief A constructor used to create an <b>BrConnected</b> instance. 604 */ 605 BrConnected(const std::string &name, utility::StateMachine &stateMachine, const RawAddress &rawAddr, 606 utility::StateMachine::State &parent); 607 608 /** 609 * @brief A destructor used to delete the <b>BrConnected</b> instance. 610 */ 611 ~BrConnected(void) override = default; 612 613 /** 614 * @brief Enters the state. 615 */ 616 void Entry(void) override; 617 618 /** 619 * @brief Exits the state. 620 */ 621 void Exit(void) override; 622 623 /** 624 * @brief Processes required messages and send unwanted messages to the parent state. 625 * 626 * @param[in] msg The message from the browse state machine. 627 * @return The result of the method execution. 628 * @retval true The message is processed. 629 * @retval false The message is not processed. 630 */ 631 bool Dispatch(const utility::Message &msg) override; 632 633 private: 634 /** 635 * @brief A deleted default constructor. 636 */ 637 BrConnected(void) = delete; 638 }; 639 640 /** 641 * @brief This class provides a set of methods for entry/exit the "DISCONNECTING" state of the browse state 642 * machine and processing messages that are sent to the state. 643 */ 644 class BrDisconnecting : public State { 645 public: 646 /** 647 * @brief A constructor used to create an <b>BrDisconnecting</b> instance. 648 */ 649 BrDisconnecting(const std::string &name, utility::StateMachine &stateMachine, const RawAddress &rawAddr, 650 utility::StateMachine::State &parent); 651 652 /** 653 * @brief A destructor used to delete the <b>BrDisconnecting</b> instance. 654 */ 655 ~BrDisconnecting(void) override = default; 656 657 /** 658 * @brief Enters the state. 659 */ 660 void Entry(void) override; 661 662 /** 663 * @brief Exits the state. 664 */ 665 void Exit(void) override; 666 667 /** 668 * @brief Processes required messages and send unwanted messages to the parent state. 669 * 670 * @param[in] msg The message from the browse state machine. 671 * @return The result of the method execution. 672 * @retval true The message is processed. 673 * @retval false The message is not processed. 674 */ 675 bool Dispatch(const utility::Message &msg) override; 676 677 private: 678 /** 679 * @brief A deleted default constructor. 680 */ 681 BrDisconnecting(void) = delete; 682 }; 683 }; 684 685 // This type indicates the pair of the state machine. 686 using StateMachinePair = std::pair<std::unique_ptr<StateMachine>, std::unique_ptr<StateMachine>>; 687 688 // Saves the state machines of the different devices. 689 std::map<std::string, StateMachinePair> stateMachines_ {}; 690 // using a local lock_guard to lock mutex guarantees unlocking on destruction / exception: 691 std::mutex mutex_ {}; 692 693 /** 694 * @brief A constructor used to create an <b>AvrcTgStateMachineManager</b> instance. 695 */ 696 AvrcTgStateMachineManager(); 697 698 /** 699 * @brief Gets the pair of state machines of the specified bluetooth address. 700 * 701 * @param[in] addr The address of the bluetooth device. 702 * @return The pair of state machines of the specified bluetooth address.. 703 */ 704 StateMachinePair *GetPairOfStateMachine(const std::string &addr); 705 706 /** 707 * @brief Checks the current state is specified state or not. 708 * 709 * @param[in] rawAddr The address of the bluetooth device. 710 * @return The result of the method execution. 711 * @retval true Current state is the specified state. 712 * @retval false Current state is not the specified state. 713 */ 714 bool IsControlSpecifiedState(const std::string &addr, std::string stateName); 715 }; 716 } // namespace bluetooth 717 } // namespace OHOS 718 719 #endif // !AVRCP_TG_STATE_MACHINE_H 720