Exemplo n.º 1
0
SaAisErrorT ntfsv_alloc_and_copy_not(ntfsv_send_not_req_t *dest, const ntfsv_send_not_req_t *src)
{
	SaAisErrorT rc;
	TRACE_ENTER2("ntfsv_send_not_req_t* src = %p", src);
	TRACE("notificationType = %x", (unsigned int)src->notificationType);
	switch (src->notificationType) {
	case SA_NTF_TYPE_ALARM:
		rc = ntfsv_alloc_ntf_alarm(&dest->notification.alarm,
					   src->notification.alarm.numSpecificProblems,
					   src->notification.alarm.numMonitoredAttributes,
					   src->notification.alarm.numProposedRepairActions);
		if (rc != SA_AIS_OK)
			goto done;
		rc = ntfsv_alloc_ntf_header(&dest->notification.alarm.notificationHeader,
					    src->notification.alarm.notificationHeader.numCorrelatedNotifications,
					    src->notification.alarm.notificationHeader.lengthAdditionalText,
					    src->notification.alarm.notificationHeader.numAdditionalInfo);
		if (rc != SA_AIS_OK)
			goto done;
		ntfsv_copy_ntf_alarm(&dest->notification.alarm, &src->notification.alarm);
		break;
	case SA_NTF_TYPE_OBJECT_CREATE_DELETE:
		rc = ntfsv_alloc_ntf_obj_create_del(&dest->notification.objectCreateDelete,
						    src->notification.objectCreateDelete.numAttributes);
		if (rc != SA_AIS_OK)
			goto done;
		rc = ntfsv_alloc_ntf_header(&dest->notification.objectCreateDelete.notificationHeader,
					    src->notification.objectCreateDelete.
					    notificationHeader.numCorrelatedNotifications,
					    src->notification.objectCreateDelete.
					    notificationHeader.lengthAdditionalText,
					    src->notification.objectCreateDelete.notificationHeader.numAdditionalInfo);
		if (rc != SA_AIS_OK)
			goto done;
		ntfsv_copy_ntf_obj_cr_del(&dest->notification.objectCreateDelete,
					  &src->notification.objectCreateDelete);
		break;
	case SA_NTF_TYPE_ATTRIBUTE_CHANGE:
		rc = ntfsv_alloc_ntf_attr_change(&dest->notification.attributeChange,
						 src->notification.attributeChange.numAttributes);
		if (rc != SA_AIS_OK)
			goto done;
		rc = ntfsv_alloc_ntf_header(&dest->notification.attributeChange.notificationHeader,
					    src->notification.attributeChange.
					    notificationHeader.numCorrelatedNotifications,
					    src->notification.attributeChange.notificationHeader.lengthAdditionalText,
					    src->notification.attributeChange.notificationHeader.numAdditionalInfo);
		if (rc != SA_AIS_OK)
			goto done;
		ntfsv_copy_ntf_attr_change(&dest->notification.attributeChange, &src->notification.attributeChange);
		break;
	case SA_NTF_TYPE_STATE_CHANGE:
		rc = ntfsv_alloc_ntf_state_change(&dest->notification.stateChange,
						  src->notification.stateChange.numStateChanges);
		if (rc != SA_AIS_OK)
			goto done;
		rc = ntfsv_alloc_ntf_header(&dest->notification.stateChange.notificationHeader,
					    src->notification.stateChange.notificationHeader.numCorrelatedNotifications,
					    src->notification.stateChange.notificationHeader.lengthAdditionalText,
					    src->notification.stateChange.notificationHeader.numAdditionalInfo);
		if (rc != SA_AIS_OK)
			goto done;
		ntfsv_copy_ntf_state_change(&dest->notification.stateChange, &src->notification.stateChange);
		break;
	case SA_NTF_TYPE_SECURITY_ALARM:
		rc = ntfsv_alloc_ntf_security_alarm(&dest->notification.securityAlarm);
		if (rc != SA_AIS_OK)
			goto done;
		rc = ntfsv_alloc_ntf_header(&dest->notification.securityAlarm.notificationHeader,
					    src->notification.securityAlarm.
					    notificationHeader.numCorrelatedNotifications,
					    src->notification.securityAlarm.notificationHeader.lengthAdditionalText,
					    src->notification.securityAlarm.notificationHeader.numAdditionalInfo);
		if (rc != SA_AIS_OK)
			goto done;
		ntfsv_copy_ntf_security_alarm(&dest->notification.securityAlarm, &src->notification.securityAlarm);
		break;
	default:
		TRACE("notificationType not valid");
		rc = SA_AIS_ERR_FAILED_OPERATION;
	}
	rc = ntfsv_v_data_cp(&dest->variable_data, &src->variable_data);
	TRACE_LEAVE();
 done:
	return rc;
}
Exemplo n.º 2
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;
}