adding a pulseaudio plugin to genivi audiomanager implements dbus methods for registe...
[profile/ivi/genivi/genivi-audio-manager.git] / PluginRoutingInterfaceDbus / src / CAmDbusMessageHandler.cpp
1 /**
2  *  Copyright (c) copyright 2011-2012 Aricent® Group  and its licensors
3  *
4  *  \author: Sampreeth Ramavana
5  *
6  *  \copyright
7  *  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction,
8  *  including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
9  *  subject to the following conditions:
10  *  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
12  *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
13  *  THE USE OR OTHER DEALINGS IN THE SOFTWARE.
14  *
15  *  For further information see http://www.genivi.org/.
16  */
17
18 #include "CAmDbusMessageHandler.h"
19 #include "CAmRoutingSenderDbus.h"
20 #include "config.h"
21
22 #include <stdlib.h>
23 #include <assert.h>
24 #include <vector>
25
26 using namespace am;
27
28 DLT_IMPORT_CONTEXT(DLT_CONTEXT)
29
30 CAmDbusMessageHandler::CAmDbusMessageHandler()
31 :       mDBusMessageIter(),
32         mDBusError(),
33         mSerial(0),
34         mErrorName(""),
35         mErrorMsg(""),
36         mDbusMessage(NULL),
37         mReveiveMessage(NULL),
38         mDBusConnection(NULL)
39 {
40 }
41
42 CAmDbusMessageHandler::~CAmDbusMessageHandler()
43 {
44 }
45
46 void CAmDbusMessageHandler::initReceive(DBusMessage* msg)
47 {
48         assert(msg!=NULL);
49         mReveiveMessage=msg;
50     if (!dbus_message_iter_init(msg, &mDBusMessageIter))
51     {
52         mErrorName=std::string(DBUS_ERROR_INVALID_ARGS);
53         mErrorMsg="DBUS Message has no arguments!";
54     }
55 }
56
57 void CAmDbusMessageHandler::initReply(DBusMessage* msg)
58 {
59         assert(msg!=NULL);
60     mDbusMessage = dbus_message_new_method_return(msg);
61     if (mDbusMessage==NULL) {
62         mErrorName=std::string(DBUS_ERROR_NO_MEMORY);
63         mErrorMsg="Cannot create reply!";
64     }
65     dbus_message_iter_init_append(mDbusMessage, &mDBusMessageIter);
66 }
67
68 void CAmDbusMessageHandler::initSignal(std::string path, std::string signalName)
69 {
70         assert(!path.empty());
71         assert(!signalName.empty());
72         std::string completePath=std::string(DBUS_SERVICE_OBJECT_PATH)+"/"+path;
73         std::string objectpath=std::string(DBUS_SERVICE_PREFIX)+"."+path;
74         mDbusMessage=dbus_message_new_signal(completePath.c_str(),objectpath.c_str(),signalName.c_str());
75
76
77     dbus_message_iter_init_append(mDbusMessage, &mDBusMessageIter);
78 }
79
80 void CAmDbusMessageHandler::sendMessage()
81 {
82         assert(mDBusConnection!=NULL);
83         if(mReveiveMessage!=0)
84         {
85                 mSerial=dbus_message_get_serial(mReveiveMessage);
86         }
87         else
88         {
89                 mSerial=1;
90         }
91         if (!mErrorName.empty()) {
92                 mDbusMessage = dbus_message_new_error(mReveiveMessage, mErrorName.c_str(), mErrorMsg.c_str());
93         }
94     if (!dbus_connection_send(mDBusConnection, mDbusMessage, &mSerial))
95     {
96         ;
97     }
98     dbus_connection_flush(mDBusConnection);
99     dbus_message_unref(mDbusMessage);
100     mDbusMessage = NULL;
101 }
102
103 char* CAmDbusMessageHandler::getString()
104 {
105     char* param=NULL;
106
107     if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&mDBusMessageIter))
108     {
109         mErrorName=std::string(DBUS_ERROR_INVALID_ARGS);
110         mErrorMsg="DBus argument is no string";
111     }
112     else
113     {
114         dbus_message_iter_get_basic(&mDBusMessageIter, &param);
115         dbus_message_iter_next(&mDBusMessageIter);
116     }
117     return (param);
118 }
119
120 dbus_bool_t CAmDbusMessageHandler::getBool()
121 {
122     dbus_bool_t boolparam=false;
123
124     if (DBUS_TYPE_BOOLEAN != dbus_message_iter_get_arg_type(&mDBusMessageIter))
125     {
126         mErrorName=std::string(DBUS_ERROR_INVALID_ARGS);
127         mErrorMsg="DBus argument is no bool";
128     }
129     else
130     {
131         dbus_message_iter_get_basic(&mDBusMessageIter, &boolparam);
132         dbus_message_iter_next(&mDBusMessageIter);
133     }
134     return (boolparam);
135 }
136
137 char CAmDbusMessageHandler::getByte()
138 {
139     char param;
140
141     if (DBUS_TYPE_BYTE != dbus_message_iter_get_arg_type(&mDBusMessageIter))
142     {
143         mErrorName=std::string(DBUS_ERROR_INVALID_ARGS);
144         mErrorMsg="DBus argument is no byte";
145     }
146     else
147     {
148         dbus_message_iter_get_basic(&mDBusMessageIter, &param);
149         dbus_message_iter_next(&mDBusMessageIter);
150     }
151     return (param);
152 }
153
154 dbus_uint16_t CAmDbusMessageHandler::getUInt()
155 {
156     dbus_uint16_t param;
157
158     if (DBUS_TYPE_UINT16 != dbus_message_iter_get_arg_type(&mDBusMessageIter))
159     {
160         mErrorName=std::string(DBUS_ERROR_INVALID_ARGS);
161         mErrorMsg="DBus argument is no uint16_t";
162     }
163     else
164     {
165         dbus_message_iter_get_basic(&mDBusMessageIter, &param);
166         dbus_message_iter_next(&mDBusMessageIter);
167     }
168     return (param);
169 }
170
171 dbus_int16_t CAmDbusMessageHandler::getInt()
172 {
173     dbus_int16_t param;
174
175     if (DBUS_TYPE_INT16 != dbus_message_iter_get_arg_type(&mDBusMessageIter))
176     {
177         mErrorName=std::string(DBUS_ERROR_INVALID_ARGS);
178         mErrorMsg="DBus argument is no int16_t";
179     }
180     else
181     {
182         dbus_message_iter_get_basic(&mDBusMessageIter, &param);
183         dbus_message_iter_next(&mDBusMessageIter);
184     }
185     return (param);
186 }
187
188 dbus_uint32_t CAmDbusMessageHandler::getUInt32()
189 {
190     dbus_uint16_t param;
191
192     if (DBUS_TYPE_UINT32 != dbus_message_iter_get_arg_type(&mDBusMessageIter))
193     {
194         mErrorName=std::string(DBUS_ERROR_INVALID_ARGS);
195         mErrorMsg="DBus argument is no uint32_t";
196     }
197     else
198     {
199         dbus_message_iter_get_basic(&mDBusMessageIter, &param);
200         dbus_message_iter_next(&mDBusMessageIter);
201     }
202     return (param);
203 }
204
205 dbus_int32_t CAmDbusMessageHandler::getInt32()
206 {
207     dbus_int32_t param;
208
209     if (DBUS_TYPE_INT32 != dbus_message_iter_get_arg_type(&mDBusMessageIter))
210     {
211         mErrorName=std::string(DBUS_ERROR_INVALID_ARGS);
212         mErrorMsg="DBus argument is no int32_t";
213     }
214     else
215     {
216         dbus_message_iter_get_basic(&mDBusMessageIter, &param);
217         dbus_message_iter_next(&mDBusMessageIter);
218     }
219     return (param);
220 }
221
222 double CAmDbusMessageHandler::getDouble()
223 {
224     double param;
225     if (DBUS_TYPE_DOUBLE != dbus_message_iter_get_arg_type(&mDBusMessageIter))
226     {
227         mErrorName=std::string(DBUS_ERROR_INVALID_ARGS);
228         mErrorMsg="DBus argument is no double";
229     }
230     else
231     {
232         dbus_message_iter_get_basic(&mDBusMessageIter, &param);
233         dbus_message_iter_next(&mDBusMessageIter);
234     }
235     return (param);
236 }
237
238 void CAmDbusMessageHandler::getProperty(dbus_int16_t & type, dbus_int16_t & value)
239 {
240         DBusMessageIter arrayIter;
241     if (DBUS_TYPE_STRUCT != dbus_message_iter_get_arg_type(&mDBusMessageIter))
242     {
243         mErrorName=std::string(DBUS_ERROR_INVALID_ARGS);
244         mErrorMsg="DBus argument is no array";
245     }
246     else
247     {
248         dbus_message_iter_recurse(&mDBusMessageIter, &arrayIter);
249         dbus_message_iter_get_basic(&arrayIter, &type);
250         dbus_message_iter_next(&arrayIter);
251         dbus_message_iter_get_basic(&arrayIter, &value);
252         dbus_message_iter_next(&mDBusMessageIter);
253     }
254 }
255
256 void CAmDbusMessageHandler::append(bool toAppend)
257 {
258         dbus_bool_t mybool=toAppend;
259     if (!dbus_message_iter_append_basic(&mDBusMessageIter, DBUS_TYPE_BOOLEAN, &mybool))
260     {
261         mErrorName=std::string(DBUS_ERROR_NO_MEMORY);
262         mErrorMsg="Cannot create reply!";
263     }
264 }
265
266
267 void CAmDbusMessageHandler::append(double toAppend)
268 {
269     if (!dbus_message_iter_append_basic(&mDBusMessageIter, DBUS_TYPE_DOUBLE, &toAppend))
270     {
271         mErrorName=std::string(DBUS_ERROR_NO_MEMORY);
272         mErrorMsg="Cannot create reply!";
273     }
274 }
275
276 void CAmDbusMessageHandler::append(char toAppend)
277 {
278     if (!dbus_message_iter_append_basic(&mDBusMessageIter, DBUS_TYPE_BYTE, &toAppend))
279     {
280         mErrorName=std::string(DBUS_ERROR_NO_MEMORY);
281         mErrorMsg="Cannot create reply!";
282     }
283 }
284
285
286 void CAmDbusMessageHandler::append(dbus_int16_t toAppend)
287 {
288     if (!dbus_message_iter_append_basic(&mDBusMessageIter, DBUS_TYPE_INT16, &toAppend))
289     {
290         mErrorName=std::string(DBUS_ERROR_NO_MEMORY);
291         mErrorMsg="Cannot create reply!";
292     }
293 }
294
295 void CAmDbusMessageHandler::append(dbus_uint16_t toAppend)
296 {
297     if (!dbus_message_iter_append_basic(&mDBusMessageIter, DBUS_TYPE_UINT16, &toAppend))
298     {
299         mErrorName=std::string(DBUS_ERROR_NO_MEMORY);
300         mErrorMsg="Cannot create reply!";
301     }
302 }
303
304 void CAmDbusMessageHandler::append(dbus_uint32_t toAppend)
305 {
306     if (!dbus_message_iter_append_basic(&mDBusMessageIter, DBUS_TYPE_UINT32, &toAppend))
307     {
308         mErrorName=std::string(DBUS_ERROR_NO_MEMORY);
309         mErrorMsg="Cannot create reply!";
310     }
311 }
312
313 void CAmDbusMessageHandler::setDBusConnection(DBusConnection *& connection)
314 {
315         assert(connection!=NULL);
316         mDBusConnection=connection;
317 }
318
319 void CAmDbusMessageHandler::append(const am::am_SinkType_s& sinkType)
320 {
321     DBusMessageIter structIter;
322     DBusMessageIter structAvailIter;
323     dbus_bool_t success=true;
324     success=success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_STRUCT, NULL, &structIter);
325     success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &sinkType.sinkID);
326     success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_STRING, &sinkType.name);
327
328     success=success && dbus_message_iter_open_container(&structIter, DBUS_TYPE_STRUCT, NULL, &structAvailIter);
329     success=success && dbus_message_iter_append_basic(&structAvailIter, DBUS_TYPE_INT16, &sinkType.availability.availability);
330     success=success && dbus_message_iter_append_basic(&structAvailIter, DBUS_TYPE_INT16, &sinkType.availability.availabilityReason);
331     success=success && dbus_message_iter_close_container(&structIter, &structAvailIter);
332
333     success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &sinkType.volume);
334     success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &sinkType.muteState);
335     success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &sinkType.sinkClassID);
336     success=success && dbus_message_iter_close_container(&mDBusMessageIter, &structIter);
337
338     if (!success)
339     {
340         mErrorName=std::string(DBUS_ERROR_NO_MEMORY);
341         mErrorMsg="Cannot create reply!";
342     }
343 }
344
345 void CAmDbusMessageHandler::append(const am::am_SourceType_s & sourceType)
346 {
347     DBusMessageIter structIter;
348     DBusMessageIter structAvailIter;
349     dbus_bool_t success=true;
350     success=success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_STRUCT, NULL, &structIter);
351     success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &sourceType.sourceID);
352     success=success &&  dbus_message_iter_append_basic(&structIter, DBUS_TYPE_STRING, &sourceType.name);
353
354     success=success && dbus_message_iter_open_container(&structIter, DBUS_TYPE_STRUCT, NULL, &structAvailIter);
355     success=success && dbus_message_iter_append_basic(&structAvailIter, DBUS_TYPE_INT16, &sourceType.availability.availability);
356     success=success && dbus_message_iter_append_basic(&structAvailIter, DBUS_TYPE_INT16, &sourceType.availability.availabilityReason);
357     success=success && dbus_message_iter_close_container(&structIter, &structAvailIter);
358
359     success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &sourceType.sourceClassID);
360     success=success && dbus_message_iter_close_container(&mDBusMessageIter, &structIter);
361
362     if (!success)
363     {
364         mErrorName=std::string(DBUS_ERROR_NO_MEMORY);
365         mErrorMsg="Cannot create reply!";
366     }
367 }
368
369 void CAmDbusMessageHandler::append(const am::am_MainSoundProperty_s mainSoundProperty)
370 {
371         DBusMessageIter structIter;
372     dbus_bool_t success=true;
373     success=success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_STRUCT, NULL, &structIter);
374     success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &mainSoundProperty.type);
375     success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &mainSoundProperty.value);
376     success=success && dbus_message_iter_close_container(&mDBusMessageIter, &structIter);
377
378     if (!success)
379     {
380         mErrorName=std::string(DBUS_ERROR_NO_MEMORY);
381         mErrorMsg="Cannot create reply!";
382     }
383 }
384
385 void CAmDbusMessageHandler::append(const am::am_Availability_s & availability)
386 {
387     DBusMessageIter structAvailIter;
388     dbus_bool_t success=true;
389     success=success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_STRUCT,NULL, &structAvailIter);
390     success=success && dbus_message_iter_append_basic(&structAvailIter, DBUS_TYPE_INT16, &availability.availability);
391     success=success && dbus_message_iter_append_basic(&structAvailIter, DBUS_TYPE_INT16, &availability.availabilityReason);
392     success=success && dbus_message_iter_close_container(&mDBusMessageIter, &structAvailIter);
393
394     if (!success)
395     {
396         mErrorName=std::string(DBUS_ERROR_NO_MEMORY);
397         mErrorMsg="Cannot create reply!";
398     }
399 }
400
401 void CAmDbusMessageHandler::append(const am::am_SystemProperty_s & SystemProperty)
402 {
403     DBusMessageIter structIter;
404     dbus_bool_t success=true;
405     success=success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_STRUCT, NULL, &structIter);
406     success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &SystemProperty.type);
407     success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &SystemProperty.value);
408     success=success && dbus_message_iter_close_container(&mDBusMessageIter, &structIter);
409
410     if (!success)
411     {
412         mErrorName=std::string(DBUS_ERROR_NO_MEMORY);
413         mErrorMsg="Cannot create reply!";
414     }
415 }
416
417 void CAmDbusMessageHandler::append(const std::vector<am::am_MainConnectionType_s>& listMainConnections)
418 {
419     DBusMessageIter arrayIter;
420     DBusMessageIter structIter;
421     std::vector<am::am_MainConnectionType_s>::const_iterator listIterator=listMainConnections.begin();
422     dbus_bool_t success=true;
423
424     success=success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_ARRAY, "(qqqnn)", &arrayIter);
425     for(;listIterator<listMainConnections.end();++listIterator)
426     {
427         success=success && dbus_message_iter_open_container(&arrayIter, DBUS_TYPE_STRUCT, NULL, &structIter);
428         success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &listIterator->mainConnectionID);
429         success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &listIterator->sourceID);
430         success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &listIterator->sinkID);
431         success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &listIterator->delay);
432         success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &listIterator->connectionState);
433         success=success && dbus_message_iter_close_container(&arrayIter, &structIter);
434     }
435     success=success && dbus_message_iter_close_container(&mDBusMessageIter, &arrayIter);
436
437     if (!success)
438     {
439         mErrorName=std::string(DBUS_ERROR_NO_MEMORY);
440         mErrorMsg="Cannot create reply!";
441     }
442 }
443
444 void CAmDbusMessageHandler::append(const std::vector<am::am_SinkType_s> & listMainSinks)
445 {
446     DBusMessageIter arrayIter;
447     DBusMessageIter structIter;
448     DBusMessageIter availIter;
449     std::vector<am::am_SinkType_s>::const_iterator listIterator=listMainSinks.begin();
450     dbus_bool_t success=true;
451
452     success=success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_ARRAY, "(qs(nn)nnq)", &arrayIter);
453     for(;listIterator<listMainSinks.end();++listIterator)
454     {
455         success=success && dbus_message_iter_open_container(&arrayIter, DBUS_TYPE_STRUCT, NULL, &structIter);
456         success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &listIterator->sinkID);
457         success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_STRING, &listIterator->name);
458         success=success && dbus_message_iter_open_container(&structIter, DBUS_TYPE_STRUCT, NULL, &availIter);
459         success=success && dbus_message_iter_append_basic(&availIter, DBUS_TYPE_INT16, &listIterator->availability.availability);
460         success=success && dbus_message_iter_append_basic(&availIter, DBUS_TYPE_INT16, &listIterator->availability.availabilityReason);
461         success=success && dbus_message_iter_close_container(&structIter, &availIter);
462         success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &listIterator->volume);
463         success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &listIterator->muteState);
464         success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &listIterator->sinkClassID);
465         success=success && dbus_message_iter_close_container(&arrayIter, &structIter);
466     }
467     success=success && dbus_message_iter_close_container(&mDBusMessageIter, &arrayIter);
468
469     if (!success)
470     {
471         mErrorName=std::string(DBUS_ERROR_NO_MEMORY);
472         mErrorMsg="Cannot create reply!";
473     }
474 }
475
476
477
478 void CAmDbusMessageHandler::append(const std::vector<am::am_SourceType_s> & listMainSources)
479 {
480     DBusMessageIter arrayIter;
481     DBusMessageIter structIter;
482     DBusMessageIter availIter;
483     std::vector<am::am_SourceType_s>::const_iterator listIterator=listMainSources.begin();
484     dbus_bool_t success=true;
485
486     success=success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_ARRAY, "(qs(nn)q)", &arrayIter);
487     for(;listIterator<listMainSources.end();++listIterator)
488     {
489         success=success && dbus_message_iter_open_container(&arrayIter, DBUS_TYPE_STRUCT, NULL, &structIter);
490         success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &listIterator->sourceID);
491         success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_STRING, &listIterator->name);
492         success=success && dbus_message_iter_open_container(&structIter, DBUS_TYPE_STRUCT, NULL, &availIter);
493         success=success && dbus_message_iter_append_basic(&availIter, DBUS_TYPE_INT16, &listIterator->availability.availability);
494         success=success && dbus_message_iter_append_basic(&availIter, DBUS_TYPE_INT16, &listIterator->availability.availabilityReason);
495         success=success && dbus_message_iter_close_container(&structIter, &availIter);
496         success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &listIterator->sourceClassID);
497         success=success && dbus_message_iter_close_container(&arrayIter, &structIter);
498     }
499     success=success && dbus_message_iter_close_container(&mDBusMessageIter, &arrayIter);
500
501     if (!success)
502     {
503         mErrorName=std::string(DBUS_ERROR_NO_MEMORY);
504         mErrorMsg="Cannot create reply!";
505     }
506 }
507
508 void CAmDbusMessageHandler::append(const std::vector<am::am_MainSoundProperty_s> & listMainSoundProperties)
509 {
510     DBusMessageIter arrayIter;
511     DBusMessageIter structIter;
512     std::vector<am::am_MainSoundProperty_s>::const_iterator listIterator=listMainSoundProperties.begin();
513     dbus_bool_t success=true;
514
515     success=success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_ARRAY, "(nn)", &arrayIter);
516     for(;listIterator<listMainSoundProperties.end();++listIterator)
517     {
518         success=success && dbus_message_iter_open_container(&arrayIter, DBUS_TYPE_STRUCT, NULL, &structIter);
519         success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &listIterator->type);
520         success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &listIterator->value);
521         success=success && dbus_message_iter_close_container(&arrayIter, &structIter);
522     }
523     success=success && dbus_message_iter_close_container(&mDBusMessageIter, &arrayIter);
524
525     if (!success)
526     {
527         mErrorName=std::string(DBUS_ERROR_NO_MEMORY);
528         mErrorMsg="Cannot create reply!";
529     }
530 }
531
532 void CAmDbusMessageHandler::append(const std::vector<am::am_SourceClass_s> & listSourceClasses)
533 {
534     DBusMessageIter arrayIter;
535     DBusMessageIter structIter;
536     DBusMessageIter propIter;
537     DBusMessageIter innerIter;
538     std::vector<am::am_SourceClass_s>::const_iterator listIterator=listSourceClasses.begin();
539     dbus_bool_t success=true;
540
541     success=success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_ARRAY, "(qsa(nn))", &arrayIter);
542     for(;listIterator<listSourceClasses.end();++listIterator)
543     {
544         success=success && dbus_message_iter_open_container(&arrayIter, DBUS_TYPE_STRUCT, NULL, &structIter);
545         success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &listIterator->sourceClassID);
546         success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_STRING, &listIterator->name);
547         success=success && dbus_message_iter_open_container(&structIter, DBUS_TYPE_ARRAY, "(nn)", &innerIter);
548
549         std::vector<am::am_ClassProperty_s>::const_iterator listInnerIterator=listIterator->listClassProperties.begin();
550         for(;listInnerIterator<listIterator->listClassProperties.end();++listInnerIterator)
551         {
552             success=success && dbus_message_iter_open_container(&innerIter, DBUS_TYPE_STRUCT, NULL, &propIter);
553             success=success && dbus_message_iter_append_basic(&propIter, DBUS_TYPE_INT16, &listInnerIterator->classProperty);
554             success=success && dbus_message_iter_append_basic(&propIter, DBUS_TYPE_INT16, &listInnerIterator->value);
555             success=success && dbus_message_iter_close_container(&innerIter, &propIter);
556         }
557         success=success && dbus_message_iter_close_container(&structIter, &innerIter);
558         success=success && dbus_message_iter_close_container(&arrayIter, &structIter);
559     }
560     success=success && dbus_message_iter_close_container(&mDBusMessageIter, &arrayIter);
561
562     if (!success)
563     {
564         mErrorName=std::string(DBUS_ERROR_NO_MEMORY);
565         mErrorMsg="Cannot create reply!";
566     }
567 }
568
569 void CAmDbusMessageHandler::append(const std::vector<am::am_SinkClass_s> & listSinkClasses)
570 {
571     DBusMessageIter arrayIter;
572     DBusMessageIter structIter;
573     DBusMessageIter propIter;
574     DBusMessageIter innerIter;
575     std::vector<am::am_SinkClass_s>::const_iterator listIterator=listSinkClasses.begin();
576     dbus_bool_t success=true;
577
578     success=success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_ARRAY, "(qsa(nn))", &arrayIter);
579     for(;listIterator<listSinkClasses.end();++listIterator)
580     {
581         success=success && dbus_message_iter_open_container(&arrayIter, DBUS_TYPE_STRUCT, NULL, &structIter);
582         success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_UINT16, &listIterator->sinkClassID);
583         success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_STRING, &listIterator->name);
584         success=success && dbus_message_iter_open_container(&structIter, DBUS_TYPE_ARRAY, "(nn)", &innerIter);
585
586         std::vector<am::am_ClassProperty_s>::const_iterator listInnerIterator=listIterator->listClassProperties.begin();
587         for(;listInnerIterator<listIterator->listClassProperties.end();++listInnerIterator)
588         {
589             success=success && dbus_message_iter_open_container(&innerIter, DBUS_TYPE_STRUCT, NULL, &propIter);
590             success=success && dbus_message_iter_append_basic(&propIter, DBUS_TYPE_INT16, &listInnerIterator->classProperty);
591             success=success && dbus_message_iter_append_basic(&propIter, DBUS_TYPE_INT16, &listInnerIterator->value);
592             success=success && dbus_message_iter_close_container(&innerIter, &propIter);
593         }
594         success=success && dbus_message_iter_close_container(&structIter, &innerIter);
595         success=success && dbus_message_iter_close_container(&arrayIter, &structIter);
596     }
597     success=success && dbus_message_iter_close_container(&mDBusMessageIter, &arrayIter);
598
599     if (!success)
600     {
601         mErrorName=std::string(DBUS_ERROR_NO_MEMORY);
602         mErrorMsg="Cannot create reply!";
603     }
604 }
605
606 void CAmDbusMessageHandler::append(const std::vector<am::am_SystemProperty_s> & listSystemProperties)
607 {
608     DBusMessageIter arrayIter;
609     DBusMessageIter structIter;
610     std::vector<am::am_SystemProperty_s>::const_iterator listIterator=listSystemProperties.begin();
611     dbus_bool_t success=true;
612
613     success=success && dbus_message_iter_open_container(&mDBusMessageIter, DBUS_TYPE_ARRAY, "(nn)", &arrayIter);
614     for(;listIterator<listSystemProperties.end();++listIterator)
615     {
616         success=success && dbus_message_iter_open_container(&arrayIter, DBUS_TYPE_STRUCT, NULL, &structIter);
617         success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &listIterator->type);
618         success=success && dbus_message_iter_append_basic(&structIter, DBUS_TYPE_INT16, &listIterator->value);
619         success=success && dbus_message_iter_close_container(&arrayIter, &structIter);
620     }
621     success=success && dbus_message_iter_close_container(&mDBusMessageIter, &arrayIter);
622
623     if (!success)
624     {
625         mErrorName=std::string(DBUS_ERROR_NO_MEMORY);
626         mErrorMsg="Cannot create reply!";
627     }
628 }
629
630
631
632
633
634
635
636
637
638
639
640
641
642