/**********************************************************************
 * Copyright (c) 2005, 2006 Scapa Technologies Limited and others
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * $Id: PerfmonAgent.h,v 1.2 2006/10/26 22:40:22 kcallaghan Exp $
 * 
 * Contributors: 
 * Scapa Technologies Limited - Initial API and implementation
 **********************************************************************/


#ifndef __PERFMON__H__
#define __PERFMON__H__

#include <iostream.h>
#ifdef LINUX
#define DEFAULT_RES "libperflin.so"
#endif

#ifdef WIN32
#define DEFAULT_RES "sysperf.dll"
#include <winsock2.h>
#endif

#include "resinterface.h"
#include "DataTransferInterface.h"
#include "DataCollectionInterface.h"

#include "tptp/agents/BaseCollectorImpl.h"
#include "tptp/TPTPCommon.h"
#include "tptp/TPTPTypes.h"
#include "tptp/TPTPUtils.h"
#include "tptp/agents/AgentLog.h"

#define DEFAULT_PERFMON_AGENT_NAME "org.eclipse.tptp.PerfmonAgent"

class PerfmonAgent : public BaseCollectorImpl
{
	private:
		tptp_int32 destinationID;
		HashTable* perf_filters;
		HashTable* perf_variables;
		HashTable* perf_tree;


		void longToString(XINT64 i, char* str);
		int increaseBufferSize(char** buf, int* buflen);
		void clearData(char** array, int count);
		void setVariables(HashTable* hasht_variables);
		int manageResources(LPSTARTUP resStartup, LPSHUTDOWN resShutdown, LPGETTREE getTree, LPGETRESULTS getResults, PerfmonAgent* myPerfmonAgentInstance);
		void handle(char* type, char* name, char* value);
		void showInfo();
		tptp_int32 sendRunResponse(CmdBlock* cmdBlock);
		tptp_int32 sendStopResponse(CmdBlock* cmdBlock);
		tptp_int32 comSendData(int destinationID, char buffer[], int bufferLength);

	public:
		PerfmonAgent(char* name) : BaseCollectorImpl(name), BaseAgentImpl(name) {};
		~PerfmonAgent() {};

		virtual tptp_int32 run(CmdBlock* cmdBlock);
		virtual tptp_int32 stop(CmdBlock* cmdBlock);
		virtual tptp_int32 processCommand(CmdBlock* cmdBlock);
		virtual tptp_int32 receiveData(tptp_int32 sourceID, char buffer[], tptp_int32 bytesRead, DIME_HEADER_PTR_T dimeHeader);
		int process(char* resDLLname, PerfmonAgent* myPerfmonAgentInstance);
};
#endif

