Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00040
00041 #include <iostream>
00042 #include <cstdlib>
00043 #include <signal.h>
00044 #include <stdio.h>
00045 #include <string.h>
00046 #include <unistd.h>
00047 #include <getopt.h>
00048
00049
00050 #include <BeliefstateROS.h>
00051
00052
00053
00054 typedef void (*Handler)(int signum);
00055 Handler hdlrOldSIGWINCH = SIG_IGN;
00056
00057
00058
00059 beliefstate::BeliefstateROS* g_bsBeliefstate;
00060
00061
00062 void printHelp(string strExecutableName) {
00063 std::cout << "Beliefstate System (version " + g_bsBeliefstate->version() + ") by Jan Winkler <winkler@cs.uni-bremen.de>" << std::endl;
00064 std::cout << "Licensed under BSD. https://www.github.com/fairlight1337/beliefstate" << std::endl << std::endl;
00065 std::cout << "Usage: " << strExecutableName << " [options]" << std::endl << std::endl;
00066
00067 std::cout << "Available options are:" << std::endl;
00068 std::cout << " -h, --help\t\tPrint this help" << std::endl;
00069 std::cout << " -c, --config <file>\tLoad config file <file> instead of the default one" << std::endl;
00070 std::cout << std::endl;
00071
00072 std::cout << "Should any questions arise, feel free to send an email to winkler@cs.uni-bremen.de" << std::endl;
00073 }
00074
00075 void catchHandler(int nSignum) {
00076 switch(nSignum) {
00077 case SIGTERM:
00078 case SIGINT: {
00079 g_bsBeliefstate->triggerShutdown();
00080 } break;
00081
00082 case SIGWINCH: {
00083 if(hdlrOldSIGWINCH != SIG_IGN && hdlrOldSIGWINCH != SIG_DFL) {
00084 (*hdlrOldSIGWINCH)(SIGWINCH);
00085 }
00086
00087 g_bsBeliefstate->triggerTerminalResize();
00088 } break;
00089
00090 default:
00091 break;
00092 }
00093 }
00094
00095 int main(int argc, char** argv) {
00096 g_bsBeliefstate = new beliefstate::BeliefstateROS(argc, argv);
00097
00098
00099 int nC, option_index = 0;
00100 static struct option long_options[] = {{"config", required_argument, 0, 'c'},
00101 {"help", no_argument, 0, 'h'},
00102 {0, 0, 0, 0}};
00103
00104 std::string strConfigFile = "";
00105 bool bQuit = false;
00106
00107 while((nC = getopt_long(argc, argv, "c:h", long_options, &option_index)) != -1) {
00108 switch(nC) {
00109 case 'c': {
00110 strConfigFile = string(optarg);
00111 } break;
00112
00113 case 'h': {
00114 printHelp(string(argv[0]));
00115 bQuit = true;
00116 } break;
00117
00118 default: {
00119 } break;
00120 }
00121 }
00122
00123 if(bQuit == false) {
00124 g_bsBeliefstate->info("Starting beliefstate system (version " + g_bsBeliefstate->version() + ").");
00125
00126 beliefstate::Result resInit = g_bsBeliefstate->init(strConfigFile);
00127
00128 if(resInit.bSuccess) {
00129
00130
00131
00132 struct sigaction action;
00133 memset(&action, 0, sizeof(struct sigaction));
00134 action.sa_handler = catchHandler;
00135 sigaction(SIGTERM, &action, NULL);
00136 sigaction(SIGINT, &action, NULL);
00137
00138 hdlrOldSIGWINCH = signal(SIGWINCH, SIG_IGN);
00139 sigaction(SIGWINCH, &action, NULL);
00140
00141 g_bsBeliefstate->info("Initialization complete, ready for action.", true);
00142 while(g_bsBeliefstate->cycle()) {
00143
00144 usleep(10);
00145 }
00146 } else {
00147 g_bsBeliefstate->fail("Initialization of the beliefstate system failed. Being a quitter.");
00148 }
00149
00150 std::cout << "\r";
00151 g_bsBeliefstate->info("Exiting gracefully.");
00152 g_bsBeliefstate->cycle();
00153
00154 g_bsBeliefstate->deinit();
00155 g_bsBeliefstate->cycle();
00156
00157 delete g_bsBeliefstate;
00158 }
00159
00160 return EXIT_SUCCESS;
00161 }