aboutsummaryrefslogtreecommitdiff
path: root/tests/dbus-types/pulseaudio-volume.cpp
blob: 8ee305f5075150704c7c0959b1b283e0798c83d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
 * Copyright (C) 2015 Canonical, Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 3, as published
 * by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Author: Xavi Garcia <xavi.garcia.mena@canonical.com>
 */
#include "dbus-types.h"

PulseaudioVolume::PulseaudioVolume() :
        type_(0),
        volume_(10)
{
}

PulseaudioVolume::PulseaudioVolume(unsigned int type, unsigned int volume) :
          type_(type)
        , volume_(volume)
{
}

PulseaudioVolume::PulseaudioVolume(const PulseaudioVolume &other) :
        type_(other.type_),
        volume_(other.volume_)
{
}

PulseaudioVolume& PulseaudioVolume::operator=(const PulseaudioVolume &other)
{
    type_ = other.type_;
    volume_ = other.volume_;

    return *this;
}

PulseaudioVolume::~PulseaudioVolume()
{
}

unsigned int PulseaudioVolume::getType() const
{
    return type_;
}

unsigned int PulseaudioVolume::getVolume() const
{
    return volume_;
}

void PulseaudioVolume::registerMetaType()
{
    qRegisterMetaType<PulseaudioVolume>("PulseaudioVolume");

    qDBusRegisterMetaType<PulseaudioVolume>();
}

QDBusArgument &operator<<(QDBusArgument &argument, const PulseaudioVolume& volume)
{
    argument.beginStructure();
    argument << volume.type_;
    argument << volume.volume_;
    argument.endStructure();

    return argument;
}

const QDBusArgument &operator>>(const QDBusArgument &argument, PulseaudioVolume &volume)
{
    argument.beginStructure();
    argument >> volume.type_;
    argument >> volume.volume_;
    argument.endStructure();

    return argument;
}

PulseaudioVolumeArray::PulseaudioVolumeArray()
{
}

PulseaudioVolumeArray::PulseaudioVolumeArray(const PulseaudioVolumeArray &other) :
          volume_array_(other.volume_array_)
{
}

PulseaudioVolumeArray& PulseaudioVolumeArray::operator=(const PulseaudioVolumeArray &other)
{
    volume_array_ = other.volume_array_;

    return *this;
}

PulseaudioVolumeArray::~PulseaudioVolumeArray()
{
}

int PulseaudioVolumeArray::getNumItems() const
{
    return volume_array_.size();
}

PulseaudioVolume PulseaudioVolumeArray::getItem(int i) const
{
    if (i < volume_array_.size())
    {
        return volume_array_[i];
    }
    return PulseaudioVolume();
}

void PulseaudioVolumeArray::addItem(PulseaudioVolume const &item)
{
    volume_array_.push_back(item);
}

void PulseaudioVolumeArray::registerMetaType()
{
    qRegisterMetaType<PulseaudioVolumeArray>("PulseaudioVolumeArray");

    qDBusRegisterMetaType<PulseaudioVolumeArray>();
}

QDBusArgument &operator<<(QDBusArgument &argument, const PulseaudioVolumeArray& volume)
{
    argument.beginArray( qMetaTypeId<PulseaudioVolume>() );
    for (int i = 0; i < volume.volume_array_.size(); ++ i)
    {
        PulseaudioVolume item = volume.getItem(i);
        argument << item;
    }
    argument.endArray();
    return argument;
}

const QDBusArgument &operator>>(const QDBusArgument &argument, PulseaudioVolumeArray &volume)
{
    argument.beginArray();
    while ( !argument.atEnd() ) {
        PulseaudioVolume item;
        argument >> item;
        volume.volume_array_.push_back(item);
    }
    argument.endArray();

    return argument;
}