diff --git a/shared/libblight/clock.h b/shared/libblight/clock.h index 04a4b226f..959724423 100644 --- a/shared/libblight/clock.h +++ b/shared/libblight/clock.h @@ -1,15 +1,37 @@ +/*! + * \addtogroup Blight + * @{ + * \file + */ #pragma once #include "libblight_global.h" #include namespace Blight{ + /*! + * \brief The ClockWatch class + * + * A simple timer class for determening how long code takes. + */ class LIBBLIGHT_EXPORT ClockWatch { public: + /*! + * \brief Create a new instance and start the timer. + */ ClockWatch(); + /*! + * \brief Get the duration since the ClockWatch was created. + * \return Duration since the ClockWatch was created. + */ std::chrono::duration diff(); + /*! + * \brief Get the elapsed seconds since the ClockWatch was created. + * \return The elapsed seconds since the ClockWatch was created. + */ double elapsed(); private: std::chrono::high_resolution_clock::time_point t1; }; } +/*! @} */ diff --git a/shared/libblight/connection.cpp b/shared/libblight/connection.cpp index 89d763f77..dc6f9ecd5 100644 --- a/shared/libblight/connection.cpp +++ b/shared/libblight/connection.cpp @@ -25,7 +25,6 @@ namespace Blight{ data_t data ) : ackid(ackid), - connection(connection), done(false), data_size(data_size), data(data) diff --git a/shared/libblight/connection.h b/shared/libblight/connection.h index 8cf730159..5d92941b0 100644 --- a/shared/libblight/connection.h +++ b/shared/libblight/connection.h @@ -1,3 +1,8 @@ +/*! + * \addtogroup Blight + * @{ + * \file + */ #pragma once #include "libblight_global.h" #include "types.h" @@ -13,11 +18,22 @@ namespace Blight { class Connection; + /*! + * \brief Handle used for waiting for a response from the display server + */ typedef struct ackid_t{ + /*! + * \brief Identifier + */ unsigned int ackid; - Connection* connection; bool done; + /*! + * \brief Return data size + */ unsigned int data_size; + /*! + * \brief Return data + */ shared_data_t data; std::mutex mutex; std::condition_variable condition; @@ -28,23 +44,87 @@ namespace Blight { data_t data = nullptr ); ~ackid_t(); + /*! + * \brief Wait for the reply to return + * \param timeout Timeout + */ bool wait(int timeout = 0); void notify_all(); } ackid_t; + /*! + * \brief Shared pointer to ackid_t + */ typedef std::shared_ptr ackid_ptr_t; + /*! + * \brief Optional response of ackid_ptr_t + */ typedef std::optional maybe_ackid_ptr_t; + /*! + * \brief Display server connection + */ class LIBBLIGHT_EXPORT Connection { public: + /*! + * \brief Create a new connection instance + * \param fd Connection socket descriptor + */ Connection(int fd); ~Connection(); + /*! + * \brief Connection socket descriptor + * \return Connection socket descriptor + */ int handle(); + /*! + * \brief input_handle input event socket descriptor + * \return input event socket descriptor + */ int input_handle(); + /*! + * \brief Run a callback when the socket disconnects from the display server + * \param callback Callback to run. + */ void onDisconnect(std::function callback); + /*! + * \brief Read a message from the display server connection + * \return A message + */ message_ptr_t read(); + /*! + * \brief Read an input event from the display server input events socket + * \return Input event packet + */ std::optional read_event(); + /*! + * \brief Send a message to the display server + * \param type Type of message + * \param data Data to send + * \param size Size of data + * \return ack_ptr_t if the message was sent + */ maybe_ackid_ptr_t send(MessageType type, data_t data, size_t size, unsigned int __ackid = 0); + /*! + * \brief Ping the server + * \param timeout Timeout + * \return Duration of ping + */ std::optional> ping(int timeout = 0); + /*! + * \brief Wait for a marker to complete repainting on the display server + * \param marker Maker to wait on + */ void waitForMarker(unsigned int marker); + /*! + * \brief Repaint a portion of a surface + * \param identifier Surface identifier + * \param x X offset on the surface + * \param y Y offset on the surface + * \param width Width to repaint + * \param height Height to repaint + * \param waveform Waveform to use + * \param marker Marker + * \return ack_ptr_t if there was no error + */ maybe_ackid_ptr_t repaint( surface_id_t identifier, int x, @@ -54,6 +134,17 @@ namespace Blight { WaveformMode waveform = WaveformMode::HighQualityGrayscale, unsigned int marker = 0 ); + /*! + * \brief Repaint a portion of a surface + * \param buf Buffer representing surface + * \param x X offset on the surface + * \param y Y offset on the surface + * \param width Width to repaint + * \param height Height to repaint + * \param waveform Waveform to use + * \param marker Marker + * \return ack_ptr_t if there was no error + */ inline maybe_ackid_ptr_t repaint( shared_buf_t buf, int x, @@ -63,13 +154,42 @@ namespace Blight { WaveformMode waveform = WaveformMode::HighQualityGrayscale, unsigned int marker = 0 ){ return repaint(buf->surface, x, y, width, height, waveform, marker); } + /*! + * \brief Repaint a surface + * \param buf Buffer representing surface + * \param waveform Waveform to use + * \param marker Marker + * \return ack_ptr_t if there was no error + */ inline maybe_ackid_ptr_t repaint( shared_buf_t buf, WaveformMode waveform = WaveformMode::HighQualityGrayscale, unsigned int marker = 0 ){ return repaint(buf->surface, buf->x, buf->y, buf->width, buf->height, waveform, marker); } + /*! + * \brief Move a surface + * \param buf Buffer representing surface + * \param x X coordinate to move to + * \param y Y coordinate to move to + */ void move(shared_buf_t buf, int x, int y); + /*! + * \brief move + * \param identifier Surface identifier + * \param x X coordinate to move to + * \param y Y coordinate to move to + * \return ack_ptr_t if there was no error + */ maybe_ackid_ptr_t move(surface_id_t identifier, int x, int y); + /*! + * \brief Resize a surface + * \param buf Buffer representing surface + * \param width Width of new surface + * \param height Height of new surface + * \param stride Bytes per line in the buffer + * \param new_data New data to use for the buffer + * \return New shared_buf_t if there was no error + */ std::optional resize( shared_buf_t buf, int width, @@ -77,15 +197,61 @@ namespace Blight { int stride, data_t new_data ); + /*! + * \brief Raise a surface + * \param identifier Surface identifier + * \return ack_ptr_t if there was no error + */ maybe_ackid_ptr_t raise(surface_id_t identifier); + /*! + * \brief Raise a surface + * \param buf Buffer representing surface + * \return ack_ptr_t if there was no error + */ maybe_ackid_ptr_t raise(shared_buf_t buf); + /*! + * \brief Lower a surface + * \param identifier Surface identifier + * \return ack_ptr_t if there was no error + */ maybe_ackid_ptr_t lower(surface_id_t identifier); + /*! + * \brief Lower a surface + * \param buf Buffer representing surface + * \return ack_ptr_t if there was no error + */ maybe_ackid_ptr_t lower(shared_buf_t buf); + /*! + * \brief Get a buffer + * \param identifier Surface identifier + * \return ack_ptr_t if there was no error + */ std::optional getBuffer(surface_id_t identifier); + /*! + * \brief Get the list of buffers for the connection + * \return List of buffers for the connection + */ std::vector buffers(); + /*! + * \brief Remove a surface + * \param buf Buffer representing surface + * \return ack_ptr_t if there was no error + */ maybe_ackid_ptr_t remove(shared_buf_t buf); + /*! + * \brief Remove a surface + * \param identifier Surface identifier + * \return ack_ptr_t if there was no error + */ maybe_ackid_ptr_t remove(surface_id_t identifier); + /*! + * \brief Get the list of surfaces for the connection + * \return List of surfaces identifiers + */ std::vector surfaces(); + /*! + * \brief Make the current connection the focused connection, which recieves input events + */ void focused(); private: @@ -97,3 +263,4 @@ namespace Blight { static void run(Connection* connection); }; } +/*! @} */ diff --git a/shared/libblight/dbus.h b/shared/libblight/dbus.h index 1ca6f4953..567efd454 100644 --- a/shared/libblight/dbus.h +++ b/shared/libblight/dbus.h @@ -1,3 +1,8 @@ +/*! + * \addtogroup Blight + * @{ + * \file + */ #pragma once #include "libblight_global.h" @@ -6,17 +11,42 @@ #include namespace Blight { + /*! + * \brief The DBusReply class + */ class LIBBLIGHT_EXPORT DBusReply{ public: DBusReply(); ~DBusReply(); + /*! + * \brief Message descriptor + */ sd_bus_message* message = nullptr; + /*! + * \brief Error descriptor + */ sd_bus_error error; + /*! + * \brief Return value of the last operation + */ int return_value; + /*! + * \brief Error message as a string + * \return + */ std::string error_message(); + /*! + * \brief If this reply is an error + * \return + */ bool isError(); + /*! + * \brief Read a value from the reply message + * \param argument_type Type of data to read from the reply message + * \return + */ template std::optional read_value(const char* argument_type){ T argument; @@ -28,20 +58,58 @@ namespace Blight { return argument; } }; - + /*! + * \brief Shared pointer of a DBusReply + */ LIBBLIGHT_EXPORT typedef std::shared_ptr dbus_reply_t; - + /*! + * \brief An exception raised by DBus + * \sa Blight::DBus::DBus(bool) + */ class LIBBLIGHT_EXPORT DBusException : public std::runtime_error{ public: DBusException(const std::string& message); }; + /*! + * \brief A helper class for dealing with sd-bus + */ class LIBBLIGHT_EXPORT DBus { public: + /*! + * \brief Create a new DBus connection + * \param use_system Use the system bus instead of the session bus + * \exception Blight::DBusException Failed to connect to the bus + */ DBus(bool use_system = false); ~DBus(); + /*! + * \brief underlying sd_bus object + * \return The sd_bus object used by sd-bus + */ sd_bus* bus(); + /*! + * \brief All the known services on the bus + * \return All the known services on the bus + * \sa has_service(std::string) + */ std::vector services(); + /*! + * \brief Check if a service is available on the bus. + * \param service Service name. + * \return If the service is available. + * \sa services() + */ bool has_service(std::string service); + /*! + * \brief Call a DBus method + * \param service Service name + * \param path Path + * \param interface Interface name + * \param member Method name + * \param argument_types Argument types + * \param args Arguments + * \return DBusReply + */ template dbus_reply_t call_method( const std::string& service, @@ -72,14 +140,29 @@ namespace Blight { } return res; } - + /*! + * \brief Call a DBus method + * \param service Service name + * \param path Path + * \param interface Interface name + * \param member Method name + * \return DBusReply + */ inline dbus_reply_t call_method( const std::string& service, const std::string& path, const std::string& interface, const std::string& member ){ return call_method(service, path, interface, member, ""); } - + /*! + * \brief Get a property from DBus + * \param service Service name + * \param path Path + * \param interface Interface name + * \param member Property name + * \param property_type Property type + * \return DBusReply + */ dbus_reply_t get_property( const std::string& service, const std::string& path, @@ -92,3 +175,4 @@ namespace Blight { sd_bus* m_bus; }; } +/*! @} */ diff --git a/shared/libblight/debug.h b/shared/libblight/debug.h index 17bd5ae5e..ebb9caa0b 100644 --- a/shared/libblight/debug.h +++ b/shared/libblight/debug.h @@ -1,3 +1,8 @@ +/*! + * \addtogroup Blight + * @{ + * \file + */ #pragma once #include @@ -8,9 +13,18 @@ #include static std::mutex __log_mutex; +/*! + * \brief BLIGHT_DEBUG_LOGGING + * + * Used to filter debug messages based on the priority. + */ static int BLIGHT_DEBUG_LOGGING = 4; void __printf_header(int priority); void __printf_footer(char const* file, unsigned int line, char const* func); + +/*! + * \brief Log a message to stderr + */ #define _PRINTF(priority, ...) \ if(priority <= BLIGHT_DEBUG_LOGGING){ \ __log_mutex.lock(); \ @@ -19,8 +33,25 @@ void __printf_footer(char const* file, unsigned int line, char const* func); __printf_footer(__FILE__, __LINE__, __PRETTY_FUNCTION__); \ __log_mutex.unlock(); \ } + +/*! + * \brief Log a debug statement to stderrr + */ #define _DEBUG(...) _PRINTF(LOG_DEBUG, __VA_ARGS__) +/*! + * \brief Log a warning statement to stderrr + */ #define _WARN(...) _PRINTF(LOG_WARNING, __VA_ARGS__) +/*! + * \brief Log an informational statement to stderrr + */ #define _INFO(...) _PRINTF(LOG_INFO, __VA_ARGS__) +/*! + * \brief Log a critical exception statement to stderrr + */ #define _CRIT(...) _PRINTF(LOG_CRIT, __VA_ARGS__) +/*! + * \brief Log a debug line indicating that a certain line of code has been reached + */ #define __RIGHT_HERE__ fprintf(stderr, "<============================ %s:%d\n", __FILE__, __LINE__) +/*! @} */ diff --git a/shared/libblight/libblight.h b/shared/libblight/libblight.h index d1484a04d..3f1fe41d9 100644 --- a/shared/libblight/libblight.h +++ b/shared/libblight/libblight.h @@ -1,19 +1,92 @@ +/*! + * \addtogroup Blight + * \brief The Blight module + * @{ + * \file + */ #include "libblight_global.h" #include "types.h" #include "connection.h" #include namespace Blight{ + /*! + * \brief Connect to DBus + * \param use_system Use the system bus instead of the session bus. + * \return If the connection was successful. + * \retval true Connected successfully. + * \retval false An error occurred. + */ LIBBLIGHT_EXPORT bool connect(bool use_system = true); + /*! + * \brief If the display server service can be found over DBus + * \return If the display server service can be found over DBus + * \retval true The service exists. + * \retval false The service does not exist, or an error occurred. + */ LIBBLIGHT_EXPORT bool exists(); + /*! + * \brief Get or create the Connection instance to the display server. + * \return The connection instance is returned. + * \retval nullptr an error occurred + */ LIBBLIGHT_EXPORT Connection* connection(); + /*! + * \brief Open a connection to the display server + * \return File descriptor for socket to communicate with the display server. + * \retval -EAGAIN Failed to connect to DBus, or the display server service does not exist. + * \sa Blight::Connection::Connection(int) + * \sa Blight::Connection::handle() + */ LIBBLIGHT_EXPORT int open(); + /*! + * \brief Open a connection to the display server to recieve input events. + * \return File descriptor for socket that the display server will use to send input events + * \sa Blight::Connection::input_handle() + * \sa Blight::Connection::read_event() + */ LIBBLIGHT_EXPORT int open_input(); + /*! + * \brief Get the clipboard + * \return Clipboard instance + */ LIBBLIGHT_EXPORT std::optional clipboard(); + /*! + * \brief Get the current selection + * \return Current selection instance + */ LIBBLIGHT_EXPORT std::optional selection(); + /*! + * \brief Get the secondary selection + * \return Secondary selection instance + */ LIBBLIGHT_EXPORT std::optional secondary(); + /*! + * \brief Set a clipboard to a new value + * \param clipboard Clipboard instance to set + * \return If the clipboard was set + * \retval true The clipboard was set + * \retval false There was an error setting the clipboard + */ LIBBLIGHT_EXPORT bool setClipboard(clipboard_t& clipboard); + /*! + * \brief Update a clipboard with the current data + * \param clipboard Clipboard instance to update + * \return If the clipboard was updated + * \retval true The clipboard was updated + * \retval false There was an error updating the clipboard + */ LIBBLIGHT_EXPORT bool updateClipboard(clipboard_t& clipboard); + /*! + * \brief createBuffer + * \param x X coordinate of the buffer + * \param y Y coordinate of the buffer + * \param width Width of the buffer + * \param height Height of the buffer + * \param stride Bytes per line in the buffer + * \param format Format of the buffer + * \return The new buffer + */ LIBBLIGHT_EXPORT std::optional createBuffer( int x, int y, @@ -22,6 +95,17 @@ namespace Blight{ int stride, Format format ); + /*! + * \brief Add a new surface to the display server + * \param fd File descriptor that points to the buffer data for the surface + * \param x X coordinate of the surface + * \param y Y coordinate of the surface + * \param width Width of the surface + * \param height Height of the surface + * \param stride Bytes per line in the buffer for the surface + * \param format Format of the buffer for the surface + * \return Identifier for the surface + */ LIBBLIGHT_EXPORT std::optional addSurface( int fd, int x, @@ -31,6 +115,10 @@ namespace Blight{ int stride, Format format ); + /*! + * \brief Add a new surface to the display server + * \param buf Buffer to use for the surface + */ LIBBLIGHT_EXPORT inline void addSurface(shared_buf_t buf){ buf->surface = addSurface( buf->fd, @@ -42,6 +130,17 @@ namespace Blight{ buf->format ).value_or(0); } + /*! + * \brief Repaint a surface, or all surfaces for a connection + * \param identifier Identifier of the surface or connection. + * \return Negative number if there was an error + */ LIBBLIGHT_EXPORT int repaint(const std::string& identifier); + /*! + * \brief Get the file descriptor of the buffer for a surface + * \param identifier Surface idnetifier + * \return Negative number if there was an error. Otherwise the file descriptor of the buffer for the surface + */ LIBBLIGHT_EXPORT int getSurface(surface_id_t identifier); } +/*! @} */ diff --git a/shared/libblight/libblight_global.h b/shared/libblight/libblight_global.h index 22528ef58..7f06c2f04 100644 --- a/shared/libblight/libblight_global.h +++ b/shared/libblight/libblight_global.h @@ -1,8 +1,3 @@ -/*! - * \addtogroup Blight - * @{ - * \file - */ #pragma once #ifndef DOXYGEN_SHOULD_SKIP_THIS @@ -20,4 +15,3 @@ #else # define ATTRIBUTE_NO_SANITIZE_ADDRESS #endif -/*! @} */ diff --git a/shared/libblight/meta.h b/shared/libblight/meta.h index 678d0ca5f..cf43c463d 100644 --- a/shared/libblight/meta.h +++ b/shared/libblight/meta.h @@ -1,6 +1,16 @@ +/*! + * \addtogroup Blight + * @{ + * \file + */ #pragma once +/*! + * \brief Name of the DBus service that the display server is available at. + */ #define BLIGHT_SERVICE "codes.eeems.blight1" +/*! + * \brief Name of the DBus interface that the display server is available at. + */ #define BLIGHT_INTERFACE BLIGHT_SERVICE ".Compositor" -#define BLIGHT_SURFACE_INTERFACE BLIGHT_SERVICE ".Surface" -#define BLIGHT_MAX_IDENTIFIER_LENGTH 255 +/*! @} */ diff --git a/shared/libblight/socket.h b/shared/libblight/socket.h index 08a8737b7..d85aeb657 100644 --- a/shared/libblight/socket.h +++ b/shared/libblight/socket.h @@ -1,25 +1,63 @@ +/*! + * \addtogroup Blight + * @{ + * \file + */ #pragma once #include "libblight_global.h" #include "types.h" - namespace Blight{ + /*! + * \brief Non-blocking recieve data from a socket. + * \param fd The socket. + * \param size Size of the data to recieve. + * \param attempts Number of attempts to recieve data. + * \param timeout Timeout to wait for data per attempt. + * \return The data if it was recieved. + */ LIBBLIGHT_EXPORT std::optional recv( int fd, ssize_t size, unsigned int attempts = 5, unsigned int timeout = 50 ); + /*! + * \brief Recieve data from a socket + * \param fd The socket. + * \param size Size of the data to recieve + * \return The data if it was recieved without error. + */ LIBBLIGHT_EXPORT std::optional recv_blocking( int fd, ssize_t size ); + /*! + * \brief Send data to a socket. + * \param fd The socket + * \param data The data to send. + * \param size The size of the data to send. + * \return If the data was sent without error. + */ LIBBLIGHT_EXPORT bool send_blocking( int fd, const data_t data, ssize_t size ); + /*! + * \brief Wait until a socket is ready to send data. + * \param fd The socket + * \param timeout Timeout + * \return If the socket is ready to send data. + */ LIBBLIGHT_EXPORT bool wait_for_send(int fd, int timeout = -1); + /*! + * \brief Wait until a socket is ready for us to recieve data. + * \param fd The socket + * \param timeout Timeout + * \return If the socket is ready for us to recieve data. + */ LIBBLIGHT_EXPORT bool wait_for_read(int fd, int timeout = -1); } +/*! @} */ diff --git a/shared/libblight/types.h b/shared/libblight/types.h index 08573f2c5..c542984f3 100644 --- a/shared/libblight/types.h +++ b/shared/libblight/types.h @@ -1,3 +1,8 @@ +/*! + * \addtogroup Blight + * @{ + * \file + */ #pragma once #include "libblight_global.h" #include @@ -7,6 +12,9 @@ #include namespace Blight{ + /*! + * \brief Image format of a buffer + */ enum Format{ Format_Invalid, Format_Mono, @@ -39,6 +47,9 @@ namespace Blight{ Format_Grayscale16, Format_BGR888, }; + /*! + * \brief Possible waveforms + */ enum Waveform { INIT = 0, DU = 1, @@ -51,6 +62,9 @@ namespace Blight{ UNKNOWN = 8, INIT2 = 9 }; + /*! + * \brief Waveform to use for a repaint + */ enum WaveformMode{ Initialize = Waveform::INIT, Mono = Waveform::DU, @@ -58,55 +72,199 @@ namespace Blight{ HighQualityGrayscale = Waveform::GC16, Highlight = Waveform::UNKNOWN }; + /*! + * \brief Size type + */ LIBBLIGHT_EXPORT typedef unsigned int size_t; + /*! + * \brief Surface identifier + */ LIBBLIGHT_EXPORT typedef unsigned short surface_id_t; + /*! + * \brief Partial input event + */ LIBBLIGHT_EXPORT typedef struct{ + /*! + * \brief Input event type + */ __u16 type; + /*! + * \brief Input event code + */ __u16 code; + /*! + * \brief Input event value + */ __s32 value; } partial_input_event_t; + /*! + * \brief Input event packet + */ LIBBLIGHT_EXPORT typedef struct { + /*! + * \brief Device that this packet is for + */ unsigned int device; + /*! + * \brief Partial input event + */ partial_input_event_t event; } event_packet_t; + /*! + * \brief Generic data pointer + */ LIBBLIGHT_EXPORT typedef unsigned char* data_t; + /*! + * \brief Shared pointer to generic data + */ LIBBLIGHT_EXPORT typedef std::shared_ptr shared_data_t; struct buf_t; + /*! + * \brief Shared pointer to buffer + */ LIBBLIGHT_EXPORT typedef std::shared_ptr shared_buf_t; + /*! + * \brief Clipboard instance + */ LIBBLIGHT_EXPORT typedef struct clipboard_t { + /*! + * \brief Data + */ shared_data_t data; + /*! + * \brief Size of data + */ size_t size; + /*! + * \brief Name of clipboard + */ std::string name; + /*! + * \brief Create a new clipboard instance + * \param name Name of clipboard + * \param data Data + * \param size Data size + */ clipboard_t(const std::string name, data_t data = nullptr, size_t size = 0); + /*! + * \brief Convert the data to a string + * \return The clipboard data as a string + */ const std::string to_string(); + /*! + * \brief Get the latest data for the clipboard + * \return If the clipboard was able to update + * \retval true The clipboard was updated + * \retval false An error occurred + */ bool update(); + /*! + * \brief Set the data for the clipboard + * \param data Data + * \param size Size of data + * \return If the clipboard was able to be set + * \retval true The clipboard data was set + * \retval false An error occurred + */ bool set(shared_data_t data, size_t size); + /*! + * \brief Set the data for the clipboard + * \param data Data + * \param size Size of data + * \return If the clipboard was able to be set + * \retval true The clipboard data was set + * \retval false An error occurred + */ inline bool set(const char* data, size_t size){ auto buf = new unsigned char[size]; memcpy(buf, data, size); return set(shared_data_t(buf), size); } + /*! + * \brief Set the data for the clipboard + * \param data Data + * \param size Size of data + * \return If the clipboard was able to be set + * \retval true The clipboard data was set + * \retval false An error occurred + */ inline bool set(const data_t data, size_t size){ return set((char*)data, size); } + /*! + * \brief Set the data for the clipboard to a string + * \param data String to set the data to + * \return If the clipboard was able to be set + * \retval true The clipboard data was set + * \retval false An error occurred + */ inline bool set(const std::string& data){ return set(data.data(), data.size()); } } clipboard_t; + /*! + * \brief A buffer used to represent a surface + */ LIBBLIGHT_EXPORT typedef struct buf_t{ + /*! + * \brief File descriptor for the buffer + */ int fd; + /*! + * \brief X coordinate of the buffer + */ int x; + /*! + * \brief Y coordinate of the buffer + */ int y; + /*! + * \brief Width of the buffer + */ int width; + /*! + * \brief Height of the buffer + */ int height; + /*! + * \brief Bytes per line in the buffer + */ int stride; + /*! + * \brief Image format of the buffer + */ Format format; + /*! + * \brief Memory mapped data of the buffer + */ data_t data; + /*! + * \brief UUID of the buffer + */ std::string uuid; + /*! + * \brief Surface identifier + */ surface_id_t surface; + /*! + * \brief Size of the buffer + * \return + */ size_t size(); + /*! + * \brief Close the buffer + * \return Negative number if there was an error + * \retval 0 No error while closing the buffer + */ int close(); ~buf_t(); + /*! + * \brief Clone a buffer + * \return Cloned buffer if there was no error + */ std::optional clone(); static shared_buf_t new_ptr(); static std::string new_uuid(); } buf_t; + /*! + * \brief Message type + */ enum MessageType{ Invalid, Ack, @@ -120,51 +278,203 @@ namespace Blight{ Lower, Wait }; + /*! + * \brief Message header + */ LIBBLIGHT_EXPORT typedef struct header_t{ + /*! + * \brief Message type + */ MessageType type; + /*! + * \brief Unique identifier for this message + */ unsigned int ackid; + /*! + * \brief Size of data + */ unsigned long size; + /*! + * \brief Get a header from data + * \param data Data + * \return Header + */ static header_t from_data(data_t data); + /*! + * \brief Get a header from data + * \param data Data + * \return Header + */ static header_t from_data(char* data); + /*! + * \brief Get a header from data + * \param data Data + * \return header + */ static header_t from_data(void* data); + /*! + * \brief Create a new invalid header + * \return Invalid header object + */ static header_t new_invalid(); } header_t; struct message_t; + /*! + * \brief Shared pointer to a message + */ LIBBLIGHT_EXPORT typedef std::shared_ptr message_ptr_t; + /*! + * \brief Message object + */ LIBBLIGHT_EXPORT typedef struct message_t{ + /*! + * \brief Message header + */ header_t header; + /*! + * \brief Message data + */ shared_data_t data; + /*! + * \brief Get a message from data + * \param _data Data + * \return + */ static message_t from_data(data_t _data); + /*! + * \brief Get a message from data + * \param data Data + * \return + */ static message_t from_data(char* data); + /*! + * \brief Get a message from data + * \param data Data + * \return + */ static message_t from_data(void* data); + /*! + * \brief Create an Ack header from a message + * \param message Message to create ack from + * \param size Size of response data + * \return Ack header + */ static header_t create_ack(message_t* message, size_t size = 0); + /*! + * \brief Create an Ack header from a message + * \param message Message to create ack from + * \param size Size of response data + * \return Ack header + */ static header_t create_ack(const message_t& message, size_t size = 0); + /*! + * \brief Read a message from a socket + * \param fd Socket descriptor + * \return Message + */ static message_ptr_t from_socket(int fd); + /*! + * \brief Create a new invalid and empty message + * \return Invalid and empty message + */ static message_ptr_t new_ptr(); } message_t; + /*! + * \brief Repaint message data + */ LIBBLIGHT_EXPORT typedef struct repaint_t{ + /*! + * \brief x X offset + */ int x; + /*! + * \brief y Y offset + */ int y; + /*! + * \brief width Width + */ int width; + /*! + * \brief height Height + */ int height; + /*! + * \brief waveform Waveform to use + */ WaveformMode waveform; + /*! + * \brief marker Marker to use + */ unsigned int marker; + /*! + * \brief identifier Surface identifier + */ surface_id_t identifier; + /*! + * \brief Get the repaint message data from a message + * \param message Message + * \return Repaint message data + */ static repaint_t from_message(const message_t* message); } repaint_t; + /*! + * \brief Move message data + */ LIBBLIGHT_EXPORT typedef struct move_t{ + /*! + * \brief identifier Surface identifier + */ surface_id_t identifier; + /*! + * \brief x X coordinate + */ int x; + /*! + * \brief y Y coordinate + */ int y; + /*! + * \brief Get the move message data from a message + * \param message Message + * \return Move message data + */ static move_t from_message(const message_t* message); } move_t; + /*! + * \brief Surface information message data + */ LIBBLIGHT_EXPORT typedef struct surface_info_t{ + /*! + * \brief x X coordinate + */ int x; + /*! + * \brief y Y coordiante + */ int y; + /*! + * \brief width Width + */ int width; + /*! + * \brief height Height + */ int height; + /*! + * \brief stride Bytes per line + */ int stride; + /*! + * \brief format Image format + */ Format format; + /*! + * \brief Get the surface information message data from data + * \param data Data + * \return Surface message data + */ static surface_info_t from_data(data_t data); } surface_info_t; } +/*! @} */