RavenNetTestServer.cpp 2.48 KB
Newer Older
1
2
3
4
5
#include <iostream>
#include <string>

#include <ITASimulationScheduler/Raven/RavenNetServer.h>

6
7
#include <ITASimulationScheduler/Raven/Simulator.h>
#include <ITASimulationScheduler/LocalScheduler.h>
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

#include <ITAFilesystemUtils.h>

#include <omp.h>

using namespace std;

int main(int argc, char** argv) {

	if( argc != 2 )
	{
		cerr << "Syntax error, usage: RavenNetTestServer RAVENDATABASEPATH" << endl;
		return 255;
	}

	string sRavenDataBasePath = string( argv[1] );
	if( doesDirectoryExist( sRavenDataBasePath ) == false )
	{
		cerr << "Given Raven data base path '" << sRavenDataBasePath << "' not found on this machine" << endl;
		return 255;
	}	

	cout << "OpenMP max threads: " << omp_get_max_threads() << endl;

	string sServerName = "0.0.0.0"; // all interfaces
	unsigned int uiPort = 12480;
34
35
    ITASimulationScheduler::RAVEN::IRavenNetServer::tPortList liFreePorts;
    liFreePorts.push_back( ITASimulationScheduler::RAVEN::IRavenNetServer::tPortRange( uiPort+1, 12499 ) );
36
37
38

	cout << "Waiting for connections on all interfaces using port " << uiPort << endl;

39
    ITASimulationScheduler::RAVEN::IRavenNetServer* pServer = ITASimulationScheduler::RAVEN::IRavenNetServer::Create();
40

41
    int iMode = ITASimulationScheduler::RAVEN::IRavenNetServer::SCHEDULER;
42

43
    if (iMode & ITASimulationScheduler::RAVEN::IRavenNetServer::SIMULATOR)
44
45
	{
		// Create and set up Standalone Raven Simulator
46
        ITASimulationScheduler::RAVEN::CRavenSimulator* pSimulator = new ITASimulationScheduler::RAVEN::CRavenSimulator(sRavenDataBasePath);
47
48

		// Create server and connect Raven instance
49
        pServer->SetRavenSimulator( (ITASimulationScheduler::ISimulationInterface*) pSimulator );
50
51
	}

52
    if (iMode & ITASimulationScheduler::RAVEN::IRavenNetServer::SCHEDULER)
53
54
	{
		// Create and set up Raven Scheduler on this machine
55
        ITASimulationScheduler::CLocalScheduler::CConfiguration oConf;
56
		oConf.sRavenDataBasePath = sRavenDataBasePath;
57
58
        ITASimulationScheduler::CLocalScheduler* pScheduler = new ITASimulationScheduler::CLocalScheduler( oConf );
        pServer->SetRavenSimulationScheduler( (ITASimulationScheduler::ISimulationSchedulerInterface*) pScheduler );
59
60
61
	}
	
	// Start
62
    if( pServer->Initialize(sServerName, (int) uiPort, liFreePorts, iMode) != ITASimulationScheduler::RAVEN::IRavenNetServer::RAVEN_NO_ERROR ) {
63
64
65
66
67
68
69
70
71
72
		cerr << "Could not initialize server" << endl;
	}

	int iAnyKey;
	cout << endl << "Any key quits ..." << endl << endl;	
	cin >> iAnyKey;

	pServer->Finalize(); // Lscht auch den Simulator
	
	return 0;
73
}