5#ifndef CCF_CONTROL_APPLICATION_HPP_
6#define CCF_CONTROL_APPLICATION_HPP_
10#include <rad/mal/replier.hpp>
11#include <rad/dbAdapterRedis.hpp>
71 template <
typename CMD_TYPE,
typename EX_TYPE>
73 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
74 auto req = rad::GetPayloadNothrow<CMD_TYPE>(event);
76 LOG4CPLUS_ERROR(
Logger(), event.GetId() <<
" has no associated request!");
79 req->SetException(EX_TYPE(
"Request rejected in state " + state, 0));
102 int Execute(
int argc,
char* argv[]);
122 void StartAcquistion(
bool force =
false,
bool exec_com_adapter_start =
true);
139 const std::string& status);
148 template <
class COM_ADPT_TYPE,
class SIM_COM_ADPT_TYPE>
150 const SIM_COM_ADPT_TYPE& sim_com_adapter_factory_obj) {
151 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
158 m_com_adapter = std::make_unique<COM_ADPT_TYPE>();
160 m_sim_com_adapter = std::make_unique<SIM_COM_ADPT_TYPE>();
165 template <
class MON_ADPT_TYPE>
167 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
168 m_mon_adapter = std::make_unique<MON_ADPT_TYPE>();
173 template <
class EXEC_ADPT_TYPE>
175 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
176 m_exec_adapter = std::make_unique<EXEC_ADPT_TYPE>();
200 const std::vector<std::string>&
GetPubThreadNames(
const std::string& proc_thread_name)
const;
240 std::shared_ptr<recif::RecStatus>& active_rec);
247 std::shared_ptr<recif::RecStatus>& active_rec)
const;
278 int8_t m_simulation{-1};
279 std::unique_ptr<rad::cii::Replier> m_mal_replier;
280 std::shared_ptr<elt::mal::Mal> m_mal{
nullptr};
281 std::unique_ptr<DataContext> m_data_ctx;
282 ActionMgr m_action_mgr;
284 bool m_dismantle_invoked{
false};
286 std::map<std::string, std::string> m_request_status_map;
290 std::unique_ptr<ifw::ccf::common::ComAdptBase> m_com_adapter{
nullptr};
291 std::unique_ptr<ifw::ccf::common::ComAdptBase> m_sim_com_adapter{
nullptr};
293 std::unique_ptr<ifw::ccf::common::MonAdptBase> m_mon_adapter;
295 std::unique_ptr<ifw::ccf::common::ExecAdptBase> m_exec_adapter;
297 std::map<std::string, std::shared_ptr<ifw::ccf::common::FrameQueue>> m_frame_queues;
299 std::vector<std::string> m_proc_thread_names;
300 std::map<std::string, std::vector<std::string>> m_proc_to_pub_thread_names;
302 std::map<std::string, bool> m_pub_thread_names;
305 std::list<ProcThread*> m_proc_threads;
308 std::list<PubThread*> m_pub_threads;
312 double m_acq_setup_expo_time{0.0};
313 int64_t m_acq_setup_nb_of_frames{0};
314 int64_t m_acq_status_frame_count{0};
315 double m_acq_end_time{UINT_MAX};
318 std::shared_ptr<recif::RecStatus> m_active_recording;
319 int64_t m_exp_nb_of_frames;
320 int32_t m_max_sz_rec_history{1000};
321 int32_t m_rec_history_exp{INT_MAX};
322 bool m_cfg_auto_stop_acq_after_rec{
false};
323 bool m_acq_auto_started_at_rec_start{
false};
325 std::map<std::string, std::shared_ptr<recif::RecStatus>> m_rec_history;
326 std::vector<std::string> m_rec_id_history;
328 std::map<std::string, std::string> m_file_stored_to_pub_id;
331 std::map<std::string, std::shared_ptr<RecWaitRequest>> m_rec_wait_requests;
334 void InitTelemetry();
335 bool m_tel_enabled{
false};
336 double m_tel_period{0};
337 bool m_disable_during_acq{
true};
338 std::map<std::string, ifw::ccf::control::TelemetryNode> m_tel_nodes;
339 std::vector<std::string> m_tel_names;
340 double m_time_last_tel_sampling_exec{0};
341 std::map<std::string, TelemetryCacheEntry> m_tel_cache;
Class to be used as parent for CCF application type of classes.
Definition appBase.hpp:26
Class to be used as parent for CCF Communication Adapters.
Definition comAdptBase.hpp:46
Class to be used as parent for CCF Execution Adapters.
Definition execAdptBase.hpp:16
Class to be used as parent for CCF Monitor Adapters.
Definition monAdptBase.hpp:20
Class used by a Publisher to handle its own publisher status.
Definition pubBase.hpp:33
Implements the core CCF Control Application.
Definition application.hpp:87
void UpdateRecStatusInDb()
Update the status of the current Recording Session in the DB.
Definition application.cpp:761
void UpdateActiveRecStatusObj(const ifw::ccf::common::PublisherStatus &sum_rec_pub_status)
Update the Active Recording Status Object in memory and in the OLDB.
Definition application.cpp:733
void ActivateRecording()
Selects publishers and activate the recording.
Definition application.cpp:1008
bool AcquisitionActive()
Definition application.cpp:651
void CheckStopAcquistion()
Check if the conditions are met to stop an ongoing acqusition session.
Definition application.cpp:832
std::string ListAdapters()
List the available adapters registered in this executable.
Definition application.cpp:433
void IncrementFrameCounter()
Increment frame counter, counting the number of complete frames received.
Definition application.cpp:915
void CleanUpRecWaitRequests()
Check if there are RecWait Requests that can be removed from the queue.
Definition application.cpp:1106
void UpdateRecordingStatus()
Disable assignment operator.
Definition application.cpp:694
void CheckRecWaitRequests(const bool recording_completed=false)
Check if there are pending requests from RecWait Requests and send response if needed.
Definition application.cpp:1068
void GetMostRecentRecStatus(std::shared_ptr< recif::RecStatus > &active_rec) const
Get the information about the most recent Recording (active or in the history).
Definition application.cpp:974
void RegisterMonAdapter(const MON_ADPT_TYPE &mon_adapter_factory_obj)
Method to allocate and register the Monitor Adapters.
Definition application.hpp:166
Application(const Application &)=delete
int GetFramesRemainingActiveRecStatus() const
Definition application.cpp:928
void SetRecordingStatus(const ifw::ccf::PubStatus status)
Set the status of the an active Recording Session (Active Recording Object).
Definition application.cpp:979
std::map< std::string, TelemetryCacheEntry > & TelemetryCache()
Definition application.cpp:1190
void StopAcquistion()
Definition application.cpp:895
void CreateThreads()
Definition application.cpp:449
const std::list< PubThread * > & GetPubThreads() const
Get the IDs of the Publisher Threads running.
Definition application.cpp:684
void UpdateControlSetupPars()
Update setup parameters used internally in the application for flow control.
Definition application.cpp:1165
ProcThread & GetProcThread(const std::string &proc_thread_name)
Get reference to Processing Thread object.
Definition application.cpp:673
void GetActiveRecStatus(std::shared_ptr< recif::RecStatus > &active_rec) const
Get the currently active Recording status.
Definition application.cpp:920
int Execute(int argc, char *argv[])
Initialise and execute the application.
Definition application.cpp:62
static Application & Instance()
Return reference to unique instance of the application class.
Definition application.cpp:39
void MoveActiveRecStatusToHistory(const ifw::ccf::PubStatus status, std::shared_ptr< recif::RecStatus > &active_rec)
Move the Active Rec Status object to the Rec Status History.
Definition application.cpp:1030
virtual ~Application()
Definition application.cpp:50
void GetRecStatus(const std::string &rec_id, std::shared_ptr< recif::RecStatus > &active_rec) const
Check if a Recording with the given ID is found and returns its status.
Definition application.cpp:935
void RegisterExecAdapter(const EXEC_ADPT_TYPE &exec_adapter_factory_obj)
Method to allocate and register the Execution Adapter.
Definition application.hpp:174
void HandleSetup()
Handle the setup of the application.
Definition application.cpp:634
void AddRecWaitRequest(std::shared_ptr< RecWaitRequest > &req_wait_req)
Add a ReqWaitRequest in the internal registry.
Definition application.cpp:1060
elt::mal::Mal & GetMal()
Return reference to the MAL (Singleton) instance.
Definition application.cpp:55
bool IsPubThread(const std::string &thread_name)
Returns bool if the thread is a Publisher Thread.
Definition application.cpp:1148
void LoadInitSetup()
Load the Initialisation Setup specified in the configuration and install it.
Definition application.cpp:624
const std::vector< std::string > & GetPubThreadNames(const std::string &proc_thread_name) const
Get the names of the Publisher Threads running for a specific Processing Thread.
Definition application.cpp:662
std::string GetRequestStatus(const std::string &request) const
Get the status of the given request.
Definition application.cpp:1133
void ConnectDevice()
Connect to the associated device.
Definition application.cpp:399
void Dismantle()
Definition application.cpp:309
void RegisterComAdapters(const COM_ADPT_TYPE &com_adapter_factory_obj, const SIM_COM_ADPT_TYPE &sim_com_adapter_factory_obj)
Method to allocate and register the Communication Adapters.
Definition application.hpp:149
std::string GetState()
Return the current state (status) of the SCXML state machine.
Definition application.cpp:689
ifw::ccf::common::ExecAdptBase & GetExecAdapter()
Return the reference to the Execution Adapter.
Definition application.cpp:616
bool IsProcThread(const std::string &thread_name)
Returns bool if the thread is a Processing Thread.
Definition application.cpp:1143
static Application * s_app_instance
Singleton instance.
Definition application.hpp:91
void DisconnectDevice()
Disconnect from the associated device.
Definition application.cpp:417
Application & operator=(const Application &)=delete
Disable copy constructor.
void SetRequestStatus(const std::string &request, const std::string &status)
Set status of the given request.
Definition application.cpp:1127
void HandleTelemetry(const double time_now)
Definition application.cpp:1246
ifw::ccf::common::MonAdptBase & GetMonAdapter()
Return the reference to the Monitoring Adapter.
Definition application.cpp:608
void StartAcquistion(bool force=false, bool exec_com_adapter_start=true)
Instruct the system to start an acquisition (finite or infnite).
Definition application.cpp:798
void AcqAutoStartedAtRecStart()
Invoke to signal that the Acqusition was auto started at RecStart.
Definition application.cpp:1160
ifw::ccf::common::ComAdptBase & GetComAdapter()
Definition application.cpp:595
const std::vector< std::string > & GetProcThreadNames() const
Get the names of the Processing Threads running.
Definition application.cpp:656
void SetActiveRecStatusObj(std::shared_ptr< recif::RecStatus > &active_rec)
Set the Active Recording Status Object.
Definition application.cpp:998
Processing Thread MPTK Thread implementation (see also ifw::ccf::mptk::Thread).
Definition procThread.hpp:16
Definition acqThread.cpp:10
const std::string ACTIVE_REC_MUTEX
Definition application.hpp:63
const std::string ACQ_THR_TAG
Definition application.hpp:43
const std::string THREAD_SIG_START
Definition application.hpp:54
const std::string REC_HISTORY_MUTEX
Definition application.hpp:64
const std::string THREAD_SIG_NEW_DATA
Definition application.hpp:52
const std::string INPUT_Q_TAG
Definition application.hpp:44
const std::string THREAD_SIG_SETUP
Definition application.hpp:51
const std::string OUTPUT_Q_TAG
Definition application.hpp:45
const std::string MON_THR_TAG
Definition application.hpp:42
const std::string MUTEX_REC_WAIT_REQUESTS
Definition application.hpp:65
const std::string MUTEX_TELEMETRY
Definition application.hpp:66
void CcfRequestRejectHandler(const rad::AnyEvent &event, const std::string &state)
Template function RAD request rejection check/handler.
Definition application.hpp:72
const std::string THREAD_SIG_TERM
Definition application.hpp:50
const std::string THREAD_SIG_PUBLISH
Definition application.hpp:53
const std::string MUTEX_TELEMETRY_CACHE
Definition application.hpp:67
Application & App()
Definition application.hpp:345
PubStatus
Defines the various possible states of a Data Publisher.
Definition base.hpp:178
log4cplus::Logger & Logger()
Definition base.cpp:23
ExpoMode
Exposure modes.
Definition base.hpp:206
void AssertPtr(const void *ptr, const std::string &object, const std::string &location)
Check that pointer is not nullptr and raise rad::exception in case it is.
Definition base.cpp:65