git-svn-id: svn://db.shs.com.ru/pip@493 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
300
main.cpp
300
main.cpp
@@ -1,38 +1,6 @@
|
||||
#include "pip.h"
|
||||
/*
|
||||
struct __S__ {
|
||||
PIString text;
|
||||
int i;
|
||||
};
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const __S__ & v) {s << v.text << v.i; return s;}
|
||||
inline PIByteArray & operator >>(PIByteArray & s, __S__ & v) {s >> v.text >> v.i; return s;}
|
||||
|
||||
REGISTER_VARIANT(__S__)
|
||||
REGISTER_VARIANT_CAST(__S__, PIString) {return v.text + PIString::fromNumber(v.i);}
|
||||
REGISTER_VARIANT_CAST(__S__, int) {return v.i;}
|
||||
*/
|
||||
/*const char app_config[] =
|
||||
"include = cd_ip.conf\n\
|
||||
port_rec = 2\n\
|
||||
port_send = 1\n\
|
||||
[connection]\n\
|
||||
device.cd = peer://cd_app:cd_pult #s\n\
|
||||
[]\n\
|
||||
connectionmodel = AAAM2Xja7VXLTttAFD12QpsikKjUSixYlLbKEpIUtVIlVEfqhk2FWuiGRRolUYtoHgrmpYiv6IItf8AveMMH9E/YsG6Ph3sde5hGoQoblLGuPHfunTPjc49nADxDA110+LTYC7FrPCAPeAO+vZu+aX7c/8PGd45WCJC0OGcfT6FDnmfSTPtwhZFt3HjgDs/Qtu5jPbZHtI/x50XfIzMQbdwEolbg9INP4ku++myPaUtCHYRaT2j1ldIh3VP60/Qff8vSfXLu9BP6JX9K/0TVH6jqVe22P1X/fao/oddWu/paDs1vBf9Jv/EZ91clbyHqv7BL6sscDOd4v4WTqs6jzaHGJ8QJerxlpJSpdZ7IWFJvDW7I2JxZqIM62k6A57RZmMQGmlyrxdV+WGBnmR01mXPI267hBKwp4FeBeo9VPtssxyb7rzHg1B7T9nCMU45U8BZlWuVWtIcD/CRGOqtsbW09851tXsHN0UTlLIAdASjSXnLyLn+H7L2+xbGYvC63Ezqg543egkLmn8qnRF6USbM4Qp9godkhzI777Ne5bCIt/5UtGz2o/yGby0nKpjqmbOa1ynkjmyzIrzvIZUeBPjvlUmbh32EFJbGyJZhR8YcvlS+3TpjhqeWSyvUkpbI9plSWtcKLcsK05beOJVEnhaEFfHEH+RwpeMcpn1JKGqWMNOL+G6wZyahlpdVOtufKfbDS+guLke9O\n\
|
||||
";
|
||||
|
||||
const char pult_config[] =
|
||||
"include = cd_ip.conf\n\
|
||||
port_rec = 1\n\
|
||||
port_send = 2\n\
|
||||
[connection]\n\
|
||||
device.cd = peer://cd_pult:cd_app #s\n\
|
||||
[]\n\
|
||||
connectionmodel = AAAM2Xja7VXLTttAFD12QpsikKjUSixYlLbKEpIUtVIlVEfqhk2FWuiGRRolUYtoHgrmpYiv6IItf8AveMMH9E/YsG6Ph3sde5hGoQoblLGuPHfunTPjc49nADxDA110+LTYC7FrPCAPeAO+vZu+aX7c/8PGd45WCJC0OGcfT6FDnmfSTPtwhZFt3HjgDs/Qtu5jPbZHtI/x50XfIzMQbdwEolbg9INP4ku++myPaUtCHYRaT2j1ldIh3VP60/Qff8vSfXLu9BP6JX9K/0TVH6jqVe22P1X/fao/oddWu/paDs1vBf9Jv/EZ91clbyHqv7BL6sscDOd4v4WTqs6jzaHGJ8QJerxlpJSpdZ7IWFJvDW7I2JxZqIM62k6A57RZmMQGmlyrxdV+WGBnmR01mXPI267hBKwp4FeBeo9VPtssxyb7rzHg1B7T9nCMU45U8BZlWuVWtIcD/CRGOqtsbW09851tXsHN0UTlLIAdASjSXnLyLn+H7L2+xbGYvC63Ezqg543egkLmn8qnRF6USbM4Qp9godkhzI777Ne5bCIt/5UtGz2o/yGby0nKpjqmbOa1ynkjmyzIrzvIZUeBPjvlUmbh32EFJbGyJZhR8YcvlS+3TpjhqeWSyvUkpbI9plSWtcKLcsK05beOJVEnhaEFfHEH+RwpeMcpn1JKGqWMNOL+G6wZyahlpdVOtufKfbDS+guLke9O\n\
|
||||
";
|
||||
*/
|
||||
|
||||
/*
|
||||
class A: public PIObject {
|
||||
PIOBJECT(A)
|
||||
public:
|
||||
@@ -43,259 +11,27 @@ class B: public PIObject {
|
||||
PIOBJECT(B)
|
||||
public:
|
||||
EVENT_HANDLER0(void, eh0) {piCout << "eh0";}
|
||||
EVENT_HANDLER1(void, eh1, float, f) {piCout << "eh1" << f;}
|
||||
EVENT_HANDLER1(void, eh1, float, f) {piCout << "eh1_1" << f;}
|
||||
EVENT_HANDLER2(void, eh1, float, f, int, s) {piCout << "eh1_2" << f << s;}
|
||||
};
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc < 2) return 0;
|
||||
bool r = PIString(argv[1]).toBool();
|
||||
PISharedMemory shm;
|
||||
//shm.setSize(64);
|
||||
shm.open("test", r ? PIIODevice::ReadOnly : PIIODevice::WriteOnly);
|
||||
piCout << "open" << shm.isOpened();
|
||||
if (!r) {
|
||||
int wr = shm.write(PIString("data").toByteArray());
|
||||
piCout << "wrote" << wr;
|
||||
return 0;
|
||||
}
|
||||
PIByteArray rb(4);
|
||||
shm.write(rb);
|
||||
piSleep(3.);
|
||||
int rd = shm.read(rb.data(), rb.size_s());
|
||||
piCout << "readed" << rd << PIString(rb);
|
||||
|
||||
// PIFFTWf fft;
|
||||
// fft.preparePlan(50, PIFFTWf::foReal);
|
||||
// PIVector<complexf> out = fft.calcFFT(in);
|
||||
// piCout << out;
|
||||
|
||||
/*for (int i = 0; i < 16; ++i) {
|
||||
piCout << asize(i, 100);
|
||||
}
|
||||
return 0;*/
|
||||
/*__S__ s, s1;
|
||||
s.text = "123";
|
||||
s.i = -1;
|
||||
PIVariant v = PIVariant::fromValue(s);
|
||||
PIByteArray ba;
|
||||
ba << v;
|
||||
PIVariant v1;
|
||||
ba >> v1;
|
||||
piCout << v1;*/
|
||||
/*PISet<int> s0;
|
||||
s0 << 1 << 3 << 5;
|
||||
PIVector<int> v;
|
||||
v << -1 << 8 << 0 << 2 << 1 << 6 << 4 << 3;
|
||||
piCout << s0;
|
||||
PISet<int> s1(v);
|
||||
piCout << s1;
|
||||
s1.subtract(s0);
|
||||
piCout << s1;*/
|
||||
|
||||
/*PIConnection c;
|
||||
PIString s(app_config);
|
||||
c.configureFromString(&s);
|
||||
c.start();
|
||||
piMSleep(3000);
|
||||
s = pult_config;
|
||||
c.stop();
|
||||
c.removeAllDevices();
|
||||
c.configureFromString(&s);
|
||||
c.start();
|
||||
piMSleep(3000);*/
|
||||
|
||||
/*PIScreen s;
|
||||
s.enableExitCapture(PIKbdListener::F10);
|
||||
s.start();
|
||||
TileList * list = new TileList();
|
||||
for (int i = 0; i < 100; ++i)
|
||||
list->content << TileList::Row(i, PIScreenTypes::CellFormat());
|
||||
s.rootTile()->addTile(list);
|
||||
s.waitForFinish();*/
|
||||
|
||||
/*PIDeque<int> d;
|
||||
d.resize(atoi(argv[1]));
|
||||
while (1) {
|
||||
d.push_back(1);
|
||||
d.pop_front();
|
||||
piCout << d.size() << d.capacity() << d._start();
|
||||
}*/
|
||||
//PIVector<PIIODevice> o;
|
||||
//o[0] = o[1];
|
||||
|
||||
A a;
|
||||
B b;
|
||||
/*CONNECTU_QUEUED(&a, ev1, &b, eh0, &b);
|
||||
CONNECTU_QUEUED(&a, ev1, &b, eh1, &a);
|
||||
piCout << "start";
|
||||
a.ev1(1.5);
|
||||
piSleep(1);
|
||||
piCout << a.maybeCallQueuedEvents();
|
||||
piSleep(1);
|
||||
piCout << b.maybeCallQueuedEvents();*/
|
||||
//piCout << "end";
|
||||
b.executeQueued(&a, "eh1", PIVariant(0.1), "0150", 10, 40);
|
||||
piSleep(1);
|
||||
a.maybeCallQueuedEvents();
|
||||
//dumpApplication();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
using namespace PIScreenTypes;
|
||||
|
||||
PIScreen screen;
|
||||
PIConnection conn;
|
||||
TileSimple statustile;
|
||||
TileSimple odbtile;
|
||||
|
||||
void update();
|
||||
void updateODB();
|
||||
|
||||
struct ODBdata {
|
||||
float speed;
|
||||
float temp_engine_coolant;
|
||||
float temp_intake_air;
|
||||
float voltage;
|
||||
float fluel;
|
||||
float pedal_accelerator;
|
||||
float throttle;
|
||||
float engine_load;
|
||||
float engine_RPM;
|
||||
};
|
||||
|
||||
ODBdata odb;
|
||||
|
||||
const char conn_config[] =
|
||||
"[connection]\n\
|
||||
device.test = ser://COM61:9600 #s\n\
|
||||
device.test.disconnectTimeout = 3.00000000 #f\n\
|
||||
filter.raw.device = test\n\
|
||||
filter.raw.splitMode = header & footer\n\
|
||||
filter.raw.header = 0x34 0x31\n\
|
||||
filter.raw.footer = 0x0D\n\
|
||||
[]\n";
|
||||
|
||||
class Obj : public PIObject {
|
||||
PIOBJECT(Obj)
|
||||
public:
|
||||
Obj() {
|
||||
quering = false;
|
||||
CONNECTU(&conn, dataReceivedEvent, this, recv);
|
||||
CONNECTU(&conn, packetReceivedEvent, this, recv2);
|
||||
CONNECTU(&timer, tickEvent, this, tick);
|
||||
st = PISystemTime::current();
|
||||
timer.start(5);
|
||||
}
|
||||
EVENT_HANDLER1(void, keyEv, PIKbdListener::KeyEvent, k) {
|
||||
//piCoutObj << k.key;
|
||||
if (k.key == -20) {
|
||||
piCout << "exiting...";
|
||||
PIKbdListener::exiting = true;
|
||||
}
|
||||
if (k.key == 's') {
|
||||
quering = !quering;
|
||||
}
|
||||
if (k.key == 'a') {
|
||||
quering = true;
|
||||
queryODB();
|
||||
}
|
||||
if (k.key == 'i') {
|
||||
initODB();
|
||||
}
|
||||
}
|
||||
|
||||
EVENT_HANDLER2(void, recv, const PIString &, from, const PIByteArray &, data) {
|
||||
PIString s(data);
|
||||
if (s.isEmpty()) return;
|
||||
piCoutObj << from << PIString(data) << PICoutManipulators::Hex << data;
|
||||
}
|
||||
|
||||
EVENT_HANDLER2(void, recv2, const PIString &, from, const PIByteArray &, data) {
|
||||
PIString s(data);
|
||||
s.cutRight(1);
|
||||
if (s.isEmpty()) return;
|
||||
piCoutObj << from << PICoutManipulators::Hex << data << s;
|
||||
PIByteArray ba = PIByteArray::fromHex(s);
|
||||
piCoutObj << s << ba;
|
||||
if (ba.size() < 3) return;
|
||||
int mode = ba[0] - 0x40;
|
||||
int pid = ba[1];
|
||||
if (mode != 1) return;
|
||||
switch(pid) {
|
||||
case 0x0D:
|
||||
odb.speed = ba[2];
|
||||
break;
|
||||
case 0x0C:
|
||||
odb.engine_RPM = (float(ba[2])*256. + float(ba[3]))/4.;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
EVENT_HANDLER(void, tick) {
|
||||
PISystemTime t = PISystemTime::current() - st;
|
||||
if (t.toSeconds() > 100. || t.toSeconds() < -100.) piCout << "time error! " << st << PISystemTime::current(true) << t;
|
||||
st = PISystemTime::current();
|
||||
if (!inited) initODB();
|
||||
queryODB();
|
||||
update();
|
||||
updateODB();
|
||||
}
|
||||
|
||||
private:
|
||||
void initODB() {
|
||||
conn.writeByName("test", PIString("ATZ\r\n").toByteArray());
|
||||
piMSleep(1000);
|
||||
inited = true;
|
||||
}
|
||||
|
||||
void queryODB() {
|
||||
if (!quering) return;
|
||||
conn.writeByName("test", PIString("01 0D\r").toByteArray());
|
||||
//piMSleep(10);
|
||||
//conn.writeByName("test", PIString("01 0C\r").toByteArray());
|
||||
}
|
||||
bool inited;
|
||||
bool quering;
|
||||
PITimer timer;
|
||||
PISystemTime st;
|
||||
};
|
||||
|
||||
int main (int argc, char * argv[]) {
|
||||
PIScreenTile * tl = new PIScreenTile();
|
||||
tl->direction = Horizontal;
|
||||
statustile.size_policy = Expanding;
|
||||
statustile.maximumWidth = 40;
|
||||
odbtile.size_policy = Expanding;
|
||||
tl->addTile(&statustile);
|
||||
tl->addTile(&odbtile);
|
||||
screen.rootTile()->addTile(tl);
|
||||
screen.rootTile()->addTile(new TilePICout());
|
||||
screen.enableExitCapture();
|
||||
screen.rootTile()->children().front()->setFocus();
|
||||
Obj * o = new Obj();
|
||||
CONNECTU(&screen, keyPressed, o, keyEv)
|
||||
PIString s = conn_config;
|
||||
conn.configureFromString(&s);
|
||||
conn.start();
|
||||
screen.waitForFinish();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void update() {
|
||||
screen.lock();
|
||||
statustile.content.clear();
|
||||
PISerial * ser = (PISerial *)conn.deviceByName("test");
|
||||
PIDiagnostics * diag = conn.diagnostic(ser);
|
||||
if (ser && diag) {
|
||||
statustile.content << TileSimple::Row(ser->constructFullPath() + " - " + PIString::fromBool(ser->isOpened()), CellFormat(PIScreenTypes::Default, PIScreenTypes::Default, PIScreenTypes::Bold));
|
||||
statustile.content << TileSimple::Row(diag->name() + " diagnostics", CellFormat(PIScreenTypes::Default, PIScreenTypes::Default, PIScreenTypes::Bold));
|
||||
statustile.content << TileSimple::Row("Received count: " + PIString::fromNumber(diag->receiveCount()), CellFormat());
|
||||
statustile.content << TileSimple::Row("Invalid count: " + PIString::fromNumber(diag->wrongCount()), CellFormat());
|
||||
statustile.content << TileSimple::Row("Sended count: " + PIString::fromNumber(diag->sendCount()), CellFormat());
|
||||
statustile.content << TileSimple::Row("Immediate Frequency, Hz: " + PIString::fromNumber(diag->immediateFrequency()), CellFormat());
|
||||
statustile.content << TileSimple::Row("Integral Frequency, Hz: " + PIString::fromNumber(diag->integralFrequency()), CellFormat());
|
||||
statustile.content << TileSimple::Row("Receive speed: " + diag->receiveSpeed(), CellFormat());
|
||||
statustile.content << TileSimple::Row("Send speed: " + diag->sendSpeed(), CellFormat());
|
||||
statustile.content << TileSimple::Row("Quality: " + PIString::fromNumber((int)diag->quality()), CellFormat());
|
||||
}
|
||||
screen.unlock();
|
||||
}
|
||||
|
||||
void updateODB() {
|
||||
screen.lock();
|
||||
odbtile.content.clear();
|
||||
odbtile.content << TileSimple::Row("Speed: " + PIString::fromNumber(odb.speed), CellFormat());
|
||||
odbtile.content << TileSimple::Row("RPM: " + PIString::fromNumber(odb.engine_RPM), CellFormat());
|
||||
screen.unlock();
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -56,12 +56,12 @@ handler A: event to event
|
||||
|
||||
|
||||
|
||||
PIString PIObject::__EHFunc::arguments() const {
|
||||
PIString PIObject::__MetaFunc::arguments() const {
|
||||
return types.join(",");
|
||||
}
|
||||
|
||||
|
||||
PIString PIObject::__EHFunc::fullFormat() const {
|
||||
PIString PIObject::__MetaFunc::fullFormat() const {
|
||||
PIString ret = type_ret + " " + scope + "::" + func_name +"(";
|
||||
for (int i = 0; i < types.size_s(); ++i) {
|
||||
if (i > 0) ret += ", ";
|
||||
@@ -90,6 +90,42 @@ PIObject::~PIObject() {
|
||||
}
|
||||
|
||||
|
||||
bool PIObject::execute(const PIString & method, const PIVector<PIVariant> & vl) {
|
||||
if (method.isEmpty()) return false;
|
||||
if (!isPIObject()) {
|
||||
piCout << "Error: \"execute(" << method << ")\":" << (void*)this << "is not PIObject!";
|
||||
return false;
|
||||
}
|
||||
int ac = 0;
|
||||
__MetaFunc func;
|
||||
bool ok = findSuitableMethodV(method, vl.size_s(), ac, func);
|
||||
if (!ok)
|
||||
return false;
|
||||
callAddrV(func.addrV, this, ac, vl);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool PIObject::executeQueued(PIObject * performer, const PIString & method, const PIVector<PIVariant> & vl) {
|
||||
if (!isPIObject()) {
|
||||
piCout << "Error: \"executeQueued(" << method << ")\": this(" << (void*)this << ") is not PIObject!";
|
||||
return false;
|
||||
}
|
||||
if (!performer->isPIObject()) {
|
||||
piCout << "Error: \"executeQueued(" << method << ")\": performer(" << (void*)performer << ") is not PIObject!";
|
||||
return false;
|
||||
}
|
||||
int ac = 0;
|
||||
__MetaFunc func;
|
||||
bool ok = findSuitableMethodV(method, vl.size_s(), ac, func);
|
||||
if (!ok)
|
||||
return false;
|
||||
performer->postQueuedEvent(QueuedEvent(func.addrV, this, this, performer, vl));
|
||||
performer->proc_event_queue = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void PIObject::piConnect(const PIString & src, const PIString & sig, void * dest, void * ev_h) {
|
||||
PIObject * o = findByName(src);
|
||||
if (o == 0) {
|
||||
@@ -193,8 +229,8 @@ PIString PIObject::methodEHFromAddr(const void * addr) const {
|
||||
}
|
||||
|
||||
|
||||
PIVector<PIObject::__EHFunc> PIObject::findEH(const PIString & name) const {
|
||||
PIVector<__EHFunc> ret;
|
||||
PIVector<PIObject::__MetaFunc> PIObject::findEH(const PIString & name) const {
|
||||
PIVector<__MetaFunc> ret;
|
||||
__MetaData & ehd(__meta_data()[className()]);
|
||||
piForeachC (__EHPair & eh, ehd.eh_func)
|
||||
if (eh.second.func_name == name)
|
||||
@@ -203,7 +239,7 @@ PIVector<PIObject::__EHFunc> PIObject::findEH(const PIString & name) const {
|
||||
}
|
||||
|
||||
|
||||
PIObject::__EHFunc PIObject::methodEH(const void * addr) const {
|
||||
PIObject::__MetaFunc PIObject::methodEH(const void * addr) const {
|
||||
PIMutexLocker ml(__meta_mutex());
|
||||
return __meta_data()[className()].eh_func.value(addr);
|
||||
}
|
||||
@@ -238,7 +274,7 @@ bool PIObject::piConnectU(PIObject * src, const PIString & ename, PIObject * des
|
||||
PIMutexLocker ml(__meta_mutex());
|
||||
PIMutexLocker mls(src->mutex_connect);
|
||||
PIMutexLocker mld(dest_o->mutex_connect, src != dest_o);
|
||||
PIVector<__EHFunc> m_src = src->findEH(ename), m_dest = dest_o->findEH(hname);
|
||||
PIVector<__MetaFunc> m_src = src->findEH(ename), m_dest = dest_o->findEH(hname);
|
||||
if (m_src.isEmpty()) {
|
||||
piCout << "[piConnectU] Error: can`t find event \"" << ename << "\" in class \"" << src->className() << "\"! (" << loc << ")";
|
||||
return false;
|
||||
@@ -250,9 +286,9 @@ bool PIObject::piConnectU(PIObject * src, const PIString & ename, PIObject * des
|
||||
void * addr_src(0), * addr_dest(0);
|
||||
int args(0);
|
||||
bool que = (performer != 0);
|
||||
piForeachC (__EHFunc & fs, m_src) {
|
||||
piForeachC (__MetaFunc & fs, m_src) {
|
||||
if (addr_src != 0) break;
|
||||
piForeachC (__EHFunc & fd, m_dest) {
|
||||
piForeachC (__MetaFunc & fd, m_dest) {
|
||||
if (addr_src != 0) break;
|
||||
if (fs.arguments().startsWith(fd.arguments()) || fd.arguments().isEmpty()) {
|
||||
addr_src = fs.addr;
|
||||
@@ -383,26 +419,58 @@ void PIObject::callQueuedEvents() {
|
||||
piForeachC (QueuedEvent & e, qe) {
|
||||
if (e.dest_o->thread_safe_) e.dest_o->mutex_.lock();
|
||||
e.dest_o->emitter_ = e.src;
|
||||
switch (e.values.size_s()) {
|
||||
case 0: ((void(*)(void *))e.slot)(e.dest); break;
|
||||
case 1: ((void(*)(void * , const PIVariant & ))e.slot)(e.dest, e.values[0]); break;
|
||||
case 2: ((void(*)(void * , const PIVariant & , const PIVariant & ))e.slot)(e.dest, e.values[0], e.values[1]); break;
|
||||
case 3: ((void(*)(void * , const PIVariant & , const PIVariant & , const PIVariant & ))e.slot)(e.dest, e.values[0], e.values[1], e.values[2]); break;
|
||||
case 4: ((void(*)(void * , const PIVariant & , const PIVariant & , const PIVariant & , const PIVariant & ))e.slot)(e.dest, e.values[0], e.values[1], e.values[2], e.values[3]); break;
|
||||
default: break;
|
||||
}
|
||||
callAddrV(e.slot, e.dest, e.values.size_s(), e.values);
|
||||
e.dest_o->emitter_ = 0;
|
||||
if (e.dest_o->thread_safe_) e.dest_o->mutex_.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool PIObject::findSuitableMethodV(const PIString & method, int args, int & ret_args, PIObject::__MetaFunc & ret) {
|
||||
PIVector<__MetaFunc> ml = findEH(method);
|
||||
if (ml.isEmpty()) {
|
||||
piCoutObj << "Error: no such method \"" << method << "\"!";
|
||||
return false;
|
||||
}
|
||||
int mfi = -1, ac = -1, mac = -1;
|
||||
for (int i = 0; i < ml.size_s(); ++i) {
|
||||
__MetaFunc & m(ml[i]);
|
||||
int j = m.names.size_s();
|
||||
if (mac < 0 || mac > j) mac = j;
|
||||
if ((j <= args) && (ac < j)) {
|
||||
ac = j;
|
||||
mfi = i;
|
||||
}
|
||||
}
|
||||
if (mfi < 0) {
|
||||
piCoutObj << "Error: no such suitable method \"" << method << "\", need at least" << mac << "arguments!";
|
||||
return false;
|
||||
}
|
||||
ret_args = ac;
|
||||
ret = ml[mfi];
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
PIVector<PIObject * > & PIObject::objects() {
|
||||
static PIVector<PIObject * > ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIObject::callAddrV(void * slot, void * obj, int args, const PIVector<PIVariant> & vl) {
|
||||
args = piMini(args, vl.size_s());
|
||||
switch (args) {
|
||||
case 0: ((void(*)(void *))slot)(obj); break;
|
||||
case 1: ((void(*)(void * , const PIVariant & ))slot)(obj, vl[0]); break;
|
||||
case 2: ((void(*)(void * , const PIVariant & , const PIVariant & ))slot)(obj, vl[0], vl[1]); break;
|
||||
case 3: ((void(*)(void * , const PIVariant & , const PIVariant & , const PIVariant & ))slot)(obj, vl[0], vl[1], vl[2]); break;
|
||||
case 4: ((void(*)(void * , const PIVariant & , const PIVariant & , const PIVariant & , const PIVariant & ))slot)(obj, vl[0], vl[1], vl[2], vl[3]); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PIString PIObject::simplifyType(const char * a) {
|
||||
PIString ret = PIStringAscii(a).trim();
|
||||
int white = -1;
|
||||
@@ -431,19 +499,6 @@ PIString PIObject::simplifyType(const char * a) {
|
||||
}
|
||||
|
||||
|
||||
bool PIObject::execute(const PIString & method) {
|
||||
if (method.isEmpty()) return false;
|
||||
PIVector<__EHFunc> ml = findEH(method);
|
||||
piForeachC (__EHFunc & m, ml) {
|
||||
if (!m.names.isEmpty()) continue;
|
||||
((void(*)(void*))m.addr)(this);
|
||||
return true;
|
||||
}
|
||||
piCoutObj << "Error: can`t find event or handler \"" << (method + "()") << "\" to execute!";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool PIObject::isPIObject(const PIObject * o) {
|
||||
if (!o) return false;
|
||||
return o->_signature_ == __PIOBJECT_SIGNATURE__;
|
||||
@@ -463,7 +518,7 @@ void PIObject::dump(const PIString & line_prefix) const {
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << p.first << ": " << p.second;
|
||||
//printf("dump %d properties ok\n", properties_.size());
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " }";
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " methodsEH {";
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " methods {";
|
||||
__MetaData & ehd(__meta_data()[className()]);
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << ehd.eh_func.size_s();
|
||||
//printf("dump %d methods\n", ehd.eh_func.size());
|
||||
@@ -477,8 +532,8 @@ void PIObject::dump(const PIString & line_prefix) const {
|
||||
//printf("dump %d connections\n",connections.size());
|
||||
piForeachC (Connection & c, connections) {
|
||||
PIObject * dst = c.dest_o;
|
||||
__EHFunc hf = dst->methodEH(c.slot);
|
||||
__EHFunc ef = methodEH(c.signal);
|
||||
__MetaFunc hf = dst->methodEH(c.slot);
|
||||
__MetaFunc ef = methodEH(c.signal);
|
||||
if (hf.func_name.isEmpty()) hf.func_name = "[BROKEN]";
|
||||
else hf.func_name += "(" + hf.arguments() + ")";
|
||||
PIString src(c.event);
|
||||
@@ -500,12 +555,15 @@ void dumpApplication() {
|
||||
PISystemInfo * pi = PISystemInfo::instance();
|
||||
PICout(PICoutManipulators::AddNewLine) << "application {";
|
||||
PICout(PICoutManipulators::AddNewLine) << " PIP version: " << PIPVersion();
|
||||
PICout(PICoutManipulators::AddNewLine) << " OS name: \"" << pi->OS_name << "\"";
|
||||
PICout(PICoutManipulators::AddNewLine) << " OS version: \"" << pi->OS_version << "\"";
|
||||
PICout(PICoutManipulators::AddNewLine) << " processors: " << pi->processorsCount;
|
||||
PICout(PICoutManipulators::AddNewLine) << " architecture: \"" << pi->architecture << "\"";
|
||||
PICout(PICoutManipulators::AddNewLine) << " hostname: \"" << pi->hostname << "\"";
|
||||
PICout(PICoutManipulators::AddNewLine) << " user: \"" << pi->user << "\"";
|
||||
PICout(PICoutManipulators::AddNewLine) << " username: \"" << pi->user << "\"";
|
||||
PICout(PICoutManipulators::AddNewLine) << " exec command: \"" << pi->execCommand << "\"";
|
||||
PICout(PICoutManipulators::AddNewLine) << " started: " << pi->execDateTime.toString();
|
||||
PICout(PICoutManipulators::AddNewLine) << " uptime, s: " << (cd.toSystemTime() - pi->execDateTime.toSystemTime()).toSeconds();
|
||||
PICout(PICoutManipulators::AddNewLine) << " uptime: " << PITime::fromSystemTime(cd.toSystemTime() - pi->execDateTime.toSystemTime()).toString();
|
||||
PICout(PICoutManipulators::AddNewLine) << " PIObjects {";
|
||||
PICout(PICoutManipulators::AddNewLine) << " count: " << PIObject::objects().size_s();
|
||||
piForeachC (PIObject * o, PIObject::objects())
|
||||
|
||||
@@ -234,7 +234,7 @@
|
||||
void * fpV = fp; \
|
||||
if (eh.eh_set[fp]) return; \
|
||||
eh.eh_set << fp; \
|
||||
__EHFunc & f(eh.eh_func[fp]); \
|
||||
__MetaFunc & f(eh.eh_func[fp]); \
|
||||
f.scope = __classNameS(); \
|
||||
f.func_name = PIStringAscii(#name); \
|
||||
f.addr = fp; \
|
||||
@@ -254,7 +254,7 @@
|
||||
void * fpV = (void*)(ret(*)(void*, const PIVariant &))__stat_eh_v_##name##__; \
|
||||
if (eh.eh_set[fp]) return; \
|
||||
eh.eh_set << fp; \
|
||||
__EHFunc & f(eh.eh_func[fp]); \
|
||||
__MetaFunc & f(eh.eh_func[fp]); \
|
||||
f.scope = __classNameS(); \
|
||||
f.func_name = PIStringAscii(#name); \
|
||||
f.addr = fp; \
|
||||
@@ -276,7 +276,7 @@
|
||||
void * fpV = (void*)(ret(*)(void*, const PIVariant &, const PIVariant &))__stat_eh_v_##name##__; \
|
||||
if (eh.eh_set[fp]) return; \
|
||||
eh.eh_set << fp; \
|
||||
__EHFunc & f(eh.eh_func[fp]); \
|
||||
__MetaFunc & f(eh.eh_func[fp]); \
|
||||
f.scope = __classNameS(); \
|
||||
f.func_name = PIStringAscii(#name); \
|
||||
f.addr = fp; \
|
||||
@@ -298,7 +298,7 @@
|
||||
void * fpV = (void*)(ret(*)(void*, const PIVariant &, const PIVariant &, const PIVariant &))__stat_eh_v_##name##__; \
|
||||
if (eh.eh_set[fp]) return; \
|
||||
eh.eh_set << fp; \
|
||||
__EHFunc & f(eh.eh_func[fp]); \
|
||||
__MetaFunc & f(eh.eh_func[fp]); \
|
||||
f.scope = __classNameS(); \
|
||||
f.func_name = PIStringAscii(#name); \
|
||||
f.addr = fp; \
|
||||
@@ -320,7 +320,7 @@
|
||||
void * fpV = (void*)(ret(*)(void*, const PIVariant &, const PIVariant &, const PIVariant &, const PIVariant &))__stat_eh_v_##name##__; \
|
||||
if (eh.eh_set[fp]) return; \
|
||||
eh.eh_set << fp; \
|
||||
__EHFunc & f(eh.eh_func[fp]); \
|
||||
__MetaFunc & f(eh.eh_func[fp]); \
|
||||
f.scope = __classNameS(); \
|
||||
f.func_name = PIStringAscii(#name); \
|
||||
f.addr = fp; \
|
||||
@@ -522,7 +522,35 @@ public:
|
||||
|
||||
void setThreadSafe(bool yes) {thread_safe_ = yes;}
|
||||
bool isThreadSafe() const {return thread_safe_;}
|
||||
|
||||
|
||||
bool execute(const PIString & method, const PIVector<PIVariant> & vl);
|
||||
bool execute(const PIString & method) {return execute(method, PIVector<PIVariant>());}
|
||||
bool execute(const PIString & method, const PIVariant & v0) {return execute(method, PIVector<PIVariant>() << v0);}
|
||||
bool execute(const PIString & method, const PIVariant & v0, const PIVariant & v1) {return execute(method, PIVector<PIVariant>() << v0 << v1);}
|
||||
bool execute(const PIString & method, const PIVariant & v0, const PIVariant & v1, const PIVariant & v2) {return execute(method, PIVector<PIVariant>() << v0 << v1 << v2);}
|
||||
bool execute(const PIString & method, const PIVariant & v0, const PIVariant & v1, const PIVariant & v2, const PIVariant & v3) {return execute(method, PIVector<PIVariant>() << v0 << v1 << v2 << v3);}
|
||||
|
||||
bool executeQueued(PIObject * performer, const PIString & method, const PIVector<PIVariant> & vl);
|
||||
bool executeQueued(PIObject * performer, const PIString & method) {return executeQueued(performer, method, PIVector<PIVariant>());}
|
||||
bool executeQueued(PIObject * performer, const PIString & method, const PIVariant & v0) {return executeQueued(performer, method, PIVector<PIVariant>() << v0);}
|
||||
bool executeQueued(PIObject * performer, const PIString & method, const PIVariant & v0, const PIVariant & v1) {return executeQueued(performer, method, PIVector<PIVariant>() << v0 << v1);}
|
||||
bool executeQueued(PIObject * performer, const PIString & method, const PIVariant & v0, const PIVariant & v1, const PIVariant & v2) {return executeQueued(performer, method, PIVector<PIVariant>() << v0 << v1 << v2);}
|
||||
bool executeQueued(PIObject * performer, const PIString & method, const PIVariant & v0, const PIVariant & v1, const PIVariant & v2, const PIVariant & v3) {return executeQueued(performer, method, PIVector<PIVariant>() << v0 << v1 << v2 << v3);}
|
||||
|
||||
static bool execute(PIObject * o, const PIString & method, const PIVector<PIVariant> & vl) {return o->execute(method, vl);}
|
||||
static bool execute(PIObject * o, const PIString & method) {return execute(o, method, PIVector<PIVariant>());}
|
||||
static bool execute(PIObject * o, const PIString & method, const PIVariant & v0) {return execute(o, method, PIVector<PIVariant>() << v0);}
|
||||
static bool execute(PIObject * o, const PIString & method, const PIVariant & v0, const PIVariant & v1) {return execute(o, method, PIVector<PIVariant>() << v0 << v1);}
|
||||
static bool execute(PIObject * o, const PIString & method, const PIVariant & v0, const PIVariant & v1, const PIVariant & v2) {return execute(o, method, PIVector<PIVariant>() << v0 << v1 << v2);}
|
||||
static bool execute(PIObject * o, const PIString & method, const PIVariant & v0, const PIVariant & v1, const PIVariant & v2, const PIVariant & v3) {return execute(o, method, PIVector<PIVariant>() << v0 << v1 << v2 << v3);}
|
||||
|
||||
static bool executeQueued(PIObject * o, PIObject * performer, const PIString & method, const PIVector<PIVariant> & vl) {return o->executeQueued(performer, method, vl);}
|
||||
static bool executeQueued(PIObject * o, PIObject * performer, const PIString & method) {return executeQueued(o, performer, method, PIVector<PIVariant>());}
|
||||
static bool executeQueued(PIObject * o, PIObject * performer, const PIString & method, const PIVariant & v0) {return executeQueued(o, performer, method, PIVector<PIVariant>() << v0);}
|
||||
static bool executeQueued(PIObject * o, PIObject * performer, const PIString & method, const PIVariant & v0, const PIVariant & v1) {return executeQueued(o, performer, method, PIVector<PIVariant>() << v0 << v1);}
|
||||
static bool executeQueued(PIObject * o, PIObject * performer, const PIString & method, const PIVariant & v0, const PIVariant & v1, const PIVariant & v2) {return executeQueued(o, performer, method, PIVector<PIVariant>() << v0 << v1 << v2);}
|
||||
static bool executeQueued(PIObject * o, PIObject * performer, const PIString & method, const PIVariant & v0, const PIVariant & v1, const PIVariant & v2, const PIVariant & v3) {return executeQueued(o, performer, method, PIVector<PIVariant>() << v0 << v1 << v2 << v3);}
|
||||
|
||||
void dump(const PIString & line_prefix = PIString()) const;
|
||||
|
||||
|
||||
@@ -760,7 +788,6 @@ public:
|
||||
if (!isTypeOf<T>()) return (T*)0;
|
||||
return (T*)this;
|
||||
}
|
||||
bool execute(const PIString & method);
|
||||
|
||||
static bool isPIObject(const PIObject * o);
|
||||
static bool isPIObject(const void * o) {return isPIObject((PIObject*)o);}
|
||||
@@ -768,12 +795,10 @@ public:
|
||||
static bool isTypeOf(const PIObject * o) {return o->isTypeOf<T>();}
|
||||
template<typename T>
|
||||
static bool isTypeOf(const void * o) {return isTypeOf<T>((PIObject*)o);}
|
||||
static bool execute(PIObject * o, const PIString & method) {return o->execute(method);}
|
||||
static bool execute(void * o, const PIString & method) {return ((PIObject*)o)->execute(method);}
|
||||
static PIString simplifyType(const char * a);
|
||||
|
||||
struct __EHFunc {
|
||||
__EHFunc(): addr(0), addrV(0) {;}
|
||||
struct __MetaFunc {
|
||||
__MetaFunc(): addr(0), addrV(0) {;}
|
||||
bool isNull() const {return addr == 0;}
|
||||
PIString arguments() const;
|
||||
PIString fullFormat() const;
|
||||
@@ -790,9 +815,9 @@ public:
|
||||
void addScope(const PIString & s) {if (!scope_list.contains(s)) scope_list << s;}
|
||||
PIStringList scope_list;
|
||||
PISet<const void * > eh_set;
|
||||
PIMap<const void * , __EHFunc> eh_func;
|
||||
PIMap<const void * , __MetaFunc> eh_func;
|
||||
};
|
||||
typedef PIPair<const void * , __EHFunc> __EHPair;
|
||||
typedef PIPair<const void * , __MetaFunc> __EHPair;
|
||||
|
||||
static PIMutex & __meta_mutex();
|
||||
static PIMap<PIString, __MetaData> & __meta_data(); // [classname]=__MetaData
|
||||
@@ -855,12 +880,14 @@ private:
|
||||
};
|
||||
typedef PIPair<PIString, PIVariant> Property;
|
||||
|
||||
PIVector<__EHFunc> findEH(const PIString & name) const;
|
||||
__EHFunc methodEH(const void * addr) const;
|
||||
bool findSuitableMethodV(const PIString & method, int args, int & ret_args, __MetaFunc & ret);
|
||||
PIVector<__MetaFunc> findEH(const PIString & name) const;
|
||||
__MetaFunc methodEH(const void * addr) const;
|
||||
void updateConnectors();
|
||||
void postQueuedEvent(const QueuedEvent & e);
|
||||
|
||||
static PIVector<PIObject * > & objects();
|
||||
static callAddrV(void * slot, void * obj, int args, const PIVector<PIVariant> & vl);
|
||||
|
||||
PIVector<Connection> connections;
|
||||
PIMap<PIString, PIVariant> properties_;
|
||||
|
||||
Reference in New Issue
Block a user