From fb44b01c0fe5abe7ddbc827fbbb60d21db1ad169 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: Sat, 22 Jun 2019 14:55:23 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/pip@803 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5 --- main.cpp | 14 +- src_main/console/piscreentiles.cpp | 5 - src_main/console/piscreentiles.h | 15 +- src_main/containers/pideque.h | 66 +----- src_main/containers/pilist.h | 2 +- src_main/containers/pimap.h | 2 +- src_main/containers/piqueue.h | 1 + src_main/containers/piset.h | 4 +- src_main/containers/pistack.h | 1 + src_main/containers/pivector.h | 57 ++--- src_main/core/pibase.h | 4 +- src_main/core/pibytearray.h | 6 +- src_main/core/piobject.h | 4 +- src_main/core/pistring.h | 4 +- src_main/introspection/piintrospection_base.h | 1 + .../piintrospection_containers.h | 2 + .../piintrospection_containers_p.cpp | 22 +- .../piintrospection_containers_p.h | 13 +- .../introspection/piintrospection_server.cpp | 37 +++- .../introspection/piintrospection_server.h | 24 +- .../piintrospection_server_p.cpp | 208 ++++++++++++++++++ .../introspection/piintrospection_server_p.h | 79 +++++++ .../introspection/piintrospection_threads.h | 1 + utils/system_daemon/main.cpp | 3 +- 24 files changed, 433 insertions(+), 142 deletions(-) create mode 100644 src_main/introspection/piintrospection_server_p.cpp create mode 100644 src_main/introspection/piintrospection_server_p.h diff --git a/main.cpp b/main.cpp index 9ff0d9a3..e4cfb014 100644 --- a/main.cpp +++ b/main.cpp @@ -9,14 +9,26 @@ public: } }; -PIKbdListener kbd; +PIKbdListener kbd(0, 0, false); +#include +#define PIIS_TYPENAME(t) typeid(t).name() + +template class Name +{ +public: + static const char * name() {return PIIS_TYPENAME(T);} +}; int main(int argc, char * argv[]) { + //piCout << Name::name(); + return 0; + PICLI cli(argc, argv); cli.setDebug(false); cli.addArgument("send"); //PISystemInfo::machineID(); kbd.enableExitCapture(); + kbd.start(); if (cli.hasArgument("send")) { /*piCout << "send mode"; diff --git a/src_main/console/piscreentiles.cpp b/src_main/console/piscreentiles.cpp index a10e869c..b0a095f4 100644 --- a/src_main/console/piscreentiles.cpp +++ b/src_main/console/piscreentiles.cpp @@ -136,11 +136,6 @@ TileList::TileList(const PIString & n): PIScreenTile(n) { } -TileList::~TileList() { - delete scroll; -} - - void TileList::sizeHint(int & w, int & h) const { w = h = 0; piForeachC (Row & r, content) diff --git a/src_main/console/piscreentiles.h b/src_main/console/piscreentiles.h index a464bc91..86890260 100644 --- a/src_main/console/piscreentiles.h +++ b/src_main/console/piscreentiles.h @@ -32,6 +32,7 @@ public: typedef PIPair Row; TileSimple(const PIString & n = PIString()); TileSimple(const Row & r); + virtual ~TileSimple() {} PIVector content; PIScreenTypes::Alignment alignment; protected: @@ -47,6 +48,7 @@ class PIP_EXPORT TileScrollBar: public PIScreenTile { friend class TileList; public: TileScrollBar(const PIString & n = PIString()); + virtual ~TileScrollBar() {} void setMinimum(int v); void setMaximum(int v); void setValue(int v); @@ -68,7 +70,7 @@ class PIP_EXPORT TileList: public PIScreenTile { PIOBJECT_SUBCLASS(TileList, PIScreenTile) public: TileList(const PIString & n = PIString()); - ~TileList(); + virtual ~TileList() {} enum SelectionMode { NoSelection, SingleSelection, @@ -100,6 +102,7 @@ class PIP_EXPORT TileButton: public PIScreenTile { PIOBJECT_SUBCLASS(TileButton, PIScreenTile) public: TileButton(const PIString & n = PIString()); + virtual ~TileButton() {} enum EventType { ButtonClicked }; @@ -119,6 +122,7 @@ class PIP_EXPORT TileButtons: public PIScreenTile { PIOBJECT_SUBCLASS(TileButtons, PIScreenTile) public: TileButtons(const PIString & n = PIString()); + virtual ~TileButtons() {} enum EventType { ButtonSelected }; @@ -131,7 +135,10 @@ protected: void drawEvent(PIScreenDrawer * d); bool keyEvent(PIKbdListener::KeyEvent key); bool mouseEvent(PIKbdListener::MouseEvent me); - struct Rect {Rect(int _x0 = 0, int _y0 = 0, int _x1 = 0, int _y1 = 0): x0(_x0),y0(_y0),x1(_x1),y1(_y1) {}; int x0,y0,x1,y1;}; + struct Rect { + Rect(int _x0 = 0, int _y0 = 0, int _x1 = 0, int _y1 = 0): x0(_x0),y0(_y0),x1(_x1),y1(_y1) {} + int x0,y0,x1,y1; + }; PIVector btn_rects; }; @@ -140,6 +147,7 @@ class PIP_EXPORT TileCheck: public PIScreenTile { PIOBJECT_SUBCLASS(TileCheck, PIScreenTile) public: TileCheck(const PIString & n = PIString()); + virtual ~TileCheck() {} enum EventType { Toggled }; @@ -158,6 +166,7 @@ class PIP_EXPORT TileProgress: public PIScreenTile { PIOBJECT_SUBCLASS(TileProgress, PIScreenTile) public: TileProgress(const PIString & n = PIString()); + virtual ~TileProgress() {} PIScreenTypes::CellFormat format; PIString prefix; PIString suffix; @@ -173,6 +182,7 @@ class PIP_EXPORT TilePICout: public TileList { PIOBJECT_SUBCLASS(TilePICout, PIScreenTile) public: TilePICout(const PIString & n = PIString()); + virtual ~TilePICout() {} PIScreenTypes::CellFormat format; int max_lines; protected: @@ -185,6 +195,7 @@ class PIP_EXPORT TileInput: public PIScreenTile { PIOBJECT_SUBCLASS(TileInput, PIScreenTile) public: TileInput(const PIString & n = PIString()); + virtual ~TileInput() {} /*enum EventType { EditFinished };*/ diff --git a/src_main/containers/pideque.h b/src_main/containers/pideque.h index 4a4ccfe4..5d4abbf0 100755 --- a/src_main/containers/pideque.h +++ b/src_main/containers/pideque.h @@ -36,38 +36,27 @@ class PIDeque { public: inline PIDeque(): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) { PIINTROSPECTION_CONTAINER_NEW(T) - //printf("new vector 1 %p (%s) ... !{\n", this, typeid(T).name()); - //printf("(s=%d, d=%p) }!\n", int(pid_size), pid_data); } inline PIDeque(const PIDeque & other): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) { PIINTROSPECTION_CONTAINER_NEW(T) - //printf("new vector 2 %p (%s) ... !{\n", this, typeid(T).name()); alloc(other.pid_size, true); newT(pid_data + pid_start, other.pid_data + other.pid_start, pid_size); - //printf("(s=%d, d=%p) }!\n", int(pid_size), pid_data); } inline PIDeque(const T * data, size_t size): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) { PIINTROSPECTION_CONTAINER_NEW(T) - //printf("new vector 2 %p (%s) ... !{\n", this, typeid(T).name()); alloc(size, true); newT(pid_data + pid_start, data, pid_size); - //printf("(s=%d, d=%p) }!\n", int(pid_size), pid_data); } inline PIDeque(size_t pid_size, const T & f = T()): pid_data(0), pid_size(0), pid_rsize(0), pid_start(0) { PIINTROSPECTION_CONTAINER_NEW(T) - //printf("new vector 3 %p (%s) ... !{\n", this, typeid(T).name()); resize(pid_size, f); - //printf("(s=%d, d=%p) }!\n", int(pid_size), pid_data); } - inline ~PIDeque() { + inline virtual ~PIDeque() { PIINTROSPECTION_CONTAINER_DELETE(T) PIINTROSPECTION_CONTAINER_FREE(T, (pid_rsize)*sizeof(T)) - //printf("delete deque %p (%s) (s=%d, rs=%d, st=%d, d=%p) ... ~{\n", this, typeid(T).name(), int(pid_size), int(pid_rsize), int(pid_start), pid_data); deleteT(pid_data + pid_start, pid_size); dealloc(); - //deleteRaw(pid_tdata); _reset(); - //printf("}~\n"); } inline PIDeque & operator =(const PIDeque & other) { @@ -188,9 +177,8 @@ public: inline PIDeque & clear() {resize(0); return *this;} inline PIDeque & fill(const T & f = T()) { - //if (sizeof(T) == 1) memset(pid_data, f, pid_size); deleteT(pid_data + pid_start, pid_size); - //zeroRaw(pid_data, pid_size); + PIINTROSPECTION_CONTAINER_USED(T, pid_size*sizeof(T)) for (size_t i = pid_start; i < pid_start + pid_size; ++i) elementNew(pid_data + i, f); return *this; @@ -206,8 +194,6 @@ public: if (new_size > pid_size) { size_t os = pid_size; alloc(new_size, true); - //if (sizeof(T) == 1) memset(&(pid_data[os]), f, ds); - //zeroRaw(&(pid_data[os]), new_size - os); PIINTROSPECTION_CONTAINER_USED(T, (new_size-os)*sizeof(T)) for (size_t i = os + pid_start; i < new_size + pid_start; ++i) elementNew(pid_data + i, f); } @@ -229,7 +215,6 @@ public: inline PIDeque & insert(size_t index, const T & v = T()) { bool dir = pid_rsize <= 2 ? true : (index >= pid_rsize / 2 ? true : false); - //piCout << "insert" << dir << index << pid_size << pid_rsize << pid_start << "!<"; if (dir) { alloc(pid_size + 1, true); if (index < pid_size - 1) { @@ -238,11 +223,9 @@ public: } } else { alloc(pid_size + 1, false, -1); - //piCout << "insert front" << pid_size << pid_rsize << pid_start << "!<"; if (index > 0) memmove((void*)(&(pid_data[pid_start])), (const void*)(&(pid_data[pid_start + 1])), index * sizeof(T)); } - //piCout << "insert" << pid_start << index << (pid_start + ssize_t(index)) << pid_size << ">!"; PIINTROSPECTION_CONTAINER_USED(T, sizeof(T)) elementNew(pid_data + pid_start + index, v); return *this; @@ -250,22 +233,16 @@ public: inline PIDeque & insert(size_t index, const PIDeque & other) { if (other.isEmpty()) return *this; bool dir = pid_rsize <= 2 ? true : (index >= pid_rsize / 2 ? true : false); - //piCout << this << "insert" << dir << index << pid_size << pid_rsize << pid_start << " <- " << other.size() << "!<"; if (dir) { ssize_t os = pid_size - index; alloc(pid_size + other.pid_size, true); if (os > 0) memmove((void*)(&(pid_data[index + pid_start + other.pid_size])), (const void*)(&(pid_data[index + pid_start])), os * sizeof(T)); } else { - //if (pid_start < other.pid_size) pid_start = 0; - //piCout << this << " insert offseted start ba" << pid_start << pid_size << pid_rsize; alloc(pid_size + other.pid_size, false, -other.pid_size); - //piCout << this << " insert offseted start aa" << pid_start << pid_size << pid_rsize; - //piCout << this << " insert front" << pid_size << pid_rsize << pid_start << "!<"; if (index > 0) memmove((void*)(&(pid_data[pid_start])), (const void*)(&(pid_data[pid_start + other.pid_size])), index * sizeof(T)); } - //piCout << this << "insert" << pid_start << index << (pid_start + ssize_t(index)) << pid_size << ">!"; newT(pid_data + pid_start + index, other.pid_data + other.pid_start, other.pid_size); return *this; } @@ -279,7 +256,6 @@ public: size_t os = pid_size - index - count; deleteT(&(pid_data[index + pid_start]), count); if (os <= index) { - //if (true) { if (os > 0) memmove((void*)(&(pid_data[index + pid_start])), (const void*)(&(pid_data[index + pid_start + count])), os * sizeof(T)); } else { if (index > 0) memmove((void*)(&(pid_data[pid_start + count])), (const void*)(&(pid_data[pid_start])), index * sizeof(T)); @@ -351,12 +327,9 @@ private: if (pid_rsize + pid_rsize >= size_t(s) && pid_rsize < size_t(s)) return pid_rsize + pid_rsize; ssize_t t = 0, s_ = s - 1; - //printf("asize .. %p rs=%d ns=%d s_=%d t=%d \n", this, pid_rsize, s, s_, t); while (s_ >> t) { ++t; - //printf("asize ++ %p rs=%d ns=%d s_=%d t=%d \n", this, pid_rsize, s, s_, t); } - //printf("asize ok %p rs=%d ns=%d s_=%d t=%d \n", this, pid_rsize, s, s_, t); return (1 << t); } inline void newT(T * dst, const T * src, size_t s) { @@ -365,11 +338,7 @@ private: elementNew(dst + i, src[i]); } inline static T * newRaw(size_t s) { - //std::cout << std::dec << " ![("< (new 0x" << (llong)ret << ") ok]!" << std::endl; return (T*)ret; } /*void reallocRawTemp(size_t s) { @@ -378,24 +347,17 @@ private: }*/ inline void deleteT(T * d, size_t sz) { PIINTROSPECTION_CONTAINER_UNUSED(T, sz*sizeof(T)) - //std::cout << " ~[("< ok]~" << endl; } inline static void deleteRaw(T *& d) { - //cout << " ~[("< ok]~" << endl; } inline static void zeroRaw(T * d, size_t s) { - //cout << " ~[("< ok]~" << endl; } inline void elementNew(T * to, const T & from) {new(to)T(from);} inline void elementDelete(T & from) {from.~T();} @@ -418,11 +380,9 @@ private: pid_start = ssize_t(pid_rsize) - pid_size - pid_size; } }*/ - //printf("(%p) check move st=%d sz=%d rs=%d\n", this, pid_start, pid_size, pid_rsize); if (pid_start < ssize_t(pid_size + pid_size) || pid_start > (ssize_t(pid_rsize) - ssize_t(pid_size) - ssize_t(pid_size))) { ssize_t ns = (pid_rsize - pid_size) / 2; if (pid_start != ns) { - //printf("(%p) move %d -> %d\n", this, pid_start, ns); memmove((void*)(pid_data + ns), (const void*)(pid_data + pid_start), pid_size * sizeof(T)); pid_start = ns; } @@ -431,14 +391,12 @@ private: } else { ssize_t ns = (pid_rsize - pid_size) / 2; if (pid_start != ns) { - //printf("(%p) move %d -> %d\n", this, pid_start, ns); memmove((void*)(pid_data + ns), (const void*)(pid_data + pid_start), pid_size * sizeof(T)); pid_start = ns; } } } inline void alloc(size_t new_size, bool direction, ssize_t start_offset = 0) { // direction == true -> alloc forward - //if(new_size == 65536) printf("(%p) alloc too much size %d->%d", this, (int)pid_size, (int)new_size); if (direction) { if (pid_start + new_size <= pid_rsize) { pid_size = new_size; @@ -447,50 +405,35 @@ private: } pid_size = new_size; size_t as = asize(pid_start + new_size); - //if(as > 1000) piCout << "too much deque size" << new_size << as; if (as != pid_rsize) { - //printf("(%p) realloc %d -> %d (%p)\n", this, pid_rsize, as, pid_data); PIINTROSPECTION_CONTAINER_ALLOC(T, (as-pid_rsize)*sizeof(T)) T * p_d = (T*)(realloc((void*)(pid_data), as*sizeof(T))); - //if(!p_d) printf("(%p) realloc (%d)%d -> %d (%p) %d\n", this, (int)pid_start, (int)pid_rsize, (int)as, pid_data, (int)new_size); assert(p_d); pid_data = p_d; pid_rsize = as; - //printf("(%p) realloc done (%p)\n", this, pid_data); } } else { size_t as; - //piCout << "INS ba" << *this; if (pid_start + start_offset < 0) as = asize(pid_rsize - start_offset); else as = pid_rsize; - //if(as > 1000) piCout << "too much deque size" << new_size << as; - //printf("%X alloc %d %d\n", this, pid_rsize, start_offset); - //printf("%X alloc %d %d %d %d %d %d\n", this, new_size, pid_size, pid_rsize, as, pid_start, start_offset); if (as > pid_rsize) { - //printf("%X alloc new size %d\n", this, as); - //cout << std::hex << " ![("< 0 && pid_data != 0) { - //printf("%X copy from %p + %d to %p + %d %d el\n", this, pid_data, pid_start, td, ns, pid_size); memcpy((void*)(td + ns), (const void*)(pid_data + pid_start), pid_size * sizeof(T)); deleteRaw(pid_data); } pid_data = td; pid_rsize = as; pid_start = ns; - //piCout << "INS aa" << *this; } pid_start += start_offset; pid_size = new_size; checkMove(direction); } - //checkMove(direction); - //printf("%X alloc new start %d\n", this, pid_start); } T * pid_data; @@ -504,8 +447,9 @@ private: template<> inline void PIDeque::elementNew(T * to, const T & from) {(*to) = from;} \ template<> inline void PIDeque::elementDelete(T & from) {;} \ template<> inline PIDeque & PIDeque::_resizeRaw(size_t new_size) {if (new_size > pid_size) alloc(new_size, true); return *this;} \ - template<> inline PIDeque & PIDeque::clear() {pid_size = 0; return *this;} \ - template<> inline PIDeque & PIDeque::assign(size_t new_size, const T & f) {_resizeRaw(new_size); return fill(f);} + template<> inline PIDeque & PIDeque::clear() {PIINTROSPECTION_CONTAINER_UNUSED(T, pid_size*sizeof(T)); pid_size = 0; return *this;} \ + template<> inline PIDeque & PIDeque::assign(size_t new_size, const T & f) {\ + _resizeRaw(new_size); return fill(f);} #else diff --git a/src_main/containers/pilist.h b/src_main/containers/pilist.h index da7dccd8..f3a0a7c8 100644 --- a/src_main/containers/pilist.h +++ b/src_main/containers/pilist.h @@ -39,7 +39,7 @@ public: PIList(const Type & v0, const Type & v1, const Type & v2) {piMonitor.containers++; _stlc::push_back(v0); _stlc::push_back(v1); _stlc::push_back(v2);} PIList(const Type & v0, const Type & v1, const Type & v2, const Type & v3) {piMonitor.containers++; _stlc::push_back(v0); _stlc::push_back(v1); _stlc::push_back(v2); _stlc::push_back(v3);} PIList(uint size, const Type & value = Type()) {piMonitor.containers++; _stlc::resize(size, value);} - ~PIList() {piMonitor.containers--;} + virtual ~PIList() {piMonitor.containers--;} Type & operator [](uint index) {return (*this)[index];} Type & operator [](uint index) const {return (*this)[index];} const Type * data(uint index = 0) const {return &(*this)[index];} diff --git a/src_main/containers/pimap.h b/src_main/containers/pimap.h index af74cbba..e680e4bd 100644 --- a/src_main/containers/pimap.h +++ b/src_main/containers/pimap.h @@ -76,7 +76,7 @@ class PIMap { public: PIMap() {;} PIMap(const PIMap & other) {*this = other;} - ~PIMap() {;} + virtual ~PIMap() {;} PIMap & operator =(const PIMap & other) { if (this == &other) return *this; diff --git a/src_main/containers/piqueue.h b/src_main/containers/piqueue.h index 7e77b6a8..4b5ff69e 100755 --- a/src_main/containers/piqueue.h +++ b/src_main/containers/piqueue.h @@ -31,6 +31,7 @@ template class PIP_EXPORT PIQueue: public PIDeque { public: PIQueue() {;} + virtual ~PIQueue() {;} PIDeque & enqueue(const T & v) {PIDeque::push_front(v); return *this;} T dequeue() {return PIDeque::take_back();} T & head() {return PIDeque::back();} diff --git a/src_main/containers/piset.h b/src_main/containers/piset.h index 5998639e..c5e9a512 100644 --- a/src_main/containers/piset.h +++ b/src_main/containers/piset.h @@ -41,7 +41,9 @@ public: //! Contructs an empty set PISet() {} - + + virtual ~PISet() {;} + //! Contructs set with one element "value" PISet(const T & value) {_CSet::insert(value, 0);} diff --git a/src_main/containers/pistack.h b/src_main/containers/pistack.h index 4bad33b4..c0f9bff5 100755 --- a/src_main/containers/pistack.h +++ b/src_main/containers/pistack.h @@ -31,6 +31,7 @@ template class PIP_EXPORT PIStack: public PIVector { public: PIStack() {;} + virtual ~PIStack() {;} PIVector & push(const T & v) {PIVector::push_back(v); return *this;} T pop() {return PIVector::take_back();} T & top() {return PIVector::back();} diff --git a/src_main/containers/pivector.h b/src_main/containers/pivector.h index 18acbb79..a0900b63 100755 --- a/src_main/containers/pivector.h +++ b/src_main/containers/pivector.h @@ -35,33 +35,28 @@ template class PIVector { public: inline PIVector(): piv_data(0), piv_size(0), piv_rsize(0) { - //printf("new vector 1 %p (%s) ... !{\n", this, typeid(T).name()); - //printf("(s=%d, d=%p) }!\n", int(piv_size), piv_data); + PIINTROSPECTION_CONTAINER_NEW(T) } inline PIVector(const T * data, size_t size): piv_data(0), piv_size(0), piv_rsize(0) { - //printf("new vector 2 %p (%s) ... !{\n", this, typeid(T).name()); + PIINTROSPECTION_CONTAINER_NEW(T) alloc(size); newT(piv_data, data, piv_size); - //printf("(s=%d, d=%p) }!\n", int(pid_size), pid_data); } inline PIVector(const PIVector & other): piv_data(0), piv_size(0), piv_rsize(0) { - //printf("new vector 2 %p (%s) ... !{\n", this, typeid(T).name()); + PIINTROSPECTION_CONTAINER_NEW(T) alloc(other.piv_size); newT(piv_data, other.piv_data, piv_size); - //printf("(s=%d, d=%p) }!\n", int(piv_size), piv_data); } inline PIVector(size_t piv_size, const T & f = T()): piv_data(0), piv_size(0), piv_rsize(0) { - //printf("new vector 3 %p (%s) ... !{\n", this, typeid(T).name()); + PIINTROSPECTION_CONTAINER_NEW(T) resize(piv_size, f); - //printf("(s=%d, d=%p) }!\n", int(piv_size), piv_data); } - inline ~PIVector() { - //printf("delete vector %p (%s) (s=%d, d=%p) ... ~{\n", this, typeid(T).name(), int(piv_size), piv_data); + inline virtual ~PIVector() { + PIINTROSPECTION_CONTAINER_DELETE(T) + PIINTROSPECTION_CONTAINER_FREE(T, (piv_rsize)*sizeof(T)) deleteT(piv_data, piv_size); dealloc(); - //deleteRaw(piv_tdata); _reset(); - //printf("}~\n"); } inline PIVector & operator =(const PIVector & other) { @@ -182,9 +177,8 @@ public: inline PIVector & clear() {resize(0); return *this;} inline PIVector & fill(const T & f = T()) { - //if (sizeof(T) == 1) memset(piv_data, f, piv_size); deleteT(piv_data, piv_size); - //zeroRaw(piv_data, piv_size); + PIINTROSPECTION_CONTAINER_USED(T, piv_size*sizeof(T)) for (size_t i = 0; i < piv_size; ++i) elementNew(piv_data + i, f); return *this; @@ -201,8 +195,7 @@ public: if (new_size > piv_size) { size_t os = piv_size; alloc(new_size); - //if (sizeof(T) == 1) memset(&(piv_data[os]), f, ds); - //zeroRaw(&(piv_data[os]), new_size - os); + PIINTROSPECTION_CONTAINER_USED(T, (new_size-os)*sizeof(T)) for (size_t i = os; i < new_size; ++i) elementNew(piv_data + i, f); } @@ -231,7 +224,7 @@ public: size_t os = piv_size - index - 1; memmove((void*)(&(piv_data[index + 1])), (const void*)(&(piv_data[index])), os * sizeof(T)); } - //zeroRaw(&(piv_data[index]), 1); + PIINTROSPECTION_CONTAINER_USED(T, sizeof(T)) elementNew(piv_data + index, v); return *this; } @@ -273,7 +266,7 @@ public: inline PIVector & removeOne(const T & v) {for (size_t i = 0; i < piv_size; ++i) if (piv_data[i] == v) {remove(i); return *this;} return *this;} inline PIVector & removeAll(const T & v) {for (ssize_t i = 0; i < ssize_t(piv_size); ++i) if (piv_data[i] == v) {remove(i); --i;} return *this;} - inline PIVector & push_back(const T & v) {alloc(piv_size + 1); elementNew(piv_data + piv_size - 1, v); return *this;} + inline PIVector & push_back(const T & v) {alloc(piv_size + 1); PIINTROSPECTION_CONTAINER_USED(T, sizeof(T)); elementNew(piv_data + piv_size - 1, v); return *this;} inline PIVector & append(const T & v) {return push_back(v);} inline PIVector & append(const PIVector & other) { size_t ps = piv_size; @@ -312,15 +305,12 @@ private: return (1 << t); } inline void newT(T * dst, const T * src, size_t s) { + PIINTROSPECTION_CONTAINER_USED(T, s*sizeof(T)) for (size_t i = 0; i < s; ++i) elementNew(dst + i, src[i]); } inline T * newRaw(size_t s) { - //cout << std::dec << " ![("< (new 0x" << (llong)ret << ") ok]!" << endl; return (T*)ret; } /*void reallocRawTemp(size_t s) { @@ -328,24 +318,18 @@ private: else piv_tdata = (T*)(realloc(piv_tdata, s * sizeof(T))); }*/ inline void deleteT(T * d, size_t sz) { - //cout << " ~[("< ok]~" << endl; } inline void deleteRaw(T *& d) { - //cout << " ~[("< ok]~" << endl; } inline void zeroRaw(T * d, size_t s) { - //cout << " ~[("< ok]~" << endl; } inline void elementNew(T * to, const T & from) {new(to)T(from);} inline void elementDelete(T & from) {from.~T();} @@ -355,19 +339,15 @@ private: piv_size = new_size; return; } - //int os = piv_size; piv_size = new_size; size_t as = asize(new_size); if (as == piv_rsize) return; - //if(as > 1000) piCout << "too much vector size" << new_size << as; + PIINTROSPECTION_CONTAINER_ALLOC(T, (as-piv_rsize)*sizeof(T)) - //cout << std::hex << " ![("< (new 0x" << (llong)piv_data << ") ok]!" << endl; /*piv_rsize = as; T * pd = newRaw(piv_rsize); if (os > 0 && piv_data != 0) { @@ -434,13 +414,14 @@ __PIVECTOR_SIMPLE_FUNCTIONS__(float) __PIVECTOR_SIMPLE_FUNCTIONS__(double) __PIVECTOR_SIMPLE_FUNCTIONS__(ldouble)*/ #define __PIVECTOR_SIMPLE_TYPE__(T) \ - template<> inline void PIVector::newT(T * dst, const T * src, size_t s) {memcpy((void*)(dst), (const void*)(src), s * sizeof(T));} \ - template<> inline void PIVector::deleteT(T * d, size_t sz) {;} \ + template<> inline void PIVector::newT(T * dst, const T * src, size_t s) {PIINTROSPECTION_CONTAINER_USED(T, s*sizeof(T)); memcpy((void*)(dst), (const void*)(src), s * sizeof(T));} \ + template<> inline void PIVector::deleteT(T * d, size_t sz) {PIINTROSPECTION_CONTAINER_UNUSED(T, sz*sizeof(T));} \ template<> inline void PIVector::elementNew(T * to, const T & from) {(*to) = from;} \ template<> inline void PIVector::elementDelete(T & from) {;} \ template<> inline PIVector & PIVector::_resizeRaw(size_t new_size) {alloc(new_size); return *this;} \ - template<> inline PIVector & PIVector::clear() {piv_size = 0; return *this;} \ - template<> inline PIVector & PIVector::assign(size_t new_size, const T & f) {_resizeRaw(new_size); return fill(f);} + template<> inline PIVector & PIVector::clear() {PIINTROSPECTION_CONTAINER_UNUSED(T, piv_size*sizeof(T)); piv_size = 0; return *this;} \ + template<> inline PIVector & PIVector::assign(size_t new_size, const T & f) {\ + _resizeRaw(new_size); return fill(f);} #else diff --git a/src_main/core/pibase.h b/src_main/core/pibase.h index 9380cd36..3d8b5fec 100644 --- a/src_main/core/pibase.h +++ b/src_main/core/pibase.h @@ -209,9 +209,9 @@ #define PRIVATE_DEFINITION_END(c) \ }; \ c::__PrivateInitializer__::__PrivateInitializer__() {p = new c::__Private__();} \ - c::__PrivateInitializer__::__PrivateInitializer__(const c::__PrivateInitializer__ & o) {/*if (p) delete p;*/ p = new c::__Private__();} \ + c::__PrivateInitializer__::__PrivateInitializer__(const c::__PrivateInitializer__ & o) {/*if (p) delete p;*/ p = new c::__Private__(); *p = *(o.p);} \ c::__PrivateInitializer__::~__PrivateInitializer__() {delete p; p = 0;} \ - c::__PrivateInitializer__ & c::__PrivateInitializer__::operator =(const c::__PrivateInitializer__ & o) {if (p) delete p; p = new c::__Private__(); return *this;} + c::__PrivateInitializer__ & c::__PrivateInitializer__::operator =(const c::__PrivateInitializer__ & o) {if (p) delete p; p = new c::__Private__(); *p = *(o.p); return *this;} #define PRIVATE (__privateinitializer__.p) #define PRIVATEWB __privateinitializer__.p diff --git a/src_main/core/pibytearray.h b/src_main/core/pibytearray.h index d8047884..285bd21f 100755 --- a/src_main/core/pibytearray.h +++ b/src_main/core/pibytearray.h @@ -34,15 +34,15 @@ __PICONTAINERS_SIMPLE_TYPE__(PIChar) template<> \ inline PIByteArray & operator <<(PIByteArray & s, const PIVector & v) {s << int(v.size_s()); int os = s.size_s(); s.enlarge(v.size_s()*sizeof(T)); memcpy(s.data(os), v.data(), v.size_s()*sizeof(T)); return s;} \ template<> \ -inline PIByteArray & operator >>(PIByteArray & s, PIVector & v) {assert(s.size_s() >= 4); int sz; s >> sz; v._resizeRaw(sz); if (sz > 0) memcpy(v.data(), s.data(), sz*sizeof(T)); s.remove(0, sz*sizeof(T)); return s;} \ +inline PIByteArray & operator >>(PIByteArray & s, PIVector & v) {assert(s.size_s() >= 4); int sz; s >> sz; v._resizeRaw(sz); PIINTROSPECTION_CONTAINER_USED(T, sz*sizeof(T)); if (sz > 0) memcpy(v.data(), s.data(), sz*sizeof(T)); s.remove(0, sz*sizeof(T)); return s;} \ template<> \ inline PIByteArray & operator <<(PIByteArray & s, const PIDeque & v) {s << int(v.size_s()); int os = s.size_s(); s.enlarge(v.size_s()*sizeof(T)); memcpy(s.data(os), v.data(), v.size_s()*sizeof(T)); return s;} \ template<> \ -inline PIByteArray & operator >>(PIByteArray & s, PIDeque & v) {assert(s.size_s() >= 4); int sz; s >> sz; v._resizeRaw(sz); if (sz > 0) memcpy(v.data(), s.data(), sz*sizeof(T)); s.remove(0, sz*sizeof(T)); return s;} \ +inline PIByteArray & operator >>(PIByteArray & s, PIDeque & v) {assert(s.size_s() >= 4); int sz; s >> sz; v._resizeRaw(sz); PIINTROSPECTION_CONTAINER_USED(T, sz*sizeof(T)); if (sz > 0) memcpy(v.data(), s.data(), sz*sizeof(T)); s.remove(0, sz*sizeof(T)); return s;} \ template<> \ inline PIByteArray & operator <<(PIByteArray & s, const PIVector2D & v) {s << int(v.rows()) << int(v.cols()); int os = s.size_s(); s.enlarge(v.size_s()*sizeof(T)); memcpy(s.data(os), v.data(), v.size_s()*sizeof(T)); return s;} \ template<> \ -inline PIByteArray & operator >>(PIByteArray & s, PIVector2D & v) {assert(s.size_s() >= 8); int r, c; s >> r >> c; v._resizeRaw(r, c); int sz = r*c; if (sz > 0) memcpy(v.data(), s.data(), sz*sizeof(T)); s.remove(0, sz*sizeof(T)); return s;} +inline PIByteArray & operator >>(PIByteArray & s, PIVector2D & v) {assert(s.size_s() >= 8); int r, c; s >> r >> c; v._resizeRaw(r, c); int sz = r*c; PIINTROSPECTION_CONTAINER_USED(T, sz*sizeof(T)); if (sz > 0) memcpy(v.data(), s.data(), sz*sizeof(T)); s.remove(0, sz*sizeof(T)); return s;} class PIString; diff --git a/src_main/core/piobject.h b/src_main/core/piobject.h index 69a615c2..3e59c880 100755 --- a/src_main/core/piobject.h +++ b/src_main/core/piobject.h @@ -462,12 +462,12 @@ typedef void (*Handler)(void * ); -class PIP_EXPORT PIObject -{ +class PIP_EXPORT PIObject { friend class PIObjectManager; friend void dumpApplication(); typedef PIObject __PIObject__; typedef void __Parent__; + friend class PIIntrospection; public: //! Contructs PIObject with name "name" diff --git a/src_main/core/pistring.h b/src_main/core/pistring.h index a104f624..4f9a4eff 100755 --- a/src_main/core/pistring.h +++ b/src_main/core/pistring.h @@ -94,7 +94,7 @@ public: // PIString(const double & value): PIDeque() {/*reserve(4); */piMonitor.strings++; piMonitor.containers--; *this = fromNumber(value);} - //~PIString() {piMonitor.strings--; piMonitor.containers++;} + ~PIString() {piMonitor.strings--; piMonitor.containers++;} PIString & operator =(const PIString & o) {if (this == &o) return *this; clear(); *this += o; return *this;} @@ -775,6 +775,8 @@ public: //! Contructs empty strings list PIStringList() {;} + + ~PIStringList() {;} //! Contructs strings list with one string "str" PIStringList(const PIString & str) {push_back(str);} diff --git a/src_main/introspection/piintrospection_base.h b/src_main/introspection/piintrospection_base.h index 2e8ce232..a6c5a906 100644 --- a/src_main/introspection/piintrospection_base.h +++ b/src_main/introspection/piintrospection_base.h @@ -27,6 +27,7 @@ class PIMutex; class PIThread; class PITimer; class PIPeer; +class PIIntrospection; #define __PIINTROSPECTION_SINGLETON__(T) \ static PIIntrospection##T##Interface * instance() {static PIIntrospection##T##Interface ret; return &ret;} \ diff --git a/src_main/introspection/piintrospection_containers.h b/src_main/introspection/piintrospection_containers.h index aae39df7..46c470d2 100644 --- a/src_main/introspection/piintrospection_containers.h +++ b/src_main/introspection/piintrospection_containers.h @@ -56,6 +56,8 @@ class PIIntrospectionContainers; #endif class PIP_EXPORT PIIntrospectionContainersInterface { + friend class PIIntrospection; + friend class PIIntrospectionServer; public: __PIINTROSPECTION_SINGLETON__(Containers) diff --git a/src_main/introspection/piintrospection_containers_p.cpp b/src_main/introspection/piintrospection_containers_p.cpp index 3004c495..4d9e2b6c 100644 --- a/src_main/introspection/piintrospection_containers_p.cpp +++ b/src_main/introspection/piintrospection_containers_p.cpp @@ -18,6 +18,7 @@ */ #include "piintrospection_containers_p.h" +#include PIIntrospectionContainers::Type::Type() { @@ -29,14 +30,17 @@ PIIntrospectionContainers::Type::Type() { PIIntrospectionContainers::PIIntrospectionContainers() { + crc = standardCRC_32(); } void PIIntrospectionContainers::containerNew(const char * tn) { - PIMutexLocker _ml(mutex); uint id = typeID(tn); - typenames[id] = PIStringAscii(tn); + PIMutexLocker _ml(mutex); + //printf("containerNew lock\n"); + typenames[id] = tn; data[id].count++; + //printf("containerNew unlock\n"); } @@ -74,18 +78,26 @@ uint PIIntrospectionContainers::typeID(const char * tn) { if (!tn) return 0u; size_t l = strlen(tn); if (l == 0) return 0u; - return crc.calculate(tn, l); + return crc.calculate(tn, int(l)); } +PIByteArray & operator <<(PIByteArray & s, const std::unordered_map & v) { + PIMap m; + for (typename std::unordered_map::const_iterator i = v.cbegin(); i != v.cend(); ++i) { + m[i->first] = PIStringAscii(i->second.c_str()); + } + s << m; + return s; +} + + PIByteArray & operator <<(PIByteArray & s, const PIIntrospectionContainers::Type & v) { s << v.count << v.items << v.bytes_allocated << v.bytes_used; return s; } - - PIByteArray & operator >>(PIByteArray & s, PIIntrospectionContainers::Type & v) { s >> v.count >> v.items >> v.bytes_allocated >> v.bytes_used; return s; diff --git a/src_main/introspection/piintrospection_containers_p.h b/src_main/introspection/piintrospection_containers_p.h index 1c4b62cc..7bdeb40b 100644 --- a/src_main/introspection/piintrospection_containers_p.h +++ b/src_main/introspection/piintrospection_containers_p.h @@ -20,10 +20,9 @@ #ifndef PIINTROSPECTION_CONTAINERS_P_H #define PIINTROSPECTION_CONTAINERS_P_H -#define PIP_FORCE_NO_PIINTROSPECTION - #include "pimutex.h" -#include "pimap.h" +#include +#include #include "picrc.h" @@ -48,15 +47,15 @@ public: ullong bytes_used; }; - PIMap data; - PIMap typenames; + std::unordered_map data; + std::unordered_map typenames; PIMutex mutex; CRC_32 crc; }; +PIByteArray & operator <<(PIByteArray & s, const std::unordered_map & v); + PIByteArray & operator <<(PIByteArray & s, const PIIntrospectionContainers::Type & v); PIByteArray & operator >>(PIByteArray & s, PIIntrospectionContainers::Type & v); -#undef PIP_FORCE_NO_PIINTROSPECTION - #endif // PIINTROSPECTION_CONTAINERS_P_H diff --git a/src_main/introspection/piintrospection_server.cpp b/src_main/introspection/piintrospection_server.cpp index 7a06435f..7ecdd0ae 100644 --- a/src_main/introspection/piintrospection_server.cpp +++ b/src_main/introspection/piintrospection_server.cpp @@ -18,11 +18,33 @@ */ #include "piintrospection_server.h" +#include "piintrospection_server_p.h" +#include "pichunkstream.h" + + +PRIVATE_DEFINITION_START(PIIntrospectionServer) + PIIntrospection::ProcessInfo process_info; +PRIVATE_DEFINITION_END(PIIntrospectionServer) PIIntrospectionServer::PIIntrospectionServer(): PIPeer(genName()) { - CONNECTU(&itimer, tickEvent, this, timerEvent) - itimer.start(100); + PRIVATE->process_info = PIIntrospection::getInfo(); + CONNECTU(&itimer, tickEvent, this, timerEvent); +} + + +PIIntrospectionServer::~PIIntrospectionServer() { + itimer.stop(false); + if (!itimer.waitForFinish(1000)) { + PIINTROSPECTION_CONTAINERS->p->mutex.unlock(); + } + PIPeer::stop(); +} + + +void PIIntrospectionServer::start() { + itimer.start(1000); + PIPeer::start(); } @@ -33,10 +55,13 @@ PIString PIIntrospectionServer::genName() { void PIIntrospectionServer::timerEvent() { + PIChunkStream cs; + cs.add(1, PIIntrospection::packInfo()) + .add(2, PIIntrospection::packContainers()) + .add(3, PIIntrospection::packThreads()) + .add(4, PIIntrospection::packObjects()); PIByteArray ba; -/* PIINTROSPECTION_THREADS->mutex.lock(); - ba << appname << *(PIINTROSPECTION_CONTAINERS) << PIINTROSPECTION_THREADS->threads.values(); - PIINTROSPECTION_THREADS->mutex.unlock();*/ - //piCout << "send" << appname; + ba << PIIntrospection::sign; + ba.append(cs.data()); send("__introspection_client__", ba); } diff --git a/src_main/introspection/piintrospection_server.h b/src_main/introspection/piintrospection_server.h index fa1a2a26..2818f14b 100644 --- a/src_main/introspection/piintrospection_server.h +++ b/src_main/introspection/piintrospection_server.h @@ -21,21 +21,35 @@ #define PIINTROSPECTION_SERVER_H #include "pipeer.h" -#include "pimutex.h" -class __PIIntrospectionServer__; +class PIIntrospectionServer; +#define PIINTROSPECTION_SERVER (PIIntrospectionServer::instance()) + +#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION) +# define PIINTROSPECTION_START PIINTROSPECTION_SERVER->start(); +#else +# define PIINTROSPECTION_START +#endif class PIP_EXPORT PIIntrospectionServer: public PIPeer { PIOBJECT_SUBCLASS(PIIntrospectionServer, PIPeer) - friend class __PIIntrospectionServer__; - PIIntrospectionServer(); public: - PIString appname; + static PIIntrospectionServer * instance() {static PIIntrospectionServer ret; return &ret;} + + void start(); + private: + PIIntrospectionServer(); + ~PIIntrospectionServer(); + NO_COPY_CLASS(PIIntrospectionServer) + EVENT_HANDLER(void, timerEvent); PIString genName(); + + PRIVATE_DECLARATION PITimer itimer; + }; #endif // PIINTROSPECTION_SERVER_H diff --git a/src_main/introspection/piintrospection_server_p.cpp b/src_main/introspection/piintrospection_server_p.cpp new file mode 100644 index 00000000..b6a7cd67 --- /dev/null +++ b/src_main/introspection/piintrospection_server_p.cpp @@ -0,0 +1,208 @@ +/* + PIP - Platform Independent Primitives + Introspection module - Base server structs + Copyright (C) 2019 Ivan Pelipenko peri4ko@yandex.ru + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "piintrospection_server_p.h" +#include "pichunkstream.h" +#include "piinit.h" +#include "pisysteminfo.h" +#include "piobject.h" + + +const uint PIIntrospection::sign = 0x0F1C2B3A; + + + + +PIIntrospection::ProcessInfo::ProcessInfo() { + processorsCount = 0; +} + + + + +PIIntrospection::ObjectInfo::ObjectInfo() { + queued_events = 0; +} + + + + +PIIntrospection::ProcessInfo PIIntrospection::getInfo() { + PIIntrospection::ProcessInfo ret; + + PISystemInfo * si = PISystemInfo::instance(); + ret.architecture = si->architecture; + ret.execCommand = si->execCommand; + ret.execDateTime = si->execDateTime; + ret.hostname = si->hostname; + ret.OS_name = si->OS_name; + ret.OS_version = si->OS_version; + ret.processorsCount = si->processorsCount; + ret.user = si->user; + + ret.build_options = PIInit::buildOptions(); + + return ret; +} + + +PIVector PIIntrospection::getObjects() { + PIVector ret; + PIObject::mutexObjects().lock(); + const PIVector & ao(PIObject::objects()); + ret.resize(ao.size()); + for (int i = 0; i < ao.size_s(); ++i) { + ret[i].classname = PIStringAscii(ao[i]->className()); + ret[i].name = ao[i]->name(); + ret[i].properties = ao[i]->properties_; + ret[i].parents = ao[i]->scopeList(); + ao[i]->mutex_queue.lock(); + ret[i].queued_events = ao[i]->events_queue.size_s(); + ao[i]->mutex_queue.unlock(); + } + PIObject::mutexObjects().unlock(); + return ret; +} + + +PIByteArray & operator <<(PIByteArray & s, const std::unordered_map & v) { + PIMap m; + for (typename std::unordered_map::const_iterator i = v.cbegin(); i != v.cend(); ++i) { + m[i->first] = i->second; + } + s << m; + return s; +} + + +PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::ProcessInfo & v) { + PIChunkStream cs; + cs.add(1, v.architecture).add(2, v.execCommand).add(3, v.execDateTime).add(4, v.hostname).add(5, v.OS_name) + .add(6, v.OS_version).add(7, v.processorsCount).add(8, v.user).add(9, v.build_options); + b << cs.data(); + return b; +} + + +PIByteArray & operator >>(PIByteArray & b, PIIntrospection::ProcessInfo & v) { + PIByteArray csba; b >> csba; + PIChunkStream cs(csba); + while (!cs.atEnd()) { + switch (cs.read()) { + case 1: cs.get(v.architecture); break; + case 2: cs.get(v.execCommand); break; + case 3: cs.get(v.execDateTime); break; + case 4: cs.get(v.hostname); break; + case 5: cs.get(v.OS_name); break; + case 6: cs.get(v.OS_version); break; + case 7: cs.get(v.processorsCount); break; + case 8: cs.get(v.user); break; + case 9: cs.get(v.build_options); break; + default: break; + } + } + return b; +} + + +PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::ObjectInfo & v) { + PIChunkStream cs; + cs.add(1, v.classname).add(2, v.name).add(3, v.parents).add(4, v.properties).add(5, v.queued_events); + b << cs.data(); + return b; +} + + +PIByteArray & operator >>(PIByteArray & b, PIIntrospection::ObjectInfo & v) { + PIByteArray csba; b >> csba; + PIChunkStream cs(csba); + while (!cs.atEnd()) { + switch (cs.read()) { + case 1: cs.get(v.classname); break; + case 2: cs.get(v.name); break; + case 3: cs.get(v.parents); break; + case 4: cs.get(v.properties); break; + case 5: cs.get(v.queued_events); break; + default: break; + } + } + return b; +} + + + + +PIByteArray PIIntrospection::packInfo() { + PIByteArray ret; + ret << getInfo(); + return ret; +} + + +void PIIntrospection::unpackInfo(PIByteArray & ba, PIIntrospection::ProcessInfo & info) { + ba >> info; +} + + +PIByteArray PIIntrospection::packContainers() { + PIByteArray ret; + PIIntrospectionContainers * p = PIINTROSPECTION_CONTAINERS->p; + p->mutex.lock(); + std::unordered_map data = p->data; + std::unordered_map typenames = p->typenames; + p->mutex.unlock(); + ret << data << typenames; + return ret; +} + + +void PIIntrospection::unpackContainers(PIByteArray & ba, PIMap & data, PIMap & typenames) { + data.clear(); + typenames.clear(); + ba >> data >> typenames; +} + + +PIByteArray PIIntrospection::packThreads() { + PIByteArray ret; + PIIntrospectionThreads * p = PIINTROSPECTION_THREADS->p; + p->mutex.lock(); + ret << p->threads.values(); + p->mutex.unlock(); + return ret; +} + + +void PIIntrospection::unpackThreads(PIByteArray & ba, PIVector & threads) { + threads.clear(); + ba >> threads; +} + + +PIByteArray PIIntrospection::packObjects() { + PIByteArray ret; + ret << getObjects(); + return ret; +} + + +void PIIntrospection::unpackObjects(PIByteArray & ba, PIVector & objects) { + objects.clear(); + ba >> objects; +} diff --git a/src_main/introspection/piintrospection_server_p.h b/src_main/introspection/piintrospection_server_p.h new file mode 100644 index 00000000..686d6506 --- /dev/null +++ b/src_main/introspection/piintrospection_server_p.h @@ -0,0 +1,79 @@ +/* + PIP - Platform Independent Primitives + Introspection module - Base server structs + Copyright (C) 2019 Ivan Pelipenko peri4ko@yandex.ru + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef PIINTROSPECTION_SERVER_P_H +#define PIINTROSPECTION_SERVER_P_H + +#include "piintrospection_containers.h" +#include "piintrospection_containers_p.h" +#include "piintrospection_threads.h" +#include "piintrospection_threads_p.h" +#include "pitime.h" + + +class PIIntrospection { +public: + + struct ProcessInfo { + ProcessInfo(); + + PIString execCommand, hostname, user, OS_name, OS_version, architecture; + PIDateTime execDateTime; + int processorsCount; + + PIStringList build_options; + }; + + struct ObjectInfo { + ObjectInfo(); + + PIString classname, name; + PIStringList parents; + PIMap properties; + int queued_events; + }; + + static const uint sign; + + static ProcessInfo getInfo(); + static PIVector getObjects(); + + static PIByteArray packInfo(); + static void unpackInfo(PIByteArray & ba, ProcessInfo & info); + + static PIByteArray packContainers(); + static void unpackContainers(PIByteArray & ba, PIMap & data, PIMap & typenames); + + static PIByteArray packThreads(); + static void unpackThreads(PIByteArray & ba, PIVector & threads); + + static PIByteArray packObjects(); + static void unpackObjects(PIByteArray & ba, PIVector & objects); + +}; + +PIByteArray & operator <<(PIByteArray & s, const std::unordered_map & v); + +PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::ProcessInfo & v); +PIByteArray & operator >>(PIByteArray & b, PIIntrospection::ProcessInfo & v); + +PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::ObjectInfo & v); +PIByteArray & operator >>(PIByteArray & b, PIIntrospection::ObjectInfo & v); + +#endif // PIINTROSPECTION_SERVER_P_H diff --git a/src_main/introspection/piintrospection_threads.h b/src_main/introspection/piintrospection_threads.h index 57690dd9..27d85a48 100644 --- a/src_main/introspection/piintrospection_threads.h +++ b/src_main/introspection/piintrospection_threads.h @@ -45,6 +45,7 @@ class PIIntrospectionThreads; #endif class PIP_EXPORT PIIntrospectionThreadsInterface { + friend class PIIntrospection; public: __PIINTROSPECTION_SINGLETON__(Threads) diff --git a/utils/system_daemon/main.cpp b/utils/system_daemon/main.cpp index bd6f1eaf..9a8b449e 100755 --- a/utils/system_daemon/main.cpp +++ b/utils/system_daemon/main.cpp @@ -25,6 +25,7 @@ #include "file_manager.h" #include "daemon.h" #include "shared.h" +#include "piintrospection_server.h" class _Init { public: @@ -337,6 +338,7 @@ void usage() { int main(int argc, char * argv[]) { + PIINTROSPECTION_START //piDebug = false; PICLI cli(argc, argv); cli.addArgument("help"); @@ -388,7 +390,6 @@ int main(int argc, char * argv[]) { PIProcess::execIndependent(exe, args); return 0; } -/// PIINTROSPECTION_START //cli.addArgument(""); screen = new PIScreen(false); screen->setMouseEnabled(true);