IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 16, 2006, 10:58:49 PM (20 years ago)
Author:
eugene
Message:

major updates to use gprint for buffered / threaded printing

Location:
trunk/Ohana/src/libohana
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/libohana/include/ohana.h

    r7039 r7917  
    166166int EmptyIOBuffer (IOBuffer *buffer, int Nmax, int fd);
    167167void FreeIOBuffer (IOBuffer *buffer);
     168int PrintIOBuffer (IOBuffer *buffer, char *format, ...);
     169int vPrintIOBuffer (IOBuffer *buffer, char *format, va_list argp);
    168170
    169171/* communication functions */
     
    173175int SendCommand (int device, int length, char *format, ...);
    174176int SendCommandV (int device, int length, char *format, va_list argp);
     177
     178char *CheckForMessage (IOBuffer *buffer);
    175179
    176180/*
  • trunk/Ohana/src/libohana/src/CommOps.c

    r5273 r7917  
    113113  return (TRUE);
    114114}
     115
     116/*
     117
     118 I need an alternative ExpectCommand function which appends to an existing buffer
     119 until the complete message is ready. 
     120
     121 A command looks like this (pre-determined length):
     122 NN bytes: XXXXX\0
     123
     124 A message looks like this (preceded by NBYTES command) :
     125 16 bytes: WORD NNN\0
     126 NNN bytes: message.... \0
     127
     128 the expect function needs to monitor the number of bytes already received
     129 we need to be able to call it repeatedly until the buffer is full.
     130
     131*/
     132
     133/* check if the first entry in the buffer corresponds to a message:
     134   A message looks like this (preceded by NBYTES command) :
     135    16 bytes: WORD NNN
     136    NNN bytes: message....
     137    note that the NULL bytes are not sent
     138  If a message is found, it is popped off the buffer and sent back as a
     139  complete line (the length portion is dropped)
     140*/
     141
     142char *CheckForMessage (IOBuffer *buffer) {
     143
     144  int Nbytes;
     145  char command[20], *line;
     146
     147  if (buffer[0].Nbuffer < 16) return NULL;
     148  memcpy (command, buffer[0].buffer, 16);
     149  command[16] = 0;
     150
     151  sscanf (command, "NBYTES: %d", &Nbytes);
     152
     153  if (buffer[0].Nbuffer < Nbytes + 16) return NULL;
     154
     155  ALLOCATE (line, char, Nbytes + 1);
     156  memcpy (line, &buffer[0].buffer[16], Nbytes);
     157  line[Nbytes] = 0;
     158
     159  buffer[0].Nbuffer -= Nbytes + 16;
     160  memmove (buffer[0].buffer, &buffer[0].buffer[Nbytes+16], buffer[0].Nbuffer);
     161  return (line);
     162}
  • trunk/Ohana/src/libohana/src/IOBufferOps.c

    r5273 r7917  
    8484  }
    8585}
     86
     87/* print to an IOBuffer (varargs form) */
     88int PrintIOBuffer (IOBuffer *buffer, char *format, ...) {
     89
     90  int status;
     91  va_list argp; 
     92
     93  va_start (argp, format);
     94  status = vPrintIOBuffer (buffer, format, argp);
     95  va_end (argp);
     96  return (status);
     97}
     98
     99/* print to an IOBuffer (va_list form) */
     100int vPrintIOBuffer (IOBuffer *buffer, char *format, va_list argp) {
     101
     102  /* add the output line to the given IOBuffer */
     103 
     104  int Nbyte, status;
     105  char tmp, *line;
     106
     107  Nbyte = vsnprintf (&tmp, 0, format, argp);
     108
     109  if (buffer[0].Nbuffer + Nbyte + 1 >= buffer[0].Nalloc) {
     110    buffer[0].Nalloc = buffer[0].Nbuffer + Nbyte + 64;
     111    REALLOCATE (buffer[0].buffer, char, buffer[0].Nalloc);
     112  }
     113
     114  vsnprintf (&buffer[0].buffer[buffer[0].Nbuffer], Nbyte + 1, format, argp);
     115  buffer[0].Nbuffer += Nbyte + 1;
     116  return (TRUE);
     117}
     118 
Note: See TracChangeset for help on using the changeset viewer.