tools/tcpImagesServer/main.cpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2011-2014, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the name of the Universite de Sherbrooke nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #include <QtNetwork/QNetworkInterface>
29 #include <QtCore/QCoreApplication>
30 #include "ImagesTcpServer.h"
31 
32 void showUsage()
33 {
34  printf("\ntcpImagesServer [options] port\n"
35  " Options:\n"
36  " --hz #.# Image rate (default 10 Hz).\n"
37  " --host #.#.#.# Set host address.\n"
38  " --path \"\" Set a path of a directory of images or a video file.\n");
39  exit(-1);
40 }
41 
42 int main(int argc, char * argv[])
43 {
44  QString ipAddress;
45  float hz = 10.0f;
46  QString path;
47 
48  if(argc < 2)
49  {
50  showUsage();
51  }
52 
53  for(int i=1; i<argc-1; ++i)
54  {
55  if(strcmp(argv[i], "-hz") == 0 || strcmp(argv[i], "--hz") == 0)
56  {
57  ++i;
58  if(i < argc-1)
59  {
60  hz = std::atof(argv[i]);
61  if(hz < 0.0f)
62  {
63  printf("[ERROR] Image rate not valid : %s\n", argv[i]);
64  showUsage();
65  }
66  }
67  else
68  {
69  showUsage();
70  }
71  continue;
72  }
73  if(strcmp(argv[i], "-host") == 0 || strcmp(argv[i], "--host") == 0)
74  {
75  ++i;
76  if(i < argc-1)
77  {
78  ipAddress = argv[i];
79  }
80  else
81  {
82  showUsage();
83  }
84  continue;
85  }
86  if(strcmp(argv[i], "-path") == 0 || strcmp(argv[i], "--path") == 0)
87  {
88  ++i;
89  if(i < argc-1)
90  {
91  path = argv[i];
92  }
93  else
94  {
95  showUsage();
96  }
97  continue;
98  }
99 
100  printf("Unrecognized option: %s\n", argv[i]);
101  showUsage();
102  }
103 
104  quint16 port = std::atoi(argv[argc-1]);
105 
106  if(!path.isEmpty())
107  {
108  printf("Using images from path \"%s\"\n", path.toStdString().c_str());
109  }
110 
111  QCoreApplication app(argc, argv);
112  ImagesTcpServer server(hz, path);
113 
114  QObject::connect(&server, SIGNAL(connectionLost()), &app, SLOT(quit()));
115 
116  if(ipAddress.isEmpty())
117  {
118  ipAddress = server.getHostAddress().toString();
119  }
120  server.connectToHost(ipAddress, port);
121 
122  if(!server.waitForReadyRead())
123  {
124  printf("ERROR: Unable to connect to %s:%d\n", ipAddress.toStdString().c_str(), port);
125  return -1;
126  }
127  return app.exec();
128 }
129 
app
f
static QHostAddress getHostAddress()
int main(int argc, char *argv[])
void showUsage()


find_object_2d
Author(s): Mathieu Labbe
autogenerated on Thu Jun 6 2019 19:22:26