PageRenderTime 118ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llmessage/lldispatcher.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 113 lines | 45 code | 14 blank | 54 comment | 0 complexity | e8a6a2456b7286f173fb5b493822c69c MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lldispatcher.h
  3. * @brief LLDispatcher class header file.
  4. *
  5. * $LicenseInfo:firstyear=2004&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLDISPATCHER_H
  27. #define LL_LLDISPATCHER_H
  28. #include <map>
  29. #include <vector>
  30. #include <string>
  31. class LLDispatcher;
  32. class LLMessageSystem;
  33. class LLUUID;
  34. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  35. // Class LLDispatchHandler
  36. //
  37. // Abstract base class for handling dispatches. Derive your own
  38. // classes, construct them, and add them to the dispatcher you want to
  39. // use.
  40. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  41. class LLDispatchHandler
  42. {
  43. public:
  44. typedef std::vector<std::string> sparam_t;
  45. //typedef std::vector<S32> iparam_t;
  46. LLDispatchHandler() {}
  47. virtual ~LLDispatchHandler() {}
  48. virtual bool operator()(
  49. const LLDispatcher* dispatcher,
  50. const std::string& key,
  51. const LLUUID& invoice,
  52. const sparam_t& string) = 0;
  53. //const iparam_t& integers) = 0;
  54. };
  55. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  56. // Class LLDispatcher
  57. //
  58. // Basic utility class that handles dispatching keyed operations to
  59. // function objects implemented as LLDispatchHandler derivations.
  60. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  61. class LLDispatcher
  62. {
  63. public:
  64. typedef std::string key_t;
  65. typedef std::vector<std::string> keys_t;
  66. typedef std::vector<std::string> sparam_t;
  67. //typedef std::vector<S32> iparam_t;
  68. // construct a dispatcher.
  69. LLDispatcher();
  70. virtual ~LLDispatcher();
  71. // Returns if they keyed handler exists in this dispatcher.
  72. bool isHandlerPresent(const key_t& name) const;
  73. // copy all known keys onto keys_t structure
  74. void copyAllHandlerNames(keys_t& names) const;
  75. // Call this method with the name of the request that has come
  76. // in. If the handler is present, it is called with the params and
  77. // returns the return value from
  78. bool dispatch(
  79. const key_t& name,
  80. const LLUUID& invoice,
  81. const sparam_t& strings) const;
  82. //const iparam_t& itegers) const;
  83. // Add a handler. If one with the same key already exists, its
  84. // pointer is returned, otherwise returns NULL. This object does
  85. // not do memory management of the LLDispatchHandler, and relies
  86. // on the caller to delete the object if necessary.
  87. LLDispatchHandler* addHandler(const key_t& name, LLDispatchHandler* func);
  88. // Helper method to unpack the dispatcher message bus
  89. // format. Returns true on success.
  90. static bool unpackMessage(
  91. LLMessageSystem* msg,
  92. key_t& method,
  93. LLUUID& invoice,
  94. sparam_t& parameters);
  95. protected:
  96. typedef std::map<key_t, LLDispatchHandler*> dispatch_map_t;
  97. dispatch_map_t mHandlers;
  98. };
  99. #endif // LL_LLDISPATCHER_H