Exemplo n.º 1
0
PRT_VALUE *P_FUN_StartTimer_IMPL(PRT_MACHINEINST *context)
{
	PRT_MACHINEINST_PRIV *p_tmp_mach_priv = (PRT_MACHINEINST_PRIV *)context;
	PRT_VALUE *p_tmp_ret = NULL;
	PRT_FUNSTACK_INFO p_tmp_frame;

	// pop frame
	PrtPopFrame(p_tmp_mach_priv, &p_tmp_frame);

	PRT_VALUE* timerMachineId = p_tmp_frame.locals[0];
	PRT_MACHINEINST* timerMachine = PrtGetMachine(context->process, timerMachineId);
	TimerContext *timerContext = (TimerContext *)timerMachine->extContext;

	int timeout_value = p_tmp_frame.locals[1]->valueUnion.nt;
	
	SleepMs(timeout_value);

	PRT_VALUE *ev = PrtMkEventValue(P_EVENT_TIMEOUT);
	PRT_MACHINEINST* clientMachine = PrtGetMachine(context->process, timerContext->client);
	PrtSend(context, clientMachine, ev, context->id, PRT_FALSE);
	PrtFreeValue(ev);

	// free the frame
	PrtFreeLocals(p_tmp_mach_priv, &p_tmp_frame);
	return NULL;
}
Exemplo n.º 2
0
	PRT_VALUE *P_FUN_GetSystemTime_IMPL(PRT_MACHINEINST *context)
	{
		PRT_MACHINEINST_PRIV *p_tmp_mach_priv = (PRT_MACHINEINST_PRIV *)context;
		PRT_FUNSTACK_INFO p_tmp_frame;
		PrtPopFrame(p_tmp_mach_priv, &p_tmp_frame);

		int ms = GetTickCount();

		PrtFreeLocals(p_tmp_mach_priv, &p_tmp_frame);
		return PrtMkIntValue(ms);
	}
Exemplo n.º 3
0
PRT_VALUE *P_FUN_TestMachine_GetPassword_IMPL(PRT_MACHINEINST *context)
{
	PRT_MACHINEINST_PRIV *p_tmp_mach_priv = (PRT_MACHINEINST_PRIV *)context;
	PRT_VALUE *p_tmp_ret = NULL;
	PRT_FUNSTACK_INFO p_tmp_frame;
	//remm to pop frame
	PrtPopFrame(p_tmp_mach_priv, &p_tmp_frame);
	//remm to free the frame
	PrtFreeLocals(p_tmp_mach_priv, &p_tmp_frame);

	return PrtMkDefaultValue(P_GEND_TYPE_StringType);
}
Exemplo n.º 4
0
	PRT_VALUE *P_FUN_CommanderMachine_SendCommandToPx4_IMPL(PRT_MACHINEINST *context)
	{
		PRT_MACHINEINST_PRIV *p_tmp_mach_priv = (PRT_MACHINEINST_PRIV *)context;
		PRT_FUNSTACK_INFO p_tmp_frame;
		PrtPopFrame(p_tmp_mach_priv, &p_tmp_frame);

		PRT_VALUE* caller = p_tmp_frame.locals[0];

		PRT_VALUE* cmdId = p_tmp_frame.locals[2];
		int cmd = 0;
		if (cmdId->discriminator == PRT_VALUE_KIND_INT)
		{
			cmd = PrtPrimGetInt(cmdId);
		}

		PRT_VALUE* confirmValue = p_tmp_frame.locals[1];
		bool confirm = false;
		if (confirmValue->discriminator == PRT_VALUE_KIND_BOOL)
		{
			confirm = (PrtPrimGetBool(confirmValue) == PRT_TRUE);
		}

		float floats[7] = { 0,0,0,0,0,0,0 };

		// gray the remaining 7 arguments and convert them to float values.
		for (int i = 3; i < 3 + 7; i++)
		{
			PRT_VALUE* arg = p_tmp_frame.locals[i];
			float value = PrtGetFloat32(arg);
			floats[i - 3] = value;
		}

		EventTrace(PProgram, 0, "Sending command: %d, with args (%f,%f,%f,%f,%f,%f,%f)\n", cmd, floats[0], floats[1], floats[2], floats[3], floats[4], floats[5], floats[6]);

		SendCommand(cmd, confirm, floats[0], floats[1], floats[2], floats[3], floats[4], floats[5], floats[6]);

		PrtFreeLocals(p_tmp_mach_priv, &p_tmp_frame);
		return NULL;
	}
Exemplo n.º 5
0
void
PrtCleanupMachine(
_Inout_ PRT_MACHINEINST_PRIV			*context
)
{
	if (context->isHalted)
		return;

	if (context->eventQueue.events != NULL)
	{
		PRT_EVENT *queue = context->eventQueue.events;
		PRT_UINT32 head = context->eventQueue.headIndex;
		PRT_UINT32 tail = context->eventQueue.tailIndex;
		PRT_UINT32 count = 0;

		while (count < context->eventQueue.size && head < context->eventQueue.eventsSize)
		{
			if (queue[head].payload != NULL)
			{
				PrtFreeValue(queue[head].payload);
			}
			if (queue[head].trigger != NULL) {
				PrtFreeValue(queue[head].trigger);
			}
			head++;
			count++;
		}
		head = 0;
		while (count < context->eventQueue.size)
		{
			if (queue[head].payload != NULL)
			{
				PrtFreeValue(queue[head].payload);
			}
			if (queue[head].trigger != NULL) {
				PrtFreeValue(queue[head].trigger);
			}
			head++;
			count++;
		}

		PrtFree(context->eventQueue.events);
	}

	for (int i = 0; i < context->callStack.length; i++)
	{
		PRT_STATESTACK_INFO *info = &context->callStack.stateStack[i];
		if (info->inheritedActionSetCompact != NULL)
		{
			PrtFree(info->inheritedActionSetCompact);
		}
		if (info->inheritedDeferredSetCompact != NULL)
		{
			PrtFree(info->inheritedDeferredSetCompact);
		}
	}

	for (int i = 0; i < context->funStack.length; i++)
	{
		PRT_FUNSTACK_INFO *info = &context->funStack.funs[i];
		PrtFreeLocals(context, info);
	}

	if (context->currentActionSetCompact != NULL)
	{
		PrtFree(context->currentActionSetCompact);
	}

	if (context->currentDeferredSetCompact != NULL)
	{
		PrtFree(context->currentDeferredSetCompact);
	}

	if (context->inheritedActionSetCompact != NULL)
	{
		PrtFree(context->inheritedActionSetCompact);
	}

	if (context->inheritedDeferredSetCompact != NULL)
	{
		PrtFree(context->inheritedDeferredSetCompact);
	}

	if (context->varValues != NULL)
	{
		UINT i;
		PRT_MACHINEDECL *mdecl = &(context->process->program->machines[context->instanceOf]);

		for (i = 0; i < mdecl->nVars; i++) {
			PrtFreeValue(context->varValues[i]);
		}
		PrtFree(context->varValues);
	}

	if (context->stateMachineLock != NULL)
	{
		PrtDestroyMutex(context->stateMachineLock);
	}

	if (context->extContext != NULL)
		context->process->program->machines[context->instanceOf].extDtorFun((PRT_MACHINEINST *)context);
	PrtFreeValue(context->id);

	PrtFreeValue(context->currentTrigger);
	PrtFreeValue(context->currentPayload);

	if (context->recvMap != NULL)
	{
		PrtFreeValue(context->recvMap);
	}
}