summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2016-02-17 09:32:55 +0100
committerMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2016-02-17 09:32:55 +0100
commit85ed63d3e0a4d27b5b07b162ccb53d82c9c2305b (patch)
tree885d5db48d3373354ab7ea75f864b22362fd3212
parent2cf4562e5540d0b275ba85427735a0e1d684484f (diff)
downloaduca-net-85ed63d3e0a4d27b5b07b162ccb53d82c9c2305b.tar.gz
uca-net-85ed63d3e0a4d27b5b07b162ccb53d82c9c2305b.tar.bz2
uca-net-85ed63d3e0a4d27b5b07b162ccb53d82c9c2305b.tar.xz
uca-net-85ed63d3e0a4d27b5b07b162ccb53d82c9c2305b.zip
Set port centrally and allow server override
-rw-r--r--CMakeLists.txt5
-rw-r--r--config.h.in1
-rw-r--r--uca-net-camera.c3
-rw-r--r--ucad.c13
4 files changed, 16 insertions, 6 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a864fd0..aa5ab7f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -16,7 +16,10 @@ pkg_check_modules(GIO gio-2.0>=2.22 REQUIRED)
pkg_check_modules(UCA libuca>=2.1.0 REQUIRED)
pkg_check_variable(libuca plugindir)
-include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${UCA_INCLUDE_DIRS} ${GIO_INCLUDE_DIRS} ${MSGPACK_INCLUDE_DIRS})
+set(UCA_NET_DEFAULT_PORT 8989)
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${UCA_INCLUDE_DIRS} ${GIO_INCLUDE_DIRS})
link_directories(${UCA_LIBRARY_DIRS} ${GIO_LIBRARY_DIRS})
# uca-net client camera
diff --git a/config.h.in b/config.h.in
new file mode 100644
index 0000000..43d9bb6
--- /dev/null
+++ b/config.h.in
@@ -0,0 +1 @@
+#cmakedefine UCA_NET_DEFAULT_PORT ${UCA_NET_DEFAULT_PORT}
diff --git a/uca-net-camera.c b/uca-net-camera.c
index d755a07..bd1c044 100644
--- a/uca-net-camera.c
+++ b/uca-net-camera.c
@@ -23,6 +23,7 @@
#include <uca/uca-camera.h>
#include "uca-net-camera.h"
#include "uca-net-protocol.h"
+#include "config.h"
#define UCA_NET_CAMERA_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), UCA_TYPE_NET_CAMERA, UcaNetCameraPrivate))
@@ -242,7 +243,7 @@ uca_net_camera_constructed (GObject *object)
if (priv->host == NULL)
priv->host = g_strdup ("localhost");
- priv->connection = g_socket_client_connect_to_host (priv->client, priv->host, 8989, NULL, &priv->construct_error);
+ priv->connection = g_socket_client_connect_to_host (priv->client, priv->host, UCA_NET_DEFAULT_PORT, NULL, &priv->construct_error);
}
static void
diff --git a/ucad.c b/ucad.c
index 699b420..6421c21 100644
--- a/ucad.c
+++ b/ucad.c
@@ -21,6 +21,7 @@
#include <uca/uca-camera.h>
#include <uca/uca-plugin-manager.h>
#include "uca-net-protocol.h"
+#include "config.h"
typedef void (*MessageHandler) (GSocketConnection *connection, UcaCamera *camera, gpointer message, GError **error);
@@ -311,14 +312,14 @@ run_callback (GSocketService *service, GSocketConnection *connection, GObject *s
}
static void
-serve (UcaCamera *camera, GError **error)
+serve (UcaCamera *camera, guint16 port, GError **error)
{
GMainLoop *loop;
GSocketService *service;
service = g_threaded_socket_service_new (1);
- if (!g_socket_listener_add_inet_port (G_SOCKET_LISTENER (service), 8989, NULL, error))
+ if (!g_socket_listener_add_inet_port (G_SOCKET_LISTENER (service), port, NULL, error))
return;
g_signal_connect (service, "run", G_CALLBACK (run_callback), camera);
@@ -334,8 +335,12 @@ main (int argc, char **argv)
UcaPluginManager *manager;
UcaCamera *camera;
GError *error = NULL;
+ static guint16 port = UCA_NET_DEFAULT_PORT;
- static GOptionEntry entries[] = { { NULL } };
+ static GOptionEntry entries[] = {
+ { "port", 'p', 0, G_OPTION_ARG_INT, &port, "Listen port (default: "G_STRINGIFY (UCA_NET_DEFAULT_PORT)")", NULL },
+ { NULL }
+ };
#if !(GLIB_CHECK_VERSION (2, 36, 0))
g_type_init();
@@ -371,7 +376,7 @@ main (int argc, char **argv)
g_option_context_free (context);
- serve (camera, &error);
+ serve (camera, port, &error);
cleanup_camera:
g_object_unref (camera);