RStudio Launcher Plugin SDK  1.1.3
A software development kit for creating plugins that work the the RStudio Launcher.
AbstractOutputStream.hpp
1 /*
2  * AbstractOutputStream.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_OUTPUT_STREAM_HPP
25 #define LAUNCHER_PLUGINS_ABSTRACT_OUTPUT_STREAM_HPP
26 
27 #include <memory>
28 
29 #include <functional>
30 
31 #include <PImpl.hpp>
32 #include <api/Job.hpp>
33 
34 namespace rstudio {
35 namespace launcher_plugins {
36 namespace api {
37 
41 enum class OutputType
42 {
44  FIRST = 0,
45 
47  STDOUT = 0,
48 
50  STDERR = 1,
51 
53  BOTH = 2,
54 
56  LAST
57 };
58 
63 {
64 public:
66  typedef std::function<void(uint64_t)> OnComplete;
67  typedef std::function<void(const Error&)> OnError;
68  typedef std::function<void(const std::string&, OutputType, uint64_t)> OnOutput;
69 
73  virtual ~AbstractOutputStream() = default;
74 
80  virtual Error start() = 0;
81 
85  virtual void stop() = 0;
86 
87 protected:
99  OutputType in_outputType,
100  JobPtr in_job,
101  OnOutput in_onOutput,
102  OnComplete in_onComplete,
103  OnError in_onError);
104 
111  void reportData(const std::string& in_data, OutputType in_outputType);
112 
118  void reportError(const Error& in_error);
119 
124  void setStreamComplete();
125 
127  OutputType m_outputType;
128 
130  JobPtr m_job;
131 
132 private:
133  // The private implementation of AbstractOutputStream.
134  PRIVATE_IMPL(m_baseImpl);
135 };
136 
137 typedef std::shared_ptr<AbstractOutputStream> OutputStreamPtr;
138 
139 } // namespace api
140 } // namespace launcher_plugins
141 } // namespace rstudio
142 
143 #endif
rstudio::launcher_plugins::api::AbstractOutputStream
Streams job output data to the launcher.
Definition: AbstractOutputStream.hpp:62
rstudio::launcher_plugins::api::AbstractOutputStream::OnComplete
std::function< void(uint64_t)> OnComplete
Definition: AbstractOutputStream.hpp:66
rstudio::launcher_plugins::api::AbstractOutputStream::reportData
void reportData(const std::string &in_data, OutputType in_outputType)
Reports output to the launcher.
rstudio::launcher_plugins::api::AbstractOutputStream::reportError
void reportError(const Error &in_error)
Reports an error to the launcher.
rstudio::launcher_plugins::api::AbstractOutputStream::start
virtual Error start()=0
Starts the output stream.
rstudio::launcher_plugins::api::AbstractOutputStream::~AbstractOutputStream
virtual ~AbstractOutputStream()=default
Virtual destructor for inheritance.
rstudio::launcher_plugins::api::AbstractOutputStream::m_outputType
OutputType m_outputType
Definition: AbstractOutputStream.hpp:127
rstudio::launcher_plugins::api::AbstractOutputStream::stop
virtual void stop()=0
Stops the output stream.
rstudio::launcher_plugins::api::AbstractOutputStream::setStreamComplete
void setStreamComplete()
Notifies the base class that the output stream has completed (i.e. all output of the specified type h...
rstudio::launcher_plugins::Error
Class which represents an error.
Definition: Error.hpp:174
rstudio::launcher_plugins::api::AbstractOutputStream::m_job
JobPtr m_job
Definition: AbstractOutputStream.hpp:130
rstudio::launcher_plugins::api::AbstractOutputStream::AbstractOutputStream
AbstractOutputStream(OutputType in_outputType, JobPtr in_job, OnOutput in_onOutput, OnComplete in_onComplete, OnError in_onError)
Constructor.