git-svn-id: svn://db.shs.com.ru/libs@378 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -18,8 +18,8 @@ endif()
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${PIP_INCLUDES})
|
||||
#file(GLOB HDRS_UTILS "*.h")
|
||||
#file(GLOB CPPS_UTILS "*.cpp")
|
||||
set(CPPS_UTILS "cdutils_core.cpp" "cdutils_types.cpp" "cdutils_parser.cpp" "cdutils_k.cpp")
|
||||
set(HDRS_UTILS "cdutils_core.h" "cdutils_types.h" "cdutils_parser.h" "cdutils_k.h" "cdutils_protocol.h")
|
||||
set(CPPS_UTILS "cdutils_core.cpp" "cdutils_types.cpp" "cdutils_parser.cpp" "cdutils_interface.cpp" "cdutils_k.cpp")
|
||||
set(HDRS_UTILS "cdutils_core.h" "cdutils_types.h" "cdutils_parser.h" "cdutils_interface.h" "cdutils_k.h" "cdutils_protocol.h")
|
||||
if (DEFINED ENV{QNX_HOST})
|
||||
add_library(${PROJECT_NAME} STATIC ${CPPS_UTILS} ${HDRS_UTILS})
|
||||
else()
|
||||
|
||||
@@ -30,6 +30,8 @@ const char CDCore::pult_config[] =
|
||||
|
||||
int __Core_Initializer__::count_(0);
|
||||
CDCore * __Core_Initializer__::__instance__(0);
|
||||
const uchar header_direct = 0x80;
|
||||
const uchar header_transfer = 0x81;
|
||||
|
||||
|
||||
__Core_Initializer__::__Core_Initializer__() {
|
||||
@@ -62,7 +64,12 @@ CDCore::CDCore() {
|
||||
/*PIString s(app_config);
|
||||
connection.configureFromString(&s);
|
||||
connection.start();*/
|
||||
initRoot(k_);
|
||||
k_.cd_type_ = CDType::cdK;
|
||||
x_.cd_type_ = CDType::cdX;
|
||||
c_.cd_type_ = CDType::cdC;
|
||||
initRoot(&k_);
|
||||
initRoot(&x_);
|
||||
initRoot(&c_);
|
||||
|
||||
CONNECTU(&datatr, sendRequest, this, dtSendRequest)
|
||||
CONNECTU(&datatr, receiveFinished, this, dtReceiveFinished)
|
||||
@@ -90,15 +97,15 @@ CDCore::~CDCore() {
|
||||
}
|
||||
|
||||
|
||||
void CDCore::k_write(PIIODevice * d) {
|
||||
k_.write(d, CDType::cdK, PIString());
|
||||
void CDCore::cd_write(CDSection * cd, PIIODevice * d) {
|
||||
cd->write(d, PIString());
|
||||
}
|
||||
|
||||
|
||||
void CDCore::k_read(PIIODevice * d) {
|
||||
void CDCore::cd_read(CDSection * cd, PIIODevice * d) {
|
||||
PIConfig conf(d, PIIODevice::ReadOnly);
|
||||
k_.read(&(conf.rootEntry()), CDType::cdK);
|
||||
initRoot(k_);
|
||||
cd->read(&(conf.rootEntry()));
|
||||
initRoot(cd);
|
||||
K_ChangedGlobal();
|
||||
/*PIVector<PIIODevice * > ds = connection.allDevices();
|
||||
piForeach(PIIODevice * d, ds) {
|
||||
@@ -108,36 +115,50 @@ void CDCore::k_read(PIIODevice * d) {
|
||||
}
|
||||
|
||||
|
||||
void CDCore::k_parse(PIIODevice * d) {
|
||||
k_ = CDParser::parse(d, CDType::cdK);
|
||||
initRoot(k_);
|
||||
void CDCore::cd_parse(CDSection * cd, PIIODevice * d) {
|
||||
*cd = CDParser::parse(d, cd->cd_type_);
|
||||
initRoot(cd);
|
||||
K_ChangedGlobal();
|
||||
}
|
||||
|
||||
|
||||
void CDCore::k_update(PIIODevice * d, UpdateModeFlags mode) {
|
||||
CDSection uk = k_;
|
||||
k_parse(d);
|
||||
void CDCore::cd_update(CDSection * cd, PIIODevice * d, UpdateModeFlags mode) {
|
||||
CDSection ucd = *cd;
|
||||
cd_parse(cd, d);
|
||||
/*bool kn = true;
|
||||
if (!uk.isEmpty())
|
||||
if (!uk.isSameStructure(k_)) {
|
||||
if (!ucd.isEmpty())
|
||||
if (!ucd.isSameStructure(k_)) {
|
||||
piCout << "ask for save names";
|
||||
K_KeepNamesRequest(&kn);
|
||||
}*/
|
||||
uk.update(k_, mode);
|
||||
//piCout << k_.count() << uk.count();
|
||||
k_ = uk;
|
||||
initRoot(k_);
|
||||
ucd.update(*cd, mode);
|
||||
//piCout << k_.count() << ucd.count();
|
||||
*cd = ucd;
|
||||
initRoot(cd);
|
||||
K_ChangedGlobal();
|
||||
}
|
||||
|
||||
|
||||
void CDCore::k_calculate() {
|
||||
k_.calculate();
|
||||
void CDCore::cd_calculate(CDSection * cd) {
|
||||
cd->calculate();
|
||||
K_ChangedGlobal();
|
||||
}
|
||||
|
||||
|
||||
void CDCore::cd_send(CDSection * cd, CDPacketType pt, bool direct) {
|
||||
PIByteArray ba, sba;
|
||||
PIIOByteArray iob(&ba, PIIODevice::ReadWrite);
|
||||
cd_write(cd, &iob);
|
||||
//piCoutObj << PIString(ba);
|
||||
sba = makeHeader(pt, 0);
|
||||
sba << ba;
|
||||
if (direct)
|
||||
sendDirect(sba);
|
||||
else
|
||||
sendThreaded(sba);
|
||||
}
|
||||
|
||||
|
||||
void CDCore::initApp() {
|
||||
init(appConfig());
|
||||
}
|
||||
@@ -163,30 +184,25 @@ void CDCore::startPing() {
|
||||
}
|
||||
|
||||
|
||||
void CDUtils::CDCore::dataReceived(const PIString & from, const PIByteArray & data) {
|
||||
// piCoutObj << "dataReceived" << from << data.size();
|
||||
PIIODevice * d = connection.deviceByName("cd");
|
||||
if (d && d == connection.deviceByFullPath(from)) {
|
||||
if (data.size() >= sizeof(4)) {
|
||||
const uint sig = *((const uint*)(data.data()));
|
||||
if (sig == PIBaseTransfer::packetSignature()) datatr.received(data);
|
||||
else {
|
||||
CDPacketType pt = (CDPacketType)sig;
|
||||
switch(pt) {
|
||||
case CD_Ping: {
|
||||
//piCoutObj << "ping";
|
||||
} break;
|
||||
case CD_KDirectChange: {
|
||||
PIByteArray ba = data;
|
||||
PacketKDirectChange p;
|
||||
ba >> p;
|
||||
k_[p.path].setValue(p.value);
|
||||
} break;
|
||||
CDSection * CDCore::root(CDType::cdT cdt) {
|
||||
switch (cdt) {
|
||||
case CDType::cdK: return &k_; break;
|
||||
case CDType::cdX: return &x_; break;
|
||||
case CDType::cdC: return &c_; break;
|
||||
default: break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
PIString CDCore::typeLetter(CDType::cdT cdt) {
|
||||
switch (cdt) {
|
||||
case CDType::cdK: return PIStringAscii("k"); break;
|
||||
case CDType::cdX: return PIStringAscii("x"); break;
|
||||
case CDType::cdC: return PIStringAscii("c"); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
return PIString();
|
||||
}
|
||||
|
||||
|
||||
@@ -199,60 +215,34 @@ CDCore * CDCore::instance() {
|
||||
|
||||
void CDCore::K_Send() {
|
||||
piCoutObj << "K_Send";
|
||||
PIByteArray ba;
|
||||
PIIOByteArray iob(&ba, PIIODevice::ReadWrite);
|
||||
k_write(&iob);
|
||||
//piCoutObj << PIString(ba);
|
||||
if (sendt.isRunning()) {
|
||||
piCoutObj << "send in process...";
|
||||
return;
|
||||
}
|
||||
wheader.session_id = 0;
|
||||
wheader.type = CD_KSend;
|
||||
send_data.clear();
|
||||
send_data << wheader << ba;
|
||||
sendt.startOnce();
|
||||
// ios.close();
|
||||
// piCout << s;
|
||||
//PIByteArray ba = PIByteArray::fromString(s);
|
||||
// PIFile pf("k.txt", PIIODevice::ReadWrite);
|
||||
// pf.resize(0);
|
||||
// pf.write(s.toUTF8());
|
||||
//k_write(&pf);
|
||||
//piCout << pf.readLine();
|
||||
cd_send(&k_, CD_KSend);
|
||||
}
|
||||
|
||||
|
||||
void CDCore::K_Request() {
|
||||
piCoutObj << "K_Request";
|
||||
if (sendt.isRunning()) {
|
||||
piCoutObj << "send in process...";
|
||||
return;
|
||||
}
|
||||
wheader.session_id = 0;
|
||||
wheader.type = CD_KQuery;
|
||||
send_data.clear();
|
||||
send_data << wheader;
|
||||
sendt.startOnce();
|
||||
PIByteArray sba = makeHeader(CD_KQuery, 0);
|
||||
sendThreaded(sba);
|
||||
}
|
||||
|
||||
|
||||
void CDUtils::CDCore::K_DirectChange(PIDeque<int> path, PIString value) {
|
||||
piCoutObj << "K_DirectChange";
|
||||
PacketKDirectChange p;
|
||||
p.header.session_id = 0;
|
||||
p.header.type = CD_KDirectChange;
|
||||
p.path = path;
|
||||
p.value = value;
|
||||
PIByteArray ba;
|
||||
ba << p;
|
||||
connection.writeByName("cd", ba);
|
||||
PIByteArray sba = makeHeader(CD_KDirectChange, 0);
|
||||
sba << p;
|
||||
sendDirect(sba);
|
||||
}
|
||||
|
||||
|
||||
void CDCore::sendThread() {
|
||||
if (send_data.size_s() < 4) return;
|
||||
PacketHeader h;
|
||||
memcpy(&h, send_data.data(), sizeof(h));
|
||||
bool ok = datatr.send(send_data);
|
||||
CDPacketType pt = (CDPacketType)wheader.type;
|
||||
switch (pt) {
|
||||
switch (h.type) {
|
||||
case CD_KSend:
|
||||
if (ok) K_Sended();
|
||||
else K_SendFail();
|
||||
@@ -275,27 +265,46 @@ void CDCore::xTimerTick() {
|
||||
}
|
||||
|
||||
|
||||
void CDCore::initRoot(CDSection & r) {
|
||||
r.name = "__root__";
|
||||
r.alias = "root";
|
||||
r.makePath();
|
||||
r.calculate();
|
||||
void CDCore::initRoot(CDSection * r) {
|
||||
r->name = "__root__";
|
||||
r->alias = "root";
|
||||
r->makePath();
|
||||
r->calculate();
|
||||
}
|
||||
|
||||
|
||||
void CDCore::dtSendRequest(PIByteArray &data) {
|
||||
connection.writeByName("cd", data);
|
||||
// piCoutObj << "send" << data.size() << ret;
|
||||
PIByteArray CDCore::makeHeader(CDPacketType type, int session_id) const {
|
||||
PacketHeader h;
|
||||
h.type = type;
|
||||
h.session_id = session_id;
|
||||
PIByteArray ret; ret << h;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void CDCore::dtReceiveFinished(bool ok) {
|
||||
if (ok) {
|
||||
PIByteArray ba = datatr.data();
|
||||
PacketHeader p;
|
||||
ba >> p;
|
||||
CDPacketType pt = (CDPacketType)p.type;
|
||||
switch (pt) {
|
||||
void CDCore::sendDirect(PIByteArray & ba) {
|
||||
ba.push_front(header_direct);
|
||||
connection.writeByName("cd", ba);
|
||||
}
|
||||
|
||||
|
||||
void CDCore::sendThreaded(PIByteArray & ba) {
|
||||
if (sendt.isRunning()) {
|
||||
piCoutObj << "Send in process, abort";
|
||||
return;
|
||||
}
|
||||
send_data = ba;
|
||||
sendt.startOnce();
|
||||
}
|
||||
|
||||
|
||||
void CDCore::procReceivedPacket(PIByteArray & ba) {
|
||||
PacketHeader h;
|
||||
ba >> h;
|
||||
switch(h.type) {
|
||||
case CD_Ping:
|
||||
//piCoutObj << "ping";
|
||||
break;
|
||||
case CD_KQuery:
|
||||
K_Send();
|
||||
break;
|
||||
@@ -306,11 +315,47 @@ void CDCore::dtReceiveFinished(bool ok) {
|
||||
k << uchar(0);
|
||||
PIString s = PIString::fromUTF8((const char *)k.data());
|
||||
PIIOString ios(&s);
|
||||
k_read(&ios);
|
||||
cd_read(&k_, &ios);
|
||||
K_Received();
|
||||
} break;
|
||||
case CD_KDirectChange: {
|
||||
PacketKDirectChange p;
|
||||
ba >> p;
|
||||
k_[p.path].setValue(p.value);
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CDUtils::CDCore::dataReceived(const PIString & from, const PIByteArray & data) {
|
||||
//piCoutObj << "dataReceived" << from << data.size();
|
||||
PIIODevice * d = connection.deviceByName("cd");
|
||||
if (d && d == connection.deviceByFullPath(from)) {
|
||||
if (data.size() >= sizeof(4)) {
|
||||
PIByteArray ba = data;
|
||||
uchar header = ba.take_front();
|
||||
if (header == header_transfer) {
|
||||
datatr.received(ba);
|
||||
}
|
||||
if (header == header_direct) {
|
||||
procReceivedPacket(ba);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CDCore::dtSendRequest(PIByteArray & data) {
|
||||
data.push_front(header_transfer);
|
||||
connection.writeByName("cd", data);
|
||||
//piCoutObj << "send" << data.size() << ret;
|
||||
}
|
||||
|
||||
|
||||
void CDCore::dtReceiveFinished(bool ok) {
|
||||
if (!ok) return;
|
||||
PIByteArray ba = datatr.data();
|
||||
procReceivedPacket(ba);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ class CDCore: public PIObject
|
||||
PIOBJECT(CDUtils::CDCore)
|
||||
friend class __Core_Initializer__;
|
||||
friend class CDSection;
|
||||
friend class KInterface;
|
||||
friend class Interface;
|
||||
public:
|
||||
static CDCore * instance();
|
||||
|
||||
@@ -39,11 +39,12 @@ public:
|
||||
EVENT_HANDLER(void, K_Request);
|
||||
EVENT_HANDLER2(void, K_DirectChange, PIDeque<int>, path, PIString, value);
|
||||
|
||||
void k_write(PIIODevice * d);
|
||||
void k_read(PIIODevice * d);
|
||||
void k_parse(PIIODevice * d);
|
||||
void k_update(PIIODevice * d, UpdateModeFlags mode);
|
||||
void k_calculate();
|
||||
void cd_write (CDSection * cd, PIIODevice * d);
|
||||
void cd_read (CDSection * cd, PIIODevice * d);
|
||||
void cd_parse (CDSection * cd, PIIODevice * d);
|
||||
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 initApp();
|
||||
void initPult();
|
||||
void init(const PIString & configuration);
|
||||
@@ -51,6 +52,8 @@ public:
|
||||
bool inProgress() {return sendt.isRunning();}
|
||||
|
||||
CDSection & k() {return k_;}
|
||||
CDSection * root(CDType::cdT cdt);
|
||||
PIString typeLetter(CDType::cdT cdt);
|
||||
|
||||
static PIString pultConfig() {return PIString(pult_config);}
|
||||
static PIString appConfig() {return PIString(app_config);}
|
||||
@@ -63,16 +66,19 @@ private:
|
||||
EVENT_HANDLER1(void, dtReceiveFinished, bool, ok);
|
||||
EVENT_HANDLER(void, sendThread);
|
||||
EVENT_HANDLER(void, xTimerTick);
|
||||
void initRoot(CDSection & r);
|
||||
void initRoot(CDSection * r);
|
||||
PIByteArray makeHeader(CDPacketType type, int session_id = 0) const;
|
||||
void sendDirect(PIByteArray & ba);
|
||||
void sendThreaded(PIByteArray & ba);
|
||||
void procReceivedPacket(PIByteArray & ba);
|
||||
|
||||
static const char app_config[], pult_config[];
|
||||
PIConnection connection;
|
||||
PIDataTransfer datatr;
|
||||
PacketHeader wheader;
|
||||
PIByteArray send_data;
|
||||
PIThread sendt;
|
||||
PITimer x_timer;
|
||||
CDSection k_;
|
||||
CDSection k_, x_, c_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
170
cd_utils/cdutils_interface.cpp
Normal file
170
cd_utils/cdutils_interface.cpp
Normal file
@@ -0,0 +1,170 @@
|
||||
#include "cdutils_interface.h"
|
||||
#include "cdutils_core.h"
|
||||
#include "piconfig.h"
|
||||
#include "pifile.h"
|
||||
|
||||
using namespace CDUtils;
|
||||
|
||||
|
||||
Interface::Interface(CDType::cdT type_) {
|
||||
core = CDCore::instance();
|
||||
s = core->root(type_);
|
||||
//piCoutObj << (void*)this << core;
|
||||
file_ = core->typeLetter(type_) + PIStringAscii(".dat");
|
||||
file_size = 0;
|
||||
}
|
||||
|
||||
|
||||
bool Interface::test(int v) {
|
||||
return s->test(v);
|
||||
}
|
||||
|
||||
|
||||
CDType & Interface::operator [](const PIString & name_) {
|
||||
return (*s)[name_];
|
||||
}
|
||||
|
||||
|
||||
const CDType Interface::operator [](const PIString & name_) const {
|
||||
return (*s)[name_];
|
||||
}
|
||||
|
||||
|
||||
CDType & Interface::operator [](const PIDeque<int> & path_) {
|
||||
return (*s)[path_];
|
||||
}
|
||||
|
||||
|
||||
const CDType Interface::operator [](const PIDeque<int> & path_) const {
|
||||
return (*s)[path_];
|
||||
}
|
||||
|
||||
|
||||
CDType & Interface::operator [](int v) {
|
||||
//piCout << (void*)this << "[]" << core;
|
||||
return (*s)[v];
|
||||
}
|
||||
|
||||
|
||||
const CDType Interface::operator [](int v) const {
|
||||
//piCout << (void*)this << "[]" << core;
|
||||
return (*s)[v];
|
||||
}
|
||||
|
||||
|
||||
CDSection & Interface::section(int v) {
|
||||
// CDSection & ret = s->section(v);
|
||||
// piCout << "[get section]" << v << ret.name;
|
||||
return s->section(v);
|
||||
}
|
||||
|
||||
|
||||
const CDSection Interface::section(int v) const {
|
||||
return s->section(v);
|
||||
}
|
||||
|
||||
|
||||
CDSection & Interface::section(const PIDeque<int> &path) {
|
||||
PIDeque<int> spath = path;
|
||||
CDSection * rs = s;
|
||||
while (!spath.isEmpty()) {
|
||||
rs = &(rs->section(spath.take_front()));
|
||||
}
|
||||
return *rs;
|
||||
}
|
||||
|
||||
|
||||
CDSection & Interface::root() {
|
||||
return *s;
|
||||
}
|
||||
|
||||
|
||||
const CDSection & Interface::root() const {
|
||||
return *s;
|
||||
}
|
||||
|
||||
|
||||
int Interface::count(bool recursive) const {
|
||||
return s->count(recursive);
|
||||
}
|
||||
|
||||
|
||||
void Interface::setFileName(const PIString & _file) {
|
||||
file_ = _file;
|
||||
}
|
||||
|
||||
|
||||
bool Interface::configure(const PIString & config) {
|
||||
PIConfig conf(config, PIIODevice::ReadOnly);
|
||||
PIConfig::Entry & e(conf.getValue(core->typeLetter(s->cd_type_)));
|
||||
bool ret = false;
|
||||
setFileName(e.getValue("file", file(), &ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void Interface::reinitConnection(const PIString &configuration) {
|
||||
core->init(configuration);
|
||||
}
|
||||
|
||||
|
||||
void Interface::startPing() {
|
||||
core->startPing();
|
||||
}
|
||||
|
||||
|
||||
void Interface::write(PIIODevice * d) {
|
||||
core->cd_write(s, d);
|
||||
}
|
||||
|
||||
|
||||
void Interface::read(PIIODevice * d) {
|
||||
core->cd_read(s, d);
|
||||
}
|
||||
|
||||
|
||||
void Interface::parse(PIIODevice * d) {
|
||||
core->cd_parse(s, d);
|
||||
}
|
||||
|
||||
|
||||
void Interface::update(PIIODevice * d, UpdateModeFlags mode) {
|
||||
core->cd_update(s, d, mode);
|
||||
}
|
||||
|
||||
|
||||
void Interface::calculate() {
|
||||
core->cd_calculate(s);
|
||||
}
|
||||
|
||||
|
||||
PIString Interface::appConfig() {
|
||||
return core->appConfig();
|
||||
}
|
||||
|
||||
|
||||
PIString Interface::pultConfig() {
|
||||
return core->pultConfig();
|
||||
}
|
||||
|
||||
|
||||
void Interface::readFile() {
|
||||
if (file_.isEmpty()) return;
|
||||
PIFile f(file_, PIIODevice::ReadOnly);
|
||||
read(&f);
|
||||
file_size = f.size();
|
||||
}
|
||||
|
||||
|
||||
void Interface::writeFile() {
|
||||
if (file_.isEmpty()) return;
|
||||
PIFile f(file_, PIIODevice::ReadWrite);
|
||||
f.clear();
|
||||
write(&f);
|
||||
file_size = f.size();
|
||||
}
|
||||
|
||||
|
||||
bool Interface::inProgress() {
|
||||
return core->inProgress();
|
||||
}
|
||||
66
cd_utils/cdutils_interface.h
Normal file
66
cd_utils/cdutils_interface.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#ifndef CDUTILS_INTERFACE_H
|
||||
#define CDUTILS_INTERFACE_H
|
||||
|
||||
#include "cdutils_types.h"
|
||||
#include "piobject.h"
|
||||
|
||||
|
||||
namespace CDUtils {
|
||||
|
||||
class CDCore;
|
||||
|
||||
|
||||
class Interface: public PIObject
|
||||
{
|
||||
PIOBJECT(CDUtils::Interface)
|
||||
public:
|
||||
Interface(CDType::cdT type_);
|
||||
|
||||
bool test(int v);
|
||||
CDType & operator [](int v);
|
||||
const CDType operator [](int v) const;
|
||||
CDType & operator [](const PIString & name_);
|
||||
const CDType operator [](const PIString & name_) const;
|
||||
CDType & operator [](const PIDeque<int> & path_);
|
||||
const CDType operator [](const PIDeque<int> & path_) const;
|
||||
CDSection & section(int v);
|
||||
const CDSection section(int v) const;
|
||||
CDSection & section(const PIDeque<int> & path);
|
||||
CDSection & root();
|
||||
const CDSection & root() const;
|
||||
|
||||
int count(bool recursive = true) const;
|
||||
const PIString file() const {return file_;}
|
||||
int fileSize() const {return file_size;}
|
||||
|
||||
void setFileName(const PIString & _file);
|
||||
bool configure(const PIString & config);
|
||||
void reinitConnection(const PIString & configuration);
|
||||
void startPing();
|
||||
void write(PIIODevice * d);
|
||||
void read(PIIODevice * d);
|
||||
void parse(PIIODevice * d);
|
||||
void update(PIIODevice * d, UpdateModeFlags mode = SaveByName);
|
||||
void calculate();
|
||||
|
||||
PIString appConfig();
|
||||
PIString pultConfig();
|
||||
|
||||
void readFile();
|
||||
void writeFile();
|
||||
bool inProgress();
|
||||
|
||||
protected:
|
||||
CDCore * core;
|
||||
CDSection * s;
|
||||
CDType::cdT type;
|
||||
PIString file_;
|
||||
int file_size;
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // CDUTILS_K_H
|
||||
@@ -1,18 +1,12 @@
|
||||
#include "cdutils_k.h"
|
||||
#include "cdutils_core.h"
|
||||
#include "piconfig.h"
|
||||
#include "pifile.h"
|
||||
|
||||
using namespace CDUtils;
|
||||
|
||||
KInterface K;
|
||||
|
||||
|
||||
KInterface::KInterface() {
|
||||
core = CDCore::instance();
|
||||
//piCoutObj << (void*)this << core;
|
||||
k_file = PIStringAscii("k.dat");
|
||||
k_file_size = 0;
|
||||
KInterface::KInterface(): Interface(CDType::cdK) {
|
||||
CONNECTU(core, K_Sended, this, sended);
|
||||
CONNECTU(core, K_SendFail, this, sendFailed);
|
||||
CONNECTU(core, K_Received, this, received);
|
||||
@@ -20,159 +14,16 @@ KInterface::KInterface() {
|
||||
}
|
||||
|
||||
|
||||
bool KInterface::test(int v) {
|
||||
return core->k_.test(v);
|
||||
}
|
||||
|
||||
|
||||
CDType & KInterface::operator [](const PIString & name_) {
|
||||
return core->k_[name_];
|
||||
}
|
||||
|
||||
|
||||
const CDType KInterface::operator [](const PIString & name_) const {
|
||||
return core->k_[name_];
|
||||
}
|
||||
|
||||
|
||||
CDType & KInterface::operator [](const PIDeque<int> & path_) {
|
||||
return core->k_[path_];
|
||||
}
|
||||
|
||||
|
||||
const CDType KInterface::operator [](const PIDeque<int> & path_) const {
|
||||
return core->k_[path_];
|
||||
}
|
||||
|
||||
|
||||
CDType & KInterface::operator [](int v) {
|
||||
//piCout << (void*)this << "[]" << core;
|
||||
return core->k_[v];
|
||||
}
|
||||
|
||||
|
||||
const CDType KInterface::operator [](int v) const {
|
||||
//piCout << (void*)this << "[]" << core;
|
||||
return core->k_[v];
|
||||
}
|
||||
|
||||
|
||||
CDSection & KInterface::section(int v) {
|
||||
// CDSection & ret = core->k_.section(v);
|
||||
// piCout << "[get section]" << v << ret.name;
|
||||
return core->k_.section(v);
|
||||
}
|
||||
|
||||
const CDSection KInterface::section(int v) const {
|
||||
return core->k_.section(v);
|
||||
}
|
||||
|
||||
|
||||
CDSection & KInterface::section(const PIDeque<int> &path) {
|
||||
PIDeque<int> spath = path;
|
||||
CDSection * rs = &core->k_;
|
||||
while (!spath.isEmpty()) {
|
||||
rs = &rs->section(spath.take_front());
|
||||
}
|
||||
return *rs;
|
||||
}
|
||||
|
||||
|
||||
CDSection & KInterface::root() {
|
||||
return core->k_;
|
||||
}
|
||||
|
||||
|
||||
const CDSection KInterface::root() const {
|
||||
return core->k_;
|
||||
}
|
||||
|
||||
|
||||
int KInterface::count(bool recursive) const {
|
||||
return core->k_.count(recursive);
|
||||
}
|
||||
|
||||
|
||||
void KInterface::send() {
|
||||
core->K_Send();
|
||||
}
|
||||
|
||||
|
||||
void KInterface::request() {
|
||||
core->K_Request();
|
||||
}
|
||||
|
||||
|
||||
bool KInterface::configure(const PIString & config, const PIString & sect) {
|
||||
PIConfig conf(config, PIIODevice::ReadOnly);
|
||||
PIConfig::Entry & e(conf.getValue(sect));
|
||||
bool ret = false;
|
||||
k_file = e.getValue("file", "k.dat", &ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void KInterface::reinitConnection(const PIString &configuration) {
|
||||
core->init(configuration);
|
||||
}
|
||||
|
||||
|
||||
void KInterface::startPing() {
|
||||
core->startPing();
|
||||
}
|
||||
|
||||
|
||||
void KInterface::write(PIIODevice * d) {
|
||||
core->k_write(d);
|
||||
}
|
||||
|
||||
|
||||
void KInterface::read(PIIODevice * d) {
|
||||
core->k_read(d);
|
||||
}
|
||||
|
||||
|
||||
void KInterface::parse(PIIODevice * d) {
|
||||
core->k_parse(d);
|
||||
}
|
||||
|
||||
|
||||
void KInterface::update(PIIODevice * d, UpdateModeFlags mode) {
|
||||
core->k_update(d, mode);
|
||||
}
|
||||
|
||||
|
||||
void KInterface::calculate() {
|
||||
core->k_calculate();
|
||||
}
|
||||
|
||||
|
||||
PIString KInterface::appConfig() {
|
||||
return core->appConfig();
|
||||
}
|
||||
|
||||
|
||||
PIString KInterface::pultConfig() {
|
||||
return core->pultConfig();
|
||||
}
|
||||
|
||||
|
||||
void KInterface::readFile() {
|
||||
if (k_file.isEmpty()) return;
|
||||
PIFile f(k_file, PIIODevice::ReadOnly);
|
||||
read(&f);
|
||||
k_file_size = f.size();
|
||||
}
|
||||
|
||||
|
||||
void KInterface::writeFile() {
|
||||
if (k_file.isEmpty()) return;
|
||||
PIFile f(k_file, PIIODevice::ReadWrite);
|
||||
f.clear();
|
||||
write(&f);
|
||||
k_file_size = f.size();
|
||||
}
|
||||
|
||||
|
||||
bool KInterface::inProgress() {
|
||||
return core->inProgress();
|
||||
void KInterface::directChange(const CDType & k, double v) {
|
||||
core->K_DirectChange(k.path(), PIString::fromNumber(v));
|
||||
}
|
||||
|
||||
@@ -1,38 +1,18 @@
|
||||
#ifndef CDUTILS_K_H
|
||||
#define CDUTILS_K_H
|
||||
|
||||
#include "cdutils_types.h"
|
||||
#include "piobject.h"
|
||||
#include "cdutils_interface.h"
|
||||
|
||||
|
||||
namespace CDUtils {
|
||||
|
||||
class CDCore;
|
||||
|
||||
|
||||
class KInterface: public PIObject
|
||||
class KInterface: public Interface
|
||||
{
|
||||
PIOBJECT(CDUtils::KInterface)
|
||||
public:
|
||||
KInterface();
|
||||
|
||||
bool test(int v);
|
||||
CDType & operator [](int v);
|
||||
const CDType operator [](int v) const;
|
||||
CDType & operator [](const PIString & name_);
|
||||
const CDType operator [](const PIString & name_) const;
|
||||
CDType & operator [](const PIDeque<int> & path_);
|
||||
const CDType operator [](const PIDeque<int> & path_) const;
|
||||
CDSection & section(int v);
|
||||
const CDSection section(int v) const;
|
||||
CDSection & section(const PIDeque<int> & path);
|
||||
CDSection & root();
|
||||
const CDSection root() const;
|
||||
|
||||
int count(bool recursive = true) const;
|
||||
const PIString file() const {return k_file;}
|
||||
int fileSize() const {return k_file_size;}
|
||||
|
||||
EVENT(sended)
|
||||
EVENT(sendFailed)
|
||||
EVENT(received)
|
||||
@@ -40,31 +20,11 @@ public:
|
||||
EVENT1(keepNamesRequest, bool*, kn)
|
||||
EVENT_HANDLER(void, send);
|
||||
EVENT_HANDLER(void, request);
|
||||
void setFileName(const PIString & file) {k_file = file;}
|
||||
bool configure(const PIString & config, const PIString & sect = PIStringAscii("k"));
|
||||
void reinitConnection(const PIString & configuration);
|
||||
void startPing();
|
||||
void write(PIIODevice * d);
|
||||
void read(PIIODevice * d);
|
||||
void parse(PIIODevice * d);
|
||||
void update(PIIODevice * d, UpdateModeFlags mode = SaveByName);
|
||||
void calculate();
|
||||
|
||||
PIString appConfig();
|
||||
PIString pultConfig();
|
||||
|
||||
void readFile();
|
||||
void writeFile();
|
||||
bool inProgress();
|
||||
|
||||
private:
|
||||
CDCore * core;
|
||||
PIString k_file;
|
||||
int k_file_size;
|
||||
void directChange(const CDType & k, double v);
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
extern CDUtils::KInterface K;
|
||||
|
||||
@@ -78,10 +78,10 @@ PIVector<int> enumValues(const PIString & e, const PIMap<PIString, CDSection> &
|
||||
|
||||
CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
|
||||
CDType::cdT et = (CDType::cdT)cdsection_type;
|
||||
if (!d) return CDSection();
|
||||
if (!d->canRead()) return CDSection();
|
||||
if (!d) return CDSection(et);
|
||||
if (!d->canRead()) return CDSection(et);
|
||||
//piCout << "[CDSection] parse start";
|
||||
CDSection cs;
|
||||
CDSection cs(et);
|
||||
CDType ck;
|
||||
PIMap<PIString, CDSection> sections;
|
||||
PIMap<PIString, int> enum_values;
|
||||
@@ -112,7 +112,7 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
|
||||
cind += 4;
|
||||
continue;
|
||||
}
|
||||
cs = CDSection();
|
||||
cs = CDSection(et);
|
||||
cs.name = line;
|
||||
//piCout << "enum" << cs.name;
|
||||
int cev = 0;
|
||||
@@ -129,11 +129,11 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
|
||||
// piCout << "#" << enum_values;
|
||||
if (!enum_values.contains(alias)) {
|
||||
piCout << "Parse error: can`t find section alias \"" << alias << "\"!";
|
||||
return CDSection();
|
||||
return CDSection(et);
|
||||
}
|
||||
if (!sections.contains(iarr.front())) {
|
||||
piCout << "Parse error: can`t find section \"" << iarr.front() << "\"!";
|
||||
return CDSection();
|
||||
return CDSection(et);
|
||||
}
|
||||
//piCout << "insert" << alias << iarr;
|
||||
int aval = enum_values.value(alias);
|
||||
@@ -150,7 +150,7 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
|
||||
ts.name = is.name;
|
||||
ts.name.insert(ibpos, PIString("[") << a << "]");
|
||||
is = ts;
|
||||
ts = CDSection();
|
||||
ts = CDSection(et);
|
||||
}
|
||||
is.alias = alias;
|
||||
cs.section(aval) = is;
|
||||
@@ -187,7 +187,7 @@ CDSection CDParser::parse(PIIODevice * d, int cdsection_type) {
|
||||
case CDType::cdK : return sections.value("KDescription");
|
||||
case CDType::cdX : return sections.value("XDescription");
|
||||
case CDType::cdC : return sections.value("CDescription");
|
||||
default: return CDSection();
|
||||
default: return CDSection(et);
|
||||
}
|
||||
return CDSection();
|
||||
return CDSection(et);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,19 @@
|
||||
|
||||
namespace CDUtils {
|
||||
|
||||
enum CDPacketType {CD_Ping, CD_Pong, CD_KQuery, CD_KSend, CD_KDirectChange, CD_XData, CD_XQuery, CD_Command};
|
||||
enum CDPacketType {CD_Ping,
|
||||
CD_Pong,
|
||||
|
||||
CD_KQuery,
|
||||
CD_KSend,
|
||||
CD_KDirectChange,
|
||||
|
||||
CD_XQuery,
|
||||
CD_XSend,
|
||||
CD_XValues,
|
||||
|
||||
CD_Command,
|
||||
};
|
||||
|
||||
# pragma pack(push,1)
|
||||
|
||||
@@ -15,7 +27,6 @@ enum CDPacketType {CD_Ping, CD_Pong, CD_KQuery, CD_KSend, CD_KDirectChange, CD_X
|
||||
};
|
||||
|
||||
struct PacketKDirectChange {
|
||||
PacketHeader header;
|
||||
PIDeque<int> path;
|
||||
PIString value;
|
||||
};
|
||||
@@ -26,8 +37,8 @@ enum CDPacketType {CD_Ping, CD_Pong, CD_KQuery, CD_KSend, CD_KDirectChange, CD_X
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PacketHeader & v) {s << v.type << v.session_id; return s;}
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PacketHeader & v) {s >> v.type >> v.session_id; return s;}
|
||||
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PacketKDirectChange & v) {s << v.header << v.path << v.value; return s;}
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PacketKDirectChange & v) {s >> v.header >> v.path >> v.value; return s;}
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PacketKDirectChange & v) {s << v.path << v.value; return s;}
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PacketKDirectChange & v) {s >> v.path >> v.value; return s;}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -226,11 +226,32 @@ PIVariantTypes::Enum CDType::parseEnumComment(PIString c) {
|
||||
//}
|
||||
|
||||
|
||||
|
||||
CDSection::CDSection(CDType::cdT type_) {
|
||||
cd_type_ = type_;
|
||||
null.cd_type_ = type_;
|
||||
}
|
||||
|
||||
|
||||
CDSection & CDSection::section(int v) {
|
||||
CDSection & ret(s[v]);
|
||||
ret.cd_type_ = cd_type_;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
const CDSection CDSection::section(int v) const {
|
||||
CDSection & ret(s[v]);
|
||||
ret.cd_type_ = cd_type_;
|
||||
return s[v];
|
||||
}
|
||||
|
||||
|
||||
int CDSection::count(bool recursive) const {
|
||||
int ret = cd.size_s();
|
||||
if (recursive) {
|
||||
PIMap<int, CDSection>::const_iterator i;
|
||||
for (i = s.begin(); i != s.end(); ++i)
|
||||
for (i = s.constBegin(); i != s.constEnd(); ++i)
|
||||
ret += i->second.count(recursive);
|
||||
}
|
||||
return ret;
|
||||
@@ -252,7 +273,8 @@ PIStringList CDSection::index_names() const {
|
||||
|
||||
|
||||
void CDSection::calculate() {
|
||||
/*CDCore::instance()->k_.*/prepareCalculate();
|
||||
prepareCalculate();
|
||||
if (cd_type_ != CDType::cdK) return;
|
||||
PIEvaluator e;
|
||||
calculateRecursive(&e);
|
||||
}
|
||||
@@ -265,7 +287,7 @@ CDType & CDSection::getByName(const PIString & name_) {
|
||||
CDSection * cs = this, * ns = 0;
|
||||
if (np.front().isEmpty()) {
|
||||
if (np.size_s() < 2) return null;
|
||||
cs = &(CDCore::instance()->k_);
|
||||
cs = CDCore::instance()->root(cd_type_);
|
||||
np.pop_front();
|
||||
}
|
||||
for (int i = 0; i < np.size_s() - 1; ++i) {
|
||||
@@ -318,15 +340,15 @@ CDType & CDSection::getByPath(const PIDeque<int> & path_) {
|
||||
}
|
||||
|
||||
|
||||
void CDSection::write(PIIODevice * d, CDType::cdT cdt, const PIString & prefix) {
|
||||
void CDSection::write(PIIODevice * d, const PIString & prefix) {
|
||||
if (!d) return;
|
||||
if (cd.isEmpty() && s.isEmpty()) return;
|
||||
// piCout << "[CDSection] write start";
|
||||
PIString l;
|
||||
PIStringList cdtl;
|
||||
cdtl << "null" << "k" << "x" << "c";
|
||||
if (prefix.isEmpty()) l = "[" + cdtl[cdt] + "]";
|
||||
else l = "[" + prefix + "." + cdtl[cdt] + "]";
|
||||
if (prefix.isEmpty()) l = "[" + cdtl[cd_type_] + "]";
|
||||
else l = "[" + prefix + "." + cdtl[cd_type_] + "]";
|
||||
l += "\n";
|
||||
d->write(l.toUTF8());
|
||||
l = "name = " + name + " \n";
|
||||
@@ -336,8 +358,8 @@ void CDSection::write(PIIODevice * d, CDType::cdT cdt, const PIString & prefix)
|
||||
PIMap<int, CDType>::iterator i;
|
||||
for (i = cd.begin(); i != cd.end(); ++i) {
|
||||
CDType & ck(i.value());
|
||||
if (ck.cd_type() != cdt) continue;
|
||||
switch (cdt) {
|
||||
if (ck.cd_type() != cd_type_) continue;
|
||||
switch (cd_type_) {
|
||||
case CDType::cdNull: break;
|
||||
case CDType::cdK:
|
||||
l.clear(); l << ck.index() << ".f = " << ck.formula() << " #s " << ck.comment() << " \n";
|
||||
@@ -373,7 +395,7 @@ void CDSection::write(PIIODevice * d, CDType::cdT cdt, const PIString & prefix)
|
||||
else l = prefix + ".s";
|
||||
PIMap<int, CDSection>::iterator j;
|
||||
for (j = s.begin(); j != s.end(); ++j) {
|
||||
j.value().write(d, cdt, l + "." + PIString::fromNumber(j.key()));
|
||||
j.value().write(d, l + "." + PIString::fromNumber(j.key()));
|
||||
}
|
||||
}
|
||||
if (prefix.isEmpty()) {
|
||||
@@ -384,18 +406,18 @@ void CDSection::write(PIIODevice * d, CDType::cdT cdt, const PIString & prefix)
|
||||
}
|
||||
|
||||
|
||||
void CDSection::read(const void * ep, CDType::cdT cdt) {
|
||||
void CDSection::read(const void * ep) {
|
||||
// piCout << "[CDSection] read start";
|
||||
PIStringList cdtl;
|
||||
cdtl << "null" << "k" << "x" << "c";
|
||||
cd.clear();
|
||||
s.clear();
|
||||
PIConfig::Entry & e(*(PIConfig::Entry*)ep);
|
||||
name = e.getValue(cdtl[cdt] + ".name").value();
|
||||
alias = e.getValue(cdtl[cdt] + ".alias").value();
|
||||
PIConfig::Entry & kl = e.getValue(cdtl[cdt]);
|
||||
for (int i = 0; i < kl.childCount(); ++i) {
|
||||
const PIConfig::Entry * e(kl.child(i));
|
||||
name = e.getValue(cdtl[cd_type_] + ".name").value();
|
||||
alias = e.getValue(cdtl[cd_type_] + ".alias").value();
|
||||
PIConfig::Entry & cdl = e.getValue(cdtl[cd_type_]);
|
||||
for (int i = 0; i < cdl.childCount(); ++i) {
|
||||
const PIConfig::Entry * e(cdl.child(i));
|
||||
bool ok = false;
|
||||
int id = e->name().toInt(-1, &ok);
|
||||
// piCout << "[read]" << ke->name() << ke->value() << ok;
|
||||
@@ -404,21 +426,21 @@ void CDSection::read(const void * ep, CDType::cdT cdt) {
|
||||
if (ok) {
|
||||
CDType c;
|
||||
PIString ev;
|
||||
switch (cdt) {
|
||||
switch (cd_type_) {
|
||||
case CDType::cdNull: break;
|
||||
case CDType::cdK:
|
||||
c = CDType(id, e->getValue("v").comment(), e->getValue("v").type(), e->getValue("v").value(), e->getValue("f").value(), e->getValue("f").comment(), cdt);
|
||||
c = CDType(id, e->getValue("v").comment(), e->getValue("v").type(), e->getValue("v").value(), e->getValue("f").value(), e->getValue("f").comment(), cd_type_);
|
||||
ev = e->getValue("ev", "");
|
||||
if (!ev.isEmpty())
|
||||
c.enum_values = c.parseEnumComment(ev);
|
||||
break;
|
||||
case CDType::cdX:
|
||||
c = CDType(id, e->getValue("name").value(), PIString(), PIString(), PIString() , e->getValue("name").comment(), cdt);
|
||||
c = CDType(id, e->getValue("name").value(), PIString(), PIString(), PIString() , e->getValue("name").comment(), cd_type_);
|
||||
c.setXMode((CDType::XMode)e->getValue("mode").value().toInt());
|
||||
c.setAvg((CDType::XMode)e->getValue("avg").value().toInt());
|
||||
break;
|
||||
case CDType::cdC:
|
||||
c = CDType(id, e->getValue("name").value(), PIString(), PIString(), PIString() , e->getValue("name").comment(), cdt);
|
||||
c = CDType(id, e->getValue("name").value(), PIString(), PIString(), PIString() , e->getValue("name").comment(), cd_type_);
|
||||
break;
|
||||
}
|
||||
cd[id] = c;
|
||||
@@ -428,7 +450,9 @@ void CDSection::read(const void * ep, CDType::cdT cdt) {
|
||||
for (int i = 0; i < sl.childCount(); ++i) {
|
||||
const PIConfig::Entry * se(sl.child(i));
|
||||
int sid = se->name().toInt();
|
||||
s[sid].read(se, cdt);
|
||||
CDSection & rs(s[sid]);
|
||||
rs.cd_type_ = cd_type_;
|
||||
rs.read(se);
|
||||
}
|
||||
// piCout << "[CDSection] read end";
|
||||
}
|
||||
@@ -442,16 +466,16 @@ void CDSection::update(CDSection & v, UpdateModeFlags mode) {
|
||||
//piCout << "[CDSection] update start";
|
||||
//piCout << "before" << k.size() << v.k.size();
|
||||
|
||||
PIMap<int, PIString> prev_k_f_bi;
|
||||
PIMap<PIString, PIString> prev_k_f_bn;
|
||||
PIMap<int, PIString> prev_cd_f_bi;
|
||||
PIMap<PIString, PIString> prev_cd_f_bn;
|
||||
PIMap<int, CDType>::iterator i;
|
||||
if (mode[SaveByIndex]) {
|
||||
for (i = cd.begin(); i != cd.end(); ++i)
|
||||
prev_k_f_bi[i.key()] = i.value().formula();
|
||||
prev_cd_f_bi[i.key()] = i.value().formula();
|
||||
}
|
||||
if (mode[SaveByName]) {
|
||||
for (i = cd.begin(); i != cd.end(); ++i)
|
||||
prev_k_f_bn[i.value().name_] = i.value().formula();
|
||||
prev_cd_f_bn[i.value().name_] = i.value().formula();
|
||||
}
|
||||
if (!mode[Merge])
|
||||
cd.clear();
|
||||
@@ -460,12 +484,12 @@ void CDSection::update(CDSection & v, UpdateModeFlags mode) {
|
||||
PIString n = i.value().name();
|
||||
cd[id] = i.value();
|
||||
if (mode[SaveByIndex]) {
|
||||
if (prev_k_f_bi.contains(id))
|
||||
cd[id].setFormula(prev_k_f_bi[id]);
|
||||
if (prev_cd_f_bi.contains(id))
|
||||
cd[id].setFormula(prev_cd_f_bi[id]);
|
||||
}
|
||||
if (mode[SaveByName]) {
|
||||
if (prev_k_f_bn.contains(n))
|
||||
cd[id].setFormula(prev_k_f_bn[n]);
|
||||
if (prev_cd_f_bn.contains(n))
|
||||
cd[id].setFormula(prev_cd_f_bn[n]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -535,14 +559,14 @@ void CDSection::update(CDSection & v, UpdateModeFlags mode) {
|
||||
|
||||
|
||||
bool CDSection::isSameStructure(CDSection & v) {
|
||||
PIMap<PIString, int> k_ids;
|
||||
PIMap<PIString, int> cd_ids;
|
||||
PIMap<int, CDType>::iterator i;
|
||||
for (i = cd.begin(); i != cd.end(); ++i)
|
||||
k_ids[i.value().name()] = i.key();
|
||||
cd_ids[i.value().name()] = i.key();
|
||||
for (i = v.cd.begin(); i != v.cd.end(); ++i) {
|
||||
if (!k_ids.contains(i.value().name())) continue;
|
||||
if (!cd_ids.contains(i.value().name())) continue;
|
||||
//piCout << i.key() << k[i.key()].name() << i.value().name();
|
||||
if (cd[k_ids[i.value().name()]].index() != i.key())
|
||||
if (cd[cd_ids[i.value().name()]].index() != i.key())
|
||||
return false;
|
||||
}
|
||||
PIMap<int, CDSection>::iterator j;
|
||||
@@ -602,7 +626,7 @@ PIVector<CDType * > CDSection::children(bool recursive) const {
|
||||
ret << const_cast<CDType * >(&(i.value()));
|
||||
if (!recursive) return ret;
|
||||
PIMap<int, CDSection>::const_iterator j;
|
||||
for (j = s.begin(); j != s.end(); ++j)
|
||||
for (j = s.constBegin(); j != s.constEnd(); ++j)
|
||||
ret << j.value().children(true);
|
||||
return ret;
|
||||
}
|
||||
@@ -611,7 +635,7 @@ PIVector<CDType * > CDSection::children(bool recursive) const {
|
||||
PIVariantTypes::Enum CDSection::enumValues() const {
|
||||
PIVariantTypes::Enum ret;
|
||||
PIMap<int, CDType>::const_iterator i;
|
||||
for (i = cd.begin(); i != cd.end(); ++i)
|
||||
for (i = cd.constBegin(); i != cd.constEnd(); ++i)
|
||||
ret << PIVariantTypes::Enumerator(i.key(), i.value().name());
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ typedef PIFlags<UpdateMode> UpdateModeFlags;
|
||||
|
||||
class CDType {
|
||||
friend class CDSection;
|
||||
friend class CDCore;
|
||||
friend class Interface;
|
||||
public:
|
||||
enum cdT {cdNull, cdK, cdX, cdC};
|
||||
enum XMode {X_Current, X_All_Avg};
|
||||
@@ -78,12 +80,13 @@ protected:
|
||||
|
||||
class CDSection {
|
||||
friend class CDCore;
|
||||
friend class Interface;
|
||||
friend class ::CD_Pult;
|
||||
friend class ::CDKItem;
|
||||
friend class ::CDKItemModel;
|
||||
public:
|
||||
|
||||
CDSection() {}
|
||||
CDSection(CDType::cdT type_ = CDType::cdNull);
|
||||
|
||||
bool test(int v) {return cd.value(v).toBool();}
|
||||
// CDType & operator [](int v) {if (!k.contains(v)) k[v].index_ = v; return k[v];}
|
||||
@@ -93,8 +96,8 @@ public:
|
||||
const CDType operator [](const PIString & name_) const {return const_cast<CDSection*>(this)->getByName(name_);}
|
||||
CDType & operator [](const PIDeque<int> & path_) {return getByPath(path_);}
|
||||
const CDType operator [](const PIDeque<int> & path_) const {return const_cast<CDSection*>(this)->getByPath(path_);}
|
||||
CDSection & section(int v) {return s[v];}
|
||||
const CDSection section(int v) const {return s[v];}
|
||||
CDSection & section(int v);
|
||||
const CDSection section(int v) const;
|
||||
|
||||
bool isEmpty() const {return cd.isEmpty() && s.isEmpty();}
|
||||
int count(bool recursive = true) const;
|
||||
@@ -116,16 +119,17 @@ protected:
|
||||
}
|
||||
CDType & getByName(const PIString & name_);
|
||||
CDType & getByPath(const PIDeque<int> & path_);
|
||||
void write(PIIODevice * d, CDType::cdT cdt, const PIString & prefix = PIString());
|
||||
void read(const void * ep, CDType::cdT cdt);
|
||||
void write(PIIODevice * d, const PIString & prefix = PIString());
|
||||
void read(const void * ep);
|
||||
void update(CDSection & v, UpdateModeFlags mode = SaveByName);
|
||||
bool isSameStructure(CDSection & v);
|
||||
void prepareCalculate();
|
||||
void calculateRecursive(PIEvaluator * e);
|
||||
|
||||
PIMap<int, CDType> cd;
|
||||
PIMap<int, CDSection> s;
|
||||
mutable PIMap<int, CDSection> s;
|
||||
CDType null;
|
||||
CDType::cdT cd_type_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ class Core : public PIObject
|
||||
PIOBJECT(Core)
|
||||
public:
|
||||
Core() {
|
||||
CDCore::instance()->initApp();
|
||||
// piCout << "testCore";
|
||||
CONNECTU(&t, tickEvent, this, timerDone);
|
||||
t.start(1000);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
project(cd_pult)
|
||||
file(GLOB SRC "*.h" "*.cpp" "*.ui" "*.qrc" "lang/*.ts")
|
||||
find_qt(${QtVersions} Core Gui OpenGL)
|
||||
qt_sources(SRC)
|
||||
qt_wrap(${SRC} HDRS out_HDR CPPS out_CPP QMS out_QM)
|
||||
qt_add_executable(${PROJECT_NAME} WIN32 out_CPP)
|
||||
qt_target_link_libraries(${PROJECT_NAME} qad_utils qad_widgets qad_graphic qcd_utils qad_application)
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
CDPultWindow::CDPultWindow(QWidget *parent) : EMainWindow(parent), ui(new Ui::CDPultWindow) {
|
||||
CDUtils::CDCore::instance()->initPult();
|
||||
qRegisterMetaType<LogIcon>("LogIcon");
|
||||
log_icons[OKIcon] = QIcon("://icons/dialog-ok-apply.png");
|
||||
log_icons[FailIcon] = QIcon("://icons/dialog-cancel.png");
|
||||
log_icons[WaitIcon] = QIcon("://icons/timer.png");
|
||||
log_icons[OKIcon] = QIcon(":/icons/dialog-ok-apply.png");
|
||||
log_icons[FailIcon] = QIcon(":/icons/dialog-cancel.png");
|
||||
log_icons[WaitIcon] = QIcon(":/icons/timer.png");
|
||||
ui->setupUi(this);
|
||||
centralWidget()->hide();
|
||||
setRecentMenu(ui->menuOpen_recent);
|
||||
|
||||
@@ -280,7 +280,7 @@ QString CDKItem::stringType(const PIString & t) const {
|
||||
case 'F': return QString("file"); break;
|
||||
case 'D': return QString("dir"); break;
|
||||
}
|
||||
return QString("double");
|
||||
return QString("string");
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user