Home | History | Annotate | Download | only in dbus
      1 //
      2 // Copyright (C) 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 SHILL_DBUS_CHROMEOS_SUPPLICANT_PROCESS_PROXY_H_
     18 #define SHILL_DBUS_CHROMEOS_SUPPLICANT_PROCESS_PROXY_H_
     19 
     20 #include <string>
     21 #include <vector>
     22 
     23 #include <base/macros.h>
     24 #include <base/memory/ref_counted.h>
     25 #include <base/memory/weak_ptr.h>
     26 
     27 #include "shill/event_dispatcher.h"
     28 #include "shill/supplicant/supplicant_process_proxy_interface.h"
     29 #include "supplicant/dbus-proxies.h"
     30 
     31 namespace shill {
     32 
     33 class EventDispatcher;
     34 
     35 class ChromeosSupplicantProcessProxy : public SupplicantProcessProxyInterface {
     36  public:
     37   ChromeosSupplicantProcessProxy(
     38       EventDispatcher* dispatcher,
     39       const scoped_refptr<dbus::Bus>& bus,
     40       const base::Closure& service_appeared_callback,
     41       const base::Closure& service_vanished_callback);
     42   ~ChromeosSupplicantProcessProxy() override;
     43 
     44   // Implementation of SupplicantProcessProxyInterface.
     45   bool CreateInterface(const KeyValueStore& args,
     46                        std::string* rpc_identifier) override;
     47   bool RemoveInterface(const std::string& rpc_identifier) override;
     48   bool GetInterface(const std::string& ifname,
     49                     std::string* rpc_identifier) override;
     50   // This function will always return true since PropertySet::Set is an async
     51   // method. Any failures will be logged in the callback.
     52   bool SetDebugLevel(const std::string& level) override;
     53   bool GetDebugLevel(std::string* level) override;
     54   bool ExpectDisconnect() override;
     55 
     56  private:
     57   class PropertySet : public dbus::PropertySet {
     58    public:
     59     PropertySet(dbus::ObjectProxy* object_proxy,
     60                 const std::string& interface_name,
     61                 const PropertyChangedCallback& callback);
     62     brillo::dbus_utils::Property<std::string> debug_level;
     63     brillo::dbus_utils::Property<bool> debug_timestamp;
     64     brillo::dbus_utils::Property<bool> debug_show_keys;
     65     brillo::dbus_utils::Property<std::vector<dbus::ObjectPath>> interfaces;
     66     brillo::dbus_utils::Property<std::vector<std::string>> eap_methods;
     67 
     68    private:
     69     DISALLOW_COPY_AND_ASSIGN(PropertySet);
     70   };
     71 
     72   static const char kInterfaceName[];
     73   static const char kPropertyDebugLevel[];
     74   static const char kPropertyDebugTimestamp[];
     75   static const char kPropertyDebugShowKeys[];
     76   static const char kPropertyInterfaces[];
     77   static const char kPropertyEapMethods[];
     78 
     79   // Signal handlers.
     80   void InterfaceAdded(const dbus::ObjectPath& path,
     81                       const brillo::VariantDictionary& properties);
     82   void InterfaceRemoved(const dbus::ObjectPath& path);
     83   void PropertiesChanged(const brillo::VariantDictionary& properties);
     84 
     85   // Called when service appeared or vanished.
     86   void OnServiceAvailable(bool available);
     87 
     88   // Service name owner changed handler.
     89   void OnServiceOwnerChanged(const std::string& old_owner,
     90                              const std::string& new_owner);
     91 
     92   // Callback invoked when the value of property |property_name| is changed.
     93   void OnPropertyChanged(const std::string& property_name);
     94 
     95 
     96   // Called when signal is connected to the ObjectProxy.
     97   void OnSignalConnected(const std::string& interface_name,
     98                          const std::string& signal_name,
     99                          bool success);
    100 
    101   std::unique_ptr<fi::w1::wpa_supplicant1Proxy> supplicant_proxy_;
    102   std::unique_ptr<PropertySet> properties_;
    103   EventDispatcher* dispatcher_;
    104   base::Closure service_appeared_callback_;
    105   base::Closure service_vanished_callback_;
    106   bool service_available_;
    107 
    108   base::WeakPtrFactory<ChromeosSupplicantProcessProxy> weak_factory_{this};
    109   DISALLOW_COPY_AND_ASSIGN(ChromeosSupplicantProcessProxy);
    110 };
    111 
    112 }  // namespace shill
    113 
    114 #endif  // SHILL_DBUS_CHROMEOS_SUPPLICANT_PROCESS_PROXY_H_
    115