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_disconnecting_state.h"
17 #include "pbap_pce_service.h"
18 #include "power_manager.h"
19
20 namespace OHOS {
21 namespace bluetooth {
PceDisconnectingState(const std::string & name,PbapPceStateMachine & stm,BaseObserverList<IPbapPceObserver> & observerMgrList)22 PceDisconnectingState::PceDisconnectingState(
23 const std::string &name, PbapPceStateMachine &stm, BaseObserverList<IPbapPceObserver> &observerMgrList)
24 : PceBaseState(name, stm, observerMgrList)
25 {}
26
Entry()27 void PceDisconnectingState::Entry()
28 {
29 PBAP_PCE_LOG_INFO("%{public}s start, Observer()->OnServiceConnectionStateChanged()->DISCONNECTING",
30 __PRETTY_FUNCTION__);
31 auto &device = stm_.GetDevice();
32 observerMgrList_.ForEach([device](IPbapPceObserver &observer) {
33 observer.OnServiceConnectionStateChanged(device, static_cast<int>(BTConnectState::DISCONNECTING));
34 });
35
36 PBAP_PCE_LOG_INFO("%{public}s end", __PRETTY_FUNCTION__);
37 }
38
Exit()39 void PceDisconnectingState::Exit()
40 {}
41
Dispatch(const utility::Message & msg)42 bool PceDisconnectingState::Dispatch(const utility::Message &msg)
43 {
44 PBAP_PCE_LOG_INFO("%{public}s start, msg.what_=[%{public}d]", __PRETTY_FUNCTION__, msg.what_);
45 uint8_t ret = true;
46 switch (msg.what_) {
47 case PCE_OBEX_DISCONNECTED:
48 Transition(PCE_DISCONNECTED_STATE);
49 break;
50 case PCE_REQ_SET_TARGET_STATE:
51 stm_.SetTargetState(msg.arg1_);
52 break;
53 case PCE_REQ_TRANSIT_TARGET_STATE:
54 stm_.TransitTargetState();
55 break;
56 default:
57 stm_.TryReleasePbapMsg(msg);
58 return false;
59 }
60
61 PBAP_PCE_LOG_INFO("%{public}s end, msg.what_=[%{public}d]", __PRETTY_FUNCTION__, msg.what_);
62 return ret;
63 }
64 } // namespace bluetooth
65 } // namespace OHOS