static void main_prog (void *closure, int argc, char *argv[]) { AppData data; GOptionContext *option_context; GError *error = NULL; gboolean retval; memset (&data, 0, sizeof (AppData)); option_context = g_option_context_new (NULL); g_option_context_set_translation_domain (option_context, GETTEXT_PACKAGE); add_main_options (option_context, &data); ar_sound_enable (FALSE); g_option_context_add_group (option_context, gtk_get_option_group (TRUE)); #ifdef HAVE_CLUTTER g_option_context_add_group (option_context, cogl_get_option_group ()); g_option_context_add_group (option_context, clutter_get_option_group_without_init ()); g_option_context_add_group (option_context, gtk_clutter_get_option_group ()); #endif /* HAVE_CLUTTER */ retval = g_option_context_parse (option_context, &argc, &argv, &error); g_option_context_free (option_context); if (!retval) { g_printerr ("%s\n", error->message); g_error_free (error); goto cleanup; } g_set_application_name (data.freecell ? _("FreeCell Solitaire") : _("AisleRiot")); aisleriot_conf_init (); /* If we are asked for a specific game, check that it is valid. */ if (!data.freecell && data.variation != NULL) { char *game_module = NULL; if (data.variation[0] != '\0') { game_module = ar_filename_to_game_module (data.variation); } g_free (data.variation); data.variation = game_module; } if (!data.freecell && !data.variation) { char *pref; pref = ar_conf_get_string_with_default (NULL, aisleriot_conf_get_key (CONF_VARIATION), DEFAULT_VARIATION); data.variation = ar_filename_to_game_module (pref); g_free (pref); } g_assert (data.variation != NULL || data.freecell); ar_stock_init (); gtk_window_set_default_icon_name (data.freecell ? "gnome-freecell" : "gnome-aisleriot"); data.window = AISLERIOT_WINDOW (aisleriot_window_new (data.freecell)); g_signal_connect (data.window, "destroy", G_CALLBACK (gtk_main_quit), NULL); if (data.freecell) { aisleriot_window_set_game_module (data.window, FREECELL_VARIATION, NULL); } else { aisleriot_window_set_game_module (data.window, data.variation, NULL); } gtk_window_present (GTK_WINDOW (data.window)); gtk_main (); aisleriot_conf_shutdown (); cleanup: g_free (data.variation); g_settings_sync (); ar_runtime_shutdown (); }
void gdict_init (int *argc, char ***argv) { GError *err = NULL; GOptionContext *context; gchar *loader_path; gchar **lookup_words = NULL; gchar **match_words = NULL; gchar *database = NULL; gchar *strategy = NULL; gchar *source_name = NULL; gboolean no_window = FALSE; gboolean list_sources = FALSE; const GOptionEntry gdict_app_goptions[] = { { "look-up", 0, 0, G_OPTION_ARG_STRING_ARRAY, &lookup_words, N_("Words to look up"), N_("word") }, { "match", 0, 0, G_OPTION_ARG_STRING_ARRAY, &match_words, N_("Words to match"), N_("word") }, { "source", 's', 0, G_OPTION_ARG_STRING, &source_name, N_("Dictionary source to use"), N_("source") }, { "list-sources", 'l', 0, G_OPTION_ARG_NONE, &list_sources, N_("Show available dictionary sources"), NULL }, { "no-window", 'n', 0, G_OPTION_ARG_NONE, &no_window, N_("Print result to the console"), NULL }, { "database", 'D', 0, G_OPTION_ARG_STRING, &database, N_("Database to use"), N_("db") }, { "strategy", 'S', 0, G_OPTION_ARG_STRING, &strategy, N_("Strategy to use"), N_("strat") }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &lookup_words, N_("Words to look up"), N_("word") }, { NULL }, }; g_assert (singleton == NULL); singleton = GDICT_APP (g_object_new (GDICT_TYPE_APP, NULL)); g_assert (GDICT_IS_APP (singleton)); /* create the new option context */ context = g_option_context_new (_(" - Look up words in dictionaries")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); g_option_context_add_main_entries (context, gdict_app_goptions, GETTEXT_PACKAGE); g_option_context_add_group (context, gdict_get_option_group ()); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_parse (context, argc, argv, &err); if (err) { g_critical ("Failed to parse argument: %s", err->message); g_error_free (err); g_option_context_free (context); gdict_cleanup (); exit (1); } g_set_application_name (_("Dictionary")); gtk_window_set_default_icon_name ("accessories-dictionary"); if (!gdict_create_data_dir ()) { gdict_cleanup (); exit (1); } singleton->settings = g_settings_new ("org.mate.dictionary"); /* add user's path for fetching dictionary sources */ singleton->loader = gdict_source_loader_new (); loader_path = gdict_get_data_dir (); gdict_source_loader_add_search_path (singleton->loader, loader_path); g_free (loader_path); if (lookup_words) { gsize i; gsize length = g_strv_length (lookup_words); for (i = 0; i < length; i++) singleton->lookup_words = g_slist_prepend (singleton->lookup_words, g_strdup (lookup_words[i])); } if (match_words) { gsize i; gsize length = g_strv_length (match_words); for (i = 0; i < length; i++) singleton->match_words = g_slist_prepend (singleton->match_words, g_strdup (match_words[i])); } if (database) singleton->database = g_strdup (database); if (source_name) singleton->source_name = g_strdup (source_name); if (no_window) singleton->no_window = TRUE; if (list_sources) singleton->list_sources = TRUE; }
int main (int argc, char **argv) { GOptionContext *ctx; GError *error = NULL; int ecode; TpDebugSender *sender; bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); session_mode = (char *) g_getenv ("GNOME_SHELL_SESSION_MODE"); ctx = meta_get_option_context (); g_option_context_add_main_entries (ctx, gnome_shell_options, GETTEXT_PACKAGE); g_option_context_add_group (ctx, g_irepository_get_option_group ()); if (!g_option_context_parse (ctx, &argc, &argv, &error)) { g_printerr ("%s: %s\n", argv[0], error->message); exit (1); } g_option_context_free (ctx); meta_plugin_manager_set_plugin_type (gnome_shell_plugin_get_type ()); meta_set_wm_name (WM_NAME); meta_set_gnome_wm_keybindings (GNOME_WM_KEYBINDINGS); /* Prevent meta_init() from causing gtk to load the atk-bridge*/ g_setenv ("NO_AT_BRIDGE", "1", TRUE); meta_init (); g_unsetenv ("NO_AT_BRIDGE"); /* FIXME: Add gjs API to set this stuff and don't depend on the * environment. These propagate to child processes. */ g_setenv ("GJS_DEBUG_OUTPUT", "stderr", TRUE); g_setenv ("GJS_DEBUG_TOPICS", "JS ERROR;JS LOG", TRUE); shell_init_debug (g_getenv ("SHELL_DEBUG")); shell_dbus_init (meta_get_replace_current_wm ()); shell_a11y_init (); shell_perf_log_init (); shell_introspection_init (); shell_fonts_init (); /* Turn on telepathy-glib debugging but filter it out in * default_log_handler. This handler also exposes all the logs over D-Bus * using TpDebugSender. */ tp_debug_set_flags ("all"); sender = tp_debug_sender_dup (); g_log_set_default_handler (default_log_handler, sender); /* Initialize the global object */ if (session_mode == NULL) session_mode = is_gdm_mode ? (char *)"gdm" : (char *)"user"; _shell_global_init ("session-mode", session_mode, NULL); shell_prefs_init (); ecode = meta_run (); if (g_getenv ("GNOME_SHELL_ENABLE_CLEANUP")) { g_printerr ("Doing final cleanup...\n"); g_object_unref (shell_global_get ()); } g_object_unref (sender); return ecode; }
int main (int argc, char **argv) { GError *err = NULL; GOptionContext *g_option_context; double x_zoom = 1.0; double y_zoom = 1.0; double dpi_x = -1.0; double dpi_y = -1.0; int width = -1; int height = -1; int bVersion = 0; char *bg_color = NULL; char *base_uri = NULL; int bKeepAspect = 0; char *id = NULL; int xid = -1; int from_stdin = 0; ViewerCbInfo info; struct RsvgSizeCallbackData size_data; char **args = NULL; gint n_args = 0; GOptionEntry options_table[] = { #ifdef ENABLE_XEMBED {"xid", 'i', 0, G_OPTION_ARG_INT, &xid, N_("XWindow ID [for X11 embedding]"), N_("<int>")}, #endif {"stdin", 's', 0, G_OPTION_ARG_NONE, &from_stdin, N_("Read from stdin instead of a file"), NULL}, {"dpi-x", 'd', 0, G_OPTION_ARG_DOUBLE, &dpi_x, N_("Set the # of Pixels Per Inch"), N_("<float>")}, {"dpi-y", 'p', 0, G_OPTION_ARG_DOUBLE, &dpi_y, N_("Set the # of Pixels Per Inch"), N_("<float>")}, {"x-zoom", 'x', 0, G_OPTION_ARG_DOUBLE, &x_zoom, N_("Set the x zoom factor"), N_("<float>")}, {"y-zoom", 'y', 0, G_OPTION_ARG_DOUBLE, &y_zoom, N_("Set the y zoom factor"), N_("<float>")}, {"width", 'w', 0, G_OPTION_ARG_INT, &width, N_("Set the image's width"), N_("<int>")}, {"height", 'h', 0, G_OPTION_ARG_INT, &height, N_("Set the image's height"), N_("<int>")}, {"bg-color", 'b', 0, G_OPTION_ARG_STRING, &bg_color, N_("Set the image background color (default: transparent)"), N_("<string>")}, {"base-uri", 'u', 0, G_OPTION_ARG_STRING, &base_uri, N_("Set the base URI (default: none)"), N_("<string>")}, {"id", 0, 0, G_OPTION_ARG_STRING, &id, N_("Only show one node (default: all)"), N_("<string>")}, {"keep-aspect", 'k', 0, G_OPTION_ARG_NONE, &bKeepAspect, N_("Preserve the image's aspect ratio"), NULL}, {"version", 'v', 0, G_OPTION_ARG_NONE, &bVersion, N_("Show version information"), NULL}, {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &args, NULL, N_("[FILE...]")}, {NULL} }; g_thread_init (NULL); info.pixbuf = NULL; info.svg_bytes = NULL; info.window = NULL; info.popup_menu = NULL; g_option_context = g_option_context_new ("- SVG Viewer"); g_option_context_add_main_entries (g_option_context, options_table, NULL); g_option_context_add_group (g_option_context, gtk_get_option_group (TRUE)); g_option_context_set_help_enabled (g_option_context, TRUE); if (!g_option_context_parse (g_option_context, &argc, &argv, NULL)) { exit (1); } g_option_context_free (g_option_context); if (bVersion != 0) { g_message (_("rsvg-view version %s\n"), VERSION); return 0; } if (args) { while (args[n_args] != NULL) n_args++; } if ((!from_stdin) && (n_args != 1)) { g_print (_("No files specified, and not using --stdin\n")); return 1; } /* initialize gtk+ and rsvg */ rsvg_init (); rsvg_set_default_dpi_x_y (dpi_x, dpi_y); /* if both are unspecified, assume user wants to zoom the pixbuf in at least 1 dimension */ if (width == -1 && height == -1) { size_data.type = RSVG_SIZE_ZOOM; size_data.x_zoom = x_zoom; size_data.y_zoom = y_zoom; } /* if both are unspecified, assume user wants to resize pixbuf in at least 1 dimension */ else if (x_zoom == 1.0 && y_zoom == 1.0) { size_data.type = RSVG_SIZE_WH; size_data.width = width; size_data.height = height; } /* assume the user wants to zoom the pixbuf, but cap the maximum size */ else { size_data.type = RSVG_SIZE_ZOOM_MAX; size_data.x_zoom = x_zoom; size_data.y_zoom = y_zoom; size_data.width = width; size_data.height = height; } size_data.keep_aspect_ratio = bKeepAspect; if (!from_stdin) { if (base_uri == NULL) base_uri = (char *) args[0]; info.svg_bytes = _rsvg_acquire_xlink_href_resource (args[0], base_uri, NULL); } else { info.svg_bytes = g_byte_array_new (); for (;;) { unsigned char buf[1024 * 8]; size_t nread = fread (buf, 1, sizeof (buf), stdin); if (nread > 0) g_byte_array_append (info.svg_bytes, buf, nread); if (nread < sizeof (buf)) { if (ferror (stdin)) { g_print (_("Error reading\n")); g_byte_array_free (info.svg_bytes, TRUE); fclose (stdin); return 1; } else if (feof (stdin)) break; } } fclose (stdin); } if (!info.svg_bytes || !info.svg_bytes->len) { g_print (_("Couldn't open %s\n"), args[0]); return 1; } info.base_uri = base_uri; info.id = id; info.pixbuf = pixbuf_from_data_with_size_data (info.svg_bytes->data, info.svg_bytes->len, &size_data, base_uri, id, &err); if (!info.pixbuf) { g_print (_("Error displaying image")); if (err) { g_print (": %s", err->message); g_error_free (err); } g_print ("\n"); return 1; } info.accel_group = gtk_accel_group_new (); view_pixbuf (&info, xid, bg_color); /* run the gtk+ main loop */ gtk_main (); g_object_unref (G_OBJECT (info.pixbuf)); g_byte_array_free (info.svg_bytes, TRUE); rsvg_term (); return 0; }
int main (int argc, char **argv) { GstPlay *play; GPtrArray *playlist; gboolean print_version = FALSE; gboolean gapless = FALSE; gchar **filenames = NULL; gchar *audio_sink = NULL; gchar *video_sink = NULL; gchar **uris; guint num, i; GError *err = NULL; GOptionContext *ctx; GOptionEntry options[] = { {"version", 0, 0, G_OPTION_ARG_NONE, &print_version, N_("Print version information and exit"), NULL}, {"videosink", 0, 0, G_OPTION_ARG_STRING, &video_sink, N_("Video sink to use (default is autovideosink)"), NULL}, {"audiosink", 0, 0, G_OPTION_ARG_STRING, &audio_sink, N_("Audio sink to use (default is autoaudiosink)"), NULL}, {"gapless", 0, 0, G_OPTION_ARG_NONE, &gapless, N_("Enable gapless playback"), NULL}, {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL}, {NULL} }; #ifdef ENABLE_NLS bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif g_set_prgname ("gst-play-" GST_API_VERSION); ctx = g_option_context_new ("FILE1|URI1 [FILE2|URI2] [FILE3|URI3] ..."); g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE); g_option_context_add_group (ctx, gst_init_get_option_group ()); if (!g_option_context_parse (ctx, &argc, &argv, &err)) { g_print ("Error initializing: %s\n", GST_STR_NULL (err->message)); return 1; } g_option_context_free (ctx); GST_DEBUG_CATEGORY_INIT (play_debug, "play", 0, "gst-play"); if (print_version) { gchar *version_str; version_str = gst_version_string (); g_print ("%s version %s\n", g_get_prgname (), PACKAGE_VERSION); g_print ("%s\n", version_str); g_print ("%s\n", GST_PACKAGE_ORIGIN); g_free (version_str); return 0; } if (filenames == NULL || *filenames == NULL) { g_printerr (_("Usage: %s FILE1|URI1 [FILE2|URI2] [FILE3|URI3] ..."), "gst-play-" GST_API_VERSION); g_printerr ("\n\n"), g_printerr ("%s\n\n", _("You must provide at least one filename or URI to play.")); return 1; } playlist = g_ptr_array_new (); /* fill playlist */ num = g_strv_length (filenames); for (i = 0; i < num; ++i) { GST_LOG ("command line argument: %s", filenames[i]); add_to_playlist (playlist, filenames[i]); } g_strfreev (filenames); g_ptr_array_add (playlist, NULL); /* play */ uris = (gchar **) g_ptr_array_free (playlist, FALSE); play = play_new (uris, audio_sink, video_sink, gapless); do_play (play); /* clean up */ play_free (play); return 0; }
/*------------------------- read command line options ------------------------*/ void readOpts(int argc,char *argv[], struct GLOBAL *global) { gchar *device=NULL; gchar *format=NULL; gchar *size = NULL; gchar *image = NULL; gchar *video=NULL; gchar *profile=NULL; gchar *separateur=NULL; gboolean help = FALSE; gboolean help_gtk = FALSE; gboolean help_all = FALSE; gboolean vers = FALSE; gchar *help_str = NULL; gchar *help_gtk_str = NULL; gchar *help_all_str = NULL; gchar *config = NULL; int hwaccel=-1; int FpsCount=-1; int cap_meth=-1; GOptionEntry entries[] = { { "help-all", 'h', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &help_all, "Display all help options", NULL}, { "help-gtk", '!', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &help_gtk, "DISPLAY GTK+ help", NULL}, { "help", '?', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &help, "Display help", NULL}, { "version", 0, 0, G_OPTION_ARG_NONE, &vers, N_("Prints version"), NULL}, { "verbose", 'v', 0, G_OPTION_ARG_NONE, &global->debug, N_("Displays debug information"), NULL }, { "device", 'd', 0, G_OPTION_ARG_STRING, &device, N_("Video Device to use [default: /dev/video0]"), "VIDEO_DEVICE" }, { "add_ctrls", 'a', 0, G_OPTION_ARG_NONE, &global->add_ctrls, N_("Exit after adding UVC extension controls (needs root/sudo)"), NULL}, { "control_only", 'o', 0, G_OPTION_ARG_NONE, &global->control_only, N_("Don't stream video (image controls only)"), NULL}, { "no_display", 0,0, G_OPTION_ARG_NONE, &global->no_display, N_("Don't display a GUI"), NULL}, { "capture_method", 'r', 0, G_OPTION_ARG_INT, &cap_meth, N_("Capture method (1-mmap (default) 2-read)"), "[1 | 2]"}, { "config", 'g', 0, G_OPTION_ARG_STRING, &config, N_("Configuration file"), "FILENAME" }, { "hwd_acel", 'w', 0, G_OPTION_ARG_INT, &hwaccel, N_("Hardware accelaration (enable(1) | disable(0))"), "[1 | 0]" }, { "format", 'f', 0, G_OPTION_ARG_STRING, &format, N_("Pixel format(mjpg|jpeg|yuyv|yvyu|uyvy|yyuv|yu12|yv12|nv12|nv21|nv16|nv61|y41p|grey|y10b|y16 |s501|s505|s508|gbrg|grbg|ba81|rggb|bgr3|rgb3)"), "FORMAT" }, { "size", 's', 0, G_OPTION_ARG_STRING, &size, N_("Frame size, default: 640x480"), "WIDTHxHEIGHT"}, { "image", 'i', 0, G_OPTION_ARG_STRING, &image, N_("Image File name"), "FILENAME"}, { "cap_time", 'c', 0, G_OPTION_ARG_INT, &global->image_timer, N_("Image capture interval in seconds"), "TIME"}, { "npics", 'm', 0, G_OPTION_ARG_INT, &global->image_npics, N_("Number of Pictures to capture"), "NUMPIC"}, { "video", 'n', 0, G_OPTION_ARG_STRING, &video, N_("Video File name (capture from start)"), "FILENAME"}, { "vid_time", 't', 0, G_OPTION_ARG_INT, &global->Capture_time,N_("Video capture time (in seconds)"), "TIME"}, { "exit_on_close", 0, 0, G_OPTION_ARG_NONE, &global->exit_on_close, N_("Exits guvcview after closing video"), NULL}, { "skip", 'j', 0, G_OPTION_ARG_INT, &global->skip_n, N_("Number of initial frames to skip"), "N_FRAMES"}, { "show_fps", 'p', 0, G_OPTION_ARG_INT, &FpsCount, N_("Show FPS value (enable(1) | disable (0))"), "[1 | 0]"}, { "profile", 'l', 0, G_OPTION_ARG_STRING, &profile, N_("Load Profile at start"), "FILENAME"}, { "lctl_method", 'k', 0, G_OPTION_ARG_INT, &global->lctl_method, N_("List controls method (0:loop, 1:next_ctrl flag [def])"), "[0 |1]"}, { NULL } }; GError *error = NULL; GOptionContext *context; context = g_option_context_new (N_("- local options")); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_set_prgname (PACKAGE); help_str = g_option_context_get_help (context, TRUE, NULL); help_gtk_str = g_option_context_get_help (context, FALSE, gtk_get_option_group (TRUE)); help_all_str = g_option_context_get_help (context, FALSE, NULL); /*disable automatic help parsing - must clean global before exit*/ g_option_context_set_help_enabled (context, FALSE); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("option parsing failed: %s\n", error->message); g_error_free ( error ); closeGlobals(global); global=NULL; g_print("%s",help_all_str); g_free(help_all_str); g_free(help_str); g_free(help_gtk_str); g_option_context_free (context); exit (1); } if(vers) { //print version and exit //version already printed in guvcview.c closeGlobals(global); global=NULL; g_free(help_all_str); g_free(help_str); g_free(help_gtk_str); g_option_context_free (context); exit(0); } /*Display help message and exit*/ if(help_all) { closeGlobals(global); global=NULL; g_print("%s",help_all_str); g_free(help_all_str); g_free(help_str); g_free(help_gtk_str); g_option_context_free (context); exit(0); } else if(help) { closeGlobals(global); global=NULL; g_print("%s",help_str); g_free(help_str); g_free(help_gtk_str); g_free(help_all_str); g_option_context_free (context); exit(0); } else if(help_gtk) { closeGlobals(global); global=NULL; g_print("%s",help_gtk_str); g_free(help_str); g_free(help_gtk_str); g_free(help_all_str); g_option_context_free (context); exit(0); } /*regular options*/ if(device) { gchar *basename = NULL; gchar *dirname = NULL; basename = g_path_get_basename(device); if(!(g_str_has_prefix(basename,"video"))) { g_printerr("%s not a valid video device name\n", basename); } else { g_free(global->videodevice); global->videodevice=NULL; dirname = g_path_get_dirname(device); if(g_strcmp0(".",dirname)==0) { g_free(dirname); dirname=g_strdup("/dev"); } global->videodevice = g_strjoin("/", dirname, basename, NULL); if(global->flg_config < 1) { if(g_strcmp0("video0",basename) !=0 ) { g_free(global->confPath); global->confPath=NULL; global->confPath = g_strjoin("/", g_get_home_dir(), ".config", "guvcview", basename, NULL); } } } g_free(dirname); g_free(basename); } if(config) { g_free(global->confPath); global->confPath=NULL; global->confPath = g_strdup(config); global->flg_config = 1; } if(format) { /*use fourcc but keep compatability with luvcview*/ if(g_strcmp0("yuv",format)==0) g_snprintf(global->mode,5,"yuyv"); else if (g_strcmp0("bggr",format)==0) // be compatible with guvcview < 1.1.4 g_snprintf(global->mode,5,"ba81"); else g_snprintf(global->mode,5,"%s ",format); printf("requested format \"%s\" from command line\n", global->mode); global->flg_mode = TRUE; } if(size) { global->width = (int) g_ascii_strtoull(size, &separateur, 10); if (*separateur != 'x') { g_printerr("Error in size usage: -s[--size] WIDTHxHEIGHT \n"); } else { ++separateur; global->height = (int) g_ascii_strtoull(separateur, &separateur, 10); if (*separateur != 0) g_printerr("hmm.. don't like that!! trying this height \n"); } global->flg_res = 1; } if(image) { global->imgFPath=splitPath(image,global->imgFPath); /*get the file type*/ global->imgFormat = check_image_type(global->imgFPath[0]); global->flg_imgFPath = TRUE; if(global->image_inc>0) { uint64_t suffix = get_file_suffix(global->imgFPath[1], global->imgFPath[0]); fprintf(stderr, "Image file suffix detected: %" PRIu64 "\n", suffix); if(suffix >= G_MAXUINT64) { global->imgFPath[0] = add_file_suffix(global->imgFPath[0], suffix); suffix = 0; } if(suffix > 0) { global->image_inc = suffix + 1; } } } if(global->image_timer > 0 ) { g_print("capturing images every %i seconds\n",global->image_timer); } if(video) { global->vidFPath=splitPath(video, global->vidFPath); if(global->vid_inc>0) { uint64_t suffix = get_file_suffix(global->vidFPath[1], global->vidFPath[0]); fprintf(stderr, "Video file suffix detected: %" PRIu64 "\n", suffix); if(suffix >= G_MAXUINT64) { global->vidFPath[0] = add_file_suffix(global->vidFPath[0], suffix); suffix = 0; } if(suffix > 0) global->vid_inc = suffix + 1; } global->vidfile = joinPath(global->vidfile, global->vidFPath); g_print("capturing video: %s , from start\n",global->vidfile); /*get the file type*/ global->VidFormat = check_video_type(global->vidFPath[0]); } if(profile) { global->lprofile=1; global->profile_FPath=splitPath(profile,global->profile_FPath); } if(hwaccel != -1 ) { global->hwaccel = hwaccel; global->flg_hwaccel = 1; } if(FpsCount != -1) { global->FpsCount = FpsCount; global->flg_FpsCount = 1; } if(cap_meth != -1) { global->flg_cap_meth = TRUE; global->cap_meth = cap_meth; } //g_print("option capture meth is %i\n", global->cap_meth); g_free(help_str); g_free(help_gtk_str); g_free(help_all_str); g_free(device); g_free(config); g_free(format); g_free(size); g_free(image); g_free(video); g_free(profile); g_option_context_free (context); }
int main (int argc, char *argv[]) { TpAccountManager *account_manager; GError *error = NULL; UniqueApp *unique_app; GOptionContext *optcontext; GOptionEntry options[] = { { "hidden", 'h', 0, G_OPTION_ARG_NONE, &hidden, N_("Don't display any dialogs; do any work (eg, importing) and exit"), NULL }, { "if-needed", 'n', 0, G_OPTION_ARG_NONE, &only_if_needed, N_("Don't display any dialogs if there are any non-salut accounts"), NULL }, { "select-account", 's', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &selected_account_name, N_("Initially select given account (eg, " "gabble/jabber/foo_40example_2eorg0)"), N_("<account-id>") }, { NULL } }; g_thread_init (NULL); empathy_init (); optcontext = g_option_context_new (N_("- Empathy Accounts")); g_option_context_add_group (optcontext, gtk_get_option_group (TRUE)); g_option_context_add_main_entries (optcontext, options, GETTEXT_PACKAGE); if (!g_option_context_parse (optcontext, &argc, &argv, &error)) { g_print ("%s\nRun '%s --help' to see a full list of available command line options.\n", error->message, argv[0]); g_warning ("Error in empathy init: %s", error->message); return EXIT_FAILURE; } g_option_context_free (optcontext); empathy_gtk_init (); g_set_application_name (_("Empathy Accounts")); gtk_window_set_default_icon_name ("empathy"); textdomain (GETTEXT_PACKAGE); unique_app = unique_app_new (EMPATHY_ACCOUNTS_DBUS_NAME, NULL); if (unique_app_is_running (unique_app)) { unique_app_send_message (unique_app, UNIQUE_ACTIVATE, NULL); g_object_unref (unique_app); return EXIT_SUCCESS; } account_manager = tp_account_manager_dup (); tp_account_manager_prepare_async (account_manager, NULL, account_manager_ready_for_accounts_cb, selected_account_name); g_signal_connect (unique_app, "message-received", G_CALLBACK (unique_app_message_cb), NULL); gtk_main (); g_object_unref (account_manager); g_object_unref (unique_app); return EXIT_SUCCESS; }
// Main int main(int argc, char* argv[]) { // Setup cmd const gchar* cmd_drv_rx = "pcap"; const gchar* cmd_mode_rx = "file"; const gchar* cmd_dev_rx = "test-rx.pcap"; const gchar* cmd_drv_tx = "none"; const gchar* cmd_mode_tx = "file"; const gchar* cmd_dev_tx = "test-tx.pcap"; GOptionEntry cmd_entry_main[] = { { "rx-drv", '\0', 0, G_OPTION_ARG_STRING, &cmd_drv_rx, "RX driver" }, { "rx-mode", '\0', 0, G_OPTION_ARG_STRING, &cmd_mode_rx, "RX mode (dev / file)" }, { "rx-dev", '\0', 0, G_OPTION_ARG_STRING, &cmd_dev_rx, "RX device (wlan0 / eth0 / file.pcap)" }, { "tx-drv", '\0', 0, G_OPTION_ARG_STRING, &cmd_drv_tx, "TX driver" }, { "tx-mode", '\0', 0, G_OPTION_ARG_STRING, &cmd_mode_tx, "TX mode (dev / file)" }, { "tx-dev", '\0', 0, G_OPTION_ARG_STRING, &cmd_dev_tx, "TX device (wlan0 / eth0 / file.pcap)" }, { NULL } }; gboolean cmd_list_pcap = false; gboolean cmd_list_lorcon = false; gboolean cmd_list_netlink = false; GOptionEntry cmd_entry_driver[] = { #ifdef PCAP_FOUND { "list-pcap", '\0', 0, G_OPTION_ARG_NONE, &cmd_list_pcap, "PCAP device list" }, #endif #ifdef LORCON_FOUND { "list-lorcon", '\0', 0, G_OPTION_ARG_NONE, &cmd_list_lorcon, "LORCON device list" }, #endif #ifdef NETLINK_FOUND { "list-netlink", '\0', 0, G_OPTION_ARG_NONE, &cmd_list_netlink, "NETLINK device list" }, #endif { NULL } }; // Parse cmd GError* cmd_error = NULL; GOptionContext* cmd_ctx = g_option_context_new("- packet injection tool"); g_option_context_add_main_entries(cmd_ctx, cmd_entry_main, NULL); GOptionGroup* cmd_lgrp = g_option_group_new("list", "Driver devices", "Driver devices", NULL, NULL); g_option_group_add_entries(cmd_lgrp, cmd_entry_driver); g_option_context_add_group(cmd_ctx, cmd_lgrp); g_option_context_set_description(cmd_ctx, "Supported drivers:\n" #ifdef PCAP_FOUND " * pcap\n" #endif #ifdef LORCON_FOUND " * lorcon\n" #endif #ifdef NETLINK_FOUND " * netlink\n" #endif ); if (!g_option_context_parse(cmd_ctx, &argc, &argv, &cmd_error)) { g_message("Option parsing failed: %s", cmd_error->message); exit(1); } // Signal setup if (signal(SIGINT, ao_signal) == SIG_ERR) { g_critical("[sys] failed to set SIGINT signal handler!"); } else if (signal(SIGWINCH, ao_signal) == SIG_ERR) { g_critical("[sys] failed to set SIGWINCH signal handler!"); } // Threads g_thread_init(NULL); // Lists if (cmd_list_pcap || cmd_list_lorcon || cmd_list_netlink) { // Console c_ui_console* ui = new c_ui_console(); ui->init(); // Show if (cmd_list_pcap) { #ifdef PCAP_FOUND c_drv_pcap::help(); #else g_critical("Pcap driver not compiled in this binary!"); #endif } if (cmd_list_lorcon) { #ifdef LORCON_FOUND c_drv_lorcon::help(); #else g_critical("Lorcon driver not compiled in this binary!"); #endif } if (cmd_list_netlink) { #ifdef NETLINK_FOUND c_drv_netlink::help(); #else g_critical("Netlink driver not compiled in this binary!"); #endif } // Quit exit(0); } // Context ao_inst = new c_context(); if (ao_inst->init(cmd_drv_rx, cmd_mode_rx, cmd_dev_rx, cmd_drv_tx, cmd_mode_tx, cmd_dev_tx)) { ao_inst->run(); } delete ao_inst; // Return return 0; }
int main (int argc, char **argv) { GstPlay *play; GPtrArray *playlist; gboolean print_version = FALSE; gboolean interactive = FALSE; /* FIXME: maybe enable by default? */ gboolean shuffle = FALSE; gboolean repeat = FALSE; gdouble volume = 1.0; gchar **filenames = NULL; gchar **uris; guint num, i; GError *err = NULL; GOptionContext *ctx; gchar *playlist_file = NULL; GOptionEntry options[] = { {"version", 0, 0, G_OPTION_ARG_NONE, &print_version, "Print version information and exit", NULL}, {"shuffle", 0, 0, G_OPTION_ARG_NONE, &shuffle, "Shuffle playlist", NULL}, {"interactive", 0, 0, G_OPTION_ARG_NONE, &interactive, "Interactive control via keyboard", NULL}, {"volume", 0, 0, G_OPTION_ARG_DOUBLE, &volume, "Volume", NULL}, {"playlist", 0, 0, G_OPTION_ARG_FILENAME, &playlist_file, "Playlist file containing input media files", NULL}, {"loop", 0, 0, G_OPTION_ARG_NONE, &repeat, "Repeat all", NULL}, {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL}, {NULL} }; g_set_prgname ("gst-play"); ctx = g_option_context_new ("FILE1|URI1 [FILE2|URI2] [FILE3|URI3] ..."); g_option_context_add_main_entries (ctx, options, NULL); g_option_context_add_group (ctx, gst_init_get_option_group ()); if (!g_option_context_parse (ctx, &argc, &argv, &err)) { g_print ("Error initializing: %s\n", GST_STR_NULL (err->message)); g_clear_error (&err); g_option_context_free (ctx); return 1; } g_option_context_free (ctx); GST_DEBUG_CATEGORY_INIT (play_debug, "play", 0, "gst-play"); if (print_version) { gchar *version_str; version_str = gst_version_string (); g_print ("%s version %s\n", g_get_prgname (), "1.0"); g_print ("%s\n", version_str); g_free (version_str); g_free (playlist_file); return 0; } playlist = g_ptr_array_new (); if (playlist_file != NULL) { gchar *playlist_contents = NULL; gchar **lines = NULL; if (g_file_get_contents (playlist_file, &playlist_contents, NULL, &err)) { lines = g_strsplit (playlist_contents, "\n", 0); num = g_strv_length (lines); for (i = 0; i < num; i++) { if (lines[i][0] != '\0') { GST_LOG ("Playlist[%d]: %s", i + 1, lines[i]); add_to_playlist (playlist, lines[i]); } } g_strfreev (lines); g_free (playlist_contents); } else { g_printerr ("Could not read playlist: %s\n", err->message); g_clear_error (&err); } g_free (playlist_file); playlist_file = NULL; } if (playlist->len == 0 && (filenames == NULL || *filenames == NULL)) { g_printerr ("Usage: %s FILE1|URI1 [FILE2|URI2] [FILE3|URI3] ...", "gst-play"); g_printerr ("\n\n"), g_printerr ("%s\n\n", "You must provide at least one filename or URI to play."); /* No input provided. Free array */ g_ptr_array_free (playlist, TRUE); return 1; } /* fill playlist */ if (filenames != NULL && *filenames != NULL) { num = g_strv_length (filenames); for (i = 0; i < num; ++i) { GST_LOG ("command line argument: %s", filenames[i]); add_to_playlist (playlist, filenames[i]); } g_strfreev (filenames); } num = playlist->len; g_ptr_array_add (playlist, NULL); uris = (gchar **) g_ptr_array_free (playlist, FALSE); if (shuffle) shuffle_uris (uris, num); /* prepare */ play = play_new (uris, volume); play->repeat = repeat; if (interactive) { if (gst_play_kb_set_key_handler (keyboard_cb, play)) { atexit (restore_terminal); } else { g_print ("Interactive keyboard handling in terminal not available.\n"); } } /* play */ do_play (play); /* clean up */ play_free (play); g_print ("\n"); return 0; }
gint main (gint argc, gchar **argv) { GOptionContext *context; PanelApplication *application; GError *error = NULL; PanelDBusService *dbus_service; gboolean succeed = FALSE; gboolean remote_succeed; guint i; const gint signums[] = { SIGINT, SIGQUIT, SIGTERM, SIGABRT, SIGUSR1 }; const gchar *error_msg; XfceSMClient *sm_client; panel_debug (PANEL_DEBUG_MAIN, "version %s on gtk+ %d.%d.%d (%d.%d.%d), glib %d.%d.%d (%d.%d.%d)", LIBXFCE4PANEL_VERSION, gtk_major_version, gtk_minor_version, gtk_micro_version, GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION, glib_major_version, glib_minor_version, glib_micro_version, GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION); /* inform the user about usage of gdb/valgrind */ panel_debug_notify_proxy (); /* set translation domain */ xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8"); #ifdef G_ENABLE_DEBUG /* do NOT remove this line for now, If something doesn't work, * fix your code instead! */ g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); #endif /* parse context options */ context = g_option_context_new (_("[ARGUMENTS...]")); g_option_context_add_main_entries (context, option_entries, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_add_group (context, xfce_sm_client_get_option_group (argc, argv)); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_print ("%s: %s.\n", PACKAGE_NAME, error->message); g_print (_("Type \"%s --help\" for usage."), G_LOG_DOMAIN); g_print ("\n"); g_error_free (error); return EXIT_FAILURE; } g_option_context_free (context); gtk_init (&argc, &argv); if (opt_version) { /* print version information */ if (opt_arguments != NULL && *opt_arguments != NULL) g_print ("%s (%s)", *opt_arguments, PACKAGE_NAME); else g_print ("%s", PACKAGE_NAME); g_print (" %s (Xfce %s)\n\n", PACKAGE_VERSION, xfce_version_string ()); g_print ("%s\n", "Copyright (c) 2004-2011"); g_print ("\t%s\n\n", _("The Xfce development team. All rights reserved.")); g_print (_("Please report bugs to <%s>."), PACKAGE_BUGREPORT); g_print ("\n"); return EXIT_SUCCESS; } else if (opt_preferences >= 0) { /* send a signal to the running instance to show the preferences dialog */ succeed = panel_dbus_client_display_preferences_dialog (opt_preferences, opt_socket_id, &error); goto dbus_return; } else if (opt_add_items >= 0) { /* send a signal to the running instance to show the add items dialog */ succeed = panel_dbus_client_display_items_dialog (opt_add_items, &error); goto dbus_return; } else if (opt_save) { /* send a save signal to the running instance */ succeed = panel_dbus_client_save (&error); goto dbus_return; } else if (opt_add != NULL) { /* send a add-new-item signal to the running instance */ succeed = panel_dbus_client_add_new_item (opt_add, opt_arguments, &error); goto dbus_return; } else if (opt_restart || opt_quit) { /* send a terminate signal to the running instance */ succeed = panel_dbus_client_terminate (opt_restart, &error); goto dbus_return; } else if (opt_plugin_event != NULL) { /* send the plugin event to the running instance */ remote_succeed = FALSE; succeed = panel_dbus_client_plugin_event (opt_plugin_event, &remote_succeed, &error); /* the panel returns EXIT_FAILURE if the dbus event succeeds, but * no suitable plugin was found on the service side */ if (succeed && !remote_succeed) succeed = FALSE; goto dbus_return; } launch_panel: /* start dbus service */ dbus_service = panel_dbus_service_get (); if (!panel_dbus_service_is_owner (dbus_service)) { /* quit without error if an instance is running */ succeed = TRUE; g_print ("%s: %s\n\n", G_LOG_DOMAIN, _("There is already a running instance")); goto dbus_return; } /* start session management */ sm_client = xfce_sm_client_get (); xfce_sm_client_set_restart_style (sm_client, XFCE_SM_CLIENT_RESTART_IMMEDIATELY); xfce_sm_client_set_priority (sm_client, XFCE_SM_CLIENT_PRIORITY_CORE); g_signal_connect (G_OBJECT (sm_client), "quit", G_CALLBACK (panel_sm_client_quit), NULL); if (!xfce_sm_client_connect (sm_client, &error)) { g_printerr ("%s: Failed to connect to session manager: %s\n", G_LOG_DOMAIN, error->message); g_clear_error (&error); } /* setup signal handlers to properly quit the main loop */ for (i = 0; i < G_N_ELEMENTS (signums); i++) signal (signums[i], panel_signal_handler); application = panel_application_get (); panel_application_load (application, opt_disable_wm_check); /* open dialog if we started from launch_panel */ if (opt_preferences >= 0) panel_preferences_dialog_show_from_id (opt_preferences, opt_socket_id); gtk_main (); /* make sure there are no incomming events when we close */ g_object_unref (G_OBJECT (dbus_service)); /* destroy all the opened dialogs */ panel_application_destroy_dialogs (application); g_object_unref (G_OBJECT (application)); g_object_unref (G_OBJECT (sm_client)); if (panel_dbus_service_get_restart ()) { /* spawn ourselfs again */ g_print ("%s: %s\n\n", G_LOG_DOMAIN, _("Restarting...")); g_spawn_command_line_async (argv[0], NULL); } return EXIT_SUCCESS; dbus_return: /* stop any running startup notification */ gdk_notify_startup_complete (); if (G_UNLIKELY (error != NULL)) { /* get suitable error message */ if (opt_preferences >= 0) error_msg = _("Failed to show the preferences dialog"); else if (opt_add_items >= 0) error_msg = _("Failed to show the add new items dialog"); else if (opt_save) error_msg = _("Failed to save the panel configuration"); else if (opt_add) error_msg = _("Failed to add a plugin to the panel"); else if (opt_restart) error_msg = _("Failed to restart the panel"); else if (opt_quit) error_msg = _("Failed to quit the panel"); else error_msg = _("Failed to send D-Bus message"); /* show understandable message for this common error */ if (error->code == DBUS_GERROR_NAME_HAS_NO_OWNER) { /* normally start the panel */ if (opt_preferences >= 0 || opt_restart) { g_clear_error (&error); if (xfce_dialog_confirm (NULL, GTK_STOCK_EXECUTE, NULL, _("Do you want to start the panel? If you do, make sure " "you save the session on logout, so the panel is " "automatically started the next time you login."), _("No running instance of %s was found"), G_LOG_DOMAIN)) { panel_debug (PANEL_DEBUG_MAIN, "user confirmed to start the panel"); goto launch_panel; } else { return EXIT_FAILURE; } } else { /* I18N: %s is replaced with xfce4-panel */ g_clear_error (&error); g_set_error (&error, 0, 0, _("No running instance of %s was found"), G_LOG_DOMAIN); } } /* show error dialog */ xfce_dialog_show_error (NULL, error, "%s", error_msg); g_error_free (error); } return succeed ? EXIT_SUCCESS : EXIT_FAILURE; }
int main (int argc, char **argv) { GtkWidget *window, *hbox, *vbox, *play_button, *pause_button, *stop_button; GstBus *bus; GOptionEntry options[] = { {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Verbose properties", NULL}, {NULL} }; gint type; GOptionContext *ctx; GError *err = NULL; ctx = g_option_context_new ("seek"); g_option_context_add_main_entries (ctx, options, NULL); g_option_context_add_group (ctx, gst_init_get_option_group ()); if (!g_option_context_parse (ctx, &argc, &argv, &err)) { g_print ("Error initializing: %s\n", err->message); exit (1); } GST_DEBUG_CATEGORY_INIT (scrubby_debug, "scrubby", 0, "scrubby example"); gtk_init (&argc, &argv); if (argc != 3) { print_usage (argc, argv); exit (-1); } type = atoi (argv[1]); if (type < 0 || type >= NUM_TYPES) { print_usage (argc, argv); exit (-1); } pipeline = pipelines[type].func (argv[2]); g_assert (pipeline); /* initialize gui elements ... */ window = gtk_window_new (GTK_WINDOW_TOPLEVEL); hbox = gtk_hbox_new (FALSE, 0); vbox = gtk_vbox_new (FALSE, 0); play_button = gtk_button_new_with_label ("play"); pause_button = gtk_button_new_with_label ("pause"); stop_button = gtk_button_new_with_label ("stop"); adjustment = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, (gdouble) RANGE_PREC, 0.1, 1.0, 1.0)); hscale = gtk_hscale_new (adjustment); gtk_scale_set_digits (GTK_SCALE (hscale), 2); sadjustment = GTK_ADJUSTMENT (gtk_adjustment_new (1.0, 0.0, 5.0, 0.1, 1.0, 0.0)); shscale = gtk_hscale_new (sadjustment); gtk_scale_set_digits (GTK_SCALE (shscale), 2); schanged_id = g_signal_connect (shscale, "value_changed", G_CALLBACK (speed_cb), pipeline); g_signal_connect (hscale, "button_press_event", G_CALLBACK (start_seek), pipeline); g_signal_connect (hscale, "button_release_event", G_CALLBACK (stop_seek), pipeline); g_signal_connect (hscale, "format_value", G_CALLBACK (format_value), pipeline); /* do the packing stuff ... */ gtk_window_set_default_size (GTK_WINDOW (window), 96, 96); gtk_container_add (GTK_CONTAINER (window), vbox); gtk_container_add (GTK_CONTAINER (vbox), hbox); gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2); gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2); gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2); gtk_box_pack_start (GTK_BOX (vbox), hscale, TRUE, TRUE, 2); gtk_box_pack_start (GTK_BOX (vbox), shscale, TRUE, TRUE, 2); /* connect things ... */ g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb), pipeline); g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb), pipeline); g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb), pipeline); g_signal_connect (G_OBJECT (window), "delete_event", gtk_main_quit, NULL); /* show the gui. */ gtk_widget_show_all (window); if (verbose) { g_signal_connect (pipeline, "deep_notify", G_CALLBACK (gst_object_default_deep_notify), NULL); } bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); g_assert (bus); bus_watch = gst_bus_add_watch_full (bus, G_PRIORITY_HIGH, bus_message, pipeline, NULL); gtk_main (); g_print ("NULL pipeline\n"); gst_element_set_state (pipeline, GST_STATE_NULL); g_print ("free pipeline\n"); gst_object_unref (pipeline); return 0; }
int main (int argc, char *argv[]) { gchar *target_times = NULL; gchar *ev_option = NULL; gchar *fn_option = NULL; GOptionEntry options[] = { {"ev-compensation", '\0', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_STRING, &ev_option, "EV compensation (-2.5..2.5, default = 0)", NULL}, {"aperture", '\0', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_INT, &aperture, "Aperture (size of lens opening, default = 0 (auto))", NULL}, {"flash-mode", '\0', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_INT, &flash_mode, "Flash mode (default = 0 (auto))", NULL}, {"scene-mode", '\0', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_INT, &scene_mode, "Scene mode (default = 6 (auto))", NULL}, {"exposure", '\0', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_INT64, &exposure, "Exposure (default = 0 (auto))", NULL}, {"iso-speed", '\0', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_INT, &iso_speed, "ISO speed (default = 0 (auto))", NULL}, {"white-balance-mode", '\0', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_INT, &wb_mode, "White balance mode (default = 0 (auto))", NULL}, {"colour-tone-mode", '\0', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_INT, &color_mode, "Colour tone mode (default = 0 (auto))", NULL}, {"directory", '\0', 0, G_OPTION_ARG_STRING, &fn_option, "Directory for capture file(s) (default is current directory)", NULL}, {"mode", '\0', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_INT, &mode, "Capture mode (default = 0 (image), 1 = video)", NULL}, {"capture-time", '\0', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_INT, &capture_time, "Time to capture video in seconds (default = 10)", NULL}, {"capture-total", '\0', 0, G_OPTION_ARG_INT, &capture_total, "Total number of captures to be done (default = 1)", NULL}, {"flags", '\0', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_INT, &flags, "Flags for camerabin, (default = 0x9)", NULL}, {"mute", '\0', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_STRING, &mute, "Mute audio (default = 0 (no))", NULL}, {"zoom", '\0', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_STRING, &zoom, "Zoom (100 = 1x (default), 200 = 2x etc.)", NULL}, {"audio-src", '\0', 0, G_OPTION_ARG_STRING, &audiosrc_name, "Audio source used in video recording", NULL}, {"audio-bitrate", '\0', 0, G_OPTION_ARG_INT, &audio_bitrate, "Audio bitrate (default 128000)", NULL}, {"audio-samplerate", '\0', 0, G_OPTION_ARG_INT, &audio_samplerate, "Audio samplerate (default 48000)", NULL}, {"audio-channels", '\0', 0, G_OPTION_ARG_INT, &audio_channels, "Audio channels (default 1)", NULL}, {"video-src", '\0', 0, G_OPTION_ARG_STRING, &videosrc_name, "Video source used in still capture and video recording", NULL}, {"audio-enc", '\0', 0, G_OPTION_ARG_STRING, &audioenc_name, "Audio encoder used in video recording", NULL}, {"video-enc", '\0', 0, G_OPTION_ARG_STRING, &videoenc_name, "Video encoder used in video recording", NULL}, {"image-enc", '\0', 0, G_OPTION_ARG_STRING, &imageenc_name, "Image encoder used in still capture", NULL}, {"image-pp", '\0', 0, G_OPTION_ARG_STRING, &imagepp_name, "Image post-processing element", NULL}, {"video-mux", '\0', 0, G_OPTION_ARG_STRING, &videomux_name, "Muxer used in video recording", NULL}, {"viewfinder-sink", '\0', 0, G_OPTION_ARG_STRING, &vfsink_name, "Viewfinder sink (default = fakesink)", NULL}, {"image-width", '\0', 0, G_OPTION_ARG_INT, &image_width, "Width for image capture", NULL}, {"image-height", '\0', 0, G_OPTION_ARG_INT, &image_height, "Height for image capture", NULL}, {"view-framerate-num", '\0', 0, G_OPTION_ARG_INT, &view_framerate_num, "Framerate numerator for viewfinder", NULL}, {"view-framerate-den", '\0', 0, G_OPTION_ARG_INT, &view_framerate_den, "Framerate denominator for viewfinder", NULL}, {"src-colorspace", '\0', 0, G_OPTION_ARG_STRING, &src_csp, "Colorspace format for video source (e.g. YUY2, UYVY)", NULL}, {"src-format", '\0', 0, G_OPTION_ARG_STRING, &src_format, "Video format for video source", NULL}, {"preview-caps", '\0', 0, G_OPTION_ARG_STRING, &preview_caps_name, "Preview caps (e.g. video/x-raw-rgb,width=320,height=240)", NULL}, {"video-source-filter", '\0', 0, G_OPTION_ARG_STRING, &video_src_filter, "Video filter to process all frames from video source", NULL}, {"viewfinder-filter", '\0', 0, G_OPTION_ARG_STRING, &viewfinder_filter, "Filter to process all frames going to viewfinder sink", NULL}, {"x-width", '\0', 0, G_OPTION_ARG_INT, &x_width, "X window width (default = 320)", NULL}, {"x-height", '\0', 0, G_OPTION_ARG_INT, &x_height, "X window height (default = 240)", NULL}, {NULL} }; GOptionContext *ctx; GError *err = NULL; /* if we fail to create xwindow should we care? */ create_host_window (); if (!g_thread_supported ()) g_thread_init (NULL); ctx = g_option_context_new ("\n\ncamerabin command line test application."); g_option_context_add_main_entries (ctx, options, NULL); g_option_context_add_group (ctx, gst_init_get_option_group ()); if (!g_option_context_parse (ctx, &argc, &argv, &err)) { g_print ("Error initializing: %s\n", err->message); exit (1); } g_option_context_free (ctx); GST_DEBUG_CATEGORY_INIT (camerabin_test, "camerabin-test", 0, "camerabin test"); /* FIXME: error handling */ if (ev_option != NULL) ev_compensation = strtod (ev_option, (char **) NULL); if (vfsink_name == NULL) vfsink_name = g_strdup ("fakesink"); filename = g_string_new (fn_option); if (filename->len == 0) filename = g_string_append (filename, "."); filename = g_string_append (filename, "/test_%04u"); if (mode == 1) filename = g_string_append (filename, ".mp4"); else filename = g_string_append (filename, ".jpg"); /* init */ if (setup_pipeline ()) { loop = g_main_loop_new (NULL, FALSE); g_idle_add ((GSourceFunc) run_pipeline, NULL); g_main_loop_run (loop); cleanup_pipeline (); g_main_loop_unref (loop); } /* free */ g_string_free (filename, TRUE); g_free (ev_option); g_free (audiosrc_name); g_free (videosrc_name); g_free (audioenc_name); g_free (videoenc_name); g_free (imageenc_name); g_free (imagepp_name); g_free (videomux_name); g_free (vfsink_name); g_free (src_csp); g_free (src_format); g_free (target_times); if (window) XDestroyWindow (display, window); if (display) XCloseDisplay (display); return 0; }
/** * main: **/ int main (int argc, char *argv[]) { GOptionContext *context; gboolean ret; GError *error = NULL; gchar **files = NULL; DBusGConnection *connection; DBusGProxy *proxy = NULL; const GOptionEntry options[] = { { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &files, /* TRANSLATORS: command line option: a list of files to install */ _("Files to install"), NULL }, { NULL} }; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); if (! g_thread_supported ()) g_thread_init (NULL); g_type_init (); gtk_init (&argc, &argv); /* TRANSLATORS: program name: application to install a package to provide a file */ g_set_application_name (_("PackageKit File Installer")); context = g_option_context_new ("gpk-install-file"); g_option_context_set_summary (context, _("PackageKit File Installer")); g_option_context_add_main_entries (context, options, NULL); g_option_context_add_group (context, egg_debug_get_option_group ()); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_parse (context, &argc, &argv, NULL); g_option_context_free (context); /* TRANSLATORS: title to pass to to the user if there are not enough privs */ ret = gpk_check_privileged_user (_("Local file installer"), TRUE); if (!ret) goto out; if (files == NULL) { /* TRANSLATORS: could not install a package that contained the file we wanted */ gpk_error_dialog (_("Failed to install a package to provide a file"), /* TRANSLATORS: nothing selected */ _("You need to specify a file to install"), NULL); goto out; } /* check dbus connections, exit if not valid */ connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (connection == NULL) { egg_warning ("%s", error->message); goto out; } /* get a connection */ proxy = dbus_g_proxy_new_for_name (connection, "org.freedesktop.PackageKit", "/org/freedesktop/PackageKit", "org.freedesktop.PackageKit.Modify"); if (proxy == NULL) { egg_warning ("Cannot connect to session service"); goto out; } /* don't timeout, as dbus-glib sets the timeout ~25 seconds */ dbus_g_proxy_set_default_timeout (proxy, INT_MAX); /* do method */ ret = dbus_g_proxy_call (proxy, "InstallPackageFiles", &error, G_TYPE_UINT, 0, /* xid */ G_TYPE_STRV, files, /* data */ G_TYPE_STRING, "hide-finished,hide-warnings", /* interaction */ G_TYPE_INVALID, G_TYPE_INVALID); if (!ret && !gpk_ignore_session_error (error)) { /* TRANSLATORS: This is when the specified DBus method did not execute successfully */ gpk_error_dialog (_("The action could not be completed"), /* TRANSLATORS: we don't have anything more useful to translate. sorry. */ _("The request failed. More details are available in the detailed report."), error->message); egg_warning ("%s", error->message); goto out; } out: if (error != NULL) g_error_free (error); if (proxy != NULL) g_object_unref (proxy); g_strfreev (files); return !ret; }
int main (int argc, char *argv[]) { GOptionContext *optcontext; GOptionEntry options[] = { { NULL } }; #ifdef ENABLE_DEBUG TpDebugSender *debug_sender; #endif GError *error = NULL; EmpathyChatManager *chat_mgr; EmpathyIdle *idle; gint retval; /* Init */ g_thread_init (NULL); optcontext = g_option_context_new (N_("- Empathy Chat Client")); g_option_context_add_group (optcontext, gtk_get_option_group (TRUE)); g_option_context_add_main_entries (optcontext, options, GETTEXT_PACKAGE); if (!g_option_context_parse (optcontext, &argc, &argv, &error)) { g_print ("%s\nRun '%s --help' to see a full list of available command " "line options.\n", error->message, argv[0]); g_warning ("Error in empathy-av init: %s", error->message); return EXIT_FAILURE; } g_option_context_free (optcontext); empathy_gtk_init (); gtk_window_set_default_icon_name ("empathy"); textdomain (GETTEXT_PACKAGE); app = gtk_application_new (EMPATHY_CHAT_DBUS_NAME, G_APPLICATION_IS_SERVICE); g_signal_connect (app, "activate", G_CALLBACK (activate_cb), NULL); #ifdef ENABLE_DEBUG /* Set up debug sender */ debug_sender = tp_debug_sender_dup (); g_log_set_default_handler (tp_debug_sender_log_handler, G_LOG_DOMAIN); #endif /* Setting up Idle */ idle = empathy_idle_dup_singleton (); chat_mgr = empathy_chat_manager_dup_singleton (); g_signal_connect (chat_mgr, "handled-chats-changed", G_CALLBACK (handled_chats_changed_cb), GUINT_TO_POINTER (1)); if (g_getenv ("EMPATHY_PERSIST") != NULL) { DEBUG ("Disable timer"); use_timer = FALSE; } /* the inactivity timeout can only be set while the application is held */ g_application_hold (G_APPLICATION (app)); g_application_set_inactivity_timeout (G_APPLICATION (app), TIMEOUT * 1000); g_application_release (G_APPLICATION (app)); DEBUG ("Waiting for text channels to handle"); retval = g_application_run (G_APPLICATION (app), argc, argv); g_object_unref (app); g_object_unref (idle); g_object_unref (chat_mgr); #ifdef ENABLE_DEBUG g_object_unref (debug_sender); #endif return retval; }
int main(int argc, char *argv[]) { UniqueApp *app; GtkStatusIcon *statusicon; GtkWidget *menu; GOptionContext *context; GError *error = NULL; bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); g_type_init (); /* Parse command-line options */ context = g_option_context_new (N_("- Bluetooth applet")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) { g_print (_("%s\nRun '%s --help' to see a full list of available command line options.\n"), error->message, argv[0]); g_error_free (error); return 1; } if (option_debug == FALSE) { app = unique_app_new ("org.mate.Bluetooth.applet", NULL); if (unique_app_is_running (app)) { gdk_notify_startup_complete (); g_warning ("Applet is already running, exiting"); return 0; } } else { app = NULL; } g_set_application_name(_("Bluetooth Applet")); gtk_window_set_default_icon_name("bluetooth"); killswitch = bluetooth_killswitch_new (); g_signal_connect (G_OBJECT (killswitch), "state-changed", G_CALLBACK (killswitch_state_changed), NULL); menu = create_popupmenu(); client = bluetooth_client_new(); devices_model = bluetooth_client_get_model(client); g_signal_connect(G_OBJECT(devices_model), "row-inserted", G_CALLBACK(device_added), NULL); g_signal_connect(G_OBJECT(devices_model), "row-deleted", G_CALLBACK(device_removed), NULL); g_signal_connect (G_OBJECT (devices_model), "row-changed", G_CALLBACK (device_changed), NULL); /* Set the default adapter */ device_changed (devices_model, NULL, NULL, NULL); if (bluetooth_killswitch_has_killswitches (killswitch) != FALSE) { killswitch_state_changed (killswitch, bluetooth_killswitch_get_state (killswitch)); } /* Make sure all the unblocked adapters are powered, * so as to avoid seeing unpowered, but unblocked * devices */ bluetooth_set_adapter_powered (); settings = g_settings_new (SCHEMA_NAME); show_icon_pref = g_settings_get_boolean (settings, PREF_SHOW_ICON); g_signal_connect (G_OBJECT (settings), "changed::" PREF_SHOW_ICON, G_CALLBACK (show_icon_changed), NULL); statusicon = init_notification(); update_icon_visibility(); g_signal_connect(statusicon, "activate", G_CALLBACK(activate_callback), menu); g_signal_connect(statusicon, "popup-menu", G_CALLBACK(popup_callback), menu); setup_agents(); gtk_main(); gtk_widget_destroy(menu); g_object_unref(settings); cleanup_agents(); cleanup_notification(); g_object_unref(devices_model); g_object_unref(client); if (app != NULL) g_object_unref (app); return 0; }
struct display * display_create(int *argc, char **argv[], const GOptionEntry *option_entries) { struct display *d; GOptionContext *context; GOptionGroup *xkb_option_group; GError *error; g_type_init(); context = g_option_context_new(NULL); if (option_entries) g_option_context_add_main_entries(context, option_entries, "Wayland View"); xkb_option_group = g_option_group_new("xkb", "Keyboard options", "Show all XKB options", NULL, NULL); g_option_group_add_entries(xkb_option_group, xkb_option_entries); g_option_context_add_group (context, xkb_option_group); if (!g_option_context_parse(context, argc, argv, &error)) { fprintf(stderr, "option parsing failed: %s\n", error->message); exit(EXIT_FAILURE); } d = malloc(sizeof *d); if (d == NULL) return NULL; d->display = wl_display_connect(NULL); if (d->display == NULL) { fprintf(stderr, "failed to create display: %m\n"); return NULL; } wl_list_init(&d->input_list); /* Set up listener so we'll catch all events. */ wl_display_add_global_listener(d->display, display_handle_global, d); /* Process connection events. */ wl_display_iterate(d->display, WL_DISPLAY_READABLE); if (d->device_name && init_drm(d) < 0) return NULL; create_pointer_surfaces(d); display_render_frame(d); d->loop = g_main_loop_new(NULL, FALSE); d->source = wl_glib_source_new(d->display); g_source_attach(d->source, NULL); wl_list_init(&d->window_list); init_xkb(d); return d; }
gint main (gint argc, gchar **argv) { GtkWidget *window; GOptionContext *context; const gchar *filename; EvDocumentModel *model; GError *error = NULL; #ifdef ENABLE_NLS /* Initialize the i18n stuff */ bindtextdomain (GETTEXT_PACKAGE, XREADER_LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif context = g_option_context_new (_("Print Preview")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); g_option_context_add_main_entries (context, goption_options, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_warning ("Error parsing command line arguments: %s", error->message); g_error_free (error); g_option_context_free (context); return 1; } g_option_context_free (context); if (!filenames) { g_warning ("File argument is required"); return 1; } filename = filenames[0]; if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR)) { g_warning ("Filename \"%s\" does not exist or is not a regular file", filename); return 1; } if (!ev_init ()) return 1; ev_stock_icons_init (); g_set_application_name (_("Print Preview")); gtk_window_set_default_icon_name ("xreader"); model = ev_document_model_new (); window = ev_previewer_window_new (model); ev_previewer_window_set_source_file (EV_PREVIEWER_WINDOW (window), filename); ev_previewer_window_set_print_settings (EV_PREVIEWER_WINDOW (window), print_settings); g_signal_connect (window, "delete-event", G_CALLBACK (gtk_main_quit), NULL); g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); gtk_widget_show (window); ev_previewer_load_document (filename, model); gtk_main (); if (unlink_temp_file) ev_previewer_unlink_tempfile (filename); if (print_settings) ev_previewer_unlink_tempfile (print_settings); ev_shutdown (); ev_stock_icons_shutdown (); g_object_unref (model); return 0; }
int main (int argc, char *argv[]) { GstNetClientInternalClock *clock; GstBus *bus; GIOChannel *channel; GIOStatus status; GError *error = NULL; GOptionContext *context; gchar *line; int ret = 1; context = g_option_context_new (NULL); g_option_context_add_main_entries (context, entries, NULL); g_option_context_add_group (context, gst_init_get_option_group ()); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_print ("Failed to parse options: %s\n\n", error->message); g_error_free (error); return 1; } if (input) { if (!(channel = g_io_channel_new_file (input, "r", NULL))) { g_print ("Could not read input file: %s\n", input); return 1; } } else { if (!(channel = g_io_channel_unix_new (0))) { g_print ("Could not read stdin"); return 1; } } clock = g_object_new (GST_TYPE_NET_CLIENT_INTERNAL_CLOCK, NULL); bus = gst_bus_new (); /* FIXME: Find a way to do this without touching the structure internals */ if (rtt_limit) clock->roundtrip_limit = rtt_limit * GST_MSECOND; clock->busses = g_list_prepend (clock->busses, bus); while ((status = g_io_channel_read_line (channel, &line, NULL, NULL, &error)) == G_IO_STATUS_NORMAL) { GstClockTime local_1, local_2, remote_1, remote_2; GstMessage *message; if (sscanf (line, "%" G_GUINT64_FORMAT " %" G_GUINT64_FORMAT " %" G_GUINT64_FORMAT " %" G_GUINT64_FORMAT, &local_1, &remote_1, &remote_2, &local_2) != 4) { g_print ("Failed to get local/remote time values from: %s\n", line); goto done; } if (debug) g_print ("%s", line); gst_net_client_internal_clock_observe_times (clock, local_1, remote_1, remote_2, local_2); g_free (line); if ((message = gst_bus_pop_filtered (bus, GST_MESSAGE_ELEMENT))) { const GstStructure *st; gchar *str; st = gst_message_get_structure (message); str = gst_structure_to_string (st); g_print ("%s\n", str); g_free (str); gst_message_unref (message); } } if (status == G_IO_CHANNEL_ERROR) { g_print ("Error reading file: %s\n", error->message); g_error_free (error); goto done; } g_io_channel_unref (channel); g_free (input); gst_object_unref (bus); ret = 0; done: return ret; }
/// @brief load command line options and and parse command input /// It uses i18n to translate command line options into the selected language /// WARNING: I18nInit() MUST be called before to enable i18n in all platforms /// (this function does some magic to ensure i18n is enabled under win32 /// platforms) /// It might cause the application to exit if the command line options couldn't /// be parsed (it calls to FatalError with the proper error code and message) /// @param main's argc /// @param main's argv void ProcessCommandLine(int argc, char **argv) { GError* error = NULL; GOptionContext* cmdContext = NULL; // create new command line context. This resource must be deleted before existing the app // i18n TRANSLATORS: Please leave the starting dash as it is part of the glib command line // i18n parsing formatting // i18n Thank you for contributing to this project cmdContext = g_option_context_new (_("- The GNU polyominoes board game")); #ifdef WIN32 // in win32 systems gettext fails when the string is static and marked as // translatable with N_() but _() is never called explicitely. Basically // there are 2 kinds of strings that are not translated: // + Those included in the GOptionEntry list, which show the available // options that can be passed to the program through command line // + Strings included in the .glade file that never change during the // execution of the application, for example a menu called "Game", or a // label that contains the word "rotate" // // We'll be calling explicitely here to _() per each translatable element // of g_cmdEntries, so they get properly translated into the current domain // g_cmdEntries is a null terminated array of structs // iterate through to call _() explicitely GOptionEntry* optEntryIterator = g_cmdEntries; while (*(reinterpret_cast<char*>(optEntryIterator)) != '\0') { optEntryIterator->description = _(optEntryIterator->description); optEntryIterator->arg_description = _(optEntryIterator->arg_description); optEntryIterator++; } #endif // WIN32 // to disable i18n write NULL instead of GETTEXT_PACKAGE in the 3rd parameter // g_option_context_add_main_entries (cmdContext, g_cmdEntries, NULL); g_option_context_add_main_entries ( cmdContext, g_cmdEntries, GETTEXT_PACKAGE); // no need for this. It is already set in g_option_context_add_main_entries // http://library.gnome.org/devel/glib/stable/glib-Commandline-option-parser.html#g-option-context-set-translation-domain //g_option_context_set_translation_domain (cmdContext, GETTEXT_PACKAGE); // http://library.gnome.org/devel/glib/unstable/glib-Commandline-option-parser.html#g-option-context-add-group // note that the group will be freed together with the context when // g_option_context_free() is called, so you must not free the group // yourself after adding it to a context g_option_context_add_group (cmdContext, gtk_get_option_group (TRUE)); // http://library.gnome.org/devel/glib/unstable/glib-Commandline-option-parser.html#g-option-group-set-translation-domain //g_option_group_set_translation_domain (grp, GETTEXT_PACKAGE); if (!g_option_context_parse (cmdContext, &argc, &argv, &error)) { std::stringstream errMessage; errMessage << _("Error parsing command line") << ": " << error->message; g_error_free(error); FatalError(argv[0], errMessage.str().c_str(), COMMAND_LINE_PARSING_ERR); } // free command line parsing resources g_option_context_free(cmdContext); }
gboolean mc_args_parse (int *argc, char ***argv, const char *translation_domain, GError ** mcerror) { const gchar *_system_codepage; gboolean ok = TRUE; mc_return_val_if_error (mcerror, FALSE); _system_codepage = str_detect_termencoding (); #ifdef ENABLE_NLS if (!str_isutf8 (_system_codepage)) bind_textdomain_codeset ("mc", "UTF-8"); #endif context = g_option_context_new (mc_args_add_usage_info ()); g_option_context_set_ignore_unknown_options (context, FALSE); mc_args_add_extended_info_to_help (); main_group = g_option_group_new ("main", _("Main options"), _("Main options"), NULL, NULL); g_option_group_add_entries (main_group, argument_main_table); g_option_context_set_main_group (context, main_group); g_option_group_set_translation_domain (main_group, translation_domain); terminal_group = g_option_group_new ("terminal", _("Terminal options"), _("Terminal options"), NULL, NULL); g_option_group_add_entries (terminal_group, argument_terminal_table); g_option_context_add_group (context, terminal_group); g_option_group_set_translation_domain (terminal_group, translation_domain); color_group = mc_args_new_color_group (); g_option_group_add_entries (color_group, argument_color_table); g_option_context_add_group (context, color_group); g_option_group_set_translation_domain (color_group, translation_domain); if (!g_option_context_parse (context, argc, argv, mcerror)) { if (*mcerror == NULL) mc_propagate_error (mcerror, 0, "%s\n", _("Arguments parse error!")); else { gchar *help_str; help_str = g_option_context_get_help (context, TRUE, NULL); if (str_isutf8 (_system_codepage)) mc_replace_error (mcerror, (*mcerror)->code, "%s\n\n%s\n", (*mcerror)->message, help_str); else { gchar *full_help_str; full_help_str = mc_args__convert_help_to_syscharset (_system_codepage, (*mcerror)->message, help_str); mc_replace_error (mcerror, (*mcerror)->code, "%s", full_help_str); g_free (full_help_str); } g_free (help_str); } ok = FALSE; } g_option_context_free (context); mc_args_clean_temp_help_strings (); #ifdef ENABLE_NLS if (!str_isutf8 (_system_codepage)) bind_textdomain_codeset ("mc", _system_codepage); #endif return ok; }
int main (int argc, char **argv) { static const GOptionEntry test_goptions[] = { {"videosink", '\0', 0, G_OPTION_ARG_STRING, &opt_videosink_str, "videosink to use (default: " DEFAULT_VIDEOSINK ")", NULL}, {"caps", '\0', 0, G_OPTION_ARG_STRING, &opt_filtercaps_str, "filter caps to narrow down formats to test", NULL}, {"with-ffmpegcolorspace", '\0', 0, G_OPTION_ARG_NONE, &opt_with_ffmpegcolorspace, "whether to add an ffmpegcolorspace element in front of the sink", NULL}, {NULL, '\0', 0, 0, NULL, NULL, NULL} }; GOptionContext *ctx; GError *opt_err = NULL; GstElement *pipeline, *src, *filter1, *crop, *scale, *filter2, *csp, *sink; GstCaps *filter_caps = NULL; GList *caps_list, *l; #if !GLIB_CHECK_VERSION (2, 31, 0) if (!g_thread_supported ()) g_thread_init (NULL); #endif /* command line option parsing */ ctx = g_option_context_new (""); g_option_context_add_group (ctx, gst_init_get_option_group ()); g_option_context_add_main_entries (ctx, test_goptions, NULL); if (!g_option_context_parse (ctx, &argc, &argv, &opt_err)) { g_error ("Error parsing command line options: %s", opt_err->message); return -1; } GST_DEBUG_CATEGORY_INIT (videocrop_test_debug, "videocroptest", 0, "vctest"); pipeline = gst_pipeline_new ("pipeline"); src = gst_element_factory_make ("videotestsrc", "videotestsrc"); g_assert (src != NULL); filter1 = gst_element_factory_make ("capsfilter", "capsfilter1"); g_assert (filter1 != NULL); crop = gst_element_factory_make ("videocrop", "videocrop"); g_assert (crop != NULL); scale = gst_element_factory_make ("videoscale", "videoscale"); g_assert (scale != NULL); filter2 = gst_element_factory_make ("capsfilter", "capsfilter2"); g_assert (filter2 != NULL); if (opt_with_ffmpegcolorspace) { g_print ("Adding ffmpegcolorspace\n"); csp = gst_element_factory_make ("ffmpegcolorspace", "colorspace"); } else { csp = gst_element_factory_make ("identity", "colorspace"); } g_assert (csp != NULL); if (opt_filtercaps_str) { filter_caps = gst_caps_from_string (opt_filtercaps_str); if (filter_caps == NULL) { g_error ("Invalid filter caps string '%s'", opt_filtercaps_str); } else { g_print ("Using filter caps '%s'\n", opt_filtercaps_str); } } if (opt_videosink_str) { g_print ("Trying videosink '%s' ...", opt_videosink_str); sink = gst_element_factory_make (opt_videosink_str, "sink"); g_print ("%s\n", (sink) ? "ok" : "element couldn't be created"); } else { sink = NULL; } if (sink == NULL) { g_print ("Trying videosink '%s' ...", DEFAULT_VIDEOSINK); sink = gst_element_factory_make (DEFAULT_VIDEOSINK, "sink"); g_print ("%s\n", (sink) ? "ok" : "element couldn't be created"); } if (sink == NULL) { g_print ("Trying videosink '%s' ...", "xvimagesink"); sink = gst_element_factory_make ("xvimagesink", "sink"); g_print ("%s\n", (sink) ? "ok" : "element couldn't be created"); } if (sink == NULL) { g_print ("Trying videosink '%s' ...", "ximagesink"); sink = gst_element_factory_make ("ximagesink", "sink"); g_print ("%s\n", (sink) ? "ok" : "element couldn't be created"); } g_assert (sink != NULL); gst_bin_add_many (GST_BIN (pipeline), src, filter1, crop, scale, filter2, csp, sink, NULL); if (!gst_element_link (src, filter1)) g_error ("Failed to link videotestsrc to capsfilter1"); if (!gst_element_link (filter1, crop)) g_error ("Failed to link capsfilter1 to videocrop"); if (!gst_element_link (crop, scale)) g_error ("Failed to link videocrop to videoscale"); if (!gst_element_link (scale, filter2)) g_error ("Failed to link videoscale to capsfilter2"); if (!gst_element_link (filter2, csp)) g_error ("Failed to link capsfilter2 to ffmpegcolorspace"); if (!gst_element_link (csp, sink)) g_error ("Failed to link ffmpegcolorspace to video sink"); caps_list = video_crop_get_test_caps (crop); for (l = caps_list; l != NULL; l = l->next) { GstStateChangeReturn ret; GstCaps *caps, *out_caps; gboolean skip = FALSE; gchar *s; if (filter_caps) { GstCaps *icaps; icaps = gst_caps_intersect (filter_caps, GST_CAPS (l->data)); skip = gst_caps_is_empty (icaps); gst_caps_unref (icaps); } /* this is the size of our window (stays fixed) */ out_caps = gst_caps_copy (GST_CAPS (l->data)); gst_structure_set (gst_caps_get_structure (out_caps, 0), "width", G_TYPE_INT, OUT_WIDTH, "height", G_TYPE_INT, OUT_HEIGHT, NULL); g_object_set (filter2, "caps", out_caps, NULL); /* filter1 gets these too to prevent videotestsrc from renegotiating */ g_object_set (filter1, "caps", out_caps, NULL); gst_caps_unref (out_caps); caps = gst_caps_copy (GST_CAPS (l->data)); GST_INFO ("testing format: %" GST_PTR_FORMAT, caps); s = gst_caps_to_string (caps); if (skip) { g_print ("Skipping format: %s\n", s); g_free (s); continue; } g_print ("Format: %s\n", s); caps = gst_caps_make_writable (caps); /* FIXME: check return values */ ret = gst_element_set_state (pipeline, GST_STATE_PLAYING); if (ret != GST_STATE_CHANGE_FAILURE) { ret = gst_element_get_state (pipeline, NULL, NULL, -1); if (ret != GST_STATE_CHANGE_FAILURE) { test_with_caps (src, crop, caps); } else { g_print ("Format: %s not supported (failed to go to PLAYING)\n", s); } } else { g_print ("Format: %s not supported\n", s); } gst_element_set_state (pipeline, GST_STATE_NULL); gst_caps_unref (caps); g_free (s); } g_list_foreach (caps_list, (GFunc) gst_caps_unref, NULL); g_list_free (caps_list); gst_element_set_state (pipeline, GST_STATE_NULL); gst_object_unref (pipeline); return 0; }
int main (int argc, char *argv[]) { GMainLoop *loop; GstRTSPServer *server; GstRTSPMountPoints *mounts; GstRTSPMediaFactory *factory; GOptionContext *optctx; GError *error = NULL; GstRTSPAuth *auth; GstRTSPToken *token; gchar *basic; #ifdef WITH_TLS GTlsCertificate *cert; #endif optctx = g_option_context_new ("<launch line> - Test RTSP Server, Launch\n\n" "Example: \"( decodebin name=depay0 ! autovideosink )\""); g_option_context_add_main_entries (optctx, entries, NULL); g_option_context_add_group (optctx, gst_init_get_option_group ()); if (!g_option_context_parse (optctx, &argc, &argv, &error)) { g_printerr ("Error parsing options: %s\n", error->message); return -1; } if (argc < 2) { g_print ("%s\n", g_option_context_get_help (optctx, TRUE, NULL)); return 1; } g_option_context_free (optctx); loop = g_main_loop_new (NULL, FALSE); /* create a server instance */ server = gst_rtsp_server_new (); g_object_set (server, "service", port, NULL); /* get the mount points for this server, every server has a default object * that be used to map uri mount points to media factories */ mounts = gst_rtsp_server_get_mount_points (server); /* make a media factory for a test stream. The default media factory can use * gst-launch syntax to create pipelines. * any launch line works as long as it contains elements named depay%d. Each * element with depay%d names will be a stream */ factory = gst_rtsp_media_factory_new (); gst_rtsp_media_factory_set_transport_mode (factory, GST_RTSP_TRANSPORT_MODE_RECORD); gst_rtsp_media_factory_set_launch (factory, argv[1]); gst_rtsp_media_factory_set_latency (factory, 2000); #ifdef WITH_TLS gst_rtsp_media_factory_set_profiles (factory, GST_RTSP_PROFILE_SAVP | GST_RTSP_PROFILE_SAVPF); #else gst_rtsp_media_factory_set_profiles (factory, GST_RTSP_PROFILE_AVP | GST_RTSP_PROFILE_AVPF); #endif /* allow user to access this resource */ gst_rtsp_media_factory_add_role (factory, "user", GST_RTSP_PERM_MEDIA_FACTORY_ACCESS, G_TYPE_BOOLEAN, TRUE, GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT, G_TYPE_BOOLEAN, TRUE, NULL); /* Anonymous users can see but not construct, so get UNAUTHORIZED */ gst_rtsp_media_factory_add_role (factory, "anonymous", GST_RTSP_PERM_MEDIA_FACTORY_ACCESS, G_TYPE_BOOLEAN, TRUE, GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT, G_TYPE_BOOLEAN, FALSE, NULL); /* attach the test factory to the /test url */ gst_rtsp_mount_points_add_factory (mounts, "/test", factory); /* don't need the ref to the mapper anymore */ g_object_unref (mounts); /* Set up the auth for user account */ /* make a new authentication manager */ auth = gst_rtsp_auth_new (); #ifdef WITH_TLS cert = g_tls_certificate_new_from_pem ("-----BEGIN CERTIFICATE-----" "MIICJjCCAY+gAwIBAgIBBzANBgkqhkiG9w0BAQUFADCBhjETMBEGCgmSJomT8ixk" "ARkWA0NPTTEXMBUGCgmSJomT8ixkARkWB0VYQU1QTEUxHjAcBgNVBAsTFUNlcnRp" "ZmljYXRlIEF1dGhvcml0eTEXMBUGA1UEAxMOY2EuZXhhbXBsZS5jb20xHTAbBgkq" "hkiG9w0BCQEWDmNhQGV4YW1wbGUuY29tMB4XDTExMDExNzE5NDcxN1oXDTIxMDEx" "NDE5NDcxN1owSzETMBEGCgmSJomT8ixkARkWA0NPTTEXMBUGCgmSJomT8ixkARkW" "B0VYQU1QTEUxGzAZBgNVBAMTEnNlcnZlci5leGFtcGxlLmNvbTBcMA0GCSqGSIb3" "DQEBAQUAA0sAMEgCQQDYScTxk55XBmbDM9zzwO+grVySE4rudWuzH2PpObIonqbf" "hRoAalKVluG9jvbHI81eXxCdSObv1KBP1sbN5RzpAgMBAAGjIjAgMAkGA1UdEwQC" "MAAwEwYDVR0lBAwwCgYIKwYBBQUHAwEwDQYJKoZIhvcNAQEFBQADgYEAYx6fMqT1" "Gvo0jq88E8mc+bmp4LfXD4wJ7KxYeadQxt75HFRpj4FhFO3DOpVRFgzHlOEo3Fwk" "PZOKjvkT0cbcoEq5whLH25dHoQxGoVQgFyAP5s+7Vp5AlHh8Y/vAoXeEVyy/RCIH" "QkhUlAflfDMcrrYjsmwoOPSjhx6Mm/AopX4=" "-----END CERTIFICATE-----" "-----BEGIN PRIVATE KEY-----" "MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEA2EnE8ZOeVwZmwzPc" "88DvoK1ckhOK7nVrsx9j6TmyKJ6m34UaAGpSlZbhvY72xyPNXl8QnUjm79SgT9bG" "zeUc6QIDAQABAkBRFJZ32VbqWMP9OVwDJLiwC01AlYLnka0mIQZbT/2xq9dUc9GW" "U3kiVw4lL8v/+sPjtTPCYYdzHHOyDen6znVhAiEA9qJT7BtQvRxCvGrAhr9MS022" "tTdPbW829BoUtIeH64cCIQDggG5i48v7HPacPBIH1RaSVhXl8qHCpQD3qrIw3FMw" "DwIga8PqH5Sf5sHedy2+CiK0V4MRfoU4c3zQ6kArI+bEgSkCIQCLA1vXBiE31B5s" "bdHoYa1BXebfZVd+1Hd95IfEM5mbRwIgSkDuQwV55BBlvWph3U8wVIMIb4GStaH8" "W535W8UBbEg=" "-----END PRIVATE KEY-----", -1, &error); if (cert == NULL) { g_printerr ("failed to parse PEM: %s\n", error->message); return -1; } gst_rtsp_auth_set_tls_certificate (auth, cert); g_object_unref (cert); #endif /* make default token - anonymous unauthenticated access */ token = gst_rtsp_token_new (GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE, G_TYPE_STRING, "anonymous", NULL); gst_rtsp_auth_set_default_token (auth, token); gst_rtsp_token_unref (token); /* make user token */ token = gst_rtsp_token_new (GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE, G_TYPE_STRING, "user", NULL); basic = gst_rtsp_auth_make_basic ("user", "password"); gst_rtsp_auth_add_basic (auth, basic, token); g_free (basic); gst_rtsp_token_unref (token); /* set as the server authentication manager */ gst_rtsp_server_set_auth (server, auth); g_object_unref (auth); /* attach the server to the default maincontext */ gst_rtsp_server_attach (server, NULL); /* start serving */ #ifdef WITH_TLS g_print ("stream ready at rtsps://127.0.0.1:%s/test\n", port); #else g_print ("stream ready at rtsp://127.0.0.1:%s/test\n", port); #endif g_main_loop_run (loop); return 0; }
static void cmdline_handler(int argc, char **argv) { gboolean help = FALSE, version = FALSE; gchar *confpath = NULL, *certpath = NULL, *keypath = NULL, *mount = NULL, *handlerextra = NULL; char *cmdarg = NULL; GOptionContext *context = NULL; GOptionEntry entries[] = { {"conf", 'c', 0, G_OPTION_ARG_FILENAME, &confpath, "config file", "FILENAME"}, {"cert", '\0', 0, G_OPTION_ARG_FILENAME, &certpath, "cert file", "PEMFILE"}, {"key", '\0', 0, G_OPTION_ARG_FILENAME, &keypath, "key file", "PEMFILE"}, {"mount", '\0', 0, G_OPTION_ARG_FILENAME, &mount, "mount prefix", "PATH"}, {"handler-args", '\0', 0, G_OPTION_ARG_STRING, &handlerextra, "extra handler arguments", "ARGS"}, {"version", '\0', 0, G_OPTION_ARG_NONE, &version, "display version", NULL}, {"help", 'h', 0, G_OPTION_ARG_NONE, &help, NULL, NULL}, {0} }; GOptionGroup *info_group = g_option_group_new("info", "Info options:", "help dummy", NULL, NULL); GError *error = NULL; gchar *text; RaucCommand rcommands[] = { {UNKNOWN, "help", "<COMMAND>", unknown_start, NULL, TRUE}, {INSTALL, "install", "install <BUNDLE>", install_start, NULL, FALSE}, {BUNDLE, "bundle", "bundle <FILE>", bundle_start, NULL, FALSE}, {CHECKSUM, "checksum", "checksum <DIRECTORY>", checksum_start, NULL, FALSE}, {INFO, "info", "info <FILE>", info_start, info_group, FALSE}, {STATUS, "status", "status", status_start, NULL, TRUE}, #if ENABLE_SERVICE == 1 {SERVICE, "service", "service", service_start, NULL, TRUE}, #endif {0} }; RaucCommand *rc; RaucCommand *rcommand = NULL; g_option_group_add_entries(info_group, entries_info); context = g_option_context_new("<COMMAND>"); g_option_context_set_help_enabled(context, FALSE); g_option_context_set_ignore_unknown_options(context, TRUE); g_option_context_add_main_entries(context, entries, NULL); g_option_context_set_description(context, "List of rauc commands:\n" \ " bundle\tCreate a bundle\n" \ " checksum\tUpdate a manifest with checksums (and optionally sign it)\n" \ " resign\tResign a bundle\n" \ " install\tInstall a bundle\n" \ " info\t\tShow file information\n" \ " status\tShow status"); if (!g_option_context_parse(context, &argc, &argv, &error)) { g_printerr("%s\n", error->message); g_error_free(error); r_exit_status = 1; goto done; } /* get first parameter wihtout dashes */ for (gint i = 1; i <= argc; i++) { if (argv[i] && !g_str_has_prefix (argv[i], "-")) { cmdarg = argv[i]; break; } } if (cmdarg == NULL) { if (version) { g_print(PACKAGE_STRING"\n"); goto done; } /* NO COMMAND given */ if (!help) { r_exit_status = 1; } goto print_help; } /* try to get known command */ rc = rcommands; while (rc->name) { if (g_strcmp0(rc->name, cmdarg) == 0) { rcommand = rc; break; } rc++; } if (rcommand == NULL) { /* INVALID COMMAND given */ g_message("Invalid command '%s' given\n", cmdarg); r_exit_status = 1; goto print_help; } /* re-setup option context for showing command-specific help */ g_clear_pointer(&context, g_option_context_free); context = g_option_context_new(rcommand->usage); g_option_context_set_help_enabled(context, FALSE); g_option_context_add_main_entries(context, entries, NULL); if (rcommand->options) g_option_context_add_group(context, rcommand->options); /* parse command-specific options */ if (!g_option_context_parse(context, &argc, &argv, &error)) { g_printerr("%s\n", error->message); g_error_free(error); r_exit_status = 1; goto print_help; } if (help) { goto print_help; } /* configuration updates are handled here */ if (!r_context_get_busy()) { r_context_conf(); if (confpath) r_context_conf()->configpath = confpath; if (certpath) r_context_conf()->certpath = certpath; if (keypath) r_context_conf()->keypath = keypath; if (mount) r_context_conf()->mountprefix = mount; if (handlerextra) r_context_conf()->handlerextra = handlerextra; } else { if (confpath != NULL || certpath != NULL || keypath != NULL) { g_error("rauc busy, cannot reconfigure"); r_exit_status = 1; goto done; } } if (r_context_get_busy() && !rcommand->while_busy) { g_error("rauc busy: cannot run %s", rcommand->name); r_exit_status = 1; goto done; } /* real commands are handled here */ if (rcommand->cmd_handler) { rcommand->cmd_handler(argc, argv); } goto done; print_help: text = g_option_context_get_help(context, FALSE, NULL); g_print("%s", text); g_free(text); done: g_clear_pointer(&context, g_option_context_free);; }