1 /* 2 * Copyright (c) 2025 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 #define LOG_TAG "global_resource" 17 #include "global_resource.h" 18 19 #include "rdb_errno.h" 20 21 namespace OHOS::NativeRdb { 22 static GlobalResource::Cleaner g_cleaners[GlobalResource::CLEAN_BUTT]; RegisterClean(CleanType type,Cleaner clean)23int32_t GlobalResource::RegisterClean(CleanType type, Cleaner clean) 24 { 25 if (type < static_cast<int32_t>(GlobalResource::ICU) || type >= static_cast<int32_t>(GlobalResource::CLEAN_BUTT) || 26 clean == nullptr) { 27 return E_INVALID_ARGS; 28 } 29 30 if (g_cleaners[type] != nullptr) { 31 return E_OK; 32 } 33 34 g_cleaners[type] = clean; 35 return E_OK; 36 } 37 CleanUp(int32_t type)38int32_t GlobalResource::CleanUp(int32_t type) 39 { 40 if (type < static_cast<int32_t>(GlobalResource::CLEAN_HEAD) || 41 type >= static_cast<int32_t>(GlobalResource::CLEAN_BUTT)) { 42 return E_INVALID_ARGS; 43 } 44 45 int32_t ret = E_OK; 46 if (g_cleaners[type] != nullptr) { 47 ret = g_cleaners[type](); 48 } 49 50 return ret; 51 } 52 } // namespace OHOS::NativeRdb