ISAAC
Overview :: Library Doc :: Server Doc :: JSON Commands

In Situ Animation of Accelerated Computations

isaac.cpp
Go to the documentation of this file.
1 /* This file is part of ISAAC.
2  *
3  * ISAAC is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU Lesser General Public License as
5  * published by the Free Software Foundation, either version 3 of the
6  * License, or (at your option) any later version.
7  *
8  * ISAAC is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with ISAAC. If not, see <www.gnu.org/licenses/>. */
15 
16 #include "Broker.hpp"
18 #include "TCPDataConnector.hpp"
19 #ifdef ISAAC_SDL
20  #include "SDLImageConnector.hpp"
21 #endif
22 #ifdef ISAAC_GST
23  #include "RTPImageConnector.hpp"
24  #include "RTMPImageConnector.hpp"
25 #endif
26 #ifdef ISAAC_JPEG
27  #include "URIImageConnector.hpp"
29 #endif
30 #include "version.hpp"
31 
32 #define ISAAC_INCREASE_NR_OR_DIE \
33  nr++; \
34  if (nr >= argc) \
35  { \
36  printf("Not enough arguments!\n"); \
37  return 1; \
38  }
39 
40 int main(int argc, char **argv)
41 {
42  json_object_seed(0);
43  int tcp_port = 2458;
44  int web_port = 2459;
45  int sim_port = 2460;
46  const char __tcp_interface[] = "*";
47  const char __web_interface[] = "*";
48  const char __sim_interface[] = "*";
49  const char* tcp_interface = __tcp_interface;
50  const char* web_interface = __web_interface;
51  const char* sim_interface = __sim_interface;
52  const char __name[] = "ISAAC Visualization server";
53  const char __url[] = "127.0.0.1";
54  const char* name = __name;
55  const char* url = __url;
56  char* dump = NULL;
57  #ifdef ISAAC_GST
58  char* twitch_apikey = NULL;
59  char* twitch_url = NULL;
60  int twitch_bitrate = 400;
61  #endif
62  int nr = 1;
63  while (nr < argc)
64  {
65  if (strcmp(argv[nr],"--help") == 0)
66  {
67  printf("ISAAC - In Situ Animation of Accelerated Computations (Server) " ISAAC_SERVER_VERSION_STRING"\n");
68  printf("Usage:\n");
69  printf("isaac [--help] [--url <X>] [--name <X>] [--web_port <X>] [--tcp_port <X>]\n");
70  printf(" [--sim_port <X>] [--web_int <X>] [--tcp_int <X>] [--sim_int <X>]\n");
71  printf(" [--dump <X>] [--version]\n");
72  printf("Explanation:\n");
73  printf(" --help: Shows this help\n");
74  printf(" --url: Set the url to connect to from outside. Default 127.0.0.1\n");
75  printf(" --name: Set the name of the server.\n");
76  printf(" --web_port: Set port for the websocket clients to connect. Default %i\n",web_port);
77  printf(" --tcp_port: Set port for the tcp clients to connect. Default %i\n",tcp_port);
78  printf(" --sim_port: Set port for the simulations to connect to. Default %i\n",sim_port);
79  printf(" --web_int: Set interface for the websocket clients to connect. Default %s\n",web_interface);
80  printf(" --tcp_int: Set interface for the tcp clients to connect. Default %s\n",tcp_interface);
81  printf(" --sim_int: Set interface for the simulations to connect. Default %s\n",sim_interface);
82  printf(" --dump: Dump all received jpegs to the disk in the given folder\n");
83  printf(" --version: Shows the version\n");
84  #ifdef ISAAC_GST
85  printf(" --twitch: Set twitch apikey for twitch live streaming\n");
86  printf("--twitch_url: Set twitch rtmp-url for ssh forwarding or another rtmp service\n");
87  printf("--twitch_bitrate: Set twitch bitrate. Default 400\n");
88  #endif
89  return 0;
90  }
91  else
92  if (strcmp(argv[nr],"--version") == 0)
93  {
94  printf("Isaac server version " ISAAC_SERVER_VERSION_STRING "\n");
95  return 0;
96  }
97  else
98  if (strcmp(argv[nr],"--web_port") == 0)
99  {
101  web_port = atoi(argv[nr]);
102  }
103  else
104  if (strcmp(argv[nr],"--tcp_port") == 0)
105  {
107  tcp_port = atoi(argv[nr]);
108  }
109  else
110  if (strcmp(argv[nr],"--sim_port") == 0)
111  {
113  sim_port = atoi(argv[nr]);
114  }
115  else
116  if (strcmp(argv[nr],"--web_int") == 0)
117  {
119  web_interface = argv[nr];
120  }
121  else
122  if (strcmp(argv[nr],"--tcp_int") == 0)
123  {
125  tcp_interface = argv[nr];
126  }
127  else
128  if (strcmp(argv[nr],"--sim_int") == 0)
129  {
131  sim_interface = argv[nr];
132  }
133  else
134  if (strcmp(argv[nr],"--url") == 0)
135  {
137  url = argv[nr];
138  }
139  else
140  if (strcmp(argv[nr],"--name") == 0)
141  {
143  name = argv[nr];
144  }
145  #ifdef ISAAC_GST
146  else
147  if (strcmp(argv[nr],"--twitch") == 0)
148  {
150  twitch_apikey = argv[nr];
151  }
152  else
153  if (strcmp(argv[nr],"--twitch_url") == 0)
154  {
156  twitch_url = argv[nr];
157  }
158  else
159  if (strcmp(argv[nr],"--twitch_bitrate") == 0)
160  {
162  twitch_bitrate = atoi(argv[nr]);
163  }
164  #endif
165  else
166  if (strcmp(argv[nr],"--dump") == 0)
167  {
169  dump = argv[nr];
170  }
171  else
172  {
173  printf("Don't know argument %s\n",argv[nr]);
174  return 1;
175  }
176  nr++;
177  }
178 
179  printf("Using web_port=%i, tcp_port=%i and sim_port=%i\n",web_port,tcp_port,sim_port);
180 
181  printf("\n");
182  Broker broker(name,sim_port,sim_interface);
183  WebSocketDataConnector* webSocketDataConnector = new WebSocketDataConnector();
184  if (webSocketDataConnector->init(web_port,web_interface) == 0)
185  broker.addDataConnector(webSocketDataConnector);
186  TCPDataConnector* tCPDataConnector = new TCPDataConnector();
187  if (tCPDataConnector->init(tcp_port,tcp_interface) == 0)
188  broker.addDataConnector(tCPDataConnector);
189  #ifdef ISAAC_GST
190  RTPImageConnector* rTPImageConnector_h264 = new RTPImageConnector(url,false,false);
191  if (rTPImageConnector_h264->init(5000,5099) == 0)
192  broker.addImageConnector(rTPImageConnector_h264);
193  RTPImageConnector* rTPImageConnector_jpeg = new RTPImageConnector(url,false,true);
194  if (rTPImageConnector_jpeg->init(5100,5199) == 0)
195  broker.addImageConnector(rTPImageConnector_jpeg);
196  #endif
197  #ifdef ISAAC_JPEG
198  URIImageConnector* uRIImageConnector = new URIImageConnector();
199  if (uRIImageConnector->init(0,0) == 0)
200  broker.addImageConnector(uRIImageConnector);
201  #endif
202  #ifdef ISAAC_GST
203  RTMPImageConnector* twitchImageConnector = NULL;
204  if (twitch_apikey)
205  {
206  if (twitch_url)
207  twitchImageConnector = new RTMPImageConnector( std::string("Twitch"), std::string(twitch_apikey), std::string(twitch_url), twitch_bitrate, true );
208  else
209  twitchImageConnector = new RTMPImageConnector( std::string("Twitch"), std::string(twitch_apikey), std::string("live-fra.twitch.tv/app"), twitch_bitrate, true );
210  if (twitchImageConnector->init(0,0) == 0)
211  broker.addImageConnector(twitchImageConnector);
212  }
213  #endif
214  #ifdef ISAAC_SDL
215  SDLImageConnector* sDLImageConnector = new SDLImageConnector();
216  if (sDLImageConnector->init(0,0) == 0)
217  broker.addImageConnector(sDLImageConnector);
218  #endif
219  #ifdef ISAAC_JPEG
220  SaveFileImageConnector* saveFileImageConnector = NULL;
221  if (dump)
222  {
223  saveFileImageConnector = new SaveFileImageConnector(std::string(dump));
224  if (saveFileImageConnector->init(0,0) == 0)
225  broker.addImageConnector(saveFileImageConnector);
226  }
227  #endif
228  int return_code = 0;
229  if (broker.run())
230  {
231  printf("Error while running isaac\n");
232  return_code = -1;
233  }
234 
235  delete webSocketDataConnector;
236  delete tCPDataConnector;
237  #ifdef ISAAC_JPEG
238  delete uRIImageConnector;
239  #endif
240  #ifdef ISAAC_GST
241  delete rTPImageConnector_h264;
242  delete rTPImageConnector_jpeg;
243  delete twitchImageConnector;
244  #endif
245  #ifdef ISAAC_SDL
246  delete sDLImageConnector;
247  delete saveFileImageConnector;
248  #endif
249  return return_code;
250 }
#define ISAAC_INCREASE_NR_OR_DIE
Definition: isaac.cpp:32
int main(int argc, char **argv)
Definition: isaac.cpp:40
errorCode init(int minport, int maxport)
errorCode init(int minport, int maxport)
errorCode init(int minport, int maxport)
errorCode init(int minport, int maxport)
errorCode init(int minport, int maxport)
errorCode addImageConnector(ImageConnector *imageConnector)
Definition: Broker.cpp:68
#define ISAAC_SERVER_VERSION_STRING
Definition: version.hpp:12
errorCode init(int port, std::string interface)
errorCode run()
Definition: Broker.cpp:276
errorCode addDataConnector(MetaDataConnector *dataConnector)
Definition: Broker.cpp:58
errorCode init(int port, std::string interface)