Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for <hints> elements within CDI representation #803

Merged
merged 4 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 54 additions & 4 deletions src/openlcb/ConfigRenderer.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ struct AtomConfigDefs
DECLARE_OPTIONALARG(Name, name, const char *, 0, nullptr);
DECLARE_OPTIONALARG(Description, description, const char *, 1, nullptr);
DECLARE_OPTIONALARG(MapValues, mapvalues, const char *, 2, nullptr);
DECLARE_OPTIONALARG(Hints, hints, const char *, 3, nullptr);
DECLARE_OPTIONALARG(SkipInit, skip_init, int, 15, 0);
DECLARE_OPTIONALARG(Offset, offset, int, 10, 0);
using Base = OptionalArg<AtomConfigDefs, Name, Description, MapValues, SkipInit, Offset>;
using Base = OptionalArg<AtomConfigDefs, Name, Description, MapValues,
Hints, SkipInit, Offset>;
};

/// Configuration implementation class for CDI Atom elements (strings, events
Expand All @@ -71,6 +73,8 @@ public:
DEFINE_OPTIONALARG(Description, description, const char *);
/// Represent the value enclosed in the "<map>" tag of the data element.
DEFINE_OPTIONALARG(MapValues, mapvalues, const char *);
/// Represent the value enclosed in the "<hints>" tag of the data element.
DEFINE_OPTIONALARG(Hints, hints, const char *);
/// When set to true, the event initializers will be skipped in this event
/// or group.
DEFINE_OPTIONALARG(SkipInit, skip_init, int);
Expand All @@ -94,6 +98,10 @@ public:
{
*r += StringPrintf("<map>%s</map>\n", mapvalues());
}
if (hints())
{
*r += StringPrintf("<hints>%s</hints>\n", hints());
}
}
};

Expand Down Expand Up @@ -147,7 +155,7 @@ struct NumericConfigDefs : public AtomConfigDefs
DECLARE_OPTIONALARG(Max, maxvalue, int, 7, INT_MAX);
DECLARE_OPTIONALARG(Default, defaultvalue, int, 8, INT_MAX);
using Base = OptionalArg<NumericConfigDefs, Name, Description, MapValues,
Min, Max, Default, SkipInit, Offset>;
Hints, Min, Max, Default, SkipInit, Offset>;
};

/// Definitions for the options for numeric CDI entries.
Expand All @@ -164,6 +172,8 @@ public:
DEFINE_OPTIONALARG(Description, description, const char *);
/// Represent the value enclosed in the <map> tag of the data element.
DEFINE_OPTIONALARG(MapValues, mapvalues, const char *);
/// Represent the value enclosed in the <hints> tag of the data element.
DEFINE_OPTIONALARG(Hints, hints, const char *);
DEFINE_OPTIONALARG(Min, minvalue, int);
DEFINE_OPTIONALARG(Max, maxvalue, int);
DEFINE_OPTIONALARG(Default, defaultvalue, int);
Expand All @@ -181,6 +191,10 @@ public:
*r +=
StringPrintf("<description>%s</description>\n", description());
}
if (hints())
{
*r += StringPrintf("<hints>%s</hints>\n", hints());
}
if (minvalue() != INT_MAX)
{
*r += StringPrintf("<min>%d</min>\n", minvalue());
Expand Down Expand Up @@ -262,8 +276,12 @@ struct GroupConfigDefs : public AtomConfigDefs
DECLARE_OPTIONALARG(RepName, repname, const char*, 12, nullptr);
DECLARE_OPTIONALARG(FixedSize, fixed_size, unsigned, 13, 0);
DECLARE_OPTIONALARG(Hidden, hidden, int, 14, 0);
// 15 is used for SkipInit
DECLARE_OPTIONALARG(LinkRef, linkref, const char *, 16, nullptr);
DECLARE_OPTIONALARG(LinkText, linktext, const char *, 17, nullptr);
using Base = OptionalArg<GroupConfigDefs, Name, Description, Segment,
Offset, RepName, FixedSize, Hidden>;
Hints, LinkRef, LinkText, Offset, RepName,
FixedSize, Hidden>;
};

