Queue.hxx 1.89 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2020 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 <string_view>
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() noexcept:id(0) {}
Max Kellermann's avatar
Max Kellermann committed
41 42 43

	UpdateQueueItem(SimpleDatabase &_db,
			Storage &_storage,
44
			std::string_view _path, bool _discard,
45
			unsigned _id) noexcept
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 noexcept {
50
		return id != 0;
51
	}
52

53
	void Clear() noexcept {
54 55
		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
	gcc_nonnull_all
	bool Push(SimpleDatabase &db, Storage &storage,
66
		  std::string_view path, bool discard, unsigned id) noexcept;
67

68
	UpdateQueueItem Pop() noexcept;
69

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

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

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

#endif