-
Notifications
You must be signed in to change notification settings - Fork 20
/
SharedVisualizationServerMain.cpp
100 lines (83 loc) · 3.17 KB
/
SharedVisualizationServerMain.cpp
1
2
3
4
5
6
7
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/***********************************************************************
Main program for a dedicated server to support collaborative data
exploration in spatially distributed VR environments.
Copyright (c) 2009 Oliver Kreylos
This file is part of the 3D Data Visualizer (Visualizer).
The 3D Data Visualizer is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.
The 3D Data Visualizer is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with the 3D Data Visualizer; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***********************************************************************/
#include <string.h>
#include <stdlib.h>
#include <signal.h>
#include <iostream>
#include <Misc/Time.h>
#include <Collaboration/CollaborationServer.h>
#include "SharedVisualizationServer.h"
volatile bool runServerLoop=true;
void termSignalHandler(int)
{
runServerLoop=false;
}
int main(int argc,char* argv[])
{
/* Create a new configuration object: */
Collaboration::CollaborationServer::Configuration* cfg=new Collaboration::CollaborationServer::Configuration;
/* Parse the command line: */
Misc::Time tickTime(cfg->getTickTime()); // Server update time interval in seconds
for(int i=1;i<argc;++i)
{
if(argv[i][0]=='-')
{
if(strcasecmp(argv[i]+1,"port")==0)
{
++i;
if(i<argc)
cfg->setListenPortId(atoi(argv[i]));
else
std::cerr<<"SharedVisualizationServerMain: ignored dangling -port option"<<std::endl;
}
else if(strcasecmp(argv[i]+1,"tick")==0)
{
++i;
if(i<argc)
tickTime=Misc::Time(atof(argv[i]));
else
std::cerr<<"SharedVisualizationServerMain: ignored dangling -tick option"<<std::endl;
}
}
}
/* Ignore SIGPIPE and leave handling of pipe errors to TCP sockets: */
struct sigaction sigPipeAction;
sigPipeAction.sa_handler=SIG_IGN;
sigemptyset(&sigPipeAction.sa_mask);
sigPipeAction.sa_flags=0x0;
sigaction(SIGPIPE,&sigPipeAction,0);
/* Create the collaboration server object: */
Collaboration::CollaborationServer server(cfg);
std::cout<<"SharedVisualizationServerMain: Started server on port "<<server.getListenPortId()<<std::endl;
/* Add a shared Visualizer protocol object: */
server.registerProtocol(new SharedVisualizationServer);
/* Reroute SIG_INT signals to cleanly shut down multiplexer: */
struct sigaction sigIntAction;
sigIntAction.sa_handler=termSignalHandler;
if(sigaction(SIGINT,&sigIntAction,0)!=0)
std::cerr<<"SharedVisualizationServerMain: Cannot intercept SIG_INT signals. Server won't shut down cleanly."<<std::endl;
/* Run the server loop at the specified time interval: */
while(runServerLoop)
{
/* Sleep for the tick time: */
Misc::sleep(tickTime);
/* Update the server state: */
server.update();
}
return 0;
}