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 | 5020b57 | 2012-10-12 15:51:14 -0700 | [diff] [blame] | 42 | private: |
| 43 | // TODO(wdg): remove debug code: |
| 44 | std::string name_; |
| 45 | |
| 46 | // When installed, this is the method Config80211 will call when it gets a |
| 47 | // message from the mac80211 drivers. |
| 48 | virtual void Config80211MessageCallback(const UserBoundNlMessage &msg); |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 49 | |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 50 | // Config80211MessageCallback method bound to this object to install as a |
| 51 | // callback. |
| 52 | base::WeakPtrFactory<Callback80211Object> weak_ptr_factory_; |
Wade Guthrie | 5020b57 | 2012-10-12 15:51:14 -0700 | [diff] [blame] | 53 | |
Wade Guthrie | 5d3d6de | 2012-11-02 11:08:34 -0700 | [diff] [blame] | 54 | protected: |
| 55 | // This is the closure that contains *|this| and a pointer to the message |
| 56 | // handling callback, below. It is used in |DeinstallAsCallback|. |
| 57 | Config80211::Callback callback_; |
| 58 | Config80211 *config80211_; |
| 59 | |
| 60 | private: |
Wade Guthrie | 5020b57 | 2012-10-12 15:51:14 -0700 | [diff] [blame] | 61 | DISALLOW_COPY_AND_ASSIGN(Callback80211Object); |
Wade Guthrie | 64b4c14 | 2012-08-20 15:21:01 -0700 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | } // namespace shill |
| 65 | |
| 66 | #endif // SHILL_CALLBACK80211_OBJECT_H |