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 | 482fbd5 | 2013-07-15 16:45:29 -0700 | [diff] [blame] | 2 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 3 | * Copyright (C) 2013 Regents of the University of California. |
| 4 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 482fbd5 | 2013-07-15 16:45:29 -0700 | [diff] [blame] | 5 | * See COPYING for copyright and distribution information. |
| 6 | */ |
| 7 | |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 8 | #ifndef NDN_ELEMENT_LISTENER_HPP |
| 9 | #define NDN_ELEMENT_LISTENER_HPP |
Jeff Thompson | 482fbd5 | 2013-07-15 16:45:29 -0700 | [diff] [blame] | 10 | |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 11 | #include "../c/encoding/element-listener.h" |
Jeff Thompson | 482fbd5 | 2013-07-15 16:45:29 -0700 | [diff] [blame] | 12 | |
| 13 | namespace ndn { |
| 14 | |
| 15 | /** |
| 16 | * An ElementListener extends an ndn_ElementListener struct to proved an abstract virtual onReceivedElement function which wraps |
| 17 | * the onReceivedElement used by the ndn_ElementListener struct. You must extend this class to override onReceivedElement. |
| 18 | */ |
Jeff Thompson | 48abd92 | 2013-07-16 16:08:26 -0700 | [diff] [blame] | 19 | class ElementListener : public ndn_ElementListener { |
Jeff Thompson | 482fbd5 | 2013-07-15 16:45:29 -0700 | [diff] [blame] | 20 | public: |
| 21 | ElementListener() |
| 22 | { |
Jeff Thompson | d1427fb | 2013-08-29 17:20:32 -0700 | [diff] [blame] | 23 | ndn_ElementListener_initialize(this, staticOnReceivedElement); |
Jeff Thompson | 482fbd5 | 2013-07-15 16:45:29 -0700 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | /** |
| 27 | * This is called when an entire binary XML element is received. You must extend this class to override this method. |
| 28 | * @param element pointer to the binary XML element. This buffer is only valid during this call. If you need the data |
| 29 | * later, you must copy. |
| 30 | * @param elementLength length of element |
| 31 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 32 | virtual void |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 33 | onReceivedElement(const uint8_t *element, size_t elementLength) = 0; |
Jeff Thompson | 482fbd5 | 2013-07-15 16:45:29 -0700 | [diff] [blame] | 34 | |
| 35 | private: |
| 36 | /** |
| 37 | * Call the virtual method onReceivedElement. This is used to initialize the base ndn_ElementListener struct. |
| 38 | * @param self |
| 39 | * @param element |
| 40 | * @param elementLength |
| 41 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 42 | static void |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame] | 43 | staticOnReceivedElement(struct ndn_ElementListener *self, uint8_t *element, size_t elementLength); |
Jeff Thompson | 482fbd5 | 2013-07-15 16:45:29 -0700 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | } |
| 47 | |
| 48 | #endif |