Leosac  0.8.0
Open Source Access Control
UpdateService.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include "UpdateFwd.hpp"
23 #include "core/SecurityContext.hpp"
24 #include "tools/JSONUtils.hpp"
25 #include "tools/bs2.hpp"
28 #include <mutex>
29 
30 namespace Leosac
31 {
32 namespace update
33 {
34 enum class Severity
35 {
36  LOW = 0,
37  NORMAL = 1,
38  HIGHT = 2,
39  CRITICAL = 3,
40 };
41 
54 {
56  virtual ~UpdateDescriptor() = default;
57 
58  std::string uuid;
60  std::string source_module;
61  std::string update_desc;
62 
63  private:
68  virtual void implement_me_() = 0;
69 };
70 
72 {
73  public:
84  virtual std::vector<UpdateDescriptorPtr> check_update() = 0;
85 
93  virtual IUpdatePtr create_update(const UpdateDescriptor &ud,
94  const ExecutionContext &) = 0;
95 
102  virtual void ack_update(IUpdatePtr u, const ExecutionContext &) = 0;
103 
110  virtual void cancel_update(IUpdatePtr u, const ExecutionContext &) = 0;
111 };
112 
127  : public ExtensibleSerializer<json, IUpdate, const SecurityContext &>
128 {
129  public:
130  std::vector<UpdateDescriptorPtr> check_update();
131 
142  IUpdatePtr create_update(const std::string &update_descriptor_uuid,
143  const ExecutionContext &ec);
144 
148  std::vector<IUpdatePtr> pending_updates();
149 
150  void ack_update(IUpdatePtr update, const ExecutionContext &ec);
151 
152  void cancel_update(IUpdatePtr update, const ExecutionContext &ec);
153 
160  void register_backend(UpdateBackendPtr backend);
161 
162  private:
163  mutable std::mutex mutex_;
164 
165  using CheckUpdateT =
166  boost::signals2::signal<std::vector<UpdateDescriptorPtr>(void),
168 
169  using CreateUpdateT =
170  boost::signals2::signal<IUpdatePtr(const UpdateDescriptor &,
171  const ExecutionContext &),
173 
174  using AckUpdateT =
175  boost::signals2::signal<void(IUpdatePtr, const ExecutionContext &)>;
176 
177  using CancelUpdateT =
178  boost::signals2::signal<void(IUpdatePtr, const ExecutionContext &)>;
179 
184 
185  std::map<std::string, UpdateDescriptorPtr> published_descriptors_;
186 };
187 }
188 }
Leosac::update::UpdateService::CreateUpdateT
boost::signals2::signal< IUpdatePtr(const UpdateDescriptor &, const ExecutionContext &), AtMostOneCombiner< IUpdatePtr > > CreateUpdateT
Definition: UpdateService.hpp:172
Leosac::update::UpdateBackend
Definition: UpdateService.hpp:71
Leosac::update::Severity
Severity
Definition: UpdateService.hpp:34
Leosac::update::UpdateBackend::cancel_update
virtual void cancel_update(IUpdatePtr u, const ExecutionContext &)=0
Cancel (not rollback) the pending update u.
Leosac::update::UpdateService::AckUpdateT
boost::signals2::signal< void(IUpdatePtr, const ExecutionContext &)> AckUpdateT
Definition: UpdateService.hpp:175
Leosac::update::UpdateService::CheckUpdateT
boost::signals2::signal< std::vector< UpdateDescriptorPtr >(void), VectorAppenderCombiner< UpdateDescriptorPtr > > CheckUpdateT
Definition: UpdateService.hpp:167
Leosac::update::UpdateBackend::check_update
virtual std::vector< UpdateDescriptorPtr > check_update()=0
Check for updates against arbitrary, module-owned object.
Leosac::update::UpdateService::published_descriptors_
std::map< std::string, UpdateDescriptorPtr > published_descriptors_
Definition: UpdateService.hpp:185
Leosac::update::UpdateService::cancel_update
void cancel_update(IUpdatePtr update, const ExecutionContext &ec)
Definition: UpdateService.cpp:108
Leosac::update::Severity::LOW
@ LOW
Leosac::update::IUpdatePtr
std::shared_ptr< IUpdate > IUpdatePtr
Definition: UpdateFwd.hpp:42
Leosac::update::Severity::HIGHT
@ HIGHT
Leosac::update::UpdateDescriptor
Describe an update that has yet to be done.
Definition: UpdateService.hpp:53
Leosac::update::UpdateService::pending_updates
std::vector< IUpdatePtr > pending_updates()
Retrieve the list of pending updates.
Definition: UpdateService.cpp:71
Leosac::update::UpdateDescriptor::UpdateDescriptor
UpdateDescriptor()
Definition: UpdateService.cpp:113
Leosac::update::UpdateService::check_update_sig_
CheckUpdateT check_update_sig_
Definition: UpdateService.hpp:180
Leosac::update::UpdateService::cancel_update_sig_
CancelUpdateT cancel_update_sig_
Definition: UpdateService.hpp:183
Leosac::update::UpdateService::mutex_
std::mutex mutex_
Definition: UpdateService.hpp:163
bs2.hpp
Leosac::update::UpdateBackendPtr
std::shared_ptr< UpdateBackend > UpdateBackendPtr
Definition: UpdateFwd.hpp:49
Registry.hpp
SecurityContext.hpp
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::update::UpdateService::register_backend
void register_backend(UpdateBackendPtr backend)
Register a backend object.
Definition: UpdateService.cpp:30
Leosac::ExecutionContext
An ExecutionContext is passed around to service so they have context about who is making the call and...
Definition: SecurityContext.hpp:301
Leosac::AtMostOneCombiner
A boost::signals2 combiner that makes sure that at most one slot returns a non-null pointer.
Definition: bs2.hpp:64
Leosac::VectorAppenderCombiner
A shortname for the boost::signals2 namespace.
Definition: bs2.hpp:35
JSONUtils.hpp
Leosac::update::UpdateService::check_update
std::vector< UpdateDescriptorPtr > check_update()
Definition: UpdateService.cpp:52
Leosac::update::UpdateDescriptor::implement_me_
virtual void implement_me_()=0
Just to make UpdateDescriptor abstract so module have to provide their own subclass.
Leosac::update::UpdateService::ack_update_sig_
AckUpdateT ack_update_sig_
Definition: UpdateService.hpp:182
Leosac::update::UpdateDescriptor::uuid
std::string uuid
Definition: UpdateService.hpp:58
Leosac::ExtensibleSerializer
Provides dynamic serializers management for a given object's hierarchy.
Definition: ExtensibleSerializer.hpp:53
Leosac::update::UpdateService::ack_update
void ack_update(IUpdatePtr update, const ExecutionContext &ec)
Definition: UpdateService.cpp:103
Leosac::update::UpdateService
This service provides various update management utilities.
Definition: UpdateService.hpp:126
Leosac::update::UpdateBackend::ack_update
virtual void ack_update(IUpdatePtr u, const ExecutionContext &)=0
Acknowledge the pending update u.
Leosac::update::UpdateDescriptor::~UpdateDescriptor
virtual ~UpdateDescriptor()=default
Leosac::update::UpdateDescriptor::update_desc
std::string update_desc
Definition: UpdateService.hpp:61
Leosac::update::UpdateDescriptor::severity
Severity severity
Definition: UpdateService.hpp:59
Leosac::update::UpdateService::create_update
IUpdatePtr create_update(const std::string &update_descriptor_uuid, const ExecutionContext &ec)
Create an Update object corresponding to the update descriptor whose uuid is update_descriptor_uuid.
Definition: UpdateService.cpp:91
UpdateFwd.hpp
Leosac::update::Severity::NORMAL
@ NORMAL
Leosac::update::UpdateService::create_update_sig_
CreateUpdateT create_update_sig_
Definition: UpdateService.hpp:181
Leosac::update::UpdateDescriptor::source_module
std::string source_module
Definition: UpdateService.hpp:60
Leosac::update::UpdateBackend::create_update
virtual IUpdatePtr create_update(const UpdateDescriptor &ud, const ExecutionContext &)=0
Create an update based on the UpdateDescriptor ud.
ExtensibleSerializer.hpp
Leosac::update::Severity::CRITICAL
@ CRITICAL
Leosac::update::UpdateService::CancelUpdateT
boost::signals2::signal< void(IUpdatePtr, const ExecutionContext &)> CancelUpdateT
Definition: UpdateService.hpp:178