File: PayloadAdapter.cc

package info (click to toggle)
alljoyn-services-1504 15.04-6
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 11,692 kB
  • sloc: cpp: 31,774; java: 30,139; xml: 5,829; objc: 5,531; python: 2,602; ansic: 1,356; makefile: 84; sh: 19
file content (686 lines) | stat: -rw-r--r-- 27,029 bytes parent folder | download | duplicates (2)
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
/******************************************************************************
 * Copyright AllSeen Alliance. All rights reserved.
 *
 *    Permission to use, copy, modify, and/or distribute this software for any
 *    purpose with or without fee is hereby granted, provided that the above
 *    copyright notice and this permission notice appear in all copies.
 *
 *    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 *    WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 *    MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 *    ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 *    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 *    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 *    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 ******************************************************************************/

#include <stdio.h>
#include <time.h>
#include <alljoyn/MsgArg.h>
#include <alljoyn/notification/Notification.h>
#include <alljoyn/notification/NotificationService.h>
#include "NotificationConstants.h"
#include "PayloadAdapter.h"
#include "Transport.h"
#include <alljoyn/notification/LogModule.h>

using namespace qcc;
using namespace ajn;
using namespace services;
using namespace nsConsts;

int32_t PayloadAdapter::m_MessageId(0);

QStatus PayloadAdapter::sendPayload(const char* deviceId, const char* deviceName,
                                    const uint8_t* appId, size_t appIdlen, const char* appName,
                                    NotificationMessageType messageType,
                                    std::vector<NotificationText> const&  notificationText,
                                    std::map<qcc::String, qcc::String> const& customAttributes,
                                    uint16_t ttl,
                                    const char* richIconUrl, std::vector<RichAudioUrl> const&  richAudioUrl,
                                    const char* richIconObjectPath, const char* richAudioObjectPath,
                                    const char* controlPanelServiceObjectPath, const char* originalSender, int32_t messageId)
{

    MsgArg deviceIdArg;
    MsgArg deviceNameArg;
    MsgArg appIdArg;
    MsgArg appNameArg;
    QStatus status;

    do {
        CHECK(deviceIdArg.Set(AJPARAM_STR.c_str(), deviceId));
        CHECK(deviceNameArg.Set(AJPARAM_STR.c_str(), deviceName));
        CHECK(appIdArg.Set(AJPARAM_ARR_BYTE.c_str(), appIdlen, appId));
        CHECK(appNameArg.Set(AJPARAM_STR.c_str(), appName));

        return(sendPayload(deviceIdArg, deviceNameArg, appIdArg, appNameArg, messageType, notificationText, customAttributes, ttl, richIconUrl, richAudioUrl, richIconObjectPath, richAudioObjectPath, controlPanelServiceObjectPath, originalSender, messageId));
    } while (0);

    QCC_LogError(status, ("Error occurred.  Could not marshal parameters."));

    return status;
}

