• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "pbap_pce_disconnected_state.h"
17 #include "btm.h"
18 #include "pbap_pce_def.h"
19 #include "pbap_pce_service.h"
20 #include "pbap_pce_state_machine.h"
21 #include "power_manager.h"
22 
23 namespace OHOS {
24 namespace bluetooth {
PceDisconnectedState(const std::string & name,PbapPceStateMachine & stm,BaseObserverList<IPbapPceObserver> & observerMgrList)25 PceDisconnectedState::PceDisconnectedState(
26     const std::string &name, PbapPceStateMachine &stm, BaseObserverList<IPbapPceObserver> &observerMgrList)
27     : PceBaseState(name, stm, observerMgrList)
28 {}
29 
Entry()30 void PceDisconnectedState::Entry()
31 {
32     PBAP_PCE_LOG_INFO("%{public}s start", __PRETTY_FUNCTION__);
33     if (stm_.GetGap() != nullptr) {  // when sdpsearch failure, stm_.GetGap() is nullptr
34         int retVal = stm_.GetGap()->Deregister();
35         if (retVal != BT_SUCCESS) {
36             PBAP_PCE_LOG_ERROR("ProcessDisconnected GAP_Deregister() error");
37         }
38     }
39 
40     PBAP_PCE_LOG_INFO("%{public}s, observer->OnServiceConnectionStateChanged", __PRETTY_FUNCTION__);
41     auto &device = stm_.GetDevice();
42     IPowerManager::GetInstance().StatusUpdate(RequestStatus::CONNECT_OFF, PROFILE_NAME_PBAP_PCE, device);
43     observerMgrList_.ForEach([device](IPbapPceObserver &observer) {
44         observer.OnServiceConnectionStateChanged(device, static_cast<int>(BTConnectState::DISCONNECTED));
45     });
46     stm_.RemoveBTMLogging();
47     stm_.TransitTargetState();
48     PBAP_PCE_LOG_INFO("%{public}s end", __PRETTY_FUNCTION__);
49 }
50 
Exit()51 void PceDisconnectedState::Exit()
52 {
53     PBAP_PCE_LOG_INFO("%{public}s start", __PRETTY_FUNCTION__);
54     PBAP_PCE_LOG_INFO("%{public}s end", __PRETTY_FUNCTION__);
55 }
56 
Dispatch(const utility::Message & msg)57 bool PceDisconnectedState::Dispatch(const utility::Message &msg)
58 {
59     PBAP_PCE_LOG_INFO("%{public}s start, msg.what_=[%{public}d]", __PRETTY_FUNCTION__, msg.what_);
60     switch (msg.what_) {
61         case PCE_REQ_SET_TARGET_STATE:
62             stm_.SetTargetState(msg.arg1_);
63             break;
64         case PCE_REQ_TRANSIT_TARGET_STATE:
65             stm_.TransitTargetState();
66             break;
67         default:
68             stm_.TryReleasePbapMsg(msg);
69             break;
70     }
71     PBAP_PCE_LOG_INFO("%{public}s end, msg.what_=[%{public}d]", __PRETTY_FUNCTION__, msg.what_);
72     return true;
73 }
74 }  // namespace bluetooth
75 }  // namespace OHOS
76