xref: /ide/tools/previewer/util/ModelManager.cpp (revision 7c804472)
1/*
2 * Copyright (c) 2023 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 <sstream>
17#include "ModelManager.h"
18
19#include "Interrupter.h"
20#include "PreviewerEngineLog.h"
21
22std::vector<ModelConfig> ModelManager::configList = { // NOLINT
23    {"liteWearable", "***", "***", "***", "***", 2},
24    {"smartVision", "***", "***", "***", "***", 2},
25};
26
27std::string ModelManager::currentDevice;
28
29std::string ModelManager::GetCurrentModel()
30{
31    return currentDevice;
32}
33
34std::string ModelManager::GetAllModelName()
35{
36    std::ostringstream allNames;
37    for (ModelConfig const& config : configList) {
38        allNames << std::string(config.modelName);
39        allNames << " ";
40    }
41    return allNames.str();
42}
43
44void ModelManager::SetCurrentDevice(const std::string& value)
45{
46    currentDevice = value;
47    ILOG("Start Simulator: %s", GetConfig().modelName.c_str());
48}
49
50/*
51 * Get the model configuration based on the model name.
52 */
53const ModelConfig& ModelManager::GetConfig(std::string device)
54{
55    for (ModelConfig const& config : configList) {
56        if (config.deviceType == device) {
57            return config;
58        }
59    }
60    FLOG("ModelManager::GetConfig current device model not exists. device : %s", currentDevice.c_str());
61    Interrupter::Interrupt();
62    return *configList.begin();
63}
64
65const ModelConfig& ModelManager::GetConfig()
66{
67    return GetConfig(currentDevice);
68}
69