/// Implementation class for the condifuration options of a CDI group element.
Expand Down Expand Up @@ -299,6 +317,15 @@ public:
/// reserved and skipped.
DEFINE_OPTIONALARG(Hidden, hidden, int);

/// Represent the value enclosed in the <hints> tag of the data element.
DEFINE_OPTIONALARG(Hints, hints, const char *);

/// Represent the <link ref=..> value.
DEFINE_OPTIONALARG(LinkRef, linkref, const char *);

/// Represent the value enclosed in the <link> tag of the data element.
DEFINE_OPTIONALARG(LinkText, linktext, const char *);

/// Declares that this group is a toplevel CDI. Causes the group to render
/// the xml header.
/// static constexpr Segment MainCdi() { return Segment(-2); }
Expand Down Expand Up @@ -353,11 +380,21 @@ public:
*r +=
StringPrintf("<description>%s</description>\n", description());
}
if (hints())
{
*r += StringPrintf("<hints>%s</hints>\n", hints());
}
if (repname())
{
*r +=
StringPrintf("<repname>%s</repname>\n", repname());
}
if (linkref())
{
*r +=
StringPrintf("<link ref=\"%s\">%s</link>\n", linkref(),
has_linktext() ? linktext() : linkref());
}
}
};

Expand Down Expand Up @@ -480,8 +517,13 @@ struct IdentificationConfigDefs
DECLARE_OPTIONALARG(Model, model, const char *, 1, nullptr);
DECLARE_OPTIONALARG(HwVersion, hardware_version, const char *, 2, nullptr);
DECLARE_OPTIONALARG(SwVersion, software_version, const char *, 3, nullptr);
// NOTE: the unique index for LinkRef and LinkText must match the values
// used in GroupConfigDefs otherwise complile_cdi will enter recursive loop
// and segfault.
DECLARE_OPTIONALARG(LinkRef, linkref, const char *, 16, nullptr);
DECLARE_OPTIONALARG(LinkText, linktext, const char *, 17, nullptr);
using Base = OptionalArg<IdentificationConfigDefs, Manufacturer, Model,
HwVersion, SwVersion>;
HwVersion, SwVersion, LinkRef, LinkText>;
};

/// Configuration implementation options for rendering CDI (identification)
Expand All @@ -496,6 +538,8 @@ public:
DEFINE_OPTIONALARG(Model, model, const char *);
DEFINE_OPTIONALARG(HwVersion, hardware_version, const char *);
DEFINE_OPTIONALARG(SwVersion, software_version, const char *);
DEFINE_OPTIONALARG(LinkRef, linkref, const char *);
DEFINE_OPTIONALARG(LinkText, linktext, const char *);

constexpr int skip_init() const
{
Expand Down Expand Up @@ -542,6 +586,12 @@ public:
alt(opts.hardware_version(), SNIP_STATIC_DATA.hardware_version), s);
render_tag("softwareVersion",
alt(opts.software_version(), SNIP_STATIC_DATA.software_version), s);
if (opts.linkref())
{
*s +=
StringPrintf("<link ref=\"%s\">%s</link>\n", opts.linkref(),
alt(opts.linktext(), opts.linkref()));
}
*s += "</identification>\n";
}
};
Expand Down
3 changes: 3 additions & 0 deletions src/openlcb/ConfigRepresentation.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public:
using Name = AtomConfigOptions::Name;
using Description = AtomConfigOptions::Description;
using MapValues = AtomConfigOptions::MapValues;
using Hints = AtomConfigOptions::Hints;
using SkipInit = AtomConfigOptions::SkipInit;
using Min = NumericConfigOptions::Min;
using Max = NumericConfigOptions::Max;
Expand All @@ -109,6 +110,8 @@ public:
using RepName = GroupConfigOptions::RepName;
using FixedSize = GroupConfigOptions::FixedSize;
using Hidden = GroupConfigOptions::Hidden;
using LinkRef = GroupConfigOptions::LinkRef;
using LinkText = GroupConfigOptions::LinkText;
using Manufacturer = IdentificationConfigOptions::Manufacturer;
using Model = IdentificationConfigOptions::Model;
using HwVersion = IdentificationConfigOptions::HwVersion;
Expand Down