QStatus PayloadAdapter::sendPayload(AboutData* propertyStore,
                                    NotificationMessageType messageType,
                                    std::vector<NotificationText> const&  notificationText,
                                    std::map<qcc::String, qcc::String> const& customAttributes,
                                    uint16_t ttl,
                                    const char* richIconUrl, std::vector<RichAudioUrl> const&  richAudioUrl,
                                    const char* richIconObjectPath, const char* richAudioObjectPath,
                                    const char* controlPanelServiceObjectPath, const char* originalSender)
{
    MsgArg deviceIdArg;
    MsgArg deviceNameArg;
    MsgArg appIdArg;
    MsgArg appNameArg;

    if (!m_MessageId) {
        srand(time(NULL));
        m_MessageId = rand();
    }

    MsgArg configArgs;
    MsgArg* configEntries;
    size_t configNum;
    QStatus status;

    if ((status = propertyStore->GetAboutData(&configArgs))) {
        return status;
    }

    if ((status = configArgs.Get(AJPARAM_ARR_DICT_STR_VAR.c_str(), &configNum, &configEntries))) {
        QCC_LogError(status, ("Error reading in about configuration data"));
        return status;
    }

    for (size_t i = 0; i < configNum; i++) {
        char* keyChar;
        String key;
        MsgArg* variant;

        CHECK(configEntries[i].Get(AJPARAM_DICT_STR_VAR.c_str(), &keyChar, &variant));

        key = keyChar;

        if (key.compare("DeviceId") == 0) {
            deviceIdArg = *variant;
        } else if (key.compare("DeviceName") == 0) {
            deviceNameArg = *variant;
        } else if (key.compare("AppId") == 0) {
            appIdArg = *variant;
        } else if (key.compare("AppName") == 0) {
            appNameArg = *variant;
        }
    }

    if (status != ER_OK) {
        QCC_LogError(status, ("Something went wrong unmarshalling the propertystore."));
        return status;
    }

    /* Validate Arguments */

    if (deviceIdArg.typeId != ALLJOYN_STRING) {
        QCC_LogError(ER_BAD_ARG_1, ("DeviceId argument is not correct type."));
        return ER_BAD_ARG_1;
    }
    if (deviceIdArg.v_string.str == 0 || deviceIdArg.v_string.len == 0) {
        QCC_LogError(ER_BAD_ARG_1, ("DeviceId argument can not be NULL or an empty String."));
        return ER_BAD_ARG_1;
    }

    if (deviceNameArg.typeId != ALLJOYN_STRING) {
        QCC_LogError(ER_BAD_ARG_1, ("DeviceName argument is not correct type."));
        return ER_BAD_ARG_1;
    }
    if (deviceNameArg.v_string.str == 0 || deviceNameArg.v_string.len == 0) {
        QCC_LogError(ER_BAD_ARG_1, ("DeviceName argument can not be NULL or an empty String."));
        return ER_BAD_ARG_1;
    }

    if (appIdArg.typeId != ALLJOYN_BYTE_ARRAY) {
        QCC_LogError(ER_BAD_ARG_1, ("ApplicationId argument is not correct type."));
        return ER_BAD_ARG_1;
    }

    if (appIdArg.v_scalarArray.numElements == 0) {
        QCC_LogError(ER_BAD_ARG_1, ("ApplicationId argument cannot be empty"));
        return ER_BAD_ARG_1;
    }

    if (appNameArg.typeId != ALLJOYN_STRING) {
        QCC_LogError(ER_BAD_ARG_1, ("ApplicationName argument is not correct type."));
        return ER_BAD_ARG_1;
    }
    if (appNameArg.v_string.str == 0 || appNameArg.v_string.len == 0) {
        QCC_LogError(ER_BAD_ARG_1, ("ApplicationName argument can not be NULL or an empty String."));
        return ER_BAD_ARG_1;
    }

    return (sendPayload(deviceIdArg, deviceNameArg, appIdArg, appNameArg, messageType, notificationText, customAttributes, ttl, richIconUrl, richAudioUrl, richIconObjectPath, richAudioObjectPath, controlPanelServiceObjectPath, originalSender, ++m_MessageId));
}

