Пример #1
0
void RemoteNetworkView::GenerateNewPositionActor(IEventDataPtr pEventData) {
	char response[4];
	std::string httpinmsg;
	IEventDataPtr pResponseHttpEvent(CREATE_EVENT(EventData_ResponseHTTP::sk_EventType));

	std::shared_ptr<EventData_GetNewPositionActor> pCastEventData = std::static_pointer_cast<EventData_GetNewPositionActor>(pEventData);

	std::string name = pCastEventData->VGetActorName();
	unsigned int ip = pCastEventData->VGetIp();

	//look for actor data in actor manager by ip / actor name
	StrongActorPtr pActor = m_ActorManager->GetActorByName(ip, name);

	if (pActor == NULL) {
		_itoa_s(http_response_code_t::NOTFOUND, response, 10);
		httpinmsg.append(response);
		std::istrstream in(httpinmsg.c_str(), httpinmsg.size());
		pResponseHttpEvent->VDeserialize(in);
		IEventManager::Get()->VTriggerEvent(pResponseHttpEvent);
		return;
	}

	// calculate new coord random (great AI !)
	int random = rand();
	Vec3 newPosition;
	newPosition.x = random % 512;
	newPosition.y = random % 480;
	newPosition.z = 0;

	pActor->SetPosition(newPosition);
	// send back all data	
	GetActor(pEventData);
}
Пример #2
0
void RemoteNetworkView::ForwardEvent(IEventDataPtr pEventData) {
	std::string httpinmsg;
	if (!pEventData) {
		GCC_ERROR("Event Invalid");
		return;
	}
	int socketId = pEventData->VGetSocketId();

	std::ostrstream out;

	pEventData->VSerialize(out);
	out << std::ends;

	IPacket *packetBack = NULL;
	if (!strncmp("HTTP", &out.rdbuf()->str()[0], 4)) {
		packetBack = GCC_NEW HTTPPacket(out.rdbuf()->str());
	}
	else {
		//TODO create binary packet
	}
	std::shared_ptr<IPacket> ipBack(packetBack);
	printf("RemoteNetworkView Forward Event socket:%d %s\n", socketId, pEventData->GetName());
	g_pSocketManager->Send(socketId, ipBack);

	if (!strncmp("HTTP", &out.rdbuf()->str()[0], 4)) {
		IEventDataPtr pCloseSocketHttpEvent(CREATE_EVENT(EventData_CloseSocketHTTP::sk_EventType));
		char* id = new char[100];
		sprintf_s(id, 100, "%d", socketId);
		httpinmsg.append(id);
		std::istrstream in(httpinmsg.c_str(), httpinmsg.size());
		pCloseSocketHttpEvent->VDeserialize(in);
		IEventManager::Get()->VQueueEvent(pCloseSocketHttpEvent);
	}
}
Пример #3
0
Файл: ed.c Проект: jollywho/nav
void ed_direct_rename(Plugin *caller, char *source, char *dest)
{
    log_msg("ED", "ed_direct_rename");
    log_msg("ED", "%s,  %s", source, dest);

    /* use source as dest. get source from buffer */
    if (!dest) {
        dest = source;
        source = NULL;
    }

    varg_T src;
    if (source) {
        src.argc = 1;
        src.argv = malloc(sizeof(char*));
        src.argv[0] = strdup(source);
    }
    else if (!ed_pull_source(&src, caller))
        return;

    log_msg("ED", "%s,  %s", source, dest);
    ed_data *data = malloc(sizeof(ed_data));
    data->src = src;
    data->dst = strdup(dest);

    CREATE_EVENT(eventq(), ed_direct_prompt, 1, data);
}
Пример #4
0
void RemoteEventSocket::CreateEvent(std::istrstream& in) {
    EventType eventType;
    in >> eventType;
    IEventDataPtr pEvent(CREATE_EVENT(eventType));

    if (pEvent) {
        pEvent->VDeserialize(in);
        IEventManager::Get()->VQueueEvent(pEvent);
    } else {
        GCC_ERROR("ERROR Unknown event type from remote: 0x%s\n", ToStr(eventType, 16).c_str());
    }
}
Пример #5
0
void RemoteNetworkView::GetActor(IEventDataPtr pEventData) {
	char response[4];
	std::string httpinmsg;
	IEventDataPtr pResponseHttpEvent(CREATE_EVENT(EventData_ResponseHTTP::sk_EventType));

	std::shared_ptr<EventData_GetActor> pCastEventData = std::static_pointer_cast<EventData_GetActor>(pEventData);
	std::string name = pCastEventData->VGetActorName();
	unsigned int ip = pCastEventData->VGetIp();
	pResponseHttpEvent->VSetSocketId(pEventData->VGetSocketId());
	pResponseHttpEvent->VSetIp(ip);
	//look for actor data in actor manager by ip / actor name
	StrongActorPtr pActor = m_ActorManager->GetActorByName(ip, name);

	if (pActor == NULL) {
		_itoa_s(http_response_code_t::NOTFOUND, response,10);
		httpinmsg.append(response);
		std::istrstream in(httpinmsg.c_str(),httpinmsg.size());
		pResponseHttpEvent->VDeserialize(in);
		IEventManager::Get()->VTriggerEvent(pResponseHttpEvent);
	}
	else {
		// Better (de-)serialize Actor with streams
		std::string buffer;
		_itoa_s(http_response_code_t::OK, response, 10);
		buffer.append(response);
		buffer.append(" ");

		char* id = new char[10];
		sprintf_s(id, 10, "%d", pActor->GetId());
		buffer.append(id);
		buffer.append("#");
		buffer.append(pActor->GetName());
		buffer.append("#");
		Vec3 position = pActor->GetPosition();
		char *xpos = new char[10];
		sprintf_s(xpos, 10, "%.3f", position.x);
		buffer.append(xpos);
		buffer.append("#");
		char *ypos = new char[10];
		sprintf_s(ypos, 10, "%.3f", position.y);
		buffer.append(ypos);
		buffer.append("#");
		char *zpos = new char[10];
		sprintf_s(zpos, 10, "%.3f", position.z);
		buffer.append(zpos);	
		buffer.push_back('\0');
		// when found, send answer	
		std::istrstream in(buffer.c_str(), buffer.size());
		pResponseHttpEvent->VDeserialize(in);
		IEventManager::Get()->VTriggerEvent(pResponseHttpEvent);
	}
}
Пример #6
0
Файл: main.c Проект: juli1/ospat
int main ()
{

	PROCESS_ATTRIBUTE_TYPE tattr;
	RETURN_CODE_TYPE ret;

	printf("	part1 - Main thread\n");

	CREATE_EVENT (pok_arinc653_events_names[0], &(pok_arinc653_events_ids[0]), &(ret));
	printf("	Event %s created! EVENT ID: %u, ret: %d \n", pok_arinc653_events_names[0], pok_arinc653_events_ids[0], ret);

	tattr.PERIOD = 400;
	tattr.BASE_PRIORITY = 10;
	tattr.ENTRY_POINT = thr1_1_job;
	CREATE_PROCESS (&(tattr), &(arinc_threads[1]), &(ret));

	tattr.PERIOD = APERIODIC_PROCESS;
	tattr.BASE_PRIORITY = 9;
	tattr.ENTRY_POINT = thr1_1bis_job;
	CREATE_PROCESS (&(tattr), &(arinc_threads[2]), &(ret));

	tattr.PERIOD = 400;
	tattr.BASE_PRIORITY = 8;
	tattr.ENTRY_POINT = thr1_3_job;
	CREATE_PROCESS (&(tattr), &(arinc_threads[3]), &(ret));

	tattr.PERIOD = APERIODIC_PROCESS;
	tattr.BASE_PRIORITY = 7;
	tattr.ENTRY_POINT = thr1_3bis_job;
	CREATE_PROCESS (&(tattr), &(arinc_threads[4]), &(ret));


	START (arinc_threads[1],&(ret));
	START (arinc_threads[2],&(ret));
	START (arinc_threads[3],&(ret));
	START (arinc_threads[4],&(ret));

	SET_PARTITION_MODE (NORMAL, &(ret));
	return 0;
}