uint8_t AJNS_Consumer_IsSuperAgentLost(AJ_Message* msg) { if (msg->msgId == AJ_SIGNAL_LOST_ADV_NAME) { AJ_Arg arg; AJ_UnmarshalArg(msg, &arg); // <arg name="name" type="s" direction="out"/> AJ_SkipArg(msg); // <arg name="transport" type="q" direction="out"/> AJ_SkipArg(msg); // <arg name="prefix" type="s" direction="out"/> AJ_ResetArgs(msg); // Reset to allow others to re-unmarshal message AJ_InfoPrintf(("LostAdvertisedName(%s)\n", arg.val.v_string)); return (strcmp(arg.val.v_string, currentSuperAgentBusName) == 0); } return FALSE; }
AJ_Status AJ_ARDP_UDP_Connect(AJ_BusAttachment* bus, void* context, const AJ_Service* service, AJ_NetSocket* netSock) { AJ_Message hello; AJ_GUID localGuid; char guid_buf[33]; AJ_Status status; AJ_Message helloResponse; AJ_GetLocalGUID(&localGuid); AJ_GUID_ToString(&localGuid, guid_buf, sizeof(guid_buf)); AJ_MarshalMethodCall(bus, &hello, AJ_METHOD_BUS_SIMPLE_HELLO, AJ_BusDestination, 0, AJ_FLAG_ALLOW_REMOTE_MSG, AJ_UDP_CONNECT_TIMEOUT); AJ_MarshalArgs(&hello, "su", guid_buf, 10); hello.hdr->bodyLen = hello.bodyBytes; status = AJ_ARDP_Connect(bus->sock.tx.readPtr, AJ_IO_BUF_AVAIL(&bus->sock.tx), context, netSock); if (status != AJ_OK) { return status; } status = AJ_UnmarshalMsg(bus, &helloResponse, AJ_UDP_CONNECT_TIMEOUT); if (status == AJ_OK && helloResponse.msgId == AJ_REPLY_ID(AJ_METHOD_BUS_SIMPLE_HELLO)) { if (helloResponse.hdr->msgType == AJ_MSG_ERROR) { status = AJ_ERR_CONNECT; } else { AJ_Arg uniqueName, protoVersion; AJ_UnmarshalArg(&helloResponse, &uniqueName); AJ_SkipArg(&helloResponse); AJ_UnmarshalArg(&helloResponse, &protoVersion); /** * The two most-significant bits are reserved for the nameType, * which we don't currently care about in the thin client */ routingProtoVersion = (uint8_t) ((*protoVersion.val.v_uint32) & 0x3FFFFFFF); if (uniqueName.len >= (sizeof(bus->uniqueName) - 1)) { AJ_ErrPrintf(("AJ_ARDP_Connect(): AJ_ERR_RESOURCES\n")); status = AJ_ERR_RESOURCES; } else { memcpy(bus->uniqueName, uniqueName.val.v_string, uniqueName.len); bus->uniqueName[uniqueName.len] = '\0'; } /AJ_InfoPrintf(("Received name: %s and version %u\n", bus->uniqueName, routingProtoVersion)); if (routingProtoVersion < AJ_GetMinProtoVersion()) { AJ_InfoPrintf(("AJ_ARDP_Connect(): Blacklisting routing node, found %u but require >= %u\n", routingProtoVersion, AJ_GetMinProtoVersion())); AddRoutingNodeToBlacklist(service); status = AJ_ERR_CONNECT; } } }
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; }
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; }