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;
57 virtual bool deserialize(
const std::string &data ) = 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>
215 return rpc::deserializeMessage<T>(m);
220 if ( !target.ParseFromString( m.
value() ) ) {
222 ERR << msg << std::endl ;
244 template<> zypp::proto::Envelope* rwcowClone<zypp::proto::Envelope>(
const zypp::proto::Envelope * rhs );
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( ); \ 294 #endif // ZYPP_CORE_ZYPPNG_RPC_MESSAGESTREAM_H_INCLUDED
virtual const std::string & typeName() const =0
std::deque< RpcMessage > _messages
Signal< void()> _sigInvalidMessageReceived
Namespace intended to collect all environment variables we use.
zyppng::rpc::HeaderSizeType _pendingMessageSize
static Ptr create(IODevice::Ptr iostr)
zypp::RWCOW_pointer< zypp::proto::Envelope > _data
RpcMessage serializeIntoMessage(const T &data)
virtual ~RpcBaseType()=default
RpcMessage & operator=(const RpcMessage &)=default
std::string serialize() const
String related utilities and Regular expression matching.
SignalProxy< void()> sigInvalidMessageReceived()
virtual void serializeInto(std::string &str) const =0
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
SignalProxy< void()> sigMessageReceived()
bool sendMessage(const RpcMessage &env)
static expected< void > parseMessageInto(const RpcMessage &m, T &target)
typename enable_if< B, T >::type enable_if_t
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
void set_value(std::string name)
void set_messagetypename(std::string name)
std::optional< RpcMessage > nextMessageWait(const std::string &msgName="")
const std::string & messageTypeName()
The Timer class provides repetitive and single-shot timers.
const std::string & messagetypename() const
virtual bool deserialize(const std::string &data)=0
std::shared_ptr< IODevice > Ptr
static expected< T > parseMessage(const RpcMessage &m)
static expected success(ConsParams &&...params)
std::shared_ptr< Timer > Ptr
static std::shared_ptr< Timer > create()
Creates a new Timer object, the timer is not started at this point.
Timer::Ptr _nextMessageTimer
const std::string & value() const
Base class for Exception.
std::optional< RpcMessage > nextMessage(const std::string &msgName="")
expected< void > deserializeMessageInto(const RpcMessage &message, T &target)
RpcMessageStream(IODevice::Ptr iostr)
RpcBaseType & operator=(const RpcBaseType &)=default
std::enable_if_t< !std::is_same_v< T, RpcMessage >, bool > sendMessage(const T &m)
void timeout(const zyppng::Timer &)
Signal< void()> _sigNextMessage
InvalidMessageReceivedException(const std::string &msg={})
Easy-to use interface to the ZYPP dependency resolver.
expected< T > deserializeMessage(const RpcMessage &message)
virtual std::string serialize() const
std::shared_ptr< Base > Ptr
std::shared_ptr< RpcMessageStream > Ptr
const std::string & msg() const
Return the message string provided to the ctor.