Beispiel #1
0
/******************************************************************************
 *
 * \par Function Name: midcol_copy
 *
 * \par Purpose: Copies a MID collection
 *
 * \retval  NULL - Failure
 *         !NULL - The copied MID collection
 *
 * \param[in]  mids  MID collection to be copied.
 *
 * \par Notes:
 *		1. This is a deep copy.
 *
 * Modification History:
 *  MM/DD/YY  AUTHOR         DESCRIPTION
 *  --------  ------------   ---------------------------------------------
 *  11/14/12  E. Birrane     Initial implementation,
 *****************************************************************************/
Lyst midcol_copy(Lyst mids)
{
	Lyst result = NULL;
	LystElt elt;
	mid_t *cur_mid = NULL;
	mid_t *new_mid = NULL;

	DTNMP_DEBUG_ENTRY("midcol_copy","(%#llx)",(unsigned long) mids);

	/* Step 0: Sanity Check. */
	if(mids == NULL)
	{
		DTNMP_DEBUG_ERR("midcol_copy","Bad Args.",NULL);
		DTNMP_DEBUG_EXIT("midcol_copy","->NULL.",NULL);
		return NULL;
	}

	/* Build the Lyst. */
	if((result = lyst_create()) == NULL)
	{
		DTNMP_DEBUG_ERR("midcol_copy","Unable to create lyst.",NULL);
		DTNMP_DEBUG_EXIT("midcol_copy","->NULL.",NULL);
		return NULL;
	}

	/* Walking copy. */
	int success = 1;
	for(elt = lyst_first(mids); elt; elt = lyst_next(elt))
	{
		cur_mid = (mid_t *) lyst_data(elt);
		if((new_mid = mid_copy(cur_mid)) == NULL)
		{
			DTNMP_DEBUG_ERR("midcol_copy","Fsiled to copy MID.",NULL);
			midcol_destroy(&result);

			DTNMP_DEBUG_EXIT("midcol_copy","->NULL.",NULL);
			return NULL;
		}
		else
		{
			lyst_insert_last(result,mid_copy(cur_mid));
		}
	}

	DTNMP_DEBUG_EXIT("midcol_copy","->%#llx.",(unsigned long) result);
	return result;
}
Beispiel #2
0
ctrl_exec_t* ctrl_create(time_t time, mid_t *mid, eid_t sender)
{
	ctrl_exec_t *result = NULL;

	AMP_DEBUG_ENTRY("ctrl_create","(%d, 0x%x)",
			          time, (unsigned long) mid);

	/* Step 0: Sanity Check. */
	if(mid == NULL)
	{
		AMP_DEBUG_ERR("ctrl_create","Bad Args.",NULL);
		AMP_DEBUG_EXIT("ctrl_create","->NULL",NULL);
		return NULL;
	}

	/* Step 1: Allocate the message. */
	if((result = (ctrl_exec_t*)STAKE(sizeof(ctrl_exec_t))) == NULL)
	{
		AMP_DEBUG_ERR("ctrl_create","Can't alloc %d bytes.",
				        sizeof(ctrl_exec_t));
		AMP_DEBUG_EXIT("ctrl_create","->NULL",NULL);
		return NULL;
	}

	/* Step 2: Find the adm_ctrl_t associated with this control. */
	if((result->adm_ctrl = adm_find_ctrl(mid)) == NULL)
	{
		AMP_DEBUG_ERR("ctrl_create","Can't find ADM ctrl.",NULL);
		SRELEASE(result);
		AMP_DEBUG_EXIT("ctrl_create","->NULL",NULL);
		return NULL;
	}

	/* Step 3: Copy the sender information. */
	memcpy(&(result->sender), &sender, sizeof(eid_t));

	/* Step 4: Calculate time information for the control. */

	result->time = time;
	result->mid = mid_copy(mid);

    if(result->time <= AMP_RELATIVE_TIME_EPOCH)
    {
    	/* Step 4a: If relative time, that is # seconds. */
    	result->countdown_ticks = result->time;
    }
    else
    {
    	/*
    	 * Step 4b: If absolute time, # seconds if difference
    	 * from now until then.
    	 */
    	result->countdown_ticks = (result->time - getUTCTime());
    }

    /* Step 5: Populate dynamic parts of the control. */
	result->status = CONTROL_ACTIVE;

	AMP_DEBUG_EXIT("ctrl_create","->0x%x",result);
	return result;
}
Beispiel #3
0
/*
 * We need to find out a description for the entry so we can print it out.
 * So, if entry is <RPT MID> <int d1><int d2><int d3> we need to match the items
 * to elements of the report definition.
 *
 */
