1 
2 /* Web Polygraph       http://www.web-polygraph.org/
3  * Copyright 2003-2011 The Measurement Factory
4  * Licensed under the Apache License, Version 2.0 */
5 
6 #ifndef POLYGRAPH__ICP_ICPCLIENT_H
7 #define POLYGRAPH__ICP_ICPCLIENT_H
8 
9 #include "xstd/Array.h"
10 #include "icp/IcpBase.h"
11 
12 class IcpCltRes {
13 	public:
theIdx(anIdx)14 		IcpCltRes(int anIdx = -1): theIdx(anIdx) {}
15 
reset()16 		void reset() { theIdx = -1; }
17 
18 		operator void*() const { return theIdx >= 0 ? (void*)-1 : 0; }
reqNum()19 		int reqNum() const { return theIdx; }
20 
21 	protected:
22 		int theIdx;
23 };
24 
25 class IcpCltUser {
26 	public:
27 		virtual ~IcpCltUser();
28 		virtual void reset();
29 
30 		virtual const ObjId &oid() const = 0;
31 		virtual void noteReply(const IcpMsg &r) = 0;
32 
33 	protected:
34 		IcpCltRes theReserv;
35 };
36 
37 // matches ICP requests and responses
38 class IcpClient: virtual public IcpBase {
39 	public:
40 		IcpClient();
41 
42 		IcpCltRes expectReply(IcpCltUser *u);
43 		void cancel(IcpCltRes &res);
44 
45 	protected:
46 		virtual void noteReply(const IcpMsg &m);
47 
48 		virtual int logCat() const;
49 
50 	protected:
51 		Array<IcpCltUser*> theUsers;
52 		int theLastReqNum;
53 };
54 
55 #endif
56