diff options
author | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2016-02-18 12:08:42 +0100 |
---|---|---|
committer | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2016-02-18 12:08:42 +0100 |
commit | 01fdd893ced1f534eea2de39dc363c9e1f43d391 (patch) | |
tree | 133b0b8227d022e9daabfc16453c0c621c819e6a /uca-net-camera.c | |
parent | 508973808a736a563e54034f86dda39335d629f4 (diff) | |
download | uca-net-01fdd893ced1f534eea2de39dc363c9e1f43d391.tar.gz uca-net-01fdd893ced1f534eea2de39dc363c9e1f43d391.tar.bz2 uca-net-01fdd893ced1f534eea2de39dc363c9e1f43d391.tar.xz uca-net-01fdd893ced1f534eea2de39dc363c9e1f43d391.zip |
Proxy custom camera properties to the client
Diffstat (limited to 'uca-net-camera.c')
-rw-r--r-- | uca-net-camera.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/uca-net-camera.c b/uca-net-camera.c index f2d5638..849d446 100644 --- a/uca-net-camera.c +++ b/uca-net-camera.c @@ -455,6 +455,59 @@ ufo_net_camera_initable_init (GInitable *initable, return TRUE; } +static GParamSpec * +deserialize_param_spec (UcaNetMessageProperty *prop) +{ +#define CASE_NUMERIC(type, storage) \ + case type: \ + return g_param_spec_##storage (prop->name, prop->nick, prop->blurb, \ + prop->spec.g##storage.minimum, prop->spec.g##storage.maximum, \ + prop->spec.g##storage.default_value, \ + prop->flags); + switch (prop->value_type) { + case G_TYPE_BOOLEAN: + return g_param_spec_boolean (prop->name, prop->nick, prop->blurb, + prop->spec.gboolean.default_value, + prop->flags); + CASE_NUMERIC (G_TYPE_INT, int) + CASE_NUMERIC (G_TYPE_UINT, uint) + CASE_NUMERIC (G_TYPE_FLOAT, float) + CASE_NUMERIC (G_TYPE_DOUBLE, double) + default: + return NULL; + } + +#undef CASE_NUMERIC +} + +static void +read_property_reply (GObject *object, GInputStream *input, guint index, GError **error) +{ + UcaNetMessageProperty property; + + if (g_input_stream_read_all (input, &property, sizeof (property), NULL, NULL, error)) { + GParamSpec *pspec; + + pspec = deserialize_param_spec (&property); + + if (pspec != NULL) + g_object_class_install_property (G_OBJECT_GET_CLASS (object), N_PROPERTIES + index + 1, pspec); + } +} + +static void +read_get_properties_reply (GObject *object, GInputStream *input, GError **error) +{ + UcaNetMessageGetPropertiesReply reply; + + if (g_input_stream_read_all (input, &reply, sizeof (reply), NULL, NULL, error)) { + g_assert (reply.type == UCA_NET_MESSAGE_GET_PROPERTIES); + + for (guint i = 0; i < reply.num_properties; i++) + read_property_reply (object, input, i, error); + } +} + static void uca_net_camera_constructed (GObject *object) { @@ -466,6 +519,11 @@ uca_net_camera_constructed (GObject *object) priv->host = g_strdup ("localhost"); priv->connection = g_socket_client_connect_to_host (priv->client, priv->host, UCA_NET_DEFAULT_PORT, NULL, &priv->construct_error); + + /* ask for additional camera properties */ + if (send_default_message (priv->connection, UCA_NET_MESSAGE_GET_PROPERTIES, &priv->construct_error)) + read_get_properties_reply (object, g_io_stream_get_input_stream (G_IO_STREAM (priv->connection)), + &priv->construct_error); } static void |