Merge lp:~thomas-voss/dbus-cpp/add_caching_for_objects into lp:dbus-cpp

Proposed by Thomas Voß
Status: Needs review
Proposed branch: lp:~thomas-voss/dbus-cpp/add_caching_for_objects
Merge into: lp:dbus-cpp
Diff against target: 182 lines (+68/-6)
6 files modified
debian/libdbus-cpp1.symbols (+13/-0)
include/core/dbus/impl/object.h (+10/-0)
include/core/dbus/object.h (+12/-1)
include/core/dbus/service.h (+2/-0)
src/core/dbus/service.cpp (+13/-1)
tests/service_test.cpp (+18/-4)
To merge this branch: bzr merge lp:~thomas-voss/dbus-cpp/add_caching_for_objects
Reviewer Review Type Date Requested Status
Antti Kaijanmäki (community) Approve
PS Jenkins bot continuous-integration Needs Fixing
Review via email: mp+204436@code.launchpad.net

Commit message

Add test for caching on service skeletons.
Add caching for Objects.

Description of the change

Add test for caching on service skeletons.
Add caching for Objects.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Pete Woods (pete-woods) wrote :

Please wait until I've merged the other branch for, or I will abandon all hope.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Antti Kaijanmäki (kaijanmaki) wrote :

LGTM.

review: Approve
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

is this going to land?

Unmerged revisions

43. By Thomas Voß

Adjust symbols file.

42. By Thomas Voß

Add test for caching on service skeletons.

41. By Thomas Voß

Add caching for Objects.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/libdbus-cpp1.symbols'
2--- debian/libdbus-cpp1.symbols 2014-01-30 09:03:22 +0000
3+++ debian/libdbus-cpp1.symbols 2014-02-03 10:59:04 +0000
4@@ -1,4 +1,17 @@
5 libdbus-cpp.so.1 libdbus-cpp1 #MINVER#
6+ (c++)"std::function<void ()>::operator()() const@Base" 0replaceme
7+ (c++)"std::function<void (std::function<void (std::function<void ()> const&)> const&)>::function(std::function<void (std::function<void (std::function<void ()> const&)> const&)> const&)@Base" 0replaceme
8+ (c++)"std::function<void (std::function<void (std::function<void ()> const&)> const&)>::function(std::function<void (std::function<void (std::function<void ()> const&)> const&)> const&)@Base" 0replaceme
9+ (c++)"std::function<void (std::function<void (std::function<void ()> const&)> const&)>::~function()@Base" 0replaceme
10+ (c++)"std::function<void (std::function<void (std::function<void ()> const&)> const&)>::~function()@Base" 0replaceme
11+ (c++)"std::function<void (std::function<void ()> const&)>::function(std::function<void (std::function<void ()> const&)> const&)@Base" 0replaceme
12+ (c++)"std::function<void (std::function<void ()> const&)>::function(std::function<void (std::function<void ()> const&)> const&)@Base" 0replaceme
13+ (c++)"std::function<void (std::function<void ()> const&)>::~function()@Base" 0replaceme
14+ (c++)"std::function<void (std::function<void ()> const&)>::~function()@Base" 0replaceme
15+ (c++)"std::function<void ()>::function(std::function<void ()> const&)@Base" 0replaceme
16+ (c++)"std::function<void ()>::function(std::function<void ()> const&)@Base" 0replaceme
17+ (c++)"std::function<void ()>::~function()@Base" 0replaceme
18+ (c++)"std::function<void ()>::~function()@Base" 0replaceme
19 (c++)"core::dbus::Fixture::default_system_bus_config_file()@Base" 1.0.0+14.04.20140123
20 (c++)"core::dbus::Fixture::default_session_bus_config_file()@Base" 1.0.0+14.04.20140123
21 (c++)"guard variable for core::dbus::DBus::GetConnectionUnixUser::name()::s@Base" 1.0.0+14.04.20140123
22
23=== modified file 'include/core/dbus/impl/object.h'
24--- include/core/dbus/impl/object.h 2014-01-23 07:28:52 +0000
25+++ include/core/dbus/impl/object.h 2014-02-03 10:59:04 +0000
26@@ -300,6 +300,16 @@
27 }
28 }
29
30+inline Object::~Object()
31+{
32+ signal_about_to_be_destroyed();
33+}
34+
35+inline const core::Signal<void>& Object::about_to_be_destroyed() const
36+{
37+ return signal_about_to_be_destroyed;
38+}
39+
40 inline void Object::add_match(const MatchRule& rule)
41 {
42 parent->add_match(rule.path(object_path));
43
44=== modified file 'include/core/dbus/object.h'
45--- include/core/dbus/object.h 2014-01-23 09:15:34 +0000
46+++ include/core/dbus/object.h 2014-02-03 10:59:04 +0000
47@@ -62,6 +62,9 @@
48 {
49 namespace dbus
50 {
51+template<typename T>
52+struct LifetimeConstraintTraits;
53+
54 namespace types
55 {
56 class Any;
57@@ -90,6 +93,8 @@
58 typedef std::shared_ptr<Object> Ptr;
59 typedef std::function<void(const Message::Ptr&)> MethodHandler;
60
61+ ~Object();
62+
63 /**
64 * @brief Emits a signal with arguments for this object.
65 */
66@@ -182,18 +187,24 @@
67 */
68 inline const types::ObjectPath& path() const;
69
70- private:
71+private:
72+ template<typename T>
73+ friend struct LifetimeConstraintTraits;
74 friend class Service;
75 template<typename T, typename U> friend class Signal;
76 template<typename T> friend class Property;
77
78 Object(const std::shared_ptr<Service> parent, const types::ObjectPath& path);
79
80+ const core::Signal<void>& about_to_be_destroyed() const;
81+
82 void add_match(const MatchRule& rule);
83 void remove_match(const MatchRule& rule);
84 void on_properties_changed(
85 const interfaces::Properties::Signals::PropertiesChanged::ArgumentType&);
86
87+
88+ core::Signal<void> signal_about_to_be_destroyed;
89 std::shared_ptr<Service> parent;
90 types::ObjectPath object_path;
91 MessageRouter<SignalKey> signal_router;
92
93=== modified file 'include/core/dbus/service.h'
94--- include/core/dbus/service.h 2013-11-27 18:57:42 +0000
95+++ include/core/dbus/service.h 2014-02-03 10:59:04 +0000
96@@ -23,6 +23,7 @@
97 #include <core/dbus/match_rule.h>
98 #include <core/dbus/message_router.h>
99 #include <core/dbus/result.h>
100+#include <core/dbus/lifetime_constrained_cache.h>
101 #include <core/dbus/visibility.h>
102
103 #include <core/dbus/interfaces/properties.h>
104@@ -153,6 +154,7 @@
105 Bus::Ptr connection;
106 std::string name;
107 std::shared_ptr<Object> root;
108+ ThreadSafeLifetimeConstrainedCache<types::ObjectPath, Object> object_cache;
109 bool stub;
110 };
111 }
112
113=== modified file 'src/core/dbus/service.cpp'
114--- src/core/dbus/service.cpp 2014-01-22 07:44:11 +0000
115+++ src/core/dbus/service.cpp 2014-02-03 10:59:04 +0000
116@@ -111,13 +111,25 @@
117
118 std::shared_ptr<Object> Service::object_for_path(const types::ObjectPath& path)
119 {
120- return std::shared_ptr<Object>(new Object(shared_from_this(), path));
121+ if (object_cache.has_value_for_key(path))
122+ return object_cache.retrieve_value_for_key(path);
123+
124+ auto object = std::shared_ptr<Object>(new Object(shared_from_this(), path));
125+
126+ object_cache.insert_value_for_key(path, object);
127+
128+ return object;
129 }
130
131 std::shared_ptr<Object> Service::add_object_for_path(const types::ObjectPath& path)
132 {
133+ if (object_cache.has_value_for_key(path))
134+ return object_cache.retrieve_value_for_key(path);
135+
136 auto object = std::shared_ptr<Object>(new Object(shared_from_this(), path));
137
138+ object_cache.insert_value_for_key(path, object);
139+
140 connection->register_object_for_path(path, object);
141
142 return object;
143
144=== modified file 'tests/service_test.cpp'
145--- tests/service_test.cpp 2014-01-14 15:19:46 +0000
146+++ tests/service_test.cpp 2014-02-03 10:59:04 +0000
147@@ -145,10 +145,6 @@
148
149 TEST_F(Service, AddingANonExistingServiceDoesNotThrow)
150 {
151- const std::string service_name
152- {
153- "very.unlikely.that.this.name.exists"
154- };
155 ASSERT_NO_THROW(auto service = dbus::Service::add_service<test::Service>(session_bus()););
156 }
157
158@@ -162,6 +158,24 @@
159 ASSERT_ANY_THROW(auto service = dbus::Service::add_service<dbus::DBus>(session_bus(), flags););
160 }
161
162+TEST_F(Service, ObjectCreationOnStubIsCached)
163+{
164+ auto service = dbus::Service::use_service<dbus::DBus>(session_bus());
165+
166+ dbus::types::ObjectPath path{"/does/not/exist"};
167+ auto object = service->object_for_path(path);
168+ EXPECT_EQ(object, service->object_for_path(path));
169+}
170+
171+TEST_F(Service, ObjectCreationOnSkeletonIsCached)
172+{
173+ auto service = dbus::Service::add_service<test::Service>(session_bus());
174+
175+ dbus::types::ObjectPath path{"/does/not/exist"};
176+ auto object = service->add_object_for_path(path);
177+ EXPECT_EQ(object, service->add_object_for_path(path));
178+}
179+
180 TEST(VoidResult, DefaultConstructionYieldsANonErrorResult)
181 {
182 dbus::Result<void> result;

Subscribers

People subscribed via source and target branches