Assorted doxygen fixes; no functional changes.
[ardour.git] / libs / pbd / sndfile_manager.cc
1 /*
2     Copyright (C) 2010 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /** @file libs/pbd/sndfile_manager.cc
21  *  @brief A FileDescriptor for files opened using libsndfile.
22  */
23
24 #include <sys/time.h>
25 #include <sys/resource.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <fcntl.h>
29 #include <cassert>
30 #include <iostream>
31 #include "pbd/compose.h"
32 #include "pbd/sndfile_manager.h"
33 #include "pbd/debug.h"
34
35 using namespace std;
36 using namespace PBD;
37
38 /** @param file_name Filename.
39  *  @param writeable true to open writeable, otherwise false.
40  *  @param info SF_INFO for the file.
41  */
42
43 SndFileDescriptor::SndFileDescriptor (string const & file_name, bool writeable, SF_INFO* info)
44         : FileDescriptor (file_name, writeable)
45         , _sndfile (0)
46         , _info (info)
47 {
48         manager()->add (this);
49 }
50
51 SndFileDescriptor::~SndFileDescriptor ()
52 {
53         manager()->remove (this);
54 }
55
56 /** @return SNDFILE*, or 0 on error */
57 SNDFILE*
58 SndFileDescriptor::allocate ()
59 {
60         bool const f = manager()->allocate (this);
61         if (f) {
62                 return 0;
63         }
64
65         /* this is ok thread-wise because allocate () has incremented
66            the Descriptor's refcount, so the file will not be closed
67         */
68         return _sndfile;
69 }
70
71 void
72 SndFileDescriptor::close ()
73 {
74         /* we must have a lock on the FileManager's mutex */
75
76         assert (_sndfile);
77         sf_close (_sndfile);
78         _sndfile = 0;
79 }
80
81 bool
82 SndFileDescriptor::is_open () const
83 {
84         /* we must have a lock on the FileManager's mutex */
85
86         return _sndfile != 0;
87 }
88
89 bool
90 SndFileDescriptor::open ()
91 {
92         /* we must have a lock on the FileManager's mutex */
93         
94         _sndfile = sf_open (_path.c_str(), _writeable ? SFM_RDWR : SFM_READ, _info);
95         return (_sndfile == 0);
96 }
97