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

Side by Side Diff: udev_listener.cc

Issue 6854002: Merge monitor_reconfigure into powerd. (Closed) Base URL: ssh://gitrw.chromium.org:9222/power_manager.git@master
Patch Set: Second version with nits. Created 9 years, 8 months 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
« udev_listener.h ('K') | « udev_listener.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 #include <glib.h>
Daniel Erat 2011/04/13 23:33:26 nit: add a blank line after this
marcheu 2011/04/14 02:23:55 Done.
6 #include "base/logging.h"
7 #include "base/platform_thread.h"
8 #include "power_manager/udev_listener.h"
9
10 namespace power_manager {
11
12 UdevListener::UdevListener(UdevCallBack* callback, std::string subsystem)
13 : callback_(callback),
14 subsystem_(subsystem)
15 {}
Daniel Erat 2011/04/13 23:33:26 move the opening brace to the end of the previous
marcheu 2011/04/14 02:23:55 Done.
16
17 bool UdevListener::Init()
18 {
Daniel Erat 2011/04/13 23:33:26 move to previous line
marcheu 2011/04/14 02:23:55 Done.
19 struct udev* udev;
20
21 // Create the udev object.
22 udev = udev_new();
Daniel Erat 2011/04/13 23:33:26 move this onto the same line as the declaration:
marcheu 2011/04/14 02:23:55 Done.
23 if (!udev) {
24 LOG(ERROR) << "Can't create udev object.";
25 return false;
26 }
27
28 // Create the udev monitor structure.
29 monitor_ = udev_monitor_new_from_netlink(udev, "udev");
30 if (!monitor_ ) {
31 LOG(ERROR) << "Can't create udev monitor.";
Daniel Erat 2011/04/13 23:33:26 leaking |udev| here; use udev_unref()
marcheu 2011/04/14 02:23:55 Done.
32 return false;
33 }
34 udev_monitor_filter_add_match_subsystem_devtype(monitor_,
35 subsystem_.c_str(),
36 NULL);
37 udev_monitor_enable_receiving(monitor_);
38
39 int fd = udev_monitor_get_fd(monitor_);
40
41 GIOChannel * channel;
Daniel Erat 2011/04/13 23:33:26 delete space before '*'
marcheu 2011/04/14 02:23:55 Done.
42 channel = g_io_channel_unix_new(fd);
Daniel Erat 2011/04/13 23:33:26 combine with declaration
marcheu 2011/04/14 02:23:55 Done.
43 g_io_add_watch(channel, G_IO_IN, &(UdevListener::EventHandler), this);
44
45 LOG(WARNING) << "Udev listener waiting for events on subsystem "
Daniel Erat 2011/04/13 23:33:26 i don't see why this is a warning. use LOG(INFO)
marcheu 2011/04/14 02:23:55 Done.
46 << subsystem_;
47
Daniel Erat 2011/04/13 23:33:26 leaking |udev| here. can you unref it now, or do
marcheu 2011/04/14 02:23:55 I added it to UdevListener class and delete in the
48 return true;
49 }
50
51 gboolean UdevListener::EventHandler(GIOChannel* source,
52 GIOCondition condition,
Daniel Erat 2011/04/13 23:33:26 fix indenting
marcheu 2011/04/14 02:23:55 Done.
53 gpointer data) {
54 UdevListener* listener = static_cast<UdevListener*>(data);
55
56 struct udev_device* dev = udev_monitor_receive_device(listener->monitor_);
57 if (dev) {
58 LOG(INFO) << "Event on ("
59 << udev_device_get_devnode(dev)
60 << "|"
61 << udev_device_get_subsystem(dev)
62 << "|"
63 << udev_device_get_devtype(dev)
64 << ") Action "
65 << udev_device_get_action(dev);
66 udev_device_unref(dev);
67 listener->callback_->CallBack(source, condition);
68 } else {
69 LOG(ERROR) << "Can't get receive_device()";
70 return false;
71 }
72 return true;
73 }
74
75 } // namespace power_manager
76
OLDNEW
« udev_listener.h ('K') | « udev_listener.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698