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_RECEIVER_PUBLIC_RECEIVER_SOCKET_FACTORY_H_
6 #define CAST_RECEIVER_PUBLIC_RECEIVER_SOCKET_FACTORY_H_
7 
8 #include <vector>
9 
10 #include "cast/common/public/cast_socket.h"
11 #include "platform/api/tls_connection_factory.h"
12 #include "platform/base/ip_address.h"
13 
14 namespace openscreen {
15 namespace cast {
16 
17 class ReceiverSocketFactory final : public TlsConnectionFactory::Client {
18  public:
19   class Client {
20    public:
21     virtual void OnConnected(ReceiverSocketFactory* factory,
22                              const IPEndpoint& endpoint,
23                              std::unique_ptr<CastSocket> socket) = 0;
24     virtual void OnError(ReceiverSocketFactory* factory, Error error) = 0;
25   };
26 
27   // |client| and |socket_client| must outlive |this|.
28   // TODO(btolsch): Add TaskRunner argument just for sequence checking.
29   ReceiverSocketFactory(Client* client, CastSocket::Client* socket_client);
30   ~ReceiverSocketFactory();
31 
32   // TlsConnectionFactory::Client overrides.
33   void OnAccepted(TlsConnectionFactory* factory,
34                   std::vector<uint8_t> der_x509_peer_cert,
35                   std::unique_ptr<TlsConnection> connection) override;
36   void OnConnected(TlsConnectionFactory* factory,
37                    std::vector<uint8_t> der_x509_peer_cert,
38                    std::unique_ptr<TlsConnection> connection) override;
39   void OnConnectionFailed(TlsConnectionFactory* factory,
40                           const IPEndpoint& remote_address) override;
41   void OnError(TlsConnectionFactory* factory, Error error) override;
42 
43  private:
44   Client* const client_;
45   CastSocket::Client* const socket_client_;
46 };
47 
48 }  // namespace cast
49 }  // namespace openscreen
50 
51 #endif  // CAST_RECEIVER_PUBLIC_RECEIVER_SOCKET_FACTORY_H_
52