Click
Loading...
Searching...
No Matches
fromfile.hh
1// -*- related-file-name: "../../lib/fromfile.cc"; c-basic-offset: 4 -*-
2#ifndef CLICK_FROMFILE_HH
3#define CLICK_FROMFILE_HH
4#include <click/string.hh>
5#include <click/vector.hh>
6#include <stdio.h>
7CLICK_DECLS
8class ErrorHandler;
9class Element;
10class Packet;
11class WritablePacket;
12
13class FromFile { public:
14
15 FromFile();
16 ~FromFile() { cleanup(); }
17
18 const String &filename() const { return _filename; }
19 String &filename() { return _filename; }
20 bool initialized() const { return _fd != -1; }
21
22 void set_landmark_pattern(const String &lp) { _landmark_pattern = lp; }
23 String landmark(const String &landmark_pattern) const;
24 String landmark() const { return landmark(_landmark_pattern); }
25 String print_filename() const;
26 int lineno() const { return _lineno; }
27 void set_lineno(int lineno) { _lineno = lineno; }
28
29 off_t file_pos() const { return _file_offset + _pos; }
30
31 int configure_keywords(Vector<String>& conf, Element* e, ErrorHandler* errh);
32 int set_data(const String& data, ErrorHandler* errh);
33 int initialize(ErrorHandler* errh, bool allow_nonexistent = false);
34 void add_handlers(Element* e, bool filepos_writable = false) const;
35 void cleanup();
36 void take_state(FromFile &, ErrorHandler *);
37
38 int seek(off_t want, ErrorHandler *);
39 int reset(off_t want, ErrorHandler *);
40
41 int read(void*, uint32_t, ErrorHandler * = 0);
42 const uint8_t* get_unaligned(size_t, void*, ErrorHandler* = 0);
43 const uint8_t* get_aligned(size_t, void*, ErrorHandler* = 0);
44 String get_string(size_t, ErrorHandler* = 0);
45 Packet* get_packet(size_t, uint32_t sec, uint32_t subsec, ErrorHandler *);
46 Packet* get_packet_from_data(const void *buf, size_t buf_size, size_t full_size, uint32_t sec, uint32_t subsec, ErrorHandler *);
47 void shift_pos(int delta) { _pos += delta; }
48
49 int read_line(String &str, ErrorHandler *errh, bool temporary = false);
50 int peek_line(String &str, ErrorHandler *errh, bool temporary = false);
51
52 int error(ErrorHandler *, const char *format, ...) const;
53 int warning(ErrorHandler *, const char *format, ...) const;
54
55 private:
56 enum { BUFFER_SIZE = 32768 };
57
58 int _fd;
59 uint32_t _pos;
60 uint32_t _len;
61
62#if !CLICK_PACKET_USE_DPDK
63 WritablePacket *_data_packet;
64 const uint8_t *_buffer;
65#else
66 unsigned char _buffer[BUFFER_SIZE];
67#endif
68
69#ifdef ALLOW_MMAP
70 bool _mmap;
71#endif
72#if HAVE_DPDK
73 bool _dpdk;
74#endif
75
76#ifdef ALLOW_MMAP
77 enum { WANT_MMAP_UNIT = 4194304 }; // 4 MB
78 size_t _mmap_unit;
79 off_t _mmap_off;
80#endif
81
82 String _filename;
83 FILE *_pipe;
84 off_t _file_offset;
85 String _landmark_pattern;
86 int _lineno;
87
88#ifdef ALLOW_MMAP
89 int read_buffer_mmap(ErrorHandler *);
90#endif
91 int read_buffer(ErrorHandler *);
92 bool read_packet(ErrorHandler *);
93 int skip_ahead(ErrorHandler *);
94
95 static String filename_handler(Element *, void *);
96 static String filesize_handler(Element *, void *);
97 static String filepos_handler(Element *, void *);
98 static int filepos_write_handler(const String&, Element*, void*, ErrorHandler*);
99
100};
101
102CLICK_ENDDECLS
103#endif
Base class for Click elements.
Definition element.hh:42
Error reporting class.
Definition error.hh:90
A network packet.
Definition packet.hh:68
A string of characters.
Definition string.hh:22
Vector template.
Definition vector.hh:111
A network packet believed not to be shared.
Definition packet.hh:1004
Click's String class.
Click's vector container template.