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

Async behavior that adds an event using gcalcli quick add. More...

#include <cb_quick_add.hpp>

Inheritance diagram for cl_gcalcli::CbQuickAdd:
Inheritance graph
Collaboration diagram for cl_gcalcli::CbQuickAdd:
Collaboration graph

Public Member Functions

 CbQuickAdd (const std::string &text, const std::string &calendar="")
 Construct with event description.
 
virtual ~CbQuickAdd ()=default
 
void onEntry () override
 
- 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)
 
virtual void onExit ()
 

Private Attributes

std::string text_
 
std::string calendar_
 
ClGcalcliclient_
 

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 adds an event using gcalcli quick add.

This behavior uses gcalcli's "quick" command to add events using natural language. Posts success on completion or failure on error.

Example:

configure<OrCalendar, CbQuickAdd>("Team meeting tomorrow at 3pm for 1 hour");

Definition at line 37 of file cb_quick_add.hpp.

Constructor & Destructor Documentation

◆ CbQuickAdd()

cl_gcalcli::CbQuickAdd::CbQuickAdd ( const std::string & text,
const std::string & calendar = "" )
explicit

Construct with event description.

Parameters
textNatural language event description
calendarOptional specific calendar name

Definition at line 20 of file cb_quick_add.cpp.

21: text_(text), calendar_(calendar), client_(nullptr)
22{
23}

◆ ~CbQuickAdd()

virtual cl_gcalcli::CbQuickAdd::~CbQuickAdd ( )
virtualdefault

Member Function Documentation

◆ onEntry()

void cl_gcalcli::CbQuickAdd::onEntry ( )
overridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 25 of file cb_quick_add.cpp.

26{
27 RCLCPP_INFO(getLogger(), "[CbQuickAdd] Adding event: %s", text_.c_str());
28
30
31 if (!client_)
32 {
33 RCLCPP_ERROR(getLogger(), "[CbQuickAdd] ClGcalcli client not available");
34 this->postFailureEvent();
35 return;
36 }
37
38 auto * connection = client_->getConnection();
39 if (!connection)
40 {
41 RCLCPP_ERROR(getLogger(), "[CbQuickAdd] CpGcalcliConnection not available");
42 this->postFailureEvent();
43 return;
44 }
45
46 // Build the quick add command
47 std::string args = "quick";
48
49 if (!calendar_.empty())
50 {
51 args += " --calendar \"" + calendar_ + "\"";
52 }
53
54 // Escape the text for shell
55 std::string escaped_text = text_;
56 // Replace double quotes with escaped quotes
57 size_t pos = 0;
58 while ((pos = escaped_text.find('"', pos)) != std::string::npos)
59 {
60 escaped_text.replace(pos, 1, "\\\"");
61 pos += 2;
62 }
63
64 args += " \"" + escaped_text + "\"";
65
66 auto result = connection->executeGcalcli(args, 30000);
67
68 if (result.exit_code == 0 && !result.timed_out)
69 {
70 RCLCPP_INFO(getLogger(), "[CbQuickAdd] Event added successfully");
71 this->postSuccessEvent();
72 }
73 else
74 {
75 RCLCPP_ERROR(getLogger(), "[CbQuickAdd] Failed to add event: %s", result.stdout_output.c_str());
76 this->postFailureEvent();
77 }
78}
CpGcalcliConnection * getConnection()
smacc2::client_core_components::SubprocessResult executeGcalcli(const std::string &args, int timeout_ms=30000)
Execute a gcalcli command.
virtual rclcpp::Logger getLogger() const
void requiresClient(SmaccClientType *&storage)

References calendar_, client_, cl_gcalcli::CpGcalcliConnection::executeGcalcli(), cl_gcalcli::ClGcalcli::getConnection(), smacc2::ISmaccClientBehavior::getLogger(), smacc2::SmaccAsyncClientBehavior::postFailureEvent(), smacc2::SmaccAsyncClientBehavior::postSuccessEvent(), smacc2::ISmaccClientBehavior::requiresClient(), and text_.

Here is the call graph for this function:

Member Data Documentation

◆ calendar_

std::string cl_gcalcli::CbQuickAdd::calendar_
private

Definition at line 53 of file cb_quick_add.hpp.

Referenced by onEntry().

◆ client_

ClGcalcli* cl_gcalcli::CbQuickAdd::client_
private

Definition at line 54 of file cb_quick_add.hpp.

Referenced by onEntry().

◆ text_

std::string cl_gcalcli::CbQuickAdd::text_
private

Definition at line 52 of file cb_quick_add.hpp.

Referenced by onEntry().


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