Refactor optional pointer to pointer

This commit is contained in:
Filip Klembara
2021-02-08 10:13:31 +01:00
parent 2b7dc4c529
commit 09dfc39fd9
12 changed files with 108 additions and 134 deletions

View File

@ -33,38 +33,31 @@ RTC_CPP_EXPORT ChainedMessagesProduct make_chained_messages_product(message_ptr
/// Ougoing messages
struct RTC_CPP_EXPORT ChainedOutgoingProduct {
ChainedOutgoingProduct(ChainedMessagesProduct messages, std::optional<message_ptr> control = nullopt);
ChainedOutgoingProduct(ChainedMessagesProduct messages = nullptr, message_ptr control = nullptr);
const ChainedMessagesProduct messages;
const std::optional<message_ptr> control;
};
/// Ougoing response to incoming messages
struct RTC_CPP_EXPORT ChainedOutgoingResponseProduct {
ChainedOutgoingResponseProduct(std::optional<ChainedMessagesProduct> messages = nullopt, std::optional<message_ptr> control = nullopt);
const std::optional<ChainedMessagesProduct> messages;
const std::optional<message_ptr> control;
const message_ptr control;
};
/// Incoming messages with response
struct RTC_CPP_EXPORT ChainedIncomingProduct {
ChainedIncomingProduct(std::optional<ChainedMessagesProduct> incoming = nullopt, std::optional<ChainedMessagesProduct> outgoing = nullopt);
const std::optional<ChainedMessagesProduct> incoming;
const std::optional<ChainedOutgoingResponseProduct> outgoing;
ChainedIncomingProduct(ChainedMessagesProduct incoming = nullptr, ChainedMessagesProduct outgoing = nullptr);
const ChainedMessagesProduct incoming;
const ChainedOutgoingProduct outgoing;
};
/// Incoming control messages with response
struct RTC_CPP_EXPORT ChainedIncomingControlProduct {
ChainedIncomingControlProduct(message_ptr incoming, std::optional<ChainedOutgoingResponseProduct> outgoing = nullopt);
const std::optional<message_ptr> incoming;
const std::optional<ChainedOutgoingResponseProduct> outgoing;
ChainedIncomingControlProduct(message_ptr incoming, std::optional<ChainedOutgoingProduct> outgoing = nullopt);
const message_ptr incoming;
const std::optional<ChainedOutgoingProduct> outgoing;
};
/// Chainable handler
class RTC_CPP_EXPORT MediaHandlerElement: public std::enable_shared_from_this<MediaHandlerElement> {
std::optional<std::shared_ptr<MediaHandlerElement>> upstream = nullopt;
std::optional<std::shared_ptr<MediaHandlerElement>> downstream = nullopt;
std::shared_ptr<MediaHandlerElement> upstream = nullptr;
std::shared_ptr<MediaHandlerElement> downstream = nullptr;
void prepareAndSendResponse(std::optional<ChainedOutgoingResponseProduct> outgoing, std::function<bool (ChainedOutgoingResponseProduct)> send);
void prepareAndSendResponse(std::optional<ChainedOutgoingProduct> outgoing, std::function<bool (ChainedOutgoingProduct)> send);
void removeFromChain();
public:
@ -73,12 +66,12 @@ public:
/// Creates response to incoming message
/// @param messages Current repsonse
/// @returns New response
std::optional<ChainedOutgoingResponseProduct> processOutgoingResponse(ChainedOutgoingResponseProduct messages);
std::optional<ChainedOutgoingProduct> processOutgoingResponse(ChainedOutgoingProduct messages);
// Process incoming and ougoing messages
std::optional<message_ptr> formIncomingControlMessage(message_ptr message, std::function<bool (ChainedOutgoingResponseProduct)> send);
std::optional<ChainedMessagesProduct> formIncomingBinaryMessage(ChainedMessagesProduct messages, std::function<bool (ChainedOutgoingResponseProduct)> send);
std::optional<message_ptr> formOutgoingControlMessage(message_ptr message);
message_ptr formIncomingControlMessage(message_ptr message, std::function<bool (ChainedOutgoingProduct)> send);
ChainedMessagesProduct formIncomingBinaryMessage(ChainedMessagesProduct messages, std::function<bool (ChainedOutgoingProduct)> send);
message_ptr formOutgoingControlMessage(message_ptr message);
std::optional<ChainedOutgoingProduct> formOutgoingBinaryMessage(ChainedOutgoingProduct product);
/// Process current control message
@ -100,7 +93,7 @@ public:
/// @param messages current message
/// @param control current control message
/// @returns Modified binary message and control message
virtual ChainedOutgoingProduct processOutgoingBinaryMessage(ChainedMessagesProduct messages, std::optional<message_ptr> control);
virtual ChainedOutgoingProduct processOutgoingBinaryMessage(ChainedMessagesProduct messages, message_ptr control);
/// Set given element as upstream to this
/// @param upstream Upstream element