Skip to content

Using multiple (different) uca-net cameras #24

@MarcusZuber

Description

@MarcusZuber

When an uca-net camera is instantiated all the properties of the remote camera are attached to the net-camera-class.
A second instantiation triggers this again, resulting in a mixing of properties.

E.g. this:
we run "ucad file -p 1234" and "ucad mock -p 8989" and use this code (ignore everything beside the main()-function):

#include <iostream>
#include <uca/uca-plugin-manager.h>
#include <uca/uca-camera.h>
#include <glib-object.h>
#include <stdlib.h>

static const gchar * get_flags_description (GParamSpec *pspec)
{
    static const gchar *descriptions[] = { "", "RO", "WO", "RW", "" };

    if (pspec->flags >= 3)
        return descriptions[3];

    return descriptions[pspec->flags];
}

static void print_properties (UcaCamera *camera)
{
    GObjectClass *oclass;
    GParamSpec **pspecs;
    GHashTable *map;
    GList *names;
    gchar *fmt_string;
    guint n_props;
    guint max_length = 0;

    oclass = G_OBJECT_GET_CLASS (camera);
    pspecs = g_object_class_list_properties (oclass, &n_props);

    for (guint i = 0; i < n_props; i++)
        max_length = MAX (max_length, strlen (g_param_spec_get_name (pspecs[i])));

    map = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);

    for (guint i = 0; i < n_props; i++) {
        GParamSpec *pspec;
        GValue value= { 0, { { 0 } } };
        const gchar *name;

        pspec = pspecs[i];
        name = g_param_spec_get_name (pspec);
        g_value_init (&value, pspec->value_type);

        g_object_get_property (G_OBJECT (camera), name, &value);
        g_hash_table_insert (map, (gpointer) name, g_strdup_value_contents (&value));
        g_value_unset (&value);
    }

    fmt_string = g_strdup_printf (" %%s | %%-%us | %%s\n", max_length);
    names = g_list_sort (g_hash_table_get_keys (map), (GCompareFunc) g_strcmp0);

    for (GList *it = g_list_first (names); it != NULL; it = g_list_next (it)) {
        GParamSpec *pspec;
        const gchar *name;
        gpointer value;

        name = (const gchar *) it->data;
        pspec = g_object_class_find_property (oclass, name);
        value = g_hash_table_lookup (map, name);
        g_print (fmt_string, get_flags_description (pspec), name, value);
    }

    g_list_free (names);
    g_hash_table_destroy (map);
    g_free (fmt_string);
    g_free (pspecs);
}

int main()
{
    GError *error = nullptr; /* this _must_ be set to NULL */
    const auto manager = uca_plugin_manager_new();

    // Mock camera
    setenv("UCA_NET_HOST", "localhost:8989", 1);
    const auto camera = uca_plugin_manager_get_camerah (manager, "net", nullptr, &error);

    // File camera
    setenv("UCA_NET_HOST", "localhost:1234", 1);
    const auto camera2 = uca_plugin_manager_get_camerah (manager, "net", nullptr, &error);

    if (error) {
        std::cerr << "Error: " << error->message << std::endl;
        g_error_free(error);
        return 1;
    }

    std::cout << "Mock via uca-net:" <<std::endl;

    print_properties(camera);

    std::cout << "File via uca-net:" <<std::endl;

    print_properties(camera2);

    g_object_unref (camera);
    g_object_unref (camera2);

    return 0;
}

This will result in this output:

Mock via uca-net:
 RW | buffered                  | FALSE
 RW | degree-value              | 1.000000
 RW | exposure-time             | 0.050000
 RW | fill-data                 | TRUE
 RW | frames-per-second         | 20.000000
 RO | has-camram-recording      | FALSE
 RO | has-streaming             | TRUE
 RW | host                      | "localhost:8989"
 RO | is-readout                | FALSE
 RO | is-recording              | FALSE
 RO | name                      | "mock camera"
 RW | num-buffers               | 4
 RW | path                      | NULL
 RO | port                      | 8989
 RO | recorded-frames           | 0
 RW | roi-height                | 512
 RO | roi-height-multiplier     | 1
 RW | roi-width                 | 512
 RO | roi-width-multiplier      | 1
 RW | roi-x0                    | 0
 RW | roi-y0                    | 0
 RO | sensor-bitdepth           | 8
 RO | sensor-height             | 4096
 RW | sensor-horizontal-binning | 1
 RO | sensor-pixel-height       | 0.000010
 RO | sensor-pixel-width        | 0.000010
 RW | sensor-vertical-binning   | 1
 RO | sensor-width              | 4096
 RW | test-enum                 | ((test-enum) UCA_MOCK_CAMERA_TEST_ENUM_FOO)
 RW | transfer-asynchronously   | FALSE
 RW | trigger-source            | ((UcaCameraTriggerSource) UCA_CAMERA_TRIGGER_SOURCE_AUTO)
 RW | trigger-type              | ((UcaCameraTriggerType) UCA_CAMERA_TRIGGER_TYPE_EDGE)
File via uca-net:
 RW | buffered                  | FALSE
 RW | degree-value              | 0.000000
 RW | exposure-time             | 0.100000
 RW | fill-data                 | FALSE
 RW | frames-per-second         | 10.000000
 RO | has-camram-recording      | FALSE
 RO | has-streaming             | TRUE
 RW | host                      | "localhost:1234"
 RO | is-readout                | FALSE
 RO | is-recording              | FALSE
 RO | name                      | "file camera"
 RW | num-buffers               | 4
 RW | path                      | "."
 RO | port                      | 8989
 RO | recorded-frames           | 0
 RW | roi-height                | 512
 RO | roi-height-multiplier     | 1
 RW | roi-width                 | 512
 RO | roi-width-multiplier      | 1
 RW | roi-x0                    | 0
 RW | roi-y0                    | 0
 RO | sensor-bitdepth           | 8
 RO | sensor-height             | 512
 RW | sensor-horizontal-binning | 1
 RO | sensor-pixel-height       | 0.000010
 RO | sensor-pixel-width        | 0.000010
 RW | sensor-vertical-binning   | 1
 RO | sensor-width              | 512
 RW | test-enum                 | ((test-enum) UCA_MOCK_CAMERA_TEST_ENUM_FOO)
 RW | transfer-asynchronously   | FALSE
 RW | trigger-source            | ((UcaCameraTriggerSource) UCA_CAMERA_TRIGGER_SOURCE_AUTO)
 RW | trigger-type              | ((UcaCameraTriggerType) UCA_CAMERA_TRIGGER_TYPE_EDGE)

(process:50509): Uca-Net-WARNING **: 11:30:12.207: Could not get property: Reply does not match request

(process:50509): Uca-Net-WARNING **: 11:30:12.210: Could not get property: Reply does not match request

(process:50509): Uca-Net-WARNING **: 11:30:12.211: Could not get property: Reply does not match request

(process:50509): Uca-Net-WARNING **: 11:30:12.211: Could not get property: Reply does not match request

Process finished with exit code 0

where the mock has a (NULL) path and the file has some mock-parameters.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions