MPD  0.20.18
SharedPipeConsumer.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 SHARED_PIPE_CONSUMER_HXX
21 #define SHARED_PIPE_CONSUMER_HXX
22 
23 #include "check.h"
24 #include "Compiler.h"
25 
26 #include <assert.h>
27 
28 struct MusicChunk;
29 class MusicPipe;
30 
43  const MusicPipe *pipe = nullptr;
44 
51  const MusicChunk *chunk;
52 
56  bool consumed;
57 
58 public:
59  void Init(const MusicPipe &_pipe) {
60  pipe = &_pipe;
61  chunk = nullptr;
62  }
63 
64  const MusicPipe &GetPipe() {
65  assert(pipe != nullptr);
66 
67  return *pipe;
68  }
69 
70  bool IsInitial() {
71  return chunk == nullptr;
72  }
73 
74  void Cancel() {
75  chunk = nullptr;
76  }
77 
78  const MusicChunk *Get() noexcept;
79 
80  void Consume(gcc_unused const MusicChunk &_chunk) {
81  assert(chunk != nullptr);
82  assert(chunk == &_chunk);
83 
84  consumed = true;
85  }
86 
87  gcc_pure
88  bool IsConsumed(const MusicChunk &_chunk) const noexcept;
89 
90  void ClearTail(gcc_unused const MusicChunk &_chunk) noexcept {
91  assert(chunk == &_chunk);
92  assert(consumed);
93  chunk = nullptr;
94  }
95 };
96 
97 #endif
A utility class which helps with consuming data from a MusicPipe.
A queue of MusicChunk objects.
Definition: MusicPipe.hxx:39
const MusicPipe & GetPipe()
A chunk of music data.
Definition: MusicChunk.hxx:43
void ClearTail(gcc_unused const MusicChunk &_chunk) noexcept
gcc_pure bool IsConsumed(const MusicChunk &_chunk) const noexcept
void Consume(gcc_unused const MusicChunk &_chunk)
void Init(const MusicPipe &_pipe)
#define gcc_unused
Definition: Compiler.h:118
const MusicChunk * Get() noexcept
#define gcc_pure
Definition: Compiler.h:116