Project

General

Profile

Statistics
| Revision:

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

History | View | Annotate | Download (1.56 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 1068 ayeager
35
        while((c = getopt(argc, argv, ":l:p:w:")) != -1)
36
        {
37
                switch(c)
38
                {
39
                        case 'l':
40
                                setLogFile(optarg);
41
                                break;
42
                        case 'p':
43
                                setLogFile(optarg);
44
                                playLog(argc, argv);
45
                                return 0;
46
                                break;
47
                        case 'w':
48
                                load_world(optarg, 100);
49
                                worldLoadedFlag = 1;
50
                                break;
51
                        case ':':
52
                                fprintf(stderr, "Argument requires file name\n");
53
                                break;
54
                        case '?':
55
                                fprintf(stderr, "Unknown argument\n");
56
                                break;
57
                }
58 988 bcoltin
        }
59 1077 bcoltin
60
        if(argc - optind < 0){
61
                printf("Usage: simulator <robot execetuable>\n");
62
                exit(-1);
63
        }
64 1006 bcoltin
65 1068 ayeager
        if(!worldLoadedFlag)
66
                load_world("../test/world.txt", 100);
67 1039 bneuman
68 1077 bcoltin
        if (optind > 0 && optind < argc)
69
                robot_create(argv[optind]);
70 1045 bpoole
71 1006 bcoltin
        sigset_t set;
72
        //TODO: errors
73
        sigemptyset(&set);
74
        sigaddset(&set, SIGCHLD);
75
        pthread_sigmask(SIG_BLOCK, &set, NULL);
76
        g_thread_init(NULL);
77
        gdk_threads_init();
78
        g_thread_create(robot_event_loop, NULL, TRUE, NULL);
79
80
        //TODO: better thread to put this in?
81
        sigemptyset(&set);
82
        sigaddset(&set, SIGCHLD);
83
        pthread_sigmask(SIG_UNBLOCK, &set, NULL);
84
85 988 bcoltin
        gtk_gui_run(argc, argv);
86 981 bneuman
87 988 bcoltin
        return 0;
88 981 bneuman
}