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 
50 };
51 
52 struct Instance final
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 {
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 
86 
88 
90 
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
ClientList * client_list
Definition: Instance.hxx:85
#define BIND_THIS_METHOD(method)
Shortcut wrapper for BIND_METHOD() which assumes "*this" is the instance to be bound.
Definition: BindMethod.hxx:207
An event loop that polls for events on file/socket descriptors.
Definition: Loop.hxx:52
void Break()
Stop execution of this EventLoop at the next chance.
Manage a bit mask of events that have occurred.
Definition: MaskMonitor.hxx:35
A partition of the Music Player Daemon.
Definition: Partition.hxx:42
An object that listens to events from the Database.
MaskMonitor idle_monitor
Definition: Instance.hxx:67
void OrMask(unsigned new_mask)
An interface that listens on events from neighbor plugins.
Definition: Listener.hxx:30
const Storage & storage
This class manages the update queue and runs the update thread.
Definition: Service.hxx:37
A utility class which, when used as the first base class, ensures that the EventLoop gets initialized...
Definition: Instance.hxx:48
EventLoop event_loop
Definition: Instance.hxx:49
void Shutdown()
Initiate shutdown.
Definition: Instance.hxx:97
Instance()
Definition: Instance.hxx:91
Partition * partition
Definition: Instance.hxx:87
A class that initializes and opens all configured neighbor plugins.
Definition: Glue.hxx:37
const Storage const char * uri
StateFile * state_file
Definition: Instance.hxx:89
void EmitIdle(unsigned mask)
Definition: Instance.hxx:101