SMACC2
Loading...
Searching...
No Matches
cl_gcalcli::CbDetectCalendarEvent Class Reference

Async behavior that waits for a calendar event's start time to arrive. More...

#include <cb_detect_calendar_event.hpp>

Inheritance diagram for cl_gcalcli::CbDetectCalendarEvent:
Inheritance graph
Collaboration diagram for cl_gcalcli::CbDetectCalendarEvent:
Collaboration graph

Public Member Functions

 CbDetectCalendarEvent (const std::string &pattern, bool use_regex=false, int minutes_before=0)
 Construct with pattern configuration.
 
virtual ~CbDetectCalendarEvent ()=default
 
void onEntry () override
 
void onExit () override
 
std::optional< CalendarEventgetDetectedEvent () const
 Get the detected event (if any)
 
- Public Member Functions inherited from smacc2::SmaccAsyncClientBehavior
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
virtual ~SmaccAsyncClientBehavior ()
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onSuccess (TCallback callback, T *object)
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onFinished (TCallback callback, T *object)
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onFailure (TCallback callback, T *object)
 
void requestForceFinish ()
 
void executeOnEntry () override
 
void executeOnExit () override
 
void waitOnEntryThread (bool requestFinish)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onSuccess (TCallbackMethod callback, T *object)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onFinished (TCallbackMethod callback, T *object)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onFailure (TCallbackMethod callback, T *object)
 
- Public Member Functions inherited from smacc2::ISmaccClientBehavior
 ISmaccClientBehavior ()
 
virtual ~ISmaccClientBehavior ()
 
ISmaccStateMachinegetStateMachine ()
 
std::string getName () const
 
template<typename SmaccClientType >
void requiresClient (SmaccClientType *&storage)
 
