RStudio Launcher Plugin SDK  1.1.3
A software development kit for creating plugins that work the the RStudio Launcher.
Options.hpp
1 /*
2  * Options.hpp
3  *
4  * Copyright (C) 2019-20 by RStudio, PBC
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
7  * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
8  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
12  * Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
15  * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18  *
19  */
20 
21 #ifndef LAUNCHER_PLUGINS_ABSTRACT_OPTIONS_HPP
22 #define LAUNCHER_PLUGINS_ABSTRACT_OPTIONS_HPP
23 
24 #include <boost/noncopyable.hpp>
25 
26 #include <boost/program_options/value_semantic.hpp>
27 
28 #include <memory>
29 
30 #include "Error.hpp"
31 #include "logging/Logger.hpp"
32 #include "system/DateTime.hpp"
33 
34 namespace rstudio {
35 namespace launcher_plugins {
36 namespace system {
37 
38 class FilePath;
39 class User;
40 
41 }
42 }
43 }
44 
45 namespace rstudio {
46 namespace launcher_plugins {
47 namespace options {
48 
49 template <class T>
50 class Value;
51 class Options;
80 template<class T>
81 class Value
82 {
83 public:
87  Value();
88 
95  explicit Value(T& io_storeTo);
96 
104  Value& setDefaultValue(const T& in_defaultValue);
105 
106 private:
110  PRIVATE_IMPL_SHARED(m_impl);
111 
112  friend class Options;
113 };
114 
118 class Options : boost::noncopyable
119 {
120 public:
124  class Init
125  {
126  public:
132  explicit Init(Options& in_owner);
133 
146  template <class T>
147  Init& operator()(const char* in_name, Value<T>& in_value, const char* in_description);
148 
161  template <class T>
162  Init& operator()(const char* in_name, Value<T>&& in_value, const char* in_description);
163 
164  private:
168  Options& m_owner;
169  };
170 
176  static Options& getInstance();
177 
184 
196  Error readOptions(int in_argc, const char* const in_argv[], const system::FilePath& in_location);
197 
204 
211 
218 
228 
237  size_t getMaxMessageSize() const;
238 
247  const std::string& getPluginName() const;
248 
256  const system::FilePath& getRSandboxPath() const;
257 
266  const system::FilePath& getScratchPath() const;
267 
273  const system::FilePath& getLoggingDir() const;
274 
282  Error getServerUser(system::User& out_serverUser) const;
283 
289  size_t getThreadPoolSize() const;
290 
296  bool useUnprivilegedMode() const;
297 
303  bool enableDebugLogging() const;
304 
305 private:
309  Options();
310 
311  // The private implementation of Options.
312  PRIVATE_IMPL(m_impl);
313 
314  friend Init;
315 };
316 
317 } // namespace options
318 } // namespace launcher_plugins
319 } // namespace rstudio
320 
321 #endif
rstudio::launcher_plugins::options::Options::getLogLevel
logging::LogLevel getLogLevel() const
Gets the maximum level of log messages to write.
rstudio::launcher_plugins::options::Options::getInstance
static Options & getInstance()
Gets the single instance of Options for the plugin.
rstudio::launcher_plugins::system::FilePath
Class which represents a path on the system. May be any type of file (e.g. directory,...
Definition: FilePath.hpp:77
rstudio::launcher_plugins::options::Value::setDefaultValue
Value & setDefaultValue(const T &in_defaultValue)
Sets the default value of the option.
rstudio::launcher_plugins::system::User
Class which represents a system user.
Definition: User.hpp:55
rstudio::launcher_plugins::options::Value
Concrete class which represents an option Value.
Definition: Options.hpp:50
rstudio::launcher_plugins::options::Options::getLoggingDir
const system::FilePath & getLoggingDir() const
Gets path where debug logs should be written.
rstudio::launcher_plugins::options::Options::enableDebugLogging
bool enableDebugLogging() const
Gets whether debug logging is activated.
rstudio::launcher_plugins::options::Options::Init::operator()
Init & operator()(const char *in_name, Value< T > &in_value, const char *in_description)
Operator which initializes a specific option value.
rstudio::launcher_plugins::options::Options::getMaxMessageSize
size_t getMaxMessageSize() const
Gets the maximum allowable size of messages which can be used in communications with the RStudio Laun...
rstudio::launcher_plugins::options::Options::Init::Init
Init(Options &in_owner)
Helper class which initializes Options.
rstudio::launcher_plugins::options::Options::getScratchPath
const system::FilePath & getScratchPath() const
Gets the scratch path to which log files and other plugin data may be written.
rstudio::launcher_plugins::options::Options::getServerUser
Error getServerUser(system::User &out_serverUser) const
Gets the user to run as when root privileges are dropped.
rstudio::launcher_plugins::options::Options::getThreadPoolSize
size_t getThreadPoolSize() const
Gets the size of the thread pool.
rstudio::launcher_plugins::logging::LogLevel
LogLevel
Enum which represents the level of detail at which to log messages.
Definition: Logger.hpp:86
rstudio::launcher_plugins::options::Options::getHeartbeatIntervalSeconds
system::TimeDuration getHeartbeatIntervalSeconds() const
Gets the number of seconds between heartbeats.
rstudio::launcher_plugins::options::Options::Init
Class for initializing Options.
Definition: Options.hpp:124
rstudio::launcher_plugins::options::Options::getLauncherConfigFile
const system::FilePath & getLauncherConfigFile() const
Gets the location of the configuration file for the RStudio Job Launcher.
rstudio::launcher_plugins::Error
Class which represents an error.
Definition: Error.hpp:174
Logger.hpp
rstudio::launcher_plugins::options::Options::useUnprivilegedMode
bool useUnprivilegedMode() const
Gets whether the plugin should run in single-user unprivileged mode.
rstudio::launcher_plugins::system::TimeDuration
Represents an duration of time (e.g. 5 hours, 43 minutes, and 21 seconds) as opposed to a point in ti...
Definition: DateTime.hpp:48
rstudio::launcher_plugins::options::Options
Options for the plugin.
Definition: Options.hpp:118
rstudio::launcher_plugins::options::Options::getJobExpiryHours
system::TimeDuration getJobExpiryHours() const
Gets the number of hours after which finished jobs expire and should be pruned from the plugin.
rstudio::launcher_plugins::options::Options::getPluginName
const std::string & getPluginName() const
Gets the name the administrator gave to this instance of the Plugin in the launcher....
rstudio::launcher_plugins::options::Options::readOptions
Error readOptions(int in_argc, const char *const in_argv[], const system::FilePath &in_location)
Reads the option file, loading all registered options.
rstudio::launcher_plugins::options::Options::getRSandboxPath
const system::FilePath & getRSandboxPath() const
Gets the path to the rsandbox executable provided by the RStudio Workbench installation.
rstudio::launcher_plugins::options::Value::Value
Value()
Default Constructor.
rstudio::launcher_plugins::options::Options::registerOptions
Init registerOptions()
Allows the caller to register their options using the Init helper object.