Jeff Thompson | a04f23c | 2013-09-16 17:48:38 -0700 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #ifndef NDN_CHANGED_EVENT_HPP |
| 8 | #define NDN_CHANGED_EVENT_HPP |
| 9 | |
| 10 | #include <vector> |
| 11 | #include "../common.hpp" |
| 12 | |
| 13 | namespace ndn { |
| 14 | |
| 15 | /** |
| 16 | * An OnChanged function object is called to notify a listener of a changed event. |
| 17 | */ |
| 18 | typedef func_lib::function<void()> OnChanged; |
| 19 | |
| 20 | class ChangedEvent { |
| 21 | public: |
| 22 | /** |
| 23 | * Add onChanged to the listener list. This does not check if a duplicate is already in the list. |
| 24 | * @param onChanged The OnChanged function object. |
| 25 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame^] | 26 | void |
| 27 | add(OnChanged onChanged) |
Jeff Thompson | a04f23c | 2013-09-16 17:48:38 -0700 | [diff] [blame] | 28 | { |
| 29 | listeners_.push_back(onChanged); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Call all the listeners. |
| 34 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame^] | 35 | void |
| 36 | fire(); |
Jeff Thompson | a04f23c | 2013-09-16 17:48:38 -0700 | [diff] [blame] | 37 | |
| 38 | #if 0 |
| 39 | private: |
| 40 | #endif |
| 41 | std::vector<OnChanged> listeners_; |
| 42 | }; |
| 43 | |
| 44 | } |
| 45 | |
| 46 | #endif |