|
SMACC2
|
Component that manages gcalcli connection health. More...
#include <cp_gcalcli_connection.hpp>
Public Member Functions | |
| CpGcalcliConnection () | |
| virtual | ~CpGcalcliConnection ()=default |
| void | onInitialize () override |
| void | configure (const GcalcliConfig &config) |
| Configure the gcalcli connection parameters. | |
| ConnectionState | getConnectionState () const |
| Get current connection state. | |
| bool | isConnected () const |
| Check if connected to Google Calendar. | |
| bool | checkConnection () |
| Manually trigger a connection check. | |
| void | restartConnection () |
| Restart connection after failure. | |
| smacc2::client_core_components::SubprocessResult | executeGcalcli (const std::string &args, int timeout_ms=30000) |
| Execute a gcalcli command. | |
| const GcalcliConfig & | getConfig () const |
| Get the gcalcli configuration. | |
| template<typename T > | |
| smacc2::SmaccSignalConnection | onConnectionLost (void(T::*callback)(), T *object) |
| template<typename T > | |
| smacc2::SmaccSignalConnection | onConnectionRestored (void(T::*callback)(), T *object) |
| template<typename T > | |
| smacc2::SmaccSignalConnection | onAuthenticationRequired (void(T::*callback)(), T *object) |
| template<typename TOrthogonal , typename TSourceObject > | |
| void | onStateOrthogonalAllocation () |
| Template method for type-safe event posting setup. | |
Public Member Functions inherited from smacc2::ISmaccComponent | |
| ISmaccComponent () | |
| virtual | ~ISmaccComponent () |
| virtual std::string | getName () const |
Public Member Functions inherited from smacc2::ISmaccUpdatable | |
| ISmaccUpdatable () | |
| ISmaccUpdatable (rclcpp::Duration duration) | |
| void | executeUpdate (rclcpp::Node::SharedPtr node) |
| void | setUpdatePeriod (rclcpp::Duration duration) |
Public Attributes | |
| smacc2::SmaccSignal< void()> | onConnectionLost_ |
| smacc2::SmaccSignal< void()> | onConnectionRestored_ |
| smacc2::SmaccSignal< void()> | onAuthenticationRequired_ |
| std::function< void()> | postConnectionLostEvent_ |
| std::function< void()> | postConnectionRestoredEvent_ |
| std::function< void()> | postAuthenticationRequiredEvent_ |
Protected Member Functions | |
| void | update () override |
| Periodic update for heartbeat (called by SignalDetector) | |
Protected Member Functions inherited from smacc2::ISmaccComponent | |
| template<typename TOrthogonal , typename TClient > | |
| void | onComponentInitialization () |
| template<typename EventType > | |
| void | postEvent (const EventType &ev) |
| template<typename EventType > | |
| void | postEvent () |
| template<typename TOrthogonal , typename TSourceObject > | |
| void | onStateOrthogonalAllocation () |
| template<typename TComponent > | |
| void | requiresComponent (TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT) |
| template<typename TComponent > | |
| void | requiresComponent (std::string name, TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT) |
| template<typename TClient > | |
| void | requiresClient (TClient *&requiredClientStorage) |
| template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs> | |
| SmaccComponentType * | createSiblingComponent (TArgs... targs) |
| template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs> | |
| SmaccComponentType * | createSiblingNamedComponent (std::string name, TArgs... targs) |
| rclcpp::Node::SharedPtr | getNode () |
| rclcpp::Logger | getLogger () const |
| ISmaccStateMachine * | getStateMachine () |
Protected Member Functions inherited from smacc2::ISmaccUpdatable | |
Private Member Functions | |
| void | performHeartbeat () |
| Perform the heartbeat check. | |
| void | handleConnectionStateChange (bool success, const std::string &output) |
| Handle connection state change. | |
| bool | isAuthenticationError (const std::string &output) const |
| Check if output indicates authentication failure. | |
Private Attributes | |
| GcalcliConfig | config_ |
| ConnectionState | connection_state_ |
| int | consecutive_failures_ |
| bool | initialized_ |
| std::chrono::steady_clock::time_point | last_heartbeat_time_ |
| smacc2::client_core_components::CpSubprocessExecutor * | subprocess_executor_ |
| std::mutex | state_mutex_ |
Additional Inherited Members | |
Protected Attributes inherited from smacc2::ISmaccComponent | |
| ISmaccStateMachine * | stateMachine_ |
| ISmaccClient * | owner_ |
Component that manages gcalcli connection health.
This component monitors the connection to Google Calendar via gcalcli. It performs periodic heartbeat checks using "gcalcli list" and tracks consecutive failures. After max_consecutive_failures, it emits EvConnectionLost events.
The component uses CpSubprocessExecutor from smacc2 core for command execution.
Definition at line 42 of file cp_gcalcli_connection.hpp.
| cl_gcalcli::CpGcalcliConnection::CpGcalcliConnection | ( | ) |
Definition at line 20 of file cp_gcalcli_connection.cpp.
|
virtualdefault |
| bool cl_gcalcli::CpGcalcliConnection::checkConnection | ( | ) |
Manually trigger a connection check.
Definition at line 69 of file cp_gcalcli_connection.cpp.
References executeGcalcli(), smacc2::ISmaccComponent::getLogger(), handleConnectionStateChange(), and subprocess_executor_.
| void cl_gcalcli::CpGcalcliConnection::configure | ( | const GcalcliConfig & | config | ) |
Configure the gcalcli connection parameters.
Definition at line 50 of file cp_gcalcli_connection.cpp.
References config_, smacc2::ISmaccComponent::getLogger(), and state_mutex_.
| smacc2::client_core_components::SubprocessResult cl_gcalcli::CpGcalcliConnection::executeGcalcli | ( | const std::string & | args, |
| int | timeout_ms = 30000 ) |
Execute a gcalcli command.
| args | Command arguments (e.g., "agenda --tsv") |
| timeout_ms | Command timeout in milliseconds |
Definition at line 96 of file cp_gcalcli_connection.cpp.
References cl_gcalcli::GcalcliConfig::calendars, config_, cl_gcalcli::GcalcliConfig::config_folder, smacc2::client_core_components::CpSubprocessExecutor::executeCommand(), smacc2::client_core_components::SubprocessResult::exit_code, cl_gcalcli::GcalcliConfig::gcalcli_path, smacc2::ISmaccComponent::getLogger(), smacc2::client_core_components::SubprocessResult::stderr_output, subprocess_executor_, and smacc2::client_core_components::SubprocessResult::timed_out.
Referenced by checkConnection(), cl_gcalcli::CbQuickAdd::onEntry(), performHeartbeat(), and cl_gcalcli::CpCalendarPoller::refreshAgenda().
|
inline |
Get the gcalcli configuration.
Definition at line 88 of file cp_gcalcli_connection.hpp.
References config_.
Referenced by cl_gcalcli::CpCalendarPoller::refreshAgenda(), and cl_gcalcli::CpCalendarPoller::update().
| ConnectionState cl_gcalcli::CpGcalcliConnection::getConnectionState | ( | ) | const |
Get current connection state.
Definition at line 57 of file cp_gcalcli_connection.cpp.
References connection_state_, and state_mutex_.
|
private |
Handle connection state change.
Definition at line 158 of file cp_gcalcli_connection.cpp.
References cl_gcalcli::AUTHENTICATING, config_, cl_gcalcli::CONNECTED, connection_state_, consecutive_failures_, cl_gcalcli::DISCONNECTED, cl_gcalcli::ERROR, smacc2::ISmaccComponent::getLogger(), isAuthenticationError(), cl_gcalcli::GcalcliConfig::max_consecutive_failures, onAuthenticationRequired_, onConnectionLost_, onConnectionRestored_, postAuthenticationRequiredEvent_, postConnectionLostEvent_, postConnectionRestoredEvent_, and state_mutex_.
Referenced by checkConnection(), and performHeartbeat().
|
private |
Check if output indicates authentication failure.
Definition at line 225 of file cp_gcalcli_connection.cpp.
Referenced by handleConnectionStateChange().
| bool cl_gcalcli::CpGcalcliConnection::isConnected | ( | ) | const |
Check if connected to Google Calendar.
Definition at line 63 of file cp_gcalcli_connection.cpp.
References cl_gcalcli::CONNECTED, connection_state_, and state_mutex_.
Referenced by cl_gcalcli::CpCalendarPoller::refreshAgenda(), and cl_gcalcli::CpCalendarPoller::update().
|
inline |
Definition at line 109 of file cp_gcalcli_connection.hpp.
References smacc2::ISmaccStateMachine::createSignalConnection(), and smacc2::ISmaccComponent::getStateMachine().
|
inline |
Definition at line 97 of file cp_gcalcli_connection.hpp.
References smacc2::ISmaccStateMachine::createSignalConnection(), and smacc2::ISmaccComponent::getStateMachine().
Referenced by cl_gcalcli::CbMonitorConnection::onEntry().
|
inline |
Definition at line 103 of file cp_gcalcli_connection.hpp.
References smacc2::ISmaccStateMachine::createSignalConnection(), and smacc2::ISmaccComponent::getStateMachine().
Referenced by cl_gcalcli::CbMonitorConnection::onEntry().
|
overridevirtual |
Reimplemented from smacc2::ISmaccComponent.
Definition at line 28 of file cp_gcalcli_connection.cpp.
References config_, cl_gcalcli::GcalcliConfig::gcalcli_path, smacc2::ISmaccComponent::getLogger(), initialized_, last_heartbeat_time_, smacc2::ISmaccComponent::requiresComponent(), and subprocess_executor_.
|
inline |
Template method for type-safe event posting setup.
Definition at line 124 of file cp_gcalcli_connection.hpp.
References postConnectionLostEvent_, and smacc2::ISmaccComponent::postEvent().
|
private |
Perform the heartbeat check.
Definition at line 148 of file cp_gcalcli_connection.cpp.
References executeGcalcli(), smacc2::ISmaccComponent::getLogger(), and handleConnectionStateChange().
Referenced by update().
| void cl_gcalcli::CpGcalcliConnection::restartConnection | ( | ) |
Restart connection after failure.
Definition at line 86 of file cp_gcalcli_connection.cpp.
References connection_state_, consecutive_failures_, cl_gcalcli::DISCONNECTED, smacc2::ISmaccComponent::getLogger(), and state_mutex_.
|
overrideprotectedvirtual |
Periodic update for heartbeat (called by SignalDetector)
Implements smacc2::ISmaccUpdatable.
Definition at line 131 of file cp_gcalcli_connection.cpp.
References config_, cl_gcalcli::GcalcliConfig::heartbeat_interval, initialized_, last_heartbeat_time_, performHeartbeat(), and subprocess_executor_.
|
private |
Definition at line 158 of file cp_gcalcli_connection.hpp.
Referenced by configure(), executeGcalcli(), getConfig(), handleConnectionStateChange(), onInitialize(), and update().
|
private |
Definition at line 159 of file cp_gcalcli_connection.hpp.
Referenced by getConnectionState(), handleConnectionStateChange(), isConnected(), and restartConnection().
|
private |
Definition at line 160 of file cp_gcalcli_connection.hpp.
Referenced by handleConnectionStateChange(), and restartConnection().
|
private |
Definition at line 161 of file cp_gcalcli_connection.hpp.
Referenced by onInitialize(), and update().
|
private |
Definition at line 163 of file cp_gcalcli_connection.hpp.
Referenced by onInitialize(), and update().
| smacc2::SmaccSignal<void()> cl_gcalcli::CpGcalcliConnection::onAuthenticationRequired_ |
Definition at line 93 of file cp_gcalcli_connection.hpp.
Referenced by handleConnectionStateChange().
| smacc2::SmaccSignal<void()> cl_gcalcli::CpGcalcliConnection::onConnectionLost_ |
Definition at line 91 of file cp_gcalcli_connection.hpp.
Referenced by handleConnectionStateChange().
| smacc2::SmaccSignal<void()> cl_gcalcli::CpGcalcliConnection::onConnectionRestored_ |
Definition at line 92 of file cp_gcalcli_connection.hpp.
Referenced by handleConnectionStateChange().
| std::function<void()> cl_gcalcli::CpGcalcliConnection::postAuthenticationRequiredEvent_ |
Definition at line 118 of file cp_gcalcli_connection.hpp.
Referenced by handleConnectionStateChange().
| std::function<void()> cl_gcalcli::CpGcalcliConnection::postConnectionLostEvent_ |
Definition at line 116 of file cp_gcalcli_connection.hpp.
Referenced by handleConnectionStateChange(), and onStateOrthogonalAllocation().
| std::function<void()> cl_gcalcli::CpGcalcliConnection::postConnectionRestoredEvent_ |
Definition at line 117 of file cp_gcalcli_connection.hpp.
Referenced by handleConnectionStateChange().
|
mutableprivate |
Definition at line 166 of file cp_gcalcli_connection.hpp.
Referenced by configure(), getConnectionState(), handleConnectionStateChange(), isConnected(), and restartConnection().
|
private |
Definition at line 165 of file cp_gcalcli_connection.hpp.
Referenced by checkConnection(), executeGcalcli(), onInitialize(), and update().