Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 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 | |
| 5 | #include "shill/callback80211_object.h" |
| 6 | |
| 7 | #include <string> |
| 8 | |
| 9 | #include <base/memory/weak_ptr.h> |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 10 | #include <base/stringprintf.h> |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 11 | |
| 12 | #include "shill/config80211.h" |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 13 | #include "shill/ieee80211.h" |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 14 | #include "shill/link_monitor.h" |
| 15 | #include "shill/logging.h" |
repo sync | d316eb7 | 2012-12-10 15:48:47 -0800 | [diff] [blame] | 16 | #include "shill/nl80211_attribute.h" |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 17 | #include "shill/nl80211_message.h" |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 18 | #include "shill/scope_logger.h" |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 19 | |
| 20 | using base::Bind; |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 21 | using base::StringAppendF; |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 22 | using std::string; |
| 23 | |
| 24 | namespace shill { |
| 25 | |
Christopher Wiley | fe34be0 | 2012-11-12 16:02:46 -0800 | [diff] [blame] | 26 | Callback80211Object::Callback80211Object() |
Wade Guthrie | 5d3d6de | 2012-11-02 11:08:34 -0700 | [diff] [blame] | 27 | : weak_ptr_factory_(this), |
Wade Guthrie | 71cb0a7 | 2013-02-27 10:27:18 -0800 | [diff] [blame] | 28 | message_handler_(Bind(&Callback80211Object::ReceiveConfig80211Message, |
| 29 | weak_ptr_factory_.GetWeakPtr())) { |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | Callback80211Object::~Callback80211Object() { |
Wade Guthrie | 71cb0a7 | 2013-02-27 10:27:18 -0800 | [diff] [blame] | 33 | DeinstallAsHandler(); |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Wade Guthrie | 71cb0a7 | 2013-02-27 10:27:18 -0800 | [diff] [blame] | 36 | void Callback80211Object::Config80211MessageHandler( |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame] | 37 | const NetlinkMessage &message) { |
Wade Guthrie | 8e27861 | 2013-02-26 10:32:34 -0800 | [diff] [blame] | 38 | message.Print(10); |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Wade Guthrie | 71cb0a7 | 2013-02-27 10:27:18 -0800 | [diff] [blame] | 41 | bool Callback80211Object::InstallAsBroadcastHandler() { |
| 42 | return Config80211::GetInstance()->AddBroadcastHandler(message_handler_); |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Wade Guthrie | 71cb0a7 | 2013-02-27 10:27:18 -0800 | [diff] [blame] | 45 | bool Callback80211Object::DeinstallAsHandler() { |
| 46 | return Config80211::GetInstance()->RemoveBroadcastHandler(message_handler_); |
Christopher Wiley | fe34be0 | 2012-11-12 16:02:46 -0800 | [diff] [blame] | 47 | } |
| 48 | |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame] | 49 | void Callback80211Object::ReceiveConfig80211Message(const NetlinkMessage &msg) { |
Wade Guthrie | 71cb0a7 | 2013-02-27 10:27:18 -0800 | [diff] [blame] | 50 | Config80211MessageHandler(msg); |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 53 | } // namespace shill. |