diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2023-08-17 12:32:50 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2023-08-17 12:32:50 +0200 |
| commit | 375799fa79d1af76f33299acc20a11a167a021f8 (patch) | |
| tree | 8f91b982ec96225c33a2f4871730ababffe5cab0 /source/lib/proto/include/wanda | |
| parent | af471b9b780869915d3217b228e24d025892de47 (diff) | |
| download | wanda-375799fa79d1af76f33299acc20a11a167a021f8.tar.xz wanda-375799fa79d1af76f33299acc20a11a167a021f8.zip | |
project: restructure libraries and build env
Diffstat (limited to 'source/lib/proto/include/wanda')
| -rw-r--r-- | source/lib/proto/include/wanda/proto/command.hpp | 46 | ||||
| -rw-r--r-- | source/lib/proto/include/wanda/proto/message.hpp | 84 | ||||
| -rw-r--r-- | source/lib/proto/include/wanda/proto/version.hpp | 12 |
3 files changed, 142 insertions, 0 deletions
diff --git a/source/lib/proto/include/wanda/proto/command.hpp b/source/lib/proto/include/wanda/proto/command.hpp new file mode 100644 index 0000000..c8dae65 --- /dev/null +++ b/source/lib/proto/include/wanda/proto/command.hpp @@ -0,0 +1,46 @@ +#ifndef WANDA_PROTO_COMMAND_HPP +#define WANDA_PROTO_COMMAND_HPP + +#include "wanda/proto/message.hpp" + +#include <optional> +#include <string> +#include <vector> + +namespace wanda::proto +{ + /** + * @brief An enum to describe different command IDs + */ + enum struct command_id : char + { + change, //< Change the wallpaper + }; + + /** + * @brief A simple type to represent commands transported through the control connection + */ + struct command + { + command_id const id; + std::vector<std::string> const arguments; + + /** + * @brief Convert the command to a message for transmission to a remote endpoint + */ + std::optional<wanda::proto::message> message() const; + }; + + /** + * @brief Extract a command from a message + */ + std::optional<command> make_command(message message); + + /** + * @brief A simple factory to create a "Change wallpaper" command + */ + command make_change_command(); + +} // namespace wanda::proto + +#endif
\ No newline at end of file diff --git a/source/lib/proto/include/wanda/proto/message.hpp b/source/lib/proto/include/wanda/proto/message.hpp new file mode 100644 index 0000000..f4a6a3b --- /dev/null +++ b/source/lib/proto/include/wanda/proto/message.hpp @@ -0,0 +1,84 @@ +/** + * @file message.hpp + * @author Felix Morgner (felix.morgner@gmail.com) + * @since 1.0.0 + */ + +#ifndef WANDA_PROTO_MESSAGE_HPP +#define WANDA_PROTO_MESSAGE_HPP + +#include <fmt/core.h> + +#include <cstddef> +#include <istream> +#include <optional> +#include <string> +#include <string_view> + +namespace wanda::proto +{ + /** + * @brief A tag to mark messages originating from the controller + */ + auto constexpr message_source_controller = "C"; + + /** + * @brief A tag to mark messages originating from the daemon + */ + auto constexpr message_source_daemon = "D"; + + /** + * @brief The command of the hello message + */ + auto constexpr message_command_hello = "HELLO"; + + /** + * @brief A control protocol message, consisting of a @p source, @p command, and @p arguments + */ + struct message + { + /** + * @brief Serialize this message into a string + */ + explicit operator std::string() const; + + /** + * @brief Get the size of the message as if it was serialized + */ + std::size_t size() const; + + /** + * @brief The source of the message + */ + std::string source; + + /** + * @brief The command of the message + */ + std::string command; + + /** + * @brief The arguments of the message command + */ + std::optional<std::string> argument; + }; + + /** + * @brief Deserialize a message from the given stream + */ + std::istream & operator>>(std::istream & in, message & message); + + /** + * @brief Serialize a message to the given stream + */ + std::ostream & operator<<(std::ostream & out, message const & message); + +} // namespace wanda::proto + +template<> +struct fmt::formatter<wanda::proto::message> : fmt::formatter<std::string> +{ + auto format(wanda::proto::message const & message, format_context & context) const -> decltype(context.out()); +}; + +#endif
\ No newline at end of file diff --git a/source/lib/proto/include/wanda/proto/version.hpp b/source/lib/proto/include/wanda/proto/version.hpp new file mode 100644 index 0000000..faa17d7 --- /dev/null +++ b/source/lib/proto/include/wanda/proto/version.hpp @@ -0,0 +1,12 @@ +#ifndef WANDA_PROTO_VERSION_HPP +#define WANDA_PROTO_VERSION_HPP + +namespace wanda::proto +{ + inline namespace v1 + { + auto constexpr version = "1.0.0"; + } +} // namespace wanda::proto + +#endif
\ No newline at end of file |
