Skip to content

Commit

Permalink
Add LinkRef/LinkText to Group/Segment and Identification.
Browse files Browse the repository at this point in the history
  • Loading branch information
atanisoft committed Nov 22, 2024
1 parent b09a089 commit 419bbd8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 12 deletions.
70 changes: 58 additions & 12 deletions src/openlcb/ConfigRenderer.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ struct AtomConfigDefs
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 Down Expand Up @@ -99,7 +100,7 @@ public:
}
if (hints())
{
*r += StringPrintf("<hints>%s</hints>\n", mapvalues());
*r += StringPrintf("<hints>%s</hints>\n", hints());
}
}
};
Expand Down Expand Up @@ -190,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 All @@ -206,10 +211,6 @@ public:
{
*r += StringPrintf("<map>%s</map>\n", mapvalues());
}
if (hints())
{
*r += StringPrintf("<hints>%s</hints>\n", mapvalues());
}
}

int clip(int value) {
Expand Down Expand Up @@ -275,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,
Hints, 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 @@ -312,8 +317,14 @@ public:
/// reserved and skipped.
DEFINE_OPTIONALARG(Hidden, hidden, int);

/// Represents the value enclosed in the <hints> tag of the data element.
DEFINE_OPTIONALARG(Hints, hints, const char*);
/// 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.
Expand Down Expand Up @@ -369,14 +380,28 @@ 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 (hints())
if (linkref())
{
*r += StringPrintf("<hints>%s</hints>\n", hints());
*r +=
StringPrintf("<link ref=\"%s\"", linkref());
if (linktext())
{
*r +=
StringPrintf(">%s</link>\n", linktext());
}
else
{
*r += " />\n";
}
}
}
};
Expand Down Expand Up @@ -500,8 +525,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 @@ -516,6 +546,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 @@ -562,6 +594,20 @@ 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\"", opts.linkref());
if (opts.linktext())
{
*s +=
StringPrintf(">%s</link>\n", opts.linktext());
}
else
{
*s += " />\n";
}
}
*s += "</identification>\n";
}
};
Expand Down
2 changes: 2 additions & 0 deletions src/openlcb/ConfigRepresentation.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -110,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

0 comments on commit 419bbd8

Please sign in to comment.