~ubuntu-branches/ubuntu/trusty/digikam/trusty

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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
 *  Copyright (C) 2010, 2011 Tuomo Penttinen, all rights reserved.
 *
 *  Author: Tuomo Penttinen <tp@herqq.org>
 *
 *  This file is part of Herqq UPnP (HUPnP) library.
 *
 *  Herqq UPnP is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Herqq UPnP is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with Herqq UPnP. If not, see <http://www.gnu.org/licenses/>.
 */

#include "hservices_setupdata.h"
#include "../dataelements/hserviceid.h"
#include "../dataelements/hresourcetype.h"

#include <QtCore/QSet>

namespace Herqq
{

namespace Upnp
{

/*******************************************************************************
 * HServiceSetupPrivate
 ******************************************************************************/
class HServiceSetupPrivate :
    public QSharedData
{

public:

    HServiceId m_serviceId;
    HResourceType m_serviceType;
    int m_version;
    HInclusionRequirement m_inclusionReq;

    HServiceSetupPrivate() :
        m_serviceId(), m_serviceType(), m_version(0),
        m_inclusionReq(InclusionRequirementUnknown)
    {
    }

    ~HServiceSetupPrivate()
    {
    }
};

/*******************************************************************************
 * HServiceSetup
 ******************************************************************************/
HServiceSetup::HServiceSetup() :
    h_ptr(new HServiceSetupPrivate())
{
}

HServiceSetup::HServiceSetup(
    const HServiceId& id, const HResourceType& serviceType,
    HInclusionRequirement ireq) :
        h_ptr(new HServiceSetupPrivate())
{
    h_ptr->m_serviceId = id;
    h_ptr->m_serviceType = serviceType;
    h_ptr->m_version = 1;
    h_ptr->m_inclusionReq = ireq;
}

HServiceSetup::HServiceSetup(
    const HServiceId& id, const HResourceType& serviceType, int version,
    HInclusionRequirement ireq) :
        h_ptr(new HServiceSetupPrivate())
{
    h_ptr->m_serviceId = id;
    h_ptr->m_serviceType = serviceType;
    h_ptr->m_version = version;
    h_ptr->m_inclusionReq = ireq;
}

HServiceSetup::~HServiceSetup()
{
}

HServiceSetup& HServiceSetup::operator=(const HServiceSetup& other)
{
    Q_ASSERT(&other != this);

    h_ptr = other.h_ptr;

    return *this;
}

HServiceSetup::HServiceSetup(const HServiceSetup& other) :
    h_ptr(other.h_ptr)
{
    Q_ASSERT(this != &other);
}

bool HServiceSetup::isValid(HValidityCheckLevel checkLevel) const
{
    return h_ptr->m_serviceId.isValid(checkLevel) &&
           h_ptr->m_serviceType.isValid() &&
           h_ptr->m_version > 0 &&
           h_ptr->m_inclusionReq != InclusionRequirementUnknown;
}

HInclusionRequirement HServiceSetup::inclusionRequirement() const
{
    return h_ptr->m_inclusionReq;
}

const HServiceId& HServiceSetup::serviceId() const
{
    return h_ptr->m_serviceId;
}

const HResourceType& HServiceSetup::serviceType() const
{
    return h_ptr->m_serviceType;
}

int HServiceSetup::version() const
{
    return h_ptr->m_version;
}

void HServiceSetup::setInclusionRequirement(HInclusionRequirement arg)
{
    h_ptr->m_inclusionReq = arg;
}

void HServiceSetup::setServiceId(const HServiceId& arg)
{
    h_ptr->m_serviceId = arg;
}

void HServiceSetup::setServiceType(const HResourceType& arg)
{
    h_ptr->m_serviceType = arg;
}

void HServiceSetup::setVersion(int version)
{
    h_ptr->m_version = version;
}

bool operator==(const HServiceSetup& obj1, const HServiceSetup& obj2)
{
    return obj1.inclusionRequirement() == obj2.inclusionRequirement() &&
           obj1.serviceId() == obj2.serviceId() &&
           obj1.serviceType() == obj2.serviceType() &&
           obj1.version() == obj2.version();
}

/*******************************************************************************
 * HServicesSetupData
 ******************************************************************************/
HServicesSetupData::HServicesSetupData() :
    m_serviceSetupInfos()
{
}

HServicesSetupData::~HServicesSetupData()
{
}

bool HServicesSetupData::insert(const HServiceSetup& setupInfo, bool overWrite)
{
    if (!setupInfo.isValid(StrictChecks))
    {
        return false;
    }

    const HServiceId& id = setupInfo.serviceId();
    if (!overWrite && m_serviceSetupInfos.contains(id))
    {
        return false;
    }

    m_serviceSetupInfos.insert(id, setupInfo);
    return true;
}

bool HServicesSetupData::remove(const HServiceId& serviceId)
{
    if (m_serviceSetupInfos.contains(serviceId))
    {
        m_serviceSetupInfos.remove(serviceId);
        return true;
    }

    return false;
}

HServiceSetup HServicesSetupData::get(const HServiceId& serviceId) const
{
    return m_serviceSetupInfos.value(serviceId);
}

bool HServicesSetupData::contains(const HServiceId& id) const
{
    return m_serviceSetupInfos.contains(id);
}

QSet<HServiceId> HServicesSetupData::serviceIds() const
{
    return m_serviceSetupInfos.keys().toSet();
}

int HServicesSetupData::size() const
{
    return m_serviceSetupInfos.size();
}

bool HServicesSetupData::isEmpty() const
{
    return m_serviceSetupInfos.isEmpty();
}

bool operator==(const HServicesSetupData& obj1, const HServicesSetupData& obj2)
{
    return obj1.m_serviceSetupInfos == obj2.m_serviceSetupInfos;
}

}
}