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