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_WIMAX_DEVICE_PROXY_H_
     18 #define SHILL_DBUS_CHROMEOS_WIMAX_DEVICE_PROXY_H_
     19 
     20 #include <string>
     21 #include <vector>
     22 
     23 #include <base/callback.h>
     24 #include <wimax_manager/dbus-proxies.h>
     25 
     26 #include "shill/wimax/wimax_device_proxy_interface.h"
     27 
     28 namespace shill {
     29 
     30 class ChromeosWiMaxDeviceProxy : public WiMaxDeviceProxyInterface {
     31  public:
     32   // Constructs a WiMaxManager.Device DBus object proxy at |rpc_identifier|.
     33   ChromeosWiMaxDeviceProxy(const scoped_refptr<dbus::Bus>& bus,
     34                            const std::string& rpc_identifier);
     35   ~ChromeosWiMaxDeviceProxy() override;
     36 
     37   // Inherited from WiMaxDeviceProxyInterface.
     38   void Enable(Error* error,
     39               const ResultCallback& callback,
     40               int timeout) override;
     41   void Disable(Error* error,
     42                const ResultCallback& callback,
     43                int timeout) override;
     44   void ScanNetworks(Error* error,
     45                     const ResultCallback& callback,
     46                     int timeout) override;
     47   void Connect(const RpcIdentifier& network,
     48                const KeyValueStore& parameters,
     49                Error* error,
     50                const ResultCallback& callback,
     51                int timeout) override;
     52   void Disconnect(Error* error,
     53                   const ResultCallback& callback,
     54                   int timeout) override;
     55   void set_networks_changed_callback(
     56       const NetworksChangedCallback& callback) override;
     57   void set_status_changed_callback(
     58       const StatusChangedCallback& callback) override;
     59   uint8_t Index(Error* error) override;
     60   std::string Name(Error* error) override;
     61   RpcIdentifiers Networks(Error* error) override;
     62 
     63  private:
     64   class PropertySet : public dbus::PropertySet {
     65    public:
     66     PropertySet(dbus::ObjectProxy* object_proxy,
     67                 const std::string& interface_name,
     68                 const PropertyChangedCallback& callback);
     69     brillo::dbus_utils::Property<uint8_t> index;
     70     brillo::dbus_utils::Property<std::string> name;
     71     brillo::dbus_utils::Property<std::vector<dbus::ObjectPath>> networks;
     72 
     73    private:
     74     DISALLOW_COPY_AND_ASSIGN(PropertySet);
     75   };
     76 
     77   static const char kPropertyIndex[];
     78   static const char kPropertyName[];
     79   static const char kPropertyNetworks[];
     80 
     81   // Signal handlers.
     82   void NetworksChanged(const std::vector<dbus::ObjectPath>& networks);
     83   void StatusChanged(int32_t status);
     84 
     85   // Status callbacks for async method calls.
     86   void OnSuccess(const ResultCallback& callback, const std::string& method);
     87   void OnFailure(const ResultCallback& callback,
     88                  const std::string& method,
     89                  brillo::Error* error);
     90 
     91   // Callback invoked when the value of property |property_name| is changed.
     92   void OnPropertyChanged(const std::string& property_name);
     93 
     94   // Called when signal is connected to the ObjectProxy.
     95   void OnSignalConnected(const std::string& interface_name,
     96                          const std::string& signal_name,
     97                          bool success);
     98 
     99   std::unique_ptr<org::chromium::WiMaxManager::DeviceProxy> proxy_;
    100   std::unique_ptr<PropertySet> properties_;
    101   NetworksChangedCallback networks_changed_callback_;
    102   StatusChangedCallback status_changed_callback_;
    103 
    104   base::WeakPtrFactory<ChromeosWiMaxDeviceProxy> weak_factory_{this};
    105   DISALLOW_COPY_AND_ASSIGN(ChromeosWiMaxDeviceProxy);
    106 };
    107 
    108 }  // namespace shill
    109 
    110 #endif  // SHILL_DBUS_CHROMEOS_WIMAX_DEVICE_PROXY_H_
    111