annotate base/TempDirectory.h @ 99:9a44ccae165c

...
author Chris Cannam
date Fri, 05 May 2006 11:33:51 +0000
parents 604bd4ee3ed4
children b290c43f01ec
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@81 36 static TempDirectory *instance();
Chris@81 37
Chris@81 38 virtual ~TempDirectory();
Chris@81 39
Chris@81 40 class DirectoryCreationFailed : virtual public std::exception
Chris@81 41 {
Chris@81 42 public:
Chris@81 43 DirectoryCreationFailed(QString directory) throw();
Chris@81 44 virtual DirectoryCreationFailed::~DirectoryCreationFailed() throw() { }
Chris@81 45 virtual const char *what() const throw();
Chris@81 46
Chris@81 47 protected:
Chris@81 48 QString m_directory;
Chris@81 49 };
Chris@81 50
Chris@81 51 /**
Chris@81 52 * Create the root temporary directory if necessary, and return
Chris@81 53 * its path. Throw DirectoryCreationFailed if the directory
Chris@81 54 * cannot be created.
Chris@81 55 */
Chris@81 56 QString getPath();
Chris@81 57
Chris@81 58 /**
Chris@81 59 * Create an immediate subdirectory of the root temporary
Chris@81 60 * directory of the given name, if it doesn't already exist, and
Chris@81 61 * return its path. Throw DirectoryCreationFailed if the
Chris@81 62 * directory cannot be created.
Chris@81 63 */
Chris@81 64 QString getSubDirectoryPath(QString subdir);
Chris@81 65
Chris@81 66 /**
Chris@81 67 * Delete the temporary directory (before exiting).
Chris@81 68 */
Chris@81 69 void cleanup();
Chris@81 70
Chris@81 71 protected:
Chris@81 72 TempDirectory();
Chris@98 73
Chris@98 74 QString createTempDirectoryIn(QString inDir);
Chris@81 75 void cleanupDirectory(QString tmpDir);
Chris@98 76 void cleanupAbandonedDirectories(QString svDir);
Chris@98 77
Chris@81 78 QString m_tmpdir;
Chris@81 79 QMutex m_mutex;
Chris@81 80
Chris@81 81 static TempDirectory *m_instance;
Chris@81 82 };
Chris@81 83
Chris@81 84
Chris@81 85 #endif