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), |
Christopher Wiley | fe34be0 | 2012-11-12 16:02:46 -0800 | [diff] [blame] | 28 | callback_(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() { |
| 33 | DeinstallAsCallback(); |
| 34 | } |
| 35 | |
| 36 | void Callback80211Object::Config80211MessageCallback( |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 37 | const Nl80211Message &message) { |
repo sync | 1538d44 | 2012-12-20 15:24:35 -0800 | [diff] [blame] | 38 | // Show the message-type-specific version of the message. |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 39 | string output("@"); |
| 40 | StringAppendF(&output, "%s", message.ToString().c_str()); |
| 41 | SLOG(WiFi, 2) << output; |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 42 | |
repo sync | 1538d44 | 2012-12-20 15:24:35 -0800 | [diff] [blame] | 43 | // Show the generic, detailed, version of the message. |
| 44 | SLOG(WiFi, 3) << message.GenericToString(); |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 47 | bool Callback80211Object::InstallAsBroadcastCallback() { |
Christopher Wiley | fe34be0 | 2012-11-12 16:02:46 -0800 | [diff] [blame] | 48 | return Config80211::GetInstance()->AddBroadcastCallback(callback_); |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | bool Callback80211Object::DeinstallAsCallback() { |
Christopher Wiley | fe34be0 | 2012-11-12 16:02:46 -0800 | [diff] [blame] | 52 | return Config80211::GetInstance()->RemoveBroadcastCallback(callback_); |
| 53 | } |
| 54 | |
repo sync | dc085c8 | 2012-12-28 08:54:41 -0800 | [diff] [blame] | 55 | void Callback80211Object::ReceiveConfig80211Message(const Nl80211Message &msg) { |
Christopher Wiley | fe34be0 | 2012-11-12 16:02:46 -0800 | [diff] [blame] | 56 | Config80211MessageCallback(msg); |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 59 | } // namespace shill. |