Files
cd/libs/core/cdutils_c.cpp

41 lines
1001 B
C++

#include "cdutils_c.h"
#include "cdutils_core.h"
using namespace CDUtils;
CInterface C;
CInterface::CInterface(): Interface(CDType::cdC) {}
void CInterface::sendCommand(const CDType & c) {
core->sendCommand(c);
}
void CInterface::connect(const CDType & c, PIObject * o, Handler eh) {
core->registerCHandler(c, o, eh);
}
void CInterface::autoConnect(PIObject * o, const PIString & prefix) {
if (!o) return;
uint cid = o->classNameID();
if (!PIObject::__meta_data().contains(cid)) return;
PIMap<PIString, Handler> eh_map;
PIObject::__MetaData & md(PIObject::__meta_data()[cid]);
for (auto it = md.eh_func.begin(); it != md.eh_func.end(); ++it) {
eh_map[it.value().func_name] = (Handler)it.value().addr;
// piCout << "func" << it.value().func_name;
}
PIVector<CDType *> cl = C.root().children();
for (const auto * c: cl) {
PIString cp = prefix + c->pathString().join("_");
if (cp.isEmpty()) continue;
if (!eh_map.contains(cp)) continue;
connect(*c, o, eh_map[cp]);
}
}