DatagramInterface.h
Go to the documentation of this file.
1// -*- C++ -*-
2// Copyright (c) 2005-2024, Isode Limited, London, England.
3// All rights reserved.
4//
5// Acquisition and use of this software and related materials for any
6// purpose requires a written licence agreement from Isode Limited,
7// or a written licence from an organisation licenced by Isode Limited
8// to grant such a licence.
9
10
11//
12//
14//
16//
17// @VERSION@
18
19#ifndef _DATAGRAMINTERFACE_H_
20#define _DATAGRAMINTERFACE_H_
21
22#include <isode/ll/internet.h>
23#include <isode/messages/ioevent.h>
24
25// Design Note: the Datagram user owns read and write buffers
26
27namespace Datagram {
28
29 class User;
30 class Provider;
31
32 // Provider interface
33
35 struct External {
36 endpoint_t fd;
37 };
38
40 // Often the address will be the 'any' address, but the port will be
41 // chosen.
43 const struct sockaddr *laddr;
44 socklen_t lalen;
45 };
46
48 struct ReadRequest {
49 char *buf;
50 size_t len;
51 struct sockaddr *saddr;
52 socklen_t salen;
53 };
54
56 struct DataRequest {
57 const char *buf;
58 size_t len;
59 const struct sockaddr *daddr;
60 socklen_t dalen;
61 void *pduref;
62 bool usearq;
63 bool inorder;
64 enum {
65 DC_NONE,
69 DataRequest() : buf(0), len(0), daddr(0), dalen(0),
70 pduref(0), usearq(false), inorder(false), confmode(DC_NONE)
71 {}
72 };
73
75 // Note: will associate the multicast address with the same IP address
76 // as used for the listening.
78 struct in_addr maddr;
79 bool listen;
80 };
81
82
85 unsigned ttl;
86 int loop;
87 // -1: off, 1: on
88 };
89
91 typedef size_t LengthFnx (const char *buf);
92
96 size_t minlen;
97 };
98
100 class Provider {
101 private:
102 User *user;
103
104 public:
106 Provider () : user(0) {}
107
109 virtual ~Provider () {}
110
112 void SetUser (User *u) { user = u; }
113
115 User *GetUser () { return user; }
116
118 virtual void Die () = 0;
119
121 // Enables the user to set the FD from some external source
122 virtual void Deliver (External *ext) = 0;
123
125 virtual void Deliver (ListenRequest *req) = 0;
126
128 virtual void Deliver (DataRequest *req) = 0;
129
131 virtual void Deliver (ReadRequest *req) = 0;
132
134 virtual void Deliver (MulticastRequest *req) = 0;
135
137 virtual void Deliver (MulticastParams *req) = 0;
138
140 virtual void Deliver (LengthFnxRequest *req) = 0;
141
143 static EVENTSVC_DLL Provider *ProviderFactory (const char *type, MSGstruct *msp);
144 };
145
146 // User interface
147
150 Provider *provider;
151 char *buf;
152 ssize_t len;
153 const struct sockaddr *saddr;
154 socklen_t salen;
155 bool arq;
156 };
157
159 struct ReleaseBuf {
160 Provider *provider;
161 const char *buf;
162 ssize_t len;
163 };
164
167 Provider *provider;
168 void *pduref;
169 MSGstruct msg;
170 int info;
171
172 StatusIndication () : provider(0), pduref(0), info(-1) { msg.data = NULL; msg.dlen = 0; }
174 this->pduref = src.pduref;
175 this->info = src.info;
176 this->provider = src.provider;
177 this->msg.dlen = src.msg.dlen;
178 if (src.msg.data == src.msg.dbuf) {
179 this->msg.data = this->msg.dbuf;
180 }
181 else {
182 this->msg.data = (unsigned char*)smalloc(src.msg.dlen);
183 }
184 memcpy (this->msg.data, src.msg.data, src.msg.dlen);
185 }
186
187 ~StatusIndication () { MSGfree (&msg); }
188
189 // Need assignment, as need to change data pointer if points to self
190 StatusIndication & operator= (const StatusIndication &src) {
191 this->provider = src.provider;
192 this->msg.dlen = src.msg.dlen;
193 if ( src.msg.data == src.msg.dbuf ) {
194 this->msg.data = this->msg.dbuf;
195 } else {
196 this->msg.data = (unsigned char *)
197 smalloc (src.msg.dlen);
198 }
199 memcpy (this->msg.data, src.msg.data, src.msg.dlen);
200
201 return *this;
202 }
203 };
204
206 // User can associate with many providers, so no specific provider field
207 class User {
208 public:
210
211 virtual ~User () {}
212
214 virtual void Deliver (DataIndication *data) = 0;
215
217 virtual void Deliver (ReleaseBuf *release) = 0;
218
220 virtual void Deliver (StatusIndication *error) = 0;
221 };
222
223}
224
225#endif /* __DATAGRAMINTERFACE_H_ */
Provider of a stream interface.
virtual void Deliver(MulticastParams *req)=0
Control multicast sending.
virtual void Deliver(External *ext)=0
Set external.
virtual ~Provider()
Destructor should be virtual.
virtual void Die()=0
Go away.
virtual void Deliver(LengthFnxRequest *req)=0
Set length function.
virtual void Deliver(DataRequest *req)=0
Send data.
virtual void Deliver(MulticastRequest *req)=0
Enable listening for multicast packets.
virtual void Deliver(ReadRequest *req)=0
Pass read buffer.
static EVENTSVC_DLL Provider * ProviderFactory(const char *type, MSGstruct *msp)
Factory method for Stream provider.
Definition EventSvc.C:175
User * GetUser()
get the user
Provider()
The user of this provider.
virtual void Deliver(ListenRequest *req)=0
Listen for data on endpoint.
void SetUser(User *u)
set the user
Virtual class defining interface to stream user.
virtual void Deliver(ReleaseBuf *release)=0
Provider finished with write buffer.
virtual ~User()
Destructor should be virtual.
virtual void Deliver(DataIndication *data)=0
Receive data read by provider.
virtual void Deliver(StatusIndication *error)=0
Provider status.
Interface between a user of a datagram service and its provider.
size_t LengthFnx(const char *buf)
Typedef for datagram length function.
Data read from provider.
ssize_t len
Address of data.
bool arq
Length of source address.
socklen_t salen
Source address.
char * buf
This provider.
const struct sockaddr * saddr
Length of data read, -ve means error.
Information for sending data.
void * pduref
Length of destination address.
bool inorder
Use ARQ mode if available.
bool usearq
Reference for this PDU.
enum Datagram::DataRequest::@0 confmode
Deliver PDUs in order.
size_t len
Pointer to data to be transferred.
@ DC_CLIENT_CONF
Force to node.
const struct sockaddr * daddr
Number of bytes to be transferred.
socklen_t dalen
Destination address.
DataRequest()
explicit confirm mode
Push an external endpoint into the provider.
Sets length function.
size_t minlen
Minimum data length to get length.
LengthFnx * fnx
Function which gets length.
Bind to an end-point.
socklen_t lalen
Listen address.
Set multicast parameters.
int loop
Set the ttl for multicast, 0: no change.
Listen/Stop listening to multicast address.
bool listen
The multicast address.
Request read from provider.
socklen_t salen
Source address buffer.
size_t len
Address of data.
struct sockaddr * saddr
Length of data read.
const char * buf
This provider.
ssize_t len
Buffer to be released.
MSGstruct msg
Reference for the PDU.
void * pduref
This provider.
int info
Gives details of error.
StatusIndication()
For connection events, max pdu size, or error reasons.

All rights reserved © 2002 - 2024 Isode Ltd.