1/*------------------------------------------------------------------------- 2 * drawElements Quality Program Execution Server 3 * --------------------------------------------- 4 * 5 * Copyright 2014 The Android Open Source Project 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 * 19 *//*! 20 * \file 21 * \brief ExecServer main(). 22 *//*--------------------------------------------------------------------*/ 23 24#include "xsExecutionServer.hpp" 25#include "deCommandLine.hpp" 26#include "deString.h" 27 28#if (DE_OS == DE_OS_WIN32) 29# include "xsWin32TestProcess.hpp" 30#else 31# include "xsPosixTestProcess.hpp" 32#endif 33 34#include <iostream> 35 36namespace opt 37{ 38 39DE_DECLARE_COMMAND_LINE_OPT(Port, int); 40DE_DECLARE_COMMAND_LINE_OPT(SingleExec, bool); 41 42void registerOptions (de::cmdline::Parser& parser) 43{ 44 using de::cmdline::Option; 45 using de::cmdline::NamedValue; 46 47 parser << Option<Port> ("p", "port", "Port", "50016") 48 << Option<SingleExec>("s", "single", "Kill execserver after first session"); 49} 50 51} 52 53int main (int argc, const char* const* argv) 54{ 55 de::cmdline::CommandLine cmdLine; 56 57#if (DE_OS == DE_OS_WIN32) 58 xs::Win32TestProcess testProcess; 59#else 60 xs::PosixTestProcess testProcess; 61 62 // Set line buffered mode to stdout so executor gets any log messages in a timely manner. 63 setvbuf(stdout, DE_NULL, _IOLBF, 4*1024); 64#endif 65 66 // Parse command line. 67 { 68 de::cmdline::Parser parser; 69 opt::registerOptions(parser); 70 71 if (!parser.parse(argc, argv, &cmdLine, std::cerr)) 72 { 73 parser.help(std::cout); 74 return -1; 75 } 76 } 77 78 try 79 { 80 const xs::ExecutionServer::RunMode runMode = cmdLine.getOption<opt::SingleExec>() 81 ? xs::ExecutionServer::RUNMODE_SINGLE_EXEC 82 : xs::ExecutionServer::RUNMODE_FOREVER; 83 const int port = cmdLine.getOption<opt::Port>(); 84 xs::ExecutionServer server (&testProcess, DE_SOCKETFAMILY_INET4, port, runMode); 85 86 std::cout << "Listening on port " << port << ".\n"; 87 server.runServer(); 88 } 89 catch (const std::exception& e) 90 { 91 std::cerr << e.what() << "\n"; 92 return -1; 93 } 94 95 return 0; 96} 97