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" |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 16 | #include "shill/metrics.h" |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 17 | #include "shill/scope_logger.h" |
| 18 | #include "shill/user_bound_nlmessage.h" |
| 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 | |
Wade Guthrie | 5020b57 | 2012-10-12 15:51:14 -0700 | [diff] [blame] | 26 | Callback80211Object::Callback80211Object(Config80211 *config80211) |
| 27 | : config80211_(config80211), weak_ptr_factory_(this) { |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | Callback80211Object::~Callback80211Object() { |
| 31 | DeinstallAsCallback(); |
| 32 | } |
| 33 | |
| 34 | void Callback80211Object::Config80211MessageCallback( |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 35 | const UserBoundNlMessage &message) { |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 36 | // Show the simplified version of the message. |
| 37 | string output("@"); |
| 38 | StringAppendF(&output, "%s", message.ToString().c_str()); |
| 39 | SLOG(WiFi, 2) << output; |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 40 | |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 41 | // Show the more complicated version of the message. |
| 42 | SLOG(WiFi, 3) << "Received " << message.GetMessageTypeString() |
| 43 | << " (" << + message.GetMessageType() << ")"; |
| 44 | |
| 45 | scoped_ptr<UserBoundNlMessage::AttributeNameIterator> i; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 46 | for (i.reset(message.GetAttributeNameIterator()); !i->AtEnd(); i->Advance()) { |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 47 | string value = "<unknown>"; |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 48 | message.GetAttributeString(i->GetName(), &value); |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 49 | SLOG(WiFi, 3) << " Attr:" << message.StringFromAttributeName(i->GetName()) |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 50 | << "=" << value |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 51 | << " Type:" << message.GetAttributeTypeString(i->GetName()); |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 52 | } |
| 53 | } |
| 54 | |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 55 | bool Callback80211Object::InstallAsBroadcastCallback() { |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 56 | if (config80211_) { |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 57 | callback_ = Bind(&Callback80211Object::Config80211MessageCallback, |
| 58 | weak_ptr_factory_.GetWeakPtr()); |
| 59 | return config80211_->AddBroadcastCallback(callback_); |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 60 | } |
| 61 | return false; |
| 62 | } |
| 63 | |
| 64 | bool Callback80211Object::DeinstallAsCallback() { |
| 65 | if (config80211_) { |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 66 | config80211_->RemoveBroadcastCallback(callback_); |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 67 | return true; |
| 68 | } |
| 69 | return false; |
| 70 | } |
| 71 | |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 72 | } // namespace shill. |