library/src/events/BP-Events.cc
// This takes an existing event and attempts to check it into a queue (works similarly to BP_EventMgrCreateEvent).
This takes an existing event and attempts to check it into a queue (works similarly to BP_EventMgrCreateEvent).
This takes an existing event and attempts to check it into a queue ( works similarly to BP_EventMgrCreateEvent ) .
BP_ERROR_T BP_EventMgrCheckinProcessedEvent
(
	P_BP_EVENT_WORKER       worker,
	P_BP_EVENT              event_to_checkin,
	BP_EVENT_MESSAGE_IN_OUT checkin_to_queue,
	BP_EVENT_PRIORITY       event_priority
)
{
	if(!worker)
		return ERR_FAILURE;
	if(!worker->event_manager)
		return ERR_FAILURE;
	if(!checkin_to_queue)
		return ERR_FAILURE;
	if(!event_priority)
		return ERR_FAILURE;
	if(!event_to_checkin)
		return ERR_FAILURE;
	BP_GHT_ENTER_CRITICAL_SECTION;
	P_BP_EVENT_MANAGER mgr = (P_BP_EVENT_MANAGER) worker->event_manager;
	if(!BP_StringIsReasonablePrintableString(worker->name, bpstrlen(worker->name), BP_FALSE, BP_FALSE))
		return ERR_FAILURE;
	if(!BP_StringIsReasonablePrintableString(mgr->name,    bpstrlen(mgr->name),    BP_FALSE, BP_FALSE))
		return ERR_FAILURE;
	if(!BP_StringIsReasonablePrintableString(event_to_checkin->name, bpstrlen(event_to_checkin->name), BP_FALSE, BP_FALSE))
		return ERR_FAILURE;
	char * priority_selected = NULL;
	switch(event_priority)
	{
		case BP_EVENT_PRIORITY_VERY_LOW:
			priority_selected = "BP_EVENT_PRIORITY_VERY_LOW";
			break;
		case BP_EVENT_PRIORITY_LOW:
			priority_selected = "BP_EVENT_PRIORITY_LOW";
			break;
		case BP_EVENT_PRIORITY_MID_NORMAL:
			priority_selected = "BP_EVENT_PRIORITY_MID_NORMAL";
			break;
		case BP_EVENT_PRIORITY_NORMAL:
			priority_selected = "BP_EVENT_PRIORITY_NORMAL";
			break;
		case BP_EVENT_PRIORITY_MID_HIGH:
			priority_selected = "BP_EVENT_PRIORITY_MID_HIGH";
			break;
		case BP_EVENT_PRIORITY_HIGH:
			priority_selected = "BP_EVENT_PRIORITY_HIGH";
			break;
		case BP_EVENT_PRIORITY_SYSTEM:
			priority_selected = "BP_EVENT_PRIORITY_SYSTEM";
			break;
		case BP_EVENT_PRIORITY_CRITICAL_SYSTEM:
			priority_selected = "BP_EVENT_PRIORITY_CRITICAL_SYSTEM";
			break;
		default:
			BP_EVENTS_SEM_UNLOCK(mgr->lock);
			BP_GHT_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	}
	if(!priority_selected)
	{
		BP_EVENTS_SEM_UNLOCK(mgr->lock);
		BP_GHT_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	}
	char * table_path_actual[10] = {0};
	BP_HASH_TABLE_TRAVERSAL_PATH table_path = (char **) &table_path_actual;
	table_path[0] = "system";
	table_path[1] = "event_managment";
	table_path[2] = mgr->name;
	switch(checkin_to_queue)
	{
		case BP_EVENT_MESSAGES_IN:
			table_path[3] = "events_in";
			break;
		case BP_EVENT_MESSAGES_OUT:
			table_path[3] = "events_out";
			break;
		default:
			BP_EVENTS_SEM_UNLOCK(mgr->lock);
			BP_GHT_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	}
	table_path[4] = priority_selected;
	table_path[5] = NULL;
	if
	(
		BP_HashRegAddDataToTableByPath
		(
			NULL,
			table_path,
			event_to_checkin->name,
			BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB,
			NULL,
			sizeof(BP_EVENT)
		) != ERR_SUCCESS
	)
	{
		BP_EVENTS_SEM_UNLOCK(mgr->lock);
		BP_GHT_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	}
	table_path[5] = event_to_checkin->name;
	table_path[6] = NULL;
	P_BP_HASH_TABLE_KEYED_ENTRY new_entry = BP_HashRegLookupTableEntryByPath
	(
		NULL,
		table_path
	);
	if(!new_entry)
	{
		BP_EVENTS_SEM_UNLOCK(mgr->lock);
		BP_GHT_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(ERR_FAILURE);
	}
	P_BP_EVENT new_event = (P_BP_EVENT) new_entry->data;
	memcpy(new_event, event_to_checkin, sizeof(BP_EVENT));
	BP_GHT_LEAVE_CRITICAL_SECTION;
	return ERR_SUCCESS;
}
BP_ERROR_T BP_EventMgrCheckinProcessedEvent ( P_BP_EVENT_WORKER worker , P_BP_EVENT event_to_checkin , BP_EVENT_MESSAGE_IN_OUT checkin_to_queue , BP_EVENT_PRIORITY event_priority ) { if ( ! worker ) return ERR_FAILURE ; if ( ! worker -> event_manager ) return ERR_FAILURE ; if ( ! checkin_to_queue ) return ERR_FAILURE ; if ( ! event_priority ) return ERR_FAILURE ; if ( ! event_to_checkin ) return ERR_FAILURE ; BP_GHT_ENTER_CRITICAL_SECTION ; P_BP_EVENT_MANAGER mgr = ( P_BP_EVENT_MANAGER ) worker -> event_manager ; if ( ! BP_StringIsReasonablePrintableString ( worker -> name , bpstrlen ( worker -> name ) , BP_FALSE , BP_FALSE ) ) return ERR_FAILURE ; if ( ! BP_StringIsReasonablePrintableString ( mgr -> name , bpstrlen ( mgr -> name ) , BP_FALSE , BP_FALSE ) ) return ERR_FAILURE ; if ( ! BP_StringIsReasonablePrintableString ( event_to_checkin -> name , bpstrlen ( event_to_checkin -> name ) , BP_FALSE , BP_FALSE ) ) return ERR_FAILURE ; char * priority_selected = NULL ; switch ( event_priority ) { case BP_EVENT_PRIORITY_VERY_LOW : priority_selected = " " ; break ; case BP_EVENT_PRIORITY_LOW : priority_selected = " " ; break ; case BP_EVENT_PRIORITY_MID_NORMAL : priority_selected = " " ; break ; case BP_EVENT_PRIORITY_NORMAL : priority_selected = " " ; break ; case BP_EVENT_PRIORITY_MID_HIGH : priority_selected = " " ; break ; case BP_EVENT_PRIORITY_HIGH : priority_selected = " " ; break ; case BP_EVENT_PRIORITY_SYSTEM : priority_selected = " " ; break ; case BP_EVENT_PRIORITY_CRITICAL_SYSTEM : priority_selected = " " ; break ; default : BP_EVENTS_SEM_UNLOCK ( mgr -> lock ) ; BP_GHT_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; } if ( ! priority_selected ) { BP_EVENTS_SEM_UNLOCK ( mgr -> lock ) ; BP_GHT_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; } char * table_path_actual [ 10 ] = { 0 } ; BP_HASH_TABLE_TRAVERSAL_PATH table_path = ( char * * ) & table_path_actual ; table_path [ 0 ] = " " ; table_path [ 1 ] = " " ; table_path [ 2 ] = mgr -> name ; switch ( checkin_to_queue ) { case BP_EVENT_MESSAGES_IN : table_path [ 3 ] = " " ; break ; case BP_EVENT_MESSAGES_OUT : table_path [ 3 ] = " " ; break ; default : BP_EVENTS_SEM_UNLOCK ( mgr -> lock ) ; BP_GHT_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; } table_path [ 4 ] = priority_selected ; table_path [ 5 ] = NULL ; if ( BP_HashRegAddDataToTableByPath ( NULL , table_path , event_to_checkin -> name , BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB , NULL , sizeof ( BP_EVENT ) ) != ERR_SUCCESS ) { BP_EVENTS_SEM_UNLOCK ( mgr -> lock ) ; BP_GHT_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; } table_path [ 5 ] = event_to_checkin -> name ; table_path [ 6 ] = NULL ; P_BP_HASH_TABLE_KEYED_ENTRY new_entry = BP_HashRegLookupTableEntryByPath ( NULL , table_path ) ; if ( ! new_entry ) { BP_EVENTS_SEM_UNLOCK ( mgr -> lock ) ; BP_GHT_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( ERR_FAILURE ) ; } P_BP_EVENT new_event = ( P_BP_EVENT ) new_entry -> data ; memcpy ( new_event , event_to_checkin , sizeof ( BP_EVENT ) ) ; BP_GHT_LEAVE_CRITICAL_SECTION ; return ERR_SUCCESS ; }
This takes an existing event and attempts to check it into a queue (works similarly to BP_EventMgrCreateEvent).
This takes an existing event and attempts to check it into a queue ( works similarly to BP_EventMgrCreateEvent ) .
// run basic parameter checks // enter critical section // set the event manager // ensure names are reasonable printables // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Stringify The Event Priority (for lookup) %%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // reference which will contain a static string // switch on the event priority and // Unlock and exit with failure if we cannot // map a priority. // unlock and exit if there is no priority (should never be able // to get here, but still adding the check anyway) // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Attempt to Lookup Events In Table %%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // create table path on the stack // set a reference to the correct type // set the table path // switch to determine which queue to use // use messages in queue // messages out // if it's not one of the message queues, unlock and exit with // failure code. // set the 4th position as the selected priority // force truncation of table // Create new binary blob in the table, name it after the processor // name. // Since we're now looking up an entry, we have to have // an entry name for lookup, so set that here.  Also truncate // next position in path. // attempt to lookup the newly created entry // exit if we couldn't look up the entry // set new event as data // copy in the new event // leave critical section // return indicating success