sr: cleanup callback: Return int.

This commit is contained in:
Uwe Hermann 2012-02-12 20:52:42 +01:00
parent 3010f21c91
commit 57ab7d9f92
10 changed files with 86 additions and 28 deletions

View File

@ -150,15 +150,19 @@ static int hw_closedev(int device_index)
return SR_OK; return SR_OK;
} }
static void hw_cleanup(void) static int hw_cleanup(void)
{ {
struct sr_device_instance *sdi; struct sr_device_instance *sdi;
if (!(sdi = sr_get_device_instance(device_instances, 0))) if (!(sdi = sr_get_device_instance(device_instances, 0))) {
return; sr_err("alsa: %s: sdi was NULL", __func__);
return SR_ERR_BUG;
}
g_free(sdi->priv); g_free(sdi->priv);
sr_device_instance_free(sdi); sr_device_instance_free(sdi);
return SR_OK;
} }
static void *hw_get_device_info(int device_index, int device_info_id) static void *hw_get_device_info(int device_index, int device_info_id)

View File

@ -721,20 +721,27 @@ static int hw_closedev(int device_index)
return SR_OK; return SR_OK;
} }
static void hw_cleanup(void) static int hw_cleanup(void)
{ {
GSList *l; GSList *l;
struct sr_device_instance *sdi; struct sr_device_instance *sdi;
int ret = SR_OK;
/* Properly close all devices. */ /* Properly close all devices. */
for (l = device_instances; l; l = l->next) { for (l = device_instances; l; l = l->next) {
sdi = l->data; if (!(sdi = l->data)) {
if (sdi->priv != NULL) /* Log error, but continue cleaning up the rest. */
sr_err("asix: %s: sdi was NULL, continuing", __func__);
ret = SR_ERR_BUG;
continue;
}
g_free(sdi->priv); g_free(sdi->priv);
sr_device_instance_free(sdi); sr_device_instance_free(sdi);
} }
g_slist_free(device_instances); g_slist_free(device_instances);
device_instances = NULL; device_instances = NULL;
return ret;
} }
static void *hw_get_device_info(int device_index, int device_info_id) static void *hw_get_device_info(int device_index, int device_info_id)

View File

@ -679,17 +679,20 @@ static int hw_closedev(int device_index)
return SR_OK; return SR_OK;
} }
static void hw_cleanup(void) static int hw_cleanup(void)
{ {
GSList *l; GSList *l;
struct sr_device_instance *sdi; struct sr_device_instance *sdi;
int ret = SR_OK;
sr_spew("la8: entering %s", __func__); sr_spew("la8: entering %s", __func__);
/* Properly close all devices. */ /* Properly close all devices. */
for (l = device_instances; l; l = l->next) { for (l = device_instances; l; l = l->next) {
if ((sdi = l->data) == NULL) { if (!(sdi = l->data)) {
/* Log error, but continue cleaning up the rest. */
sr_err("la8: %s: sdi was NULL, continuing", __func__); sr_err("la8: %s: sdi was NULL, continuing", __func__);
ret = SR_ERR_BUG;
continue; continue;
} }
#if 0 #if 0
@ -707,6 +710,8 @@ static void hw_cleanup(void)
} }
g_slist_free(device_instances); /* Returns void. */ g_slist_free(device_instances); /* Returns void. */
device_instances = NULL; device_instances = NULL;
return ret;
} }
static void *hw_get_device_info(int device_index, int device_info_id) static void *hw_get_device_info(int device_index, int device_info_id)

View File

@ -174,9 +174,10 @@ static int hw_closedev(int device_index)
return SR_OK; return SR_OK;
} }
static void hw_cleanup(void) static int hw_cleanup(void)
{ {
/* Nothing needed so far. */ /* Nothing needed so far. */
return SR_OK;
} }
static void *hw_get_device_info(int device_index, int device_info_id) static void *hw_get_device_info(int device_index, int device_info_id)

View File

@ -518,25 +518,30 @@ ret:
return devcnt; return devcnt;
} }
static void hw_cleanup(void) static int hw_cleanup(void)
{ {
GSList *l; GSList *l;
struct sr_device_instance *sdi; struct sr_device_instance *sdi;
int ret = SR_OK;
/* Properly close all devices. */ /* Properly close all devices. */
for (l = device_instances; l; l = l->next) { for (l = device_instances; l; l = l->next) {
sdi = l->data; if (!(sdi = l->data)) {
/* Log error, but continue cleaning up the rest. */
sr_err("mso19: %s: sdi was NULL, continuing", __func__);
ret = SR_ERR_BUG;
continue;
}
if (sdi->serial->fd != -1) if (sdi->serial->fd != -1)
serial_close(sdi->serial->fd); serial_close(sdi->serial->fd);
if (sdi->priv != NULL)
{
g_free(sdi->priv); g_free(sdi->priv);
sdi->priv = NULL; sdi->priv = NULL;
}
sr_device_instance_free(sdi); sr_device_instance_free(sdi);
} }
g_slist_free(device_instances); g_slist_free(device_instances);
device_instances = NULL; device_instances = NULL;
return SR_OK;
} }
static int hw_opendev(int device_index) static int hw_opendev(int device_index)

View File

