/** * Test that return value SA_AIS_ERR_BAD_HANDLE works * * Strategy: Set the handle to zero or invalid number * Create a handle and then destroy it. */ void saNtfStateChangeNotificationAllocate_02(void) { int errors = 0; SaNtfStateChangeNotificationT myNotification; saNotificationAllocationParamsT myNotificationAllocationParams; saNotificationFilterAllocationParamsT myNotificationFilterAllocationParams; saNotificationParamsT myNotificationParams; fillInDefaultValues(&myNotificationAllocationParams, &myNotificationFilterAllocationParams, &myNotificationParams); rc = saNtfStateChangeNotificationAllocate( 0, /* handle to Notification Service instance */ &myNotification, /* number of correlated notifications */ myNotificationAllocationParams.numCorrelatedNotifications, /* length of additional text */ myNotificationAllocationParams.lengthAdditionalText, /* number of additional info items*/ myNotificationAllocationParams.numAdditionalInfo, /* number of state changes */ myNotificationAllocationParams.numAttributes, /* use default allocation size */ myNotificationAllocationParams.variableDataSize); if(rc != SA_AIS_ERR_BAD_HANDLE) { errors++; } safassert(saNtfInitialize(&ntfHandle, &ntfSendCallbacks, &ntfVersion) , SA_AIS_OK); safassert(saNtfFinalize(ntfHandle) , SA_AIS_OK); rc = saNtfStateChangeNotificationAllocate( ntfHandle, /* handle to Notification Service instance */ &myNotification, /* number of correlated notifications */ myNotificationAllocationParams.numCorrelatedNotifications, /* length of additional text */ myNotificationAllocationParams.lengthAdditionalText, /* number of additional info items*/ myNotificationAllocationParams.numAdditionalInfo, /* number of state changes */ myNotificationAllocationParams.numAttributes, /* use default allocation size */ myNotificationAllocationParams.variableDataSize); if(rc != SA_AIS_ERR_BAD_HANDLE) { errors++; } rc = (errors == 0)? SA_AIS_OK: SA_AIS_ERR_BAD_HANDLE; test_validate(rc, SA_AIS_OK); }
/** * Test that the return value SA_AIS_ERR_INVALID_PARAM works * * Strategy: */ void saNtfStateChangeNotificationAllocate_03(void) { saNotificationAllocationParamsT myNotificationAllocationParams; saNotificationFilterAllocationParamsT myNotificationFilterAllocationParams; saNotificationParamsT myNotificationParams; fillInDefaultValues(&myNotificationAllocationParams, &myNotificationFilterAllocationParams, &myNotificationParams); safassert(saNtfInitialize(&ntfHandle, &ntfSendCallbacks, &ntfVersion) , SA_AIS_OK); rc = saNtfStateChangeNotificationAllocate( ntfHandle, /* handle to Notification Service instance */ NULL, /* number of correlated notifications */ myNotificationAllocationParams.numCorrelatedNotifications, /* length of additional text */ myNotificationAllocationParams.lengthAdditionalText, /* number of additional info items*/ myNotificationAllocationParams.numAdditionalInfo, /* number of state changes */ myNotificationAllocationParams.numAttributes, /* use default allocation size */ myNotificationAllocationParams.variableDataSize); safassert(saNtfFinalize(ntfHandle) , SA_AIS_OK); test_validate(rc, SA_AIS_ERR_INVALID_PARAM); }
static uint32_t sendStateChangeNotificationClms(CLMS_CB * clms_cb, SaNameT node_name, SaUint8T *add_text, SaUint16T majorId, SaUint16T minorId, uint32_t sourceIndicator, SaUint32T stateId, SaUint32T newState) { uint32_t status = NCSCC_RC_FAILURE; SaNtfStateChangeNotificationT myStateNotification; status = saNtfStateChangeNotificationAllocate(clms_cb->ntf_hdl, /* handle to Notification Service instance */ &myStateNotification, /* number of correlated notifications */ 0, /* length of additional text */ ADDITION_TEXT_LENGTH, /* number of additional info items */ 0, /* number of state changes */ 1, /* use default allocation size */ 0); if (status != SA_AIS_OK) { /* log the error code here */ return NCSCC_RC_FAILURE; } fill_ntf_header_part_clms(&myStateNotification.notificationHeader, SA_NTF_OBJECT_STATE_CHANGE, node_name, add_text, majorId, minorId, CLMS_NTF_SENDER); *(myStateNotification.sourceIndicator) = sourceIndicator; myStateNotification.changedStates->stateId = stateId; myStateNotification.changedStates->oldStatePresent = SA_FALSE; myStateNotification.changedStates->newState = newState; status = saNtfNotificationSend(myStateNotification.notificationHandle); if (status != SA_AIS_OK) { saNtfNotificationFree(myStateNotification.notificationHandle); /* log the error code here */ return NCSCC_RC_FAILURE; } status = saNtfNotificationFree(myStateNotification.notificationHandle); if (status != SA_AIS_OK) { /* log the error code here */ return NCSCC_RC_FAILURE; } return status; }
static SaAisErrorT ntfa_alloc_callback_notification(SaNtfNotificationsT *notification, ntfsv_send_not_req_t *not_cbk, ntfa_client_hdl_rec_t *hdl_rec) { SaAisErrorT rc = SA_AIS_OK; ntfa_notification_hdl_rec_t *notification_hdl_rec; notification->notificationType = not_cbk->notificationType; switch (not_cbk->notificationType) { case SA_NTF_TYPE_OBJECT_CREATE_DELETE: TRACE_2("type: SA_NTF_TYPE_OBJECT_CREATE_DELETE"); rc = saNtfObjectCreateDeleteNotificationAllocate(hdl_rec->local_hdl, ¬ification->notification. objectCreateDeleteNotification, not_cbk->notification.objectCreateDelete. notificationHeader.numCorrelatedNotifications, not_cbk->notification.objectCreateDelete. notificationHeader.lengthAdditionalText, not_cbk->notification.objectCreateDelete. notificationHeader.numAdditionalInfo, not_cbk->notification.objectCreateDelete.numAttributes, SA_NTF_ALLOC_SYSTEM_LIMIT); if (SA_AIS_OK == rc) { pthread_mutex_lock(&ntfa_cb.cb_lock); notification_hdl_rec = ncshm_take_hdl(NCS_SERVICE_ID_NTFA, notification->notification.objectCreateDeleteNotification. notificationHandle); if (notification_hdl_rec == NULL) { pthread_mutex_unlock(&ntfa_cb.cb_lock); TRACE("ncshm_take_hdl notificationHandle failed"); rc = SA_AIS_ERR_BAD_HANDLE; break; } /* to be able to delelte cbk_notification in saNtfNotificationFree */ notification_hdl_rec->cbk_notification = notification; rc = ntfsv_v_data_cp(¬ification_hdl_rec->variable_data, ¬_cbk->variable_data); ncshm_give_hdl(notification->notification.objectCreateDeleteNotification.notificationHandle); ntfsv_copy_ntf_obj_cr_del(¬ification->notification.objectCreateDeleteNotification, ¬_cbk->notification.objectCreateDelete); pthread_mutex_unlock(&ntfa_cb.cb_lock); } break; case SA_NTF_TYPE_ATTRIBUTE_CHANGE: TRACE_2("type: SA_NTF_TYPE_ATTRIBUTE_CHANGE"); rc = saNtfAttributeChangeNotificationAllocate(hdl_rec->local_hdl, ¬ification->notification.attributeChangeNotification, not_cbk->notification.attributeChange.notificationHeader. numCorrelatedNotifications, not_cbk->notification.attributeChange.notificationHeader. lengthAdditionalText, not_cbk->notification.attributeChange.notificationHeader. numAdditionalInfo, not_cbk->notification.attributeChange.numAttributes, SA_NTF_ALLOC_SYSTEM_LIMIT); if (SA_AIS_OK == rc) { pthread_mutex_lock(&ntfa_cb.cb_lock); notification_hdl_rec = ncshm_take_hdl(NCS_SERVICE_ID_NTFA, notification->notification.attributeChangeNotification. notificationHandle); if (notification_hdl_rec == NULL) { pthread_mutex_unlock(&ntfa_cb.cb_lock); TRACE("ncshm_take_hdl notificationHandle failed"); rc = SA_AIS_ERR_BAD_HANDLE; break; } /* to be able to delelte cbk_notification in saNtfNotificationFree */ notification_hdl_rec->cbk_notification = notification; rc = ntfsv_v_data_cp(¬ification_hdl_rec->variable_data, ¬_cbk->variable_data); ncshm_give_hdl(notification->notification.attributeChangeNotification.notificationHandle); ntfsv_copy_ntf_attr_change(¬ification->notification.attributeChangeNotification, ¬_cbk->notification.attributeChange); pthread_mutex_unlock(&ntfa_cb.cb_lock); } break; case SA_NTF_TYPE_STATE_CHANGE: TRACE_2("type: SA_NTF_TYPE_STATE_CHANGE"); rc = saNtfStateChangeNotificationAllocate(hdl_rec->local_hdl, ¬ification->notification.stateChangeNotification, not_cbk->notification.stateChange.notificationHeader. numCorrelatedNotifications, not_cbk->notification.stateChange.notificationHeader. lengthAdditionalText, not_cbk->notification.stateChange.notificationHeader. numAdditionalInfo, not_cbk->notification.stateChange.numStateChanges, SA_NTF_ALLOC_SYSTEM_LIMIT); if (SA_AIS_OK == rc) { pthread_mutex_lock(&ntfa_cb.cb_lock); notification_hdl_rec = ncshm_take_hdl(NCS_SERVICE_ID_NTFA, notification->notification.stateChangeNotification. notificationHandle); if (notification_hdl_rec == NULL) { pthread_mutex_unlock(&ntfa_cb.cb_lock); TRACE("ncshm_take_hdl notificationHandle failed"); rc = SA_AIS_ERR_BAD_HANDLE; break; } /* to be able to delelte cbk_notification in saNtfNotificationFree */ notification_hdl_rec->cbk_notification = notification; rc = ntfsv_v_data_cp(¬ification_hdl_rec->variable_data, ¬_cbk->variable_data); ncshm_give_hdl(notification->notification.stateChangeNotification.notificationHandle); ntfsv_copy_ntf_state_change(¬ification->notification.stateChangeNotification, ¬_cbk->notification.stateChange); pthread_mutex_unlock(&ntfa_cb.cb_lock); } break; case SA_NTF_TYPE_ALARM: rc = saNtfAlarmNotificationAllocate(hdl_rec->local_hdl, ¬ification->notification.alarmNotification, not_cbk->notification.alarm. notificationHeader.numCorrelatedNotifications, not_cbk->notification.alarm.notificationHeader.lengthAdditionalText, not_cbk->notification.alarm.notificationHeader.numAdditionalInfo, not_cbk->notification.alarm.numSpecificProblems, not_cbk->notification.alarm.numMonitoredAttributes, not_cbk->notification.alarm.numProposedRepairActions, SA_NTF_ALLOC_SYSTEM_LIMIT); if (SA_AIS_OK == rc) { pthread_mutex_lock(&ntfa_cb.cb_lock); notification_hdl_rec = ncshm_take_hdl(NCS_SERVICE_ID_NTFA, notification->notification. alarmNotification.notificationHandle); if (notification_hdl_rec == NULL) { pthread_mutex_unlock(&ntfa_cb.cb_lock); TRACE("ncshm_take_hdl notificationHandle failed"); rc = SA_AIS_ERR_BAD_HANDLE; break; } /* to be able to delelte cbk_notification in saNtfNotificationFree */ notification_hdl_rec->cbk_notification = notification; rc = ntfsv_v_data_cp(¬ification_hdl_rec->variable_data, ¬_cbk->variable_data); ncshm_give_hdl(notification->notification.alarmNotification.notificationHandle); ntfsv_copy_ntf_alarm(¬ification->notification.alarmNotification, ¬_cbk->notification.alarm); pthread_mutex_unlock(&ntfa_cb.cb_lock); } break; case SA_NTF_TYPE_SECURITY_ALARM: TRACE_2("type: SA_NTF_TYPE_SECURITY_ALARM"); rc = saNtfSecurityAlarmNotificationAllocate(hdl_rec->local_hdl, ¬ification->notification.securityAlarmNotification, not_cbk->notification.securityAlarm.notificationHeader. numCorrelatedNotifications, not_cbk->notification.securityAlarm.notificationHeader. lengthAdditionalText, not_cbk->notification.securityAlarm.notificationHeader. numAdditionalInfo, SA_NTF_ALLOC_SYSTEM_LIMIT); if (SA_AIS_OK == rc) { pthread_mutex_lock(&ntfa_cb.cb_lock); notification_hdl_rec = ncshm_take_hdl(NCS_SERVICE_ID_NTFA, notification->notification.securityAlarmNotification. notificationHandle); if (notification_hdl_rec == NULL) { pthread_mutex_unlock(&ntfa_cb.cb_lock); TRACE("ncshm_take_hdl notificationHandle failed"); rc = SA_AIS_ERR_BAD_HANDLE; break; } /* to be able to delelte cbk_notification in saNtfNotificationFree */ notification_hdl_rec->cbk_notification = notification; rc = ntfsv_v_data_cp(¬ification_hdl_rec->variable_data, ¬_cbk->variable_data); ncshm_give_hdl(notification->notification.securityAlarmNotification.notificationHandle); ntfsv_copy_ntf_security_alarm(¬ification->notification.securityAlarmNotification, ¬_cbk->notification.securityAlarm); pthread_mutex_unlock(&ntfa_cb.cb_lock); } break; default: LOG_ER("Unkown notification type"); rc = SA_AIS_ERR_INVALID_PARAM; } return rc; }