1 // Copyright 2019 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CAST_COMMON_PUBLIC_MESSAGE_PORT_H_ 6 #define CAST_COMMON_PUBLIC_MESSAGE_PORT_H_ 7 8 #include <string> 9 10 #include "platform/base/error.h" 11 12 namespace openscreen { 13 namespace cast { 14 15 // This interface is intended to provide an abstraction for communicating 16 // cast messages across a pipe with guaranteed delivery. This is used to 17 // decouple the cast streaming receiver and sender sessions from the 18 // network implementation. 19 class MessagePort { 20 public: 21 class Client { 22 public: 23 virtual ~Client() = default; 24 virtual void OnMessage(const std::string& source_sender_id, 25 const std::string& message_namespace, 26 const std::string& message) = 0; 27 virtual void OnError(Error error) = 0; 28 }; 29 30 virtual ~MessagePort() = default; 31 virtual void SetClient(Client* client, std::string client_sender_id) = 0; 32 virtual void ResetClient() = 0; 33 34 virtual void PostMessage(const std::string& destination_sender_id, 35 const std::string& message_namespace, 36 const std::string& message) = 0; 37 }; 38 39 } // namespace cast 40 } // namespace openscreen 41 42 #endif // CAST_COMMON_PUBLIC_MESSAGE_PORT_H_ 43