simclick / CLICK_DECLS, CLICK_ENDDECLS

Eddie Kohler kohler at icir.org
Mon Aug 5 22:24:05 EDT 2002


Hi all,

The rad nsclick work from Colorado
<http://systems.cs.colorado.edu/Networking/nsclick/>, 
which makes a version of Click that can run inside the NS-2 simulator, is
beginning to be integrated into the main Click repository.

One change so far that everyone should know about. All declarations and
definitions of Click-related C++ code should be wrapped in the macros
CLICK_DECLS and CLICK_ENDDECLS. Usually, header files will look like this:

    #ifndef CLICK_HEADER_HH
    #define CLICK_HEADER_HH
    #include <click/element.hh>
    #include <whatever.h>
    #include <click/whatever.hh>
    CLICK_DECLS

    // ... class and function declarations ...

    CLICK_ENDDECLS
    #endif

and source files will look like this:

    /* Comment... */
    #include <click/config.h>
    #include <click/whatever.hh>
    #include <sys/whatever.h>
    #include "whatever.hh"
    CLICK_DECLS

    // ... function and method definitions ...

    EXPORT_ELEMENT(Whatever)
    CLICK_ENDDECLS

Why? Some Click identifiers unfortunately conflict with identifiers inside
NS. When compiling under NS, the CLICK_DECLS and CLICK_ENDDECLS macros will
expand into `namespace Click {' and `}', thus shoving all Click code into a
separate namespace where it can't hurt anyone.

There is no need to use the macros in your elements if you don't plan to
support nsclick.

There are 4 macros altogether; here is how they expand:

    Macro               Normal drivers  Simulator drivers
    CLICK_DECLS         /* */           namespace Click {
    CLICK_ENDDECLS      /* */           }
    CLICK_USING_DECLS   /* */           using namespace Click;
    CLICK_NAME(n)       n               Click::n

All the necessary code has been checked in to the repository, and all
elements have been updated.

Eddie

Michael Neufeld <neufeldm at cs.colorado.edu> and others (?) did the nsclick
patch. Many thanks!




More information about the click mailing list