Paul Stewart | a3c56f9 | 2011-05-26 07:08:52 -0700 | [diff] [blame] | 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 | |
Paul Stewart | a3c56f9 | 2011-05-26 07:08:52 -0700 | [diff] [blame] | 5 | #include "shill/rtnl_listener.h" |
| 6 | #include "shill/rtnl_handler.h" |
| 7 | |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 8 | using base::Callback; |
| 9 | |
Paul Stewart | a3c56f9 | 2011-05-26 07:08:52 -0700 | [diff] [blame] | 10 | namespace shill { |
| 11 | |
| 12 | RTNLListener::RTNLListener(int listen_flags, |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 13 | const Callback<void(const RTNLMessage &)> &callback) |
Paul Stewart | a3c56f9 | 2011-05-26 07:08:52 -0700 | [diff] [blame] | 14 | : listen_flags_(listen_flags), callback_(callback) { |
| 15 | RTNLHandler::GetInstance()->AddListener(this); |
| 16 | } |
| 17 | |
| 18 | RTNLListener::~RTNLListener() { |
| 19 | RTNLHandler::GetInstance()->RemoveListener(this); |
| 20 | } |
| 21 | |
Chris Masone | 2aa9707 | 2011-08-09 17:35:08 -0700 | [diff] [blame] | 22 | void RTNLListener::NotifyEvent(int type, const RTNLMessage &msg) { |
Paul Stewart | a3c56f9 | 2011-05-26 07:08:52 -0700 | [diff] [blame] | 23 | if ((type & listen_flags_) != 0) |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 24 | callback_.Run(msg); |
Paul Stewart | a3c56f9 | 2011-05-26 07:08:52 -0700 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | } // namespace shill |