Simple Geolocalization and Course Transmission Protocol (SGCTP)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Pages
transmit.hpp
Go to the documentation of this file.
1 // INDENTING (emacs/vi): -*- mode:c++; tab-width:2; c-basic-offset:2; intent-tabs-mode:nil; -*- ex: set tabstop=2 expandtab:
2 
3 /*
4  * Simple Geolocalization and Course Transmission Protocol (SGCTP)
5  * Copyright (C) 2014 Cedric Dufour <http://cedric.dufour.name>
6  *
7  * The Simple Geolocalization and Course Transmission Protocol (SGCTP) is
8  * free software:
9  * you can redistribute it and/or modify it under the terms of the GNU General
10  * Public License as published by the Free Software Foundation, Version 3.
11  *
12  * The Simple Geolocalization and Course Transmission Protocol (SGCTP) is
13  * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15  * PARTICULAR PURPOSE.
16  *
17  * See the GNU General Public License for more details.
18  */
19 
20 #ifndef SGCTP_CTRANSMIT_HPP
21 #define SGCTP_CTRANSMIT_HPP
22 
23 // C
24 #include <stdint.h>
25 #include <string.h>
26 
27 // SGCTP
28 #include "sgctp/parameters.hpp"
29 
30 
31 // SGCTP namespace
32 namespace SGCTP
33 {
34 
35  // External
36  class CData;
37  class CPayload;
38 
40 
46  class CTransmit: public CParameters
47  {
48 
49  //----------------------------------------------------------------------
50  // CONSTANTS / STATIC
51  //----------------------------------------------------------------------
52 
53  public:
55  static const uint8_t PROTOCOL_VERSION = 1;
56 
61  TRANSMIT_FILE = 128,
63  };
64 
66  enum EPayloadType {
70  };
71 
72 
73  //----------------------------------------------------------------------
74  // FIELDS
75  //----------------------------------------------------------------------
76 
77  protected:
79  unsigned char *pucBuffer;
86 
88  double fdTimeout;
89 
94 
95 
96  //----------------------------------------------------------------------
97  // CONSTRUCTORS / DESTRUCTOR
98  //----------------------------------------------------------------------
99 
100  public:
101  CTransmit();
102  virtual ~CTransmit();
103 
104 
105  //----------------------------------------------------------------------
106  // METHODS
107  //----------------------------------------------------------------------
108 
109  protected:
111 
114  int allocBuffer();
116 
121  int recvBuffer( int _iDescriptor,
122  int _iSize );
124 
128  const unsigned char* pullBuffer( int _iSize );
130  void flushBuffer();
132  void resetBuffer();
133 
134  public:
136 
140  virtual void setTimeout( int _iDescriptor,
141  double _fdTimeout )
142  {
143  fdTimeout = _fdTimeout;
144  };
146  bool hasData()
147  {
149  };
150 
151  protected:
153 
160  virtual int recv( int _iDescriptor,
161  void *_pBuffer,
162  int _iSize,
163  int _iFlags ) = 0;
165 
172  virtual int send( int _iDescriptor,
173  const void *_pBuffer,
174  int _iSize,
175  int _iFlags ) = 0;
176 
177  public:
179  virtual ETransmitType getTransmitType() = 0;
181  virtual bool hasPayload()
182  {
183  return (bool)poPayload;
184  };
186  virtual void resetPayload();
188 
191  virtual int initPayload( uint8_t _ui8tPayloadType = PAYLOAD_RAW );
193 
196  virtual int allocPayload();
198  virtual void freePayload();
201  {
202  return ePayloadType;
203  };
204 
206 
209  virtual int alloc() = 0;
211 
216  virtual int serialize( int _iDescriptor,
217  const CData &_roData );
219 
225  virtual int unserialize( int _iDescriptor,
226  CData *_poData,
227  int _iMaxSize = 0 );
229  virtual void free();
230 
231  };
232 
233 }
234 
235 #endif // SGCTP_CTRANSMIT_HPP
static const uint8_t PROTOCOL_VERSION
Protocol version.
Definition: transmit.hpp:55
virtual int serialize(int _iDescriptor, const CData &_roData)
Serialize the given SGCTP data to the given descriptor.
Definition: transmit.cpp:212
virtual ~CTransmit()
Definition: transmit.cpp:53
ETransmitType
Transmission types.
Definition: transmit.hpp:58
int iBufferDataEnd
Transmission buffer actual data end offset.
Definition: transmit.hpp:85
int iBufferSize
Transmission buffer size.
Definition: transmit.hpp:81
virtual int allocPayload()
Allocate resources required for payload (un-)serialization.
Definition: transmit.cpp:198
virtual void free()
Free resources required for data transmission (un-/serialization)
Definition: transmit.cpp:304
virtual int send(int _iDescriptor, const void *_pBuffer, int _iSize, int _iFlags)=0
Send data to the given descriptor.
virtual void setTimeout(int _iDescriptor, double _fdTimeout)
Set the transmission (send/receive) timeout, in seconds.
Definition: transmit.hpp:140
void flushBuffer()
Flush the data buffer (from pulled data)
Definition: transmit.cpp:127
AES128-encrypted payload.
Definition: transmit.hpp:68
virtual int initPayload(uint8_t _ui8tPayloadType=PAYLOAD_RAW)
Associate and initialize payload object.
Definition: transmit.cpp:160
double fdTimeout
Transmission timeout, in seconds.
Definition: transmit.hpp:88
const unsigned char * pullBuffer(int _iSize)
Pull data from the transmission buffer.
Definition: transmit.cpp:121
virtual EPayloadType getPayloadType()
Return the payload type.
Definition: transmit.hpp:200
int recvBuffer(int _iDescriptor, int _iSize)
Receive data from the given descriptor (and push them on the data buffer)
Definition: transmit.cpp:80
SGCTP data container.
Definition: data.hpp:44
virtual bool hasPayload()
Return whether a payload object has been successfully associated/initialized.
Definition: transmit.hpp:181
CPayload * poPayload
Associated payload object.
Definition: transmit.hpp:91
Generic transmission of SGCTP payload.
Definition: transmit.hpp:46
EPayloadType ePayloadType
Associated payload type.
Definition: transmit.hpp:93
bool hasData()
Return whether data are available (in the transmission buffer)
Definition: transmit.hpp:146
virtual void resetPayload()
Reset (clear) the associated payload object.
Definition: transmit.cpp:152
virtual int alloc()=0
Allocate resources required for data transmission (un-/serialization)
(Raw) SGCTP payload
Definition: payload.hpp:41
virtual int recv(int _iDescriptor, void *_pBuffer, int _iSize, int _iFlags)=0
Receive data from the given descriptor.
void resetBuffer()
Reset the data buffer (clear all data)
Definition: transmit.cpp:146
unsigned char * pucBuffer
Transmission buffer.
Definition: transmit.hpp:79
virtual int unserialize(int _iDescriptor, CData *_poData, int _iMaxSize=0)
Unserialize the SGCTP data from the given descriptor.
Definition: transmit.cpp:256
int iBufferDataStart
Transmission buffer actual data start offset.
Definition: transmit.hpp:83
SGCTP transmission/payload parameters.
Definition: parameters.hpp:40
EPayloadType
Payload types.
Definition: transmit.hpp:66
virtual ETransmitType getTransmitType()=0
Return the transmission type.
virtual void freePayload()
Free resources required for payload (un-)serialization.
Definition: transmit.cpp:205
int allocBuffer()
Allocate resources required for data transmission.
Definition: transmit.cpp:66