Queue.hxx 1.77 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright (C) 2003-2014 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"
Max Kellermann's avatar
Max Kellermann committed
24
#include "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
class UpdateQueue {
	static constexpr unsigned MAX_UPDATE_QUEUE_SIZE = 32;
56

57
	std::list<UpdateQueueItem> update_queue;
58 59

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

	UpdateQueueItem Pop();
65 66

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

	gcc_nonnull_all
	void Erase(SimpleDatabase &db);

	gcc_nonnull_all
	void Erase(Storage &storage);
75
};
76 77

#endif