1 /*
2 * Copyright (C) 2025-2026 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 "networkslice_loop_manager.h"
17 #include "networkslice_submodule.h"
18 #include "parameters.h"
19
20 namespace OHOS {
21 namespace NetManagerStandard {
22 const std::string NETMANAGER_EXT_NETWORKSLICE_ABILITY = "persist.netmgr_ext.networkslice";
NetworkSlice_Loop_Manager()23 NetworkSlice_Loop_Manager::NetworkSlice_Loop_Manager()
24 {
25 NETMGR_EXT_LOG_I("NetworkSlice_Loop_Manager start");
26 bool isSupportNrSlice = OHOS::system::GetBoolParameter(NETMANAGER_EXT_NETWORKSLICE_ABILITY, false);
27 if (isSupportNrSlice) {
28 initLoopMap();
29 NETMGR_EXT_LOG_I("NetworkSlice_Loop_Manager end");
30 }
31 }
32 NetworkSlice_Loop_Manager::~NetworkSlice_Loop_Manager() = default;
33
initLoopMap()34 void NetworkSlice_Loop_Manager::initLoopMap()
35 {
36 NETMGR_EXT_LOG_I("initLoopMap start");
37 std::unordered_map<LooperType, std::string> loopTypeToString = {
38 {OLLIE_MESSAGE_THREAD, "OllieMsgThread"}
39 };
40
41 for (auto it = loopTypeToString.begin(); it != loopTypeToString.end(); it++) {
42 auto loop = AppExecFwk::EventRunner::Create(it->second);
43 if (loop == nullptr) {
44 NETMGR_EXT_LOG_E("Lopper Create failed. %{public}s", it->second.c_str());
45 continue;
46 }
47 loopMap_.insert(std::make_pair(it->first, loop));
48 }
49 NETMGR_EXT_LOG_I("initLoopMap end");
50 }
51
getLoop(LooperType type)52 std::shared_ptr<AppExecFwk::EventRunner> NetworkSlice_Loop_Manager::getLoop(LooperType type)
53 {
54 NETMGR_EXT_LOG_I("getLoop start");
55 auto it = loopMap_.find(type);
56 if (it != loopMap_.end()) {
57 return it->second;
58 }
59 NETMGR_EXT_LOG_I("getLoop null");
60 return nullptr;
61 }
62 } // namespace NetManagerStandard
63 } // namespace OHOS
64