rogue
Loading...
Searching...
No Matches
SrpV3Emulation.h
Go to the documentation of this file.
1
17#ifndef __ROGUE_PROTOCOLS_SRP_SRPV3EMULATION_H__
18#define __ROGUE_PROTOCOLS_SRP_SRPV3EMULATION_H__
19#include "rogue/Directives.h"
20
21#include <stdint.h>
22
23#include <condition_variable>
24#include <map>
25#include <memory>
26#include <mutex>
27#include <queue>
28#include <thread>
29
30#include "rogue/Logging.h"
34
35namespace rogue {
36namespace protocols {
37namespace srp {
38
81 std::shared_ptr<rogue::Logging> log_;
82
83 static const uint32_t HeadLen = 20;
84 static const uint32_t TailLen = 4;
85
86 // Memory map type: 4K-aligned base address -> 4K page
87 typedef std::map<uint64_t, uint8_t*> MemoryMap;
88
89 // Internal memory emulation
90 MemoryMap memMap_;
91
92 // Memory access mutex
93 std::mutex memMtx_;
94
95 // Allocation tracking
96 uint32_t totAlloc_;
97
98 // Worker thread and queue
99 std::thread thread_;
100 std::queue<std::shared_ptr<rogue::interfaces::stream::Frame> > queue_;
101 std::mutex queMtx_;
102 std::condition_variable queCond_;
103 bool threadEn_;
104
106 void runThread();
107
109 void processFrame(std::shared_ptr<rogue::interfaces::stream::Frame> frame);
110
111 public:
122 static std::shared_ptr<rogue::protocols::srp::SrpV3Emulation> create();
123
125 static void setup_python();
126
136
139
146 void stop();
147
159 void acceptFrame(std::shared_ptr<rogue::interfaces::stream::Frame> frame);
160
161 private:
168 uint8_t* allocatePage(uint64_t addr4k);
169
177 void readMemory(uint64_t address, uint8_t* data, uint32_t size);
178
186 void writeMemory(uint64_t address, const uint8_t* data, uint32_t size);
187};
188
189// Convenience
190typedef std::shared_ptr<rogue::protocols::srp::SrpV3Emulation> SrpV3EmulationPtr;
191} // namespace srp
192} // namespace protocols
193} // namespace rogue
194#endif
Stream master endpoint.
Definition Master.h:65
Stream slave endpoint and default frame pool.
Definition Slave.h:72
Software SRPv3 server that emulates a hardware SRP endpoint.
SrpV3Emulation()
Constructs an SRP v3 server instance.
static std::shared_ptr< rogue::protocols::srp::SrpV3Emulation > create()
Creates an SRP v3 server instance.
static void setup_python()
Registers Python bindings for this class.
void stop()
Stops the worker thread.
~SrpV3Emulation()
Destroys the SRP v3 server instance and frees allocated memory.
void acceptFrame(std::shared_ptr< rogue::interfaces::stream::Frame > frame)
Queues an incoming SRP v3 request frame for processing.
std::shared_ptr< rogue::protocols::srp::SrpV3Emulation > SrpV3EmulationPtr