diff --git a/cd_utils/cdutils_c.cpp b/cd_utils/cdutils_c.cpp index 3770e43..951b3ee 100644 --- a/cd_utils/cdutils_c.cpp +++ b/cd_utils/cdutils_c.cpp @@ -7,20 +7,6 @@ CInterface C; CInterface::CInterface(): Interface(CDType::cdC) { - CONNECTU(core, C_Sended, this, sended); - CONNECTU(core, C_SendFail, this, sendFailed); - CONNECTU(core, C_Received, this, received); - CONNECTU(core, C_ReceiveFail, this, receiveFailed); -} - - -void CInterface::send() { - core->C_Send(); -} - - -void CInterface::request() { - core->C_Request(); } diff --git a/cd_utils/cdutils_c.h b/cd_utils/cdutils_c.h index e09b89d..72590ca 100644 --- a/cd_utils/cdutils_c.h +++ b/cd_utils/cdutils_c.h @@ -9,18 +9,10 @@ namespace CDUtils { class CInterface: public Interface { - PIOBJECT(CDUtils::CInterface) + PIOBJECT_SUBCLASS(CInterface, Interface) public: CInterface(); - EVENT(sended) - EVENT(sendFailed) - EVENT(received) - EVENT(receiveFailed) - EVENT1(keepNamesRequest, bool*, cn) - EVENT_HANDLER(void, send); - EVENT_HANDLER(void, request); - void sendCommand(const CDType & c); void connect(const CDType & c, PIObject * o, Handler eh); void autoConnect(PIObject * o, const PIString & prefix = PIStringAscii("c_")); diff --git a/cd_utils/cdutils_core.cpp b/cd_utils/cdutils_core.cpp index 01e0f61..9e9f644 100644 --- a/cd_utils/cdutils_core.cpp +++ b/cd_utils/cdutils_core.cpp @@ -106,6 +106,8 @@ void CDCore::cd_write(CDSection * cd, PIIODevice * d) { void CDCore::cd_read(CDSection * cd, PIIODevice * d) { PIConfig conf(d, PIIODevice::ReadOnly); cd->read(&(conf.rootEntry())); + if (cd->cd_type_ == CDType::cdX) + x_selected = cd->collectX(); initRoot(cd); K_ChangedGlobal(); /*PIVector ds = connection.allDevices(); @@ -147,6 +149,7 @@ void CDCore::cd_calculate(CDSection * cd) { void CDCore::cd_send(CDSection * cd, CDPacketType pt, bool direct) { + if (!cd) return; PIByteArray ba, sba; PIIOByteArray iob(&ba, PIIODevice::ReadWrite); cd_write(cd, &iob); @@ -160,6 +163,33 @@ void CDCore::cd_send(CDSection * cd, CDPacketType pt, bool direct) { } +void CDCore::send(CDType::cdT cdt) { + CDPacketType pt = CD_Ping; + switch (cdt) { + case CDType::cdK: pt = CD_KSend; break; + case CDType::cdX: pt = CD_XSend; break; + case CDType::cdC: pt = CD_CSend; break; + default: break; + } + piCoutObj << "send" << typeLetter(cdt); + cd_send(root(cdt), pt); +} + + +void CDCore::request(CDType::cdT cdt) { + CDPacketType pt = CD_Ping; + switch (cdt) { + case CDType::cdK: pt = CD_KQuery; break; + case CDType::cdX: pt = CD_XQuery; break; + case CDType::cdC: pt = CD_CQuery; break; + default: break; + } + piCoutObj << "request" << typeLetter(cdt); + PIByteArray sba = makeHeader(pt, 0); + sendThreaded(sba); +} + + void CDCore::initApp() { init(appConfig(), false); } @@ -243,19 +273,6 @@ CDCore * CDCore::instance() { } -void CDCore::K_Send() { - piCoutObj << "K_Send"; - cd_send(&k_, CD_KSend); -} - - -void CDCore::K_Request() { - piCoutObj << "K_Request"; - PIByteArray sba = makeHeader(CD_KQuery, 0); - sendThreaded(sba); -} - - void CDUtils::CDCore::K_DirectChange(PIDeque path, PIString value) { piCoutObj << "K_DirectChange"; PacketKDirectChange p; @@ -267,32 +284,6 @@ void CDUtils::CDCore::K_DirectChange(PIDeque path, PIString value) { } -void CDCore::X_Send() { - piCoutObj << "X_Send"; - cd_send(&x_, CD_XSend); -} - - -void CDCore::X_Request() { - piCoutObj << "X_Request"; - PIByteArray sba = makeHeader(CD_XQuery, 0); - sendThreaded(sba); -} - - -void CDCore::C_Send() { - piCoutObj << "C_Send"; - cd_send(&c_, CD_CSend); -} - - -void CDCore::C_Request() { - piCoutObj << "C_Request"; - PIByteArray sba = makeHeader(CD_CQuery, 0); - sendThreaded(sba); -} - - void CDCore::sendThread() { if (send_data.size_s() < 4) return; PacketHeader h; @@ -392,7 +383,7 @@ void CDCore::procReceivedPacket(PIByteArray & ba) { //piCoutObj << "ping"; break; case CD_KQuery: - K_Send(); + send(CDType::cdK); break; case CD_KSend: { piCoutObj << "K received"; @@ -410,7 +401,7 @@ void CDCore::procReceivedPacket(PIByteArray & ba) { k_[p.path].setValue(p.value); } break; case CD_XQuery: - X_Send(); + send(CDType::cdX); break; case CD_XSend: { piCoutObj << "X received"; @@ -420,6 +411,7 @@ void CDCore::procReceivedPacket(PIByteArray & ba) { PIString s = PIString::fromUTF8((const char *)x.data()); PIIOString ios(&s); cd_read(&x_, &ios); + x_selected = x_.collectX(); X_Received(); } break; case CD_XRequest: { @@ -447,7 +439,7 @@ void CDCore::procReceivedPacket(PIByteArray & ba) { X_ReceivedX(x_vals); } break; case CD_CQuery: - C_Send(); + send(CDType::cdC); break; case CD_CSend: { piCoutObj << "C received"; diff --git a/cd_utils/cdutils_core.h b/cd_utils/cdutils_core.h index 4a6cccd..3fe45d6 100644 --- a/cd_utils/cdutils_core.h +++ b/cd_utils/cdutils_core.h @@ -36,24 +36,20 @@ public: EVENT(K_Received) EVENT(K_ReceiveFail) EVENT(K_ChangedGlobal) - EVENT_HANDLER(void, K_Send); - EVENT_HANDLER(void, K_Request); EVENT_HANDLER2(void, K_DirectChange, PIDeque, path, PIString, value); EVENT(X_Sended) EVENT(X_SendFail) EVENT(X_Received) EVENT(X_ReceiveFail) + EVENT(X_ChangedGlobal) EVENT1(X_ReceivedX, PIVector >, pathes) - EVENT_HANDLER(void, X_Send); - EVENT_HANDLER(void, X_Request); EVENT(C_Sended) EVENT(C_SendFail) EVENT(C_Received) EVENT(C_ReceiveFail) - EVENT_HANDLER(void, C_Send); - EVENT_HANDLER(void, C_Request); + EVENT(C_ChangedGlobal) void cd_write (CDSection * cd, PIIODevice * d); void cd_read (CDSection * cd, PIIODevice * d); @@ -61,6 +57,8 @@ public: void cd_update (CDSection * cd, PIIODevice * d, UpdateModeFlags mode); void cd_calculate(CDSection * cd); void cd_send (CDSection * cd, CDPacketType pt, bool direct = false); + void send(CDType::cdT cdt); + void request(CDType::cdT cdt); void initApp(); void initPult(); void init(const PIString & configuration, bool pult = false); diff --git a/cd_utils/cdutils_interface.cpp b/cd_utils/cdutils_interface.cpp index d836645..f976772 100644 --- a/cd_utils/cdutils_interface.cpp +++ b/cd_utils/cdutils_interface.cpp @@ -13,6 +13,27 @@ Interface::Interface(CDType::cdT type_) { //piCoutObj << (void*)this << core; file_ = core->typeLetter(type_) + PIStringAscii(".dat"); file_size = 0; + switch (type) { + case CDType::cdK: + CONNECTU(core, K_Sended, this, sended); + CONNECTU(core, K_SendFail, this, sendFailed); + CONNECTU(core, K_Received, this, received); + CONNECTU(core, K_ReceiveFail, this, receiveFailed); + break; + case CDType::cdX: + CONNECTU(core, X_Sended, this, sended); + CONNECTU(core, X_SendFail, this, sendFailed); + CONNECTU(core, X_Received, this, received); + CONNECTU(core, X_ReceiveFail, this, receiveFailed); + break; + case CDType::cdC: + CONNECTU(core, C_Sended, this, sended); + CONNECTU(core, C_SendFail, this, sendFailed); + CONNECTU(core, C_Received, this, received); + CONNECTU(core, C_ReceiveFail, this, receiveFailed); + break; + default: break; + } } @@ -164,3 +185,13 @@ void Interface::writeFile() { bool Interface::inProgress() { return core->inProgress(); } + + +void Interface::send() { + core->send(type); +} + + +void Interface::request() { + core->request(type); +} diff --git a/cd_utils/cdutils_interface.h b/cd_utils/cdutils_interface.h index ded7fc1..0ad710a 100644 --- a/cd_utils/cdutils_interface.h +++ b/cd_utils/cdutils_interface.h @@ -50,6 +50,14 @@ public: void writeFile(); bool inProgress(); + EVENT(sended) + EVENT(sendFailed) + EVENT(received) + EVENT(receiveFailed) + EVENT(changedGlobal) + EVENT_HANDLER(void, send); + EVENT_HANDLER(void, request); + protected: CDCore * core; CDSection * s; diff --git a/cd_utils/cdutils_k.cpp b/cd_utils/cdutils_k.cpp index b833a0e..76038d0 100644 --- a/cd_utils/cdutils_k.cpp +++ b/cd_utils/cdutils_k.cpp @@ -7,20 +7,6 @@ KInterface K; KInterface::KInterface(): Interface(CDType::cdK) { - CONNECTU(core, K_Sended, this, sended); - CONNECTU(core, K_SendFail, this, sendFailed); - CONNECTU(core, K_Received, this, received); - CONNECTU(core, K_ReceiveFail, this, receiveFailed); -} - - -void KInterface::send() { - core->K_Send(); -} - - -void KInterface::request() { - core->K_Request(); } diff --git a/cd_utils/cdutils_k.h b/cd_utils/cdutils_k.h index 137f932..5374a41 100644 --- a/cd_utils/cdutils_k.h +++ b/cd_utils/cdutils_k.h @@ -9,17 +9,11 @@ namespace CDUtils { class KInterface: public Interface { - PIOBJECT(CDUtils::KInterface) + PIOBJECT_SUBCLASS(KInterface, Interface) public: KInterface(); - EVENT(sended) - EVENT(sendFailed) - EVENT(received) - EVENT(receiveFailed) EVENT1(keepNamesRequest, bool*, kn) - EVENT_HANDLER(void, send); - EVENT_HANDLER(void, request); void directChange(const CDType & k, double v); diff --git a/cd_utils/cdutils_types.cpp b/cd_utils/cdutils_types.cpp index 1f60a51..b491881 100644 --- a/cd_utils/cdutils_types.cpp +++ b/cd_utils/cdutils_types.cpp @@ -440,6 +440,8 @@ void CDSection::write(PIIODevice * d, const PIString & prefix) { d->write(l.toUTF8()); l.clear(); l << ck.index() << ".avg = " << ck.avg() << " #n " << "\n"; d->write(l.toUTF8()); + l.clear(); l << ck.index() << ".sel = " << (ck.isSelectedX() ? "1" : "0") << " #n " << "\n"; + d->write(l.toUTF8()); break; case CDType::cdC: l.clear(); l << ck.index() << ".name = " << ck.name() << " #s " << ck.comment() << " \n"; @@ -495,6 +497,7 @@ void CDSection::read(const void * ep) { c = CDType(id, e->getValue("name").value(), PIString(), PIString(), PIString() , e->getValue("name").comment(), cd_type_); c.setXMode((CDType::XMode)e->getValue("mode", int(CDType::X_Current)).value().toInt()); c.setAvg((CDType::XMode)e->getValue("avg", 1).value().toInt()); + c.x_enabled = e->getValue("sel", false).value().toBool(); break; case CDType::cdC: c = CDType(id, e->getValue("name").value(), PIString(), PIString(), PIString() , e->getValue("name").comment(), cd_type_); diff --git a/cd_utils/cdutils_x.cpp b/cd_utils/cdutils_x.cpp index 03d063c..2b2d24a 100644 --- a/cd_utils/cdutils_x.cpp +++ b/cd_utils/cdutils_x.cpp @@ -7,24 +7,10 @@ XInterface X; XInterface::XInterface(): Interface(CDType::cdX) { - CONNECTU(core, X_Sended, this, sended); - CONNECTU(core, X_SendFail, this, sendFailed); - CONNECTU(core, X_Received, this, received); - CONNECTU(core, X_ReceiveFail, this, receiveFailed); CONNECTU(core, X_ReceivedX, this, receivedX); } -void XInterface::send() { - core->X_Send(); -} - - -void XInterface::request() { - core->X_Request(); -} - - void XInterface::setEnabled(const CDType & x, bool en) { core->x_mutex.lock(); CDType & t((*s)[x.path()]); diff --git a/cd_utils/cdutils_x.h b/cd_utils/cdutils_x.h index cff188a..bbfc56a 100644 --- a/cd_utils/cdutils_x.h +++ b/cd_utils/cdutils_x.h @@ -9,17 +9,11 @@ namespace CDUtils { class XInterface: public Interface { - PIOBJECT(CDUtils::XInterface) + PIOBJECT_SUBCLASS(XInterface, Interface) public: XInterface(); - EVENT(sended) - EVENT(sendFailed) - EVENT(received) - EVENT(receiveFailed) EVENT1(keepNamesRequest, bool*, xn) - EVENT_HANDLER(void, send); - EVENT_HANDLER(void, request); EVENT1(receivedX, PIVector >, pathes) void enable(const CDType & x) {setEnabled(x, true);} diff --git a/qad/utils/qpiconfig.h b/qad/utils/qpiconfig.h index d7dd7fd..1c8a267 100644 --- a/qad/utils/qpiconfig.h +++ b/qad/utils/qpiconfig.h @@ -13,7 +13,7 @@ #include -inline QByteArray QString2QByteArray(const QString & string) {return qUncompress(QByteArray::fromBase64(string.toLatin1()));} +inline QByteArray QString2QByteArray(const QString & string) {return string.isEmpty() ? QByteArray() : qUncompress(QByteArray::fromBase64(string.toLatin1()));} int QString2int(const QString & string); inline QColor QString2QColor(const QString & string) {return (string.left(1) == "#" ? QColor(string.right(string.length() - 1).toInt(0, 16)) : QColor(QString2int(string)));} QRect QString2QRect(const QString & string); @@ -24,7 +24,7 @@ QPointF QString2QPointF(const QString & string); inline QString QColor2QString(const QColor & color) {QString s = color.name(); return "0x" + QString::number(color.alpha(), 16).rightJustified(2, '0') + s.right(s.length() - 1);} inline QString QPoint2QString(const QPoint & point) {return QString::number(point.x()) + ";" + QString::number(point.y());} inline QString QPointF2QString(const QPointF & point) {return QString::number(point.x()) + ";" + QString::number(point.y());} -inline QString QByteArray2QString(const QByteArray & array) {return QString(qCompress(array, 9).toBase64());} +inline QString QByteArray2QString(const QByteArray & array) {return array.isEmpty() ? QString() : QString(qCompress(array, 9).toBase64());} QString QRect2QString(const QRect & rect); QString QRectF2QString(const QRectF & rect);