1 /**
2  *  Frame.h
3  *
4  *  Base class for frames. This base class can not be constructed from outside
5  *  the library, and is only used internally.
6  *
7  *  @copyright 2014 - 2018 Copernica BV
8  */
9 
10 /**
11  *  Include guard
12  */
13 #pragma once
14 
15 /**
16  *  Dependencies
17  */
18 #include "protocolexception.h"
19 
20 /**
21  *  Set up namespace
22  */
23 namespace AMQP {
24 
25 /**
26  *  Forward declarations
27  */
28 class ConnectionImpl;
29 
30 /**
31  *  Class definition
32  */
33 class Frame
34 {
35 protected:
36     /**
37      *  Protected constructor to ensure that no objects are created from
38      *  outside the library
39      */
Frame()40     Frame() {}
41 
42 public:
43     /**
44      *  Destructor
45      */
~Frame()46     virtual ~Frame() {}
47 
48     /**
49      *  return the total size of the frame
50      *  @return uint32_t
51      */
52     virtual uint32_t totalSize() const = 0;
53 
54     /**
55      *  Fill an output buffer
56      *  @param  buffer
57      */
58     virtual void fill(OutBuffer &buffer) const = 0;
59 
60     /**
61      *  Is this a frame that is part of the connection setup?
62      *  @return bool
63      */
partOfHandshake()64     virtual bool partOfHandshake() const { return false; }
65 
66     /**
67      *  Is this a frame that is part of the connection close operation?
68      *  @return bool
69      */
partOfShutdown()70     virtual bool partOfShutdown() const { return false; }
71 
72     /**
73      *  Does this frame need an end-of-frame seperator?
74      *  @return bool
75      */
needsSeparator()76     virtual bool needsSeparator() const { return true; }
77 
78     /**
79      *  Is this a synchronous frame?
80      *
81      *  After a synchronous frame no more frames may be
82      *  sent until the accompanying -ok frame arrives
83      */
synchronous()84     virtual bool synchronous() const { return false; }
85 
86     /**
87      *  Process the frame
88      *  @param  connection      The connection over which it was received
89      *  @return bool            Was it succesfully processed?
90      */
process(ConnectionImpl * connection)91     virtual bool process(ConnectionImpl *connection)
92     {
93         // make sure compilers dont complain about unused parameters
94         (void) connection;
95 
96         // this is an exception
97         throw ProtocolException("unimplemented frame");
98 
99         // unreachable
100         return false;
101     }
102 };
103 
104 /**
105  *  End of namespace
106  */
107 }
108 
109