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 "plugin_manager/include/plugin_label.h"
17
18 #include "plugin_manager/include/aie_plugin_info.h"
19 #include "utils/log/aie_log.h"
20
21 namespace OHOS {
22 namespace AI {
23 namespace {
24 const char * const CONFIG_INI_FILE_PATH = "/etc/ai_engine_plugin.ini";
25 const std::string PLUS = "+";
26 const std::string DELIMITER = ":";
27 }
28
29 std::mutex PluginLabel::instanceLock_;
30 PluginLabel *PluginLabel::instance_ = nullptr;
31
GetInstance()32 PluginLabel *PluginLabel::GetInstance()
33 {
34 CHK_RET(instance_ != nullptr, instance_);
35
36 std::lock_guard<std::mutex> lock(instanceLock_);
37 CHK_RET(instance_ != nullptr, instance_);
38
39 PluginLabel *temp = nullptr;
40 AIE_NEW(temp, PluginLabel);
41 CHK_RET(temp == nullptr, nullptr);
42
43 instance_ = temp;
44 return instance_;
45 }
46
ReleaseInstance()47 void PluginLabel::ReleaseInstance()
48 {
49 std::lock_guard<std::mutex> lock(instanceLock_);
50 AIE_DELETE(instance_);
51 }
52
53 PluginLabel::PluginLabel() = default;
54
55 PluginLabel::~PluginLabel() = default;
56
GetLibPath(const std::string & aid,long long & version,std::string & libPath)57 int PluginLabel::GetLibPath(const std::string &aid, long long &version, std::string &libPath)
58 {
59 // The label combined algorithm ID and algorithm version
60 std::string label = aid + PLUS + std::to_string(version);
61 auto queryKey = label + DELIMITER + ALGORITHM_INFO_TABLE_FIELD_NAME_FULLPATH;
62 if (label == "cv_card_rectification+20001001") {
63 libPath = "/usr/lib/libcv_card_rectification.so";
64 } else if (label == "sample_plugin_1+1") {
65 libPath = "/usr/lib/libsample_plugin_1.so";
66 } else if (label == "sample_plugin_2+1") {
67 libPath = "/usr/lib/libsample_plugin_2.so";
68 } else if (label == "asr_keyword_spotting+20001002") {
69 libPath = "/usr/lib/libasr_keyword_spotting.so";
70 } else if (label == "cv_image_classification+20001001") {
71 libPath = "/usr/lib/libcv_image_classification.so";
72 } else {
73 libPath = "";
74 }
75 if (libPath.empty()) {
76 HILOGE("[PluginLabel]Query lib path failed.");
77 return RETCODE_FAILURE;
78 }
79 HILOGI("[PluginLabel]Succeed to get lib path of %s.", aid.c_str());
80 return RETCODE_SUCCESS;
81 }
82 } // namespace AI
83 } // namespace OHOS