Queue.hxx 1.86 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2019 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 "util/Compiler.h"
24

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

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

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

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

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

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

48
	bool IsDefined() const noexcept {
49
		return id != 0;
50
	}
51

52
	void Clear() noexcept {
53 54
		id = 0;
	}
55 56
};

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

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

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

67
	UpdateQueueItem Pop() noexcept;
68

69
	void Clear() noexcept {
70
		update_queue.clear();
71
	}
Max Kellermann's avatar
Max Kellermann committed
72 73

	gcc_nonnull_all
74
	void Erase(SimpleDatabase &db) noexcept;
Max Kellermann's avatar
Max Kellermann committed
75 76

	gcc_nonnull_all
77
	void Erase(Storage &storage) noexcept;
78
};
79 80

#endif