MPD  0.20.6
Wrapper.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_OUTPUT_WRAPPER_HXX
21 #define MPD_OUTPUT_WRAPPER_HXX
22 
23 #include "util/Cast.hxx"
24 
25 #include <chrono>
26 
27 struct ConfigBlock;
28 
29 template<class T>
31  static T &Cast(AudioOutput &ao) {
32  return ContainerCast(ao, &T::base);
33  }
34 
35  static AudioOutput *Init(const ConfigBlock &block) {
36  T *t = T::Create(block);
37  return &t->base;
38  }
39 
40  static void Finish(AudioOutput *ao) {
41  T *t = &Cast(*ao);
42  delete t;
43  }
44 
45  static void Enable(AudioOutput *ao) {
46  T &t = Cast(*ao);
47  t.Enable();
48  }
49 
50  static void Disable(AudioOutput *ao) {
51  T &t = Cast(*ao);
52  t.Disable();
53  }
54 
55  static void Open(AudioOutput *ao, AudioFormat &audio_format) {
56  T &t = Cast(*ao);
57  t.Open(audio_format);
58  }
59 
60  static void Close(AudioOutput *ao) {
61  T &t = Cast(*ao);
62  t.Close();
63  }
64 
65  gcc_pure
66  static std::chrono::steady_clock::duration Delay(AudioOutput *ao) {
67  T &t = Cast(*ao);
68  return t.Delay();
69  }
70 
71  gcc_pure
72  static void SendTag(AudioOutput *ao, const Tag &tag) {
73  T &t = Cast(*ao);
74  t.SendTag(tag);
75  }
76 
77  static size_t Play(AudioOutput *ao, const void *chunk, size_t size) {
78  T &t = Cast(*ao);
79  return t.Play(chunk, size);
80  }
81 
82  static void Drain(AudioOutput *ao) {
83  T &t = Cast(*ao);
84  t.Drain();
85  }
86 
87  static void Cancel(AudioOutput *ao) {
88  T &t = Cast(*ao);
89  t.Cancel();
90  }
91 
92  gcc_pure
93  static bool Pause(AudioOutput *ao) {
94  T &t = Cast(*ao);
95  return t.Pause();
96  }
97 };
98 
99 #endif
static size_t Play(AudioOutput *ao, const void *chunk, size_t size)
Definition: Wrapper.hxx:77
This structure describes the format of a raw PCM stream.
Definition: AudioFormat.hxx:37
The meta information about a song file.
Definition: Tag.hxx:34
static gcc_pure bool Pause(AudioOutput *ao)
Definition: Wrapper.hxx:93
static void Close(AudioOutput *ao)
Definition: Wrapper.hxx:60
static void Enable(AudioOutput *ao)
Definition: Wrapper.hxx:45
static C & ContainerCast(A &a, A C::*member)
Cast the given pointer to a struct member to its parent structure.
Definition: Cast.hxx:91
static gcc_pure std::chrono::steady_clock::duration Delay(AudioOutput *ao)
Definition: Wrapper.hxx:66
static gcc_pure void SendTag(AudioOutput *ao, const Tag &tag)
Definition: Wrapper.hxx:72
static void Open(AudioOutput *ao, AudioFormat &audio_format)
Definition: Wrapper.hxx:55
static void Cancel(AudioOutput *ao)
Definition: Wrapper.hxx:87
static T & Cast(AudioOutput &ao)
Definition: Wrapper.hxx:31
static void Finish(AudioOutput *ao)
Definition: Wrapper.hxx:40
static AudioOutput * Init(const ConfigBlock &block)
Definition: Wrapper.hxx:35
static void Drain(AudioOutput *ao)
Definition: Wrapper.hxx:82
#define gcc_pure
Definition: Compiler.h:116
static void Disable(AudioOutput *ao)
Definition: Wrapper.hxx:50