void MamdaFundamentalListener::MamdaFundamentalListenerImpl::handleFundamentalMessage (
        MamdaSubscription*  subscription,
        const MamaMsg&      msg,
        short               msgType)
    {
        // Ensure that the field handling is set up (once for all
        // MamdaFundamentalListener instances).
        if (!mUpdatersComplete)
        {
            wthread_static_mutex_lock (&mFundamentalFieldUpdaterLockMutex);

            if (!mUpdatersComplete)
            {
                if (!MamdaFundamentalFields::isSet())
                {
                     mama_log (MAMA_LOG_LEVEL_WARN,
                               "MamdaFundamentalListener: MamdaFundamentalFields::setDictionary() "
                               "has not been called.");
                     wthread_static_mutex_unlock (&mFundamentalFieldUpdaterLockMutex);
                     return;
                }

                try
                {
                    initFieldUpdaters ();
                }
                catch (MamaStatus &e)
                {
                    mama_log (MAMA_LOG_LEVEL_WARN,
                              "MamdaFundamentalListener: Could not set field updaters: %s",
                              e.toString ());
                    wthread_static_mutex_unlock (&mFundamentalFieldUpdaterLockMutex);
                    return;
                }
                mUpdatersComplete = true;
            }

            wthread_static_mutex_unlock (&mFundamentalFieldUpdaterLockMutex);
        }

        // Handle fields in message:
        updateFieldStates       ();
        updateFundamentalFields (msg);

        // Handle according to message type:
        switch (msgType)
        {
        case MAMA_MSG_TYPE_INITIAL:
        case MAMA_MSG_TYPE_RECAP:
            handleRecap (subscription, msg);
            break;
        case MAMA_MSG_TYPE_UPDATE:
            handleUpdate (subscription, msg);
            break;
        }
    }
Пример #2
0
void Window::update()
{
    if(!mWindow) return;

    double time = glfwGetTime();
    mFrameDuration = time - mPreviousFrameTime;
    mPreviousFrameTime = time;

    glfwPollEvents();

    // close window if it was closed
    if(!isOpen()) {
        close();
    }

    handleUpdate(mFrameDuration);
}
Пример #3
0
 bool ArchiveModule::handleRequest(Request &req, Response &resp) {
     std::string reqtype = req.m_json["reqtype"].asString();
     if (reqtype == "findUnique") {
         return handleFindUnique(req, resp);
     } else if (reqtype == "getDatastoresList") {
         return handleGetDatastoresList(req, resp);
     } else if (reqtype == "registerDatastore") {
         return handleRegisterDatastore(req, resp);
     } else if (reqtype == "insert") {
         return handleInsert(req, resp);
     } else if (reqtype == "update") {
         return handleUpdate(req, resp);
     } else if (reqtype == "find") {
         return handleFind (req, resp);
     } else if (reqtype == "remove") {
         return handleRemove(req, resp);
     }
     return false;
 }
