annotate base/TempDirectory.h @ 267:fa612dc181af

* Fix failure to play right to the end of files loaded from mp3 or ogg
author Chris Cannam
date Thu, 14 Jun 2007 13:49:30 +0000
parents 82f529a08cf3
children 93fb1ebff76b
rev   line source
Chris@81 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@81 2
Chris@81 3 /*
Chris@81 4 Sonic Visualiser
Chris@81 5 An audio file viewer and annotation editor.
Chris@81 6 Centre for Digital Music, Queen Mary, University of London.
Chris@81 7 This file copyright 2006 Chris Cannam.
Chris@81 8
Chris@81 9 This program is free software; you can redistribute it and/or
Chris@81 10 modify it under the terms of the GNU General Public License as
Chris@81 11 published by the Free Software Foundation; either version 2 of the
Chris@81 12 License, or (at your option) any later version. See the file
Chris@81 13 COPYING included with this distribution for more information.
Chris@81 14 */
Chris@81 15
Chris@81 16 #ifndef _TEMP_DIRECTORY_H_
Chris@81 17 #define _TEMP_DIRECTORY_H_
Chris@81 18
Chris@81 19 #include <QString>
Chris@81 20 #include <QMutex>
Chris@81 21
Chris@81 22 #include <exception>
Chris@81 23
Chris@81 24 /**
Chris@81 25 * A class that manages the creation and removal of a temporary
Chris@81 26 * directory tree to store data during the program run. There is one
Chris@81 27 * root temporary directory for the program, created on demand and
Chris@81 28 * deleted when the program exits.
Chris@81 29 *
Chris@81 30 * This class is thread safe.
Chris@81 31 */
Chris@81 32
Chris@81 33 class TempDirectory
Chris@81 34 {
Chris@81 35 public:
Chris@145 36 static TempDirectory *getInstance();
Chris@81 37
Chris@81 38 virtual ~TempDirectory();
Chris@81 39
Chris@81 40 /**
Chris@81 41 * Create the root temporary directory if necessary, and return
Chris@81 42 * its path. Throw DirectoryCreationFailed if the directory
Chris@81 43 * cannot be created.
Chris@81 44 */
Chris@81 45 QString getPath();
Chris@81 46
Chris@81 47 /**
Chris@81 48 * Create an immediate subdirectory of the root temporary
Chris@81 49 * directory of the given name, if it doesn't already exist, and
Chris@81 50 * return its path. Throw DirectoryCreationFailed if the
Chris@81 51 * directory cannot be created.
Chris@81 52 */
Chris@81 53 QString getSubDirectoryPath(QString subdir);
Chris@81 54
Chris@81 55 /**
Chris@81 56 * Delete the temporary directory (before exiting).
Chris@81 57 */
Chris@81 58 void cleanup();
Chris@81 59
Chris@81 60 protected:
Chris@81 61 TempDirectory();
Chris@98 62
Chris@98 63 QString createTempDirectoryIn(QString inDir);
Chris@81 64 void cleanupDirectory(QString tmpDir);
Chris@98 65 void cleanupAbandonedDirectories(QString svDir);
Chris@98 66
Chris@81 67 QString m_tmpdir;
Chris@81 68 QMutex m_mutex;
Chris@81 69
Chris@81 70 static TempDirectory *m_instance;
Chris@81 71 };
Chris@81 72
Chris@81 73
Chris@81 74 #endif