hmbdc
simplify-high-performance-messaging-programming
Public Member Functions | List of all members
hmbdc::app::RequestReplySender< CcSender > Struct Template Reference

synchronous request reply interface for the Network Sender More...

#include <RequestReply.hpp>

Public Member Functions

template<RequestC RequestT, typename ReplyContext , typename ReplyHandler >
bool requestReply (RequestT &&request, ReplyContext &ctx, ReplyHandler &replyHandler, time::Duration timeout=time::Duration::seconds(0xffffffff))
 The caller is blocked until the replies to this request are heard and processed. Just like regular Messages REQUEST is sent out to Clients through the CcSender. More...
 
template<MessageC M>
void sendReply (REPLY< M > &&reply)
 part of synchronous request reply interface. Send a constructed REPLY using the CcSender, it will only reach to the origianl sender Client. ALL REPLY via a Sender need to sent out using this interface to avoid undefined behavior. More...
 
template<MessageC M>
void sendReply (REPLY< M > const &reply)
 part of synchronous request reply interface. Send a constructed REPLY using the CcSender, it will only reach to the origianl sender Client. ALL REPLY via a Sender need to sent out using this interface to avoid undefined behavior. More...
 

Detailed Description

template<typename CcSender>
struct hmbdc::app::RequestReplySender< CcSender >

synchronous request reply interface for the Network Sender

Template Parameters
CcSenderconcrete Sender

Member Function Documentation

◆ requestReply()

template<typename CcSender>
template<RequestC RequestT, typename ReplyContext , typename ReplyHandler >
bool hmbdc::app::RequestReplySender< CcSender >::requestReply ( RequestT &&  request,
ReplyContext &  ctx,
ReplyHandler &  replyHandler,
time::Duration  timeout = time::Duration::seconds(0xffffffff) 
)
inline

The caller is blocked until the replies to this request are heard and processed. Just like regular Messages REQUEST is sent out to Clients through the CcSender.

Template Parameters
MessageCMessage the type wrapped in REQUEST<> template
ReplyContextthe Context Type that ReplyT messages need to be able to reach, it needs to have a pool
template <typename Ctx>
struct Auctioner
: Client<Auctioner<Ctx>, REPLY<Bid>> {
Auctioner(Ctx& ctx, char const ** items, size_t count)
: ctx_(ctx)
, sender_(NetCtx::instance().getSender(AUCTION_TOPIC))
, items_(items)
, count_(count) {
}
void invokedCb(uint16_t) {
if (current_ == count_) throw 0; //all done
REQUEST<AuctionItem> ra;
strcpy(ra.request.description, items_[current_++]);
//blocking for a second to collect all bids in this period
//for this item
sender_->requestReply(ra
, ctx_
, *this
, time::Duration::seconds(1));
if (highestBidder_.size()) {
std::cout << ra.request.description << " sold at " << (int)highestPrice_
<< " to " << highestBidder_ << std::endl;
} else {
std::cout << ra.request.description << " bought-in " << std::endl;
}
highestPrice_ = 0;
highestBidder_ = std::string();
}
//when replies come back - handle it here since
//the Client regular callbacks is blocked on requestReply()
// - it is safe to use any data here
//this Bid is garanteed by hmbdc to be for the current Item,
//request-reply ensures the above
void handleReplyCb(Bid const& bid) {
if (bid.price > highestPrice_) {
highestPrice_ = bid.price;
highestBidder_ = std::string(bid.bidder);
}
}
private:
Ctx& ctx_;
Sender* sender_;
char const** items_;
size_t count_;
size_t current_ = 0;
uint8_t highestPrice_ = 0;
std::string highestBidder_;
};
ReplyHandlertype for how to handle the replies. example of a handler expect two steps replies for requestReply call:
struct ClientAlsoHandlesReplies
: Client<ClientAlsoHandlesReplies, REPLY<Reply0>, REPLY<Reply1>, OtherMsg> {
void handleReplyCb(Reply0 const&){
// got step 1 reply
}
void handleReplyCb(Reply1 const&){
// got step 2 reply
throw hmbdc::ExitCode(0); // all replies received, now
// throw to unblock the requestReply call
}
Parameters
requestthe REQUEST sent out
ctxthe replies are expected to show up in this Context which contains a pool
replyHandlerthe callback logic to handle replies

◆ sendReply() [1/2]

template<typename CcSender>
template<MessageC M>
void hmbdc::app::RequestReplySender< CcSender >::sendReply ( REPLY< M > &&  reply)
inline

part of synchronous request reply interface. Send a constructed REPLY using the CcSender, it will only reach to the origianl sender Client. ALL REPLY via a Sender need to sent out using this interface to avoid undefined behavior.

Template Parameters
MessageCMessage the type wrapped in REPLY<> template example usage:
REPLY<Response> resp(req, req.request); //see REPLY<> ctor
myCtx.sendReply(resp);
Parameters
reply(rvalue) the REPLY (previously constructed from a REQUEST) to sent out

◆ sendReply() [2/2]

template<typename CcSender>
template<MessageC M>
void hmbdc::app::RequestReplySender< CcSender >::sendReply ( REPLY< M > const &  reply)
inline

part of synchronous request reply interface. Send a constructed REPLY using the CcSender, it will only reach to the origianl sender Client. ALL REPLY via a Sender need to sent out using this interface to avoid undefined behavior.

Template Parameters
MessageCMessage the type wrapped in REPLY<> template example usage:
REPLY<Response> resp(req, req.request); //see REPLY<> ctor
myCtx.sendReply(resp);
Parameters
reply(lvalue) the REPLY (previously constructed from a REQUEST) to sent out

The documentation for this struct was generated from the following file: