Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
ConfigRepresentation.hxx File Reference

Go to the source code of this file.

Classes

class  openlcb::GroupBaseEntry
 Constexpr base class for all group like structures. More...
 
class  openlcb::EntryMarker< N >
 Helper class for partial template specialization. More...
 
class  openlcb::NoopGroupEntry
 Empty group entry that can be used for structuring the CDI configs. More...
 
class  openlcb::GroupBase
 Base class for all CDI Group structures (including segment, and the whole CDI entry). More...
 
class  openlcb::RepeatedGroup< Group, N >
 Defines a repeated group of a given type and a given number of repeats. More...
 
class  openlcb::EmptyGroup< N >
 Defines an empty group with no members, but blocking a certain amount of space in the rendered configuration. More...
 
class  openlcb::ToplevelEntryBase
 Base class for all entries that can appear in the MainCdi group. More...
 
class  openlcb::Identification
 Add this entry to the beginning of the CDI group to render an "<identification>" tag at the beginning of the output cdi.xml. More...
 
class  openlcb::Acdi
 Renders an "<acdi>" tag in the CDI group. More...
 

Namespaces

namespace  openlcb
 

Macros

#define CDI_GROUP_HELPER(START_LINE, GroupName, ARGS...)
 Helper macro for rendering code for CDI groups.
 
#define CDI_GROUP_ENTRY_HELPER(LINE, NAME, TYPE, ...)
 
#define CDI_GROUP_END_HELPER(LINE)
 Helper macro to generate the code needed at the end of a group.
 
#define CDI_GROUP(GroupName, ARGS...)    CDI_GROUP_HELPER(__LINE__, GroupName, ##ARGS)
 Starts a CDI group.
 
#define CDI_GROUP_ENTRY(NAME, TYPE, ARGS...)    CDI_GROUP_ENTRY_HELPER(__LINE__, NAME, TYPE, ##ARGS)
 Adds an entry to a CDI group.
 
#define CDI_GROUP_END()   CDI_GROUP_END_HELPER(__LINE__)
 Closes a CDI group structure definition.
 
#define CDI_FACTORY_RESET(PATH)    PATH().write(fd, PATH##_options().defaultvalue())
 Performs factory reset on a CDI variable.
 
#define CDI_READ_TRIMMED(PATH, fd)
 Requests a readout of a numeric variable with trimming.
 
#define CDI_READ_TRIM_DEFAULT(PATH, fd)
 Requests a readout of a numeric variable with verifying range.
 
#define RENDER_CDI(NS, TYPE, NAME, N)
 Use this macro if additional CDI entries need to be rendered, in addition to the openlcb::ConfigDef.
 

Functions

 openlcb::CDI_GROUP (UserInfoSegment, Segment(MemoryConfigDefs::SPACE_ACDI_USR), Offset(1))
 Configuration description for a segment containing the ACDI user-modifiable data.
 
 openlcb::CDI_GROUP_ENTRY (name, StringConfigEntry< 63 >, Name("User Name"), Description("This name will appear in network browsers for this device."))
 User name entry.
 
 openlcb::CDI_GROUP_ENTRY (description, StringConfigEntry< 64 >, Name("User Description"), Description("This description will appear in network browsers for " "this device."))
 User description entry.
 
 openlcb::CDI_GROUP_END ()
 Signals termination of the group.
 
 openlcb::CDI_GROUP (InternalConfigData, Name("Internal data"), Description("Do not change these settings."))
 Configuration description for internal configuration variables.
 
 openlcb::CDI_GROUP_ENTRY (version, Uint16ConfigEntry, Name("Version"))
 Used to detect firmwares that have their config layout set in incompatible ways.
 
 openlcb::CDI_GROUP_ENTRY (next_event, Uint16ConfigEntry, Name("Next event ID"))
 Last two bytes ofthe next available event ID that can be assigned in a factory reset to the producers/consumers.
 
