FP Perception 0.1.2
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
fp_perception::RestBase Class Referenceabstract

RestBase. More...

#include <rest_base.hpp>

Inheritance diagram for fp_perception::RestBase:
Inheritance graph
[legend]
Collaboration diagram for fp_perception::RestBase:
Collaboration graph
[legend]

Public Member Functions

 RestBase ()
 Constructor.
 
virtual ~RestBase ()
 Destructor.
 
virtual void initialize_rest_base (const rclcpp::Node::SharedPtr &node, std::string plugin_name="RestBase", std::string api_key_name="")
 Initialize the REST base class.
 
virtual fp_perception::RESTResponse call (const fp_perception::RESTRequest &req)
 Request data from the REST API.
 
virtual fp_perception::RESTResponse call_audio (const fp_perception::RESTRequest &req)
 Request audio data from the REST API.
 
virtual fp_perception::RESTResponse call_tts (const fp_perception::RESTRequest &req)
 
- Public Member Functions inherited from fp_perception::DriverBase
virtual ~DriverBase ()=default
 
virtual void initialize (const rclcpp::Node::SharedPtr &node)
 Initialize the driver.
 
virtual void deinitialize ()=0
 Deinitialize the driver.
 
virtual std::string getName () const
 Get the name of the driver.
 
virtual void test ()
 Test the driver.
 
void check_directory (std::string folder_name)
 Check if the test directory exists, create it if not.
 
const std::filesystem::path check_file (const std::string &file_name)
 

Protected Member Functions

void apply_timeouts (CURL *curl)
 
void record_rest_result (bool success, long http_code, const std::string &error)
 
virtual nlohmann::json toJson (const fp_perception::RESTRequest &request)=0
 Convert a prompt request to a JSON object.
 
virtual fp_perception::RESTResponse fromJson (const nlohmann::json &object)=0
 Convert a JSON object to a fp_perception response.
 
- Protected Member Functions inherited from fp_perception::DriverBase
void initialize_base (const rclcpp::Node::SharedPtr &node)
 Initializer base driver in place of constructor due to plugin semantics.
 
bool diagnostics_enabled () const
 
void enable_diagnostics (const std::string &hardware_id, const std::string &task_name, std::function< void(diagnostic_updater::DiagnosticStatusWrapper &)> task, std::chrono::milliseconds period=std::chrono::seconds(1))
 
void disable_diagnostics ()
 

Static Protected Member Functions

static std::string build_http_error_message (long http_code, const std::string &response_data)
 
static size_t write_callback (void *contents, size_t size, size_t nmemb, std::string *userp)
 

Protected Attributes

std::string plugin_name_
 
std::string uri_
 
std::string method_
 
bool ssl_verify_
 
std::string auth_type_
 
std::string api_key_
 
long timeout_sec_ { 60 }
 
long connect_timeout_sec_ { 10 }
 
std::atomic< uint64_t > rest_request_count_ { 0 }
 
std::atomic< uint64_t > rest_failure_count_ { 0 }
 
std::atomic< bool > last_rest_success_ { true }
 
std::atomic< long > last_rest_http_code_ { 0 }
 
std::mutex rest_status_mutex_
 
std::string last_rest_error_
 
- Protected Attributes inherited from fp_perception::DriverBase
rclcpp::Node::SharedPtr node_
 ROS node for the driver.
 
std::string name_
 Name of the driver.
 
std::mutex buffer_mutex_
 Mutex to protect access to the driver data.
 
std::condition_variable buffer_cv_
 Condition variable to notify when new data is available.
 
std::atomic< bool > is_running_ { false }
 Flag to indicate if the driver thread is running.
 
bool diagnostics_enabled_ { false }
 Flag to enable standard ROS diagnostics publishing.
 
std::unique_ptr< diagnostic_updater::Updater > diagnostics_updater_
 
rclcpp::TimerBase::SharedPtr diagnostics_timer_
 

Detailed Description

RestBase.

This class implements a base class for RESTful fp_perception plugins. It provides a common interface for sending requests and receiving responses.

Constructor & Destructor Documentation

◆ RestBase()

fp_perception::RestBase::RestBase ( )
inline

Constructor.

Initializes the RestBase with default values.

◆ ~RestBase()

virtual fp_perception::RestBase::~RestBase ( )
inlinevirtual

Destructor.

Cleans up resources used by the RestBase.

Member Function Documentation

◆ apply_timeouts()

void fp_perception::RestBase::apply_timeouts ( CURL *  curl)
inlineprotected

◆ build_http_error_message()

