diff options
author | Chris Wilson <chris+github@qwirx.com> | 2011-08-27 14:06:46 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2011-08-27 14:06:46 +0000 |
commit | a473bb0923b0f7800bb95ef96ba20f5cf6cbe5b4 (patch) | |
tree | 68620eb4a0566889c5a2e903a5b2fb0b678d9613 /lib/server/Protocol.h | |
parent | 50aac86024fae12072a240e6b952c9bb11437956 (diff) |
Combine client and server protocols to make way for an offline/local protocol.
Rename ProtocolObject to Message.
Diffstat (limited to 'lib/server/Protocol.h')
-rw-r--r-- | lib/server/Protocol.h | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/lib/server/Protocol.h b/lib/server/Protocol.h index e037e33c..42cb0ff8 100644 --- a/lib/server/Protocol.h +++ b/lib/server/Protocol.h @@ -12,12 +12,14 @@ #include <sys/types.h> -class IOStream; -#include "ProtocolObject.h" #include <memory> #include <vector> #include <string> +#include "Message.h" + +class IOStream; + // default timeout is 15 minutes #define PROTOCOL_DEFAULT_TIMEOUT (15*60*1000) // 16 default maximum object size -- should be enough @@ -40,11 +42,14 @@ public: private: Protocol(const Protocol &rToCopy); +protected: + // Unsafe to make public, as they may allow sending objects + // from a different protocol. The derived class prevents this. + std::auto_ptr<Message> ReceiveInternal(); + void SendInternal(const Message &rObject); + public: void Handshake(); - std::auto_ptr<ProtocolObject> Receive(); - void Send(const ProtocolObject &rObject); - std::auto_ptr<IOStream> ReceiveStream(); void SendStream(IOStream &rStream); @@ -54,8 +59,6 @@ public: UnknownError = 0 }; - bool GetLastError(int &rTypeOut, int &rSubTypeOut); - // -------------------------------------------------------------------------- // // Function @@ -87,7 +90,7 @@ public: // -------------------------------------------------------------------------- void SetMaxObjectSize(unsigned int NewMaxObjSize) {mMaxObjectSize = NewMaxObjSize;} - // For ProtocolObject derived classes + // For Message derived classes void Read(void *Buffer, int Size); void Read(std::string &rOut, int Size); void Read(int64_t &rOut); @@ -168,11 +171,15 @@ public: { ProtocolStream_SizeUncertain = 0xffffffff }; + bool GetLogToSysLog() { return mLogToSysLog; } + FILE *GetLogToFile() { return mLogToFile; } + void SetLogToSysLog(bool Log = false) {mLogToSysLog = Log;} + void SetLogToFile(FILE *File = 0) {mLogToFile = File;} -protected: - virtual std::auto_ptr<ProtocolObject> MakeProtocolObject(int ObjType) = 0; - virtual const char *GetIdentString() = 0; - void SetError(int Type, int SubType) {mLastErrorType = Type; mLastErrorSubType = SubType;} +protected: + virtual std::auto_ptr<Message> MakeMessage(int ObjType) = 0; + virtual const char *GetProtocolIdentString() = 0; + void CheckAndReadHdr(void *hdr); // don't use type here to avoid dependency // Will be used for logging @@ -183,7 +190,6 @@ private: void EnsureBufferAllocated(int Size); int SendStreamSendBlock(uint8_t *Block, int BytesInBlock); -private: IOStream &mrStream; bool mHandshakeDone; unsigned int mMaxObjectSize; @@ -193,8 +199,12 @@ private: int mReadOffset; int mWriteOffset; int mValidDataSize; - int mLastErrorType; - int mLastErrorSubType; + bool mLogToSysLog; + FILE *mLogToFile; +}; + +class ProtocolContext +{ }; #endif // PROTOCOL__H |