rad 6.2.0
Loading...
Searching...
No Matches
actionMgr.hpp
Go to the documentation of this file.
1
10#ifndef RAD_ACTION_MGR_HPP
11#define RAD_ACTION_MGR_HPP
12
13#include <rad/actionGroup.hpp>
15#include <rad/guardCallback.hpp>
16
17#include <scxml4cpp/Action.h>
18#include <scxml4cpp/Activity.h>
19
20#include <list>
21#include <functional>
22
23namespace rad {
24
25
26/*
27 * @TODO For the moment we keep it as lists since scxml4cpp interface
28 * requires it. Later we could modify it to a map. However actions and
29 * activities are resolved at startup/init time so there is no performance
30 * issues.
31 */
32typedef std::list<scxml4cpp::Action*> ActionList;
33typedef std::list<rad::ActionGroup*> ActionGroupList;
34typedef std::list<scxml4cpp::Activity*> ActivityList;
35
40class ActionMgr {
41 public:
42 ActionMgr();
43 virtual ~ActionMgr();
44
45 template <class T>
46 void RegisterAction(const std::string& id,
47 void (T::*method)(scxml4cpp::Context* c),
48 T* group) {
49 using std::placeholders::_1;
50 scxml4cpp::Action* the_action = new rad::ActionCallback(id, std::bind(method, group, _1));
51 if (the_action == nullptr) {
52 RAD_LOG_THROW(rad::Exception, GetLogger(), "Cannot create action callback for " + id);
53 } else {
54 AddAction(the_action);
55 }
56 }
57
58 template <class T>
59 void RegisterGuard(const std::string& id,
60 bool (T::*method)(scxml4cpp::Context* c),
61 T* group) {
62 using std::placeholders::_1;
63 scxml4cpp::Action* the_guard = new rad::GuardCallback(id, std::bind(method, group, _1));
64 if (the_guard == nullptr) {
65 RAD_LOG_THROW(rad::Exception, GetLogger(), "Cannot create guard callback for " + id);
66 } else {
67 AddAction(the_guard);
68 }
69 }
70
71 void AddAction(scxml4cpp::Action* the_action);
72 void AddActionGroup(rad::ActionGroup* the_action_group);
73 void AddActivity(scxml4cpp::Activity* the_activity);
74
78
79 scxml4cpp::Action* FindAction(const std::string& id);
80 ActionGroup* FindActionGroup(const std::string& id);
81
82 void DelAction(const std::string& id);
83
84 ActionMgr(const ActionMgr&) = delete;
85 ActionMgr& operator=(const ActionMgr&) = delete;
86
87 private:
88 ActionList m_actions;
89 ActionGroupList m_action_groups;
90 ActivityList m_activities;
91};
92
93} // namespace rad
94
95#endif // RAD_ACTION_MGR_HPP
Action header.
Activity header.
ActionCallback class header file.
ActionGroup class header file.
Definition actionCallback.hpp:26
Definition actionGroup.hpp:20
Definition actionMgr.hpp:40
void AddAction(scxml4cpp::Action *the_action)
Definition actionMgr.cpp:57
virtual ~ActionMgr()
Definition actionMgr.cpp:24
ActionList & GetActions()
Definition actionMgr.cpp:88
void AddActionGroup(rad::ActionGroup *the_action_group)
Definition actionMgr.cpp:68
void DelAction(const std::string &id)
Definition actionMgr.cpp:151
ActionMgr(const ActionMgr &)=delete
void AddActivity(scxml4cpp::Activity *the_activity)
Definition actionMgr.cpp:79
ActionGroupList & GetActionGroups()
Definition actionMgr.cpp:96
void RegisterGuard(const std::string &id, bool(T::*method)(scxml4cpp::Context *c), T *group)
Definition actionMgr.hpp:59
void RegisterAction(const std::string &id, void(T::*method)(scxml4cpp::Context *c), T *group)
Definition actionMgr.hpp:46
ActionMgr & operator=(const ActionMgr &)=delete
Disable copy constructor.
scxml4cpp::Action * FindAction(const std::string &id)
Definition actionMgr.cpp:115
ActivityList & GetActivities()
Definition actionMgr.cpp:104
ActionMgr()
Definition actionMgr.cpp:19
ActionGroup * FindActionGroup(const std::string &id)
Definition actionMgr.cpp:136
Base class for the exceptions thrown by RAD and its users.
Definition exceptions.hpp:53
Definition guardCallback.hpp:24
Definition Action.h:66
Definition Activity.h:52
#define RAD_LOG_THROW(exceptionType_t, logger, msg)
Throw exception with information about the throw location.
Definition exceptions.hpp:356
GuardCallback class header file.
Definition actionsApp.cpp:23
log4cplus::Logger & GetLogger()
Definition logger.cpp:72
std::list< scxml4cpp::Activity * > ActivityList
Definition actionMgr.hpp:34
std::list< scxml4cpp::Action * > ActionList
Definition actionMgr.hpp:32
std::list< rad::ActionGroup * > ActionGroupList
Definition actionMgr.hpp:33
Definition Action.cpp:36
Definition testCoroActivity.cpp:16