Exemple #1
0
void XeenEngine::gameLoop() {
	// Main game loop
	while (isLoadPending() || !shouldExit()) {
		if (isLoadPending()) {
			// Load any pending savegame
			int saveSlot = _loadSaveSlot;
			_loadSaveSlot = -1;
			_saves->loadGameState(saveSlot);
			_interface->drawParty(true);
		}

		_map->cellFlagLookup(_party->_mazePosition);
		if (_map->_currentIsEvent) {
			_gameMode = (GameMode)_scripts->checkEvents();
			if (isLoadPending())
				continue;
			if (shouldExit())
				return;
		}
		_party->giveTreasure();

		// Main user interface handler for waiting for and processing user input
		_interface->perform();

		if (_party->_dead)
			break;
	}
}
bool ResourceMonitorAndroid::run()
{
	Watch w;

	HAGGLE_DBG("Running resource monitor\n");

        if (uevent_init() == -1) {
                HAGGLE_ERR("Could not open uevent socket\n");
                return false;
        }

	while (!shouldExit()) {
		int ret;

		w.reset();
                
                int ueventIndex = w.add(uevent_fd);

		ret = w.wait();
                
		if (ret == Watch::ABANDONED) {
			break;
		} else if (ret == Watch::FAILED) {
			HAGGLE_ERR("Wait on objects failed\n");
			break;
		}

                if (w.isSet(ueventIndex)) {
                        uevent_read();
                }
	}
	return false;
}
Exemple #3
0
/*------------------------------------------------------------------*/
bool AzRgforest::growForest()
{
    clock_t b_time;
    time_begin(&b_time);

    /*---  find the best split  ---*/
    AzTrTsplit best_split;
    searchBestSplit(&best_split);
    if (shouldExit(&best_split)) { /* exit if no more split */
        return true; /* exit */
    }

    /*---  split the node  ---*/
    double w_inc;
    int leaf_nx[2] = {-1,-1};
    const AzRgfTree *tree = splitNode(&best_split, &w_inc, leaf_nx);

    if (lmax_timer.reachedMax(l_num, "AzRgforest: #leaf", out)) {
        return true; /* #leaf reached max; exit */
    }

    /*---  update target  ---*/
    updateTarget(tree, leaf_nx, w_inc);

    time_end(b_time, &search_time);
    return false; /* don't exit */
}
Exemple #4
0
bool SecurityHelper::run()
{	
	HAGGLE_DBG("SecurityHelper running...\n");
	
	while (!shouldExit()) {
		QueueEvent_t qe;
		SecurityTask *task = NULL;
		
		qe = taskQ.retrieve(&task);
		
		switch (qe) {
		case QUEUE_ELEMENT:
			doTask(task);

			// Delete task here or return it with result in private event?
			//delete task;
			break;
		case QUEUE_WATCH_ABANDONED:
			HAGGLE_DBG("SecurityHelper instructed to exit...\n");
			return false;
		default:
			HAGGLE_ERR("Unknown security task queue return value\n");
		}
	}
	return false;
}
Exemple #5
0
/**
* @internal
* @brief Allows user to draw and update the application
*/
void Application::drawApp()
{
	// Loop while window is open
	while( !shouldExit() )
	{
        drawOneFrame();
	}
}
Exemple #6
0
	bool Room::go()
	{
		while ( !shouldExit() )
		{
			VALIDATE( onUpdateStart() );

			VALIDATE( update() );
			VALIDATE( render() );

			VALIDATE( onUpdateEnd( kTimeStepMilliseconds ) );
		}

		return true;
	}
