solanaceae_ipc1/solanaceae/ipc1/tox_ipc_server.hpp

52 lines
858 B
C++
Raw Normal View History

2023-04-08 22:19:09 +02:00
#pragma once
//#include <solanaceae/core/tox_interface.hpp>
#include <ipc.h>
#include <atomic>
#include <mutex>
#include <thread>
#include <vector>
// fwd
struct ToxI;
struct Tox_Events;
class ToxIPCServer {
ipc_sharedmemory _mem_rpc;
ipc_sharedsemaphore _sem_rpc_c;
ipc_sharedsemaphore _sem_rpc_s;
ipc_sharedmemory _mem_events;
ipc_sharedsemaphore _sem_events_lock;
ToxI& _t;
std::mutex& _t_m;
std::atomic_bool _quit = false;
std::thread _thread;
std::vector<uint8_t> _tmp_events_buf;
void run(void);
public:
ToxIPCServer(ToxI& t, std::mutex& t_m);
~ToxIPCServer(void);
bool connect(void);
// starts a thread and serves
void start(void);
void stop(void);
// take events, serialize
void updateEvents(const Tox_Events* events);
// this might sleep for longer, and events might get discarded
void pub(void);
};