source: trunk/FACT++/dim/src/did/did.c@ 11408

Last change on this file since 11408 was 11071, checked in by tbretz, 14 years ago
Replaced v19r21 by a version extracted with 'unzip -a' to get proper unix text format.
File size: 77.8 KB
Line 
1#include <stdio.h>
2#include <ctype.h>
3#include <time.h>
4#include <dim.h>
5#include <dic.h>
6#include <dis.h>
7#include "did.h"
8
9int First_time = 1;
10int Curr_view_opt = -1;
11char Curr_view_opt_par[80];
12char Curr_service_name[132];
13char Curr_service_format[256];
14int Curr_service_print_type = 0;
15int N_servers = 0;
16int N_services = 0;
17int no_link_int = -1;
18FILE *fptr;
19
20char *Service_content_str;
21char *Service_buffer;
22int Service_size;
23char *Curr_service_list = 0;
24char *Curr_client_list = 0;
25int Curr_service_id = 0;
26Widget Curr_client_id;
27Widget Curr_service_list_id;
28SERVER *Got_Service_List = 0;
29SERVER *Got_Client_List = 0;
30
31Widget SubscribeButton;
32Widget Subscribe10Button;
33
34int Timer_q;
35
36int Force_update = 0;
37/*
38 * Global data
39 */
40static XmFontList did_default_font, did_small_font,
41 did_label_font, did_server_font;
42
43/*static MrmType class_id;*/ /* Place to keep class ID*/
44/*static MrmType *dummy_class;*/ /* and class variable. */
45
46/*static char *db_filename_vec[1];*/ /* Mrm.hierachy file list. */
47/*static int db_filename_num;*/
48
49/*
50 * Forward declarations
51 */
52void did_exit();
53void create_main();
54void create_label();
55void create_matrix();
56void view_opts();
57void dns_control();
58void ok_pop_up();
59void cancel_pop_up();
60
61extern void set_something();
62extern void get_something();
63extern void set_color();
64
65/*
66 * Names and addresses of callback routines to register with Mrm
67 */
68/*
69static MrmRegisterArg reglist [] = {
70{"did_exit", (caddr_t)did_exit},
71{"create_main", (caddr_t)create_main},
72{"create_label", (caddr_t)create_label},
73{"create_matrix", (caddr_t)create_matrix},
74{"view_opts", (caddr_t)view_opts},
75{"dns_control", (caddr_t)dns_control},
76{"ok_pop_up", (caddr_t)ok_pop_up},
77{"cancel_pop_up", (caddr_t)cancel_pop_up},
78};
79
80static int reglist_num = (sizeof reglist / sizeof reglist[0]);
81*/
82/*
83 * OS transfer point. The main routine does all the one-time setup and
84 * then calls XtAppMainLoop.
85 */
86
87SERVER *Curr_servp;
88
89XmFontList util_get_font( char *fontname, Widget top )
90{
91XFontStruct * mf;
92XmFontList font;
93/*
94char * fontname;
95
96 if ( size == 'm' ) {
97 fontname = MENU_FONT;
98 }
99 else if ( size == 'b' ) {
100 fontname = LABEL_FONT;
101 }
102 else {
103 fontname = DEFAULT_FONT;
104 }
105*/
106 if ( (mf = XLoadQueryFont(XtDisplay(top),fontname))==NULL) {
107 printf("Couldn't open the following fonts:\n\t%s\n",
108 fontname);
109 XtVaGetValues ( top, XmNdefaultFontList, &font, NULL );
110 }
111 else {
112 font = XmFontListCreate (mf, XmSTRING_DEFAULT_CHARSET);
113 }
114 return font;
115}
116
117void create_matrix_widget()
118{
119Widget row_col_id, top_id;
120Arg arglist[10];
121int n = 0;
122char w_name[MAX_NAME];
123
124 top_id = Window_id;
125 XtSetArg(arglist[n], XmNborderWidth, 0); n++;
126 XtSetArg(arglist[n], XmNorientation, XmVERTICAL); n++;
127 XtSetArg(arglist[n], XmNnumColumns, 4); n++;
128 XtSetArg(arglist[n], XmNpacking, XmPACK_COLUMN); n++;
129 XtSetArg(arglist[n], XmNadjustLast, False); n++;
130 sprintf(w_name,"matrix_row");
131 row_col_id = XmCreateRowColumn(top_id,w_name,arglist,n);
132 XtManageChild(row_col_id);
133 Matrix_id[Curr_matrix] = row_col_id;
134 /*
135 XmScrolledWindowSetAreas(Window_id,NULL, NULL, Matrix_id);
136 */
137}
138
139void gui_create_main_window(Widget parent)
140{
141
142Widget mw;
143Widget mb;
144Widget mf;
145Widget tl;
146Widget sl;
147Widget f;
148XmString xms;
149int par;
150int reason;
151Arg ar[20];
152int n;
153
154 mw = XmCreateMainWindow ( parent, "DidMainWindow", NULL, 0 );
155 XtVaSetValues( mw,
156 XmNresizePolicy, XmRESIZE_ANY,
157
158 XmNfontList, did_default_font,
159 NULL);
160 XtManageChild( mw );
161 /* create menu bar */
162 mb = XmCreateMenuBar ( mw, "DidMenuBar", NULL, 0 );
163 XtVaSetValues( mb,
164 XmNmarginHeight,2,
165 XmNborderWidth, 0,
166 XmNfontList, did_default_font,
167 NULL);
168
169 gui_create_main_menu( mb );
170 XtManageChild ( mb );
171
172 /* create main form */
173 mf = XmCreateForm ( mw, "DidMainForm", NULL, 0 );
174 XtVaSetValues ( mf,
175 XmNresizePolicy, XmRESIZE_NONE,
176
177 NULL );
178 XtManageChild ( mf );
179
180 /* create top label */
181 xms = create_str(" \n ");
182
183 tl = XmCreateLabel ( mf, "DidTitle", NULL, 0 );
184 XtVaSetValues( tl,
185 XmNtopAttachment, XmATTACH_FORM,
186 XmNbottomAttachment, XmATTACH_NONE,
187 XmNleftAttachment, XmATTACH_FORM,
188 XmNrightAttachment, XmATTACH_FORM,
189 XmNleftOffset, 0,
190 XmNtopOffset, 0,
191 XmNbottomOffset, 0,
192 XmNrightOffset, 0,
193 XmNborderWidth, 0,
194 XmNlabelString, xms,
195 XmNshadowThickness, 0,
196 XmNhighlightThickness, 0,
197 XmNheight, 32,
198 XmNalignment, XmALIGNMENT_CENTER,
199 XmNfontList, did_label_font,
200 NULL);
201 XtManageChild( tl );
202/*
203 tl = XtVaCreateManagedWidget( "SmiTitle",
204 xmPushButtonWidgetClass, mw,
205 XmNborderWidth, 0,
206 XmNlabelString, xms,
207 XmNshadowThickness, 0,
208 XmNhighlightThickness, 0,
209 XmNalignment, XmALIGNMENT_CENTER,
210 XmNfontList, smid_label_font,
211 NULL);
212*/
213 XmStringFree ( xms );
214 /*
215 XtAddCallback(tl, MrmNcreateCallback,
216 (XtCallbackProc)create_label, 0);
217 */
218 par = 0;
219 reason = 0;
220 create_label(tl, &par, &reason);
221
222 /* create main form */
223 /*
224 mf = (Widget)XmCreateForm ( mw, "DidMainForm", NULL, 0 );
225 XtVaSetValues ( mf,
226 XmNborderWidth,1,
227 XmNshadowThickness, 2,
228 XmNwidth,806,
229 XmNheight,300,
230
231 XmNresizePolicy, XmRESIZE_NONE, NULL );
232 XtManageChild ( mf );
233 */
234 /*
235 XtAddCallback(mf, MrmNcreateCallback,
236 (XtCallbackProc)create_main, 0);
237 */
238
239 create_main(mf, &par, &reason);
240
241 f = XmCreateForm( mf, "ScrollForm", NULL, 0 );
242 XtVaSetValues ( f,
243 XmNwidth, 806,
244 XmNheight,300,
245 XmNtopAttachment, XmATTACH_WIDGET,
246 XmNbottomAttachment, XmATTACH_FORM,
247 XmNleftAttachment, XmATTACH_FORM,
248 XmNrightAttachment, XmATTACH_FORM,
249 XmNrightOffset, 0,
250 XmNleftOffset, 0,
251 XmNbottomOffset, 0,
252 XmNtopWidget, tl,
253 XmNtopOffset, 0,
254 XmNshadowThickness, 2,
255 XmNbottomOffset, 0,
256 /*
257 XmNshadowType, XmSHADOW_OUT,
258 */
259 XmNborderWidth,0,
260 NULL);
261
262 /*
263 f = XtVaCreateManagedWidget ( "XDScrolledForm",
264 xmFormWidgetClass, mf,
265 XmNtopAttachment, XmATTACH_WIDGET,
266 XmNbottomAttachment, XmATTACH_FORM,
267 XmNleftAttachment, XmATTACH_FORM,
268 XmNrightAttachment, XmATTACH_FORM,
269 XmNrightOffset, 0,
270 XmNleftOffset, 0,
271 XmNbottomOffset, 0,
272 XmNtopWidget, tl,
273 XmNtopOffset, 0,
274 XmNshadowThickness, 2,
275 XmNbottomOffset, 0,
276 XmNshadowType, XmSHADOW_OUT,
277 XmNborderWidth,1,
278 NULL);
279*/
280 /*
281 XtAddCallback(f, MrmNcreateCallback,
282 (XtCallbackProc)create_window, 0);
283 */
284
285 XtManageChild ( f );
286 /* create scrolled list */
287
288 n = 0;
289 XtSetArg ( ar[n], XmNtopAttachment, XmATTACH_FORM); n++;
290 XtSetArg ( ar[n], XmNbottomAttachment, XmATTACH_FORM); n++;
291 XtSetArg ( ar[n], XmNleftAttachment, XmATTACH_FORM); n++;
292 XtSetArg ( ar[n], XmNrightAttachment, XmATTACH_FORM); n++;
293 XtSetArg ( ar[n], XmNrightOffset, 0); n++;
294 XtSetArg ( ar[n], XmNleftOffset, 0); n++;
295 XtSetArg ( ar[n], XmNbottomOffset, 0); n++;
296 XtSetArg ( ar[n], XmNtopOffset, 0); n++;
297 /*
298 XtSetArg ( ar[n], XmNvisualPolicy, XmCONSTANT); n++;
299 */
300 XtSetArg ( ar[n], XmNscrollBarDisplayPolicy, XmAS_NEEDED); n++;
301
302 XtSetArg ( ar[n], XmNscrollingPolicy, XmAUTOMATIC); n++;
303
304 sl = XmCreateScrolledWindow ( f, "ScrollWin", ar, n );
305 /*
306 XtVaSetValues ( sl,
307 XmNtopAttachment, XmATTACH_FORM,
308 XmNbottomAttachment, XmATTACH_FORM,
309 XmNleftAttachment, XmATTACH_FORM,
310 XmNrightAttachment, XmATTACH_FORM,
311 XmNrightOffset, 0,
312 XmNleftOffset, 0,
313 XmNbottomOffset, 0,
314 XmNtopOffset, 0,
315
316 XmNvisualPolicy, XmCONSTANT,
317
318 XmNscrollBarDisplayPolicy, XmSTATIC,
319
320 XmNscrollingPolicy, XmAUTOMATIC,
321
322 NULL);
323 */
324 XtManageChild ( sl );
325 /*
326 create_window(sl, &par, &reason);
327 */
328 Window_id = sl;
329
330 create_matrix_widget();
331
332/*
333 sl = XtVaCreateWidget ( "DidServersScrl",
334 xmScrolledWindowWidgetClass, f,
335 XmNscrollingPolicy, XmAUTOMATIC,
336 XmNscrollBarDisplayPolicy, XmSTATIC,
337 XmNtopAttachment, XmATTACH_FORM,
338 XmNleftAttachment, XmATTACH_FORM,
339 XmNrightAttachment, XmATTACH_FORM,
340 XmNbottomAttachment, XmATTACH_FORM,
341 XmNvisualPolicy, XmCONSTANT,
342 XmNtopOffset, 4,
343 XmNleftOffset, 4,
344 XmNbottomOffset, 4,
345 XmNrightOffset, 4,
346 NULL );
347 XtManageChild ( sl );
348*/
349 /*
350 XtVaSetValues( mw,
351 XmNworkWindow,mf,
352 XmNcommandWindow, tl,
353 NULL);
354 */
355
356}
357
358Widget create_separator(Widget parent_id)
359{
360 Widget w;
361 Arg arglist[10];
362 int n = 0;
363
364 w = XmCreateSeparator(parent_id, "separator",
365 arglist,n);
366 XtManageChild(w);
367 return(w);
368}
369
370void gui_create_main_menu( Widget mb )
371{
372Widget cb;
373Widget mn;
374Widget bt;
375XmString xms;
376 /* File */
377 mn = XmCreatePulldownMenu ( mb, "FileMB", NULL, 0 );
378 cb = XmCreateCascadeButton(mb, "File", NULL, 0);
379 XtVaSetValues ( cb,
380 XmNsubMenuId, mn,
381 NULL);
382 XtManageChild ( cb );
383 /*
384 cb = XtVaCreateManagedWidget ( "File",
385 xmCascadeButtonWidgetClass, mb,
386 XtVaTypedArg, XmNmnemonic, XmRString, "F", 2,
387 XmNsubMenuId, mn,
388 NULL);
389 */
390 XtVaSetValues ( mn,
391 XmNradioAlwaysOne, True,
392 XmNradioBehavior, True,
393 NULL);
394 XtVaSetValues ( cb,
395 XmNfontList, did_default_font,
396 NULL);
397 /* buttons */
398 xms = create_str ("Exit DID");
399 /*
400 bt = XtVaCreateManagedWidget ( "MenuExitButton",
401 xmPushButtonWidgetClass, mn,
402 XmNlabelString, xms,
403 XmNaccelerator, "Ctrl<Key>C",
404 XmNacceleratorText, xma,
405 NULL);
406 */
407 bt = XmCreatePushButton ( mn, "button", NULL, 0 );
408 XtVaSetValues( bt,
409 XmNlabelString, xms,
410 XmNfontList, did_default_font,
411 NULL);
412 XtManageChild( bt );
413 XmStringFree ( xms );
414 XtAddCallback ( bt, XmNactivateCallback, (XtCallbackProc)did_exit, 0 );
415 /*
416 util_recolor ( XtParent(mn) );
417 */
418 /* View */
419 mn = XmCreatePulldownMenu ( mb, "ViewMB", NULL, 0 );
420 cb = XmCreateCascadeButton(mb, "View", NULL, 0);
421 XtVaSetValues ( cb,
422 XmNsubMenuId, mn,
423 NULL);
424 XtVaSetValues ( cb,
425 XmNfontList, did_default_font,
426 NULL);
427 XtManageChild ( cb );
428 /*
429 cb = XtVaCreateManagedWidget ( "View",
430 xmCascadeButtonWidgetClass, mb,
431 XtVaTypedArg, XmNmnemonic, XmRString, "V", 2,
432 XmNsubMenuId, mn,
433 NULL);
434 */
435 XtVaSetValues ( mn,
436 XmNradioAlwaysOne, True,
437 XmNradioBehavior, True,
438 NULL);
439 /* buttons */
440
441 xms = create_str ("All Servers");
442 /*
443 bt = XtVaCreateManagedWidget ( "V_MenuAllButton",
444 xmPushButtonWidgetClass, mn,
445 XmNlabelString, xms,
446 XmNaccelerator, "Ctrl<Key>A",
447 XmNacceleratorText, xma,
448 NULL);
449 */
450 bt = XmCreatePushButton ( mn, "button", NULL, 0 );
451 XtVaSetValues( bt,
452 XmNlabelString, xms,
453 XmNfontList, did_default_font,
454 NULL);
455 XtManageChild( bt );
456 XmStringFree ( xms );
457 XtAddCallback ( bt, XmNactivateCallback, (XtCallbackProc)view_opts,
458 (XtPointer)1 );
459
460 xms = create_str ("Servers by Node");
461 /*
462 bt = XtVaCreateManagedWidget ( "V_MenuNodeButton",
463 xmPushButtonWidgetClass, mn,
464 XmNlabelString, xms,
465 XmNaccelerator, "Ctrl<Key>N",
466 XmNacceleratorText, xma,
467 NULL);
468 XmStringFree ( xms );
469 */
470 bt = XmCreatePushButton ( mn, "button", NULL, 0 );
471 XtVaSetValues( bt,
472 XmNlabelString, xms,
473 XmNfontList, did_default_font,
474 NULL);
475 XtManageChild( bt );
476 XmStringFree ( xms );
477 XtAddCallback ( bt, XmNactivateCallback, (XtCallbackProc)view_opts,
478 (XtPointer)0 );
479
480 xms = create_str ("Servers by Service");
481 /*
482 bt = XtVaCreateManagedWidget ( "V_MenuServiceButton",
483 xmPushButtonWidgetClass, mn,
484 XmNlabelString, xms,
485 XmNaccelerator, "Ctrl<Key>S",
486 XmNacceleratorText, xma,
487 NULL);
488 XmStringFree ( xms );
489 XmStringFree ( xma );
490 */
491 bt = XmCreatePushButton ( mn, "button", NULL, 0 );
492 XtVaSetValues( bt,
493 XmNlabelString, xms,
494 XmNfontList, did_default_font,
495 NULL);
496 XtManageChild( bt );
497 XmStringFree ( xms );
498 XtAddCallback ( bt, XmNactivateCallback, (XtCallbackProc)view_opts,
499 (XtPointer)2 );
500
501 create_separator(mn);
502 /*
503 bt = XtVaCreateManagedWidget ( "W_MenuSep",
504 xmSeparatorGadgetClass, mn,
505 NULL);
506 */
507 xms = create_str ("Servers in Error");
508 /*
509 bt = XtVaCreateManagedWidget ( "V_MenuErrorButton",
510 xmPushButtonWidgetClass, mn,
511 XmNlabelString, xms,
512 XmNaccelerator, "Ctrl<Key>E",
513 XmNacceleratorText, xma,
514 NULL);
515 XmStringFree ( xms );
516 XmStringFree ( xma );
517 */
518 bt = XmCreatePushButton ( mn, "button", NULL, 0 );
519 XtVaSetValues( bt,
520 XmNlabelString, xms,
521 XmNfontList, did_default_font,
522 NULL);
523 XtManageChild( bt );
524 XmStringFree ( xms );
525 XtAddCallback ( bt, XmNactivateCallback, (XtCallbackProc)view_opts,
526 (XtPointer)3 );
527 /*
528 util_recolor ( XtParent(mn) );
529 */
530 /* Commands */
531 mn = XmCreatePulldownMenu ( mb, "CommandMB", NULL, 0 );
532 cb = XmCreateCascadeButton(mb, "Commands", NULL, 0);
533 XtVaSetValues ( cb,
534 XmNsubMenuId, mn,
535 NULL);
536 XtVaSetValues ( cb,
537 XmNfontList, did_default_font,
538 NULL);
539 XtManageChild ( cb );
540 /*
541 cb = XtVaCreateManagedWidget ( "Commands",
542 xmCascadeButtonWidgetClass, mb,
543 XtVaTypedArg, XmNmnemonic, XmRString, "C", 2,
544 XmNsubMenuId, mn,
545 XmNsensitive, commands_enable,
546 NULL);
547 */
548 /* buttons */
549 /* Utils */
550 /*
551 xms = util_create_str ("Show Command Buttons");
552 xma = util_create_str ("Ctrl+B");
553 bt = XtVaCreateManagedWidget ( "C_ShowCmndButt",
554 xmToggleButtonWidgetClass, mn,
555 XmNlabelString, xms,
556 XmNaccelerator, "Ctrl<Key>B",
557 XmNacceleratorText, xma,
558 XmNset, False,
559 XmNindicatorSize,12,
560 XmNvisibleWhenOff, True,
561 NULL);
562 XmStringFree ( xms );
563 XmStringFree ( xma );
564 XtAddCallback ( bt, XmNvalueChangedCallback, (XtCallbackProc)show_command_buttons_callback, NULL );
565
566 bt = XtVaCreateManagedWidget ( "W_MenuSep",
567 xmSeparatorGadgetClass, mn,
568 NULL);
569 */
570
571 xms = create_str ("LOG Connections");
572 /*
573 bt = XtVaCreateManagedWidget ( "C_MenuButtonLOG",
574 xmPushButtonWidgetClass, mn,
575 XmNlabelString, xms,
576 XmNaccelerator, "Ctrl<Key>G",
577 XmNacceleratorText, xma,
578 NULL);
579 XmStringFree ( xms );
580 XmStringFree ( xma );
581 XtAddCallback ( bt, XmNactivateCallback, (XtCallbackProc)dns_control_callback, "log" );
582 */
583 bt = XmCreatePushButton ( mn, "button", NULL, 0 );
584 XtVaSetValues( bt,
585 XmNlabelString, xms,
586 XmNfontList, did_default_font,
587 NULL);
588 XtManageChild( bt );
589 XmStringFree ( xms );
590 XtAddCallback ( bt, XmNactivateCallback, (XtCallbackProc)dns_control,
591 (XtPointer)0 );
592
593 create_separator(mn);
594 /*
595 bt = XtVaCreateManagedWidget ( "W_MenuSep",
596 xmSeparatorGadgetClass, mn,
597 NULL);
598 */
599 xms = create_str ("Set Debug ON");
600 /*
601 bt = XtVaCreateManagedWidget ( "C_MenuButtonDON",
602 xmPushButtonWidgetClass, mn,
603 XmNlabelString, xms,
604 XmNaccelerator, "<Key>F2:",
605 XmNacceleratorText, xma,
606 NULL);
607 XmStringFree ( xms );
608 XmStringFree ( xma );
609 XtAddCallback ( bt, XmNactivateCallback, (XtCallbackProc)dns_control_callback, "on" );
610 */
611 bt = XmCreatePushButton ( mn, "button", NULL, 0 );
612 XtVaSetValues( bt,
613 XmNlabelString, xms,
614 XmNfontList, did_default_font,
615 NULL);
616 XtManageChild( bt );
617 XmStringFree ( xms );
618 XtAddCallback ( bt, XmNactivateCallback, (XtCallbackProc)dns_control,
619 (XtPointer)1 );
620
621 xms = create_str ("Set Debug OFF");
622 /*
623 bt = XtVaCreateManagedWidget ( "C_MenuButtonDOFF",
624 xmPushButtonWidgetClass, mn,
625 XmNlabelString, xms,
626 XmNaccelerator, "<Key>F3:",
627 XmNacceleratorText, xma,
628 NULL);
629 XmStringFree ( xms );
630 XmStringFree ( xma );
631 XtAddCallback ( bt, XmNactivateCallback, (XtCallbackProc)dns_control_callback, "off" );
632 */
633 bt = XmCreatePushButton ( mn, "button", NULL, 0 );
634 XtVaSetValues( bt,
635 XmNlabelString, xms,
636 XmNfontList, did_default_font,
637 NULL);
638 XtManageChild( bt );
639 XmStringFree ( xms );
640 XtAddCallback ( bt, XmNactivateCallback, (XtCallbackProc)dns_control,
641 (XtPointer)2 );
642
643 create_separator(mn);
644 /*
645 bt = XtVaCreateManagedWidget ( "W_MenuSep",
646 xmSeparatorGadgetClass, mn,
647 NULL);
648 */
649 xms = create_str ("Print Hash Table");
650 /*
651 bt = XtVaCreateManagedWidget ( "C_MenuButtonPrint",
652 xmPushButtonWidgetClass, mn,
653 XmNlabelString, xms,
654 XmNaccelerator, "Ctrl<Key>T",
655 XmNacceleratorText, xma,
656 NULL);
657 XmStringFree ( xms );
658 XmStringFree ( xma );
659 XtAddCallback ( bt, XmNactivateCallback, (XtCallbackProc)dns_control_callback, "hash" );
660 */
661 bt = XmCreatePushButton ( mn, "button", NULL, 0 );
662 XtVaSetValues( bt,
663 XmNlabelString, xms,
664 XmNfontList, did_default_font,
665 NULL);
666 XtManageChild( bt );
667 XmStringFree ( xms );
668 XtAddCallback ( bt, XmNactivateCallback, (XtCallbackProc)dns_control,
669 (XtPointer)4 );
670 /* kill
671 create_separator(mn);
672 */
673 /*
674 bt = XtVaCreateManagedWidget ( "W_MenuSep",
675 xmSeparatorGadgetClass, mn,
676 NULL);
677 */
678 /* kill
679 xms = create_str ("Kill DIM Servers");
680 */
681 /*
682 bt = XtVaCreateManagedWidget ( "C_MenuButtonKill",
683 xmPushButtonWidgetClass, mn,
684 XmNlabelString, xms,
685 XmNaccelerator, "Ctrl<Key>K",
686 XmNacceleratorText, xma,
687 NULL);
688 XmStringFree ( xms );
689 XmStringFree ( xma );
690 XtAddCallback ( bt, XmNactivateCallback, (XtCallbackProc)dns_control_callback, "kill" );
691 */
692 /* kill
693 bt = XmCreatePushButton ( mn, "button", NULL, 0 );
694 XtVaSetValues( bt,
695 XmNlabelString, xms,
696 XmNfontList, did_default_font,
697 NULL);
698 XtManageChild( bt );
699 XmStringFree ( xms );
700 XtAddCallback ( bt, XmNactivateCallback, (XtCallbackProc)dns_control,
701 (XtPointer)3 );
702 */
703 /*
704 util_recolor ( XtParent(mn) );
705 */
706 /* Help */
707 mn = XmCreatePulldownMenu ( mb, "HelpMB", NULL, 0 );
708 /*
709 cb = XtVaCreateManagedWidget ( "Help",
710 xmCascadeButtonWidgetClass, mb,
711 XtVaTypedArg, XmNmnemonic, XmRString, "H", 2,
712 XmNsubMenuId, mn,
713 NULL);
714 */
715 cb = XmCreateCascadeButton ( mb, "Help", NULL, 0 );
716 XtVaSetValues( cb,
717 XmNsubMenuId, mn,
718 XmNfontList, did_default_font,
719 NULL);
720 XtManageChild( cb );
721
722 xms = create_str ("Help");
723 /*
724 bt = XtVaCreateManagedWidget ( "C_XDAbout",
725 xmPushButtonWidgetClass, mn,
726 XmNlabelString, xms,
727 XmNaccelerator, "Ctrl<Key>H",
728 XmNacceleratorText, xma,
729 NULL);
730 */
731 bt = XmCreatePushButton ( mn, "button", NULL, 0 );
732 XtVaSetValues( bt,
733 XmNlabelString, xms,
734 XmNfontList, did_default_font,
735 NULL);
736 XtManageChild( bt );
737 XmStringFree ( xms );
738 /*
739 XtAddCallback ( bt, XmNactivateCallback, (XtCallbackProc)about_xd_callback, NULL );
740 */
741 /* set help menu */
742 XtVaSetValues ( mb, XmNmenuHelpWidget, cb, NULL );
743 /*
744 util_recolor ( XtParent(mn) );
745 */
746}
747
748
749Widget gui_toplevel(char **argv)
750{
751int n;
752Arg arglist[6];
753
754 n = 0;
755 XtSetArg ( arglist[n], XmNallowShellResize, True); n++;
756 XtSetArg ( arglist[n], XmNiconName, "DID"); n++;
757 XtSetArg ( arglist[n], XmNtitle, "xDid"); n++;
758 XtSetArg ( arglist[n], XmNtraversalOn,True); n++;
759 return XtAppCreateShell(argv[0], NULL, applicationShellWidgetClass,
760 display, arglist, n);
761
762}
763
764Widget gui_initialize (int argc, char **argv)
765{
766Widget toplevel;
767void gui_create_main_window();
768
769 XtToolkitInitialize();
770 app_context = XtCreateApplicationContext();
771 display = XtOpenDisplay(app_context, NULL, argv[0], "DID",
772 NULL, 0, &argc, argv);
773 if (display == NULL)
774 {
775 printf("%s: Can't open display\n", argv[0]);
776 exit(1);
777 }
778 toplevel = gui_toplevel(argv);
779
780 did_default_font = (XmFontList)util_get_font(DEFAULT_FONT, toplevel);
781 did_small_font = (XmFontList)util_get_font(MENU_FONT, toplevel);
782 did_label_font = (XmFontList)util_get_font(LABEL_FONT, toplevel);
783 did_server_font = (XmFontList)util_get_font(SERVER_FONT, toplevel);
784
785 gui_create_main_window(toplevel);
786
787 XtRealizeWidget ( toplevel );
788 return toplevel;
789}
790
791int main(int argc, char *argv[])
792{
793 int i;
794 char opt_str[20], *ptr;
795 XtInputMask mask;
796 void do_got_service_list();
797 void do_show_clients();
798 void app_initialize();
799
800 dim_no_threads();
801 dic_disable_padding();
802 dis_disable_padding();
803
804 if(argc > 1)
805 {
806 if(argv[1][0] == '-')
807 {
808 sprintf(opt_str,"%s",&argv[1][1]);
809 if((!strncmp(opt_str,"node",4)) ||
810 (!strncmp(opt_str,"NODE",4)))
811 Curr_view_opt = 0;
812 else if((!strncmp(opt_str,"all",3)) ||
813 (!strncmp(opt_str,"ALL",3)))
814 Curr_view_opt = 1;
815 else if((!strncmp(opt_str,"service",7)) ||
816 (!strncmp(opt_str,"SERVICE",7)))
817 Curr_view_opt = 2;
818 else if((!strncmp(opt_str,"error",5)) ||
819 (!strncmp(opt_str,"ERROR",5)))
820 Curr_view_opt = 3;
821 else if((!strncmp(opt_str,"help",4)) ||
822 (!strncmp(opt_str,"HELP",4)))
823 {
824 printf("Did - DIM Information Display\n");
825 printf("\t-all Show ALL Servers\n");
826 printf("\t-service=<str> Show Servers providing Service <str>\n");
827 printf("\t-node=<nodename> Show Servers on Node <nodename>\n");
828 printf("\t-error Show Servers in Error\n");
829 printf("\t-help Show this message\n\n");
830 exit(0);
831 }
832 else
833 Curr_view_opt = -1;
834 if((Curr_view_opt == 0) || (Curr_view_opt == 2))
835 {
836 if(!(ptr = strchr(argv[1],'=')))
837 {
838 if( (ptr = strchr(argv[2],'=')) )
839 {
840 ptr++;
841 if(!(*ptr))
842 ptr = argv[3];
843 }
844 else
845 ptr++;
846 }
847 else
848 {
849 ptr++;
850 if(!(*ptr))
851 ptr = argv[2];
852 }
853 for(i = 0;*ptr; ptr++, i++)
854 Curr_view_opt_par[i] = toupper(*ptr);
855 Curr_view_opt_par[i] = '\0';
856 }
857 }
858 }
859
860 toplevel_widget = (Widget)gui_initialize(argc, argv);
861 app_initialize();
862 /*
863 * Sit around forever waiting to process X-events. We never leave
864 * XtAppMainLoop. From here on, we only execute our callback routines.
865 */
866
867 while(1)
868 {
869 {
870 DISABLE_AST
871 mask = XtAppPending(app_context);
872 ENABLE_AST
873 }
874 if(mask)
875 {
876 DISABLE_AST
877 XtAppProcessEvent(app_context, mask);
878 if(Got_Service_List)
879 {
880 do_got_service_list(Got_Service_List);
881 Got_Service_List = 0;
882 }
883 if(Got_Client_List)
884 {
885 do_show_clients(Got_Client_List);
886 Got_Client_List = 0;
887 }
888 ENABLE_AST
889 }
890 else
891 {
892 dim_usleep(100000);
893 /*
894 usleep(100000);
895 */
896 }
897 }
898
899}
900
901static char no_link = -1;
902
903void app_initialize(int tag)
904{
905void check_put_label();
906
907void update_servers();
908void update_servers_new();
909void update_show_servers();
910extern void get_all_colors();
911extern void set_title();
912extern void set_icon_title();
913char dns_node[64];
914int dns_port;
915char title[128],icon_title[128];
916
917 if(tag){}
918 dic_get_dns_node(dns_node);
919 dns_port = dic_get_dns_port();
920 if(dns_port != DNS_PORT)
921 {
922 sprintf(title,"DID - DIM Information Display DNS=%s:%d",dns_node,dns_port);
923 }
924 else
925 {
926 sprintf(title,"DID - DIM Information Display DNS=%s",dns_node);
927 }
928 sprintf(icon_title,"DID %s",dns_node);
929 get_all_colors(display,Matrix_id[Curr_matrix]);
930 set_title(toplevel_widget,title);
931 set_icon_title(toplevel_widget,icon_title);
932 Timer_q = dtq_create();
933 dic_info_service("DIS_DNS/SERVER_INFO",MONITORED,0,0,0,update_servers,0,
934 &no_link,1);
935 /*
936 dic_info_service("DIS_DNS/SERVER_LIST",MONITORED,0,0,0,
937 update_servers_new,0, &no_link,1);
938 */
939 /*
940 dtq_add_entry(Timer_q, 2, check_put_label, 0);
941 */
942 XtAppAddTimeOut(app_context, 1000, update_show_servers, 0);
943}
944
945/*
946 * All errors are fatal.
947 */
948void s_error(char *problem_string)
949{
950 printf("%s\n", problem_string);
951 exit(0);
952}
953
954void did_exit(Widget w, int *tag, unsigned long *reason)
955{
956 if(w){}
957 if(tag){}
958 if(reason){}
959 exit(0);
960}
961
962extern Pixel rgb_colors[MAX_COLORS];
963
964void create_main (Widget w, int *tag, unsigned long *reason)
965{
966 if(tag){}
967 if(reason){}
968 Window_id = w;
969/*
970 dtq_start_timer(5, app_initialize, 0);
971*/
972}
973
974void view_opts(Widget w, int tag, unsigned long *reason)
975{
976 void get_server_node(), get_server_service(), show_servers();
977
978 if(w){}
979 if(reason){}
980 Curr_view_opt = tag;
981 switch(tag)
982 {
983 case 0 :
984 get_server_node();
985 break;
986 case 1 :
987 show_servers();
988 break;
989 case 2 :
990 get_server_service();
991 break;
992 case 3 :
993 show_servers();
994 break;
995 }
996}
997
998void dns_control(Widget w, int tag, unsigned long *reason)
999{
1000
1001 if(w){}
1002 if(reason){}
1003 switch(tag)
1004 {
1005 case 0 :
1006 dic_cmnd_service("DIS_DNS/PRINT_STATS",0,0);
1007 break;
1008 case 1 :
1009 dic_cmnd_service("DIS_DNS/DEBUG_ON",0,0);
1010 break;
1011 case 2 :
1012 dic_cmnd_service("DIS_DNS/DEBUG_OFF",0,0);
1013 break;
1014 case 3 :
1015 put_selection(DID_KILL_ALL,"Confirmation");
1016 break;
1017 case 4 :
1018 dic_cmnd_service("DIS_DNS/PRINT_HASH_TABLE",0,0);
1019 break;
1020 }
1021}
1022
1023void get_server_node()
1024{
1025Widget id,sel_id;
1026int i, j, n_nodes, curr_index = 0;
1027char nodes_str[MAX_NODE_NAME*MAX_CONNS], max_str[MAX_NODE_NAME];
1028char *ptr, *nodeptrs[MAX_CONNS], *curr_str, *sptr;
1029int get_nodes();
1030
1031 sel_id = put_selection(DID_SEL_NODE,"Node Selection");
1032 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_HELP_BUTTON);
1033 XtUnmanageChild(id);
1034 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_APPLY_BUTTON);
1035 XtUnmanageChild(id);
1036 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_LIST);
1037 XmListDeleteAllItems(id);
1038 n_nodes = get_nodes(nodes_str);
1039 ptr = nodes_str;
1040
1041 for(i=0;i<n_nodes;i++)
1042 {
1043 nodeptrs[i] = ptr;
1044 sptr = ptr;
1045 ptr = strchr(ptr,'\n');
1046 for(j = 0; j < (int)strlen(sptr); j++)
1047 sptr[j] = tolower(sptr[j]);
1048 *ptr++ = '\0';
1049 }
1050 strcpy(max_str,"zzzzzzzzzzzzzzzzzzzzzzzzzzzz");
1051 for(i=0;i<n_nodes; i++)
1052 {
1053 curr_str = max_str;
1054 for(j=0;j<n_nodes; j++)
1055 {
1056 sptr = nodeptrs[j];
1057 if(!sptr)
1058 continue;
1059
1060 if(strcmp(sptr,curr_str) < 0)
1061 {
1062 curr_str = sptr;
1063 curr_index = j;
1064 }
1065 }
1066 nodeptrs[curr_index] = 0;
1067 XmListAddItem(id,create_str(curr_str),i+1);
1068 }
1069 /*
1070 for(i=0;i<n_nodes;i++)
1071 {
1072 node = ptr;
1073 ptr = strchr(ptr,'\n');
1074 *ptr++ = '\0';
1075 XmListAddItem(id,create_str(node),i+1);
1076 }
1077 */
1078 set_something(id,XmNlistItemCount,i);
1079 set_something(id,XmNlistVisibleItemCount,(i < 8) ? i : 8);
1080}
1081
1082void get_server_service()
1083{
1084Widget id,sel_id;
1085
1086 sel_id = put_selection(DID_SEL_SERVICE,"Service Selection");
1087 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_HELP_BUTTON);
1088 XtUnmanageChild(id);
1089 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_APPLY_BUTTON);
1090 XtUnmanageChild(id);
1091
1092 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_LIST);
1093 /*
1094 XtUnmanageChild(id);
1095 */
1096 XtUnmapWidget(id);
1097
1098 /*
1099 id = (Widget)XmSelectionBoxGetChild(sel_id,XmDIALOG_LIST_LABEL);
1100 XtUnmanageChild(id);
1101 */
1102}
1103
1104int get_nodes(char *node_ptr)
1105{
1106DNS_SERVER_INFO *ptr;
1107int n_nodes = 0;
1108SERVER *servp;
1109
1110 node_ptr[0] = '\0';
1111 servp = Server_head;
1112 while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
1113 {
1114 ptr = &servp->server;
1115 if(strstr(node_ptr,ptr->node) <= (char *)0)
1116 {
1117 strcat(node_ptr,ptr->node);
1118 strcat(node_ptr,"\n");
1119 n_nodes++;
1120 }
1121 }
1122 return(n_nodes);
1123}
1124
1125void get_service_format()
1126{
1127
1128 char str[256], *ptr, *ptr1;
1129 int rpc_flag;
1130
1131 strcpy(str,Curr_service_name);
1132 rpc_flag = 0;
1133 if( (ptr = strstr(str,"/RpcIn")) )
1134 {
1135 *ptr = '\0';
1136 rpc_flag = 1;
1137 }
1138 if( (ptr = strstr(str,"/RpcOut")) )
1139 {
1140 *ptr = '\0';
1141 rpc_flag = 2;
1142 }
1143 strcat(str,"|");
1144 if( (ptr = strstr(Curr_service_list,str)) )
1145 {
1146 if(!rpc_flag)
1147 {
1148 ptr += strlen(str);
1149 ptr1 = strchr(ptr,'|');
1150 }
1151 else if(rpc_flag == 1)
1152 {
1153 ptr += strlen(str);
1154 ptr1 = strchr(ptr,',');
1155 }
1156 else
1157 {
1158 ptr += strlen(str);
1159 ptr = strchr(ptr,',');
1160 ptr++;
1161 ptr1 = strchr(ptr,'|');
1162 }
1163 strncpy(Curr_service_format,ptr,(int)(ptr1 - ptr));
1164 Curr_service_format[(int)(ptr1-ptr)] = '\0';
1165 }
1166}
1167
1168void recv_service_info(int *tag, int *buffer, int *size)
1169{
1170/*
1171 char str[256], *ptr, *ptr1;
1172 int rpc_flag;
1173*/
1174 void print_service_formatted();
1175
1176 if(tag){}
1177 Service_content_str = malloc(1024 + (*size)*16);
1178 Service_buffer = malloc(*size);
1179 memcpy(Service_buffer, (char *)buffer, *size);
1180 Service_size = *size;
1181 get_service_format();
1182 if((*size == 4 ) && (*buffer == -1))
1183 {
1184 sprintf(Service_content_str,
1185 "Service %s Not Available\n", Curr_service_name);
1186 }
1187 else
1188 {
1189 switch(Curr_service_print_type)
1190 {
1191 case 0:
1192 print_service_formatted(buffer,*size);
1193 break;
1194 /*
1195 case 1:
1196 print_service_float(buffer, ((*size - 1) / 4) + 1);
1197 break;
1198 case 2:
1199 print_service_double(buffer, ((*size - 1) / 4) + 1);
1200 break;
1201 */
1202 }
1203 }
1204 set_something(Content_label_id,XmNlabelString, Service_content_str);
1205 /*
1206 if(Matrix_id[Curr_matrix])
1207 XFlush(XtDisplay(Matrix_id[Curr_matrix]));
1208 */
1209}
1210
1211void print_service_formatted(void *buff, int size)
1212{
1213char type;
1214int num, ret;
1215char str[128];
1216char *ptr;
1217void *buffer_ptr;
1218char timestr[128], aux[10];
1219int quality = 0, secs = 0, mili = 0;
1220int did_write_string(char, int, void **, int);
1221time_t tsecs;
1222
1223 sprintf(Service_content_str,
1224 "Service %s (%s) Contents :\n \n", Curr_service_name,
1225 Curr_service_format);
1226 /*
1227 if(Curr_service_id)
1228 {
1229 */
1230 dic_get_timestamp(0, &secs, &mili);
1231 quality = dic_get_quality(0);
1232/*
1233#ifdef LYNXOS
1234 ctime_r((time_t *)&secs, timestr, 128);
1235#else
1236 ctime_r((time_t *)&secs, timestr);
1237#endif
1238*/
1239 tsecs = secs;
1240 my_ctime(&tsecs, timestr, 128);
1241 ptr = strrchr(timestr,' ');
1242 strcpy(aux, ptr);
1243 sprintf(ptr,".%03d",mili);
1244 strcat(timestr, aux);
1245 timestr[strlen(timestr)-1] = '\0';
1246
1247 sprintf(str," Timestamp: %s Quality: %d\n\n",
1248 timestr, quality);
1249
1250 strcat(Service_content_str,str);
1251 /*
1252 }
1253 */
1254 ptr = Curr_service_format;
1255 buffer_ptr = buff;
1256 while(*ptr)
1257 {
1258 type = *ptr++;
1259 if(*ptr == ':')
1260 {
1261 ptr++;
1262 sscanf(ptr, "%d", &num);
1263 ret = did_write_string(type, num, &buffer_ptr, size);
1264 size -= ret;
1265 if( (ptr = strchr(ptr,';')) )
1266 ptr++;
1267 else
1268 break;
1269 }
1270 else
1271 {
1272 ret = did_write_string(type, 0, &buffer_ptr, size);
1273 size -= ret;
1274 break;
1275 }
1276 }
1277}
1278
1279int did_write_string(char type, int num, void **buffer_ptr, int ssize)
1280{
1281void *ptr;
1282int size, psize;
1283
1284 void print_service_standard();
1285 void print_service_char();
1286 void print_service_short();
1287 void print_service_float();
1288 void print_service_double();
1289
1290 ptr = *buffer_ptr;
1291 switch(type)
1292 {
1293 case 'L':
1294 case 'l':
1295 strcat(Service_content_str," L");
1296 if(!num)
1297 size = ssize/sizeof(int);
1298 else
1299 size = num;
1300 psize = size * sizeof(int);
1301 print_service_standard(ptr, size);
1302 break;
1303 case 'I':
1304 case 'i':
1305 strcat(Service_content_str," I");
1306 if(!num)
1307 size = ssize/sizeof(int);
1308 else
1309 size = num;
1310 psize = size * sizeof(int);
1311 print_service_standard(ptr, size);
1312 break;
1313 case 'S':
1314 case 's':
1315 strcat(Service_content_str," S");
1316 if(!num)
1317 size = ssize/sizeof(short);
1318 else
1319 size = num;
1320 psize = size * sizeof(short);
1321 print_service_short(ptr, size);
1322 break;
1323 case 'F':
1324 case 'f':
1325 strcat(Service_content_str," F");
1326 if(!num)
1327 size = ssize/sizeof(float);
1328 else
1329 size = num;
1330 psize = size * sizeof(float);
1331 print_service_float(ptr, size);
1332 break;
1333 case 'D':
1334 case 'd':
1335 strcat(Service_content_str," D");
1336 if(!num)
1337 size = ssize/sizeof(double);
1338 else
1339 size = num;
1340 psize = size * sizeof(double);
1341 print_service_double(ptr, size);
1342 break;
1343 case 'X':
1344 case 'x':
1345 strcat(Service_content_str," X");
1346 if(!num)
1347 size = ssize/sizeof(longlong);
1348 else
1349 size = num;
1350 psize = size * sizeof(longlong);
1351 print_service_standard(ptr, size*2);
1352 break;
1353 case 'C':
1354 case 'c':
1355 default:
1356 strcat(Service_content_str," C");
1357 if(!num)
1358 size = ssize;
1359 else
1360 size = num;
1361 psize = size;
1362 print_service_char(ptr, size);
1363 }
1364 ptr = (char *)ptr + psize;
1365 *buffer_ptr = ptr;
1366 return psize;
1367}
1368/*
1369print_service(buff, size)
1370int *buff, size;
1371{
1372int i,j, str_flag = 0;
1373char *asc, *ptr, str[80];
1374int last[4];
1375
1376 sprintf(Service_content_str,
1377 "Service %s (%s) Contents :\n \n", Curr_service_name,
1378 Curr_service_format);
1379 asc = (char *)buff;
1380 for( i = 0; i < size; i++)
1381 {
1382 if(i%4 == 0)
1383 {
1384 sprintf(str,"%4d: ",i);
1385 strcat(Service_content_str,str);
1386 }
1387 if(!(i%4))
1388 strcat(Service_content_str,"H");
1389 sprintf(str," %08X ",buff[i]);
1390 strcat(Service_content_str,str);
1391 last[i%4] = buff[i];
1392 if(i%4 == 3)
1393 {
1394 strcat(Service_content_str," '");
1395 for(j = 0; j <16; j++)
1396 {
1397 if(isprint(asc[j]))
1398 {
1399 sprintf(str,"%c",asc[j]);
1400 strcat(Service_content_str,str);
1401 }
1402 else
1403 {
1404 sprintf(str,".");
1405 strcat(Service_content_str,str);
1406 }
1407 }
1408 strcat(Service_content_str,"'\n");
1409 for(j = 0; j <4; j++)
1410 {
1411 if(j == 0)
1412 strcat(Service_content_str," D");
1413 sprintf(str,"%11d ",last[j]);
1414 strcat(Service_content_str,str);
1415 }
1416 strcat(Service_content_str,"\n");
1417 asc = (char *)&buff[i+1];
1418 }
1419 }
1420 if(i%4)
1421 {
1422 for(j = 0; j < 4 - (i%4); j++)
1423 strcat(Service_content_str," ");
1424 strcat(Service_content_str," '");
1425 for(j = 0; j < (i%4) * 4; j++)
1426 {
1427 if(isprint(asc[j]))
1428 {
1429 sprintf(str,"%c",asc[j]);
1430 strcat(Service_content_str,str);
1431 }
1432 else
1433 strcat(Service_content_str,".");
1434 }
1435 strcat(Service_content_str,"'\n");
1436 for(j = 0; j < (i%4); j++)
1437 {
1438 if(j == 0)
1439 strcat(Service_content_str," D");
1440 sprintf(str,"%11d ",last[j]);
1441 strcat(Service_content_str,str);
1442 }
1443 strcat(Service_content_str,"\n");
1444 }
1445}
1446*/
1447
1448void print_service_standard(int *buff, int size)
1449{
1450int i,j;
1451char *asc, *ptr, str[80], tmp[256];
1452int last[4];
1453
1454 asc = (char *)buff;
1455 ptr = Service_content_str;
1456 ptr += strlen(Service_content_str);
1457 for( i = 0; i < size; i++)
1458 {
1459 strcpy(tmp,"");
1460 if(i%4 == 0)
1461 {
1462 if(i != 0)
1463 {
1464 strcat(tmp," ");
1465 }
1466 sprintf(str,"%5d ",i);
1467 strcat(tmp,str);
1468 }
1469 if(!(i%4))
1470 strcat(tmp,"H: ");
1471 sprintf(str," %08X",buff[i]);
1472 strcat(tmp,str);
1473 last[i%4] = buff[i];
1474 if((i%4 == 3) || (i == (size-1)))
1475 {
1476 /*
1477 if(i%4 != 3)
1478 {
1479 for(j = 1; j < 4 - (i%4); j++)
1480 strcat(tmp," ");
1481 }
1482 strcat(tmp," '");
1483 for(j = 0; j < ((i%4)*4)+4 ; j++)
1484 {
1485 if(isprint(asc[j]))
1486 {
1487 sprintf(str,"%c",asc[j]);
1488 strcat(tmp,str);
1489 }
1490 else
1491 {
1492 sprintf(str,".");
1493 strcat(tmp,str);
1494 }
1495 }
1496 */
1497 strcat(tmp,"\n");
1498 for(j = 0; j <= (i%4); j++)
1499 {
1500 if(j == 0)
1501 strcat(tmp," D: ");
1502 sprintf(str,"%12d",last[j]);
1503 strcat(tmp,str);
1504 }
1505 strcat(tmp,"\n");
1506 asc = (char *)&buff[i+1];
1507 }
1508 strcpy(ptr, tmp);
1509 ptr += strlen(tmp);
1510 }
1511 strcpy(tmp,"\n");
1512 strcpy(ptr, tmp);
1513}
1514
1515void print_service_longlong(longlong *buff, int size)
1516{
1517int i,j;
1518char *asc, *ptr, str[80], tmp[256];
1519longlong last[4];
1520
1521 asc = (char *)buff;
1522 ptr = Service_content_str;
1523 ptr += strlen(Service_content_str);
1524 for( i = 0; i < size; i++)
1525 {
1526 strcpy(tmp,"");
1527 if(i%4 == 0)
1528 {
1529 if(i != 0)
1530 {
1531 strcat(tmp," ");
1532 }
1533 sprintf(str,"%5d ",i);
1534 strcat(tmp,str);
1535 }
1536 if(!(i%4))
1537 strcat(tmp,"H: ");
1538 sprintf(str," %08X",(unsigned)buff[i]);
1539 strcat(tmp,str);
1540 last[i%4] = buff[i];
1541 if((i%4 == 3) || (i == (size-1)))
1542 {
1543 strcat(tmp,"\n");
1544 for(j = 0; j <= (i%4); j++)
1545 {
1546 if(j == 0)
1547 strcat(tmp," D: ");
1548 sprintf(str,"%12d",(int)last[j]);
1549 strcat(tmp,str);
1550 }
1551 strcat(tmp,"\n");
1552 asc = (char *)&buff[i+1];
1553 }
1554 strcpy(ptr, tmp);
1555 ptr += strlen(tmp);
1556 }
1557 strcpy(tmp,"\n");
1558 strcpy(ptr, tmp);
1559}
1560
1561void print_service_short(short *buff, int size)
1562{
1563int i,j;
1564char *asc, *ptr, str[80], tmp[256];
1565short last[8];
1566
1567 asc = (char *)buff;
1568 ptr = Service_content_str;
1569 ptr += strlen(Service_content_str);
1570 for( i = 0; i < size; i++)
1571 {
1572 strcpy(tmp,"");
1573 if(i%8 == 0)
1574 {
1575 if(i != 0)
1576 {
1577 strcat(tmp," ");
1578 }
1579 sprintf(str,"%5d ",i);
1580 strcat(tmp,str);
1581 }
1582 if(!(i%8))
1583 strcat(tmp,"H: ");
1584 sprintf(str," %04X",buff[i]);
1585 strcat(tmp,str);
1586 last[i%8] = buff[i];
1587 if((i%8 == 7) || (i == (size-1)))
1588 {
1589 /*
1590 if(i%7 != 7)
1591 {
1592 for(j = 1; j < 8 - (i%8); j++)
1593 strcat(tmp," ");
1594 }
1595 strcat(tmp," '");
1596 for(j = 0; j < ((i%8)*2)+2 ; j++)
1597 {
1598 if(isprint(asc[j]))
1599 {
1600 sprintf(str,"%c",asc[j]);
1601 strcat(tmp,str);
1602 }
1603 else
1604 {
1605 sprintf(str,".");
1606 strcat(tmp,str);
1607 }
1608 }
1609 */
1610 strcat(tmp,"\n");
1611 for(j = 0; j <= (i%8); j++)
1612 {
1613 if(j == 0)
1614 strcat(tmp," D: ");
1615 sprintf(str," %5d",last[j]);
1616 strcat(tmp,str);
1617 }
1618 strcat(tmp,"\n");
1619 asc = (char *)&buff[i+1];
1620 }
1621 strcpy(ptr, tmp);
1622 ptr += strlen(tmp);
1623 }
1624 strcpy(tmp,"\n");
1625 strcpy(ptr, tmp);
1626}
1627
1628void print_service_char(char *buff, int size)
1629{
1630int i,j;
1631char *asc, *ptr, str[80], tmp[256];
1632char last[16];
1633
1634 asc = (char *)buff;
1635 ptr = Service_content_str;
1636 ptr += strlen(Service_content_str);
1637 for( i = 0; i < size; i++)
1638 {
1639 strcpy(tmp,"");
1640 if(i%16 == 0)
1641 {
1642 if(i != 0)
1643 {
1644 strcat(tmp," ");
1645 }
1646 sprintf(str,"%5d ",i);
1647 strcat(tmp,str);
1648 }
1649 if(!(i%16))
1650 strcat(tmp,"H: ");
1651 sprintf(str,"%02X",buff[i]);
1652/* strcat(tmp,str);
1653*/
1654 strcat(tmp," ");
1655 strcat(tmp,&str[strlen(str)-2]);
1656 last[i%16] = buff[i];
1657 /*
1658 if(i%4 == 3)
1659 strcat(tmp," ");
1660 */
1661 if((i%16 == 15) || (i == (size-1)))
1662 {
1663 if(i%16 != 15)
1664 {
1665 for(j = 1; j < 16 - (i%16); j++)
1666 strcat(tmp," ");
1667 }
1668 strcat(tmp," '");
1669 for(j = 0; j <= (i%16) ; j++)
1670 {
1671 if(isprint(asc[j]))
1672 {
1673 sprintf(str,"%c",asc[j]);
1674 strcat(tmp,str);
1675 }
1676 else
1677 {
1678 sprintf(str,".");
1679 strcat(tmp,str);
1680 }
1681 }
1682 strcat(tmp,"'\n");
1683 asc = (char *)&buff[i+1];
1684 }
1685 strcpy(ptr, tmp);
1686 ptr += strlen(tmp);
1687 }
1688 strcpy(tmp,"\n");
1689 strcpy(ptr, tmp);
1690}
1691
1692void print_service_float(float *buff, int size)
1693{
1694int i;
1695char *ptr, str[80], tmp[256];
1696
1697 ptr = Service_content_str;
1698 ptr += strlen(Service_content_str);
1699 for( i = 0; i < size; i++)
1700 {
1701 strcpy(tmp,"");
1702 if(i%4 == 0)
1703 {
1704 if(i != 0)
1705 {
1706 strcat(tmp," ");
1707 }
1708 sprintf(str," %5d: ",i);
1709 strcat(tmp,str);
1710 }
1711 sprintf(str,"%12.3G",*(buff++));
1712 strcat(tmp,str);
1713 if((i%4 == 3) || (i == size-1))
1714 {
1715 strcat(tmp,"\n");
1716 }
1717 strcpy(ptr, tmp);
1718 ptr += strlen(tmp);
1719 }
1720 strcpy(tmp,"\n");
1721 strcpy(ptr, tmp);
1722 ptr += strlen(tmp);
1723}
1724
1725void print_service_double(double *buff, int size)
1726{
1727int i;
1728char *ptr, str[80], tmp[256];
1729
1730 ptr = Service_content_str;
1731 ptr += strlen(Service_content_str);
1732 for( i = 0; i < size; i++)
1733 {
1734 strcpy(tmp,"");
1735 if(i%4 == 0)
1736 {
1737 if(i != 0)
1738 {
1739 strcat(tmp," ");
1740 }
1741 sprintf(str," %5d: ",i);
1742 strcat(tmp,str);
1743 }
1744 sprintf(str,"%12.3G",*(buff++));
1745 strcat(tmp,str);
1746 if((i%4 == 3) || (i == size-1))
1747 {
1748 strcat(tmp,"\n");
1749 }
1750 strcpy(ptr, tmp);
1751 ptr += strlen(tmp);
1752 }
1753 strcpy(tmp,"\n");
1754 strcpy(ptr, tmp);
1755 ptr += strlen(tmp);
1756}
1757
1758void ok_pop_up (Widget w, long tag, unsigned long *reason)
1759{
1760Widget id, sel_id;
1761char *str, *pstr;
1762void recv_service_info();
1763void did_prepare_command();
1764void show_servers();
1765
1766/*
1767 if(tag == 5)
1768 {
1769 id = (Widget)XmSelectionBoxGetChild(w,XmDIALOG_TEXT);
1770 str = (char *)XmTextGetString(id);
1771 if(!str[0])
1772 {
1773 XtFree(str);
1774 return;
1775 }
1776 if( ( fptr = fopen( str, "w" ) ) == (FILE *)0 )
1777 {
1778 printf("Cannot open: %s for writing\n",str);
1779 return;
1780 }
1781 ptr = &Curr_servp->server;
1782 if (ptr->pid > 0x1000000)
1783 fprintf(fptr,"Server %s (pid = %X) on node %s\n provides %d services :\n",
1784 Curr_servp->name, ptr->pid, ptr->node, ptr->n_services);
1785 else
1786 fprintf(fptr,"Server %s (pid = %d) on node %s\n provides %d services :\n",
1787 Curr_servp->name, ptr->pid, ptr->node, ptr->n_services);
1788 service_ptr = Curr_servp->service_ptr;
1789 for(i=0;i<ptr->n_services; i++)
1790 {
1791 sprintf(str,service_ptr->name);
1792 fprintf(fptr," %s\n",service_ptr->name);
1793 service_ptr++;
1794 }
1795 fclose(fptr);
1796 XtFree(str);
1797 return;
1798 }
1799 if(tag == 4)
1800 {
1801 sel_id = put_selection(4, "Printing...");
1802 id = (Widget)XmSelectionBoxGetChild(sel_id,XmDIALOG_HELP_BUTTON);
1803 XtUnmanageChild(id);
1804
1805 id = (Widget)XmSelectionBoxGetChild(sel_id,XmDIALOG_APPLY_BUTTON);
1806 XtUnmanageChild(id);
1807 id = (Widget)XmSelectionBoxGetChild(sel_id,XmDIALOG_TEXT);
1808 str = (char *)XmTextGetString(id);
1809 if(!str[0])
1810 {
1811 XtFree(str);
1812 return;
1813 }
1814 ptr = &Curr_servp->server;
1815 if(pstr = strrchr(str,']'))
1816 *(++pstr) = '\0';
1817 if(pstr = strrchr(str,'/'))
1818 *(++pstr) = '\0';
1819 sprintf(txt_str,"%s%s.TXT",str,Curr_servp->name);
1820 XtFree(str);
1821 XmTextSetString(id, txt_str);
1822 return;
1823 }
1824*/
1825 if(reason){}
1826 if(tag == DID_KILL_ALL)
1827 {
1828 dic_cmnd_service("DIS_DNS/KILL_SERVERS",0,0);
1829 return;
1830 }
1831 id = XmSelectionBoxGetChild(w,XmDIALOG_TEXT);
1832 str = XmTextGetString(id);
1833 if(!str[0])
1834 {
1835 XtFree(str);
1836 return;
1837 }
1838 if ((tag == DID_SEL_NODE) || (tag == DID_SEL_SERVICE))
1839 {
1840 strcpy(Curr_view_opt_par, str);
1841 show_servers();
1842 XtFree(str);
1843 }
1844 if(tag == DID_SERVICES)
1845 {
1846 pstr = strchr(str,' ');
1847 if(!pstr)
1848 {
1849 strcpy(Curr_service_name, str);
1850 strcpy(str,"SVC");
1851 }
1852 else
1853 {
1854 pstr++;
1855 strcpy(Curr_service_name, pstr);
1856 }
1857 if(Curr_service_id)
1858 {
1859 dic_release_service(Curr_service_id);
1860 Curr_service_id = 0;
1861 }
1862 if(str[0] == 'S')
1863 {
1864 /*
1865 if((!strstr(pstr,"/SERVICE_LIST")) &&
1866 (!strstr(pstr,"/CLIENT_LIST")) &&
1867 (!strstr(pstr,"/SERVER_LIST")))
1868 {
1869 Curr_service_id = dic_info_service(Curr_service_name,
1870 MONITORED,5,0,0,
1871 recv_service_info,0,
1872 &no_link_int,4);
1873 }
1874 else
1875 {
1876 */
1877 dic_info_service_stamped(Curr_service_name,
1878 ONCE_ONLY,10,0,0,
1879 recv_service_info,0,
1880 &no_link_int,4);
1881 /*
1882 }
1883 */
1884 put_selection(DID_SERVICE,"Service Contents");
1885 }
1886 else
1887 {
1888 get_service_format();
1889 sel_id = put_selection(DID_COMMAND,"Send Command");
1890 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_HELP_BUTTON);
1891 XtUnmanageChild(id);
1892 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_APPLY_BUTTON);
1893 XtUnmanageChild(id);
1894 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_LIST);
1895 /*
1896 XtUnmanageChild(id);
1897 */
1898 XtUnmapWidget(id);
1899 }
1900 XtFree(str);
1901 }
1902 if(tag == DID_COMMAND)
1903 {
1904 did_prepare_command(str);
1905 XtFree(str);
1906 }
1907}
1908
1909int get_type_size(char type)
1910{
1911 int size;
1912
1913 switch(type)
1914 {
1915 case 'L':
1916 case 'l':
1917 size = sizeof(long);
1918 break;
1919 case 'I':
1920 case 'i':
1921 size = sizeof(int);
1922 break;
1923 case 'S':
1924 case 's':
1925 size = sizeof(short);
1926 break;
1927 case 'F':
1928 case 'f':
1929 size = sizeof(float);
1930 break;
1931 case 'D':
1932 case 'd':
1933 size = sizeof(double);
1934 break;
1935 case 'C':
1936 case 'c':
1937 default:
1938 size = 1;
1939 }
1940 return(size);
1941}
1942
1943void did_prepare_command(char *str)
1944{
1945char type;
1946int num;
1947int size, full_size = 0;
1948char *ptr;
1949static int last_size = 0;
1950static void *last_buffer = 0;
1951void *buffer_ptr;
1952char *str_ptr;
1953void did_read_string(char, int, void **, char **);
1954
1955 str_ptr = str;
1956 ptr = Curr_service_format;
1957 while(*ptr)
1958 {
1959 type = *ptr++;
1960 if(*ptr == ':')
1961 {
1962 ptr++;
1963 size = get_type_size(type);
1964 sscanf(ptr, "%d", &num);
1965 full_size += size * num;
1966 if( (ptr = strchr(ptr,';')) )
1967 ptr++;
1968 else
1969 break;
1970 }
1971 }
1972
1973 full_size += 256;
1974 if(full_size > last_size)
1975 {
1976 if(last_size)
1977 free(last_buffer);
1978 last_buffer = malloc(full_size);
1979 last_size = full_size;
1980 }
1981 buffer_ptr = last_buffer;
1982 ptr = Curr_service_format;
1983 while(*ptr)
1984 {
1985 type = *ptr++;
1986 if(*ptr == ':')
1987 {
1988 ptr++;
1989 sscanf(ptr, "%d", &num);
1990 did_read_string(type, num, &buffer_ptr, &str_ptr);
1991 if(!str_ptr)
1992 break;
1993 if( (ptr = strchr(ptr,';')) )
1994 ptr++;
1995 else
1996 break;
1997 }
1998 else
1999 {
2000 did_read_string(type, 0, &buffer_ptr, &str_ptr);
2001 break;
2002 }
2003 }
2004 full_size = (int) ((char *)buffer_ptr - (char *)last_buffer);
2005 dic_cmnd_service(Curr_service_name,last_buffer,full_size);
2006}
2007
2008int read_str_int(char *str)
2009{
2010 int i;
2011 if((str[0] == '0') && (str[1] == 'x'))
2012 sscanf(str+2,"%x",&i);
2013 else
2014 sscanf(str,"%d",&i);
2015 return(i);
2016}
2017
2018int read_str_char(char *str, char *cc)
2019{
2020
2021 if(str[0] == '\'')
2022 *cc = str[1];
2023 else if(str[0] == '\"')
2024 return(0);
2025 else if((str[0] == '0') && (str[1] == 'x'))
2026 sscanf(str+2,"%x",(int *)cc);
2027 else if(isalpha(str[0]))
2028 return(-1);
2029 else
2030 sscanf(str,"%d",(int *)cc);
2031 return(1);
2032}
2033
2034void did_read_string(char type, int num, void **buffer_ptr, char **str_ptr)
2035{
2036int i, ret = 0;
2037float ff;
2038double dd;
2039void *ptr;
2040char *strp, *ptr1;
2041char cc;
2042 short s;
2043
2044 strp = *str_ptr;
2045 ptr = *buffer_ptr;
2046 if(!num)
2047 num = 1000000;
2048 switch(type)
2049 {
2050 case 'L':
2051 case 'l':
2052 case 'I':
2053 case 'i':
2054 for(i = 0; i<num; i++)
2055 {
2056 *(int *)ptr = read_str_int(strp);
2057 ptr = (int *)ptr +1;
2058 if( (strp = strchr(strp,' ')) )
2059 strp++;
2060 else
2061 break;
2062 }
2063 break;
2064 case 'S':
2065 case 's':
2066 for(i = 0; i<num; i++)
2067 {
2068 s = (short)read_str_int(strp);
2069 *((short *)ptr) = s;
2070 ptr = (short *)ptr +1;
2071 if( (strp = strchr(strp,' ')) )
2072 strp++;
2073 else
2074 break;
2075 }
2076 break;
2077 case 'F':
2078 case 'f':
2079 for(i = 0; i<num; i++)
2080 {
2081 sscanf(strp,"%f",&ff);
2082 *(float *)ptr = ff;
2083 ptr = (float *)ptr +1;
2084 if( (strp = strchr(strp,' ')) )
2085 strp++;
2086 else
2087 break;
2088 }
2089 break;
2090 case 'D':
2091 case 'd':
2092 for(i = 0; i<num; i++)
2093 {
2094 sscanf(strp,"%f",&ff);
2095 dd = (double)ff;
2096 *(double *)ptr = dd;
2097 ptr = (double *)ptr +1;
2098 if( (strp = strchr(strp,' ')) )
2099 strp++;
2100 else
2101 break;
2102 }
2103 break;
2104 case 'C':
2105 case 'c':
2106 default:
2107 for(i = 0; i<num; i++)
2108 {
2109 if((ret = read_str_char(strp, &cc)) <= 0)
2110 break;
2111 *(char *)ptr = cc;
2112 ptr = (char *)ptr +1;
2113 if( (strp = strchr(strp,' ')) )
2114 strp++;
2115 else
2116 break;
2117 }
2118 if(ret <= 0)
2119 {
2120 if(!ret)
2121 {
2122 strp++;
2123 }
2124 num = strlen(strp)+1;
2125 strncpy((char *)ptr,strp,num);
2126 if( (ptr1 = (char *)strchr((char *)ptr,'\"')) )
2127 {
2128 num--;
2129 *ptr1 = '\0';
2130 }
2131 ptr = (char *)ptr + num;
2132 if( (strp = strchr(strp,' ')) )
2133 strp++;
2134 else
2135 break;
2136 }
2137 }
2138 *buffer_ptr = ptr;
2139 *str_ptr = strp;
2140}
2141
2142void cancel_pop_up (Widget w, int tag, unsigned long *reason)
2143{
2144 void print_service_formatted();
2145
2146 if(reason){}
2147 if(tag == MAX_POP_UPS+1)
2148 {
2149 print_service_formatted(Service_buffer,Service_size);
2150 set_something(Content_label_id,XmNlabelString, Service_content_str);
2151 Curr_service_print_type = 0;
2152 }
2153 /*
2154 else if(tag == MAX_POP_UPS+2)
2155 {
2156 print_service_float(Service_buffer, ((Service_size - 1) / 4) + 1);
2157 set_something(Content_label_id,XmNlabelString, Service_content_str);
2158 Curr_service_print_type = 1;
2159 }
2160 else if(tag == MAX_POP_UPS+3)
2161 {
2162 print_service_double(Service_buffer, ((Service_size - 1) / 4) + 1);
2163 set_something(Content_label_id,XmNlabelString, Service_content_str);
2164 Curr_service_print_type = 2;
2165 }
2166 */
2167 else if(tag == MAX_POP_UPS+4)
2168 {
2169
2170 if((!strstr(Curr_service_name,"/SERVICE_LIST")) &&
2171 (!strstr(Curr_service_name,"/CLIENT_LIST")) &&
2172 (!strstr(Curr_service_name,"/SERVER_LIST")))
2173 {
2174 if(Curr_service_id)
2175 {
2176 dic_release_service(Curr_service_id);
2177 Curr_service_id = 0;
2178 }
2179 Curr_service_id = dic_info_service_stamped(Curr_service_name,
2180 MONITORED,10,0,0,
2181 recv_service_info,0,
2182 &no_link_int,4);
2183 }
2184 XtSetSensitive(w, False);
2185 XtSetSensitive(SubscribeButton, True);
2186 }
2187 else if(tag == MAX_POP_UPS+5)
2188 {
2189
2190 if((!strstr(Curr_service_name,"/SERVICE_LIST")) &&
2191 (!strstr(Curr_service_name,"/CLIENT_LIST")) &&
2192 (!strstr(Curr_service_name,"/SERVER_LIST")))
2193 {
2194 if(Curr_service_id)
2195 {
2196 dic_release_service(Curr_service_id);
2197 Curr_service_id = 0;
2198 }
2199 Curr_service_id = dic_info_service_stamped(Curr_service_name,
2200 MONITORED,0,0,0,
2201 recv_service_info,0,
2202 &no_link_int,4);
2203 }
2204 XtSetSensitive(w, False);
2205 XtSetSensitive(Subscribe10Button, True);
2206 }
2207/*
2208 else if(tag == 5)
2209 {
2210 *
2211 XtUnmapWidget(XtParent(pop_widget_id[4]));
2212 *
2213 }
2214*/
2215 else if(tag == DID_SERVICE)
2216 {
2217 if(Curr_service_id)
2218 {
2219 dic_release_service(Curr_service_id);
2220 Curr_service_id = 0;
2221 }
2222 XtUnmanageChild(pop_widget_id[DID_SERVICE]);
2223 free(Service_content_str);
2224 free(Service_buffer);
2225 }
2226}
2227
2228void create_matrix(Widget w, int *tag, unsigned long *reason)
2229{
2230
2231 if(reason){}
2232 Matrix_id[*tag] = w;
2233 if(*tag)
2234 XtUnmanageChild(w);
2235 else
2236 Curr_matrix = 0;
2237}
2238
2239void create_label(Widget w, int *tag, unsigned long *reason)
2240{
2241 if(reason){}
2242 if(!*tag)
2243 Label_id = w;
2244 else
2245 Content_label_id = w;
2246}
2247
2248void switch_matrix()
2249{
2250 /*
2251 XtUnmanageChild(Matrix_id[Curr_matrix]);
2252 Curr_matrix = (Curr_matrix) ? 0 : 1;
2253 XtManageChild(Matrix_id[Curr_matrix]);
2254 */
2255 XmScrolledWindowSetAreas(Window_id,NULL, NULL, Matrix_id[Curr_matrix]);
2256}
2257
2258/*
2259static int curr_allocated_size = 0;
2260static DNS_SERVER_INFO *dns_info_buffer;
2261*/
2262
2263void update_servers_new(int *tag, char *buffer, int *size)
2264{
2265 if(tag){}
2266 if(size){}
2267 printf("Server_list:\n%s\n",buffer);
2268}
2269
2270SERVER *find_server(char *node, int pid)
2271{
2272 SERVER *servp;
2273 DNS_SERVER_INFO *ptr;
2274
2275 servp = Server_head;
2276 while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
2277 {
2278 ptr = &servp->server;
2279 if((ptr->pid == pid) && (!strcmp(ptr->node,node)))
2280 {
2281 return(servp);
2282 }
2283 }
2284 return ((SERVER *)0);
2285}
2286 /*
2287 if(!(servp = (SERVER *)sll_search((SLL *)Server_head,
2288 (char *)&buffer->server, MAX_NODE_NAME+MAX_TASK_NAME-4)))
2289 */
2290
2291
2292void update_servers(int *tag, DNS_DID *buffer, int *size)
2293{
2294int n_services, service_size;
2295SERVER *servp;
2296int j;
2297char str[MAX_NAME], sname[MAX_NAME], *ptr;
2298
2299 if(tag){}
2300 if(!Server_head)
2301 {
2302 Server_head = (SERVER *)malloc(sizeof(SERVER));
2303 sll_init((SLL *)Server_head);
2304 }
2305 if(First_time)
2306 {
2307 switch_matrix();
2308 First_time = 0;
2309 }
2310
2311 if(!*size)
2312 return;
2313 if(*(char *)buffer == -1)
2314 {
2315 N_servers = 0;
2316 N_services = 0;
2317 return;
2318 }
2319 buffer->server.n_services = vtohl(buffer->server.n_services);
2320 buffer->server.pid = vtohl(buffer->server.pid);
2321 n_services = buffer->server.n_services;
2322
2323 if(n_services == 1)
2324 return;
2325 strcpy(sname, buffer->server.task);
2326 if(n_services > 1)
2327 {
2328 for(j = 0; j < n_services; j++)
2329 {
2330 buffer->services[j].type = vtohl(
2331 buffer->services[j].type);
2332 buffer->services[j].status = vtohl(
2333 buffer->services[j].status);
2334 buffer->services[j].n_clients = vtohl(
2335 buffer->services[j].n_clients);
2336 if(strlen(sname) == MAX_TASK_NAME-4-1)
2337 {
2338 strcpy(str,buffer->services[j].name);
2339 if( (ptr = strstr(str,"/CLIENT_LIST")) )
2340 {
2341 *ptr = '\0';
2342 strcpy(sname,str);
2343 }
2344 }
2345 }
2346 }
2347 if (!(servp = find_server(buffer->server.node,buffer->server.pid)))
2348 /*
2349 if(!(servp = (SERVER *)sll_search((SLL *)Server_head,
2350 (char *)&buffer->server, MAX_NODE_NAME+MAX_TASK_NAME-4)))
2351 */
2352 {
2353 if(n_services)
2354 {
2355 servp = (SERVER *)malloc(sizeof(SERVER));
2356 strcpy(servp->name,sname);
2357 servp->next = 0;
2358 servp->button_id = 0;
2359 servp->pop_widget_id[0] = 0;
2360 servp->pop_widget_id[1] = 0;
2361 servp->busy = 0;
2362 servp->server.n_services = 0;
2363 servp->service_ptr = 0;
2364 sll_insert_queue((SLL *)Server_head,(SLL *)servp);
2365 }
2366 }
2367 if(n_services != 0)
2368 {
2369 if(n_services == servp->server.n_services)
2370 {
2371 return;
2372 }
2373 if(servp->server.n_services == 0)
2374 N_servers++;
2375 if(servp->server.n_services != -1)
2376 N_services -= servp->server.n_services;
2377 memcpy(&servp->server,&buffer->server,sizeof(DNS_SERVER_INFO));
2378 if(servp->service_ptr)
2379 {
2380 free(servp->service_ptr);
2381 servp->service_ptr = 0;
2382 }
2383 if(n_services != -1)
2384 {
2385 service_size = n_services*sizeof(DNS_SERVICE_INFO);
2386 servp->service_ptr = (DNS_SERVICE_INFO *)malloc(service_size);
2387 memcpy(servp->service_ptr, buffer->services, service_size);
2388 N_services += n_services;
2389 }
2390 servp->busy = 1;
2391 }
2392 else
2393 {
2394 if(servp)
2395 {
2396 N_servers--;
2397 if(servp->server.n_services != -1)
2398 {
2399 N_services -= servp->server.n_services;
2400 }
2401 else
2402 Force_update = 1;
2403 servp->server.n_services = 0;
2404 servp->busy = -1;
2405 }
2406 }
2407}
2408
2409void show_servers()
2410{
2411SERVER *servp;
2412void update_show_servers();
2413void remove_all_buttons();
2414void put_label();
2415
2416 if(!Matrix_id[Curr_matrix])
2417 return;
2418 remove_all_buttons();
2419
2420#ifndef linux
2421 switch_matrix();
2422#endif
2423 put_label();
2424 servp = Server_head;
2425 while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
2426 {
2427 servp->busy = 1;
2428 }
2429 Force_update = 1;
2430}
2431
2432void update_show_servers(void *tag, unsigned long *reason)
2433{
2434DNS_SERVER_INFO *server_ptr;
2435DNS_SERVICE_INFO *service_ptr;
2436int i, j, found, n_done = 0;
2437Widget w, create_button();
2438SERVER *servp, *prevp;
2439static int old_n_services = 0;
2440char node[MAX_NODE_NAME], par[MAX_NODE_NAME], *ptr;
2441void remove_button();
2442void remove_all_buttons();
2443void put_label();
2444
2445 DISABLE_AST
2446 if(tag){}
2447 if(reason){}
2448 if((N_services != old_n_services) || (Force_update))
2449 {
2450 if(!Matrix_id[Curr_matrix])
2451 {
2452 XtAppAddTimeOut(app_context, 1000, update_show_servers, 0);
2453 ENABLE_AST
2454 return;
2455 }
2456 if(!N_servers)
2457 {
2458 remove_all_buttons();
2459 if(! No_link_button_id)
2460 {
2461 No_link_button_id = create_button("DNS is down", 0);
2462 set_color(No_link_button_id, XmNbackground, RED);
2463 get_something(No_link_button_id,XmNuserData,&w);
2464 set_color(w, XmNbackground, RED);
2465 XtSetSensitive(No_link_button_id, False);
2466 }
2467 while(!sll_empty((SLL *)Server_head))
2468 {
2469 servp = (SERVER *)sll_remove_head((SLL *)Server_head);
2470 if(servp->service_ptr)
2471 free(servp->service_ptr);
2472 free(servp);
2473 }
2474 put_label();
2475 old_n_services = N_services;
2476 Force_update = 0;
2477 XtAppAddTimeOut(app_context, 1000, update_show_servers, 0);
2478 ENABLE_AST
2479 return;
2480 }
2481 if(No_link_button_id)
2482 {
2483 XtDestroyWidget(No_link_button_id);
2484 /*
2485 XFlush(XtDisplay(No_link_button_id));
2486 */
2487 No_link_button_id = 0;
2488 }
2489 servp = Server_head;
2490 prevp = 0;
2491 while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
2492 {
2493 if(prevp)
2494 {
2495 free(prevp);
2496 prevp = 0;
2497 }
2498 if(n_done == 10)
2499 {
2500 if(!Force_update)
2501 put_label();
2502 XtAppAddTimeOut(app_context, 100, update_show_servers, 0);
2503 ENABLE_AST
2504 return;
2505 }
2506 server_ptr = &servp->server;
2507 if(servp->busy == 1)
2508 {
2509 if(!servp->button_id)
2510 {
2511 switch(Curr_view_opt)
2512 {
2513 case 1 :
2514 servp->button_id = create_button(/*server_ptr->task*/servp->name, servp);
2515 n_done++;
2516 break;
2517 case 0 :
2518 strcpy(node, server_ptr->node);
2519 strcpy(par, Curr_view_opt_par);
2520 ptr = strchr(node, '.');
2521 if(ptr)
2522 *ptr = '\0';
2523 ptr = strchr(par,'.');
2524 if(ptr)
2525 *ptr = '\0';
2526 ptr = node;
2527 for(i = 0; i < (int)strlen(ptr); i++)
2528 ptr[i] = tolower(ptr[i]);
2529 ptr = par;
2530 for(i = 0; i < (int)strlen(ptr); i++)
2531 ptr[i] = tolower(ptr[i]);
2532 if(!strcmp(/*server_ptr->*/node, /*Curr_view_opt_*/par))
2533 {
2534 servp->button_id = create_button(/*server_ptr->task*/servp->name, servp);
2535 n_done++;
2536 }
2537 break;
2538 case 2 :
2539 found = 0;
2540 if(!(service_ptr = servp->service_ptr))
2541 break;
2542 for(j = 0; j < server_ptr->n_services; j++)
2543 {
2544 if(strstr(service_ptr->name, Curr_view_opt_par) > (char *)0)
2545 {
2546 found = 1;
2547 break;
2548 }
2549 service_ptr++;
2550 }
2551 if (found)
2552 {
2553 servp->button_id = create_button(/*server_ptr->task*/servp->name, servp);
2554 n_done++;
2555 }
2556 break;
2557 case 3 :
2558 if(server_ptr->n_services == -1)
2559 {
2560 servp->button_id = create_button(/*server_ptr->task*/servp->name, servp);
2561 n_done++;
2562 }
2563 else
2564 {
2565 if(servp->button_id)
2566 remove_button(servp);
2567 }
2568 n_done++;
2569 break;
2570 }
2571 }
2572 servp->busy = 2;
2573 if(servp->button_id)
2574 {
2575 if(Curr_view_opt != -1)
2576 {
2577 if (server_ptr->n_services == -1)
2578 {
2579 set_color(servp->button_id, XmNbackground, RED);
2580 get_something(servp->button_id,XmNuserData,&w);
2581 set_color(w, XmNbackground, RED);
2582 }
2583 else
2584 {
2585 set_color(servp->button_id, XmNbackground, GREEN);
2586 get_something(servp->button_id,XmNuserData,&w);
2587 set_color(w, XmNbackground, GREEN);
2588 }
2589 }
2590 }
2591 }
2592 else if (servp->busy == -1)
2593 {
2594 remove_button(servp);
2595 sll_remove((SLL *)Server_head, (SLL *)servp);
2596 if(servp->service_ptr)
2597 {
2598 free(servp->service_ptr);
2599 servp->service_ptr = 0;
2600 }
2601 prevp = servp;
2602 n_done++;
2603 }
2604 }
2605 if(prevp)
2606 {
2607 free(prevp);
2608 prevp = 0;
2609 }
2610 put_label();
2611 old_n_services = N_services;
2612 Force_update = 0;
2613 }
2614 XtAppAddTimeOut(app_context, 1000, update_show_servers, 0);
2615 ENABLE_AST
2616}
2617
2618Widget create_button(char *name, SERVER *servp)
2619{
2620Arg arglist[10];
2621int n, n_services = -1;
2622Widget w, ww, w_id;
2623void activate_services(), activate_clients();
2624char w_name[MAX_NAME];
2625
2626 w_name[0] = 0;
2627 if(servp)
2628 n_services = servp->server.n_services;
2629 strcpy(w_name,name);
2630 if(strlen(w_name) >= MAX_TASK_NAME - 4)
2631 w_name[16] = '\0';
2632 n = 0;
2633 XtSetArg(arglist[n], XmNorientation, XmVERTICAL); n++;
2634 XtSetArg(arglist[n], XmNentryAlignment, XmALIGNMENT_CENTER); n++;
2635 w_id = w = XmCreateMenuBar(Matrix_id[Curr_matrix],
2636 (String)XmStringCreateLtoR ( w_name,XmSTRING_DEFAULT_CHARSET),
2637 arglist,n);
2638/*
2639 if(n_services == -1)
2640 set_color(w, XmNbackground, RED);
2641 else
2642 set_color(w, XmNbackground, GREEN);
2643*/
2644 XtManageChild(w);
2645 strcat(w_name,"1");
2646 n = 0;
2647 XtSetArg(arglist[n], XmNalignment, XmALIGNMENT_CENTER); n++;
2648 XtSetArg(arglist[n], XmNfontList, did_server_font); n++;
2649 w = XmCreateCascadeButton(w,
2650 (String)XmStringCreateLtoR ( w_name,XmSTRING_DEFAULT_CHARSET),
2651 arglist,n);
2652 set_something(w,XmNlabelString,name);
2653 set_something(w,XmNalignment,XmALIGNMENT_CENTER);
2654/*
2655 if(n_services == -1)
2656 set_color(w, XmNbackground, RED);
2657 else
2658 set_color(w, XmNbackground, GREEN);
2659*/
2660 set_something(w_id,XmNuserData,w);
2661 strcat(w_name,"1");
2662 n = 0;
2663 ww = XmCreatePulldownMenu(w_id,
2664 (String)XmStringCreateLtoR ( w_name,XmSTRING_DEFAULT_CHARSET),
2665 arglist,n);
2666 set_something(w,XmNsubMenuId,ww);
2667 XtManageChild(w);
2668 strcat(w_name,"1");
2669 n = 0;
2670 XtSetArg(arglist[n], XmNfontList, did_default_font); n++;
2671 w = XmCreatePushButton(ww,
2672 (String)XmStringCreateLtoR ( w_name,XmSTRING_DEFAULT_CHARSET),
2673 arglist,n);
2674
2675 set_something(w,XmNlabelString,"Services");
2676 if(servp)
2677 {
2678 XtAddCallback(w,XmNactivateCallback, activate_services, servp);
2679 XtManageChild(w);
2680 strcat(w_name,"1");
2681 n = 0;
2682 XtSetArg(arglist[n], XmNfontList, did_default_font); n++;
2683 w = XmCreatePushButton(ww,
2684 (String)XmStringCreateLtoR ( w_name,XmSTRING_DEFAULT_CHARSET),
2685 arglist,n);
2686
2687 set_something(w,XmNlabelString,"Clients");
2688 XtAddCallback(w,XmNactivateCallback, activate_clients, servp);
2689 XtManageChild(w);
2690 /*
2691 servp->popping = 0;
2692 create_client_popup(servp);
2693 */
2694 }
2695 return(w_id);
2696}
2697
2698void remove_all_buttons()
2699{
2700SERVER *servp;
2701
2702 servp = Server_head;
2703 while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
2704 {
2705 if(servp->button_id)
2706 {
2707 XtDestroyWidget(servp->button_id);
2708 servp->button_id = 0;
2709 servp->busy = 0;
2710 }
2711 }
2712}
2713
2714void remove_button(SERVER *servp)
2715{
2716
2717 if(servp->button_id)
2718 {
2719 XtDestroyWidget(servp->button_id);
2720 servp->button_id = 0;
2721 servp->busy = 0;
2722 }
2723}
2724
2725void activate_services(Widget w, SERVER *servp, unsigned long *reason)
2726{
2727DNS_SERVER_INFO *ptr;
2728char str[MAX_NAME];
2729Widget id,sel_id;
2730void got_service_list();
2731void kick_it();
2732
2733 if(w){}
2734 if(reason){}
2735 if(servp->pop_widget_id[0])
2736 {
2737 XtDestroyWidget(servp->pop_widget_id[0]);
2738 servp->pop_widget_id[0] = 0;
2739 /*
2740 return;
2741 */
2742 }
2743 Curr_servp = servp;
2744 ptr = &servp->server;
2745
2746 sel_id = put_popup(servp, 0,"Service Info");
2747
2748 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_OK_BUTTON);
2749 XtUnmanageChild(id);
2750
2751 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_LIST_LABEL);
2752 if (ptr->pid > 0x1000000)
2753 sprintf(str,"Server %s (pid = %X) on node %s\n\nprovides %d services :\n",
2754 servp->name, ptr->pid, ptr->node, ptr->n_services);
2755 else
2756 sprintf(str,"Server %s (pid = %d) on node %s\n\nprovides %d services :\n",
2757 servp->name, ptr->pid, ptr->node, ptr->n_services);
2758 set_something(sel_id,XmNlistLabelString,str);
2759
2760 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_LIST);
2761 Curr_service_list_id = id;
2762
2763 XmListAddItem(id,create_str(
2764 "Ordering services alphabeticaly, please be patient..."),1);
2765
2766 set_something(id,XmNlistItemCount,1);
2767 set_something(id,XmNlistVisibleItemCount,1);
2768
2769 sprintf(str,"%s/SERVICE_LIST",/*ptr->task*/servp->name);
2770 dic_info_service(str,ONCE_ONLY,20,0,0,
2771 got_service_list,(long)servp,"None",5);
2772 /*
2773#ifdef solaris
2774 */
2775 /*
2776 XtAppAddTimeOut(app_context, 1000, kick_it, 0);
2777 */
2778 /*
2779#endif
2780 */
2781}
2782
2783void kick_it()
2784{
2785 printf("kick_it\n");
2786}
2787
2788typedef char DID_SLOT[MAX_NAME];
2789
2790void got_service_list(SERVER **servp_ptr, char *buffer, int *size)
2791{
2792SERVER *servp;
2793void do_got_service_list();
2794
2795 if(size){}
2796 servp = *servp_ptr;
2797 if(Curr_service_list)
2798 free(Curr_service_list);
2799 Curr_service_list = malloc(strlen(buffer)+1);
2800 strcpy(Curr_service_list, buffer);
2801 /*
2802#ifdef solaris
2803 */
2804 Got_Service_List = servp;
2805 /*
2806#else
2807 do_got_service_list(servp);
2808#endif
2809 */
2810}
2811
2812void do_got_service_list(SERVER *servp)
2813{
2814char cmd_str[256], svc_str[256];
2815DNS_SERVER_INFO *ptr;
2816DNS_SERVICE_INFO *service_ptr;
2817Widget id;
2818char *curr_str, max_str[MAX_NAME], *sptr;
2819DID_SLOT *service_list;
2820int i, j, curr_index = 0, n_services;
2821XmString xstr;
2822void delete_str();
2823
2824 ptr = &servp->server;
2825 id = Curr_service_list_id;
2826
2827 XmListDeleteAllItems(id);
2828
2829 strcpy(cmd_str,"CMD: ");
2830 strcpy(svc_str,"SVC: ");
2831
2832 service_ptr = servp->service_ptr;
2833 service_list = (DID_SLOT *)malloc(ptr->n_services * MAX_NAME);
2834 n_services = ptr->n_services;
2835
2836 for(i=0;i<n_services; i++)
2837 {
2838 strcpy(service_list[i],service_ptr->name);
2839 service_ptr++;
2840 }
2841 strcpy(max_str,"zzzzzzzzzzzzzzzzzzzzzzzzzzzz");
2842 for(i=0;i<n_services; i++)
2843 {
2844 curr_str = max_str;
2845 for(j=0;j<n_services; j++)
2846 {
2847 sptr = service_list[j];
2848 if(!*sptr)
2849 continue;
2850
2851 if(strcmp(sptr,curr_str) < 0)
2852 {
2853 curr_str = sptr;
2854 curr_index = j;
2855 }
2856 }
2857 service_list[curr_index][0] = '\0';
2858 service_ptr = &(servp->service_ptr[curr_index]);
2859 if(service_ptr->type)
2860 {
2861 strcpy(&cmd_str[5],service_ptr->name);
2862 xstr = create_str(cmd_str);
2863 XmListAddItem(id,xstr,i+1);
2864 delete_str(xstr);
2865 }
2866 else
2867 {
2868 strcpy(&svc_str[5],service_ptr->name);
2869 xstr = create_str(svc_str);
2870 XmListAddItem(id,xstr,i+1);
2871 delete_str(xstr);
2872 }
2873 }
2874 free(service_list);
2875
2876 set_something(id,XmNlistItemCount,i);
2877 set_something(id,XmNlistVisibleItemCount,(i < 20) ? i : 20);
2878}
2879
2880void show_clients(SERVER **servp_ptr, char *buffer, int *size)
2881{
2882SERVER *servp;
2883void do_show_clients();
2884
2885 if(size){}
2886 servp = *servp_ptr;
2887 if(Curr_client_list)
2888 free(Curr_client_list);
2889 Curr_client_list = malloc(strlen(buffer)+1);
2890 strcpy(Curr_client_list, buffer);
2891 /*
2892#ifdef solaris
2893 */
2894 Got_Client_List = servp;
2895 /*
2896#else
2897 do_show_clients(servp);
2898#endif
2899 */
2900}
2901
2902void do_show_clients(SERVER *servp)
2903{
2904int i = 0;
2905char str[2048], *strp, *strp1;
2906DNS_SERVER_INFO *ptr;
2907XmString xstr;
2908void delete_str();
2909
2910 ptr = &servp->server;
2911 /*
2912 sel_id = servp->pop_widget_id[1];
2913 id = (Widget)XmSelectionBoxGetChild(sel_id,XmDIALOG_LIST_LABEL);
2914 */
2915 if(Curr_client_list[0] == -1)
2916 {
2917 sprintf(str,"Information not available\n");
2918 XmListAddItem(Curr_client_id,create_str(str),i+1);
2919 /*
2920 set_something(sel_id,XmNlistLabelString,str);
2921 */
2922 return;
2923 }
2924 /*
2925 sprintf(str,"Clients of %s are : \n",
2926 ptr->task);
2927 set_something(sel_id,XmNlistLabelString,str);
2928
2929 id = (Widget)XmSelectionBoxGetChild(sel_id,XmDIALOG_LIST);
2930 XmListDeleteAllItems(id);
2931 */
2932 strp1 = Curr_client_list;
2933 while(strp1)
2934 {
2935 if(!*strp1)
2936 break;
2937 sprintf(str,"Process ");
2938 strp = strp1;
2939 strp1 = strchr(strp,'@');
2940 *strp1 = '\0';
2941 strp1++;
2942 strcat(str,strp);
2943 strcat(str," on node ");
2944 strp = strp1;
2945 if( (strp1 = strchr(strp,'|')) )
2946 {
2947 *strp1 = '\0';
2948 strp1++;
2949 }
2950 strcat(str,strp);
2951 xstr = create_str(str);
2952 XmListAddItem(Curr_client_id,xstr,i+1);
2953 delete_str(xstr);
2954 i++;
2955 }
2956 if(!i)
2957 {
2958 sprintf(str,"NONE");
2959 xstr = create_str(str);
2960 XmListAddItem(Curr_client_id,xstr,i+1);
2961 delete_str(xstr);
2962 }
2963 /*
2964 set_something(id,XmNlistItemCount,i);
2965 */
2966 /*
2967 if(Matrix_id[Curr_matrix])
2968 XFlush(XtDisplay(Matrix_id[Curr_matrix]));
2969 */
2970}
2971
2972void activate_clients(Widget w, SERVER *servp, unsigned long *reason)
2973{
2974DNS_SERVER_INFO *ptr;
2975char str[100];
2976void show_clients();
2977void kick_it_again();
2978Widget id,sel_id;
2979
2980 if(w) {}
2981 if(reason){}
2982 Curr_servp = servp;
2983 ptr = &servp->server;
2984 if(servp->pop_widget_id[1])
2985 {
2986 XtDestroyWidget(servp->pop_widget_id[1]);
2987 servp->pop_widget_id[1] = 0;
2988 }
2989 sel_id = put_popup(servp,1,"Client Info");
2990
2991 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_HELP_BUTTON);
2992 XtUnmanageChild(id);
2993
2994 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_APPLY_BUTTON);
2995 XtUnmanageChild(id);
2996
2997 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_CANCEL_BUTTON);
2998 XtUnmanageChild(id);
2999
3000 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_TEXT);
3001 XtUnmanageChild(id);
3002
3003 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_SELECTION_LABEL);
3004 XtUnmanageChild(id);
3005 /*
3006 id = (Widget)XmSelectionBoxGetChild(sel_id,XmDIALOG_LIST_LABEL);
3007 */
3008 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_LIST);
3009 XmListDeleteAllItems(id);
3010
3011 Curr_client_id = id;
3012 sprintf(str,"Clients of %s are : \n",
3013 servp->name);
3014 set_something(sel_id,XmNlistLabelString,str);
3015
3016 sprintf(str,"%s/CLIENT_LIST",/*ptr->task*/servp->name);
3017 dic_info_service(str,ONCE_ONLY,10,0,0,
3018 show_clients,(long)servp,&no_link,1);
3019 /*
3020#ifdef solaris
3021 */
3022 /*
3023 XtAppAddTimeOut(app_context, 1000, kick_it_again, 0);
3024 */
3025 /*
3026#endif
3027 */
3028}
3029
3030void kick_it_again()
3031{
3032 printf("kick_it_again\n");
3033}
3034
3035Widget put_popup(SERVER *servp, int type, char *title)
3036{
3037 Widget id;
3038 void activate_services(), activate_clients();
3039 extern void set_title();
3040
3041 if(type)
3042 {
3043 id = create_client_dialog();
3044 /*
3045 XtAddCallback(id,XmNokCallback, activate_clients, servp);
3046 XtAddCallback(id,XmNcancelCallback, activate_clients, servp);
3047 */
3048 }
3049 else
3050 {
3051 id = create_server_dialog();
3052 /*
3053 XtAddCallback(id,XmNcancelCallback, activate_services, servp);
3054 */
3055 }
3056 servp->pop_widget_id[type] = id;
3057 /*
3058 }
3059 */
3060 XtManageChild(id);
3061 set_title(XtParent(id),title);
3062 return(id);
3063}
3064
3065Widget put_selection(int tag, char *title)
3066{
3067 Widget id = 0;
3068 extern void set_title();
3069
3070 if(pop_widget_id[tag])
3071 {
3072 XtDestroyWidget(pop_widget_id[tag]);
3073 }
3074 switch(tag)
3075 {
3076 case DID_SEL_NODE:
3077 id = create_node_selection();
3078 break;
3079 case DID_SEL_SERVICE:
3080 id = create_service_selection();
3081 break;
3082 case DID_KILL_ALL:
3083 id = create_kill_confirmation();
3084 break;
3085 case DID_SERVICE:
3086 id = create_service_dialog();
3087 break;
3088 case DID_COMMAND:
3089 id = create_send_command();
3090 break;
3091 }
3092
3093 pop_widget_id[tag] = id;
3094 XtManageChild(id);
3095 set_title(XtParent(id),title);
3096 return(id);
3097}
3098
3099void check_put_label(int tag)
3100{
3101 static int old_n_services = 0;
3102 static int changing = 0;
3103 void put_label();
3104
3105 if(tag){}
3106 if(N_services != old_n_services)
3107 {
3108 put_label();
3109 if(N_services > old_n_services)
3110 changing = 1;
3111 old_n_services = N_services;
3112
3113#ifdef linux
3114 show_servers();
3115#endif
3116 }
3117/*
3118 else
3119 {
3120 if(changing)
3121 {
3122 show_servers();
3123 changing = 0;
3124 }
3125 }
3126*/
3127}
3128
3129void put_label()
3130{
3131 char str[MAX_NAME], str1[MAX_NAME];
3132
3133 DISABLE_AST
3134 sprintf(str,"%d Servers known - %d Services Available\n",
3135 N_servers,N_services);
3136 switch(Curr_view_opt)
3137 {
3138 case 1 :
3139 strcat(str,"Displaying ALL Servers");
3140 break;
3141 case 0 :
3142 sprintf(str1,"Displaying Servers on node %s",Curr_view_opt_par);
3143 strcat(str,str1);
3144 break;
3145 case 2 :
3146 sprintf(str1,"Displaying Servers providing Service *%s*",
3147 Curr_view_opt_par);
3148 strcat(str,str1);
3149 break;
3150 case 3 :
3151 strcat(str,"Displaying Servers in ERROR");
3152 break;
3153 case -1 :
3154 strcat(str,"Please Select Viewing Option");
3155 break;
3156 }
3157 set_something(Label_id,XmNlabelString,str);
3158 XFlush(XtDisplay(Label_id));
3159 ENABLE_AST
3160}
3161
3162Widget create_client_dialog()
3163{
3164 Widget id;
3165 id = create_selection_dialog("Dismiss","","","","",DID_CLIENTS, 3);
3166 return(id);
3167
3168}
3169
3170Widget create_server_dialog()
3171{
3172 Widget id;
3173 id = create_selection_dialog("","View / Send","Dismiss","",
3174 "Service / Command :",
3175 DID_SERVICES, 20);
3176 return(id);
3177}
3178
3179Widget create_node_selection()
3180{
3181 Widget id;
3182 id = create_selection_dialog("","","","Nodes :","Selected Node :",DID_SEL_NODE, 8);
3183 return(id);
3184
3185}
3186
3187Widget create_service_selection()
3188{
3189 Widget id;
3190 /*
3191 id = create_prompt_dialog("Enter Service Name :",DID_SEL_SERVICE);
3192 */
3193 id = create_selection_dialog("","","","","Enter Service Name (or search string):",DID_SEL_SERVICE, 0);
3194 return(id);
3195
3196}
3197
3198Widget create_send_command()
3199{
3200 Widget id;
3201 char str[256], str1[256];
3202
3203 sprintf(str,"Command to %s (%s)\n\n",
3204 Curr_service_name, Curr_service_format);
3205
3206 id = create_selection_dialog("","","",str,"Command:",DID_COMMAND, 1);
3207
3208 strcpy(str1,"Please enter items separated by spaces:\n(for example: 2 0x123 'A' 23.4 \"a text\")");
3209
3210 set_something(id,XmNselectionLabelString,str1);
3211
3212 return(id);
3213
3214}
3215
3216Widget create_kill_confirmation()
3217{
3218 Widget id;
3219 id = create_question_dialog("Do you really want to kill ALL DIM servers ?",
3220 DID_KILL_ALL);
3221 return(id);
3222
3223}
3224
3225Widget create_selection_dialog(char *ok, char *apply, char *cancel, char *list, char *sel,
3226 long tag, int items)
3227{
3228Widget sd;
3229XmString xmOk, xmApply, xmCancel, xmList, xmSelection;
3230Arg ar[20];
3231int n;
3232
3233 xmList = create_str(list);
3234 xmOk = create_str(ok);
3235 xmApply = create_str(apply);
3236 xmCancel = create_str (cancel);
3237 xmSelection = create_str (sel);
3238
3239 n = 0;
3240 /*
3241 XtSetArg(ar[n],XmNdialogStyle,XmDIALOG_FULL_APPLICATION_MODAL); n++;
3242 XtSetArg(ar[n],XmNmwmFunctions,MWM_FUNC_MOVE); n++;
3243 */
3244 XtSetArg(ar[n],XmNtitle,"Selection"); n++;
3245 XtSetArg(ar[n],XmNlabelFontList, did_default_font); n++;
3246 XtSetArg(ar[n],XmNbuttonFontList, did_default_font); n++;
3247 XtSetArg(ar[n],XmNtextFontList, did_small_font); n++;
3248 XtSetArg(ar[n],XmNborderWidth, 1); n++;
3249 XtSetArg(ar[n],XmNlistLabelString, xmList); n++;
3250 XtSetArg(ar[n],XmNlistVisibleItemCount,items); n++;
3251 if(ok[0])
3252 {
3253 XtSetArg(ar[n],XmNokLabelString, xmOk); n++;
3254 }
3255 if(apply[0])
3256 {
3257 XtSetArg(ar[n],XmNapplyLabelString, xmApply); n++;
3258 }
3259 if(cancel[0])
3260 {
3261 XtSetArg(ar[n],XmNcancelLabelString, xmCancel); n++;
3262 }
3263 if(sel[0])
3264 {
3265 XtSetArg(ar[n],XmNselectionLabelString, xmSelection); n++;
3266 }
3267 sd = XmCreateSelectionDialog ( toplevel_widget, "Selection", ar, n );
3268 XmStringFree(xmList);
3269 XmStringFree(xmOk);
3270 XmStringFree(xmApply);
3271 XmStringFree(xmCancel);
3272 XmStringFree(xmSelection);
3273 if(tag >= 0)
3274 {
3275 XtAddCallback ( sd, XmNcancelCallback,
3276 (XtCallbackProc)cancel_pop_up, (XtPointer)tag );
3277 XtAddCallback ( sd, XmNapplyCallback,
3278 (XtCallbackProc)ok_pop_up, (XtPointer)tag );
3279 XtAddCallback ( sd, XmNokCallback,
3280 (XtCallbackProc)ok_pop_up, (XtPointer)tag );
3281 }
3282 return(sd);
3283}
3284
3285Widget create_file_selection_dialog(long type)
3286{
3287Widget sd;
3288XmString xm1;
3289Arg ar[20];
3290int n;
3291
3292 xm1 = create_str ("");
3293 n = 0;
3294 /*
3295 XtSetArg(ar[n],XmNdialogStyle,XmDIALOG_FULL_APPLICATION_MODAL); n++;
3296 XtSetArg(ar[n],XmNmwmFunctions,MWM_FUNC_MOVE); n++;
3297 */
3298 XtSetArg(ar[n],XmNtitle,"FileSelection"); n++;
3299 XtSetArg(ar[n],XmNlabelFontList, did_default_font); n++;
3300 XtSetArg(ar[n],XmNbuttonFontList, did_default_font); n++;
3301 XtSetArg(ar[n],XmNtextFontList, did_default_font); n++;
3302 XtSetArg(ar[n],XmNborderWidth, 1); n++;
3303 XtSetArg(ar[n],XmNwidth, 500); n++;
3304 XtSetArg(ar[n],XmNdirMask, xm1); n++;
3305 sd = XmCreateFileSelectionDialog ( toplevel_widget, "FileSelection", ar, n );
3306
3307 XmStringFree(xm1);
3308
3309 XtAddCallback ( sd, XmNcancelCallback,
3310 (XtCallbackProc)cancel_pop_up, (XtPointer)type );
3311 XtAddCallback ( sd, XmNokCallback,
3312 (XtCallbackProc)ok_pop_up, (XtPointer)type );
3313
3314 return(sd);
3315}
3316
3317Widget create_prompt_dialog(char *label, long tag)
3318{
3319Widget sd;
3320XmString xm1;
3321Arg ar[20];
3322int n;
3323
3324 xm1 = create_str (label);
3325 n = 0;
3326 XtSetArg(ar[n],XmNlabelFontList, did_default_font); n++;
3327 XtSetArg(ar[n],XmNbuttonFontList, did_default_font); n++;
3328 XtSetArg(ar[n],XmNborderWidth, 1); n++;
3329 /*
3330 XtSetArg(ar[n],XmNwidth, 450); n++;
3331 XtSetArg(ar[n],XmNresizePolicy, XmRESIZE_NONE); n++;
3332 */
3333 XtSetArg(ar[n],XmNselectionLabelString, xm1); n++;
3334 sd = XmCreatePromptDialog ( toplevel_widget, "Prompt", ar, n );
3335
3336 XmStringFree(xm1);
3337
3338 XtAddCallback ( sd, XmNcancelCallback,
3339 (XtCallbackProc)cancel_pop_up, (XtPointer)tag );
3340 XtAddCallback ( sd, XmNokCallback,
3341 (XtCallbackProc)ok_pop_up, (XtPointer)tag );
3342
3343 return(sd);
3344}
3345
3346Widget create_question_dialog(char *label, long tag)
3347{
3348Widget sd;
3349XmString xm1;
3350Arg ar[20];
3351int n;
3352
3353 xm1 = create_str (label);
3354 n = 0;
3355 XtSetArg(ar[n],XmNlabelFontList, did_default_font); n++;
3356 XtSetArg(ar[n],XmNbuttonFontList, did_default_font); n++;
3357 XtSetArg(ar[n],XmNborderWidth, 1); n++;
3358 /*
3359 XtSetArg(ar[n],XmNwidth, 450); n++;
3360 XtSetArg(ar[n],XmNresizePolicy, XmRESIZE_NONE); n++;
3361 */
3362 XtSetArg(ar[n],XmNmessageString, xm1); n++;
3363 sd = XmCreateQuestionDialog ( toplevel_widget, "Question", ar, n );
3364
3365 XmStringFree(xm1);
3366
3367 XtAddCallback ( sd, XmNcancelCallback,
3368 (XtCallbackProc)cancel_pop_up, (XtPointer)tag );
3369 XtAddCallback ( sd, XmNokCallback,
3370 (XtCallbackProc)ok_pop_up, (XtPointer)tag );
3371
3372 return(sd);
3373}
3374
3375Widget create_service_dialog()
3376{
3377Widget fd, rc, sw, lb, rc1;
3378XmString xm1;
3379Arg ar[20];
3380int n, par;
3381unsigned long reason;
3382
3383 n = 0;
3384 XtSetArg(ar[n],XmNborderWidth, 1); n++;
3385 XtSetArg(ar[n],XmNresizePolicy, XmRESIZE_ANY); n++;
3386 fd = XmCreateFormDialog ( toplevel_widget, "Form", ar, n );
3387 XtManageChild(fd);
3388
3389 /* create rowcolumn */
3390 n = 0;
3391 XtSetArg(ar[n],XmNborderWidth, 1); n++;
3392 XtSetArg(ar[n],XmNentryAlignment, XmALIGNMENT_CENTER); n++;
3393 XtSetArg(ar[n],XmNbottomAttachment, XmATTACH_FORM); n++;
3394 XtSetArg(ar[n],XmNbottomOffset, 0); n++;
3395 XtSetArg(ar[n],XmNrightAttachment, XmATTACH_FORM); n++;
3396 XtSetArg(ar[n],XmNrightOffset, 0); n++;
3397 XtSetArg(ar[n],XmNtopAttachment, XmATTACH_FORM); n++;
3398 XtSetArg(ar[n],XmNtopOffset, 0); n++;
3399 XtSetArg(ar[n],XmNleftAttachment, XmATTACH_FORM); n++;
3400 XtSetArg(ar[n],XmNleftOffset, 0); n++;
3401 rc = XmCreateRowColumn ( fd, "rowcol", ar, n );
3402 XtManageChild(rc);
3403
3404 /* create scrolled window */
3405 n = 0;
3406 XtSetArg ( ar[n], XmNwidth, 770); n++;
3407 XtSetArg ( ar[n], XmNheight, 350); n++;
3408 XtSetArg ( ar[n], XmNscrollBarDisplayPolicy, XmAS_NEEDED); n++;
3409 XtSetArg ( ar[n], XmNscrollingPolicy, XmAUTOMATIC); n++;
3410
3411 sw = XmCreateScrolledWindow ( rc, "ScrollWin", ar, n );
3412 XtManageChild ( sw );
3413
3414 /* create label */
3415 n = 0;
3416 xm1 = create_str(" ");
3417 XtSetArg(ar[n],XmNfontList, did_small_font); n++;
3418 XtSetArg(ar[n],XmNlabelString, xm1); n++;
3419 XtSetArg(ar[n],XmNalignment, XmALIGNMENT_BEGINNING); n++;
3420 lb = XmCreateLabel ( sw, "label", ar, n );
3421 XtManageChild(lb);
3422 XmStringFree(xm1);
3423 par = 1;
3424 reason = 0;
3425 create_label(lb, &par, &reason);
3426
3427 /* create button rowcolumn */
3428 n = 0;
3429 XtSetArg(ar[n],XmNborderWidth, 0); n++;
3430 XtSetArg(ar[n],XmNentryAlignment, XmALIGNMENT_CENTER); n++;
3431 XtSetArg(ar[n],XmNorientation, XmVERTICAL); n++;
3432 XtSetArg(ar[n],XmNnumColumns, 3); n++;
3433 XtSetArg(ar[n],XmNpacking, XmPACK_COLUMN); n++;
3434 rc1 = XmCreateRowColumn ( rc, "buttons", ar, n );
3435 XtManageChild(rc1);
3436 /*
3437 create_push_button(rc1,"View Standard",MAX_POP_UPS+1);
3438 create_push_button(rc1,"View Float",MAX_POP_UPS+2);
3439 create_push_button(rc1,"View Double",MAX_POP_UPS+3);
3440 */
3441 SubscribeButton = create_push_button(rc1," Subscribe (On Change) ",
3442 MAX_POP_UPS+5);
3443 Subscribe10Button = create_push_button(rc1," Subscribe (Update Rate 10 seconds) ",
3444 MAX_POP_UPS+4);
3445 create_push_button(rc1,"Dismiss",DID_SERVICE);
3446 Curr_service_print_type = 0;
3447
3448 return(fd);
3449}
3450
3451Widget create_push_button(Widget parent, char *str, long tag)
3452{
3453Widget b;
3454XmString xm1;
3455Arg ar[20];
3456int n;
3457
3458 n = 0;
3459 xm1 = create_str(str);
3460 XtSetArg(ar[n],XmNalignment, XmALIGNMENT_CENTER); n++;
3461 XtSetArg(ar[n],XmNfontList, did_default_font); n++;
3462 XtSetArg(ar[n],XmNlabelString, xm1); n++;
3463 b = XmCreatePushButton ( parent, "button", ar, n );
3464
3465 XtManageChild(b);
3466 XmStringFree(xm1);
3467
3468 XtAddCallback ( b, XmNactivateCallback,
3469 (XtCallbackProc)cancel_pop_up, (XtPointer)tag );
3470 return(b);
3471}
3472
3473
3474
3475
Note: See TracBrowser for help on using the repository browser.