Files
pip/src_main/introspection/piintrospection_server.cpp

77 lines
2.2 KiB
C++

/*
PIP - Platform Independent Primitives
Introspection module
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 <http://www.gnu.org/licenses/>.
*/
#ifdef PIP_INTROSPECTION
#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()) {
PRIVATE->process_info = PIIntrospection::getInfo();
}
PIIntrospectionServer::~PIIntrospectionServer() {
PIPeer::stop();
}
void PIIntrospectionServer::start() {
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::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);
}
#endif // PIP_INTROSPECTION