bool ConnectivityBluetooth::run()
{
	CoInitializeEx (0, COINIT_MULTITHREADED);

	if (registerSDPService(&sdpRecordHandle) < 0) {
		CM_DBG("WSAGetLastError=%s\n", StrError(WSAGetLastError()));
		fflush(stdout);
		CM_DBG("Could not register SDP service\n");
		return false;
	}

	cancelableSleep(5000);

	while (!shouldExit()) {
		
		bluetoothDiscovery(this);

#define BLUETOOTH_FORCE_DISCOVERABLE_MODE

#ifdef BLUETOOTH_FORCE_DISCOVERABLE_MODE
		DWORD mode;

		if (BthGetMode(&mode) == ERROR_SUCCESS) {
			/* If we are in connectable mode, but
			not discoverable, then we force the
			mode into discoverable. However, we
			honor the radio being in off mode. */
			if (mode == BTH_CONNECTABLE) {
				HAGGLE_DBG("Bluetooth is in connectable mode; forcing discoverable mode\n");
				
				if (BthSetMode(BTH_DISCOVERABLE) != ERROR_SUCCESS) {
					HAGGLE_ERR("Could not switch Bluetooth from connectable to discoverable mode\n");
				}
			}
		}
#endif
		age_interfaces(rootInterface);

		cancelableSleep(TIME_TO_WAIT * 1000);
	}

	return false;
}
bool ResourceMonitorLinux::run()
{
	Watch w;

	HAGGLE_DBG("Running resource monitor\n");

	while (!shouldExit()) {
		int ret;

		w.reset();

		ret = w.wait();

		if (ret < 0) {
			HAGGLE_ERR("Wait on objects failed\n");
			break;
		}
	}
	return false;
}
Exemple #9
0
void AbstractThread::run()
{
	// is the very first since there is a possibility of something being altered there
	onStart();

	int exceptions = 0;
	bool lastWasException = false;
	m_terminateRequested = false;

	for (;;)
	{
		bool gotException = false;

		//	report me being alive if I am being checked for status
		if( m_hangCheck != 0 )
		{
			m_hangCheck = 0;
		}

		try
		{
			tick();

			// ensure this is recorded as 'idle' time (ideally this should
			// be in tick() but we cannot guarantee it to be called there
			CurrentProfileData.Start(PROFILE_IDLE);
		}
		catch( const CException& e )
		{
			gotException = true;
			g_Log.CatchEvent(&e, "%s::tick", getName());
			CurrentProfileData.Count(PROFILE_STAT_FAULTS, 1);
		}
		catch( ... )
		{
			gotException = true;
			g_Log.CatchEvent(NULL, "%s::tick", getName());
			CurrentProfileData.Count(PROFILE_STAT_FAULTS, 1);
		}

		if( gotException )
		{
			if( lastWasException )
			{
				exceptions++;
			}
			else
			{
				lastWasException = true;
				exceptions = 0;
			}
			if( exceptions >= EXCEPTIONS_ALLOWED )
			{
				// a bad thing really happened. ALL previous EXCEPTIONS_ALLOWED ticks resulted in exception
				// almost for sure we have looped somewhere and have no way to get out from this situation
				// probably a thread restart can fix the problems
				// but there is no real need to restart a thread, we will just simulate a thread restart,
				// notifying a subclass like we have been just restarted, so it will restart it's operations
				g_Log.Event(LOGL_CRIT, "'%s' thread raised too many exceptions, restarting...\n", getName());
				onStart();
				lastWasException = false;
			}
		}
		else
		{
			lastWasException = false;
		}

		if( shouldExit() )
			break;

		m_sleepEvent.wait(m_tickPeriod);
	}
}
unsigned Connection::threadProc( void *param ) {
	while( !shouldExit(10) ) {
		processImpl();
	}
	return 0;
}
bool ConnectivityBluetooth::run()
{
	unsigned char uuid[] = HAGGLE_BLUETOOTH_SDP_UUID;
#define MAX_PROPERTY_KEYS 10
	CFStringRef keys[MAX_PROPERTY_KEYS];
	CFStringRef values[MAX_PROPERTY_KEYS];
	long i;
	CFDictionaryRef dict;
	IOBluetoothSDPServiceRecordRef serviceRecordRef;
	UInt16 tmp;

	isInquiring = false;
	
	inqRef = IOBluetoothDeviceInquiryCreateWithCallbackRefCon(this);

	if (!inqRef) {
		CM_DBG("Failed to create inquiry reference\n");
		return false;
	}	
	
	// Set up SDP keys:
	i = 0;
	keys[i] = CFSTR("0001 - ServiceClassIDList");
	values[i] = (CFStringRef)CFArrayCreateMutable(kCFAllocatorDefault, 0, NULL);

	CFArrayAppendValue((CFMutableArrayRef) values[i], IOBluetoothSDPUUIDCreateWithBytes(uuid, sizeof(uuid)));
	i++;
	keys[i] = CFSTR("0004 - Protocol descriptor list");
	values[i] = (CFStringRef)CFArrayCreateMutable(kCFAllocatorDefault, 0, NULL);
	{
		CFMutableArrayRef tmp_array;
		
		tmp_array = CFArrayCreateMutable(kCFAllocatorDefault, 0, NULL);
		CFArrayAppendValue((CFMutableArrayRef) values[i], tmp_array);
		tmp = htons(0x0100); // L2CAP
		CFArrayAppendValue(tmp_array, IOBluetoothSDPUUIDCreateWithBytes(&tmp, sizeof(tmp)));
	}
	{
		CFMutableArrayRef tmp_array;

		tmp_array = CFArrayCreateMutable(kCFAllocatorDefault, 0, NULL);
		CFArrayAppendValue((CFMutableArrayRef) values[i], tmp_array);
		tmp = htons(0x0003);	// RFCOMM
		CFArrayAppendValue(tmp_array, IOBluetoothSDPUUIDCreateWithBytes(&tmp, sizeof(tmp)));
		tmp = RFCOMM_DEFAULT_CHANNEL;	// Channel
		CFNumberRef n = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt16Type, &tmp);
		CFArrayAppendValue(tmp_array, n);
	}
	i++;
	if (i > MAX_PROPERTY_KEYS)
		CM_DBG("CODING ERROR: overran end of array in " "ConnectivityBluetoothMacOSX.cpp\n");

	// Create dictionary:
	dict = CFDictionaryCreate(kCFAllocatorDefault, (const void **) keys, (const void **) values, i, NULL, NULL);

	// Create service
	if (IOBluetoothAddServiceDict(dict, &serviceRecordRef) == kIOReturnSuccess) {
		// Get service handle:
		IOBluetoothSDPServiceRecordGetServiceRecordHandle(serviceRecordRef, &mServerHandle);
		IOBluetoothObjectRelease(serviceRecordRef);

#if 0
		// DEBUG: output dictionary as XML:
		CFDataRef data;

		data = CFPropertyListCreateXMLData(kCFAllocatorDefault, dict);
		CM_DBG("XML: %s\n", CFDataGetBytePtr(data));
		CFRelease(data);
#endif
	} else {
		CM_DBG("Unable to add service.\n");
		mServerHandle = NULL;
	}

	CFRelease(dict);
	// Need to release these:
	for (i--; i >= 0; i--)
		CFRelease(values[i]);

	while (!shouldExit()) {

		doInquiry();
		
		cancelableSleep(TIME_TO_WAIT_MSECS);

		age_interfaces(rootInterface);
	}
	return false;
}
/*
 General overview of thread loop:

 The forwarding module waits for tasks that are input into the task queue (taskQ) by the
 forwarding manager. Once a task is available, the forwarding module will read it and
 execute any tasks. The module may return results of the task to the forwarding manager
 by using a private event. In that case, it passes the original task object back to the
 manager with any results embedded. Sometimes it might just be enough to signal that a
 a task is complete.

 */
