Vault  4.1
vmessage.h
Go to the documentation of this file.
00001 /*
00002 Copyright c1997-2014 Trygve Isaacson. All rights reserved.
00003 This file is part of the Code Vault version 4.1
00004 http://www.bombaydigital.com/
00005 License: MIT. See LICENSE.md in the Vault top level directory.
00006 */
00007 
00008 #ifndef vmessage_h
00009 #define vmessage_h
00010 
00011 #include "vtypes.h"
00012 #include "vstring.h"
00013 #include "vbinaryiostream.h"
00014 #include "vmemorystream.h"
00015 
00022 class VServer;
00023 
00024 typedef Vs32 VMessageLength;    
00025 typedef int  VMessageID;        
00026 
00028 #define VLOGGER_MESSAGE_LEVEL(level, message) VLOGGER_NAMED_LEVEL(VMessage::kMessageLoggerName, level, message)
00029 
00030 #define VLOGGER_MESSAGE_FATAL(message) VLOGGER_NAMED_FATAL(VMessage::kMessageLoggerName, message)
00031 
00032 #define VLOGGER_MESSAGE_ERROR(message) VLOGGER_NAMED_ERROR(VMessage::kMessageLoggerName, message)
00033 
00034 #define VLOGGER_MESSAGE_WARN(message) VLOGGER_NAMED_WARN(VMessage::kMessageLoggerName, message)
00035 
00036 #define VLOGGER_MESSAGE_INFO(message) VLOGGER_NAMED_INFO(VMessage::kMessageLoggerName, message)
00037 
00038 #define VLOGGER_MESSAGE_DEBUG(message) VLOGGER_NAMED_DEBUG(VMessage::kMessageLoggerName, message)
00039 
00040 #define VLOGGER_MESSAGE_TRACE(message) VLOGGER_NAMED_TRACE(VMessage::kMessageLoggerName, message)
00041 
00042 #define VLOGGER_MESSAGE_HEXDUMP(message, buffer, length) VLOGGER_NAMED_HEXDUMP(VMessage::kMessageLoggerName, VMessage::kMessageContentHexDumpLevel, message, buffer, length)
00043 
00044 #define VLOGGER_MESSAGE_WOULD_LOG(level) VLOGGER_NAMED_WOULD_LOG(VMessage::kMessageLoggerName, level)
00045 
00052 class VMessage : public VBinaryIOStream {
00053     public:
00054 
00064         virtual void recycleForSend(VMessageID messageID);
00071         virtual void recycleForReceive();
00072 
00077         void setMessageID(VMessageID messageID) { mMessageID = messageID; }
00081         VMessageID getMessageID() const { return mMessageID; }
00082 
00094         virtual void send(const VString& sessionLabel, VBinaryIOStream& out) = 0;
00104         virtual void receive(const VString& sessionLabel, VBinaryIOStream& in) = 0;
00117         void copyMessageData(VMessage& targetMessage) const;
00118 
00124         VMessageLength getMessageDataLength() const;
00133         Vu8* getBuffer() const;
00139         Vs64 getBufferSize() const;
00140         /*
00141         These are the log level definitions used for consistent logging
00142         of message traffic, processing, and dispatch. Use these
00143         levels and log to the appropriate logger -- whose name is usually in
00144         the path form "vault.messages.{classname}.{messageid}" -- in order to
00145         be consistent in message logging.
00146         There are issues with some compilers and lazy constant evaluation even
00147         though these are ints, so we define the actual values in the .cpp file
00148         separately.
00149 
00150         The format of logged messages should be:
00151          [session-label] data
00152         where session-label is:
00153          id:ip:port
00154         where id is some descriptive name of the session that does not distinguish which
00155         client it is (since the ip:port does that)
00156 
00157         Use the macros defined at the top of this file to emit message log output.
00158         */
00159         static const VString kMessageLoggerName;
00160         static const int kMessageContentRecordingLevel; 
00161         static const int kMessageHeaderLevel;           
00162         static const int kMessageContentFieldsLevel;    
00163         static const int kMessageTrafficDetailsLevel;   
00164         static const int kMessageHandlerDispatchLevel;  
00165         static const int kMessageHandlerDetailLevel;    
00166         static const int kMessageContentHexDumpLevel;   
00167         static const int kMessageQueueOpsLevel;         
00168         static const int kMessageTraceDetailLevel;      
00169         static const int kMessageHandlerLifecycleLevel; 
00170 
00171     protected:
00172 
00178         VMessage();
00185         VMessage(VMessageID messageID, Vs64 initialBufferSize = 1024);
00189         virtual ~VMessage() {}
00190 
00191         mutable VMemoryStream    mMessageDataBuffer;        
00192 
00193     private:
00194 
00195         VMessage(const VMessage&); // not copyable
00196         VMessage& operator=(const VMessage&); // not assignable
00197 
00198         VMessageID      mMessageID;             
00199 };
00200 
00201 typedef VSharedPtr<VMessage> VMessagePtr;
00202 typedef VSharedPtr<const VMessage> VMessageConstPtr;
00203 
00210 class VMessageFactory {
00211     public:
00212 
00213         VMessageFactory() {}
00214         virtual ~VMessageFactory() {}
00215 
00222         virtual VMessagePtr instantiateNewMessage(VMessageID messageID = 0) const = 0;
00223 };
00224 
00225 #endif /* vmessage_h */

Copyright ©1997-2014 Trygve Isaacson. All rights reserved. This documentation was generated with Doxygen.