Ejemplo n.º 1
0
Archivo: adm.c Proyecto: brnrc/ion-dtn
void adm_add_ctrl_run(uint8_t *mid_str, adm_ctrl_fn run)
{
	uint32_t used = 0;
	mid_t *mid = NULL;
	adm_ctrl_t *entry = NULL;

	DTNMP_DEBUG_ENTRY("adm_add_ctrl_run","(%lld, %lld)", mid_str, run);

	if((mid_str == NULL) || (run == NULL))
	{
		DTNMP_DEBUG_ERR("adm_add_ctrl_run","Bad Args.", NULL);
		DTNMP_DEBUG_EXIT("adm_add_ctrl_run","->.",NULL);
		return;
	}

	if((mid = mid_deserialize(mid_str, ADM_MID_ALLOC, &used)) == NULL)
	{
		char *tmp = utils_hex_to_string(mid_str, ADM_MID_ALLOC);
		DTNMP_DEBUG_ERR("adm_add_ctrl_run","Can't deserialized MID %s", tmp);
		MRELEASE(tmp);
		DTNMP_DEBUG_EXIT("adm_add_ctrl_run","->.",NULL);
		return;
	}

	if((entry = adm_find_ctrl(mid)) == NULL)
	{
		char *tmp = mid_to_string(mid);
		DTNMP_DEBUG_ERR("adm_add_ctrl_run","Can't find control for MID %s", tmp);
		MRELEASE(tmp);
	}
	else
	{
		entry->run = run;
	}

	mid_release(mid);

	DTNMP_DEBUG_EXIT("adm_add_ctrl_run","->.",NULL);
}
Ejemplo n.º 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;
}