bool ForwarderAsynchronous::run(void)
{
    while (!shouldExit()) {
        ForwardingTask *task = NULL;

        switch (taskQ.retrieve(&task)) {
        default:
            if (task)
                delete task;
            break;
        case QUEUE_TIMEOUT:
            /*
             This shouldn't happen - but we make sure the module doesn't
             break if it does. This means that it has either taken an
             exceptionally long time to get the state string, or that it
             is not coming. Either one is problematic.
             */
            HAGGLE_DBG("WARNING: timeout occurred in forwarder task queue.\n");
            break;
        case QUEUE_ELEMENT:
            switch (task->getType()) {
            case FWD_TASK_NEW_ROUTING_INFO:
                newRoutingInformation(getRoutingInformation(task->getDataObject()));
                break;
            case FWD_TASK_NEW_NEIGHBOR:
                _newNeighbor(task->getNode());
                break;
            case FWD_TASK_END_NEIGHBOR:
                _endNeighbor(task->getNode());
                break;
            case FWD_TASK_GENERATE_TARGETS:
                _generateTargetsFor(task->getNode());
                break;

            case FWD_TASK_GENERATE_DELEGATES:
                _generateDelegatesFor(task->getDataObject(), task->getNode(), task->getNodeList());
                break;
            case FWD_TASK_GENERATE_ROUTING_INFO_DATA_OBJECT:
                task->setDataObject(createRoutingInformationDataObject());
                addEvent(new Event(eventType, task));
                task = NULL;
                break;
#ifdef DEBUG
            case FWD_TASK_PRINT_RIB:
                _printRoutingTable();
                break;
#endif
            case FWD_TASK_CONFIG:
                _onForwarderConfig(*task->getConfig());
                break;
            case FWD_TASK_QUIT:
                /*
                	When the forwarding module is asked to quit,
                	the forwarding manager should save any of its
                	state. Return this state to the manager in a
                	callback.
                 */
                if (eventType) {
                    task->setRepositoryEntryList(new RepositoryEntryList());

                    if (task->getRepositoryEntryList()) {
                        getSaveState(*task->getRepositoryEntryList());
                    }
                }
                // Always send the callback to ensure the manager is notified
                // that the module is done.
                HAGGLE_DBG("Forwarding module %s QUITs\n", getName());
                addEvent(new Event(eventType, task));
                task = NULL;

                cancel();
                break;
            }
            break;
        }
        if (task)
            delete task;
    }
    return false;
}