1 // Copyright 2015 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef BUFFET_AP_MANAGER_CLIENT_H_
16 #define BUFFET_AP_MANAGER_CLIENT_H_
17 
18 #include <memory>
19 #include <string>
20 
21 #include <apmanager/dbus-proxies.h>
22 #include <base/callback.h>
23 #include <base/memory/ref_counted.h>
24 
25 namespace buffet {
26 
27 // Manages soft AP for wifi bootstrapping.
28 // Once created can handle multiple Start/Stop requests.
29 class ApManagerClient final {
30  public:
31   explicit ApManagerClient(const scoped_refptr<dbus::Bus>& bus);
32   ~ApManagerClient();
33 
34   void Start(const std::string& ssid);
35   void Stop();
36 
GetSsid()37   std::string GetSsid() const { return ssid_; }
38 
39  private:
40   void RemoveService(const dbus::ObjectPath& object_path);
41 
42   void OnManagerAdded(
43       org::chromium::apmanager::ManagerProxyInterface* manager_proxy);
44   void OnServiceAdded(
45       org::chromium::apmanager::ServiceProxyInterface* service_proxy);
46 
47   void OnSsidSet(bool success);
48 
49   void OnServiceRemoved(const dbus::ObjectPath& object_path);
50   void OnManagerRemoved(const dbus::ObjectPath& object_path);
51 
52   scoped_refptr<dbus::Bus> bus_;
53 
54   std::unique_ptr<org::chromium::apmanager::ObjectManagerProxy>
55       object_manager_proxy_;
56   org::chromium::apmanager::ManagerProxyInterface* manager_proxy_{nullptr};
57 
58   dbus::ObjectPath service_path_;
59   org::chromium::apmanager::ServiceProxyInterface* service_proxy_{nullptr};
60 
61   std::string ssid_;
62 
63   base::WeakPtrFactory<ApManagerClient> weak_ptr_factory_{this};
64 };
65 
66 }  // namespace buffet
67 
68 #endif  // BUFFET_AP_MANAGER_CLIENT_H_
69