Example #1
0
void __cdecl ServerWorkerThread(void*)
{
	int done = FALSE;
	const HANDLE events[] = {heServerExec, heServerClose};
	const int cEvents = sizeof(events) / sizeof(events[0]);

	while (!done)
	{
		switch (WaitForMultipleObjects(cEvents, events, FALSE, INFINITE))
		{
			case WAIT_OBJECT_0: //need to process something
			{
				ProcessConsoleCommand(&sdCmdLine->command, sdCmdLine->arguments, sdCmdLine->cArguments, &sdCmdLine->reply);
				SetEvent(heServerDone); //notify the client we've finished

				break;
			}

			case WAIT_OBJECT_0 + 1: //server is closing
			{
				done = TRUE; //stop the thread

				break;
			}
		}
	}
}
Example #2
0
void mainloop(simulation_data *sim)
{
    int blocking, visitstate, err = 0;

    /* If we're not running by default then simulate once there's something
     * once VisIt connects.
     */
    if(sim->runMode == SIM_STOPPED)
        simulate_one_timestep(sim);

    if (sim->par_rank == 0)
    {
        fprintf(stderr, "command> ");
        fflush(stderr);
    }

    do
    {
        blocking = (sim->runMode == SIM_RUNNING) ? 0 : 1;
        /* Get input from VisIt or timeout so the simulation can run. */
        if(sim->par_rank == 0)
        {
            visitstate = VisItDetectInput(blocking, fileno(stdin));
        }
#ifdef PARALLEL
        /* Broadcast the return value of VisItDetectInput to all procs. */
        MPI_Bcast(&visitstate, 1, MPI_INT, 0, sim->par_comm);
#endif
        /* Do different things depending on the output from VisItDetectInput. */
        switch(visitstate)
        {
        case 0:
            /* There was no input from VisIt, return control to sim. */
            simulate_one_timestep(sim);
            break;
        case 1:
            /* VisIt is trying to connect to sim. */
            if(VisItAttemptToCompleteConnection() == VISIT_OKAY)
            {
                fprintf(stderr, "VisIt connected\n");
                VisItSetCommandCallback(ControlCommandCallback, (void*)sim);
                VisItSetSlaveProcessCallback2(SlaveProcessCallback, (void*)sim);

                VisItSetGetMetaData(SimGetMetaData, (void*)sim);
                VisItSetGetMesh(SimGetMesh, (void*)sim);
                VisItSetGetVariable(SimGetVariable, (void*)sim);
                VisItSetGetDomainList(SimGetDomainList, (void*)sim);
            }
            else 
            {
                /* Print the error message */
                char *err = VisItGetLastError();
                fprintf(stderr, "VisIt did not connect: %s\n", err);
                free(err);
            }
            break;
        case 2:
            /* VisIt wants to tell the engine something. */
            if(!ProcessVisItCommand(sim))
            {
                /* Disconnect on an error or closed connection. */
                VisItDisconnect();
                /* Start running again if VisIt closes. */
                /*sim->runMode = SIM_RUNNING;*/
            }
            break;
        case 3:
            /* VisItDetectInput detected console input - do something with it.
             * NOTE: you can't get here unless you pass a file descriptor to
             * VisItDetectInput instead of -1.
             */
            ProcessConsoleCommand(sim);
            if (sim->par_rank == 0)
            {
                fprintf(stderr, "command> ");
                fflush(stderr);
            }
            break;
        default:
            fprintf(stderr, "Can't recover from error %d!\n", visitstate);
            err = 1;
            break;
        }
    } while(!sim->done && err == 0);
}
Example #3
0
void mainloop(simulation_data *sim)
{
    int blocking, visitstate, err = 0;

    /* Do one iteration */
    simulate_one_timestep(sim);

    /* main loop */
    fprintf(stderr, "command> ");
    fflush(stderr);
    do
    {
        blocking = (sim->runMode == SIM_RUNNING) ? 0 : 1;
        /* Get input from VisIt or timeout so the simulation can run. */
        visitstate = VisItDetectInput(blocking, fileno(stdin));

        /* Do different things depending on the output from VisItDetectInput. */
        if(visitstate >= -5 && visitstate <= -1)
        {
            fprintf(stderr, "Can't recover from error!\n");
            err = 1;
        }
        else if(visitstate == 0)
        {
            /* There was no input from VisIt, return control to sim. */
            simulate_one_timestep(sim);
        }
        else if(visitstate == 1)
        {
            /* VisIt is trying to connect to sim. */
            if(VisItAttemptToCompleteConnection() == VISIT_OKAY)
            {
                sim->runMode = SIM_STOPPED;
                fprintf(stderr, "VisIt connected\n");
                VisItSetCommandCallback(ControlCommandCallback, (void*)sim);

                VisItSetGetMetaData(SimGetMetaData, (void*)sim);
                VisItSetGetCurve(SimGetCurve, (void*)sim);
            }
            else
                fprintf(stderr, "VisIt did not connect\n");
        }
        else if(visitstate == 2)
        {
            /* VisIt wants to tell the engine something. */
            if(VisItProcessEngineCommand() == VISIT_ERROR)
            {
                /* Disconnect on an error or closed connection. */
                VisItDisconnect();
                /* Start running again if VisIt closes. */
                sim->runMode = SIM_RUNNING;
            }
        }
        else if(visitstate == 3)
        {
            /* VisItDetectInput detected console input - do something with it.
             * NOTE: you can't get here unless you pass a file descriptor to
             * VisItDetectInput instead of -1.
             */
            ProcessConsoleCommand(sim);
            fprintf(stderr, "command> ");
            fflush(stderr);
        }
    } while(!sim->done && err == 0);
}
Example #4
0
File: stubs.c Project: ybouret/iics
void mainloop(simulation_data *sim)
{
    int blocking, visitstate, err = 0;
    //char buffer[100];
    //  double startTime,endTime;
    
    /* If we're not running by default then simulate once there's something
     * once VisIt connects.
     
     if(sim->runMode == SIM_STOPPED)
     simulate_one_timestep(sim);
     */
    VisItUI_valueChanged("MU",     ui_Mu_changed, sim);
    VisItUI_valueChanged("MUTEXT", do_nothing, NULL);
    paramMu=1;
	//sprintf(buffer,"%g",paramMu);
    //VisItUI_setValueS("MUTEXT",buffer,0);
    
    
    
    VisItUI_valueChanged("A", ui_A_changed, sim);
    VisItUI_valueChanged("ATEXT", ui_A_changed, sim);
    
    VisItUI_clicked("RUN",  ui_run_clicked, sim);
    VisItUI_clicked("HALT", ui_halt_clicked, sim);
    VisItUI_clicked("RAZ" , ui_raz_clicked, sim);
    
    if (sim->par_rank == 0)
    {
        fprintf(stderr, "command> ");
        fflush(stderr);
    }
    
    do
    {
        blocking = (sim->runMode == SIM_RUNNING) ? 0 : 1;
        /* Get input from VisIt or timeout so the simulation can run. */
        if(sim->par_rank == 0)
        {
            visitstate = VisItDetectInput(blocking, fileno(stdin));
        }
        
        
        MPI_Bcast(&visitstate, 1, MPI_INT, 0, MPI_COMM_WORLD);
        
        switch(visitstate)
        {
            case 0:
                /* There was no input from VisIt, return control to sim. */
                simulate_one_timestep(sim);
                break;
            case 1:
                /* VisIt is trying to connect to sim. */
                if(VisItAttemptToCompleteConnection() == VISIT_OKAY)
                {
                    fprintf(stderr, "VisIt connected\n");
                    VisItSetCommandCallback(ControlCommandCallback, (void*)sim);
                    VisItSetSlaveProcessCallback(SlaveProcessCallback);
                    
                    VisItSetGetMetaData(SimGetMetaData, (void*)sim);
                    VisItSetGetMesh(SimGetMesh, (void*)sim);
                    //VisItSetGetCurve(SimGetCurve, (void*)sim);
                    VisItSetGetVariable(SimGetVariable, (void*)sim);
                    VisItSetGetDomainList(SimGetDomainList, (void*)sim);
                    sim->visitIsConnected=1;
                    
                }
                else
                {
                    /* Print the error message */
                    char *errString = VisItGetLastError();
                    fprintf(stderr, "VisIt did not connect: %s\n", errString);
                    free(errString);
                }
                break;
            case 2:
                /* VisIt wants to tell the engine something. */
                if(!ProcessVisItCommand(sim))
                {
                    /* Disconnect on an error or closed connection. */
                    VisItDisconnect();
                    sim->visitIsConnected=0;
                    
                    /* Start running again if VisIt closes. */
                    /*sim->runMode = SIM_RUNNING;*/
                }
                break;
            case 3:
                /* VisItDetectInput detected console input - do something with it.
                 * NOTE: you can't get here unless you pass a file descriptor to
                 * VisItDetectInput instead of -1.
                 */
                ProcessConsoleCommand(sim);
                if (sim->par_rank == 0)
                {
                    fprintf(stderr, "command> ");
                    fflush(stderr);
                }
                break;
            default:
                fprintf(stderr, "Can't recover from error %d!\n", visitstate);
                err = 1;
                break;
        }
    } while(!sim->done && err == 0);
}