Project

General

Profile

Statistics
| Revision:

root / branches / simulator / projects / simulator / simulator / core / main.c @ 1128

History | View | Annotate | Download (1.66 KB)

1 988 bcoltin
/**
2
 * @file main.c
3
 * @author Colony Project
4
 * @brief Initializes the program.
5
 *
6
 * Contains only the main function, which
7
 * initializes the program.
8
 **/
9
10
#include <stdlib.h>
11 981 bneuman
#include <stdio.h>
12 1006 bcoltin
#include <gtk/gtk.h>
13
#include <glib.h>
14
#include <signal.h>
15 1068 ayeager
#include <unistd.h>
16 973 bcoltin
17 988 bcoltin
#include "gtk_gui.h"
18
#include "robot.h"
19 1045 bpoole
#include "world.h"
20 1068 ayeager
#include "logger.h"
21
#include "player.h"
22 981 bneuman
23 1068 ayeager
24
extern char *optarg;
25
extern int optind, optopt;
26
27 988 bcoltin
int main(int argc, char** argv)
28 984 ayeager
{
29 988 bcoltin
        if (robots_initialize())
30
                return -1;
31 984 ayeager
32 1068 ayeager
        int c;
33 1077 bcoltin
        char worldLoadedFlag = 0;
34 1128 ayeager
        char *worldFile = NULL;
35 1068 ayeager
36 1128 ayeager
        while((c = getopt(argc, argv, ":p:w:l:")) != -1)
37 1068 ayeager
        {
38
                switch(c)
39
                {
40
                        case 'l':
41 1128 ayeager
                                //What about when -w not set...
42
                                setWriteFile(optarg, worldFile);
43 1068 ayeager
                                break;
44
                        case 'p':
45 1128 ayeager
                                setReadFile(optarg, &worldFile);
46 1068 ayeager
                                playLog(argc, argv);
47
                                return 0;
48
                                break;
49
                        case 'w':
50
                                load_world(optarg, 100);
51 1128 ayeager
                                worldFile = optarg;
52 1068 ayeager
                                worldLoadedFlag = 1;
53
                                break;
54
                        case ':':
55
                                fprintf(stderr, "Argument requires file name\n");
56
                                break;
57
                        case '?':
58
                                fprintf(stderr, "Unknown argument\n");
59
                                break;
60
                }
61 988 bcoltin
        }
62 1077 bcoltin
63
        if(argc - optind < 0){
64
                printf("Usage: simulator <robot execetuable>\n");
65
                exit(-1);
66
        }
67 1006 bcoltin
68 1068 ayeager
        if(!worldLoadedFlag)
69
                load_world("../test/world.txt", 100);
70 1039 bneuman
71 1077 bcoltin
        if (optind > 0 && optind < argc)
72
                robot_create(argv[optind]);
73 1045 bpoole
74 1006 bcoltin
        sigset_t set;
75
        //TODO: errors
76
        sigemptyset(&set);
77
        sigaddset(&set, SIGCHLD);
78
        pthread_sigmask(SIG_BLOCK, &set, NULL);
79
        g_thread_init(NULL);
80
        gdk_threads_init();
81
        g_thread_create(robot_event_loop, NULL, TRUE, NULL);
82
83
        //TODO: better thread to put this in?
84
        sigemptyset(&set);
85
        sigaddset(&set, SIGCHLD);
86
        pthread_sigmask(SIG_UNBLOCK, &set, NULL);
87
88 988 bcoltin
        gtk_gui_run(argc, argv);
89 981 bneuman
90 988 bcoltin
        return 0;
91 981 bneuman
}