QStatus PayloadAdapter::sendPayload(PropertyStore* propertyStore,
                                    NotificationMessageType messageType,
                                    std::vector<NotificationText> const&  notificationText,
                                    std::map<qcc::String, qcc::String> const& customAttributes,
                                    uint16_t ttl,
                                    const char* richIconUrl, std::vector<RichAudioUrl> const&  richAudioUrl,
                                    const char* richIconObjectPath, const char* richAudioObjectPath,
                                    const char* controlPanelServiceObjectPath, const char* originalSender)
{
    MsgArg deviceIdArg;
    MsgArg deviceNameArg;
    MsgArg appIdArg;
    MsgArg appNameArg;

    if (!m_MessageId) {
        srand(time(NULL));
        m_MessageId = rand();
    }

    MsgArg configArgs[1];
    MsgArg* configEntries;
    size_t configNum;
    QStatus status;

    if ((status = propertyStore->ReadAll(0, PropertyStore::READ, configArgs[0]))) {
        return status;
    }

    if ((status = configArgs[0].Get(AJPARAM_ARR_DICT_STR_VAR.c_str(), &configNum, &configEntries))) {
        QCC_LogError(status, ("Error reading in about configuration data"));
        return status;
    }

    for (size_t i = 0; i < configNum; i++) {
        char* keyChar;
        String key;
        MsgArg* variant;

        CHECK(configEntries[i].Get(AJPARAM_DICT_STR_VAR.c_str(), &keyChar, &variant));

        key = keyChar;

        if (key.compare("DeviceId") == 0) {
            deviceIdArg = *variant;
        } else if (key.compare("DeviceName") == 0) {
            deviceNameArg = *variant;
        } else if (key.compare("AppId") == 0) {
            appIdArg = *variant;
        } else if (key.compare("AppName") == 0) {
            appNameArg = *variant;
        }
    }

    if (status != ER_OK) {
        QCC_LogError(status, ("Something went wrong unmarshalling the propertystore."));
        return status;
    }

    /* Validate Arguments */

    if (deviceIdArg.typeId != ALLJOYN_STRING) {
        QCC_LogError(ER_BAD_ARG_1, ("DeviceId argument is not correct type."));
        return ER_BAD_ARG_1;
    }
    if (deviceIdArg.v_string.str == 0 || deviceIdArg.v_string.len == 0) {
        QCC_LogError(ER_BAD_ARG_1, ("DeviceId argument can not be NULL or an empty String."));
        return ER_BAD_ARG_1;
    }

    if (deviceNameArg.typeId != ALLJOYN_STRING) {
        QCC_LogError(ER_BAD_ARG_1, ("DeviceName argument is not correct type."));
        return ER_BAD_ARG_1;
    }
    if (deviceNameArg.v_string.str == 0 || deviceNameArg.v_string.len == 0) {
        QCC_LogError(ER_BAD_ARG_1, ("DeviceName argument can not be NULL or an empty String."));
        return ER_BAD_ARG_1;
    }

    if (appIdArg.typeId != ALLJOYN_BYTE_ARRAY) {
        QCC_LogError(ER_BAD_ARG_1, ("ApplicationId argument is not correct type."));
        return ER_BAD_ARG_1;
    }

    if (appIdArg.v_scalarArray.numElements == 0) {
        QCC_LogError(ER_BAD_ARG_1, ("ApplicationId argument cannot be empty"));
        return ER_BAD_ARG_1;
    }

    if (appNameArg.typeId != ALLJOYN_STRING) {
        QCC_LogError(ER_BAD_ARG_1, ("ApplicationName argument is not correct type."));
        return ER_BAD_ARG_1;
    }
    if (appNameArg.v_string.str == 0 || appNameArg.v_string.len == 0) {
        QCC_LogError(ER_BAD_ARG_1, ("ApplicationName argument can not be NULL or an empty String."));
        return ER_BAD_ARG_1;
    }

    return (sendPayload(deviceIdArg, deviceNameArg, appIdArg, appNameArg, messageType, notificationText, customAttributes, ttl, richIconUrl, richAudioUrl, richIconObjectPath, richAudioObjectPath, controlPanelServiceObjectPath, originalSender, ++m_MessageId));
}

