static AJ_Status PropAccess(AJ_Message* msg, PropCallback* cb, uint8_t op) { AJ_Status status; AJ_Message reply; uint32_t propId; const char* sig; AJ_InfoPrintf(("PropAccess(msg=0x%p, cb=0x%p, op=%s)\n", msg, cb, (op == AJ_PROP_GET) ? "get" : "set")); /* * Find out which property is being accessed and whether the access is a GET or SET */ status = AJ_UnmarshalPropertyArgs(msg, &propId, &sig); if (status == AJ_OK) { AJ_MarshalReplyMsg(msg, &reply); /* * Callback to let the application marshal or unmarshal the value */ if (op == AJ_PROP_GET) { AJ_MarshalVariant(&reply, sig); status = cb->Get(&reply, propId, cb->context); } else { const char* variant; AJ_UnmarshalVariant(msg, &variant); /* * Check that the value has the expected signature */ if (strcmp(sig, variant) == 0) { status = cb->Set(msg, propId, cb->context); } else { AJ_InfoPrintf(("PropAccess(): AJ_ERR_SIGNATURE\n")); status = AJ_ERR_SIGNATURE; } } } if (status != AJ_OK) { AJ_MarshalStatusMsg(msg, &reply, status); } return AJ_DeliverMsg(&reply); }
static AJ_Status SetWidgetProp(AJ_Message* msg) { AJS_Widget* widget = NULL; AJ_Message reply; AJ_Status status; uint32_t propId; const char* vsig; AJ_InfoPrintf(("SetWidgetProp %s\n", msg->objPath)); status = AJ_UnmarshalPropertyArgs(msg, &propId, &vsig); /* * Two levels of variant because Set always uses a variant and the property type for the widget * is not known until runtime so is specified as a variant type in the property widget interface. */ if (status == AJ_OK) { status = AJ_UnmarshalVariant(msg, &vsig); } if (status == AJ_OK) { status = AJ_UnmarshalVariant(msg, &vsig); } if (status == AJ_OK) { widget = (AJS_Widget*)objectList[OBJ_INDEX(propId)].context; /* * Value is the only property that is writeable. Figure out how to unmarshal it. */ switch (widget->property.wdt.signature[0]) { case 'i': status = AJ_UnmarshalArgs(msg, "i", &widget->property.val.i); break; case 'q': status = AJ_UnmarshalArgs(msg, "q", &widget->property.val.q); break; case 'b': status = AJ_UnmarshalArgs(msg, "b", &widget->property.val.b); break; case 'd': status = AJ_UnmarshalArgs(msg, "d", &widget->property.val.d); break; case 's': status = AJ_UnmarshalArgs(msg, "s", &widget->property.val.s); break; default: { AJ_Arg st; uint16_t propertyType; status = AJ_UnmarshalContainer(msg, &st, AJ_ARG_STRUCT); if (status != AJ_OK) { break; } status = AJ_UnmarshalArgs(msg, "q", &propertyType); if (status != AJ_OK) { break; } /* * For some reason the implementors of the control panel service used 0/1 to * distingsuish between date/time rather than 1/2. Incrementing the property type * fixes this oversight. */ if (++propertyType != widget->property.wdt.propertyType) { status = AJ_ERR_INVALID; break; } if (propertyType == TIME_VALUE_PROPERTY) { status = AJ_UnmarshalArgs(msg, "(qqq)", &widget->property.val.time.hour, &widget->property.val.time.minute, &widget->property.val.time.second); } else { status = AJ_UnmarshalArgs(msg, "(qqq)", &widget->property.val.date.mDay, &widget->property.val.date.month, &widget->property.val.date.fullYear); } /* * Signal that the value has been changed */ AJS_CPS_SignalValueChanged(AJS_GetBusAttachment(), widget); if (status == AJ_OK) { status = AJ_UnmarshalCloseContainer(msg, &st); } } break; } } else { return AJ_ERR_RESOURCES; } /* * Need to make a clone of the message and close the original */ msg = AJS_CloneAndCloseMessage(widget->dukCtx, msg); if (!msg) { return AJ_ERR_RESOURCES; } if (status == AJ_OK) { /* * Call JavaScript to report the value change */ status = AJS_CPS_OnValueChanged(widget); } else { AJ_ErrPrintf(("SetWidgetProp %s\n", AJ_StatusText(status))); } if (status == AJ_OK) { AJ_MarshalReplyMsg(msg, &reply); } else { AJ_MarshalStatusMsg(msg, &reply, status); } AJ_DeliverMsg(&reply); return status; }
AJ_Status AJCFG_UpdateConfigurationsHandler(AJ_Message* msg) { AJ_Status status = AJ_OK; AJ_Arg array; AJ_Arg dict; AJ_Message reply; char* key; char* sig; char* value; char* language; int8_t langIndex = AJSVC_PROPERTY_STORE_ERROR_LANGUAGE_INDEX; uint8_t numOfUpdatedItems = 0; uint8_t errorReply = FALSE; AJ_InfoPrintf(("Handling UpdateConfigurations request\n")); status = AJ_UnmarshalArgs(msg, "s", &language); if (status != AJ_OK) { goto Exit; } AJ_InfoPrintf(("Lang=%s\n", language)); errorReply = !AJSVC_IsLanguageSupported(msg, &reply, language, &langIndex); if (!errorReply) { status = AJ_UnmarshalContainer(msg, &array, AJ_ARG_ARRAY); if (status != AJ_OK) { goto Exit; } while (1) { status = AJ_UnmarshalContainer(msg, &dict, AJ_ARG_DICT_ENTRY); if (status != AJ_OK) { break; } status = AJ_UnmarshalArgs(msg, "s", &key); if (status != AJ_OK) { break; } status = AJ_UnmarshalVariant(msg, (const char**)&sig); if (status != AJ_OK) { break; } status = AJ_UnmarshalArgs(msg, sig, &value); if (status != AJ_OK) { break; } AJ_InfoPrintf(("key=%s value=%s\n", key, value)); if (IsValueValid(msg, &reply, key, value)) { status = AJSVC_PropertyStore_Update(key, langIndex, value); if (status == AJ_OK) { numOfUpdatedItems++; } else if (status == AJ_ERR_INVALID) { if (!errorReply) { AJ_MarshalErrorMsg(msg, &reply, AJSVC_ERROR_INVALID_VALUE); errorReply = TRUE; } } else if (status == AJ_ERR_FAILURE) { if (!errorReply) { AJ_MarshalErrorMsg(msg, &reply, AJSVC_ERROR_UPDATE_NOT_ALLOWED); errorReply = TRUE; } } } else { errorReply = TRUE; } status = AJ_UnmarshalCloseContainer(msg, &dict); if (status != AJ_OK) { break; } } if (status != AJ_OK && status != AJ_ERR_NO_MORE) { goto Exit; } status = AJ_UnmarshalCloseContainer(msg, &array); if (status != AJ_OK) { goto Exit; } } if (!errorReply) { status = AJ_MarshalReplyMsg(msg, &reply); if (status != AJ_OK) { goto Exit; } } status = AJ_DeliverMsg(&reply); if (status != AJ_OK) { goto Exit; } Exit: if (numOfUpdatedItems) { if (errorReply) { AJSVC_PropertyStore_LoadAll(); // Discard partial successful updates } else { AJSVC_PropertyStore_SaveAll(); AJ_AboutSetShouldAnnounce(); } } return status; }
int AJ_Main() #endif { AJ_Status status = AJ_OK; AJ_BusAttachment bus; uint8_t connected = FALSE; uint32_t sessionId = 0; AJ_Status authStatus = AJ_ERR_NULL; #ifdef SECURE_INTERFACE uint32_t suites[AJ_AUTH_SUITES_NUM]; size_t numsuites = 0; uint8_t clearkeys = FALSE; #endif #ifdef MAIN_ALLOWS_ARGS #if defined(SECURE_INTERFACE) || defined(SECURE_OBJECT) ac--; av++; /* * Enable authentication mechanism by command line */ if (ac) { if (0 == strncmp(*av, "-ek", 3)) { clearkeys = TRUE; ac--; av++; } else if (0 == strncmp(*av, "-e", 2)) { ac--; av++; } if (!ac) { AJ_AlwaysPrintf(("-e(k) requires an auth mechanism.\n")); return 1; } while (ac) { if (0 == strncmp(*av, "ECDHE_ECDSA", 11)) { suites[numsuites++] = AUTH_SUITE_ECDHE_ECDSA; } else if (0 == strncmp(*av, "ECDHE_PSK", 9)) { suites[numsuites++] = AUTH_SUITE_ECDHE_PSK; } else if (0 == strncmp(*av, "ECDHE_NULL", 10)) { suites[numsuites++] = AUTH_SUITE_ECDHE_NULL; } ac--; av++; } } #endif #else suites[numsuites++] = AUTH_SUITE_ECDHE_ECDSA; clearkeys = TRUE; #endif #ifdef SECURE_INTERFACE if (numsuites == 0) { /* Default security to ECDHE_NULL, if not explicit elsewhere */ suites[numsuites++] = AUTH_SUITE_ECDHE_NULL; } #endif /* * One time initialization before calling any other AllJoyn APIs */ AJ_Initialize(); AJ_PrintXML(ProxyObjects); AJ_RegisterObjects(NULL, ProxyObjects); while (TRUE) { AJ_Message msg; if (!connected) { #if defined (ANNOUNCE_BASED_DISCOVERY) status = AJ_StartClientByPeerDescription(&bus, NULL, CONNECT_TIMEOUT, FALSE, &pingServicePeer, testServicePort, &sessionId, g_peerServiceName, NULL); #elif defined (NGNS) status = AJ_StartClientByInterface(&bus, NULL, CONNECT_TIMEOUT, FALSE, testInterfaceNames, &sessionId, g_peerServiceName, NULL); #else status = AJ_StartClientByName(&bus, NULL, CONNECT_TIMEOUT, FALSE, testServiceName, testServicePort, &sessionId, NULL, g_peerServiceName); #endif if (status == AJ_OK) { AJ_AlwaysPrintf(("StartClient returned %d, sessionId=%u, serviceName=%s\n", status, sessionId, g_peerServiceName)); AJ_AlwaysPrintf(("Connected to Daemon:%s\n", AJ_GetUniqueName(&bus))); connected = TRUE; #if defined(SECURE_INTERFACE) || defined(SECURE_OBJECT) AJ_BusEnableSecurity(&bus, suites, numsuites); AJ_BusSetAuthListenerCallback(&bus, AuthListenerCallback); if (clearkeys) { AJ_ClearCredentials(AJ_GENERIC_MASTER_SECRET | AJ_CRED_TYPE_GENERIC); AJ_ClearCredentials(AJ_GENERIC_ECDSA_MANIFEST | AJ_CRED_TYPE_GENERIC); AJ_ClearCredentials(AJ_GENERIC_ECDSA_KEYS | AJ_CRED_TYPE_GENERIC); } status = AJ_BusAuthenticatePeer(&bus, g_peerServiceName, AuthCallback, &authStatus); if (status != AJ_OK) { AJ_AlwaysPrintf(("AJ_BusAuthenticatePeer returned %d\n", status)); } #else authStatus = AJ_OK; #endif } else { AJ_AlwaysPrintf(("StartClient returned %d\n", status)); break; } } AJ_AlwaysPrintf(("Auth status %d and AllJoyn status %d\n", authStatus, status)); if (status == AJ_ERR_RESOURCES) { AJ_InfoPrintf(("Peer is busy, disconnecting and retrying auth...\n")); AJ_Disconnect(&bus); connected = FALSE; continue; } if (authStatus != AJ_ERR_NULL) { if (authStatus != AJ_OK) { AJ_Disconnect(&bus); break; } authStatus = AJ_ERR_NULL; AJ_BusSetLinkTimeout(&bus, sessionId, 10 * 1000); } status = AJ_UnmarshalMsg(&bus, &msg, UNMARSHAL_TIMEOUT); if (status != AJ_OK) { if (status == AJ_ERR_TIMEOUT) { AppDoWork(&bus, sessionId, g_peerServiceName); continue; } } else { switch (msg.msgId) { case AJ_REPLY_ID(AJ_METHOD_SET_LINK_TIMEOUT): { uint32_t disposition; uint32_t timeout; status = AJ_UnmarshalArgs(&msg, "uu", &disposition, &timeout); if (disposition == AJ_SETLINKTIMEOUT_SUCCESS) { AJ_AlwaysPrintf(("Link timeout set to %d\n", timeout)); } else { AJ_AlwaysPrintf(("SetLinkTimeout failed %d\n", disposition)); } SendPing(&bus, sessionId, g_peerServiceName, 1); } break; case AJ_REPLY_ID(AJ_METHOD_BUS_PING): { uint32_t disposition; status = AJ_UnmarshalArgs(&msg, "u", &disposition); if (disposition == AJ_PING_SUCCESS) { AJ_AlwaysPrintf(("Bus Ping reply received\n")); } else { AJ_AlwaysPrintf(("Bus Ping failed, disconnecting: %d\n", disposition)); status = AJ_ERR_LINK_DEAD; } } break; case AJ_REPLY_ID(PRX_MY_PING): { AJ_Arg arg; AJ_UnmarshalArg(&msg, &arg); AJ_AlwaysPrintf(("Got ping reply\n")); AJ_InfoPrintf(("INFO Got ping reply\n")); status = SendGetProp(&bus, sessionId, g_peerServiceName); } break; case AJ_REPLY_ID(PRX_GET_PROP): { const char* sig; status = AJ_UnmarshalVariant(&msg, &sig); if (status == AJ_OK) { status = AJ_UnmarshalArgs(&msg, sig, &g_iterCount); AJ_AlwaysPrintf(("Get prop reply %d\n", g_iterCount)); if (status == AJ_OK) { g_iterCount = g_iterCount + 1; status = SendSetProp(&bus, sessionId, g_peerServiceName, g_iterCount); } } } break; case AJ_REPLY_ID(PRX_SET_PROP): AJ_AlwaysPrintf(("Set prop reply\n")); break; case AJ_SIGNAL_SESSION_LOST_WITH_REASON: /* * Force a disconnect */ { uint32_t id, reason; AJ_UnmarshalArgs(&msg, "uu", &id, &reason); AJ_AlwaysPrintf(("Session lost. ID = %u, reason = %u\n", id, reason)); } status = AJ_ERR_SESSION_LOST; break; default: /* * Pass to the built-in handlers */ status = AJ_BusHandleBusMessage(&msg); break; } } /* * Messages must be closed to free resources */ AJ_CloseMsg(&msg); if ((status == AJ_ERR_SESSION_LOST) || (status == AJ_ERR_READ) || (status == AJ_ERR_WRITE) || (status == AJ_ERR_LINK_DEAD)) { AJ_AlwaysPrintf(("AllJoyn disconnect\n")); AJ_AlwaysPrintf(("Disconnected from Daemon:%s\n", AJ_GetUniqueName(&bus))); AJ_Disconnect(&bus); break; } } AJ_AlwaysPrintf(("clientlite EXIT %d\n", status)); return status; }
AJ_Status AJNS_Consumer_NotifySignalHandler(AJ_Message* msg) { AJ_Status status; AJNS_Notification notification; AJNS_NotificationContent content; char appId[UUID_LENGTH * 2 + 1]; AJ_Arg attrbtArray; AJ_Arg customAttributeArray; AJ_Arg notTextArray; AJ_Arg richAudioArray; memset(¬ification, 0, sizeof(AJNS_Notification)); memset(&content, 0, sizeof(AJNS_NotificationContent)); notification.content = &content; AJ_InfoPrintf(("Received notification signal from sender %s\n", msg->sender)); status = AJ_UnmarshalArgs(msg, "q", ¬ification.version); if (status != AJ_OK) { goto Exit; } status = AJ_UnmarshalArgs(msg, "i", ¬ification.notificationId); if (status != AJ_OK) { goto Exit; } status = AJ_UnmarshalArgs(msg, "q", ¬ification.messageType); if (status != AJ_OK) { goto Exit; } status = AJ_UnmarshalArgs(msg, "s", ¬ification.deviceId); if (status != AJ_OK) { goto Exit; } status = AJ_UnmarshalArgs(msg, "s", ¬ification.deviceName); if (status != AJ_OK) { goto Exit; } status = AJSVC_UnmarshalAppId(msg, appId, sizeof(appId)); if (status != AJ_OK) { goto Exit; } notification.appId = appId; status = AJ_UnmarshalArgs(msg, "s", ¬ification.appName); if (status != AJ_OK) { goto Exit; } status = AJ_UnmarshalContainer(msg, &attrbtArray, AJ_ARG_ARRAY); if (status != AJ_OK) { goto Exit; } while (1) { AJ_Arg dictArg; int32_t attrbtKey; const char* variantSig; status = AJ_UnmarshalContainer(msg, &dictArg, AJ_ARG_DICT_ENTRY); if (status == AJ_ERR_NO_MORE) { status = AJ_UnmarshalCloseContainer(msg, &attrbtArray); if (status != AJ_OK) { goto Exit; } else { break; } } else if (status == AJ_OK) { goto Exit; } status = AJ_UnmarshalArgs(msg, "i", &attrbtKey); if (status != AJ_OK) { goto Exit; } switch (attrbtKey) { case AJNS_RICH_CONTENT_ICON_URL_ATTRIBUTE_KEY: { status = AJ_UnmarshalVariant(msg, &variantSig); if (status != AJ_OK) { goto Exit; } status = AJ_UnmarshalArgs(msg, "s", &(notification.content->richIconUrl)); if (status != AJ_OK) { goto Exit; } } break; case AJNS_RICH_CONTENT_ICON_OBJECT_PATH_ATTRIBUTE_KEY: { status = AJ_UnmarshalVariant(msg, &variantSig); if (status != AJ_OK) { goto Exit; } status = AJ_UnmarshalArgs(msg, "s", &(notification.content->richIconObjectPath)); if (status != AJ_OK) { goto Exit; } } break; case AJNS_RICH_CONTENT_AUDIO_OBJECT_PATH_ATTRIBUTE_KEY: { status = AJ_UnmarshalVariant(msg, &variantSig); if (status != AJ_OK) { goto Exit; } status = AJ_UnmarshalArgs(msg, "s", &(notification.content->richAudioObjectPath)); if (status != AJ_OK) { goto Exit; } } break; case AJNS_CONTROLPANELSERVICE_OBJECT_PATH_ATTRIBUTE_KEY: { status = AJ_UnmarshalVariant(msg, &variantSig); if (status != AJ_OK) { goto Exit; } status = AJ_UnmarshalArgs(msg, "s", &(notification.content->controlPanelServiceObjectPath)); if (status != AJ_OK) { goto Exit; } } break; case AJNS_ORIGINAL_SENDER_NAME_ATTRIBUTE_KEY: { status = AJ_UnmarshalVariant(msg, &variantSig); if (status != AJ_OK) { goto Exit; } status = AJ_UnmarshalArgs(msg, "s", ¬ification.originalSenderName); if (status != AJ_OK) { goto Exit; } } break; case AJNS_RICH_CONTENT_AUDIO_URL_ATTRIBUTE_KEY: { status = AJ_UnmarshalVariant(msg, &variantSig); if (status != AJ_OK) { goto Exit; } status = AJ_UnmarshalContainer(msg, &richAudioArray, AJ_ARG_ARRAY); if (status != AJ_OK) { goto Exit; } while (1) { AJ_Arg structArg; char* urlLanguage; char* urlText; status = AJ_UnmarshalContainer(msg, &structArg, AJ_ARG_STRUCT); if (status == AJ_ERR_NO_MORE) { status = AJ_UnmarshalCloseContainer(msg, &richAudioArray); if (status != AJ_OK) { goto Exit; } else { break; } } else if (status == AJ_OK) { goto Exit; } status = AJ_UnmarshalArgs(msg, "ss", &urlLanguage, &urlText); if (status != AJ_OK) { goto Exit; } if (notification.content->numAudioUrls < NUMALLOWEDRICHNOTS) { // if it doesn't fit we just skip richAudiosRecd[notification.content->numAudioUrls].key = urlLanguage; richAudiosRecd[notification.content->numAudioUrls].value = urlText; notification.content->numAudioUrls++; } status = AJ_UnmarshalCloseContainer(msg, &structArg); if (status != AJ_OK) { goto Exit; } } notification.content->richAudioUrls = richAudiosRecd; } break; default: AJ_InfoPrintf(("Unknown argument - skipping\n")); status = AJ_SkipArg(msg); if (status != AJ_OK) { AJ_ErrPrintf(("Error could not skip argument\n")); return status; } } status = AJ_UnmarshalCloseContainer(msg, &dictArg); if (status != AJ_OK) { goto Exit; } } status = AJ_UnmarshalContainer(msg, &customAttributeArray, AJ_ARG_ARRAY); if (status != AJ_OK) { goto Exit; } while (1) { AJ_Arg customAttributeDictArg; char* customKey; char* customVal; status = AJ_UnmarshalContainer(msg, &customAttributeDictArg, AJ_ARG_DICT_ENTRY); if (status == AJ_ERR_NO_MORE) { status = AJ_UnmarshalCloseContainer(msg, &customAttributeArray); if (status != AJ_OK) { goto Exit; } else { break; } } else if (status == AJ_OK) { goto Exit; } status = AJ_UnmarshalArgs(msg, "ss", &customKey, &customVal); if (status != AJ_OK) { goto Exit; } if (notification.content->numCustomAttributes < NUMALLOWEDCUSTOMATTRIBUTES) { // if it doesn't fit we just skip customAttributesRecd[notification.content->numCustomAttributes].key = customKey; customAttributesRecd[notification.content->numCustomAttributes].value = customVal; notification.content->numCustomAttributes++; } status = AJ_UnmarshalCloseContainer(msg, &customAttributeDictArg); if (status != AJ_OK) { goto Exit; } } notification.content->customAttributes = customAttributesRecd; status = AJ_UnmarshalContainer(msg, ¬TextArray, AJ_ARG_ARRAY); if (status != AJ_OK) { goto Exit; } while (1) { AJ_Arg structArg; char* notificationLanguage; char* notificationText; status = AJ_UnmarshalContainer(msg, &structArg, AJ_ARG_STRUCT); if (status == AJ_ERR_NO_MORE) { status = AJ_UnmarshalCloseContainer(msg, ¬TextArray); if (status != AJ_OK) { goto Exit; } else { break; } } else if (status == AJ_OK) { goto Exit; } status = AJ_UnmarshalArgs(msg, "ss", ¬ificationLanguage, ¬ificationText); if (status != AJ_OK) { goto Exit; } if (notification.content->numTexts < NUMALLOWEDTEXTS) { // if it doesn't fit we just skip textsRecd[notification.content->numTexts].key = notificationLanguage; textsRecd[notification.content->numTexts].value = notificationText; notification.content->numTexts++; } status = AJ_UnmarshalCloseContainer(msg, &structArg); if (status != AJ_OK) { goto Exit; } } notification.content->texts = textsRecd; Exit: if (status != AJ_OK) { AJ_ErrPrintf(("Handle Notification failed: '%s'\n", AJ_StatusText(status))); } else { if (appOnNotify) { status = (*appOnNotify)(¬ification); } } AJ_CloseMsg(msg); return status; }
int AJ_Main(void) { AJ_Status status = AJ_OK; AJ_BusAttachment bus; uint8_t connected = FALSE; uint32_t sessionId = 0; AJ_Status authStatus = AJ_ERR_NULL; /* * One time initialization before calling any other AllJoyn APIs */ AJ_Initialize(); AJ_PrintXML(ProxyObjects); AJ_RegisterObjects(NULL, ProxyObjects); while (TRUE) { AJ_Message msg; if (!connected) { status = AJ_StartClient(&bus, NULL, CONNECT_TIMEOUT, FALSE, ServiceName, ServicePort, &sessionId, NULL); if (status == AJ_OK) { AJ_Printf("StartClient returned %d, sessionId=%u\n", status, sessionId); AJ_Printf("Connected to Daemon:%s\n", AJ_GetUniqueName(&bus)); connected = TRUE; #ifdef SECURE_INTERFACE AJ_BusSetPasswordCallback(&bus, PasswordCallback); status = AJ_BusAuthenticatePeer(&bus, ServiceName, AuthCallback, &authStatus); if (status != AJ_OK) { AJ_Printf("AJ_BusAuthenticatePeer returned %d\n", status); } #else authStatus = AJ_OK; #endif } else { AJ_Printf("StartClient returned %d\n", status); break; } } if (authStatus != AJ_ERR_NULL) { if (authStatus != AJ_OK) { AJ_Disconnect(&bus); break; } authStatus = AJ_ERR_NULL; AJ_BusSetLinkTimeout(&bus, sessionId, 10 * 1000); } status = AJ_UnmarshalMsg(&bus, &msg, UNMARSHAL_TIMEOUT); if (status != AJ_OK) { if (status == AJ_ERR_TIMEOUT) { AppDoWork(&bus, sessionId); continue; } } else { switch (msg.msgId) { case AJ_REPLY_ID(AJ_METHOD_SET_LINK_TIMEOUT): { uint32_t disposition; uint32_t timeout; status = AJ_UnmarshalArgs(&msg, "uu", &disposition, &timeout); if (disposition == AJ_SETLINKTIMEOUT_SUCCESS) { AJ_Printf("Link timeout set to %d\n", timeout); } else { AJ_Printf("SetLinkTimeout failed %d\n", disposition); } SendPing(&bus, sessionId, 1); } break; case AJ_REPLY_ID(PRX_MY_PING): { AJ_Arg arg; AJ_UnmarshalArg(&msg, &arg); status = SendGetProp(&bus, sessionId); } break; case AJ_REPLY_ID(PRX_GET_PROP): { const char* sig; status = AJ_UnmarshalVariant(&msg, &sig); if (status == AJ_OK) { status = AJ_UnmarshalArgs(&msg, sig, &g_iterCount); AJ_Printf("Get prop reply %d\n", g_iterCount); if (status == AJ_OK) { g_iterCount = g_iterCount + 1; status = SendSetProp(&bus, sessionId, g_iterCount); } } } break; case AJ_REPLY_ID(PRX_SET_PROP): AJ_Printf("Set prop reply\n"); break; case AJ_SIGNAL_SESSION_LOST_WITH_REASON: /* * Force a disconnect */ { uint32_t id, reason; AJ_UnmarshalArgs(&msg, "uu", &id, &reason); AJ_Printf("Session lost. ID = %u, reason = %u", id, reason); } status = AJ_ERR_SESSION_LOST; break; default: /* * Pass to the built-in handlers */ status = AJ_BusHandleBusMessage(&msg); break; } } /* * Messages must be closed to free resources */ AJ_CloseMsg(&msg); if ((status == AJ_ERR_SESSION_LOST) || (status == AJ_ERR_READ) || (status == AJ_ERR_LINK_DEAD)) { AJ_Printf("AllJoyn disconnect\n"); AJ_Printf("Disconnected from Daemon:%s\n", AJ_GetUniqueName(&bus)); AJ_Disconnect(&bus); return status; } } AJ_Printf("clientlite EXIT %d\n", status); return status; }
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; }
LampResponseCode LAMP_UnmarshalState(LampStateContainer* state, AJ_Message* msg) { AJ_Arg array1, struct1; AJ_Status status = AJ_UnmarshalContainer(msg, &array1, AJ_ARG_ARRAY); LampResponseCode responseCode = LAMP_OK; AJ_DumpMsg("LAMP_UnmarshalState", msg, TRUE); // initialize memset(state, 0, sizeof(LampStateContainer)); do { char* field; char* sig; status = AJ_UnmarshalContainer(msg, &struct1, AJ_ARG_DICT_ENTRY); if (status != AJ_OK) { break; } status = AJ_UnmarshalArgs(msg, "s", &field); if (status != AJ_OK) { printf("AJ_UnmarshalArgs: %s\n", AJ_StatusText(status)); return LAMP_ERR_MESSAGE; } // Process the field! status = AJ_UnmarshalVariant(msg, (const char**) &sig); if (status != AJ_OK) { AJ_ErrPrintf(("AJ_UnmarshalVariant: %s\n", AJ_StatusText(status))); return LAMP_ERR_MESSAGE; } if (0 == strcmp(field, "OnOff")) { uint32_t onoff; status = AJ_UnmarshalArgs(msg, "b", &onoff); state->state.onOff = onoff ? TRUE : FALSE; state->stateFieldIndicators |= LAMP_STATE_ON_OFF_FIELD_INDICATOR; } else if (0 == strcmp(field, "Hue")) { status = AJ_UnmarshalArgs(msg, "u", &state->state.hue); state->stateFieldIndicators |= LAMP_STATE_HUE_FIELD_INDICATOR; } else if (0 == strcmp(field, "Saturation")) { status = AJ_UnmarshalArgs(msg, "u", &state->state.saturation); state->stateFieldIndicators |= LAMP_STATE_SATURATION_FIELD_INDICATOR; } else if (0 == strcmp(field, "ColorTemp")) { status = AJ_UnmarshalArgs(msg, "u", &state->state.colorTemp); state->stateFieldIndicators |= LAMP_STATE_COLOR_TEMP_FIELD_INDICATOR; } else if (0 == strcmp(field, "Brightness")) { status = AJ_UnmarshalArgs(msg, "u", &state->state.brightness); state->stateFieldIndicators |= LAMP_STATE_BRIGHTNESS_FIELD_INDICATOR; } else { AJ_ErrPrintf(("Unknown field: %s\n", field)); responseCode = LAMP_ERR_MESSAGE; AJ_SkipArg(msg); } status = AJ_UnmarshalCloseContainer(msg, &struct1); // if field invalid, throw the whole thing out and return the error } while (status == AJ_OK && responseCode == LAMP_OK); AJ_UnmarshalCloseContainer(msg, &array1); return responseCode; }