コード例 #1
0
static AJ_Status SendEvent(AJ_BusAttachment* busAttachment, uint32_t eventId)
{
    AJ_Status status = AJ_OK;
    AJ_Message msg;

    status = AJ_MarshalSignal(busAttachment, &msg, eventId, NULL, 0, AJ_FLAG_SESSIONLESS, 0);
    if (status != AJ_OK) {
        goto ErrorExit;
    }
    status = AJ_DeliverMsg(&msg);
    if (status != AJ_OK) {
        goto ErrorExit;
    }
    status = AJ_CloseMsg(&msg);
    if (status != AJ_OK) {
        goto ErrorExit;
    }
    AJ_AlwaysPrintf(("Event sent successfully\n"));
    return status;

ErrorExit:

    AJ_AlwaysPrintf(("Event sending failed with status=%s\n", AJ_StatusText(status)));
    return status;
}
コード例 #2
0
static AJ_Status SendSignal()
{
    AJ_Message msg;

    AJ_AlwaysPrintf(("Emitting Name Changed Signal. New value for property 'name' is '%s'.\n", propertyName));

    /* For the signal to transmit outside of the current process the session ID must be 0. */
    AJ_MarshalSignal(&busAttachment, &msg, BASIC_SIGNAL_SERVICE_SIGNAL, NULL, 0, AJ_FLAG_GLOBAL_BROADCAST, 0);
    AJ_MarshalArgs(&msg, "s", propertyName);

    return AJ_DeliverMsg(&msg);
}
コード例 #3
0
static AJ_Status AJ_SendLinkProbeReq(AJ_BusAttachment* bus)
{
    AJ_Status status;
    AJ_Message msg;

    status = AJ_MarshalSignal(bus, &msg, AJ_SIGNAL_PROBE_REQ, AJ_BusDestination, 0, 0, 0);
    if (status == AJ_OK) 
	{
        status = AJ_DeliverMsg(&msg);
    }
    return status;
}
コード例 #4
0
AJ_Status AppSendChatSignal(AJ_BusAttachment* bus, uint32_t sessionId, const char* chatString, uint8_t flags, uint32_t ttl)
{
    AJ_Status status = AJ_OK;
    AJ_Message msg;

    status = AJ_MarshalSignal(bus, &msg, APP_CHAT_SIGNAL, NULL, sessionId, flags, ttl);
    if (status == AJ_OK) {
        status = AJ_MarshalArgs(&msg, "s", chatString);
    }

    if (status == AJ_OK) {
        status = AJ_DeliverMsg(&msg);
    }
    AJ_AlwaysPrintf(("TX chat: %s\n", chatString));
    return status;
}
コード例 #5
0
ファイル: siglite.c プロジェクト: reignme/ajtcl
static AJ_Status SendSignal(AJ_BusAttachment* bus, uint32_t sessionId)
{
    AJ_Status status;
    AJ_Message msg;


    status = AJ_MarshalSignal(bus, &msg, PRX_MY_SIGNAL, ServiceName, sessionId, 0, 0);
    if (status == AJ_OK) {
        AJ_Arg arg;
        status = AJ_MarshalContainer(&msg, &arg, AJ_ARG_ARRAY);
        status = AJ_MarshalCloseContainer(&msg, &arg);
    }
    if (status == AJ_OK) {
        status = AJ_DeliverMsg(&msg);
    }
    return status;
}
コード例 #6
0
ファイル: svclite.c プロジェクト: fonlabs/ajtcl
int AJ_Main()
{
    AJ_Status status = AJ_OK;
    AJ_BusAttachment bus;
    uint8_t connected = FALSE;
    uint32_t sessionId = 0;

    /*
     * One time initialization before calling any other AllJoyn APIs
     */
    AJ_Initialize();

    AJ_PrintXML(AppObjects);
    AJ_RegisterObjects(AppObjects, NULL);

    SetBusAuthPwdCallback(MyBusAuthPwdCB);
    while (TRUE) {
        AJ_Message msg;

        if (!connected) {
            status = AJ_StartService(&bus, NULL, CONNECT_TIMEOUT, FALSE, ServicePort, ServiceName, AJ_NAME_REQ_DO_NOT_QUEUE, NULL);
            if (status != AJ_OK) {
                continue;
            }
            AJ_InfoPrintf(("StartService returned AJ_OK\n"));
            AJ_InfoPrintf(("Connected to Daemon:%s\n", AJ_GetUniqueName(&bus)));

            connected = TRUE;
#ifdef SECURE_OBJECT
            status = AJ_SetObjectFlags("/org/alljoyn/alljoyn_test", AJ_OBJ_FLAG_SECURE, 0);
            if (status != AJ_OK) {
                AJ_ErrPrintf(("Error calling AJ_SetObjectFlags.. [%s] \n", AJ_StatusText(status)));
                return -1;
            }
#endif

#if defined(SECURE_INTERFACE) || defined(SECURE_OBJECT)

            /* Register a callback for providing bus authentication password */
            AJ_BusSetPasswordCallback(&bus, PasswordCallback);
            AJ_BusEnableSecurity(&bus, suites, numsuites);
            AJ_BusSetAuthListenerCallback(&bus, AuthListenerCallback);
#endif

            /* Configure timeout for the link to the daemon bus */
            AJ_SetBusLinkTimeout(&bus, 60); // 60 seconds
        }

        status = AJ_UnmarshalMsg(&bus, &msg, UNMARSHAL_TIMEOUT);
        if (AJ_ERR_TIMEOUT == status && AJ_ERR_LINK_TIMEOUT == AJ_BusLinkStateProc(&bus)) {
            status = AJ_ERR_READ;
        }
        if (status != AJ_OK) {
            if (status == AJ_ERR_TIMEOUT) {
                AppDoWork();
                continue;
            }
        }

        if (status == AJ_OK) {
            switch (msg.msgId) {

            case AJ_REPLY_ID(AJ_METHOD_ADD_MATCH):
                if (msg.hdr->msgType == AJ_MSG_ERROR) {
                    AJ_InfoPrintf(("Failed to add match\n"));
                    status = AJ_ERR_FAILURE;
                } else {
                    status = AJ_OK;
                }
                break;

            case AJ_METHOD_ACCEPT_SESSION:
                {
                    uint16_t port;
                    char* joiner;
                    AJ_UnmarshalArgs(&msg, "qus", &port, &sessionId, &joiner);
                    if (port == ServicePort) {
                        status = AJ_BusReplyAcceptSession(&msg, TRUE);
                        AJ_InfoPrintf(("Accepted session session_id=%u joiner=%s\n", sessionId, joiner));
                    } else {
                        status = AJ_BusReplyAcceptSession(&msg, FALSE);
                        AJ_InfoPrintf(("Accepted rejected session_id=%u joiner=%s\n", sessionId, joiner));
                    }
                }
                break;

            case APP_MY_PING:
                status = AppHandlePing(&msg);
                break;

            case APP_GET_PROP:
                status = AJ_BusPropGet(&msg, PropGetHandler, NULL);
                break;

            case APP_SET_PROP:
                status = AJ_BusPropSet(&msg, PropSetHandler, NULL);
                if (status == AJ_OK) {
                    AJ_InfoPrintf(("Property successfully set to %d.\n", propVal));
                } else {
                    AJ_InfoPrintf(("Property set attempt unsuccessful. Status = 0x%04x.\n", status));
                }
                break;

            case AJ_SIGNAL_SESSION_LOST_WITH_REASON:
                {
                    uint32_t id, reason;
                    AJ_UnmarshalArgs(&msg, "uu", &id, &reason);
                    AJ_InfoPrintf(("Session lost. ID = %u, reason = %u", id, reason));
                    if (CancelAdvertiseName) {
                        status = AJ_BusAdvertiseName(&bus, ServiceName, AJ_TRANSPORT_ANY, AJ_BUS_START_ADVERTISING, 0);
                    }
                    status = AJ_ERR_SESSION_LOST;
                }
                break;

            case AJ_SIGNAL_SESSION_JOINED:
                if (CancelAdvertiseName) {
                    status = AJ_BusAdvertiseName(&bus, ServiceName, AJ_TRANSPORT_ANY, AJ_BUS_STOP_ADVERTISING, 0);
                }
                break;

            case AJ_REPLY_ID(AJ_METHOD_CANCEL_ADVERTISE):
            case AJ_REPLY_ID(AJ_METHOD_ADVERTISE_NAME):
                if (msg.hdr->msgType == AJ_MSG_ERROR) {
                    status = AJ_ERR_FAILURE;
                }
                break;

            case APP_MY_SIGNAL:
                AJ_InfoPrintf(("Received my_signal\n"));
                status = AJ_OK;

                if (ReflectSignal) {
                    AJ_Message out;
                    AJ_MarshalSignal(&bus, &out, APP_MY_SIGNAL, msg.destination, msg.sessionId, 0, 0);
                    AJ_MarshalArgs(&out, "a{ys}", 0, NULL);
                    AJ_DeliverMsg(&out);
                    AJ_CloseMsg(&out);
                }
                break;

            default:
                /*
                 * Pass to the built-in bus message handlers
                 */
                status = AJ_BusHandleBusMessage(&msg);
                break;
            }

            // Any received packets indicates the link is active, so call to reinforce the bus link state
            AJ_NotifyLinkActive();
        }
        /*
         * Unarshaled messages must be closed to free resources
         */
        AJ_CloseMsg(&msg);

        if ((status == AJ_ERR_READ) || (status == AJ_ERR_LINK_DEAD)) {
            AJ_InfoPrintf(("AllJoyn disconnect\n"));
            AJ_InfoPrintf(("Disconnected from Daemon:%s\n", AJ_GetUniqueName(&bus)));
            AJ_Disconnect(&bus);
            connected = FALSE;
            /*
             * Sleep a little while before trying to reconnect
             */
            AJ_Sleep(10 * 1000);
        }
    }
    AJ_WarnPrintf(("svclite EXIT %d\n", status));

    return status;
}
コード例 #7
0
/**
 * Marshal Notification
 */
