diff --git a/.gitignore b/.gitignore index 4fcd01f..54ee763 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ build/ +build-static/ +build-shared/ vxi11.h vxi11_cmd vxi11_clnt.c @@ -8,7 +10,9 @@ TAGS vxi11_test.cc vxi11_test.cc docs -libvxi11.so.0 +libvxi11.a +libvxi11.so +libvxi11.so.* vxi11_send *.o *.pyc diff --git a/Makefile b/Makefile index 7761e9e..e28bf8c 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION=2.0 +VERSION=2.1 include config.mk diff --git a/library/Makefile b/library/Makefile index 881b419..f9d7bd2 100644 --- a/library/Makefile +++ b/library/Makefile @@ -1,6 +1,6 @@ include ../config.mk -.PHONY : all install clean dist distclean +.PHONY : all static shared install clean dist distclean UNAME:=$(shell uname -s) @@ -8,31 +8,45 @@ ifneq ($(UNAME),SunOS) LDFLAGS:=$(LDFLAGS) -Wl,--version-script=linker.version endif -all : libvxi11.so.${SOVERSION} +OBJ:=vxi11_user.o vxi11_clnt.o vxi11_xdr.o +SDIR:=build-static +DDIR:=build-shared -libvxi11.so.${SOVERSION} : vxi11_user.o vxi11_clnt.o vxi11_xdr.o +all : static shared +static : libvxi11.a +shared : libvxi11.so + +libvxi11.so : libvxi11.so.${SOVERSION} + ln -sf libvxi11.so.${SOVERSION} libvxi11.so + +libvxi11.so.${SOVERSION} : $(addprefix ${DDIR}/,${OBJ}) $(CC) $(LDFLAGS) -shared -Wl,-soname,libvxi11.so.${SOVERSION} $^ -o $@ -vxi11_user.o: vxi11_user.c vxi11.h - $(CC) -fPIC $(CFLAGS) -c $< -o $@ +libvxi11.a : $(addprefix ${SDIR}/,${OBJ}) + $(AR) rcs $@ $^ -vxi11_clnt.o : vxi11_clnt.c +${DDIR}/%.o : %.c vxi11.h | ${DDIR} $(CC) -fPIC $(CFLAGS) -c $< -o $@ -vxi11_xdr.o : vxi11_xdr.c - $(CC) -fPIC $(CFLAGS) -c $< -o $@ +${SDIR}/%.o : %.c vxi11.h | ${SDIR} + $(CC) $(CFLAGS) -c $< -o $@ vxi11.h vxi11_clnt.c vxi11_xdr.c : vxi11.x rpcgen -M vxi11.x +${SDIR} ${DDIR}: + @mkdir $@ + TAGS: $(wildcard *.c) $(wildcard *.h) $(wildcard *.c) etags $^ clean: - rm -f *.o libvxi11.so.${SOVERSION} vxi11.h vxi11_svc.c vxi11_xdr.c vxi11_clnt.c TAGS + rm -rf ${SDIR} ${DDIR} + rm -f *.o libvxi11.so libvxi11.so.${SOVERSION} libvxi11.a vxi11.h vxi11_svc.c vxi11_xdr.c vxi11_clnt.c TAGS install: all $(INSTALL) -d $(DESTDIR)$(prefix)/lib${LIB_SUFFIX}/ + $(INSTALL) libvxi11.a $(DESTDIR)$(prefix)/lib${LIB_SUFFIX}/ $(INSTALL) libvxi11.so.${SOVERSION} $(DESTDIR)$(prefix)/lib${LIB_SUFFIX}/ ln -sf libvxi11.so.${SOVERSION} $(DESTDIR)$(prefix)/lib${LIB_SUFFIX}/libvxi11.so $(INSTALL) -d $(DESTDIR)$(prefix)/include/ diff --git a/library/linker.version b/library/linker.version index 3d9c829..4b9a8e4 100644 --- a/library/linker.version +++ b/library/linker.version @@ -2,15 +2,17 @@ * symbols are exported. */ -VXI11_2.0 { +VXI11_2.1 { global: vxi11_close_device; + vxi11_close_device_clients; vxi11_lib_version; vxi11_obtain_double_value; vxi11_obtain_double_value_timeout; vxi11_obtain_long_value; vxi11_obtain_long_value_timeout; vxi11_open_device; + vxi11_open_device_clients; vxi11_receive; vxi11_receive_data_block; vxi11_receive_timeout; diff --git a/library/vxi11_user.c b/library/vxi11_user.c index de216ed..046f899 100644 --- a/library/vxi11_user.c +++ b/library/vxi11_user.c @@ -63,16 +63,7 @@ struct _VXI11_CLINK { * with the same address or not */ -struct _vxi11_client_t { - struct _vxi11_client_t *next; - char address[20]; -#ifndef WIN32 - CLIENT *client_address; -#endif - int link_count; -}; - -static struct _vxi11_client_t *VXI11_CLIENTS = NULL; +static vxi11_client_t *VXI11_CLIENTS = NULL; /* Internal function declarations. */ static int _vxi11_open_link(VXI11_CLINK * clink, const char *address, @@ -99,13 +90,18 @@ int vxi11_lib_version(int *major, int *minor, int *revision) /* Use this function from user land to open a device and create a link. Can be * used multiple times for the same device (the library will keep track).*/ int vxi11_open_device(VXI11_CLINK **clink, const char *address, char *device) +{ + return vxi11_open_device_clients(clink, address, device, &VXI11_CLIENTS); +} + +int vxi11_open_device_clients(VXI11_CLINK **clink, const char *address, char *device, vxi11_client_t **clients) { #ifdef WIN32 ViStatus status; char buf[256]; #else int ret; - struct _vxi11_client_t *tail, *client = NULL; + vxi11_client_t *tail, *client = NULL; #endif char default_device[6] = "inst0"; char *use_device; @@ -141,7 +137,7 @@ int vxi11_open_device(VXI11_CLINK **clink, const char *address, char *device) #else /* Have a look to see if we've already initialised an instrument with * this address */ - tail = VXI11_CLIENTS; + tail = *clients; while (tail) { if (strcmp(address, tail->address) == 0) { client = tail; @@ -156,7 +152,7 @@ int vxi11_open_device(VXI11_CLINK **clink, const char *address, char *device) * is, for this address. Because it's a new client, this * must be link number 1. Keep track of how many devices we've * opened so we don't run out of storage space. */ - client = (struct _vxi11_client_t *)calloc(1, sizeof(struct _vxi11_client_t)); + client = (vxi11_client_t *)calloc(1, sizeof(vxi11_client_t)); if (!client) { free(*clink); *clink = NULL; @@ -186,8 +182,8 @@ int vxi11_open_device(VXI11_CLINK **clink, const char *address, char *device) strncpy(client->address, address, 20); client->client_address = (*clink)->client; client->link_count = 1; - client->next = VXI11_CLIENTS; - VXI11_CLIENTS = client; + client->next = *clients; + *clients = client; } else { /* Copy the client pointer address. Just establish a new link * not a new client). Add one to the link count */ @@ -205,16 +201,21 @@ int vxi11_open_device(VXI11_CLINK **clink, const char *address, char *device) /* Use this function from user land to close a device and/or sever a link. Can * be used multiple times for the same device (the library will keep track).*/ int vxi11_close_device(VXI11_CLINK * clink, const char *address) +{ + return vxi11_close_device_clients(clink, address, &VXI11_CLIENTS); +} + +int vxi11_close_device_clients(VXI11_CLINK * clink, const char *address, vxi11_client_t **clients) { int ret = 0; #ifdef WIN32 viClose(clink->session); viClose(clink->rm); #else - struct _vxi11_client_t *tail, *last = NULL, *client = NULL; + vxi11_client_t *tail, *last = NULL, *client = NULL; /* Which instrument are we referring to? */ - tail = VXI11_CLIENTS; + tail = *clients; while (tail) { if (strncmp(address, tail->address, 20) == 0) { client = tail; @@ -245,7 +246,7 @@ int vxi11_close_device(VXI11_CLINK * clink, const char *address) if (last) { last->next = client->next; } else { - VXI11_CLIENTS = client->next; + *clients = client->next; } } } diff --git a/library/vxi11_user.h b/library/vxi11_user.h index 1a2e042..84fcc79 100644 --- a/library/vxi11_user.h +++ b/library/vxi11_user.h @@ -41,10 +41,11 @@ extern "C" { #endif #include +#include #define LIBVXI11_MAJOR 2 -#define LIBVXI11_MINOR 0 +#define LIBVXI11_MINOR 1 #define LIBVXI11_REVISION 0 /* LIBVXI11_VERSION_NUMBER looks like 2002001 for e.g. version 2.2.1. */ #define LIBVXI11_VERSION_NUMBER (LIBVXI11_MAJOR*1000000+LIBVXI11_MINOR*1000+LIBVXI11_REVISION) @@ -65,6 +66,15 @@ typedef struct _VXI11_CLINK VXI11_CLINK; /* vxi11_send() return value if a sent command times out ON THE INSTRUMENT. */ #define VXI11_NULL_WRITE_RESP 51 +/* client list stucture */ +typedef struct _vxi11_client_t { + struct _vxi11_client_t *next; + char address[20]; +#ifndef WIN32 + CLIENT *client_address; +#endif + int link_count; +} vxi11_client_t; /* Function: vxi11_library_version * @@ -105,6 +115,27 @@ vx_EXPORT int vxi11_lib_version(int *major, int *minor, int *revision); vx_EXPORT int vxi11_open_device(VXI11_CLINK **clink, const char *address, char *device); +/* Function: vxi11_open_device_clients + * + * Open a connection to an instrument. + * + * Parameters: + * clink - pointer to a VXI11_CLINK pointer, will be initialised on a + * successful connection. + * address - the IP address or (where supported) USB address for the + * instrument to connect to. + * device - some instruments have multiple interfaces, this allows you to + * specify which to connect to. Set to NULL to use the default of + * "inst0". + * clients - pointer to a vxi11_clients structure + * + * Returns: + * 0 - on success + * 1 - on failure. clink will not be a valid pointer. + */ +vx_EXPORT int vxi11_open_device_clients(VXI11_CLINK **clink, const char *address, char *device, vxi11_client_t **clients); + + /* Function: vxi11_close_device * * Parameters: @@ -118,6 +149,20 @@ vx_EXPORT int vxi11_open_device(VXI11_CLINK **clink, const char *address, char * vx_EXPORT int vxi11_close_device(VXI11_CLINK *clink, const char *address); +/* Function: vxi11_close_device_clients + * + * Parameters: + * clink - a valid VXI11_CLINK pointer. + * address - the IP address or (where supported) USB address for the + * instrument. + * clients - pointer to a vxi11_clients structure + * + * Returns: + * 0 - on success + */ +vx_EXPORT int vxi11_close_device_clients(VXI11_CLINK *clink, const char *address, vxi11_client_t **clients); + + /* Function: vxi11_send * * Send data to an instrument. diff --git a/utils/Makefile b/utils/Makefile index d73a8f7..c30f067 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -3,19 +3,14 @@ include ../config.mk .PHONY : all install clean CFLAGS:=${CFLAGS} -I../library +LDFLAGS:=${LDFLAGS} -L../library -lvxi11 all : vxi11_cmd vxi11_send -vxi11_cmd: vxi11_cmd.o ../library/libvxi11.so.${SOVERSION} +vxi11_cmd vxi11_send: %: %.o $(CC) -o $@ $^ $(LDFLAGS) -vxi11_cmd.o: vxi11_cmd.c ../library/vxi11_user.c ../library/vxi11.h - $(CC) $(CFLAGS) -c $< -o $@ - -vxi11_send: vxi11_send.o ../library/libvxi11.so.${SOVERSION} - $(CC) -o $@ $^ $(LDFLAGS) - -vxi11_send.o: vxi11_send.c ../library/vxi11_user.c ../library/vxi11.h +%.o: %.c $(CC) $(CFLAGS) -c $< -o $@ clean: