Lens AI Profiler Cpp
http_uploader.h
Go to the documentation of this file.
1 
6 #ifndef HTTP_UPLOADER_H
7 #define HTTP_UPLOADER_H
8 
9 #include "tar_gz_creator.h"
10 #include <string>
11 #include <vector>
12 #include <ctime>
13 #include <thread>
14 #include <atomic>
15 #include <map>
16 
18 #define UPLOAD_RETRY_COUNT 2
19 
23 typedef struct {
24  std::string endpointUrl;
25  std::string token;
26  std::vector<std::string> folderPath;
27  std::string sensorId;
28  std::vector<std::string> fileType;
29  std::vector<bool> deletedata;
30  int interval;
32 
36 class HttpUploader {
37 public:
41  ~HttpUploader();
42 
48  HttpUploader(const std::string& conf_path, const std::string& uploader_name);
49 
53  void StartUpload();
54 
58  void StopUpload();
59 
63  void UploadLoop();
64 
65 private:
66  std::map<std::string, std::vector<std::string>> lensaipublisherConfig;
67  http_uploader_data_t http_uploader_data_;
68 
69  std::thread upload_thread_;
70  std::mutex upload_mutex_;
71 
72  std::atomic<bool> exitUploadLoop;
73 
74  std::string uploader_name_;
75 
84  bool postFile(const std::string& filePath, const std::string& sensorId, time_t timestamp, const std::string& fileType);
85 
91  bool uploadFolder(int &index);
92 };
93 
94 #endif // HTTP_UPLOADER_H
The HttpUploader class handles uploading files to an HTTP server.
Definition: http_uploader.h:36
HttpUploader(const std::string &conf_path, const std::string &uploader_name)
Constructor for HttpUploader.
Definition: http_uploader.cpp:51
void StartUpload()
Starts the upload process in a separate thread.
Definition: http_uploader.cpp:90
~HttpUploader()
Destructor for HttpUploader.
Definition: http_uploader.cpp:35
void StopUpload()
Stops the upload process by joining the upload thread.
Definition: http_uploader.cpp:136
void UploadLoop()
The main loop for uploading files, executed in a separate thread.
Definition: http_uploader.cpp:100
Struct to hold HTTP uploader configuration data.
Definition: http_uploader.h:23
std::string sensorId
Sensor ID to be used in the upload.
Definition: http_uploader.h:27
int interval
Interval in seconds between uploads.
Definition: http_uploader.h:30
std::string endpointUrl
URL of the HTTP endpoint.
Definition: http_uploader.h:24
std::string token
Authorization token.
Definition: http_uploader.h:25
std::vector< std::string > fileType
File types to upload.
Definition: http_uploader.h:28
std::vector< std::string > folderPath
Paths of the folders to upload.
Definition: http_uploader.h:26
std::vector< bool > deletedata
Flags to indicate whether to delete data after upload.
Definition: http_uploader.h:29