MAK RTIspy API Documentation for HLA Evolved
basicEhsDoc.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  ** Copyright (c) 2006 MaK Technologies, Inc.
00003  ** All rights reserved.
00004  *********************************************************************/
00005 /*******************************************************************************
00006  ** $RCSfile: basicEhsDoc.h,v $ $Revision: 1.11 $ $State: Exp $
00007  *******************************************************************************/
00008 #ifndef DtBasicEhsDoc_H_
00009 #define DtBasicEhsDoc_H_
00010 
00011 #include <rtiMsConfig.h>
00012 #include "webSpyUtils.h"
00013 
00014 #include <wwwRequestXmlBlock.h>
00015 #include <lrcEventLog.h>
00016 #include <vlutil/vlString.h>
00017 #include <vlutil/vlSmartPointers.h>
00018 #include <vlutil/vlThreadSafe.h>
00019 
00020 #include <ehs.h>
00021 
00022 // Forward References
00023 class DtBasicEhsDoc;
00024 typedef DtBoost::shared_ptr<DtBasicEhsDoc> DtBasicEhsDocSP;
00025 typedef DtBoost::weak_ptr<DtBasicEhsDoc>   DtBasicEhsDocWP;
00026 
00027 
00028 // The DtBasicEhsDoc is the base class for all MAK RTI EHS pages
00029 // NOTE: any changes to basic EHS functionality should be made by extending this class
00030 //       without modification to the 3rd party library
00031 class DT_DLL_WWWEHS DtBasicEhsDoc : public EHS
00032 {
00033 private:
00034    // No default constructor
00035    DtBasicEhsDoc();
00036    // Copy Constructor not implimented : Copy not allowed
00037    DtBasicEhsDoc(const DtBasicEhsDoc&);
00038    // Assignment not implimented : Copy not allowed
00039    DtBasicEhsDoc& operator=(const DtBasicEhsDoc&);
00040 
00041 public:
00042    
00043    DtBasicEhsDoc( const DtString& name );
00044    virtual ~DtBasicEhsDoc();
00045 
00046    inline DtString name() const;
00047 
00048    // Takes ownership of a new state update for the web server connection represented
00049    // by this page ( if appendToExisting is set, the new state extends the existing state)
00050    virtual void updateState( std::auto_ptr< DtWebSpyUtils::ConnectionState > connState, bool appendToExisting );
00051 
00052    // Get the current page for the requested component
00053    std::auto_ptr< DtString > getComponentState(
00054       unsigned long componentId, DtWebSpyUtils::StateComponentType stateType ) const;
00055 
00056 
00057    // Append an event to the page's connection log
00058    virtual void appendLogEvent( unsigned long componentId, DtLrcConsoleLogXmlBlockSP logSegmentSP );
00059 
00060    // Over-rides the base EHS request handler.
00061    // It adds default handling for file requests and calls the derived
00062    // class' specialization for all other requests
00063    virtual ResponseCode HandleRequest( HttpRequest * ipoHttpRequest, 
00064                                        HttpResponse * ipoHttpResponse );
00065 
00066    // Return a handle to the sub-document registered by the requested name
00067    // Returns null if child not found (or not a DtBasicEhsDoc)
00068    virtual DtBasicEhsDoc* childDoc( const DtString& childName );
00069 
00070 protected:
00071 
00072    typedef std::auto_ptr< DtString > ( DtBasicEhsDoc::*RequestHandlerFn)( unsigned long,
00073       DtWwwRequestXmlBlockSP requestSP, std::auto_ptr< DtString > requestString );
00074 
00075    typedef std::map< DtWebSpyUtils::WwwControlMsgCommandId, RequestHandlerFn > MessageHandlersByKindMap;
00076 
00077    // Default handler for file requests (ex. .htm and .jpg files )
00078    virtual ResponseCode HandleFileRequest( HttpRequest * ipoHttpRequest, 
00079                                            HttpResponse * ipoHttpResponse );
00080 
00081    // Handler to deal with all non-file requests
00082    // - the standard EHS doc tree is mapped as a directory structure
00083    // - Derived classes may over-ride this method to serve the page, 
00084    //   but they must ensure that all operations are thread-safe
00085    //   (ie - if page uses more than just myPage (which is threadsafe))
00086    // - By default, the page expects HttpRequests to come in the form of WwwRequest messages
00087    //   or just empty requests for the default state page
00088    virtual ResponseCode HandleNonFileRequest( HttpRequest * ipoHttpRequest, 
00089                                               HttpResponse * ipoHttpResponse );
00090 
00091 
00092    // Parse the HTTP Request call a registered Request Handler to return the requested page
00093    // Handlers may forward the request message from the web client to the HTTP server for processing
00094    std::auto_ptr< DtString > processHttpRequest( HttpRequest * ipoHttpRequest );
00095 
00096 
00097    // Parse an XML request from the web client into a usable form
00098    DtWwwRequestXmlBlockSP parseWebClientRequestMessage( const DtString& request ) const;
00099 
00100 
00101    // Return the value of the first instance of a name/value pair in an XML request
00102    // - returns null string if name not found
00103    virtual DtString getRequestParam( const DtString& paramName, DtWwwRequestXmlBlockSP request ) const;
00104 
00105    // Set the value of the first instance of a name/value pair in an XML request ( adds a new param if it
00106    // does not exist )
00107    void setRequestParam( const DtString& paramName, const DtString& paramVal, DtWwwRequestXmlBlockSP request ) const;
00108 
00109 
00110    // Error Condition Responses:
00111 
00112    // 403 - forbidden uri
00113    virtual ResponseCode forbiddenUriResponse403( HttpRequest * ipoHttpRequest, HttpResponse * ipoHttpResponse );
00114 
00115    // 404 - file not found
00116    virtual ResponseCode uriNotFoundResponse404( HttpRequest * ipoHttpRequest, HttpResponse * ipoHttpResponse );
00117 
00118 
00119    // Register a handler for a specific WwwRequestMsg type
00120    void registerRequestHandler( DtWebSpyUtils::WwwControlMsgCommandId kind, DtBasicEhsDoc::RequestHandlerFn func );
00121 
00122    // UnRegister a handler for a specific WwwRequestMsg type
00123    void unRegisterRequestHandler( DtWebSpyUtils::WwwControlMsgCommandId kind, DtBasicEhsDoc::RequestHandlerFn func );
00124 
00125    // Get the registered handler for the specific WwwRequestMsg type
00126    RequestHandlerFn requestHandlerForKind( DtWebSpyUtils::WwwControlMsgCommandId kind ) const;
00127 
00128 protected:
00129 
00130    DtClock myClock;
00131 
00132    // Name with which the page is to be Registered with EHS
00133    DtString myPageName;
00134 
00135    // Cache of the current body of the page
00136    // - Not thread-safe => cannot be accessed by the web-server since EHS threads will use it
00137    DtString myPage;
00138 
00139    // WwwRequest message handlers registered by derived web pages to deal with incoming requests/commands
00140    // from the Web Client
00141    MessageHandlersByKindMap myRequestHandlers;
00142 
00143 
00144    // The current state of the RTI component(s) represented by this page
00145    // - myState is threadsafe since it is updated by the WwwSpy thread and read by the EHS thread
00146    DtThreadSafe< DtWebSpyUtils::ConnectionState > myState;
00147 
00148    // The current event log(s) of the RTI LRC component(s) represented by this page
00149    // - myLog is threadsafe since it is updated by the WwwSpy thread and read by the EHS thread
00150    DtThreadSafe< DtLrcEventLog > myLrcLogs;
00151 };
00152 
00153 DtString DtBasicEhsDoc::name() const { return myPageName; }
00154 
00155 #endif // DtBasicEhsDoc_H_

Document ID: Generated on Thu Jun 14 14:15:04 EDT 2012 from SVN revision 116116
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)