@ -521,16 +521,29 @@ static int hw_closedev(int device_index)
return SR_OK; return SR_OK;
} }
static void hw_cleanup(void) static int hw_cleanup(void)
{ {
GSList *l; GSList *l;
struct sr_device_instance *sdi; struct sr_device_instance *sdi;
struct ols_device *ols; struct ols_device *ols;
int ret = SR_OK;
/* Properly close and free all devices. */ /* Properly close and free all devices. */
for (l = device_instances; l; l = l->next) { for (l = device_instances; l; l = l->next) {
sdi = l->data; if (!(sdi = l->data)) {
ols = sdi->priv; /* Log error, but continue cleaning up the rest. */
sr_err("ols: %s: sdi was NULL, continuing", __func__);
ret = SR_ERR_BUG;
continue;
}
if (!(ols = sdi->priv)) {
/* Log error, but continue cleaning up the rest. */
sr_err("ols: %s: sdi->priv was NULL, continuing",
__func__);
ret = SR_ERR_BUG;
continue;
}
/* TODO: Check for serial != NULL. */
if (ols->serial->fd != -1) if (ols->serial->fd != -1)
serial_close(ols->serial->fd); serial_close(ols->serial->fd);
sr_serial_device_instance_free(ols->serial); sr_serial_device_instance_free(ols->serial);
@ -538,6 +551,8 @@ static void hw_cleanup(void)
} }
g_slist_free(device_instances); g_slist_free(device_instances);
device_instances = NULL; device_instances = NULL;
return ret;
} }
static void *hw_get_device_info(int device_index, int device_info_id) static void *hw_get_device_info(int device_index, int device_info_id)

View File

@ -460,16 +460,28 @@ static int hw_closedev(int device_index)
return SR_OK; return SR_OK;
} }
static void hw_cleanup(void) static int hw_cleanup(void)
{ {
GSList *l; GSList *l;
struct sr_device_instance *sdi; struct sr_device_instance *sdi;
struct fx2_device *fx2; struct fx2_device *fx2;
int ret = SR_OK;
/* Properly close and free all devices. */ /* Properly close and free all devices. */
for (l = device_instances; l; l = l->next) { for (l = device_instances; l; l = l->next) {
sdi = l->data; if (!(sdi = l->data)) {
fx2 = sdi->priv; /* Log error, but continue cleaning up the rest. */
sr_err("fx2: %s: sdi was NULL, continuing", __func__);
ret = SR_ERR_BUG;
continue;
}
if (!(fx2 = sdi->priv)) {
/* Log error, but continue cleaning up the rest. */
sr_err("fx2: %s: sdi->priv was NULL, continuing",
__func__);
ret = SR_ERR_BUG;
continue;
}
close_device(sdi); close_device(sdi);
sr_usb_device_instance_free(fx2->usb); sr_usb_device_instance_free(fx2->usb);
sr_device_instance_free(sdi); sr_device_instance_free(sdi);
@ -481,6 +493,8 @@ static void hw_cleanup(void)
if (usb_context) if (usb_context)
libusb_exit(usb_context); libusb_exit(usb_context);
usb_context = NULL; usb_context = NULL;
return ret;
} }
static void *hw_get_device_info(int device_index, int device_info_id) static void *hw_get_device_info(int device_index, int device_info_id)

View File

@ -485,10 +485,12 @@ static int hw_closedev(int device_index)
return SR_OK; return SR_OK;
} }
static void hw_cleanup(void) static int hw_cleanup(void)
{ {
GSList *l; GSList *l;
/* TODO: Error handling. */
/* Properly close all devices... */ /* Properly close all devices... */
for (l = device_instances; l; l = l->next) for (l = device_instances; l; l = l->next)
close_device((struct sr_device_instance *)l->data); close_device((struct sr_device_instance *)l->data);
@ -502,6 +504,8 @@ static void hw_cleanup(void)
if (usb_context) if (usb_context)
libusb_exit(usb_context); libusb_exit(usb_context);
usb_context = NULL; usb_context = NULL;
return SR_OK;
} }
static void *hw_get_device_info(int device_index, int device_info_id) static void *hw_get_device_info(int device_index, int device_info_id)

View File

@ -138,7 +138,7 @@ static int feed_chunk(int fd, int revents, void *session_data)
} }
/* driver callbacks */ /* driver callbacks */
static void hw_cleanup(void); static int hw_cleanup(void);
/** /**
* TODO. * TODO.
@ -149,7 +149,6 @@ static void hw_cleanup(void);
*/ */
static int hw_init(const char *deviceinfo) static int hw_init(const char *deviceinfo)
{ {
sessionfile = g_strdup(deviceinfo); sessionfile = g_strdup(deviceinfo);
return 0; return 0;
@ -159,10 +158,12 @@ static int hw_init(const char *deviceinfo)
* TODO. * TODO.
* *
*/ */
static void hw_cleanup(void) static int hw_cleanup(void)
{ {
GSList *l; GSList *l;
/* TODO: Error handling. */
for (l = device_instances; l; l = l->next) for (l = device_instances; l; l = l->next)
sr_device_instance_free(l->data); sr_device_instance_free(l->data);
@ -172,6 +173,8 @@ static void hw_cleanup(void)
sr_session_source_remove(-1); sr_session_source_remove(-1);
g_free(sessionfile); g_free(sessionfile);
return SR_OK;
} }
static int hw_opendev(int device_index) static int hw_opendev(int device_index)

View File

@ -344,7 +344,7 @@ struct sr_device_plugin {
char *longname; char *longname;
int api_version; int api_version;
int (*init) (const char *deviceinfo); int (*init) (const char *deviceinfo);
void (*cleanup) (void); int (*cleanup) (void);
/* Device-specific */ /* Device-specific */
int (*opendev) (int device_index); int (*opendev) (int device_index);