lldispatcher.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLDISPATCHER_H
00033 #define LL_LLDISPATCHER_H
00034 
00035 #include <map>
00036 #include <vector>
00037 #include <string>
00038 
00039 class LLDispatcher;
00040 class LLMessageSystem;
00041 class LLUUID;
00042 
00043 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00044 // Class LLDispatchHandler
00045 //
00046 // Abstract base class for handling dispatches. Derive your own
00047 // classes, construct them, and add them to the dispatcher you want to
00048 // use.
00049 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00050 
00051 class LLDispatchHandler
00052 {
00053 public:
00054         typedef std::vector<std::string> sparam_t;
00055         //typedef std::vector<S32> iparam_t;
00056         LLDispatchHandler() {}
00057         virtual ~LLDispatchHandler() {}
00058         virtual bool operator()(
00059                 const LLDispatcher* dispatcher,
00060                 const std::string& key,
00061                 const LLUUID& invoice,
00062                 const sparam_t& string) = 0;
00063         //const iparam_t& integers) = 0;
00064 };
00065 
00066 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00067 // Class LLDispatcher
00068 //
00069 // Basic utility class that handles dispatching keyed operations to
00070 // function objects implemented as LLDispatchHandler derivations.
00071 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00072 class LLDispatcher
00073 {
00074 public:
00075         typedef std::string key_t;
00076         typedef std::vector<std::string> keys_t;
00077         typedef std::vector<std::string> sparam_t;
00078         //typedef std::vector<S32> iparam_t;
00079 
00080         // construct a dispatcher.
00081         LLDispatcher();
00082         virtual ~LLDispatcher();
00083 
00084         // Returns if they keyed handler exists in this dispatcher.
00085         bool isHandlerPresent(const key_t& name) const;
00086 
00087         // copy all known keys onto keys_t structure
00088         void copyAllHandlerNames(keys_t& names) const;
00089 
00090         // Call this method with the name of the request that has come
00091         // in. If the handler is present, it is called with the params and
00092         // returns the return value from 
00093         bool dispatch(
00094                 const key_t& name,
00095                 const LLUUID& invoice,
00096                 const sparam_t& strings) const;
00097         //const iparam_t& itegers) const;
00098 
00099         // Add a handler. If one with the same key already exists, its
00100         // pointer is returned, otherwise returns NULL. This object does
00101         // not do memory management of the LLDispatchHandler, and relies
00102         // on the caller to delete the object if necessary.
00103         LLDispatchHandler* addHandler(const key_t& name, LLDispatchHandler* func);
00104 
00105         // Helper method to unpack the dispatcher message bus
00106         // format. Returns true on success.
00107         static bool unpackMessage(
00108                 LLMessageSystem* msg,
00109                 key_t& method,
00110                 LLUUID& invoice,
00111                 sparam_t& parameters);
00112 
00113 protected:
00114         typedef std::map<key_t, LLDispatchHandler*> dispatch_map_t;
00115         dispatch_map_t mHandlers;
00116 };
00117 
00118 #endif // LL_LLDISPATCHER_H

Generated on Thu Jul 1 06:08:24 2010 for Second Life Viewer by  doxygen 1.4.7