Commit 3f8b65ee authored by whitlocb's avatar whitlocb

I completed porting libsim to Windows. Reading from console now works too....

I completed porting libsim to Windows. Reading from console now works too. Some changes are more broad. I was unable to use the engine return socket for return data and for asynchronous data at the same time due to how qsocketnotifier works on Windows. So, until the engine API is asynchronous, another socket to the viewer is required. This should be okay with previous SimV2's since the changes were only in the runtime library.

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@13571 18c085ea-50e0-402c-830e-de6fd14e8384
parent a405e06d
......@@ -290,6 +290,9 @@ Engine::Engine() : viewerArgs()
netmgr = NULL;
lb = NULL;
procAtts = NULL;
simxfer = NULL;
simConnection = NULL;
simulationCommandCallback = NULL;
simulationCommandCallbackData = NULL;
metaData = NULL;
......@@ -365,6 +368,8 @@ Engine::~Engine()
{
delete xfer;
delete lb;
delete simxfer;
delete silAtts;
delete metaData;
delete commandFromSim;
......@@ -524,6 +529,8 @@ Engine::Initialize(int *argc, char **argv[], bool sigs)
VisItInit::Initialize(*argc, *argv, 0,1, true, sigs);
#endif
simxfer = new Xfer;
// Configure external options.
RuntimeSetting::parse_command_line(*argc, const_cast<const char**>(*argv));
......@@ -803,6 +810,14 @@ Engine::SetUpViewerInterface(int *argc, char **argv[])
else
vtkConnection = viewerP->GetReadConnection(1);
if(simulationPluginsEnabled)
{
if(reverseLaunch)
simConnection = viewer->GetWriteConnection(2);
else
simConnection = viewerP->GetReadConnection(2);
}
// Parse the command line.
ProcessCommandLine(*argc, *argv);
......@@ -994,9 +1009,9 @@ Engine::SetUpViewerInterface(int *argc, char **argv[])
metaData = new avtDatabaseMetaData;
silAtts = new SILAttributes;
commandFromSim = new SimulationCommand;
xfer->Add(metaData);
xfer->Add(silAtts);
xfer->Add(commandFromSim);
simxfer->Add(metaData);
simxfer->Add(silAtts);
simxfer->Add(commandFromSim);
//
// Hook up the viewer connections to Xfer
......@@ -1008,6 +1023,9 @@ Engine::SetUpViewerInterface(int *argc, char **argv[])
xfer->SetInputConnection(viewer->GetWriteConnection());
else
xfer->SetInputConnection(viewerP->GetWriteConnection());
if(simulationPluginsEnabled)
simxfer->SetOutputConnection(simConnection);
}
else
{
......@@ -1020,6 +1038,9 @@ Engine::SetUpViewerInterface(int *argc, char **argv[])
xfer->SetInputConnection(viewer->GetWriteConnection());
else
xfer->SetInputConnection(viewerP->GetWriteConnection());
if(simulationPluginsEnabled)
simxfer->SetOutputConnection(simConnection);
#endif
if(reverseLaunch)
xfer->SetOutputConnection(viewer->GetReadConnection());
......@@ -1222,7 +1243,7 @@ Engine::ReverseLaunchViewer(int *argc, char **argv[])
0, // ssh port
false, // ssh tunnelling
1, // num read sockets
2); // num write sockets
simulationPluginsEnabled ? 3 : 2); // num write sockets
}
CATCH(VisItException)
{
......@@ -1295,10 +1316,11 @@ Engine::ConnectViewer(int *argc, char **argv[])
{
// The viewer launched the engine
viewerP = new ParentProcess;
int nwrite = simulationPluginsEnabled ? 3 : 2;
#ifdef PARALLEL
viewerP->Connect(1, 2, argc, argv, PAR_UIProcess());
viewerP->Connect(1, nwrite, argc, argv, PAR_UIProcess());
#else
viewerP->Connect(1, 2, argc, argv, true);
viewerP->Connect(1, nwrite, argc, argv, true);
#endif
}
}
......@@ -3267,7 +3289,7 @@ Engine::PopulateSimulationMetaData(const std::string &db,
// Send the metadata and SIL to the viewer
if(!quitRPC->GetQuit())
{
xfer->SetUpdate(true);
simxfer->SetUpdate(true);
metaData->Notify();
silAtts->SelectAll();
silAtts->Notify();
......@@ -3345,7 +3367,7 @@ Engine::SimulationInitiateCommand(const std::string &command)
{
// Allow the command to be sent, even if we're in the middle of an
// Xfer::Process. This fixes a synchronization bug.
xfer->SetUpdate(true);
simxfer->SetUpdate(true);
commandFromSim->SetCommand(command);
commandFromSim->Notify();
......
......@@ -376,6 +376,8 @@ class ENGINE_MAIN_API Engine
// The metadata, filename, format, control data for a simulation
std::string filename;
std::string format;
Xfer *simxfer;
Connection *simConnection;
avtDatabaseMetaData *metaData;
SILAttributes *silAtts;
SimulationCommand *commandFromSim;
......
......@@ -94,12 +94,12 @@
//
// ****************************************************************************
EngineProxy::EngineProxy() : RemoteProxyBase("-engine")
EngineProxy::EngineProxy(bool sim) : RemoteProxyBase("-engine")
{
engineP = NULL;
// Indicate that we want 2 write sockets from the engine.
nWrite = 2;
nWrite = sim ? 3 : 2;
// Initialize the engine information that we can query.
numProcs = 1;
......@@ -108,6 +108,7 @@ EngineProxy::EngineProxy() : RemoteProxyBase("-engine")
// Create the status attributes that we use to communicate status
// information to the client.
simxfer = sim ? (new Xfer) : NULL;
statusAtts = new StatusAttributes;
metaData = new avtDatabaseMetaData;
silAtts = new SILAttributes;
......@@ -156,6 +157,8 @@ EngineProxy::EngineProxy() : RemoteProxyBase("-engine")
EngineProxy::~EngineProxy()
{
delete statusAtts;
delete simxfer;
delete metaData;
delete silAtts;
delete commandFromSim;
......@@ -197,7 +200,8 @@ EngineProxy::Connect(const stringVector &args)
int argc = args.size();
engineP = new ParentProcess;
engineP->Connect(1, 2, &argc, &argv, true);
int nwrite = (simxfer != NULL) ? 3 : 2;
engineP->Connect(1, nwrite, &argc, &argv, true);
delete [] argv;
// Use engineP's connections for xfer.
......@@ -300,14 +304,20 @@ EngineProxy::SetupComponentRPCs()
xfer.Add(&constructDataBinningRPC);
xfer.Add(&namedSelectionRPC);
xfer.Add(&setEFileOpenOptionsRPC);
xfer.Add(&exprList);
//
// Add other state objects to the transfer object
//
xfer.Add(&exprList);
xfer.Add(metaData);
xfer.Add(silAtts);
xfer.Add(commandFromSim);
Xfer *x = &xfer;
if(simxfer != NULL && component != NULL)
{
x = simxfer;
simxfer->SetInputConnection(component->GetWriteConnection(2));
}
x->Add(metaData);
x->Add(silAtts);
x->Add(commandFromSim);
// Extract some information about the engine from the command line
// arguments that were used to create it.
......@@ -1734,8 +1744,8 @@ EngineProxy::ExportDatabase(const int id, const ExportDBAttributes *atts)
int
EngineProxy::GetWriteSocket()
{
if (xfer.GetInputConnection())
return xfer.GetInputConnection()->GetDescriptor();
if (simxfer != NULL && simxfer->GetInputConnection() != NULL)
return simxfer->GetInputConnection()->GetDescriptor();
else
return -1;
}
......@@ -1757,9 +1767,9 @@ EngineProxy::GetWriteSocket()
void
EngineProxy::ReadDataAndProcess()
{
int amountRead = xfer.GetInputConnection()->Fill();
int amountRead = simxfer->GetInputConnection()->Fill();
if (amountRead > 0)
xfer.Process();
simxfer->Process();
else
EXCEPTION0(LostConnectionException);
}
......
......@@ -320,7 +320,7 @@ class ParentProcess;
class ENGINE_PROXY_API EngineProxy : public RemoteProxyBase
{
public:
EngineProxy();
EngineProxy(bool sim = false);
virtual ~EngineProxy();
// This version of Create is specifically for reverse launch.
......@@ -472,6 +472,7 @@ private:
StatusAttributes *statusAtts;
// Metadata, SIL published by a simulation
Xfer *simxfer;
avtDatabaseMetaData *metaData;
SILAttributes *silAtts;
SimulationCommand *commandFromSim;
......
This diff is collapsed.
......@@ -305,6 +305,24 @@ int VisItDetectInputWithTimeout(int blocking, int timeout_usec, int consoledes
* ****************************************************************************/
int VisItAttemptToCompleteConnection(void);
/******************************************************************************
* Function: VisItReadConsole
*
* Purpose:
* Read characters from the console.
*
* Arguments:
* maxlen : The size of the buffer.
* buffer : the buffer into which the values will be read.
*
* Returns: VISIT_OKAY on success; VISIT_ERROR on failure
*
* Note: This function should be called when VisItDetectInput returns 3.
* Only the root processor should call this function.
*
* ****************************************************************************/
int VisItReadConsole(int maxlen, char *buffer);
/******************************************************************************
* Function: VisItSetSlaveProcessCallback
*
......
......@@ -217,7 +217,6 @@ calculate_amr(patch_t *patch, int level, int max_levels, int ratio)
#define SIM_STOPPED 0
#define SIM_RUNNING 1
#define SIM_RUNNING_SLOW 2
struct simulation_data
{
......@@ -345,16 +344,12 @@ ProcessConsoleCommand(simulation_data *sim)
/* Read A Command */
char cmd[1000];
int iseof = (fgets(cmd, 1000, stdin) == NULL);
if (iseof)
if(VisItReadConsole(1000, cmd) == VISIT_ERROR)
{
sprintf(cmd, "quit");
printf("quit\n");
}
if (strlen(cmd)>0 && cmd[strlen(cmd)-1] == '\n')
cmd[strlen(cmd)-1] = '\0';
if(strcmp(cmd, "quit") == 0)
sim->done = 1;
else if(strcmp(cmd, "halt") == 0)
......@@ -478,7 +473,7 @@ void read_input_deck(void) { }
void mainloop(void)
{
int blocking, visitstate, timeout, err = 0;
int blocking, visitstate, err = 0;
// Set up some simulation data.
simulation_data sim;
......@@ -496,9 +491,8 @@ void mainloop(void)
do
{
blocking = (sim.runMode == SIM_STOPPED) ? 1 : 0;
timeout = (sim.runMode == SIM_RUNNING_SLOW) ? 500000 : 0;
/* Get input from VisIt or timeout so the simulation can run. */
visitstate = VisItDetectInputWithTimeout(blocking, timeout, fileno(stdin));
visitstate = VisItDetectInput(blocking, fileno(stdin));
/* Do different things depending on the output from VisItDetectInput. */
if(visitstate >= -5 && visitstate <= -1)
......@@ -516,7 +510,7 @@ void mainloop(void)
/* VisIt is trying to connect to sim. */
if(VisItAttemptToCompleteConnection() == VISIT_OKAY)
{
sim.runMode = SIM_RUNNING_SLOW;
sim.runMode = SIM_STOPPED;
fprintf(stderr, "VisIt connected\n");
VisItSetCommandCallback(ControlCommandCallback, (void*)&sim);
......
......@@ -252,15 +252,11 @@ ProcessConsoleCommand(simulation_data *sim)
if (sim->par_rank == 0)
{
int iseof = (fgets(cmd, 1000, stdin) == NULL);
if (iseof)
if(VisItReadConsole(1000, cmd) == VISIT_ERROR)
{
sprintf(cmd, "quit");
printf("quit\n");
}
if (strlen(cmd)>0 && cmd[strlen(cmd)-1] == '\n')
cmd[strlen(cmd)-1] = '\0';
}
#ifdef PARALLEL
......
......@@ -706,6 +706,9 @@ ViewerEngineManager::CreateEngine(const EngineKey &ek,
// Jeremy Meredith, Thu Feb 18 15:25:27 EST 2010
// Split HostProfile int MachineProfile and LaunchProfile.
//
// Brad Whitlock, Wed Dec 1 23:35:34 PST 2010
// Tell EngineProxy that it is a simulation.
//
// ****************************************************************************
bool
......@@ -736,7 +739,7 @@ ViewerEngineManager::ConnectSim(const EngineKey &ek,
// If an engine for the host doesn't already exist, create one.
//
EngineInformation newEngine;
newEngine.proxy = new EngineProxy;
newEngine.proxy = new EngineProxy(true);
//
// Add some arguments to the engine proxy before we try to
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment