Merge lp:~charlesk/indicator-datetime/timezone-class-privacy into lp:indicator-datetime/13.10
- timezone-class-privacy
- Merge into trunk.14.10
Status: | Merged |
---|---|
Approved by: | Ted Gould |
Approved revision: | 378 |
Merged at revision: | 379 |
Proposed branch: | lp:~charlesk/indicator-datetime/timezone-class-privacy |
Merge into: | lp:indicator-datetime/13.10 |
Diff against target: |
798 lines (+368/-319) 6 files modified
include/datetime/clock.h (+0/-2) include/datetime/timezone-file.h (+5/-14) include/datetime/timezone-geoclue.h (+4/-20) src/timezone-file.cpp (+110/-77) src/timezone-geoclue.cpp (+247/-206) src/wakeup-timer-powerd.cpp (+2/-0) |
To merge this branch: | bzr merge lp:~charlesk/indicator-datetime/timezone-class-privacy |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot (community) | continuous-integration | Approve | |
Ted Gould (community) | Approve | ||
Review via email:
|
Commit message
Move timezone code behind a private Impl class
Description of the change
Simple cleanup done while working on other bugfixes.
This doesn't change the behavior of any code; just moves the implementation details of GeoclueTimezone and FileTimezone into private Impl classes.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Ted Gould (ted) : | # |
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Ted Gould (ted) wrote : | # |
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:378
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'include/datetime/clock.h' | |||
2 | --- include/datetime/clock.h 2014-09-13 18:12:04 +0000 | |||
3 | +++ include/datetime/clock.h 2014-09-16 22:48:45 +0000 | |||
4 | @@ -25,8 +25,6 @@ | |||
5 | 25 | #include <core/property.h> | 25 | #include <core/property.h> |
6 | 26 | #include <core/signal.h> | 26 | #include <core/signal.h> |
7 | 27 | 27 | ||
8 | 28 | #include <gio/gio.h> // GDBusConnection | ||
9 | 29 | |||
10 | 30 | #include <memory> // std::shared_ptr, std::unique_ptr | 28 | #include <memory> // std::shared_ptr, std::unique_ptr |
11 | 31 | 29 | ||
12 | 32 | namespace unity { | 30 | namespace unity { |
13 | 33 | 31 | ||
14 | === modified file 'include/datetime/timezone-file.h' | |||
15 | --- include/datetime/timezone-file.h 2014-02-02 21:28:52 +0000 | |||
16 | +++ include/datetime/timezone-file.h 2014-09-16 22:48:45 +0000 | |||
17 | @@ -24,9 +24,6 @@ | |||
18 | 24 | 24 | ||
19 | 25 | #include <string> // std::string | 25 | #include <string> // std::string |
20 | 26 | 26 | ||
21 | 27 | #include <glib.h> | ||
22 | 28 | #include <gio/gio.h> | ||
23 | 29 | |||
24 | 30 | namespace unity { | 27 | namespace unity { |
25 | 31 | namespace indicator { | 28 | namespace indicator { |
26 | 32 | namespace datetime { | 29 | namespace datetime { |
27 | @@ -37,21 +34,15 @@ | |||
28 | 37 | class FileTimezone: public Timezone | 34 | class FileTimezone: public Timezone |
29 | 38 | { | 35 | { |
30 | 39 | public: | 36 | public: |
31 | 40 | FileTimezone(); | ||
32 | 41 | FileTimezone(const std::string& filename); | 37 | FileTimezone(const std::string& filename); |
33 | 42 | ~FileTimezone(); | 38 | ~FileTimezone(); |
34 | 43 | 39 | ||
35 | 44 | private: | 40 | private: |
46 | 45 | void set_filename(const std::string& filename); | 41 | class Impl; |
47 | 46 | static void on_file_changed(gpointer gself); | 42 | friend Impl; |
48 | 47 | void clear(); | 43 | std::unique_ptr<Impl> impl; |
49 | 48 | void reload(); | 44 | |
50 | 49 | 45 | // we have pointers in here, so disable copying | |
41 | 50 | std::string m_filename; | ||
42 | 51 | GFileMonitor * m_monitor = nullptr; | ||
43 | 52 | unsigned long m_monitor_handler_id = 0; | ||
44 | 53 | |||
45 | 54 | // we have raw pointers and glib tags in here, so disable copying | ||
51 | 55 | FileTimezone(const FileTimezone&) =delete; | 46 | FileTimezone(const FileTimezone&) =delete; |
52 | 56 | FileTimezone& operator=(const FileTimezone&) =delete; | 47 | FileTimezone& operator=(const FileTimezone&) =delete; |
53 | 57 | }; | 48 | }; |
54 | 58 | 49 | ||
55 | === modified file 'include/datetime/timezone-geoclue.h' | |||
56 | --- include/datetime/timezone-geoclue.h 2014-01-15 05:07:10 +0000 | |||
57 | +++ include/datetime/timezone-geoclue.h 2014-09-16 22:48:45 +0000 | |||
58 | @@ -22,11 +22,6 @@ | |||
59 | 22 | 22 | ||
60 | 23 | #include <datetime/timezone.h> // base class | 23 | #include <datetime/timezone.h> // base class |
61 | 24 | 24 | ||
62 | 25 | #include <string> | ||
63 | 26 | |||
64 | 27 | #include <glib.h> | ||
65 | 28 | #include <gio/gio.h> | ||
66 | 29 | |||
67 | 30 | namespace unity { | 25 | namespace unity { |
68 | 31 | namespace indicator { | 26 | namespace indicator { |
69 | 32 | namespace datetime { | 27 | namespace datetime { |
70 | @@ -41,21 +36,10 @@ | |||
71 | 41 | ~GeoclueTimezone(); | 36 | ~GeoclueTimezone(); |
72 | 42 | 37 | ||
73 | 43 | private: | 38 | private: |
89 | 44 | static void on_bus_got (GObject*, GAsyncResult*, gpointer); | 39 | struct Impl; |
90 | 45 | static void on_client_created (GObject*, GAsyncResult*, gpointer); | 40 | std::unique_ptr<Impl> impl; |
91 | 46 | static void on_address_changed (GDBusConnection*, const gchar*, const gchar*, const gchar*, const gchar*, GVariant*, gpointer); | 41 | |
92 | 47 | static void on_requirements_set (GObject*, GAsyncResult*, gpointer); | 42 | // we've got pointers in here, so don't allow copying |
78 | 48 | static void on_address_started (GObject*, GAsyncResult*, gpointer); | ||
79 | 49 | static void on_address_got (GObject*, GAsyncResult*, gpointer); | ||
80 | 50 | void setTimezoneFromAddressVariant (GVariant*); | ||
81 | 51 | static GVariant * call_finish (GObject*, GAsyncResult*); | ||
82 | 52 | |||
83 | 53 | GCancellable * m_cancellable = nullptr; | ||
84 | 54 | GDBusConnection * m_connection = nullptr; | ||
85 | 55 | std::string m_client_object_path; | ||
86 | 56 | guint m_signal_subscription = 0; | ||
87 | 57 | |||
88 | 58 | // we've got pointers and gsignal tags in here, so don't allow copying | ||
93 | 59 | GeoclueTimezone(const GeoclueTimezone&) =delete; | 43 | GeoclueTimezone(const GeoclueTimezone&) =delete; |
94 | 60 | GeoclueTimezone& operator=(const GeoclueTimezone&) =delete; | 44 | GeoclueTimezone& operator=(const GeoclueTimezone&) =delete; |
95 | 61 | }; | 45 | }; |
96 | 62 | 46 | ||
97 | === modified file 'src/timezone-file.cpp' | |||
98 | --- src/timezone-file.cpp 2014-05-05 15:06:34 +0000 | |||
99 | +++ src/timezone-file.cpp 2014-09-16 22:48:45 +0000 | |||
100 | @@ -19,11 +19,97 @@ | |||
101 | 19 | 19 | ||
102 | 20 | #include <datetime/timezone-file.h> | 20 | #include <datetime/timezone-file.h> |
103 | 21 | 21 | ||
104 | 22 | #include <gio/gio.h> | ||
105 | 23 | |||
106 | 22 | #include <cerrno> | 24 | #include <cerrno> |
107 | 23 | #include <cstdlib> | 25 | #include <cstdlib> |
108 | 24 | 26 | ||
110 | 25 | namespace | 27 | namespace unity { |
111 | 28 | namespace indicator { | ||
112 | 29 | namespace datetime { | ||
113 | 30 | |||
114 | 31 | /*** | ||
115 | 32 | **** | ||
116 | 33 | ***/ | ||
117 | 34 | |||
118 | 35 | class FileTimezone::Impl | ||
119 | 26 | { | 36 | { |
120 | 37 | public: | ||
121 | 38 | |||
122 | 39 | Impl(FileTimezone& owner, const std::string& filename): | ||
123 | 40 | m_owner(owner) | ||
124 | 41 | { | ||
125 | 42 | set_filename(filename); | ||
126 | 43 | } | ||
127 | 44 | |||
128 | 45 | ~Impl() | ||
129 | 46 | { | ||
130 | 47 | clear(); | ||
131 | 48 | } | ||
132 | 49 | |||
133 | 50 | private: | ||
134 | 51 | |||
135 | 52 | void clear() | ||
136 | 53 | { | ||
137 | 54 | if (m_monitor_handler_id) | ||
138 | 55 | g_signal_handler_disconnect(m_monitor, m_monitor_handler_id); | ||
139 | 56 | |||
140 | 57 | g_clear_object (&m_monitor); | ||
141 | 58 | |||
142 | 59 | m_filename.clear(); | ||
143 | 60 | } | ||
144 | 61 | |||
145 | 62 | void set_filename(const std::string& filename) | ||
146 | 63 | { | ||
147 | 64 | clear(); | ||
148 | 65 | |||
149 | 66 | auto tmp = realpath(filename.c_str(), nullptr); | ||
150 | 67 | if(tmp != nullptr) | ||
151 | 68 | { | ||
152 | 69 | m_filename = tmp; | ||
153 | 70 | free(tmp); | ||
154 | 71 | } | ||
155 | 72 | else | ||
156 | 73 | { | ||
157 | 74 | g_warning("Unable to resolve path '%s': %s", filename.c_str(), g_strerror(errno)); | ||
158 | 75 | m_filename = filename; // better than nothing? | ||
159 | 76 | } | ||
160 | 77 | |||
161 | 78 | auto file = g_file_new_for_path(m_filename.c_str()); | ||
162 | 79 | GError * err = nullptr; | ||
163 | 80 | m_monitor = g_file_monitor_file(file, G_FILE_MONITOR_NONE, nullptr, &err); | ||
164 | 81 | g_object_unref(file); | ||
165 | 82 | if (err) | ||
166 | 83 | { | ||
167 | 84 | g_warning("%s Unable to monitor timezone file '%s': %s", G_STRLOC, TIMEZONE_FILE, err->message); | ||
168 | 85 | g_error_free(err); | ||
169 | 86 | } | ||
170 | 87 | else | ||
171 | 88 | { | ||
172 | 89 | m_monitor_handler_id = g_signal_connect_swapped(m_monitor, "changed", G_CALLBACK(on_file_changed), this); | ||
173 | 90 | g_debug("%s Monitoring timezone file '%s'", G_STRLOC, m_filename.c_str()); | ||
174 | 91 | } | ||
175 | 92 | |||
176 | 93 | reload(); | ||
177 | 94 | } | ||
178 | 95 | |||
179 | 96 | static void on_file_changed(gpointer gself) | ||
180 | 97 | { | ||
181 | 98 | static_cast<Impl*>(gself)->reload(); | ||
182 | 99 | } | ||
183 | 100 | |||
184 | 101 | void reload() | ||
185 | 102 | { | ||
186 | 103 | const auto new_timezone = get_timezone_from_file(m_filename); | ||
187 | 104 | |||
188 | 105 | if (!new_timezone.empty()) | ||
189 | 106 | m_owner.timezone.set(new_timezone); | ||
190 | 107 | } | ||
191 | 108 | |||
192 | 109 | /*** | ||
193 | 110 | **** | ||
194 | 111 | ***/ | ||
195 | 112 | |||
196 | 27 | std::string get_timezone_from_file(const std::string& filename) | 113 | std::string get_timezone_from_file(const std::string& filename) |
197 | 28 | { | 114 | { |
198 | 29 | GError * error; | 115 | GError * error; |
199 | @@ -73,86 +159,33 @@ | |||
200 | 73 | 159 | ||
201 | 74 | return ret; | 160 | return ret; |
202 | 75 | } | 161 | } |
216 | 76 | } | 162 | |
217 | 77 | 163 | /*** | |
218 | 78 | namespace unity { | 164 | **** |
219 | 79 | namespace indicator { | 165 | ***/ |
220 | 80 | namespace datetime { | 166 | |
221 | 81 | 167 | FileTimezone & m_owner; | |
222 | 82 | FileTimezone::FileTimezone() | 168 | std::string m_filename; |
223 | 83 | { | 169 | GFileMonitor * m_monitor = nullptr; |
224 | 84 | } | 170 | unsigned long m_monitor_handler_id = 0; |
225 | 85 | 171 | }; | |
226 | 86 | FileTimezone::FileTimezone(const std::string& filename) | 172 | |
227 | 87 | { | 173 | /*** |
228 | 88 | set_filename(filename); | 174 | **** |
229 | 175 | ***/ | ||
230 | 176 | |||
231 | 177 | FileTimezone::FileTimezone(const std::string& filename): | ||
232 | 178 | impl(new Impl{*this, filename}) | ||
233 | 179 | { | ||
234 | 89 | } | 180 | } |
235 | 90 | 181 | ||
236 | 91 | FileTimezone::~FileTimezone() | 182 | FileTimezone::~FileTimezone() |
237 | 92 | { | 183 | { |
301 | 93 | clear(); | 184 | } |
302 | 94 | } | 185 | |
303 | 95 | 186 | /*** | |
304 | 96 | void | 187 | **** |
305 | 97 | FileTimezone::clear() | 188 | ***/ |
243 | 98 | { | ||
244 | 99 | if (m_monitor_handler_id) | ||
245 | 100 | g_signal_handler_disconnect(m_monitor, m_monitor_handler_id); | ||
246 | 101 | |||
247 | 102 | g_clear_object (&m_monitor); | ||
248 | 103 | |||
249 | 104 | m_filename.clear(); | ||
250 | 105 | } | ||
251 | 106 | |||
252 | 107 | void | ||
253 | 108 | FileTimezone::set_filename(const std::string& filename) | ||
254 | 109 | { | ||
255 | 110 | clear(); | ||
256 | 111 | |||
257 | 112 | auto tmp = realpath(filename.c_str(), nullptr); | ||
258 | 113 | if(tmp != nullptr) | ||
259 | 114 | { | ||
260 | 115 | m_filename = tmp; | ||
261 | 116 | free(tmp); | ||
262 | 117 | } | ||
263 | 118 | else | ||
264 | 119 | { | ||
265 | 120 | g_warning("Unable to resolve path '%s': %s", filename.c_str(), g_strerror(errno)); | ||
266 | 121 | m_filename = filename; // better than nothing? | ||
267 | 122 | } | ||
268 | 123 | |||
269 | 124 | auto file = g_file_new_for_path(m_filename.c_str()); | ||
270 | 125 | GError * err = nullptr; | ||
271 | 126 | m_monitor = g_file_monitor_file(file, G_FILE_MONITOR_NONE, nullptr, &err); | ||
272 | 127 | g_object_unref(file); | ||
273 | 128 | if (err) | ||
274 | 129 | { | ||
275 | 130 | g_warning("%s Unable to monitor timezone file '%s': %s", G_STRLOC, TIMEZONE_FILE, err->message); | ||
276 | 131 | g_error_free(err); | ||
277 | 132 | } | ||
278 | 133 | else | ||
279 | 134 | { | ||
280 | 135 | m_monitor_handler_id = g_signal_connect_swapped(m_monitor, "changed", G_CALLBACK(on_file_changed), this); | ||
281 | 136 | g_debug("%s Monitoring timezone file '%s'", G_STRLOC, m_filename.c_str()); | ||
282 | 137 | } | ||
283 | 138 | |||
284 | 139 | reload(); | ||
285 | 140 | } | ||
286 | 141 | |||
287 | 142 | void | ||
288 | 143 | FileTimezone::on_file_changed(gpointer gself) | ||
289 | 144 | { | ||
290 | 145 | static_cast<FileTimezone*>(gself)->reload(); | ||
291 | 146 | } | ||
292 | 147 | |||
293 | 148 | void | ||
294 | 149 | FileTimezone::reload() | ||
295 | 150 | { | ||
296 | 151 | const auto new_timezone = get_timezone_from_file(m_filename); | ||
297 | 152 | |||
298 | 153 | if (!new_timezone.empty()) | ||
299 | 154 | timezone.set(new_timezone); | ||
300 | 155 | } | ||
306 | 156 | 189 | ||
307 | 157 | } // namespace datetime | 190 | } // namespace datetime |
308 | 158 | } // namespace indicator | 191 | } // namespace indicator |
309 | 159 | 192 | ||
310 | === modified file 'src/timezone-geoclue.cpp' | |||
311 | --- src/timezone-geoclue.cpp 2014-01-15 05:07:10 +0000 | |||
312 | +++ src/timezone-geoclue.cpp 2014-09-16 22:48:45 +0000 | |||
313 | @@ -19,225 +19,266 @@ | |||
314 | 19 | 19 | ||
315 | 20 | #include <datetime/timezone-geoclue.h> | 20 | #include <datetime/timezone-geoclue.h> |
316 | 21 | 21 | ||
317 | 22 | #include <gio/gio.h> | ||
318 | 23 | |||
319 | 24 | #include <memory> | ||
320 | 25 | #include <string> | ||
321 | 26 | #include <vector> | ||
322 | 27 | |||
323 | 22 | #define GEOCLUE_BUS_NAME "org.freedesktop.Geoclue.Master" | 28 | #define GEOCLUE_BUS_NAME "org.freedesktop.Geoclue.Master" |
324 | 23 | 29 | ||
325 | 24 | namespace unity { | 30 | namespace unity { |
326 | 25 | namespace indicator { | 31 | namespace indicator { |
327 | 26 | namespace datetime { | 32 | namespace datetime { |
328 | 27 | 33 | ||
329 | 34 | class GeoclueTimezone::Impl | ||
330 | 35 | { | ||
331 | 36 | |||
332 | 37 | public: | ||
333 | 38 | |||
334 | 39 | Impl(GeoclueTimezone& owner): | ||
335 | 40 | m_owner(owner), | ||
336 | 41 | m_cancellable(g_cancellable_new()) | ||
337 | 42 | { | ||
338 | 43 | g_bus_get(G_BUS_TYPE_SESSION, m_cancellable, on_bus_got, this); | ||
339 | 44 | } | ||
340 | 45 | |||
341 | 46 | ~Impl() | ||
342 | 47 | { | ||
343 | 48 | g_cancellable_cancel(m_cancellable); | ||
344 | 49 | g_object_unref(m_cancellable); | ||
345 | 50 | g_object_unref(m_bus); | ||
346 | 51 | } | ||
347 | 52 | |||
348 | 53 | private: | ||
349 | 54 | |||
350 | 55 | void remember_subscription(GDBusConnection * bus, | ||
351 | 56 | guint tag) | ||
352 | 57 | { | ||
353 | 58 | g_object_ref(bus); | ||
354 | 59 | |||
355 | 60 | auto deleter = [tag](GDBusConnection* bus){ | ||
356 | 61 | g_dbus_connection_signal_unsubscribe(bus, tag); | ||
357 | 62 | g_object_unref(G_OBJECT(bus)); | ||
358 | 63 | }; | ||
359 | 64 | |||
360 | 65 | m_subscriptions.push_back(std::shared_ptr<GDBusConnection>(bus, deleter)); | ||
361 | 66 | } | ||
362 | 67 | |||
363 | 68 | static void on_bus_got(GObject * /*source*/, | ||
364 | 69 | GAsyncResult * res, | ||
365 | 70 | gpointer gself) | ||
366 | 71 | { | ||
367 | 72 | GError * error; | ||
368 | 73 | GDBusConnection * connection; | ||
369 | 74 | |||
370 | 75 | error = nullptr; | ||
371 | 76 | connection = g_bus_get_finish(res, &error); | ||
372 | 77 | if (error) | ||
373 | 78 | { | ||
374 | 79 | if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) | ||
375 | 80 | g_warning("Couldn't get bus: %s", error->message); | ||
376 | 81 | |||
377 | 82 | g_error_free(error); | ||
378 | 83 | } | ||
379 | 84 | else | ||
380 | 85 | { | ||
381 | 86 | auto self = static_cast<Impl*>(gself); | ||
382 | 87 | |||
383 | 88 | self->m_bus = connection; | ||
384 | 89 | |||
385 | 90 | g_dbus_connection_call(self->m_bus, | ||
386 | 91 | GEOCLUE_BUS_NAME, | ||
387 | 92 | "/org/freedesktop/Geoclue/Master", | ||
388 | 93 | "org.freedesktop.Geoclue.Master", | ||
389 | 94 | "Create", | ||
390 | 95 | nullptr, // parameters | ||
391 | 96 | G_VARIANT_TYPE("(o)"), | ||
392 | 97 | G_DBUS_CALL_FLAGS_NONE, | ||
393 | 98 | -1, | ||
394 | 99 | self->m_cancellable, | ||
395 | 100 | on_client_created, | ||
396 | 101 | self); | ||
397 | 102 | } | ||
398 | 103 | } | ||
399 | 104 | |||
400 | 105 | static void on_client_created(GObject* source, GAsyncResult* res, gpointer gself) | ||
401 | 106 | { | ||
402 | 107 | GVariant * result; | ||
403 | 108 | |||
404 | 109 | if ((result = call_finish(G_STRFUNC, source, res))) | ||
405 | 110 | { | ||
406 | 111 | auto self = static_cast<Impl*>(gself); | ||
407 | 112 | |||
408 | 113 | GVariant * child = g_variant_get_child_value(result, 0); | ||
409 | 114 | self->m_client_object_path = g_variant_get_string(child, nullptr); | ||
410 | 115 | g_variant_unref(child); | ||
411 | 116 | g_variant_unref(result); | ||
412 | 117 | |||
413 | 118 | auto tag = g_dbus_connection_signal_subscribe(self->m_bus, | ||
414 | 119 | GEOCLUE_BUS_NAME, | ||
415 | 120 | "org.freedesktop.Geoclue.Address", // interface | ||
416 | 121 | "AddressChanged", // signal name | ||
417 | 122 | self->m_client_object_path.c_str(), // object path | ||
418 | 123 | nullptr, // arg0 | ||
419 | 124 | G_DBUS_SIGNAL_FLAGS_NONE, | ||
420 | 125 | on_address_changed, | ||
421 | 126 | self, | ||
422 | 127 | nullptr); | ||
423 | 128 | self->remember_subscription(self->m_bus, tag); | ||
424 | 129 | |||
425 | 130 | g_dbus_connection_call(self->m_bus, | ||
426 | 131 | GEOCLUE_BUS_NAME, | ||
427 | 132 | self->m_client_object_path.c_str(), | ||
428 | 133 | "org.freedesktop.Geoclue.MasterClient", | ||
429 | 134 | "SetRequirements", | ||
430 | 135 | g_variant_new("(iibi)", 2, 0, FALSE, 1023), | ||
431 | 136 | nullptr, | ||
432 | 137 | G_DBUS_CALL_FLAGS_NONE, | ||
433 | 138 | -1, | ||
434 | 139 | self->m_cancellable, | ||
435 | 140 | on_requirements_set, | ||
436 | 141 | self); | ||
437 | 142 | } | ||
438 | 143 | } | ||
439 | 144 | |||
440 | 145 | static void on_address_changed(GDBusConnection* /*connection*/, | ||
441 | 146 | const gchar* /*sender_name*/, | ||
442 | 147 | const gchar* /*object_path*/, | ||
443 | 148 | const gchar* /*interface_name*/, | ||
444 | 149 | const gchar* /*signal_name*/, | ||
445 | 150 | GVariant* parameters, | ||
446 | 151 | gpointer gself) | ||
447 | 152 | { | ||
448 | 153 | static_cast<Impl*>(gself)->set_timezone_from_address_variant(parameters); | ||
449 | 154 | } | ||
450 | 155 | |||
451 | 156 | static void on_requirements_set(GObject* source, GAsyncResult* res, gpointer gself) | ||
452 | 157 | { | ||
453 | 158 | GVariant * result; | ||
454 | 159 | |||
455 | 160 | if ((result = call_finish(G_STRFUNC, source, res))) | ||
456 | 161 | { | ||
457 | 162 | auto self = static_cast<Impl*>(gself); | ||
458 | 163 | |||
459 | 164 | g_dbus_connection_call(self->m_bus, | ||
460 | 165 | GEOCLUE_BUS_NAME, | ||
461 | 166 | self->m_client_object_path.c_str(), | ||
462 | 167 | "org.freedesktop.Geoclue.MasterClient", | ||
463 | 168 | "AddressStart", | ||
464 | 169 | nullptr, | ||
465 | 170 | nullptr, | ||
466 | 171 | G_DBUS_CALL_FLAGS_NONE, | ||
467 | 172 | -1, | ||
468 | 173 | self->m_cancellable, | ||
469 | 174 | on_address_started, | ||
470 | 175 | self); | ||
471 | 176 | |||
472 | 177 | g_variant_unref(result); | ||
473 | 178 | } | ||
474 | 179 | } | ||
475 | 180 | |||
476 | 181 | static void on_address_started(GObject* source, GAsyncResult* res, gpointer gself) | ||
477 | 182 | { | ||
478 | 183 | GVariant * result; | ||
479 | 184 | |||
480 | 185 | if ((result = call_finish(G_STRFUNC, source, res))) | ||
481 | 186 | { | ||
482 | 187 | auto self = static_cast<Impl*>(gself); | ||
483 | 188 | |||
484 | 189 | g_dbus_connection_call(self->m_bus, | ||
485 | 190 | GEOCLUE_BUS_NAME, | ||
486 | 191 | self->m_client_object_path.c_str(), | ||
487 | 192 | "org.freedesktop.Geoclue.Address", | ||
488 | 193 | "GetAddress", | ||
489 | 194 | nullptr, | ||
490 | 195 | G_VARIANT_TYPE("(ia{ss}(idd))"), | ||
491 | 196 | G_DBUS_CALL_FLAGS_NONE, | ||
492 | 197 | -1, | ||
493 | 198 | self->m_cancellable, | ||
494 | 199 | on_address_got, | ||
495 | 200 | self); | ||
496 | 201 | |||
497 | 202 | g_variant_unref(result); | ||
498 | 203 | } | ||
499 | 204 | } | ||
500 | 205 | |||
501 | 206 | static void on_address_got(GObject* source, GAsyncResult* res, gpointer gself) | ||
502 | 207 | { | ||
503 | 208 | GVariant * result; | ||
504 | 209 | |||
505 | 210 | if ((result = call_finish(G_STRFUNC, source, res))) | ||
506 | 211 | { | ||
507 | 212 | static_cast<Impl*>(gself)->set_timezone_from_address_variant(result); | ||
508 | 213 | g_variant_unref(result); | ||
509 | 214 | } | ||
510 | 215 | } | ||
511 | 216 | |||
512 | 217 | /*** | ||
513 | 218 | **** | ||
514 | 219 | ***/ | ||
515 | 220 | |||
516 | 221 | void set_timezone_from_address_variant(GVariant * variant) | ||
517 | 222 | { | ||
518 | 223 | g_return_if_fail(g_variant_is_of_type(variant, G_VARIANT_TYPE("(ia{ss}(idd))"))); | ||
519 | 224 | |||
520 | 225 | const gchar * timezone_string = nullptr; | ||
521 | 226 | GVariant * dict = g_variant_get_child_value(variant, 1); | ||
522 | 227 | if (dict) | ||
523 | 228 | { | ||
524 | 229 | if (g_variant_lookup(dict, "timezone", "&s", &timezone_string)) | ||
525 | 230 | { | ||
526 | 231 | g_debug("from geoclue, setting timezone to '%s'", timezone_string); | ||
527 | 232 | m_owner.timezone.set(timezone_string); | ||
528 | 233 | } | ||
529 | 234 | |||
530 | 235 | g_variant_unref(dict); | ||
531 | 236 | } | ||
532 | 237 | } | ||
533 | 238 | |||
534 | 239 | static GVariant* call_finish(const char * funcname, GObject * source, GAsyncResult * res) | ||
535 | 240 | { | ||
536 | 241 | GError * error; | ||
537 | 242 | GVariant * result; | ||
538 | 243 | |||
539 | 244 | error = nullptr; | ||
540 | 245 | result = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), res, &error); | ||
541 | 246 | |||
542 | 247 | if (error) | ||
543 | 248 | { | ||
544 | 249 | if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) | ||
545 | 250 | g_warning("%s failed: %s", funcname, error->message); | ||
546 | 251 | |||
547 | 252 | g_error_free(error); | ||
548 | 253 | |||
549 | 254 | g_clear_pointer(&result, g_variant_unref); | ||
550 | 255 | } | ||
551 | 256 | |||
552 | 257 | return result; | ||
553 | 258 | } | ||
554 | 259 | |||
555 | 260 | /*** | ||
556 | 261 | **** | ||
557 | 262 | ***/ | ||
558 | 263 | |||
559 | 264 | GeoclueTimezone & m_owner; | ||
560 | 265 | GDBusConnection * m_bus = nullptr; | ||
561 | 266 | GCancellable * m_cancellable = nullptr; | ||
562 | 267 | std::string m_client_object_path; | ||
563 | 268 | std::vector<std::shared_ptr<GDBusConnection>> m_subscriptions; | ||
564 | 269 | }; | ||
565 | 270 | |||
566 | 271 | /**** | ||
567 | 272 | ***** | ||
568 | 273 | ****/ | ||
569 | 28 | 274 | ||
570 | 29 | GeoclueTimezone::GeoclueTimezone(): | 275 | GeoclueTimezone::GeoclueTimezone(): |
572 | 30 | m_cancellable(g_cancellable_new()) | 276 | impl(new Impl{*this}) |
573 | 31 | { | 277 | { |
574 | 32 | g_bus_get(G_BUS_TYPE_SESSION, m_cancellable, on_bus_got, this); | ||
575 | 33 | } | 278 | } |
576 | 34 | 279 | ||
577 | 35 | GeoclueTimezone::~GeoclueTimezone() | 280 | GeoclueTimezone::~GeoclueTimezone() |
578 | 36 | { | 281 | { |
579 | 37 | g_cancellable_cancel(m_cancellable); | ||
580 | 38 | g_object_unref(m_cancellable); | ||
581 | 39 | |||
582 | 40 | if (m_signal_subscription) | ||
583 | 41 | g_dbus_connection_signal_unsubscribe(m_connection, m_signal_subscription); | ||
584 | 42 | |||
585 | 43 | g_object_unref(m_connection); | ||
586 | 44 | } | ||
587 | 45 | |||
588 | 46 | /*** | ||
589 | 47 | **** | ||
590 | 48 | ***/ | ||
591 | 49 | |||
592 | 50 | void | ||
593 | 51 | GeoclueTimezone::on_bus_got(GObject* /*source*/, | ||
594 | 52 | GAsyncResult* res, | ||
595 | 53 | gpointer gself) | ||
596 | 54 | { | ||
597 | 55 | GError * error; | ||
598 | 56 | GDBusConnection * connection; | ||
599 | 57 | |||
600 | 58 | error = nullptr; | ||
601 | 59 | connection = g_bus_get_finish(res, &error); | ||
602 | 60 | if (error) | ||
603 | 61 | { | ||
604 | 62 | if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) | ||
605 | 63 | g_warning("Couldn't get bus: %s", error->message); | ||
606 | 64 | |||
607 | 65 | g_error_free(error); | ||
608 | 66 | } | ||
609 | 67 | else | ||
610 | 68 | { | ||
611 | 69 | auto self = static_cast<GeoclueTimezone*>(gself); | ||
612 | 70 | |||
613 | 71 | self->m_connection = connection; | ||
614 | 72 | |||
615 | 73 | g_dbus_connection_call(self->m_connection, | ||
616 | 74 | GEOCLUE_BUS_NAME, | ||
617 | 75 | "/org/freedesktop/Geoclue/Master", | ||
618 | 76 | "org.freedesktop.Geoclue.Master", | ||
619 | 77 | "Create", | ||
620 | 78 | nullptr, // parameters | ||
621 | 79 | G_VARIANT_TYPE("(o)"), | ||
622 | 80 | G_DBUS_CALL_FLAGS_NONE, | ||
623 | 81 | -1, | ||
624 | 82 | self->m_cancellable, | ||
625 | 83 | on_client_created, | ||
626 | 84 | self); | ||
627 | 85 | } | ||
628 | 86 | } | ||
629 | 87 | |||
630 | 88 | void | ||
631 | 89 | GeoclueTimezone::on_client_created(GObject * source, GAsyncResult * res, gpointer gself) | ||
632 | 90 | { | ||
633 | 91 | GVariant * result; | ||
634 | 92 | |||
635 | 93 | if ((result = call_finish(source, res))) | ||
636 | 94 | { | ||
637 | 95 | auto self = static_cast<GeoclueTimezone*>(gself); | ||
638 | 96 | |||
639 | 97 | GVariant * child = g_variant_get_child_value(result, 0); | ||
640 | 98 | self->m_client_object_path = g_variant_get_string(child, nullptr); | ||
641 | 99 | g_variant_unref(child); | ||
642 | 100 | g_variant_unref(result); | ||
643 | 101 | |||
644 | 102 | self->m_signal_subscription = g_dbus_connection_signal_subscribe( | ||
645 | 103 | self->m_connection, | ||
646 | 104 | GEOCLUE_BUS_NAME, | ||
647 | 105 | "org.freedesktop.Geoclue.Address", // inteface | ||
648 | 106 | "AddressChanged", // signal name | ||
649 | 107 | self->m_client_object_path.c_str(), // object path | ||
650 | 108 | nullptr, // arg0 | ||
651 | 109 | G_DBUS_SIGNAL_FLAGS_NONE, | ||
652 | 110 | on_address_changed, | ||
653 | 111 | self, | ||
654 | 112 | nullptr); | ||
655 | 113 | |||
656 | 114 | g_dbus_connection_call(self->m_connection, | ||
657 | 115 | GEOCLUE_BUS_NAME, | ||
658 | 116 | self->m_client_object_path.c_str(), | ||
659 | 117 | "org.freedesktop.Geoclue.MasterClient", | ||
660 | 118 | "SetRequirements", | ||
661 | 119 | g_variant_new("(iibi)", 2, 0, FALSE, 1023), | ||
662 | 120 | nullptr, | ||
663 | 121 | G_DBUS_CALL_FLAGS_NONE, | ||
664 | 122 | -1, | ||
665 | 123 | self->m_cancellable, | ||
666 | 124 | on_requirements_set, | ||
667 | 125 | self); | ||
668 | 126 | } | ||
669 | 127 | } | ||
670 | 128 | |||
671 | 129 | void | ||
672 | 130 | GeoclueTimezone::on_address_changed(GDBusConnection* /*connection*/, | ||
673 | 131 | const gchar* /*sender_name*/, | ||
674 | 132 | const gchar* /*object_path*/, | ||
675 | 133 | const gchar* /*interface_name*/, | ||
676 | 134 | const gchar* /*signal_name*/, | ||
677 | 135 | GVariant* parameters, | ||
678 | 136 | gpointer gself) | ||
679 | 137 | { | ||
680 | 138 | static_cast<GeoclueTimezone*>(gself)->setTimezoneFromAddressVariant(parameters); | ||
681 | 139 | } | ||
682 | 140 | |||
683 | 141 | void | ||
684 | 142 | GeoclueTimezone::on_requirements_set(GObject* source, GAsyncResult* res, gpointer gself) | ||
685 | 143 | { | ||
686 | 144 | GVariant * result; | ||
687 | 145 | |||
688 | 146 | if ((result = call_finish(source, res))) | ||
689 | 147 | { | ||
690 | 148 | auto self = static_cast<GeoclueTimezone*>(gself); | ||
691 | 149 | |||
692 | 150 | g_dbus_connection_call(self->m_connection, | ||
693 | 151 | GEOCLUE_BUS_NAME, | ||
694 | 152 | self->m_client_object_path.c_str(), | ||
695 | 153 | "org.freedesktop.Geoclue.MasterClient", | ||
696 | 154 | "AddressStart", | ||
697 | 155 | nullptr, | ||
698 | 156 | nullptr, | ||
699 | 157 | G_DBUS_CALL_FLAGS_NONE, | ||
700 | 158 | -1, | ||
701 | 159 | self->m_cancellable, | ||
702 | 160 | on_address_started, | ||
703 | 161 | self); | ||
704 | 162 | |||
705 | 163 | g_variant_unref(result); | ||
706 | 164 | } | ||
707 | 165 | } | ||
708 | 166 | |||
709 | 167 | void | ||
710 | 168 | GeoclueTimezone::on_address_started(GObject * source, GAsyncResult * res, gpointer gself) | ||
711 | 169 | { | ||
712 | 170 | GVariant * result; | ||
713 | 171 | |||
714 | 172 | if ((result = call_finish(source, res))) | ||
715 | 173 | { | ||
716 | 174 | auto self = static_cast<GeoclueTimezone*>(gself); | ||
717 | 175 | |||
718 | 176 | g_dbus_connection_call(self->m_connection, | ||
719 | 177 | GEOCLUE_BUS_NAME, | ||
720 | 178 | self->m_client_object_path.c_str(), | ||
721 | 179 | "org.freedesktop.Geoclue.Address", | ||
722 | 180 | "GetAddress", | ||
723 | 181 | nullptr, | ||
724 | 182 | G_VARIANT_TYPE("(ia{ss}(idd))"), | ||
725 | 183 | G_DBUS_CALL_FLAGS_NONE, | ||
726 | 184 | -1, | ||
727 | 185 | self->m_cancellable, | ||
728 | 186 | on_address_got, | ||
729 | 187 | self); | ||
730 | 188 | |||
731 | 189 | g_variant_unref(result); | ||
732 | 190 | } | ||
733 | 191 | } | ||
734 | 192 | |||
735 | 193 | void | ||
736 | 194 | GeoclueTimezone::on_address_got(GObject * source, GAsyncResult * res, gpointer gself) | ||
737 | 195 | { | ||
738 | 196 | GVariant * result; | ||
739 | 197 | |||
740 | 198 | if ((result = call_finish(source, res))) | ||
741 | 199 | { | ||
742 | 200 | static_cast<GeoclueTimezone*>(gself)->setTimezoneFromAddressVariant(result); | ||
743 | 201 | g_variant_unref(result); | ||
744 | 202 | } | ||
745 | 203 | } | ||
746 | 204 | |||
747 | 205 | void | ||
748 | 206 | GeoclueTimezone::setTimezoneFromAddressVariant(GVariant * variant) | ||
749 | 207 | { | ||
750 | 208 | g_return_if_fail(g_variant_is_of_type(variant, G_VARIANT_TYPE("(ia{ss}(idd))"))); | ||
751 | 209 | |||
752 | 210 | const gchar * timezone_string = nullptr; | ||
753 | 211 | GVariant * dict = g_variant_get_child_value(variant, 1); | ||
754 | 212 | if (dict) | ||
755 | 213 | { | ||
756 | 214 | if (g_variant_lookup(dict, "timezone", "&s", &timezone_string)) | ||
757 | 215 | timezone.set(timezone_string); | ||
758 | 216 | |||
759 | 217 | g_variant_unref(dict); | ||
760 | 218 | } | ||
761 | 219 | } | ||
762 | 220 | |||
763 | 221 | GVariant* | ||
764 | 222 | GeoclueTimezone::call_finish(GObject * source, GAsyncResult * res) | ||
765 | 223 | { | ||
766 | 224 | GError * error; | ||
767 | 225 | GVariant * result; | ||
768 | 226 | |||
769 | 227 | error = nullptr; | ||
770 | 228 | result = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), res, &error); | ||
771 | 229 | |||
772 | 230 | if (error) | ||
773 | 231 | { | ||
774 | 232 | if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) | ||
775 | 233 | g_warning("AddressStart() failed: %s", error->message); | ||
776 | 234 | |||
777 | 235 | g_error_free(error); | ||
778 | 236 | |||
779 | 237 | g_clear_pointer(&result, g_variant_unref); | ||
780 | 238 | } | ||
781 | 239 | |||
782 | 240 | return result; | ||
783 | 241 | } | 282 | } |
784 | 242 | 283 | ||
785 | 243 | /**** | 284 | /**** |
786 | 244 | 285 | ||
787 | === modified file 'src/wakeup-timer-powerd.cpp' | |||
788 | --- src/wakeup-timer-powerd.cpp 2014-08-19 04:08:38 +0000 | |||
789 | +++ src/wakeup-timer-powerd.cpp 2014-09-16 22:48:45 +0000 | |||
790 | @@ -22,6 +22,8 @@ | |||
791 | 22 | 22 | ||
792 | 23 | #include <notifications/dbus-shared.h> // BUS_POWERD_NAME | 23 | #include <notifications/dbus-shared.h> // BUS_POWERD_NAME |
793 | 24 | 24 | ||
794 | 25 | #include <gio/gio.h> | ||
795 | 26 | |||
796 | 25 | #include <memory> // std::shared_ptr | 27 | #include <memory> // std::shared_ptr |
797 | 26 | 28 | ||
798 | 27 | namespace unity { | 29 | namespace unity { |
The camelcase to underscores I think were the final straw for meld. It didn't do as good of a job as I would have expected.