xref: /aosp_15_r20/external/openscreen/cast/common/public/message_port.h (revision 3f982cf4871df8771c9d4abe6e9a6f8d829b2736)
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 void OnMessage(const std::string& source_sender_id,
24                            const std::string& message_namespace,
25                            const std::string& message) = 0;
26     virtual void OnError(Error error) = 0;
27 
28    protected:
29     virtual ~Client() = default;
30   };
31 
32   virtual ~MessagePort() = default;
33   virtual void SetClient(Client* client, std::string client_sender_id) = 0;
34   virtual void ResetClient() = 0;
35 
36   virtual void PostMessage(const std::string& destination_sender_id,
37                            const std::string& message_namespace,
38                            const std::string& message) = 0;
39 };
40 
41 }  // namespace cast
42 }  // namespace openscreen
43 
44 #endif  // CAST_COMMON_PUBLIC_MESSAGE_PORT_H_
45