Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(666)

Side by Side Diff: src/property_changed_handler.h

Issue 5380002: cashew: defer all D-Bus signal processing to main loop (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/cashew.git@master
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef SRC_PROPERTY_CHANGED_HANDLER_H_
6 #define SRC_PROPERTY_CHANGED_HANDLER_H_
7
8 #include <glib.h>
9
10 #include <queue>
11 #include <string>
12 #include <utility>
13
14 #include <base/basictypes.h> // NOLINT
15 #include <dbus-c++/dbus.h> // NOLINT
16
17 namespace cashew {
18
19 class PropertyChangedDelegate;
20
21 // tuple of (property name, new property value) representing a D-Bus
22 // PropertyChanged signal
23 typedef std::pair<const std::string, const DBus::Variant> PropertyChangedSignal;
24
25 // queue of PropertyChangedSignal tuples
26 typedef std::queue<PropertyChangedSignal> PropertyChangedQueue;
27
28 // PropertyChangedHandler allows tuples representing D-Bus PropertyChanged
29 // signals to be enqueued for deferred handling from the glib main loop.
30 class PropertyChangedHandler {
31 public:
32 PropertyChangedHandler();
33 virtual ~PropertyChangedHandler();
34
35 // set delegate that will receive OnPropertyChanged callbacks
36 // ok to clear delegate by setting it to NULL
37 virtual void delegate(PropertyChangedDelegate *delegate);
38
39 // add a PropertyChangedSignal to |signal_queue_|
40 // schedules a glib callback for deferred signal processing if one is not
41 // already scheduled
42 virtual void EnqueueSignal(const PropertyChangedSignal& signal);
43
44 private:
45 // delegate for OnPropertyChanged callbacks
46 PropertyChangedDelegate *delegate_;
47
48 // glib source id for deferred processing callback
49 guint source_id_;
50
51 // queue of PropertyChangedSignal tuples awaiting deferred processing
52 PropertyChangedQueue signal_queue_;
53
54 // glib integration: static wrapper
55 // takes PropertyChangedDelegate as data and invokes
56 // delegate->OnPropertyChanged for each signal in |signal_queue_|
57 static gboolean StaticOnPropertyChangedCallback(gpointer data);
58
59 // clear |signal_queue_|
60 void DeletePendingSignals();
61
62 DISALLOW_COPY_AND_ASSIGN(PropertyChangedHandler);
63 };
64
65 // callback interface for deferred PropertyChanged signal processing
66 class PropertyChangedDelegate {
67 public:
68 PropertyChangedDelegate() {}
69 virtual ~PropertyChangedDelegate() {}
70
71 // callback method for deferred PropertyChanged signal processing
72 virtual void OnPropertyChanged(const PropertyChangedHandler *handler,
73 const std::string& property_name,
74 const DBus::Variant& new_value) = 0;
75
76 private:
77 DISALLOW_COPY_AND_ASSIGN(PropertyChangedDelegate);
78 };
79
80 } // namespace cashew
81
82 #endif // SRC_PROPERTY_CHANGED_HANDLER_H_
OLDNEW
« no previous file with comments | « src/main.cc ('k') | src/property_changed_handler.cc » ('j') | src/property_changed_handler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698