static std::string fp_perception::RestBase::build_http_error_message ( long  http_code,
const std::string &  response_data 
)
inlinestaticprotected

◆ call()

virtual fp_perception::RESTResponse fp_perception::RestBase::call ( const fp_perception::RESTRequest req)
inlinevirtual

Request data from the REST API.

This method sends a RESTRequest to the REST API and returns the response.

Parameters
reqThe REST request containing the prompt and options.
Returns
A RESTResponse containing the response data.
Exceptions
fp_perception_exceptionif there is an error during the request.

◆ call_audio()

virtual fp_perception::RESTResponse fp_perception::RestBase::call_audio ( const fp_perception::RESTRequest req)
inlinevirtual

Request audio data from the REST API.

This method sends an audio file to the REST API and returns the response.

Parameters
reqThe REST request containing the audio file and options.
Returns
A RESTResponse containing the response data.
Exceptions
fp_perception_exceptionif there is an error during the request.

◆ call_tts()

virtual fp_perception::RESTResponse fp_perception::RestBase::call_tts ( const fp_perception::RESTRequest req)
inlinevirtual

◆ fromJson()

virtual fp_perception::RESTResponse fp_perception::RestBase::fromJson ( const nlohmann::json &  object)
protectedpure virtual

Convert a JSON object to a fp_perception response.

This method converts a JSON object received from the fp_perception plugin into a fp_perception response. It extracts the relevant fields from the JSON object and returns a fp_perception response object.

Parameters
objectThe JSON object to convert
Returns
A fp_perception response object containing the response data

Implemented in fp_perception::OpenAIImageAnalysisDriver, fp_perception::OpenAISpeechDriver, fp_perception::OpenAIDriver, and fp_perception::SentimentDriver.

◆ initialize_rest_base()

virtual void fp_perception::RestBase::initialize_rest_base ( const rclcpp::Node::SharedPtr &  node,
std::string  plugin_name = "RestBase",
std::string  api_key_name = "" 
)
inlinevirtual

Initialize the REST base class.

This method initializes the REST base class with parameters from the ROS parameter server.

Parameters
noderclcpp::Node::SharedPtr ROS node
Exceptions
fp_perception_exceptionif there is an error during initialization

◆ record_rest_result()

void fp_perception::RestBase::record_rest_result ( bool  success,
long  http_code,
const std::string &  error 
)
inlineprotected

◆ toJson()

virtual nlohmann::json fp_perception::RestBase::toJson ( const fp_perception::RESTRequest request)
protectedpure virtual

Convert a prompt request to a JSON object.

This method converts the fp_perception request to a JSON object that can be sent to the fp_perception plugin. It includes the prompt text and options for the JSON object.

Parameters
promptThe fp_perception request to convert
Returns
A JSON object representing the prompt request

Implemented in fp_perception::OpenAIImageAnalysisDriver, fp_perception::OpenAISpeechDriver, fp_perception::OpenAIDriver, and fp_perception::SentimentDriver.

◆ write_callback()

static size_t fp_perception::RestBase::write_callback ( void *  contents,
size_t  size,
size_t  nmemb,
std::string *  userp 
)
inlinestaticprotected

Member Data Documentation

◆ api_key_

std::string fp_perception::RestBase::api_key_
protected

◆ auth_type_

std::string fp_perception::RestBase::auth_type_
protected

◆ connect_timeout_sec_

long fp_perception::RestBase::connect_timeout_sec_ { 10 }
protected

◆ last_rest_error_

std::string fp_perception::RestBase::last_rest_error_
protected

◆ last_rest_http_code_

std::atomic<long> fp_perception::RestBase::last_rest_http_code_ { 0 }
protected

◆ last_rest_success_

std::atomic<bool> fp_perception::RestBase::last_rest_success_ { true }
protected

◆ method_

std::string fp_perception::RestBase::method_
protected

◆ plugin_name_

std::string fp_perception::RestBase::plugin_name_
protected

◆ rest_failure_count_

std::atomic<uint64_t> fp_perception::RestBase::rest_failure_count_ { 0 }
protected

◆ rest_request_count_

std::atomic<uint64_t> fp_perception::RestBase::rest_request_count_ { 0 }
protected

◆ rest_status_mutex_

std::mutex fp_perception::RestBase::rest_status_mutex_
protected

◆ ssl_verify_

bool fp_perception::RestBase::ssl_verify_
protected

◆ timeout_sec_

long fp_perception::RestBase::timeout_sec_ { 60 }
protected

◆ uri_

std::string fp_perception::RestBase::uri_
protected

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