QStatus PayloadAdapter::sendPayload(ajn::MsgArg deviceIdArg, ajn::MsgArg deviceNameArg,
                                    ajn::MsgArg appIdArg, ajn::MsgArg appNameArg,
                                    NotificationMessageType messageType,
                                    std::vector<NotificationText> const&  notificationText,
                                    std::map<qcc::String, qcc::String> const& customAttributes,
                                    uint16_t ttl,
                                    const char* richIconUrl, std::vector<RichAudioUrl> const&  richAudioUrl,
                                    const char* richIconObjectPath, const char* richAudioObjectPath,
                                    const char* controlPanelServiceObjectPath, const char* originalSender, int32_t messageId)
{
    QStatus status;
    MsgArg versionArg;
    MsgArg messageIdArg;
    MsgArg messageTypeArg;
    MsgArg richIconUrlArg;
    MsgArg richAudioArg;
    MsgArg richIconObjectPathArg;
    MsgArg richAudioObjectPathArg;
    MsgArg controlPanelServiceObjectPathArg;
    MsgArg originalSenderArg;

    do {
        CHECK(versionArg.Set(AJPARAM_UINT16.c_str(), NotificationService::getVersion()));

        CHECK(messageIdArg.Set(AJPARAM_INT.c_str(), messageId));

        CHECK(messageTypeArg.Set(AJPARAM_UINT16.c_str(), messageType));

        int32_t attrSize = 1;

        if (richIconUrl) {
            attrSize++;
        }
        if (!richAudioUrl.empty()) {
            attrSize++;
        }
        if (richIconObjectPath) {
            attrSize++;
        }
        if (richAudioObjectPath) {
            attrSize++;
        }
        if (controlPanelServiceObjectPath) {
            attrSize++;
        }

        std::vector<MsgArg> attributes(attrSize);
        std::vector<RichAudioUrl>::const_iterator contIter;
        std::vector<MsgArg> audioContent(richAudioUrl.size());

        int32_t attrIndx = 0;

        CHECK(originalSenderArg.Set(AJPARAM_STR.c_str(), originalSender))
        CHECK(attributes[attrIndx++].Set(AJPARAM_DICT_INT_VAR.c_str(), ORIGINAL_SENDER_ATTRIBUTE_KEY, &originalSenderArg));

        if (richIconUrl) {
            CHECK(richIconUrlArg.Set(AJPARAM_STR.c_str(), richIconUrl))
            CHECK(attributes[attrIndx++].Set(AJPARAM_DICT_INT_VAR.c_str(), RICH_CONTENT_ICON_URL_ATTRIBUTE_KEY, &richIconUrlArg));
        }

        if (!richAudioUrl.empty()) {
            /* Fill the audioContent array using the richAudioUrl passed in
               Then Marshal attributes argument */

            int32_t audioIndx = 0;
            for (contIter = richAudioUrl.begin(); contIter != richAudioUrl.end(); contIter++) {
                if (!(contIter->getLanguage().size()) || !(contIter->getUrl().size())) {
                    QCC_LogError(ER_BAD_ARG_7, ("Problem sending message. Cannot send a message with audio content with an empty language/url values."));
                    return ER_BAD_ARG_7;
                }
                CHECK(audioContent[audioIndx++].Set(AJPARAM_STRUCT_STR_STR.c_str(), contIter->getLanguage().c_str(),
                                                    contIter->getUrl().c_str()));
            }
            if (status != ER_OK) {
                break;
            }

            CHECK(richAudioArg.Set(AJPARAM_ARR_STRUCT_STR_STR.c_str(), audioContent.size(), audioContent.data()))
            CHECK(attributes[attrIndx++].Set(AJPARAM_DICT_INT_VAR.c_str(), RICH_CONTENT_AUDIO_URL_ATTRIBUTE_KEY, &richAudioArg));
        }

        if (richIconObjectPath) {
            CHECK(richIconObjectPathArg.Set(AJPARAM_STR.c_str(), richIconObjectPath))
            CHECK(attributes[attrIndx++].Set(AJPARAM_DICT_INT_VAR.c_str(), RICH_CONTENT_ICON_OBJECT_PATH_ATTRIBUTE_KEY, &richIconObjectPathArg));
        }

        if (richAudioObjectPath) {
            CHECK(richAudioObjectPathArg.Set(AJPARAM_STR.c_str(), richAudioObjectPath))
            CHECK(attributes[attrIndx++].Set(AJPARAM_DICT_INT_VAR.c_str(), RICH_CONTENT_AUDIO_OBJECT_PATH_ATTRIBUTE_KEY, &richAudioObjectPathArg));
        }

        if (controlPanelServiceObjectPath) {
            CHECK(controlPanelServiceObjectPathArg.Set(AJPARAM_STR.c_str(), controlPanelServiceObjectPath))
            CHECK(attributes[attrIndx++].Set(AJPARAM_DICT_INT_VAR.c_str(), CPS_OBJECT_PATH_ATTRIBUTE_KEY, &controlPanelServiceObjectPathArg));
        }

        if (status != ER_OK) {
            break;
        }

        MsgArg attributesArg;
        CHECK(attributesArg.Set(AJPARAM_ARR_DICT_INT_VAR.c_str(), attrSize, attributes.data()));

        /* Fill the custom attributes array then using customAttributes
           Then Marshal the custom attributes argument */

        int32_t customAttrIndx = 0;
        std::vector<MsgArg> sendCustomAttributes(customAttributes.size());
        std::map<qcc::String, qcc::String>::const_iterator cAiter;
        for (cAiter = customAttributes.begin(); cAiter != customAttributes.end(); cAiter++) {
            CHECK(sendCustomAttributes[customAttrIndx++].Set(AJPARAM_DICT_STR_STR.c_str(),
                                                             cAiter->first.c_str(), cAiter->second.c_str()));
        }
        if (status != ER_OK) {
            break;
        }

        MsgArg customAttributesArg;
        CHECK(customAttributesArg.Set(AJPARAM_ARR_DICT_STR_STR.c_str(), customAttributes.size(), sendCustomAttributes.data()));

        /* Fill the notificationText array using the notifications passed in
           Then Marshal notificationText argument */

        int32_t notifIndx = 0;
        std::vector<NotificationText>::const_iterator notIter;
        std::vector<MsgArg> notifications(notificationText.size());

        for (notIter = notificationText.begin(); notIter != notificationText.end(); notIter++) {
            if (!(notIter->getLanguage().size()) || !(notIter->getText().size())) {
                QCC_LogError(ER_BAD_ARG_6, ("Problem sending message. Cannot send a message with an empty language/text values."));
                return ER_BAD_ARG_6;
            }
            CHECK(notifications[notifIndx++].Set(AJPARAM_STRUCT_STR_STR.c_str(), notIter->getLanguage().c_str(),
                                                 notIter->getText().c_str()));
        }
        if (status != ER_OK) {
            break;
        }

        MsgArg notificationTextArg;
        CHECK(notificationTextArg.Set(AJPARAM_ARR_STRUCT_STR_STR.c_str(), notificationText.size(), notifications.data()));

        MsgArg notificationArgs[AJ_NOTIFY_NUM_PARAMS];
        notificationArgs[0] = versionArg;
        notificationArgs[1] = messageIdArg;
        notificationArgs[2] = messageTypeArg;
        notificationArgs[3] = deviceIdArg;
        notificationArgs[4] = deviceNameArg;
        notificationArgs[5] = appIdArg;
        notificationArgs[6] = appNameArg;
        notificationArgs[7] = attributesArg;
        notificationArgs[8] = customAttributesArg;
        notificationArgs[9] = notificationTextArg;

        QCC_DbgPrintf(("Attempting to send messageId: %d", messageId));

        Transport* transport = Transport::getInstance();
        status = transport->sendNotification(messageType, notificationArgs, ttl);
        if (status == ER_OK) {
            QCC_DbgHLPrintf(("Message sent successfully with messageId: %d", messageId));
        }
        return status;
    } while (0);

    QCC_LogError(status, ("Error occurred.  Could not marshal parameters."));

    return status;
}

