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 <atomic>
24#include <condition_variable>
25#include <map>
26#include <memory>
27#include <mutex>
28#include <queue>
29#include <thread>
30
31#include "rogue/Logging.h"
35
36namespace rogue {
37namespace protocols {
38namespace srp {
39
82 std::shared_ptr<rogue::Logging> log_;
83
84 static const uint32_t HeadLen = 20;
85 static const uint32_t TailLen = 4;
86
87 // Memory map type: 4K-aligned base address -> 4K page
88 typedef std::map<uint64_t, uint8_t*> MemoryMap;
89
90 // Internal memory emulation
91 MemoryMap memMap_;
92
93 // Memory access mutex
94 std::mutex memMtx_;
95
96 // Allocation tracking
97 uint32_t totAlloc_;
98
99 // Worker thread and queue
100 std::thread thread_;
101 std::queue<std::shared_ptr<rogue::interfaces::stream::Frame> > queue_;
102 std::mutex queMtx_;
103 std::condition_variable queCond_;
104
106 protected:
107 std::atomic<bool> threadEn_{false};
109
110 private:
112 void runThread();
113
115 void processFrame(std::shared_ptr<rogue::interfaces::stream::Frame> frame);
116
117 public:
128 static std::shared_ptr<rogue::protocols::srp::SrpV3Emulation> create();
129
131 static void setup_python();
132
142
145
152 void stop();
153
165 void acceptFrame(std::shared_ptr<rogue::interfaces::stream::Frame> frame);
166
167 private:
174 uint8_t* allocatePage(uint64_t addr4k);
175
183 void readMemory(uint64_t address, uint8_t* data, uint32_t size);
184
192 void writeMemory(uint64_t address, const uint8_t* data, uint32_t size);
193};
194
195// Convenience
196typedef std::shared_ptr<rogue::protocols::srp::SrpV3Emulation> SrpV3EmulationPtr;
197} // namespace srp
198} // namespace protocols
199} // namespace rogue
200#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