X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fpbd%2Fpbd%2Ffile_manager.h;h=14552f9fefaf16269a964f562de99613a353cfee;hb=e6521bb0434d88802aa28e75235bc8c19ebb9262;hp=3f708eb44e14a16ba925445fad10ffa93c6cd74a;hpb=f1114dedeecf4279a4c19a85be0c11e9fde5610b;p=ardour.git diff --git a/libs/pbd/pbd/file_manager.h b/libs/pbd/pbd/file_manager.h index 3f708eb44e..14552f9fef 100644 --- a/libs/pbd/pbd/file_manager.h +++ b/libs/pbd/pbd/file_manager.h @@ -23,8 +23,8 @@ #include #include #include -#include -#include +#include +#include #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 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 _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