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__CLIENT_PIPELINEDCXM_H
7 #define POLYGRAPH__CLIENT_PIPELINEDCXM_H
8 
9 #include "xstd/Queue.h"
10 #include "client/CltXactMgr.h"
11 
12 class CltXact;
13 class Connection;
14 
15 // a manager of a single CltXact that does not share the connection
16 // with other client transactions
17 class PipelinedCxm: public CltXactMgr {
18 	public:
19 		static PipelinedCxm *Get();
20 
21 	public:
22 		PipelinedCxm();
23 
24 		virtual void reset();
25 
26 		virtual bool pipelining() const;
27 
28 		void assumeReadControl(CltXact *x, CltXactMgr *oldMgr);
29 		virtual void join(CltXact *x);
30 		virtual void control(CltXact *x);
31 		virtual void release(CltXact *x); // opposite of Get()
32 
33 		virtual void resumeWriting(CltXact *);
34 
35 		virtual void noteAbort(CltXact *x);
36 		virtual void noteDone(CltXact *x);
37 		virtual void noteLastXaction(CltXact *x);
38 
39 		virtual void noteReadReady(int fd);
40 		virtual void noteWriteReady(int fd);
41 
42 		virtual Connection *conn();
43 
44 	protected:
45 		typedef Queue<CltXact, &CltXact::pipelinedXacts> Line;
46 		void prepReading(CltXact *x);
47 		void abortLines(CltXact *cause);
48 		void abortLine(Line &line, CltXact *cause);
49 		void kickNextRead();
50 
51 	protected:
52 		Line theFillers;
53 		Line theWriters;
54 		Line theReaders;
55 		Connection *theConn; // cached value
56 		int theUseLevel;
57 };
58 
59 #endif
60