1 /*
2 * Copyright (c) 2024 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 "dh_state_listener.h"
17
18 #include <cinttypes>
19
20 #include "anonymous_string.h"
21 #include "component_manager.h"
22 #include "dh_utils_tool.h"
23 #include "distributed_hardware_log.h"
24
25 class ComponentManager;
26 namespace OHOS {
27 namespace DistributedHardware {
28 #undef DH_LOG_TAG
29 #define DH_LOG_TAG "DHStateListener"
DHStateListener()30 DHStateListener::DHStateListener()
31 {
32 DHLOGI("Ctor DHStateListener");
33 }
34
~DHStateListener()35 DHStateListener::~DHStateListener()
36 {
37 DHLOGI("Dtor DHStateListener");
38 }
39
OnStateChanged(const std::string & networkId,const std::string & dhId,const BusinessState state)40 void DHStateListener::OnStateChanged(const std::string &networkId, const std::string &dhId, const BusinessState state)
41 {
42 if (!IsIdLengthValid(networkId)) {
43 return;
44 }
45 DHLOGI("Receive business state change, networkId: %{public}s, dhId: %{public}s, state: %{public}" PRIu32,
46 GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str(), (uint32_t)state);
47 ComponentManager::GetInstance().UpdateBusinessState(networkId, dhId, state);
48 }
49 } // namespace DistributedHardware
50 } // namespace OHOS