Phonon

streameventqueue.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2008 Matthias Kretz <kretz@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) version 3, or any
8 later version accepted by the membership of KDE e.V. (or its
9 successor approved by the membership of KDE e.V.), Nokia Corporation
10 (or its successors, if any) and the KDE Free Qt Foundation, which shall
11 act as a proxy defined in Section 6 of version 3 of the license.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library. If not, see <http://www.gnu.org/licenses/>.
20
21*/
22
23#include "streameventqueue_p.h"
24#include "phononnamespace_p.h"
25#include <QtDebug>
26
27namespace Phonon
28{
29
30//////////////////////////////////////////
31// any thread
32
33StreamEventQueue::StreamEventQueue()
34 : m_dropWriteCommands(0),
35 m_connecting(0)
36{
37}
38
39StreamEventQueue::~StreamEventQueue()
40{
41}
42
43void StreamEventQueue::setBackendCommandHandler(LockFreeQueueBase::DataReadyHandler *h)
44{
45 m_forBackend.setDataReadyHandler(h);
46}
47
48void StreamEventQueue::setFrontendCommandHandler(LockFreeQueueBase::DataReadyHandler *h)
49{
50 m_forFrontend.setDataReadyHandler(h);
51}
52
53
54//////////////////////////////////////////
55// frontend thread
56
57void StreamEventQueue::sendToBackend(CommandType command, const QVariant &data)
58{
59 m_forBackend.enqueue(Command(command, data));
60}
61
62bool StreamEventQueue::nextCommandForFrontend(Command *command)
63{
64 Q_ASSERT(command);
65 return m_forFrontend.dequeue(command);
66}
67
68
69//////////////////////////////////////////
70// backend thread
71
72void StreamEventQueue::sendToFrontend(CommandType command, const QVariant &data)
73{
74 switch (command) {
75 case Seek:
76 case Reset:
77 ++m_dropWriteCommands;
78 break;
79 case Connect:
80 ++m_connecting;
81 m_dropWriteCommands = 0;
82 break;
83 default:
84 break;
85 }
86 m_forFrontend.enqueue(Command(command, data));
87}
88
89bool StreamEventQueue::nextCommandForBackend(Command *command)
90{
91 Q_ASSERT(command);
92 bool valid = m_forBackend.dequeue(command);
93 while (valid) {
94 if (m_connecting) {
95 if (command->command == ConnectDone) {
96 --m_connecting;
97 }
98 // drop all other commands until m_connecting == 0
99 } else if (m_dropWriteCommands) {
100 switch (command->command) {
101 case Write:
102 case EndOfData:
103 // drop until m_dropWriteCommands == 0
104 break;
105 case SeekDone:
106 case ResetDone:
107 --m_dropWriteCommands;
108 break;
109 case ConnectDone:
110 pFatal("received a ConnectDone, but there was no Connect request");
111 break;
112 default:
113 return valid;
114 }
115 } else {
116 return valid;
117 }
118 valid = m_forBackend.dequeue(command);
119 }
120 return valid;
121}
122
123} // namespace Phonon
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:20:24 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.