code format
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module - base macros and types
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module - base macros and types
|
||||
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/>.
|
||||
*/
|
||||
//! \defgroup Introspection Introspection
|
||||
//! \~\brief
|
||||
@@ -61,13 +61,12 @@ class PIIntrospection;
|
||||
class PIIntrospectionServer;
|
||||
|
||||
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
|
||||
#define __PIINTROSPECTION_SINGLETON_H__(T) \
|
||||
static PIIntrospection##T##Interface * instance();
|
||||
# define __PIINTROSPECTION_SINGLETON_H__(T) static PIIntrospection##T##Interface * instance();
|
||||
|
||||
#define __PIINTROSPECTION_SINGLETON_CPP__(T) \
|
||||
PIIntrospection##T##Interface * PIIntrospection##T##Interface::instance() {\
|
||||
static PIIntrospection##T##Interface ret;\
|
||||
return &ret;\
|
||||
}
|
||||
# define __PIINTROSPECTION_SINGLETON_CPP__(T) \
|
||||
PIIntrospection##T##Interface * PIIntrospection##T##Interface::instance() { \
|
||||
static PIIntrospection##T##Interface ret; \
|
||||
return &ret; \
|
||||
}
|
||||
#endif // PIP_INTROSPECTION
|
||||
#endif // PIINTROSPECTION_BASE_H
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module - interface for containers
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module - interface for containers
|
||||
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 "piintrospection_containers.h"
|
||||
|
||||
PIIntrospectionContainersType::~PIIntrospectionContainersType() {
|
||||
if (has_demangled) {
|
||||
//free((void*)demangled);
|
||||
// free((void*)demangled);
|
||||
has_demangled = false;
|
||||
}
|
||||
}
|
||||
@@ -29,21 +29,23 @@ PIIntrospectionContainersType::~PIIntrospectionContainersType() {
|
||||
|
||||
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
|
||||
|
||||
#include "piintrospection_containers_p.h"
|
||||
# include "piintrospection_containers_p.h"
|
||||
|
||||
__PIINTROSPECTION_SINGLETON_CPP__(Containers)
|
||||
|
||||
#ifdef CC_GCC
|
||||
# include <cxxabi.h>
|
||||
# ifdef CC_GCC
|
||||
# include <cxxabi.h>
|
||||
const char * demangle(const char * name) {
|
||||
int status = -4;
|
||||
char * res = abi::__cxa_demangle(name, NULL, NULL, &status);
|
||||
if (status == 0) return res;
|
||||
return name;
|
||||
}
|
||||
#else
|
||||
const char * demangle(const char * name) {return name;}
|
||||
#endif
|
||||
# else
|
||||
const char * demangle(const char * name) {
|
||||
return name;
|
||||
}
|
||||
# endif
|
||||
|
||||
|
||||
void PIIntrospectionContainersType::finish() {
|
||||
@@ -53,11 +55,10 @@ void PIIntrospectionContainersType::finish() {
|
||||
return;
|
||||
}
|
||||
size_t l = strlen(name);
|
||||
if (l > 0)
|
||||
id = piHashData((const uchar*)name, int(l));
|
||||
demangled = demangle(name);
|
||||
if (l > 0) id = piHashData((const uchar *)name, int(l));
|
||||
demangled = demangle(name);
|
||||
has_demangled = name != demangled;
|
||||
//printf("create typeinfo for %s -> %s\n", name, demangled);
|
||||
// printf("create typeinfo for %s -> %s\n", name, demangled);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module - interface for containers
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module - interface for containers
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef PIINTROSPECTION_CONTAINERS_H
|
||||
@@ -58,11 +58,11 @@ private:
|
||||
# define PIINTROSPECTION_CONTAINERS (PIIntrospectionContainersInterface::instance())
|
||||
|
||||
// clang-format off
|
||||
# define PIINTROSPECTION_CONTAINER_NEW (t, isz) PIINTROSPECTION_CONTAINERS->containerNew (PIIntrospectionContainersTypeInfo<t>::get(), isz);
|
||||
# define PIINTROSPECTION_CONTAINER_DELETE(t ) PIINTROSPECTION_CONTAINERS->containerDelete(PIIntrospectionContainersTypeInfo<t>::get() );
|
||||
# define PIINTROSPECTION_CONTAINER_ALLOC (t, cnt) PIINTROSPECTION_CONTAINERS->containerAlloc (PIIntrospectionContainersTypeInfo<t>::get(), cnt);
|
||||
# define PIINTROSPECTION_CONTAINER_FREE (t, cnt) PIINTROSPECTION_CONTAINERS->containerFree (PIIntrospectionContainersTypeInfo<t>::get(), cnt);
|
||||
# define PIINTROSPECTION_CONTAINER_USED (t, cnt) PIINTROSPECTION_CONTAINERS->containerUsed (PIIntrospectionContainersTypeInfo<t>::get(), cnt);
|
||||
# define PIINTROSPECTION_CONTAINER_NEW(t, isz) PIINTROSPECTION_CONTAINERS->containerNew (PIIntrospectionContainersTypeInfo<t>::get(), isz);
|
||||
# define PIINTROSPECTION_CONTAINER_DELETE(t) PIINTROSPECTION_CONTAINERS->containerDelete(PIIntrospectionContainersTypeInfo<t>::get() );
|
||||
# define PIINTROSPECTION_CONTAINER_ALLOC(t, cnt) PIINTROSPECTION_CONTAINERS->containerAlloc (PIIntrospectionContainersTypeInfo<t>::get(), cnt);
|
||||
# define PIINTROSPECTION_CONTAINER_FREE(t, cnt) PIINTROSPECTION_CONTAINERS->containerFree (PIIntrospectionContainersTypeInfo<t>::get(), cnt);
|
||||
# define PIINTROSPECTION_CONTAINER_USED(t, cnt) PIINTROSPECTION_CONTAINERS->containerUsed (PIIntrospectionContainersTypeInfo<t>::get(), cnt);
|
||||
# define PIINTROSPECTION_CONTAINER_UNUSED(t, cnt) PIINTROSPECTION_CONTAINERS->containerUnused(PIIntrospectionContainersTypeInfo<t>::get(), cnt);
|
||||
// clang-format on
|
||||
|
||||
|
||||
@@ -1,44 +1,46 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module - implementation of containers
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module - implementation of containers
|
||||
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 "piintrospection_containers_p.h"
|
||||
|
||||
#include "piintrospection_containers.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
PIIntrospectionContainers::PIIntrospectionContainers() {
|
||||
//printf("PIIntrospectionContainers %p\n", this);
|
||||
// printf("PIIntrospectionContainers %p\n", this);
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospectionContainers::containerNew(const PIIntrospectionContainersType & ti, uint isz) {
|
||||
PISpinlockLocker _ml(mutex);
|
||||
//printf("containerNew lock\n");
|
||||
// printf("containerNew lock\n");
|
||||
PIIntrospectionContainersType & t(types[ti.id]);
|
||||
_Type & d(data[ti.id]);
|
||||
if (!t.inited) {
|
||||
t = ti;
|
||||
d.id = ti.id;
|
||||
t = ti;
|
||||
d.id = ti.id;
|
||||
d.item_size = isz;
|
||||
}
|
||||
d.count++;
|
||||
//printf("containerNew unlock\n");
|
||||
// printf("containerNew unlock\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +51,7 @@ void PIIntrospectionContainers::containerDelete(const PIIntrospectionContainersT
|
||||
|
||||
|
||||
void PIIntrospectionContainers::containerAlloc(const PIIntrospectionContainersType & ti, ullong cnt) {
|
||||
//printf(" alloc %s %d\n", tn, cnt);
|
||||
// printf(" alloc %s %d\n", tn, cnt);
|
||||
if (cnt == 0) return;
|
||||
PISpinlockLocker _ml(mutex);
|
||||
data[ti.id].allocated += cnt;
|
||||
@@ -57,7 +59,7 @@ void PIIntrospectionContainers::containerAlloc(const PIIntrospectionContainersTy
|
||||
|
||||
|
||||
void PIIntrospectionContainers::containerFree(const PIIntrospectionContainersType & ti, ullong cnt) {
|
||||
//printf(" free %s %d\n", tn, cnt);
|
||||
// printf(" free %s %d\n", tn, cnt);
|
||||
if (cnt == 0) return;
|
||||
PISpinlockLocker _ml(mutex);
|
||||
data[ti.id].allocated -= cnt;
|
||||
@@ -65,7 +67,7 @@ void PIIntrospectionContainers::containerFree(const PIIntrospectionContainersTyp
|
||||
|
||||
|
||||
void PIIntrospectionContainers::containerUsed(const PIIntrospectionContainersType & ti, ullong cnt) {
|
||||
//printf(" used %s %d\n", tn, cnt);
|
||||
// printf(" used %s %d\n", tn, cnt);
|
||||
if (cnt == 0) return;
|
||||
PISpinlockLocker _ml(mutex);
|
||||
data[ti.id].used += cnt;
|
||||
@@ -73,7 +75,7 @@ void PIIntrospectionContainers::containerUsed(const PIIntrospectionContainersTyp
|
||||
|
||||
|
||||
void PIIntrospectionContainers::containerUnused(const PIIntrospectionContainersType & ti, ullong cnt) {
|
||||
//printf("unused %s %d\n", tn, cnt);
|
||||
// printf("unused %s %d\n", tn, cnt);
|
||||
if (cnt == 0) return;
|
||||
PISpinlockLocker _ml(mutex);
|
||||
data[ti.id].used -= cnt;
|
||||
@@ -84,14 +86,14 @@ PIVector<PIIntrospectionContainers::TypeInfo> PIIntrospectionContainers::getInfo
|
||||
PIVector<PIIntrospectionContainers::TypeInfo> ret;
|
||||
mutex.lock();
|
||||
std::map<uint, PIIntrospectionContainers::_Type> d = data;
|
||||
std::map<uint, PIIntrospectionContainersType> t = types;
|
||||
std::map<uint, PIIntrospectionContainersType> t = types;
|
||||
mutex.unlock();
|
||||
ret.reserve(t.size());
|
||||
for (typename std::map<uint, PIIntrospectionContainersType>::const_iterator i = t.begin(); i != t.end(); ++i) {
|
||||
ret.push_back(TypeInfo());
|
||||
TypeInfo & ti(ret.back());
|
||||
_Type & _t(d[i->first]);
|
||||
memcpy((void*)&ti, (const void*)&_t, sizeof(_t));
|
||||
memcpy((void *)&ti, (const void *)&_t, sizeof(_t));
|
||||
ti.name = PIStringAscii(i->second.demangled);
|
||||
}
|
||||
return ret;
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module - implementation of containers
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module - implementation of containers
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef PIINTROSPECTION_CONTAINERS_P_H
|
||||
|
||||
@@ -1,111 +1,108 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module
|
||||
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 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/>.
|
||||
*/
|
||||
|
||||
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
|
||||
|
||||
#include "piintrospection_server.h"
|
||||
#include "piintrospection_server_p.h"
|
||||
#include "piprocess.h"
|
||||
#include "pichunkstream.h"
|
||||
|
||||
|
||||
PRIVATE_DEFINITION_START(PIIntrospectionServer)
|
||||
PIIntrospection::ProcessInfo process_info;
|
||||
PRIVATE_DEFINITION_END(PIIntrospectionServer)
|
||||
|
||||
|
||||
PIIntrospectionServer::PIIntrospectionServer(): PIPeer(genName()) {
|
||||
PRIVATE->process_info = PIIntrospection::getInfo();
|
||||
sysmon = 0;
|
||||
}
|
||||
|
||||
|
||||
PIIntrospectionServer::~PIIntrospectionServer() {
|
||||
PIPeer::stop();
|
||||
if (sysmon)
|
||||
if (sysmon->property("__iserver__").toBool())
|
||||
delete sysmon;
|
||||
sysmon = 0;
|
||||
}
|
||||
|
||||
|
||||
PIIntrospectionServer * PIIntrospectionServer::instance() {
|
||||
static PIIntrospectionServer ret;
|
||||
return &ret;
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospectionServer::start(const PIString & server_name) {
|
||||
if (!sysmon) {
|
||||
sysmon = PISystemMonitor::Pool::instance()->getByPID(PIProcess::currentPID());
|
||||
if (sysmon) {
|
||||
piCoutObj << "using existing sysmon";
|
||||
CONNECT1(void, PIObject *, sysmon, deleted, this, sysmonDeleted);
|
||||
} else {
|
||||
piCoutObj << "create own sysmon";
|
||||
sysmon = new PISystemMonitor();
|
||||
sysmon->setProperty("__iserver__", true);
|
||||
sysmon->startOnSelf();
|
||||
}
|
||||
}
|
||||
changeName(server_name + genName());
|
||||
PIPeer::start();
|
||||
}
|
||||
|
||||
|
||||
PIString PIIntrospectionServer::genName() {
|
||||
randomize();
|
||||
return "__introspection__server_" + PIString::fromNumber(randomi() % 1000);
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospectionServer::dataReceived(const PIString & from, const PIByteArray & data) {
|
||||
if (data.size() < 8) return;
|
||||
PIByteArray rba(data);
|
||||
uint _sign(0); rba >> _sign;
|
||||
if (_sign != PIIntrospection::sign) return;
|
||||
PIIntrospection::RequiredInfo ri;
|
||||
rba >> ri;
|
||||
PIChunkStream cs;
|
||||
if (ri.types[PIIntrospection::itInfo])
|
||||
cs.add(PIIntrospection::itInfo, PIIntrospection::packInfo());
|
||||
if (ri.types[PIIntrospection::itProcStat]) {
|
||||
sysmon_mutex.lock();
|
||||
cs.add(PIIntrospection::itProcStat, PIIntrospection::packProcStat(sysmon));
|
||||
sysmon_mutex.unlock();
|
||||
}
|
||||
if (ri.types[PIIntrospection::itContainers])
|
||||
cs.add(PIIntrospection::itContainers, PIIntrospection::packContainers());
|
||||
if (ri.types[PIIntrospection::itObjects])
|
||||
cs.add(PIIntrospection::itObjects, PIIntrospection::packObjects());
|
||||
if (ri.types[PIIntrospection::itThreads])
|
||||
cs.add(PIIntrospection::itThreads, PIIntrospection::packThreads());
|
||||
PIByteArray ba;
|
||||
ba << PIIntrospection::sign;
|
||||
ba.append(cs.data());
|
||||
send(from, ba);
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospectionServer::sysmonDeleted() {
|
||||
PIMutexLocker _ml(sysmon_mutex);
|
||||
sysmon = 0;
|
||||
}
|
||||
|
||||
#endif // PIP_INTROSPECTION
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module
|
||||
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 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/>.
|
||||
*/
|
||||
|
||||
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
|
||||
|
||||
# include "piintrospection_server.h"
|
||||
|
||||
# include "pichunkstream.h"
|
||||
# include "piintrospection_server_p.h"
|
||||
# include "piprocess.h"
|
||||
|
||||
|
||||
PRIVATE_DEFINITION_START(PIIntrospectionServer)
|
||||
PIIntrospection::ProcessInfo process_info;
|
||||
PRIVATE_DEFINITION_END(PIIntrospectionServer)
|
||||
|
||||
|
||||
PIIntrospectionServer::PIIntrospectionServer(): PIPeer(genName()) {
|
||||
PRIVATE->process_info = PIIntrospection::getInfo();
|
||||
sysmon = 0;
|
||||
}
|
||||
|
||||
|
||||
PIIntrospectionServer::~PIIntrospectionServer() {
|
||||
PIPeer::stop();
|
||||
if (sysmon)
|
||||
if (sysmon->property("__iserver__").toBool()) delete sysmon;
|
||||
sysmon = 0;
|
||||
}
|
||||
|
||||
|
||||
PIIntrospectionServer * PIIntrospectionServer::instance() {
|
||||
static PIIntrospectionServer ret;
|
||||
return &ret;
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospectionServer::start(const PIString & server_name) {
|
||||
if (!sysmon) {
|
||||
sysmon = PISystemMonitor::Pool::instance()->getByPID(PIProcess::currentPID());
|
||||
if (sysmon) {
|
||||
piCoutObj << "using existing sysmon";
|
||||
CONNECT1(void, PIObject *, sysmon, deleted, this, sysmonDeleted);
|
||||
} else {
|
||||
piCoutObj << "create own sysmon";
|
||||
sysmon = new PISystemMonitor();
|
||||
sysmon->setProperty("__iserver__", true);
|
||||
sysmon->startOnSelf();
|
||||
}
|
||||
}
|
||||
changeName(server_name + genName());
|
||||
PIPeer::start();
|
||||
}
|
||||
|
||||
|
||||
PIString PIIntrospectionServer::genName() {
|
||||
randomize();
|
||||
return "__introspection__server_" + PIString::fromNumber(randomi() % 1000);
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospectionServer::dataReceived(const PIString & from, const PIByteArray & data) {
|
||||
if (data.size() < 8) return;
|
||||
PIByteArray rba(data);
|
||||
uint _sign(0);
|
||||
rba >> _sign;
|
||||
if (_sign != PIIntrospection::sign) return;
|
||||
PIIntrospection::RequiredInfo ri;
|
||||
rba >> ri;
|
||||
PIChunkStream cs;
|
||||
if (ri.types[PIIntrospection::itInfo]) cs.add(PIIntrospection::itInfo, PIIntrospection::packInfo());
|
||||
if (ri.types[PIIntrospection::itProcStat]) {
|
||||
sysmon_mutex.lock();
|
||||
cs.add(PIIntrospection::itProcStat, PIIntrospection::packProcStat(sysmon));
|
||||
sysmon_mutex.unlock();
|
||||
}
|
||||
if (ri.types[PIIntrospection::itContainers]) cs.add(PIIntrospection::itContainers, PIIntrospection::packContainers());
|
||||
if (ri.types[PIIntrospection::itObjects]) cs.add(PIIntrospection::itObjects, PIIntrospection::packObjects());
|
||||
if (ri.types[PIIntrospection::itThreads]) cs.add(PIIntrospection::itThreads, PIIntrospection::packThreads());
|
||||
PIByteArray ba;
|
||||
ba << PIIntrospection::sign;
|
||||
ba.append(cs.data());
|
||||
send(from, ba);
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospectionServer::sysmonDeleted() {
|
||||
PIMutexLocker _ml(sysmon_mutex);
|
||||
sysmon = 0;
|
||||
}
|
||||
|
||||
#endif // PIP_INTROSPECTION
|
||||
|
||||
@@ -1,77 +1,77 @@
|
||||
/*! \file piintrospection_server.h
|
||||
* \ingroup Introspection
|
||||
* \~\brief
|
||||
* \~english Introspection server
|
||||
* \~russian Сервер интроспекции
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module
|
||||
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 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/>.
|
||||
*/
|
||||
|
||||
#ifndef PIINTROSPECTION_SERVER_H
|
||||
#define PIINTROSPECTION_SERVER_H
|
||||
|
||||
#ifdef DOXYGEN
|
||||
|
||||
//! \ingroup Introspection
|
||||
//! \~english Start introspection server with name "name"
|
||||
//! \~russian Запускает сервер интроспекции с именем "name"
|
||||
# define PIINTROSPECTION_START(name)
|
||||
|
||||
#else
|
||||
|
||||
# if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
|
||||
|
||||
#include "pipeer.h"
|
||||
|
||||
class PIIntrospectionServer;
|
||||
class PISystemMonitor;
|
||||
|
||||
# define PIINTROSPECTION_SERVER (PIIntrospectionServer::instance())
|
||||
# define PIINTROSPECTION_START(name) PIINTROSPECTION_SERVER->start(#name);
|
||||
|
||||
class PIP_EXPORT PIIntrospectionServer: public PIPeer {
|
||||
PIOBJECT_SUBCLASS(PIIntrospectionServer, PIPeer);
|
||||
public:
|
||||
static PIIntrospectionServer * instance();
|
||||
|
||||
void start(const PIString & server_name);
|
||||
|
||||
private:
|
||||
PIIntrospectionServer();
|
||||
~PIIntrospectionServer();
|
||||
NO_COPY_CLASS(PIIntrospectionServer);
|
||||
|
||||
PIString genName();
|
||||
virtual void dataReceived(const PIString & from, const PIByteArray & data);
|
||||
EVENT_HANDLER(void, sysmonDeleted);
|
||||
|
||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||
PITimer itimer;
|
||||
PISystemMonitor * sysmon;
|
||||
PIMutex sysmon_mutex;
|
||||
|
||||
};
|
||||
|
||||
# else
|
||||
# define PIINTROSPECTION_START(name)
|
||||
# endif
|
||||
|
||||
#endif // DOXYGEN
|
||||
|
||||
#endif // PIINTROSPECTION_SERVER_H
|
||||
/*! \file piintrospection_server.h
|
||||
* \ingroup Introspection
|
||||
* \~\brief
|
||||
* \~english Introspection server
|
||||
* \~russian Сервер интроспекции
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module
|
||||
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 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/>.
|
||||
*/
|
||||
|
||||
#ifndef PIINTROSPECTION_SERVER_H
|
||||
#define PIINTROSPECTION_SERVER_H
|
||||
|
||||
#ifdef DOXYGEN
|
||||
|
||||
//! \ingroup Introspection
|
||||
//! \~english Start introspection server with name "name"
|
||||
//! \~russian Запускает сервер интроспекции с именем "name"
|
||||
# define PIINTROSPECTION_START(name)
|
||||
|
||||
#else
|
||||
|
||||
# if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
|
||||
|
||||
# include "pipeer.h"
|
||||
|
||||
class PIIntrospectionServer;
|
||||
class PISystemMonitor;
|
||||
|
||||
# define PIINTROSPECTION_SERVER (PIIntrospectionServer::instance())
|
||||
# define PIINTROSPECTION_START(name) PIINTROSPECTION_SERVER->start(#name);
|
||||
|
||||
class PIP_EXPORT PIIntrospectionServer: public PIPeer {
|
||||
PIOBJECT_SUBCLASS(PIIntrospectionServer, PIPeer);
|
||||
|
||||
public:
|
||||
static PIIntrospectionServer * instance();
|
||||
|
||||
void start(const PIString & server_name);
|
||||
|
||||
private:
|
||||
PIIntrospectionServer();
|
||||
~PIIntrospectionServer();
|
||||
NO_COPY_CLASS(PIIntrospectionServer);
|
||||
|
||||
PIString genName();
|
||||
virtual void dataReceived(const PIString & from, const PIByteArray & data);
|
||||
EVENT_HANDLER(void, sysmonDeleted);
|
||||
|
||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||
PITimer itimer;
|
||||
PISystemMonitor * sysmon;
|
||||
PIMutex sysmon_mutex;
|
||||
};
|
||||
|
||||
# else
|
||||
# define PIINTROSPECTION_START(name)
|
||||
# endif
|
||||
|
||||
#endif // DOXYGEN
|
||||
|
||||
#endif // PIINTROSPECTION_SERVER_H
|
||||
|
||||
@@ -1,171 +1,170 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module - Base server structs
|
||||
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 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/>.
|
||||
*/
|
||||
|
||||
#include "piintrospection_server_p.h"
|
||||
#include "pichunkstream.h"
|
||||
#include "piinit.h"
|
||||
#include "pisysteminfo.h"
|
||||
#include "piobject.h"
|
||||
|
||||
|
||||
const uint PIIntrospection::sign = 0x0F1C2B3A;
|
||||
|
||||
|
||||
PIIntrospection::RequiredInfo::RequiredInfo() {
|
||||
types = itInfo;
|
||||
}
|
||||
|
||||
|
||||
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::ObjectInfo> PIIntrospection::getObjects() {
|
||||
PIVector<PIIntrospection::ObjectInfo> ret;
|
||||
PIObject::mutexObjects().lock();
|
||||
const PIVector<PIObject * > & 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 PIIntrospection::packInfo() {
|
||||
PIByteArray ret;
|
||||
ret << getInfo();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospection::unpackInfo(PIByteArray & ba, PIIntrospection::ProcessInfo & info) {
|
||||
ba >> info;
|
||||
}
|
||||
|
||||
|
||||
PIByteArray PIIntrospection::packProcStat(PISystemMonitor * sm) {
|
||||
ProcessStat ps;
|
||||
if (sm) {
|
||||
ps.proc = sm->statistic();
|
||||
ps.threads = sm->threadsStatistic();
|
||||
}
|
||||
PIByteArray ret;
|
||||
ret << ps.proc << ps.threads;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospection::unpackProcStat(PIByteArray & ba, PIIntrospection::ProcessStat & info) {
|
||||
ba >> info.proc >> info.threads;
|
||||
}
|
||||
|
||||
|
||||
PIByteArray PIIntrospection::packContainers() {
|
||||
PIByteArray ret;
|
||||
PIVector<PIIntrospectionContainers::TypeInfo> data;
|
||||
PIIntrospectionContainers * p = 0;
|
||||
#ifdef PIP_INTROSPECTION
|
||||
p = PIINTROSPECTION_CONTAINERS->p;
|
||||
#endif
|
||||
if (p) {
|
||||
data = p->getInfo();
|
||||
}
|
||||
ret << data;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospection::unpackContainers(PIByteArray & ba, PIVector<PIIntrospectionContainers::TypeInfo> & data) {
|
||||
data.clear();
|
||||
ba >> data;
|
||||
}
|
||||
|
||||
|
||||
PIByteArray PIIntrospection::packThreads() {
|
||||
PIByteArray ret;
|
||||
PIIntrospectionThreads * p = 0;
|
||||
#ifdef PIP_INTROSPECTION
|
||||
p = PIINTROSPECTION_THREADS->p;
|
||||
#endif
|
||||
if (p) {
|
||||
p->mutex.lock();
|
||||
PIMap<PIThread*, PIIntrospectionThreads::ThreadInfo> & tm(p->threads);
|
||||
auto it = tm.makeIterator();
|
||||
while (it.next()) {
|
||||
it.value().classname = PIStringAscii(it.key()->className());
|
||||
it.value().name = it.key()->name();
|
||||
}
|
||||
ret << tm.values();
|
||||
p->mutex.unlock();
|
||||
} else {
|
||||
ret << PIVector<PIIntrospectionThreads::ThreadInfo>();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospection::unpackThreads(PIByteArray & ba, PIVector<PIIntrospectionThreads::ThreadInfo> & threads) {
|
||||
threads.clear();
|
||||
ba >> threads;
|
||||
}
|
||||
|
||||
|
||||
PIByteArray PIIntrospection::packObjects() {
|
||||
PIByteArray ret;
|
||||
ret << getObjects();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospection::unpackObjects(PIByteArray & ba, PIVector<PIIntrospection::ObjectInfo> & objects) {
|
||||
objects.clear();
|
||||
ba >> objects;
|
||||
}
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module - Base server structs
|
||||
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 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/>.
|
||||
*/
|
||||
|
||||
#include "piintrospection_server_p.h"
|
||||
|
||||
#include "pichunkstream.h"
|
||||
#include "piinit.h"
|
||||
#include "piobject.h"
|
||||
#include "pisysteminfo.h"
|
||||
|
||||
|
||||
const uint PIIntrospection::sign = 0x0F1C2B3A;
|
||||
|
||||
|
||||
PIIntrospection::RequiredInfo::RequiredInfo() {
|
||||
types = itInfo;
|
||||
}
|
||||
|
||||
|
||||
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::ObjectInfo> PIIntrospection::getObjects() {
|
||||
PIVector<PIIntrospection::ObjectInfo> ret;
|
||||
PIObject::mutexObjects().lock();
|
||||
const PIVector<PIObject *> & 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 PIIntrospection::packInfo() {
|
||||
PIByteArray ret;
|
||||
ret << getInfo();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospection::unpackInfo(PIByteArray & ba, PIIntrospection::ProcessInfo & info) {
|
||||
ba >> info;
|
||||
}
|
||||
|
||||
|
||||
PIByteArray PIIntrospection::packProcStat(PISystemMonitor * sm) {
|
||||
ProcessStat ps;
|
||||
if (sm) {
|
||||
ps.proc = sm->statistic();
|
||||
ps.threads = sm->threadsStatistic();
|
||||
}
|
||||
PIByteArray ret;
|
||||
ret << ps.proc << ps.threads;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospection::unpackProcStat(PIByteArray & ba, PIIntrospection::ProcessStat & info) {
|
||||
ba >> info.proc >> info.threads;
|
||||
}
|
||||
|
||||
|
||||
PIByteArray PIIntrospection::packContainers() {
|
||||
PIByteArray ret;
|
||||
PIVector<PIIntrospectionContainers::TypeInfo> data;
|
||||
PIIntrospectionContainers * p = 0;
|
||||
#ifdef PIP_INTROSPECTION
|
||||
p = PIINTROSPECTION_CONTAINERS->p;
|
||||
#endif
|
||||
if (p) {
|
||||
data = p->getInfo();
|
||||
}
|
||||
ret << data;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospection::unpackContainers(PIByteArray & ba, PIVector<PIIntrospectionContainers::TypeInfo> & data) {
|
||||
data.clear();
|
||||
ba >> data;
|
||||
}
|
||||
|
||||
|
||||
PIByteArray PIIntrospection::packThreads() {
|
||||
PIByteArray ret;
|
||||
PIIntrospectionThreads * p = 0;
|
||||
#ifdef PIP_INTROSPECTION
|
||||
p = PIINTROSPECTION_THREADS->p;
|
||||
#endif
|
||||
if (p) {
|
||||
p->mutex.lock();
|
||||
PIMap<PIThread *, PIIntrospectionThreads::ThreadInfo> & tm(p->threads);
|
||||
auto it = tm.makeIterator();
|
||||
while (it.next()) {
|
||||
it.value().classname = PIStringAscii(it.key()->className());
|
||||
it.value().name = it.key()->name();
|
||||
}
|
||||
ret << tm.values();
|
||||
p->mutex.unlock();
|
||||
} else {
|
||||
ret << PIVector<PIIntrospectionThreads::ThreadInfo>();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospection::unpackThreads(PIByteArray & ba, PIVector<PIIntrospectionThreads::ThreadInfo> & threads) {
|
||||
threads.clear();
|
||||
ba >> threads;
|
||||
}
|
||||
|
||||
|
||||
PIByteArray PIIntrospection::packObjects() {
|
||||
PIByteArray ret;
|
||||
ret << getObjects();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void PIIntrospection::unpackObjects(PIByteArray & ba, PIVector<PIIntrospection::ObjectInfo> & objects) {
|
||||
objects.clear();
|
||||
ba >> objects;
|
||||
}
|
||||
|
||||
@@ -1,36 +1,35 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module - Base server structs
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module - Base server structs
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef PIINTROSPECTION_SERVER_P_H
|
||||
#define PIINTROSPECTION_SERVER_P_H
|
||||
|
||||
#include "pichunkstream.h"
|
||||
#include "piintrospection_containers.h"
|
||||
#include "piintrospection_containers_p.h"
|
||||
#include "piintrospection_threads.h"
|
||||
#include "piintrospection_threads_p.h"
|
||||
#include "pichunkstream.h"
|
||||
#include "pisystemmonitor.h"
|
||||
|
||||
|
||||
class PIP_EXPORT PIIntrospection {
|
||||
public:
|
||||
|
||||
enum InfoTypes {
|
||||
itInfo = 0x01,
|
||||
itProcStat = 0x02,
|
||||
@@ -89,7 +88,6 @@ public:
|
||||
|
||||
static PIByteArray packObjects();
|
||||
static void unpackObjects(PIByteArray & ba, PIVector<PIIntrospection::ObjectInfo> & objects);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -100,7 +98,8 @@ BINARY_STREAM_WRITE(PIIntrospection::RequiredInfo) {
|
||||
return s;
|
||||
}
|
||||
BINARY_STREAM_READ(PIIntrospection::RequiredInfo) {
|
||||
PIByteArray csba; s >> csba;
|
||||
PIByteArray csba;
|
||||
s >> csba;
|
||||
PIChunkStream cs(csba);
|
||||
while (!cs.atEnd()) {
|
||||
switch (cs.read()) {
|
||||
@@ -113,13 +112,21 @@ BINARY_STREAM_READ(PIIntrospection::RequiredInfo) {
|
||||
|
||||
BINARY_STREAM_WRITE(PIIntrospection::ProcessInfo) {
|
||||
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);
|
||||
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);
|
||||
s << cs.data();
|
||||
return s;
|
||||
}
|
||||
BINARY_STREAM_READ(PIIntrospection::ProcessInfo) {
|
||||
PIByteArray csba; s >> csba;
|
||||
PIByteArray csba;
|
||||
s >> csba;
|
||||
PIChunkStream cs(csba);
|
||||
while (!cs.atEnd()) {
|
||||
switch (cs.read()) {
|
||||
@@ -145,7 +152,8 @@ BINARY_STREAM_WRITE(PIIntrospection::ObjectInfo) {
|
||||
return s;
|
||||
}
|
||||
BINARY_STREAM_READ(PIIntrospection::ObjectInfo) {
|
||||
PIByteArray csba; s >> csba;
|
||||
PIByteArray csba;
|
||||
s >> csba;
|
||||
PIChunkStream cs(csba);
|
||||
while (!cs.atEnd()) {
|
||||
switch (cs.read()) {
|
||||
|
||||
@@ -1,26 +1,27 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module - interface for threads
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module - interface for threads
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
|
||||
|
||||
#include "piintrospection_threads.h"
|
||||
#include "piintrospection_threads_p.h"
|
||||
# include "piintrospection_threads.h"
|
||||
|
||||
# include "piintrospection_threads_p.h"
|
||||
|
||||
__PIINTROSPECTION_SINGLETON_CPP__(Threads)
|
||||
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module - interface for threads
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module - interface for threads
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef PIINTROSPECTION_THREADS_H
|
||||
@@ -26,17 +26,15 @@
|
||||
|
||||
class PIIntrospectionThreads;
|
||||
|
||||
# define PIINTROSPECTION_THREADS (PIIntrospectionThreadsInterface::instance())
|
||||
# define PIINTROSPECTION_THREADS (PIIntrospectionThreadsInterface::instance())
|
||||
|
||||
// clang-format off
|
||||
# define PIINTROSPECTION_THREAD_NEW (t ) PIINTROSPECTION_THREADS->threadNew (t );
|
||||
# define PIINTROSPECTION_THREAD_DELETE (t ) PIINTROSPECTION_THREADS->threadDelete (t );
|
||||
# define PIINTROSPECTION_THREAD_START (t ) PIINTROSPECTION_THREADS->threadStart (t );
|
||||
# define PIINTROSPECTION_THREAD_RUN (t ) PIINTROSPECTION_THREADS->threadRun (t );
|
||||
# define PIINTROSPECTION_THREAD_WAIT (t ) PIINTROSPECTION_THREADS->threadWait (t );
|
||||
# define PIINTROSPECTION_THREAD_STOP (t ) PIINTROSPECTION_THREADS->threadStop (t );
|
||||
# define PIINTROSPECTION_THREAD_RUN_DONE(t,us) PIINTROSPECTION_THREADS->threadRunDone(t,us);
|
||||
// clang-format on
|
||||
# define PIINTROSPECTION_THREAD_NEW(t) PIINTROSPECTION_THREADS->threadNew(t);
|
||||
# define PIINTROSPECTION_THREAD_DELETE(t) PIINTROSPECTION_THREADS->threadDelete(t);
|
||||
# define PIINTROSPECTION_THREAD_START(t) PIINTROSPECTION_THREADS->threadStart(t);
|
||||
# define PIINTROSPECTION_THREAD_RUN(t) PIINTROSPECTION_THREADS->threadRun(t);
|
||||
# define PIINTROSPECTION_THREAD_WAIT(t) PIINTROSPECTION_THREADS->threadWait(t);
|
||||
# define PIINTROSPECTION_THREAD_STOP(t) PIINTROSPECTION_THREADS->threadStop(t);
|
||||
# define PIINTROSPECTION_THREAD_RUN_DONE(t, us) PIINTROSPECTION_THREADS->threadRunDone(t, us);
|
||||
|
||||
class PIP_EXPORT PIIntrospectionThreadsInterface {
|
||||
friend class PIIntrospection;
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module - implementation of threads
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module - implementation of threads
|
||||
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 "piintrospection_threads_p.h"
|
||||
@@ -22,16 +22,13 @@
|
||||
|
||||
PIIntrospectionThreads::ThreadInfo::ThreadInfo() {
|
||||
id = delay = 0;
|
||||
state = sStopped;
|
||||
priority = 0;
|
||||
state = sStopped;
|
||||
priority = 0;
|
||||
run_us = run_count = 0U;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
PIIntrospectionThreads::PIIntrospectionThreads() {
|
||||
}
|
||||
PIIntrospectionThreads::PIIntrospectionThreads() {}
|
||||
|
||||
|
||||
void PIIntrospectionThreads::threadNew(PIThread * t) {
|
||||
@@ -49,10 +46,10 @@ void PIIntrospectionThreads::threadDelete(PIThread * t) {
|
||||
void PIIntrospectionThreads::threadStart(PIThread * t) {
|
||||
PIMutexLocker _ml(mutex);
|
||||
ThreadInfo & ti(threads[t]);
|
||||
ti.id = t->tid();
|
||||
ti.id = t->tid();
|
||||
ti.priority = t->priority();
|
||||
ti.delay = t->delay_;
|
||||
ti.state = sStarting;
|
||||
ti.delay = t->delay_;
|
||||
ti.state = sStarting;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module - implementation of threads
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Introspection module - implementation of threads
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef PIINTROSPECTION_THREADS_P_H
|
||||
|
||||
Reference in New Issue
Block a user