#include <sys/types.h>
#include <string>
#include <map>
-#include <sndfile.h>
-#include <glibmm/thread.h>
+#include <list>
+#include <glibmm/threads.h>
#include "pbd/signals.h"
namespace PBD {
FileDescriptor (std::string const &, bool);
virtual ~FileDescriptor () {}
+ const std::string& path() const { return _path; }
+
void release ();
+ virtual void set_path (const std::string&);
/** Emitted when the file is closed */
PBD::Signal0<void> Closed;
int _refcount; ///< number of active users of this file
double _last_used; ///< monotonic time that this file was last allocated
- std::string _name; ///< filename
+ std::string _path; ///< file path
bool _writeable; ///< true if it should be opened writeable, otherwise false
FileManager* manager ();
static FileManager* _manager;
};
-/** FileDescriptor for a file to be opened using libsndfile */
-class SndFileDescriptor : public FileDescriptor
-{
-public:
- SndFileDescriptor (std::string const &, bool, SF_INFO *);
- ~SndFileDescriptor ();
-
- SNDFILE* allocate ();
-
-private:
-
- friend class FileManager;
-
- bool open ();
- void close ();
- bool is_open () const;
-
- SNDFILE* _sndfile; ///< SNDFILE* pointer, or 0 if the file is closed
- SF_INFO* _info; ///< libsndfile's info for this file
-};
/** FileDescriptor for a file to be opened using POSIX open */
class FdFileDescriptor : public FileDescriptor
{
public:
- FdFileDescriptor (std::string const &, bool, mode_t);
+ FdFileDescriptor (std::string const & file_name, bool writeable, mode_t mode);
~FdFileDescriptor ();
int allocate ();
class StdioFileDescriptor : public FileDescriptor
{
public:
- StdioFileDescriptor (std::string const &, std::string const &);
+ StdioFileDescriptor (std::string const & file_name, std::string const & mode);
~StdioFileDescriptor ();
FILE* allocate ();
std::string _mode;
};
+
+/** Class to limit the number of files held open */
+class FileManager
+{
+public:
+ FileManager ();
+
+ void add (FileDescriptor *);
+ void remove (FileDescriptor *);
+
+ void release (FileDescriptor *);
+ bool allocate (FileDescriptor *);
+
+private:
+
+ void close (FileDescriptor *);
+
+ std::list<FileDescriptor*> _files; ///< files we know about
+ Glib::Threads::Mutex _mutex; ///< mutex for _files, _open and FileDescriptor contents
+ int _open; ///< number of open files
+ int _max_open; ///< maximum number of open files
+};
+
}
#endif