RStudio Launcher Plugin SDK  1.1.3
A software development kit for creating plugins that work the the RStudio Launcher.
JobStatusNotifier.hpp
1 /*
2  * JobStatusNotifier.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_JOB_STATUS_NOTIFIER_HPP
25 #define LAUNCHER_PLUGINS_JOB_STATUS_NOTIFIER_HPP
26 
27 #include <Noncopyable.hpp>
28 
29 #include <string>
30 #include <functional>
31 #include <memory>
32 
33 #include <PImpl.hpp>
34 #include <api/Job.hpp>
35 #include <system/DateTime.hpp>
36 
37 namespace rstudio {
38 namespace launcher_plugins {
39 namespace jobs {
40 
41 // Forward declarations
42 class AbstractJobRepository;
43 
44 struct Subscription;
45 typedef std::shared_ptr<Subscription> SubscriptionHandle;
46 
48 typedef std::function<void(const api::JobPtr&)> OnJobStatusUpdate;
49 
53 class JobStatusNotifier final :
54  public Noncopyable,
55  public std::enable_shared_from_this<JobStatusNotifier>
56 {
57 public:
62 
70  SubscriptionHandle subscribe(const OnJobStatusUpdate& in_onJobStatusUpdate);
71 
72 
81  SubscriptionHandle subscribe(const std::string& in_jobId, const OnJobStatusUpdate& in_onJobStatusUpdate);
82 
94  void updateJob(
95  const api::JobPtr& in_job,
96  api::Job::State in_newStatus,
97  const std::string& in_statusMessage = "",
98  const system::DateTime& in_invocationTime = system::DateTime());
99 
100 private:
101  // The private implementation of JobStatusNotifier.
102  PRIVATE_IMPL(m_impl);
103 
104  friend class Subscription;
105 };
106 
108 typedef std::shared_ptr<JobStatusNotifier> JobStatusNotifierPtr;
109 
110 } // namespace jobs
111 } // namespace launcher_plugins
112 } // namespace rstudio
113 
114 #endif
rstudio::launcher_plugins::jobs::JobStatusNotifier::JobStatusNotifier
JobStatusNotifier()
Constructor.
rstudio::launcher_plugins::jobs::JobStatusNotifier::subscribe
SubscriptionHandle subscribe(const OnJobStatusUpdate &in_onJobStatusUpdate)
Subscribes to all jobs.
rstudio::launcher_plugins::api::Job::State
State
Definition: Job.hpp:153
rstudio::launcher_plugins::system::DateTime
Class which represents a date and time in UTC.
Definition: DateTime.hpp:244
rstudio::launcher_plugins::jobs::JobStatusNotifier::updateJob
void updateJob(const api::JobPtr &in_job, api::Job::State in_newStatus, const std::string &in_statusMessage="", const system::DateTime &in_invocationTime=system::DateTime())
Updates the status of a job with a new status and optionally a new status message.
rstudio::launcher_plugins::Noncopyable
Class which can be inherited from to disallow copying of its child classes.
Definition: Noncopyable.hpp:34
rstudio::launcher_plugins::jobs::JobStatusNotifier
Class which notifies subscribers when a job updates.
Definition: JobStatusNotifier.hpp:53