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 | // 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 Guthrie | 5020b57 | 2012-10-12 15:51:14 -0700 | [diff] [blame] | 17 | #include <base/memory/weak_ptr.h> |
| 18 | |
| 19 | #include "shill/config80211.h" |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 20 | |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 21 | namespace shill { |
| 22 | |
| 23 | class UserBoundNlMessage; |
| 24 | |
| 25 | // Example Config80211 callback object; the callback prints a description of |
Wade Guthrie | 5020b57 | 2012-10-12 15:51:14 -0700 | [diff] [blame] | 26 | // each message with its attributes. |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 27 | class Callback80211Object { |
| 28 | public: |
Wade Guthrie | 5020b57 | 2012-10-12 15:51:14 -0700 | [diff] [blame] | 29 | explicit Callback80211Object(Config80211 *config80211); |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 30 | virtual ~Callback80211Object(); |
| 31 | |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 32 | // Install ourselves as a callback. |
| 33 | virtual bool InstallAsBroadcastCallback(); |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 34 | |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 35 | // Deinstall ourselves as a callback. |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 36 | bool DeinstallAsCallback(); |
| 37 | |
Wade Guthrie | 5020b57 | 2012-10-12 15:51:14 -0700 | [diff] [blame] | 38 | // TODO(wdg): remove debug code: |
| 39 | void SetName(std::string name) { name_ = name;} |
| 40 | const std::string &GetName() { return name_; } |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 41 | |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 42 | protected: |
Wade Guthrie | 5020b57 | 2012-10-12 15:51:14 -0700 | [diff] [blame] | 43 | // 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 Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 46 | Config80211 *config80211_; |
| 47 | |
Wade Guthrie | 5020b57 | 2012-10-12 15:51:14 -0700 | [diff] [blame] | 48 | 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 Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 55 | |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 56 | // Config80211MessageCallback method bound to this object to install as a |
| 57 | // callback. |
| 58 | base::WeakPtrFactory<Callback80211Object> weak_ptr_factory_; |
Wade Guthrie | 5020b57 | 2012-10-12 15:51:14 -0700 | [diff] [blame] | 59 | |
| 60 | DISALLOW_COPY_AND_ASSIGN(Callback80211Object); |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | } // namespace shill |
| 64 | |
| 65 | #endif // SHILL_CALLBACK80211_OBJECT_H |