⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 element.hh

📁 Click is a modular router toolkit. To use it you ll need to know how to compile and install the sof
💻 HH
📖 第 1 页 / 共 2 页
字号:
 * configuration parsing functions, should place that code inside a * static_cleanup() static member function.  Click's build machinery will find * that function and cause it to be called when the element code is unloaded. * * static_cleanup functions are called in an arbitrary and unpredictable order * (not, for example, the configure_phase() order, and not the reverse of the * static_initialize order).  Element authors are responsible for handling * static cleanup dependencies. * * For Click to find a static_cleanup declaration, it must appear inside the * element class's class declaration on its own line and have the following * prototype: * * @code * static void static_cleanup(); * @endcode * * It must also have public accessibility. * * @sa Element::static_initialize */inline voidElement::static_cleanup(){}/** @brief Return the element's router. */inline Router*Element::router() const{    return _router;}/** @brief Return the element's index within its router. * @invariant this == router()->element(eindex()) */inline intElement::eindex() const{    return _eindex;}/** @brief Return the element's index within router @a r. * * Returns -1 if @a r != router(). */inline intElement::eindex(Router* r) const{    return (router() == r ? _eindex : -1);}/** @brief Return the number of input or output ports. * @param isoutput false for input ports, true for output ports */inline intElement::nports(bool isoutput) const{    return _nports[isoutput];}/** @brief Return the number of input ports. */inline intElement::ninputs() const{    return _nports[0];}/** @brief Return the number of output ports. */inline intElement::noutputs() const{    return _nports[1];}/** @brief Return one of the element's ports. * @param isoutput false for input ports, true for output ports * @param port port number * * An assertion fails if @a p is out of range. */inline const Element::Port&Element::port(bool isoutput, int port) const{    assert((unsigned) port < (unsigned) _nports[isoutput]);    return _ports[isoutput][port];}/** @brief Return one of the element's input ports. * @param port port number * * An assertion fails if @a port is out of range. * * @sa Port, port */inline const Element::Port&Element::input(int port) const{    return Element::port(false, port);}/** @brief Return one of the element's output ports. * @param port port number * * An assertion fails if @a port is out of range. * * @sa Port, port */inline const Element::Port&Element::output(int port) const{    return Element::port(true, port);}/** @brief Check whether a port is active. * @param isoutput false for input ports, true for output ports * @param port port number * * Returns true iff @a port is in range and @a port is active.  Push outputs * and pull inputs are active; pull outputs and push inputs are not. * * @sa Element::Port::active */inline boolElement::port_active(bool isoutput, int port) const{    return (unsigned) port < (unsigned) nports(isoutput)	&& _ports[isoutput][port].active();}/** @brief Check whether output @a port is push. * * Returns true iff output @a port exists and is push.  @sa port_active */inline boolElement::output_is_push(int port) const{    return port_active(true, port);}/** @brief Check whether output @a port is pull. * * Returns true iff output @a port exists and is pull. */inline boolElement::output_is_pull(int port) const{    return (unsigned) port < (unsigned) nports(true)	&& !_ports[1][port].active();}/** @brief Check whether input @a port is pull. * * Returns true iff input @a port exists and is pull.  @sa port_active */inline boolElement::input_is_pull(int port) const{    return port_active(false, port);}/** @brief Check whether input @a port is push. * * Returns true iff input @a port exists and is push. */inline boolElement::input_is_push(int port) const{    return (unsigned) port < (unsigned) nports(false)	&& !_ports[0][port].active();}#if CLICK_STATS >= 2# define PORT_ASSIGN(o) _packets = 0; _owner = (o)#elif CLICK_STATS >= 1# define PORT_ASSIGN(o) _packets = 0; (void) (o)#else# define PORT_ASSIGN(o) (void) (o)#endifinlineElement::Port::Port()    : _e(0), _port(-2){    PORT_ASSIGN(0);}inline voidElement::Port::assign(Element *owner, Element *e, int port, bool isoutput){    PORT_ASSIGN(owner);    _e = e;    _port = port;    (void) isoutput;}/** @brief Returns whether this port is active (a push output or a pull input). * * @sa Element::port_active */inline boolElement::Port::active() const{    return _port >= 0;}/** @brief Returns the element connected to this active port. * * Returns 0 if this port is not active(). */inline Element*Element::Port::element() const{    return _e;}/** @brief Returns the port number of the port connected to this active port. * * Returns < 0 if this port is not active(). */inline intElement::Port::port() const{    return _port;}/** @brief Push packet @a p over this port. * * Pushes packet @a p downstream through the router configuration by passing * it to the next element's @link Element::push() push() @endlink function. * Returns when the rest of the router finishes processing @a p. * * This port must be an active() push output port.  Usually called from * element code like @link Element::output output(i) @endlink .push(p). * * When element code calls Element::Port::push(@a p), it relinquishes control * of packet @a p.  When push() returns, @a p may have been altered or even * freed by downstream elements.  Thus, you must not use @a p after pushing it * downstream.  To push a copy and keep a copy, see Packet::clone(). * * output(i).push(p) basically behaves like the following code, although it * maintains additional statistics depending on how CLICK_STATS is defined: * * @code * output(i).element()->push(output(i).port(), p); * @endcode */inline voidElement::Port::push(Packet* p) const{    assert(_e && p);#if CLICK_STATS >= 1    ++_packets;#endif#if CLICK_STATS >= 2    ++_e->input(_port)._packets;    click_cycles_t c0 = click_get_cycles();    _e->push(_port, p);    click_cycles_t x = click_get_cycles() - c0;    ++_e->_calls;    _e->_self_cycles += x;    _owner->_child_cycles += x;#else    _e->push(_port, p);#endif}/** @brief Pull a packet over this port and return it. * * Pulls a packet from upstream in the router configuration by calling the * previous element's @link Element::pull() pull() @endlink function.  When * the router finishes processing, returns the result. * * This port must be an active() pull input port.  Usually called from element * code like @link Element::input input(i) @endlink .pull(). * * input(i).pull() basically behaves like the following code, although it * maintains additional statistics depending on how CLICK_STATS is defined: * * @code * input(i).element()->pull(input(i).port()) * @endcode */inline Packet*Element::Port::pull() const{    assert(_e);#if CLICK_STATS >= 2    click_cycles_t c0 = click_get_cycles();    Packet *p = _e->pull(_port);    click_cycles_t x = click_get_cycles() - c0;    ++_e->_calls;    _e->_self_cycles += x;    _owner->_child_cycles += x;    if (p)	++_e->output(_port)._packets;#else    Packet *p = _e->pull(_port);#endif#if CLICK_STATS >= 1    if (p)	++_packets;#endif    return p;}/** @brief Push packet @a p to output @a port, or kill it if @a port is out of * range. * * @param port output port number * @param p packet to push * * If @a port is in range (>= 0 and < noutputs()), then push packet @a p * forward using output(@a port).push(@a p).  Otherwise, kill @a p with @a p * ->kill(). * * @note It is invalid to call checked_output_push() on a pull output @a port. */inline voidElement::checked_output_push(int port, Packet* p) const{    if ((unsigned) port < (unsigned) noutputs())	_ports[1][port].push(p);    else	p->kill();}#undef PORT_ASSIGNCLICK_ENDDECLS#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -