summaryrefslogtreecommitdiff
path: root/receiver/filehandle.h
blob: 1dc57bf2d43c96bc5fa0084172797e0e1cd17a28 (plain)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* 
 * File:   filehandle.h
 * Author: savop
 *
 * Created on 15. Oktober 2009, 10:49
 */

#ifndef _FILEHANDLE_H
#define	_FILEHANDLE_H

#include <upnp/upnp.h>
#include "../common.h"

/**
 * Interface for File Handles
 * 
 * This class is a pure virtual class to act as an interface for file handles
 * used by the webserver.
 */
class cFileHandle {
public:
    /**
     * Opens the file
     *
     * Opens the file at the given mode. These can be:
     * - \b UPNP_READ, to read from the file
     * - \b UPNP_WRITE, to write to the file
     *
     * @param mode The file mode, i.e. one of the following
     *              - \b UPNP_READ
     *              - \b UPNP_WRITE
     */
    virtual void open(
        UpnpOpenFileMode mode ///< The file mode, i.e. one of the following
                              ///< - \b UPNP_READ
                              ///< - \b UPNP_WRITE
    ) = 0;
    /**
     * Reads from the file
     *
     * Reads from the file a certain amount of bytes and stores them in a buffer
     *
     * @return returns
     * - \b <0, in case of an error
     * - \b 0, when reading was successful
     *
     * @param buf The char buffer
     * @param buflen The size of the buffer
     */
    virtual int read(
        char* buf,              ///< The char buffer
        size_t buflen           ///< The size of the buffer
    ) = 0;
    /**
     * Writes to the file
     *
     * Writes to the file a certain amount of bytes which are stored in a buffer
     *
     * @return returns
     * - \b <0, in case of an error
     * - \b 0, when reading was successful
     *
     * @param buf The char buffer
     * @param buflen The size of the buffer
     */
    virtual int write(
        char* buf,              ///< The char buffer
        size_t buflen           ///< The size of the buffer
    ) = 0;
    /**
     * Seeks in the file
     *
     * Seeks in the file where the offset is the relativ position depending on
     * the second parameter. This means, in case of
     *
     * - \b SEEK_SET, the offset is relative to the beginning of the file
     * - \b SEEK_CUR, it is relative to the current position or
     * - \b SEEK_END, relative to the end of the file.
     *
     * @return returns
     * - \b <0, in case of an error
     * - \b 0, when reading was successful
     *
     * @param offset The byte offset in the file
     * @param whence one of the following
     *               - \b SEEK_SET,
     *               - \b SEEK_CUR,
     *               - \b SEEK_END
     */
    virtual int seek(
        off_t offset,           ///< The byte offset in the file
        int whence              ///< one of the following
                                ///< - \b SEEK_SET,
                                ///< - \b SEEK_CUR,
                                ///< - \b SEEK_END
    ) = 0;
    /**
     * Closes the open file
     *
     * This will close open file handles and frees the memory obtained by it.
     */
    virtual void close() = 0;
    virtual ~cFileHandle(){};
private:
};

#endif	/* _FILEHANDLE_H */