rogue
Loading...
Searching...
No Matches
StreamReader.h
Go to the documentation of this file.
1
17#ifndef __ROGUE_UTILITIES_FILEIO_STREAM_READER_H__
18#define __ROGUE_UTILITIES_FILEIO_STREAM_READER_H__
19#include "rogue/Directives.h"
20
21#include <stdint.h>
22
23#include <atomic>
24#include <condition_variable>
25#include <map>
26#include <memory>
27#include <mutex>
28#include <string>
29#include <thread>
30
32
33namespace rogue {
34namespace utilities {
35namespace fileio {
36
53 // Base file name for indexed-file mode.
54 std::string baseName_;
55
56 int32_t fd_ = -1;
57
58 // Current file index in indexed-file mode.
59 uint32_t fdIdx_ = 0;
60
61 // True while read thread is actively processing file data.
62 bool active_ = false;
63
65 protected:
66 std::thread* readThread_ = nullptr;
67 std::atomic<bool> threadEn_{false};
69
70 private:
71 // Worker thread entry point.
72 void runThread();
73
74 // Open next indexed file in sequence.
75 bool nextFile();
76
77 // Internal close helper.
78 void intClose();
79
80 // Condition signaled when activity state changes.
81 std::condition_variable cond_;
82
83 // Mutex for file/thread/activity state.
84 std::mutex mtx_;
85
86 public:
97 static std::shared_ptr<rogue::utilities::fileio::StreamReader> create();
98
100 static void setup_python();
101
109 StreamReader();
110
113
119 void open(std::string file);
120
124 void close();
125
131 bool isOpen();
132
136 void closeWait();
137
143 bool isActive();
144};
145
146// Convenience
147typedef std::shared_ptr<rogue::utilities::fileio::StreamReader> StreamReaderPtr;
148} // namespace fileio
149} // namespace utilities
150} // namespace rogue
151#endif
Stream master endpoint.
Definition Master.h:65
Reads Rogue stream data files and emits frames on stream master interface.
static std::shared_ptr< rogue::utilities::fileio::StreamReader > create()
Creates a stream reader instance.
~StreamReader()
Destroys stream reader and closes active file/thread.
void close()
Stops read thread and closes active file immediately.
void open(std::string file)
Opens a file and starts background read processing.
bool isOpen()
Returns whether a file descriptor is currently open.
static void setup_python()
Registers Python bindings for this class.
StreamReader()
Constructs a stream reader instance.
void closeWait()
Waits for read activity to complete, then closes file/thread.
bool isActive()
Returns read activity state.
std::shared_ptr< rogue::utilities::fileio::StreamReader > StreamReaderPtr