blob: 7d13312e79624a537a3c8200928df1c3018f5259 [file] [log] [blame]
Jeff Thompson25b4e612013-10-10 16:03:24 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Jeff Thompson482fbd52013-07-15 16:45:29 -07002/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07003 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson482fbd52013-07-15 16:45:29 -07005 * See COPYING for copyright and distribution information.
6 */
7
Jeff Thompson25b4e612013-10-10 16:03:24 -07008#ifndef NDN_ELEMENT_LISTENER_HPP
9#define NDN_ELEMENT_LISTENER_HPP
Jeff Thompson482fbd52013-07-15 16:45:29 -070010
Jeff Thompson25b4e612013-10-10 16:03:24 -070011#include "../c/encoding/element-listener.h"
Jeff Thompson482fbd52013-07-15 16:45:29 -070012
13namespace 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 Thompson48abd922013-07-16 16:08:26 -070019class ElementListener : public ndn_ElementListener {
Jeff Thompson482fbd52013-07-15 16:45:29 -070020public:
21 ElementListener()
22 {
Jeff Thompsond1427fb2013-08-29 17:20:32 -070023 ndn_ElementListener_initialize(this, staticOnReceivedElement);
Jeff Thompson482fbd52013-07-15 16:45:29 -070024 }
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 Thompson0050abe2013-09-17 12:50:25 -070032 virtual void
Jeff Thompson97223af2013-09-24 17:01:27 -070033 onReceivedElement(const uint8_t *element, size_t elementLength) = 0;
Jeff Thompson482fbd52013-07-15 16:45:29 -070034
35private:
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 Thompson0050abe2013-09-17 12:50:25 -070042 static void
Jeff Thompson97223af2013-09-24 17:01:27 -070043 staticOnReceivedElement(struct ndn_ElementListener *self, uint8_t *element, size_t elementLength);
Jeff Thompson482fbd52013-07-15 16:45:29 -070044};
45
46}
47
48#endif