void ui_print_entry(rpt_entry_t *entry, uvast *mid_sizes, uvast *data_sizes)
{
	LystElt elt = NULL;
	def_gen_t *cur_def = NULL;
	uint8_t del_def = 0;

	if((entry == NULL) || (mid_sizes == NULL) || (data_sizes == NULL))
	{
		AMP_DEBUG_ERR("ui_print_entry","Bad Args.", NULL);
		return;
	}

	/* Step 1: Calculate sizes...*/
    *mid_sizes = *mid_sizes + entry->id->raw_size;

    for(elt = lyst_first(entry->contents->datacol); elt; elt = lyst_next(elt))
    {
    	blob_t *cur = lyst_data(elt);
        *data_sizes = *data_sizes + cur->length;
    }
    *data_sizes = *data_sizes + entry->contents->hdr.length;

	/* Step 1: Print the MID associated with the Entry. */
    printf(" (");
    ui_print_mid(entry->id);
	printf(") has %d values.", entry->contents->hdr.length);


    /*
     * Step 2: Try and find the metadata associated with each
     *         value in the TDC. Since the TDC is already typed, the
     *         needed meta-data information is simply the
     *         "name" of the data.
     *
     *         i Only computed data definitions, reports, and macros
     *         need names. Literals, controls, and atomic data do
     *         not (currently) define extra meta-data for their
     *         definitions.
     *
     *         \todo: Consider printing names for each return
     *         value from a control.
     */

    cur_def = NULL;

	if(MID_GET_FLAG_ID(entry->id->flags) == MID_ATOMIC)
	{
		adm_datadef_t *ad_entry = adm_find_datadef(entry->id);

		/* Fake a def_gen_t for now. */
		if(ad_entry != NULL)
		{
	    	Lyst tmp = lyst_create();
	    	lyst_insert(tmp,mid_copy(ad_entry->mid));
	    	cur_def = def_create_gen(mid_copy(ad_entry->mid), ad_entry->type, tmp);
	    	del_def = 1;
		}
	}
	else if(MID_GET_FLAG_ID(entry->id->flags) == MID_COMPUTED)
	{
		var_t *cd = NULL;
	    if(MID_GET_FLAG_ISS(entry->id->flags) == 0)
	    {
	    	cd = var_find_by_id(gAdmComputed, NULL, entry->id);
	    }
	    else
	    {
	    	cd = var_find_by_id(gMgrVDB.compdata, &(gMgrVDB.compdata_mutex), entry->id);
	    }

	    // Fake a def_gen just for this CD item.
	    if(cd != NULL)
	    {
	    	Lyst tmp = lyst_create();
	    	lyst_insert(tmp,mid_copy(cd->id));
	    	cur_def = def_create_gen(mid_copy(cd->id), cd->value.type, tmp);
	    	del_def = 1;
	    }
	}
	else if(MID_GET_FLAG_ID(entry->id->flags) == MID_REPORT)
	{
	    if(MID_GET_FLAG_ISS(entry->id->flags) == 0)
	    {
	    	cur_def = def_find_by_id(gAdmRpts, NULL, entry->id);
	    }
	    else
	    {
	    	cur_def = def_find_by_id(gMgrVDB.reports, &(gMgrVDB.reports_mutex), entry->id);
	    }
	}
	else if(MID_GET_FLAG_ID(entry->id->flags) == MID_MACRO)
	{
	    if(MID_GET_FLAG_ISS(entry->id->flags) == 0)
	    {
	    	cur_def = def_find_by_id(gAdmMacros, NULL, entry->id);
	    }
	    else
	    {
	    	cur_def = def_find_by_id(gMgrVDB.macros, &(gMgrVDB.macros_mutex), entry->id);
	    }

	}

	/* Step 3: Print the TDC holding data for the entry. */
    ui_print_tdc(entry->contents, cur_def);

    if(del_def)
    {
    	def_release_gen(cur_def);
    }
    return;
}