libzypp 17.34.0
zyppng::RpcMessageStream Class Reference

#include <zypp-core/zyppng/rpc/messagestream.h>

Inheritance diagram for zyppng::RpcMessageStream:

Public Types

using Ptr = std::shared_ptr<RpcMessageStream>
 
- Public Types inherited from zyppng::Base
using Ptr = std::shared_ptr<Base>
 
using WeakPtr = std::weak_ptr<Base>
 

Public Member Functions

std::optional< RpcMessagenextMessage (const std::string &msgName="")
 
std::optional< RpcMessagenextMessageWait (const std::string &msgName="")
 
bool sendMessage (const RpcMessage &env)
 
void readAllMessages ()
 
template<typename T >
std::enable_if_t< !std::is_same_v< T, RpcMessage >, boolsendMessage (const T &m)
 
SignalProxy< void()> sigMessageReceived ()
 
SignalProxy< void()> sigInvalidMessageReceived ()
 
- Public Member Functions inherited from zyppng::Base
 Base ()
 
virtual ~Base ()
 
WeakPtr parent () const
 
void addChild (const Base::Ptr &child)
 
void removeChild (const Ptr &child)
 
const std::unordered_set< Ptr > & children () const
 
std::thread::id threadId () const
 
template<typename T >
std::vector< std::weak_ptr< T > > findChildren () const
 
template<typename T >
std::shared_ptr< T > shared_this () const
 
template<typename T >
std::shared_ptr< T > shared_this ()
 
template<typename T >
std::weak_ptr< T > weak_this () const
 
template<typename T >
std::weak_ptr< T > weak_this ()
 
template<typename SenderFunc , typename ReceiverFunc >
auto connect (SenderFunc &&sFun, typename internal::MemberFunction< ReceiverFunc >::ClassType &recv, ReceiverFunc &&rFunc)
 
template<typename SenderFunc , typename ReceiverFunc , typename ... Tracker>
std::enable_if_t< std::is_member_function_pointer_v< SenderFunc >, connectionconnectFunc (SenderFunc &&sFun, ReceiverFunc &&rFunc, const Tracker &...trackers)
 

Static Public Member Functions

static Ptr create (IODevice::Ptr iostr)
 
template<class T >
static expected< T > parseMessage (const RpcMessage &m)
 
template<class T >
static expected< voidparseMessageInto (const RpcMessage &m, T &target)
 
