PageRenderTime 32ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/llcommandmanager.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 202 lines | 127 code | 50 blank | 25 comment | 2 complexity | fff90c6aba6f008957b0716d52cbd3b5 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llcommandmanager.h
  3. * @brief LLCommandManager class to hold commands
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2011, 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_LLCOMMANDMANAGER_H
  27. #define LL_LLCOMMANDMANAGER_H
  28. #include "llinitparam.h"
  29. #include "llsingleton.h"
  30. class LLCommand;
  31. class LLCommandManager;
  32. class LLCommandId
  33. {
  34. public:
  35. friend class LLCommand;
  36. friend class LLCommandManager;
  37. struct Params : public LLInitParam::Block<Params>
  38. {
  39. Mandatory<std::string> name;
  40. Params()
  41. : name("name")
  42. {}
  43. };
  44. LLCommandId(const std::string& name)
  45. {
  46. mUUID = LLUUID::generateNewID(name);
  47. }
  48. LLCommandId(const Params& p)
  49. {
  50. mUUID = LLUUID::generateNewID(p.name);
  51. }
  52. LLCommandId(const LLUUID& uuid)
  53. : mUUID(uuid)
  54. {}
  55. const LLUUID& uuid() const { return mUUID; }
  56. bool operator!=(const LLCommandId& command) const
  57. {
  58. return (mUUID != command.mUUID);
  59. }
  60. bool operator==(const LLCommandId& command) const
  61. {
  62. return (mUUID == command.mUUID);
  63. }
  64. static const LLCommandId null;
  65. private:
  66. LLUUID mUUID;
  67. };
  68. typedef std::list<LLCommandId> command_id_list_t;
  69. class LLCommand
  70. {
  71. public:
  72. struct Params : public LLInitParam::Block<Params>
  73. {
  74. Mandatory<bool> available_in_toybox;
  75. Mandatory<std::string> icon;
  76. Mandatory<std::string> label_ref;
  77. Mandatory<std::string> name;
  78. Mandatory<std::string> tooltip_ref;
  79. Mandatory<std::string> execute_function;
  80. Optional<LLSD> execute_parameters;
  81. Optional<std::string> execute_stop_function;
  82. Optional<LLSD> execute_stop_parameters;
  83. Optional<std::string> is_enabled_function;
  84. Optional<LLSD> is_enabled_parameters;
  85. Optional<std::string> is_running_function;
  86. Optional<LLSD> is_running_parameters;
  87. Optional<std::string> is_starting_function;
  88. Optional<LLSD> is_starting_parameters;
  89. Params();
  90. };
  91. LLCommand(const LLCommand::Params& p);
  92. const bool availableInToybox() const { return mAvailableInToybox; }
  93. const std::string& icon() const { return mIcon; }
  94. const LLCommandId& id() const { return mIdentifier; }
  95. const std::string& labelRef() const { return mLabelRef; }
  96. const std::string& name() const { return mName; }
  97. const std::string& tooltipRef() const { return mTooltipRef; }
  98. const std::string& executeFunctionName() const { return mExecuteFunction; }
  99. const LLSD& executeParameters() const { return mExecuteParameters; }
  100. const std::string& executeStopFunctionName() const { return mExecuteStopFunction; }
  101. const LLSD& executeStopParameters() const { return mExecuteStopParameters; }
  102. const std::string& isEnabledFunctionName() const { return mIsEnabledFunction; }
  103. const LLSD& isEnabledParameters() const { return mIsEnabledParameters; }
  104. const std::string& isRunningFunctionName() const { return mIsRunningFunction; }
  105. const LLSD& isRunningParameters() const { return mIsRunningParameters; }
  106. const std::string& isStartingFunctionName() const { return mIsStartingFunction; }
  107. const LLSD& isStartingParameters() const { return mIsStartingParameters; }
  108. private:
  109. LLCommandId mIdentifier;
  110. bool mAvailableInToybox;
  111. std::string mIcon;
  112. std::string mLabelRef;
  113. std::string mName;
  114. std::string mTooltipRef;
  115. std::string mExecuteFunction;
  116. LLSD mExecuteParameters;
  117. std::string mExecuteStopFunction;
  118. LLSD mExecuteStopParameters;
  119. std::string mIsEnabledFunction;
  120. LLSD mIsEnabledParameters;
  121. std::string mIsRunningFunction;
  122. LLSD mIsRunningParameters;
  123. std::string mIsStartingFunction;
  124. LLSD mIsStartingParameters;
  125. };
  126. class LLCommandManager
  127. : public LLSingleton<LLCommandManager>
  128. {
  129. public:
  130. struct Params : public LLInitParam::Block<Params>
  131. {
  132. Multiple< LLCommand::Params, AtLeast<1> > commands;
  133. Params()
  134. : commands("command")
  135. {
  136. }
  137. };
  138. LLCommandManager();
  139. ~LLCommandManager();
  140. U32 commandCount() const;
  141. LLCommand * getCommand(U32 commandIndex);
  142. LLCommand * getCommand(const LLCommandId& commandId);
  143. static bool load();
  144. protected:
  145. void addCommand(LLCommand * command);
  146. private:
  147. typedef std::map<LLUUID, U32> CommandIndexMap;
  148. typedef std::vector<LLCommand *> CommandVector;
  149. CommandVector mCommands;
  150. CommandIndexMap mCommandIndices;
  151. };
  152. #endif // LL_LLCOMMANDMANAGER_H