Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

mutableserverrequest.h

Go to the documentation of this file.
00001 // mutableserverrequest.h: interface for the MutableServerRequest class.
00002 //
00003 // This is a virtual base class for handling within MutableServerBase.
00004 // Mostly unimplemented, it serves as a template to provide a
00005 // consistent interface.
00006 //
00007 // It adds passport handling on top of a MutableServerMessage.
00009 
00010 #if !defined(MUTABLESERVERREQUEST_H)
00011 #define MUTABLESERVERREQUEST_H
00012 
00013 #if _MSC_VER > 1000
00014 #pragma once
00015 #endif // _MSC_VER > 1000
00016 
00017 #include "mutableservermessage.h"
00018 
00019 
00020 // Each passport line is started thusly:
00021 //
00022 //  |->PP <passport_line>
00023 //
00024 //  as if:  sprintf( buffer, "%s....", MSR_PASSPORT_TAG,... )
00025 //
00026 #define MSR_PASSPORT_TAG  "PP "
00027 
00028 // After the passport, the start of the data is
00029 // indicated with this tag alone on a line:
00030 //
00031 //  |->DATA
00032 //
00033 //  as if:  sprintf( buffer, "%s\n", MSR_DATASTART_LINE );
00034 //
00035 #define MSR_DATASTART_LINE "DATA"
00036 
00037 
00038 // --------------------------------------------------------------------
00039 class MutableServerRequest : public MutableServerMessage
00040 {
00041 protected:
00042 
00043    // ----------------------------------------------------------
00044    //     virtual methods from MutableServerMessage
00045    //     to be implemented for a complete derivative classes
00046    // ----------------------------------------------------------
00047 
00048    // BufferInitAlloc -- when preparing to format a message
00049    //                    using FormatBuffer()], this is
00050    //                    first called.  The result is,
00051    //                    for the first call, MessageBuffer
00052    //                    will be assured to be at least this
00053    //                    long.
00054    //                    Overriding this method allows
00055    //                    derivative classes to minimize
00056    //                    reallocations as bits are appended
00057    //                    to the message buffer;
00058    //
00059    // NOTE: In each derivative implementation,
00060    //       call <super_class>::BufferInitAlloc() to get the
00061    //       space needed by that super class (and all baser
00062    //       classes), then add the size needed by the
00063    //       derivative to arrive at the total size needed.
00064    //       The 10 specified here is for the message-
00065    //       terminating '\n' and a slight overrun space.
00066    //
00067    long BufferInitAlloc();
00068 
00069 
00070    // FormatDerivativeData
00071    //
00072    //     Method by which derivative classes append
00073    //     their content to MessageBuffer.
00074    //
00075    //  NOTE: ALWAYS CALL <super_class>::FormatDerivativeData()
00076    //        at the start of each implementation to allow
00077    //        base classes to append their stuff (if any)
00078    //        to the buffer.
00079    //        Thus the buffer is built up from the base-most class.
00080    //
00081    // THROW worm_exception for errors
00082    //
00083    void FormatDerivativeData();
00084 
00085 
00086    // ParseDerivativeData
00087    //
00088    //     Method by which derivative classes extract
00089    //     their content to MessageBuffer.
00090    //
00091    //  NOTE: Always call <super_class>::ParseDerivativeData()
00092    //        at the top of each implementation to allow
00093    //        base classes to get their data out of the
00094    //        buffer first.
00095    //
00096    //  USAGE:
00097    //
00098    //     If parsing a multi-line message ('\n'-terminated lines),
00099    //     use a loop consisting of:
00100    //
00101    //       i = MessageBuffer.find("\n")  to find the first line end,
00102    //       MessageBuffer.substr(0, i)    to extract the string
00103    //                                        (excluding the '\n')
00104    //       MessageBuffer.erase(0, i+1)     to remove that portion
00105    //
00106    //     Since the message should be terminated by an additional
00107    //     '\n', when the string returned in the second step
00108    //     is of zero length, that is the end of the message.
00109    //
00110    //     (If find() does not, it returns MessageBuffer.npos)
00111    //
00112    // THROW worm_exception for errors
00113    //
00114    void ParseDerivativeData();
00115 
00116    // ----------------------------------------------------------
00117    //             for MutableServerRequest class
00118    // ----------------------------------------------------------
00119 
00120    std::vector<std::string> Passport;
00121 
00122 public:
00123 
00124    // ----------------------------------------------------------
00125    //             for MutableServerRequest class
00126    // ----------------------------------------------------------
00127 
00128         MutableServerRequest();
00129 
00130    void ClearPassport();
00131 
00132    void AddPassportLine( const char * p_line );
00133 
00134    void AddPassportLine( std::string p_line );
00135 
00136    int GetPassportLineCount();
00137 
00138    // GetPassportLine() -- return one of the passport lines.
00139    //
00140    //  p_index must be in the range 0 - GetPassportLineCount()
00141    //
00142    // RETURNS:
00143    //        the passport line
00144    //     or NULL if index out of range, etc.
00145    //
00146    const char * GetPassportLine( int p_index );
00147 
00148 };
00149 
00150 #endif // !defined(MUTABLESERVERREQUEST_H)

Generated on Tue May 6 09:16:06 2003 for Earthworm Libs by doxygen1.3-rc3