int8_t AJSVC_PropertyStore_GetCurrentDefaultLanguageIndex() { const char* currentDefaultLanguage = AJSVC_PropertyStore_GetValue(AJSVC_PROPERTY_STORE_DEFAULT_LANGUAGE); int8_t currentDefaultLanguageIndex = AJSVC_PropertyStore_GetLanguageIndex(currentDefaultLanguage); if (currentDefaultLanguageIndex == AJSVC_PROPERTY_STORE_ERROR_LANGUAGE_INDEX) { currentDefaultLanguageIndex = AJSVC_PROPERTY_STORE_NO_LANGUAGE_INDEX; AJ_WarnPrintf(("Failed to find default language %s defaulting to %s", (currentDefaultLanguage != NULL ? currentDefaultLanguage : "NULL"), propertyStoreDefaultLanguages[AJSVC_PROPERTY_STORE_NO_LANGUAGE_INDEX])); } return currentDefaultLanguageIndex; }
/* * This function is registered with About and handles property store read requests */ static AJ_Status AboutPropGetter(AJ_Message* msg, const char* language) { AJ_Status status = AJ_ERR_INVALID; int8_t langIndex; AJSVC_PropertyStoreCategoryFilter filter; memset(&filter, 0, sizeof(AJSVC_PropertyStoreCategoryFilter)); if (msg->msgId == AJ_SIGNAL_ABOUT_ANNOUNCE) { filter.bit2Announce = TRUE; langIndex = AJSVC_PropertyStore_GetLanguageIndex(language); status = AJ_OK; } else if (msg->msgId == AJ_REPLY_ID(AJ_METHOD_ABOUT_GET_ABOUT_DATA)) { filter.bit0About = TRUE; langIndex = AJSVC_PropertyStore_GetLanguageIndex(language); status = (langIndex == AJSVC_PROPERTY_STORE_ERROR_LANGUAGE_INDEX) ? AJ_ERR_UNKNOWN : AJ_OK; } if (status == AJ_OK) { status = AJSVC_PropertyStore_ReadAll(msg, filter, langIndex); } return status; }
/** * Send Notification - see notes in h file */ AJ_Status AJNS_Producer_SendNotification(AJ_BusAttachment* busAttachment, AJNS_NotificationContent* content, uint16_t messageType, uint32_t ttl, uint32_t* messageSerialNumber) { AJ_Status status; AJNS_Notification notification; uint32_t serialNumber; // AJ_InfoPrintf(("In SendNotification\n")); notification.version = AJNS_NotificationVersion; if (messageType >= AJNS_NUM_MESSAGE_TYPES) { AJ_ErrPrintf(("Could not Send Notification - MessageType is not valid\n")); return AJ_ERR_DISALLOWED; } notification.messageType = messageType; if ((ttl < AJNS_NOTIFICATION_TTL_MIN) || (ttl > AJNS_NOTIFICATION_TTL_MAX)) { //ttl is mandatory and must be in range AJ_ErrPrintf(("TTL '%u' is not a valid TTL value\n", ttl)); return AJ_ERR_DISALLOWED; } notification.deviceId = AJSVC_PropertyStore_GetValue(AJSVC_PROPERTY_STORE_DEVICE_ID); notification.deviceName = AJSVC_PropertyStore_GetValueForLang(AJSVC_PROPERTY_STORE_DEVICE_NAME, AJSVC_PropertyStore_GetLanguageIndex("")); notification.appId = AJSVC_PropertyStore_GetValue(AJSVC_PROPERTY_STORE_APP_ID); notification.appName = AJSVC_PropertyStore_GetValue(AJSVC_PROPERTY_STORE_APP_NAME); if ((notification.deviceId == 0) || (notification.deviceName == 0) || (notification.appId == 0) || (notification.appName == 0)) { AJ_ErrPrintf(("DeviceId/DeviceName/AppId/AppName can not be NULL\n")); return AJ_ERR_DISALLOWED; } if ((strlen(notification.deviceId) == 0) || (strlen(notification.deviceName) == 0) || (strlen(notification.appId) == 0) || (strlen(notification.appName) == 0)) { AJ_ErrPrintf(("DeviceId/DeviceName/AppId/AppName can not be empty\n")); return AJ_ERR_DISALLOWED; } if (notification.version > 1) { notification.originalSenderName = AJ_GetUniqueName(busAttachment); if (notification.originalSenderName == 0) { AJ_ErrPrintf(("OriginalSender can not be NULL\n")); return AJ_ERR_DISALLOWED; } if (strlen(notification.originalSenderName) == 0) { AJ_ErrPrintf(("OriginalSender can not be empty\n")); return AJ_ERR_DISALLOWED; } } else { notification.originalSenderName = NULL; } if (!notificationId) { // AJ_InfoPrintf(("Generating random number for notification id\n")); AJ_RandBytes((uint8_t*)¬ificationId, 4); } notification.notificationId = notificationId; notification.content = content; status = AJNS_Producer_SendNotifySignal(busAttachment, ¬ification, ttl, &serialNumber); if (status == AJ_OK) { lastSentNotifications[messageType].notificationId = notificationId++; lastSentNotifications[messageType].serialNum = serialNumber; if (messageSerialNumber != NULL) { *messageSerialNumber = serialNumber; } } return status; }
static const char* DescriptionLookup(uint32_t descId, const char* lang) { const char* actualLanguage; int8_t langIndex = AJSVC_PropertyStore_GetLanguageIndex(lang); char deviceName[DEVICE_NAME_VALUE_LENGTH] = { '\0' }; uint8_t i; const char* deviceNamePerLanguage; AJ_InfoPrintf(("Looking up description for o:%u i:%u m:%u a:%u\n", (descId >> 24) & 0xFF, (descId >> 16) & 0xFF, (descId >> 8) & 0xFF, (descId >> 0) & 0xFF)); if (langIndex != AJSVC_PROPERTY_STORE_ERROR_LANGUAGE_INDEX) { actualLanguage = AJSVC_PropertyStore_GetLanguageName(langIndex); AJ_InfoPrintf((" language=%s\n", actualLanguage)); deviceNamePerLanguage = AJSVC_PropertyStore_GetValueForLang(AJSVC_PROPERTY_STORE_DEVICE_NAME, langIndex); if (deviceNamePerLanguage == NULL) { deviceNamePerLanguage = AJSVC_PropertyStore_GetValueForLang(AJSVC_PROPERTY_STORE_DEVICE_NAME, AJSVC_PropertyStore_GetCurrentDefaultLanguageIndex()); if (deviceNamePerLanguage == NULL) { AJ_ErrPrintf(("DeviceName for language=%s does not exist!\n", actualLanguage)); } } if (deviceNamePerLanguage != NULL) { strncpy(deviceName, deviceNamePerLanguage, DEVICE_NAME_VALUE_LENGTH); } for (i = 0; i < DEVICE_NAME_VALUE_LENGTH; i++) { // Replace any illegal/escaped XML characters with '_' if (deviceName[i] == '>' || deviceName[i] == '<' || deviceName[i] == '"' || deviceName[i] == '\'' || deviceName[i] == '&') { deviceName[i] = '_'; } } switch (descId) { case (EVENTSANDACTIONS_OBJECT_DESC): #ifdef _WIN32 _snprintf(description, DESCRIPTION_LENGTH, "%s Events and Actions [%s]", deviceName, actualLanguage); #else snprintf(description, DESCRIPTION_LENGTH, "%s Events and Actions [%s]", deviceName, actualLanguage); #endif return description; case (EVENTS_INTERFACE_DESC): #ifdef _WIN32 _snprintf(description, DESCRIPTION_LENGTH, "%s Events [%s]", deviceName, actualLanguage); #else snprintf(description, DESCRIPTION_LENGTH, "%s Events [%s]", deviceName, actualLanguage); #endif return description; case (EVENTS_TEMPERATURE80FREACHED_SLS_DESC): return "Triggerred when extreme temperature of 80F is reached while heating"; case (EVENTS_TEMPERATURE60FREACHED_SLS_DESC): return "Triggerred when extreme temperature of 60F is reached while cooling"; case (EVENTS_TURNEDOFF_SLS_DESC): return "Triggerred when the AC is turned OFF"; case (EVENTS_TURNEDON_SLS_DESC): return "Triggerred when the AC is turned ON"; case (ACTIONS_INTERFACE_DESC): #ifdef _WIN32 _snprintf(description, DESCRIPTION_LENGTH, "%s Actions [%s]", deviceName, actualLanguage); #else snprintf(description, DESCRIPTION_LENGTH, "%s Actions [%s]", deviceName, actualLanguage); #endif return description; case (ACTIONS_SETMODETOAUTO_DESC): return "Set AC mode to Auto"; case (ACTIONS_SETMODETOCOOL_DESC): return "Set AC mode to Cool"; case (ACTIONS_SETMODETOHEAT_DESC): return "Set AC mode to Heat"; case (ACTIONS_SETMODETOFAN_DESC): return "Set AC mode to Fan"; case (ACTIONS_SETMODETOOFF_DESC): return "Set AC mode to Off"; default: return NULL; } } AJ_WarnPrintf(("\nError: Unsupported language=%s\n", lang == NULL ? "NULL" : lang)); return NULL; }