static AJ_Status AJNS_Producer_MarshalNotificationMsg(AJ_BusAttachment* busAttachment, AJ_Message* msg, AJNS_Notification* notification, uint32_t ttl)
{
    AJ_Status status = AJ_OK;
    AJ_Arg attrbtArray;
    AJ_Arg customAttributeArray;
    AJ_Arg notTextArray;
    AJ_Arg richAudioArray;
    AJ_Arg dictArg;
    AJ_Arg customAttributeDictArg;
    AJ_Arg structArg;
    AJ_Arg audioStructArg;
    AJ_Arg richAudioAttrArray;
    int8_t indx;

    if (notification == NULL) 
	{
    //    AJ_InfoPrintf(("Nothing to send\n"));
        return status;
    }

    status = AJ_MarshalSignal(busAttachment, msg, AJ_ENCODE_MESSAGE_ID(AJNS_OBJECT_LIST_INDEX, NOTIFICATION_OBJECT_INDEX + notification->messageType, 1, 0), NULL, 0, AJ_FLAG_SESSIONLESS, ttl);
    if (status != AJ_OK) 
	{
        AJ_ErrPrintf(("Could not Marshal Signal\n"));
        return status;
    }

    ///////////////////       Proto     /////////////////////
    status = AJ_MarshalArgs(msg, "q", notification->version);
    if (status != AJ_OK) 
	{
        goto ErrorExit;
    }

    ///////////////////    MessgeId    /////////////////////
    status = AJ_MarshalArgs(msg, "i", notification->notificationId);
    if (status != AJ_OK) 
	{
        goto ErrorExit;
    }

    ///////////////////    MessageType   ////////////////////////////
    status = AJ_MarshalArgs(msg, "q", notification->messageType);
    if (status != AJ_OK) 
	{
        goto ErrorExit;

    }

    ///////////////////    DeviceId   ////////////////////////////
    status = AJ_MarshalArgs(msg, "s", notification->deviceId);
    if (status != AJ_OK) 
	{
        goto ErrorExit;
    }

    ///////////////////    DeviceName   ////////////////////////////
    status = AJ_MarshalArgs(msg, "s", notification->deviceName);
    if (status != AJ_OK) 
	{
        goto ErrorExit;
    }

    ///////////////////    AppId   ////////////////////////////
    status = AJSVC_MarshalAppId(msg, notification->appId);
    if (status != AJ_OK) 
	{
        goto ErrorExit;
    }

    ///////////////////    AppName   ////////////////////////////
    status = AJ_MarshalArgs(msg, "s", notification->appName);
    if (status != AJ_OK) 
	{
        goto ErrorExit;
    }

    ///////////////////    Attributes   ////////////////////////////
    status = AJ_MarshalContainer(msg, &attrbtArray, AJ_ARG_ARRAY);
    if (status != AJ_OK) 
	{
        goto ErrorExit;
    }

    if (notification->content->richIconUrl != 0) 
	{
        status = AJ_MarshalContainer(msg, &dictArg, AJ_ARG_DICT_ENTRY);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
        status = AJ_MarshalArgs(msg, "i", AJNS_RICH_CONTENT_ICON_URL_ATTRIBUTE_KEY);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
        status = AJ_MarshalVariant(msg, "s");
        if (status != AJ_OK)
		{
            goto ErrorExit;
        }
        status = AJ_MarshalArgs(msg, "s", notification->content->richIconUrl);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
        status = AJ_MarshalCloseContainer(msg, &dictArg);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
    }
    if (notification->content->numAudioUrls > 0) 
	{
        status = AJ_MarshalContainer(msg, &richAudioArray, AJ_ARG_DICT_ENTRY);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
        status = AJ_MarshalArgs(msg, "i", AJNS_RICH_CONTENT_AUDIO_URL_ATTRIBUTE_KEY);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
        status = AJ_MarshalVariant(msg, "a(ss)");
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
        status = AJ_MarshalContainer(msg, &richAudioAttrArray, AJ_ARG_ARRAY);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }

        for (indx = 0; indx < notification->content->numAudioUrls; indx++) 
		{
            if ((strlen(notification->content->richAudioUrls[indx].key) == 0) || (strlen(notification->content->richAudioUrls[indx].value) == 0)) 
			{
                AJ_ErrPrintf(("Rich Audio Language/Url can not be empty\n"));
                AJ_MarshalCloseContainer(msg, &richAudioArray);
                status = AJ_ERR_DISALLOWED;
                goto ErrorExit;
            }
            status = AJ_MarshalContainer(msg, &audioStructArg, AJ_ARG_STRUCT);
            if (status != AJ_OK) 
			{
                goto ErrorExit;
            }
            status = AJ_MarshalArgs(msg, "ss", notification->content->richAudioUrls[indx].key, notification->content->richAudioUrls[indx].value);
            if (status != AJ_OK) 
			{
                goto ErrorExit;
            }
            status = AJ_MarshalCloseContainer(msg, &audioStructArg);
            if (status != AJ_OK) 
			{
                goto ErrorExit;
            }
        }

        status = AJ_MarshalCloseContainer(msg, &richAudioAttrArray);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }

        status = AJ_MarshalCloseContainer(msg, &richAudioArray);
        if (status != AJ_OK)
		{
            goto ErrorExit;
        }
    }

    if (notification->content->richIconObjectPath != 0) 
	{
        status = AJ_MarshalContainer(msg, &dictArg, AJ_ARG_DICT_ENTRY);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
        status = AJ_MarshalArgs(msg, "i", AJNS_RICH_CONTENT_ICON_OBJECT_PATH_ATTRIBUTE_KEY);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
        status = AJ_MarshalVariant(msg, "s");
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
        status = AJ_MarshalArgs(msg, "s", notification->content->richIconObjectPath);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
        status = AJ_MarshalCloseContainer(msg, &dictArg);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
    }

    if (notification->content->richAudioObjectPath != 0) 
	{
        status = AJ_MarshalContainer(msg, &dictArg, AJ_ARG_DICT_ENTRY);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
        status = AJ_MarshalArgs(msg, "i", AJNS_RICH_CONTENT_AUDIO_OBJECT_PATH_ATTRIBUTE_KEY);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
        status = AJ_MarshalVariant(msg, "s");
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
        status = AJ_MarshalArgs(msg, "s", notification->content->richAudioObjectPath);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
        status = AJ_MarshalCloseContainer(msg, &dictArg);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
    }

    if (notification->content->controlPanelServiceObjectPath != 0) 
	{
        status = AJ_MarshalContainer(msg, &dictArg, AJ_ARG_DICT_ENTRY);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
        status = AJ_MarshalArgs(msg, "i", AJNS_CONTROLPANELSERVICE_OBJECT_PATH_ATTRIBUTE_KEY);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
        status = AJ_MarshalVariant(msg, "s");
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
        status = AJ_MarshalArgs(msg, "s", notification->content->controlPanelServiceObjectPath);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
        status = AJ_MarshalCloseContainer(msg, &dictArg);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
    }

    if (notification->version > 1) 
	{
        status = AJ_MarshalContainer(msg, &dictArg, AJ_ARG_DICT_ENTRY);
        if (status != AJ_OK)
		{
            goto ErrorExit;
        }
        status = AJ_MarshalArgs(msg, "i", AJNS_ORIGINAL_SENDER_NAME_ATTRIBUTE_KEY);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
        status = AJ_MarshalVariant(msg, "s");
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
        status = AJ_MarshalArgs(msg, "s", notification->originalSenderName);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
        status = AJ_MarshalCloseContainer(msg, &dictArg);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
    }

    status = AJ_MarshalCloseContainer(msg, &attrbtArray);
    if (status != AJ_OK) 
	{
        goto ErrorExit;
    }

    ///////////////////    Custom Attributes   ///////////////////
    status = AJ_MarshalContainer(msg, &customAttributeArray, AJ_ARG_ARRAY);
    if (status != AJ_OK) 
	{
        goto ErrorExit;
    }

    for (indx = 0; indx < notification->content->numCustomAttributes; indx++) 
	{
        status = AJ_MarshalContainer(msg, &customAttributeDictArg, AJ_ARG_DICT_ENTRY);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
        status = AJ_MarshalArgs(msg, "ss", notification->content->customAttributes[indx].key, notification->content->customAttributes[indx].value);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
        status = AJ_MarshalCloseContainer(msg, &customAttributeDictArg);
        if (status != AJ_OK)
		{
            goto ErrorExit;
        }
    }

    status = AJ_MarshalCloseContainer(msg, &customAttributeArray);
    if (status != AJ_OK) 
	{
        goto ErrorExit;
    }

    ///////////////////   Notifications   ////////////////////////////
    status = AJ_MarshalContainer(msg, &notTextArray, AJ_ARG_ARRAY);
    if (status != AJ_OK) 
	{
        goto ErrorExit;
    }

    for (indx = 0; indx < notification->content->numTexts; indx++) 
	{
        if ((strlen(notification->content->texts[indx].key) == 0) || (strlen(notification->content->texts[indx].value) == 0)) 
		{
            AJ_ErrPrintf(("Language/Text can not be empty\n"));
            AJ_MarshalCloseContainer(msg, &notTextArray);
            status = AJ_ERR_DISALLOWED;
            goto ErrorExit;
        }
        status = AJ_MarshalContainer(msg, &structArg, AJ_ARG_STRUCT);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
        status = AJ_MarshalArgs(msg, "ss", notification->content->texts[indx].key, notification->content->texts[indx].value);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
        status = AJ_MarshalCloseContainer(msg, &structArg);
        if (status != AJ_OK) 
		{
            goto ErrorExit;
        }
    }

    status = AJ_MarshalCloseContainer(msg, &notTextArray);
    if (status != AJ_OK) 
	{
        goto ErrorExit;
    }

    return AJ_OK;

