From e33406b283d36078b7aabd61d4edd82089a677ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Sun, 7 May 2017 09:36:13 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/pip@496 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5 --- CMakeLists.txt | 9 +++++---- main.cpp | 27 ++++++++------------------- main.h | 27 +++++++++++++++++++++++++++ src_main/core/pichar.cpp | 7 ------- src_main/core/pichar.h | 5 ----- src_main/core/piobject.cpp | 10 ++++++++-- src_main/core/piobject.h | 5 ++++- src_main/core/pistring_std.h | 2 ++ src_main/system/picodec.h | 2 +- src_main/system/piprocess.h | 2 +- 10 files changed, 56 insertions(+), 40 deletions(-) create mode 100644 main.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 34777bf6..c3a63dce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -324,10 +324,11 @@ endif() # Test program -#find_package(Qt4 REQUIRED) -#include_directories(${QT_INCLUDES}) -add_executable(pip_test "main.cpp" "ccm_kbd.cpp") -target_link_libraries(pip_test pip pip_fftw)# ${QT_QTCORE_LIBRARY}) +find_package(Qt4 REQUIRED) +include_directories(${QT_INCLUDES}) +qt4_wrap_cpp(CMOCS_TEST "main.h" OPTIONS -nw) +add_executable(pip_test "main.cpp" "main.h" "ccm_kbd.cpp" ${CMOCS_TEST}) +target_link_libraries(pip_test pip pip_fftw ${QT_QTCORE_LIBRARY}) # Install diff --git a/main.cpp b/main.cpp index 835c7d86..b628f8bd 100644 --- a/main.cpp +++ b/main.cpp @@ -1,25 +1,11 @@ -#include "pip.h" - - -class A: public PIObject { - PIOBJECT(A) -public: - EVENT1(ev1, float, f) -}; - -class B: public PIObject { - PIOBJECT(B) -public: - EVENT_HANDLER0(void, eh0) {piCout << "eh0";} - EVENT_HANDLER1(void, eh1, float, f) {piCout << "eh1_1" << f;} - EVENT_HANDLER2(void, eh1, float, f, int, s) {piCout << "eh1_2" << f << s;} -}; - +#include "main.h" #include int main(int argc, char *argv[]) { A a; B b; + a.setName("__a__"); + b.setName("__b__"); /*CONNECTU_QUEUED(&a, ev1, &b, eh0, &b); CONNECTU_QUEUED(&a, ev1, &b, eh1, &a); piCout << "start"; @@ -29,9 +15,12 @@ int main(int argc, char *argv[]) { piSleep(1); piCout << b.maybeCallQueuedEvents();*/ //piCout << "end"; - b.executeQueued(&a, "eh1", PIVariant(0.1), "0150", 10, 40); + /*b.executeQueued(&a, "eh1", PIVariant(0.1), "0150", 10, 40); piSleep(1); - a.maybeCallQueuedEvents(); + a.maybeCallQueuedEvents();*/ //dumpApplication(); + b.execute("eh1", PIVariant(0.1), "0150", 10, 40); + b.executeQueued(&a, "eh1", PIVariant(0.1), "0150", 10, 40); + a.callQueuedEvents(); return 0; } diff --git a/main.h b/main.h new file mode 100644 index 00000000..8abef8a2 --- /dev/null +++ b/main.h @@ -0,0 +1,27 @@ +#ifndef MAIN_H +#define MAIN_H + +#include +#include "pip.h" + +struct _S { + uchar _c[164]; +}; + +class A: public QObject, public PIObject { + PIOBJECT(A) +public: + A() {} + EVENT1(ev1, float, f) +}; + +class B: public QObject, public PIObject { + PIOBJECT(B) +public: + B() {} + EVENT_HANDLER0(void, eh0) {piCout << "eh0" << emitter();} + EVENT_HANDLER1(void, eh1, float, f) {piCout << "eh1_1" << f << emitter();} + EVENT_HANDLER2(void, eh1, float, f, int, s) {piCout << "eh1_2" << f << s << emitter();} +}; + +#endif // MAIN_H diff --git a/src_main/core/pichar.cpp b/src_main/core/pichar.cpp index 86613e2a..4563c7c2 100644 --- a/src_main/core/pichar.cpp +++ b/src_main/core/pichar.cpp @@ -266,13 +266,6 @@ PIChar PIChar::toLower() const { } -#ifdef PIP_STD_IOSTREAM -std::ostream & operator <<(std::ostream & s, const PIChar & v) { - s << v.toCharPtr(); - return s; -} -#endif - PICout operator <<(PICout s, const PIChar & v) { s.space(); s.setControl(0, true); diff --git a/src_main/core/pichar.h b/src_main/core/pichar.h index 3184089f..4c6c1393 100755 --- a/src_main/core/pichar.h +++ b/src_main/core/pichar.h @@ -157,11 +157,6 @@ private: }; -#ifdef PIP_STD_IOSTREAM -//! Output operator to \c std::ostream -std::ostream & operator <<(std::ostream & s, const PIChar & v); -#endif - //! Output operator to \a PICout PICout operator <<(PICout s, const PIChar & v); diff --git a/src_main/core/piobject.cpp b/src_main/core/piobject.cpp index ae5b211f..dac82d70 100755 --- a/src_main/core/piobject.cpp +++ b/src_main/core/piobject.cpp @@ -101,7 +101,7 @@ bool PIObject::execute(const PIString & method, const PIVector & vl) bool ok = findSuitableMethodV(method, vl.size_s(), ac, func); if (!ok) return false; - callAddrV(func.addrV, this, ac, vl); + callAddrV(func.addrV, toThis(), ac, vl); return true; } @@ -120,7 +120,7 @@ bool PIObject::executeQueued(PIObject * performer, const PIString & method, cons bool ok = findSuitableMethodV(method, vl.size_s(), ac, func); if (!ok) return false; - performer->postQueuedEvent(QueuedEvent(func.addrV, this, this, performer, vl)); + performer->postQueuedEvent(QueuedEvent(func.addrV, toThis(), this, performer, vl)); performer->proc_event_queue = true; return true; } @@ -399,6 +399,12 @@ void PIObject::postQueuedEvent(const PIObject::QueuedEvent & e) { } +void * PIObject::toThis() const { + //piCout << ptrOffset() << (void*)this << (void*)((char*)this - ptrOffset()); + return (void*)((char*)this - ptrOffset()); +} + + PIMutex & PIObject::__meta_mutex() { static PIMutex ret; return ret; diff --git a/src_main/core/piobject.h b/src_main/core/piobject.h index b3cd4649..a084e4e9 100755 --- a/src_main/core/piobject.h +++ b/src_main/core/piobject.h @@ -195,7 +195,8 @@ public: \ static const PIString __classNameS() {return PIStringAscii(#name);} \ virtual const char * className() const {return #name;} \ - private: + private: \ + virtual int ptrOffset() const {name * o = (name*)100; return int(llong((PIObject*)o) - llong(o));} #define PIOBJECT_PARENT(name) \ class __##name##_ParentInitializer__ { \ @@ -885,6 +886,8 @@ private: __MetaFunc methodEH(const void * addr) const; void updateConnectors(); void postQueuedEvent(const QueuedEvent & e); + void * toThis() const; + virtual int ptrOffset() const {return 0;} static PIVector & objects(); static void callAddrV(void * slot, void * obj, int args, const PIVector & vl); diff --git a/src_main/core/pistring_std.h b/src_main/core/pistring_std.h index 9a580896..95178d2d 100644 --- a/src_main/core/pistring_std.h +++ b/src_main/core/pistring_std.h @@ -75,6 +75,8 @@ inline PIString StdWString2PIString(const std::wstring & v) { +//! \relatesalso PIChar \brief Output operator to \c std::ostream +inline std::ostream & operator <<(std::ostream & s, const PIChar & v) {s << v.toCharPtr(); return s;} //! \relatesalso PIString \brief Return concatenated string inline PIString operator +(const PIString & f, const std::string & str) {PIString s(f); s += StdString2PIString(str); return s;} diff --git a/src_main/system/picodec.h b/src_main/system/picodec.h index 27df05e6..45725e34 100755 --- a/src_main/system/picodec.h +++ b/src_main/system/picodec.h @@ -22,7 +22,7 @@ #include "piprocess.h" -class PIP_EXPORT PICodec: private PIProcess +class PIP_EXPORT PICodec: protected PIProcess { PIOBJECT(PICodec) public: diff --git a/src_main/system/piprocess.h b/src_main/system/piprocess.h index 12cdcfa8..f365cfcf 100755 --- a/src_main/system/piprocess.h +++ b/src_main/system/piprocess.h @@ -38,7 +38,7 @@ /// bool exec(const PIString & program, const PIStringList & args) /// void terminate() /// bool waitForFinish(int timeout_msecs = 60000) -class PIP_EXPORT PIProcess: private PIThread +class PIP_EXPORT PIProcess: protected PIThread { PIOBJECT_SUBCLASS(PIProcess, PIThread) public: