/*
	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/>.
*/

#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 "pisystemmonitor.h"


class PIP_EXPORT PIIntrospection {
public:

	enum InfoTypes {
		itInfo       = 0x01,
		itProcStat   = 0x02,
		itContainers = 0x04,
		itObjects    = 0x08,
		itThreads    = 0x10,
	};

	struct PIP_EXPORT RequiredInfo {
		RequiredInfo();
		PIFlags<InfoTypes> types;
	};

	struct PIP_EXPORT ProcessInfo {
		ProcessInfo();

		PIString execCommand, hostname, user, OS_name, OS_version, architecture;
		PIDateTime execDateTime;
		int processorsCount;

		PIStringList build_options;
	};

	struct PIP_EXPORT ProcessStat {
		ProcessStat() {}

		PISystemMonitor::ProcessStats proc;
		PIVector<PISystemMonitor::ThreadStats> threads;
	};

	struct PIP_EXPORT ObjectInfo {
		ObjectInfo();

		PIString classname, name;
		PIStringList parents;
		PIMap<PIString, PIVariant> properties;
		int queued_events;
	};

	static const uint sign;

	static ProcessInfo getInfo();
	static PIVector<ObjectInfo> getObjects();

	static PIByteArray packInfo();
	static void unpackInfo(PIByteArray & ba, ProcessInfo & info);

	static PIByteArray packProcStat(PISystemMonitor * sm);
	static void unpackProcStat(PIByteArray & ba, ProcessStat & info);

	static PIByteArray packContainers();
	static void unpackContainers(PIByteArray & ba, PIVector<PIIntrospectionContainers::TypeInfo> & data);

	static PIByteArray packThreads();
	static void unpackThreads(PIByteArray & ba, PIVector<PIIntrospectionThreads::ThreadInfo> & threads);

	static PIByteArray packObjects();
	static void unpackObjects(PIByteArray & ba, PIVector<PIIntrospection::ObjectInfo> & objects);

};

PIP_EXPORT PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::RequiredInfo & v);
PIP_EXPORT PIByteArray & operator >>(PIByteArray & b, PIIntrospection::RequiredInfo & v);

PIP_EXPORT PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::ProcessInfo & v);
PIP_EXPORT PIByteArray & operator >>(PIByteArray & b, PIIntrospection::ProcessInfo & v);

PIP_EXPORT PIByteArray & operator <<(PIByteArray & b, const PIIntrospection::ObjectInfo & v);
PIP_EXPORT PIByteArray & operator >>(PIByteArray & b, PIIntrospection::ObjectInfo & v);

#endif // PIINTROSPECTION_SERVER_P_H
