VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
commandSpecBuilder.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (c) 2026 MAK Technologies, Inc.
3  * All rights reserved.
4  ******************************************************************************/
5 
6 #pragma once
7 
8 #include <memory>
9 #include <string>
10 #include <unordered_map>
11 #include <unordered_set>
12 #include <vector>
13 
14 #include <json/json.h>
15 #include <tbb/mutex.h>
16 
19 #include "commandSpecJob.h"
20 #include "rwCommandSpecBuilder.h"
22 
25 class DtScenarioManager;
26 
28 {
29 public:
36  explicit DtCommandSpecBuilder(DtScenarioManager& mgr, const std::string& configFilePath = "");
37  ~DtCommandSpecBuilder() = default;
38 
42  Json::Value buildCommandSummaries(const std::vector<std::string>& filter = {}) const;
43 
53  const std::string& commandType, const std::string& objectName = "");
54 
58  void tick();
59 
66  bool isHiddenCommand(const std::string& commandType) const;
67 
71  bool isHiddenRwCommand(const std::string& commandType) const;
72 
78 
85  bool updateCommandSpecEntry(const std::string& commandType, const Json::Value& entry);
86 
87 protected:
88  // Checks the commandSpecs override file and returns a job for the override spec if found and valid, or a null job if not.
89  std::shared_ptr<DtCommandSpecJobBuilder> commandSpecJobFromOverrideFile(const std::string& commandType, const std::string& objectName) const;
90  // Checks the scripted task manager and returns a job for the command spec derived from the task metadata if found and valid, or a null job if not.
91  std::shared_ptr<DtCommandSpecJobBuilder> commandSpecFromScriptedTaskMetaData(const std::string& commandType, const std::string& objectName) const;
92  // Checks if commandType corresponds to a registered RW task/set type and returns a job for the command spec built from the RW factory if so, or a null job if not.
93  std::shared_ptr<DtCommandSpecJobBuilder> commandSpecJobFromRwFactory(const std::string& commandType, const std::string& objectName) const;
94 
95 
96 private:
98  {
99  std::string commandType;
100  std::string displayName;
101  int level = 1;
102  std::string group;
103  std::string icon;
104  bool magic = false;
105  };
106 
108  std::vector<DtCatalogEntry> myCatalog;
110  std::unordered_map<std::string, size_t> myCatalogIndex;
111  // Full spec overrides loaded from the config file, keyed by commandType.
112  std::unordered_map<std::string, Json::Value> myCommandSpecOverrides;
113 
120 
124  std::unordered_set<std::string> myRwCommandTypes;
128  std::unordered_set<std::string> myVisibleRwCommands;
131 
139  mutable tbb::mutex myWriteMutex;
140 
141  void initializeCatalog();
142  void loadCommandSpecFile(const std::string& filePath);
143 
145  static constexpr int theSpecTimeoutMs = 5000;
146 
147 
148 
153  static std::string groupFromMetaData(const DtScriptedTaskMetaData& metaData);
154 
160 
164 
168  std::vector<std::weak_ptr<DtCommandSpecJobBuilder>> myPendingJobBuilders;
169 };
Definition: scenarioManager.h:40
std::unordered_map< std::string, Json::Value > myCommandSpecOverrides
Definition: commandSpecBuilder.h:112
int level
Definition: commandSpecBuilder.h:101
DtRemoteControlScriptedTaskManager & myScriptedTaskManager
Definition: commandSpecBuilder.h:118
std::string commandType
Definition: commandSpecBuilder.h:99
std::unordered_map< std::string, size_t > myCatalogIndex
Fast lookup from commandType string to index in myCatalog.
Definition: commandSpecBuilder.h:110
static DtCatalogEntry combineCatalogEntries(const DtCatalogEntry &a, const DtCatalogEntry &b)
Combines two catalog entries into one, preferring non-empty fields from the first entry and falling b...
std::unordered_set< std::string > myRwCommandTypes
Set of all RW task/set type strings registered in the VRF factory at construction time...
Definition: commandSpecBuilder.h:124
~DtCommandSpecBuilder()=default
DtCommandSpecBuilder(DtScenarioManager &mgr, const std::string &configFilePath="")
configFilePath — path to an optional JSON file that may override or supplement the built-in command c...
Central registry mapping wire-type strings to async DtCommandSpecParamBuilder factories.
Definition: customParamBuilderRegistry.h:46
std::string myCommandSpecsFilePath
Path passed to the constructor; used for write-back by updateCommandSpecEntry.
Definition: commandSpecBuilder.h:133
Definition: commandSpecBuilder.h:97
Json::Value buildRwCommandSpecsConfig() const
Returns a JSON array of all registered RW command types merged with any existing configuration from c...
static constexpr int theSpecTimeoutMs
Timeout used when waiting for async command spec data.
Definition: commandSpecBuilder.h:145
std::unordered_set< std::string > myVisibleRwCommands
Command types explicitly allowed by commandSpecs.json (&quot;hidden&quot; absent or false). Only populated when...
Definition: commandSpecBuilder.h:128
DtCommandSpecJobHandle buildCommandSpec(const std::string &commandType, const std::string &objectName="")
Returns the full parameter spec for a single command type as a job handle. If objectName is non-empty...
DtScriptedTaskParamSpecBuilder myParamSpecBuilder
Definition: commandSpecBuilder.h:116
std::string displayName
Definition: commandSpecBuilder.h:100
std::shared_ptr< DtCommandSpecJob > DtCommandSpecJobHandle
Shared-ownership handle to a DtCommandSpecJob.
Definition: commandSpecJob.h:57
DtRwCommandSpecBuilder.
Definition: rwCommandSpecBuilder.h:33
Awaitable result handle for asynchronous command spec building.
static std::string groupFromMetaData(const DtScriptedTaskMetaData &metaData)
Returns the group string extracted from the first menu location in metaData. The group is the text th...
Registry of custom command spec parameter builders, keyed on wire type string.
std::vector< DtCatalogEntry > myCatalog
Ordered catalog of all known command types and their display metadata.
Definition: commandSpecBuilder.h:108
Translates catalog JSON parameter descriptors into DtCommandSpecParamBuilder instances.
Definition: catalogParamSpecBuilder.h:24
bool magic
Definition: commandSpecBuilder.h:104
IMGUI_API void Value(const char *prefix, bool b)
bool isHiddenRwCommand(const std::string &commandType) const
Returns true if commandSpecs.json was loaded and the commandType is not listed there (or is listed wi...
Definition: remoteControlScriptedTaskManager.h:29
bool myCommandSpecFileWasLoaded
True once a commandSpecs.json file has been successfully parsed.
Definition: commandSpecBuilder.h:130
std::vector< std::weak_ptr< DtCommandSpecJobBuilder > > myPendingJobBuilders
Weak references to in-progress job builders. Only jobs that were not yet complete at creation time ar...
Definition: commandSpecBuilder.h:168
bool isHiddenCommand(const std::string &commandType) const
Returns true if commandType should be suppressed from the AvailableCommands list sent to web clients...
std::shared_ptr< DtCommandSpecJobBuilder > commandSpecJobFromRwFactory(const std::string &commandType, const std::string &objectName) const
Json::Value myRawFileRoot
Entire parsed commandSpecs.json root. Pre-initialised to {&quot;commands&quot;:[]} so that updateCommandSpecEnt...
Definition: commandSpecBuilder.h:137
DtRwCommandSpecBuilder myRwCommandSpecBuilder
Definition: commandSpecBuilder.h:117
void tick()
Advances all pending DtCommandSpecJobBuilder instances: removes expired or completed jobs...
std::string icon
Definition: commandSpecBuilder.h:103
std::string group
Definition: commandSpecBuilder.h:102
std::shared_ptr< DtCommandSpecJobBuilder > commandSpecFromScriptedTaskMetaData(const std::string &commandType, const std::string &objectName) const
DtScriptedTaskParamSpecBuilder.
Definition: scriptedTaskParamSpecBuilder.h:32
Json::Value buildCommandSummaries(const std::vector< std::string > &filter={}) const
Returns a JSON array of lightweight command summaries. If filter is non-empty, only entries whose com...
std::shared_ptr< DtCommandSpecJobBuilder > commandSpecJobFromOverrideFile(const std::string &commandType, const std::string &objectName) const
DtScenarioManager & myScenarioManager
Definition: commandSpecBuilder.h:119
DtCatalogParamSpecBuilder myCatalogParamSpecBuilder
Definition: commandSpecBuilder.h:115
tbb::mutex myWriteMutex
Serialises concurrent configure writes and the config read endpoint.
Definition: commandSpecBuilder.h:139
Translates JSON catalog parameter descriptors into DtCommandSpecParamBuilder instances.
class DtScriptedTaskMetaData
Definition: scriptedTaskMetaData.h:58
void loadCommandSpecFile(const std::string &filePath)
DtCustomParamBuilderRegistry myCustomParamRegistry
Definition: commandSpecBuilder.h:114
Definition: commandSpecBuilder.h:27
bool updateCommandSpecEntry(const std::string &commandType, const Json::Value &entry)
Upserts the entry for commandType in the in-memory raw config and writes the updated commandSpecs...
static DtCatalogEntry catalogEntryFromScriptedTaskMetaData(const DtScriptedTaskMetaData &metaData)
Extracts the summary catalog fields (CommandType, DisplayName, Group, Icon, Level) from scripted task...

Document ID: Generated on Thu Oct 15 21:27:02 EDT 2026 from SVN revision 296421
Copyright © 2005-2026 MAK Technologies. All Rights Reserved (www.mak.com)