Exemplo n.º 1
0
void InputDaemon::quit()
{
    stopped = true;
    pollResetTimer.stop();

    disconnect(eventWorker, SIGNAL(eventRaised()), this, 0);

    // Wait for SDL to finish. Let worker destructor close SDL.
    // Let InputDaemon destructor close thread instance.
    if (graphical)
    {
        QMetaObject::invokeMethod(eventWorker, "stop");
        QMetaObject::invokeMethod(eventWorker, "quit");
        QMetaObject::invokeMethod(eventWorker, "deleteLater", Qt::BlockingQueuedConnection);
        //QMetaObject::invokeMethod(eventWorker, "deleteLater");
    }
    else
    {
        eventWorker->stop();
        eventWorker->quit();
        delete eventWorker;
    }

    eventWorker = 0;
}
Exemplo n.º 2
0
void SDLEventReader::refresh()
{
    if (sdlIsOpen)
    {
        stop();
        connect(this, SIGNAL(eventRaised()), this, SLOT(secondaryRefresh()));
    }
}
Exemplo n.º 3
0
void SDLEventReader::performWork()
{
    if (sdlIsOpen)
    {
        int status = SDL_WaitEvent(NULL);
        if (status)
        {
            emit eventRaised();
        }
    }
}
Exemplo n.º 4
0
void SDLEventReader::secondaryRefresh()
{
    disconnect(this, SIGNAL(eventRaised()), this, 0);

    if (sdlIsOpen)
    {
        closeSDL();
    }

    initSDL();
}
Exemplo n.º 5
0
void SDLEventReader::performWork()
{
    if (sdlIsOpen)
    {
        //int status = SDL_WaitEvent(NULL);
        int status = CheckForEvents();

        if (status)
        {
            pollRateTimer.stop();
            emit eventRaised();
        }
    }
}
Exemplo n.º 6
0
InputDaemon::InputDaemon(QMap<SDL_JoystickID, InputDevice*> *joysticks,
                         AntiMicroSettings *settings,
                         bool graphical, QObject *parent) :
    QObject(parent),
    pollResetTimer(this)
{
    this->joysticks = joysticks;
    this->stopped = false;
    this->graphical = graphical;
    this->settings = settings;

    eventWorker = new SDLEventReader(joysticks, settings);
    refreshJoysticks();

    sdlWorkerThread = 0;
    if (graphical)
    {
        sdlWorkerThread = new QThread();
        eventWorker->moveToThread(sdlWorkerThread);
    }

    if (graphical)
    {
        connect(sdlWorkerThread, SIGNAL(started()), eventWorker, SLOT(performWork()));
        connect(eventWorker, SIGNAL(eventRaised()), this, SLOT(run()));

        connect(JoyButton::getMouseHelper(), SIGNAL(gamepadRefreshRateUpdated(uint)),
                eventWorker, SLOT(updatePollRate(uint)));

        connect(JoyButton::getMouseHelper(), SIGNAL(gamepadRefreshRateUpdated(uint)),
                this, SLOT(updatePollResetRate(uint)));
        connect(JoyButton::getMouseHelper(), SIGNAL(mouseRefreshRateUpdated(uint)),
                this, SLOT(updatePollResetRate(uint)));

        // Timer in case SDL does not produce an axis event during a joystick
        // poll.
        pollResetTimer.setSingleShot(true);
        pollResetTimer.setInterval(
                    qMax(JoyButton::getMouseRefreshRate(),
                         JoyButton::getGamepadRefreshRate()) + 1);

        connect(&pollResetTimer, SIGNAL(timeout()), this,
                SLOT(resetActiveButtonMouseDistances()));

        //sdlWorkerThread->start(QThread::HighPriority);
        //QMetaObject::invokeMethod(eventWorker, "performWork", Qt::QueuedConnection);
    }
}
Exemplo n.º 7
0
HyvesAPI::HyvesAPI() :
	m_d(new Private()) {
	
	m_d->log = new Logger::Logger("HyvesAPI");
	
	Extender::Extender::instance()->registerObject("hyvesApi", this);
	
	QString baseServer = SettingsManager::SettingsManager::instance()->baseServer();
	
	QString consumerKey;
	QString consumerSecret;
	if (baseServer.endsWith(".vmware")) {
		// development keys
		consumerKey = "N1_oC7UKCi9Kx1dWMiHRqIr9";
		consumerSecret = "N19ZLYKDpyooMnRkXBYJoJgI";
	} else if (baseServer == "hyves.nl") {
		// live keys
		consumerKey = "N19fDUdURoNxyRwGgUEr1QZo";
		consumerSecret = "N18N6EFtM5tktXNAW11z4iuf";
	} else if (baseServer.contains("staging")) {
		// staging keys
		consumerKey = "N1-R29hjojOpgts7Iopp3lKB";
		consumerSecret = "N18UTG3nrp8ifKD5hvDKkXdF";
	}
	
	m_d->genusApis = new GenusApis::GenusApis(consumerKey, consumerSecret);
	m_d->genusApis->setNetworkAccessManager(NetworkAccessManager::instance());
	
	if (baseServer.startsWith("hyves.")) {
		m_d->genusApis->setApiHost("data.hyves-api." + baseServer.mid(6));
	}
	
	connect(m_d->genusApis, SIGNAL(resultReady(int, ResultDocument, bool)),
	                        SLOT(handleResult(int, ResultDocument, bool)));
	
	connect(WindowManager::WindowManager::instance(), SIGNAL(eventRaised(QVariantMap)),
	                                                  SLOT(onEventRaised(QVariantMap)));
}
Exemplo n.º 8
0
InputDaemon::InputDaemon(QHash<SDL_JoystickID, InputDevice*> *joysticks, bool graphical, QObject *parent) :
#else
InputDaemon::InputDaemon(QHash<int, InputDevice*> *joysticks, bool graphical, QObject *parent) :
#endif
    QObject(parent)
{
    this->joysticks = joysticks;
    this->stopped = false;
    this->graphical = graphical;

    eventWorker = new SDLEventReader(joysticks);
    thread = new QThread();
    eventWorker->moveToThread(thread);

    if (graphical)
    {
        connect(thread, SIGNAL(started()), eventWorker, SLOT(performWork()));
        connect(eventWorker, SIGNAL(eventRaised()), this, SLOT(run()));
        thread->start();
    }
    refreshJoysticks();
}

