mirror of
https://github.com/paulscherrerinstitute/sf_daq_buffer.git
synced 2026-05-01 22:42:23 +02:00
Use the std namespace
This commit is contained in:
+34
-32
@@ -7,9 +7,11 @@
|
||||
#include <iostream>
|
||||
#include <cstddef>
|
||||
|
||||
using namespace std;
|
||||
|
||||
RingBuffer::RingBuffer(size_t n_slots) : n_slots(n_slots), ringbuffer_slots(n_slots, 0){
|
||||
#ifdef DEBUG
|
||||
std::cout << "[RingBuffer::RingBuffer] Creating ring buffer with n_slots " << n_slots << std::endl;
|
||||
cout << "[RingBuffer::RingBuffer] Creating ring buffer with n_slots " << n_slots << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -25,14 +27,14 @@ void RingBuffer::initialize(size_t slot_size)
|
||||
{
|
||||
// Check if the ring buffer is already initialized.
|
||||
if (frame_data_buffer != NULL) {
|
||||
std::stringstream error_message;
|
||||
error_message << "Ring buffer already initialized." << std::endl;
|
||||
stringstream error_message;
|
||||
error_message << "Ring buffer already initialized." << endl;
|
||||
|
||||
throw std::runtime_error(error_message.str());
|
||||
throw runtime_error(error_message.str());
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
std::cout << "[RingBuffer::initialize] Initializing ring buffer with slot_size " << slot_size << std::endl;
|
||||
cout << "[RingBuffer::initialize] Initializing ring buffer with slot_size " << slot_size << endl;
|
||||
#endif
|
||||
|
||||
this->write_index = 0;
|
||||
@@ -43,7 +45,7 @@ void RingBuffer::initialize(size_t slot_size)
|
||||
this->ring_buffer_initialized = true;
|
||||
|
||||
#ifdef DEBUG
|
||||
std::cout << "[RingBuffer::initialize] Total buffer_size " << buffer_size << std::endl;
|
||||
cout << "[RingBuffer::initialize] Total buffer_size " << buffer_size << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -56,11 +58,11 @@ void RingBuffer::write(FrameMetadata &metadata, char* data)
|
||||
|
||||
// All images must fit in the ring buffer.
|
||||
if (metadata.frame_bytes_size > slot_size) {
|
||||
std::stringstream error_message;
|
||||
error_message << "Received frame index "<< metadata.frame_index <<" that is too large for ring buffer slot." << std::endl;
|
||||
error_message << "RingBuffer slot size " << slot_size << ", but frame bytes size " << metadata.frame_bytes_size << std::endl;
|
||||
stringstream error_message;
|
||||
error_message << "Received frame index "<< metadata.frame_index <<" that is too large for ring buffer slot." << endl;
|
||||
error_message << "RingBuffer slot size " << slot_size << ", but frame bytes size " << metadata.frame_bytes_size << endl;
|
||||
|
||||
throw std::runtime_error(error_message.str());
|
||||
throw runtime_error(error_message.str());
|
||||
}
|
||||
|
||||
// Check and reserve slot in the buffer.
|
||||
@@ -73,7 +75,7 @@ void RingBuffer::write(FrameMetadata &metadata, char* data)
|
||||
metadata.buffer_slot_index = write_index;
|
||||
|
||||
#ifdef DEBUG
|
||||
std::cout << "[RingBuffer::write] Ring buffer slot " << metadata.buffer_slot_index << " reserved for frame_index " << metadata.frame_index << std::endl;
|
||||
cout << "[RingBuffer::write] Ring buffer slot " << metadata.buffer_slot_index << " reserved for frame_index " << metadata.frame_index << endl;
|
||||
#endif
|
||||
|
||||
// Increase and wrap the write index around if needed.
|
||||
@@ -83,20 +85,20 @@ void RingBuffer::write(FrameMetadata &metadata, char* data)
|
||||
buffer_used_slots++;
|
||||
|
||||
} else {
|
||||
std::stringstream error_message;
|
||||
error_message << "Ring buffer is full. Collision at write_index = " << write_index << std::endl;
|
||||
stringstream error_message;
|
||||
error_message << "Ring buffer is full. Collision at write_index = " << write_index << endl;
|
||||
|
||||
throw std::runtime_error(error_message.str());
|
||||
throw runtime_error(error_message.str());
|
||||
}
|
||||
|
||||
ringbuffer_slots_mutex.unlock();
|
||||
|
||||
// Write to the buffer. The slot is already reserved.
|
||||
char* slot_memory_address = get_buffer_slot_address(metadata.buffer_slot_index);
|
||||
std::memcpy(slot_memory_address, data, metadata.frame_bytes_size);
|
||||
memcpy(slot_memory_address, data, metadata.frame_bytes_size);
|
||||
|
||||
#ifdef DEBUG
|
||||
std::cout << "[RingBuffer::write] Copied " << metadata.frame_bytes_size << " frame bytes to buffer_slot_index " << metadata.buffer_slot_index << std::endl;
|
||||
cout << "[RingBuffer::write] Copied " << metadata.frame_bytes_size << " frame bytes to buffer_slot_index " << metadata.buffer_slot_index << endl;
|
||||
#endif
|
||||
|
||||
frame_metadata_queue_mutex.lock();
|
||||
@@ -107,7 +109,7 @@ void RingBuffer::write(FrameMetadata &metadata, char* data)
|
||||
frame_metadata_queue_mutex.unlock();
|
||||
|
||||
#ifdef DEBUG
|
||||
std::cout << "[RingBuffer] Metadata for frame_index " << metadata.frame_index << " added to metadata queue." << std::endl;
|
||||
cout << "[RingBuffer] Metadata for frame_index " << metadata.frame_index << " added to metadata queue." << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -116,20 +118,20 @@ char* RingBuffer::get_buffer_slot_address(size_t buffer_slot_index) {
|
||||
|
||||
// Check if the memory address is valid.
|
||||
if (slot_memory_address > frame_data_buffer + buffer_size) {
|
||||
std::stringstream error_message;
|
||||
error_message << "Calculated ring buffer address is out of bound for buffer_slot_index " << buffer_slot_index << std::endl;
|
||||
stringstream error_message;
|
||||
error_message << "Calculated ring buffer address is out of bound for buffer_slot_index " << buffer_slot_index << endl;
|
||||
|
||||
throw std::runtime_error(error_message.str());
|
||||
throw runtime_error(error_message.str());
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
std::cout << "[RingBuffer::get_buffer_slot_address] For buffer_slot_index " << buffer_slot_index << " the calculated memory address is " << long(slot_memory_address) << std::endl;
|
||||
cout << "[RingBuffer::get_buffer_slot_address] For buffer_slot_index " << buffer_slot_index << " the calculated memory address is " << long(slot_memory_address) << endl;
|
||||
#endif
|
||||
|
||||
return slot_memory_address;
|
||||
}
|
||||
|
||||
std::pair<FrameMetadata, char*> RingBuffer::read()
|
||||
pair<FrameMetadata, char*> RingBuffer::read()
|
||||
{
|
||||
FrameMetadata frame_metadata;
|
||||
|
||||
@@ -149,7 +151,7 @@ std::pair<FrameMetadata, char*> RingBuffer::read()
|
||||
frame_metadata_queue_mutex.unlock();
|
||||
|
||||
#ifdef DEBUG
|
||||
std::cout << "[RingBuffer::read] Received metadata for frame_index " << frame_metadata.frame_index << std::endl;
|
||||
cout << "[RingBuffer::read] Received metadata for frame_index " << frame_metadata.frame_index << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -157,10 +159,10 @@ std::pair<FrameMetadata, char*> RingBuffer::read()
|
||||
ringbuffer_slots_mutex.lock();
|
||||
|
||||
if (!ringbuffer_slots[frame_metadata.buffer_slot_index]) {
|
||||
std::stringstream error_message;
|
||||
error_message << "Ring buffer slot referenced in message header " << frame_metadata.buffer_slot_index << " is empty." << std::endl;
|
||||
stringstream error_message;
|
||||
error_message << "Ring buffer slot referenced in message header " << frame_metadata.buffer_slot_index << " is empty." << endl;
|
||||
|
||||
throw std::runtime_error(error_message.str());
|
||||
throw runtime_error(error_message.str());
|
||||
}
|
||||
|
||||
ringbuffer_slots_mutex.unlock();
|
||||
@@ -175,10 +177,10 @@ std::pair<FrameMetadata, char*> RingBuffer::read()
|
||||
void RingBuffer::release(size_t buffer_slot_index) {
|
||||
// Cannot release a slot index that is out of range.
|
||||
if (buffer_slot_index >= n_slots) {
|
||||
std::stringstream error_message;
|
||||
error_message << "Slot index to release " << buffer_slot_index << " is out of range. Ring buffer n_slots = " << n_slots << std::endl;
|
||||
stringstream error_message;
|
||||
error_message << "Slot index to release " << buffer_slot_index << " is out of range. Ring buffer n_slots = " << n_slots << endl;
|
||||
|
||||
throw std::runtime_error(error_message.str());
|
||||
throw runtime_error(error_message.str());
|
||||
}
|
||||
|
||||
// Release the buffer slot.
|
||||
@@ -191,10 +193,10 @@ void RingBuffer::release(size_t buffer_slot_index) {
|
||||
buffer_used_slots--;
|
||||
|
||||
} else {
|
||||
std::stringstream error_message;
|
||||
error_message << "Cannot release empty ring buffer slot " << buffer_slot_index << std::endl;
|
||||
stringstream error_message;
|
||||
error_message << "Cannot release empty ring buffer slot " << buffer_slot_index << endl;
|
||||
|
||||
throw std::runtime_error(error_message.str());
|
||||
throw runtime_error(error_message.str());
|
||||
}
|
||||
|
||||
ringbuffer_slots_mutex.unlock();
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include "rest_interface.hpp"
|
||||
#include "crow_all.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void start_rest_api(WriterManager& writer_manager, uint16_t port)
|
||||
{
|
||||
crow::SimpleApp app;
|
||||
@@ -62,8 +64,8 @@ void start_rest_api(WriterManager& writer_manager, uint16_t port)
|
||||
auto request_parameters = crow::json::load(req.body);
|
||||
|
||||
// TODO: Fix this.
|
||||
|
||||
// const std::map<std::string, std::string> parameters_to_set;
|
||||
|
||||
// const map<string, string> parameters_to_set;
|
||||
|
||||
// for (const auto& item : request_parameters) {
|
||||
// parameters_to_set[item.first] = item.second;
|
||||
|
||||
Reference in New Issue
Block a user