Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/arvfakeinterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ arv_fake_interface_update_device_list (ArvInterface *interface, GArray *device_i
}

static ArvDevice *
arv_fake_interface_open_device (ArvInterface *interface, const char *device_id, GError **error)
arv_fake_interface_open_device (ArvInterface *interface, const char *key, GError **error)
{
if (g_strcmp0 (device_id, ARV_FAKE_DEVICE_ID) == 0 ||
g_strcmp0 (device_id, ARV_FAKE_PHYSICAL_ID) == 0)
if (g_strcmp0 (key, ARV_FAKE_DEVICE_ID) == 0 ||
g_strcmp0 (key, ARV_FAKE_PHYSICAL_ID) == 0)
return arv_fake_device_new ("1", error);

return NULL;
Expand Down
99 changes: 66 additions & 33 deletions src/arvgentlinterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,25 @@
/* ArvGenTLnterface implementation */

typedef struct {
ArvGenTLSystem *system;
char *interface;

char *guid;
char *id;
char *name;
char *full_name;
char *vendor_serial;
char *vendor_alias_serial;
char *vendor;
char *model;
char *serial_nbr;

ArvGenTLSystem *system;
char *interface;
volatile gint ref_count;
} ArvGenTLInterfaceDeviceInfos;

static ArvGenTLInterfaceDeviceInfos *
arv_gentl_interface_device_infos_new (ArvGenTLSystem *system,
const char *tl_vendor,
const char *interface,
const char *id,
const char *guid,
const char *vendor,
const char *model,
const char *serial_nbr)
Expand All @@ -62,25 +65,26 @@ arv_gentl_interface_device_infos_new (ArvGenTLSystem *system,

g_return_val_if_fail (system != NULL, NULL);
g_return_val_if_fail (interface != NULL, NULL);
g_return_val_if_fail (id != NULL, NULL);
g_return_val_if_fail (guid != NULL, NULL);
g_return_val_if_fail (vendor != NULL, NULL);
g_return_val_if_fail (model != NULL, NULL);
g_return_val_if_fail (serial_nbr != NULL, NULL);

infos = g_new (ArvGenTLInterfaceDeviceInfos, 1);
infos->system = system;
infos->interface = g_strdup(interface);
infos->id = g_strdup(id);
infos->name = g_strdup_printf ("%s-%s", arv_vendor_alias_lookup (vendor), serial_nbr);
infos->full_name = g_strdup_printf ("%s-%s", vendor, serial_nbr);
infos->guid = g_strdup (guid);
infos->id = g_strdup_printf ("%s-%s-%s-%s", tl_vendor, vendor, model, serial_nbr);
infos->vendor_alias_serial = g_strdup_printf ("%s-%s-%s", tl_vendor, arv_vendor_alias_lookup (vendor), serial_nbr);
infos->vendor_serial = g_strdup_printf ("%s-%s-%s", tl_vendor, vendor, serial_nbr);
infos->vendor = g_strdup (vendor);
infos->model = g_strdup (model);
infos->serial_nbr = g_strdup (serial_nbr);
infos->ref_count = 1;

arv_str_strip (infos->id, ARV_DEVICE_NAME_ILLEGAL_CHARACTERS, ARV_DEVICE_NAME_REPLACEMENT_CHARACTER);
arv_str_strip (infos->name, ARV_DEVICE_NAME_ILLEGAL_CHARACTERS, ARV_DEVICE_NAME_REPLACEMENT_CHARACTER);
arv_str_strip (infos->full_name, ARV_DEVICE_NAME_ILLEGAL_CHARACTERS, ARV_DEVICE_NAME_REPLACEMENT_CHARACTER);
arv_str_strip (infos->vendor_serial, ARV_DEVICE_NAME_ILLEGAL_CHARACTERS, ARV_DEVICE_NAME_REPLACEMENT_CHARACTER);
arv_str_strip (infos->vendor_alias_serial, ARV_DEVICE_NAME_ILLEGAL_CHARACTERS, ARV_DEVICE_NAME_REPLACEMENT_CHARACTER);

return infos;
}
Expand All @@ -105,9 +109,10 @@ arv_gentl_interface_device_infos_unref (ArvGenTLInterfaceDeviceInfos *infos)
if (g_atomic_int_dec_and_test (&infos->ref_count)) {
infos->system = NULL;
g_clear_pointer (&infos->interface, g_free);
g_clear_pointer (&infos->guid, g_free);
g_clear_pointer (&infos->id, g_free);
g_clear_pointer (&infos->name, g_free);
g_clear_pointer (&infos->full_name, g_free);
g_clear_pointer (&infos->vendor_serial, g_free);
g_clear_pointer (&infos->vendor_alias_serial, g_free);
g_clear_pointer (&infos->vendor, g_free);
g_clear_pointer (&infos->model, g_free);
g_clear_pointer (&infos->serial_nbr, g_free);
Expand All @@ -132,6 +137,24 @@ struct _ArvGenTLInterfaceClass {

G_DEFINE_TYPE_WITH_CODE (ArvGenTLInterface, arv_gentl_interface, ARV_TYPE_INTERFACE, G_ADD_PRIVATE (ArvGenTLInterface))

static char *
_gentl_get_tl_info_str (ArvGenTLModule *gentl, TL_HANDLE handle, TL_INFO_CMD info_cmd)
{
GC_ERROR error;
INFO_DATATYPE type;
size_t size;
char *value = NULL;

error = gentl->TLGetInfo (handle, info_cmd, &type, NULL, &size);
if (error == GC_ERR_SUCCESS) {
value = g_malloc0(size);
gentl->TLGetInfo (handle, info_cmd, &type, value, &size);
} else {
arv_warning_interface("_gentl_get_tl_info_str: error %d", error);
}
return value;
}

static char *
_gentl_get_info_str(GC_ERROR(*func)(void*, const char *, int32_t, int32_t*, void*, size_t*),
void *interface, const char *device, BUFFER_INFO_CMD info_cmd)
Expand Down Expand Up @@ -224,12 +247,14 @@ _discover (ArvGenTLInterface *gentl_interface, GArray *device_ids)

/* Iterate over all devices of a GenTL interface */
for (uint32_t j=0; j<num_devices; j++) {
char *device_id, *id, *model, *vendor, *serial_nbr;
ArvGenTLInterfaceDeviceInfos *device_info;
char *tl_vendor, *device_id, *id, *model, *vendor, *serial_nbr;
ArvGenTLInterfaceDeviceInfos *device_infos;
ArvInterfaceDeviceIds *ids;

device_id = _gentl_get_id(gentl->IFGetDeviceID, interface_handle, j);

tl_vendor = _gentl_get_tl_info_str(gentl, system_handle, TL_INFO_VENDOR);

id = _gentl_get_info_str(gentl->IFGetDeviceInfo,
interface_handle, device_id, DEVICE_INFO_ID);
model = _gentl_get_info_str(gentl->IFGetDeviceInfo,
Expand All @@ -239,34 +264,43 @@ _discover (ArvGenTLInterface *gentl_interface, GArray *device_ids)
serial_nbr = _gentl_get_info_str(gentl->IFGetDeviceInfo,
interface_handle, device_id, DEVICE_INFO_SERIAL_NUMBER);

arv_info_interface ("Device: %s", device_id);
arv_info_interface (" ID: %s", id);
arv_info_interface (" VENDOR: %s", vendor);
arv_info_interface (" MODEL: %s", model);
arv_info_interface (" S/N: %s", serial_nbr);

device_info = arv_gentl_interface_device_infos_new(gentl_system, interface_id, id,
device_infos = arv_gentl_interface_device_infos_new(gentl_system, tl_vendor, interface_id, id,
vendor, model, serial_nbr);
g_hash_table_replace(priv->devices, device_info->id,
arv_gentl_interface_device_infos_ref(device_info));
arv_info_interface ("[GentTLInterface::discovery] Device '%s' found",
device_infos->id);

g_hash_table_replace(priv->devices, device_infos->id,
arv_gentl_interface_device_infos_ref(device_infos));
arv_info_interface (" %s", device_infos->id);
g_hash_table_replace (priv->devices, device_infos->vendor_serial,
arv_gentl_interface_device_infos_ref (device_infos));
arv_info_interface (" %s", device_infos->vendor_serial);
g_hash_table_replace (priv->devices, device_infos->vendor_alias_serial,
arv_gentl_interface_device_infos_ref (device_infos));
arv_info_interface (" %s", device_infos->vendor_alias_serial);
g_hash_table_replace (priv->devices, device_infos->guid,
arv_gentl_interface_device_infos_ref (device_infos));
arv_info_interface (" %s", device_infos->guid);

if (device_ids) {
ids = g_new0 (ArvInterfaceDeviceIds, 1);
ids->device = id;
ids->device = g_strdup (device_infos->id);
ids->model = model;
ids->vendor = vendor;
ids->serial_nbr = serial_nbr;
ids->address = g_strdup(interface_type);
ids->protocol = arv_protocol_from_transport_layer_type (interface_type);
g_array_append_val (device_ids, ids);
g_free (id);
} else {
g_free(id);
g_free(model);
g_free(vendor);
g_free(serial_nbr);
}
g_clear_pointer(&device_id, g_free);
arv_gentl_interface_device_infos_unref(device_info);

arv_gentl_interface_device_infos_unref(device_infos);
}
arv_gentl_system_close_interface_handle(gentl_system, interface_id);

Expand All @@ -288,38 +322,37 @@ arv_gentl_interface_update_device_list (ArvInterface *interface, GArray *device_
}

static ArvDevice *
arv_gentl_interface_open_device (ArvInterface *interface, const char *device_id, GError **error)
arv_gentl_interface_open_device (ArvInterface *interface, const char *key, GError **error)
{
ArvGenTLInterfacePrivate *priv = arv_gentl_interface_get_instance_private(ARV_GENTL_INTERFACE (interface));
ArvDevice *device = NULL;
ArvGenTLInterfaceDeviceInfos *device_infos = NULL;

if (device_id == NULL) {
if (key == NULL) {
GList *device_list;

device_list = g_hash_table_get_values (priv->devices);
device_infos = device_list != NULL ? device_list->data : NULL;
g_list_free (device_list);
} else
device_infos = g_hash_table_lookup (priv->devices, device_id);
device_infos = g_hash_table_lookup (priv->devices, key);

/* Refresh devices if the requested device is in the cache. */
if (device_infos == NULL) {
GList *device_list;

_discover(ARV_GENTL_INTERFACE(interface), NULL);

if (device_id == NULL) {
if (key == NULL) {
device_list = g_hash_table_get_values (priv->devices);
device_infos = device_list != NULL ? device_list->data : NULL;
g_list_free (device_list);
} else
device_infos = g_hash_table_lookup (priv->devices, device_id);
device_infos = g_hash_table_lookup (priv->devices, key);
}

if (device_infos)
device = arv_gentl_device_new (device_infos->system, device_infos->interface,
device_infos->id, error);
device = arv_gentl_device_new (device_infos->system, device_infos->interface, device_infos->guid, error);

return device;
}
Expand Down
41 changes: 27 additions & 14 deletions src/arvgvinterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,28 +443,41 @@ _discover (GHashTable *devices, const char *device_id, gboolean allow_broadcast_

if (devices != NULL) {
if (device_infos->id != NULL &&
device_infos->id[0] != '\0')
device_infos->id[0] != '\0') {
g_hash_table_replace
(devices, device_infos->id,
arv_gv_interface_device_infos_ref (device_infos));
arv_info_interface (" %s", device_infos->id);
}
if (device_infos->user_id != NULL &&
device_infos->user_id[0] != '\0')
device_infos->user_id[0] != '\0') {
g_hash_table_replace
(devices, device_infos->user_id,
arv_gv_interface_device_infos_ref (device_infos));
arv_info_interface (" %s",
device_infos->user_id);
}
if (device_infos->vendor_serial != NULL &&
device_infos->vendor_serial[0] != '\0')
device_infos->vendor_serial[0] != '\0') {
g_hash_table_replace
(devices, device_infos->vendor_serial,
arv_gv_interface_device_infos_ref (device_infos));
arv_info_interface (" %s",
device_infos->vendor_serial);
}
if (device_infos->vendor_alias_serial != NULL &&
device_infos->vendor_alias_serial[0] != '\0')
device_infos->vendor_alias_serial[0] != '\0') {
g_hash_table_replace
(devices, device_infos->vendor_alias_serial,
arv_gv_interface_device_infos_ref (device_infos));
arv_info_interface (" %s",
device_infos->vendor_alias_serial);
}
g_hash_table_replace
(devices, device_infos->mac,
arv_gv_interface_device_infos_ref (device_infos));
arv_info_interface (" %s",
device_infos->mac);
} else {
if (device_id == NULL ||
g_strcmp0 (device_infos->id, device_id) == 0 ||
Expand Down Expand Up @@ -667,7 +680,7 @@ arv_gv_interface_camera_locate (ArvGvInterface *gv_interface, GInetAddress *devi
}

static ArvDevice *
_open_device (ArvInterface *interface, GHashTable *devices, const char *device_id, GError **error)
_open_device (ArvInterface *interface, GHashTable *devices, const char *key, GError **error)
{
ArvGvInterface *gv_interface;
ArvDevice *device = NULL;
Expand All @@ -676,29 +689,29 @@ _open_device (ArvInterface *interface, GHashTable *devices, const char *device_i

gv_interface = ARV_GV_INTERFACE (interface);

if (device_id == NULL) {
if (key == NULL) {
GList *device_list;

device_list = g_hash_table_get_values (devices);
device_infos = device_list != NULL ? device_list->data : NULL;
g_list_free (device_list);
} else
device_infos = g_hash_table_lookup (devices, device_id);
device_infos = g_hash_table_lookup (devices, key);

if (device_infos == NULL) {
struct addrinfo hints;
struct addrinfo *servinfo, *endpoint;

if (device_id == NULL)
if (key == NULL)
return NULL;

/* Try if device_id is a hostname/IP address */
/* Try if key is a hostname/IP address */

memset(&hints, 0, sizeof (hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_DGRAM;

if (getaddrinfo(device_id, "3956", &hints, &servinfo) != 0) {
if (getaddrinfo(key, "3956", &hints, &servinfo) != 0) {
return NULL;
}

Expand Down Expand Up @@ -728,7 +741,7 @@ _open_device (ArvInterface *interface, GHashTable *devices, const char *device_i

if (device == NULL)
g_set_error (error, ARV_DEVICE_ERROR, ARV_DEVICE_ERROR_NOT_FOUND,
"Can't connect to device at address '%s'", device_id);
"Can't connect to device at address '%s'", key);

return device;
}
Expand All @@ -741,15 +754,15 @@ _open_device (ArvInterface *interface, GHashTable *devices, const char *device_i
}

static ArvDevice *
arv_gv_interface_open_device (ArvInterface *interface, const char *device_id, GError **error)
arv_gv_interface_open_device (ArvInterface *interface, const char *key, GError **error)
{
ArvDevice *device;
ArvGvInterfaceDeviceInfos *device_infos;
char *discovery_interface;
GError *local_error = NULL;
int flags;

device = _open_device (interface, ARV_GV_INTERFACE (interface)->priv->devices, device_id, &local_error);
device = _open_device (interface, ARV_GV_INTERFACE (interface)->priv->devices, key, &local_error);
if (ARV_IS_DEVICE (device) || local_error != NULL) {
if (local_error != NULL)
g_propagate_error (error, local_error);
Expand All @@ -758,7 +771,7 @@ arv_gv_interface_open_device (ArvInterface *interface, const char *device_id, GE

flags = arv_interface_get_flags (interface);
discovery_interface = arv_gv_interface_dup_discovery_interface_name();
device_infos = _discover (NULL, device_id, flags & ARV_GVCP_DISCOVERY_PACKET_FLAGS_ALLOW_BROADCAST_ACK,
device_infos = _discover (NULL, key, flags & ARV_GVCP_DISCOVERY_PACKET_FLAGS_ALLOW_BROADCAST_ACK,
discovery_interface);
g_free (discovery_interface);

Expand Down
8 changes: 4 additions & 4 deletions src/arvinterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,23 +372,23 @@ arv_interface_get_device_protocol (ArvInterface *iface, unsigned int index)
/**
* arv_interface_open_device:
* @iface: a #ArvInterface
* @device_id: (allow-none): device unique id
* @key: (allow-none): device search key
* @error: a #GError placeholder, %NULL to ignore
*
* Creates a new #ArvDevice object corresponding to the given device id string.
* The first available device is returned if @device_id is %NULL.
* The first available device is returned if @key is %NULL.
*
* Returns: (transfer full): a new #ArvDevice
*
* Since: 0.2.0
*/

ArvDevice *
arv_interface_open_device (ArvInterface *iface, const char *device_id, GError **error)
arv_interface_open_device (ArvInterface *iface, const char *key, GError **error)
{
g_return_val_if_fail (ARV_IS_INTERFACE (iface), NULL);

return ARV_INTERFACE_GET_CLASS (iface)->open_device (iface, device_id, error);
return ARV_INTERFACE_GET_CLASS (iface)->open_device (iface, key, error);
}

static void
Expand Down
Loading
Loading