/*
 * 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;
}
Exemple #2
0
agent_t* mgr_agent_create(eid_t *in_eid)
{
	Object  *entry = NULL;
	agent_t *agent	= NULL;

	DTNMP_DEBUG_ENTRY("mgr_agent_create", "(%s)", in_eid->name);

	/* Step 0: Sanity Check. */
	if(in_eid == NULL)
	{
		DTNMP_DEBUG_ENTRY("mgr_agent_create", "(NULL)", NULL);
		DTNMP_DEBUG_EXIT("mgr_agent_create", "->NULL", NULL);
		return NULL;
	}

	/* Step 1:  Allocate space for the new agent. */
	if((agent = (agent_t*)MTAKE(sizeof(agent_t))) == NULL)
	{
		DTNMP_DEBUG_ERR("mgr_agent_create",
				        "Unable to allocate %d bytes for new agent %s",
				        sizeof(agent_t), in_eid->name);
		DTNMP_DEBUG_EXIT("mgr_agent_create", "->NULL", NULL);
		return NULL;
	}

	/* Step 2: Copy over the name. */
	strncpy(agent->agent_eid.name, in_eid->name, MAX_EID_LEN);

	/* Step 3: Create associated lists. */
	if((agent->custom_defs = lyst_create()) == NULL)
	{
		DTNMP_DEBUG_ERR("mgr_agent_create","Unable to create custom definition lyst for agent %s",
				in_eid->name);
		MRELEASE(agent);

		DTNMP_DEBUG_EXIT("mgr_agent_create","->NULL", NULL);
		return NULL;
	}

	if((agent->reports = lyst_create()) == NULL)
	{
		DTNMP_DEBUG_ERR("mgr_agent_create","Unable to create report lyst for agent %s",
				in_eid->name);
		lyst_destroy(agent->custom_defs);
		MRELEASE(agent);

		DTNMP_DEBUG_EXIT("mgr_agent_create","->NULL", NULL);
		return NULL;
	}

	if(lyst_insert(known_agents, agent) == NULL)
	{
		DTNMP_DEBUG_ERR("mgr_agent_create","Unable to insert agent %s into known agents lyst",
				in_eid->name);
		lyst_destroy(agent->custom_defs);
		lyst_destroy(agent->reports);
		MRELEASE(agent);

		DTNMP_DEBUG_EXIT("mgr_agent_create","->NULL", NULL);
		return NULL;
	}

	initResourceLock(&(agent->mutex));

	DTNMP_DEBUG_EXIT("mgr_agent_create", "->New Agent %s", agent->agent_eid.name);
	return agent;
}