ErrorExit:

    AJ_ErrPrintf(("MarshalNotification failed: '%s'\n", AJ_StatusText(status)));
    return status;
}
コード例 #8
0
ファイル: mutter.c プロジェクト: reignme/ajtcl
int AJ_Main()
{
    AJ_Status status;
    AJ_BusAttachment bus;
    AJ_Message txMsg;
    AJ_Message rxMsg;
    AJ_Arg arg;
    AJ_Arg array1;
    AJ_Arg array2;
    AJ_Arg struct1;
    AJ_Arg struct2;
    size_t sz;
    uint32_t i;
    uint32_t j;
    uint32_t k;
    uint32_t key;
    uint32_t len;
    uint32_t u;
    uint32_t v;
    int32_t n;
    int32_t m;
    uint16_t q;
    uint16_t r;
    uint8_t y;
    char* str;
    char* sig;
    void* raw;

    bus.sock.tx.direction = AJ_IO_BUF_TX;
    bus.sock.tx.bufSize = sizeof(txBuffer);
    bus.sock.tx.bufStart = txBuffer;
    bus.sock.tx.readPtr = bus.sock.tx.bufStart;
    bus.sock.tx.writePtr = bus.sock.tx.bufStart;
    bus.sock.tx.send = TxFunc;

    bus.sock.rx.direction = AJ_IO_BUF_RX;
    bus.sock.rx.bufSize = sizeof(rxBuffer);
    bus.sock.rx.bufStart = rxBuffer;
    bus.sock.rx.readPtr = bus.sock.rx.bufStart;
    bus.sock.rx.writePtr = bus.sock.rx.bufStart;
    bus.sock.rx.recv = RxFunc;

    /*
     * Set the hook
     */
#ifndef NDEBUG
    MutterHook = MsgInit;
#else
    AJ_Printf("mutter only works in DEBUG builds\n");
    return -1;
#endif

    for (i = 0; i < ArraySize(testSignature); ++i) {

        status = AJ_MarshalSignal(&bus, &txMsg, i, "mutter.service", 0, 0, 0);
        if (status != AJ_OK) {
            break;
        }

        switch (i) {
        case 0:
            CHECK(AJ_MarshalContainer(&txMsg, &array1, AJ_ARG_ARRAY));
            for (key = 0; key < ArraySize(Fruits); ++key) {
                AJ_Arg dict;
                CHECK(AJ_MarshalContainer(&txMsg, &dict, AJ_ARG_DICT_ENTRY));
                CHECK(AJ_MarshalArgs(&txMsg, "us", key, Fruits[key]));
                CHECK(AJ_MarshalCloseContainer(&txMsg, &dict));
            }
            if (status == AJ_OK) {
                CHECK(AJ_MarshalCloseContainer(&txMsg, &array1));
            }
            break;

        case 1:
            CHECK(AJ_MarshalArgs(&txMsg, "u", 11111));
            CHECK(AJ_MarshalContainer(&txMsg, &struct1, AJ_ARG_STRUCT));
            CHECK(AJ_MarshalArgs(&txMsg, "usu", 22222, "hello", 33333));
            CHECK(AJ_MarshalContainer(&txMsg, &struct2, AJ_ARG_STRUCT));
            CHECK(AJ_MarshalArgs(&txMsg, "ii", -100, -200));
            CHECK(AJ_MarshalCloseContainer(&txMsg, &struct2));
            CHECK(AJ_MarshalArgs(&txMsg, "qsq", 4444, "goodbye", 5555));
            CHECK(AJ_MarshalCloseContainer(&txMsg, &struct1));
            CHECK(AJ_MarshalArgs(&txMsg, "yyy", 1, 2, 3));
            break;

        case 2:
            CHECK(AJ_MarshalContainer(&txMsg, &array1, AJ_ARG_ARRAY));
            for (u = 0; u < ArraySize(Fruits); ++u) {
                CHECK(AJ_MarshalContainer(&txMsg, &struct1, AJ_ARG_STRUCT));
                CHECK(AJ_MarshalArgs(&txMsg, "us", u, Fruits[u]));
                CHECK(AJ_MarshalArg(&txMsg, AJ_InitArg(&arg, AJ_ARG_BYTE, AJ_ARRAY_FLAG, Data8, u)));
                CHECK(AJ_MarshalCloseContainer(&txMsg, &struct1));
            }
            if (status == AJ_OK) {
                CHECK(AJ_MarshalCloseContainer(&txMsg, &array1));
            }
            break;

        case 3:
            CHECK(AJ_MarshalContainer(&txMsg, &array1, AJ_ARG_ARRAY));
            for (j = 0; j < 3; ++j) {
                CHECK(AJ_MarshalContainer(&txMsg, &array2, AJ_ARG_ARRAY));
                for (k = j; k < ArraySize(Fruits); ++k) {
                    CHECK(AJ_MarshalArgs(&txMsg, "s", Fruits[k]));
                }
                CHECK(AJ_MarshalCloseContainer(&txMsg, &array2));
            }
            if (status == AJ_OK) {
                CHECK(AJ_MarshalCloseContainer(&txMsg, &array1));
            }
            break;

        case 4:
            CHECK(AJ_MarshalArgs(&txMsg, "i", 987654321));
            CHECK(AJ_MarshalVariant(&txMsg, "a(ii)"));
            CHECK(AJ_MarshalContainer(&txMsg, &array1, AJ_ARG_ARRAY));
            for (j = 0; j < 16; ++j) {
                CHECK(AJ_MarshalContainer(&txMsg, &struct1, AJ_ARG_STRUCT));
                CHECK(AJ_MarshalArgs(&txMsg, "ii", j + 1, (j + 1) * 100));
                CHECK(AJ_MarshalCloseContainer(&txMsg, &struct1));
            }
            if (status == AJ_OK) {
                CHECK(AJ_MarshalCloseContainer(&txMsg, &array1));
            }
            CHECK(AJ_MarshalArgs(&txMsg, "i", 123456789));
            break;

        case 5:
            CHECK(AJ_MarshalVariant(&txMsg, "(ivi)"));
            CHECK(AJ_MarshalContainer(&txMsg, &struct1, AJ_ARG_STRUCT));
            CHECK(AJ_MarshalArgs(&txMsg, "i", 1212121));
            CHECK(AJ_MarshalVariant(&txMsg, "s"));
            CHECK(AJ_MarshalArgs(&txMsg, "s", "inner variant"));
            CHECK(AJ_MarshalArgs(&txMsg, "i", 3434343));
            CHECK(AJ_MarshalCloseContainer(&txMsg, &struct1));
            break;

        case 6:
            CHECK(AJ_MarshalVariant(&txMsg, "v"));
            CHECK(AJ_MarshalVariant(&txMsg, "v"));
            CHECK(AJ_MarshalVariant(&txMsg, "v"));
            CHECK(AJ_MarshalVariant(&txMsg, "v"));
            CHECK(AJ_MarshalVariant(&txMsg, "s"));
            CHECK(AJ_MarshalArgs(&txMsg, "s", "deep variant"));
            break;

        case 7:
            CHECK(AJ_MarshalContainer(&txMsg, &struct1, AJ_ARG_STRUCT));
            CHECK(AJ_MarshalVariant(&txMsg, "i"));
            CHECK(AJ_MarshalArgs(&txMsg, "i", 1212121));
            CHECK(AJ_MarshalVariant(&txMsg, "s"));
            CHECK(AJ_MarshalArgs(&txMsg, "s", "variant"));
            CHECK(AJ_MarshalVariant(&txMsg, "ay"));
            CHECK(AJ_MarshalArg(&txMsg, AJ_InitArg(&arg, AJ_ARG_BYTE, AJ_ARRAY_FLAG, Data8, sizeof(Data8))));
            CHECK(AJ_MarshalVariant(&txMsg, "aq"));
            CHECK(AJ_MarshalArg(&txMsg, AJ_InitArg(&arg, AJ_ARG_UINT16, AJ_ARRAY_FLAG, Data16, sizeof(Data16))));
            CHECK(AJ_MarshalCloseContainer(&txMsg, &struct1));
            break;

        case 8:
            CHECK(AJ_MarshalArgs(&txMsg, "uq", 0xF00F00F0, 0x0707));
            len = 5000;
            CHECK(AJ_DeliverMsgPartial(&txMsg, len + 4));
            CHECK(AJ_MarshalRaw(&txMsg, &len, 4));
            for (j = 0; j < len; ++j) {
                uint8_t n = (uint8_t)j;
                CHECK(AJ_MarshalRaw(&txMsg, &n, 1));
            }
            break;

        case 9:
            len = 500;
            u = len * sizeof(TestStruct);
            CHECK(AJ_DeliverMsgPartial(&txMsg, u + sizeof(u) + 4));
            CHECK(AJ_MarshalRaw(&txMsg, &u, sizeof(u)));
            /*
             * Structs are always 8 byte aligned
             */
            u = 0;
            CHECK(AJ_MarshalRaw(&txMsg, &u, 4));
            for (j = 0; j < len; ++j) {
                TestStruct ts;
                ts.a = j;
                ts.b = j + 1;
                ts.c = j + 2;
                ts.d = j + 3;
                CHECK(AJ_MarshalRaw(&txMsg, &ts, sizeof(ts)));
            }
            break;

        case 10:
            CHECK(AJ_MarshalContainer(&txMsg, &array1, AJ_ARG_ARRAY));
            CHECK(AJ_MarshalCloseContainer(&txMsg, &array1));
            break;

        case 11:
            CHECK(AJ_MarshalArgs(&txMsg, "y", 127));
            CHECK(AJ_MarshalContainer(&txMsg, &array1, AJ_ARG_ARRAY));
            for (key = 0; key < ArraySize(Colors); ++key) {
                AJ_Arg dict;
                CHECK(AJ_MarshalContainer(&txMsg, &dict, AJ_ARG_DICT_ENTRY));
                CHECK(AJ_MarshalArgs(&txMsg, "ss", Colors[key], Fruits[key]));
                CHECK(AJ_MarshalCloseContainer(&txMsg, &dict));
            }
            if (status == AJ_OK) {
                CHECK(AJ_MarshalCloseContainer(&txMsg, &array1));
            }
            break;

        case 12:
            CHECK(AJ_MarshalArgs(&txMsg, "y", 0x11));
            CHECK(AJ_MarshalArgs(&txMsg, "y", 0x22));
            CHECK(AJ_MarshalArgs(&txMsg, "y", 0x33));
            CHECK(AJ_MarshalArgs(&txMsg, "y", 0x44));
            CHECK(AJ_MarshalArgs(&txMsg, "y", 0x55));
            CHECK(AJ_MarshalContainer(&txMsg, &array1, AJ_ARG_ARRAY));
            for (key = 0; key < ArraySize(Colors); ++key) {
                AJ_Arg dict;
                CHECK(AJ_MarshalContainer(&txMsg, &dict, AJ_ARG_DICT_ENTRY));
                CHECK(AJ_MarshalArgs(&txMsg, "ys", (uint8_t)key, Colors[key]));
                CHECK(AJ_MarshalCloseContainer(&txMsg, &dict));
            }
            if (status == AJ_OK) {
                CHECK(AJ_MarshalCloseContainer(&txMsg, &array1));
            }
            break;

        case 13:
            CHECK(AJ_MarshalContainer(&txMsg, &struct1, AJ_ARG_STRUCT));
            CHECK(AJ_MarshalArgs(&txMsg, "i", 3434343));
            CHECK(AJ_MarshalArg(&txMsg, AJ_InitArg(&arg, AJ_ARG_BYTE, AJ_ARRAY_FLAG, Data8, sizeof(Data8))));
            CHECK(AJ_MarshalCloseContainer(&txMsg, &struct1));
            break;
        }
        if (status != AJ_OK) {
            AJ_Printf("Failed %d\n", i);
            break;
        }

        AJ_Printf("deliver\n");
        AJ_DeliverMsg(&txMsg);

        status = AJ_UnmarshalMsg(&bus, &rxMsg, 0);
        if (status != AJ_OK) {
            break;
        }

        switch (i) {
        case 0:
            CHECK(AJ_UnmarshalContainer(&rxMsg, &array1, AJ_ARG_ARRAY));
            while (TRUE) {
                char* fruit;
                AJ_Arg dict;
                CHECK(AJ_UnmarshalContainer(&rxMsg, &dict, AJ_ARG_DICT_ENTRY));
                CHECK(AJ_UnmarshalArgs(&rxMsg, "us", &key, &fruit));
                AJ_Printf("Unmarshal[%d] = %s\n", key, fruit);
                CHECK(AJ_UnmarshalCloseContainer(&rxMsg, &dict));
            }
            /*
             * We expect AJ_ERR_NO_MORE
             */
            if (status == AJ_ERR_NO_MORE) {
                CHECK(AJ_UnmarshalCloseContainer(&rxMsg, &array1));
            }
            break;

        case 1:
            CHECK(AJ_UnmarshalArgs(&rxMsg, "u", &u));
            AJ_Printf("Unmarshal %u\n", u);
            CHECK(AJ_UnmarshalContainer(&rxMsg, &struct1, AJ_ARG_STRUCT));
            CHECK(AJ_UnmarshalArgs(&rxMsg, "usu", &u, &str, &v));
            AJ_Printf("Unmarshal %u %s %u\n", u, str, v);
            CHECK(AJ_UnmarshalContainer(&rxMsg, &struct2, AJ_ARG_STRUCT));
            CHECK(AJ_UnmarshalArgs(&rxMsg, "ii", &n, &m));
            AJ_Printf("Unmarshal %d %d\n", n, m);
            CHECK(AJ_UnmarshalCloseContainer(&rxMsg, &struct2));
            CHECK(AJ_UnmarshalArgs(&rxMsg, "qsq", &q, &str, &r));
            AJ_Printf("Unmarshal %u %s %u\n", q, str, r);
            CHECK(AJ_UnmarshalCloseContainer(&rxMsg, &struct1));
            CHECK(AJ_UnmarshalArgs(&rxMsg, "y", &y));
            AJ_Printf("Unmarshal %d\n", y);
            CHECK(AJ_UnmarshalArgs(&rxMsg, "y", &y));
            AJ_Printf("Unmarshal %d\n", y);
            CHECK(AJ_UnmarshalArgs(&rxMsg, "y", &y));
            AJ_Printf("Unmarshal %d\n", y);
            break;

        case 2:
            CHECK(AJ_UnmarshalContainer(&rxMsg, &array1, AJ_ARG_ARRAY));
            while (status == AJ_OK) {
                CHECK(AJ_UnmarshalContainer(&rxMsg, &struct1, AJ_ARG_STRUCT));
                CHECK(AJ_UnmarshalArgs(&rxMsg, "us", &u, &str));
                CHECK(AJ_UnmarshalArg(&rxMsg, &arg));
                CHECK(AJ_UnmarshalCloseContainer(&rxMsg, &struct1));
            }
            /*
             * We expect AJ_ERR_NO_MORE
             */
            if (status == AJ_ERR_NO_MORE) {
                CHECK(AJ_UnmarshalCloseContainer(&rxMsg, &array1));
            }
            break;

        case 3:
            CHECK(AJ_UnmarshalContainer(&rxMsg, &array1, AJ_ARG_ARRAY));
            while (status == AJ_OK) {
                CHECK(AJ_UnmarshalContainer(&rxMsg, &array2, AJ_ARG_ARRAY));
                while (status == AJ_OK) {
                    CHECK(AJ_UnmarshalArg(&rxMsg, &arg));
                    AJ_Printf("Unmarshal %s\n", arg.val.v_string);
                }
                /*
                 * We expect AJ_ERR_NO_MORE
                 */
                if (status == AJ_ERR_NO_MORE) {
                    CHECK(AJ_UnmarshalCloseContainer(&rxMsg, &array2));
                }
            }
            /*
             * We expect AJ_ERR_NO_MORE
             */
            if (status == AJ_ERR_NO_MORE) {
                CHECK(AJ_UnmarshalCloseContainer(&rxMsg, &array1));
            }
            break;

        case 4:
            CHECK(AJ_UnmarshalArgs(&rxMsg, "i", &j));
            AJ_Printf("Unmarshal %d\n", j);
            CHECK(AJ_UnmarshalVariant(&rxMsg, (const char**)&sig));
            AJ_Printf("Unmarshal variant %s\n", sig);
            CHECK(AJ_UnmarshalContainer(&rxMsg, &array1, AJ_ARG_ARRAY));
            while (status == AJ_OK) {
                CHECK(AJ_UnmarshalContainer(&rxMsg, &struct1, AJ_ARG_STRUCT));
                CHECK(AJ_UnmarshalArgs(&rxMsg, "ii", &j, &k));
                AJ_Printf("Unmarshal[%d] %d\n", j, k);
                CHECK(AJ_UnmarshalCloseContainer(&rxMsg, &struct1));
            }
            /*
             * We expect AJ_ERR_NO_MORE
             */
            if (status != AJ_ERR_NO_MORE) {
                break;
            }
            CHECK(AJ_UnmarshalCloseContainer(&rxMsg, &array1));
            CHECK(AJ_UnmarshalArgs(&rxMsg, "i", &j));
            AJ_Printf("Unmarshal %d\n", j);
            break;

        case 5:
            CHECK(AJ_UnmarshalVariant(&rxMsg, (const char**)&sig));
            AJ_Printf("Unmarshal variant %s\n", sig);
            CHECK(AJ_UnmarshalContainer(&rxMsg, &struct1, AJ_ARG_STRUCT));
            CHECK(AJ_UnmarshalArgs(&rxMsg, "i", &j));
            AJ_Printf("Unmarshal %d\n", j);
            CHECK(AJ_UnmarshalVariant(&rxMsg, (const char**)&sig));
            AJ_Printf("Unmarshal variant %s\n", sig);
            CHECK(AJ_UnmarshalArgs(&rxMsg, "s", &str));
            AJ_Printf("Unmarshal %s\n", str);
            CHECK(AJ_UnmarshalArgs(&rxMsg, "i", &j));
            AJ_Printf("Unmarshal %d\n", j);
            CHECK(AJ_UnmarshalCloseContainer(&rxMsg, &struct1));
            break;

        case 6:
            CHECK(AJ_UnmarshalVariant(&rxMsg, (const char**)&sig));
            AJ_Printf("Unmarshal variant %s\n", sig);
            CHECK(AJ_UnmarshalVariant(&rxMsg, (const char**)&sig));
            AJ_Printf("Unmarshal variant %s\n", sig);
            CHECK(AJ_UnmarshalVariant(&rxMsg, (const char**)&sig));
            AJ_Printf("Unmarshal variant %s\n", sig);
            CHECK(AJ_UnmarshalVariant(&rxMsg, (const char**)&sig));
            AJ_Printf("Unmarshal variant %s\n", sig);
            CHECK(AJ_UnmarshalVariant(&rxMsg, (const char**)&sig));
            AJ_Printf("Unmarshal variant %s\n", sig);
            CHECK(AJ_UnmarshalArgs(&rxMsg, "s", &str));
            AJ_Printf("Unmarshal %s\n", str);
            break;

        case 7:
            CHECK(AJ_UnmarshalContainer(&rxMsg, &struct1, AJ_ARG_STRUCT));
            CHECK(AJ_UnmarshalVariant(&rxMsg, (const char**)&sig));
            AJ_Printf("Unmarshal variant %s\n", sig);
            CHECK(AJ_UnmarshalArgs(&rxMsg, "i", &j));
            AJ_Printf("Unmarshal %d\n", j);
            CHECK(AJ_UnmarshalVariant(&rxMsg, (const char**)&sig));
            AJ_Printf("Unmarshal variant %s\n", sig);
            CHECK(AJ_UnmarshalArgs(&rxMsg, "s", &str));
            CHECK(AJ_UnmarshalVariant(&rxMsg, (const char**)&sig));
            AJ_Printf("Unmarshal variant %s\n", sig);
            CHECK(AJ_UnmarshalArg(&rxMsg, &arg));
            CHECK(AJ_UnmarshalVariant(&rxMsg, (const char**)&sig));
            AJ_Printf("Unmarshal variant %s\n", sig);
            CHECK(AJ_UnmarshalArg(&rxMsg, &arg));
            CHECK(AJ_UnmarshalCloseContainer(&rxMsg, &struct1));
            break;

        case 8:
            CHECK(AJ_UnmarshalArgs(&rxMsg, "uq", &j, &q));
            AJ_Printf("Unmarshal %x\n", j);
            AJ_Printf("Unmarshal %x\n", q);
            CHECK(AJ_UnmarshalRaw(&rxMsg, (const void**)&raw, sizeof(len), &sz));
            len = *((uint32_t*)raw);
            AJ_Printf("UnmarshalRaw %d\n", len);
            for (j = 0; j < len; ++j) {
                uint8_t v;
                CHECK(AJ_UnmarshalRaw(&rxMsg, (const void**)&raw, 1, &sz));
                v = *((uint8_t*)raw);
                if (v != (uint8_t)j) {
                    status = AJ_ERR_FAILURE;
                    break;
                }
            }
            break;

        case 9:
            CHECK(AJ_UnmarshalRaw(&rxMsg, (const void**)&raw, 4, &sz));
            len = *((uint32_t*)raw) / sizeof(TestStruct);
            /*
             * Structs are always 8 byte aligned
             */
            CHECK(AJ_UnmarshalRaw(&rxMsg, (const void**)&raw, 4, &sz));
            for (j = 0; j < len; ++j) {
                TestStruct* ts;
                CHECK(AJ_UnmarshalRaw(&rxMsg, (const void**)&ts, sizeof(TestStruct), &sz));
                if ((ts->a != j) || (ts->b != (j + 1)) || (ts->c != (j + 2)) || (ts->d != (j + 3))) {
                    status = AJ_ERR_FAILURE;
                    break;
                }
            }
            break;

        case 10:
            CHECK(AJ_UnmarshalContainer(&rxMsg, &array1, AJ_ARG_ARRAY));
            status = AJ_UnmarshalArg(&rxMsg, &arg);
            /*
             * We expect AJ_ERR_NO_MORE
             */
            if (status == AJ_ERR_NO_MORE) {
                CHECK(AJ_UnmarshalCloseContainer(&rxMsg, &array1));
            }
            break;

        case 11:
            CHECK(AJ_UnmarshalArgs(&rxMsg, "y", &y));
            CHECK(AJ_UnmarshalContainer(&rxMsg, &array1, AJ_ARG_ARRAY));
            while (TRUE) {
                AJ_Arg dict;
                char* fruit;
                char* color;
                CHECK(AJ_UnmarshalContainer(&rxMsg, &dict, AJ_ARG_DICT_ENTRY));
                CHECK(AJ_UnmarshalArgs(&rxMsg, "ss", &color, &fruit));
                AJ_Printf("Unmarshal[%s] = %s\n", color, fruit);
                CHECK(AJ_UnmarshalCloseContainer(&rxMsg, &dict));
            }
            /*
             * We expect AJ_ERR_NO_MORE
             */
            if (status == AJ_ERR_NO_MORE) {
                CHECK(AJ_UnmarshalCloseContainer(&rxMsg, &array1));
            }
            break;

        case 12:
            CHECK(AJ_UnmarshalArgs(&rxMsg, "y", &y));
            CHECK(AJ_UnmarshalArgs(&rxMsg, "y", &y));
            CHECK(AJ_UnmarshalArgs(&rxMsg, "y", &y));
            CHECK(AJ_UnmarshalArgs(&rxMsg, "y", &y));
            CHECK(AJ_UnmarshalArgs(&rxMsg, "y", &y));
            CHECK(AJ_UnmarshalContainer(&rxMsg, &array1, AJ_ARG_ARRAY));
            while (TRUE) {
                AJ_Arg dict;
                char* color;
                CHECK(AJ_UnmarshalContainer(&rxMsg, &dict, AJ_ARG_DICT_ENTRY));
                CHECK(AJ_UnmarshalArgs(&rxMsg, "ys", &y, &color));
                AJ_Printf("Unmarshal[%d] = %s\n", y, color);
                CHECK(AJ_UnmarshalCloseContainer(&rxMsg, &dict));
            }
            /*
             * We expect AJ_ERR_NO_MORE
             */
            if (status == AJ_ERR_NO_MORE) {
                CHECK(AJ_UnmarshalCloseContainer(&rxMsg, &array1));
            }
            break;

        case 13:
            CHECK(AJ_UnmarshalContainer(&rxMsg, &struct1, AJ_ARG_STRUCT));
            CHECK(AJ_UnmarshalArgs(&rxMsg, "i", &n));
            AJ_ASSERT(n == 3434343);

            CHECK(AJ_UnmarshalArg(&rxMsg, &arg));
            for (j = 0; j < arg.len; ++j) {
                uint8_t val = arg.val.v_byte[j];
                AJ_Printf("Unmarhsalled array1[%u] = %u\n", j, val);
                AJ_ASSERT(val == Data8[j]);
            }

            CHECK(AJ_UnmarshalCloseContainer(&rxMsg, &struct1));
            break;
        }

        if (status != AJ_OK) {
            AJ_Printf("Failed %d\n", i);
            break;
        }
        AJ_CloseMsg(&rxMsg);
        AJ_Printf("Passed %d\n", i);

    }
    if (status != AJ_OK) {
        AJ_Printf("Marshal/Unmarshal unit test[%d] failed %d\n", i, status);
    }

    return status;
}
コード例 #9
0
ファイル: cfuncs.c プロジェクト: Gowthambalu/IoT-framework
AJ_Status AJ_MarshalSignal_cgo(AJ_Message* msg, uint32_t msgId, uint32_t sessionId, uint8_t flags, uint32_t ttl) {
	return AJ_MarshalSignal(&c_bus, msg, msgId, NULL, (AJ_SessionId) sessionId, flags, ttl);
}