Skip to content

Commit

Permalink
Fix #1979, implement abstract config registry module
Browse files Browse the repository at this point in the history
Adds a new module called "config" that tracks simple
key/value pairs.  All values are const.

As a proof of concept, all version information is mirrored
into this key store, and ES is updated to use this instead
of the GLOBAL_CONFIGDATA when generating events.
  • Loading branch information
jphickey committed Sep 28, 2021
1 parent 98f78e8 commit 111fa4b
Show file tree
Hide file tree
Showing 25 changed files with 1,780 additions and 101 deletions.
2 changes: 1 addition & 1 deletion cmake/mission_defaults.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ set(MISSION_CORE_MODULES
"msg"
"sbr"
"resourceid"
"config"
)

# The "MISSION_GLOBAL_APPLIST" is a set of apps/libs that will be built
Expand Down Expand Up @@ -75,4 +76,3 @@ list(APPEND MISSION_GLOBAL_APPLIST cfe_assert)
if (ENABLE_UNIT_TESTS)
list(APPEND MISSION_GLOBAL_APPLIST cfe_testcase)
endif (ENABLE_UNIT_TESTS)

29 changes: 29 additions & 0 deletions modules/config/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
##################################################################
#
# cFE Configuration Service (CONFIG) module CMake build recipe
#
##################################################################

project(CFE_CONFIG C)

# Executive services source files
set(config_SOURCES
fsw/src/cfe_config_init.c
fsw/src/cfe_config_lookup.c
fsw/src/cfe_config_get.c
fsw/src/cfe_config_set.c
)
add_library(config STATIC
${config_SOURCES}
${MISSION_BINARY_DIR}/src/cfe_config_map.c
)

# need to include the "src" dir explicitly here, in order to compile
# the generated tables under ${MISSION_BINARY_DIR}
target_include_directories(config PRIVATE fsw/src)
target_link_libraries(config PRIVATE core_private)

# Add unit test coverage subdirectory
if (ENABLE_UNIT_TESTS)
add_subdirectory(ut-coverage)
endif (ENABLE_UNIT_TESTS)
22 changes: 22 additions & 0 deletions modules/config/cmake/cfe_config_ids.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* This file is auto-generated from CMake build system. Do not manually edit! */
#ifndef CFE_CONFIG_IDS_H
#define CFE_CONFIG_IDS_H

#include "cfe_config_api_typedefs.h"
#include "cfe_resourceid.h"
#include "cfe_core_resourceid_basevalues.h"

/* Value offsets from base (needed for macros; do not use directly) */
enum CFE_ConfigIdOffset
{
@GENERATED_ENUM_OFFSET_LIST@
CFE_ConfigIdOffset_MAX
};

/*
* Set of actual CONFIGID constants -
* these may be used in application code
*/
@GENERATED_CONSTANT_DEFINE_LIST@

#endif /* CFE_CONFIG_IDS_H */
8 changes: 8 additions & 0 deletions modules/config/cmake/cfe_config_map.c.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* This file is auto-generated from CMake build system. Do not manually edit! */
#include "cfe_config_map.h"

/* Map of configuration key IDs to printable names */
const CFE_Config_IdNameEntry_t CFE_CONFIG_IDNAME_MAP[CFE_ConfigIdOffset_MAX] =
{
@GENERATED_IDNAME_MAP_LIST@
};
175 changes: 175 additions & 0 deletions modules/config/fsw/src/cfe_config_get.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
/*
** GSC-18128-1, "Core Flight Executive Version 6.7"
**
** Copyright (c) 2006-2019 United States Government as represented by
** the Administrator of the National Aeronautics and Space Administration.
** All Rights Reserved.
**
** 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.
*/

/**
* @file
*
* API definition for configuration registry
*
* This defines the "getter" functions, which are publicly available
*/

/*
** Required header files.
*/
#include "cfe_config_priv.h"
#include "cfe_config_map.h"

#include <string.h>

/*----------------------------------------------------------------
*
* Function: CFE_Config_GetValue
*
* Defined per public API
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
uint32 CFE_Config_GetValue(CFE_ConfigId_t ConfigId)
{
const CFE_Config_ValueEntry_t *Entry;

Entry = CFE_Config_LocateConfigRecordByID(ConfigId);
if (Entry == NULL || Entry->ActualType != CFE_ConfigType_VALUE)
{
return 0;
}

return Entry->Datum.AsInteger;
}

/*----------------------------------------------------------------
*
* Function: CFE_Config_GetObjPointer
*
* Defined per public API
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
const void *CFE_Config_GetObjPointer(CFE_ConfigId_t ConfigId)
{
const CFE_Config_ValueEntry_t *Entry;

Entry = CFE_Config_LocateConfigRecordByID(ConfigId);
if (Entry == NULL || (Entry->ActualType != CFE_ConfigType_POINTER && Entry->ActualType != CFE_ConfigType_STRING))
{
return NULL;
}

return Entry->Datum.AsPointer;
}

/*----------------------------------------------------------------
*
* Function: CFE_Config_GetObjPointer
*
* Defined per public API
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
const char *CFE_Config_GetString(CFE_ConfigId_t ConfigId)
{
const CFE_Config_ValueEntry_t *Entry;

Entry = CFE_Config_LocateConfigRecordByID(ConfigId);
if (Entry == NULL || Entry->ActualType != CFE_ConfigType_STRING)
{
return CFE_Config_Global.UnknownString;
}

return Entry->Datum.AsPointer;
}

/*----------------------------------------------------------------
*
* Function: CFE_Config_GetName
*
* Defined per public API
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
const char *CFE_Config_GetName(CFE_ConfigId_t ConfigId)
{
uint32 OffsetVal;

OffsetVal = CFE_Config_IdToOffset(ConfigId);

if (OffsetVal >= CFE_ConfigIdOffset_MAX)
{
return CFE_Config_Global.UnknownString;
}

return CFE_CONFIG_IDNAME_MAP[OffsetVal].Name;
}

/*----------------------------------------------------------------
*
* Function: CFE_Config_GetIdByName
*
* Defined per public API
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
CFE_ConfigId_t CFE_Config_GetIdByName(const char *Name)
{
const CFE_Config_IdNameEntry_t *NamePtr;
uint32 OffsetVal;

NamePtr = CFE_CONFIG_IDNAME_MAP;
for (OffsetVal = 0; OffsetVal < CFE_ConfigIdOffset_MAX; ++OffsetVal)
{
if (NamePtr->Name != NULL && strcmp(NamePtr->Name, Name) == 0)
{
break;
}
++NamePtr;
}

if (OffsetVal >= CFE_ConfigIdOffset_MAX)
{
return CFE_CONFIGID_UNDEFINED;
}

return CFE_Config_OffsetToId(OffsetVal);
}

/*----------------------------------------------------------------
*
* Function: CFE_Config_GetIdByName
*
* Defined per public API
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
void CFE_Config_IterateAll(void *Arg, CFE_Config_Callback_t Callback)
{
const CFE_Config_IdNameEntry_t *NamePtr;
uint32 OffsetVal;

NamePtr = CFE_CONFIG_IDNAME_MAP;
for (OffsetVal = 0; OffsetVal < CFE_ConfigIdOffset_MAX; ++OffsetVal)
{
if (CFE_Config_Global.Table[OffsetVal].ActualType != CFE_ConfigType_UNDEFINED)
{
Callback(Arg, CFE_Config_OffsetToId(OffsetVal), NamePtr->Name);
}
++NamePtr;
}
}
Loading

0 comments on commit 111fa4b

Please sign in to comment.