~matthaeus123/+junk/gupnp-igd

« back to all changes in this revision

Viewing changes to tests/examples/test-thread.c

  • Committer: Matthew Walker
  • Date: 2009-03-23 19:36:45 UTC
  • Revision ID: matthew@matthew-desktop-20090323193645-r4z27ojffzc9fuoy
initial checkin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include <stdlib.h>
 
3
#include <unistd.h>
 
4
 
 
5
#include <glib.h>
 
6
 
 
7
#include <libgupnp-igd/gupnp-simple-igd-thread.h>
 
8
 
 
9
static void
 
10
_mapped_external_port (GUPnPSimpleIgd *igd, gchar *proto,
 
11
    gchar *external_ip, gchar *replaces_external_ip, guint external_port,
 
12
    gchar *local_ip, guint local_port,
 
13
    gchar *description, gpointer user_data)
 
14
{
 
15
  g_debug ("proto:%s ex:%s oldex:%s exp:%u local:%s localp:%u desc:%s",
 
16
      proto, external_ip, replaces_external_ip, external_port, local_ip,
 
17
      local_port, description);
 
18
 
 
19
}
 
20
 
 
21
 
 
22
 
 
23
static void
 
24
_error_mapping_external_port (GUPnPSimpleIgd *igd, GError *error,
 
25
    gchar *proto, guint external_port,
 
26
    gchar *description, gpointer user_data)
 
27
{
 
28
  g_error ("proto:%s port:%u desc:%s error: %s", proto, external_port,
 
29
      description, error->message);
 
30
}
 
31
 
 
32
 
 
33
int
 
34
main (int argc, char **argv)
 
35
{
 
36
  GUPnPSimpleIgdThread *igd = NULL;
 
37
  guint external_port, internal_port;
 
38
 
 
39
 
 
40
  if (argc != 5)
 
41
  {
 
42
    g_print ("Usage: %s <external port> <local ip> <local port> <description>\n",
 
43
        argv[0]);
 
44
    return 0;
 
45
  }
 
46
 
 
47
  external_port = atoi (argv[1]);
 
48
  internal_port = atoi (argv[3]);
 
49
  g_return_val_if_fail (external_port && internal_port, 1);
 
50
 
 
51
  g_type_init ();
 
52
  g_thread_init (NULL);
 
53
 
 
54
  igd = gupnp_simple_igd_thread_new ();
 
55
 
 
56
  g_signal_connect (igd, "mapped-external-port",
 
57
      G_CALLBACK (_mapped_external_port),
 
58
      NULL);
 
59
  g_signal_connect (igd, "error-mapping-port",
 
60
      G_CALLBACK (_error_mapping_external_port),
 
61
      NULL);
 
62
 
 
63
  gupnp_simple_igd_add_port (GUPNP_SIMPLE_IGD (igd),
 
64
      "TCP", external_port, argv[2],
 
65
      internal_port, 20, argv[4]);
 
66
 
 
67
  sleep (30);
 
68
 
 
69
  gupnp_simple_igd_remove_port (GUPNP_SIMPLE_IGD (igd), "TCP",
 
70
      external_port);
 
71
 
 
72
  sleep (5);
 
73
 
 
74
  g_object_unref (igd);
 
75
 
 
76
  return 0;
 
77
}