RStudio Launcher Plugin SDK  1.1.3
A software development kit for creating plugins that work the the RStudio Launcher.
FileOutputStream.hpp
1 /*
2  * FileOutputStream.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 
25 #ifndef LAUNCHER_PLUGINS_FILE_OUTPUT_STREAM_HPP
26 #define LAUNCHER_PLUGINS_FILE_OUTPUT_STREAM_HPP
27 
28 #include <api/stream/AbstractOutputStream.hpp>
29 
30 #include <memory>
31 
32 #include <PImpl.hpp>
33 #include <api/Job.hpp>
34 #include <system/DateTime.hpp>
35 
36 namespace rstudio {
37 namespace launcher_plugins {
38 namespace api {
39 
43 class FileOutputStream : public AbstractOutputStream, public std::enable_shared_from_this<FileOutputStream>
44 {
45 public:
58  OutputType in_outputType,
59  api::JobPtr in_job,
60  AbstractOutputStream::OnOutput in_onOutput,
62  AbstractOutputStream::OnError in_onError,
64 
68  virtual ~FileOutputStream() = default;
69 
75  Error start() override;
76 
80  void stop() override;
81 
82 private:
84  typedef std::function<void()> OnStreamEnd;
85 
93  static void onExitCallback(
94  std::weak_ptr<FileOutputStream> in_weakThis,
95  OutputType in_outputType,
96  int in_exitCode);
97 
103  static void onFindFileTimerCallback(std::weak_ptr<FileOutputStream> in_weakThis);
104 
114  virtual void onOutput(const std::string& in_output, OutputType in_outputType);
115 
125  virtual void waitForStreamEnd(const OnStreamEnd& in_onStreamEnd);
126 
127  // The private implementation of FileOutputStream
128  PRIVATE_IMPL(m_impl);
129 };
130 
131 } // namespace api
132 } // namespace launcher_plugins
133 } // namespace rstudio
134 
135 #endif
rstudio::launcher_plugins::api::FileOutputStream::start
Error start() override
Starts the output stream.
rstudio::launcher_plugins::api::AbstractOutputStream
Streams job output data to the launcher.
Definition: AbstractOutputStream.hpp:62
rstudio::launcher_plugins::api::FileOutputStream::stop
void stop() override
Stops the output stream.
rstudio::launcher_plugins::api::FileOutputStream::~FileOutputStream
virtual ~FileOutputStream()=default
Virtual destructor for inheritance.
rstudio::launcher_plugins::api::AbstractOutputStream::OnComplete
std::function< void(uint64_t)> OnComplete
Definition: AbstractOutputStream.hpp:66
rstudio::launcher_plugins::Error
Class which represents an error.
Definition: Error.hpp:174
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::system::TimeDuration::Seconds
static TimeDuration Seconds(int64_t in_seconds)
Constructs an TimeDuration which represents the specified number of seconds.
rstudio::launcher_plugins::api::FileOutputStream::FileOutputStream
FileOutputStream(OutputType in_outputType, api::JobPtr in_job, AbstractOutputStream::OnOutput in_onOutput, AbstractOutputStream::OnComplete in_onComplete, AbstractOutputStream::OnError in_onError, system::TimeDuration in_maxWaitTime=system::TimeDuration::Seconds(10))
Constructor.
rstudio::launcher_plugins::api::FileOutputStream
Streams job output data from a file.
Definition: FileOutputStream.hpp:43