Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

src/traplasGUI.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 Traplas visualisation.
00004 
00005 Copyright (C) 2006 Herbert de Vos & Willem Drost
00006 
00007 This program 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.
00008 
00009 This program 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.
00010 
00011 You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00012 
00013 (For full Licence see ../GPL-Licence.txt)
00014 
00015 */
00016 
00017 #ifndef _STDLIB_H
00018 #include <stdlib.h>
00019 #endif
00020 
00021 #ifndef _STDIO_H
00022 #include <stdio.h>
00023 #endif
00024 
00025 #ifndef _STRING_H
00026 #include <string.h>
00027 #endif
00028 
00029 #ifndef STATECONTROL_H
00030 #include "../include/StateControl.h"
00031 #endif
00032 
00033 #ifndef DISPATCHER_H
00034 #include "Dispatcher.h"
00035 #endif
00036 
00037 using namespace std;
00038 
00039 /*Here we have a dispatcher.*/
00040 Dispatcher* disp = NULL;
00041 
00042 bool parse(int argc, char** argv){
00043         for(int ind=1; ind< argc; ind++){
00044                         if((strcmp(argv[ind], "-f")==0) || (strcmp(argv[ind], "--file") == 0)){
00045                         if(!(ind+1 < argc)){
00046                                 cout << "No file specified" << endl;
00047                                 return false;
00048                         }
00049 
00050                         //read simulation from the file that is in the next argument
00051                         return disp->communicationMode(0, string(argv[ind+1]));
00052                         }
00053 
00054                 if((strcmp(argv[ind], "-d")==0) || (strcmp(argv[ind], "--dbus") == 0)){
00055                         if(!(ind+2 < argc)){
00056                          cout << "no name on the bus specified. Should be of the format:\n\n \t -d <own name> <traplas name>\n";
00057                          return false;
00058                         }
00059                         cout << "ok, go communicate: " << endl;
00060                         //Read own name on dbus from next argument and the name of Traplas from the one after that.
00061                         return disp->communicationMode(1, string(argv[ind+1]), string(argv[ind+2]));
00062                         //Tell dispatcher that the communication mode is 'dbus'
00063 
00064 
00065                 }
00066 
00067                 //Well, that's it for now.
00068 
00069         }
00070         return true;
00071 }
00072 
00073 int main(int argc, char** argv){
00074 
00075         if(argc>1)
00076         {
00077                 if((strcmp(argv[1], "-h")==0) || (strcmp(argv[1], "--help") == 0)){
00078                         cout << "Visualisation for Traplas\n\n\t dystopia [-h] [-d own_name traplas_name] [-f filename]\n\n\t -h --help \t this help.\n\t -d --dbus\t ipc mode using dbus. \n\t\t\tThe 1st argument is the name of the visualisation on the bus, the 2nd is the name of Traplas on the bus.\n\t -f --file\t read simulation from file. \n\t\t\tArguments: filename, relative to the visualisation binary or the absolute path in the filesystem.\n\n";
00079                         return 1;
00080 
00081                 }
00082                 //ok, it's not a help request. Start the visualisation, call constructors. Twist those knobs! TWIST THOSE KNOBS!:
00083                 disp = new Dispatcher();
00084                 //There, started.
00085 
00086                 //Parse arguments:
00087                 if(!parse(argc, argv) || disp == NULL){
00088                         cout << "terminating, error parsing or creating the Dispatcher instance.\n";
00089                         return 1;
00090                 }
00091         }
00092 
00093         while (true)
00094                 sleep(1);
00095 
00096 
00097         return 0;
00098 }

Generated on Mon Jun 19 10:22:04 2006 for TraplasVisualisation by  doxygen 1.4.4