📄 timerange.cc
字号:
// -*- mode: c++; c-basic-offset: 4 -*-/* * timerange.{cc,hh} -- element observes range of timestamps * Eddie Kohler * * Copyright (c) 2001 International Computer Science Institute * * 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 <click/error.hh>#include "timerange.hh"#include <click/confparse.hh>#include <click/straccum.hh>CLICK_DECLSTimeRange::TimeRange(){}TimeRange::~TimeRange(){}intTimeRange::configure(Vector<String> &conf, ErrorHandler *errh){ _simple = false; if (cp_va_kparse(conf, this, errh, "SIMPLE", 0, cpBool, &_simple, cpEnd) < 0) return -1; return 0;}Packet *TimeRange::simple_action(Packet *p){ const Timestamp& tv = p->timestamp_anno(); if (!_first) _first = _last = tv; else if (_simple) _last = tv; else if (_last < tv) _last = tv; else if (tv < _first) _first = tv; return p;}StringTimeRange::read_handler(Element *e, void *thunk){ TimeRange *tr = static_cast<TimeRange *>(e); StringAccum sa; switch ((intptr_t)thunk) { case h_range: sa << tr->_first << ' ' << tr->_last; break; case h_interval: sa << (tr->_last - tr->_first); break; } return sa.take_string();}intTimeRange::write_handler(const String &, Element *e, void *, ErrorHandler *){ TimeRange *tr = static_cast<TimeRange *>(e); tr->_first = tr->_last = Timestamp(); return 0;}voidTimeRange::add_handlers(){ add_data_handlers("first", Handler::OP_READ, &_first); add_data_handlers("last", Handler::OP_READ, &_last); add_read_handler("range", read_handler, h_range); add_read_handler("interval", read_handler, h_interval); add_write_handler("reset", write_handler, h_reset, Handler::BUTTON);}CLICK_ENDDECLSEXPORT_ELEMENT(TimeRange)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -