ifw-ccf  2.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_TAG = "MonThr";
39  const std::string ACQ_THR_TAG = "AcqThr";
40  const std::string PROC_THR_TAG = "ProcThr::{}";
41  const std::string PUB_THR_TAG = "PubThr::{}::{}";
42  const std::string INPUT_Q_TAG = "InputQueue";
43  const std::string OUTPUT_Q_TAG = "OutputQueue::{}";
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  LOG4CPLUS_TRACE_METHOD(Logger(), __PRETTY_FUNCTION__);
70  auto req = rad::GetPayloadNothrow<T>(event);
71  if (req == nullptr) {
72  CCFERROR(Logger(), event.GetId() << " has no associated request!");
73  return;
74  }
75  //req->SetException(rad::Exception("Request rejected in state " + state));
76  req->SetException(elt::mal::MalException("Request rejected in state " + state));
77  }
78 
84  public:
85 
88 
90  static Application& Instance();
91 
92  virtual ~Application();
93 
95  elt::mal::Mal& GetMal();
96 
98  //Config& GetGetCfg().
99 
101  int Execute(int argc, char* argv[]);
102 
105  void CreateThreads();
106 
108  void LoadInitSetup();
109 
111  void HandleSetup();
112 
115  void Dismantle();
116 
118  bool GetAcquisitionActive();
119 
121  void StartAcquistion();
122 
125  void StopAcquistion();
126 
128  void CheckStopAcquistion();
129 
131  void IncrementFrameCounter();
132 
134  std::string GetState();
135 
137  void SetRequestStatus(const std::string& request,
138  const std::string& status);
139 
141  std::string GetRequestStatus(const std::string& request) const;
142 
144  std::string ListAdapters();
145 
147  template <class COM_ADPT_TYPE, class SIM_COM_ADPT_TYPE>
148  void RegisterComAdapters(const COM_ADPT_TYPE& com_adapter_factory_obj,
149  const SIM_COM_ADPT_TYPE& sim_com_adapter_factory_obj) {
150  LOG4CPLUS_TRACE_METHOD(Logger(), __PRETTY_FUNCTION__);
151  // if (m_com_adapter != nullptr) {
152  // delete m_com_adapter;
153  // }
154  // if (m_sim_com_adapter != nullptr) {
155  // delete m_sim_com_adapter;
156  // }
157  //m_com_adapter = new(std::nothrow)COM_ADPT_TYPE;
158  m_com_adapter = std::make_unique<COM_ADPT_TYPE>();
159  ccf::AssertPtr(m_com_adapter.get(), "Communication Adapter", CCFLOC);
160  //m_sim_com_adapter = new(std::nothrow)SIM_COM_ADPT_TYPE;
161  m_sim_com_adapter = std::make_unique<SIM_COM_ADPT_TYPE>();
162  ccf::AssertPtr(m_sim_com_adapter.get(), "Simulation Communication Adapter", CCFLOC);
163  }
164 
168 
170  void ConnectDevice();
171 
173  void DisconnectDevice();
174 
176  const std::vector<std::string>& GetProcThreadIds() const;
177 
179  const std::vector<std::string>& GetPubThreadIds(const std::string& proc_thread_id) const;
180 
182  const std::list<PubThread*>& GetPubThreads() const;
183 
184  Application(const Application&) = delete;
185  Application& operator=(const Application&) = delete;
186 
188  // Recording handling
190 
192  void UpdateRecordingStatus();
193 
195  void SetActiveRecStatusObj(std::shared_ptr<recif::RecStatus>& active_rec);
196 
198  void UpdateActiveRecStatusObj(const ccf::common::PublisherStatus& sum_rec_pub_status);
199 
201  void UpdateRecStatusInDb();
202 
204  void GetActiveRecStatus(std::shared_ptr<recif::RecStatus>& active_rec) const;
205 
208  std::shared_ptr<recif::RecStatus>& active_rec);
209 
211  void SetRecordingStatus(const ccf::PubStatus status);
212 
214  void GetRecStatus(const std::string& rec_id,
215  std::shared_ptr<recif::RecStatus>& active_rec) const;
216 
218  void GetMostRecentRecStatus(std::shared_ptr<recif::RecStatus>& active_rec) const;
219 
221  void AddRecWaitRequest(std::shared_ptr<RecWaitRequest>& req_wait_req);
222 
224  void CheckRecWaitRequests(const bool recording_completed=false);
225 
227  void CleanUpRecWaitRequests();
229 
230  private:
231  Application();
232 
233  int8_t m_simulation;
234  std::unique_ptr<rad::cii::Replier> m_mal_replier;
235  std::shared_ptr<elt::mal::Mal> m_mal;
236  std::unique_ptr<DataContext> m_data_ctx;
237  ActionMgr m_action_mgr;
238  //StdActions* m_actions_std;
239  bool m_dismantle_invoked;
240 
241  std::map<std::string, std::string> m_request_status_map;
242 
243  std::unique_ptr<ccf::common::ComAdptBase> m_com_adapter;
244  std::unique_ptr<ccf::common::ComAdptBase> m_sim_com_adapter;
245 
246  std::map<std::string, std::shared_ptr<ccf::common::FrameQueue>> m_frame_queues;
247 
248  std::vector<std::string> m_proc_thread_names;
249  std::vector<std::string> m_proc_thread_ids;
250  std::map<std::string, std::vector<std::string>> m_pub_thread_ids;
251 
252  // For easy access. The threads are handled by the MPTK.
253  std::list<PubThread*> m_pub_threads;
254 
255  // Acquisition control.
256  ccf::ExpoMode m_acq_setup_expo_mode;
257  int64_t m_acq_setup_nb_of_frames;
258  int64_t m_acq_status_frame_count;
259 
260  // Recording session control.
261  std::shared_ptr<recif::RecStatus> m_active_recording;
262  int64_t m_exp_nb_of_frames;
263  int32_t m_max_sz_rec_history;
264  int32_t m_rec_history_exp;
265  // Maps "<rec id>" into the set of associated Recording Sessions.
266  std::map<std::string, std::shared_ptr<recif::RecStatus>> m_rec_history;
267  std::vector<std::string> m_rec_id_history;
268 
269  std::map<std::string, std::string> m_file_stored_to_pub_id;
270 
271  // Pending ReqWait Requests.
272  std::map<std::string, std::shared_ptr<RecWaitRequest>> m_rec_wait_requests;
273 };
274 
275 inline Application& App() {
276  return Application::Instance();
277 }
278 
279 } // namespace ccf::control
280 
281 #endif // CCFCONTROL_APPLICATION_HPP_
dataContext.hpp
ccf::control::Application
Implements the core CCF Control Application.
Definition: application.hpp:83
stdCmdsImpl.hpp
frameQueue.hpp
ccf::control::PUB_THR_TAG
const std::string PUB_THR_TAG
Definition: application.hpp:41
ccf::control::ACQ_THR_TAG
const std::string ACQ_THR_TAG
Definition: application.hpp:39
ccf::control::Application::SetActiveRecStatusObj
void SetActiveRecStatusObj(std::shared_ptr< recif::RecStatus > &active_rec)
Set the Active Recording Status Object.
Definition: application.cpp:790
ccf::control::Application::SetRecordingStatus
void SetRecordingStatus(const ccf::PubStatus status)
Set the status of the an active Recording Session (Active Recording Object).
Definition: application.cpp:771
ccf::AssertPtr
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:53
ccf::control::ACTIVE_REC_MUTEX
const std::string ACTIVE_REC_MUTEX
Definition: application.hpp:61
ccf::control::Application::Dismantle
void Dismantle()
Definition: application.cpp:232
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:539
ccf::control::INPUT_Q_TAG
const std::string INPUT_Q_TAG
Definition: application.hpp:42
ccf::common::AppBase
Class to be used as parent for CCF application type of classes.
Definition: appBase.hpp:25
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()
Definition: application.cpp:491
ccf::control::Application::GetPubThreads
const std::list< PubThread * > & GetPubThreads() const
Get the IDs of the Publisher Threads running.
Definition: application.cpp:550
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:727
ccf::control::Application::GetMal
elt::mal::Mal & GetMal()
Return reference to the MAL (Singleton) instance.
Definition: application.cpp:60
ccf::control::Application::GetState
std::string GetState()
Return the current state (status) of the SCXML state machine.
Definition: application.cpp:555
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:32
acqThread.hpp
CCFLOC
#define CCFLOC
Macro generating a location identifier: "<file>:<line>:<function>:<thread>".
Definition: base.hpp:457
config.hpp
ccf::control::Application::CreateThreads
void CreateThreads()
Definition: application.cpp:356
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:835
ccf::PubStatus
PubStatus
Defines the various possible states of a Data Publisher.
Definition: base.hpp:285
ccf::control::Application::Execute
int Execute(int argc, char *argv[])
Return reference to the configuration object.
Definition: application.cpp:66
CCFERROR
#define CCFERROR(logger, msg)
ERROR log macro. Includes the location ("CCFLOC") in the log message.
Definition: base.hpp:546
ccf::control::Application::HandleSetup
void HandleSetup()
Handle the setup of the application.
Definition: application.cpp:512
ccf::control::Application::IncrementFrameCounter
void IncrementFrameCounter()
Increment frame counter, counting the number of complete frames received.
Definition: application.cpp:714
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:533
ccf::control::Application::MoveActiveRecStatusToHistory
void MoveActiveRecStatusToHistory(const ccf::PubStatus status, std::shared_ptr< recif::RecStatus > &active_rec)
Move the Active Rec Status object to the Rec Status History.
Definition: application.cpp:799
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:599
ccf::control::Application::StartAcquistion
void StartAcquistion()
Instruct the system to start an acquisition (finite or infnite).
Definition: application.cpp:653
ccf::control::OUTPUT_Q_TAG
const std::string OUTPUT_Q_TAG
Definition: application.hpp:43
ccf::control::THREAD_SIG_SETUP
const std::string THREAD_SIG_SETUP
Definition: application.hpp:49
ccf::control::App
Application & App()
Definition: application.hpp:275
ccf::control::Application::ConnectDevice
void ConnectDevice()
Connect to the associated device.
Definition: application.cpp:306
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:148
ccf::control::Application::~Application
virtual ~Application()
Definition: application.cpp:55
ccf::control::Application::GetRequestStatus
std::string GetRequestStatus(const std::string &request) const
Get the status of the given request.
Definition: application.cpp:900
ccf::control::Application::UpdateRecStatusInDb
void UpdateRecStatusInDb()
Update the status of the current Recording Session in the DB.
Definition: application.cpp:626
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:766
comAdptBase.hpp
ccf::control::Application::GetAcquisitionActive
bool GetAcquisitionActive()
Returns true if image acquisition is active.
Definition: application.cpp:528
ccf::control::Application::SetRequestStatus
void SetRequestStatus(const std::string &request, const std::string &status)
Set status of the given request.
Definition: application.cpp:894
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:682
ccf::control::Application::LoadInitSetup
void LoadInitSetup()
Load the Initialisation Setup specified in the configuration and install it.
Definition: application.cpp:504
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:719
ccf::ExpoMode
ExpoMode
Exposure modes.
Definition: base.hpp:313
ccf::control::THREAD_SIG_NEW_DATA
const std::string THREAD_SIG_NEW_DATA
Definition: application.hpp:50
ccf::control::Application::DisconnectDevice
void DisconnectDevice()
Disconnect from the associated device.
Definition: application.cpp:324
ccf::control::Application::ListAdapters
std::string ListAdapters()
List the available adapters registered in this executable.
Definition: application.cpp:340
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:34
comAdptSim.hpp
ccf::control::PROC_THR_TAG
const std::string PROC_THR_TAG
Definition: application.hpp:40
ccf::control::MON_THR_TAG
const std::string MON_THR_TAG
Definition: application.hpp:38
recWaitRequest.hpp
recipeBase.hpp
ccf::control::Application::StopAcquistion
void StopAcquistion()
Definition: application.cpp:699
ccf::control
Definition: acqThread.cpp:10
ccf::control::Application::AddRecWaitRequest
void AddRecWaitRequest(std::shared_ptr< RecWaitRequest > &req_wait_req)
Add a ReqWaitRequest in the internal registry.
Definition: application.cpp:827
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:87
dcsCmdsImpl.hpp
ccf::control::Application::CleanUpRecWaitRequests
void CleanUpRecWaitRequests()
Check if there are RecWait Requests that can be removed from the queue.
Definition: application.cpp:873
ccf::control::Application::UpdateRecordingStatus
void UpdateRecordingStatus()
Disable assignment operator.
Definition: application.cpp:560
actionMgr.hpp
ccf::Logger
log4cplus::Logger & Logger()
Definition: base.cpp:9
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