Alex Vakulenko | 15aea55 | 2015-08-17 09:34:08 -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_NETWORK_CLIENT_H_ |
| 18 | #define BUFFET_NETWORK_CLIENT_H_ |
| 19 | |
| 20 | #include <memory> |
| 21 | #include <vector> |
| 22 | |
| 23 | #include <base/cancelable_callback.h> |
| 24 | #include <weave/network.h> |
| 25 | |
| 26 | #include "connectivity_client.h" |
| 27 | |
| 28 | namespace buffet { |
| 29 | |
| 30 | class NetworkClient : public weave::Network { |
| 31 | public: |
| 32 | NetworkClient(); |
| 33 | ~NetworkClient() override; |
| 34 | |
| 35 | // Implements the Network interface. |
| 36 | void AddOnConnectionChangedCallback( |
| 37 | const OnConnectionChangedCallback& listener) override; |
| 38 | bool ConnectToService(const std::string& ssid, |
| 39 | const std::string& passphrase, |
| 40 | const base::Closure& on_success, |
| 41 | chromeos::ErrorPtr* error) override; |
| 42 | weave::NetworkState GetConnectionState() const override; |
| 43 | void EnableAccessPoint(const std::string& ssid) override; |
| 44 | void DisableAccessPoint() override; |
| 45 | |
| 46 | private: |
| 47 | enum class ConnectionState { |
| 48 | kIdle, |
| 49 | kInProgress, |
| 50 | kConnected, |
| 51 | kTimedOut |
| 52 | }; |
| 53 | void OnConnectionTimeout(); |
| 54 | void ScheduleNextStatePoll(); |
| 55 | void UpdateConnectionState(); |
| 56 | |
| 57 | ConnectivityClient connectivity_client_; |
| 58 | std::vector<OnConnectionChangedCallback> connection_listeners_; |
| 59 | base::CancelableClosure connection_timeout_closure_; |
| 60 | base::CancelableClosure periodic_connection_state_closure_; |
| 61 | base::Closure connection_success_closure_; |
| 62 | weave::NetworkState state_; |
| 63 | bool is_connected_; |
| 64 | |
| 65 | DISALLOW_COPY_AND_ASSIGN(NetworkClient); |
| 66 | }; |
| 67 | |
| 68 | } // namespace buffet |
| 69 | |
| 70 | #endif // BUFFET_NETWORK_CLIENT_H_ |
| 71 | |