Make more variables/functions static and non-global.

The 'GSList *devices' from device.c was actually really global (i.e.,
listed in sigrok.h), which is now fixed.
This commit is contained in:
Uwe Hermann 2011-12-28 22:55:21 +01:00
parent c5d660ae24
commit a0ecd83bc6
10 changed files with 10 additions and 31 deletions

View File

@ -22,7 +22,7 @@
#include <sigrok.h> #include <sigrok.h>
#include <sigrok-internal.h> #include <sigrok-internal.h>
GSList *devices = NULL; static GSList *devices = NULL;
/** /**
* Scan the system for attached logic analyzers / devices. * Scan the system for attached logic analyzers / devices.

View File

@ -31,7 +31,6 @@
#include <string.h> #include <string.h>
#include "config.h" #include "config.h"
int ezusb_reset(struct libusb_device_handle *hdl, int set_clear) int ezusb_reset(struct libusb_device_handle *hdl, int set_clear)
{ {
int err; int err;

View File

@ -35,7 +35,7 @@
// FIXME: Must be moved, or rather passed as function argument. // FIXME: Must be moved, or rather passed as function argument.
#ifdef _WIN32 #ifdef _WIN32
HANDLE hdl; static HANDLE hdl;
#endif #endif
const char *serial_port_glob[] = { const char *serial_port_glob[] = {

View File

@ -564,7 +564,7 @@ static int receive_data(int fd, int revents, void *user_data)
return TRUE; return TRUE;
} }
void receive_transfer(struct libusb_transfer *transfer) static void receive_transfer(struct libusb_transfer *transfer)
{ {
/* TODO: these statics have to move to fx2_device struct */ /* TODO: these statics have to move to fx2_device struct */
static int num_samples = 0; static int num_samples = 0;

View File

@ -28,7 +28,7 @@
#include <sigrok-internal.h> #include <sigrok-internal.h>
/* The list of loaded plugins lives here. */ /* The list of loaded plugins lives here. */
GSList *plugins; static GSList *plugins;
/* /*
* This enumerates which plugin capabilities correspond to user-settable * This enumerates which plugin capabilities correspond to user-settable
@ -68,7 +68,6 @@ extern struct sr_device_plugin link_mso19_plugin_info;
extern struct sr_device_plugin alsa_plugin_info; extern struct sr_device_plugin alsa_plugin_info;
#endif #endif
/* TODO: No linked list needed, this can be a simple array. */ /* TODO: No linked list needed, this can be a simple array. */
int load_hwplugins(void) int load_hwplugins(void)
{ {
@ -99,7 +98,6 @@ int load_hwplugins(void)
plugins = g_slist_append(plugins, (gpointer *)&alsa_plugin_info); plugins = g_slist_append(plugins, (gpointer *)&alsa_plugin_info);
#endif #endif
return SR_OK; return SR_OK;
} }
@ -133,7 +131,6 @@ void sr_cleanup_hwplugins(void)
if (plugin->cleanup) if (plugin->cleanup)
plugin->cleanup(); plugin->cleanup();
} }
} }
struct sr_device_instance *sr_device_instance_new(int index, int status, struct sr_device_instance *sr_device_instance_new(int index, int status,
@ -195,7 +192,6 @@ void sr_device_instance_free(struct sr_device_instance *sdi)
g_free(sdi->model); g_free(sdi->model);
g_free(sdi->version); g_free(sdi->version);
g_free(sdi); g_free(sdi);
} }
#ifdef HAVE_LIBUSB_1_0 #ifdef HAVE_LIBUSB_1_0

View File

