libzypp 17.34.0
|
#include <zypp-core/zyppng/rpc/messagestream.h>
Public Types | |
using | Ptr = std::shared_ptr<RpcMessageStream> |
![]() | |
using | Ptr = std::shared_ptr<Base> |
using | WeakPtr = std::weak_ptr<Base> |
Public Member Functions | |
std::optional< RpcMessage > | nextMessage (const std::string &msgName="") |
std::optional< RpcMessage > | nextMessageWait (const std::string &msgName="") |
bool | sendMessage (const RpcMessage &env) |
void | readAllMessages () |
template<typename T > | |
std::enable_if_t< !std::is_same_v< T, RpcMessage >, bool > | sendMessage (const T &m) |
SignalProxy< void()> | sigMessageReceived () |
SignalProxy< void()> | sigInvalidMessageReceived () |
![]() | |
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 >, connection > | connectFunc (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< void > | parseMessageInto (const RpcMessage &m, T &target) |
![]() | |
template<typename Obj , typename Functor > | |
static decltype(auto) | make_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 | |
![]() | |
Base (BasePrivate &dd) | |
![]() | |
std::unique_ptr< BasePrivate > | d_ptr |
Implements the basic protocol for sending zypp RPC messages over a IODevice
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.
using zyppng::RpcMessageStream::Ptr = std::shared_ptr<RpcMessageStream> |
Definition at line 153 of file messagestream.h.
|
private |
Definition at line 64 of file messagestream.cc.
|
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.
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.
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
Definition at line 158 of file messagestream.cc.
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.
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.
|
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.
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.
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.
|
inlinestatic |
Definition at line 214 of file messagestream.h.
|
inlinestatic |
Definition at line 219 of file messagestream.h.
|
private |
Definition at line 74 of file messagestream.cc.
|
private |
Definition at line 107 of file messagestream.cc.
|
private |
Definition at line 233 of file messagestream.h.
|
private |
Definition at line 234 of file messagestream.h.
|
private |
Definition at line 235 of file messagestream.h.
|
private |
Definition at line 236 of file messagestream.h.
Definition at line 237 of file messagestream.h.
Definition at line 238 of file messagestream.h.