blob: 0037e98884fe12a4571f88257a9bf906157a3b07 [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>
Wade Guthrie5020b572012-10-12 15:51:14 -070017#include <base/memory/weak_ptr.h>
18
19#include "shill/config80211.h"
Wade Guthrie64b4c142012-08-20 15:21:01 -070020
Wade Guthrie64b4c142012-08-20 15:21:01 -070021namespace shill {
22
23class UserBoundNlMessage;
24
25// Example Config80211 callback object; the callback prints a description of
Wade Guthrie5020b572012-10-12 15:51:14 -070026// each message with its attributes.
Wade Guthrie64b4c142012-08-20 15:21:01 -070027class Callback80211Object {
28 public:
Wade Guthrie5020b572012-10-12 15:51:14 -070029 explicit Callback80211Object(Config80211 *config80211);
Wade Guthrie64b4c142012-08-20 15:21:01 -070030 virtual ~Callback80211Object();
31
Wade Guthrieb1ec8602012-10-18 17:26:14 -070032 // Install ourselves as a callback.
33 virtual bool InstallAsBroadcastCallback();
Wade Guthrie64b4c142012-08-20 15:21:01 -070034
Wade Guthrieb1ec8602012-10-18 17:26:14 -070035 // Deinstall ourselves as a callback.
Wade Guthrie64b4c142012-08-20 15:21:01 -070036 bool DeinstallAsCallback();
37
Wade Guthrie5020b572012-10-12 15:51:14 -070038 // TODO(wdg): remove debug code:
39 void SetName(std::string name) { name_ = name;}
40 const std::string &GetName() { return name_; }
Wade Guthried4977f22012-08-22 12:37:54 -070041
Wade Guthrie64b4c142012-08-20 15:21:01 -070042 protected:
Wade Guthrie5020b572012-10-12 15:51:14 -070043 // This is the closure that contains *|this| and a pointer to the message
44 // handling callback, below. It is used in |DeinstallAsCallback|.
45 Config80211::Callback callback_;
Wade Guthrie64b4c142012-08-20 15:21:01 -070046 Config80211 *config80211_;
47
Wade Guthrie5020b572012-10-12 15:51:14 -070048 private:
49 // TODO(wdg): remove debug code:
50 std::string name_;
51
52 // When installed, this is the method Config80211 will call when it gets a
53 // message from the mac80211 drivers.
54 virtual void Config80211MessageCallback(const UserBoundNlMessage &msg);
Wade Guthried4977f22012-08-22 12:37:54 -070055
Wade Guthrie64b4c142012-08-20 15:21:01 -070056 // Config80211MessageCallback method bound to this object to install as a
57 // callback.
58 base::WeakPtrFactory<Callback80211Object> weak_ptr_factory_;
Wade Guthrie5020b572012-10-12 15:51:14 -070059
60 DISALLOW_COPY_AND_ASSIGN(Callback80211Object);
Wade Guthrie64b4c142012-08-20 15:21:01 -070061};
62
63} // namespace shill
64
65#endif // SHILL_CALLBACK80211_OBJECT_H