xref: /aosp_15_r20/external/libchrome/dbus/object_path.h (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1*635a8641SAndroid Build Coastguard Worker // Copyright (c) 2012 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_PATH_H_
6*635a8641SAndroid Build Coastguard Worker #define DBUS_OBJECT_PATH_H_
7*635a8641SAndroid Build Coastguard Worker 
8*635a8641SAndroid Build Coastguard Worker #include <iosfwd>
9*635a8641SAndroid Build Coastguard Worker #include <string>
10*635a8641SAndroid Build Coastguard Worker 
11*635a8641SAndroid Build Coastguard Worker #include "dbus/dbus_export.h"
12*635a8641SAndroid Build Coastguard Worker 
13*635a8641SAndroid Build Coastguard Worker namespace dbus {
14*635a8641SAndroid Build Coastguard Worker 
15*635a8641SAndroid Build Coastguard Worker // ObjectPath is a type used to distinguish D-Bus object paths from simple
16*635a8641SAndroid Build Coastguard Worker // strings, especially since normal practice is that these should be only
17*635a8641SAndroid Build Coastguard Worker // initialized from static constants or obtained from remote objects and no
18*635a8641SAndroid Build Coastguard Worker // assumptions about their value made.
19*635a8641SAndroid Build Coastguard Worker class CHROME_DBUS_EXPORT ObjectPath {
20*635a8641SAndroid Build Coastguard Worker  public:
21*635a8641SAndroid Build Coastguard Worker   // Permit initialization without a value for passing to
22*635a8641SAndroid Build Coastguard Worker   // dbus::MessageReader::PopObjectPath to fill in and from std::string
23*635a8641SAndroid Build Coastguard Worker   // objects.
24*635a8641SAndroid Build Coastguard Worker   //
25*635a8641SAndroid Build Coastguard Worker   // The compiler synthesised copy constructor and assignment operator are
26*635a8641SAndroid Build Coastguard Worker   // sufficient for our needs, as is implicit initialization of a std::string
27*635a8641SAndroid Build Coastguard Worker   // from a string constant.
ObjectPath()28*635a8641SAndroid Build Coastguard Worker   ObjectPath() {}
ObjectPath(const std::string & value)29*635a8641SAndroid Build Coastguard Worker   explicit ObjectPath(const std::string& value) : value_(value) {}
30*635a8641SAndroid Build Coastguard Worker 
31*635a8641SAndroid Build Coastguard Worker   // Retrieves value as a std::string.
value()32*635a8641SAndroid Build Coastguard Worker   const std::string& value() const { return value_; }
33*635a8641SAndroid Build Coastguard Worker 
34*635a8641SAndroid Build Coastguard Worker   // Returns true if the value is a valid object path.
35*635a8641SAndroid Build Coastguard Worker   bool IsValid() const;
36*635a8641SAndroid Build Coastguard Worker 
37*635a8641SAndroid Build Coastguard Worker   // Permit sufficient comparison to allow an ObjectPath to be used as a
38*635a8641SAndroid Build Coastguard Worker   // key in a std::map.
39*635a8641SAndroid Build Coastguard Worker   bool operator<(const ObjectPath&) const;
40*635a8641SAndroid Build Coastguard Worker 
41*635a8641SAndroid Build Coastguard Worker   // Permit testing for equality, required for mocks to work and useful for
42*635a8641SAndroid Build Coastguard Worker   // observers.
43*635a8641SAndroid Build Coastguard Worker   bool operator==(const ObjectPath&) const;
44*635a8641SAndroid Build Coastguard Worker   bool operator!=(const ObjectPath&) const;
45*635a8641SAndroid Build Coastguard Worker 
46*635a8641SAndroid Build Coastguard Worker  private:
47*635a8641SAndroid Build Coastguard Worker   std::string value_;
48*635a8641SAndroid Build Coastguard Worker };
49*635a8641SAndroid Build Coastguard Worker 
50*635a8641SAndroid Build Coastguard Worker // This is required by gtest to print a readable output on test failures.
51*635a8641SAndroid Build Coastguard Worker CHROME_DBUS_EXPORT void PrintTo(const ObjectPath& path, std::ostream* out);
52*635a8641SAndroid Build Coastguard Worker 
53*635a8641SAndroid Build Coastguard Worker }  // namespace dbus
54*635a8641SAndroid Build Coastguard Worker 
55*635a8641SAndroid Build Coastguard Worker #endif  // DBUS_OBJECT_PATH_H_
56