Attention: this is a legacy library and thus not supported by Toradex anymore. We recommend that you use the new libraries for all Toradex modules. Please see the Toradex CE Libraries and Code Samples for up-to-date information.
Amazon Simple Notification Service (Amazon SNS) is a web service that makes it easy to set up, operate, and send notifications from the cloud. It provides developers with a highly scalable, flexible, and cost-effective capability to publish messages from an application and immediately deliver them to subscribers or other applications. It is designed to make web-scale computing easier for developers.
Notes:
For more information, please refer to: http://aws.amazon.com/sns/
Before calling any other function, call SnsOpenTopic() with all the parameter inputs: AWS Access Id, AWS Secret Key, AWS Owner ID, AWS SnS Region / Path,topicName, Topic and Display name(optional).
HSNS NewTopic; //Declare Topic handle if (!SnsOpenTopic(AWS_ACCOUNT_ACCESS_ID, AWS_ACCOUNT_SECRET_KEY, AWS_ACCOUNT_OWNER_ID, AWS_SQS_USA_EAST_REGION, “TopicName”, “DisplayName”, &NewTopic)) { printf("SnsOpenTopic Fail"); printf(", Error Code: %d\n", GetLastError()); } else { printf("SnsOpenTopic Success\n"); }
NewTopic needs to be passed to all function calls after this point.
The SnsCreateTopic() function is used to create a new topic. This is the 2nd function to be called after SnsOpenTopic(). It is mandatory to call this function otherwise other calls will automatically fail.
if (!SnsCreateTopic(NewTopic)) { printf("SnsCreateTopic Fail"); printf(", Error Code: %d\n", GetLastError()); } else { printf("SnsCreateTopic Success\n"); }
SnsListTopics() function is used to list all the topics.
if (!SnsListTopics(NewTopic, "\\listoftopics.txt")) { printf("SnsListTopics Fail"); printf(", Error Code: %d\n", GetLastError()); } else { printf("SnsListTopics Success\n"); }
The SnsFindTopic() function is used to find topic details one by one from a list data stored in the local file.
DWORD listTopicNextPointer = 0; char topicData[256] = {0}; memset(topicData, 0, 256); if (SnsFindTopic("\\listoftopics.txt", topicData, BUFFER_SIZE_TOPIC_DATA, &listTopicNextPointer, fileSize)) { printf("> %s\n", topicData); }
To find the next topic, call SnsFindTopic again as below. This time don’t set listTopicNextPointer to zero.
memset(topicData, 0, 256); if (SnsFindTopic("\\listoftopics.txt", topicData, BUFFER_SIZE_TOPIC_DATA, &listTopicNextPointer, fileSize)) { printf("> %s\n", topicData); }
The SnsDeleteTopic() function is used to delete a topic.
if (!SnsDeleteTopic(NewTopic)) { printf("SnsDeleteTopic Fail"); printf(", Error Code: %d\n", GetLastError()); } else { printf("SnsDeleteTopic Success\n"); }
The SnsListSubscriptions() function is used to list all the subscriptions of a topic.
if (!SnsListSubscriptions(NewTopic, "\\ListSubscriptionsByTopic.txt")) { printf("SnsListSubscriptions Fail"); printf(", Error Code: %d\n", GetLastError()); } else { printf("SnsListSubscriptions Success\n"); }
The SnsFindSubscriptions() function is used to find subscription details one by one from list data stored in the local file.
DWORD listSubscriptionNextPointer = 0; char subscriptionData[1024] = {0}; memset(subscriptionData, 0, 1024); if (SnsFindSubscriptions("\\ListSubscriptionsByTopic.txt", subscriptionData, 1024, &listSubscriptionNextPointer, fileSize)) { printf("> %s\n", subscriptionData); }
To find the next subscription call SnsFindSubscriptions() again as detailed below. This time don’t set listSubscriptionNextPointer to zero.
memset(subscriptionData, 0, 1024); if (SnsFindSubscriptions("\\ListSubscriptionsByTopic.txt", subscriptionData, 1024, &listSubscriptionNextPointer, fileSize)) { printf("> %s\n", subscriptionData); }
The SnsSubscribe() function is used to subscribe an endpoint to a topic.
// USE MACRO for 3rd parameter if (!SnsSubscribe(NewTopic, “example@toradex.com”, PROTOCOL_TYPE_EMAIL)) { printf("SnsSubscribe Fail"); printf(", Error Code: %d\n", GetLastError()); } else { printf("SnsSubscribe Success\n"); }
The SnsUnsubscribe() function is used to unsubscribe an endpoint from a topic.
if (!SnsUnsubscribe(NewTopic, "arn:aws:sns:us-east-1:823890622362:USA_NewAlerts-1:e86e12f4-ccb7-4153-acd2-33a2c8e30de5")) { printf("SnsUnsubscribe Fail"); printf(", Error Code: %d\n", GetLastError()); } else { printf("SnsUnsubscribe Success\n"); }
The SnsGetSubscriptionAttribtues() function is used to get subscription attributes.
char subscriptionAttributesData[1024] = {0}; memset(subscriptionAttributesData, 0, 1024); if (!SnsGetSubscriptionAttribtues(NewTopic, "arn:aws:sns:us-east-1:823890622362:test:81bb4313-b150-48bf-8fd5-cf98a6a85535", subscriptionAttributesData, 1024)) { printf("SnsGetSubscriptionAttribtues Fail"); printf(", Error Code: %d\n", GetLastError()); } else { printf("%s\n", subscriptionAttributesData); printf("SnsGetSubscriptionAttribtues Success\n"); }
The SnsGetTopicAttributes() function is used to get topic attributes.
char topicAttributesData[1024] = {0}; memset(topicAttributesData, 0, 1024); if (!SnsGetTopicAttributes(NewTopic, topicAttributesData, 1024)) { printf("SnsGetTopicAttributes Fail"); printf(", Error Code: %d\n", GetLastError()); } else { printf("%s\n", topicAttributesData); printf("SnsGetTopicAttributes Success\n"); }
The SnsSetTopicAttributes() function is used to set the attribute of a topic.
2nd parameter is the attribute type use macros:
#define ATTRIBUTE_TYPE_POLICY 1 #define ATTRIBUTE_TYPE_DISPLAYNAME 2 #define ATTRIBUTE_TYPE_DELIVERYPOLICY 3
3rd parameter is the attribute name/value.
if (!SnsSetTopicAttributes(NewTopic, ATTRIBUTE_TYPE_DISPLAYNAME, “TORADEX”)) { printf("SnsSetTopicAttributes Fail"); printf(", Error Code: %d\n", GetLastError()); } else { printf("SnsSetTopicAttributes Success\n"); }
The SnsPublish() function is used to send a message to a topic.
if (!SnsPublish(NewTopic, "Test", "Message, sent by Toradex SNS Cloud Library :)")) { printf("SnsPublish Fail"); printf(", Error Code: %d\n", GetLastError()); } else { printf("SnsPublish Success\n"); }
The SnsCloseTopic() function is used to close the handle opened by the call to SnsOpenTopic().
if (!SnsCloseTopic(&NewTopic)) { printf("SnsCloseTopic Fail"); printf(", Error Code: %d\n", GetLastError()); }