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_ATTRS_H 17 #define SECURITY_GUARD_MODEL_ATTRS_H 18 19 #include <dlfcn.h> 20 21 #include "i_model.h" 22 #include "security_guard_log.h" 23 24 namespace OHOS::Security::SecurityGuard { 25 class ModelAttrs { 26 public: ~ModelAttrs()27 ~ModelAttrs() 28 { 29 SGLOGI("~ModelAttrs"); 30 if (api_ != nullptr) { 31 delete api_; 32 api_ = nullptr; 33 } 34 if (handle_ != nullptr) { 35 dlclose(handle_); 36 handle_ = nullptr; 37 } 38 }; 39 SetHandle(void * handle)40 void SetHandle(void *handle) { handle_ = handle; }; SetModelApi(IModel * api)41 void SetModelApi(IModel *api) { api_ = api; }; GetHandle()42 void *GetHandle() { return handle_; }; GetModelApi()43 IModel *GetModelApi() { return api_; }; 44 45 private: 46 void *handle_; 47 IModel *api_; 48 }; 49 } // namespace OHOS::Security::SecurityGuard 50 51 #endif // SECURITY_GUARD_I_MODEL_MANAGER_API_H 52