Move docs for PBD::sys::get_absolute_path into header
[ardour.git] / libs / pbd / file_manager.cc
index 0f05ecedc4c438daf5453408caa76831f3c139e7..29ef7d6e6ee6245bc72b99b97b551ebcd02e6adf 100644 (file)
@@ -23,7 +23,6 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <cassert>
-#include <iostream>
 #include <cstdio>
 
 #ifdef __APPLE__
@@ -100,23 +99,23 @@ FileManager::allocate (FileDescriptor* d)
                                DEBUG::FileManager,
                                string_compose (
                                        "closed file for %1 to release file handle; now have %2 of %3 open\n",
-                                       (*oldest)->_name, _open, _max_open
+                                       (*oldest)->_path, _open, _max_open
                                        )
                                );
                }
 
                if (d->open ()) {
-                       DEBUG_TRACE (DEBUG::FileManager, string_compose ("open of %1 failed.\n", d->_name));
+                       DEBUG_TRACE (DEBUG::FileManager, string_compose ("open of %1 failed.\n", d->_path));
                        return true;
                }
 
                _open++;
 
-               DEBUG_TRACE (DEBUG::FileManager, string_compose ("opened file for %1; now have %2 of %3 open.\n", d->_name, _open, _max_open));
+               DEBUG_TRACE (DEBUG::FileManager, string_compose ("opened file for %1; now have %2 of %3 open.\n", d->_path, _open, _max_open));
        }
 
 #ifdef __APPLE__
-       d->_last_used = get_absolute_time();
+       d->_last_used = mach_absolute_time();
 #else
        struct timespec t;
        clock_gettime (CLOCK_MONOTONIC, &t);
@@ -148,7 +147,7 @@ FileManager::remove (FileDescriptor* d)
                close (d);
                DEBUG_TRACE (
                        DEBUG::FileManager,
-                       string_compose ("closed file for %1; file is being removed; now have %2 of %3 open\n", d->_name, _open, _max_open)
+                       string_compose ("closed file for %1; file is being removed; now have %2 of %3 open\n", d->_path, _open, _max_open)
                        );
        }
 
@@ -168,7 +167,7 @@ FileManager::close (FileDescriptor* d)
 FileDescriptor::FileDescriptor (string const & n, bool w)
        : _refcount (0)
        , _last_used (0)
-       , _name (n)
+       , _path (n)
        , _writeable (w)
 {
 
@@ -193,15 +192,15 @@ FileDescriptor::release ()
 
 
 
-/** @param n Filename.
- *  @param w true to open writeable, otherwise false.
- *  @param m Open mode for the file.
+/** @param file_name Filename.
+ *  @param writeable true to open writeable, otherwise false.
+ *  @param mode Open mode for the file.
  */
 
-FdFileDescriptor::FdFileDescriptor (string const & n, bool w, mode_t m)
-       : FileDescriptor (n, w)
+FdFileDescriptor::FdFileDescriptor (string const & file_name, bool writeable, mode_t mode)
+       : FileDescriptor (file_name, writeable)
        , _fd (-1)
-       , _mode (m)
+       , _mode (mode)
 {
        manager()->add (this);
 }
@@ -224,7 +223,7 @@ FdFileDescriptor::open ()
 {
        /* we must have a lock on the FileManager's mutex */
        
-       _fd = ::open (_name.c_str(), _writeable ? (O_RDWR | O_CREAT) : O_RDONLY, _mode);
+       _fd = ::open (_path.c_str(), _writeable ? (O_RDWR | O_CREAT) : O_RDONLY, _mode);
        return (_fd == -1);
 }
 
@@ -253,14 +252,20 @@ FdFileDescriptor::allocate ()
 }
 
 
-/** @param n Filename.
- *  @param w true to open writeable, otherwise false.
+void
+FileDescriptor::set_path (const string& p)
+{
+        _path = p;
+}
+
+/** @param file_name Filename.
+ *  @param mode Mode to pass to fopen.
  */
 
-StdioFileDescriptor::StdioFileDescriptor (string const & n, std::string const & m)
-       : FileDescriptor (n, false)
+StdioFileDescriptor::StdioFileDescriptor (string const & file_name, std::string const & mode)
+       : FileDescriptor (file_name, false)
        , _file (0)
-       , _mode (m)
+       , _mode (mode)
 {
        manager()->add (this);
 }
@@ -283,7 +288,7 @@ StdioFileDescriptor::open ()
 {
        /* we must have a lock on the FileManager's mutex */
        
-       _file = fopen (_name.c_str(), _mode.c_str());
+       _file = fopen (_path.c_str(), _mode.c_str());
        return (_file == 0);
 }