Пример #4
0
//******************************************************************************
SHSensors::SHSensors(QObject *parent) :
    QObject(parent)
{
    //*** initialize vars ***
    enabled_ = 0;
    ready_ = false;
    validIMU_ = false;
    started_ = false;
    imu_ = 0;
    pressure_ = 0;
    humidity_ = 0;
    imuTimer_ = 0;
    updateIntervalMSec_ = 200;

    //*** get the settings ***
    settings_ = new RTIMUSettings();

    //*** create an IMU object ***
    imu_ = RTIMU::createIMU( settings_ );

    //*** check for a valid IMU ***
    if ( (imu_ == NULL) || (imu_->IMUType() == RTIMU_TYPE_NULL) )
    {
        qDebug() << "No valid IMU found";
        return;
    }

    qDebug() << "IMU Found";

    //*** set valid flag ***
    validIMU_ = true;

    //*** set up the IMU ***
    imu_->IMUInit();

    //*** not sure what this does yet ***
    imu_->setSlerpPower( 0.02 );

    //*** create timer ***
    imuTimer_ = new QTimer( this );
    connect( imuTimer_, SIGNAL(timeout()), SLOT(handleUpdate()) );
}
Пример #5
0
void GameState::spawnEgg(const glm::vec2& pos) {
    m_egg = std::make_shared<Egg>();
    m_egg->setHatching(true);
    add(m_egg);
    m_egg->setPhysicsPosition(pos);
    m_egg->setPhysicsRotation(thor::Pi / 2);
    m_center = m_egg->position();

    for(int i = 0; i < 10; ++i) {
        auto egg = std::make_shared<Egg>();
        add(egg);
        egg->setPhysicsPosition(pos + glm::vec2(thor::random(-2.5f, -1.0f), thor::random(-0.5f, 0.f)));
        egg->setPhysicsRotation(thor::random(-thor::Pi, thor::Pi));
        float s = thor::random(0.5f, 0.7f);
        egg->setScale(glm::vec2(s, s));
        egg->handleUpdate(0);
    }

    m_dynamicsWorld->stepSimulation(10.f, 100);
}
Пример #6
0
void sendResponse(char *allTokens[], char response[MAX_RESPONSE_SIZE], struct connection_bundle *connBundle, char request[MAX_REQUEST_SIZE]){
	//Selects a passed in statement and appropriately assigns a return message
	//General mechanism for message passing between server and client
	int clientSock = connBundle->clientSock;
	int isPrimary = IS_PRIMARY;
	
	/*2. Coordination: The primary takes each request atomically, in the order in which it
	receives it. It checks the unique identifier, in case it has already executed the request,
	and if so it simply resends the response.*/	
	//If request is an UPDATE
	if((strncmp(allTokens[0], "REGISTER", strlen(allTokens[0])) == 0) ||
		(strncmp(allTokens[0], "ADD_TWEET", strlen(allTokens[0])) == 0) ||
		(strncmp(allTokens[0], "ADD_FOLLOWEE", strlen(allTokens[0])) == 0) || 
		(strncmp(allTokens[0], "REMOVE_FOLLOWEE", strlen(allTokens[0])) == 0) ||
		(strncmp(allTokens[0], "DELETE_ACCOUNT", strlen(allTokens[0])) == 0)){
			//check log
			int found = checkLog(request); //stores only updates
			if(found){
				if(snprintf(response, MAX_RESPONSE_SIZE, "%i\n", found) < 0)
				{
					perror("Snprintf failed.");
					exit(SNPRINTF_FAILED);
				}
				//Make sure the back-ups have updated logs
				if(isPrimary)
				{
					notifyBackups(request);
				}
				if(send(clientSock, response, MAX_RESPONSE_SIZE, 0) == -1)
				{
					perror("Send Failed.");
				}
			}
			else
			{
				//3. Execution: The primary executes the request and stores the response.
				//Execute update
				
				handleUpdate(allTokens, response);
				//Log Response
				addLog(request);
				/*4. Agreement: If the request is an update, then the primary sends the updated state,
					the response and the unique identifier to all the backups. The backups send an
					acknowledgement.*/
				if(isPrimary)
				{
					notifyBackups(request);
				}
				/*5. Response: The primary responds to the front end, which hands the response back to the client.*/
				if(send(clientSock, response, MAX_RESPONSE_SIZE, 0) == -1)
				{
					perror("Send Failed.");
					//exit(SEND_FAILED);
				}
				
				
				
			}	  
		}
	else if((strncmp(allTokens[0], "LOGIN", strlen(allTokens[0])) == 0) ||
			(strncmp(allTokens[0], "LIST_FOLLOWEES", strlen(allTokens[0])) == 0) ||
			(strncmp(allTokens[0], "LIST_OTHERS", strlen(allTokens[0])) == 0) ||
			(strncmp(allTokens[0], "LIST_TWEETS", strlen(allTokens[0])) == 0)){
			//Execute read & respond
			handleRead(allTokens, response, clientSock);
			
	}
	else if((strncmp(allTokens[0], "GET_PRIMARY", strlen(allTokens[0])) == 0))
	{	
		int target = (int)atoi(allTokens[1]);
		printf("Target: %s", allTokens[1]);
		puts(request);
		int killed = killPort(target);
		if(killed){
			int myPort = MY_PORT;
			int otherPort1 = OTHER_PORT1;
			int otherPort2 = OTHER_PORT2;
			
			//make choice
			int candidate = selectCandidate(myPort, otherPort1, otherPort2);
			char electoralRequest[MAX_REQUEST_SIZE];
			pthread_mutex_lock(&isPrimaryMutex);
			PRIMARY = candidate;
			if(candidate == myPort)
			{
				IS_PRIMARY = 1;
			}
			pthread_mutex_unlock(&isPrimaryMutex);
			if(snprintf(electoralRequest, MAX_REQUEST_SIZE, "dd\tAPPOINT\t%i", candidate) < 0)
			{
				perror("Snprintf failed.");
				exit(SNPRINTF_FAILED);
			}
			if(otherPort1 != -1)
			{
				//Send candidate
				conductElections(electoralRequest, otherPort1);
			}
			if(otherPort2 != -1)
			{
				conductElections(electoralRequest, otherPort2);
			}
			if(snprintf(response, MAX_RESPONSE_SIZE, "%i\n", candidate) < 0)
			{
				perror("Snprintf failed.");
				exit(SNPRINTF_FAILED);
			}
		}
		else
		{
			//already dead
			int primary = PRIMARY;
			if(primary == -1)
			{
				puts("Invalid primary");
			}
			if(snprintf(response, MAX_RESPONSE_SIZE, "%i\n", primary) < 0)
			{
				perror("Snprintf failed.");
				exit(SNPRINTF_FAILED);
			}
		}
		printf("New leader: %s\n", response);
		if(send(clientSock, response, MAX_RESPONSE_SIZE, 0) == -1)
		{
			perror("Send Failed.");
		}
	}
	else if((strncmp(allTokens[0], "APPOINT", strlen(allTokens[0])) == 0))
	{
		int newPort = atoi(allTokens[1]);
		int myPort = MY_PORT;
		PRIMARY = newPort;
		if(myPort == PRIMARY)
		{
			pthread_mutex_lock(&isPrimaryMutex);
			IS_PRIMARY = 1;
			pthread_mutex_unlock(&isPrimaryMutex);
		}
		
	}
	else{
			exit(INVALID_SELECTION);
		}
}
Пример #7
0
GUI::GUI(QWidget* parent, Qt::WindowFlags f)
    : QWidget(parent, f)
    , _layout(nullptr)
    , _renderer(nullptr)
    , _sourcePositionXText(nullptr)
    , _sourcePositionYText(nullptr)
    , _sourcePositionZText(nullptr)
    , _sourcePositionRandomize(nullptr)
    , _sourceValueSlider(nullptr)
    , _sourceLabel(nullptr)
    , _sourcePointButton(nullptr)
    , _sourceConeButton(nullptr)
    , _effectPositionXText(nullptr)
    , _effectPositionYText(nullptr)
    , _effectPositionZText(nullptr)
    , _effectPositionRandomize(nullptr)
    , _effectValueSlider(nullptr)
    , _effectLabel(nullptr)
    , _effectGravityButton(nullptr)
    , _effectWindButton(nullptr)
    , _timer(nullptr)
    , _sourceAddedCallback([](SourceType, glm::vec3, float){}) // initialize function pointer with empty lambda expressions
    , _effectAddedCallback([](EffectType, glm::vec3, float){}) // initialize function pointer with empty lambda expressions
    , _updateCallback([](float){}) // initialize function pointer with empty lambda expressions
    , _removeAllCallback([](){}) // initialize function pointer with empty lambda expressions
{
    //   -----------------------------------------------------------
    //   |                                         |               |
    //   |                                         |    Source     | row 0
    //   |                                         |               |
    //   |                                         |---------------|
    //   |                                         |               |
    //   |                                         |    Effect     | row 1
    //   |                                         |               |
    //   |                Renderer                 |---------------|
    //   |                                         |               |
    //   |                                         |   Removeall   | row 2
    //   |                                         |               |
    //   |                                         |---------------|
    //   |                                         |               |
    //   |                                         | Renderoptions | row 3
    //   |                                         |               |
    //   -----------------------------------------------------------
    //                   column 0                       column 1

    _layout = new QGridLayout;
    // Setting the size contraint to QLayout::SetFixedSize, we prohibit resizing
    _layout->setSizeConstraint(QLayout::SetFixedSize);
    // Allow the first column to take 5x as much space as the others
    _layout->setColumnStretch(0, 5);
    setLayout(_layout);

    createRenderer();
    createSourceBox();
    createEffectBox();

    QPushButton* removeAll = new QPushButton("Remove all");
    connect(removeAll, SIGNAL(clicked(bool)), this, SLOT(handleRemoveAll()));
    _layout->addWidget(removeAll, 2, 1, 1, 1);

    createRenderingBox();

    // Create the timer that will drive the rendering and update rate of 60Hz
    _timer = new QTimer(this);
    connect(_timer, SIGNAL(timeout()), this, SLOT(handleUpdate()));
    _timer->start(16); // 16ms = 60Hz refresh rate
}