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_DBUS_OBJECTMANAGER_PROXY_H_
     18 #define SHILL_DBUS_CHROMEOS_DBUS_OBJECTMANAGER_PROXY_H_
     19 
     20 #include <map>
     21 #include <string>
     22 #include <vector>
     23 
     24 #include "cellular/dbus-proxies.h"
     25 #include "shill/cellular/dbus_objectmanager_proxy_interface.h"
     26 
     27 namespace shill {
     28 
     29 class EventDispatcher;
     30 
     31 class ChromeosDBusObjectManagerProxy : public DBusObjectManagerProxyInterface {
     32  public:
     33   ChromeosDBusObjectManagerProxy(
     34       EventDispatcher* dispatcher,
     35       const scoped_refptr<dbus::Bus>& bus,
     36       const std::string& path,
     37       const std::string& service,
     38       const base::Closure& service_appeared_callback,
     39       const base::Closure& service_vanished_callback);
     40   ~ChromeosDBusObjectManagerProxy() override;
     41 
     42   // Inherited methods from DBusObjectManagerProxyInterface.
     43   void GetManagedObjects(Error* error,
     44                          const ManagedObjectsCallback& callback,
     45                          int timeout) override;
     46 
     47   void set_interfaces_added_callback(
     48       const InterfacesAddedSignalCallback& callback) override {
     49     interfaces_added_callback_ = callback;
     50   }
     51 
     52   void set_interfaces_removed_callback(
     53       const InterfacesRemovedSignalCallback& callback) override {
     54     interfaces_removed_callback_ = callback;
     55   }
     56 
     57  private:
     58   typedef std::map<std::string, brillo::VariantDictionary>
     59       DBusInterfaceToProperties;
     60   typedef std::map<dbus::ObjectPath, DBusInterfaceToProperties>
     61       DBusObjectsWithProperties;
     62 
     63   // Signal handlers.
     64   void InterfacesAdded(
     65       const dbus::ObjectPath& object_path,
     66       const DBusInterfaceToProperties& interfaces_and_properties);
     67   void InterfacesRemoved(const dbus::ObjectPath& object_path,
     68                          const std::vector<std::string>& interfaces);
     69 
     70   // GetManagedObject method callbacks
     71   void OnGetManagedObjectsSuccess(
     72       const ManagedObjectsCallback& callback,
     73       const DBusObjectsWithProperties& objects_with_properties);
     74   void OnGetManagedObjectsFailure(const ManagedObjectsCallback& callback,
     75                                   brillo::Error* error);
     76 
     77   // Called when service appeared or vanished.
     78   void OnServiceAvailable(bool available);
     79 
     80   // Service name owner changed handler.
     81   void OnServiceOwnerChanged(const std::string& old_owner,
     82                              const std::string& new_owner);
     83 
     84   // Called when signal is connected to the ObjectProxy.
     85   void OnSignalConnected(const std::string& interface_name,
     86                          const std::string& signal_name,
     87                          bool success);
     88 
     89   void ConvertDBusInterfaceProperties(
     90       const DBusInterfaceToProperties& dbus_interface_to_properties,
     91       InterfaceToProperties* interface_to_properties);
     92 
     93   InterfacesAddedSignalCallback interfaces_added_callback_;
     94   InterfacesRemovedSignalCallback interfaces_removed_callback_;
     95 
     96   std::unique_ptr<org::freedesktop::DBus::ObjectManagerProxy> proxy_;
     97   EventDispatcher* dispatcher_;
     98   base::Closure service_appeared_callback_;
     99   base::Closure service_vanished_callback_;
    100   bool service_available_;
    101 
    102   base::WeakPtrFactory<ChromeosDBusObjectManagerProxy> weak_factory_{this};
    103   DISALLOW_COPY_AND_ASSIGN(ChromeosDBusObjectManagerProxy);
    104 };
    105 
    106 }  // namespace shill
    107 
    108 #endif  // SHILL_DBUS_CHROMEOS_DBUS_OBJECTMANAGER_PROXY_H_
    109