RStudio Launcher Plugin SDK  1.1.3
A software development kit for creating plugins that work the the RStudio Launcher.
AbstractMultiStream.hpp
1 /*
2  * AbstractMultiStream.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_MULTI_STREAM_HPP
25 #define LAUNCHER_PLUGINS_ABSTRACT_MULTI_STREAM_HPP
26 
27 #include <Noncopyable.hpp>
28 
29 #include <string>
30 #include <set>
31 #include <mutex>
32 
33 #include <Error.hpp>
34 #include <PImpl.hpp>
35 #include <comms/AbstractLauncherCommunicator.hpp>
36 
37 namespace rstudio {
38 namespace launcher_plugins {
39 namespace system {
40 
41 class User;
42 
43 } // namespace system
44 } // namespace launcher_plugins
45 } // namespace rstudio
46 
47 namespace rstudio {
48 namespace launcher_plugins {
49 namespace api {
50 
57 template <typename R, typename ... Args>
59 {
60 public:
66  explicit AbstractMultiStream(comms::AbstractLauncherCommunicatorPtr in_launcherCommunicator);
67 
74  virtual void addRequest(uint64_t in_requestId, const system::User& in_requestUser) = 0;
75 
81  virtual Error initialize() = 0;
82 
88  bool isEmpty() const;
89 
95  virtual void removeRequest(uint64_t in_requestId);
96 
97 protected:
105  void onAddRequest(uint64_t in_requestId);
106 
114  void onRemoveRequest(uint64_t in_requestId);
115 
123  void sendResponse(Args... in_responseArgs);
124 
133  void sendResponse(const std::set<uint64_t>& in_requestIds, Args... in_responseArgs);
134 
136  mutable std::mutex m_mutex;
137 
138 private:
139  PRIVATE_IMPL(m_baseImpl);
140 };
141 
142 } // namespace api
143 } // namespace launcher_plugins
144 } // namespace rstudio
145 
146 #endif
rstudio::launcher_plugins::api::AbstractMultiStream::m_mutex
std::mutex m_mutex
Definition: AbstractMultiStream.hpp:136
rstudio::launcher_plugins::api::AbstractMultiStream
Manages the sending of streamed responses.
Definition: AbstractMultiStream.hpp:58
rstudio::launcher_plugins::api::AbstractMultiStream::onAddRequest
void onAddRequest(uint64_t in_requestId)
Adds a new request ID to the multi-stream response.
rstudio::launcher_plugins::system::User
Class which represents a system user.
Definition: User.hpp:55
rstudio::launcher_plugins::api::AbstractMultiStream::isEmpty
bool isEmpty() const
Checks whether there are any requests listening to this stream.
rstudio::launcher_plugins::api::AbstractMultiStream::AbstractMultiStream
AbstractMultiStream(comms::AbstractLauncherCommunicatorPtr in_launcherCommunicator)
Constructor.
rstudio::launcher_plugins::api::AbstractMultiStream::sendResponse
void sendResponse(Args... in_responseArgs)
Sends a response to the Launcher for all requests.
rstudio::launcher_plugins::api::AbstractMultiStream::addRequest
virtual void addRequest(uint64_t in_requestId, const system::User &in_requestUser)=0
Adds a request to the stream.
rstudio::launcher_plugins::api::AbstractMultiStream::removeRequest
virtual void removeRequest(uint64_t in_requestId)
Removes a request from the multi-stream response.
rstudio::launcher_plugins::Error
Class which represents an error.
Definition: Error.hpp:174
rstudio::launcher_plugins::api::AbstractMultiStream::onRemoveRequest
void onRemoveRequest(uint64_t in_requestId)
Removes a request from the multi-stream response.
rstudio::launcher_plugins::api::AbstractMultiStream::initialize
virtual Error initialize()=0
Initializes the response stream.
rstudio::launcher_plugins::Noncopyable
Class which can be inherited from to disallow copying of its child classes.
Definition: Noncopyable.hpp:34