-
Notifications
You must be signed in to change notification settings - Fork 78
/
clipboard.hh
72 lines (53 loc) · 2 KB
/
clipboard.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// -*- c-basic-offset: 4 -*-
#ifndef CLICK_CLIPBOARD_HH
#define CLICK_CLIPBOARD_HH
#include <click/element.hh>
CLICK_DECLS
/*
=c
Clipboard(RANGE_1, ..., RANGE_N)
=s basicmod
copies data from one packet to another
=d
Takes as arguments one or more byte ranges to copy. When Clipboard receives a
packet on input 0, it copies the selected bytes to the clipboard buffer and
emits the packet unchanged on output 0. When receiving a packet on input 1,
Clipboard updates the packet with the bytes from the buffer and outputs the
modified packet on output 1. This way, data from a single packet can be copied
to 0 or more packets.
Each RANGE is on the form C<x/n>, where C<x> is the offset and C<n> the number
of bytes.
Each Clipboard input/output pair can work in either a push or a pull context.
Clipboard can also be used to copy data from one place in a packet to another,
by looping the same packet back through Clipboard and using Strip and Unstrip
to offset the packet data.
Passing a packet through input/output 1 before any packets have passed through
input/output 0 will cause undefined data to be written into the packet. Passing
a packet through input/output 1 which is too small for any one of the ranges
will cause the packet contents to be undefined.
=a StoreData, Strip, Unstrip
*/
struct Range {
uint32_t offset;
uint32_t length;
};
class Clipboard : public Element {
public:
Clipboard() CLICK_COLD;
const char *class_name() const override { return "Clipboard"; }
const char *flags() const { return "S0"; }
const char *flow_code() const { return "#/#"; }
const char *port_count() const override { return "2/2"; }
int configure(Vector<String> &, ErrorHandler *) CLICK_COLD;
bool can_live_reconfigure() const { return true; }
Packet *pull(int port);
void push(int port, Packet *p);
private:
Vector<unsigned char> _clipboard;
Vector<Range> _ranges;
uint32_t _minPacketLength;
void copy(Packet *p);
Packet *paste(Packet *p);
};
CLICK_ENDDECLS
#endif