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. Caller holds lock on mtx_; it is released while
78 // joining the read thread.
79 void intClose(std::unique_lock<std::mutex>& lock);
80
81 // Condition signaled when activity state changes.
82 std::condition_variable cond_;
83
84 // Mutex for file/thread/activity state.
85 std::mutex mtx_;
86
87 public:
98 static std::shared_ptr<rogue::utilities::fileio::StreamReader> create();
99
101 static void setup_python();
102
110 StreamReader();
111
114
120 void open(std::string file);
121
125 void close();
126
132 bool isOpen();
133
137 void closeWait();
138
144 bool isActive();
145};
146
147// Convenience
148typedef std::shared_ptr<rogue::utilities::fileio::StreamReader> StreamReaderPtr;
149} // namespace fileio
150} // namespace utilities
151} // namespace rogue
152#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