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 "cf_ability.h" 17 18 #include "cf_log.h" 19 #include "cf_result.h" 20 21 static CfAbility g_abilityList[CF_ABILITY_MAX_SIZE] = {{0}}; 22 RegisterAbility(uint32_t id,CfBase * func)23int32_t RegisterAbility(uint32_t id, CfBase *func) 24 { 25 for (uint32_t i = 0; i < CF_ABILITY_MAX_SIZE; ++i) { 26 if (g_abilityList[i].id == id) { 27 return CF_NOT_SUPPORT; 28 } else if (g_abilityList[i].id != 0) { 29 continue; 30 } 31 32 g_abilityList[i].id = id; 33 g_abilityList[i].func = func; 34 return CF_SUCCESS; 35 } 36 CF_LOG_E("register failed: exceed max number of abilities, id = %u", id); 37 return CF_NOT_SUPPORT; 38 } 39 GetAbility(uint32_t id)40CfBase *GetAbility(uint32_t id) 41 { 42 for (uint32_t i = 0; i < CF_ABILITY_MAX_SIZE; ++i) { 43 if (g_abilityList[i].id == id) { 44 return g_abilityList[i].func; 45 } 46 } 47 return NULL; 48 } 49 50