RStudio Launcher Plugin SDK  1.1.3
A software development kit for creating plugins that work the the RStudio Launcher.
AbstractUserProfiles.hpp
1 /*
2  * AbstractUserProfiles.hpp
3  *
4  * Copyright (C) 2020 by RStudio, PBC
5  *
6  * Unless you have received this program directly from RStudio pursuant to the terms of a commercial license agreement
7  * with RStudio, then this program is licensed to you under the following terms:
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
10  * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
11  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
15  * Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18  * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  */
23 
24 #ifndef LAUNCHER_PLUGINS_ABSTRACT_USER_PROFILES_HPP
25 #define LAUNCHER_PLUGINS_ABSTRACT_USER_PROFILES_HPP
26 
27 #include <Noncopyable.hpp>
28 
29 #include <functional>
30 
31 #include <PImpl.hpp>
32 #include <map>
33 #include <set>
34 
35 namespace rstudio {
36 namespace launcher_plugins {
37 
38 class Error;
39 
40 namespace system {
41 
42 class FilePath;
43 class User;
44 
45 } // namespace system
46 } // namespace launcher_plugins
47 } // namespace rstudio
48 
49 namespace rstudio {
50 namespace launcher_plugins {
51 namespace options {
52 
60 typedef std::function<Error(const std::string& in_value)> CustomValueValidator;
61 
66 {
67 public:
71  virtual ~AbstractUserProfiles() = default;
72 
78  Error initialize();
79 
80 protected:
89 
97  explicit AbstractUserProfiles(const std::string& in_pluginName);
98 
126  template <typename T>
127  Error getValueForUser(const std::string& in_valueName, const system::User& in_user, T& out_value) const;
128 
139  static bool isValueNotFoundError(const Error& in_error);
140 
153  template <typename T>
154  Error validateValue(const std::string& in_valueName) const;
155 
167  const std::string& in_valueName,
168  const CustomValueValidator& in_validator) const;
169 
170 private:
180  virtual const system::FilePath& getConfigurationFile() const;
181 
189  virtual const std::set<std::string>& getValidFieldNames() const = 0;
190 
203  virtual Error validateValues() const = 0;
204 
205  // The private implementation of AbstractUserProfiles.
206  PRIVATE_IMPL(m_impl);
207 };
208 
209 } // namespace options
210 } // namespace launcher_plugins
211 } // namespace rstudio
212 
213 #endif
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::system::User
Class which represents a system user.
Definition: User.hpp:55
rstudio::launcher_plugins::options::AbstractUserProfiles::AbstractUserProfiles
AbstractUserProfiles()
Default constructor.
rstudio::launcher_plugins::options::AbstractUserProfiles::~AbstractUserProfiles
virtual ~AbstractUserProfiles()=default
Default virtual destructor for inheritance.
rstudio::launcher_plugins::options::AbstractUserProfiles::getValueForUser
Error getValueForUser(const std::string &in_valueName, const system::User &in_user, T &out_value) const
Gets the value with the specified name for the given user, based on the profiles configuration file.
rstudio::launcher_plugins::options::AbstractUserProfiles::initialize
Error initialize()
Initializes the user profiles. Must be called before attempting to retrieve configuration values.
rstudio::launcher_plugins::Error
Class which represents an error.
Definition: Error.hpp:174
rstudio::launcher_plugins::Noncopyable
Class which can be inherited from to disallow copying of its child classes.
Definition: Noncopyable.hpp:34
rstudio::launcher_plugins::options::AbstractUserProfiles::isValueNotFoundError
static bool isValueNotFoundError(const Error &in_error)
Checks whether the error indicates that the configuration value was not found.
rstudio::launcher_plugins::options::AbstractUserProfiles
Base class which reads an ini-based user profiles file.
Definition: AbstractUserProfiles.hpp:65
rstudio::launcher_plugins::options::AbstractUserProfiles::validateValue
Error validateValue(const std::string &in_valueName) const
Parses all occurrences of the configuration setting with name in_valueName to validate it is correctl...