template<typename CdiType >
void render_cdi_helper (const CdiType &t, string ns, string name)
 Helper function defined in CompileCdiMain.cxx.
 
template<int N>
void render_all_cdi ()
 Forward declaration of the recursive helper template for adding multiple CDIs to a single binary image.
 
template<>
void render_all_cdi< 0 > ()
 End-of-recursion template instantiation for CDI rendering.
 

Detailed Description

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Static representation of a config file.

Author
Balazs Racz
Date
31 May 2014

Definition in file ConfigRepresentation.hxx.

Macro Definition Documentation

◆ CDI_FACTORY_RESET

#define CDI_FACTORY_RESET (   PATH)     PATH().write(fd, PATH##_options().defaultvalue())

Performs factory reset on a CDI variable.

The variable must have a default value defined. Usage: CDI_FACTORY_RESET(opts_.short_retry_delay); assuming that there is something like CDI_GROUP_ENTRY(short_retry_delay, Uint8ConfigEntry, Default(13)); in the CDI group whose type opts_ is, and there is a local variable fd for writing to the configuration file. Will generate compile error if the variable does not have a default value in the configuration group entry.

Definition at line 301 of file ConfigRepresentation.hxx.

◆ CDI_GROUP

#define CDI_GROUP (   GroupName,
  ARGS... 
)     CDI_GROUP_HELPER(__LINE__, GroupName, ##ARGS)

Starts a CDI group.

Parameters
GroupNameis the c++ name of the struct that is being defined.
ARGSare additional arguments for group options, like Name(...), Description(...), Segment(...), Offset(...) or MainCdi().

Definition at line 275 of file ConfigRepresentation.hxx.

◆ CDI_GROUP_END

#define CDI_GROUP_END ( )    CDI_GROUP_END_HELPER(__LINE__)

Closes a CDI group structure definition.

Definition at line 290 of file ConfigRepresentation.hxx.

◆ CDI_GROUP_END_HELPER

#define CDI_GROUP_END_HELPER (   LINE)
Value:
constexpr unsigned end_offset() const \
{ \
static_assert((group_opts().fixed_size() == 0) || \
(zero_offset_this() \
.end_offset() <= (unsigned)group_opts().fixed_size()), \
"FixedSize group contents too large"); \
return (group_opts().fixed_size() == 0) \
? entry(openlcb::EntryMarker<LINE>()).end_offset() \
: offset_ + group_opts().fixed_size(); \
} \
constexpr unsigned end_buffer_length() const \
{ \
return group_opts().fixed_size() - \
(entry(openlcb::EntryMarker<LINE>()).end_offset() - offset()); \
} \
static void render_content_cdi(std::string *s) \
{ \
return render_content_cdi(openlcb::EntryMarker<LINE>(), s); \
} \
void __attribute__((always_inline)) \
handle_events(const openlcb::EventOffsetCallback &fn) \
{ \
recursive_handle_events(openlcb::EntryMarker<LINE>(), fn); \
} \
}
Helper class for partial template specialization.
std::function< void(unsigned)> EventOffsetCallback
Function declaration that will be called with all event offsets that exist in the configuration space...

Helper macro to generate the code needed at the end of a group.

Parameters
LINEline number in the config.hxx where this group should end. Used to start the recursion looking for group entries.

Definition at line 242 of file ConfigRepresentation.hxx.

◆ CDI_GROUP_ENTRY

#define CDI_GROUP_ENTRY (   NAME,
  TYPE,
  ARGS... 
)     CDI_GROUP_ENTRY_HELPER(__LINE__, NAME, TYPE, ##ARGS)

Adds an entry to a CDI group.

Parameters
NAMEis the c++ name of the entry
TYPEis the c++ class / struct of the entry being added
ARGSare additional arguments for the entry options, like Name(...), Description(...). If a subgroup is added, then group options are also allowed and they will override the respective values from the group definition.

Definition at line 286 of file ConfigRepresentation.hxx.

◆ CDI_GROUP_ENTRY_HELPER

#define CDI_GROUP_ENTRY_HELPER (   LINE,
  NAME,
  TYPE,
  ... 
)
Todo:
(balazs.racz) the group config renderer should not get an instance of the current group.

