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 #ifndef SECURITY_GUARD_MODEL_MANAGER_H 17 #define SECURITY_GUARD_MODEL_MANAGER_H 18 19 #include <cstdint> 20 #include <mutex> 21 #include <vector> 22 #include <unordered_map> 23 24 #include "singleton.h" 25 26 #include "i_model_manager.h" 27 #include "model_attrs.h" 28 #include "i_model_result_listener.h" 29 30 namespace OHOS::Security::SecurityGuard { 31 class ModelManager : public Singleton<ModelManager> { 32 public: 33 void Init(); 34 int32_t InitModel(uint32_t modelId); 35 std::string GetResult(uint32_t modelId, const std::string ¶m); 36 int32_t SubscribeResult(uint32_t modelId, std::shared_ptr<IModelResultListener> listener); 37 void Release(uint32_t modelId); 38 39 private: 40 std::mutex mutex_; 41 std::unordered_map<uint32_t, std::unique_ptr<ModelAttrs>> modelIdApiMap_; 42 static std::shared_ptr<IModelManager> modelManagerApi_; 43 }; 44 } // namespace OHOS::Security::SecurityGuard 45 46 #endif // SECURITY_GUARD_I_MODEL_MANAGER_API_H 47