osaf/tools/safntf/include/ntfclient.h | 25 ++++ osaf/tools/safntf/ntfread/ntfread.c | 16 +- osaf/tools/safntf/ntfsend/ntfsend.c | 24 +- osaf/tools/safntf/ntfsubscribe/ntfsubscribe.c | 22 +- osaf/tools/safntf/src/ntfclient.c | 158 ++++++++++++++++++++++++++ 5 files changed, 214 insertions(+), 31 deletions(-)
Since NTF support the SC outage which the NTF client has to handle TRY_AGAIN return code, the patch adds wrapper for APIs being used in ntftools that shall receives TRY_AGAIN when both SCs are down. diff --git a/osaf/tools/safntf/include/ntfclient.h b/osaf/tools/safntf/include/ntfclient.h --- a/osaf/tools/safntf/include/ntfclient.h +++ b/osaf/tools/safntf/include/ntfclient.h @@ -142,4 +142,29 @@ int get_long_long_digit(char *str, long bool validate_nType_eType(SaNtfNotificationTypeT nType, SaNtfEventTypeT eType); void set_nType_for_eType(SaNtfNotificationTypeT *nType, SaNtfEventTypeT *eType); +/* wrapper of NTF API to handle TRY_AGAIN */ +SaAisErrorT ntftool_saNtfInitialize( + SaNtfHandleT *ntfHandle, + const SaNtfCallbacksT *ntfCallbacks, + SaVersionT *version); +SaAisErrorT ntftool_saNtfDispatch( + SaNtfHandleT ntfHandle, + SaDispatchFlagsT dispatchFlags); +SaAisErrorT ntftool_saNtfNotificationSend( + SaNtfNotificationHandleT notificationHandle); +SaAisErrorT ntftool_saNtfNotificationSubscribe( + const SaNtfNotificationTypeFilterHandlesT *notificationFilterHandles, + SaNtfSubscriptionIdT subscriptionId); +SaAisErrorT ntftool_saNtfNotificationUnsubscribe( + SaNtfSubscriptionIdT subscriptionId); +SaAisErrorT ntftool_saNtfNotificationReadInitialize( + SaNtfSearchCriteriaT searchCriteria, + const SaNtfNotificationTypeFilterHandlesT *notificationFilterHandles, + SaNtfReadHandleT *readHandle); +SaAisErrorT ntftool_saNtfNotificationReadNext( + SaNtfReadHandleT readHandle, + SaNtfSearchDirectionT searchDirection, SaNtfNotificationsT *notification); +SaAisErrorT ntftool_saNtfNotificationReadFinalize( + SaNtfReadHandleT readhandle); + #endif diff --git a/osaf/tools/safntf/ntfread/ntfread.c b/osaf/tools/safntf/ntfread/ntfread.c --- a/osaf/tools/safntf/ntfread/ntfread.c +++ b/osaf/tools/safntf/ntfread/ntfread.c @@ -224,23 +224,23 @@ static SaAisErrorT readAll() { fhdls.alarmFilterHandle = af.notificationFilterHandle; fhdls.securityAlarmFilterHandle = saf.notificationFilterHandle; - rc = saNtfNotificationReadInitialize(searchCriteria, &fhdls, + rc = ntftool_saNtfNotificationReadInitialize(searchCriteria, &fhdls, &readHandle); if (rc != SA_AIS_OK) { - fprintf(stderr, "saNtfNotificationReadInitialize failed - %s\n", + fprintf(stderr, "ntftool_saNtfNotificationReadInitialize failed - %s\n", error_output(rc)); goto done; } /* read as many notifications as exist */ - while ((rc = saNtfNotificationReadNext(readHandle, searchDirection, &n)) + while ((rc = ntftool_saNtfNotificationReadNext(readHandle, searchDirection, &n)) == SA_AIS_OK) { saNtfNotificationCallback(0, &n); } if (rc == SA_AIS_ERR_NOT_EXIST) { rc = SA_AIS_OK; /* no more notification exists */ } else { - fprintf(stderr, "saNtfNotificationReadNext failed - %s\n", + fprintf(stderr, "ntftool_saNtfNotificationReadNext failed - %s\n", error_output(rc)); } done: @@ -362,9 +362,9 @@ int main(int argc, char *argv[]) { fprintf(stderr, "Try '%s -h' for more information. \n", argv[0]); exit(EXIT_FAILURE); } - rc = saNtfInitialize(&ntfHandle, &ntfCallbacks, &version); + rc = ntftool_saNtfInitialize(&ntfHandle, &ntfCallbacks, &version); if (SA_AIS_OK != rc) { - fprintf(stderr, "saNtfInitialize failed - %s\n", + fprintf(stderr, "ntftool_saNtfInitialize failed - %s\n", error_output(rc)); exit(EXIT_FAILURE); } @@ -389,9 +389,9 @@ int main(int argc, char *argv[]) { exit(EXIT_FAILURE); } } - rc = saNtfNotificationReadFinalize(readHandle); + rc = ntftool_saNtfNotificationReadFinalize(readHandle); if (SA_AIS_OK != rc) { - fprintf(stderr, "saNtfNotificationReadFinalize failed - %s\n", + fprintf(stderr, "ntftool_saNtfNotificationReadFinalize failed - %s\n", error_output(rc)); exit(EXIT_FAILURE); } diff --git a/osaf/tools/safntf/ntfsend/ntfsend.c b/osaf/tools/safntf/ntfsend/ntfsend.c --- a/osaf/tools/safntf/ntfsend/ntfsend.c +++ b/osaf/tools/safntf/ntfsend/ntfsend.c @@ -349,9 +349,9 @@ sendNotification(const saNotificationAll unsigned int repeat = notificationParams->repeateSends; do { - errorCode = saNtfInitialize(&ntfHandle, NULL, &version); + errorCode = ntftool_saNtfInitialize(&ntfHandle, NULL, &version); if (SA_AIS_OK != errorCode && SA_AIS_ERR_TRY_AGAIN != errorCode) { - (void)printf("saNtfInitialize %s\n", error_output(errorCode)); + (void)printf("ntftool_saNtfInitialize %s\n", error_output(errorCode)); return errorCode; } if (SA_AIS_ERR_TRY_AGAIN == errorCode) { @@ -681,9 +681,9 @@ sendNotification(const saNotificationAll /* Send the alarm notification */ do { - errorCode = saNtfNotificationSend(myAlarmNotification.notificationHandle); + errorCode = ntftool_saNtfNotificationSend(myAlarmNotification.notificationHandle); if (SA_AIS_OK != errorCode && SA_AIS_ERR_TRY_AGAIN != errorCode) { - (void)printf("saNtfNotificationSend %s\n", error_output(errorCode)); + (void)printf("ntftool_saNtfNotificationSend %s\n", error_output(errorCode)); return errorCode; } if (SA_AIS_ERR_TRY_AGAIN == errorCode) { @@ -720,9 +720,9 @@ sendNotification(const saNotificationAll /* Send the state change notification */ do { - errorCode = saNtfNotificationSend(myStateChangeNotification.notificationHandle); + errorCode = ntftool_saNtfNotificationSend(myStateChangeNotification.notificationHandle); if (SA_AIS_OK != errorCode && SA_AIS_ERR_TRY_AGAIN != errorCode) { - (void)printf("saNtfNotificationSend %s\n", error_output(errorCode)); + (void)printf("ntftool_saNtfNotificationSend %s\n", error_output(errorCode)); return errorCode; } if (SA_AIS_ERR_TRY_AGAIN == errorCode) { @@ -759,9 +759,9 @@ sendNotification(const saNotificationAll do { - errorCode = saNtfNotificationSend(myObjectCreateDeleteNotification.notificationHandle); + errorCode = ntftool_saNtfNotificationSend(myObjectCreateDeleteNotification.notificationHandle); if (SA_AIS_OK != errorCode && SA_AIS_ERR_TRY_AGAIN != errorCode) { - (void)printf("saNtfNotificationSend %s\n", error_output(errorCode)); + (void)printf("ntftool_saNtfNotificationSend %s\n", error_output(errorCode)); return errorCode; } if (SA_AIS_ERR_TRY_AGAIN == errorCode) { @@ -799,9 +799,9 @@ sendNotification(const saNotificationAll case SA_NTF_TYPE_ATTRIBUTE_CHANGE: /* Send the attribute change notification */ do { - errorCode = saNtfNotificationSend(myAttributeChangeNotification.notificationHandle); + errorCode = ntftool_saNtfNotificationSend(myAttributeChangeNotification.notificationHandle); if (SA_AIS_OK != errorCode && SA_AIS_ERR_TRY_AGAIN != errorCode) { - (void)printf("saNtfNotificationSend %s\n", error_output(errorCode)); + (void)printf("ntftool_saNtfNotificationSend %s\n", error_output(errorCode)); return errorCode; } if (SA_AIS_ERR_TRY_AGAIN == errorCode) { @@ -838,9 +838,9 @@ sendNotification(const saNotificationAll case SA_NTF_TYPE_SECURITY_ALARM: /* Send the state change notification */ do { - errorCode = saNtfNotificationSend(mySecurityAlarmNotification.notificationHandle); + errorCode = ntftool_saNtfNotificationSend(mySecurityAlarmNotification.notificationHandle); if (SA_AIS_OK != errorCode && SA_AIS_ERR_TRY_AGAIN != errorCode) { - (void)printf("saNtfNotificationSend %s\n", error_output(errorCode)); + (void)printf("ntftool_saNtfNotificationSend %s\n", error_output(errorCode)); return errorCode; } if (SA_AIS_ERR_TRY_AGAIN == errorCode) { diff --git a/osaf/tools/safntf/ntfsubscribe/ntfsubscribe.c b/osaf/tools/safntf/ntfsubscribe/ntfsubscribe.c --- a/osaf/tools/safntf/ntfsubscribe/ntfsubscribe.c +++ b/osaf/tools/safntf/ntfsubscribe/ntfsubscribe.c @@ -145,25 +145,25 @@ static SaAisErrorT waitForNotifications( if (fds[FD_NTF].revents & POLLIN) { do { - error = saNtfDispatch(myHandle, SA_DISPATCH_ALL); + error = ntftool_saNtfDispatch(myHandle, SA_DISPATCH_ALL); if (SA_AIS_ERR_TRY_AGAIN == error) sleep(1); } while (SA_AIS_ERR_TRY_AGAIN == error); if (error != SA_AIS_OK) - fprintf(stderr, "saNtfDispatch Error %d\n", error); + fprintf(stderr, "ntftool_saNtfDispatch Error %d\n", error); } if ((fds[FD_TERM].revents & POLLIN) || (fds[FD_INT].revents & POLLIN)) { - error = saNtfDispatch(myHandle, SA_DISPATCH_ALL); + error = ntftool_saNtfDispatch(myHandle, SA_DISPATCH_ALL); if (error != SA_AIS_OK) { - fprintf(stderr, "saNtfDispatch Error %d\n", error); + fprintf(stderr, "ntftool_saNtfDispatch Error %d\n", error); exit(EXIT_FAILURE); } - error = saNtfNotificationUnsubscribe(my_subscriptionId); + error = ntftool_saNtfNotificationUnsubscribe(my_subscriptionId); if (error != SA_AIS_OK) { - fprintf(stderr, "saNtfNotificationUnsubscribe failed - %d\n", error); + fprintf(stderr, "ntftool_saNtfNotificationUnsubscribe failed - %d\n", error); exit(EXIT_FAILURE); } @@ -308,9 +308,9 @@ static SaAisErrorT subscribeForNotificat } - errorCode = saNtfNotificationSubscribe(¬ificationFilterHandles, subscriptionId); + errorCode = ntftool_saNtfNotificationSubscribe(¬ificationFilterHandles, subscriptionId); if (SA_AIS_OK != errorCode) { - fprintf(stderr, "saNtfNotificationSubscribe failed - %s\n", error_output(errorCode)); + fprintf(stderr, "ntftool_saNtfNotificationSubscribe failed - %s\n", error_output(errorCode)); return errorCode; } freeNtfFilter (¬ificationFilterHandles.alarmFilterHandle); @@ -421,9 +421,9 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } - error = saNtfInitialize(&ntfHandle, &ntfCallbacks, &version); + error = ntftool_saNtfInitialize(&ntfHandle, &ntfCallbacks, &version); if (SA_AIS_OK != error) { - fprintf(stderr, "saNtfInitialize failed - %s\n", error_output(error)); + fprintf(stderr, "ntftool_saNtfInitialize failed - %s\n", error_output(error)); exit(EXIT_FAILURE); } @@ -445,7 +445,7 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } - error = saNtfNotificationUnsubscribe(my_subscriptionId); + error = ntftool_saNtfNotificationUnsubscribe(my_subscriptionId); if (SA_AIS_OK != error) { fprintf(stderr, "waitForNotifications failed - %s\n", error_output(error)); exit(EXIT_FAILURE); diff --git a/osaf/tools/safntf/src/ntfclient.c b/osaf/tools/safntf/src/ntfclient.c --- a/osaf/tools/safntf/src/ntfclient.c +++ b/osaf/tools/safntf/src/ntfclient.c @@ -34,6 +34,8 @@ void ntfsvtools_exitIfFalse(const char * } } +unsigned int gl_apiTolerance = 900; // in seconds +unsigned int gl_apiRetry = 3; // in seconds static const char *sa_probable_cause_list[] = { "SA_NTF_ADAPTER_ERROR", "SA_NTF_APPLICATION_SUBSYSTEM_FAILURE", @@ -1126,3 +1128,159 @@ void set_nType_for_eType(SaNtfNotificati *nType = SA_NTF_TYPE_SECURITY_ALARM; } + +/** + * @brief wrapper of saNtfInitialize + */ +SaAisErrorT ntftool_saNtfInitialize(SaNtfHandleT *ntfHandle, const SaNtfCallbacksT *ntfCallbacks, SaVersionT *version) +{ + int curRetryTime = 0; + SaAisErrorT rc; + do { + rc = saNtfInitialize(ntfHandle, ntfCallbacks, version); + if (rc == SA_AIS_ERR_TRY_AGAIN) { + sleep(gl_apiRetry); + curRetryTime += gl_apiRetry; + } else + break; + } while (curRetryTime < gl_apiTolerance); + + return rc; +} + +/** + * @brief wrapper of saNtfDispatch + */ +SaAisErrorT ntftool_saNtfDispatch(SaNtfHandleT ntfHandle, SaDispatchFlagsT dispatchFlags) +{ + int curRetryTime = 0; + SaAisErrorT rc; + do { + rc = saNtfDispatch(ntfHandle, dispatchFlags); + if (rc == SA_AIS_ERR_TRY_AGAIN) { + sleep(gl_apiRetry); + curRetryTime += gl_apiRetry; + } else + break; + } while (curRetryTime < gl_apiTolerance); + + return rc; +} + +/** + * @brief wrapper of saNtfNotificationSend + */ +SaAisErrorT ntftool_saNtfNotificationSend(SaNtfNotificationHandleT notificationHandle) +{ + int curRetryTime = 0; + SaAisErrorT rc; + do { + rc = saNtfNotificationSend(notificationHandle); + if (rc == SA_AIS_ERR_TRY_AGAIN) { + sleep(gl_apiRetry); + curRetryTime += gl_apiRetry; + } else + break; + } while (curRetryTime < gl_apiTolerance); + + return rc; +} + +/** + * @brief wrapper of saNtfNotificationSubscribe + */ +SaAisErrorT ntftool_saNtfNotificationSubscribe(const SaNtfNotificationTypeFilterHandlesT *notificationFilterHandles, + SaNtfSubscriptionIdT subscriptionId) +{ + int curRetryTime = 0; + SaAisErrorT rc; + do { + rc = saNtfNotificationSubscribe(notificationFilterHandles, subscriptionId); + if (rc == SA_AIS_ERR_TRY_AGAIN) { + sleep(gl_apiRetry); + curRetryTime += gl_apiRetry; + } else + break; + } while (curRetryTime < gl_apiTolerance); + + return rc; +} + +/** + * @brief wrapper of saNtfNotificationUnsubscribe + */ +SaAisErrorT ntftool_saNtfNotificationUnsubscribe(SaNtfSubscriptionIdT subscriptionId) +{ + int curRetryTime = 0; + SaAisErrorT rc; + do { + rc = saNtfNotificationUnsubscribe(subscriptionId); + if (rc == SA_AIS_ERR_TRY_AGAIN) { + sleep(gl_apiRetry); + curRetryTime += gl_apiRetry; + } else + break; + } while (curRetryTime < gl_apiTolerance); + + return rc; +} + +/** + * @brief wrapper of saNtfNotificationReadIntialize + */ +SaAisErrorT ntftool_saNtfNotificationReadInitialize(SaNtfSearchCriteriaT searchCriteria, + const SaNtfNotificationTypeFilterHandlesT *notificationFilterHandles, + SaNtfReadHandleT *readHandle) +{ + int curRetryTime = 0; + SaAisErrorT rc; + do { + rc = saNtfNotificationReadInitialize(searchCriteria, notificationFilterHandles, readHandle); + if (rc == SA_AIS_ERR_TRY_AGAIN) { + sleep(gl_apiRetry); + curRetryTime += gl_apiRetry; + } else + break; + } while (curRetryTime < gl_apiTolerance); + + return rc; +} + +/** + * @brief wrapper of saNtfNotificationReadNext + */ +SaAisErrorT ntftool_saNtfNotificationReadNext(SaNtfReadHandleT readHandle, + SaNtfSearchDirectionT searchDirection, SaNtfNotificationsT *notification) +{ + int curRetryTime = 0; + SaAisErrorT rc; + do { + rc = saNtfNotificationReadNext(readHandle, searchDirection, notification); + if (rc == SA_AIS_ERR_TRY_AGAIN) { + sleep(gl_apiRetry); + curRetryTime += gl_apiRetry; + } else + break; + } while (curRetryTime < gl_apiTolerance); + + return rc; +} + +/** + * @brief wrapper of saNtfNotificationReadFinalize + */ +SaAisErrorT ntftool_saNtfNotificationReadFinalize(SaNtfReadHandleT readhandle) +{ + int curRetryTime = 0; + SaAisErrorT rc; + do { + rc = saNtfNotificationReadFinalize(readhandle); + if (rc == SA_AIS_ERR_TRY_AGAIN) { + sleep(gl_apiRetry); + curRetryTime += gl_apiRetry; + } else + break; + } while (curRetryTime < gl_apiTolerance); + + return rc; +} ------------------------------------------------------------------------------ _______________________________________________ Opensaf-devel mailing list Opensaf-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensaf-devel