Alex Vakulenko | f0f5534 | 2015-08-18 15:51:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef BUFFET_BRILLO_NETWORK_CLIENT_H_ |
| 18 | #define BUFFET_BRILLO_NETWORK_CLIENT_H_ |
| 19 | |
| 20 | #include <memory> |
| 21 | #include <vector> |
| 22 | |
| 23 | #include <base/cancelable_callback.h> |
Alex Vakulenko | 0fef815 | 2015-09-25 08:45:22 -0700 | [diff] [blame^] | 24 | #include <weave/network_provider.h> |
Alex Vakulenko | f0f5534 | 2015-08-18 15:51:40 -0700 | [diff] [blame] | 25 | |
| 26 | #include "connectivity_client.h" |
| 27 | |
| 28 | #include "buffet/network_client.h" |
| 29 | |
| 30 | namespace buffet { |
| 31 | |
| 32 | class BrilloNetworkClient : public NetworkClient { |
| 33 | public: |
| 34 | explicit BrilloNetworkClient(const std::set<std::string>& device_whitelist); |
| 35 | ~BrilloNetworkClient() override; |
| 36 | |
| 37 | // Implements the Network interface. |
Alex Vakulenko | 0fef815 | 2015-09-25 08:45:22 -0700 | [diff] [blame^] | 38 | void AddConnectionChangedCallback( |
| 39 | const ConnectionChangedCallback& listener) override; |
| 40 | void Connect( |
Alex Vakulenko | 059c30d | 2015-09-22 14:09:16 -0700 | [diff] [blame] | 41 | const std::string& ssid, |
| 42 | const std::string& passphrase, |
Alex Vakulenko | 0fef815 | 2015-09-25 08:45:22 -0700 | [diff] [blame^] | 43 | const weave::SuccessCallback& on_success, |
Alex Vakulenko | 059c30d | 2015-09-22 14:09:16 -0700 | [diff] [blame] | 44 | const base::Callback<void(const weave::Error*)>& on_error) override; |
Alex Vakulenko | f0f5534 | 2015-08-18 15:51:40 -0700 | [diff] [blame] | 45 | weave::NetworkState GetConnectionState() const override; |
Alex Vakulenko | 0fef815 | 2015-09-25 08:45:22 -0700 | [diff] [blame^] | 46 | void StartAccessPoint(const std::string& ssid) override; |
| 47 | void StopAccessPoint() override; |
Alex Vakulenko | f0f5534 | 2015-08-18 15:51:40 -0700 | [diff] [blame] | 48 | |
| 49 | private: |
| 50 | enum class ConnectionState { |
| 51 | kIdle, |
| 52 | kInProgress, |
| 53 | kConnected, |
| 54 | kTimedOut |
| 55 | }; |
| 56 | void OnConnectionTimeout(); |
| 57 | void ScheduleNextStatePoll(); |
| 58 | void UpdateConnectionState(); |
| 59 | |
| 60 | ConnectivityClient connectivity_client_; |
Alex Vakulenko | 0fef815 | 2015-09-25 08:45:22 -0700 | [diff] [blame^] | 61 | std::vector<ConnectionChangedCallback> connection_listeners_; |
Alex Vakulenko | f0f5534 | 2015-08-18 15:51:40 -0700 | [diff] [blame] | 62 | base::CancelableClosure connection_timeout_closure_; |
| 63 | base::CancelableClosure periodic_connection_state_closure_; |
| 64 | base::Closure connection_success_closure_; |
| 65 | weave::NetworkState state_; |
| 66 | bool is_connected_; |
| 67 | |
| 68 | DISALLOW_COPY_AND_ASSIGN(BrilloNetworkClient); |
| 69 | }; |
| 70 | |
| 71 | } // namespace buffet |
| 72 | |
| 73 | #endif // BUFFET_BRILLO_NETWORK_CLIENT_H_ |
| 74 | |