@ -28,7 +28,6 @@
#define CHUNKSIZE 4096 #define CHUNKSIZE 4096
#define DEFAULT_NUM_PROBES 8 #define DEFAULT_NUM_PROBES 8
static int format_match(const char *filename) static int format_match(const char *filename)
{ {
/* suppress compiler warning */ /* suppress compiler warning */

View File

@ -38,12 +38,12 @@ struct source {
}; };
/* There can only be one session at a time. */ /* There can only be one session at a time. */
/* 'session' is not static, it's used elsewhere (via 'extern'). */
struct sr_session *session; struct sr_session *session;
int num_sources = 0; static int num_sources = 0;
struct source *sources = NULL;
int source_timeout = -1;
static struct source *sources = NULL;
static int source_timeout = -1;
struct sr_session *sr_session_new(void) struct sr_session *sr_session_new(void)
{ {
@ -54,7 +54,6 @@ struct sr_session *sr_session_new(void)
void sr_session_destroy(void) void sr_session_destroy(void)
{ {
g_slist_free(session->devices); g_slist_free(session->devices);
/* TODO: Loop over protocol decoders and free them. */ /* TODO: Loop over protocol decoders and free them. */
@ -152,7 +151,6 @@ static void sr_session_run_poll()
} }
} }
free(fds); free(fds);
} }
int sr_session_start(void) int sr_session_start(void)
@ -174,7 +172,6 @@ int sr_session_start(void)
void sr_session_run(void) void sr_session_run(void)
{ {
sr_info("session: running"); sr_info("session: running");
session->running = TRUE; session->running = TRUE;
@ -186,15 +183,12 @@ void sr_session_run(void)
else else
/* real sources, use g_poll() main loop */ /* real sources, use g_poll() main loop */
sr_session_run_poll(); sr_session_run_poll();
} }
void sr_session_halt(void) void sr_session_halt(void)
{ {
sr_info("session: halting"); sr_info("session: halting");
session->running = FALSE; session->running = FALSE;
} }
void sr_session_stop(void) void sr_session_stop(void)
@ -209,7 +203,6 @@ void sr_session_stop(void)
if (device->plugin && device->plugin->stop_acquisition) if (device->plugin && device->plugin->stop_acquisition)
device->plugin->stop_acquisition(device->plugin_index, device); device->plugin->stop_acquisition(device->plugin_index, device);
} }
} }
static void datafeed_dump(struct sr_datafeed_packet *packet) static void datafeed_dump(struct sr_datafeed_packet *packet)
@ -236,7 +229,6 @@ static void datafeed_dump(struct sr_datafeed_packet *packet)
default: default:
sr_dbg("bus: received unknown packet type %d", packet->type); sr_dbg("bus: received unknown packet type %d", packet->type);
} }
} }
void sr_session_bus(struct sr_device *device, struct sr_datafeed_packet *packet) void sr_session_bus(struct sr_device *device, struct sr_datafeed_packet *packet)
@ -304,4 +296,3 @@ void sr_session_source_remove(int fd)
free(new_sources); free(new_sources);
} }
} }

View File

@ -47,7 +47,6 @@ static int capabilities[] = {
0, 0,
}; };
static struct session_vdevice *get_vdevice_by_index(int device_index) static struct session_vdevice *get_vdevice_by_index(int device_index)
{ {
struct sr_device_instance *sdi; struct sr_device_instance *sdi;
@ -147,7 +146,6 @@ static void hw_cleanup(void)
sr_session_source_remove(-1); sr_session_source_remove(-1);
g_free(sessionfile); g_free(sessionfile);
} }
static int hw_opendev(int device_index) static int hw_opendev(int device_index)
@ -190,7 +188,7 @@ static int hw_get_status(int device_index)
/* Avoid compiler warnings. */ /* Avoid compiler warnings. */
(void)device_index; (void)device_index;
if (devices) if (sr_device_list() != NULL)
return SR_OK; return SR_OK;
else else
return SR_ERR; return SR_ERR;
@ -198,7 +196,6 @@ static int hw_get_status(int device_index)
static int *hw_get_capabilities(void) static int *hw_get_capabilities(void)
{ {
return capabilities; return capabilities;
} }
@ -296,6 +293,7 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id)
return SR_OK; return SR_OK;
} }
/* Not static, it's used elsewhere (via 'extern'). */
struct sr_device_plugin session_driver = { struct sr_device_plugin session_driver = {
"session", "session",
"Session-emulating driver", "Session-emulating driver",

View File

@ -225,9 +225,6 @@ struct sr_probe {
char *trigger; char *trigger;
}; };
/* TODO: Get rid of this global variable. */
extern GSList *devices;
/* Hardware plugin capabilities */ /* Hardware plugin capabilities */
enum { enum {
SR_HWCAP_DUMMY, /* Used to terminate lists */ SR_HWCAP_DUMMY, /* Used to terminate lists */

View File

@ -284,4 +284,3 @@ gboolean sr_parse_boolstring(const char *boolstr)
return FALSE; return FALSE;
} }