Cleaned up ANSTO code to merge with sinqdev.sics
This is our new RELEASE-4_0 branch which was taken from ansto/93d9a7c Conflicts: .gitignore SICSmain.c asynnet.c confvirtualmot.c counter.c devexec.c drive.c event.h exebuf.c exeman.c histmem.c interface.h motor.c motorlist.c motorsec.c multicounter.c napi.c napi.h napi4.c network.c nwatch.c nxscript.c nxxml.c nxxml.h ofac.c reflist.c scan.c sicshipadaba.c sicsobj.c site_ansto/docs/Copyright.txt site_ansto/instrument/lyrebird/config/tasmad/sicscommon/nxsupport.tcl site_ansto/instrument/lyrebird/config/tasmad/taspub_sics/tasscript.tcl statusfile.c tasdrive.c tasub.c tasub.h tasublib.c tasublib.h
This commit is contained in:
55
rwpuffer.c
55
rwpuffer.c
@@ -4,6 +4,11 @@
|
||||
* copyright: see file COPYRIGHT
|
||||
*
|
||||
* Mark Koennecke, January 2009
|
||||
*
|
||||
* added resizing option and MakeBigRWPuffer in order to support transfer
|
||||
* of large amounts of image data on few connections
|
||||
*
|
||||
* Mark Koennecke, August 2014
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -15,6 +20,7 @@ typedef struct __RWBuffer {
|
||||
int length;
|
||||
int startPtr;
|
||||
int endPtr;
|
||||
int maxSize;
|
||||
} RWBuffer;
|
||||
/*----------------------------------------------------------------------*/
|
||||
prwBuffer MakeRWPuffer(int size)
|
||||
@@ -32,9 +38,18 @@ prwBuffer MakeRWPuffer(int size)
|
||||
self->length = size;
|
||||
self->startPtr = 0;
|
||||
self->endPtr = 0;
|
||||
self->maxSize = size;
|
||||
return self;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
prwBuffer MakeBigRWPuffer(int size, int maxSize)
|
||||
{
|
||||
prwBuffer result = MakeRWPuffer(size);
|
||||
if(result != NULL){
|
||||
result->maxSize = maxSize;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/*------------------------------------------------------------------------*/
|
||||
void KillRWBuffer(prwBuffer self)
|
||||
{
|
||||
@@ -46,16 +61,51 @@ void KillRWBuffer(prwBuffer self)
|
||||
}
|
||||
free(self);
|
||||
}
|
||||
/*------------------------------------------------------------------------*/
|
||||
int CanStoreRWBuffer(prwBuffer self, void *data, int count)
|
||||
{
|
||||
int length;
|
||||
char *ptr;
|
||||
|
||||
length = self->endPtr - self->startPtr;
|
||||
if (count + length >= self->length ) {
|
||||
if(self->length < self->maxSize){
|
||||
ptr = calloc(self->maxSize,sizeof(char));
|
||||
if(ptr == NULL) {
|
||||
return 0;
|
||||
}
|
||||
memcpy(ptr,self->data, length*sizeof(char));
|
||||
free(self->data);
|
||||
self->data = ptr;
|
||||
self->length = self->maxSize;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
/*------------------------------------------------------------------------*/
|
||||
int StoreRWBuffer(prwBuffer self, void *data, int count)
|
||||
{
|
||||
int length;
|
||||
char *ptr;
|
||||
|
||||
length = self->endPtr - self->startPtr;
|
||||
if (count + length >= self->length ) {
|
||||
if(self->length < self->maxSize){
|
||||
ptr = calloc(self->maxSize,sizeof(char));
|
||||
if(ptr == NULL) {
|
||||
printf("HELP: RWBuffer overrun!!!!\n");
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
memcpy(ptr,self->data, length*sizeof(char));
|
||||
free(self->data);
|
||||
self->data = ptr;
|
||||
self->length = self->maxSize;
|
||||
} else {
|
||||
printf("HELP: RWBuffer overrun!!!!\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (count + self->endPtr > self->length) {
|
||||
memmove(self->data, self->data + self->startPtr, length);
|
||||
@@ -81,5 +131,6 @@ void RemoveRWBufferData(prwBuffer self, int count)
|
||||
if (self->startPtr >= self->endPtr) {
|
||||
self->startPtr = 0;
|
||||
self->endPtr = 0;
|
||||
memset(self->data,0,self->length*sizeof(char));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user