00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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
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
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
00061 return disp->communicationMode(1, string(argv[ind+1]), string(argv[ind+2]));
00062
00063
00064
00065 }
00066
00067
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
00083 disp = new Dispatcher();
00084
00085
00086
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 }