Lens AI Profiler Cpp
saver.h
1 #ifndef SAVER_H
2 #define SAVER_H
3 
4 #include <mutex>
5 #include <thread>
6 #include <condition_variable>
7 #include <queue>
8 #include <string>
9 #include <atomic>
10 #include <opencv2/opencv.hpp>
11 
12 // Filesystem includes
13 #if __has_include(<filesystem>)
14  #include <filesystem>
15  namespace fs = std::filesystem;
16 #elif __has_include(<boost/filesystem.hpp>)
17  #include <boost/filesystem.hpp>
18  namespace fs = boost::filesystem;
19 #else
20  #error "No suitable filesystem library available"
21 #endif
22 
23 //#include "MyObject.h" // Include your object header
24 typedef struct {
25  std::string filename;
26  int type;
27  void *obj;
28  uint32_t max_size;
30 
31 typedef enum {
32  KLL_TYPE,
33  FI_TYPE,
34  JPEG_TYPE,
35  PNG_TYPE,
36  TYPE_MAX
37 }data_object_type_e;
38 
39 class Saver {
40 public:
41  // Constructor to specify filename and save interval
42  Saver(int interval, std::string class_name);
43  ~Saver();
44 
45  // Add an object to the queue for saving
46  void AddObjectToSave(void *object, int type, const std::string& filename);
47 
48  // Start the background thread to save objects from the queue periodically
49  void StartSaving();
50 
51  // Manual trigger to save all objects in the queue immediately
52  void TriggerSave();
53 
54  void StopSaving();
55 
56 #ifndef TEST
57 private:
58 #endif
59  // Function to be executed in the background thread
60  std::string parent_name;
61  void SaveLoop();
62 
63  std::atomic<bool> exitSaveLoop;
64  std::queue<data_object_t *> objects_to_save_; // Queue of objects to be saved
65  int save_interval_; // Interval between saves in minutes
66  std::thread save_thread_; // Thread object for saving
67  std::mutex queue_mutex_; // Mutex for queue access
68  std::condition_variable cv_; // Condition variable for thread synchronization
69 
70  // Replace this function with your actual logic to save the object to a file
71  void SaveObjectToFile(data_object_t *object);
72 };
73 
74 #endif // SAVER_H
Definition: saver.h:39
Definition: saver.h:24