MPD: Instance.hxx Source File

MPD 0.20.18

Instance.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_INSTANCE_HXX
21 #define MPD_INSTANCE_HXX
22
23 #include "check.h"
24 #include "event/Loop.hxx"
25 #include "event/MaskMonitor.hxx"
26 #include "Compiler.h"
27
28 #ifdef ENABLE_NEIGHBOR_PLUGINS
29 #include "neighbor/Listener.hxx"
30 class NeighborGlue;
31 #endif
32
33 #ifdef ENABLE_DATABASE
34 #include "db/DatabaseListener.hxx"
35 class Database;
36 class Storage;
37 class UpdateService;
38 #endif
39
40 class ClientList;
41 struct Partition;
42 class StateFile;
43
48 struct EventLoopHolder {
49 EventLoop event_loop;
50 };
51
52 struct Instance final
53 : EventLoopHolder
54 #if defined(ENABLE_DATABASE) || defined(ENABLE_NEIGHBOR_PLUGINS)
55 ,
56 #endif
57 #ifdef ENABLE_DATABASE
58 public DatabaseListener
59 #ifdef ENABLE_NEIGHBOR_PLUGINS
60 ,
61 #endif
62 #endif
63 #ifdef ENABLE_NEIGHBOR_PLUGINS
64 public NeighborListener
65 #endif
66 {
67 MaskMonitor idle_monitor;
68
69 #ifdef ENABLE_NEIGHBOR_PLUGINS
70 NeighborGlue *neighbors;
71 #endif
72
73 #ifdef ENABLE_DATABASE
74 Database *database;
75
80 Storage *storage = nullptr;
81
82 UpdateService *update = nullptr;
83 #endif
84
85 ClientList *client_list;
86
87 Partition *partition;
88
89 StateFile *state_file;
90
91 Instance()
92 :idle_monitor(event_loop, BIND_THIS_METHOD(OnIdle)), state_file(nullptr) {}
93
97 void Shutdown() {
98 event_loop.Break();
99 }
100
101 void EmitIdle(unsigned mask) {
102 idle_monitor.OrMask(mask);
103 }
104
105 #ifdef ENABLE_DATABASE
106
111 Database *GetDatabase() {
112 return database;
113 }
114
120 const Database &GetDatabaseOrThrow() const;
121 #endif
122
123 private:
124 #ifdef ENABLE_DATABASE
125 void OnDatabaseModified() override;
126 void OnDatabaseSongRemoved(const char *uri) override;
127 #endif
128
129 #ifdef ENABLE_NEIGHBOR_PLUGINS
130 /* virtual methods from class NeighborListener */
131 void FoundNeighbor(const NeighborInfo &info) override;
132 void LostNeighbor(const NeighborInfo &info) override;
133 #endif
134
135 /* callback for #idle_monitor */
136 void OnIdle(unsigned mask);
137 };
138
139 #endif
check.h
Instance::client_list
ClientList * client_list
Definition: Instance.hxx:85
StateFile
Definition: StateFile.hxx:34
BIND_THIS_METHOD
#define BIND_THIS_METHOD(method)
Shortcut wrapper for BIND_METHOD() which assumes "*this" is the instance to be bound.
Definition: BindMethod.hxx:207
Database
Definition: Interface.hxx:35
EventLoop
An event loop that polls for events on file/socket descriptors.
Definition: Loop.hxx:52
EventLoop::Break
void Break()
Stop execution of this EventLoop at the next chance.
Storage
Definition: StorageInterface.hxx:45
MaskMonitor
Manage a bit mask of events that have occurred.
Definition: MaskMonitor.hxx:35
Partition
A partition of the Music Player Daemon.
Definition: Partition.hxx:42
DatabaseListener
An object that listens to events from the Database.
Definition: DatabaseListener.hxx:30
Instance
Definition: Instance.hxx:52
NeighborInfo
Definition: Info.hxx:25
ClientList
Definition: ClientList.hxx:27
Loop.hxx
Instance::idle_monitor
MaskMonitor idle_monitor
Definition: Instance.hxx:67
DatabaseListener.hxx
MaskMonitor::OrMask
void OrMask(unsigned new_mask)
Compiler.h
NeighborListener
An interface that listens on events from neighbor plugins.
Definition: Listener.hxx:30
storage
const Storage & storage
Definition: DatabasePlaylist.hxx:31
UpdateService
This class manages the update queue and runs the update thread.
Definition: Service.hxx:37
EventLoopHolder
A utility class which, when used as the first base class, ensures that the EventLoop gets initialized...
Definition: Instance.hxx:48
EventLoopHolder::event_loop
EventLoop event_loop
Definition: Instance.hxx:49
Instance::Shutdown
void Shutdown()
Initiate shutdown.
Definition: Instance.hxx:97
Listener.hxx
Instance::Instance
Instance()
Definition: Instance.hxx:91
Instance::partition
Partition * partition
Definition: Instance.hxx:87
NeighborGlue
A class that initializes and opens all configured neighbor plugins.
Definition: Glue.hxx:37
MaskMonitor.hxx
uri
const Storage const char * uri
Definition: DatabasePlaylist.hxx:31
Instance::state_file
StateFile * state_file
Definition: Instance.hxx:89
Instance::EmitIdle
void EmitIdle(unsigned mask)
Definition: Instance.hxx:101