/usr/include/crtmpserver/thelib/protocols/baseprotocol.h is in crtmpserver-dev 1.0~dfsg-5.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | /*
* Copyright (c) 2010,
* Gavriloaie Eugen-Andrei (shiretu@gmail.com)
*
* This file is part of crtmpserver.
* crtmpserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* crtmpserver is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with crtmpserver. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _BASEPROTOCOL_H
#define _BASEPROTOCOL_H
#include "common.h"
#include "protocols/protocoltypes.h"
class IOBuffer;
class IOHandler;
class BaseClientApplication;
/*!
@class BaseProtocol
@brief The base class on which all atomic protocols must derive from.
*/
class DLLEXP BaseProtocol {
private:
static uint32_t _idGenerator;
uint32_t _id;
BaseClientApplication *_pApplication;
protected:
uint64_t _type;
BaseProtocol *_pFarProtocol;
BaseProtocol *_pNearProtocol;
bool _deleteFar;
bool _deleteNear;
bool _enqueueForDelete;
bool _gracefullyEnqueueForDelete;
Variant _customParameters;
double _creationTimestamp;
public:
BaseProtocol(uint64_t type);
virtual ~BaseProtocol();
//
//general purpose, fixed methods
//
/*!
@abstract Returns the type of the protocol
*/
uint64_t GetType();
/*!
@brief Returns the id of the protocol. Each protocol instance has an id. The id is unique across all protocols, no matter the type
*/
uint32_t GetId();
/*!
@brief Returns the creation timestamp expressed in milliseconds for 1970 epoch
*/
double GetSpawnTimestamp();
/*!
@brief Gets the far protocol
*/
BaseProtocol *GetFarProtocol();
/*!
@brief Sets the far protocol
@param pProtocol
*/
void SetFarProtocol(BaseProtocol *pProtocol);
/*!
@brief Break the far side of the protocol chain by making far protocol NULL
*/
void ResetFarProtocol();
/*!
@brief Gets the near protocol
*/
BaseProtocol *GetNearProtocol();
/*!
@brief Sets the near protocol
@param pProtocol
*/
void SetNearProtocol(BaseProtocol *pProtocol);
/*!
@brief Break the near side of the protocol chain by making near protocol NULL
*/
void ResetNearProtocol();
//Normally, if this protocol will be deleted, all the stack will be deleted
//Using the next 2 functions we can tell where the protocol deletion will stop
/*!
@brief Deletes the protocol
@param deleteNear: Indicates which protocol to delete.
@discussion Normally, if this protocol will be deleted, all the stack will be deleted. Using the DeleteNearProtocol and DeleteFarProtocol, we can tell where the protocol deletion will stop.
*/
void DeleteNearProtocol(bool deleteNear);
/*!
@brief Deletes the protocol
@param deleteNear: Indicates which protocol to delete.
@discussion Normally, if this protocol will be deleted, all the stack will be deleted. Using the DeleteNearProtocol and DeleteFarProtocol, we can tell where the protocol deletion will stop.
*/
void DeleteFarProtocol(bool deleteFar);
/*!
@brief Gets the far-most protocol in the protocl chain.
@discussion Far-end protocol - is the one close to the transport layer
*/
BaseProtocol *GetFarEndpoint();
/*!
@brief Gets the near-most protocol in the protocl chain.
@discussion Near-end protocol - is the one close to the business rules layer
*/
BaseProtocol *GetNearEndpoint();
/*!
@brief Tests to see if the protocol is enqueued for delete
*/
bool IsEnqueueForDelete();
/*!
@brief Gets the protocol's application
*/
BaseClientApplication * GetApplication();
//This are functions for set/get the costom parameters
//in case of outbound protocols
/*!
@brief Sets the custom parameters in case of outbound protocols
@param customParameters: Variant contaitning the custom parameters
*/
void SetOutboundConnectParameters(Variant &customParameters);
/*!
@brief Gets the custom parameters
*/
Variant &GetCustomParameters();
/*!
@brief This will return complete information about all protocols in the current stack, including the carrier if available.
@param info
*/
void GetStackStats(Variant &info, uint32_t namespaceId = 0);
//utility functions
operator string();
//
//virtuals
//
/*!
@brief This is called to initialize internal resources specific to each protocol. This is called before adding the protocol to the stack.
@param parameters
*/
virtual bool Initialize(Variant ¶meters);
/*!
@brief Enqueues the protocol to the delete queue imediatly. All transport related routines called from now on, will be ignored.
*/
virtual void EnqueueForDelete();
/*!
@brief Enqueues the protocol to the delete queue if there is no outstanding outbound data.
@param fromFarSide
*/
virtual void GracefullyEnqueueForDelete(bool fromFarSide = true);
/*!
@brief Returns the IO handler of the protocol chain.
*/
virtual IOHandler *GetIOHandler();
/*!
@brief Sets the IO Handler of the protocol chain.
@param pCarrier
*/
virtual void SetIOHandler(IOHandler *pCarrier);
/*!
@brief Gets the input buffers
*/
virtual IOBuffer * GetInputBuffer();
/*!
@brief Gets the output buffers
*/
virtual IOBuffer * GetOutputBuffer();
/*!
@brief Get the total amount of bytes that this protocol transported (raw bytes).
*/
virtual uint64_t GetDecodedBytesCount();
/*!
@brief This function can be called by anyone who wants to signal the transport layer that there is data ready to be sent. pExtraParameters usually is a pointer to an OutboundBuffer, but this depends on the protocol type.
*/
virtual bool EnqueueForOutbound();
/*!
@brief Enqueue the current protocol stack for timed event
@param seconds
*/
virtual bool EnqueueForTimeEvent(uint32_t seconds);
/*!
@brief This is invoked by the framework when the protocol is enqueued for timing oprrations
*/
virtual bool TimePeriodElapsed();
/*!
@brief This is invoked by the framework when the underlaying system is ready to send more data
*/
virtual void ReadyForSend();
/*!
* @brief This is invoked from various parts of the project to signal inter-protocol events.
@param event
* @discussion For example, you enqueue a DNS request and you want to be informed when the request is done and the results are available. It will always bubble up towards the near protocol
*/
virtual void SignalInterProtocolEvent(Variant &event);
/*!
@brief Sets the protocol's application
@param application
*/
virtual void SetApplication(BaseClientApplication *pApplication);
/*!
@brief This is called by the framework when data is available for processing, when making use of connection-less protocols
@param buffer
@param pPeerAddress
*/
virtual bool SignalInputData(IOBuffer &buffer, sockaddr_in *pPeerAddress);
/*!
@brief This is called by the framework when data is available for processing, directly from the network i/o layer
@brief recvAmount
@param pPeerAddress
*/
virtual bool SignalInputData(int32_t recvAmount, sockaddr_in *pPeerAddress);
/*!
@brief This will return a Variant containing various statistic information. This should be overridden if more/less info is desired
@param info
*/
virtual void GetStats(Variant &info, uint32_t namespaceId = 0);
//
//must be implemented by the class that inherits this class
//
/*!
@brief Should return true if this protocol can be linked with a far protocol of type 'type'. Otherwise should return false
@param type
@discussion This function must be implemented by the class that inherits this class
*/
virtual bool AllowFarProtocol(uint64_t type) = 0;
/*!
@brief Should return true if this protocol can be linked with a near protocol of type 'type'. Otherwise should return false
@param type
@discussion This function must be implemented by the class that inherits this class
*/
virtual bool AllowNearProtocol(uint64_t type) = 0;
/*!
@brief This is called by the framework when data is available for processing, directly from the network i/o layer
@param recvAmount
@discussion This function must be implemented by the class that inherits this class
*/
virtual bool SignalInputData(int32_t recvAmount) = 0;
/*!
@brief This is called by the framework when data is available for processing, from the underlaying protocol (NOT i/o layer)
@param buffer
@discussion This function must be implemented by the class that inherits this class
*/
virtual bool SignalInputData(IOBuffer &buffer) = 0;
private:
//utility function
string ToString(uint32_t currentId);
};
#endif /* _BASEPROTOCOL_H */
|