blob: 839758758a594c03fbaeaf962fb50ca24446554a [file] [log] [blame]
Vitaly Buka3ef4fff2015-07-31 01:12:07 -07001// Copyright 2014 The Chromium OS 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 BUFFET_AP_MANAGER_CLIENT_H_
6#define BUFFET_AP_MANAGER_CLIENT_H_
7
8#include <memory>
9#include <string>
10
11#include <base/callback.h>
12#include <base/memory/ref_counted.h>
13
14#include "apmanager/dbus-proxies.h"
15
16namespace buffet {
17
18// Manages soft AP for wifi bootstrapping.
19// Once created can handle multiple Start/Stop requests.
20class ApManagerClient final {
21 public:
22 explicit ApManagerClient(const scoped_refptr<dbus::Bus>& bus);
23 ~ApManagerClient();
24
25 void Start(const std::string& ssid);
26 void Stop();
27
28 std::string GetSsid() const { return ssid_; }
29
30 private:
31 void RemoveService(const dbus::ObjectPath& object_path);
32
33 void OnManagerAdded(org::chromium::apmanager::ManagerProxy* manager_proxy);
34 void OnServiceAdded(org::chromium::apmanager::ServiceProxy* service_proxy);
35
36 void OnSsidSet(bool success);
37
38 void OnServiceRemoved(const dbus::ObjectPath& object_path);
39 void OnManagerRemoved(const dbus::ObjectPath& object_path);
40
41 scoped_refptr<dbus::Bus> bus_;
42
43 std::unique_ptr<org::chromium::apmanager::ObjectManagerProxy>
44 object_manager_proxy_;
45 org::chromium::apmanager::ManagerProxy* manager_proxy_{nullptr};
46
47 dbus::ObjectPath service_path_;
48 org::chromium::apmanager::ServiceProxy* service_proxy_{nullptr};
49
50 std::string ssid_;
51
52 base::WeakPtrFactory<ApManagerClient> weak_ptr_factory_{this};
53};
54
55} // namespace buffet
56
57#endif // BUFFET_AP_MANAGER_CLIENT_H_