blob: f05bd9711f7b8561c07188ee72054850f8945efe [file] [log] [blame]
Alex Vakulenkof0f55342015-08-18 15:51:40 -07001/*
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 Vakulenko0fef8152015-09-25 08:45:22 -070024#include <weave/network_provider.h>
Alex Vakulenkof0f55342015-08-18 15:51:40 -070025
26#include "connectivity_client.h"
27
28#include "buffet/network_client.h"
29
30namespace buffet {
31
32class 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 Vakulenko0fef8152015-09-25 08:45:22 -070038 void AddConnectionChangedCallback(
39 const ConnectionChangedCallback& listener) override;
40 void Connect(
Alex Vakulenko059c30d2015-09-22 14:09:16 -070041 const std::string& ssid,
42 const std::string& passphrase,
Alex Vakulenko0fef8152015-09-25 08:45:22 -070043 const weave::SuccessCallback& on_success,
Alex Vakulenko059c30d2015-09-22 14:09:16 -070044 const base::Callback<void(const weave::Error*)>& on_error) override;
Alex Vakulenkof0f55342015-08-18 15:51:40 -070045 weave::NetworkState GetConnectionState() const override;
Alex Vakulenko0fef8152015-09-25 08:45:22 -070046 void StartAccessPoint(const std::string& ssid) override;
47 void StopAccessPoint() override;
Alex Vakulenkof0f55342015-08-18 15:51:40 -070048
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 Vakulenko0fef8152015-09-25 08:45:22 -070061 std::vector<ConnectionChangedCallback> connection_listeners_;
Alex Vakulenkof0f55342015-08-18 15:51:40 -070062 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