aboutsummaryrefslogtreecommitdiff
path: root/src/protocol.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/protocol.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/protocol.h b/src/protocol.h
new file mode 100644
index 0000000..cd18e37
--- /dev/null
+++ b/src/protocol.h
@@ -0,0 +1,58 @@
1#ifndef PROTOCOL_H
2#define PROTOCOL_H
3
4#include "connection.h"
5
6/** This is the template for a class that handles specialized input and output
7 * to connections of different types with different protocols.
8 *@author Mike Buland
9 */
10class Protocol
11{
12public:
13 /** Constructor */
14 Protocol();
15 /** Deconstructor */
16 virtual ~Protocol();
17
18 /**
19 * Function is called every time there is new data on the line. This is
20 * called directly from the Connection class to process data. This is not
21 * called whever there is pending data on the input, but every time new data
22 * is added to the input buffer.
23 *@returns True if processing went alright, false if something went wrong,
24 * I suppose. In truth this value is thrown away right now.
25 *@todo Either make a return value of false mean something, or make these
26 * void.
27 */
28 virtual bool onNewData()=0;
29
30 /**
31 * Function is called when there is a new connection. This should only
32 * happen once per Protocol object, but gives each protocol object a
33 * chance to perform connection handshaking and initialization at a point
34 * where they know that they have a handle to an active Connection.
35 *@returns See onNewData
36 */
37 virtual bool onNewConnection()=0;
38
39 /**
40 * Sets the Protocol's Connection object. This is rather important, and
41 * handled usually by the ConnectionManager.
42 *@param pNewConnection The Connection object that this protocol will use to
43 * deal with the outside world.
44 */
45 void setConnection( class Connection *pNewConnection );
46
47 /**
48 * Get a pointer to this object's Connection object, or NULL if one was
49 * never set. If used with the ConnectionManager that should never happen.
50 *@returns A pointer to the active Connection.
51 */
52 Connection *getConnection();
53
54private:
55 class Connection *pConnection; /**< The pointer to the Connection. */
56};
57
58#endif