blob: 95c28c2fc9733069288236c11aed58eac6d4e7fa [file] [log] [blame]
Paul Stewarta3c56f92011-05-26 07:08:52 -07001// 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 Stewarta3c56f92011-05-26 07:08:52 -07005#include "shill/rtnl_listener.h"
6#include "shill/rtnl_handler.h"
7
Eric Shienbrood3e20a232012-02-16 11:35:56 -05008using base::Callback;
9
Paul Stewarta3c56f92011-05-26 07:08:52 -070010namespace shill {
11
12RTNLListener::RTNLListener(int listen_flags,
Eric Shienbrood3e20a232012-02-16 11:35:56 -050013 const Callback<void(const RTNLMessage &)> &callback)
Paul Stewarta3c56f92011-05-26 07:08:52 -070014 : listen_flags_(listen_flags), callback_(callback) {
15 RTNLHandler::GetInstance()->AddListener(this);
16}
17
18RTNLListener::~RTNLListener() {
19 RTNLHandler::GetInstance()->RemoveListener(this);
20}
21
Chris Masone2aa97072011-08-09 17:35:08 -070022void RTNLListener::NotifyEvent(int type, const RTNLMessage &msg) {
Paul Stewarta3c56f92011-05-26 07:08:52 -070023 if ((type & listen_flags_) != 0)
Eric Shienbrood3e20a232012-02-16 11:35:56 -050024 callback_.Run(msg);
Paul Stewarta3c56f92011-05-26 07:08:52 -070025}
26
27} // namespace shill