1 //
2 // Copyright (C) 2011 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 #include "shill/net/rtnl_listener.h"
18
19 #include "shill/net/rtnl_handler.h"
20
21 using base::Callback;
22
23 namespace shill {
24
RTNLListener(int listen_flags,const Callback<void (const RTNLMessage &)> & callback)25 RTNLListener::RTNLListener(int listen_flags,
26 const Callback<void(const RTNLMessage&)>& callback)
27 : RTNLListener{listen_flags, callback, RTNLHandler::GetInstance()} {}
28
RTNLListener(int listen_flags,const Callback<void (const RTNLMessage &)> & callback,RTNLHandler * rtnl_handler)29 RTNLListener::RTNLListener(int listen_flags,
30 const Callback<void(const RTNLMessage&)>& callback,
31 RTNLHandler* rtnl_handler)
32 : listen_flags_(listen_flags),
33 callback_(callback),
34 rtnl_handler_(rtnl_handler) {
35 rtnl_handler_->AddListener(this);
36 }
37
~RTNLListener()38 RTNLListener::~RTNLListener() {
39 rtnl_handler_->RemoveListener(this);
40 }
41
NotifyEvent(int type,const RTNLMessage & msg)42 void RTNLListener::NotifyEvent(int type, const RTNLMessage& msg) {
43 if ((type & listen_flags_) != 0)
44 callback_.Run(msg);
45 }
46
47 } // namespace shill
48