blob: 18e3e06d66ba5e70bbed183745de758c297a2de8 [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// This class is a callback object that observes all nl80211 events that come
6// up from the kernel.
7
8#ifndef SHILL_CALLBACK80211_OBJECT_H
9#define SHILL_CALLBACK80211_OBJECT_H
10
11#include <iomanip>
12#include <map>
13#include <string>
14
15#include <base/basictypes.h>
16#include <base/bind.h>
17#include <base/lazy_instance.h>
18
Wade Guthrie64b4c142012-08-20 15:21:01 -070019namespace shill {
20
Wade Guthried4977f22012-08-22 12:37:54 -070021class Config80211;
22class Metrics;
Wade Guthrie64b4c142012-08-20 15:21:01 -070023class UserBoundNlMessage;
24
25// Example Config80211 callback object; the callback prints a description of
26// each message with its attributes. You want to make it a singleton so that
27// its life isn't dependent on any other object (plus, since this handles
28// global events from msg80211, you only want/need one).
29class Callback80211Object {
30 public:
31 Callback80211Object();
32 virtual ~Callback80211Object();
33
34 // Get a pointer to the singleton Callback80211Object.
35 static Callback80211Object *GetInstance();
36
37 // Install ourselves as a callback. Done automatically by constructor.
38 bool InstallAsCallback();
39
40 // Deinstall ourselves as a callback. Done automatically by destructor.
41 bool DeinstallAsCallback();
42
43 // Simple accessor.
44 void set_config80211(Config80211 *config80211) { config80211_ = config80211; }
45
Wade Guthried4977f22012-08-22 12:37:54 -070046 // Simple accessor.
47 void set_metrics(Metrics *metrics) { metrics_ = metrics; }
48
Wade Guthrie64b4c142012-08-20 15:21:01 -070049 protected:
50 friend struct base::DefaultLazyInstanceTraits<Callback80211Object>;
51
52 private:
53 // When installed, this is the method Config80211 will call when it gets a
54 // message from the mac80211 drivers.
55 void Config80211MessageCallback(const UserBoundNlMessage &msg);
56
57 static const char kMetricLinkDisconnectCount[];
58
59 Config80211 *config80211_;
60
Wade Guthried4977f22012-08-22 12:37:54 -070061 Metrics *metrics_;
62
Wade Guthrie64b4c142012-08-20 15:21:01 -070063 // Config80211MessageCallback method bound to this object to install as a
64 // callback.
65 base::WeakPtrFactory<Callback80211Object> weak_ptr_factory_;
66};
67
68} // namespace shill
69
70#endif // SHILL_CALLBACK80211_OBJECT_H