/* Web Polygraph       http://www.web-polygraph.org/
 * (C) 2003-2006 The Measurement Factory
 * Licensed under the Apache License, Version 2.0 */

#ifndef POLYGRAPH__CLIENT_CLTCFG_H
#define POLYGRAPH__CLIENT_CLTCFG_H

#include "xstd/Ring.h"
#include "runtime/AgentCfg.h"
#include "client/MembershipMap.h"
#include "client/AclGroup.h"

class Goal;
class ObjId;
class RndDistr;
class PopModel;
class RepHdr;
class RobotSym;
class WarmupPlan;
class XactAbortCoord;
class RegExGroup;
class ForeignWorld;
class XmlTagIdentifier;

// Client configuration items that can be shared among multiple clients
class CltCfg: public AgentCfg {
	public:
		CltCfg();
		~CltCfg();

		void configure(const RobotSym *aRobot);

		int viservLimit() const;
		bool hasViserv(int viserv) const;

		void startWarmup();
		void stopWarmup();

		int selectInterest();
		int selectViserv();
		bool selectProxy(NetAddr &addr);
		bool selectCredentials(String &newName);
		void selectAbortCoord(XactAbortCoord &coord);
		int selectCookieCount(const ObjId &id);
		Size selectCookieSize(const ObjId &id);

		bool followAllUris(const RepHdr &rep) const;
		int findMemberships(const String &user, Memberships &memberships) const;
		const AclGroup &acl() const { return theAcl; }
		ForeignWorld *foreignWorld() { return theForeignWorld; }

	protected:
		void configureInterests();
		void configureReqTypes();
		void configureReqMethods();
		void configureOrigins();
		void configureProxies();
		void configureCredentials();
		void configureMemberships();
		void configureContainerTags();
		void configureAcceptedContentCodings();
		void configurePipeDepth();
		void configureTrace(const String &fname);

		void addOrigName(const NetAddr &oname);
		void checkTargets(int viserv);

	protected:
		static Memberships TheGlbMemberships;

	public:
		const RobotSym *theRobot;  // used to identify/share configs

		Array<int> theViservs;     // origin idx to HostMap idx (viserv)
		RndDistr *theOriginSel;    // selects origin idx
		RndDistr *theInterestSel;  // selects interest groups
		RndDistr *theReqTypeSel;   // selects request types
		RndDistr *theReqMethodSel; // selects request methods
		PopModel *thePopModel;     // popularity model to select old oids

		Goal *theBusyPeriod;       // sessions's busy period config
		RndDistr *theIdlePeriodDur;// sessions's idle period config
		Time theSessionHeartbitGap;// hearbit interval

		Ring<NetAddr*> theProxies;
		int theProxyCycleCnt;      // to randomize proxy selection

		RndDistr *thePipelineDepth;// maximum concurrent pipelined requests

		NetAddr thePeerHttp;       // caching peer talking HTTP
		NetAddr thePeerIcp;        // caching peer talking ICP
		double thePublicRatio;     // how often to request a "public" object
		double theRecurRatio;      // how often to re-visit an old object
		double theEmbedRecurRatio; // how often to re-visit an old embedded obj
		double theAbortProb;	   // prob of aborting a transaction
		double theAuthError;       // prob of an authentication error

		int theWaitXactLmt;        // limit on the number of postponed requests
		int theIcpPort;            // IPC client should use this port

		Memberships theLclMemberships; // all user groups users belong to
		Ring<String*> theCredentials;  // all users under this cfg
		int theCredentialCycleCnt;
		AclGroup theAcl;

		String theUriThrower;          // follow all URIs from this server
		ForeignWorld *theForeignWorld; // foreign URLs trace, if any

		XmlTagIdentifier *theContainerTags;
		String *theAcceptedContentCodings; // for Accept-Encoding header
		bool acceptingGzipContent;         // pre-parsed status

		RndDistr *theCookiesKeepLimitSel; // how many cookies to keep

		WarmupPlan *theWarmupPlan;

		bool genUniqUrls;          // each generated URL must be unique
		bool didWarmup;            // warmup plan was completed

};


class CltSharedCfgs: protected Array<CltCfg*> {
	public:
		CltCfg *getConfig(const RobotSym *cfg);

	protected:
		CltCfg *addConfig(const RobotSym *cfg);
};

#endif


syntax highlighted by Code2HTML, v. 0.9.1