Beam-lib  2.16.3
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) 2012 All Right Reserved, Beam Ltd, http://www.beam.ltd.uk
5  *******************************************************************************
6  */
7 #ifndef Boap_HH
8 #define Boap_HH
9 
10 #include <stdint.h>
11 #include <BPoll.h>
12 #include <BSocket.h>
13 #include <BError.h>
14 
15 // Main BOAP Types
16 typedef int8_t Int8;
17 typedef uint8_t UInt8;
18 typedef int16_t Int16;
19 typedef uint16_t UInt16;
20 typedef int32_t Int32;
21 typedef uint32_t UInt32;
22 typedef double Double;
23 typedef uint32_t BoapService;
25 
26 // Boap packet header
27 struct BoapPacketHead {
33 };
34 
35 // Boap packet
36 class BoapPacket {
37 public:
38  BoapPacket();
39  ~BoapPacket();
40 
41  int resize(int size);
42  BError setData(void* data, int nbytes);
43  int nbytes();
44  char* data();
45 
47  int push(Int8 v);
48  int push(UInt8 v);
49  int push(Int16 v);
50  int push(UInt16 v);
51  int push(Int32 v);
52  int push(UInt32 v);
53  int push(BString& v);
54  int push(Double v);
55  int push(BError& v);
56  int push(UInt32 nBytes, const void* data);
57 
59  int pop(Int8& v);
60  int pop(UInt8& v);
61  int pop(Int16& v);
62  int pop(UInt16& v);
63  int pop(Int32& v);
64  int pop(UInt32& v);
65  int pop(BString& v);
66  int pop(Double& v);
67  int pop(BError& v);
68  int pop(UInt32 nBytes, void* data);
69 private:
70  void updateLen();
71  int osize;
72  int onbytes;
73  char* odata;
74  int opos;
75 
76 };
77 
78 /*******************************************************************************
79  * Main Client communications classes
80  *******************************************************************************
81  */
82 
83 /*******************************************************************************
84  * Base for all Client Objects
85  *******************************************************************************
86  */
87 class BoapClientObject : public BSocket {
88 public:
90 
92 protected:
93  BError performSend(BoapPacket& tx); // Performs a send to the named service
94  BError performRecv(BoapPacket& rx); // Performs a receive
95  BError performCall(BoapPacket& tx, BoapPacket& rx); // Performs a RPC call to the named service
96 
97  BString oname;
99  int oconnected;
100  BoapPacket otx;
101  BoapPacket orx;
102 };
103 
104 class BoapSignalObject : public BSocket {
105 public:
107 
108 protected:
109  BError performSend(BoapPacket& tx); // Performs a send to the named service
110  BoapPacket otx;
111  BoapPacket orx;
112 };
113 
114 
115 /*******************************************************************************
116  * Main Server communications class
117  *******************************************************************************
118  */
119 class BoapServiceObject;
120 
121 class BoapServiceEntry {
122 public:
123  BoapServiceEntry(BoapService service = 0, BoapServiceObject* object = 0){
124  oservice = service;
125  oobject = object;
126  }
129 };
130 
131 class BoapServer {
132 public:
133  BoapServer();
134  BError init(int boapNs = 0);
135  BError run();
136 
138 
139  // Support routines
141  BError process(int fd);
143  BSocket& getSocket();
145  BError processEvent(int fd);
147 private:
148  int oboapNs;
149  BoapPacket orx;
150  BoapPacket otx;
151  BList<BoapServiceEntry> oservices;
152  BPoll opoll;
153  BSocket onet;
154  BSocket onetEvent;
155  BSocketAddressINET onetEventAddress;
156  BString ohostName;
157 };
158 
159 /*******************************************************************************
160  * Base for all Server Objects
161  *******************************************************************************
162  */
163 class BoapServiceObject;
164 
166 
167 class BoapFuncEntry {
168 public:
169  BoapFuncEntry(int cmd, BoapFunc func);
171  BoapFunc ofunc;
172 };
173 
174 class BoapServiceObject {
175 public:
177  virtual ~BoapServiceObject();
178 
179  BError sendEvent(BString signalName, Int32 arg);
180  virtual BError processEvent(BString objectName, BString name, Int32 arg);
181 
182  BString name();
184  virtual BError processEvent(BoapPacket& rx);
185 protected:
187 
189  BString oname;
191 };
192 #endif
BError process(BoapServerConnection *conn, BoapPacket &rx, BoapPacket &tx)
Definition: Boap.cpp:961
BoapPacket()
Definition: Boap.cpp:54
BoapPacket orx
Definition: Boap.h:88
virtual BError process(BoapServerConnection *conn, BoapPacket &rx, BoapPacket &tx)
Definition: Boap.cpp:784
BoapPacket orx
Definition: Boap.h:101
Definition: BoapSimple.h:24
uint32_t BoapService
Definition: BoapSimple.h:23
int pop(Int8 &v)
Definition: BoapSimple.cc:165
virtual BError processEvent(BString objectName, BString name, BInt32 arg)
Definition: Boap.cpp:996
Definition: Boap.h:94
UInt32 ocmd
Definition: BoapSimple.h:170
BError sendEvent(BString signalName, BInt32 arg)
Definition: Boap.cpp:977
char * data()
Definition: BoapSimple.cc:61
Definition: BString.h:18
BoapServiceObject * oobject
Definition: Boap.h:118
BString getHostName()
Definition: Boap.cpp:859
Definition: BSocket.h:78
uint8_t UInt8
Definition: BoapSimple.h:17
BString oname
Definition: Boap.h:81
BError(BoapServiceObject::* BoapFunc)(BoapPacket &rx, BoapPacket &tx)
Definition: BoapSimple.h:165
BoapPacket otx
Definition: Boap.h:87
Definition: Boap.h:149
~BoapPacket()
Definition: Boap.cpp:56
BUInt32 BoapService
Definition: Boap.h:24
BoapServer()
Definition: Boap.cpp:624
BError performSend(BoapPacket &tx)
Performs a send to the named service.
Definition: Boap.cpp:345
BoapSignalObject()
Definition: Boap.cpp:468
BUInt8 cmd
Definition: BoapMc.h:385
BoapMc1PacketHead head
Definition: BoapMc1.h:20
BString oname
Definition: Boap.h:228
BoapServiceEntry(BoapService service=0, BoapServiceObject *object=0)
Definition: BoapSimple.h:123
Definition: Boap.h:209
BoapType
Definition: Boap.h:23
BError connectService(BString name)
Connects to the named service.
Definition: Boap.cpp:128
int popHead(BoapPacketHead &head)
Definition: Boap.cpp:95
BList< BoapFuncEntry > ofuncList
Definition: Boap.h:230
virtual ~BoapServiceObject()
Definition: Boap.cpp:901
BSocket & getSocket()
Definition: Boap.cpp:851
Definition: Boap.h:28
int resize(int size)
Definition: BoapSimple.cc:41
BString name()
Definition: Boap.cpp:912
BError setData(void *data, int nbytes)
Definition: BoapSimple.cc:49
BoapType type
Definition: BoapSimple.h:29
UInt32 length
Definition: BoapSimple.h:28
BError performRecv(BoapPacket &rx)
Performs a receive.
Definition: Boap.cpp:362
uint32_t UInt32
Definition: BoapSimple.h:21
BoapPacket otx
Definition: Boap.h:100
Definition: Boap.h:111
UInt32 cmd
Definition: BoapSimple.h:31
BoapService service
Definition: BoapSimple.h:30
BSocket & getEventSocket()
Definition: Boap.cpp:855
BoapService oservice
Definition: Boap.h:84
Definition: Boap.h:202
This class provides an interface for polling a number of file descriptors. It uses round robin pollin...
Definition: BPoll.h:43
BUInt32 size()
Size of the buffer in bytes.
Definition: BBuffer.cpp:31
BError run()
Definition: BoapSimple.cc:443
int push(Int8 v)
Definition: BoapSimple.cc:78
BoapService oservice
Definition: Boap.h:117
int8_t Int8
Definition: BoapSimple.h:16
virtual BError init(BString boapNsHost="", int port=0, int threaded=0, int isBoapns=0)
Definition: Boap.cpp:636
virtual BError processEvent(BoapPacket &rx)
Definition: Boap.cpp:799
BoapFunc ofunc
Definition: Boap.h:206
BError performSend(BoapPacket &tx)
Definition: Boap.cpp:472
BoapClientObject(BString name="")
Definition: Boap.cpp:115
int pushHead(BoapPacketHead &head)
Definition: Boap.cpp:75
Definition: Boap.h:36
virtual BError sendEvent(BoapPacket &tx)
Definition: Boap.cpp:829
int oconnected
Definition: Boap.h:85
UInt32 reserved[12]
Definition: BoapSimple.h:32
IP aware socket address.
Definition: BSocket.h:57
Definition: Boap.h:58
Definition: BError.h:25
BoapServiceObject(BoapServer &server, BString name="")
Definition: Boap.cpp:894
int nbytes()
Definition: BoapSimple.cc:57
BError performCall(BoapPacket &tx, BoapPacket &rx)
Performs a RPC call to the named service.
Definition: Boap.cpp:421
Definition: BoapSimple.h:24
int32_t Int32
Definition: BoapSimple.h:20
uint16_t UInt16
Definition: BoapSimple.h:19
virtual BError addObject(BoapServiceObject *object)
Definition: Boap.cpp:776
double Double
Definition: BoapSimple.h:22
BoapFuncEntry(int cmd, BoapFunc func)
Definition: Boap.cpp:890
int16_t Int16
Definition: BoapSimple.h:18
BoapServer & oserver
Definition: Boap.h:227