1*635a8641SAndroid Build Coastguard Worker // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be 3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file. 4*635a8641SAndroid Build Coastguard Worker 5*635a8641SAndroid Build Coastguard Worker #ifndef DBUS_OBJECT_MANAGER_H_ 6*635a8641SAndroid Build Coastguard Worker #define DBUS_OBJECT_MANAGER_H_ 7*635a8641SAndroid Build Coastguard Worker 8*635a8641SAndroid Build Coastguard Worker #include <stdint.h> 9*635a8641SAndroid Build Coastguard Worker 10*635a8641SAndroid Build Coastguard Worker #include <map> 11*635a8641SAndroid Build Coastguard Worker 12*635a8641SAndroid Build Coastguard Worker #include "base/macros.h" 13*635a8641SAndroid Build Coastguard Worker #include "base/memory/ref_counted.h" 14*635a8641SAndroid Build Coastguard Worker #include "base/memory/weak_ptr.h" 15*635a8641SAndroid Build Coastguard Worker #include "dbus/object_path.h" 16*635a8641SAndroid Build Coastguard Worker #include "dbus/property.h" 17*635a8641SAndroid Build Coastguard Worker 18*635a8641SAndroid Build Coastguard Worker // Newer D-Bus services implement the Object Manager interface to inform other 19*635a8641SAndroid Build Coastguard Worker // clients about the objects they export, the properties of those objects, and 20*635a8641SAndroid Build Coastguard Worker // notification of changes in the set of available objects: 21*635a8641SAndroid Build Coastguard Worker // http://dbus.freedesktop.org/doc/dbus-specification.html 22*635a8641SAndroid Build Coastguard Worker // #standard-interfaces-objectmanager 23*635a8641SAndroid Build Coastguard Worker // 24*635a8641SAndroid Build Coastguard Worker // This interface is very closely tied to the Properties interface, and uses 25*635a8641SAndroid Build Coastguard Worker // even more levels of nested dictionaries and variants. In addition to 26*635a8641SAndroid Build Coastguard Worker // simplifying implementation, since there tends to be a single object manager 27*635a8641SAndroid Build Coastguard Worker // per service, spanning the complete set of objects an interfaces available, 28*635a8641SAndroid Build Coastguard Worker // the classes implemented here make dealing with this interface simpler. 29*635a8641SAndroid Build Coastguard Worker // 30*635a8641SAndroid Build Coastguard Worker // Except where noted, use of this class replaces the need for the code 31*635a8641SAndroid Build Coastguard Worker // documented in dbus/property.h 32*635a8641SAndroid Build Coastguard Worker // 33*635a8641SAndroid Build Coastguard Worker // Client implementation classes should begin by deriving from the 34*635a8641SAndroid Build Coastguard Worker // dbus::ObjectManager::Interface class, and defining a Properties structure as 35*635a8641SAndroid Build Coastguard Worker // documented in dbus/property.h. 36*635a8641SAndroid Build Coastguard Worker // 37*635a8641SAndroid Build Coastguard Worker // Example: 38*635a8641SAndroid Build Coastguard Worker // class ExampleClient : public dbus::ObjectManager::Interface { 39*635a8641SAndroid Build Coastguard Worker // public: 40*635a8641SAndroid Build Coastguard Worker // struct Properties : public dbus::PropertySet { 41*635a8641SAndroid Build Coastguard Worker // dbus::Property<std::string> name; 42*635a8641SAndroid Build Coastguard Worker // dbus::Property<uint16_t> version; 43*635a8641SAndroid Build Coastguard Worker // dbus::Property<dbus::ObjectPath> parent; 44*635a8641SAndroid Build Coastguard Worker // dbus::Property<std::vector<std::string>> children; 45*635a8641SAndroid Build Coastguard Worker // 46*635a8641SAndroid Build Coastguard Worker // Properties(dbus::ObjectProxy* object_proxy, 47*635a8641SAndroid Build Coastguard Worker // const PropertyChangedCallback callback) 48*635a8641SAndroid Build Coastguard Worker // : dbus::PropertySet(object_proxy, kExampleInterface, callback) { 49*635a8641SAndroid Build Coastguard Worker // RegisterProperty("Name", &name); 50*635a8641SAndroid Build Coastguard Worker // RegisterProperty("Version", &version); 51*635a8641SAndroid Build Coastguard Worker // RegisterProperty("Parent", &parent); 52*635a8641SAndroid Build Coastguard Worker // RegisterProperty("Children", &children); 53*635a8641SAndroid Build Coastguard Worker // } 54*635a8641SAndroid Build Coastguard Worker // virtual ~Properties() {} 55*635a8641SAndroid Build Coastguard Worker // }; 56*635a8641SAndroid Build Coastguard Worker // 57*635a8641SAndroid Build Coastguard Worker // The link between the implementation class and the object manager is set up 58*635a8641SAndroid Build Coastguard Worker // in the constructor and removed in the destructor; the class should maintain 59*635a8641SAndroid Build Coastguard Worker // a pointer to its object manager for use in other methods and establish 60*635a8641SAndroid Build Coastguard Worker // itself as the implementation class for its interface. 61*635a8641SAndroid Build Coastguard Worker // 62*635a8641SAndroid Build Coastguard Worker // Example: 63*635a8641SAndroid Build Coastguard Worker // explicit ExampleClient::ExampleClient(dbus::Bus* bus) 64*635a8641SAndroid Build Coastguard Worker // : bus_(bus), 65*635a8641SAndroid Build Coastguard Worker // weak_ptr_factory_(this) { 66*635a8641SAndroid Build Coastguard Worker // object_manager_ = bus_->GetObjectManager(kServiceName, kManagerPath); 67*635a8641SAndroid Build Coastguard Worker // object_manager_->RegisterInterface(kInterface, this); 68*635a8641SAndroid Build Coastguard Worker // } 69*635a8641SAndroid Build Coastguard Worker // 70*635a8641SAndroid Build Coastguard Worker // virtual ExampleClient::~ExampleClient() { 71*635a8641SAndroid Build Coastguard Worker // object_manager_->UnregisterInterface(kInterface); 72*635a8641SAndroid Build Coastguard Worker // } 73*635a8641SAndroid Build Coastguard Worker // 74*635a8641SAndroid Build Coastguard Worker // This class calls GetManagedObjects() asynchronously after the remote service 75*635a8641SAndroid Build Coastguard Worker // becomes available and additionally refreshes managed objects after the 76*635a8641SAndroid Build Coastguard Worker // service stops or restarts. 77*635a8641SAndroid Build Coastguard Worker // 78*635a8641SAndroid Build Coastguard Worker // The object manager interface class has one abstract method that must be 79*635a8641SAndroid Build Coastguard Worker // implemented by the class to create Properties structures on demand. As well 80*635a8641SAndroid Build Coastguard Worker // as implementing this, you will want to implement a public GetProperties() 81*635a8641SAndroid Build Coastguard Worker // method. 82*635a8641SAndroid Build Coastguard Worker // 83*635a8641SAndroid Build Coastguard Worker // Example: 84*635a8641SAndroid Build Coastguard Worker // dbus::PropertySet* CreateProperties(dbus::ObjectProxy* object_proxy, 85*635a8641SAndroid Build Coastguard Worker // const std::string& interface_name) 86*635a8641SAndroid Build Coastguard Worker // override { 87*635a8641SAndroid Build Coastguard Worker // Properties* properties = new Properties( 88*635a8641SAndroid Build Coastguard Worker // object_proxy, interface_name, 89*635a8641SAndroid Build Coastguard Worker // base::Bind(&PropertyChanged, 90*635a8641SAndroid Build Coastguard Worker // weak_ptr_factory_.GetWeakPtr(), 91*635a8641SAndroid Build Coastguard Worker // object_path)); 92*635a8641SAndroid Build Coastguard Worker // return static_cast<dbus::PropertySet*>(properties); 93*635a8641SAndroid Build Coastguard Worker // } 94*635a8641SAndroid Build Coastguard Worker // 95*635a8641SAndroid Build Coastguard Worker // Properties* GetProperties(const dbus::ObjectPath& object_path) { 96*635a8641SAndroid Build Coastguard Worker // return static_cast<Properties*>( 97*635a8641SAndroid Build Coastguard Worker // object_manager_->GetProperties(object_path, kInterface)); 98*635a8641SAndroid Build Coastguard Worker // } 99*635a8641SAndroid Build Coastguard Worker // 100*635a8641SAndroid Build Coastguard Worker // Note that unlike classes that only use dbus/property.h there is no need 101*635a8641SAndroid Build Coastguard Worker // to connect signals or obtain the initial values of properties. The object 102*635a8641SAndroid Build Coastguard Worker // manager class handles that for you. 103*635a8641SAndroid Build Coastguard Worker // 104*635a8641SAndroid Build Coastguard Worker // PropertyChanged is a method of your own to notify your observers of a change 105*635a8641SAndroid Build Coastguard Worker // in your properties, either as a result of a signal from the Properties 106*635a8641SAndroid Build Coastguard Worker // interface or from the Object Manager interface. You may also wish to 107*635a8641SAndroid Build Coastguard Worker // implement the optional ObjectAdded and ObjectRemoved methods of the class 108*635a8641SAndroid Build Coastguard Worker // to likewise notify observers. 109*635a8641SAndroid Build Coastguard Worker // 110*635a8641SAndroid Build Coastguard Worker // When your class needs an object proxy for a given object path, it may 111*635a8641SAndroid Build Coastguard Worker // obtain it from the object manager. Unlike the equivalent method on the bus 112*635a8641SAndroid Build Coastguard Worker // this will return NULL if the object is not known. 113*635a8641SAndroid Build Coastguard Worker // 114*635a8641SAndroid Build Coastguard Worker // object_proxy = object_manager_->GetObjectProxy(object_path); 115*635a8641SAndroid Build Coastguard Worker // if (object_proxy) { 116*635a8641SAndroid Build Coastguard Worker // ... 117*635a8641SAndroid Build Coastguard Worker // } 118*635a8641SAndroid Build Coastguard Worker // 119*635a8641SAndroid Build Coastguard Worker // There is no need for code using your implementation class to be aware of the 120*635a8641SAndroid Build Coastguard Worker // use of object manager behind the scenes, the rules for updating properties 121*635a8641SAndroid Build Coastguard Worker // documented in dbus/property.h still apply. 122*635a8641SAndroid Build Coastguard Worker 123*635a8641SAndroid Build Coastguard Worker namespace dbus { 124*635a8641SAndroid Build Coastguard Worker 125*635a8641SAndroid Build Coastguard Worker const char kObjectManagerInterface[] = "org.freedesktop.DBus.ObjectManager"; 126*635a8641SAndroid Build Coastguard Worker const char kObjectManagerGetManagedObjects[] = "GetManagedObjects"; 127*635a8641SAndroid Build Coastguard Worker const char kObjectManagerInterfacesAdded[] = "InterfacesAdded"; 128*635a8641SAndroid Build Coastguard Worker const char kObjectManagerInterfacesRemoved[] = "InterfacesRemoved"; 129*635a8641SAndroid Build Coastguard Worker 130*635a8641SAndroid Build Coastguard Worker class Bus; 131*635a8641SAndroid Build Coastguard Worker class MessageReader; 132*635a8641SAndroid Build Coastguard Worker class ObjectProxy; 133*635a8641SAndroid Build Coastguard Worker class Response; 134*635a8641SAndroid Build Coastguard Worker class Signal; 135*635a8641SAndroid Build Coastguard Worker 136*635a8641SAndroid Build Coastguard Worker // ObjectManager implements both the D-Bus client components of the D-Bus 137*635a8641SAndroid Build Coastguard Worker // Object Manager interface, as internal methods, and a public API for 138*635a8641SAndroid Build Coastguard Worker // client classes to utilize. 139*635a8641SAndroid Build Coastguard Worker class CHROME_DBUS_EXPORT ObjectManager 140*635a8641SAndroid Build Coastguard Worker : public base::RefCountedThreadSafe<ObjectManager> { 141*635a8641SAndroid Build Coastguard Worker public: 142*635a8641SAndroid Build Coastguard Worker // ObjectManager::Interface must be implemented by any class wishing to have 143*635a8641SAndroid Build Coastguard Worker // its remote objects managed by an ObjectManager. 144*635a8641SAndroid Build Coastguard Worker class Interface { 145*635a8641SAndroid Build Coastguard Worker public: ~Interface()146*635a8641SAndroid Build Coastguard Worker virtual ~Interface() {} 147*635a8641SAndroid Build Coastguard Worker 148*635a8641SAndroid Build Coastguard Worker // Called by ObjectManager to create a Properties structure for the remote 149*635a8641SAndroid Build Coastguard Worker // D-Bus object identified by |object_path| and accessibile through 150*635a8641SAndroid Build Coastguard Worker // |object_proxy|. The D-Bus interface name |interface_name| is that passed 151*635a8641SAndroid Build Coastguard Worker // to RegisterInterface() by the implementation class. 152*635a8641SAndroid Build Coastguard Worker // 153*635a8641SAndroid Build Coastguard Worker // The implementation class should create and return an instance of its own 154*635a8641SAndroid Build Coastguard Worker // subclass of dbus::PropertySet; ObjectManager will then connect signals 155*635a8641SAndroid Build Coastguard Worker // and update the properties from its own internal message reader. 156*635a8641SAndroid Build Coastguard Worker virtual PropertySet* CreateProperties( 157*635a8641SAndroid Build Coastguard Worker ObjectProxy *object_proxy, 158*635a8641SAndroid Build Coastguard Worker const dbus::ObjectPath& object_path, 159*635a8641SAndroid Build Coastguard Worker const std::string& interface_name) = 0; 160*635a8641SAndroid Build Coastguard Worker 161*635a8641SAndroid Build Coastguard Worker // Called by ObjectManager to inform the implementation class that an 162*635a8641SAndroid Build Coastguard Worker // object has been added with the path |object_path|. The D-Bus interface 163*635a8641SAndroid Build Coastguard Worker // name |interface_name| is that passed to RegisterInterface() by the 164*635a8641SAndroid Build Coastguard Worker // implementation class. 165*635a8641SAndroid Build Coastguard Worker // 166*635a8641SAndroid Build Coastguard Worker // If a new object implements multiple interfaces, this method will be 167*635a8641SAndroid Build Coastguard Worker // called on each interface implementation with differing values of 168*635a8641SAndroid Build Coastguard Worker // |interface_name| as appropriate. An implementation class will only 169*635a8641SAndroid Build Coastguard Worker // receive multiple calls if it has registered for multiple interfaces. ObjectAdded(const ObjectPath & object_path,const std::string & interface_name)170*635a8641SAndroid Build Coastguard Worker virtual void ObjectAdded(const ObjectPath& object_path, 171*635a8641SAndroid Build Coastguard Worker const std::string& interface_name) { } 172*635a8641SAndroid Build Coastguard Worker 173*635a8641SAndroid Build Coastguard Worker // Called by ObjectManager to inform the implementation class than an 174*635a8641SAndroid Build Coastguard Worker // object with the path |object_path| has been removed. Ths D-Bus interface 175*635a8641SAndroid Build Coastguard Worker // name |interface_name| is that passed to RegisterInterface() by the 176*635a8641SAndroid Build Coastguard Worker // implementation class. Multiple interfaces are handled as with 177*635a8641SAndroid Build Coastguard Worker // ObjectAdded(). 178*635a8641SAndroid Build Coastguard Worker // 179*635a8641SAndroid Build Coastguard Worker // This method will be called before the Properties structure and the 180*635a8641SAndroid Build Coastguard Worker // ObjectProxy object for the given interface are cleaned up, it is safe 181*635a8641SAndroid Build Coastguard Worker // to retrieve them during removal to vary processing. ObjectRemoved(const ObjectPath & object_path,const std::string & interface_name)182*635a8641SAndroid Build Coastguard Worker virtual void ObjectRemoved(const ObjectPath& object_path, 183*635a8641SAndroid Build Coastguard Worker const std::string& interface_name) { } 184*635a8641SAndroid Build Coastguard Worker }; 185*635a8641SAndroid Build Coastguard Worker 186*635a8641SAndroid Build Coastguard Worker // Client code should use Bus::GetObjectManager() instead of this constructor. 187*635a8641SAndroid Build Coastguard Worker ObjectManager(Bus* bus, 188*635a8641SAndroid Build Coastguard Worker const std::string& service_name, 189*635a8641SAndroid Build Coastguard Worker const ObjectPath& object_path); 190*635a8641SAndroid Build Coastguard Worker 191*635a8641SAndroid Build Coastguard Worker // Register a client implementation class |interface| for the given D-Bus 192*635a8641SAndroid Build Coastguard Worker // interface named in |interface_name|. That object's CreateProperties() 193*635a8641SAndroid Build Coastguard Worker // method will be used to create instances of dbus::PropertySet* when 194*635a8641SAndroid Build Coastguard Worker // required. 195*635a8641SAndroid Build Coastguard Worker virtual void RegisterInterface(const std::string& interface_name, 196*635a8641SAndroid Build Coastguard Worker Interface* interface); 197*635a8641SAndroid Build Coastguard Worker 198*635a8641SAndroid Build Coastguard Worker // Unregister the implementation class for the D-Bus interface named in 199*635a8641SAndroid Build Coastguard Worker // |interface_name|, objects and properties of this interface will be 200*635a8641SAndroid Build Coastguard Worker // ignored. 201*635a8641SAndroid Build Coastguard Worker virtual void UnregisterInterface(const std::string& interface_name); 202*635a8641SAndroid Build Coastguard Worker 203*635a8641SAndroid Build Coastguard Worker // Returns a list of object paths, in an undefined order, of objects known 204*635a8641SAndroid Build Coastguard Worker // to this manager. 205*635a8641SAndroid Build Coastguard Worker virtual std::vector<ObjectPath> GetObjects(); 206*635a8641SAndroid Build Coastguard Worker 207*635a8641SAndroid Build Coastguard Worker // Returns the list of object paths, in an undefined order, of objects 208*635a8641SAndroid Build Coastguard Worker // implementing the interface named in |interface_name| known to this manager. 209*635a8641SAndroid Build Coastguard Worker virtual std::vector<ObjectPath> GetObjectsWithInterface( 210*635a8641SAndroid Build Coastguard Worker const std::string& interface_name); 211*635a8641SAndroid Build Coastguard Worker 212*635a8641SAndroid Build Coastguard Worker // Returns a ObjectProxy pointer for the given |object_path|. Unlike 213*635a8641SAndroid Build Coastguard Worker // the equivalent method on Bus this will return NULL if the object 214*635a8641SAndroid Build Coastguard Worker // manager has not been informed of that object's existence. 215*635a8641SAndroid Build Coastguard Worker virtual ObjectProxy* GetObjectProxy(const ObjectPath& object_path); 216*635a8641SAndroid Build Coastguard Worker 217*635a8641SAndroid Build Coastguard Worker // Returns a PropertySet* pointer for the given |object_path| and 218*635a8641SAndroid Build Coastguard Worker // |interface_name|, or NULL if the object manager has not been informed of 219*635a8641SAndroid Build Coastguard Worker // that object's existence or the interface's properties. The caller should 220*635a8641SAndroid Build Coastguard Worker // cast the returned pointer to the appropriate type, e.g.: 221*635a8641SAndroid Build Coastguard Worker // static_cast<Properties*>(GetProperties(object_path, my_interface)); 222*635a8641SAndroid Build Coastguard Worker virtual PropertySet* GetProperties(const ObjectPath& object_path, 223*635a8641SAndroid Build Coastguard Worker const std::string& interface_name); 224*635a8641SAndroid Build Coastguard Worker 225*635a8641SAndroid Build Coastguard Worker // Instructs the object manager to refresh its list of managed objects; 226*635a8641SAndroid Build Coastguard Worker // automatically called by the D-Bus thread manager, there should never be 227*635a8641SAndroid Build Coastguard Worker // a need to call this manually. 228*635a8641SAndroid Build Coastguard Worker void GetManagedObjects(); 229*635a8641SAndroid Build Coastguard Worker 230*635a8641SAndroid Build Coastguard Worker // Cleans up any match rules and filter functions added by this ObjectManager. 231*635a8641SAndroid Build Coastguard Worker // The Bus object will take care of this so you don't have to do it manually. 232*635a8641SAndroid Build Coastguard Worker // 233*635a8641SAndroid Build Coastguard Worker // BLOCKING CALL. 234*635a8641SAndroid Build Coastguard Worker void CleanUp(); 235*635a8641SAndroid Build Coastguard Worker 236*635a8641SAndroid Build Coastguard Worker protected: 237*635a8641SAndroid Build Coastguard Worker virtual ~ObjectManager(); 238*635a8641SAndroid Build Coastguard Worker 239*635a8641SAndroid Build Coastguard Worker private: 240*635a8641SAndroid Build Coastguard Worker friend class base::RefCountedThreadSafe<ObjectManager>; 241*635a8641SAndroid Build Coastguard Worker 242*635a8641SAndroid Build Coastguard Worker // Called from the constructor to add a match rule for PropertiesChanged 243*635a8641SAndroid Build Coastguard Worker // signals on the D-Bus thread and set up a corresponding filter function. 244*635a8641SAndroid Build Coastguard Worker bool SetupMatchRuleAndFilter(); 245*635a8641SAndroid Build Coastguard Worker 246*635a8641SAndroid Build Coastguard Worker // Called on the origin thread once the match rule and filter have been set 247*635a8641SAndroid Build Coastguard Worker // up. Connects the InterfacesAdded and InterfacesRemoved signals and 248*635a8641SAndroid Build Coastguard Worker // refreshes objects if the service is available. |success| is false if an 249*635a8641SAndroid Build Coastguard Worker // error occurred during setup and true otherwise. 250*635a8641SAndroid Build Coastguard Worker void OnSetupMatchRuleAndFilterComplete(bool success); 251*635a8641SAndroid Build Coastguard Worker 252*635a8641SAndroid Build Coastguard Worker // Called by dbus:: when a message is received. This is used to filter 253*635a8641SAndroid Build Coastguard Worker // PropertiesChanged signals from the correct sender and relay the event to 254*635a8641SAndroid Build Coastguard Worker // the correct PropertySet. 255*635a8641SAndroid Build Coastguard Worker static DBusHandlerResult HandleMessageThunk(DBusConnection* connection, 256*635a8641SAndroid Build Coastguard Worker DBusMessage* raw_message, 257*635a8641SAndroid Build Coastguard Worker void* user_data); 258*635a8641SAndroid Build Coastguard Worker DBusHandlerResult HandleMessage(DBusConnection* connection, 259*635a8641SAndroid Build Coastguard Worker DBusMessage* raw_message); 260*635a8641SAndroid Build Coastguard Worker 261*635a8641SAndroid Build Coastguard Worker // Called when a PropertiesChanged signal is received from the sender. 262*635a8641SAndroid Build Coastguard Worker // This method notifies the relevant PropertySet that it should update its 263*635a8641SAndroid Build Coastguard Worker // properties based on the received signal. Called from HandleMessage. 264*635a8641SAndroid Build Coastguard Worker void NotifyPropertiesChanged(const dbus::ObjectPath object_path, 265*635a8641SAndroid Build Coastguard Worker Signal* signal); 266*635a8641SAndroid Build Coastguard Worker void NotifyPropertiesChangedHelper(const dbus::ObjectPath object_path, 267*635a8641SAndroid Build Coastguard Worker Signal* signal); 268*635a8641SAndroid Build Coastguard Worker 269*635a8641SAndroid Build Coastguard Worker // Called by dbus:: in response to the GetManagedObjects() method call. 270*635a8641SAndroid Build Coastguard Worker void OnGetManagedObjects(Response* response); 271*635a8641SAndroid Build Coastguard Worker 272*635a8641SAndroid Build Coastguard Worker // Called by dbus:: when an InterfacesAdded signal is received and initially 273*635a8641SAndroid Build Coastguard Worker // connected. 274*635a8641SAndroid Build Coastguard Worker void InterfacesAddedReceived(Signal* signal); 275*635a8641SAndroid Build Coastguard Worker void InterfacesAddedConnected(const std::string& interface_name, 276*635a8641SAndroid Build Coastguard Worker const std::string& signal_name, 277*635a8641SAndroid Build Coastguard Worker bool success); 278*635a8641SAndroid Build Coastguard Worker 279*635a8641SAndroid Build Coastguard Worker // Called by dbus:: when an InterfacesRemoved signal is received and 280*635a8641SAndroid Build Coastguard Worker // initially connected. 281*635a8641SAndroid Build Coastguard Worker void InterfacesRemovedReceived(Signal* signal); 282*635a8641SAndroid Build Coastguard Worker void InterfacesRemovedConnected(const std::string& interface_name, 283*635a8641SAndroid Build Coastguard Worker const std::string& signal_name, 284*635a8641SAndroid Build Coastguard Worker bool success); 285*635a8641SAndroid Build Coastguard Worker 286*635a8641SAndroid Build Coastguard Worker // Updates the map entry for the object with path |object_path| using the 287*635a8641SAndroid Build Coastguard Worker // D-Bus message in |reader|, which should consist of an dictionary mapping 288*635a8641SAndroid Build Coastguard Worker // interface names to properties dictionaries as recieved by both the 289*635a8641SAndroid Build Coastguard Worker // GetManagedObjects() method return and the InterfacesAdded() signal. 290*635a8641SAndroid Build Coastguard Worker void UpdateObject(const ObjectPath& object_path, MessageReader* reader); 291*635a8641SAndroid Build Coastguard Worker 292*635a8641SAndroid Build Coastguard Worker // Updates the properties structure of the object with path |object_path| 293*635a8641SAndroid Build Coastguard Worker // for the interface named |interface_name| using the D-Bus message in 294*635a8641SAndroid Build Coastguard Worker // |reader| which should consist of the properties dictionary for that 295*635a8641SAndroid Build Coastguard Worker // interface. 296*635a8641SAndroid Build Coastguard Worker // 297*635a8641SAndroid Build Coastguard Worker // Called by UpdateObjects() for each interface in the dictionary; this 298*635a8641SAndroid Build Coastguard Worker // method takes care of both creating the entry in the ObjectMap and 299*635a8641SAndroid Build Coastguard Worker // ObjectProxy if required, as well as the PropertySet instance for that 300*635a8641SAndroid Build Coastguard Worker // interface if necessary. 301*635a8641SAndroid Build Coastguard Worker void AddInterface(const ObjectPath& object_path, 302*635a8641SAndroid Build Coastguard Worker const std::string& interface_name, 303*635a8641SAndroid Build Coastguard Worker MessageReader* reader); 304*635a8641SAndroid Build Coastguard Worker 305*635a8641SAndroid Build Coastguard Worker // Removes the properties structure of the object with path |object_path| 306*635a8641SAndroid Build Coastguard Worker // for the interfaces named |interface_name|. 307*635a8641SAndroid Build Coastguard Worker // 308*635a8641SAndroid Build Coastguard Worker // If no further interfaces remain, the entry in the ObjectMap is discarded. 309*635a8641SAndroid Build Coastguard Worker void RemoveInterface(const ObjectPath& object_path, 310*635a8641SAndroid Build Coastguard Worker const std::string& interface_name); 311*635a8641SAndroid Build Coastguard Worker 312*635a8641SAndroid Build Coastguard Worker // Removes all objects and interfaces from the object manager when 313*635a8641SAndroid Build Coastguard Worker // |old_owner| is not the empty string and/or re-requests the set of managed 314*635a8641SAndroid Build Coastguard Worker // objects when |new_owner| is not the empty string. 315*635a8641SAndroid Build Coastguard Worker void NameOwnerChanged(const std::string& old_owner, 316*635a8641SAndroid Build Coastguard Worker const std::string& new_owner); 317*635a8641SAndroid Build Coastguard Worker 318*635a8641SAndroid Build Coastguard Worker Bus* bus_; 319*635a8641SAndroid Build Coastguard Worker std::string service_name_; 320*635a8641SAndroid Build Coastguard Worker std::string service_name_owner_; 321*635a8641SAndroid Build Coastguard Worker std::string match_rule_; 322*635a8641SAndroid Build Coastguard Worker ObjectPath object_path_; 323*635a8641SAndroid Build Coastguard Worker ObjectProxy* object_proxy_; 324*635a8641SAndroid Build Coastguard Worker bool setup_success_; 325*635a8641SAndroid Build Coastguard Worker bool cleanup_called_; 326*635a8641SAndroid Build Coastguard Worker 327*635a8641SAndroid Build Coastguard Worker // Maps the name of an interface to the implementation class used for 328*635a8641SAndroid Build Coastguard Worker // instantiating PropertySet structures for that interface's properties. 329*635a8641SAndroid Build Coastguard Worker typedef std::map<std::string, Interface*> InterfaceMap; 330*635a8641SAndroid Build Coastguard Worker InterfaceMap interface_map_; 331*635a8641SAndroid Build Coastguard Worker 332*635a8641SAndroid Build Coastguard Worker // Each managed object consists of a ObjectProxy used to make calls 333*635a8641SAndroid Build Coastguard Worker // against that object and a collection of D-Bus interface names and their 334*635a8641SAndroid Build Coastguard Worker // associated PropertySet structures. 335*635a8641SAndroid Build Coastguard Worker struct Object { 336*635a8641SAndroid Build Coastguard Worker Object(); 337*635a8641SAndroid Build Coastguard Worker ~Object(); 338*635a8641SAndroid Build Coastguard Worker 339*635a8641SAndroid Build Coastguard Worker ObjectProxy* object_proxy; 340*635a8641SAndroid Build Coastguard Worker 341*635a8641SAndroid Build Coastguard Worker // Maps the name of an interface to the specific PropertySet structure 342*635a8641SAndroid Build Coastguard Worker // of that interface's properties. 343*635a8641SAndroid Build Coastguard Worker typedef std::map<const std::string, PropertySet*> PropertiesMap; 344*635a8641SAndroid Build Coastguard Worker PropertiesMap properties_map; 345*635a8641SAndroid Build Coastguard Worker }; 346*635a8641SAndroid Build Coastguard Worker 347*635a8641SAndroid Build Coastguard Worker // Maps the object path of an object to the Object structure. 348*635a8641SAndroid Build Coastguard Worker typedef std::map<const ObjectPath, Object*> ObjectMap; 349*635a8641SAndroid Build Coastguard Worker ObjectMap object_map_; 350*635a8641SAndroid Build Coastguard Worker 351*635a8641SAndroid Build Coastguard Worker // Weak pointer factory for generating 'this' pointers that might live longer 352*635a8641SAndroid Build Coastguard Worker // than we do. 353*635a8641SAndroid Build Coastguard Worker // Note: This should remain the last member so it'll be destroyed and 354*635a8641SAndroid Build Coastguard Worker // invalidate its weak pointers before any other members are destroyed. 355*635a8641SAndroid Build Coastguard Worker base::WeakPtrFactory<ObjectManager> weak_ptr_factory_; 356*635a8641SAndroid Build Coastguard Worker 357*635a8641SAndroid Build Coastguard Worker DISALLOW_COPY_AND_ASSIGN(ObjectManager); 358*635a8641SAndroid Build Coastguard Worker }; 359*635a8641SAndroid Build Coastguard Worker 360*635a8641SAndroid Build Coastguard Worker } // namespace dbus 361*635a8641SAndroid Build Coastguard Worker 362*635a8641SAndroid Build Coastguard Worker #endif // DBUS_OBJECT_MANAGER_H_ 363