first version of InternalUDPService

This commit is contained in:
Henry Winkel
2022-11-12 14:23:12 +01:00
parent 3006f79883
commit 84305eb7fa
16 changed files with 1924 additions and 136 deletions

View File

@@ -1,60 +1,60 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
// /*
// * This Source Code Form is subject to the terms of the Mozilla Public
// * License, v. 2.0. If a copy of the MPL was not distributed with this
// * file, You can obtain one at https://mozilla.org/MPL/2.0/.
// */
/**
* @file BasicMessageQueue.cpp
* @brief class which encapsulates queue
* @author Christina Sander <christina.sander@hsu-hh.de>
* @date 25.06.2020
* @copyright MPLv2
*/
#include <WHISPER/threadSafeQueue.hpp>
#include <iostream>
#include <string>
// /**
// * @file BasicMessageQueue.cpp
// * @brief class which encapsulates queue
// * @author Christina Sander <christina.sander@hsu-hh.de>
// * @date 25.06.2020
// * @copyright MPLv2
// */
// #include <WHISPER/threadSafeQueue.hpp>
// #include <iostream>
// #include <string>
template<class T>
WHISPER::threadSafeQueue<T> threadSafeQueue(){
// template<class T>
// WHISPER::threadSafeQueue<T> threadSafeQueue(){
}
// }
// appends the given message to the message queue
template<class T>
void WHISPER::threadSafeQueue< T>::addElement(std::unique_ptr<T> elem)
{
std::unique_lock<std::mutex> lk(mx);
q.push( std::move(elem) );
lk.unlock();
condVar.notify_one();
}
// // appends the given message to the message queue
// template<class T>
// void WHISPER::threadSafeQueue< T>::addElement(std::unique_ptr<T> elem)
// {
// std::unique_lock<std::mutex> lk(mx);
// q.push( std::move(elem) );
// lk.unlock();
// condVar.notify_one();
// }
// gets a message from the queue
template<class T>
std::unique_ptr<T> WHISPER::threadSafeQueue<T>::getElement()
{
std::unique_lock<std::mutex> lk(mx);
if( 0 == q.size() )
{
lk.unlock();
throw std::length_error("Empty Queue\n");
}
std::unique_ptr<std::string> elem = std::move( q.front() );
q.pop();
lk.unlock();
return std::move(elem);
}
// // gets a message from the queue
// template<class T>
// std::unique_ptr<T> WHISPER::threadSafeQueue<T>::getElement()
// {
// std::unique_lock<std::mutex> lk(mx);
// if( 0 == q.size() )
// {
// lk.unlock();
// throw std::length_error("Empty Queue\n");
// }
// std::unique_ptr<std::string> elem = std::move( q.front() );
// q.pop();
// lk.unlock();
// return std::move(elem);
// }
//returns the size of the message queue
template<class T>
unsigned int WHISPER::threadSafeQueue<T>::size()
{
std::unique_lock<std::mutex> lk(mx);
unsigned int size = q.size();
lk.unlock();
return size;
}
// //returns the size of the message queue
// template<class T>
// unsigned int WHISPER::threadSafeQueue<T>::size()
// {
// std::unique_lock<std::mutex> lk(mx);
// unsigned int size = q.size();
// lk.unlock();
// return size;
// }