AJ_Status marshalTimePropertyValue(TimePropertyValue* timePropertyValue, AJ_Message* reply) { AJ_Status status; AJ_Arg outerStructArg, innerStructArg; status = AJ_MarshalVariant(reply, TIME_PROPERTY_SIG); if (status != AJ_OK) { return status; } status = AJ_MarshalContainer(reply, &outerStructArg, AJ_ARG_STRUCT); if (status != AJ_OK) { return status; } status = AJ_MarshalArgs(reply, "q", TIME_PROPERTY); if (status != AJ_OK) { return status; } status = AJ_MarshalContainer(reply, &innerStructArg, AJ_ARG_STRUCT); if (status != AJ_OK) { return status; } status = AJ_MarshalArgs(reply, "qqq", timePropertyValue->hour, timePropertyValue->minute, timePropertyValue->second); if (status != AJ_OK) { return status; } status = AJ_MarshalCloseContainer(reply, &innerStructArg); if (status != AJ_OK) { return status; } return AJ_MarshalCloseContainer(reply, &outerStructArg); }
AJ_Status AddPropertyForGetAll(AJ_Message* reply, char* key, const char* sig, BaseWidget* widget, uint16_t language, MarshalWidgetFptr functionPtr) { AJ_Status status; AJ_Arg dictArg; status = AJ_MarshalContainer(reply, &dictArg, AJ_ARG_DICT_ENTRY); if (status != AJ_OK) { return status; } status = AJ_MarshalArgs(reply, "s", key); if (status != AJ_OK) { return status; } status = AJ_MarshalVariant(reply, sig); if (status != AJ_OK) { return status; } status = functionPtr(widget, reply, language); if (status != AJ_OK) { return status; } return AJ_MarshalCloseContainer(reply, &dictArg); }
AJ_Status marshalDatePropertyValue(DatePropertyValue* datePropertyValue, AJ_Message* reply) { AJ_Status status; AJ_Arg outerStructArg, innerStructArg; status = AJ_MarshalVariant(reply, DATE_PROPERTY_SIG); if (status != AJ_OK) { return status; } status = AJ_MarshalContainer(reply, &outerStructArg, AJ_ARG_STRUCT); if (status != AJ_OK) { return status; } status = AJ_MarshalArgs(reply, "q", DATE_PROPERTY); if (status != AJ_OK) { return status; } status = AJ_MarshalContainer(reply, &innerStructArg, AJ_ARG_STRUCT); if (status != AJ_OK) { return status; } status = AJ_MarshalArgs(reply, "qqq", datePropertyValue->mDay, datePropertyValue->month, datePropertyValue->fullYear); if (status != AJ_OK) { return status; } status = AJ_MarshalCloseContainer(reply, &innerStructArg); if (status != AJ_OK) { return status; } return AJ_MarshalCloseContainer(reply, &outerStructArg); }
AJ_Status MarshalAllRootProperties(AJ_Message* reply) { AJ_Status status; AJ_Arg rootGetAllArray; AJ_Arg dictArg; status = AJ_MarshalContainer(reply, &rootGetAllArray, AJ_ARG_ARRAY); if (status != AJ_OK) { return status; } status = AJ_MarshalContainer(reply, &dictArg, AJ_ARG_DICT_ENTRY); if (status != AJ_OK) { return status; } status = AJ_MarshalArgs(reply, "s", PROPERTY_TYPE_VERSION_NAME); if (status != AJ_OK) { return status; } status = AJ_MarshalVariant(reply, PROPERTY_TYPE_VERSION_SIG); if (status != AJ_OK) { return status; } status = MarshalVersionRootProperties(reply); if (status != AJ_OK) { return status; } status = AJ_MarshalCloseContainer(reply, &dictArg); if (status != AJ_OK) { return status; } return AJ_MarshalCloseContainer(reply, &rootGetAllArray); }
AJ_Status StartComplexOptionalParam(AJ_Message* reply, AJ_Arg* arg, uint16_t key, const char* sig) { AJ_Status status; status = AJ_MarshalContainer(reply, arg, AJ_ARG_DICT_ENTRY); if (status != AJ_OK) { return status; } status = AJ_MarshalArgs(reply, "q", key); if (status != AJ_OK) { return status; } return AJ_MarshalVariant(reply, sig); }
AJ_Status MarshalVariant(AJ_Message* reply, const char* sig, const void* value) { AJ_Status status; status = AJ_MarshalVariant(reply, sig); if (status != AJ_OK) { return status; } if (value == 0) { return AJ_ERR_UNEXPECTED; } if (strcmp(sig, "s") == 0) { return AJ_MarshalArgs(reply, sig, *((char**)value)); } else if (strcmp(sig, "i") == 0) { return AJ_MarshalArgs(reply, sig, *((int*)value)); } else if (strcmp(sig, "b") == 0) { return AJ_MarshalArgs(reply, sig, *((uint8_t*)value)); } else if (strcmp(sig, "q") == 0) { return AJ_MarshalArgs(reply, sig, *((uint16_t*)value)); } else if (strcmp(sig, "u") == 0) { return AJ_MarshalArgs(reply, sig, *((uint32_t*)value)); } else if (strcmp(sig, "d") == 0) { return AJ_MarshalArgs(reply, sig, *((double*)value)); } else if (strcmp(sig, "g") == 0) { return AJ_MarshalArgs(reply, sig, *((char**)value)); } else if (strcmp(sig, "o") == 0) { return AJ_MarshalArgs(reply, sig, *((char**)value)); } else if (strcmp(sig, "n") == 0) { return AJ_MarshalArgs(reply, sig, *((int16_t*)value)); } else if (strcmp(sig, "t") == 0) { return AJ_MarshalArgs(reply, sig, *((uint64_t*)value)); } else if (strcmp(sig, "x") == 0) { return AJ_MarshalArgs(reply, sig, *((int64_t*)value)); } else if (strcmp(sig, "y") == 0) { return AJ_MarshalArgs(reply, sig, *((char*)value)); } else if (strcmp(sig, "h") == 0) { return AJ_MarshalArgs(reply, sig, *((int*)value)); } return AJ_ERR_UNEXPECTED; }
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=%d.)\n", msg, cb, op)); /* * 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); }
AJ_Status AJSVC_PropertyStore_ReadAll(AJ_Message* msg, AJSVC_PropertyStoreCategoryFilter filter, int8_t langIndex) { AJ_Status status = AJ_OK; AJ_Arg array; AJ_Arg array2; AJ_Arg dict; const char* value; AJ_Arg arg; uint8_t rawValue[16]; uint8_t index; const char* ajVersion; AJ_InfoPrintf(("PropertyStore_ReadAll()\n")); status = AJ_MarshalContainer(msg, &array, AJ_ARG_ARRAY); if (status != AJ_OK) { return status; } //AJSVC_PropertyStoreFieldIndices fieldIndex = 0; int fieldIndex = 0; for (; fieldIndex < AJSVC_PROPERTY_STORE_NUMBER_OF_KEYS; fieldIndex++) { #ifdef CONFIG_SERVICE if (propertyStoreProperties[fieldIndex].mode7Public && (filter.bit0About || (filter.bit1Config && propertyStoreProperties[fieldIndex].mode0Write) || (filter.bit2Announce && propertyStoreProperties[fieldIndex].mode1Announce))) { #else if (propertyStoreProperties[fieldIndex].mode7Public && (filter.bit0About || (filter.bit2Announce && propertyStoreProperties[fieldIndex].mode1Announce))) { #endif value = AJSVC_PropertyStore_GetValueForLang((AJSVC_PropertyStoreFieldIndices)fieldIndex, langIndex); if (value == NULL && fieldIndex >= AJSVC_PROPERTY_STORE_NUMBER_OF_MANDATORY_KEYS) { // Non existing values are skipped! AJ_WarnPrintf(("PropertyStore_ReadAll - Failed to get value for field=(name=%s, index=%d) and language=(name=%s, index=%d), skipping.\n", AJSVC_PropertyStore_GetFieldName((AJSVC_PropertyStoreFieldIndices)fieldIndex), (int)fieldIndex, AJSVC_PropertyStore_GetLanguageName(langIndex), (int)langIndex)); } else { if (fieldIndex == AJSVC_PROPERTY_STORE_APP_ID) { if (value == NULL) { AJ_ErrPrintf(("PropertyStore_ReadAll - Failed to get value for mandatory field=(name=%s, index=%d) and language=(name=%s, index=%d), aborting.\n", AJSVC_PropertyStore_GetFieldName((AJSVC_PropertyStoreFieldIndices)fieldIndex), (int)fieldIndex, AJSVC_PropertyStore_GetLanguageName(langIndex), (int)langIndex)); return AJ_ERR_NULL; } status = AJ_MarshalContainer(msg, &dict, AJ_ARG_DICT_ENTRY); if (status != AJ_OK) { return status; } status = AJ_MarshalArgs(msg, "s", propertyStoreProperties[fieldIndex].keyName); if (status != AJ_OK) { return status; } status = AJ_MarshalVariant(msg, "ay"); if (status != AJ_OK) { return status; } status = AJ_HexToRaw(value, 0, rawValue, (size_t)sizeof(rawValue)); if (status != AJ_OK) { return status; } status = AJ_MarshalArg(msg, AJ_InitArg(&arg, AJ_ARG_BYTE, AJ_ARRAY_FLAG, rawValue, sizeof(rawValue))); if (status != AJ_OK) { return status; } status = AJ_MarshalCloseContainer(msg, &dict); if (status != AJ_OK) { return status; } #ifdef CONFIG_SERVICE } else if (fieldIndex == AJSVC_PROPERTY_STORE_MAX_LENGTH) { status = AJ_MarshalContainer(msg, &dict, AJ_ARG_DICT_ENTRY); if (status != AJ_OK) { return status; } status = AJ_MarshalArgs(msg, "s", propertyStoreProperties[fieldIndex].keyName); if (status != AJ_OK) { return status; } status = AJ_MarshalVariant(msg, "q"); if (status != AJ_OK) { return status; } status = AJ_MarshalArgs(msg, "q", DEVICE_NAME_VALUE_LENGTH); if (status != AJ_OK) { return status; } status = AJ_MarshalCloseContainer(msg, &dict); if (status != AJ_OK) { return status; } AJ_InfoPrintf(("Has key [%s] runtime Value [%d]\n", propertyStoreProperties[AJSVC_PROPERTY_STORE_MAX_LENGTH].keyName, DEVICE_NAME_VALUE_LENGTH)); #endif } else if (fieldIndex == AJSVC_PROPERTY_STORE_AJ_SOFTWARE_VERSION) { ajVersion = AJ_GetVersion(); if (ajVersion == NULL) { AJ_ErrPrintf(("PropertyStore_ReadAll - Failed to get value for mandatory field=(name=%s, index=%d) and language=(name=%s, index=%d), aborting.\n", AJSVC_PropertyStore_GetFieldName((AJSVC_PropertyStoreFieldIndices)fieldIndex), (int)fieldIndex, AJSVC_PropertyStore_GetLanguageName(langIndex), (int)langIndex)); return AJ_ERR_NULL; } status = AJ_MarshalContainer(msg, &dict, AJ_ARG_DICT_ENTRY); if (status != AJ_OK) { return status; } status = AJ_MarshalArgs(msg, "s", propertyStoreProperties[fieldIndex].keyName); if (status != AJ_OK) { return status; } status = AJ_MarshalVariant(msg, "s"); if (status != AJ_OK) { return status; } status = AJ_MarshalArgs(msg, "s", ajVersion); if (status != AJ_OK) { return status; } status = AJ_MarshalCloseContainer(msg, &dict); if (status != AJ_OK) { return status; } AJ_InfoPrintf(("Has key [%s] runtime Value [%s]\n", propertyStoreProperties[AJSVC_PROPERTY_STORE_AJ_SOFTWARE_VERSION].keyName, ajVersion)); } else { if (value == NULL) { AJ_ErrPrintf(("PropertyStore_ReadAll - Failed to get value for mandatory field=(name=%s, index=%d) and language=(name=%s, index=%d), aborting.\n", AJSVC_PropertyStore_GetFieldName((AJSVC_PropertyStoreFieldIndices)fieldIndex), (int)fieldIndex, AJSVC_PropertyStore_GetLanguageName(langIndex), (int)langIndex)); return AJ_ERR_NULL; } status = AJ_MarshalContainer(msg, &dict, AJ_ARG_DICT_ENTRY); if (status != AJ_OK) { return status; } status = AJ_MarshalArgs(msg, "s", propertyStoreProperties[fieldIndex].keyName); if (status != AJ_OK) { return status; } status = AJ_MarshalVariant(msg, "s"); if (status != AJ_OK) { return status; } status = AJ_MarshalArgs(msg, "s", value); if (status != AJ_OK) { return status; } status = AJ_MarshalCloseContainer(msg, &dict); if (status != AJ_OK) { return status; } } } } } if (filter.bit0About) { // Add supported languages status = AJ_MarshalContainer(msg, &dict, AJ_ARG_DICT_ENTRY); if (status != AJ_OK) { return status; } status = AJ_MarshalArgs(msg, "s", defaultLanguagesKeyName); if (status != AJ_OK) { return status; } status = AJ_MarshalVariant(msg, "as"); if (status != AJ_OK) { return status; } status = AJ_MarshalContainer(msg, &array2, AJ_ARG_ARRAY); if (status != AJ_OK) { return status; } index = AJSVC_PROPERTY_STORE_NO_LANGUAGE_INDEX; for (; index < AJSVC_PROPERTY_STORE_NUMBER_OF_LANGUAGES; index++) { status = AJ_MarshalArgs(msg, "s", propertyStoreDefaultLanguages[index]); if (status != AJ_OK) { return status; } } status = AJ_MarshalCloseContainer(msg, &array2); if (status != AJ_OK) { return status; } status = AJ_MarshalCloseContainer(msg, &dict); if (status != AJ_OK) { return status; } } status = AJ_MarshalCloseContainer(msg, &array); if (status != AJ_OK) { return status; } return status; } #ifdef CONFIG_SERVICE AJ_Status AJSVC_PropertyStore_Update(const char* key, int8_t langIndex, const char* value) { AJSVC_PropertyStoreFieldIndices fieldIndex = AJSVC_PropertyStore_GetFieldIndex(key); if (fieldIndex == AJSVC_PROPERTY_STORE_ERROR_FIELD_INDEX || fieldIndex >= AJSVC_PROPERTY_STORE_NUMBER_OF_CONFIG_KEYS) { return AJ_ERR_INVALID; } if (!UpdateFieldInRAM(fieldIndex, langIndex, value)) { return AJ_ERR_FAILURE; } return AJ_OK; }
/** * 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, ¬TextArray, 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, ¬TextArray); 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, ¬TextArray); if (status != AJ_OK) { goto ErrorExit; } return AJ_OK; ErrorExit: AJ_ErrPrintf(("MarshalNotification failed: '%s'\n", AJ_StatusText(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; }
static AJ_Status AboutPropGetter(AJ_Message* reply, const char* language) { AJ_Status status = AJ_OK; AJ_Arg array; AJ_GUID theAJ_GUID; char machineIdValue[UUID_LENGTH * 2 + 1]; machineIdValue[UUID_LENGTH * 2] = '\0'; if ((language != NULL) && (0 != strcmp(language, "en")) && (0 != strcmp(language, ""))) { /* the language supplied was not supported */ status = AJ_ERR_NO_MATCH; } if (status == AJ_OK) { status = AJ_MarshalContainer(reply, &array, AJ_ARG_ARRAY); if (status == AJ_OK) { status = AJ_GetLocalGUID(&theAJ_GUID); if (status == AJ_OK) { AJ_GUID_ToString(&theAJ_GUID, machineIdValue, UUID_LENGTH * 2 + 1); } if (status == AJ_OK) { status = MarshalAppId(reply, &machineIdValue[0]); } if (status == AJ_OK) { status = AJ_MarshalArgs(reply, "{sv}", "AppName", "s", "svclite"); } if (status == AJ_OK) { status = AJ_MarshalArgs(reply, "{sv}", "DeviceId", "s", machineIdValue); } if (status == AJ_OK) { status = AJ_MarshalArgs(reply, "{sv}", "DeviceName", "s", "Tester"); } if (status == AJ_OK) { status = AJ_MarshalArgs(reply, "{sv}", "Manufacturer", "s", "QCE"); } if (status == AJ_OK) { status = AJ_MarshalArgs(reply, "{sv}", "ModelNumber", "s", "1.0"); } //SupportedLanguages if (status == AJ_OK) { AJ_Arg dict; AJ_Arg languageListArray; status = AJ_MarshalContainer(reply, &dict, AJ_ARG_DICT_ENTRY); if (status == AJ_OK) { status = AJ_MarshalArgs(reply, "s", "SupportedLanguages"); } if (status == AJ_OK) { status = AJ_MarshalVariant(reply, "as"); } if (status == AJ_OK) { status = AJ_MarshalContainer(reply, &languageListArray, AJ_ARG_ARRAY); } if (status == AJ_OK) { status = AJ_MarshalArgs(reply, "s", "en"); } if (status == AJ_OK) { status = AJ_MarshalCloseContainer(reply, &languageListArray); } if (status == AJ_OK) { status = AJ_MarshalCloseContainer(reply, &dict); } } if (status == AJ_OK) { status = AJ_MarshalArgs(reply, "{sv}", "Description", "s", "svclite test app"); } if (status == AJ_OK) { status = AJ_MarshalArgs(reply, "{sv}", "DefaultLanguage", "s", "en"); } if (status == AJ_OK) { status = AJ_MarshalArgs(reply, "{sv}", "SoftwareVersion", "s", AJ_GetVersion()); } if (status == AJ_OK) { status = AJ_MarshalArgs(reply, "{sv}", "AJSoftwareVersion", "s", AJ_GetVersion()); } } if (status == AJ_OK) { status = AJ_MarshalCloseContainer(reply, &array); } } return status; }
AJ_Status MyAboutPropGetter(AJ_Message* reply, const char* language) { AJ_Status status = (0 == strcmp(language, "")) ? AJ_OK : AJ_ERR_NO_MATCH; int langIndex = -1; while(languages[++langIndex] && status == AJ_ERR_NO_MATCH){ fflush(stdout); if ((0 != strcmp(language, languages[langIndex]))) continue; status = AJ_OK; } if (status != AJ_OK) { return status; } AJ_Arg array; // char guidStr[16 * 2 + 1]; uint8_t appId[16]; // memset(guidStr, '\0', sizeof(guidStr)); char* propDeviceId = (char*)GetProperty("DeviceId"); // if (propDeviceId){ // strcpy(guidStr, propDeviceId); // } else { // AJ_GUID guid; // status = AJ_GetLocalGUID(&guid); // if (status != AJ_OK) { // return status; // } // AJ_GUID_ToString(&guid, guidStr, sizeof(guidStr)); // } char* propAppId = (char*)GetProperty("AppId"); status = AJ_HexToRaw(propAppId, 0, appId, 16); if (status != AJ_OK) { return status; } status = AJ_MarshalContainer(reply, &array, AJ_ARG_ARRAY); if (status == AJ_OK) { status = AJ_MarshalArgs(reply, "{sv}", "AppId", "ay", appId, 16); } if (status == AJ_OK) { // printf("AppName: %s\n", (char*)GetProperty("AppName")); status = AJ_MarshalArgs(reply, "{sv}", "AppName", "s", (char*)GetProperty("AppName")); } if (status == AJ_OK) { // printf("DeviceId: %s\n", propDeviceId); status = AJ_MarshalArgs(reply, "{sv}", "DeviceId", "s", propDeviceId); } if (status == AJ_OK) { // not mandatory char * DeviceName = (char*)GetProperty("DeviceName"); if (DeviceName){ // printf("DeviceName: %s\n", DeviceName); status = AJ_MarshalArgs(reply, "{sv}", "DeviceName", "s", DeviceName); } } if (status == AJ_OK) { status = AJ_MarshalArgs(reply, "{sv}", "Manufacturer", "s", (char*)GetProperty("Manufacturer")); } if (status == AJ_OK) { // not mandatory char * DateOfManufacture = (char*)GetProperty("DateOfManufacture"); if (DateOfManufacture){ status = AJ_MarshalArgs(reply, "{sv}", "DateOfManufacture", "s", DateOfManufacture); } } if (status == AJ_OK) { status = AJ_MarshalArgs(reply, "{sv}", "ModelNumber", "s", (char*)GetProperty("ModelNumber")); } if (status == AJ_OK) { // not mandatory char * SupportUrl = (char*)GetProperty("SupportUrl"); if (SupportUrl){ status = AJ_MarshalArgs(reply, "{sv}", "SupportUrl", "s", SupportUrl); } } //SupportedLanguages if (status == AJ_OK) { AJ_Arg dict; AJ_Arg languageListArray; status = AJ_MarshalContainer(reply, &dict, AJ_ARG_DICT_ENTRY); if (status == AJ_OK) { status = AJ_MarshalArgs(reply, "s", "SupportedLanguages"); } if (status == AJ_OK) { status = AJ_MarshalVariant(reply, "as"); } if (status == AJ_OK) { status = AJ_MarshalContainer(reply, &languageListArray, AJ_ARG_ARRAY); } int langIndex = -1; while(languages[++langIndex]){ if (status == AJ_OK) { status = AJ_MarshalArgs(reply, "s", languages[langIndex]); } } if (status == AJ_OK) { status = AJ_MarshalCloseContainer(reply, &languageListArray); } if (status == AJ_OK) { status = AJ_MarshalCloseContainer(reply, &dict); } } if (status == AJ_OK) { status = AJ_MarshalArgs(reply, "{sv}", "Description", "s", (char*)GetProperty("Description")); } if (status == AJ_OK) { status = AJ_MarshalArgs(reply, "{sv}", "DefaultLanguage", "s", languages[0]); } if (status == AJ_OK) { status = AJ_MarshalArgs(reply, "{sv}", "SoftwareVersion", "s", AJ_GetVersion()); } if (status == AJ_OK) { status = AJ_MarshalArgs(reply, "{sv}", "AJSoftwareVersion", "s", AJ_GetVersion()); } if (status == AJ_OK) { status = AJ_MarshalCloseContainer(reply, &array); } return status; }