git-svn-id: svn://db.shs.com.ru/pip@506 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -126,10 +126,20 @@ bool PIConnection::configure(PIConfig & conf, const PIString & name_) {
|
||||
cb(ce.getValue("channel").children()), sb(ce.getValue("sender").children());
|
||||
PIStringList dev_list(ce.getValue("device").value());
|
||||
PIStringList name_list(ce.getValue("device").name());
|
||||
PIStringList flt_list(ce.getValue("filter").value());
|
||||
piForeachC (PIConfig::Entry * e, db) {
|
||||
dev_list << e->value();
|
||||
name_list << e->name();
|
||||
}
|
||||
piForeachC (PIConfig::Entry * e, fb)
|
||||
flt_list << e->name();
|
||||
PISet<PIString> chk_set = (PISet<PIString>(name_list) & PISet<PIString>(flt_list));
|
||||
//piCout << name_list << flt_list << chk_set;
|
||||
chk_set.remove("");
|
||||
if (!chk_set.isEmpty()) {
|
||||
piCoutObj << "Error," << chk_set.toVector() << "names assigned to both devices and filters!";
|
||||
return false;
|
||||
}
|
||||
PIMap<PIString, PIString> dev_aliases;
|
||||
for (int i = 0; i < dev_list.size_s(); ++i) {
|
||||
PIString fn(dev_list[i]);
|
||||
@@ -138,10 +148,11 @@ bool PIConnection::configure(PIConfig & conf, const PIString & name_) {
|
||||
PIIODevice::DeviceMode dm = PIIODevice::ReadWrite;
|
||||
PIIODevice::splitFullPath(fn, &fn, &dm);
|
||||
//piCout << fn;
|
||||
//piCoutObj << "add" << fn << n;
|
||||
PIIODevice * dev = addDevice(fn, dm);
|
||||
if (!dev) continue;
|
||||
dev_aliases[n] = fn;
|
||||
device_names[n] = dev;
|
||||
//device_names[n] = dev;
|
||||
setDeviceName(dev, n);
|
||||
dev->setName(name_ + ".device." + dev_list[i]);
|
||||
PIConfig::Entry de = ce.getValue("device." + n);
|
||||
@@ -267,8 +278,11 @@ PIString PIConnection::makeConfig() const {
|
||||
if (f.second == 0) continue;
|
||||
if (f.second->extractor == 0) continue;
|
||||
PIString prefix = "filter." + f.first;
|
||||
for (int i = 0; i < f.second->devices.size_s(); ++i)
|
||||
ret << prefix << ".device." << i << " = " << device_names.key(f.second->devices[i]) << " #s\n";
|
||||
for (int i = 0; i < f.second->devices.size_s(); ++i) {
|
||||
PIString dname = device_names.key(f.second->devices[i]);
|
||||
if (dname.isEmpty()) dname = devPath(f.second->devices[i]);
|
||||
ret << prefix << ".device." << i << " = " << dname << " #s\n";
|
||||
}
|
||||
PIDiagnostics * diag = diags_.value(f.second->extractor, 0);
|
||||
ret << prefix << ".bufferSize = " << f.second->extractor->bufferSize() << " #n\n";
|
||||
if (diag != 0)
|
||||
@@ -293,15 +307,22 @@ PIString PIConnection::makeConfig() const {
|
||||
piForeachC (CPair & c, channels_) {
|
||||
piForeachC (PIIODevice * d, c.second) {
|
||||
PIString prefix = "channel." + PIString::fromNumber(dn); ++dn;
|
||||
ret << prefix << ".from = " << devPath(c.first) << " #s\n";
|
||||
ret << prefix << ".to = " << devPath(d) << " #s\n";
|
||||
PIString dname = device_names.key(c.first);
|
||||
if (dname.isEmpty()) dname = devPath(c.first);
|
||||
ret << prefix << ".from = " << dname << " #s\n";
|
||||
dname = device_names.key(const_cast<PIIODevice *>(d));
|
||||
if (dname.isEmpty()) dname = devPath(d);
|
||||
ret << prefix << ".to = " << dname << " #s\n";
|
||||
}
|
||||
}
|
||||
piForeachC (SPair & s, senders) {
|
||||
if (s.second == 0) continue;
|
||||
PIString prefix = "sender." + s.second->name();
|
||||
for (int i = 0; i < s.second->devices.size_s(); ++i)
|
||||
ret << prefix << ".device." << i << " = " << devPath(s.second->devices[i]) << " #s\n";
|
||||
for (int i = 0; i < s.second->devices.size_s(); ++i) {
|
||||
PIString dname = device_names.key(s.second->devices[i]);
|
||||
if (dname.isEmpty()) dname = devPath(s.second->devices[i]);
|
||||
ret << prefix << ".device." << i << " = " << dname << " #s\n";
|
||||
}
|
||||
double int_ = s.second->int_;
|
||||
if (int_ > 0.)
|
||||
ret << prefix << ".frequency = " << (1000. / int_) << " #f\n";
|
||||
@@ -333,7 +354,14 @@ PIIODevice * PIConnection::addDevice(const PIString & full_path, PIIODevice::Dev
|
||||
}
|
||||
|
||||
|
||||
PIStringList PIConnection::deviceNames(const PIIODevice *dev) const {
|
||||
void PIConnection::setDeviceName(PIIODevice * dev, const PIString & name) {
|
||||
if (!dev) return;
|
||||
device_names[name] = dev;
|
||||
//dev->setProperty();
|
||||
}
|
||||
|
||||
|
||||
PIStringList PIConnection::deviceNames(const PIIODevice * dev) const {
|
||||
PIStringList ret;
|
||||
piForeachC (DNPair & s, device_names)
|
||||
if (s.second == dev)
|
||||
@@ -423,17 +451,15 @@ PIVector<PIIODevice * > PIConnection::boundedDevices() const {
|
||||
|
||||
|
||||
PIPacketExtractor * PIConnection::addFilter(const PIString & name_, const PIString & full_path, PIPacketExtractor::SplitMode mode) {
|
||||
PIString fp(PIIODevice::normalizeFullPath(full_path));
|
||||
PIString fname_ = name_.trimmed();
|
||||
Extractor * e = extractors.value(fname_);
|
||||
if (full_path.isEmpty()) return (e == 0 ? 0 : e->extractor);
|
||||
PIIODevice * dev = deviceByName(fp);
|
||||
if (!dev) dev = deviceByFullPath(fp);
|
||||
PIIODevice * dev = devByString(full_path);
|
||||
PIPacketExtractor * pe(0);
|
||||
if (extractors.value(full_path) != 0) pe = extractors.value(full_path)->extractor;
|
||||
if (pe != 0) dev = pe;
|
||||
if (dev == 0) {
|
||||
piCoutObj << "\"addFilter\" error: no such device \"" << full_path << "\"!";
|
||||
piCoutObj << "\"addFilter\" error: no such device or filter \"" << full_path << "\"!";
|
||||
return 0;
|
||||
}
|
||||
if (e == 0) {
|
||||
@@ -467,15 +493,14 @@ PIPacketExtractor * PIConnection::addFilter(const PIString & name_, const PIStri
|
||||
|
||||
|
||||
PIPacketExtractor * PIConnection::addFilter(PIPacketExtractor * filter, const PIString & full_path) {
|
||||
PIString fp(PIIODevice::normalizeFullPath(full_path));
|
||||
Extractor * e = 0;
|
||||
if (full_path.isEmpty()) return (e == 0 ? 0 : e->extractor);
|
||||
PIIODevice * dev = deviceByFullPath(fp);
|
||||
PIIODevice * dev = devByString(full_path);
|
||||
PIPacketExtractor * pe(0);
|
||||
if (extractors.value(full_path) != 0) pe = extractors.value(full_path)->extractor;
|
||||
if (pe != 0) dev = pe;
|
||||
if (dev == 0) {
|
||||
piCoutObj << "\"addFilter\" error: no such device \"" << full_path << "\"!";
|
||||
piCoutObj << "\"addFilter\" error: no such device or filter \"" << full_path << "\"!";
|
||||
return 0;
|
||||
}
|
||||
if (e == 0) {
|
||||
@@ -505,12 +530,17 @@ PIPacketExtractor * PIConnection::addFilter(PIPacketExtractor * filter, const PI
|
||||
|
||||
|
||||
bool PIConnection::removeFilter(const PIString & name_, const PIString & full_path) {
|
||||
PIString fp(PIIODevice::normalizeFullPath(full_path));
|
||||
return removeFilter(name_, devByString(full_path));
|
||||
}
|
||||
|
||||
|
||||
bool PIConnection::removeFilter(const PIString & name_, const PIIODevice * dev) {
|
||||
if (dev == 0) return false;
|
||||
Extractor * p = extractors.value(name_.trimmed());
|
||||
if (p == 0) return false;
|
||||
bool ret = false;
|
||||
for (int i = 0; i < p->devices.size_s(); ++i) {
|
||||
if (devFPath(p->devices[i]) == fp || devFPath(p->devices[i]) == full_path) {
|
||||
if (p->devices[i] == dev) {
|
||||
bounded_extractors[p->devices[i]].removeAll(p->extractor);
|
||||
p->devices.remove(i);
|
||||
--i;
|
||||
@@ -525,12 +555,6 @@ bool PIConnection::removeFilter(const PIString & name_, const PIString & full_pa
|
||||
}
|
||||
|
||||
|
||||
bool PIConnection::removeFilter(const PIString & name, const PIIODevice * dev) {
|
||||
if (dev == 0) return false;
|
||||
return removeFilter(name, devFPath(dev));
|
||||
}
|
||||
|
||||
|
||||
bool PIConnection::removeFilter(const PIString & name_) {
|
||||
Extractor * p = extractors.value(name_.trimmed());
|
||||
if (p == 0) return false;
|
||||
@@ -597,9 +621,7 @@ PIVector<PIIODevice * > PIConnection::filterBoundedDevices(const PIString & name
|
||||
bool PIConnection::addChannel(const PIString & name0, const PIString & name1) {
|
||||
//piCout << "addChannel" << name0 << name1;
|
||||
if (name0.isEmpty() || name1.isEmpty()) return false;
|
||||
PIIODevice * dev0 = deviceByName(name0), * dev1 = deviceByName(name1);
|
||||
if (!dev0) dev0 = deviceByFullPath(name0);
|
||||
if (!dev1) dev1 = deviceByFullPath(name1);
|
||||
PIIODevice * dev0 = devByString(name0), * dev1 = devByString(name1);
|
||||
PIPacketExtractor * pe0(0), * pe1(0);
|
||||
if (extractors.value(name0) != 0) pe0 = extractors.value(name0)->extractor;
|
||||
if (extractors.value(name1) != 0) pe1 = extractors.value(name1)->extractor;
|
||||
@@ -617,7 +639,7 @@ bool PIConnection::addChannel(const PIString & name0, const PIString & name1) {
|
||||
|
||||
|
||||
bool PIConnection::removeChannel(const PIString & name0, const PIString & name1) {
|
||||
PIIODevice * dev0 = deviceByFullPath(name0), * dev1 = deviceByFullPath(name1);
|
||||
PIIODevice * dev0 = devByString(name0), * dev1 = devByString(name1);
|
||||
PIPacketExtractor * pe0(0), * pe1(0);
|
||||
if (extractors.value(name0) != 0) pe0 = extractors.value(name0)->extractor;
|
||||
if (extractors.value(name1) != 0) pe1 = extractors.value(name1)->extractor;
|
||||
@@ -630,7 +652,7 @@ bool PIConnection::removeChannel(const PIString & name0, const PIString & name1)
|
||||
|
||||
|
||||
bool PIConnection::removeChannel(const PIString & name0) {
|
||||
PIIODevice * dev0 = deviceByFullPath(name0);
|
||||
PIIODevice * dev0 = devByString(name0);
|
||||
PIPacketExtractor * pe0(0);
|
||||
if (extractors.value(name0) != 0) pe0 = extractors.value(name0)->extractor;
|
||||
if (pe0 != 0) dev0 = pe0;
|
||||
@@ -661,6 +683,14 @@ PIString PIConnection::devFPath(const PIIODevice * d) const {
|
||||
}
|
||||
|
||||
|
||||
PIIODevice * PIConnection::devByString(const PIString & s) const {
|
||||
if (s.isEmpty()) return 0;
|
||||
PIIODevice * ret = deviceByName(s);
|
||||
if (!ret) ret = deviceByFullPath(s);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIVector<PIPair<PIString, PIString > > PIConnection::channels() const {
|
||||
PIVector<PIPair<PIString, PIString > > ret;
|
||||
piForeachC (CPair & i, channels_) {
|
||||
@@ -672,20 +702,19 @@ PIVector<PIPair<PIString, PIString > > PIConnection::channels() const {
|
||||
}
|
||||
|
||||
|
||||
void PIConnection::addSender(const PIString & name_, const PIString & full_path, float frequency, bool start_) {
|
||||
PIString fp(PIIODevice::normalizeFullPath(full_path));
|
||||
void PIConnection::addSender(const PIString & name_, const PIString & full_path_name, float frequency, bool start_) {
|
||||
PIString fname_ = name_.trimmed();
|
||||
if (fp.isEmpty() || frequency <= 0.) return;
|
||||
if (full_path_name.isEmpty() || frequency <= 0.) return;
|
||||
Sender * s = senders.value(fname_);
|
||||
PIIODevice * dev = deviceByFullPath(fp);
|
||||
if (s == 0) {
|
||||
s = new Sender(this);
|
||||
s->setName(fname_);
|
||||
s->int_ = 1000. / frequency;
|
||||
senders[fname_] = s;
|
||||
}
|
||||
PIIODevice * dev = devByString(full_path_name);
|
||||
if (dev == 0) {
|
||||
piCoutObj << "\"addSender\" error: no such device \"" << full_path << "\"!";
|
||||
piCoutObj << "\"addSender\" error: no such device \"" << full_path_name << "\"!";
|
||||
return;
|
||||
}
|
||||
if (!s->isRunning() && start_) {
|
||||
@@ -699,10 +728,9 @@ void PIConnection::addSender(const PIString & name_, const PIString & full_path,
|
||||
}
|
||||
|
||||
|
||||
bool PIConnection::removeSender(const PIString & name, const PIString & full_path) {
|
||||
PIString fp(PIIODevice::normalizeFullPath(full_path));
|
||||
bool PIConnection::removeSender(const PIString & name, const PIString & full_path_name) {
|
||||
Sender * s = senders.value(name, 0);
|
||||
PIIODevice * d = deviceByFullPath(fp);
|
||||
PIIODevice * d = devByString(full_path_name);
|
||||
if (s == 0 || d == 0) return false;
|
||||
s->lock();
|
||||
bool ret = s->devices.contains(d);
|
||||
@@ -766,9 +794,8 @@ void PIConnection::removeAllSenders() {
|
||||
}
|
||||
|
||||
|
||||
void PIConnection::startThreadedRead(const PIString & full_path) {
|
||||
PIString fp(PIIODevice::normalizeFullPath(full_path));
|
||||
DevicePool::DeviceData * dd = __device_pool__->devices.value(fp, 0);
|
||||
void PIConnection::startThreadedRead(const PIString & full_path_name) {
|
||||
DevicePool::DeviceData * dd = __device_pool__->deviceData(devByString(full_path_name));
|
||||
if (dd == 0) return;
|
||||
if (dd->dev == 0) return;
|
||||
if (dd->started || dd->dev->mode() == PIIODevice::WriteOnly) return;
|
||||
@@ -800,9 +827,8 @@ void PIConnection::startAllSenders() {
|
||||
}
|
||||
|
||||
|
||||
void PIConnection::stopThreadedRead(const PIString & full_path) {
|
||||
PIString fp(PIIODevice::normalizeFullPath(full_path));
|
||||
DevicePool::DeviceData * dd = __device_pool__->devices.value(fp, 0);
|
||||
void PIConnection::stopThreadedRead(const PIString & full_path_name) {
|
||||
DevicePool::DeviceData * dd = __device_pool__->deviceData(devByString(full_path_name));
|
||||
if (dd == 0) return;
|
||||
if (dd->dev == 0) return;
|
||||
if (!dd->started || dd->dev->mode() == PIIODevice::WriteOnly) return;
|
||||
@@ -834,8 +860,7 @@ void PIConnection::stopAllSenders() {
|
||||
|
||||
|
||||
PIDiagnostics * PIConnection::diagnostic(const PIString & full_path_name) const {
|
||||
PIIODevice * dev = deviceByFullPath(full_path_name);
|
||||
if (dev == 0) dev = device_names.value(full_path_name, 0);
|
||||
PIIODevice * dev = devByString(full_path_name);
|
||||
PIPacketExtractor * pe(0);
|
||||
if (extractors.value(full_path_name) != 0) pe = extractors.value(full_path_name)->extractor;
|
||||
if (pe != 0) dev = pe;
|
||||
@@ -1004,6 +1029,16 @@ PIIODevice * PIConnection::DevicePool::device(const PIString & fp) const {
|
||||
}
|
||||
|
||||
|
||||
PIConnection::DevicePool::DeviceData * PIConnection::DevicePool::deviceData(PIIODevice * d) const {
|
||||
if (!d) return 0;
|
||||
piForeachC (DDPair & i, devices) {
|
||||
if (i.second->dev == d)
|
||||
return i.second;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
PIVector<PIConnection * > PIConnection::DevicePool::boundedConnections() const {
|
||||
PIVector<PIConnection * > ret;
|
||||
piForeachC (DDPair & i, devices) {
|
||||
|
||||
Reference in New Issue
Block a user