blob: d10bfe468f4fdf1331e5c91bba3a80e3b312377b [file] [log] [blame]
Wade Guthrie64b4c142012-08-20 15:21:01 -07001// 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 Guthrieb1ec8602012-10-18 17:26:14 -070010#include <base/stringprintf.h>
Wade Guthrie64b4c142012-08-20 15:21:01 -070011
12#include "shill/config80211.h"
Wade Guthried4977f22012-08-22 12:37:54 -070013#include "shill/ieee80211.h"
Wade Guthrie64b4c142012-08-20 15:21:01 -070014#include "shill/link_monitor.h"
15#include "shill/logging.h"
repo syncd316eb72012-12-10 15:48:47 -080016#include "shill/nl80211_attribute.h"
repo syncdc085c82012-12-28 08:54:41 -080017#include "shill/nl80211_message.h"
Wade Guthrie64b4c142012-08-20 15:21:01 -070018#include "shill/scope_logger.h"
Wade Guthrie64b4c142012-08-20 15:21:01 -070019
20using base::Bind;
Wade Guthrieb1ec8602012-10-18 17:26:14 -070021using base::StringAppendF;
Wade Guthrie64b4c142012-08-20 15:21:01 -070022using std::string;
23
24namespace shill {
25
Christopher Wileyfe34be02012-11-12 16:02:46 -080026Callback80211Object::Callback80211Object()
Wade Guthrie5d3d6de2012-11-02 11:08:34 -070027 : weak_ptr_factory_(this),
Christopher Wileyfe34be02012-11-12 16:02:46 -080028 callback_(Bind(&Callback80211Object::ReceiveConfig80211Message,
29 weak_ptr_factory_.GetWeakPtr())) {
Wade Guthrie64b4c142012-08-20 15:21:01 -070030}
31
32Callback80211Object::~Callback80211Object() {
33 DeinstallAsCallback();
34}
35
36void Callback80211Object::Config80211MessageCallback(
repo syncdc085c82012-12-28 08:54:41 -080037 const Nl80211Message &message) {
repo sync1538d442012-12-20 15:24:35 -080038 // Show the message-type-specific version of the message.
Wade Guthrieb1ec8602012-10-18 17:26:14 -070039 string output("@");
40 StringAppendF(&output, "%s", message.ToString().c_str());
41 SLOG(WiFi, 2) << output;
Wade Guthrie64b4c142012-08-20 15:21:01 -070042
repo sync1538d442012-12-20 15:24:35 -080043 // Show the generic, detailed, version of the message.
44 SLOG(WiFi, 3) << message.GenericToString();
Wade Guthrie64b4c142012-08-20 15:21:01 -070045}
46
Wade Guthrieb1ec8602012-10-18 17:26:14 -070047bool Callback80211Object::InstallAsBroadcastCallback() {
Christopher Wileyfe34be02012-11-12 16:02:46 -080048 return Config80211::GetInstance()->AddBroadcastCallback(callback_);
Wade Guthrie64b4c142012-08-20 15:21:01 -070049}
50
51bool Callback80211Object::DeinstallAsCallback() {
Christopher Wileyfe34be02012-11-12 16:02:46 -080052 return Config80211::GetInstance()->RemoveBroadcastCallback(callback_);
53}
54
repo syncdc085c82012-12-28 08:54:41 -080055void Callback80211Object::ReceiveConfig80211Message(const Nl80211Message &msg) {
Christopher Wileyfe34be02012-11-12 16:02:46 -080056 Config80211MessageCallback(msg);
Wade Guthrie64b4c142012-08-20 15:21:01 -070057}
58
Wade Guthrie64b4c142012-08-20 15:21:01 -070059} // namespace shill.