Changeset 13354
- Timestamp:
- May 11, 2007, 9:41:26 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/kapa-mods-2007-05/Ohana/src/opihi/lib.data/open_kapa.c
r13345 r13354 9 9 10 10 /* list of available socket connections */ 11 static int Active; // currently active socket (not device)11 static int Active; // currently active socket entry (index value, not socket value) 12 12 static int *Socket = NULL; // list of available sockets 13 static int *Device = NULL; // list of device numbers for each socked14 static int N socket= 0; // number of available sockets / devices13 static char **Device = NULL; // list of device names for each socket 14 static int Ndevice = 0; // number of available sockets / devices 15 15 16 16 void InitKapa () { 17 17 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 25 int 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 41 int 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 60 int FindKapaDevice (char *name) { 28 61 29 62 int i; 30 63 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); 35 66 } 36 67 return (-1); 37 68 } 38 69 39 // set the active device to the given device number, open if needed40 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 71 int open_kapa (int entry) { 72 73 int fd; 74 char *kapa_exec, *kapa_name; 44 75 45 76 // 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); 57 79 58 80 // if the (now) active socket is not open, open it 59 if (Socket[ Active] < 0) {81 if (Socket[entry] < 0) { 60 82 kapa_exec = get_variable ("KAPA"); 61 83 if (kapa_exec == (char *) NULL) { … … 65 87 66 88 // 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); 70 92 free (kapa_exec); 93 free (kapa_name); 71 94 72 95 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]); 75 97 return (FALSE); 76 98 } 77 Device[Active] = thisDevice; 78 Socket[Active] = fd; 99 Socket[entry] = fd; 79 100 } 101 Active = entry; 80 102 return (TRUE); 81 103 } 82 104 83 105 /**************** graph ops */ 84 85 106 // XXX for now, use a local variable. later: get from kapa 86 107 static Graphdata graphdata; … … 117 138 # endif 118 139 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 143 int GetGraph (Graphdata *data, int *fd, char *name) { 144 145 int entry; 123 146 124 147 SetImageDevice (FALSE); 125 if ( dev== NULL) {148 if (name == NULL) { 126 149 if (Active < 0) { 127 thisDevice = 0;150 entry = AddKapaDevice ("0"); 128 151 } else { 129 thisDevice = Device[Active];152 entry = Active; 130 153 } 131 154 } else { 132 thisDevice = *dev;155 entry = AddKapaDevice (name); 133 156 } 134 157 135 if (!open_kapa ( thisDevice)) {158 if (!open_kapa (entry)) { 136 159 return (FALSE); 137 160 } … … 144 167 145 168 /* 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) {169 int GetGraphData (Graphdata *data, int *fd, char *name) { 170 171 int entry; 172 173 if (name == NULL) { 151 174 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]; 168 188 if (data != NULL) *data = graphdata; 169 170 189 return (TRUE); 171 190 } … … 202 221 203 222 /* return pointers for current Ximage, set if desired, test, open if needed */ 204 int GetImage (int *fd, int *N) {223 int GetImage (int *fd, char *name) { 205 224 int status; 206 status = GetGraph (NULL, fd, N);225 status = GetGraph (NULL, fd, name); 207 226 return (status); 208 227 }
Note:
See TracChangeset
for help on using the changeset viewer.
