8#ifndef OCM_DAQ_MANAGER_HPP_
9#define OCM_DAQ_MANAGER_HPP_
17#include <boost/asio/deadline_timer.hpp>
18#include <boost/thread/future.hpp>
19#include <log4cplus/logger.h>
40 explicit InvalidDaqId(std::string_view
id, std::string_view reason);
79 std::chrono::system_clock::time_point* out =
nullptr);
92 template <
class Observer>
94 return m_signal.connect(std::move(o));
164 virtual std::string
MakeDaqId(std::chrono::system_clock::time_point* time =
nullptr)
const = 0;
233 virtual boost::future<Result<Status>>
273 std::shared_ptr<ObservableEventLog> event_log,
275 std::shared_ptr<DpmClient> dpm_client,
276 log4cplus::Logger
const& logger);
283 std::string
MakeDaqId(std::chrono::system_clock::time_point* time =
nullptr)
const override;
285 bool HaveDaq(std::string_view
id, std::string_view file_id = {})
const noexcept override;
295 boost::future<Result<Status>>
306 Daq(std::string id_arg,
307 std::shared_ptr<DaqController> controller_arg,
308 boost::signals2::connection conn_status_arg,
309 boost::signals2::connection conn_context_arg)
noexcept;
312 std::shared_ptr<DaqController> controller;
314 boost::signals2::scoped_connection conn_status;
315 boost::signals2::scoped_connection conn_context;
321 using Func = std::function<bool()>;
322 OpAbortFunc(Func&& f);
323 OpAbortFunc(OpAbortFunc&&) =
default;
324 OpAbortFunc& operator=(OpAbortFunc&&) =
default;
326 std::uint64_t GetId()
const noexcept;
327 bool Abort()
noexcept;
330 static std::uint64_t NextId();
332 std::function<bool()> m_func;
335 enum class Store { Yes, No };
353 void AddDaq(std::shared_ptr<DaqController>
const&
daq, Store store = Store::Yes);
361 void RemoveDaq(std::string_view
id);
362 void ArchiveDaq(std::string
const&
id);
366 void StoreActiveDaqs()
const;
369 void RemoveAbortFunc(std::uint64_t
id)
noexcept;
370 DaqController const* FindDaq(std::string_view
id)
const noexcept;
373 DaqController const& FindDaqOrThrow(std::string_view
id)
const;
378 void MoveToMergePhase(std::string_view
id);
386 void ScheduleDaqsAsync();
388 std::shared_ptr<bool> m_alive_token;
393 std::shared_ptr<ObservableEventLog> m_event_log;
395 std::shared_ptr<DpmClient> m_dpm_client;
399 std::vector<Daq> m_daq_controllers;
402 std::vector<OpAbortFunc> m_abort_funcs;
403 log4cplus::Logger m_logger;
406 std::optional<boost::asio::deadline_timer> m_schedule_retry;
Abstract factory for DaqControllers.
Controls the execution of single data acquisition that ultimately result in a set of FITS keywords an...
void RestoreFromWorkspace() override
Loads status and constructs DaqControllers corresponding to stored state.
Status GetStatus(std::string_view id) const override
Get status.
boost::future< Result< Status > > AwaitDaqStateAsync(std::string_view id, State, std::chrono::milliseconds timeout) override
Await DAQ state.
bool HaveDaq(std::string_view id, std::string_view file_id={}) const noexcept override
Query existing data acquisition by id and optional file_id.
std::string MakeDaqId(std::chrono::system_clock::time_point *time=nullptr) const override
Creates a new unique identifier based on the instrument id and current time.
void UpdateKeywords(std::string_view id, fits::KeywordVector const &keywords) override
Update FITS keywords for DaqController identified by id.
boost::future< State > StartDaqAsync(DaqContext ctx) override
Start DaqController identified by id.
boost::future< Status > StopDaqAsync(std::string_view id, ErrorPolicy policy) override
Stop DaqController identified by id.
boost::future< Status > AbortDaqAsync(std::string_view id, ErrorPolicy policy) override
Abort DaqController identified by id.
StatusSignal & GetStatusSignal() override
std::vector< std::shared_ptr< DaqController const > > GetDaqControllers() override
Manager owns DaqController and FitsController (active data acquisitions) instances and multiplexes re...
boost::signals2::signal< void(ObservableStatus const &)> Signal
virtual boost::future< Result< Status > > AwaitDaqStateAsync(std::string_view id, State state, std::chrono::milliseconds timeout)=0
Await DAQ state.
virtual boost::future< State > StartDaqAsync(DaqContext ctx)=0
Start DaqController identified by id.
virtual Status GetStatus(std::string_view id) const =0
Get status.
virtual boost::future< Status > AbortDaqAsync(std::string_view id, ErrorPolicy policy)=0
Abort DaqController identified by id.
virtual void UpdateKeywords(std::string_view id, fits::KeywordVector const &keywords)=0
Update FITS keywords for DaqController identified by id.
virtual boost::future< Status > StopDaqAsync(std::string_view id, ErrorPolicy policy)=0
Stop DaqController identified by id.
virtual std::string MakeDaqId(std::chrono::system_clock::time_point *time=nullptr) const =0
Creates a new unique identifier based on the instrument id and current time.
virtual void RestoreFromWorkspace()=0
Restore from state stored in workspace.
virtual std::vector< std::shared_ptr< DaqController const > > GetDaqControllers()=0
virtual bool HaveDaq(std::string_view id, std::string_view file_id={}) const DAQ_NOEXCEPT=0
Query existing data acquisition by id and optional file_id.
virtual StatusSignal & GetStatusSignal()=0
Stores data acquisition status and allows subscription to status changes.
boost::signals2::connection ConnectObserver(Observer o)
boost::signals2::signal< void(ObservableStatus const &)> SignalType
void Signal(ObservableStatus const &status)
Interface to interact with DPM workspace.
Adapts boost::asio::io_context into a compatible boost::thread Executor type.
Contains declaration of daq::Context.
Contains error related declarations for DAQ.
Contains declaration for EventLog, ObservableEventLog and related events.
Contains data structure for FITS keywords.
Declares daq::State and related functions.
std::vector< KeywordVariant > KeywordVector
Vector of keywords.
std::string MakeIdCandidate(char const *instrument_id, unsigned jitter=0, std::chrono::system_clock::time_point *out=nullptr)
Creates a DAQ id candidate that may or may not be unique.
std::chrono::hours merging_stale_age
Age of DAQ in merging state, after which it is automatically considered abandoned and will be archive...
ErrorPolicy
Error policy supported by certain operations.
std::string instrument_id
Instrument identifier.
State
Observable states of the data acquisition process.
std::chrono::hours acquiring_stale_age
Age of DAQ in acquiring state after which it is automatically considered abandoned and will be archiv...
Configurations parameters directly related to manager.
Config class header file.
Contains declaration for Status and ObservableStatus.
Structure carrying context needed to start a Data Acquisition and construct a Data Product Specificat...
Exception indicating the DAQ id was invalid.
Non observable status object that keeps stores status of data acquisition.
Declaration of utilities.