12 constexpr
const char *
k_http =
"http://";
13 constexpr
const char *
k_api =
"/api/v1/";
15 { AlbCurlHelper::processing_service_e::Restart,
"processing/restart" },
16 { AlbCurlHelper::processing_service_e::Stop,
"processing/stop" },
17 { AlbCurlHelper::processing_service_e::Status,
"processing/status" }
37 static size_t write_callback(
void *contents,
size_t size,
size_t nmemb,
void *userp)
39 ((std::string *)userp)->append((
char *)contents, size * nmemb);
44 static size_t write_to_file_callback(
void *ptr,
size_t size,
size_t nmemb, FILE *stream)
46 size_t written = fwrite(ptr, size, nmemb, stream);
54 if (!ip_address.empty()) {
62 curl_easy_cleanup(
curl);
63 curl_slist_free_all(
chunk);
86 curl_easy_setopt(
curl, CURLOPT_HTTPHEADER, chunk);
88 curl_easy_setopt(
curl, CURLOPT_POST, 1L);
89 curl_easy_setopt(
curl, CURLOPT_POSTFIELDS,
"");
105 curl_easy_setopt(
curl, CURLOPT_HTTPHEADER, chunk);
108 error_message = std::string(
"[AlbCurlHelper] Unable to get processing status.");
118 outsight_alb_driver::AlbConfig::Request &request)
135 if (service == processing_config_e::Get) {
137 error_message = std::string(
"[AlbCurlHelper] Error exporting the config data.");
156 curl_easy_setopt(
curl, CURLOPT_HTTPHEADER,
chunk);
173 bool define_command =
false;
174 if (service == storage_service_e::List) {
180 if (!define_command) {
188 if (service == storage_service_e::List) {
190 std::string(
"List ") + request.category + std::string(
" files on ALB:"));
202 curl = curl_easy_init();
208 std::string full_address;
213 curl_easy_setopt(
curl, CURLOPT_URL, full_address.c_str());
216 curl_easy_setopt(
curl, CURLOPT_WRITEFUNCTION, write_callback);
221 outsight_alb_driver::AlbConfig::Request &request)
223 if (service == processing_config_e::Get) {
225 curl_easy_setopt(
curl, CURLOPT_HTTPHEADER,
chunk);
226 }
else if (service == processing_config_e::Put) {
229 curl_easy_setopt(
curl, CURLOPT_HTTPHEADER,
chunk);
231 std::string post_data =
readData(request.filepath);
233 if (post_data.empty()) {
239 curl_easy_setopt(
curl, CURLOPT_COPYPOSTFIELDS, post_data.c_str());
240 curl_easy_setopt(
curl, CURLOPT_CUSTOMREQUEST,
"PUT");
247 outsight_alb_driver::AlbFile::Request &request)
249 std::string storage_command;
251 storage_command.append(request.category);
252 storage_command.append(
"/");
253 storage_command.append(request.alb_filename);
255 std::string full_address;
260 curl_easy_setopt(
curl, CURLOPT_URL, full_address.c_str());
263 if (service == storage_service_e::Download) {
264 file = fopen(request.filepath.c_str(),
"wb");
267 error_message = std::string(
"Unable to open the output filepath.");
271 curl_easy_setopt(
curl, CURLOPT_WRITEFUNCTION, write_to_file_callback);
272 curl_easy_setopt(
curl, CURLOPT_WRITEDATA,
file);
274 curl_easy_setopt(
curl, CURLOPT_WRITEFUNCTION, write_callback);
279 curl_easy_setopt(
curl, CURLOPT_HTTPHEADER,
chunk);
281 file = fopen(request.filepath.c_str(),
"rb");
284 error_message = std::string(
"Unable to open the output filepath.");
288 curl_easy_setopt(
curl, CURLOPT_READDATA,
file);
289 curl_easy_setopt(
curl, CURLOPT_UPLOAD, 1L);
298 curl_code = curl_easy_perform(
curl);
300 if (curl_code != CURLE_OK) {
321 if (output_path.empty()) {
322 ROS_INFO(
"%s\n%s", print_text.c_str(), data.c_str());
327 fd = fopen(output_path.c_str(),
"w");
333 fwrite(data.c_str(),
sizeof(char), strlen(data.c_str()), fd);
343 fd = fopen(filepath.c_str(),
"r");
346 error_message = std::string(
"Unable to open file ") + filepath;
350 fseek(fd, 0, SEEK_END);
351 long fsize = ftell(fd);
352 fseek(fd, 0, SEEK_SET);
355 buffer = (
char *)malloc(
sizeof(
char) * (fsize + 1));
357 fread(buffer, 1, fsize, fd);
360 data = std::string(buffer);
368 std::string storage_command;
370 storage_command.append(request.category);
372 std::string full_address;
377 curl_easy_setopt(
curl, CURLOPT_URL, full_address.c_str());
380 curl_easy_setopt(
curl, CURLOPT_WRITEFUNCTION, write_callback);
384 curl_easy_setopt(
curl, CURLOPT_HTTPHEADER,
chunk);
processing_config_e
Processing configuration services.
bool defineStorageCommand(const storage_service_e service, outsight_alb_driver::AlbFile::Request &request)
Define the storage command.
bool initCurl(void)
Initialize the curl command.
bool isProcessingRunning(bool &running)
Check if processing is running.
constexpr const char * k_http
processing_service_e
Processing services of the ALB.
AlbCurlHelper(const std::string &ip_address)
constexpr const char * k_header_accept
bool defineProcessingConfig(const processing_config_e &service, outsight_alb_driver::AlbConfig::Request &request)
Define the processing configuration command.
constexpr const char * k_processing_config
void defineBaseCommand(const std::string &alb_command)
Define base curl command for the ALB.
constexpr const char * k_storage
constexpr const char * k_processing_zones
std::string error_message
const std::map< AlbCurlHelper::processing_service_e, std::string > k_processing_commands
constexpr const char * k_display_config
std::string callback_data
constexpr const char * k_api
constexpr const int k_server_success
bool defineStorageListCommand(const outsight_alb_driver::AlbFile::Request &request)
Define the command to list storage files.
bool executeProcessingConfig(const processing_config_e &service, outsight_alb_driver::AlbConfig::Request &request)
Execute the processing command for the configuration.
constexpr const int k_server_upload_success
constexpr const char * k_header_app_octet
bool executeProcessing(const processing_service_e service)
Execute the processing command.
storage_service_e
Storage services.
ROSCPP_DECL std::string append(const std::string &left, const std::string &right)
struct curl_slist * chunk
constexpr const char * k_header_app_json
const std::string getErrorMessage(void) const
Get the error message.
bool exportData(const std::string &data, const std::string &output_path, const std::string &print_text=std::string("Print data:"))
Export the data to the output filepath.
bool executeStorage(const storage_service_e service, outsight_alb_driver::AlbFile::Request &request)
Execute the storage command.
bool executeCurlCommand(const std::string &command)
Execute the curl command.
bool executeProcessingZones(std::string &zones)
Execute the processing command for the zones.
constexpr const char * k_header_content
const std::string readData(const std::string &filepath)
Read data from the input filepath.