/* **level\_data** is created and populated with * level specific entities. Some entities require further * initialization, such as the timeline. * A timeline allows creating a sequence of events * on a, well.. time line. Each event has a start time, * duration and callback function the will get called * each time the timeline is updated and if the event * is active. * We use a timeline to animate the title, creating 3 * events: (1) slide the title into the screen (2) * make the title "bling" and (3) slide the title out * of the screen. * Using the SECOND and SECONDS constant is for * the sake of readability only. */ static struct level_data* create_level_data(void) { struct level_data* ldata = calloc(1, sizeof(*ldata)); if (ldata == NULL) goto error; ldata->wizard = create_wizard(); if (ldata->wizard == NULL) goto cleanup_level_data; if (prepare_title(&ldata->title) != 0) goto cleanup_level_data; if (prepare_tree(&ldata->tree) != 0) goto cleanup_level_data; ldata->grass_tile = create_image("res/grass_tile.png"); if (ldata->grass_tile == NULL) goto cleanup_level_data; ldata->earth_tile = create_image("res/earth_tile.png"); if (ldata->earth_tile == NULL) goto cleanup_level_data; play_animation(ldata->tree.sprite, ldata->tree.windblow); ldata->timeline = create_timeline(); if (ldata->timeline == NULL) goto cleanup_level_data; append_event(ldata->timeline, 0, 1 * SECOND, before_title_in); append_event(ldata->timeline, 0, 1 * SECOND, slide_title_in); append_event(ldata->timeline, 0, 4 * SECONDS, bling_title); append_event(ldata->timeline, 0, 1 * SECOND, slide_title_out); ldata->font = create_font("res/font.png", 32, 4); if (ldata->font == NULL) goto cleanup_level_data; ldata->music = create_sound("res/wizard.ogg"); play_sound(ldata->music, -1); return ldata; cleanup_level_data: destroy_level_data(ldata); error: ERROR("Unable to create level data"); return NULL; }
int main (int argc, char *argv[]) { struct pollfd pfd; char line[4096], *p; char *name, *id, *polname, *filters; int nfilters, res; time_t curtime; GList *items = NULL; GtkWidget *systracewin; GtkWidget *processname; GtkWidget *policyname; GtkWidget *processid; GtkWidget *syscallinfo; GtkWidget *statusline; GtkWidget *timeline; GtkWidget *reviewbutton; GtkWidget *detachlabel; GtkWidget *filterentry; GtkStyle *default_style, *red_style; /* Set up required parameters */ parameters(); gtk_set_locale (); gtk_init (&argc, &argv); add_pixmap_directory (PACKAGE_DATA_DIR "/pixmaps"); add_pixmap_directory (PACKAGE_SOURCE_DIR "/pixmaps"); /* * The following code was added by Glade to create one of each component * (except popup menus), just so that you see something after building * the project. Delete any components that you don't want shown initially. */ systracewin = create_systracewin (); filterreview = create_filterreview(); wizard = create_wizard(); processname = lookup_widget(GTK_WIDGET(systracewin), "processname"); processid = lookup_widget(GTK_WIDGET(systracewin), "processid"); policyname = lookup_widget(GTK_WIDGET(systracewin), "policyname"); syscallinfo = lookup_widget(GTK_WIDGET(systracewin), "syscallinfo"); statusline = lookup_widget(GTK_WIDGET(systracewin), "statusline"); timeline = lookup_widget(GTK_WIDGET(systracewin), "timeline"); reviewbutton = lookup_widget(GTK_WIDGET(systracewin), "reviewbutton"); wizardbutton = lookup_widget(GTK_WIDGET(systracewin), "wizardbutton"); detachlabel = lookup_widget(GTK_WIDGET(systracewin), "detachlabel"); filterentry = lookup_widget(GTK_WIDGET(systracewin), "filterentry"); default_style = gtk_widget_get_style(processname); red_style = make_color(default_style, 0xd000, 0x1000, 0); red_style->private_font = gdk_font_load("-*-helvetica-bold-r-normal--*-140-*-*-*-*-iso8859-1"); gtk_widget_set_style(processname, red_style); gtk_widget_set_style(processid, red_style); gtk_widget_set_style(policyname, red_style); gtk_widget_set_style(syscallinfo, red_style); /* Return key is not supposed to pop it up */ gtk_combo_disable_activate(GTK_COMBO(filterentry)); /* Connect to cradle server if requested */ if (argc == 2 && strcmp(argv[1], "-C") == 0) { struct sockaddr_un sun; int s; char path[MAXPATHLEN]; snprintf(path, sizeof(path), "/tmp/systrace-%d/%s", getuid(), CRADLE_UI); if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) err(1, "socket()"); memset(&sun, 0, sizeof (sun)); sun.sun_family = AF_UNIX; if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >= sizeof(sun.sun_path)) errx(1, "Path too long: %s", path); if (connect(s, (struct sockaddr *)&sun, sizeof(sun)) == -1) err(1, "connect()"); if (dup2(s, fileno(stdin)) == -1) err(1, "dup2"); if (dup2(s, fileno(stdout)) == -1) err(1, "dup2"); } /* Make IO line buffered */ setvbuf(stdin, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0); while (1) { /* See if we can read from the file descriptor */ memset(&pfd, 0, sizeof(pfd)); pfd.fd = fileno(stdin); pfd.events = POLLIN; res = poll(&pfd, 1, 1000); if (res == -1) { if (errno == EINTR || errno == EAGAIN) break; } else if (res == 0) { while (gtk_events_pending()) gtk_main_iteration(); continue; } if (freadline(line, sizeof(line), stdin) == NULL) break; p = line; name = strsep(&p, ","); if (p == NULL || *p == '\0') errx(1, "Bad input line"); p++; strsep(&p, " "); if (p == NULL || *p == '\0') errx(1, "Bad input line"); id = strsep(&p, "("); if (p == NULL || *p == '\0') errx(1, "Bad input line"); strsep(&p, ":"); if (p == NULL || *p == '\0') errx(1, "Bad input line"); p++; polname = strsep(&p, ","); if (p == NULL || *p == '\0') errx(1, "Bad input line"); strsep(&p, ":"); if (p == NULL || *p == '\0') errx(1, "Bad input line"); p++; filters = strsep(&p, ","); if (p == NULL || *p == '\0') errx(1, "Bad input line"); nfilters = atoi(filters); strsep(&p, ":"); if (p == NULL || *p == '\0') errx(1, "Bad input line"); p++; gtk_label_set_text(GTK_LABEL(processname), name); gtk_label_set_text(GTK_LABEL(processid), id); gtk_label_set_text(GTK_LABEL(policyname), polname); gtk_label_set_text(GTK_LABEL(syscallinfo), p); gtk_label_set_text(GTK_LABEL(statusline), ""); items = make_policy_suggestion(p); curtime = time(NULL); snprintf(line, sizeof(line), "%.25s", ctime(&curtime)); gtk_label_set_text(GTK_LABEL(timeline), line); if (nfilters) { gtk_widget_set_sensitive(wizardbutton, 0); gtk_widget_set_sensitive(reviewbutton, 1); gtk_label_set_text(GTK_LABEL(detachlabel), "Automatic"); } else { gtk_widget_set_sensitive(wizardbutton, 1); gtk_widget_set_sensitive(reviewbutton, 0); gtk_label_set_text(GTK_LABEL(detachlabel), "Detach"); } gtk_widget_show (systracewin); gtk_combo_set_popdown_strings (GTK_COMBO(filterentry), items); g_list_foreach(items, free_list, NULL); g_list_free(items); do { gtk_main (); while (freadline(line, sizeof(line), stdin)) { if (!strcmp(line, "OKAY")) goto done; if (!strcmp(line, "WRONG")) break; gtk_label_set_text(GTK_LABEL(statusline), line); } } while (1); done: gtk_widget_hide (systracewin); while (gtk_events_pending()) gtk_main_iteration(); } return 0; }