IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13354


Ignore:
Timestamp:
May 11, 2007, 9:41:26 AM (19 years ago)
Author:
eugene
Message:

fixing default values, converting to char device names

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/kapa-mods-2007-05/Ohana/src/opihi/lib.data/open_kapa.c

    r13345 r13354  
    99
    1010/* list of available socket connections */
    11 static int        Active;        // currently active socket (not device)
     11static int        Active;        // currently active socket entry (index value, not socket value)
    1212static int       *Socket = NULL; // list of available sockets
    13 static int       *Device = NULL; // list of device numbers for each socked
    14 static int       Nsocket = 0;    // number of available sockets / devices
     13static char     **Device = NULL; // list of device names for each socket
     14static int       Ndevice = 0;    // number of available sockets / devices
    1515
    1616void InitKapa () {
    1717
    18   Active  = -1;               // -1 is the INVALID entry
    19   Nsocket = 0;                // number of defined sockets
    20   ALLOCATE (Device, int, 1);
    21   ALLOCATE (Socket, int, 1);
    22   Device[Active] = 0; 
    23   Socket[Active] = 0; 
    24 }
    25 
    26 // returns the number of the requested device, or -1 if not found
    27 int FindKapaDevice (int thisDevice) {
     18  Active  = -1;                                   // -1 is the INVALID entry
     19  Ndevice = 0;                                    // number of defined sockets
     20  ALLOCATE (Device, char *, 1);                   // for future REALLOCATE calls
     21  ALLOCATE (Socket, int, 1);                      // for future REALLOCATE calls
     22}
     23
     24// add new device name if not found
     25int AddKapaDevice (char *name) {
     26
     27  int N;
     28
     29  N = FindKapaDevice (name);
     30  if (N != -1) return (N);
     31  N = Ndevice;
     32  Ndevice ++;
     33  REALLOCATE (Device, char *, Ndevice);
     34  REALLOCATE (Socket, int, Ndevice);
     35  Device[N] = strcreate (name);
     36  Socket[N] = -1;
     37  return (N);
     38}
     39
     40// delete device by name, close if not closed
     41int DelKapaDevice (char *name) {
     42
     43  int N;
     44
     45  N = FindKapaDevice (name);
     46  if (N == -1) return (FALSE);
     47  if (Socket[N] != -1) close (Socket[N]);
     48  free (Device[N]);
     49  for (i = N; i < Ndevice - 1; i++) {
     50    Device[N] = Device[N+1];
     51    Socket[N] = Socket[N+1];
     52  }
     53  Ndevice --;
     54  REALLOCATE (Device, char *, Ndevice);
     55  REALLOCATE (Socket, int, Ndevice);
     56  return (TRUE);
     57}
     58
     59// returns the entry of the requested device, or -1 if not found
     60int FindKapaDevice (char *name) {
    2861
    2962  int i;
    3063
    31   for (i = 0; i < Nsocket; i++) {
    32     if (Device[i] == thisDevice) {
    33       return (i);
    34     }
     64  for (i = 0; i < Ndevice; i++) {
     65    if (!strcmp(Device[i], name)) return (i);
    3566  }
    3667  return (-1);
    3768}
    3869
    39 // set the active device to the given device number, open if needed
    40 int open_kapa (int thisDevice) {
    41 
    42   int fd, entry;
    43   char *kapa_exec, name[16];
     70// set the active device to the given device, open if needed
     71int open_kapa (int entry) {
     72
     73  int fd;
     74  char *kapa_exec, *kapa_name;
    4475
    4576  // find the given device number, or create. set this to active
    46   entry = FindKapaDevice (thisDevice);
    47   if (entry < 0) {
    48     Active = Nsocket;
    49     Nsocket ++;
    50     REALLOCATE (Device, int, Nsocket);
    51     REALLOCATE (Socket, int, Nsocket);
    52     Device[Active] = -1;
    53     Socket[Active] = -1;
    54   } else {
    55     Active = entry;
    56   }
     77  assert (entry > 0);
     78  assert (entry < Ndevice);
    5779
    5880  // if the (now) active socket is not open, open it
    59   if (Socket[Active] < 0) {
     81  if (Socket[entry] < 0) {
    6082    kapa_exec = get_variable ("KAPA");
    6183    if (kapa_exec == (char *) NULL) {
     
    6587
    6688    // KAPA may be either kapa://host or /path/to/program
    67 
    68     snprintf (name, 16, "[%d]", thisDevice);
    69     fd = KapaOpen (kapa_exec, name);
     89    ALLOCATE (kapa_name, char, strlen(Device[entry]) + 5);
     90    snprintf (kapa_name, strlen(Device[entry]) + 5, "[%s]", Device[entry]);
     91    fd = KapaOpen (kapa_exec, kapa_name);
    7092    free (kapa_exec);
     93    free (kapa_name);
    7194
    7295    if (fd < 0) {
    73       gprint (GP_ERR, "error starting kapa\n");
    74       // delete the active entry
     96      gprint (GP_ERR, "error starting kapa device %s\n", Device[entry]);
    7597      return (FALSE);
    7698    }
    77     Device[Active] = thisDevice;
    78     Socket[Active] = fd;
     99    Socket[entry] = fd;
    79100  }
     101  Active = entry;
    80102  return (TRUE);
    81103}
    82104
    83105/**************** graph ops */
    84 
    85106// XXX for now, use a local variable.  later: get from kapa
    86107static Graphdata graphdata;
     
    117138# endif
    118139
    119 /* return pointers for current Xgraph, set if desired, test, open if needed */
    120 int GetGraph (Graphdata *data, int *fd, int *dev) {
    121 
    122   int thisDevice;
     140/* return pointers for named device or current; open if needed */
     141// if fd == NULL, don't return the value
     142// if name == NULL, use the currently active device
     143int GetGraph (Graphdata *data, int *fd, char *name) {
     144
     145  int entry;
    123146
    124147  SetImageDevice (FALSE);
    125   if (dev == NULL) {
     148  if (name == NULL) {
    126149    if (Active < 0) {
    127       thisDevice = 0;
     150      entry = AddKapaDevice ("0");
    128151    } else {
    129       thisDevice = Device[Active];
     152      entry = Active;
    130153    }
    131154  } else {
    132     thisDevice = *dev;
     155    entry = AddKapaDevice (name);
    133156  }
    134157 
    135   if (!open_kapa (thisDevice)) {
     158  if (!open_kapa (entry)) {
    136159    return (FALSE);
    137160  }
     
    144167
    145168/* return pointers for given Xgraph, don't set or open */
    146 int GetGraphData (Graphdata *data, int *fd, int *dev) {
    147 
    148   int n;
    149 
    150   if (dev == NULL) {
     169int GetGraphData (Graphdata *data, int *fd, char *name) {
     170
     171  int entry;
     172
     173  if (name == NULL) {
    151174    if (Active < 0) {
    152       gprint (GP_ERR, "invalid Xgraph window %d\n", *dev);
    153       return (FALSE);
    154     }
    155     *fd = Socket[Active];
    156     return (TRUE);
    157   }
    158 
    159   n = FindKapaDevice (*dev);
    160   if (n < 0) {
    161     gprint (GP_ERR, "invalid Xgraph window %d\n", *dev);
    162     return (FALSE);
    163   }
    164 
    165   Active = n;
    166 
    167   if (fd != NULL) *fd = Socket[Active];
     175      gprint (GP_ERR, "no active kapa window\n");
     176      return (FALSE);
     177    }
     178    entry = Active
     179  } else {
     180    entry = FindKapaDevice (name);
     181    if (entry < 0) {
     182      gprint (GP_ERR, "invalid kapa window %s\n", name);
     183      return (FALSE);
     184    }
     185  }
     186
     187  if (fd != NULL) *fd = Socket[entry];
    168188  if (data != NULL) *data = graphdata;
    169 
    170189  return (TRUE);
    171190}
     
    202221
    203222/* return pointers for current Ximage, set if desired, test, open if needed */
    204 int GetImage (int *fd, int *N) {
     223int GetImage (int *fd, char *name) {
    205224  int status;
    206   status = GetGraph (NULL, fd, N);
     225  status = GetGraph (NULL, fd, name);
    207226  return (status);
    208227}
Note: See TracChangeset for help on using the changeset viewer.