template<typename SmaccComponentType >
void requiresComponent (SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 

Private Member Functions

void onEventStarted (const CalendarEvent &event)
 Callback when an event starts.
 

Private Attributes

std::string pattern_
 
bool use_regex_
 
int minutes_before_
 
CpCalendarEventListenerlistener_
 
ClGcalcliclient_
 
std::optional< CalendarEventdetected_event_
 
bool triggered_
 

Additional Inherited Members

- Protected Member Functions inherited from smacc2::SmaccAsyncClientBehavior
void postSuccessEvent ()
 
void postFailureEvent ()
 
virtual void dispose () override
 
bool isShutdownRequested ()
 onEntry is executed in a new thread. However the current state cannot be left until the onEntry thread finishes. This flag can be checked from the onEntry thread to force finishing the thread.
 
- Protected Member Functions inherited from smacc2::ISmaccClientBehavior
virtual void runtimeConfigure ()
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
ISmaccStategetCurrentState ()
 
virtual rclcpp::Node::SharedPtr getNode () const
 
virtual rclcpp::Logger getLogger () const
 

Detailed Description

Async behavior that waits for a calendar event's start time to arrive.

This behavior configures a watch pattern on the CpCalendarEventListener and waits for an event matching the pattern to start. When the event start time arrives (minus minutes_before), it posts EvCbSuccess.

Usage in state:

static void staticConfigure() {
// Wait for "Standup" events, trigger 5 minutes before start
configure<OrCalendar, CbDetectCalendarEvent>(".*Standup.*", true, 5);
}

Definition at line 43 of file cb_detect_calendar_event.hpp.

Constructor & Destructor Documentation

◆ CbDetectCalendarEvent()

cl_gcalcli::CbDetectCalendarEvent::CbDetectCalendarEvent ( const std::string & pattern,
bool use_regex = false,
int minutes_before = 0 )

Construct with pattern configuration.

Parameters
patternPattern to match event titles
use_regexIf true, use regex matching; if false, substring match
minutes_beforeTrigger N minutes before event starts (0 = at start)

Definition at line 24 of file cb_detect_calendar_event.cpp.

◆ ~CbDetectCalendarEvent()

virtual cl_gcalcli::CbDetectCalendarEvent::~CbDetectCalendarEvent ( )
virtualdefault

Member Function Documentation

◆ getDetectedEvent()

std::optional< CalendarEvent > cl_gcalcli::CbDetectCalendarEvent::getDetectedEvent ( ) const
inline

Get the detected event (if any)

Definition at line 63 of file cb_detect_calendar_event.hpp.

63{ return detected_event_; }
std::optional< CalendarEvent > detected_event_

References detected_event_.

◆ onEntry()

void cl_gcalcli::CbDetectCalendarEvent::onEntry ( )
overridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 35 of file cb_detect_calendar_event.cpp.

36{
37 RCLCPP_INFO(
38 getLogger(),
39 "[CbDetectCalendarEvent] Waiting for event matching pattern '%s' (regex=%s, minutes_before=%d)",
40 pattern_.c_str(), use_regex_ ? "true" : "false", minutes_before_);
41
42 // Get the client and listener component
44 if (client_)
45 {
47 }
48
49 if (!listener_)
50 {
51 RCLCPP_ERROR(getLogger(), "[CbDetectCalendarEvent] CpCalendarEventListener not available");
52 this->postFailureEvent();
53 return;
54 }
55
56 // Reset triggered events to allow re-detection
58
59 // Configure the watch
60 EventWatch watch;
61 watch.pattern = pattern_;
62 watch.use_regex = use_regex_;
63 watch.minutes_before = minutes_before_;
64 watch.trigger_on_start = true;
65 watch.trigger_on_end = false;
66 watch.continuous = false;
67
68 listener_->addWatch(watch);
69
70 // Connect to the event started signal
72}
void onEventStarted(const CalendarEvent &event)
Callback when an event starts.
CpCalendarEventListener * getEventListener()
void resetTriggeredEvents()
Reset triggered event tracking (allows re-triggering)
smacc2::SmaccSignalConnection onEventStarted(void(T::*callback)(const CalendarEvent &), T *object)
void addWatch(const EventWatch &watch)
Add a watch pattern for event detection.
virtual rclcpp::Logger getLogger() const
void requiresClient(SmaccClientType *&storage)

References cl_gcalcli::CpCalendarEventListener::addWatch(), client_, cl_gcalcli::EventWatch::continuous, cl_gcalcli::ClGcalcli::getEventListener(), smacc2::ISmaccClientBehavior::getLogger(), listener_, cl_gcalcli::EventWatch::minutes_before, minutes_before_, onEventStarted(), cl_gcalcli::CpCalendarEventListener::onEventStarted(), cl_gcalcli::EventWatch::pattern, pattern_, smacc2::SmaccAsyncClientBehavior::postFailureEvent(), smacc2::ISmaccClientBehavior::requiresClient(), cl_gcalcli::CpCalendarEventListener::resetTriggeredEvents(), cl_gcalcli::EventWatch::trigger_on_end, cl_gcalcli::EventWatch::trigger_on_start, cl_gcalcli::EventWatch::use_regex, and use_regex_.

Here is the call graph for this function:

◆ onEventStarted()

void cl_gcalcli::CbDetectCalendarEvent::onEventStarted ( const CalendarEvent & event)
private

Callback when an event starts.

Definition at line 79 of file cb_detect_calendar_event.cpp.

80{
81 if (triggered_)
82 {
83 return; // Already triggered
84 }
85
86 // Check if this event matches our pattern
87 bool matches = false;
88 if (use_regex_)
89 {
90 try
91 {
92 boost::regex regex(pattern_, boost::regex::icase);
93 matches = boost::regex_search(event.title, regex);
94 }
95 catch (const boost::regex_error &)
96 {
97 matches = false;
98 }
99 }
100 else
101 {
102 std::string title_lower = event.title;
103 std::string pattern_lower = pattern_;
104 std::transform(title_lower.begin(), title_lower.end(), title_lower.begin(), ::tolower);
105 std::transform(pattern_lower.begin(), pattern_lower.end(), pattern_lower.begin(), ::tolower);
106 matches = title_lower.find(pattern_lower) != std::string::npos;
107 }
108
109 if (matches)
110 {
111 triggered_ = true;
112 detected_event_ = event;
113
114 RCLCPP_INFO(getLogger(), "[CbDetectCalendarEvent] Event detected: %s", event.title.c_str());
115
116 this->postSuccessEvent();
117 }
118}

References detected_event_, smacc2::ISmaccClientBehavior::getLogger(), pattern_, smacc2::SmaccAsyncClientBehavior::postSuccessEvent(), cl_gcalcli::CalendarEvent::title, triggered_, and use_regex_.

Referenced by onEntry().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onExit()

void cl_gcalcli::CbDetectCalendarEvent::onExit ( )
overridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 74 of file cb_detect_calendar_event.cpp.

75{
76 RCLCPP_DEBUG(getLogger(), "[CbDetectCalendarEvent] Exiting");
77}

References smacc2::ISmaccClientBehavior::getLogger().

Here is the call graph for this function:

Member Data Documentation

◆ client_

ClGcalcli* cl_gcalcli::CbDetectCalendarEvent::client_
private

Definition at line 76 of file cb_detect_calendar_event.hpp.

Referenced by onEntry().

◆ detected_event_

std::optional<CalendarEvent> cl_gcalcli::CbDetectCalendarEvent::detected_event_
private

Definition at line 78 of file cb_detect_calendar_event.hpp.

Referenced by getDetectedEvent(), and onEventStarted().

◆ listener_

CpCalendarEventListener* cl_gcalcli::CbDetectCalendarEvent::listener_
private

Definition at line 75 of file cb_detect_calendar_event.hpp.

Referenced by onEntry().

◆ minutes_before_

int cl_gcalcli::CbDetectCalendarEvent::minutes_before_
private

Definition at line 73 of file cb_detect_calendar_event.hpp.

Referenced by onEntry().

◆ pattern_

std::string cl_gcalcli::CbDetectCalendarEvent::pattern_
private

Definition at line 71 of file cb_detect_calendar_event.hpp.

Referenced by onEntry(), and onEventStarted().

◆ triggered_

bool cl_gcalcli::CbDetectCalendarEvent::triggered_
private

Definition at line 79 of file cb_detect_calendar_event.hpp.

Referenced by onEventStarted().

◆ use_regex_

bool cl_gcalcli::CbDetectCalendarEvent::use_regex_
private

Definition at line 72 of file cb_detect_calendar_event.hpp.

Referenced by onEntry(), and onEventStarted().


The documentation for this class was generated from the following files: