예제 #1
0
파일: ntl_net.c 프로젝트: karfai/portfolio
ntl_Net* ntl_net_new(void)
{
    ntl_Net* rv = g_new(ntl_Net, 1);
    gnet_init();
    {
        GInetAddr* a = gnet_inetaddr_new("localhost", 4242);
        rv->sock = gnet_tcp_socket_new(a);
        gnet_inetaddr_delete(a);
    }
    
    return rv;
}
예제 #2
0
파일: example-server.c 프로젝트: dov/gemtcl
int
main(int argc, char** argv)
{
  int port = 8123;
  GNetXmlRpcServer *server;
  GMainLoop* main_loop;

  Tcl_FindExecutable(argv[0]);
  gnet_init ();

  if (argc > 1)
      port = atoi(argv[1]);

  /* Create the main loop */
  main_loop = g_main_new (FALSE);

  server = gnet_xmlrpc_server_new(port);

  printf("port = %d\n", port);
  
  if (!server)
    {
      fprintf (stderr, "Error: Could not start server\n");
      exit (EXIT_FAILURE);
    }

  tcl_interp = Tcl_CreateInterp();
  Tcl_Init(tcl_interp);
  Tcl_CreateCommand(tcl_interp, "ping",
                    tcl_ping, (ClientData) NULL,
                    (Tcl_CmdDeleteProc *) NULL);

  gnet_xmlrpc_server_register_command(server,
				      "ping",
				      xmlrpc_cmd_ping,
				      NULL);

  gnet_xmlrpc_server_register_command(server,
				      "cmd",
				      xmlrpc_cmd_tcl,
				      NULL);

  /* Start the main loop */
  g_main_run(main_loop);

  exit (EXIT_SUCCESS);
  return 0;
}
예제 #3
0
int
main(int argc, char** argv)
{
  int port = 8123;
	gchar* addr = "localhost";
  GNetXmlRpcServer *server;
  GMainLoop* main_loop;

  gnet_init ();

  if (argc > 1)
      port = atoi(argv[1]);

  /* Create the main loop */
  main_loop = g_main_loop_new (NULL,
                               FALSE);

  server = gnet_xmlrpc_server_new(addr, port);

  if (!server)
    {
      fprintf (stderr, "Error: Could not start server\n");
      exit (EXIT_FAILURE);
    }

  gnet_xmlrpc_server_register_command(server,
				      "foo",
				      do_foo,
				      NULL);

  gnet_xmlrpc_server_register_command(server,
				      "echo",
				      do_echo,
				      NULL);
  
  gnet_xmlrpc_server_register_async_command(server,
				      "async",
				      do_async,
				      NULL);

  /* Start the main loop */
  g_main_loop_run(main_loop);

  exit (EXIT_SUCCESS);
  return 0;
}
예제 #4
0
int main (int argc, char** argv)
{
    gchar* hostname;
    gint port;
    GMainLoop* main_loop;
    GConn* conn;

    gnet_init ();

    /* Parse args */
    if (argc != 4)
    {
        g_print ("usage: %s <server> <port> <output-directory>\n", argv[0]);
        exit(EXIT_FAILURE);
    }
    hostname = argv[1];
    port = atoi(argv[2]);
    out_dir = argv[3];
    check_dir (out_dir);
    update_filename ();

    /* Create the main loop */
    main_loop = g_main_new(FALSE);

    /* Create connection object */
    conn = gnet_conn_new (hostname, port, ob_conn_func, NULL);
    g_assert (conn);

    /* Connect */
    gnet_conn_connect (conn);
    gnet_conn_set_watch_error (conn, TRUE);
    gnet_conn_timeout (conn, 30000);  /* 30 second timeout */

    //open the xml file
    init_xml ();
    atexit (flush_xml);

    /* Start the main loop */
    g_main_run (main_loop);

    exit (EXIT_SUCCESS);
    return 0;
}
예제 #5
0
int
main(int argc, char** argv)
{
  gchar* hostname;
  gint port;
  GMainLoop* main_loop;
  GConn* conn;
  GIOChannel* in;

  gnet_init ();

  /* Parse args */
  if (argc != 3)
    {
      g_print ("usage: %s <server> <port>\n", argv[0]);
      exit(EXIT_FAILURE);
    }
  hostname = argv[1];
  port = atoi(argv[2]);

  /* Create the main loop */
  main_loop = g_main_new(FALSE);
  
  /* Create connection object */
  conn = gnet_conn_new (hostname, port, ob_conn_func, NULL);
  g_assert (conn);

  /* Connect */
  gnet_conn_connect (conn);
  gnet_conn_set_watch_error (conn, TRUE);
  gnet_conn_timeout (conn, 30000);  /* 30 second timeout */

  /* Read from stdin */
  in = g_io_channel_unix_new (fileno(stdin));
  g_io_add_watch(in, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL, 
		 ob_in_iofunc, conn);

  /* Start the main loop */
  g_main_run (main_loop);

  exit (EXIT_SUCCESS);
  return 0;
}
예제 #6
0
파일: gnetcheck.c 프로젝트: UIKit0/gnet
/* initialize GNet testing */
static void
gnet_check_init (int *argc, char **argv[])
{
  gnet_init ();

  /* GST_DEBUG_CATEGORY_INIT (check_debug, "check", 0, "check regression tests"); */

  if (g_getenv ("GNET_TEST_DEBUG"))
    _gnet_check_debug = TRUE;

  if (g_getenv ("SOCKS_SERVER")) {
    GInetAddr *ia;

    ia = gnet_socks_get_server ();
    if (ia) {
      gchar *name;

      name = gnet_inetaddr_get_canonical_name (ia);
      g_print ("\nUsing SOCKS %u proxy: %s\n", gnet_socks_get_version(), name);
      g_free (name);
      gnet_inetaddr_unref (ia);
      gnet_socks_set_enabled (TRUE);
    }
  }

  g_log_set_handler (NULL, G_LOG_LEVEL_MESSAGE, gnet_check_log_message_func,
      NULL);
  g_log_set_handler (NULL, G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING,
      gnet_check_log_critical_func, NULL);
  g_log_set_handler ("GNet", G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING,
      gnet_check_log_critical_func, NULL);
  g_log_set_handler ("GLib", G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING,
      gnet_check_log_critical_func, NULL);
  g_log_set_handler ("GLib-GObject", G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING,
      gnet_check_log_critical_func, NULL);

  check_cond = g_cond_new ();
  check_mutex = g_mutex_new ();
}
예제 #7
0
int
main(int argc, char** argv)
{
  int port;
  GServer* server;
  GMainLoop* main_loop;

  gnet_init ();

  if (argc != 2)
    {
      fprintf (stderr, "usage: echoserver <port> \n");
      exit(EXIT_FAILURE);
    }

  fprintf (stderr, "NOTE: You can not use the standard echoclient with this server.\n");

  port = atoi(argv[argc - 1]);

  /* Create the main loop */
  main_loop = g_main_new (FALSE);

  /* Create the server */
  server = gnet_server_new (NULL, port, ob_server_func, NULL);
  if (!server)
    {
      fprintf (stderr, "Error: Could not start server\n");
      exit (EXIT_FAILURE);
    }

  ob_server = server;
  signal (SIGINT, ob_sig_int);

  /* Start the main loop */
  g_main_run(main_loop);

  exit (EXIT_SUCCESS);
  return 0;
}
예제 #8
0
int
main(int argc, char** argv)
{
  gchar *path = NULL;
  ServerType server_type = NORMAL;
  gboolean abstract = FALSE;
	
  gnet_init ();

  if (argc < 2) {
    usage(EXIT_FAILURE);
  }
  if (argc > 2) {
    if (strcmp(argv[1], "--async") == 0 || strcmp(argv[2], "--async") == 0)
      server_type = ASYNC;
    if (strcmp(argv[1], "--abstract") == 0 ||
            strcmp(argv[2], "--abstract") == 0)
      abstract = TRUE;
  }

  path = g_strdup (argv[argc - 1]);

  signal(SIGINT, cleanup_on_sig);
  signal(SIGTERM, cleanup_on_sig);
		
  switch (server_type) {
  case NORMAL:
    g_print("Normal echo server running\n");
    normal_echoserver(path, abstract);
    break;
  case ASYNC:
    g_print("Async echo server running\n");
    async_echoserver(path, abstract);
    break;
  default:
    g_assert_not_reached();
  }
  return 0;
}
예제 #9
0
파일: echoclient.c 프로젝트: GNOME/gnet
int
main(int argc, char** argv)
{
  gchar* hostname;
  gint port;
  GInetAddr* addr;
  GTcpSocket* socket;
  GIOChannel* iochannel;
  GIOError error = G_IO_ERROR_NONE;
  gchar buffer[1024];
  gsize n;

  gnet_init ();

  /* Parse args */
  if (argc != 3)
    {  
      g_print ("usage: %s <server> <port>\n", argv[0]);
      exit(EXIT_FAILURE);
    }
  hostname = argv[1];
  port = atoi(argv[2]);

  /* Create the address */
  addr = gnet_inetaddr_new (hostname, port);
  if (!addr)
    {
      fprintf (stderr, "Error: Name lookup for %s failed\n", hostname);
      exit (EXIT_FAILURE);
    }

  /* Create the socket */
  socket = gnet_tcp_socket_new (addr);
  gnet_inetaddr_delete (addr);
  if (!socket)
    {
      fprintf (stderr, "Error: Could not connect to %s:%d\n", hostname, port);
      exit (EXIT_FAILURE);
    }

#if 0
  {
    gchar* cname;

    /* Print local address */
    addr = gnet_tcp_socket_get_local_inetaddr (socket);
    g_assert (addr);
    cname = gnet_inetaddr_get_canonical_name (addr);
    g_assert (cname);
    g_print ("Local address: %s:%d\n", cname, gnet_inetaddr_get_port(addr));
    g_free (cname);
    gnet_inetaddr_delete (addr);

    /* Print remote address */
    addr = gnet_tcp_socket_get_remote_inetaddr (socket);
    g_assert (addr);
    cname = gnet_inetaddr_get_canonical_name (addr);
    g_assert (cname);
    g_print ("Remote address: %s:%d\n", cname, gnet_inetaddr_get_port(addr));
    g_free (cname);
    gnet_inetaddr_delete (addr);
  }
#endif

  /* Get the IOChannel */
  iochannel = gnet_tcp_socket_get_io_channel (socket);
  g_assert (iochannel != NULL);

  while (fgets(buffer, sizeof(buffer), stdin) != 0)
    {
      n = strlen(buffer);
      error = gnet_io_channel_writen (iochannel, buffer, n, &n);
      if (error != G_IO_ERROR_NONE) break;

      error = gnet_io_channel_readn (iochannel, buffer, n, &n);
      if (error != G_IO_ERROR_NONE) break;

      if (fwrite(buffer, n, 1, stdout) != 1) {
       fprintf (stderr, "Error: fwrite to stdout failed: %s\n", g_strerror (errno));
      }
    }

  if (error != G_IO_ERROR_NONE) 
    fprintf (stderr, "Error: IO error (%d)\n", error);

  gnet_tcp_socket_delete (socket);

  return 0;
}
예제 #10
0
int main(int argc, char ** argv) {
    IterativeMap* map;
    Animation* animation;
    gboolean animate = FALSE;
    gboolean have_gtk;
    gboolean verbose = FALSE;
    gboolean hidden = FALSE;
    enum {INTERACTIVE, RENDER, SCREENSAVER, REMOTE} mode = INTERACTIVE;
    const gchar *outputFile = NULL;
    const gchar *pidfile = NULL;
    int c, option_index=0;
    double quality = 1.0;
#ifdef HAVE_GNET
    int port_number = FYRE_DEFAULT_PORT;
#endif
    GError *error = NULL;

    math_init();
    g_type_init();
    have_gtk = gtk_init_check(&argc, &argv);

#ifdef HAVE_GNET
    gnet_init();
#  ifdef WIN32
    gnet_ipv6_set_policy(GIPV6_POLICY_IPV4_ONLY);
#  endif
#endif

    map = ITERATIVE_MAP(de_jong_new());
    animation = animation_new();

    while (1) {
        static struct option long_options[] = {
            {"help",         0, NULL, 'h'},
            {"read",         1, NULL, 'i'},
            {"animate",      1, NULL, 'n'},
            {"output",       1, NULL, 'o'},
            {"param",        1, NULL, 'p'},
            {"size",         1, NULL, 's'},
            {"oversample",   1, NULL, 'S'},
            {"quality",      1, NULL, 'q'},
            {"remote",       0, NULL, 'r'},
            {"verbose",      0, NULL, 'v'},
            {"port",         1, NULL, 'P'},
            {"cluster",      1, NULL, 'c'},
            {"auto-cluster", 0, NULL, 'C'},
            {"screensaver",  0, NULL, 1000},   /* Undocumented, still experimental */
            {"hidden",       0, NULL, 1001},
            {"chdir",        1, NULL, 1002},   /* Undocumented, used by win32 file associations */
            {"pidfile",      1, NULL, 1003},
            {"version",      0, NULL, 1004},
            {NULL},
        };
        c = getopt_long(argc, argv, "hi:n:o:p:s:S:q:rvP:c:C",
                        long_options, &option_index);
        if (c == -1)
            break;

        switch (c) {

        case 'i':
        {
            histogram_imager_load_image_file(HISTOGRAM_IMAGER(map), optarg, &error);
            break;
        }

        case 'n':
        {
            GtkTreeIter iter;

            animation_load_file(animation, optarg);
            animate = TRUE;
            gtk_tree_model_get_iter_first(GTK_TREE_MODEL(animation->model), &iter);
            animation_keyframe_load(animation, &iter, PARAMETER_HOLDER(map));
            break;
        }

        case 'o':
            mode = RENDER;
            outputFile = optarg;
            break;

        case 'p':
            parameter_holder_load_string(PARAMETER_HOLDER(map), optarg);
            break;

        case 's':
            parameter_holder_set(PARAMETER_HOLDER(map), "size" , optarg);
            break;

        case 'S':
            parameter_holder_set(PARAMETER_HOLDER(map), "oversample", optarg);
            break;

        case 'q':
            quality = atof(optarg);
            break;

        case 'v':
            verbose = TRUE;
            break;

#ifdef HAVE_GNET
        case 'c':
        {
            ClusterModel *cluster = cluster_model_get(map, TRUE);
            cluster_model_add_nodes(cluster, optarg);
        }
        break;
        case 'C':
        {
            ClusterModel *cluster = cluster_model_get(map, TRUE);
            cluster_model_enable_discovery(cluster);
        }
        break;
        case 'r':
            mode = REMOTE;
            break;
        case 'P':
            port_number = atol(optarg);
            break;
#else
        case 'c':
        case 'C':
        case 'P':
            fprintf(stderr,
                    "This Fyre binary was compiled without gnet support.\n"
                    "Cluster support is not available.\n");
            break;
        case 'r':
            fprintf(stderr,
                    "This Fyre binary was compiled without gnet support.\n"
                    "Cluster support is not available.\n");
            exit(1);
            break;
#endif

        case 1000: /* --screensaver */
            mode = SCREENSAVER;
            break;

        case 1001: /* --hidden */
            hidden = TRUE;
            break;

        case 1002: /* --chdir */
            chdir(optarg);
            break;

        case 1003: /* --pidfile */
            pidfile = optarg;
            break;

        case 1004: /* --version */
            printf("%s\n", VERSION);
            return 0;

        case 'h':
        default:
            usage(argv);
            return 1;
        }
    }

    if (optind + 1 < argc) {
        usage(argv);
        return 1;
    }

    if (optind != argc) {
        char *ext = strrchr (argv[optind], '.');
        if (ext) {
            if (g_strcasecmp(ext, ".png") == 0) {
                histogram_imager_load_image_file(HISTOGRAM_IMAGER(map), argv[optind], &error);
            } else if (g_strcasecmp(ext, ".fa") == 0) {
                GtkTreeIter iter;

                animation_load_file(animation, argv[optind]);
                animate = TRUE;
                gtk_tree_model_get_iter_first(GTK_TREE_MODEL(animation->model), &iter);
                animation_keyframe_load(animation, &iter, PARAMETER_HOLDER(map));
            } else {
                usage(argv);
                return 1;
            }
        } else {
            usage(argv);
            return 1;
        }
    }

    switch (mode) {

    case INTERACTIVE: {
        Explorer *explorer;

        if (!have_gtk) {
            fprintf(stderr, "GTK intiailization failed, can't start in interactive mode\n");
            return 1;
        }
        explorer = explorer_new (map, animation);
        if (error) {
            GtkWidget *dialog, *label;
            gchar *text;

            dialog = glade_xml_get_widget (explorer->xml, "error dialog");
            label = glade_xml_get_widget (explorer->xml, "error label");

            text = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">Error!</span>\n\n%s", error->message);
            gtk_label_set_markup (GTK_LABEL (label), text);
            g_free (text);
            g_error_free (error);

            gtk_dialog_run (GTK_DIALOG (dialog));
            gtk_widget_hide (dialog);
        }
        gtk_main();
        break;
    }

    case RENDER: {
        acquire_console();
        if (error) {
            g_print ("Error: %s\n", error->message);
            g_error_free (error);
        }
        if (animate)
            animation_render_main (map, animation, outputFile, quality);
        else
            batch_image_render (map, outputFile, quality);
        break;
    }

    case REMOTE: {
#ifdef HAVE_GNET
        if (verbose) {
            acquire_console();
        }
        else {
            daemonize_to_pidfile(pidfile);
        }
        if (!hidden)
            discovery_server_new(FYRE_DEFAULT_SERVICE, port_number);
        remote_server_main_loop(port_number, have_gtk, verbose);
#else
        fprintf(stderr,
                "This Fyre binary was compiled without gnet support.\n"
                "Remote control mode is not available.\n");
#endif
        break;
    }

    case SCREENSAVER: {
        ScreenSaver* screensaver;
        GtkWidget* window;

        if (!have_gtk) {
            fprintf(stderr, "GTK intiailization failed, can't start in screensaver mode\n");
            return 1;
        }

        screensaver = screensaver_new(map, animation);
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        fyre_set_icon_later(window);
        gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
        gtk_window_set_title(GTK_WINDOW(window), "Fyre Screensaver");
        gtk_container_add(GTK_CONTAINER(window), screensaver->view);
        gtk_widget_show_all(window);

        gtk_main();
        break;
    }
    }

    return 0;
}