git-svn-id: svn://db.shs.com.ru/pip@478 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
144
main.cpp
144
main.cpp
@@ -32,141 +32,33 @@ const char pult_config[] =
|
|||||||
";
|
";
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <typeinfo>
|
|
||||||
|
|
||||||
template<typename T>
|
class A: public PIObject {
|
||||||
struct Info {
|
PIOBJECT(A)
|
||||||
enum {Defined = 0};
|
|
||||||
};
|
|
||||||
template<typename T>
|
|
||||||
struct TypeInfo {
|
|
||||||
typedef T PureType;
|
|
||||||
typedef const T ConstPureType;
|
|
||||||
typedef T * PointerType;
|
|
||||||
typedef const T * ConstPointerType;
|
|
||||||
typedef T & ReferenceType;
|
|
||||||
typedef const T & ConstReferenceType;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define TYPEINFO_SINGLE(PT, T) \
|
|
||||||
template<> struct TypeInfo<T> { \
|
|
||||||
typedef PT PureType; \
|
|
||||||
typedef const PT ConstPureType; \
|
|
||||||
typedef PT * PointerType; \
|
|
||||||
typedef const PT * ConstPointerType; \
|
|
||||||
typedef PT & ReferenceType; \
|
|
||||||
typedef const PT & ConstReferenceType; \
|
|
||||||
};
|
|
||||||
#define TYPEINFO(T) \
|
|
||||||
TYPEINFO_SINGLE(T, T &) \
|
|
||||||
TYPEINFO_SINGLE(T, const T) \
|
|
||||||
TYPEINFO_SINGLE(T, const T &) \
|
|
||||||
TYPEINFO_SINGLE(T, T *) \
|
|
||||||
TYPEINFO_SINGLE(T, const T *)
|
|
||||||
|
|
||||||
TYPEINFO(PIString)
|
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
class A {
|
|
||||||
public:
|
public:
|
||||||
void f() {
|
EVENT1(ev1, float, f)
|
||||||
piCout << "T";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
class B: public PIObject {
|
||||||
class A<const T&> {
|
PIOBJECT(B)
|
||||||
public:
|
public:
|
||||||
void f() {
|
EVENT_HANDLER0(void, eh0) {piCout << "eh0";}
|
||||||
piCout << "const T&";
|
EVENT_HANDLER1(void, eh1, float, f) {piCout << "eh1" << f;}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#include "pivector2d.h"
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
/*
|
A a;
|
||||||
enum VCO_Aim_Type {VCO_Aim_Type_None, VCO_Aim_Type_Detected, VCO_Aim_Type_New, VCO_Aim_Type_Confirmed, VCO_Aim_Type_Deleted = 127};
|
B b;
|
||||||
#pragma pack (push, 1)
|
CONNECTU_QUEUED(&a, ev1, &b, eh0, &b);
|
||||||
struct VCO_Element {
|
CONNECTU_QUEUED(&a, ev1, &b, eh1, &a);
|
||||||
VCO_Element() {}
|
piCout << "start";
|
||||||
VCO_Aim_Type type;
|
a.ev1(1.5);
|
||||||
double elapsed;
|
piSleep(1);
|
||||||
float wls_a; // m/s
|
piCout << a.maybeCallQueuedEvents();
|
||||||
float wls_b; // m
|
piSleep(1);
|
||||||
float speed;
|
piCout << b.maybeCallQueuedEvents();
|
||||||
float acceleration; // m/s^2
|
piCout << "end";
|
||||||
float prediction_pos; // m
|
|
||||||
float variance; // m
|
|
||||||
float power;
|
|
||||||
float angle;
|
|
||||||
int id;
|
|
||||||
int missed;
|
|
||||||
int missed_ml;
|
|
||||||
int confirmed;
|
|
||||||
int history_size;
|
|
||||||
bool tracing;
|
|
||||||
bool _found;
|
|
||||||
bool _checked;
|
|
||||||
bool _delete;
|
|
||||||
PIVector<PIVector<double> > history;
|
|
||||||
};
|
|
||||||
#pragma pack (pop)
|
|
||||||
struct VCO_ElementX {
|
|
||||||
VCO_Aim_Type type;
|
|
||||||
double elapsed;
|
|
||||||
float wls_a; // m/s
|
|
||||||
float wls_b; // m
|
|
||||||
float speed;
|
|
||||||
float acceleration; // m/s^2
|
|
||||||
float prediction_pos; // m
|
|
||||||
float variance; // m
|
|
||||||
float power;
|
|
||||||
float angle;
|
|
||||||
int id;
|
|
||||||
int missed;
|
|
||||||
int missed_ml;
|
|
||||||
int confirmed;
|
|
||||||
int history_size;
|
|
||||||
bool tracing;
|
|
||||||
bool _found;
|
|
||||||
bool _checked;
|
|
||||||
bool _delete;
|
|
||||||
};
|
|
||||||
struct VCO_ElementY : VCO_ElementX {
|
|
||||||
PIVector<PIVector<double> > history;
|
|
||||||
};
|
|
||||||
VCO_Element v;
|
|
||||||
VCO_ElementX x;
|
|
||||||
VCO_ElementY y;
|
|
||||||
piCout << sizeof(x);
|
|
||||||
piCout << sizeof(y) << sizeof(y.history) << sizeof(y) - sizeof(y.history) ;
|
|
||||||
piCout << sizeof(v) << sizeof(v.history) << sizeof(v) - sizeof(v.history) ;
|
|
||||||
return 0;*/
|
|
||||||
|
|
||||||
PIVector<PIVector<double> > in;
|
|
||||||
in.resize(5);
|
|
||||||
for (int i = 0; i < in.size_s(); ++i)
|
|
||||||
for (int j = 0; j < 20; ++j)
|
|
||||||
in[i] << j+i*100;
|
|
||||||
// piCout << in.size() << in[0].size();
|
|
||||||
PIVector2D<double> f0;
|
|
||||||
PIVector2D<double> f1(30, 40);
|
|
||||||
//in.resize(1);
|
|
||||||
PIVector2D<double> f2(in);
|
|
||||||
f0 = f2;
|
|
||||||
// piCout << f0;
|
|
||||||
// piCout << f1;
|
|
||||||
// piCout << f2;
|
|
||||||
// piCout << f2.rows() << f2.cols() << f2.size_all() << f2.rows()*f2.cols();
|
|
||||||
piCout << in;
|
|
||||||
piCout << f2;
|
|
||||||
piCout << f2.toVectors();
|
|
||||||
PIVector<double> t = f2.toPlainVector();
|
|
||||||
piCout << t;
|
|
||||||
piCout << PIVector2D<double>(f2.rows(), f2.cols(), t);
|
|
||||||
return 0;
|
|
||||||
// PIFFTWf fft;
|
// PIFFTWf fft;
|
||||||
// fft.preparePlan(50, PIFFTWf::foReal);
|
// fft.preparePlan(50, PIFFTWf::foReal);
|
||||||
// PIVector<complexf> out = fft.calcFFT(in);
|
// PIVector<complexf> out = fft.calcFFT(in);
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ PIString PIObject::__EHFunc::fullFormat() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIObject::PIObject(const PIString & name): _signature_(__PIOBJECT_SIGNATURE__), emitter_(0), thread_safe_(false) {
|
PIObject::PIObject(const PIString & name): _signature_(__PIOBJECT_SIGNATURE__), emitter_(0), thread_safe_(false), proc_event_queue(false) {
|
||||||
piMonitor.objects++;
|
piMonitor.objects++;
|
||||||
//__PIVariantInitBuiltin__();
|
//__PIVariantInitBuiltin__();
|
||||||
setName(name);
|
setName(name);
|
||||||
@@ -225,7 +225,7 @@ void PIObject::piConnect(PIObject * src, const PIString & sig, PIObject * dest_o
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PIObject::piConnectU(PIObject * src, const PIString & ename, PIObject * dest_o, void * dest, const PIString & hname, const char * loc) {
|
bool PIObject::piConnectU(PIObject * src, const PIString & ename, PIObject * dest_o, void * dest, const PIString & hname, const char * loc, PIObject * performer) {
|
||||||
if (src == 0 || dest_o == 0 || dest == 0) return false;
|
if (src == 0 || dest_o == 0 || dest == 0) return false;
|
||||||
if (!src->isPIObject()) {
|
if (!src->isPIObject()) {
|
||||||
piCout << "[piConnectU] \"" << ename << "\" -> \"" << hname << "\" error: source object is not PIObject! (" << loc << ")";
|
piCout << "[piConnectU] \"" << ename << "\" -> \"" << hname << "\" error: source object is not PIObject! (" << loc << ")";
|
||||||
@@ -249,13 +249,14 @@ bool PIObject::piConnectU(PIObject * src, const PIString & ename, PIObject * des
|
|||||||
}
|
}
|
||||||
void * addr_src(0), * addr_dest(0);
|
void * addr_src(0), * addr_dest(0);
|
||||||
int args(0);
|
int args(0);
|
||||||
|
bool que = (performer != 0);
|
||||||
piForeachC (__EHFunc & fs, m_src) {
|
piForeachC (__EHFunc & fs, m_src) {
|
||||||
if (addr_src != 0) break;
|
if (addr_src != 0) break;
|
||||||
piForeachC (__EHFunc & fd, m_dest) {
|
piForeachC (__EHFunc & fd, m_dest) {
|
||||||
if (addr_src != 0) break;
|
if (addr_src != 0) break;
|
||||||
if (fs.arguments().startsWith(fd.arguments()) || fd.arguments().isEmpty()) {
|
if (fs.arguments().startsWith(fd.arguments()) || fd.arguments().isEmpty()) {
|
||||||
addr_src = fs.addr;
|
addr_src = fs.addr;
|
||||||
addr_dest = fd.addr;
|
addr_dest = que ? fd.addrV : fd.addr;
|
||||||
args = fd.names.size_s();
|
args = fd.names.size_s();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -266,7 +267,8 @@ bool PIObject::piConnectU(PIObject * src, const PIString & ename, PIObject * des
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//piCout << "connect" << ename << "->" << hname << "with" << args << "args";
|
//piCout << "connect" << ename << "->" << hname << "with" << args << "args";
|
||||||
src->connections << PIObject::Connection(addr_dest, addr_src, ename, dest_o, dest, args);
|
src->connections << PIObject::Connection(addr_dest, addr_src, ename, dest_o, dest, args, performer);
|
||||||
|
if (que) performer->proc_event_queue = true;
|
||||||
dest_o->connectors << src;
|
dest_o->connectors << src;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -354,6 +356,13 @@ void PIObject::updateConnectors() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PIObject::postQueuedEvent(const PIObject::QueuedEvent & e) {
|
||||||
|
mutex_queue.lock();
|
||||||
|
events_queue << e;
|
||||||
|
mutex_queue.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
PIMutex & PIObject::__meta_mutex() {
|
PIMutex & PIObject::__meta_mutex() {
|
||||||
static PIMutex ret;
|
static PIMutex ret;
|
||||||
return ret;
|
return ret;
|
||||||
@@ -366,6 +375,28 @@ PIMap<PIString, PIObject::__MetaData> & PIObject::__meta_data() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PIObject::callQueuedEvents() {
|
||||||
|
mutex_queue.lock();
|
||||||
|
PIVector<QueuedEvent> qe = events_queue;
|
||||||
|
events_queue.clear();
|
||||||
|
mutex_queue.unlock();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
e.dest_o->emitter_ = 0;
|
||||||
|
if (e.dest_o->thread_safe_) e.dest_o->mutex_.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
PIVector<PIObject * > & PIObject::objects() {
|
PIVector<PIObject * > & PIObject::objects() {
|
||||||
static PIVector<PIObject * > ret;
|
static PIVector<PIObject * > ret;
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
#include "pivariant.h"
|
#include "pivariant.h"
|
||||||
#include "pimutex.h"
|
#include "pimutex.h"
|
||||||
#include "piset.h"
|
#include "piset.h"
|
||||||
|
#include "piqueue.h"
|
||||||
|
|
||||||
|
|
||||||
#ifdef DOXYGEN
|
#ifdef DOXYGEN
|
||||||
@@ -109,6 +110,10 @@
|
|||||||
/// \relatesalso PIObject \brief connect event \"event\" from object \"src\" to event handler \"handler\". \"Event\" and \"handler\" must has equal argument lists.
|
/// \relatesalso PIObject \brief connect event \"event\" from object \"src\" to event handler \"handler\". \"Event\" and \"handler\" must has equal argument lists.
|
||||||
#define CONNECTU(src, event, dest, handler)
|
#define CONNECTU(src, event, dest, handler)
|
||||||
|
|
||||||
|
/// \relatesalso PIObject \brief connect event \"event\" from object \"src\" to event handler \"handler\".
|
||||||
|
/// Event handler will be executed by \"performer\". \"Event\" and \"handler\" must has equal argument lists.
|
||||||
|
#define CONNECTU_QUEUED(src, event, dest, handler, performer)
|
||||||
|
|
||||||
/// \relatesalso PIObject \brief connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" with check of event and handler exists
|
/// \relatesalso PIObject \brief connect event \"event\" from object \"src\" to event handler \"handler\" with return type \"ret\" from object \"dest\" with check of event and handler exists
|
||||||
#define CONNECT0(ret, src, event, dest, handler)
|
#define CONNECT0(ret, src, event, dest, handler)
|
||||||
|
|
||||||
@@ -421,6 +426,7 @@
|
|||||||
#define RAISE_EVENT RAISE_EVENT0
|
#define RAISE_EVENT RAISE_EVENT0
|
||||||
|
|
||||||
#define CONNECTU(src, event, dest, handler) PIObject::piConnectU(src, PIStringAscii(#event), dest, dest, PIStringAscii(#handler), LOCATION);
|
#define CONNECTU(src, event, dest, handler) PIObject::piConnectU(src, PIStringAscii(#event), dest, dest, PIStringAscii(#handler), LOCATION);
|
||||||
|
#define CONNECTU_QUEUED(src, event, dest, handler, performer) PIObject::piConnectU(src, PIStringAscii(#event), dest, dest, PIStringAscii(#handler), LOCATION, performer);
|
||||||
|
|
||||||
#define CONNECT0(ret, src, event, dest, handler) PIObject::piConnect(src, PIStringAscii(#event), dest, dest, (void*)(ret(*)(void*))(&(dest)->__stat_eh_##handler##__), (void*)(void(*)(void*))(&(src)->__stat_eh_##event##__), 0, LOCATION);
|
#define CONNECT0(ret, src, event, dest, handler) PIObject::piConnect(src, PIStringAscii(#event), dest, dest, (void*)(ret(*)(void*))(&(dest)->__stat_eh_##handler##__), (void*)(void(*)(void*))(&(src)->__stat_eh_##event##__), 0, LOCATION);
|
||||||
#define CONNECT1(ret, a0, src, event, dest, handler) PIObject::piConnect(src, PIStringAscii(#event), dest, dest, (void*)(ret(*)(void*, a0))(&(dest)->__stat_eh_##handler##__), (void*)(void(*)(void*, a0))(&(src)->__stat_eh_##event##__), 1, LOCATION);
|
#define CONNECT1(ret, a0, src, event, dest, handler) PIObject::piConnect(src, PIStringAscii(#event), dest, dest, (void*)(ret(*)(void*, a0))(&(dest)->__stat_eh_##handler##__), (void*)(void(*)(void*, a0))(&(src)->__stat_eh_##event##__), 1, LOCATION);
|
||||||
@@ -556,7 +562,7 @@ public:
|
|||||||
|
|
||||||
// / Direct connect
|
// / Direct connect
|
||||||
static void piConnect(PIObject * src, const PIString & sig, PIObject * dest_o, void * dest, void * ev_h, void * e_h, int args, const char * loc);
|
static void piConnect(PIObject * src, const PIString & sig, PIObject * dest_o, void * dest, void * ev_h, void * e_h, int args, const char * loc);
|
||||||
static bool piConnectU(PIObject * src, const PIString & ename, PIObject * dest_o, void * dest, const PIString & hname, const char * loc);
|
static bool piConnectU(PIObject * src, const PIString & ename, PIObject * dest_o, void * dest, const PIString & hname, const char * loc, PIObject * performer = 0);
|
||||||
|
|
||||||
// / Through names and mixed
|
// / Through names and mixed
|
||||||
static void piConnect(const PIString & src, const PIString & sig, void * dest, void * ev_h);
|
static void piConnect(const PIString & src, const PIString & sig, void * dest, void * ev_h);
|
||||||
@@ -578,12 +584,15 @@ public:
|
|||||||
for (int j = 0; j < sender->connections.size_s(); ++j) {
|
for (int j = 0; j < sender->connections.size_s(); ++j) {
|
||||||
Connection & i(sender->connections[j]);
|
Connection & i(sender->connections[j]);
|
||||||
if (i.event != event) continue;
|
if (i.event != event) continue;
|
||||||
//piCout << uint(i.dest) << uint(i.dest_o);
|
if (i.performer) {
|
||||||
if (sender->thread_safe_) i.dest_o->mutex_.lock();
|
i.performer->postQueuedEvent(QueuedEvent(i.slot, i.dest, i.dest_o, sender));
|
||||||
i.dest_o->emitter_ = sender;
|
} else {
|
||||||
((void( *)(void * ))i.slot)(i.dest);
|
if (sender->thread_safe_) i.dest_o->mutex_.lock();
|
||||||
i.dest_o->emitter_ = 0;
|
i.dest_o->emitter_ = sender;
|
||||||
if (sender->thread_safe_) i.dest_o->mutex_.unlock();
|
((void( *)(void * ))i.slot)(i.dest);
|
||||||
|
i.dest_o->emitter_ = 0;
|
||||||
|
if (sender->thread_safe_) i.dest_o->mutex_.unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -592,12 +601,18 @@ public:
|
|||||||
for (int j = 0; j < sender->connections.size_s(); ++j) {
|
for (int j = 0; j < sender->connections.size_s(); ++j) {
|
||||||
Connection & i(sender->connections[j]);
|
Connection & i(sender->connections[j]);
|
||||||
if (i.event != event) continue;
|
if (i.event != event) continue;
|
||||||
if (sender->thread_safe_) i.dest_o->mutex_.lock();
|
if (i.performer) {
|
||||||
i.dest_o->emitter_ = sender;
|
PIVector<PIVariant> vl;
|
||||||
if (i.args_count == 0) ((void(*)(void *))i.slot)(i.dest);
|
if (i.args_count > 0) vl << PIVariant::fromValue(v0);
|
||||||
else ((void(*)(void * , T0))i.slot)(i.dest, v0);
|
i.performer->postQueuedEvent(QueuedEvent(i.slot, i.dest, i.dest_o, sender, vl));
|
||||||
i.dest_o->emitter_ = 0;
|
} else {
|
||||||
if (sender->thread_safe_) i.dest_o->mutex_.unlock();
|
if (sender->thread_safe_) i.dest_o->mutex_.lock();
|
||||||
|
i.dest_o->emitter_ = sender;
|
||||||
|
if (i.args_count == 0) ((void(*)(void *))i.slot)(i.dest);
|
||||||
|
else ((void(*)(void * , T0))i.slot)(i.dest, v0);
|
||||||
|
i.dest_o->emitter_ = 0;
|
||||||
|
if (sender->thread_safe_) i.dest_o->mutex_.unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
template <typename T0, typename T1>
|
template <typename T0, typename T1>
|
||||||
@@ -605,15 +620,22 @@ public:
|
|||||||
for (int j = 0; j < sender->connections.size_s(); ++j) {
|
for (int j = 0; j < sender->connections.size_s(); ++j) {
|
||||||
Connection & i(sender->connections[j]);
|
Connection & i(sender->connections[j]);
|
||||||
if (i.event != event) continue;
|
if (i.event != event) continue;
|
||||||
if (sender->thread_safe_) i.dest_o->mutex_.lock();
|
if (i.performer) {
|
||||||
i.dest_o->emitter_ = sender;
|
PIVector<PIVariant> vl;
|
||||||
switch (i.args_count) {
|
if (i.args_count > 0) vl << PIVariant::fromValue(v0);
|
||||||
case 0: ((void(*)(void *))i.slot)(i.dest); break;
|
if (i.args_count > 1) vl << PIVariant::fromValue(v1);
|
||||||
case 1: ((void(*)(void * , T0))i.slot)(i.dest, v0); break;
|
i.performer->postQueuedEvent(QueuedEvent(i.slot, i.dest, i.dest_o, sender, vl));
|
||||||
default: ((void(*)(void * , T0, T1))i.slot)(i.dest, v0, v1); break;
|
} else {
|
||||||
|
if (sender->thread_safe_) i.dest_o->mutex_.lock();
|
||||||
|
i.dest_o->emitter_ = sender;
|
||||||
|
switch (i.args_count) {
|
||||||
|
case 0: ((void(*)(void *))i.slot)(i.dest); break;
|
||||||
|
case 1: ((void(*)(void * , T0))i.slot)(i.dest, v0); break;
|
||||||
|
default: ((void(*)(void * , T0, T1))i.slot)(i.dest, v0, v1); break;
|
||||||
|
}
|
||||||
|
i.dest_o->emitter_ = 0;
|
||||||
|
if (sender->thread_safe_) i.dest_o->mutex_.unlock();
|
||||||
}
|
}
|
||||||
i.dest_o->emitter_ = 0;
|
|
||||||
if (sender->thread_safe_) i.dest_o->mutex_.unlock();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
template <typename T0, typename T1, typename T2>
|
template <typename T0, typename T1, typename T2>
|
||||||
@@ -621,16 +643,24 @@ public:
|
|||||||
for (int j = 0; j < sender->connections.size_s(); ++j) {
|
for (int j = 0; j < sender->connections.size_s(); ++j) {
|
||||||
Connection & i(sender->connections[j]);
|
Connection & i(sender->connections[j]);
|
||||||
if (i.event != event) continue;
|
if (i.event != event) continue;
|
||||||
if (sender->thread_safe_) i.dest_o->mutex_.lock();
|
if (i.performer) {
|
||||||
i.dest_o->emitter_ = sender;
|
PIVector<PIVariant> vl;
|
||||||
switch (i.args_count) {
|
if (i.args_count > 0) vl << PIVariant::fromValue(v0);
|
||||||
case 0: ((void(*)(void *))i.slot)(i.dest); break;
|
if (i.args_count > 1) vl << PIVariant::fromValue(v1);
|
||||||
case 1: ((void(*)(void * , T0))i.slot)(i.dest, v0); break;
|
if (i.args_count > 2) vl << PIVariant::fromValue(v2);
|
||||||
case 2: ((void(*)(void * , T0, T1))i.slot)(i.dest, v0, v1); break;
|
i.performer->postQueuedEvent(QueuedEvent(i.slot, i.dest, i.dest_o, sender, vl));
|
||||||
default: ((void(*)(void * , T0, T1, T2))i.slot)(i.dest, v0, v1, v2); break;
|
} else {
|
||||||
|
if (sender->thread_safe_) i.dest_o->mutex_.lock();
|
||||||
|
i.dest_o->emitter_ = sender;
|
||||||
|
switch (i.args_count) {
|
||||||
|
case 0: ((void(*)(void *))i.slot)(i.dest); break;
|
||||||
|
case 1: ((void(*)(void * , T0))i.slot)(i.dest, v0); break;
|
||||||
|
case 2: ((void(*)(void * , T0, T1))i.slot)(i.dest, v0, v1); break;
|
||||||
|
default: ((void(*)(void * , T0, T1, T2))i.slot)(i.dest, v0, v1, v2); break;
|
||||||
|
}
|
||||||
|
i.dest_o->emitter_ = 0;
|
||||||
|
if (sender->thread_safe_) i.dest_o->mutex_.unlock();
|
||||||
}
|
}
|
||||||
i.dest_o->emitter_ = 0;
|
|
||||||
if (sender->thread_safe_) i.dest_o->mutex_.unlock();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
template <typename T0, typename T1, typename T2, typename T3>
|
template <typename T0, typename T1, typename T2, typename T3>
|
||||||
@@ -638,17 +668,26 @@ public:
|
|||||||
for (int j = 0; j < sender->connections.size_s(); ++j) {
|
for (int j = 0; j < sender->connections.size_s(); ++j) {
|
||||||
Connection & i(sender->connections[j]);
|
Connection & i(sender->connections[j]);
|
||||||
if (i.event != event) continue;
|
if (i.event != event) continue;
|
||||||
if (sender->thread_safe_) i.dest_o->mutex_.lock();
|
if (i.performer) {
|
||||||
i.dest_o->emitter_ = sender;
|
PIVector<PIVariant> vl;
|
||||||
switch (i.args_count) {
|
if (i.args_count > 0) vl << PIVariant::fromValue(v0);
|
||||||
case 0: ((void(*)(void *))i.slot)(i.dest); break;
|
if (i.args_count > 1) vl << PIVariant::fromValue(v1);
|
||||||
case 1: ((void(*)(void * , T0))i.slot)(i.dest, v0); break;
|
if (i.args_count > 2) vl << PIVariant::fromValue(v2);
|
||||||
case 2: ((void(*)(void * , T0, T1))i.slot)(i.dest, v0, v1); break;
|
if (i.args_count > 3) vl << PIVariant::fromValue(v3);
|
||||||
case 3: ((void(*)(void * , T0, T1, T2))i.slot)(i.dest, v0, v1, v2); break;
|
i.performer->postQueuedEvent(QueuedEvent(i.slot, i.dest, i.dest_o, sender, vl));
|
||||||
default: ((void(*)(void * , T0, T1, T2, T3))i.slot)(i.dest, v0, v1, v2, v3); break;
|
} else {
|
||||||
|
if (sender->thread_safe_) i.dest_o->mutex_.lock();
|
||||||
|
i.dest_o->emitter_ = sender;
|
||||||
|
switch (i.args_count) {
|
||||||
|
case 0: ((void(*)(void *))i.slot)(i.dest); break;
|
||||||
|
case 1: ((void(*)(void * , T0))i.slot)(i.dest, v0); break;
|
||||||
|
case 2: ((void(*)(void * , T0, T1))i.slot)(i.dest, v0, v1); break;
|
||||||
|
case 3: ((void(*)(void * , T0, T1, T2))i.slot)(i.dest, v0, v1, v2); break;
|
||||||
|
default: ((void(*)(void * , T0, T1, T2, T3))i.slot)(i.dest, v0, v1, v2, v3); break;
|
||||||
|
}
|
||||||
|
i.dest_o->emitter_ = 0;
|
||||||
|
if (sender->thread_safe_) i.dest_o->mutex_.unlock();
|
||||||
}
|
}
|
||||||
i.dest_o->emitter_ = 0;
|
|
||||||
if (sender->thread_safe_) i.dest_o->mutex_.unlock();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -754,9 +793,13 @@ public:
|
|||||||
PIMap<const void * , __EHFunc> eh_func;
|
PIMap<const void * , __EHFunc> eh_func;
|
||||||
};
|
};
|
||||||
typedef PIPair<const void * , __EHFunc> __EHPair;
|
typedef PIPair<const void * , __EHFunc> __EHPair;
|
||||||
|
|
||||||
static PIMutex & __meta_mutex();
|
static PIMutex & __meta_mutex();
|
||||||
static PIMap<PIString, __MetaData> & __meta_data(); // [classname]=__MetaData
|
static PIMap<PIString, __MetaData> & __meta_data(); // [classname]=__MetaData
|
||||||
|
|
||||||
|
void callQueuedEvents();
|
||||||
|
bool maybeCallQueuedEvents() {if (proc_event_queue) callQueuedEvents(); return proc_event_queue;}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
//! Returns PIObject* which has raised an event. This value is correct only in definition of some event handler
|
//! Returns PIObject* which has raised an event. This value is correct only in definition of some event handler
|
||||||
@@ -764,8 +807,7 @@ protected:
|
|||||||
|
|
||||||
//! Virtual function executes after property with name "name" has been changed
|
//! Virtual function executes after property with name "name" has been changed
|
||||||
virtual void propertyChanged(const PIString & name) {}
|
virtual void propertyChanged(const PIString & name) {}
|
||||||
|
|
||||||
|
|
||||||
EVENT(deleted)
|
EVENT(deleted)
|
||||||
|
|
||||||
//! \events
|
//! \events
|
||||||
@@ -780,36 +822,53 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
struct Connection {
|
struct Connection {
|
||||||
Connection(void * sl = 0, void * si = 0, const PIString & e = PIString(), PIObject * d_o = 0, void * d = 0, int ac = 0) {
|
Connection(void * sl = 0, void * si = 0, const PIString & e = PIString(), PIObject * d_o = 0, void * d = 0, int ac = 0, PIObject * p = 0) {
|
||||||
slot = sl;
|
slot = sl;
|
||||||
signal = si;
|
signal = si;
|
||||||
event = e;
|
event = e;
|
||||||
dest_o = d_o;
|
dest_o = d_o;
|
||||||
dest = d;
|
dest = d;
|
||||||
args_count = ac;
|
args_count = ac;
|
||||||
|
performer = p;
|
||||||
}
|
}
|
||||||
void * slot;
|
void * slot;
|
||||||
void * signal;
|
void * signal;
|
||||||
PIString event;
|
PIString event;
|
||||||
PIObject * dest_o;
|
PIObject * dest_o;
|
||||||
|
PIObject * performer;
|
||||||
void * dest;
|
void * dest;
|
||||||
int args_count;
|
int args_count;
|
||||||
};
|
};
|
||||||
|
struct QueuedEvent {
|
||||||
|
QueuedEvent(void * sl = 0, void * d = 0, PIObject * d_o = 0, PIObject * s = 0, const PIVector<PIVariant> & v = PIVector<PIVariant>()) {
|
||||||
|
slot = sl;
|
||||||
|
dest = d;
|
||||||
|
dest_o = d_o;
|
||||||
|
src = s;
|
||||||
|
values = v;
|
||||||
|
}
|
||||||
|
void * slot;
|
||||||
|
void * dest;
|
||||||
|
PIObject * dest_o;
|
||||||
|
PIObject * src;
|
||||||
|
PIVector<PIVariant> values;
|
||||||
|
};
|
||||||
|
typedef PIPair<PIString, PIVariant> Property;
|
||||||
|
|
||||||
PIVector<__EHFunc> findEH(const PIString & name) const;
|
PIVector<__EHFunc> findEH(const PIString & name) const;
|
||||||
__EHFunc methodEH(const void * addr) const;
|
__EHFunc methodEH(const void * addr) const;
|
||||||
void updateConnectors();
|
void updateConnectors();
|
||||||
|
void postQueuedEvent(const QueuedEvent & e);
|
||||||
PIVector<Connection> connections;
|
|
||||||
typedef PIPair<PIString, PIVariant> Property;
|
|
||||||
PIMap<PIString, PIVariant> properties_;
|
|
||||||
|
|
||||||
static PIVector<PIObject * > & objects();
|
static PIVector<PIObject * > & objects();
|
||||||
|
|
||||||
|
PIVector<Connection> connections;
|
||||||
|
PIMap<PIString, PIVariant> properties_;
|
||||||
PISet<PIObject * > connectors;
|
PISet<PIObject * > connectors;
|
||||||
PIMutex mutex_, mutex_connect;
|
PIVector<QueuedEvent> events_queue;
|
||||||
|
PIMutex mutex_, mutex_connect, mutex_queue;
|
||||||
PIObject * emitter_;
|
PIObject * emitter_;
|
||||||
bool thread_safe_;
|
bool thread_safe_, proc_event_queue;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -249,7 +249,7 @@ int PISharedMemory::read(void * read_to, int max_size, int offset) {
|
|||||||
memcpy(read_to, &(((char*)(PRIVATE->data))[offset]), max_size);
|
memcpy(read_to, &(((char*)(PRIVATE->data))[offset]), max_size);
|
||||||
return max_size;
|
return max_size;
|
||||||
#endif
|
#endif
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -269,4 +269,5 @@ int PISharedMemory::write(const void * data, int max_size, int offset) {
|
|||||||
memcpy(&(((char*)(PRIVATE->data))[offset]), data, max_size);
|
memcpy(&(((char*)(PRIVATE->data))[offset]), data, max_size);
|
||||||
return max_size;
|
return max_size;
|
||||||
#endif
|
#endif
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user