MPD 0.20.6

- Main Page
- Namespaces
- Data Structures
- Files

- File List
- Globals

Service.hxx
Go to the documentation of this file.
1 /*
2 * Copyright 2003-2017 The Music Player Daemon Project
3 * http://www.musicpd.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef MPD_UPDATE_SERVICE_HXX
21 #define MPD_UPDATE_SERVICE_HXX
22
23 #include "check.h"
24 #include "Queue.hxx"
25 #include "event/DeferredMonitor.hxx"
26 #include "thread/Thread.hxx"
27 #include "Compiler.h"
28
29 class SimpleDatabase;
30 class DatabaseListener;
31 class UpdateWalk;
32 class CompositeStorage;
33
37 class UpdateService final : DeferredMonitor {
38 SimpleDatabase &db;
39 CompositeStorage &storage;
40
41 DatabaseListener &listener;
42
43 bool modified;
44
45 Thread update_thread;
46
47 static constexpr unsigned update_task_id_max = 1 << 15;
48
49 unsigned update_task_id;
50
51 UpdateQueue queue;
52
53 UpdateQueueItem next;
54
55 UpdateWalk *walk;
56
57 public:
58 UpdateService(EventLoop &_loop, SimpleDatabase &_db,
59 CompositeStorage &_storage,
60 DatabaseListener &_listener);
61
62 ~UpdateService();
63
68 unsigned GetId() const {
69 return next.id;
70 }
71
79 gcc_nonnull_all
80 unsigned Enqueue(const char *path, bool discard);
81
86 void CancelAllAsync();
87
93 void CancelMount(const char *uri);
94
95 private:
96 /* virtual methods from class DeferredMonitor */
97 virtual void RunDeferred() override;
98
99 /* the update thread */
100 void Task();
101 static void Task(void *ctx);
102
103 void StartThread(UpdateQueueItem &&i);
104
105 unsigned GenerateId();
106 };
107
108 #endif
UpdateQueueItem::id
unsigned id
Definition: Queue.hxx:37
check.h
gcc_nonnull_all
#define gcc_nonnull_all
Definition: Compiler.h:122
UpdateService::~UpdateService
~UpdateService()
UpdateQueue
Definition: Queue.hxx:54
EventLoop
An event loop that polls for events on file/socket descriptors.
Definition: Loop.hxx:51
UpdateQueueItem
Definition: Queue.hxx:32
UpdateWalk
Definition: Walk.hxx:34
UpdateService::UpdateService
UpdateService(EventLoop &_loop, SimpleDatabase &_db, CompositeStorage &_storage, DatabaseListener &_listener)
DatabaseListener
An object that listens to events from the Database.
Definition: DatabaseListener.hxx:30
DeferredMonitor
Defer execution of an event into an EventLoop.
Definition: DeferredMonitor.hxx:32
Thread.hxx
Compiler.h
UpdateService::Enqueue
gcc_nonnull_all unsigned Enqueue(const char *path, bool discard)
Add this path to the database update queue.
UpdateService::GetId
unsigned GetId() const
Returns a non-zero job id when we are currently updating the database.
Definition: Service.hxx:68
UpdateService
This class manages the update queue and runs the update thread.
Definition: Service.hxx:37
UpdateService::CancelMount
void CancelMount(const char *uri)
Cancel all updates for the given mount point.
SimpleDatabase
Definition: SimpleDatabasePlugin.hxx:38
DeferredMonitor.hxx
Thread
Definition: Thread.hxx:34
Queue.hxx
CompositeStorage
A Storage implementation that combines multiple other Storage instances in one virtual tree...
Definition: CompositeStorage.hxx:39
UpdateService::CancelAllAsync
void CancelAllAsync()
Clear the queue and cancel the current update.
uri
const Storage const char * uri
Definition: DatabasePlaylist.hxx:31