blob: fef354e009bd99407277d65420e8abdb150ea4f7 [file] [log] [blame]
// Copyright 2018 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 "shill/net/rtnl_listener.h"
#include "shill/net/rtnl_handler.h"
namespace shill {
RTNLListener::RTNLListener(
int listen_flags, const base::Callback<void(const RTNLMessage&)>& callback)
: RTNLListener{listen_flags, callback, RTNLHandler::GetInstance()} {}
RTNLListener::RTNLListener(
int listen_flags,
const base::Callback<void(const RTNLMessage&)>& callback,
RTNLHandler* rtnl_handler)
: listen_flags_(listen_flags),
callback_(callback),
rtnl_handler_(rtnl_handler) {
rtnl_handler_->AddListener(this);
}
RTNLListener::~RTNLListener() {
rtnl_handler_->RemoveListener(this);
}
void RTNLListener::NotifyEvent(int type, const RTNLMessage& msg) const {
if (type & listen_flags_)
callback_.Run(msg);
}
} // namespace shill