/* * Shared State CLI * * Copyright (C) 2024 Gioacchino Mazzurco * Copyright (C) 2024 AsociaciĆ³n Civil Altermundi * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Affero General Public License as published by the * Free Software Foundation, version 3. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. * See the GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see * * SPDX-License-Identifier: AGPL-3.0-only */ #pragma once #include "sharedstate.hh" #include "io_context.hh" struct SharedStateCli: SharedState { explicit SharedStateCli(IOContext& ioContext) : SharedState(ioContext) { loadRegisteredTypes(); } /** Similar meaning as [[noreturn]] but only for reader benefit, used as in * co-routines that exit the process on finish. * example: std::task doSomethingThenExit(); */ typedef void NoReturn; /** Discover potencial peers and print their addresses to standard output * then exit */ std::task discover(); /** Dump type full shared-state including, TTL, authors etc.to standard * output. Useful to save * current state to a persistent storage or for ispection. */ std::task dump(const std::string& typeName); /** Get clean data out of current shared-state */ std::task get(const std::string& typeName); /** @brief Insert data entries into shared-state * Removal on request is not possible, entries will fade away by bleaching * depending on type TTL, still it is possible to insert a null value which * can be considered as a remove equivalent for most types */ std::task insert(const std::string& typeName); std::task peer(); std::task registerDataType( const std::string& typeName, const std::string& typeSope, std::chrono::seconds updateInterval, std::chrono::seconds TTL ); /** * @param peerAddresses address to sync with, if empty an attempt to * discover peers is done internally */ std::task sync( const std::string& typeName, const std::vector& peerAddresses ); protected: std::task acceptReqSyncConnectionsLoop(ListeningSocket& listener); };