15#ifndef ZYPP_CORE_ZYPPNG_RPC_MESSAGESTREAM_H_INCLUDED
16#define ZYPP_CORE_ZYPPNG_RPC_MESSAGESTREAM_H_INCLUDED
18#include <zypp-core/zyppng/base/Base>
19#include <zypp-core/zyppng/base/Signals>
20#include <zypp-core/zyppng/base/Timer>
21#include <zypp-core/zyppng/io/IODevice>
35 class RpcMessageStream;
56 virtual const std::string &
typeName()
const = 0;
79 const std::string &
value()
const;
95 static std::string name = T().GetTypeName();
102 if ( !target.deserialize( message.
value() ) ) {
104 ERR << msg << std::endl ;
110 template <
typename T>
120 template <
typename T>
124 env.set_messagetypename( data.typeName() );
125 env.set_value( data.serialize() );
153 using Ptr = std::shared_ptr<RpcMessageStream>;
169 std::optional<RpcMessage>
nextMessage (
const std::string &msgName =
"" );
179 std::optional<RpcMessage>
nextMessageWait (
const std::string &msgName =
"" );
197 template <
typename T>
220 if ( !target.ParseFromString( m.
value() ) ) {
222 ERR << msg << std::endl ;
251#define ZYPP_RPCBASE \
253 static const std::string &staticTypeName(); \
254 const std::string &typeName() const override; \
255 bool deserialize(const std::string &data) override; \
256 void serializeInto(std::string &str) const override; \
257 std::string serialize( ) const override; \
266#define ZYPP_IMPL_RPCBASE(Class, ImplClass, implVar) \
267 const std::string &Class::staticTypeName() \
269 return rpc::messageTypeName<ImplClass>(); \
272 const std::string &Class::typeName() const \
274 return staticTypeName(); \
277 bool Class::deserialize(const std::string &data) \
279 return implVar->ParseFromString( data ); \
282 void Class::serializeInto(std::string &str) const \
284 implVar->SerializeToString( &str ); \
287 std::string Class::serialize( ) const \
289 return implVar->SerializeAsString( ); \
Base class for Exception.
const std::string & msg() const
Return the message string provided to the ctor.
std::shared_ptr< IODevice > Ptr
InvalidMessageReceivedException(const std::string &msg={})
virtual std::string serialize() const
virtual bool deserialize(const std::string &data)=0
RpcBaseType & operator=(RpcBaseType &&)=default
virtual ~RpcBaseType()=default
virtual const std::string & typeName() const =0
RpcBaseType(RpcBaseType &&)=default
RpcBaseType(const RpcBaseType &)=default
virtual void serializeInto(std::string &str) const =0
RpcBaseType & operator=(const RpcBaseType &)=default
Signal< void()> _sigInvalidMessageReceived
SignalProxy< void()> sigMessageReceived()
Signal< void()> _sigNextMessage
Timer::Ptr _nextMessageTimer
std::shared_ptr< RpcMessageStream > Ptr
zyppng::rpc::HeaderSizeType _pendingMessageSize
std::optional< RpcMessage > nextMessage(const std::string &msgName="")
std::enable_if_t< !std::is_same_v< T, RpcMessage >, bool > sendMessage(const T &m)
static expected< void > parseMessageInto(const RpcMessage &m, T &target)
RpcMessageStream(IODevice::Ptr iostr)
static expected< T > parseMessage(const RpcMessage &m)
std::deque< RpcMessage > _messages
bool sendMessage(const RpcMessage &env)
SignalProxy< void()> sigInvalidMessageReceived()
static Ptr create(IODevice::Ptr iostr)
void timeout(const zyppng::Timer &)
std::optional< RpcMessage > nextMessageWait(const std::string &msgName="")
zypp::RWCOW_pointer< zypp::proto::Envelope > _data
void set_value(std::string name)
RpcMessage(const RpcMessage &)=default
void set_messagetypename(std::string name)
std::string serialize() const
RpcMessage(RpcMessage &&)=default
RpcMessage & operator=(const RpcMessage &)=default
RpcMessage & operator=(RpcMessage &&)=default
const std::string & value() const
const std::string & messagetypename() const
The Timer class provides repetitive and single-shot timers.
static std::shared_ptr< Timer > create()
Creates a new Timer object, the timer is not started at this point.
std::shared_ptr< Timer > Ptr
static expected success(ConsParams &&...params)
typename enable_if< B, T >::type enable_if_t
String related utilities and Regular expression matching.
Namespace intended to collect all environment variables we use.
Easy-to use interface to the ZYPP dependency resolver.
zypp::proto::Envelope * rwcowClone< zypp::proto::Envelope >(const zypp::proto::Envelope *rhs)
expected< void > deserializeMessageInto(const RpcMessage &message, T &target)
const std::string & messageTypeName()
expected< T > deserializeMessage(const RpcMessage &message)
RpcMessage serializeIntoMessage(const T &data)
RW_pointer supporting 'copy on write' functionality.
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.