Merge branch 'master' into cairocanvas
[ardour.git] / libs / pbd / pbd / file_manager.h
index 3f708eb44e14a16ba925445fad10ffa93c6cd74a..14552f9fefaf16269a964f562de99613a353cfee 100644 (file)
@@ -23,8 +23,8 @@
 #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 {
@@ -51,7 +51,10 @@ public:
        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;
@@ -71,7 +74,7 @@ protected:
 
        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 ();
@@ -81,32 +84,12 @@ private:
        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 ();
@@ -127,7 +110,7 @@ private:
 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 ();
@@ -144,6 +127,29 @@ private:
        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