Queue.hxx 1.8 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2017 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 * http://www.musicpd.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

Max Kellermann's avatar
Max Kellermann committed
20 21
#ifndef MPD_UPDATE_QUEUE_HXX
#define MPD_UPDATE_QUEUE_HXX
22

23
#include "check.h"
24
#include "util/Compiler.h"
25

26
#include <string>
27
#include <list>
28

Max Kellermann's avatar
Max Kellermann committed
29 30 31
class SimpleDatabase;
class Storage;

32
struct UpdateQueueItem {
Max Kellermann's avatar
Max Kellermann committed
33 34 35
	SimpleDatabase *db;
	Storage *storage;

36
	std::string path_utf8;
37
	unsigned id;
38 39
	bool discard;

40
	UpdateQueueItem():id(0) {}
Max Kellermann's avatar
Max Kellermann committed
41 42 43 44

	UpdateQueueItem(SimpleDatabase &_db,
			Storage &_storage,
			const char *_path, bool _discard,
45
			unsigned _id)
Max Kellermann's avatar
Max Kellermann committed
46 47
		:db(&_db), storage(&_storage), path_utf8(_path),
		 id(_id), discard(_discard) {}
48 49

	bool IsDefined() const {
50
		return id != 0;
51
	}
52 53 54 55

	void Clear() {
		id = 0;
	}
56 57
};

58 59
class UpdateQueue {
	static constexpr unsigned MAX_UPDATE_QUEUE_SIZE = 32;
60

61
	std::list<UpdateQueueItem> update_queue;
62 63

public:
Max Kellermann's avatar
Max Kellermann committed
64 65 66
	gcc_nonnull_all
	bool Push(SimpleDatabase &db, Storage &storage,
		  const char *path, bool discard, unsigned id);
67 68

	UpdateQueueItem Pop();
69 70

	void Clear() {
71
		update_queue.clear();
72
	}
Max Kellermann's avatar
Max Kellermann committed
73 74 75 76 77 78

	gcc_nonnull_all
	void Erase(SimpleDatabase &db);

	gcc_nonnull_all
	void Erase(Storage &storage);
79
};
80 81

#endif