diff options
| author | kwacker <vdr@w-i-r.com> | 2010-04-11 13:46:11 +0200 |
|---|---|---|
| committer | kwacker <vdr@w-i-r.com> | 2010-04-11 13:46:11 +0200 |
| commit | 9b144d30e0ea8ce900c37b96ba2cbdda14b0ae88 (patch) | |
| tree | 3a52de029f950dcd9f9856a53fd67abef8519e68 /plugins/streamdev/streamdev-cvs/server/connection.h | |
| parent | 9cd931834ecadbf5efefdf484abb966e9248ebbb (diff) | |
| download | x-vdr-9b144d30e0ea8ce900c37b96ba2cbdda14b0ae88.tar.gz x-vdr-9b144d30e0ea8ce900c37b96ba2cbdda14b0ae88.tar.bz2 | |
Burn 0.2.0-beta3 und Streamdev mit Paches aktualisiert
Diffstat (limited to 'plugins/streamdev/streamdev-cvs/server/connection.h')
| -rw-r--r-- | plugins/streamdev/streamdev-cvs/server/connection.h | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/plugins/streamdev/streamdev-cvs/server/connection.h b/plugins/streamdev/streamdev-cvs/server/connection.h new file mode 100644 index 0000000..73cb3d5 --- /dev/null +++ b/plugins/streamdev/streamdev-cvs/server/connection.h @@ -0,0 +1,99 @@ +/* + * $Id: connection.h,v 1.8 2009/09/18 10:43:26 schmirl Exp $ + */ + +#ifndef VDR_STREAMDEV_SERVER_CONNECTION_H +#define VDR_STREAMDEV_SERVER_CONNECTION_H + +#include "tools/socket.h" +#include "common.h" + +class cChannel; +class cDevice; + +/* Basic capabilities of a straight text-based protocol, most functions + virtual to support more complicated protocols */ + +class cServerConnection: public cListObject, public cTBSocket +{ +private: + const char *m_Protocol; + bool m_DeferClose; + bool m_Pending; + + char m_ReadBuffer[MAXPARSEBUFFER]; + uint m_ReadBytes; + + char m_WriteBuffer[MAXPARSEBUFFER]; + uint m_WriteBytes; + uint m_WriteIndex; + +protected: + /* Will be called when a command terminated by a newline has been + received */ + virtual bool Command(char *Cmd) = 0; + + /* Will put Message into the response queue, which will be sent in the next + server cycle. Note that Message will be line-terminated by Respond. + Only one line at a time may be sent. If there are lines to follow, set + Last to false. Command(NULL) will be called in the next cycle, so you can + post the next line. */ + virtual bool Respond(const char *Message, bool Last = true, ...); + //__attribute__ ((format (printf, 2, 4))); + + static const cChannel *ChannelFromString(const char *String, int *Apid = NULL); + +public: + /* If you derive, specify a short string such as HTTP for Protocol, which + will be displayed in error messages */ + cServerConnection(const char *Protocol, int Type = SOCK_STREAM); + virtual ~cServerConnection(); + + /* If true, any client IP will be accepted */ + virtual bool CanAuthenticate(void) { return false; } + + /* Gets called if the client has been accepted by the core */ + virtual void Welcome(void) { } + + /* Gets called if the client has been rejected by the core */ + virtual void Reject(void) { DeferClose(); } + + /* Get the client socket's file number */ + virtual int Socket(void) const { return (int)*this; } + + /* Determine if there is data to send or any command pending */ + virtual bool HasData(void) const; + + /* Gets called by server when the socket can accept more data. Writes + the buffer filled up by Respond(). Calls Command(NULL) if there is a + command pending. Returns false in case of an error */ + virtual bool Write(void); + + /* Gets called by server when there is incoming data to read. Calls + Command() for each line. Returns false in case of an error, or if + the connection shall be closed and removed by the server */ + virtual bool Read(void); + + /* Is polled regularely by the server. Returns true if the connection + needs to be terminated. */ + virtual bool Abort(void) const = 0; + + /* Will make the socket close after sending all queued output data */ + void DeferClose(void) { m_DeferClose = true; } + + /* Will retrieve an unused device for transmitting data. Use the returned + cDevice in a following call to StartTransfer */ + cDevice *GetDevice(const cChannel *Channel, int Priority); + + virtual void Flushed(void) {} + + virtual void Detach(void) = 0; + virtual void Attach(void) = 0; +}; + +inline bool cServerConnection::HasData(void) const +{ + return m_WriteBytes > 0 || m_Pending || m_DeferClose; +} + +#endif // VDR_STREAMDEV_SERVER_CONNECTION_H |
