// Copyright (c) 2023 - present, Anton Anikin // All rights reserved. #pragma once #include #if defined(_WIN32) #include #endif namespace ipc { void init(); void init(const std::string& name, unsigned int mode); void start_external(const std::string& executable, bool is_server); void start_external(const std::string& executable, const std::string& ipc_name, bool is_server); class Ipc { public: Ipc(bool is_server, int verbose = 0); Ipc(const std::string& name, bool is_server, int verbose = 0); ~Ipc(); void write(const char* str); template void write(const T& data) { write(&data, 1, sizeof(T)); } template void write(const T* data, size_t count) { write(data, count, sizeof(T)); } void write(const void* buffer, size_t count, size_t size); void read(char* str); template void read(T& data) { read(&data, 1, sizeof(T)); } template void read(T* data, size_t count) { read(data, count, sizeof(T)); } void read(void* buffer, size_t count, size_t size); protected: ssize_t _write(const void* buffer, size_t bytes); ssize_t _read(void* buffer, size_t bytes); protected: int m_verbose; std::string m_message; #if defined(_WIN32) HANDLE m_pipe; #else int m_writer_fd; int m_reader_fd; #endif }; }