![]() |
VR-Forces Developer's Guide
|
DtRoleAssignmentStore — process-wide singleton for saved username-to-role assignments.
At startup, initialize() scans a directory of JSON saved assignment files and builds an index. A specific set is activated via loadAssignmentSet(); the caller is responsible for applying the returned assignments to active sessions.
Saved assignment JSON format (one file per named set):
Thread safety: all public methods are safe to call from concurrent threads.
Public Member Functions | |
| void | initialize (const std::string &assignmentsDir) |
| std::vector < DtAssignmentSetSummary > | listAssignmentSets () const |
| bool | getAssignmentSetById (const std::string &assignmentId, Json::Value &outJson, std::string &outError) const |
| bool | loadAssignmentSetById (const std::string &assignmentId, std::string &outError) |
| bool | loadAssignmentSet (const std::string &name) |
| std::string | createAssignmentSet (const std::string &name, const std::string &description, const std::string &scenarioName, const std::string &definitionId, const std::map< std::string, std::vector< std::string >> &assignments, std::string &outError) |
| bool | updateAssignmentSetDescription (const std::string &assignmentId, const std::string &description, std::string &outError) |
| bool | updateAssignmentSetUserRoles (const std::string &assignmentId, const std::string &username, const std::vector< std::string > &roleNames, std::string &outError) |
| bool | updateActiveAssignmentUserRoles (const std::string &username, const std::vector< std::string > &roleNames, std::string &outError) |
| bool | deleteAssignmentSet (const std::string &assignmentId, std::string &outError) |
| bool | saveActiveAssignmentSet (const std::map< std::string, std::vector< std::string >> &assignments, std::string &outError) |
| void | clearActiveAssignment () |
| std::string | activeAssignmentSetId () const |
| std::string | activeAssignmentSetName () const |
| std::string | activeAssignmentSetDescription () const |
| std::string | activeAssignmentDefinitionId () const |
| std::vector< std::string > | savedAssignments (const std::string &username) const |
| std::map< std::string, std::vector< std::string > > | allSavedAssignments () const |
| uint64_t | assignmentGeneration () const |
Static Public Member Functions | |
| static DtRoleAssignmentStore & | getInstance () |
Private Member Functions | |
| DtRoleAssignmentStore ()=default | |
Static Private Member Functions | |
| static std::vector< std::string > | scanDirectory (const std::string &dir) |
| static std::string | generateUuid () |
| static bool | readAssignmentFile (const std::string &filePath, Json::Value &outRoot, std::string &outError) |
| static bool | writeAssignmentFile (const std::string &filePath, const Json::Value &root, std::string &outError) |
Private Attributes | |
| tbb::spin_rw_mutex | myMutex |
| std::string | myAssignmentsDir |
| std::map< std::string, std::string > | myIdToFilePath |
| std::map< std::string, std::string > | myNameToId |
| std::map< std::string, DtAssignmentSetSummary > | myIndex |
| std::string | myActiveSetId |
| std::string | myActiveSetName |
| std::string | myActiveSetDescription |
| std::string | myActiveDefinitionId |
| std::map< std::string, std::vector< std::string > > | myActiveAssignments |
| std::atomic< uint64_t > | myAssignmentGeneration {0} |
|
privatedefault |
|
static |
Returns the process-wide singleton instance.
| void DtRoleAssignmentStore::initialize | ( | const std::string & | assignmentsDir | ) |
Scans assignmentsDir for *.json saved assignment files and builds the index. Ensures a reserved "default" assignment file exists in the folder. Must be called from main() before any background threads start. Logs a warning if assignmentsDir does not exist or contains no files; not an error.
| std::vector<DtAssignmentSetSummary> DtRoleAssignmentStore::listAssignmentSets | ( | ) | const |
Returns summary information for all available assignment set files.
| bool DtRoleAssignmentStore::getAssignmentSetById | ( | const std::string & | assignmentId, |
| Json::Value & | outJson, | ||
| std::string & | outError | ||
| ) | const |
Reads and returns one saved assignment set by stable assignmentId.
| bool DtRoleAssignmentStore::loadAssignmentSetById | ( | const std::string & | assignmentId, |
| std::string & | outError | ||
| ) |
Loads and activates the assignment set by stable assignmentId. Replaces any previously active set.
| bool DtRoleAssignmentStore::loadAssignmentSet | ( | const std::string & | name | ) |
Loads and activates the named assignment set. Replaces any previously active set. Compatibility helper that resolves name -> assignmentId and forwards to loadAssignmentSetById().
| std::string DtRoleAssignmentStore::createAssignmentSet | ( | const std::string & | name, |
| const std::string & | description, | ||
| const std::string & | scenarioName, | ||
| const std::string & | definitionId, | ||
| const std::map< std::string, std::vector< std::string >> & | assignments, | ||
| std::string & | outError | ||
| ) |
Creates a new saved assignment set and activates it.
| bool DtRoleAssignmentStore::updateAssignmentSetDescription | ( | const std::string & | assignmentId, |
| const std::string & | description, | ||
| std::string & | outError | ||
| ) |
Updates the saved assignment set description.
| bool DtRoleAssignmentStore::updateAssignmentSetUserRoles | ( | const std::string & | assignmentId, |
| const std::string & | username, | ||
| const std::vector< std::string > & | roleNames, | ||
| std::string & | outError | ||
| ) |
Replaces one user's role list within a saved assignment set. Passing an empty roleNames vector removes the user entry.
| bool DtRoleAssignmentStore::updateActiveAssignmentUserRoles | ( | const std::string & | username, |
| const std::vector< std::string > & | roleNames, | ||
| std::string & | outError | ||
| ) |
Replaces one user's role list within the currently active assignment set in memory. Passing an empty roleNames vector removes the user entry. Changes are not persisted to disk until saveActiveAssignmentSet() is called.
| bool DtRoleAssignmentStore::deleteAssignmentSet | ( | const std::string & | assignmentId, |
| std::string & | outError | ||
| ) |
Deletes a saved assignment set by stable assignmentId.
| bool DtRoleAssignmentStore::saveActiveAssignmentSet | ( | const std::map< std::string, std::vector< std::string >> & | assignments, |
| std::string & | outError | ||
| ) |
Saves (overwrites) the active assignment set's username -> roleNames map.
| void DtRoleAssignmentStore::clearActiveAssignment | ( | ) |
Activates the reserved "default" assignment set and cached mapping.
This is used when role-definition context changes and there should be no previously selected named assignment. The default assignment remains editable in memory but direct Save is intentionally disabled.
| std::string DtRoleAssignmentStore::activeAssignmentSetId | ( | ) | const |
Returns the stable assignmentId of the currently active set, or empty string if none.
| std::string DtRoleAssignmentStore::activeAssignmentSetName | ( | ) | const |
Returns the name of the currently active assignment set, or an empty string if none.
| std::string DtRoleAssignmentStore::activeAssignmentSetDescription | ( | ) | const |
Returns the description of the currently active assignment set, or empty string.
| std::string DtRoleAssignmentStore::activeAssignmentDefinitionId | ( | ) | const |
Returns the definitionId bound to the currently active assignment set, or empty string.
| std::vector<std::string> DtRoleAssignmentStore::savedAssignments | ( | const std::string & | username | ) | const |
Returns the role names saved for the given username in the active assignment set. Returns an empty vector if no set is active or the username is not in the set.
| std::map<std::string, std::vector<std::string> > DtRoleAssignmentStore::allSavedAssignments | ( | ) | const |
Returns a copy of the complete username -> roleNames map for the active set. Returns an empty map if no set is active.
| uint64_t DtRoleAssignmentStore::assignmentGeneration | ( | ) | const |
Monotonically increasing counter incremented whenever assignment metadata or active-assignment state changes.
|
staticprivate |
Returns full file paths for every *.json file found directly in dir.
|
staticprivate |
Generates a random UUID in 8-4-4-4-12 lowercase hex format.
|
staticprivate |
Reads one assignment file from disk.
|
staticprivate |
Writes one assignment file to disk.
|
mutableprivate |
|
private |
|
private |
assignmentId -> absolute file path
|
private |
name -> assignmentId
|
private |
assignmentId -> summary
|
private |
|
private |
|
private |
|
private |
|
private |
username -> roleNames
|
private |