summaryrefslogtreecommitdiffstats
path: root/ucad.c
diff options
context:
space:
mode:
authorMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2017-10-10 17:03:52 +0200
committerMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2017-10-10 17:03:52 +0200
commit74f1bde37dd4363e3fe3251b2a3567b3666d3a14 (patch)
treeab945a0717aa70ef92a8d353864d678646c34d93 /ucad.c
parent8317ec2fe9c892091c1c3d021277775e91435e95 (diff)
downloaduca-net-74f1bde37dd4363e3fe3251b2a3567b3666d3a14.tar.gz
uca-net-74f1bde37dd4363e3fe3251b2a3567b3666d3a14.tar.bz2
uca-net-74f1bde37dd4363e3fe3251b2a3567b3666d3a14.tar.xz
uca-net-74f1bde37dd4363e3fe3251b2a3567b3666d3a14.zip
Improve custom enum handling
Diffstat (limited to 'ucad.c')
-rw-r--r--ucad.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/ucad.c b/ucad.c
index f5817b9..28fbc16 100644
--- a/ucad.c
+++ b/ucad.c
@@ -114,6 +114,26 @@ serialize_param_spec (GParamSpec *pspec, UcaNetMessageProperty *prop)
prop->value_type = pspec->value_type;
prop->flags = pspec->flags;
+ if (g_type_is_a (pspec->value_type, G_TYPE_ENUM)) {
+ GEnumClass *enum_class;
+
+ enum_class = ((GParamSpecEnum *) pspec)->enum_class;
+ prop->value_type = G_TYPE_ENUM;
+ prop->spec.genum.default_value = ((GParamSpecEnum *) pspec)->default_value;
+ prop->spec.genum.minimum = enum_class->minimum;
+ prop->spec.genum.maximum = enum_class->maximum;
+ prop->spec.genum.n_values = enum_class->n_values;
+
+ if (enum_class->n_values > UCA_NET_MAX_ENUM_LENGTH)
+ g_warning ("Cannot serialize all values of %s", prop->name);
+
+ /* We do not transfer the enum value names (yet) ... */
+ for (guint i = 0; i < MIN (enum_class->n_values, UCA_NET_MAX_ENUM_LENGTH); i++)
+ prop->spec.genum.values[i] = enum_class->values[i].value;
+
+ return TRUE;
+ }
+
#define CASE_NUMERIC(type, storage, typeclass) \
case type: \
prop->spec.storage.minimum = ((typeclass *) pspec)->minimum; \