void PayloadAdapter::receivePayload(Message& msg)
{
    QStatus status;

    const MsgArg* versionArg = msg.unwrap()->GetArg(0);
    const MsgArg* messageIdArg = msg.unwrap()->GetArg(1);
    const MsgArg* messageTypeArg = msg.unwrap()->GetArg(2);
    const MsgArg* deviceIdArg = msg.unwrap()->GetArg(3);
    const MsgArg* deviceNameArg = msg.unwrap()->GetArg(4);
    const MsgArg* appIdArg = msg.unwrap()->GetArg(5);
    const MsgArg* appNameArg = msg.unwrap()->GetArg(6);
    const MsgArg* attributesArg = msg.unwrap()->GetArg(7);
    const MsgArg* customAttributesArg = msg.unwrap()->GetArg(8);
    const MsgArg* notificationsArg = msg.unwrap()->GetArg(9);

    const char* sender = msg->GetSender();

    do {
        //Unmarshal Version
        if (versionArg->typeId != ALLJOYN_UINT16) {
            QCC_DbgHLPrintf(("Problem receiving message: Can not Unmarshal this Version argument."));
            return;
        }

        uint16_t version;
        CHECK(versionArg->Get(AJPARAM_UINT16.c_str(), &version));

        //Unmarshal messageId
        if (messageIdArg->typeId != ALLJOYN_INT32) {
            QCC_DbgHLPrintf(("Problem receiving message: Can not Unmarshal this messageId argument."));
            return;
        }

        int32_t messageId;
        CHECK(messageIdArg->Get(AJPARAM_INT.c_str(), &messageId));

        //Unmarshal messageType
        if (messageTypeArg->typeId != ALLJOYN_UINT16) {
            QCC_DbgHLPrintf(("Problem receiving message: Can not Unmarshal this message type argument."));
            return;
        }

        uint16_t intVal;
        NotificationMessageType messageType;
        CHECK(messageTypeArg->Get(AJPARAM_UINT16.c_str(), &intVal));
        messageType = MessageTypeUtil::getMessageType(intVal);

        //Unmarshal deviceId
        if (deviceIdArg->typeId != ALLJOYN_STRING) {
            QCC_DbgHLPrintf(("Problem receiving message: Can not Unmarshal this deviceId argument."));
            return;
        }

        char* deviceId;
        CHECK(deviceIdArg->Get(AJPARAM_STR.c_str(), &deviceId));

        //Unmarshal deviceName
        if (deviceNameArg->typeId != ALLJOYN_STRING) {
            QCC_DbgHLPrintf(("Problem receiving message: Can not Unmarshal this device Name argument."));
            return;
        }

        char* deviceName;
        CHECK(deviceNameArg->Get(AJPARAM_STR.c_str(), &deviceName));

        //Unmarshal appId
        if (appIdArg->typeId != ALLJOYN_BYTE_ARRAY) {
            QCC_DbgHLPrintf(("Problem receiving message: Can not Unmarshal this appId argument."));
            return;
        }

        String appId;
        uint8_t* appIdBin;
        size_t len;
        CHECK(appIdArg->Get(AJPARAM_ARR_BYTE.c_str(), &len, &appIdBin));

        if (len != UUID_LENGTH) {
            QCC_DbgHLPrintf(("App id length is not equal to %u", UUID_LENGTH * 2));
            return;
        }

        //convert bytes to stringstrea
        uint32_t i;
        static const char* const chars = "0123456789ABCDEF";

        appId.reserve(2 * len);
        for (i = 0; i < len; ++i) {
            const unsigned char c = appIdBin[i];
            appId.push_back(chars[c >> 4]);
            appId.push_back(chars[c & 15]);
        }

        //Unmarshal appName
        if (appNameArg->typeId != ALLJOYN_STRING) {
            QCC_DbgHLPrintf(("Problem receiving message: Can not Unmarshal this app Name argument."));
            return;
        }

        char* appName;
        CHECK(appNameArg->Get(AJPARAM_STR.c_str(), &appName));

        //Unmarshal Attributes
        if (attributesArg->typeId != ALLJOYN_ARRAY) {
            QCC_DbgHLPrintf(("Problem receiving message: Can not Unmarshal this Attributes argument."));
            return;
        }

        MsgArg*attribEntries;
        size_t attribNum;
        char* richIconUrl = 0;
        char* richIconObjectPath = 0;
        char* richAudioObjectPath = 0;
        char* controlPanelServiceObjectPath = 0;
        char* originalSender = 0;
        std::vector<RichAudioUrl> richAudioUrl;


        CHECK(attributesArg->Get(AJPARAM_ARR_DICT_INT_VAR.c_str(), &attribNum, &attribEntries));

        for (size_t i = 0; i < attribNum; i++) {
            int32_t key;
            MsgArg* variant;

            CHECK(attribEntries[i].Get(AJPARAM_DICT_INT_VAR.c_str(), &key, &variant));

            switch (key) {
            case RICH_CONTENT_ICON_URL_ATTRIBUTE_KEY:
                {
                    CHECK(variant->Get(AJPARAM_STR.c_str(), &richIconUrl));
                    break;
                }

            case RICH_CONTENT_AUDIO_URL_ATTRIBUTE_KEY:
                {

                    MsgArg*richAudioEntries;
                    size_t richAudioNum;

                    CHECK(variant->Get(AJPARAM_ARR_STRUCT_STR_STR.c_str(), &richAudioNum, &richAudioEntries));

                    for (size_t i = 0; i < richAudioNum; i++) {
                        char*key;
                        char*StringVal;
                        status = richAudioEntries[i].Get(AJPARAM_STRUCT_STR_STR.c_str(), &key, &StringVal);
                        if (status != ER_OK) {
                            QCC_LogError(status, ("Can not Unmarshal this NotificationText argument."));
                            break;
                        }
                        richAudioUrl.push_back(RichAudioUrl(key, StringVal));
                    }
                    break;
                }

            case RICH_CONTENT_ICON_OBJECT_PATH_ATTRIBUTE_KEY:
                {
                    CHECK(variant->Get(AJPARAM_STR.c_str(), &richIconObjectPath));
                    break;
                }

            case RICH_CONTENT_AUDIO_OBJECT_PATH_ATTRIBUTE_KEY:
                {
                    CHECK(variant->Get(AJPARAM_STR.c_str(), &richAudioObjectPath));
                    break;
                }

            case CPS_OBJECT_PATH_ATTRIBUTE_KEY:
                {
                    CHECK(variant->Get(AJPARAM_STR.c_str(), &controlPanelServiceObjectPath));
                    break;
                }

            case ORIGINAL_SENDER_ATTRIBUTE_KEY:
                {
                    CHECK(variant->Get(AJPARAM_STR.c_str(), &originalSender));
                    break;
                }

            default:
                QCC_DbgHLPrintf(("Can not Unmarshal this attribute argument"));
                break;
            }
        } // for (size_t i = 0; i < attribNum; i++)

        //Unmarshal Custom Attributes
        if (customAttributesArg->typeId != ALLJOYN_ARRAY) {
            QCC_DbgHLPrintf(("Problem receiving message: Can not Unmarshal this custom Attributes argument."));
            return;
        }

        MsgArg*customAttributesEntries;
        size_t customAttributesNum;
        std::map<qcc::String, qcc::String> customAttributes;

        CHECK(customAttributesArg->Get(AJPARAM_ARR_DICT_STR_STR.c_str(), &customAttributesNum, &customAttributesEntries));

        for (size_t i = 0; i < customAttributesNum; i++) {
            char*key;
            char*StringVal;
            status = customAttributesEntries[i].Get(AJPARAM_DICT_STR_STR.c_str(), &key, &StringVal);
            if (status != ER_OK) {
                QCC_DbgHLPrintf(("Can not Unmarshal this Custom Attribute argument"));
                break;
            }
            customAttributes.insert(std::pair<qcc::String, qcc::String>(key, StringVal));
        }

        if (status != ER_OK) {
            break;
        }

        //Unmarshal NotificationTexts
        if (notificationsArg->typeId != ALLJOYN_ARRAY) {
            QCC_DbgHLPrintf(("Problem receiving message: Can not Unmarshal this NotificationsArg argument."));
            return;
        }

        MsgArg*notTextEntries;
        size_t notTextNum;
        CHECK(notificationsArg->Get(AJPARAM_ARR_STRUCT_STR_STR.c_str(), &notTextNum, &notTextEntries));

        std::vector<NotificationText> text;
        for (size_t i = 0; i < notTextNum; i++) {
            char*key;
            char*StringVal;
            status = notTextEntries[i].Get(AJPARAM_STRUCT_STR_STR.c_str(), &key, &StringVal);
            if (status != ER_OK) {
                QCC_DbgHLPrintf(("Can not Unmarshal this NotificationText argument"));
                break;
            }
            text.push_back(NotificationText(key, StringVal));
        }


        if (status != ER_OK) {
            break;
        }

        //Create notification and send it on
        Notification notification(messageId, messageType, deviceId, deviceName,
                                  appId.c_str(), appName, sender, customAttributes, text,
                                  richIconUrl, richAudioUrl, richIconObjectPath, richAudioObjectPath, controlPanelServiceObjectPath, originalSender);

        Transport* transport = Transport::getInstance();
        transport->onReceivedNotification(notification);
        return;

    } while (0);

    QCC_LogError(status, ("Error occurred.  Could not unmarshal parameters."));

    return;
}