Beamlib  3.0.1
This is the Beam C++ class library.
BoapSimple.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * Boap.h Boap RPC protocol
3  * T.Barnaby, BEAM Ltd, 8/5/03
4  * Copyright (c) 2022 All Right Reserved, Beam Ltd, https://www.beam.ltd.uk
5  * For license see LICENSE.txt at the root of the beamlib source tree.
6  *******************************************************************************
7  */
8 #ifndef Boap_HH
9 #define Boap_HH
10 
11 #include <stdint.h>
12 #include <BPoll.h>
13 #include <BSocket.h>
14 #include <BError.h>
15 
16 // Main BOAP Types
17 typedef int8_t Int8;
18 typedef uint8_t UInt8;
19 typedef int16_t Int16;
20 typedef uint16_t UInt16;
21 typedef int32_t Int32;
22 typedef uint32_t UInt32;
23 typedef double Double;
24 typedef uint32_t BoapService;
26 
27 // Boap packet header
28 struct BoapPacketHead {
34 };
35 
36 // Boap packet
37 class BoapPacket {
38 public:
41 
42  int resize(int size);
43  BError setData(void* data, int nbytes);
44  int nbytes();
45  char* data();
46 
48  int push(Int8 v);
49  int push(UInt8 v);
50  int push(Int16 v);
51  int push(UInt16 v);
52  int push(Int32 v);
53  int push(UInt32 v);
54  int push(BString& v);
55  int push(Double v);
56  int push(BError& v);
57  int push(UInt32 nBytes, const void* data);
58 
60  int pop(Int8& v);
61  int pop(UInt8& v);
62  int pop(Int16& v);
63  int pop(UInt16& v);
64  int pop(Int32& v);
65  int pop(UInt32& v);
66  int pop(BString& v);
67  int pop(Double& v);
68  int pop(BError& v);
69  int pop(UInt32 nBytes, void* data);
70 private:
71  void updateLen();
72  int osize;
73  int onbytes;
74  char* odata;
75  int opos;
76 
77 };
78 
79 /*******************************************************************************
80  * Main Client communications classes
81  *******************************************************************************
82  */
83 
84 /*******************************************************************************
85  * Base for all Client Objects
86  *******************************************************************************
87  */
88 class BoapClientObject : public BSocket {
89 public:
91 
93 protected:
94  BError performSend(BoapPacket& tx); // Performs a send to the named service
95  BError performRecv(BoapPacket& rx); // Performs a receive
96  BError performCall(BoapPacket& tx, BoapPacket& rx); // Performs a RPC call to the named service
97 
98  BString oname;
100  int oconnected;
101  BoapPacket otx;
102  BoapPacket orx;
103 };
104 
105 class BoapSignalObject : public BSocket {
106 public:
108 
109 protected:
110  BError performSend(BoapPacket& tx); // Performs a send to the named service
111  BoapPacket otx;
112  BoapPacket orx;
113 };
114 
115 
116 /*******************************************************************************
117  * Main Server communications class
118  *******************************************************************************
119  */
120 class BoapServiceObject;
121 
122 class BoapServiceEntry {
123 public:
124  BoapServiceEntry(BoapService service = 0, BoapServiceObject* object = 0){
125  oservice = service;
126  oobject = object;
127  }
130 };
131 
132 class BoapServer {
133 public:
135  BError init(int boapNs = 0);
136  BError run();
137 
139 
140  // Support routines
142  BError process(int fd);
148 private:
149  int oboapNs;
150  BoapPacket orx;
151  BoapPacket otx;
153  BPoll opoll;
154  BSocket onet;
158 };
159 
160 /*******************************************************************************
161  * Base for all Server Objects
162  *******************************************************************************
163  */
164 class BoapServiceObject;
165 
167 
168 class BoapFuncEntry {
169 public:
172  BoapFunc ofunc;
173 };
174 
175 class BoapServiceObject {
176 public:
179 
180  BError sendEvent(BString signalName, Int32 arg);
181  virtual BError processEvent(BString objectName, BString name, Int32 arg);
182 
186 protected:
188 
190  BString oname;
192 };
193 #endif
BoapMc1PacketHead head
Definition: BoapMc1.h:1
BUInt8 cmd
Definition: BoapMc.h:3
int8_t Int8
Definition: BoapSimple.h:17
double Double
Definition: BoapSimple.h:23
int32_t Int32
Definition: BoapSimple.h:21
@ BoapTypeRpc
Definition: BoapSimple.h:25
@ BoapTypeSignal
Definition: BoapSimple.h:25
int16_t Int16
Definition: BoapSimple.h:19
uint32_t UInt32
Definition: BoapSimple.h:22
uint32_t BoapService
Definition: BoapSimple.h:24
uint16_t UInt16
Definition: BoapSimple.h:20
BError(BoapServiceObject::* BoapFunc)(BoapPacket &rx, BoapPacket &tx)
Definition: BoapSimple.h:166
uint8_t UInt8
Definition: BoapSimple.h:18
BoapType
Definition: Boap.h:24
BUInt32 BoapService
Definition: Boap.h:25
BUInt32 size()
Size of the buffer in bytes.
Definition: BBuffer.cpp:33
Error return class. This class is used to return the error status from a function....
Definition: BError.h:31
This class provides an interface for polling a number of file descriptors. It uses round robin pollin...
Definition: BPoll.h:48
IPV4 aware socket address.
Definition: BSocket.h:58
A network communications socket.
Definition: BSocket.h:80
This class stores and manipulates ASCII strings.
Definition: BString.h:20
Base for all Boap client objects.
Definition: Boap.h:56
BError performSend(BoapPacket &tx)
BoapPacket orx
Definition: Boap.h:87
BError performRecv(BoapPacket &rx)
BoapClientObject(BString name)
BoapService oservice
Definition: Boap.h:83
BError connectService(BString name)
BString oname
Definition: Boap.h:80
BError performCall(BoapPacket &tx, BoapPacket &rx)
int oconnected
Definition: Boap.h:84
BoapPacket otx
Definition: Boap.h:86
Boap service function.
Definition: Boap.h:207
UInt32 ocmd
Definition: BoapSimple.h:171
BoapFuncEntry(int cmd, BoapFunc func)
BoapFunc ofunc
Definition: Boap.h:211
Boap packet.
Definition: Boap.h:37
int nbytes()
Definition: BoapSimple.cc:56
int push(Int8 v)
Definition: BoapSimple.cc:77
int pushHead(BoapPacketHead &head)
char * data()
Definition: BoapSimple.cc:60
BError setData(void *data, int nbytes)
Definition: BoapSimple.cc:48
int popHead(BoapPacketHead &head)
int pop(Int8 &v)
Definition: BoapSimple.cc:164
int resize(int size)
Definition: BoapSimple.cc:40
Boap server.
Definition: Boap.h:153
BSocket onet
Definition: Boap.h:189
BError run()
Definition: BoapSimple.cc:442
BError processEvent(int fd)
BError sendEvent(BoapPacket &tx)
BError processEvent(BoapPacket &rx)
BList< BoapServiceEntry > oservices
Definition: Boap.h:187
virtual BError process(BoapServerConnection *conn, BoapPacket &rx, BoapPacket &tx)
Definition: Boap.cpp:786
BSocket onetEvent
Definition: Boap.h:190
BSocket & getEventSocket()
BString getHostName()
BString ohostName
Definition: Boap.h:192
virtual BError init(BString boapNsHost="", int port=0, int threaded=0, int isBoapns=0)
Definition: Boap.cpp:638
BSocket & getSocket()
BPoll opoll
Definition: Boap.h:188
BSocketAddressINET onetEventAddress
Definition: Boap.h:191
BError addObject(BoapServiceObject *object)
Boap server single service entry.
Definition: Boap.h:113
BoapService oservice
Definition: Boap.h:119
BoapServiceEntry(BoapService service=0, BoapServiceObject *object=0)
Definition: BoapSimple.h:124
BoapServiceObject * oobject
Definition: Boap.h:120
Boap service object.
Definition: Boap.h:215
BoapServer & oserver
Definition: Boap.h:234
virtual BError processEvent(BString objectName, BString name, Int32 arg)
BoapServiceObject(BoapServer &server, BString name)
BString name()
Definition: Boap.cpp:914
BError process(BoapServerConnection *conn, BoapPacket &rx, BoapPacket &tx)
Definition: Boap.cpp:967
BError sendEvent(BoapPacket &tx)
BError sendEvent(BString signalName, Int32 arg)
BList< BoapFuncEntry > ofuncList
Definition: Boap.h:237
virtual BError processEvent(BoapPacket &rx)
virtual ~BoapServiceObject()
BString oname
Definition: Boap.h:235
A Boap object to send signals using an RPC mechanism.
Definition: Boap.h:95
BoapPacket otx
Definition: Boap.h:101
BoapPacket orx
Definition: Boap.h:102
BError performSend(BoapPacket &tx)
Boap packet header.
Definition: Boap.h:29
UInt32 cmd
Definition: BoapSimple.h:32
BoapService service
Definition: BoapSimple.h:31
UInt32 length
Definition: BoapSimple.h:29
UInt32 reserved[12]
Definition: BoapSimple.h:33
BoapType type
Definition: BoapSimple.h:30