Definition at line 195 of file ConfigRepresentation.hxx.

◆ CDI_GROUP_HELPER

#define CDI_GROUP_HELPER (   START_LINE,
  GroupName,
  ARGS... 
)

Helper macro for rendering code for CDI groups.

Parameters
START_LINEthe line number (in the config.hxx) file where the group starts. This line number will be used to terminate the recursion looking for config entries.
GroupNameC++ identifier for the name of this group.
ARGSProxied additional arguments, forwarded to the Options class.

Definition at line 134 of file ConfigRepresentation.hxx.

◆ CDI_READ_TRIM_DEFAULT

#define CDI_READ_TRIM_DEFAULT (   PATH,
  fd 
)
Value:
PATH().read_or_write_default(fd, PATH##_options().minvalue(), \
PATH##_options().maxvalue(), PATH##_options().defaultvalue())

Requests a readout of a numeric variable with verifying range.

If the value currently present in the config file is outside the defined minimum/maximum, then sets the value to the default value in the config file (overwriting). Returns the current value after trimming.

Usage: uint16_t my_value = CDI_READ_TRIM_DEFAULT(cfg.seg().foo_bar, fd);

Definition at line 322 of file ConfigRepresentation.hxx.

◆ CDI_READ_TRIMMED

#define CDI_READ_TRIMMED (   PATH,
  fd 
)
Value:
PATH().read_or_write_trimmed( \
fd, PATH##_options().minvalue(), PATH##_options().maxvalue())

Requests a readout of a numeric variable with trimming.

If the value currently present in the config file is less than the defined minimum, then sets the value to the minimum in the config file (overwriting), same for max. Returns the current value after trimming.

Usage: uint16_t my_value = CDI_READ_TRIMMED(cfg.seg().foo_bar, fd);

Definition at line 311 of file ConfigRepresentation.hxx.

◆ RENDER_CDI

#define RENDER_CDI (   NS,
  TYPE,
  NAME,
 
)
Value:
template <> inline void render_all_cdi<2 * N>() \
{ \
NS::TYPE def(0); \
render_cdi_helper(def, #NS, NAME); \
render_all_cdi<2 * N - 1>(); \
}
void render_all_cdi()
Forward declaration of the recursive helper template for adding multiple CDIs to a single binary imag...

Use this macro if additional CDI entries need to be rendered, in addition to the openlcb::ConfigDef.

Example usage:

} // namespace XXX – RENDER_CDI will work only if at toplevel!

RENDER_CDI(openlcb, ConfigDef, "CDI", 3); this will create CDI_DATA and CDI_SIZE symbols.

Parameters
NSis the namespace without quotes
TYPEis the typename of the CDI root group (with MainCdi())
NAMEis the basenamefor the output symbols. Generated will be _DATA and _SIZE
Nis a unique integer between 2 and 10 for the invocation.

Definition at line 515 of file ConfigRepresentation.hxx.

Function Documentation

◆ render_all_cdi()

template<int N>
void render_all_cdi ( )

Forward declaration of the recursive helper template for adding multiple CDIs to a single binary image.

Definition at line 17 of file CompileCdiMain.cxx.

◆ render_all_cdi< 0 >()

template<>
void render_all_cdi< 0 > ( )
inline

End-of-recursion template instantiation for CDI rendering.

Definition at line 497 of file ConfigRepresentation.hxx.

◆ render_cdi_helper()

template<typename CdiType >
void render_cdi_helper ( const CdiType &  t,
string  ns,
string  name 
)

Helper function defined in CompileCdiMain.cxx.

Definition at line 24 of file CompileCdiMain.cxx.