Debian Codegraph @

apps/ctnnetwork/ctnnetwork.c

raw ◀ ▶
Source reconstructed at patch state 0 of 3 — not the installed (fully patched) source.
3 Debian patches touch this file
1 /*
2 Copyright (C) 1993, 1994, RSNA and Washington University
3
4 The software and supporting documentation for the Radiological
5 Society of North America (RSNA) 1993, 1994 Digital Imaging and
6 Communications in Medicine (DICOM) Demonstration were developed
7 at the
8 Electronic Radiology Laboratory
9 Mallinckrodt Institute of Radiology
10 Washington University School of Medicine
11 510 S. Kingshighway Blvd.
12 St. Louis, MO 63110
13 as part of the 1993, 1994 DICOM Central Test Node project for, and
14 under contract with, the Radiological Society of North America.
15
16 THIS SOFTWARE IS MADE AVAILABLE, AS IS, AND NEITHER RSNA NOR
17 WASHINGTON UNIVERSITY MAKE ANY WARRANTY ABOUT THE SOFTWARE, ITS
18 PERFORMANCE, ITS MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR
19 USE, FREEDOM FROM ANY COMPUTER DISEASES OR ITS CONFORMITY TO ANY
20 SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND PERFORMANCE OF
21 THE SOFTWARE IS WITH THE USER.
22
23 Copyright of the software and supporting documentation is
24 jointly owned by RSNA and Washington University, and free access
25 is hereby granted as a license to use this software, copy this
26 software and prepare derivative works based upon this software.
27 However, any distribution of this software source code or
28 supporting documentation or derivative works (source code and
29 supporting documentation) must include the three paragraphs of
30 the copyright notice.
31 */
32 /* Copyright marker. Copyright will be inserted above. Do not remove */
33 /*
34 ** DICOM 93
35 ** Electronic Radiology Laboratory
36 ** Mallinckrodt Institute of Radiology
37 ** Washington University School of Medicine
38 **
39 ** Module Name(s): ctnnetwork (main()), UpdateSlot, ReleaseSlot,
40 ** FindSlot, GetUnusedSlot, CTNNETWORK_CheckStatus
41 ** Author, Date: David E. Beecher, 7-Jul-93
42 ** Intent: A simple network monitor for CTN's
43 ** Last Update: $Author: smm $, $Date: 1999-11-02 21:22:35 $
44 ** Source File: $RCSfile: ctnnetwork.c,v $
45 ** Revision: $Revision: 1.26 $
46 ** Status: $State: Exp $
47 */
48
49 static char rcsid[] = "$Revision: 1.26 $ $RCSfile: ctnnetwork.c,v $";
50
51 #include <stdio.h>
52 #include <stdlib.h>
53 #include <math.h>
54 #ifdef X11
55 #include <X11/Xlib.h>
56 #include <X11/Xutil.h>
57 #include <X11/Xos.h>
58 #include <X11/Xatom.h>
59
60 #include "dicom.h"
61 #include "ctnthread.h"
62 #include "condition.h"
63 #include "lst.h"
64 #include "dicom_objects.h"
65 #include "iqueues.h"
66 #include "gq.h"
67 #include "ctnnetwork.h"
68
69 #define SLEEP_TIME ((unsigned) 100000)
70
71 char *CTNNETWORK_usage = "CTNNETWORK Usage: ctnnetwork -q queue_number -n number_to_display [-w display_width -h display_height]\n";
72 /*
73 * Globals (preceded with G_)...declared extern in other files
74 */
75 Window G_big_window;
76
77 Display *G_display; /* Xstuff used all over... */
78
79 Colormap G_cmap;
80
81 GC G_gclargeT, /* Graphics contexts needed... */
82 G_gcgreen;
83
84 int G_display_width,
85 G_display_height, /* Well know screen stuff... */
86 G_screen;
87
88 char G_nodename[MAX_STRING_LENGTH];
89 char G_dpnname[MAX_STRING_LENGTH];
90
91 CTNNETWORK_Queue
92 *G_Array;
93 int
94 G_Number,
95 *G_Used;
96
97 /*
98 * End Globals...
99 */
100
101 static void
102 CTNNETWORK_CheckStatus();
103 static void
104 ReleaseSlot(CTNNETWORK_Queue *element);
105 static void
106 UpdateSlot(int index, CTNNETWORK_Queue *element);
107
108 /*******************************************************************/
109 main(int argc, char **argv)
110 {
111 CONDITION
112 retval;
113 CTNNETWORK_Queue
114 element;
115 int
116 i,
117 QueueElementSize,
118 diag_level,
119 image_Q_id = 0;
120
121 int
122 slot;
123
124 THR_Init();
125 QueueElementSize = sizeof(CTNNETWORK_Queue);
126
127 /*
128 * Get the input paramaters from command line
129 */
130 if (argc < 3) {
131 COND_PushCondition(CTNNETWORK_CMDLINE, "%s", CTNNETWORK_usage);
132 COND_DumpConditions();
133 exit(-1);
134 }
135 G_display_width = G_display_height = -1;
136 G_Number = 0;
137 argc--;
138 argv++;
139 while (argc > 0) {
140 if ((strcmp(*argv, "-q")) == 0) {
141 argc--;
142 argv++;
143 image_Q_id = atoi(*argv);
144 if (image_Q_id < 0) {
145 COND_PushCondition(CTNNETWORK_CMDLINE,
146 "CTNNETWORK: Queue number must > 0");
147 COND_DumpConditions();
148 exit(-1);
149 }
150 argc--;
151 argv++;
152 } else if ((strcmp(*argv, "-w")) == 0) {
153 argc--;
154 argv++;
155 G_display_width = atoi(*argv);
156 if (G_display_width < MIN_DISPLAY_WIDTH) {
157 COND_PushCondition(CTNNETWORK_CMDLINE,
158 "CTNNETWORK: Display width must be > MIN_DISPLAY_WIDTH");
159 COND_DumpConditions();
160 exit(-1);
161 }
162 argc--;
163 argv++;
164 } else if ((strcmp(*argv, "-h")) == 0) {
165 argc--;
166 argv++;
167 G_display_height = atoi(*argv);
168 if (G_display_height < MIN_DISPLAY_HEIGHT) {
169 COND_PushCondition(CTNNETWORK_CMDLINE,
170 "CTNNETWORK: Display height must be > MIN_DISPLAY_HEIGHT");
171 COND_DumpConditions();
172 exit(-1);
173 }
174 argc--;
175 argv++;
176 } else if ((strcmp(*argv, "-n")) == 0) {
177 argc--;
178 argv++;
179 strcpy(G_nodename, *argv);
180 G_Number = atoi(*argv);
181 argc--;
182 argv++;
183 } else {
184 COND_PushCondition(CTNNETWORK_CMDLINE, CTNNETWORK_usage);
185 COND_DumpConditions();
186 exit(-1);
187 }
188 }
189 if (G_Number < 1) {
190 G_Number = 10;
191 }
192 if ((G_Array = (CTNNETWORK_Queue *) malloc(G_Number * QueueElementSize)) ==
193 (CTNNETWORK_Queue *) NULL) {
194 COND_PushCondition(CTNNETWORK_NOMEMORY,
195 "CTNNETWORK: Can't allocate local memory for list");
196 COND_DumpConditions();
197 exit(-1);
198 }
199 if ((G_Used = (int *) malloc(G_Number * sizeof(int))) == (int *) NULL) {
200 COND_PushCondition(CTNNETWORK_NOMEMORY,
201 "CTNNETWORK: Can't allocate local memory for list");
202 COND_DumpConditions();
203 exit(-1);
204 }
205 for (i = 0; i < G_Number; i++) { /* Set all the slots to open */
206 G_Used[i] = 0;
207 }
208
209 /*
210 * Initialize the Generalized Queue for images and status messages
211 */
212 if (GQ_GetQueue(image_Q_id, QueueElementSize) != GQ_NORMAL) {
213 if ((GQ_InitQueue(image_Q_id, QUEUE_SIZE, QueueElementSize)) != GQ_NORMAL) {
214 COND_PushCondition(CTNNETWORK_NOGQ,
215 "CTNNETWORK: Not able to acess Image Queue.");
216 COND_DumpConditions();
217 exit(-1);
218 }
219 if (GQ_GetQueue(image_Q_id, QueueElementSize) != GQ_NORMAL) {
220 COND_PushCondition(CTNNETWORK_NOGQ,
221 "CTNNETWORK: Not able to get Image Queue.");
222 COND_DumpConditions();
223 exit(-1);
224 }
225 }
226 /*
227 * Initialize the X stuff, and create the graphics contexts
228 */
229 if ((CTNNETWORK_InitializeX()) != CTNNETWORK_NORMAL) {
230 COND_PushCondition(CTNNETWORK_NOXWINDOWS,
231 "CTNNETWORK: No Connection to X-Server.");
232 (void) GQ_KillQueue(image_Q_id);
233 COND_DumpConditions();
234 exit(-1);
235 }
236 /*
237 * Display node name and the status buttons...
238 */
239 CTNNETWORK_CreateNetworkWindow();
240
241 /*
242 * Main Control loop for ctnnetwork
243 */
244 retval = GQ_Dequeue(image_Q_id, (void *) &element);
245 strcpy(G_nodename, element.vendorid);
246 strcpy(G_dpnname, element.dpnid);
247 while (strcmp(element.vendorid, KILL_DISPLAY) != 0) {
248 while (retval == GQ_NORMAL) {
249 switch (element.connection) {
250 case CONN_INOPEN:
251 case CONN_OUTOPEN:
252 slot = GetUnusedSlot(&element);
253 CTNNETWORK_OpenConnection(slot);
254 break;
255 case CONN_INXFER:
256 case CONN_OUTXFER:
257 slot = FindSlot(&element);
258 UpdateSlot(slot, &element);
259 CTNNETWORK_ShowPercentage(slot);
260 break;
261 case CONN_INCLOSE:
262 case CONN_OUTCLOSE:
263 slot = FindSlot(&element);
264 UpdateSlot(slot, &element);
265 CTNNETWORK_CloseConnection(slot);
266 ReleaseSlot(&element);
267 break;
268 case CONN_INDISPLAY:
269 case CONN_OUTDISPLAY:
270 default:
271 break;
272 }
273 retval = GQ_Dequeue(image_Q_id, (void *) &element);
274 }
275 #ifdef IRIX
276 (void) sginap(6);
277 #elif defined(USLEEP)
278 (void) usleep(SLEEP_TIME);
279 #else
280 (void) sleep(1);
281 #endif
282 retval = GQ_Dequeue(image_Q_id, (void *) &element);
283 strcpy(G_dpnname, element.dpnid);
284 strcpy(G_nodename, element.vendorid);
285
286 CTNNETWORK_CheckStatus();
287 (void)COND_PopCondition(TRUE);
288 }
289 THR_Shutdown();
290 return 0;
291 }
292
293
294
295 /*******************************************************************/
296 static void
297 CTNNETWORK_CheckStatus()
298 {
299
300 CTNNETWORK_Queue
301 element;
302
303 XEvent
304 report;
305
306 unsigned long
307 mask_event;
308
309 CONDITION
310 val;
311
312 /*
313 * Check for X events that require redrawing the screen...
314 */
315 mask_event = StructureNotifyMask | SubstructureNotifyMask | ExposureMask;
316 while (XCheckMaskEvent(G_display, mask_event, &report) == True) {
317
318 CTNNETWORK_RefreshStatus();
319 }
320
321 return;
322 }
323
324 int
325 GetUnusedSlot(CTNNETWORK_Queue *element)
326 {
327
328 int
329 i;
330
331 for (i = 0; i < G_Number; i++) {
332 if (G_Used[i] == 0) {
333 G_Used[i] = 1;
334 strcpy(G_Array[i].vendorid, element->vendorid);
335 strcpy(G_Array[i].dpnid, element->dpnid);
336 G_Array[i].association_id = element->association_id;
337 G_Array[i].connection = element->connection;
338 G_Array[i].percentage = element->percentage;
339 return (i);
340 }
341 }
342 return (-1);
343 }
344
345 int
346 FindSlot(CTNNETWORK_Queue *element)
347 {
348
349 int
350 i;
351
352 for (i = 0; i < G_Number; i++) {
353 if (G_Used[i] == 1) {
354 if (G_Array[i].association_id == element->association_id) {
355 return (i);
356 }
357 }
358 }
359 return (-1);
360 }
361
362 static void
363 ReleaseSlot(CTNNETWORK_Queue *element)
364 {
365
366 int
367 i;
368
369 for (i = 0; i < G_Number; i++) {
370 if (G_Used[i] == 1) {
371 if (G_Array[i].association_id == element->association_id) {
372 G_Used[i] = 0;
373 return;
374 }
375 }
376 }
377 return;
378 }
379 /*lint -e578*/
380
381 static void
382 UpdateSlot(int index, CTNNETWORK_Queue *element)
383 {
384
385
386 if (index < 0 || index > G_Number)
387 return;
388 strcpy(G_Array[index].vendorid, element->vendorid);
389 strcpy(G_Array[index].dpnid, element->dpnid);
390 G_Array[index].association_id = element->association_id;
391 G_Array[index].connection = element->connection;
392 G_Array[index].percentage = element->percentage;
393 return;
394 }
395 /*lint +e578*/
396
397 #else
398
399 main()
400 {
401 fprintf(stderr, "ctnnetwork requires the X Window System\n");
402 fprintf(stderr, "This version was compiled without the proper MACRO\n");
403 fprintf(stderr, "defined to use X11. Please refer to the source code\n");
404 fprintf(stderr, "(and recompile) to use this application\n");
405 }
406 #endif