-
Notifications
You must be signed in to change notification settings - Fork 1
/
fifo.cpp
40 lines (31 loc) · 826 Bytes
/
fifo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
static FIFOs accessible from all processes
uses: libboost-dev library
*/
#include <boost/lockfree/spsc_queue.hpp>
#include <string>
#include <fstream>
#include <iostream>
#include "fifo.h"
using string = std::string;
struct Message {
string topic;
string payload;
Message(const string& t1, const string& t2) : topic(t1), payload(t2) {}
};
constexpr size_t queue_size = 10000;
boost::lockfree::spsc_queue<Message, boost::lockfree::capacity<queue_size>> mqttqueue;
void send_to_mqtt(const string& topic, const string& payload)
{
mqttqueue.push(Message(topic,payload));
}
bool read_from_readbatt(string& topic, string& payload)
{
Message message("", "");
bool ret = mqttqueue.pop(message);
if(ret) {
topic = message.topic;
payload = message.payload;
}
return ret;
}