Robot Raconteur Core C++ Library
NodeDirectories.h
Go to the documentation of this file.
1 
24 #pragma once
25 
27 #include "RobotRaconteur/NodeID.h"
28 
29 #include <boost/filesystem/path.hpp>
30 
31 namespace RobotRaconteur
32 {
44 class ROBOTRACONTEUR_CORE_API NodeDirectories
45 {
46  public:
54  boost::filesystem::path system_data_dir;
55 
63  boost::filesystem::path system_config_dir;
64 
72  boost::filesystem::path system_state_dir;
73 
81  boost::filesystem::path system_cache_dir;
82 
90  boost::filesystem::path system_run_dir;
91 
99  boost::filesystem::path user_data_dir;
100 
108  boost::filesystem::path user_config_dir;
109 
117  boost::filesystem::path user_state_dir;
118 
126  boost::filesystem::path user_cache_dir;
127 
136  boost::filesystem::path user_run_dir;
137 };
138 
139 class NodeDirectoriesFD;
140 
145 class ROBOTRACONTEUR_CORE_API NodeDirectoriesUtil
146 {
147  public:
156  const RR_SHARED_PTR<RobotRaconteurNode>& node = RR_SHARED_PTR<RobotRaconteurNode>());
157 
163  static std::string GetLogonUserName();
164 
171  static bool IsLogonUserRoot();
172 
180  // TODO
181  // static void CreateUserNodeDirectory(const boost::filesystem::path& dir);
182 
190  // TODO
191  // static void CreateSystemPrivateNodeDirectory(const boost::filesystem::path& dir);
192 
202  // TODO
203  // static void CreateSystemPublicNodeDirectory(const boost::filesystem::path& dir);
204 
210  // TODO
211  // static void CreateUserRunDirectory(const NodeDirectories& node_dirs);
212 
221  static bool ReadInfoFile(const boost::filesystem::path& fname, std::map<std::string, std::string>& data);
222 
232  static RR_SHARED_PTR<NodeDirectoriesFD> CreatePidFile(const boost::filesystem::path& path);
233 
244  static RR_SHARED_PTR<NodeDirectoriesFD> CreateInfoFile(const boost::filesystem::path& path,
245  std::map<std::string, std::string> info);
246 
255  static void RefreshInfoFile(const RR_SHARED_PTR<NodeDirectoriesFD>& h_info,
256  const std::map<std::string, std::string>& updated_info);
257 };
258 
263 class ROBOTRACONTEUR_CORE_API GetUuidForNameAndLockResult
264 {
265  public:
276  std::string name;
281  std::vector<std::string> scope;
286  RR_SHARED_PTR<NodeDirectoriesFD> fd;
287 };
288 
311 ROBOTRACONTEUR_CORE_API GetUuidForNameAndLockResult GetUuidForNameAndLock(const NodeDirectories& node_dirs,
312  boost::string_ref name,
313  const std::vector<std::string>& scope);
314 
320 class ROBOTRACONTEUR_CORE_API NodeDirectoriesResourceAlreadyInUse : public std::runtime_error
321 {
322  public:
323  NodeDirectoriesResourceAlreadyInUse() : runtime_error("Identifier UUID or Name already in use"){};
324 };
325 
326 } // namespace RobotRaconteur
GetUuidForNameAndLockResult GetUuidForNameAndLock(const NodeDirectories &node_dirs, boost::string_ref name, const std::vector< std::string > &scope)
Get a saved UUID for a name with a specified scope.
Structure to hold result of GetUuidForNameAndLock.
Definition: NodeDirectories.h:264
NodeID uuid
The UUID assigned to the name in specified domain.
Definition: NodeDirectories.h:271
std::string name
The identifier name.
Definition: NodeDirectories.h:276
boost::shared_ptr< NodeDirectoriesFD > fd
Lock for identifier. Release fd to release the lock.
Definition: NodeDirectories.h:286
std::vector< std::string > scope
The scope of the identifier.
Definition: NodeDirectories.h:281
Directories on local system used by the node.
Definition: NodeDirectories.h:45
boost::filesystem::path system_state_dir
Robot Raconteur System config directory.
Definition: NodeDirectories.h:72
boost::filesystem::path user_cache_dir
Robot Raconteur User cache directory.
Definition: NodeDirectories.h:126
boost::filesystem::path user_config_dir
Robot Raconteur User config directory.
Definition: NodeDirectories.h:108
boost::filesystem::path system_config_dir
Robot Raconteur System config directory.
Definition: NodeDirectories.h:63
boost::filesystem::path system_run_dir
Robot Raconteur System run directory.
Definition: NodeDirectories.h:90
boost::filesystem::path system_data_dir
Robot Raconteur System data directory.
Definition: NodeDirectories.h:54
boost::filesystem::path user_state_dir
Robot Raconteur User state directory.
Definition: NodeDirectories.h:117
boost::filesystem::path system_cache_dir
Robot Raconteur System cache directory.
Definition: NodeDirectories.h:81
boost::filesystem::path user_run_dir
Robot Raconteur User state directory.
Definition: NodeDirectories.h:136
boost::filesystem::path user_data_dir
Robot Raconteur User data directory.
Definition: NodeDirectories.h:99
Exception thrown by GetUuidForNameAndLockResult if the name with the specified scope is currently in ...
Definition: NodeDirectories.h:321
Utility functions for working with NodeDirectories.
Definition: NodeDirectories.h:146
static boost::shared_ptr< NodeDirectoriesFD > CreatePidFile(const boost::filesystem::path &path)
Create a pid file.
static bool IsLogonUserRoot()
Returns true if user is root.
static void RefreshInfoFile(const boost::shared_ptr< NodeDirectoriesFD > &h_info, const std::map< std::string, std::string > &updated_info)
Update key-value pairs in a file created with CreateInfoFile()
static boost::shared_ptr< NodeDirectoriesFD > CreateInfoFile(const boost::filesystem::path &path, std::map< std::string, std::string > info)
Create an info file with key-value pairs.
static NodeDirectories GetDefaultNodeDirectories(const boost::shared_ptr< RobotRaconteurNode > &node=boost::shared_ptr< RobotRaconteurNode >())
Get the Default Node Directories object.
static bool ReadInfoFile(const boost::filesystem::path &fname, std::map< std::string, std::string > &data)
Create directories with user permissions.
static std::string GetLogonUserName()
Get the logon name of the current user.
NodeID UUID storage and generation.
Definition: NodeID.h:58