1 // Copyright 2015 The Weave 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 LIBWEAVE_INCLUDE_WEAVE_PROVIDER_NETWORK_H_ 6 #define LIBWEAVE_INCLUDE_WEAVE_PROVIDER_NETWORK_H_ 7 8 #include <string> 9 10 #include <base/callback.h> 11 #include <weave/error.h> 12 #include <weave/stream.h> 13 14 namespace weave { 15 namespace provider { 16 17 // Interface with methods to detect network connectivity and opening network 18 // connections. 19 class Network { 20 public: 21 enum class State { 22 kOffline = 0, 23 kError, 24 kConnecting, 25 kOnline, 26 }; 27 28 // Callback type for AddConnectionChangedCallback. 29 using ConnectionChangedCallback = base::Closure; 30 31 // Callback type for OpenSslSocket. 32 using OpenSslSocketCallback = 33 base::Callback<void(std::unique_ptr<Stream> stream, ErrorPtr error)>; 34 35 // Subscribes to notification about changes in network connectivity. Changes 36 // may include but not limited: interface up or down, new IP was assigned, 37 // cable is disconnected. 38 virtual void AddConnectionChangedCallback( 39 const ConnectionChangedCallback& callback) = 0; 40 41 // Returns current Internet connectivity state 42 virtual State GetConnectionState() const = 0; 43 44 // Opens bidirectional sockets and returns attached stream. 45 virtual void OpenSslSocket(const std::string& host, 46 uint16_t port, 47 const OpenSslSocketCallback& callback) = 0; 48 49 protected: ~Network()50 virtual ~Network() {} 51 }; 52 53 } // namespace provider 54 } // namespace weave 55 56 #endif // LIBWEAVE_INCLUDE_WEAVE_PROVIDER_NETWORK_H_ 57