Logo
ApraPipes 1.0
Loading...
Searching...
No Matches
FileReaderModule.h
1#pragma once
2#include <string>
3#include <unordered_map>
4#include <array>
5#include <map>
6#include <vector>
7#include "Module.h"
8#include <boost/serialization/vector.hpp>
9#include "declarative/PropertyMacros.h"
10
11using namespace std;
12
14
16{
17public:
18 FileReaderModuleProps(const std::string& _strFullFileNameWithPattern, int _startIndex = 0, int _maxIndex = -1): ModuleProps()
19 {
20 strFullFileNameWithPattern = _strFullFileNameWithPattern;
21 startIndex = _startIndex;
22 maxIndex = _maxIndex;
23 readLoop = true;
24 }
25
27 {
29 startIndex = 0;
30 maxIndex = -1;
31 readLoop = true;
32 }
33
35 {
36 size_t len = 0;
37 auto noOfFiles = files.size();
38 for (auto i = 0; i < noOfFiles; i++)
39 {
40 len += files[i].length();
41 }
42
43 return ModuleProps::getSerializeSize() + sizeof(startIndex) + sizeof(maxIndex) + strFullFileNameWithPattern.length() + sizeof(string) + sizeof(readLoop) + sizeof(files) + len;
44 }
45
50 std::vector<std::string> files;
51
52 // ============================================================
53 // Property Binding for Declarative Pipeline (Legacy Binding)
54 // Maps TOML property names to existing member variables
55 // ============================================================
56 template<typename PropsT>
57 static void applyProperties(
58 PropsT& props,
59 const std::map<std::string, apra::ScalarPropertyValue>& values,
60 std::vector<std::string>& missingRequired
61 ) {
62 apra::applyProp(props.strFullFileNameWithPattern, "strFullFileNameWithPattern", values, true, missingRequired);
63 apra::applyProp(props.startIndex, "startIndex", values, false, missingRequired);
64 apra::applyProp(props.maxIndex, "maxIndex", values, false, missingRequired);
65 apra::applyProp(props.readLoop, "readLoop", values, false, missingRequired);
66 }
67
68 // Runtime property getter
69 apra::ScalarPropertyValue getProperty(const std::string& propName) const {
70 if (propName == "strFullFileNameWithPattern") return strFullFileNameWithPattern;
71 if (propName == "startIndex") return static_cast<int64_t>(startIndex);
72 if (propName == "maxIndex") return static_cast<int64_t>(maxIndex);
73 if (propName == "readLoop") return readLoop;
74 throw std::runtime_error("Unknown property: " + propName);
75 }
76
77 // Runtime property setter (all properties are static for this module)
78 bool setProperty(const std::string& propName, const apra::ScalarPropertyValue& value) {
79 throw std::runtime_error("Cannot modify static property '" + propName + "' after initialization");
80 }
81
82 // No dynamic properties
83 static std::vector<std::string> dynamicPropertyNames() {
84 return {};
85 }
86
87private:
89
90 template<class Archive>
91 void serialize(Archive &ar, const unsigned int version)
92 {
93 ar & boost::serialization::base_object<ModuleProps>(*this);
94 ar & startIndex;
96 ar & readLoop;
97 ar & files;
98 }
99};
100
101
103public:
105 virtual ~FileReaderModule();
106 bool init();
107 bool term();
108
109 bool jump(uint64_t index);
110
111 void setProps(FileReaderModuleProps& props);
113
114protected:
115 bool produce();
116 bool validateOutputPins();
117 void notifyPlay(bool play);
118 bool handleCommand(Command::CommandType type, frame_sp& frame);
119 bool handlePropsChange(frame_sp& frame);
120private:
121 string mPinId;
122 boost::shared_ptr<FileSequenceDriver> mDriver;
124 frame_container mFrames;
125 bool mCache;
126};
CommandType
Definition Command.h:9
Definition FileReaderModule.h:16
string strFullFileNameWithPattern
Definition FileReaderModule.h:48
static void applyProperties(PropsT &props, const std::map< std::string, apra::ScalarPropertyValue > &values, std::vector< std::string > &missingRequired)
Definition FileReaderModule.h:57
bool readLoop
Definition FileReaderModule.h:49
size_t getSerializeSize()
Definition FileReaderModule.h:34
std::vector< std::string > files
Definition FileReaderModule.h:50
int startIndex
Definition FileReaderModule.h:46
FileReaderModuleProps()
Definition FileReaderModule.h:26
void serialize(Archive &ar, const unsigned int version)
Definition FileReaderModule.h:91
friend class boost::serialization::access
Definition FileReaderModule.h:88
static std::vector< std::string > dynamicPropertyNames()
Definition FileReaderModule.h:83
FileReaderModuleProps(const std::string &_strFullFileNameWithPattern, int _startIndex=0, int _maxIndex=-1)
Definition FileReaderModule.h:18
int maxIndex
Definition FileReaderModule.h:47
apra::ScalarPropertyValue getProperty(const std::string &propName) const
Definition FileReaderModule.h:69
bool setProperty(const std::string &propName, const apra::ScalarPropertyValue &value)
Definition FileReaderModule.h:78
Definition FileReaderModule.h:102
virtual ~FileReaderModule()
Definition FileReaderModule.cpp:14
void notifyPlay(bool play)
Definition FileReaderModule.cpp:114
bool handleCommand(Command::CommandType type, frame_sp &frame)
Definition FileReaderModule.cpp:126
FileReaderModuleProps getProps()
Definition FileReaderModule.cpp:146
bool handlePropsChange(frame_sp &frame)
Definition FileReaderModule.cpp:152
bool term()
Definition FileReaderModule.cpp:45
frame_container mFrames
Definition FileReaderModule.h:124
string mPinId
Definition FileReaderModule.h:121
bool jump(uint64_t index)
Definition FileReaderModule.cpp:119
boost::shared_ptr< FileSequenceDriver > mDriver
Definition FileReaderModule.h:122
FileReaderModuleProps mProps
Definition FileReaderModule.h:123
bool init()
Definition FileReaderModule.cpp:28
bool mCache
Definition FileReaderModule.h:125
FileReaderModule(FileReaderModuleProps _props)
Definition FileReaderModule.cpp:8
void setProps(FileReaderModuleProps &props)
Definition FileReaderModule.cpp:141
bool produce()
Definition FileReaderModule.cpp:51
bool validateOutputPins()
Definition FileReaderModule.cpp:16
Definition FileSequenceDriver.h:10
Definition Module.h:33
virtual size_t getSerializeSize()
Definition Module.h:101
Definition Module.h:151
bool play(float speed, bool direction=true)
Definition Module.cpp:1140
void applyProp(T &member, const char *propName, const std::map< std::string, ScalarPropertyValue > &values, bool isRequired, std::vector< std::string > &missingRequired)
Definition PropertyMacros.h:36
std::variant< int64_t, double, bool, std::string > ScalarPropertyValue
Definition ModuleRegistry.h:30