blob: d0285582fed2a7f861dce79f310cce9a5fab631f [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>
10
11#include "shill/config80211.h"
12#include "shill/link_monitor.h"
13#include "shill/logging.h"
14#include "shill/scope_logger.h"
15#include "shill/user_bound_nlmessage.h"
16
17using base::Bind;
18using base::LazyInstance;
19using std::string;
20
21namespace shill {
22
23namespace {
24LazyInstance<Callback80211Object> g_callback80211 = LAZY_INSTANCE_INITIALIZER;
25} // namespace
26
27// static
28const char Callback80211Object::kMetricLinkDisconnectCount[] =
29 "Network.Shill.DisconnectCount";
30
31Callback80211Object::Callback80211Object() :
32 config80211_(NULL),
33 weak_ptr_factory_(this) {
34}
35
36Callback80211Object::~Callback80211Object() {
37 DeinstallAsCallback();
38}
39
40void Callback80211Object::Config80211MessageCallback(
41 const UserBoundNlMessage &msg) {
42 SLOG(WiFi, 2) << "Received " << msg.GetMessageTypeString()
43 << " (" << + msg.GetMessageType() << ")";
44 scoped_ptr<UserBoundNlMessage::AttributeNameIterator> i;
45
46 for (i.reset(msg.GetAttributeNameIterator()); !i->AtEnd(); i->Advance()) {
47 string value = "<unknown>";
48 msg.GetAttributeString(i->GetName(), &value);
49 SLOG(WiFi, 2) << " Attr:" << msg.StringFromAttributeName(i->GetName())
50 << "=" << value
51 << " Type:" << msg.GetAttributeTypeString(i->GetName());
52 }
53}
54
55bool Callback80211Object::InstallAsCallback() {
56 if (config80211_) {
57 Config80211::Callback callback =
58 Bind(&Callback80211Object::Config80211MessageCallback,
59 weak_ptr_factory_.GetWeakPtr());
60 config80211_->SetDefaultCallback(callback);
61 return true;
62 }
63 return false;
64}
65
66bool Callback80211Object::DeinstallAsCallback() {
67 if (config80211_) {
68 config80211_->UnsetDefaultCallback();
69 return true;
70 }
71 return false;
72}
73
74Callback80211Object *Callback80211Object::GetInstance() {
75 return g_callback80211.Pointer();
76}
77
78} // namespace shill.