InputDaemon::~InputDaemon()
{
    if (eventWorker)
    {
        quit();
    }

    if (thread)
    {
        thread->quit();
        thread->wait();
        delete thread;
        thread = 0;
    }
}

void InputDaemon::run ()
{
    SDL_Event event;
#ifdef USE_SDL_2
    event.type = SDL_FIRSTEVENT;

#else
    event.type = SDL_NOEVENT;
#endif

    if (!stopped)
    {
        event = eventWorker->getCurrentEvent();

        do
        {
            switch (event.type)
            {
                case SDL_JOYBUTTONDOWN:
                {
#ifdef USE_SDL_2
                    InputDevice *joy = trackjoysticks.value(event.jbutton.which);
#else
                    InputDevice *joy = joysticks->value(event.jbutton.which);
#endif
                    if (joy)
                    {
                        SetJoystick* set = joy->getActiveSetJoystick();
                        JoyButton *button = set->getJoyButton(event.jbutton.button);

                        if (button)
                        {
                            button->joyEvent(true);
                        }
                    }

                    break;
                }

                case SDL_JOYBUTTONUP:
                {
#ifdef USE_SDL_2
                    InputDevice *joy = trackjoysticks.value(event.jbutton.which);
#else
                    InputDevice *joy = joysticks->value(event.jbutton.which);
#endif
                    if (joy)
                    {
                        SetJoystick* set = joy->getActiveSetJoystick();
                        JoyButton *button = set->getJoyButton(event.jbutton.button);

                        if (button)
                        {
                            button->joyEvent(false);
                        }
                    }

                    break;
                }

                case SDL_JOYAXISMOTION:
                {
#ifdef USE_SDL_2
                    InputDevice *joy = trackjoysticks.value(event.jaxis.which);
#else
                    InputDevice *joy = joysticks->value(event.jaxis.which);
#endif
                    if (joy)
                    {
                        SetJoystick* set = joy->getActiveSetJoystick();
                        JoyAxis *axis = set->getJoyAxis(event.jaxis.axis);
                        if (axis)
                        {
                            axis->joyEvent(event.jaxis.value);
                        }
                    }

                    break;
                }

                case SDL_JOYHATMOTION:
                {
#ifdef USE_SDL_2
                    InputDevice *joy = trackjoysticks.value(event.jhat.which);
#else
                    InputDevice *joy = joysticks->value(event.jhat.which);
#endif
                    if (joy)
                    {
                        SetJoystick* set = joy->getActiveSetJoystick();
                        JoyDPad *dpad = set->getJoyDPad(event.jhat.hat);
                        if (dpad)
                        {
                            dpad->joyEvent(event.jhat.value);
                        }
                    }

                    break;
                }

#ifdef USE_SDL_2
                case SDL_CONTROLLERAXISMOTION:
                {
                    InputDevice *joy = trackcontrollers.value(event.caxis.which);
                    if (joy)
                    {
                        SetJoystick* set = joy->getActiveSetJoystick();
                        JoyAxis *axis = set->getJoyAxis(event.caxis.axis);
                        if (axis)
                        {
                            axis->joyEvent(event.caxis.value);
                        }
                    }
                    break;
                }

                case SDL_CONTROLLERBUTTONDOWN:
                case SDL_CONTROLLERBUTTONUP:
                {
                    InputDevice *joy = trackcontrollers.value(event.cbutton.which);
                    if (joy)
                    {
                        SetJoystick* set = joy->getActiveSetJoystick();
                        JoyButton *button = set->getJoyButton(event.cbutton.button);

                        if (button)
                        {
                            button->joyEvent(event.type == SDL_CONTROLLERBUTTONDOWN ? true : false);
                        }
                    }

                    break;
                }

                case SDL_JOYDEVICEREMOVED:
                {
                    InputDevice *device = joysticks->value(event.jdevice.which);
                    if (device)
                    {
                        removeDevice(device);
                    }

                    break;
                }

                case SDL_JOYDEVICEADDED:
                {
                    addInputDevice(event.jdevice.which);
                    break;
                }
#endif

                case SDL_QUIT:
                {
                    stopped = true;
                    break;
                }

                default:
                    break;
            }
        }
        while (SDL_PollEvent(&event) > 0);
    }

    if (stopped)
    {
        if (joysticks->count() > 0)
        {
            emit complete(joysticks->value(0));
        }
        emit complete();
        stopped = false;

        // Check for a grabbed instance of an SDL_QUIT event. If the last event was
        // not an SDL_QUIT event, push an event onto the queue so SdlEventReader
        // will finish properly.
#ifdef USE_SDL_2
        if (event.type != SDL_FIRSTEVENT && event.type != SDL_QUIT)
#else
        if (event.type != SDL_NOEVENT && event.type != SDL_QUIT)
#endif
        {
            event.type = SDL_QUIT;
            SDL_PushEvent(&event);
            QTimer::singleShot(0, eventWorker, SLOT(performWork()));
        }
    }
    else
    {
        QTimer::singleShot(0, eventWorker, SLOT(performWork()));
    }
}