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

Unified 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 side-by-side diff with in-line comments
Download patch
« udev_listener.h ('K') | « udev_listener.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: udev_listener.cc
diff --git a/udev_listener.cc b/udev_listener.cc
new file mode 100644
index 0000000000000000000000000000000000000000..13081af85bdf5d3cf18ec76c1fb6a5885be86ec2
--- /dev/null
+++ b/udev_listener.cc
@@ -0,0 +1,76 @@
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#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.
+#include "base/logging.h"
+#include "base/platform_thread.h"
+#include "power_manager/udev_listener.h"
+
+namespace power_manager {
+
+UdevListener::UdevListener(UdevCallBack* callback, std::string subsystem)
+ : callback_(callback),
+ subsystem_(subsystem)
+{}
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.
+
+bool UdevListener::Init()
+{
Daniel Erat 2011/04/13 23:33:26 move to previous line
marcheu 2011/04/14 02:23:55 Done.
+ struct udev* udev;
+
+ // Create the udev object.
+ 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.
+ if (!udev) {
+ LOG(ERROR) << "Can't create udev object.";
+ return false;
+ }
+
+ // Create the udev monitor structure.
+ monitor_ = udev_monitor_new_from_netlink(udev, "udev");
+ if (!monitor_ ) {
+ 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.
+ return false;
+ }
+ udev_monitor_filter_add_match_subsystem_devtype(monitor_,
+ subsystem_.c_str(),
+ NULL);
+ udev_monitor_enable_receiving(monitor_);
+
+ int fd = udev_monitor_get_fd(monitor_);
+
+ GIOChannel * channel;
Daniel Erat 2011/04/13 23:33:26 delete space before '*'
marcheu 2011/04/14 02:23:55 Done.
+ 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.
+ g_io_add_watch(channel, G_IO_IN, &(UdevListener::EventHandler), this);
+
+ 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.
+ << subsystem_;
+
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
+ return true;
+}
+
+gboolean UdevListener::EventHandler(GIOChannel* source,
+ GIOCondition condition,
Daniel Erat 2011/04/13 23:33:26 fix indenting
marcheu 2011/04/14 02:23:55 Done.
+ gpointer data) {
+ UdevListener* listener = static_cast<UdevListener*>(data);
+
+ struct udev_device* dev = udev_monitor_receive_device(listener->monitor_);
+ if (dev) {
+ LOG(INFO) << "Event on ("
+ << udev_device_get_devnode(dev)
+ << "|"
+ << udev_device_get_subsystem(dev)
+ << "|"
+ << udev_device_get_devtype(dev)
+ << ") Action "
+ << udev_device_get_action(dev);
+ udev_device_unref(dev);
+ listener->callback_->CallBack(source, condition);
+ } else {
+ LOG(ERROR) << "Can't get receive_device()";
+ return false;
+ }
+ return true;
+}
+
+} // namespace power_manager
+
« 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