azkoyen_technical_test/include/UnixIpcBridge.hpp

32 lines
737 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// UnixIpcBridge.hpp
// SPDX-License-Identifier: GPL-3.0-or-later
// Author: Unai Blazquez <unaibg2000@gmail.com>
#pragma once
#include <fcntl.h> // nonblocking
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h> // close()
#include <string>
///@brief Small bridge to allow the producer class to send data over UNIX domain
/// sockets
class UnixIpcBridge
{
public:
///@brief constructor
///@param socket path pointing the socket
explicit UnixIpcBridge(const std::string& socket_path);
///@brief sending function, this goes into the producer
///@param integer to send over the socket
void send(int value);
private:
std::string m_socket_path;
int m_socket_fd = -1;
void connect_to_consumer();
};