minor changes and addeed debug tests
This commit is contained in:
@@ -1147,23 +1147,33 @@ void DebugServiceBase::InfoNode(const char8 *path, StreamString &out) {
|
||||
}
|
||||
|
||||
void DebugServiceBase::ListNodes(const char8 *path, StreamString &out) {
|
||||
Reference ref =
|
||||
bool isRoot =
|
||||
(path == NULL_PTR(const char8 *) || StringHelper::Length(path) == 0 ||
|
||||
StringHelper::Compare(path, "/") == 0)
|
||||
? ObjectRegistryDatabase::Instance()
|
||||
: ObjectRegistryDatabase::Instance()->Find(path);
|
||||
StringHelper::Compare(path, "/") == 0);
|
||||
|
||||
// NOTE: ObjectRegistryDatabase::Instance() is a raw, long-lived singleton
|
||||
// pointer that is never itself owned by a Reference. Wrapping it in a
|
||||
// Reference here (as previously done via a ternary) would increment its
|
||||
// reference count and then delete it when the local Reference goes out of
|
||||
// scope, destroying the registry. Keep the root case as a raw pointer.
|
||||
ReferenceContainer *rc = NULL_PTR(ReferenceContainer *);
|
||||
Reference ref;
|
||||
if (isRoot) {
|
||||
rc = ObjectRegistryDatabase::Instance();
|
||||
} else {
|
||||
ref = ObjectRegistryDatabase::Instance()->Find(path);
|
||||
if (ref.IsValid()) {
|
||||
rc = dynamic_cast<ReferenceContainer *>(ref.operator->());
|
||||
}
|
||||
}
|
||||
out.Printf("Nodes under %s:\n", path ? path : "/");
|
||||
if (ref.IsValid()) {
|
||||
ReferenceContainer *rc =
|
||||
dynamic_cast<ReferenceContainer *>(ref.operator->());
|
||||
if (rc != NULL_PTR(ReferenceContainer *)) {
|
||||
uint32 n = rc->Size();
|
||||
for (uint32 i = 0u; i < n; i++) {
|
||||
Reference c = rc->Get(i);
|
||||
if (c.IsValid()) {
|
||||
out.Printf(" %s [%s]\n", c->GetName(),
|
||||
c->GetClassProperties()->GetName());
|
||||
}
|
||||
if (rc != NULL_PTR(ReferenceContainer *)) {
|
||||
uint32 n = rc->Size();
|
||||
for (uint32 i = 0u; i < n; i++) {
|
||||
Reference c = rc->Get(i);
|
||||
if (c.IsValid()) {
|
||||
out.Printf(" %s [%s]\n", c->GetName(),
|
||||
c->GetClassProperties()->GetName());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -1198,141 +1208,6 @@ void DebugServiceBase::RebuildConfigFromRegistry() {
|
||||
RebuildTransportConfig();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Tree export
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
uint32 DebugServiceBase::ExportTree(ReferenceContainer *container,
|
||||
StreamString &json,
|
||||
const char8 *pathPrefix) {
|
||||
if (container == NULL_PTR(ReferenceContainer *))
|
||||
return 0u;
|
||||
uint32 size = container->Size();
|
||||
uint32 valid = 0u;
|
||||
for (uint32 i = 0u; i < size; i++) {
|
||||
Reference child = container->Get(i);
|
||||
if (!child.IsValid())
|
||||
continue;
|
||||
if (valid > 0u)
|
||||
json += ",\n";
|
||||
const char8 *cname = child->GetName();
|
||||
if (cname == NULL_PTR(const char8 *))
|
||||
cname = "unnamed";
|
||||
StreamString cp;
|
||||
if (pathPrefix != NULL_PTR(const char8 *))
|
||||
cp.Printf("%s.%s", pathPrefix, cname);
|
||||
else
|
||||
cp = cname;
|
||||
|
||||
StreamString nj;
|
||||
nj += "{\"Name\":\"";
|
||||
EscapeJson(cname, nj);
|
||||
nj += "\",\"Class\":\"";
|
||||
EscapeJson(child->GetClassProperties()->GetName(), nj);
|
||||
nj += "\"";
|
||||
|
||||
ReferenceContainer *inner =
|
||||
dynamic_cast<ReferenceContainer *>(child.operator->());
|
||||
DataSourceI *ds = dynamic_cast<DataSourceI *>(child.operator->());
|
||||
GAM *gam = dynamic_cast<GAM *>(child.operator->());
|
||||
|
||||
if (inner != NULL_PTR(ReferenceContainer *) ||
|
||||
ds != NULL_PTR(DataSourceI *) || gam != NULL_PTR(GAM *)) {
|
||||
nj += ",\"Children\":[\n";
|
||||
uint32 sc = 0u;
|
||||
if (inner != NULL_PTR(ReferenceContainer *))
|
||||
sc += ExportTree(inner, nj, cp.Buffer());
|
||||
if (ds != NULL_PTR(DataSourceI *)) {
|
||||
uint32 ns = ds->GetNumberOfSignals();
|
||||
for (uint32 j = 0u; j < ns; j++) {
|
||||
if (sc > 0u) {
|
||||
nj += ",\n";
|
||||
}
|
||||
sc++;
|
||||
StreamString sn;
|
||||
(void)ds->GetSignalName(j, sn);
|
||||
const char8 *st = TypeDescriptor::GetTypeNameFromTypeDescriptor(
|
||||
ds->GetSignalType(j));
|
||||
uint8 d = 0u;
|
||||
(void)ds->GetSignalNumberOfDimensions(j, d);
|
||||
uint32 el = 0u;
|
||||
(void)ds->GetSignalNumberOfElements(j, el);
|
||||
StreamString sfp;
|
||||
sfp.Printf("%s.%s", cp.Buffer(), sn.Buffer());
|
||||
bool tr = false, fo = false;
|
||||
(void)IsInstrumented(sfp.Buffer(), tr, fo);
|
||||
nj += "{\"Name\":\"";
|
||||
EscapeJson(sn.Buffer(), nj);
|
||||
nj += "\",\"Class\":\"Signal\",\"Type\":\"";
|
||||
EscapeJson(st ? st : "Unknown", nj);
|
||||
nj.Printf("\",\"Dimensions\":%u,\"Elements\":%u,"
|
||||
"\"IsTraceable\":%s,\"IsForcable\":%s}",
|
||||
d, el, tr ? "true" : "false", fo ? "true" : "false");
|
||||
}
|
||||
}
|
||||
if (gam != NULL_PTR(GAM *)) {
|
||||
uint32 nIn = gam->GetNumberOfInputSignals();
|
||||
for (uint32 j = 0u; j < nIn; j++) {
|
||||
if (sc > 0u) {
|
||||
nj += ",\n";
|
||||
}
|
||||
sc++;
|
||||
StreamString sn;
|
||||
(void)gam->GetSignalName(InputSignals, j, sn);
|
||||
const char8 *st = TypeDescriptor::GetTypeNameFromTypeDescriptor(
|
||||
gam->GetSignalType(InputSignals, j));
|
||||
uint32 d = 0u;
|
||||
(void)gam->GetSignalNumberOfDimensions(InputSignals, j, d);
|
||||
uint32 el = 0u;
|
||||
(void)gam->GetSignalNumberOfElements(InputSignals, j, el);
|
||||
StreamString sfp;
|
||||
sfp.Printf("%s.In.%s", cp.Buffer(), sn.Buffer());
|
||||
bool tr = false, fo = false;
|
||||
(void)IsInstrumented(sfp.Buffer(), tr, fo);
|
||||
nj += "{\"Name\":\"In.";
|
||||
EscapeJson(sn.Buffer(), nj);
|
||||
nj += "\",\"Class\":\"InputSignal\",\"Type\":\"";
|
||||
EscapeJson(st ? st : "Unknown", nj);
|
||||
nj.Printf("\",\"Dimensions\":%u,\"Elements\":%u,"
|
||||
"\"IsTraceable\":%s,\"IsForcable\":%s}",
|
||||
d, el, tr ? "true" : "false", fo ? "true" : "false");
|
||||
}
|
||||
uint32 nOut = gam->GetNumberOfOutputSignals();
|
||||
for (uint32 j = 0u; j < nOut; j++) {
|
||||
if (sc > 0u) {
|
||||
nj += ",\n";
|
||||
}
|
||||
sc++;
|
||||
StreamString sn;
|
||||
(void)gam->GetSignalName(OutputSignals, j, sn);
|
||||
const char8 *st = TypeDescriptor::GetTypeNameFromTypeDescriptor(
|
||||
gam->GetSignalType(OutputSignals, j));
|
||||
uint32 d = 0u;
|
||||
(void)gam->GetSignalNumberOfDimensions(OutputSignals, j, d);
|
||||
uint32 el = 0u;
|
||||
(void)gam->GetSignalNumberOfElements(OutputSignals, j, el);
|
||||
StreamString sfp;
|
||||
sfp.Printf("%s.Out.%s", cp.Buffer(), sn.Buffer());
|
||||
bool tr = false, fo = false;
|
||||
(void)IsInstrumented(sfp.Buffer(), tr, fo);
|
||||
nj += "{\"Name\":\"Out.";
|
||||
EscapeJson(sn.Buffer(), nj);
|
||||
nj += "\",\"Class\":\"OutputSignal\",\"Type\":\"";
|
||||
EscapeJson(st ? st : "Unknown", nj);
|
||||
nj.Printf("\",\"Dimensions\":%u,\"Elements\":%u,"
|
||||
"\"IsTraceable\":%s,\"IsForcable\":%s}",
|
||||
d, el, tr ? "true" : "false", fo ? "true" : "false");
|
||||
}
|
||||
}
|
||||
nj += "\n]";
|
||||
}
|
||||
nj += "}";
|
||||
json += nj;
|
||||
valid++;
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// EnrichWithConfig
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user