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