code format
This commit is contained in:
@@ -1,29 +1,30 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Object, base class of some PIP classes, provide EVENT -> EVENT_HANDLER mechanism
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Object, base class of some PIP classes, provide EVENT -> EVENT_HANDLER mechanism
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "piobject.h"
|
||||
#include "pithread.h"
|
||||
|
||||
#include "piconditionvar.h"
|
||||
#include "pithread.h"
|
||||
#ifndef MICRO_PIP
|
||||
# include "pisysteminfo.h"
|
||||
# include "pifile.h"
|
||||
# include "piiostream.h"
|
||||
# include "pisysteminfo.h"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -104,15 +105,14 @@
|
||||
PIObject::__MetaFunc::__MetaFunc() {
|
||||
for (int i = 0; i < __PIOBJECT_MAX_ARGS__; ++i) {
|
||||
types[i] = names[i] = nullptr;
|
||||
types_id[i] = 0;
|
||||
types_id[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int PIObject::__MetaFunc::argumentsCount() const {
|
||||
for (int i = 0; i < __PIOBJECT_MAX_ARGS__; ++i)
|
||||
if (!types[i])
|
||||
return i;
|
||||
if (!types[i]) return i;
|
||||
return __PIOBJECT_MAX_ARGS__;
|
||||
}
|
||||
|
||||
@@ -129,9 +129,7 @@ PIString PIObject::__MetaFunc::arguments() const {
|
||||
|
||||
|
||||
PIString PIObject::__MetaFunc::fullFormat() const {
|
||||
PIString ret = PIStringAscii(type_ret) + " " +
|
||||
PIStringAscii(scope) + "::" +
|
||||
PIStringAscii(func_name) +"(";
|
||||
PIString ret = PIStringAscii(type_ret) + " " + PIStringAscii(scope) + "::" + PIStringAscii(func_name) + "(";
|
||||
for (int i = 0; i < __PIOBJECT_MAX_ARGS__; ++i) {
|
||||
if (!types[i]) break;
|
||||
if (i > 0) ret += ", ";
|
||||
@@ -143,7 +141,7 @@ PIString PIObject::__MetaFunc::fullFormat() const {
|
||||
|
||||
|
||||
void PIObject::__MetaFunc::__setFuncName(const char * n) {
|
||||
func_name = n;
|
||||
func_name = n;
|
||||
func_name_id = PIStringAscii(n).hash();
|
||||
}
|
||||
|
||||
@@ -151,27 +149,25 @@ void PIObject::__MetaFunc::__setFuncName(const char * n) {
|
||||
void PIObject::__MetaFunc::__addArgument(const char * t, const char * n) {
|
||||
for (int i = 0; i < __PIOBJECT_MAX_ARGS__; ++i) {
|
||||
if (types[i]) continue;
|
||||
types[i] = t;
|
||||
names[i] = n;
|
||||
types[i] = t;
|
||||
names[i] = n;
|
||||
types_id[i] = PIObject::simplifyType(t, false).hash();
|
||||
break;
|
||||
}
|
||||
//PICout(PICoutManipulators::DefaultControls | PICoutManipulators::AddQuotes)
|
||||
// PICout(PICoutManipulators::DefaultControls | PICoutManipulators::AddQuotes)
|
||||
// << "__addArgument" << t << n << PIObject::simplifyType(t) << types_id.back();
|
||||
}
|
||||
|
||||
|
||||
bool PIObject::__MetaFunc::canConnectTo(const __MetaFunc & dst, int & args_count) const {
|
||||
for (int i = 0; i < __PIOBJECT_MAX_ARGS__; ++i) {
|
||||
//piCout << "canConnectTo" << i << types[i] << dst.types[i];
|
||||
// piCout << "canConnectTo" << i << types[i] << dst.types[i];
|
||||
args_count = i;
|
||||
if (!dst.types[i]) break;
|
||||
if (!types[i]) return false;
|
||||
if (types_id[i] != dst.types_id[i])
|
||||
return false;
|
||||
if (types_id[i] != dst.types_id[i]) return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -182,13 +178,13 @@ PIObject::PIObject(const PIString & name): _signature_(__PIOBJECT_SIGNATURE__),
|
||||
mutexObjects().lock();
|
||||
objects() << this;
|
||||
mutexObjects().unlock();
|
||||
//piCout << "new" << this;
|
||||
// piCout << "new" << this;
|
||||
}
|
||||
|
||||
|
||||
PIObject::~PIObject() {
|
||||
in_event_cnt = 0;
|
||||
//piCout << "delete" << this;
|
||||
// piCout << "delete" << this;
|
||||
mutexObjects().lock();
|
||||
objects().removeAll(this);
|
||||
mutexObjects().unlock();
|
||||
@@ -198,19 +194,16 @@ PIObject::~PIObject() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool PIObject::execute(const PIString & method, const PIVector<PIVariantSimple> & vl) {
|
||||
if (method.isEmpty()) return false;
|
||||
if (!isPIObject()) {
|
||||
piCout << "Error: \"execute(" << method << ")\":" << (void*)this << "is not PIObject!";
|
||||
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;
|
||||
if (!ok) return false;
|
||||
callAddrV(func.addrV, toThis(), ac, vl);
|
||||
return true;
|
||||
}
|
||||
@@ -218,18 +211,17 @@ bool PIObject::execute(const PIString & method, const PIVector<PIVariantSimple>
|
||||
|
||||
bool PIObject::executeQueued(PIObject * performer, const PIString & method, const PIVector<PIVariantSimple> & vl) {
|
||||
if (!isPIObject()) {
|
||||
piCout << "Error: \"executeQueued(" << method << ")\": this(" << (void*)this << ") is not PIObject!";
|
||||
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!";
|
||||
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;
|
||||
if (!ok) return false;
|
||||
performer->postQueuedEvent(__QueuedEvent(func.addrV, toThis(), this, performer, vl));
|
||||
performer->proc_event_queue = true;
|
||||
return true;
|
||||
@@ -262,8 +254,7 @@ bool PIObject::isMethodEHContains(const PIString & name) const {
|
||||
PIMutexLocker ml(__meta_mutex());
|
||||
const __MetaData & ehd(__meta_data()[classNameID()]);
|
||||
for (auto eh = ehd.eh_func.begin(); eh != ehd.eh_func.end(); eh++) {
|
||||
if (eh.value().func_name_id == search_id)
|
||||
return true;
|
||||
if (eh.value().func_name_id == search_id) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -274,8 +265,7 @@ PIString PIObject::methodEHArguments(const PIString & name) const {
|
||||
PIMutexLocker ml(__meta_mutex());
|
||||
const __MetaData & ehd(__meta_data()[classNameID()]);
|
||||
for (auto eh = ehd.eh_func.begin(); eh != ehd.eh_func.end(); eh++) {
|
||||
if (eh.value().func_name_id == search_id)
|
||||
return eh.value().arguments();
|
||||
if (eh.value().func_name_id == search_id) return eh.value().arguments();
|
||||
}
|
||||
return PIString();
|
||||
}
|
||||
@@ -286,8 +276,7 @@ PIString PIObject::methodEHFullFormat(const PIString & name) const {
|
||||
PIMutexLocker ml(__meta_mutex());
|
||||
const __MetaData & ehd(__meta_data()[classNameID()]);
|
||||
for (auto eh = ehd.eh_func.begin(); eh != ehd.eh_func.end(); eh++) {
|
||||
if (eh.value().func_name_id == search_id)
|
||||
return eh.value().fullFormat();
|
||||
if (eh.value().func_name_id == search_id) return eh.value().fullFormat();
|
||||
}
|
||||
return PIString();
|
||||
}
|
||||
@@ -303,8 +292,7 @@ PIVector<PIObject::__MetaFunc> PIObject::findEH(const PIString & name) const {
|
||||
PIVector<__MetaFunc> ret;
|
||||
const __MetaData & ehd(__meta_data()[classNameID()]);
|
||||
for (auto eh = ehd.eh_func.begin(); eh != ehd.eh_func.end(); eh++) {
|
||||
if (eh.value().func_name_id == search_id)
|
||||
ret << eh.value();
|
||||
if (eh.value().func_name_id == search_id) ret << eh.value();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -316,25 +304,38 @@ PIObject::__MetaFunc PIObject::methodEH(const void * addr) const {
|
||||
}
|
||||
|
||||
|
||||
PIObject::Connection PIObject::piConnect(PIObject * src, const PIString & sig, PIObject * dest_o, void * dest, void * ev_h, void * e_h, int args, const char * loc) {
|
||||
//piCout << "piConnect ...";
|
||||
//piCout << "piConnect" << src << (void*)(dest) << sig;
|
||||
//piCout << "piConnect" << src->className() << "->" << ((PIObject*)dest)->className();
|
||||
PIObject::Connection PIObject::piConnect(PIObject * src,
|
||||
const PIString & sig,
|
||||
PIObject * dest_o,
|
||||
void * dest,
|
||||
void * ev_h,
|
||||
void * e_h,
|
||||
int args,
|
||||
const char * loc) {
|
||||
// piCout << "piConnect ...";
|
||||
// piCout << "piConnect" << src << (void*)(dest) << sig;
|
||||
// piCout << "piConnect" << src->className() << "->" << ((PIObject*)dest)->className();
|
||||
PIMutexLocker _ml(src->mutex_connect);
|
||||
PIMutexLocker _mld(dest_o->mutex_connect, src != dest_o);
|
||||
|
||||
|
||||
Connection conn(ev_h, e_h, sig, src, dest_o, dest, args);
|
||||
src->connections << conn;
|
||||
//piCout << "piConnect" << ((PIObject*)dest) << sig << ((PIObject*)dest)->connectors.size_s() << "...";
|
||||
//piCout << "addConnector" << dest_o << src;
|
||||
// piCout << "piConnect" << ((PIObject*)dest) << sig << ((PIObject*)dest)->connectors.size_s() << "...";
|
||||
// piCout << "addConnector" << dest_o << src;
|
||||
dest_o->connectors << src;
|
||||
//piCout << "piConnect" << ((PIObject*)dest) << sig << ((PIObject*)dest)->connectors.size_s();
|
||||
//piCout << "piConnect ok";
|
||||
// piCout << "piConnect" << ((PIObject*)dest) << sig << ((PIObject*)dest)->connectors.size_s();
|
||||
// piCout << "piConnect ok";
|
||||
return conn;
|
||||
}
|
||||
|
||||
|
||||
PIObject::Connection PIObject::piConnectU(PIObject * src, const PIString & sig, PIObject * dest_o, void * dest, const PIString & hname, const char * loc, PIObject * performer) {
|
||||
PIObject::Connection PIObject::piConnectU(PIObject * src,
|
||||
const PIString & sig,
|
||||
PIObject * dest_o,
|
||||
void * dest,
|
||||
const PIString & hname,
|
||||
const char * loc,
|
||||
PIObject * performer) {
|
||||
if (src == 0 || dest_o == 0 || dest == 0) return Connection();
|
||||
if (!src->isPIObject()) {
|
||||
piCout << "[piConnectU] \"" << sig << "\" -> \"" << hname << "\" error: source object is not PIObject! (" << loc << ")";
|
||||
@@ -356,29 +357,29 @@ PIObject::Connection PIObject::piConnectU(PIObject * src, const PIString & sig,
|
||||
piCout << "[piConnectU] Error: can`t find handler \"" << hname << "\" in class \"" << dest_o->className() << "\"! (" << loc << ")";
|
||||
return Connection();
|
||||
}
|
||||
void * addr_src(0), * addr_dest(0);
|
||||
void *addr_src(0), *addr_dest(0);
|
||||
int args(0);
|
||||
bool que = (performer != 0);
|
||||
piForeachC (__MetaFunc & fs, m_src) {
|
||||
piForeachC(__MetaFunc & fs, m_src) {
|
||||
if (addr_src != 0) break;
|
||||
piForeachC (__MetaFunc & fd, m_dest) {
|
||||
piForeachC(__MetaFunc & fd, m_dest) {
|
||||
if (addr_src != 0) break;
|
||||
if (fs.canConnectTo(fd, args)) {
|
||||
addr_src = fs.addr;
|
||||
addr_src = fs.addr;
|
||||
addr_dest = que ? fd.addrV : fd.addr;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (addr_src == 0) {
|
||||
piCout << "[piConnectU] Error: can`t find suitable pair of event \"" << sig << "\" in class \"" << src->className()
|
||||
<< "\" and handler \"" << hname << "\" in class \"" << dest_o->className() << "\"! (" << loc << ")";
|
||||
<< "\" and handler \"" << hname << "\" in class \"" << dest_o->className() << "\"! (" << loc << ")";
|
||||
return Connection();
|
||||
}
|
||||
Connection conn(addr_dest, addr_src, sig, src, dest_o, dest, args, performer);
|
||||
src->connections << conn;
|
||||
if (que) performer->proc_event_queue = true;
|
||||
dest_o->connectors << src;
|
||||
//piCout << cc << cq << _ol.size();//"connect" << src << "->" << dest_o << ", dest.connectors.size() =" << dest_o->connectors.size();
|
||||
// piCout << cc << cq << _ol.size();//"connect" << src << "->" << dest_o << ", dest.connectors.size() =" << dest_o->connectors.size();
|
||||
return conn;
|
||||
}
|
||||
|
||||
@@ -395,7 +396,7 @@ PIObject::Connection PIObject::piConnectLS(PIObject * src, const PIString & sig,
|
||||
}
|
||||
PIMutexLocker ml(__meta_mutex());
|
||||
PIMutexLocker mls(src->mutex_connect);
|
||||
//piCout << "locked";
|
||||
// piCout << "locked";
|
||||
PIVector<__MetaFunc> m_src = src->findEH(sig);
|
||||
if (m_src.isEmpty()) {
|
||||
piCout << "[piConnectLS] Error: can`t find event \"" << sig << "\" in class \"" << src->className() << "\"! (" << loc << ")";
|
||||
@@ -403,15 +404,16 @@ PIObject::Connection PIObject::piConnectLS(PIObject * src, const PIString & sig,
|
||||
return Connection();
|
||||
}
|
||||
if (m_src.size() != 1) {
|
||||
piCout << "[piConnectLS] Error: can`t connect overloaded event \"" << sig << "\" in class \"" << src->className() << "\"! (" << loc << ")";
|
||||
piCout << "[piConnectLS] Error: can`t connect overloaded event \"" << sig << "\" in class \"" << src->className() << "\"! (" << loc
|
||||
<< ")";
|
||||
delete f;
|
||||
return Connection();
|
||||
}
|
||||
PIObject::Connection conn(0, m_src[0].addr, sig, src);
|
||||
//piCout << "found";
|
||||
// piCout << "found";
|
||||
conn.functor = f;
|
||||
src->connections << conn;
|
||||
//piCout << "finished";
|
||||
// piCout << "finished";
|
||||
return conn;
|
||||
}
|
||||
|
||||
@@ -468,10 +470,10 @@ void PIObject::piDisconnect(PIObject * src, const PIString & sig) {
|
||||
|
||||
void PIObject::piDisconnectAll() {
|
||||
PIMutexLocker _ml(mutex_connect);
|
||||
PIVector<PIObject * > cv = connectors.toVector();
|
||||
// piCout << "disconnect connectors =" << connectors.size();
|
||||
piForeach (PIObject * o, cv) {
|
||||
// piCout << "disconnect"<< src << o;
|
||||
PIVector<PIObject *> cv = connectors.toVector();
|
||||
// piCout << "disconnect connectors =" << connectors.size();
|
||||
piForeach(PIObject * o, cv) {
|
||||
// piCout << "disconnect"<< src << o;
|
||||
if (!o || (o == this)) continue;
|
||||
if (!o->isPIObject()) continue;
|
||||
#if !defined(ANDROID) && !defined(MAC_OS) && !defined(MICRO_PIP)
|
||||
@@ -480,7 +482,7 @@ void PIObject::piDisconnectAll() {
|
||||
PIVector<Connection> & oc(o->connections);
|
||||
for (int i = 0; i < oc.size_s(); ++i) {
|
||||
if (oc[i].functor) continue;
|
||||
//piCout << " check" << (void*)(oc[i].dest_o) << "==" << (void*)(src);
|
||||
// piCout << " check" << (void*)(oc[i].dest_o) << "==" << (void*)(src);
|
||||
if (oc[i].dest_o == this) {
|
||||
oc[i].destroy();
|
||||
oc.remove(i);
|
||||
@@ -488,8 +490,8 @@ void PIObject::piDisconnectAll() {
|
||||
}
|
||||
}
|
||||
}
|
||||
// piCout << "disconnect connections =" << connections.size();
|
||||
piForeachC (PIObject::Connection & c, connections) {
|
||||
// piCout << "disconnect connections =" << connections.size();
|
||||
piForeachC(PIObject::Connection & c, connections) {
|
||||
if (c.functor) continue;
|
||||
if (!c.dest_o) continue;
|
||||
if (!c.dest_o->isPIObject()) continue;
|
||||
@@ -502,15 +504,14 @@ void PIObject::piDisconnectAll() {
|
||||
|
||||
|
||||
void PIObject::updateConnectors() {
|
||||
//piCout << "*** updateConnectors" << this;
|
||||
// piCout << "*** updateConnectors" << this;
|
||||
connectors.clear();
|
||||
PIMutexLocker _ml(mutexObjects());
|
||||
piForeach (PIObject * o, objects()) {
|
||||
piForeach(PIObject * o, objects()) {
|
||||
if (o == this) continue;
|
||||
PIVector<Connection> & oc(o->connections);
|
||||
piForeach (Connection & c, oc)
|
||||
if (c.dest == this)
|
||||
connectors << o;
|
||||
piForeach(Connection & c, oc)
|
||||
if (c.dest == this) connectors << o;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -523,8 +524,8 @@ void PIObject::postQueuedEvent(const PIObject::__QueuedEvent & e) {
|
||||
|
||||
|
||||
void * PIObject::toThis() const {
|
||||
//piCout << ptrOffset() << (void*)this << (void*)((char*)this - ptrOffset());
|
||||
return (void*)((char*)this - ptrOffset());
|
||||
// piCout << ptrOffset() << (void*)this << (void*)((char*)this - ptrOffset());
|
||||
return (void *)((char *)this - ptrOffset());
|
||||
}
|
||||
|
||||
|
||||
@@ -545,7 +546,7 @@ void PIObject::callQueuedEvents() {
|
||||
PIVector<__QueuedEvent> qe = events_queue;
|
||||
events_queue.clear();
|
||||
mutex_queue.unlock();
|
||||
piForeachC (__QueuedEvent & e, qe) {
|
||||
piForeachC(__QueuedEvent & e, qe) {
|
||||
if (e.dest_o->thread_safe_) e.dest_o->mutex_.lock();
|
||||
e.dest_o->emitter_ = e.src;
|
||||
callAddrV(e.slot, e.dest, e.values.size_s(), e.values);
|
||||
@@ -580,7 +581,7 @@ bool PIObject::findSuitableMethodV(const PIString & method, int args, int & ret_
|
||||
int j = m.argumentsCount();
|
||||
if (mac < 0 || mac > j) mac = j;
|
||||
if ((j <= args) && (ac < j)) {
|
||||
ac = j;
|
||||
ac = j;
|
||||
mfi = i;
|
||||
}
|
||||
}
|
||||
@@ -589,13 +590,13 @@ bool PIObject::findSuitableMethodV(const PIString & method, int args, int & ret_
|
||||
return false;
|
||||
}
|
||||
ret_args = ac;
|
||||
ret = ml[mfi];
|
||||
ret = ml[mfi];
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
PIVector<PIObject * > & PIObject::objects() {
|
||||
static PIVector<PIObject * > * ret = new PIVector<PIObject * >();
|
||||
PIVector<PIObject *> & PIObject::objects() {
|
||||
static PIVector<PIObject *> * ret = new PIVector<PIObject *>();
|
||||
return *ret;
|
||||
}
|
||||
|
||||
@@ -609,11 +610,16 @@ PIMutex & PIObject::mutexObjects() {
|
||||
void PIObject::callAddrV(void * slot, void * obj, int args, const PIVector<PIVariantSimple> & vl) {
|
||||
args = piMini(args, vl.size_s());
|
||||
switch (args) {
|
||||
case 0: ((void(*)(void *))slot)(obj); break;
|
||||
case 1: ((void(*)(void * , const PIVariantSimple & ))slot)(obj, vl[0]); break;
|
||||
case 2: ((void(*)(void * , const PIVariantSimple & , const PIVariantSimple & ))slot)(obj, vl[0], vl[1]); break;
|
||||
case 3: ((void(*)(void * , const PIVariantSimple & , const PIVariantSimple & , const PIVariantSimple & ))slot)(obj, vl[0], vl[1], vl[2]); break;
|
||||
case 4: ((void(*)(void * , const PIVariantSimple & , const PIVariantSimple & , const PIVariantSimple & , const PIVariantSimple & ))slot)(obj, vl[0], vl[1], vl[2], vl[3]); break;
|
||||
case 0: ((void (*)(void *))slot)(obj); break;
|
||||
case 1: ((void (*)(void *, const PIVariantSimple &))slot)(obj, vl[0]); break;
|
||||
case 2: ((void (*)(void *, const PIVariantSimple &, const PIVariantSimple &))slot)(obj, vl[0], vl[1]); break;
|
||||
case 3:
|
||||
((void (*)(void *, const PIVariantSimple &, const PIVariantSimple &, const PIVariantSimple &))slot)(obj, vl[0], vl[1], vl[2]);
|
||||
break;
|
||||
case 4:
|
||||
((void (*)(void *, const PIVariantSimple &, const PIVariantSimple &, const PIVariantSimple &, const PIVariantSimple &))
|
||||
slot)(obj, vl[0], vl[1], vl[2], vl[3]);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@@ -625,7 +631,7 @@ PIString PIObject::simplifyType(const char * a, bool readable) {
|
||||
int white = -1;
|
||||
for (int i = 0; i < ret.size_s(); ++i) {
|
||||
bool iw = ret[i] == ' ' || ret[i] == '\t' || ret[i] == '\r' || ret[i] == '\n';
|
||||
//piCout << i << iw << white;
|
||||
// piCout << i << iw << white;
|
||||
if (white < 0) {
|
||||
if (iw) {
|
||||
white = i;
|
||||
@@ -634,9 +640,9 @@ PIString PIObject::simplifyType(const char * a, bool readable) {
|
||||
} else {
|
||||
if (!iw) {
|
||||
ret.replace(white, i - white, " ");
|
||||
i = white;
|
||||
i = white;
|
||||
white = -1;
|
||||
//piCout << i;
|
||||
// piCout << i;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -652,11 +658,9 @@ PIString PIObject::simplifyType(const char * a, bool readable) {
|
||||
ret.replaceAll("> ", '>');
|
||||
ret.replaceAll("& ", '&');
|
||||
ret.replaceAll("* ", '*');
|
||||
if (ret.startsWith("const ") && ret.endsWith("&"))
|
||||
ret.cutLeft(6).cutRight(1).trim();
|
||||
if (ret.startsWith("const ") && ret.endsWith("&")) ret.cutLeft(6).cutRight(1).trim();
|
||||
} else {
|
||||
if (ret.startsWith("const ") && ret.endsWith("&"))
|
||||
ret.cutLeft(6).cutRight(1).trim();
|
||||
if (ret.startsWith("const ") && ret.endsWith("&")) ret.cutLeft(6).cutRight(1).trim();
|
||||
ret.removeAll(' ').removeAll('\t').removeAll('\r').removeAll('\n');
|
||||
}
|
||||
return ret;
|
||||
@@ -670,49 +674,53 @@ bool PIObject::isPIObject(const PIObject * o) {
|
||||
|
||||
|
||||
void PIObject::dump(const PIString & line_prefix) const {
|
||||
//printf("dump %s \"%s\"\n", className(), name().data());
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << "class " << className() << " (" << (const void*)this << ", \"" << name() << "\") {";
|
||||
// printf("dump %s \"%s\"\n", className(), name().data());
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << "class " << className() << " (" << (const void *)this << ", \"" << name()
|
||||
<< "\") {";
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " scope: " << scopeList().join(" -> ");
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " properties {";
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << properties_.size_s();
|
||||
//printf("dump %d properties\n", properties_.size());
|
||||
// printf("dump %d properties\n", properties_.size());
|
||||
const char * o_name = "name";
|
||||
auto it = properties_.makeIterator();
|
||||
auto it = properties_.makeIterator();
|
||||
while (it.next()) {
|
||||
if (it.key() != piHashData((const uchar *)o_name, strlen(o_name)))
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << it.key() << ": " << it.value();
|
||||
}
|
||||
//printf("dump %d properties ok\n", properties_.size());
|
||||
// printf("dump %d properties ok\n", properties_.size());
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " }";
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " methods {";
|
||||
const __MetaData & ehd(__meta_data()[classNameID()]);
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << ehd.eh_func.size_s();
|
||||
//printf("dump %d methods\n", ehd.eh_func.size());
|
||||
// printf("dump %d methods\n", ehd.eh_func.size());
|
||||
for (auto eh = ehd.eh_func.begin(); eh != ehd.eh_func.end(); eh++) {
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << eh.value().fullFormat();
|
||||
}
|
||||
//printf("dump %d methods ok\n", ehd.eh_func.size());
|
||||
// printf("dump %d methods ok\n", ehd.eh_func.size());
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " }";
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " connections {";
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " count: " << connections.size_s();
|
||||
//printf("dump %d connections\n",connections.size());
|
||||
for (const Connection & c : connections) {
|
||||
// printf("dump %d connections\n",connections.size());
|
||||
for (const Connection & c: connections) {
|
||||
PIObject * dst = c.dest_o;
|
||||
__MetaFunc ef = methodEH(c.signal);
|
||||
__MetaFunc ef = methodEH(c.signal);
|
||||
PIString src(c.event);
|
||||
if (ef.func_name)
|
||||
src = PIStringAscii(ef.func_name) + "(" + ef.arguments() + ")";
|
||||
if (ef.func_name) src = PIStringAscii(ef.func_name) + "(" + ef.arguments() + ")";
|
||||
if (dst) {
|
||||
__MetaFunc hf = dst->methodEH(c.slot);
|
||||
PIString hf_fn;
|
||||
if (!hf.func_name) hf_fn = "[BROKEN]";
|
||||
else hf_fn = PIStringAscii(hf.func_name) + "(" + hf.arguments() + ")";
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << src << " -> " << dst->className() << " (" << c.dest << ", \"" << dst->name() << "\")::" << hf_fn;
|
||||
if (!hf.func_name)
|
||||
hf_fn = "[BROKEN]";
|
||||
else
|
||||
hf_fn = PIStringAscii(hf.func_name) + "(" + hf.arguments() + ")";
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << src << " -> " << dst->className() << " (" << c.dest
|
||||
<< ", \"" << dst->name() << "\")::" << hf_fn;
|
||||
} else {
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << src << " -> " << "[lambda]";
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " " << src << " -> "
|
||||
<< "[lambda]";
|
||||
}
|
||||
}
|
||||
//printf("dump %d connections ok\n",connections.size());
|
||||
// printf("dump %d connections ok\n",connections.size());
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << " }";
|
||||
PICout(PICoutManipulators::AddNewLine) << line_prefix << "}";
|
||||
}
|
||||
@@ -721,8 +729,8 @@ void PIObject::dump(const PIString & line_prefix) const {
|
||||
#ifndef MICRO_PIP
|
||||
void dumpApplication(bool with_objects) {
|
||||
PIMutexLocker _ml(PIObject::mutexObjects());
|
||||
//printf("dump application ...\n");
|
||||
PIDateTime cd = PIDateTime::current();
|
||||
// printf("dump application ...\n");
|
||||
PIDateTime cd = PIDateTime::current();
|
||||
PISystemInfo * pi = PISystemInfo::instance();
|
||||
PICout(PICoutManipulators::AddNewLine) << "application {";
|
||||
PICout(PICoutManipulators::AddNewLine) << " PIP version: " << PIPVersion();
|
||||
@@ -734,7 +742,8 @@ void dumpApplication(bool with_objects) {
|
||||
PICout(PICoutManipulators::AddNewLine) << " username: \"" << pi->user << "\"";
|
||||
PICout(PICoutManipulators::AddNewLine) << " exec command: \"" << pi->execCommand << "\"";
|
||||
PICout(PICoutManipulators::AddNewLine) << " started: " << pi->execDateTime.toString();
|
||||
PICout(PICoutManipulators::AddNewLine) << " uptime: " << PITime::fromSystemTime(cd.toSystemTime() - pi->execDateTime.toSystemTime()).toString();
|
||||
PICout(PICoutManipulators::AddNewLine) << " uptime: "
|
||||
<< PITime::fromSystemTime(cd.toSystemTime() - pi->execDateTime.toSystemTime()).toString();
|
||||
PICout(PICoutManipulators::AddNewLine) << " PIObjects {";
|
||||
PICout(PICoutManipulators::AddNewLine) << " count: " << PIObject::objects().size_s();
|
||||
if (with_objects) {
|
||||
@@ -743,7 +752,7 @@ void dumpApplication(bool with_objects) {
|
||||
}
|
||||
PICout(PICoutManipulators::AddNewLine) << " }";
|
||||
PICout(PICoutManipulators::AddNewLine) << "}";
|
||||
//printf("dump application done\n");
|
||||
// printf("dump application done\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -774,8 +783,6 @@ void PIObject::__MetaData::addScope(const char * s, uint shash) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void PIObject::Connection::destroy() {
|
||||
if (functor) delete functor;
|
||||
functor = nullptr;
|
||||
@@ -785,9 +792,9 @@ void PIObject::Connection::destroy() {
|
||||
PIObject::Connection::Connection() {
|
||||
slot = signal = dest = nullptr;
|
||||
src_o = dest_o = performer = nullptr;
|
||||
functor = nullptr;
|
||||
eventID = 0;
|
||||
args_count = 0;
|
||||
functor = nullptr;
|
||||
eventID = 0;
|
||||
args_count = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -804,11 +811,9 @@ bool PIObject::Connection::disconnect() {
|
||||
Connection & cc(src_o->connections[i]);
|
||||
if (cc.eventID == eventID) {
|
||||
if (dest_o && (cc.dest_o == dest_o)) {
|
||||
if (cc.slot == slot)
|
||||
found = true;
|
||||
if (cc.slot == slot) found = true;
|
||||
}
|
||||
if (functor && (cc.functor == functor))
|
||||
found = true;
|
||||
if (functor && (cc.functor == functor)) found = true;
|
||||
}
|
||||
if (found) {
|
||||
src_o->connections[i].destroy();
|
||||
@@ -818,44 +823,43 @@ bool PIObject::Connection::disconnect() {
|
||||
}
|
||||
}
|
||||
if (dest_o) {
|
||||
if (dest_o->isPIObject())
|
||||
dest_o->updateConnectors();
|
||||
if (dest_o->isPIObject()) dest_o->updateConnectors();
|
||||
}
|
||||
if (ndm) dest_o->mutex_connect.unlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
PRIVATE_DEFINITION_START(PIObject::Deleter)
|
||||
PIThread thread;
|
||||
PIConditionVariable cond_var;
|
||||
PIVector<PIObject*> obj_queue;
|
||||
PIVector<PIObject *> obj_queue;
|
||||
PRIVATE_DEFINITION_END(PIObject::Deleter)
|
||||
|
||||
|
||||
PIObject::Deleter::Deleter() {
|
||||
//piCout << "Deleter start ...";
|
||||
PRIVATE->thread.setSlot([this](){
|
||||
PIVector<PIObject*> oq;
|
||||
// piCout << "Deleter start ...";
|
||||
PRIVATE->thread.setSlot([this]() {
|
||||
PIVector<PIObject *> oq;
|
||||
PRIVATE->thread.lock();
|
||||
if (PRIVATE->obj_queue.isEmpty()) PRIVATE->cond_var.wait(PRIVATE->thread.mutex());
|
||||
oq.swap(PRIVATE->obj_queue);
|
||||
PRIVATE->thread.unlock();
|
||||
for (PIObject * o : oq) deleteObject(o);
|
||||
for (PIObject * o: oq)
|
||||
deleteObject(o);
|
||||
});
|
||||
PRIVATE->thread.start();
|
||||
}
|
||||
|
||||
|
||||
PIObject::Deleter::~Deleter() {
|
||||
//piCout << "~Deleter ...";
|
||||
// piCout << "~Deleter ...";
|
||||
PRIVATE->thread.stop();
|
||||
PRIVATE->cond_var.notifyAll();
|
||||
PRIVATE->thread.waitForFinish();
|
||||
for (PIObject * o : PRIVATE->obj_queue) deleteObject(o);
|
||||
//piCout << "~Deleter ok";
|
||||
for (PIObject * o: PRIVATE->obj_queue)
|
||||
deleteObject(o);
|
||||
// piCout << "~Deleter ok";
|
||||
}
|
||||
|
||||
|
||||
@@ -867,24 +871,25 @@ PIObject::Deleter * PIObject::Deleter::instance() {
|
||||
|
||||
void PIObject::Deleter::post(PIObject * o) {
|
||||
if (!o->isPIObject()) return;
|
||||
//piCout << "[Deleter] post" << o << "...";
|
||||
// piCout << "[Deleter] post" << o << "...";
|
||||
PRIVATE->thread.lock();
|
||||
if (!PRIVATE->obj_queue.contains(o)) {
|
||||
PRIVATE->obj_queue << o;
|
||||
PRIVATE->cond_var.notifyAll();
|
||||
}
|
||||
PRIVATE->thread.unlock();
|
||||
//piCout << "[Deleter] post" << o << "done";
|
||||
// piCout << "[Deleter] post" << o << "done";
|
||||
}
|
||||
|
||||
|
||||
void PIObject::Deleter::deleteObject(PIObject * o) {
|
||||
//piCout << "[Deleter] delete" << (uintptr_t)o << "...";
|
||||
// piCout << "[Deleter] delete" << (uintptr_t)o << "...";
|
||||
if (o->isPIObject()) {
|
||||
//piCout << "[Deleter] delete" << (uintptr_t)o << "wait atomic ...";
|
||||
while (o->isInEvent()) piMinSleep();
|
||||
//piCout << "[Deleter] delete" << (uintptr_t)o << "wait atomic done";
|
||||
// piCout << "[Deleter] delete" << (uintptr_t)o << "wait atomic ...";
|
||||
while (o->isInEvent())
|
||||
piMinSleep();
|
||||
// piCout << "[Deleter] delete" << (uintptr_t)o << "wait atomic done";
|
||||
delete o;
|
||||
}
|
||||
//piCout << "[Deleter] delete" << (uintptr_t)o << "done";
|
||||
// piCout << "[Deleter] delete" << (uintptr_t)o << "done";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user