~vanvugt/ubuntu/oneiric/mediatomb/fix-770964-784431

« back to all changes in this revision

Viewing changes to src/fd_io_handler.h

  • Committer: Bazaar Package Importer
  • Author(s): Andres Mejia
  • Date: 2009-04-22 21:39:19 UTC
  • mto: (4.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20090422213919-52m015y6gcpv1m1g
Tags: upstream-0.12.0~svn2018
ImportĀ upstreamĀ versionĀ 0.12.0~svn2018

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*MT*
 
2
    
 
3
    MediaTomb - http://www.mediatomb.cc/
 
4
    
 
5
    fd_io_handler.h - this file is part of MediaTomb.
 
6
    
 
7
    Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>,
 
8
                       Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>
 
9
    
 
10
    Copyright (C) 2006-2009 Gena Batyan <bgeradz@mediatomb.cc>,
 
11
                            Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>,
 
12
                            Leonhard Wimmer <leo@mediatomb.cc>
 
13
    
 
14
    MediaTomb is free software; you can redistribute it and/or modify
 
15
    it under the terms of the GNU General Public License version 2
 
16
    as published by the Free Software Foundation.
 
17
    
 
18
    MediaTomb is distributed in the hope that it will be useful,
 
19
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
    GNU General Public License for more details.
 
22
    
 
23
    You should have received a copy of the GNU General Public License
 
24
    version 2 along with MediaTomb; if not, write to the Free Software
 
25
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
26
    
 
27
    $Id$
 
28
*/
 
29
 
 
30
/// \file fd_io_handler.h
 
31
/// \brief Definition of the FDIOHandler class.
 
32
#ifndef __FD_IO_HANDLER_H__
 
33
#define __FD_IO_HANDLER_H__
 
34
 
 
35
#include "common.h"
 
36
#include "io_handler.h"
 
37
 
 
38
/// \brief Allows the web server to read from a file, operation is blocking.
 
39
class FDIOHandler : public IOHandler
 
40
{
 
41
protected:
 
42
    /// \brief Name of the file.
 
43
    zmm::String filename;
 
44
 
 
45
    /// \brief Handle of the file.
 
46
    int fd;
 
47
    bool closed;
 
48
    zmm::Ref<IOHandler> other;
 
49
    zmm::Ref<zmm::Array<zmm::Object> > reference_list;
 
50
public:
 
51
    /// \brief Sets the filename to work with.
 
52
    FDIOHandler(zmm::String filename);
 
53
 
 
54
    /// \brief Sets an aleady opened file descriptor to work with, call to
 
55
    /// open() will be ignored.
 
56
    FDIOHandler(int fd);
 
57
 
 
58
    void addReference(zmm::Ref<zmm::Object> reference);
 
59
    void closeOther(zmm::Ref<IOHandler> other);
 
60
 
 
61
    /// \brief Opens file for reading (writing is not supported)
 
62
    virtual void open(IN enum UpnpOpenFileMode mode);
 
63
 
 
64
    /// \brief Reads a previously opened file sequentially.
 
65
    /// \param buf Data from the file will be copied into this buffer.
 
66
    /// \param length Number of bytes to be copied into the buffer.
 
67
    virtual int read(OUT char *buf, IN size_t length);
 
68
   
 
69
    /// \brief Writes to a previously opened file.
 
70
    /// \param buf Data from the buffer will be written to the file.
 
71
    /// \param length Number of bytes to be written from the buffer.
 
72
    /// \return number of bytes written.
 
73
    virtual int write(OUT char *buf, IN size_t length);
 
74
 
 
75
    /// \brief Performs seek on an open file.
 
76
    /// \param offset Number of bytes to move in the file. For seeking forwards
 
77
    /// positive values are used, for seeking backwards - negative. Offset must
 
78
    /// be positive if origin is set to SEEK_SET
 
79
    /// \param whence The position to move relative to. SEEK_CUR to move relative
 
80
    /// to current position, SEEK_END to move relative to the end of file,
 
81
    /// SEEK_SET to specify an absolute offset.
 
82
    virtual void seek(IN off_t offset, IN int whence);
 
83
 
 
84
    /// \brief Close a previously opened file.
 
85
    virtual void close();
 
86
};
 
87
 
 
88
 
 
89
#endif // __FD_IO_HANDLER_H__