MPD  0.20.15
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"
26 #include "thread/Thread.hxx"
27 #include "Compiler.h"
28 
29 class SimpleDatabase;
30 class DatabaseListener;
31 class UpdateWalk;
32 class CompositeStorage;
33 
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:
59  CompositeStorage &_storage,
60  DatabaseListener &_listener);
61 
63 
68  unsigned GetId() const {
69  return next.id;
70  }
71 
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
unsigned id
Definition: Queue.hxx:37
unsigned GetId() const
Returns a non-zero job id when we are currently updating the database.
Definition: Service.hxx:68
#define gcc_nonnull_all
Definition: Compiler.h:122
An event loop that polls for events on file/socket descriptors.
Definition: Loop.hxx:51
UpdateService(EventLoop &_loop, SimpleDatabase &_db, CompositeStorage &_storage, DatabaseListener &_listener)
An object that listens to events from the Database.
Defer execution of an event into an EventLoop.
gcc_nonnull_all unsigned Enqueue(const char *path, bool discard)
Add this path to the database update queue.
This class manages the update queue and runs the update thread.
Definition: Service.hxx:37
void CancelMount(const char *uri)
Cancel all updates for the given mount point.
A Storage implementation that combines multiple other Storage instances in one virtual tree...
void CancelAllAsync()
Clear the queue and cancel the current update.
const Storage const char * uri