ifw-ccf  1.0.0
application.hpp
Go to the documentation of this file.
1 
5 #ifndef CCF_CONTROL_APPLICATION_HPP_
6 #define CCF_CONTROL_APPLICATION_HPP_
7 
8 #include <mal/Mal.hpp>
9 
10 #include <rad/mal/replier.hpp>
11 #include <rad/dbAdapterRedis.hpp>
12 
13 #include <Recif.hpp>
14 
15 #include <ccf/common/base.hpp>
19 #include <ccf/common/appBase.hpp>
20 #include <ccf/control/config.hpp>
33 
34 namespace ccf::control {
35 
37  // @{
38  const std::string MON_THR_NAME = "CcfMonThr";
39  const std::string ACQ_THR_NAME = "CcfAcqThr";
40  const std::string PROC_THR_TAG = "CcfProc";
41  const std::string PUB_THR_TAG = "Pub";
42  const std::string INPUT_Q_NAME = "InputQueue";
43  const std::string OUTPUT_Q_NAME = "OutputQueue%d";
44  // @}
45 
47  // @{
48  const std::string THREAD_SIG_TERM = "SigTerm";
49  const std::string THREAD_SIG_SETUP = "SigSetup";
50  const std::string THREAD_SIG_NEW_DATA = "SigNewData";
51  const std::string THREAD_SIG_PUBLISH = "SigPublish";
52  const std::string THREAD_SIG_START = "SigStart";
53  // @}
54 
55  //const std::string THREAD_SYNC_ACK_OK = "SigAckOk";
56  //const std::string THREAD_SYNC_ACK_ERROR = "SigAckError";
57  //const std::string THREAD_SYNC_UNKNOWN = "SigUnknown";
58 
60  // @{
61  const std::string ACTIVE_REC_MUTEX = "ActiveRecMutex";
62  const std::string REC_HISTORY_MUTEX = "RecHistoryMutex";
63  const std::string MUTEX_REC_WAIT_REQUESTS = "RecWaitRequests";
64  // @}
65 
67  template <typename T>
68  void CcfRequestRejectHandler(const rad::AnyEvent& event, const std::string& state) {
69  CCFTRACE;
70  auto req = rad::GetPayloadNothrow<T>(event);
71  if (req == nullptr) {
72  CCFERROR(event.GetId() << " has no associated request!");
73  return;
74  }
75  req->SetException(rad::Exception("Request rejected in state " + state));
76  }
77 
83  public:
84 
87 
89  static Application& Instance();
90 
91  virtual ~Application();
92 
94  elt::mal::Mal& GetMal();
95 
97  Config& GetCfg();
98 
100  int Execute(int argc, char* argv[]);
101 
103  void CreateThreads();
104 
106  void LoadInitSetup();
107 
109  void HandleSetup();
110 
113  void Dismantle();
114 
116  bool GetAcquisitionActive();
117 
119  void StartAcquistion();
120 
122  void StopAcquistion();
123 
125  void CheckStopAcquistion();
126 
128  void IncrementFrameCounter();
129 
131  std::string GetState();
132 
134  void SetRequestStatus(const std::string& request,
135  const std::string& status);
136 
138  std::string GetRequestStatus(const std::string& request) const;
139 
141  std::string ListAdapters();
142 
144  template <class COM_ADPT_TYPE, class SIM_COM_ADPT_TYPE>
145  void RegisterComAdapters(const COM_ADPT_TYPE& com_adapter_factory_obj,
146  const SIM_COM_ADPT_TYPE& sim_com_adapter_factory_obj) {
147  CCFTRACE;
148  if (m_com_adapter != NULL) {
149  delete m_com_adapter;
150  }
151  if (m_sim_com_adapter != NULL) {
152  delete m_sim_com_adapter;
153  }
154  m_com_adapter = new(std::nothrow)COM_ADPT_TYPE;
155  ccf::common::AssertPtr(m_com_adapter, "Communication Adapter", CCFLOC);
156  m_sim_com_adapter = new(std::nothrow)SIM_COM_ADPT_TYPE;
157  ccf::common::AssertPtr(m_sim_com_adapter, "Simulation Communication Adapter", CCFLOC);
158  }
159 
162 
164  void ConnectDevice();
165 
167  const std::vector<std::string>& GetProcThreadIds() const;
168 
170  const std::vector<std::string>& GetPubThreadIds(const std::string& proc_thread_id) const;
171 
173  const std::list<PubThread*>& GetPubThreads() const;
174 
175  Application(const Application&) = delete;
176  Application& operator=(const Application&) = delete;
177 
179  // Recording handling
181 
183  void UpdateRecordingStatus();
184 
186  void SetActiveRecStatusObj(std::shared_ptr<recif::RecStatus>& active_rec);
187 
189  void UpdateActiveRecStatusObj(const ccf::common::PublisherStatus& sum_rec_pub_status);
190 
192  void UpdateRecStatusInDb();
193 
195  void GetActiveRecStatus(std::shared_ptr<recif::RecStatus>& active_rec) const;
196 
199  std::shared_ptr<recif::RecStatus>& active_rec);
200 
202  void SetRecordingStatus(const ccf::common::PubStatus status);
203 
205  void GetRecStatus(const std::string& rec_id,
206  std::shared_ptr<recif::RecStatus>& active_rec) const;
207 
209  void GetMostRecentRecStatus(std::shared_ptr<recif::RecStatus>& active_rec) const;
210 
212  void AddRecWaitRequest(std::shared_ptr<RecWaitRequest>& req_wait_req);
213 
215  void CheckRecWaitRequests(const bool recording_completed=false);
216 
218  void CleanUpRecWaitRequests();
220 
221  private:
222  Application();
223 
224  int8_t m_simulation;
225  Config m_config;
226  rad::cii::Replier* m_mal_replier;
227  elt::mal::Mal* m_mal;
228  DataContext* m_data_ctx;
229  ActionMgr m_action_mgr;
230  StdActions* m_actions_std;
231  bool m_dismantle_invoked;
232 
233  std::map<std::string, std::string> m_request_status_map;
234 
235  ccf::common::ComAdptBase* m_com_adapter;
236  ccf::common::ComAdptBase* m_sim_com_adapter;
237 
238  std::map<std::string, ccf::common::FrameQueue*> m_frame_queues;
239 
240  std::vector<std::string> m_proc_thread_ids;
241  std::map<std::string, std::vector<std::string>> m_pub_thread_ids;
242 
243  // For type safe/easy access. The threads are handled by the MPTK.
244  std::list<PubThread*> m_pub_threads;
245 
246  // Acquisition control.
247  ccf::common::ExpoMode m_acq_setup_expo_mode;
248  int64_t m_acq_setup_nb_of_frames;
249  int64_t m_acq_status_frame_count;
250 
251  // Recording session control.
252  std::shared_ptr<recif::RecStatus> m_active_recording;
253  int64_t m_exp_nb_of_frames;
254  int32_t m_max_sz_rec_history;
255  int32_t m_rec_history_exp;
256  // Maps "<rec id>" into the set of associated Recording Sessions.
257  std::map<std::string, std::shared_ptr<recif::RecStatus>> m_rec_history;
258  std::vector<std::string> m_rec_id_history;
259 
260  std::map<std::string, std::string> m_file_stored_to_pub_id;
261 
262  // Pending ReqWait Requests.
263  std::map<std::string, std::shared_ptr<RecWaitRequest>> m_rec_wait_requests;
264 };
265 
266 } // namespace ccf::control
267 
268 #endif // CCFCONTROL_APPLICATION_HPP_
ccf::common::PubStatus
PubStatus
Defines the various possible states of a Data Publisher.
Definition: base.hpp:173
dataContext.hpp
ccf::control::MON_THR_NAME
const std::string MON_THR_NAME
Definition: application.hpp:38
ccf::control::Application
Implements the core CCF Control Application.
Definition: application.hpp:82
stdCmdsImpl.hpp
frameQueue.hpp
ccf::control::PUB_THR_TAG
const std::string PUB_THR_TAG
Definition: application.hpp:41
ccf::control::StdActions
RAD Action Group for the actions in connection with the "stdif".
Definition: stdActions.hpp:47
config.hpp
ccf::control::Application::SetActiveRecStatusObj
void SetActiveRecStatusObj(std::shared_ptr< recif::RecStatus > &active_rec)
Set the Active Recording Status Object.
Definition: application.cpp:716
ccf::control::Config
Provides access to the command line options and the configuration parameters stored in the configurat...
Definition: config.hpp:44
ccf::control::ACTIVE_REC_MUTEX
const std::string ACTIVE_REC_MUTEX
Definition: application.hpp:61
ccf::control::Application::Dismantle
void Dismantle()
Definition: application.cpp:187
ccf::control::THREAD_SIG_PUBLISH
const std::string THREAD_SIG_PUBLISH
Definition: application.hpp:51
ccf::control::Application::GetPubThreadIds
const std::vector< std::string > & GetPubThreadIds(const std::string &proc_thread_id) const
Get the IDs of the Publisher Threads running.
Definition: application.cpp:484
ccf::control::Application::GetCfg
Config & GetCfg()
Return reference to the configuration object.
Definition: application.cpp:290
ccf::common::AppBase
Class to be used as parent for CCF application type of classes.
Definition: appBase.hpp:25
ccf::common::ExpoMode
ExpoMode
Exposure modes.
Definition: base.hpp:201
monitorThread.hpp
ccf::control::ActionMgr
Responsible for the life-cycle management of actions and activities.
Definition: actionMgr.hpp:19
ccf::control::Application::GetComAdapter
ccf::common::ComAdptBase & GetComAdapter()
Return the reference to the appropriate Communication Adapter (real mode or simulation adapter).
Definition: application.cpp:433
ccf::control::Application::GetPubThreads
const std::list< PubThread * > & GetPubThreads() const
Get the IDs of the Publisher Threads running.
Definition: application.cpp:494
ccf::control::CcfRequestRejectHandler
void CcfRequestRejectHandler(const rad::AnyEvent &event, const std::string &state)
Template function RAD request rejection check/handler.
Definition: application.hpp:68
recCmdsImpl.hpp
ccf::control::Application::GetRecStatus
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:656
ccf::control::Application::GetMal
elt::mal::Mal & GetMal()
Return reference to the MAL (Singleton) instance.
Definition: application.cpp:59
ccf::control::Application::GetState
std::string GetState()
Return the current state (status) of the SCXML state machine.
Definition: application.cpp:499
ccf::control::REC_HISTORY_MUTEX
const std::string REC_HISTORY_MUTEX
Definition: application.hpp:62
procThread.hpp
ccf::common::PublisherStatus
Class used by a Publisher to handle its own publisher status.
Definition: pubBase.hpp:38
acqThread.hpp
ccf::control::OUTPUT_Q_NAME
const std::string OUTPUT_Q_NAME
Definition: application.hpp:43
CCFLOC
#define CCFLOC
Macro generating a location identifier: "<file>:<line>:<function>:<thread>".
Definition: base.hpp:292
ccf::control::Application::CreateThreads
void CreateThreads()
Create the internal worker threads according to the configuration loaded. Existing threads will be de...
Definition: application.cpp:295
ccf::control::Application::Application
Application(const Application &)=delete
ccf::control::Application::CheckRecWaitRequests
void CheckRecWaitRequests(const bool recording_completed=false)
Check if there are pending requests from RecWait Requests and send response if needed.
Definition: application.cpp:759
ccf::control::Application::Execute
int Execute(int argc, char *argv[])
Initialise and execute the application.
Definition: application.cpp:65
ccf::control::Application::HandleSetup
void HandleSetup()
Handle the setup of the application.
Definition: application.cpp:458
ccf::control::Application::IncrementFrameCounter
void IncrementFrameCounter()
Increment frame counter, counting the number of complete frames received.
Definition: application.cpp:644
ccf::common::AssertPtr
void AssertPtr(const void *ptr, const std::string &object, const std::string &location)
Check that pointer is not NULL and raise rad::exception in case it is.
Definition: base.cpp:49
stdActions.hpp
pubThread.hpp
ccf::control::Application::GetProcThreadIds
const std::vector< std::string > & GetProcThreadIds() const
Get the IDs of the Processing Threads running.
Definition: application.cpp:479
ccf::control::Application::UpdateActiveRecStatusObj
void UpdateActiveRecStatusObj(const ccf::common::PublisherStatus &sum_rec_pub_status)
Update the Active Recording Status Object in memory and in the OLDB.
Definition: application.cpp:541
ccf::control::Application::StartAcquistion
void StartAcquistion()
Instruct the system to start an acquisition (finite or infnite).
Definition: application.cpp:584
ccf::control::INPUT_Q_NAME
const std::string INPUT_Q_NAME
Definition: application.hpp:42
ccf::control::THREAD_SIG_SETUP
const std::string THREAD_SIG_SETUP
Definition: application.hpp:49
ccf::control::Application::MoveActiveRecStatusToHistory
void MoveActiveRecStatusToHistory(const ccf::common::PubStatus status, std::shared_ptr< recif::RecStatus > &active_rec)
Move the Active Rec Status object to the Rec Status History.
Definition: application.cpp:725
ccf::control::Application::ConnectDevice
void ConnectDevice()
Connect to the associated device.
Definition: application.cpp:256
ccf::control::Application::RegisterComAdapters
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:145
ccf::control::Application::~Application
virtual ~Application()
Definition: application.cpp:54
ccf::control::Application::GetRequestStatus
std::string GetRequestStatus(const std::string &request) const
Get the status of the given request.
Definition: application.cpp:819
ccf::control::Application::UpdateRecStatusInDb
void UpdateRecStatusInDb()
Update the status of the current Recording Session in the DB.
Definition: application.cpp:566
base.hpp
ccf::control::Application::GetMostRecentRecStatus
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:695
comAdptBase.hpp
ccf::control::Application::GetAcquisitionActive
bool GetAcquisitionActive()
Returns true if image acquisition is active.
Definition: application.cpp:474
ccf::control::Application::SetRequestStatus
void SetRequestStatus(const std::string &request, const std::string &status)
Set status of the given request.
Definition: application.cpp:813
ccf::control::THREAD_SIG_TERM
const std::string THREAD_SIG_TERM
Definition: application.hpp:48
ccf::control::Application::CheckStopAcquistion
void CheckStopAcquistion()
Check if the conditions are met to stop an ongoing acqusition session.
Definition: application.cpp:612
ccf::control::Application::LoadInitSetup
void LoadInitSetup()
Load the Initialisation Setup specified in the configuration and install it.
Definition: application.cpp:445
appBase.hpp
ccf::control::Application::GetActiveRecStatus
void GetActiveRecStatus(std::shared_ptr< recif::RecStatus > &active_rec) const
Get the currently active Recording status.
Definition: application.cpp:649
ccf::control::THREAD_SIG_NEW_DATA
const std::string THREAD_SIG_NEW_DATA
Definition: application.hpp:50
ccf::control::Application::ListAdapters
std::string ListAdapters()
List the available adapters registered in this executable.
Definition: application.cpp:270
ccf::control::THREAD_SIG_START
const std::string THREAD_SIG_START
Definition: application.hpp:52
ccf::control::Application::Instance
static Application & Instance()
Return reference to unique instance of the application class.
Definition: application.cpp:33
comAdptSim.hpp
ccf::control::PROC_THR_TAG
const std::string PROC_THR_TAG
Definition: application.hpp:40
recWaitRequest.hpp
recipeBase.hpp
CCFTRACE
#define CCFTRACE
TRACE log macro. Includes the location ("CCFLOC") in the log message.
Definition: base.hpp:403
ccf::control::Application::StopAcquistion
void StopAcquistion()
Instruct the system to stopt an ongoing acquisition. If none is active, no actions are performed.
Definition: application.cpp:629
ccf::control::DataContext
Provides access to the application run-time data.
Definition: dataContext.hpp:20
ccf::control
Definition: acqThread.cpp:10
ccf::control::ACQ_THR_NAME
const std::string ACQ_THR_NAME
Definition: application.hpp:39
ccf::control::Application::AddRecWaitRequest
void AddRecWaitRequest(std::shared_ptr< RecWaitRequest > &req_wait_req)
Add a ReqWaitRequest in the internal registry.
Definition: application.cpp:751
ccf::control::Application::SetRecordingStatus
void SetRecordingStatus(const ccf::common::PubStatus status)
Set the status of the an active Recording Session (Active Recording Object).
Definition: application.cpp:700
ccf::control::Application::operator=
Application & operator=(const Application &)=delete
Disable copy constructor.
ccf::control::Application::s_app_instance
static Application * s_app_instance
Singleton instance.
Definition: application.hpp:86
dcsCmdsImpl.hpp
ccf::control::Application::CleanUpRecWaitRequests
void CleanUpRecWaitRequests()
Check if there are RecWait Requests that can be removed from the queue.
Definition: application.cpp:792
ccf::control::Application::UpdateRecordingStatus
void UpdateRecordingStatus()
Disable assignment operator.
Definition: application.cpp:504
actionMgr.hpp
CCFERROR
#define CCFERROR(msg)
ERROR log macro. Includes the location ("CCFLOC") in the log message.
Definition: base.hpp:376
ccf::control::MUTEX_REC_WAIT_REQUESTS
const std::string MUTEX_REC_WAIT_REQUESTS
Definition: application.hpp:63
ccf::common::ComAdptBase
Class to be used as parent for CCF Communication Adapters.
Definition: comAdptBase.hpp:31