- Static Public Member Functions inherited from zyppng::Base
template<typename Obj , typename Functor >
static decltype(automake_base_slot (Obj *o, Functor &&f)
 
template<typename SenderFunc , typename ReceiverFunc >
static auto connect (typename internal::MemberFunction< SenderFunc >::ClassType &s, SenderFunc &&sFun, typename internal::MemberFunction< ReceiverFunc >::ClassType &recv, ReceiverFunc &&rFunc)
 
template<typename SenderFunc , typename ReceiverFunc , typename ... Tracker>
static auto connectFunc (typename internal::MemberFunction< SenderFunc >::ClassType &s, SenderFunc &&sFun, ReceiverFunc &&rFunc, const Tracker &...trackers)
 

Private Member Functions

 RpcMessageStream (IODevice::Ptr iostr)
 
bool readNextMessage ()
 
void timeout (const zyppng::Timer &)
 

Private Attributes

IODevice::Ptr _ioDev
 
Timer::Ptr _nextMessageTimer = Timer::create()
 
zyppng::rpc::HeaderSizeType _pendingMessageSize = 0
 
std::deque< RpcMessage_messages
 
Signal< void()> _sigNextMessage
 
Signal< void()> _sigInvalidMessageReceived
 

Additional Inherited Members

- Protected Member Functions inherited from zyppng::Base
 Base (BasePrivate &dd)
 
- Protected Attributes inherited from zyppng::Base
std::unique_ptr< BasePrivated_ptr
 

Detailed Description

Implements the basic protocol for sending zypp RPC messages over a IODevice

Communication Format:

Each message is serialized into a zypp.proto.Envelope and sent over the communication medium in binary format. The binary format looks like:

+-----------------------------—+------------------------------—+ | msglen ( 32 bit unsigned int ) | binary zypp.proto.Envelope data | +-----------------------------—+------------------------------—+

The header defines the size in bytes of the following data trailer. The header type is a 32 bit uint, endianess is defined by the underlying CPU arch. The data portion is directly generated by libprotobuf via SerializeToZeroCopyStream() to generate the binary representation of the message.

Definition at line 149 of file messagestream.h.

Member Typedef Documentation

◆ Ptr

Definition at line 153 of file messagestream.h.

Constructor & Destructor Documentation

◆ RpcMessageStream()

zyppng::RpcMessageStream::RpcMessageStream ( IODevice::Ptr iostr)
private

Definition at line 64 of file messagestream.cc.

Member Function Documentation

◆ create()

static Ptr zyppng::RpcMessageStream::create ( IODevice::Ptr iostr)
inlinestatic

Uses the given iostream to send and receive messages. If the device is already open and readable tries to read messages right away. So make sure to check if messages have already been received via nextMessage

Definition at line 160 of file messagestream.h.

◆ nextMessage()

std::optional< RpcMessage > zyppng::RpcMessageStream::nextMessage ( const std::string & msgName = "")

Returns the next message in the queue, wait for the sigMessageReceived signal to know when new messages have arrived. If msgName is specified returns the next message in the queue that matches the msgName

Definition at line 116 of file messagestream.cc.

◆ nextMessageWait()

std::optional< RpcMessage > zyppng::RpcMessageStream::nextMessageWait ( const std::string & msgName = "")

Waits until at least one message is in the queue and returns it. Will return a empty optional if a error occurs.

If msgName is set this will block until a message with the given message name arrives and returns it

Note
Make sure to check if there are more than one messages in the queue after this function returns

Definition at line 158 of file messagestream.cc.

◆ sendMessage() [1/2]

bool zyppng::RpcMessageStream::sendMessage ( const RpcMessage & env)

Send out a RpcMessage to the other side, depending on the underlying device state this will be buffered and send when the device is writeable again.

Definition at line 191 of file messagestream.cc.

◆ readAllMessages()

void zyppng::RpcMessageStream::readAllMessages ( )

Reads all messages from the underlying IO Device, this is usually called automatically but when shutting down this can be used to process all remaining messages.

Definition at line 213 of file messagestream.cc.

◆ sendMessage() [2/2]

template<typename T >
std::enable_if_t< !std::is_same_v< T, RpcMessage >, bool > zyppng::RpcMessageStream::sendMessage ( const T & m)
inline

Send a messagee to the server side, it will be enclosed in a Envelope and immediately sent out.

Definition at line 198 of file messagestream.h.

◆ sigMessageReceived()

SignalProxy< void()> zyppng::RpcMessageStream::sigMessageReceived ( )

Emitted when new messages have arrived. This will continuously be emitted as long as messages are in the queue.

Definition at line 203 of file messagestream.cc.

◆ sigInvalidMessageReceived()

SignalProxy< void()> zyppng::RpcMessageStream::sigInvalidMessageReceived ( )

Signal is emitted every time there was data on the line that could not be parsed

Definition at line 208 of file messagestream.cc.

◆ parseMessage()

template<class T >
static expected< T > zyppng::RpcMessageStream::parseMessage ( const RpcMessage & m)
inlinestatic

Definition at line 214 of file messagestream.h.

◆ parseMessageInto()

template<class T >
static expected< void > zyppng::RpcMessageStream::parseMessageInto ( const RpcMessage & m,
T & target )
inlinestatic

Definition at line 219 of file messagestream.h.

◆ readNextMessage()

bool zyppng::RpcMessageStream::readNextMessage ( )
private

Definition at line 74 of file messagestream.cc.

◆ timeout()

void zyppng::RpcMessageStream::timeout ( const zyppng::Timer & )
private

Definition at line 107 of file messagestream.cc.

Member Data Documentation

◆ _ioDev

IODevice::Ptr zyppng::RpcMessageStream::_ioDev
private

Definition at line 233 of file messagestream.h.

◆ _nextMessageTimer

Timer::Ptr zyppng::RpcMessageStream::_nextMessageTimer = Timer::create()
private

Definition at line 234 of file messagestream.h.

◆ _pendingMessageSize

zyppng::rpc::HeaderSizeType zyppng::RpcMessageStream::_pendingMessageSize = 0
private

Definition at line 235 of file messagestream.h.

◆ _messages

std::deque<RpcMessage> zyppng::RpcMessageStream::_messages
private

Definition at line 236 of file messagestream.h.

◆ _sigNextMessage

Signal<void()> zyppng::RpcMessageStream::_sigNextMessage
private

Definition at line 237 of file messagestream.h.

◆ _sigInvalidMessageReceived

Signal<void()> zyppng::RpcMessageStream::_sigInvalidMessageReceived
private

Definition at line 238 of file messagestream.h.


The documentation for this class was generated from the following files: