Queue.hxx 1.81 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2021 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 <string>
24
#include <string_view>
25
#include <list>
26

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

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

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

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

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

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

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

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

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

public:
Max Kellermann's avatar
Max Kellermann committed
62
	bool Push(SimpleDatabase &db, Storage &storage,
63
		  std::string_view path, bool discard, unsigned id) noexcept;
64

65
	UpdateQueueItem Pop() noexcept;
66

67
	void Clear() noexcept {
68
		update_queue.clear();
69
	}
Max Kellermann's avatar
Max Kellermann committed
70

71
	void Erase(SimpleDatabase &db) noexcept;
Max Kellermann's avatar
Max Kellermann committed
72

73
	void Erase(Storage &storage) noexcept;
74
};
75 76

#endif