blob: 71ad42b4d3b3b71821bddd4aa1a3e1538b4c5553 [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"
using base::Callback;
namespace shill {
RTNLListener::RTNLListener(int listen_flags,
const Callback<void(const RTNLMessage&)>& callback)
: RTNLListener{listen_flags, callback, RTNLHandler::GetInstance()} {}
RTNLListener::RTNLListener(int listen_flags,
const 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