/* * Copyright (c) 2023 Fancy Code. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "ConfigBaseCode.h" #include "ILog.h" #include static const char *ConfigCodeString[CONFIG_CODE_END - STATUS_CODE_END + 1] = {"CONFIG_CODE_PARAM_NOT_EXIST", "CONFIG_CODE_END"}; static const char *PrintStringConfigCode(const StatusCode this) { const int CODE_INDEX = this.mStatusCode - STATUS_CODE_END; if (STATUS_CODE_END <= this.mStatusCode && this.mStatusCode <= CONFIG_CODE_END) { LogInfo("Config code = [ %s ]\n", ConfigCodeString[CODE_INDEX]); return ConfigCodeString[CODE_INDEX]; } LogError("Config code undefine.\n"); return "Config code undefine.\n"; } static const bool CodeEqual(const StatusCode code, const char *value) { if (memcmp(value, ConfigCodeString[code.mStatusCode - STATUS_CODE_END], strlen(value)) == 0) { return true; } return false; } static StatusCode NewConfigCode(const long int code) { StatusCode result = {PrintStringConfigCode, CodeEqual, code}; return result; } const StatusCode CreateConfigCode(const long int code) { // if (STATUS_CODE_OK <= code && code < STATUS_CODE_END) // { // return CreateStatusCode(code); // } if (STATUS_CODE_END <= code && code < CONFIG_CODE_END) { return NewConfigCode(code); } LogError("undefined code.\n"); return CreateStatusCode(STATUS_CODE_END); }