/**
 * 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 saNtfObjectCreateDeleteNotificationAllocate_02(void)
{
	int errors = 0;

    SaNtfObjectCreateDeleteNotificationT myNotification;

    saNotificationAllocationParamsT myNotificationAllocationParams;
    saNotificationFilterAllocationParamsT myNotificationFilterAllocationParams;
    saNotificationParamsT myNotificationParams;

    fillInDefaultValues(&myNotificationAllocationParams,
                        &myNotificationFilterAllocationParams,
                        &myNotificationParams);

    ntfHandle = 0;
    rc = saNtfObjectCreateDeleteNotificationAllocate(
        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.numObjectAttributes,
        /* use default allocation size */
        myNotificationAllocationParams.variableDataSize);
	if(rc != SA_AIS_ERR_BAD_HANDLE) {
		errors++;
	}

    free(myNotificationParams.additionalText);
    safassert(saNtfInitialize(&ntfHandle, &ntfCallbacks, &ntfVersion), SA_AIS_OK);
    safassert(saNtfFinalize(ntfHandle), SA_AIS_OK);

    rc = saNtfObjectCreateDeleteNotificationAllocate(
        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.numObjectAttributes,
        /* 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 saNtfObjectCreateDeleteNotificationAllocate_03(void)
{
    saNotificationAllocationParamsT myNotificationAllocationParams;
    saNotificationFilterAllocationParamsT myNotificationFilterAllocationParams;
    saNotificationParamsT myNotificationParams;

    fillInDefaultValues(&myNotificationAllocationParams,
                        &myNotificationFilterAllocationParams,
                        &myNotificationParams);

    safassert(saNtfInitialize(&ntfHandle, &ntfCallbacks, &ntfVersion), SA_AIS_OK);
    rc = saNtfObjectCreateDeleteNotificationAllocate(
        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.numObjectAttributes,
        /* use default allocation size */
        myNotificationAllocationParams.variableDataSize);

    free(myNotificationParams.additionalText);
    safassert(saNtfFinalize(ntfHandle), SA_AIS_OK);
    test_validate(rc, SA_AIS_ERR_INVALID_PARAM);
}
void saNtfObjectCreateDeleteNotificationAllocate_01(void)
{
    SaNtfObjectCreateDeleteNotificationT myNotification;

    saNotificationAllocationParamsT myNotificationAllocationParams;
    saNotificationFilterAllocationParamsT myNotificationFilterAllocationParams;
    saNotificationParamsT myNotificationParams;

    fillInDefaultValues(&myNotificationAllocationParams,
                        &myNotificationFilterAllocationParams,
                        &myNotificationParams);

    safassert(saNtfInitialize(&ntfHandle, &ntfCallbacks, &ntfVersion), SA_AIS_OK);
    rc = saNtfObjectCreateDeleteNotificationAllocate(
        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.numObjectAttributes,
        /* use default allocation size */
        myNotificationAllocationParams.variableDataSize);

    /* Event type */
    *(myNotification.notificationHeader.eventType) =
        SA_NTF_OBJECT_CREATION;

    /* event time to be set automatically to current
    time by saNtfNotificationSend */
    *(myNotification.notificationHeader.eventTime) =
        myNotificationParams.eventTime;

    /* Set Notification Object */
    myNotification.notificationHeader.notificationObject->length =
        myNotificationParams.notificationObject.length;
    (void)memcpy(myNotification.notificationHeader.notificationObject->value,
                 myNotificationParams.notificationObject.value,
                 myNotificationParams.notificationObject.length);

    /* Set Notifying Object */
    myNotification.notificationHeader.notifyingObject->length =
        myNotificationParams.notifyingObject.length;
    (void)memcpy(myNotification.notificationHeader.notifyingObject->value,
                 myNotificationParams.notifyingObject.value,
                 myNotificationParams.notifyingObject.length);

    /* set Notification Class Identifier */
    /* vendor id 33333 is not an existing SNMP enterprise number.
    Just an example */
    myNotification.notificationHeader.notificationClassId->vendorId =
        myNotificationParams.notificationClassId.vendorId;

    /* sub id of this notification class within "name space" of vendor ID */
    myNotification.notificationHeader.notificationClassId->majorId =
        myNotificationParams.notificationClassId.majorId;
    myNotification.notificationHeader.notificationClassId->minorId =
        myNotificationParams.notificationClassId.minorId;

    /* set additional text and additional info */
    (void)strncpy(myNotification.notificationHeader.additionalText,
                  myNotificationParams.additionalText,
                  myNotificationAllocationParams.lengthAdditionalText);

    /* Set source indicator */
    myNotification.sourceIndicator =
        &myNotificationParams.objectCreateDeleteSourceIndicator;

    /* Set objectAttibutes */
    myNotification.objectAttributes[0].attributeId =
        myNotificationParams.objectAttributes[0].attributeId;
    myNotification.objectAttributes[0].attributeType =
        myNotificationParams.objectAttributes[0].attributeType;
    myNotification.objectAttributes[0].attributeValue.int32Val =
        myNotificationParams.objectAttributes[0].attributeValue.int32Val;

    free(myNotificationParams.additionalText);
    safassert(saNtfNotificationFree(myNotification.notificationHandle), SA_AIS_OK);
    safassert(saNtfFinalize(ntfHandle), SA_AIS_OK);
    test_validate(rc, SA_AIS_OK);
}
示例#4
0
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,
								 &notification->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(&notification_hdl_rec->variable_data, &not_cbk->variable_data);
			ncshm_give_hdl(notification->notification.objectCreateDeleteNotification.notificationHandle);
			ntfsv_copy_ntf_obj_cr_del(&notification->notification.objectCreateDeleteNotification,
						  &not_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,
							      &notification->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(&notification_hdl_rec->variable_data, &not_cbk->variable_data);
			ncshm_give_hdl(notification->notification.attributeChangeNotification.notificationHandle);
			ntfsv_copy_ntf_attr_change(&notification->notification.attributeChangeNotification,
						   &not_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,
							  &notification->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(&notification_hdl_rec->variable_data, &not_cbk->variable_data);
			ncshm_give_hdl(notification->notification.stateChangeNotification.notificationHandle);
			ntfsv_copy_ntf_state_change(&notification->notification.stateChangeNotification,
						    &not_cbk->notification.stateChange);
			pthread_mutex_unlock(&ntfa_cb.cb_lock);
		}
		break;
	case SA_NTF_TYPE_ALARM:
		rc = saNtfAlarmNotificationAllocate(hdl_rec->local_hdl,
						    &notification->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(&notification_hdl_rec->variable_data, &not_cbk->variable_data);
			ncshm_give_hdl(notification->notification.alarmNotification.notificationHandle);
			ntfsv_copy_ntf_alarm(&notification->notification.alarmNotification,
					     &not_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,
							    &notification->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(&notification_hdl_rec->variable_data, &not_cbk->variable_data);
			ncshm_give_hdl(notification->notification.securityAlarmNotification.notificationHandle);
			ntfsv_copy_ntf_security_alarm(&notification->notification.securityAlarmNotification,
						      &not_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;
}