summaryrefslogtreecommitdiff
path: root/media/pluginManager.cpp
blob: 5d3c9ea9c22e855a227e744eb47920c6b4cee206 (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
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/*
 * pluginManager.cpp
 *
 *  Created on: 05.09.2012
 *      Author: savop
 */

#include "../include/plugin.h"
#include "../include/tools.h"
#include <string>

using namespace std;

namespace upnp {

const char* cMetadata::KEY_OBJECTID         = "object@id";
const char* cMetadata::KEY_PARENTID         = "object@parentID";
const char* cMetadata::KEY_TITLE            = "dc:title";
const char* cMetadata::KEY_CREATOR          = "dc:creator";
const char* cMetadata::KEY_CLASS            = "upnp:class";
const char* cMetadata::KEY_RESTRICTED       = "object@container";
const char* cMetadata::KEY_DESCRIPTION      = "dc:description";
const char* cMetadata::KEY_LONG_DESCRIPTION = "upnp:longDescription";
const char* cMetadata::KEY_DATE             = "dc:date";
const char* cMetadata::KEY_LANGUAGE         = "dc:language";
const char* cMetadata::KEY_CHANNEL_NR       = "upnp:channelNr";
const char* cMetadata::KEY_CHANNEL_NAME     = "upnp:channelName";
const char* cMetadata::KEY_SCHEDULED_START  = "upnp:scheduledStartTime";
const char* cMetadata::KEY_SCHEDULED_END    = "upnp:scheduledEndTime";

bool cMetadata::SetObjectIDByUri(string uri){
  return SetObjectID(tools::GenerateUUIDFromURL(uri));
}

bool cMetadata::SetParentIDByUri(string uri){
  return SetParentID(tools::GenerateUUIDFromURL(uri));
}

bool cMetadata::SetObjectID(string objectID){
  if(objectID.empty() || objectID.compare("0") == 0) return false;

  this->objectID = objectID;

  return true;
};

bool cMetadata::SetParentID(string parentID){
  if(objectID.compare("-1") == 0) return false;

  this->parentID = parentID;

  return true;
};

bool cMetadata::SetTitle(string title){
  this->title = title;

  return true;
};

bool cMetadata::SetUpnpClass(string upnpClass){
  //TODO: Validiere upnpClass.
  this->upnpClass = upnpClass;

  return true;
};

bool cMetadata::SetRestricted(bool restricted){
  this->restricted = restricted;

  return true;
};

bool cMetadata::SetDescription(string description){
  this->description = description;

  return true;
};

bool cMetadata::SetLongDescription(string longDescription){
  this->longDescription = longDescription;

  return true;
};

bool cMetadata::SetDate(string date){
  this->date = date;

  return true;
};

bool cMetadata::SetLanguage(string language){
  this->language = language;

  return true;
};

bool cMetadata::SetChannelNr(int channelNr){
  this->channelNr = channelNr;

  return true;
};

bool cMetadata::SetChannelName(string channelName){
  this->channelName = channelName;

  return true;
};

bool cMetadata::SetScheduledStart(string scheduledStart){
  this->scheduledStart = scheduledStart;

  return true;
};

bool cMetadata::SetScheduledEnd(string scheduledEnd){
  this->scheduledEnd = scheduledEnd;

  return true;
};


bool cMetadata::AddProperty(Property property){
  properties.insert(pair<string, Property>(property.GetKey(), property));
  return true;
}

bool cMetadata::SetProperty(Property property, int index){
  PropertyRange ret = properties.equal_range(property.GetKey());

  // No property with the given name found. Let's add it to the map.
  if(ret.first == ret.second) return AddProperty(property);

  int i = 0;
  for(PropertyMap::iterator it = ret.first; it != ret.second; ++it){
    if(i == index){
      (*it).second = property;
      return true;
    }
    ++i;
  }

  return false;

}

cMetadata::PropertyRange cMetadata::GetPropertiesByKey(string property) {
  return properties.equal_range(property);
}

cMetadata::PropertyRange cMetadata::GetAllProperties() {
  PropertyRange range(properties.begin(), properties.end());
  return range;
}

cMetadata::Property& cMetadata::GetPropertyByKey(string property) {
  return (*properties.find(property)).second;
}

cMetadata::Property::Property(string key, bool val)
: key(key)
{
  value = val ? "true" : "false";
}

cMetadata::Property::Property(string key, string value)
: key(key)
, value(value)
{
}

cMetadata::Property::Property(string key, long val)
: key(key)
{
  value = tools::ToString(val);
}

string cMetadata::Property::GetString() const {
  return value;
}

bool cMetadata::Property::GetBoolean() const {
  return value.compare("true") == 0 ? true : false;
}

long cMetadata::Property::GetInteger() const {
  return atol(value.c_str());
}

string cMetadata::Property::GetKey() const {
  return key;
}

bool cMetadata::Resource::SetResourceUri(string resourceUri){
  this->resourceUri = resourceUri;
  return true;
}

bool cMetadata::Resource::SetProtocolInfo(string protocolInfo){
  this->protocolInfo = protocolInfo;
  return true;
}

bool cMetadata::Resource::SetDuration(string duration){
  this->duration = duration;
  return true;
}

bool cMetadata::Resource::SetResolution(string resolution){
  this->resolution = resolution;
  return true;
}

bool cMetadata::Resource::SetBitrate(uint32_t bitrate){
  this->bitrate = bitrate;
  return true;
}

bool cMetadata::Resource::SetSize(uint32_t size){
  this->size = size;
  return true;
}

bool cMetadata::Resource::SetSampleFrequency(uint32_t sampleFrequency){
  this->sampleFrequency = sampleFrequency;
  return true;
}

bool cMetadata::Resource::SetBitsPerSample(uint32_t bitsPerSample){
  this->bitsPerSample = bitsPerSample;
  return true;
}

bool cMetadata::Resource::SetNrAudioChannels(uint32_t nrAudioChannels){
  this->nrAudioChannels = nrAudioChannels;
  return true;
}

bool cMetadata::Resource::SetColorDepth(uint32_t colorDepth){
  this->colorDepth = colorDepth;
  return true;
}

cMetadata* cUPnPResourceProvider::GetMetadata(string uri){

  cMetadata* metadata = new cMetadata;

  metadata->SetTitle(uri.substr(uri.find_last_of("/")+1));
  metadata->SetUpnpClass("object.container");
  metadata->SetObjectIDByUri(uri);
  metadata->SetParentIDByUri(uri.substr(0,uri.find_last_of("/")));
  metadata->SetRestricted(true);

  return metadata;

}

string cUPnPResourceProvider::GetHTTPUri(string uri){
  return string();
}

bool cUPnPResourceProvider::Open(string uri){
  return false;
}

size_t cUPnPResourceProvider::Read(char* buf, size_t bufLen){
  return -1;
}

bool cUPnPResourceProvider::Seek(size_t offset, int origin){
  return false;
}

void cUPnPResourceProvider::Close(){
}

}  // namespace uünü