annotate base/TempDirectory.h @ 1727:8efce64dd85e

Fix potential deadlock when notifying a handler that more models are [not] available
author Chris Cannam
date Thu, 20 Jun 2019 11:09:36 +0100
parents fbe8afdfa8a6
children
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@1519 16 #ifndef SV_TEMP_DIRECTORY_H
Chris@1519 17 #define SV_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@460 41 * Return the path of the directory in which the temporary
Chris@460 42 * directory has been or will be created. This directory is
Chris@460 43 * particular to this application, although not to this instance
Chris@460 44 * of it, and it will not be removed when the application exits.
Chris@460 45 * Persistent cache data or similar may be placed in this
Chris@460 46 * directory or other, non-temporary subdirectories of it.
Chris@460 47 *
Chris@460 48 * If this directory does not exist, it will be created. Throw
Chris@460 49 * DirectoryCreationFailed if the directory cannot be created.
Chris@460 50 */
Chris@460 51 QString getContainingPath();
Chris@460 52
Chris@460 53 /**
Chris@81 54 * Create the root temporary directory if necessary, and return
Chris@460 55 * its path. This directory will be removed when the application
Chris@460 56 * exits.
Chris@460 57 *
Chris@460 58 * Throw DirectoryCreationFailed if the directory cannot be
Chris@460 59 * created.
Chris@81 60 */
Chris@81 61 QString getPath();
Chris@81 62
Chris@81 63 /**
Chris@81 64 * Create an immediate subdirectory of the root temporary
Chris@81 65 * directory of the given name, if it doesn't already exist, and
Chris@460 66 * return its path. This directory will be removed when the
Chris@460 67 * application exits.
Chris@460 68 *
Chris@460 69 * Throw DirectoryCreationFailed if the directory cannot be
Chris@460 70 * created.
Chris@81 71 */
Chris@81 72 QString getSubDirectoryPath(QString subdir);
Chris@81 73
Chris@81 74 /**
Chris@81 75 * Delete the temporary directory (before exiting).
Chris@81 76 */
Chris@81 77 void cleanup();
Chris@81 78
Chris@81 79 protected:
Chris@81 80 TempDirectory();
Chris@98 81
Chris@98 82 QString createTempDirectoryIn(QString inDir);
Chris@81 83 void cleanupDirectory(QString tmpDir);
Chris@98 84 void cleanupAbandonedDirectories(QString svDir);
Chris@98 85
Chris@81 86 QString m_tmpdir;
Chris@81 87 QMutex m_mutex;
Chris@81 88
Chris@81 89 static TempDirectory *m_instance;
Chris@81 90 };
Chris@81 91
Chris@81 92
Chris@81 93 #endif