1
/* This file is part of Strigi Desktop Search
3
* Copyright (C) 2007 Jos van den Oever <jos@vandenoever.info>
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Library General Public
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Library General Public License for more details.
15
* You should have received a copy of the GNU Library General Public License
16
* along with this library; see the file COPYING.LIB. If not, write to
17
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
* Boston, MA 02110-1301, USA.
20
#ifndef STRIGI_DATAEVENTINPUTSTREAM_H
21
#define STRIGI_DATAEVENTINPUTSTREAM_H
22
#include <strigi/strigiconfig.h>
23
#include <strigi/streambase.h>
28
* @brief Handler interface for handling data events.
30
* By passing an implementation of this class to a
31
* DataEventInputStream, it will receive the data
32
* as it is read from the DataEventInputStream.
34
* See the DataEventInputStream documentation for
37
class STREAMS_EXPORT DataEventHandler {
40
virtual ~DataEventHandler() {}
42
* @brief Handle a data event.
44
* Each piece of data from an InputStream attached to a
45
* DataEventInputStream will be passed to this function
46
* (in order) as it is read from the DataEventInputStream.
48
* When handleEnd is called, it is guaranteed that each
49
* element in the input stream has been passed in exactly
50
* one call to this function, and that the calls happened
51
* in the same order as the the data occurred in the
54
* You should not call this function yourself. It forms
55
* part of an interface for the use of a DataEventInputStream.
57
* @param data pointer to the data from the inputstream
58
* @param size the size of the data pointed to by @p data
59
* @return @c true when the handler wants to receive more events
60
* false when the handler does not want any more events from this
63
virtual bool handleData(const char* data, uint32_t size) = 0;
65
* @brief Handle the end of the stream.
67
* This function will be called exactly once, and notifies
68
* the DataEventHandler that all the data from the stream
69
* has been read and passed in exactly one call to handleData.
71
virtual void handleEnd() {}
75
* @brief An InputStream that makes parallel handling of incoming data easier.
77
* When you read from this InputStream, it sends out data events to a registered
78
* handler. The data events cover all bytes in the inputstream and they are
79
* sent out in the same order as they occur in the stream. Each byte occurs in
80
* one event only. Rewinding this stream and rereading parts of it will not send
81
* a new event for the same data.
83
* Multiple DataEventInputStreams can be linked in series to send events to
86
* DataEventHandler handler1, handler2, handler3;
87
* InputStream inputStream;
88
* DataEventInputStream handlerStream1(inputStream, handler1);
89
* DataEventInputStream handlerStream2(handlerStream1, handler1);
90
* DataEventInputStream handlerStream3(handlerStream2, handler1);
91
* int nRead = handlerStream3.read(start, min, max);
94
class STREAMS_EXPORT DataEventInputStream : public InputStream {
98
DataEventHandler& handler;
104
* @brief Creates a DataEventInputStream with a given InputStream
105
* as the data source.
107
* Each instance of a DataEventHandler should only be passed to
108
* one DataEventInputStream. Behaviour is undefined otherwise.
110
* @param input the InputStream to use as the data source
111
* @param handler the DataEventHandler that should be sent the
114
explicit DataEventInputStream(InputStream *input,
115
DataEventHandler& handler);
116
int32_t read(const char*& start, int32_t min, int32_t max);
117
int64_t skip(int64_t ntoskip);
118
int64_t reset(int64_t pos);
121
} // end namespace Strigi