setanno element

John Bicket jbicket at mit.edu
Wed Jun 25 23:23:56 EDT 2003


Hi, 

I wrote a more generic version of paint that I have found useful and I wanted to stick it 
in elements/standard.

If I don't hear anything back within a few days, I'll go ahead and commit it.

Any other thoughts?

--john


#ifndef CLICK_SETANNO_HH
#define CLICK_SETANNO_HH
#include <click/element.hh>
CLICK_DECLS

/*
=c

SetAnno(OFFSET, VALUE)

=s annotations

sets packet user annotations

=d

Sets each packet's user annotation at OFFSET to VALUE, an integer 0..255. 

=n

VALUE is stored in user annotation OFFSET.

=a Paint */

class SetAnno : public Element {
  
  unsigned char _value;
  int _offset;
 public:
  
  SetAnno();
  ~SetAnno();
  
  const char *class_name() const		{ return "SetAnno"; }
  const char *processing() const		{ return AGNOSTIC; }
  SetAnno *clone() const;
  
  int configure(Vector<String> &, ErrorHandler *);

  Packet *simple_action(Packet *);

  void add_handlers();
  static String offset_read_handler(Element *e, void *);
  static String value_read_handler(Element *e, void *);
};

CLICK_ENDDECLS
#endif




----------------------------

/*
 * setanno.{cc,hh} -- element sets packets' user annotation
 * John Bicket
 *
 * Copyright (c) 1999-2000 Massachusetts Institute of Technology
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, subject to the conditions
 * listed in the Click LICENSE file. These conditions include: you must
 * preserve this copyright notice, and you cannot mention the copyright
 * holders in advertising related to the Software without their permission.
 * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
 * notice is a summary of the Click LICENSE file; the license in that file is
 * legally binding.
 */

#include <click/config.h>
#include "setanno.hh"
#include <click/confparse.hh>
#include <click/error.hh>
#include <click/glue.hh>
#include <click/straccum.hh>
#include <click/packet_anno.hh>
CLICK_DECLS

SetAnno::SetAnno()
  : Element(1, 1)
{
  MOD_INC_USE_COUNT;
  _offset = 0;
  _value = 0;
}

SetAnno::~SetAnno()
{
  MOD_DEC_USE_COUNT;
}

SetAnno *
SetAnno::clone() const
{
  return new SetAnno();
}

int
SetAnno::configure(Vector<String> &conf, ErrorHandler *errh)
{
  return cp_va_parse(conf, this, errh,
		     cpInteger, "offset", &_offset,
		     cpByte, "value", &_value,
		     0);
}

Packet *
SetAnno::simple_action(Packet *p)
{
  (p)->set_user_anno_c(_offset, _value);
  return p;
}

String
SetAnno::offset_read_handler(Element *e, void *)
{
  SetAnno *anno = (SetAnno *)e;
  StringAccum sa;
  sa << anno->_offset << "\n";
  return sa.take_string();
}


String
SetAnno::value_read_handler(Element *e, void *)
{
  SetAnno *anno = (SetAnno *)e;
  StringAccum sa;
  sa << (int)anno->_value << "\n";
  return sa.take_string();
}

void
SetAnno::add_handlers()
{
  add_read_handler("offset", offset_read_handler, (void *)0);
  add_read_handler("value", value_read_handler, (void *)0);
}

CLICK_ENDDECLS
EXPORT_ELEMENT(SetAnno)
ELEMENT_MT_SAFE(SetAnno)





More information about the click mailing list