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

Last change on this file since 17869 was 15282, checked in by tbretz, 12 years ago
Updated to v20r7.
File size: 78.6 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,(Cardinal)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, (Cardinal)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,(Cardinal)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, (Cardinal)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,"dns",3)) ||
816 (!strncmp(opt_str,"DNS",3))) {
817 char text[132];
818 sprintf(text,"DIM_DNS_NODE=%s",opt_str+4);
819 putenv(text);
820 dim_set_dns_node(opt_str+4);
821 }
822 else if((!strncmp(opt_str,"service",7)) ||
823 (!strncmp(opt_str,"SERVICE",7)))
824 Curr_view_opt = 2;
825 else if((!strncmp(opt_str,"error",5)) ||
826 (!strncmp(opt_str,"ERROR",5)))
827 Curr_view_opt = 3;
828 else if((!strncmp(opt_str,"help",4)) ||
829 (!strncmp(opt_str,"HELP",4)))
830 {
831 printf("Did - DIM Information Display\n");
832 printf("\t-all Show ALL Servers\n");
833 printf("\t-dns=<str> Show Servers with DIM_DNS_NODE provided by <str>\n");
834 printf("\t-service=<str> Show Servers providing Service <str>\n");
835 printf("\t-node=<nodename> Show Servers on Node <nodename>\n");
836 printf("\t-error Show Servers in Error\n");
837 printf("\t-help Show this message\n\n");
838 exit(0);
839 }
840 else
841 Curr_view_opt = -1;
842 if((Curr_view_opt == 0) || (Curr_view_opt == 2))
843 {
844 if(!(ptr = strchr(argv[1],'=')))
845 {
846 if( (ptr = strchr(argv[2],'=')) )
847 {
848 ptr++;
849 if(!(*ptr))
850 ptr = argv[3];
851 }
852 else
853 ptr++;
854 }
855 else
856 {
857 ptr++;
858 if(!(*ptr))
859 ptr = argv[2];
860 }
861 for(i = 0;*ptr; ptr++, i++)
862 Curr_view_opt_par[i] = (char)toupper((int)*ptr);
863 Curr_view_opt_par[i] = '\0';
864 }
865 }
866 }
867
868 toplevel_widget = (Widget)gui_initialize(argc, argv);
869 app_initialize();
870 /*
871 * Sit around forever waiting to process X-events. We never leave
872 * XtAppMainLoop. From here on, we only execute our callback routines.
873 */
874
875 while(1)
876 {
877 {
878 DISABLE_AST
879 mask = XtAppPending(app_context);
880 ENABLE_AST
881 }
882 if(mask)
883 {
884 DISABLE_AST
885 XtAppProcessEvent(app_context, mask);
886 if(Got_Service_List)
887 {
888 do_got_service_list(Got_Service_List);
889 Got_Service_List = 0;
890 }
891 if(Got_Client_List)
892 {
893 do_show_clients(Got_Client_List);
894 Got_Client_List = 0;
895 }
896 ENABLE_AST
897 }
898 else
899 {
900 dim_usleep(100000);
901 /*
902 usleep(100000);
903 */
904 }
905 }
906
907}
908
909static char no_link = -1;
910
911void app_initialize(int tag)
912{
913void check_put_label();
914
915void update_servers();
916void update_servers_new();
917void update_show_servers();
918extern void get_all_colors();
919extern void set_title();
920extern void set_icon_title();
921char dns_node[64];
922int dns_port;
923char title[128],icon_title[128];
924
925 if(tag){}
926 dic_get_dns_node(dns_node);
927 dns_port = dic_get_dns_port();
928 if(dns_port != DNS_PORT)
929 {
930 sprintf(title,"DID - DIM Information Display DNS=%s:%d",dns_node,dns_port);
931 }
932 else
933 {
934 sprintf(title,"DID - DIM Information Display DNS=%s",dns_node);
935 }
936 sprintf(icon_title,"DID %s",dns_node);
937 get_all_colors(display,Matrix_id[Curr_matrix]);
938 set_title(toplevel_widget,title);
939 set_icon_title(toplevel_widget,icon_title);
940 Timer_q = dtq_create();
941 dic_info_service("DIS_DNS/SERVER_INFO",MONITORED,0,0,0,update_servers,0,
942 &no_link,1);
943 /*
944 dic_info_service("DIS_DNS/SERVER_LIST",MONITORED,0,0,0,
945 update_servers_new,0, &no_link,1);
946 */
947 /*
948 dtq_add_entry(Timer_q, 2, check_put_label, 0);
949 */
950 XtAppAddTimeOut(app_context, 1000, update_show_servers, 0);
951}
952
953/*
954 * All errors are fatal.
955 */
956void s_error(char *problem_string)
957{
958 printf("%s\n", problem_string);
959 exit(0);
960}
961
962void did_exit(Widget w, int *tag, unsigned long *reason)
963{
964 if(w){}
965 if(tag){}
966 if(reason){}
967 exit(0);
968}
969
970extern Pixel rgb_colors[MAX_COLORS];
971
972void create_main (Widget w, int *tag, unsigned long *reason)
973{
974 if(tag){}
975 if(reason){}
976 Window_id = w;
977/*
978 dtq_start_timer(5, app_initialize, 0);
979*/
980}
981
982void view_opts(Widget w, int tag, unsigned long *reason)
983{
984 void get_server_node(), get_server_service(), show_servers();
985
986 if(w){}
987 if(reason){}
988 Curr_view_opt = tag;
989 switch(tag)
990 {
991 case 0 :
992 get_server_node();
993 break;
994 case 1 :
995 show_servers();
996 break;
997 case 2 :
998 get_server_service();
999 break;
1000 case 3 :
1001 show_servers();
1002 break;
1003 }
1004}
1005
1006void dns_control(Widget w, int tag, unsigned long *reason)
1007{
1008
1009 if(w){}
1010 if(reason){}
1011 switch(tag)
1012 {
1013 case 0 :
1014 dic_cmnd_service("DIS_DNS/PRINT_STATS",0,0);
1015 break;
1016 case 1 :
1017 dic_cmnd_service("DIS_DNS/DEBUG_ON",0,0);
1018 break;
1019 case 2 :
1020 dic_cmnd_service("DIS_DNS/DEBUG_OFF",0,0);
1021 break;
1022 case 3 :
1023 put_selection(DID_KILL_ALL,"Confirmation");
1024 break;
1025 case 4 :
1026 dic_cmnd_service("DIS_DNS/PRINT_HASH_TABLE",0,0);
1027 break;
1028 }
1029}
1030
1031void get_server_node()
1032{
1033Widget id,sel_id;
1034int i, j, n_nodes, curr_index = 0;
1035char nodes_str[MAX_NODE_NAME*MAX_CONNS*2], max_str[MAX_NODE_NAME];
1036char *ptr, *nodeptrs[MAX_CONNS*2], *curr_str, *sptr;
1037int get_nodes();
1038
1039 sel_id = put_selection(DID_SEL_NODE,"Node Selection");
1040 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_HELP_BUTTON);
1041 XtUnmanageChild(id);
1042 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_APPLY_BUTTON);
1043 XtUnmanageChild(id);
1044 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_LIST);
1045 XmListDeleteAllItems(id);
1046 n_nodes = get_nodes(nodes_str);
1047 ptr = nodes_str;
1048
1049 for(i=0;i<n_nodes;i++)
1050 {
1051 nodeptrs[i] = ptr;
1052 sptr = ptr;
1053 ptr = strchr(ptr,'\n');
1054 *ptr++ = '\0';
1055 for(j = 0; j < (int)strlen(sptr); j++)
1056 sptr[j] = (char)tolower((int)sptr[j]);
1057 }
1058 strcpy(max_str,"zzzzzzzzzzzzzzzzzzzzzzzzzzzz");
1059 for(i=0;i<n_nodes; i++)
1060 {
1061 curr_str = max_str;
1062 for(j=0;j<n_nodes; j++)
1063 {
1064 sptr = nodeptrs[j];
1065 if(!sptr)
1066 continue;
1067
1068 if(strcmp(sptr,curr_str) < 0)
1069 {
1070 curr_str = sptr;
1071 curr_index = j;
1072 }
1073 }
1074 nodeptrs[curr_index] = 0;
1075 XmListAddItem(id,create_str(curr_str),i+1);
1076 }
1077 /*
1078 for(i=0;i<n_nodes;i++)
1079 {
1080 node = ptr;
1081 ptr = strchr(ptr,'\n');
1082 *ptr++ = '\0';
1083 XmListAddItem(id,create_str(node),i+1);
1084 }
1085 */
1086 set_something(id,XmNlistItemCount,i);
1087 set_something(id,XmNlistVisibleItemCount,(i < 8) ? i : 8);
1088}
1089
1090void get_server_service()
1091{
1092Widget id,sel_id;
1093
1094 sel_id = put_selection(DID_SEL_SERVICE,"Service Selection");
1095 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_HELP_BUTTON);
1096 XtUnmanageChild(id);
1097 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_APPLY_BUTTON);
1098 XtUnmanageChild(id);
1099
1100 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_LIST);
1101 /*
1102 XtUnmanageChild(id);
1103 */
1104 XtUnmapWidget(id);
1105
1106 /*
1107 id = (Widget)XmSelectionBoxGetChild(sel_id,XmDIALOG_LIST_LABEL);
1108 XtUnmanageChild(id);
1109 */
1110}
1111
1112int get_nodes(char *node_ptr)
1113{
1114DNS_SERVER_INFO *ptr;
1115int n_nodes = 0;
1116SERVER *servp;
1117
1118 node_ptr[0] = '\0';
1119 servp = Server_head;
1120 while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
1121 {
1122 ptr = &servp->server;
1123 if(strstr(node_ptr,ptr->node) <= (char *)0)
1124 {
1125 strcat(node_ptr,ptr->node);
1126 strcat(node_ptr,"\n");
1127 n_nodes++;
1128 }
1129 }
1130 return(n_nodes);
1131}
1132
1133void get_service_format()
1134{
1135
1136 char str[256], *ptr, *ptr1;
1137 int rpc_flag;
1138
1139 strcpy(str,Curr_service_name);
1140 rpc_flag = 0;
1141 if( (ptr = strstr(str,"/RpcIn")) )
1142 {
1143 *ptr = '\0';
1144 rpc_flag = 1;
1145 }
1146 if( (ptr = strstr(str,"/RpcOut")) )
1147 {
1148 *ptr = '\0';
1149 rpc_flag = 2;
1150 }
1151 strcat(str,"|");
1152 if( (ptr = strstr(Curr_service_list,str)) )
1153 {
1154 if(!rpc_flag)
1155 {
1156 ptr += strlen(str);
1157 ptr1 = strchr(ptr,'|');
1158 }
1159 else if(rpc_flag == 1)
1160 {
1161 ptr += strlen(str);
1162 ptr1 = strchr(ptr,',');
1163 }
1164 else
1165 {
1166 ptr += strlen(str);
1167 ptr = strchr(ptr,',');
1168 ptr++;
1169 ptr1 = strchr(ptr,'|');
1170 }
1171 strncpy(Curr_service_format,ptr,(size_t)(ptr1 - ptr));
1172 Curr_service_format[(int)(ptr1-ptr)] = '\0';
1173 }
1174}
1175
1176void recv_service_info(int *tag, int *buffer, int *size)
1177{
1178/*
1179 char str[256], *ptr, *ptr1;
1180 int rpc_flag;
1181*/
1182 void print_service_formatted();
1183
1184 if(tag){}
1185 Service_content_str = malloc((size_t)(1024 + (*size)*16));
1186 Service_buffer = malloc((size_t)*size);
1187 memcpy(Service_buffer, (char *)buffer, (size_t)*size);
1188 Service_size = *size;
1189 get_service_format();
1190 if((*size == 4 ) && (*buffer == -1))
1191 {
1192 sprintf(Service_content_str,
1193 "Service %s Not Available\n", Curr_service_name);
1194 }
1195 else
1196 {
1197 switch(Curr_service_print_type)
1198 {
1199 case 0:
1200 print_service_formatted(buffer,*size);
1201 break;
1202 /*
1203 case 1:
1204 print_service_float(buffer, ((*size - 1) / 4) + 1);
1205 break;
1206 case 2:
1207 print_service_double(buffer, ((*size - 1) / 4) + 1);
1208 break;
1209 */
1210 }
1211 }
1212 set_something(Content_label_id,XmNlabelString, Service_content_str);
1213 /*
1214 if(Matrix_id[Curr_matrix])
1215 XFlush(XtDisplay(Matrix_id[Curr_matrix]));
1216 */
1217}
1218
1219void print_service_formatted(void *buff, int size)
1220{
1221char type;
1222int num, ret;
1223char str[128];
1224char *ptr;
1225void *buffer_ptr;
1226char timestr[128], aux[10];
1227int quality = 0, secs = 0, mili = 0;
1228int did_write_string(char, int, void **, int);
1229time_t tsecs;
1230
1231 sprintf(Service_content_str,
1232 "Service %s (%s) Contents :\n \n", Curr_service_name,
1233 Curr_service_format);
1234 /*
1235 if(Curr_service_id)
1236 {
1237 */
1238 dic_get_timestamp(0, &secs, &mili);
1239 quality = dic_get_quality(0);
1240/*
1241#ifdef LYNXOS
1242 ctime_r((time_t *)&secs, timestr, 128);
1243#else
1244 ctime_r((time_t *)&secs, timestr);
1245#endif
1246*/
1247 tsecs = secs;
1248 my_ctime(&tsecs, timestr, 128);
1249 ptr = strrchr(timestr,' ');
1250 strcpy(aux, ptr);
1251 sprintf(ptr,".%03d",mili);
1252 strcat(timestr, aux);
1253 timestr[strlen(timestr)-1] = '\0';
1254
1255 sprintf(str," Timestamp: %s Quality: %d\n\n",
1256 timestr, quality);
1257
1258 strcat(Service_content_str,str);
1259 /*
1260 }
1261 */
1262 ptr = Curr_service_format;
1263 buffer_ptr = buff;
1264 while(*ptr)
1265 {
1266 type = *ptr++;
1267 if(*ptr == ':')
1268 {
1269 ptr++;
1270 sscanf(ptr, "%d", &num);
1271 ret = did_write_string(type, num, &buffer_ptr, size);
1272 size -= ret;
1273 if( (ptr = strchr(ptr,';')) )
1274 ptr++;
1275 else
1276 break;
1277 }
1278 else
1279 {
1280 ret = did_write_string(type, 0, &buffer_ptr, size);
1281 size -= ret;
1282 break;
1283 }
1284 }
1285}
1286
1287int did_write_string(char type, int num, void **buffer_ptr, int ssize)
1288{
1289void *ptr;
1290int size, psize;
1291
1292 void print_service_standard();
1293 void print_service_char();
1294 void print_service_short();
1295 void print_service_float();
1296 void print_service_double();
1297
1298 ptr = *buffer_ptr;
1299 switch(type)
1300 {
1301 case 'L':
1302 case 'l':
1303 strcat(Service_content_str," L");
1304 if(!num)
1305 size = ssize/(int)sizeof(int);
1306 else
1307 size = num;
1308 psize = size * (int)sizeof(int);
1309 print_service_standard(ptr, size);
1310 break;
1311 case 'I':
1312 case 'i':
1313 strcat(Service_content_str," I");
1314 if(!num)
1315 size = ssize/(int)sizeof(int);
1316 else
1317 size = num;
1318 psize = size * (int)sizeof(int);
1319 print_service_standard(ptr, size);
1320 break;
1321 case 'S':
1322 case 's':
1323 strcat(Service_content_str," S");
1324 if(!num)
1325 size = ssize/(int)sizeof(short);
1326 else
1327 size = num;
1328 psize = size * (int)sizeof(short);
1329 print_service_short(ptr, size);
1330 break;
1331 case 'F':
1332 case 'f':
1333 strcat(Service_content_str," F");
1334 if(!num)
1335 size = ssize/(int)sizeof(float);
1336 else
1337 size = num;
1338 psize = size * (int)sizeof(float);
1339 print_service_float(ptr, size);
1340 break;
1341 case 'D':
1342 case 'd':
1343 strcat(Service_content_str," D");
1344 if(!num)
1345 size = ssize/(int)sizeof(double);
1346 else
1347 size = num;
1348 psize = size * (int)sizeof(double);
1349 print_service_double(ptr, size);
1350 break;
1351 case 'X':
1352 case 'x':
1353 strcat(Service_content_str," X");
1354 if(!num)
1355 size = ssize/(int)sizeof(longlong);
1356 else
1357 size = num;
1358 psize = size * (int)sizeof(longlong);
1359 print_service_standard(ptr, size*2);
1360 break;
1361 case 'C':
1362 case 'c':
1363 default:
1364 strcat(Service_content_str," C");
1365 if(!num)
1366 size = ssize;
1367 else
1368 size = num;
1369 psize = size;
1370 print_service_char(ptr, size);
1371 }
1372 ptr = (char *)ptr + psize;
1373 *buffer_ptr = ptr;
1374 return psize;
1375}
1376/*
1377print_service(buff, size)
1378int *buff, size;
1379{
1380int i,j, str_flag = 0;
1381char *asc, *ptr, str[80];
1382int last[4];
1383
1384 sprintf(Service_content_str,
1385 "Service %s (%s) Contents :\n \n", Curr_service_name,
1386 Curr_service_format);
1387 asc = (char *)buff;
1388 for( i = 0; i < size; i++)
1389 {
1390 if(i%4 == 0)
1391 {
1392 sprintf(str,"%4d: ",i);
1393 strcat(Service_content_str,str);
1394 }
1395 if(!(i%4))
1396 strcat(Service_content_str,"H");
1397 sprintf(str," %08X ",buff[i]);
1398 strcat(Service_content_str,str);
1399 last[i%4] = buff[i];
1400 if(i%4 == 3)
1401 {
1402 strcat(Service_content_str," '");
1403 for(j = 0; j <16; j++)
1404 {
1405 if(isprint(asc[j]))
1406 {
1407 sprintf(str,"%c",asc[j]);
1408 strcat(Service_content_str,str);
1409 }
1410 else
1411 {
1412 sprintf(str,".");
1413 strcat(Service_content_str,str);
1414 }
1415 }
1416 strcat(Service_content_str,"'\n");
1417 for(j = 0; j <4; j++)
1418 {
1419 if(j == 0)
1420 strcat(Service_content_str," D");
1421 sprintf(str,"%11d ",last[j]);
1422 strcat(Service_content_str,str);
1423 }
1424 strcat(Service_content_str,"\n");
1425 asc = (char *)&buff[i+1];
1426 }
1427 }
1428 if(i%4)
1429 {
1430 for(j = 0; j < 4 - (i%4); j++)
1431 strcat(Service_content_str," ");
1432 strcat(Service_content_str," '");
1433 for(j = 0; j < (i%4) * 4; j++)
1434 {
1435 if(isprint(asc[j]))
1436 {
1437 sprintf(str,"%c",asc[j]);
1438 strcat(Service_content_str,str);
1439 }
1440 else
1441 strcat(Service_content_str,".");
1442 }
1443 strcat(Service_content_str,"'\n");
1444 for(j = 0; j < (i%4); j++)
1445 {
1446 if(j == 0)
1447 strcat(Service_content_str," D");
1448 sprintf(str,"%11d ",last[j]);
1449 strcat(Service_content_str,str);
1450 }
1451 strcat(Service_content_str,"\n");
1452 }
1453}
1454*/
1455
1456void print_service_standard(int *buff, int size)
1457{
1458int i,j;
1459char *ptr, str[80], tmp[256];
1460int last[4];
1461/*
1462char *asc;
1463 asc = (char *)buff;
1464*/
1465 ptr = Service_content_str;
1466 ptr += strlen(Service_content_str);
1467 for( i = 0; i < size; i++)
1468 {
1469 strcpy(tmp,"");
1470 if(i%4 == 0)
1471 {
1472 if(i != 0)
1473 {
1474 strcat(tmp," ");
1475 }
1476 sprintf(str,"%5d ",i);
1477 strcat(tmp,str);
1478 }
1479 if(!(i%4))
1480 strcat(tmp,"H: ");
1481 sprintf(str," %08X",buff[i]);
1482 strcat(tmp,str);
1483 last[i%4] = buff[i];
1484 if((i%4 == 3) || (i == (size-1)))
1485 {
1486 /*
1487 if(i%4 != 3)
1488 {
1489 for(j = 1; j < 4 - (i%4); j++)
1490 strcat(tmp," ");
1491 }
1492 strcat(tmp," '");
1493 for(j = 0; j < ((i%4)*4)+4 ; j++)
1494 {
1495 if(isprint(asc[j]))
1496 {
1497 sprintf(str,"%c",asc[j]);
1498 strcat(tmp,str);
1499 }
1500 else
1501 {
1502 sprintf(str,".");
1503 strcat(tmp,str);
1504 }
1505 }
1506 */
1507 strcat(tmp,"\n");
1508 for(j = 0; j <= (i%4); j++)
1509 {
1510 if(j == 0)
1511 strcat(tmp," D: ");
1512 sprintf(str,"%12d",last[j]);
1513 strcat(tmp,str);
1514 }
1515 strcat(tmp,"\n");
1516/*
1517 asc = (char *)&buff[i+1];
1518*/
1519 }
1520 strcpy(ptr, tmp);
1521 ptr += strlen(tmp);
1522 }
1523 strcpy(tmp,"\n");
1524 strcpy(ptr, tmp);
1525}
1526
1527void print_service_longlong(longlong *buff, int size)
1528{
1529int i,j;
1530char *ptr, str[80], tmp[256];
1531longlong last[4];
1532/*
1533char *asc;
1534 asc = (char *)buff;
1535*/
1536 ptr = Service_content_str;
1537 ptr += strlen(Service_content_str);
1538 for( i = 0; i < size; i++)
1539 {
1540 strcpy(tmp,"");
1541 if(i%4 == 0)
1542 {
1543 if(i != 0)
1544 {
1545 strcat(tmp," ");
1546 }
1547 sprintf(str,"%5d ",i);
1548 strcat(tmp,str);
1549 }
1550 if(!(i%4))
1551 strcat(tmp,"H: ");
1552 sprintf(str," %08X",(unsigned)buff[i]);
1553 strcat(tmp,str);
1554 last[i%4] = buff[i];
1555 if((i%4 == 3) || (i == (size-1)))
1556 {
1557 strcat(tmp,"\n");
1558 for(j = 0; j <= (i%4); j++)
1559 {
1560 if(j == 0)
1561 strcat(tmp," D: ");
1562 sprintf(str,"%12d",(int)last[j]);
1563 strcat(tmp,str);
1564 }
1565 strcat(tmp,"\n");
1566/*
1567 asc = (char *)&buff[i+1];
1568*/
1569 }
1570 strcpy(ptr, tmp);
1571 ptr += strlen(tmp);
1572 }
1573 strcpy(tmp,"\n");
1574 strcpy(ptr, tmp);
1575}
1576
1577void print_service_short(short *buff, int size)
1578{
1579int i,j;
1580char *ptr, str[80], tmp[256];
1581short last[8];
1582/*
1583char *asc;
1584 asc = (char *)buff;
1585*/
1586 ptr = Service_content_str;
1587 ptr += strlen(Service_content_str);
1588 for( i = 0; i < size; i++)
1589 {
1590 strcpy(tmp,"");
1591 if(i%8 == 0)
1592 {
1593 if(i != 0)
1594 {
1595 strcat(tmp," ");
1596 }
1597 sprintf(str,"%5d ",i);
1598 strcat(tmp,str);
1599 }
1600 if(!(i%8))
1601 strcat(tmp,"H: ");
1602 sprintf(str," %04X",buff[i]);
1603 strcat(tmp,str);
1604 last[i%8] = buff[i];
1605 if((i%8 == 7) || (i == (size-1)))
1606 {
1607 /*
1608 if(i%7 != 7)
1609 {
1610 for(j = 1; j < 8 - (i%8); j++)
1611 strcat(tmp," ");
1612 }
1613 strcat(tmp," '");
1614 for(j = 0; j < ((i%8)*2)+2 ; j++)
1615 {
1616 if(isprint(asc[j]))
1617 {
1618 sprintf(str,"%c",asc[j]);
1619 strcat(tmp,str);
1620 }
1621 else
1622 {
1623 sprintf(str,".");
1624 strcat(tmp,str);
1625 }
1626 }
1627 */
1628 strcat(tmp,"\n");
1629 for(j = 0; j <= (i%8); j++)
1630 {
1631 if(j == 0)
1632 strcat(tmp," D: ");
1633 sprintf(str," %5d",last[j]);
1634 strcat(tmp,str);
1635 }
1636 strcat(tmp,"\n");
1637/*
1638 asc = (char *)&buff[i+1];
1639*/
1640 }
1641 strcpy(ptr, tmp);
1642 ptr += strlen(tmp);
1643 }
1644 strcpy(tmp,"\n");
1645 strcpy(ptr, tmp);
1646}
1647
1648void print_service_char(char *buff, int size)
1649{
1650int i,j;
1651char *asc, *ptr, str[80], tmp[256];
1652/*
1653char last[16];
1654*/
1655 asc = (char *)buff;
1656 ptr = Service_content_str;
1657 ptr += strlen(Service_content_str);
1658 for( i = 0; i < size; i++)
1659 {
1660 strcpy(tmp,"");
1661 if(i%16 == 0)
1662 {
1663 if(i != 0)
1664 {
1665 strcat(tmp," ");
1666 }
1667 sprintf(str,"%5d ",i);
1668 strcat(tmp,str);
1669 }
1670 if(!(i%16))
1671 strcat(tmp,"H: ");
1672 sprintf(str,"%02X",buff[i]);
1673/* strcat(tmp,str);
1674*/
1675 strcat(tmp," ");
1676 strcat(tmp,&str[strlen(str)-2]);
1677 /*
1678 last[i%16] = buff[i];
1679 if(i%4 == 3)
1680 strcat(tmp," ");
1681 */
1682 if((i%16 == 15) || (i == (size-1)))
1683 {
1684 if(i%16 != 15)
1685 {
1686 for(j = 1; j < 16 - (i%16); j++)
1687 strcat(tmp," ");
1688 }
1689 strcat(tmp," '");
1690 for(j = 0; j <= (i%16) ; j++)
1691 {
1692 if(isprint(asc[j]))
1693 {
1694 sprintf(str,"%c",asc[j]);
1695 strcat(tmp,str);
1696 }
1697 else
1698 {
1699 sprintf(str,".");
1700 strcat(tmp,str);
1701 }
1702 }
1703 strcat(tmp,"'\n");
1704 asc = (char *)&buff[i+1];
1705 }
1706 strcpy(ptr, tmp);
1707 ptr += strlen(tmp);
1708 }
1709 strcpy(tmp,"\n");
1710 strcpy(ptr, tmp);
1711}
1712
1713void print_service_float(float *buff, int size)
1714{
1715int i;
1716char *ptr, str[80], tmp[256];
1717
1718 ptr = Service_content_str;
1719 ptr += strlen(Service_content_str);
1720 for( i = 0; i < size; i++)
1721 {
1722 strcpy(tmp,"");
1723 if(i%4 == 0)
1724 {
1725 if(i != 0)
1726 {
1727 strcat(tmp," ");
1728 }
1729 sprintf(str," %5d: ",i);
1730 strcat(tmp,str);
1731 }
1732 sprintf(str,"%12.3G",*(buff++));
1733 strcat(tmp,str);
1734 if((i%4 == 3) || (i == size-1))
1735 {
1736 strcat(tmp,"\n");
1737 }
1738 strcpy(ptr, tmp);
1739 ptr += strlen(tmp);
1740 }
1741 strcpy(tmp,"\n");
1742 strcpy(ptr, tmp);
1743 ptr += strlen(tmp);
1744}
1745
1746void print_service_double(double *buff, int size)
1747{
1748int i;
1749char *ptr, str[80], tmp[256];
1750
1751 ptr = Service_content_str;
1752 ptr += strlen(Service_content_str);
1753 for( i = 0; i < size; i++)
1754 {
1755 strcpy(tmp,"");
1756 if(i%4 == 0)
1757 {
1758 if(i != 0)
1759 {
1760 strcat(tmp," ");
1761 }
1762 sprintf(str," %5d: ",i);
1763 strcat(tmp,str);
1764 }
1765 sprintf(str,"%12.3G",*(buff++));
1766 strcat(tmp,str);
1767 if((i%4 == 3) || (i == size-1))
1768 {
1769 strcat(tmp,"\n");
1770 }
1771 strcpy(ptr, tmp);
1772 ptr += strlen(tmp);
1773 }
1774 strcpy(tmp,"\n");
1775 strcpy(ptr, tmp);
1776 ptr += strlen(tmp);
1777}
1778
1779void ok_pop_up (Widget w, long tag, unsigned long *reason)
1780{
1781Widget id, sel_id;
1782char *str, *pstr;
1783void recv_service_info();
1784void did_prepare_command();
1785void show_servers();
1786
1787/*
1788 if(tag == 5)
1789 {
1790 id = (Widget)XmSelectionBoxGetChild(w,XmDIALOG_TEXT);
1791 str = (char *)XmTextGetString(id);
1792 if(!str[0])
1793 {
1794 XtFree(str);
1795 return;
1796 }
1797 if( ( fptr = fopen( str, "w" ) ) == (FILE *)0 )
1798 {
1799 printf("Cannot open: %s for writing\n",str);
1800 return;
1801 }
1802 ptr = &Curr_servp->server;
1803 if (ptr->pid > 0x1000000)
1804 fprintf(fptr,"Server %s (pid = %X) on node %s\n provides %d services :\n",
1805 Curr_servp->name, ptr->pid, ptr->node, ptr->n_services);
1806 else
1807 fprintf(fptr,"Server %s (pid = %d) on node %s\n provides %d services :\n",
1808 Curr_servp->name, ptr->pid, ptr->node, ptr->n_services);
1809 service_ptr = Curr_servp->service_ptr;
1810 for(i=0;i<ptr->n_services; i++)
1811 {
1812 sprintf(str,service_ptr->name);
1813 fprintf(fptr," %s\n",service_ptr->name);
1814 service_ptr++;
1815 }
1816 fclose(fptr);
1817 XtFree(str);
1818 return;
1819 }
1820 if(tag == 4)
1821 {
1822 sel_id = put_selection(4, "Printing...");
1823 id = (Widget)XmSelectionBoxGetChild(sel_id,XmDIALOG_HELP_BUTTON);
1824 XtUnmanageChild(id);
1825
1826 id = (Widget)XmSelectionBoxGetChild(sel_id,XmDIALOG_APPLY_BUTTON);
1827 XtUnmanageChild(id);
1828 id = (Widget)XmSelectionBoxGetChild(sel_id,XmDIALOG_TEXT);
1829 str = (char *)XmTextGetString(id);
1830 if(!str[0])
1831 {
1832 XtFree(str);
1833 return;
1834 }
1835 ptr = &Curr_servp->server;
1836 if(pstr = strrchr(str,']'))
1837 *(++pstr) = '\0';
1838 if(pstr = strrchr(str,'/'))
1839 *(++pstr) = '\0';
1840 sprintf(txt_str,"%s%s.TXT",str,Curr_servp->name);
1841 XtFree(str);
1842 XmTextSetString(id, txt_str);
1843 return;
1844 }
1845*/
1846 if(reason){}
1847 if(tag == DID_KILL_ALL)
1848 {
1849 dic_cmnd_service("DIS_DNS/KILL_SERVERS",0,0);
1850 return;
1851 }
1852 id = XmSelectionBoxGetChild(w,XmDIALOG_TEXT);
1853 str = XmTextGetString(id);
1854 if(!str[0])
1855 {
1856 XtFree(str);
1857 return;
1858 }
1859 if ((tag == DID_SEL_NODE) || (tag == DID_SEL_SERVICE))
1860 {
1861 strcpy(Curr_view_opt_par, str);
1862 show_servers();
1863 XtFree(str);
1864 }
1865 if(tag == DID_SERVICES)
1866 {
1867 pstr = strchr(str,' ');
1868 if(!pstr)
1869 {
1870 strcpy(Curr_service_name, str);
1871 strcpy(str,"SVC");
1872 }
1873 else
1874 {
1875 pstr++;
1876 strcpy(Curr_service_name, pstr);
1877 }
1878 if(Curr_service_id)
1879 {
1880 dic_release_service(Curr_service_id);
1881 Curr_service_id = 0;
1882 }
1883 if(str[0] == 'S')
1884 {
1885 /*
1886 if((!strstr(pstr,"/SERVICE_LIST")) &&
1887 (!strstr(pstr,"/CLIENT_LIST")) &&
1888 (!strstr(pstr,"/SERVER_LIST")))
1889 {
1890 Curr_service_id = dic_info_service(Curr_service_name,
1891 MONITORED,5,0,0,
1892 recv_service_info,0,
1893 &no_link_int,4);
1894 }
1895 else
1896 {
1897 */
1898 dic_info_service_stamped(Curr_service_name,
1899 ONCE_ONLY,10,0,0,
1900 recv_service_info,0,
1901 &no_link_int,4);
1902 /*
1903 }
1904 */
1905 put_selection(DID_SERVICE,"Service Contents");
1906 }
1907 else
1908 {
1909 get_service_format();
1910 sel_id = put_selection(DID_COMMAND,"Send Command");
1911 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_HELP_BUTTON);
1912 XtUnmanageChild(id);
1913 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_APPLY_BUTTON);
1914 XtUnmanageChild(id);
1915 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_LIST);
1916 /*
1917 XtUnmanageChild(id);
1918 */
1919 XtUnmapWidget(id);
1920 }
1921 XtFree(str);
1922 }
1923 if(tag == DID_COMMAND)
1924 {
1925 did_prepare_command(str);
1926 XtFree(str);
1927 }
1928}
1929
1930int get_type_size(char type)
1931{
1932 int size;
1933
1934 switch(type)
1935 {
1936 case 'L':
1937 case 'l':
1938 size = sizeof(long);
1939 break;
1940 case 'I':
1941 case 'i':
1942 size = sizeof(int);
1943 break;
1944 case 'S':
1945 case 's':
1946 size = sizeof(short);
1947 break;
1948 case 'F':
1949 case 'f':
1950 size = sizeof(float);
1951 break;
1952 case 'D':
1953 case 'd':
1954 size = sizeof(double);
1955 break;
1956 case 'C':
1957 case 'c':
1958 default:
1959 size = 1;
1960 }
1961 return(size);
1962}
1963
1964void did_prepare_command(char *str)
1965{
1966char type;
1967int num;
1968int size, full_size = 0;
1969char *ptr;
1970static int last_size = 0;
1971static void *last_buffer = 0;
1972void *buffer_ptr;
1973char *str_ptr;
1974void did_read_string(char, int, void **, char **);
1975
1976 str_ptr = str;
1977 ptr = Curr_service_format;
1978 while(*ptr)
1979 {
1980 type = *ptr++;
1981 if(*ptr == ':')
1982 {
1983 ptr++;
1984 size = get_type_size(type);
1985 sscanf(ptr, "%d", &num);
1986 full_size += size * num;
1987 if( (ptr = strchr(ptr,';')) )
1988 ptr++;
1989 else
1990 break;
1991 }
1992 }
1993
1994 full_size += 256;
1995 if(full_size > last_size)
1996 {
1997 if(last_size)
1998 free(last_buffer);
1999 last_buffer = malloc((size_t)full_size);
2000 last_size = full_size;
2001 }
2002 buffer_ptr = last_buffer;
2003 ptr = Curr_service_format;
2004 while(*ptr)
2005 {
2006 type = *ptr++;
2007 if(*ptr == ':')
2008 {
2009 ptr++;
2010 sscanf(ptr, "%d", &num);
2011 did_read_string(type, num, &buffer_ptr, &str_ptr);
2012 if(!str_ptr)
2013 break;
2014 if( (ptr = strchr(ptr,';')) )
2015 ptr++;
2016 else
2017 break;
2018 }
2019 else
2020 {
2021 did_read_string(type, 0, &buffer_ptr, &str_ptr);
2022 break;
2023 }
2024 }
2025 full_size = (int) ((char *)buffer_ptr - (char *)last_buffer);
2026 dic_cmnd_service(Curr_service_name,last_buffer,full_size);
2027}
2028
2029int read_str_int(char *str)
2030{
2031 int i;
2032 if((str[0] == '0') && (str[1] == 'x'))
2033 sscanf(str+2,"%x",&i);
2034 else
2035 sscanf(str,"%d",&i);
2036 return(i);
2037}
2038
2039int read_str_char(char *str, char *cc)
2040{
2041
2042 if(str[0] == '\'')
2043 *cc = str[1];
2044 else if(str[0] == '\"')
2045 return(0);
2046 else if((str[0] == '0') && (str[1] == 'x'))
2047 sscanf(str+2,"%x",(int *)cc);
2048 else if(isalpha(str[0]))
2049 return(-1);
2050 else
2051 sscanf(str,"%d",(int *)cc);
2052 return(1);
2053}
2054
2055void did_read_string(char type, int num, void **buffer_ptr, char **str_ptr)
2056{
2057int i, ret = 0;
2058float ff;
2059double dd;
2060void *ptr;
2061char *strp, *ptr1;
2062char cc;
2063 short s;
2064
2065 strp = *str_ptr;
2066 ptr = *buffer_ptr;
2067 if(!num)
2068 num = 1000000;
2069 switch(type)
2070 {
2071 case 'L':
2072 case 'l':
2073 case 'I':
2074 case 'i':
2075 for(i = 0; i<num; i++)
2076 {
2077 *(int *)ptr = read_str_int(strp);
2078 ptr = (int *)ptr +1;
2079 if( (strp = strchr(strp,' ')) )
2080 strp++;
2081 else
2082 break;
2083 }
2084 break;
2085 case 'S':
2086 case 's':
2087 for(i = 0; i<num; i++)
2088 {
2089 s = (short)read_str_int(strp);
2090 *((short *)ptr) = s;
2091 ptr = (short *)ptr +1;
2092 if( (strp = strchr(strp,' ')) )
2093 strp++;
2094 else
2095 break;
2096 }
2097 break;
2098 case 'F':
2099 case 'f':
2100 for(i = 0; i<num; i++)
2101 {
2102 sscanf(strp,"%f",&ff);
2103 *(float *)ptr = ff;
2104 ptr = (float *)ptr +1;
2105 if( (strp = strchr(strp,' ')) )
2106 strp++;
2107 else
2108 break;
2109 }
2110 break;
2111 case 'D':
2112 case 'd':
2113 for(i = 0; i<num; i++)
2114 {
2115 sscanf(strp,"%f",&ff);
2116 dd = (double)ff;
2117 *(double *)ptr = dd;
2118 ptr = (double *)ptr +1;
2119 if( (strp = strchr(strp,' ')) )
2120 strp++;
2121 else
2122 break;
2123 }
2124 break;
2125 case 'C':
2126 case 'c':
2127 default:
2128 for(i = 0; i<num; i++)
2129 {
2130 if((ret = read_str_char(strp, &cc)) <= 0)
2131 break;
2132 *(char *)ptr = cc;
2133 ptr = (char *)ptr +1;
2134 if( (strp = strchr(strp,' ')) )
2135 strp++;
2136 else
2137 break;
2138 }
2139 if(ret <= 0)
2140 {
2141 if(!ret)
2142 {
2143 strp++;
2144 }
2145 num = (int)strlen(strp)+1;
2146 strncpy((char *)ptr,strp,(size_t)num);
2147 if( (ptr1 = (char *)strchr((char *)ptr,'\"')) )
2148 {
2149 num--;
2150 *ptr1 = '\0';
2151 }
2152 ptr = (char *)ptr + num;
2153 if( (strp = strchr(strp,' ')) )
2154 strp++;
2155 else
2156 break;
2157 }
2158 }
2159 *buffer_ptr = ptr;
2160 *str_ptr = strp;
2161}
2162
2163void cancel_pop_up (Widget w, int tag, unsigned long *reason)
2164{
2165 void print_service_formatted();
2166
2167 if(reason){}
2168 if(tag == MAX_POP_UPS+1)
2169 {
2170 print_service_formatted(Service_buffer,Service_size);
2171 set_something(Content_label_id,XmNlabelString, Service_content_str);
2172 Curr_service_print_type = 0;
2173 }
2174 /*
2175 else if(tag == MAX_POP_UPS+2)
2176 {
2177 print_service_float(Service_buffer, ((Service_size - 1) / 4) + 1);
2178 set_something(Content_label_id,XmNlabelString, Service_content_str);
2179 Curr_service_print_type = 1;
2180 }
2181 else if(tag == MAX_POP_UPS+3)
2182 {
2183 print_service_double(Service_buffer, ((Service_size - 1) / 4) + 1);
2184 set_something(Content_label_id,XmNlabelString, Service_content_str);
2185 Curr_service_print_type = 2;
2186 }
2187 */
2188 else if(tag == MAX_POP_UPS+4)
2189 {
2190
2191 if((!strstr(Curr_service_name,"/SERVICE_LIST")) &&
2192 (!strstr(Curr_service_name,"/CLIENT_LIST")) &&
2193 (!strstr(Curr_service_name,"/SERVER_LIST")))
2194 {
2195 if(Curr_service_id)
2196 {
2197 dic_release_service(Curr_service_id);
2198 Curr_service_id = 0;
2199 }
2200 Curr_service_id = (int)dic_info_service_stamped(Curr_service_name,
2201 MONITORED,10,0,0,
2202 recv_service_info,0,
2203 &no_link_int,4);
2204 }
2205 XtSetSensitive(w, False);
2206 XtSetSensitive(SubscribeButton, True);
2207 }
2208 else if(tag == MAX_POP_UPS+5)
2209 {
2210
2211 if((!strstr(Curr_service_name,"/SERVICE_LIST")) &&
2212 (!strstr(Curr_service_name,"/CLIENT_LIST")) &&
2213 (!strstr(Curr_service_name,"/SERVER_LIST")))
2214 {
2215 if(Curr_service_id)
2216 {
2217 dic_release_service(Curr_service_id);
2218 Curr_service_id = 0;
2219 }
2220 Curr_service_id = (int)dic_info_service_stamped(Curr_service_name,
2221 MONITORED,0,0,0,
2222 recv_service_info,0,
2223 &no_link_int,4);
2224 }
2225 XtSetSensitive(w, False);
2226 XtSetSensitive(Subscribe10Button, True);
2227 }
2228/*
2229 else if(tag == 5)
2230 {
2231 *
2232 XtUnmapWidget(XtParent(pop_widget_id[4]));
2233 *
2234 }
2235*/
2236 else if(tag == DID_SERVICE)
2237 {
2238 if(Curr_service_id)
2239 {
2240 dic_release_service(Curr_service_id);
2241 Curr_service_id = 0;
2242 }
2243 XtUnmanageChild(pop_widget_id[DID_SERVICE]);
2244 free(Service_content_str);
2245 free(Service_buffer);
2246 }
2247}
2248
2249void create_matrix(Widget w, int *tag, unsigned long *reason)
2250{
2251
2252 if(reason){}
2253 Matrix_id[*tag] = w;
2254 if(*tag)
2255 XtUnmanageChild(w);
2256 else
2257 Curr_matrix = 0;
2258}
2259
2260void create_label(Widget w, int *tag, unsigned long *reason)
2261{
2262 if(reason){}
2263 if(!*tag)
2264 Label_id = w;
2265 else
2266 Content_label_id = w;
2267}
2268
2269void switch_matrix()
2270{
2271 /*
2272 XtUnmanageChild(Matrix_id[Curr_matrix]);
2273 Curr_matrix = (Curr_matrix) ? 0 : 1;
2274 XtManageChild(Matrix_id[Curr_matrix]);
2275 */
2276 XmScrolledWindowSetAreas(Window_id,NULL, NULL, Matrix_id[Curr_matrix]);
2277}
2278
2279/*
2280static int curr_allocated_size = 0;
2281static DNS_SERVER_INFO *dns_info_buffer;
2282*/
2283
2284void update_servers_new(int *tag, char *buffer, int *size)
2285{
2286 if(tag){}
2287 if(size){}
2288 printf("Server_list:\n%s\n",buffer);
2289}
2290
2291SERVER *find_server(char *node, int pid)
2292{
2293 SERVER *servp;
2294 DNS_SERVER_INFO *ptr;
2295
2296 servp = Server_head;
2297 while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
2298 {
2299 ptr = &servp->server;
2300 if((ptr->pid == pid) && (!strcmp(ptr->node,node)))
2301 {
2302 return(servp);
2303 }
2304 }
2305 return ((SERVER *)0);
2306}
2307 /*
2308 if(!(servp = (SERVER *)sll_search((SLL *)Server_head,
2309 (char *)&buffer->server, MAX_NODE_NAME+MAX_TASK_NAME-4)))
2310 */
2311
2312
2313void update_servers(int *tag, DNS_DID *buffer, int *size)
2314{
2315int n_services, service_size;
2316SERVER *servp;
2317int j;
2318char str[MAX_NAME], sname[MAX_NAME], *ptr;
2319
2320 if(tag){}
2321 if(!Server_head)
2322 {
2323 Server_head = (SERVER *)malloc(sizeof(SERVER));
2324 sll_init((SLL *)Server_head);
2325 }
2326 if(First_time)
2327 {
2328 switch_matrix();
2329 First_time = 0;
2330 }
2331
2332 if(!*size)
2333 return;
2334 if(*(char *)buffer == -1)
2335 {
2336 N_servers = 0;
2337 N_services = 0;
2338 return;
2339 }
2340 buffer->server.n_services = vtohl(buffer->server.n_services);
2341 buffer->server.pid = vtohl(buffer->server.pid);
2342 n_services = buffer->server.n_services;
2343
2344 if(n_services == 1)
2345 return;
2346 strcpy(sname, buffer->server.task);
2347 if(n_services > 1)
2348 {
2349 for(j = 0; j < n_services; j++)
2350 {
2351 buffer->services[j].type = vtohl(
2352 buffer->services[j].type);
2353 buffer->services[j].status = vtohl(
2354 buffer->services[j].status);
2355 buffer->services[j].n_clients = vtohl(
2356 buffer->services[j].n_clients);
2357 if(strlen(sname) == MAX_TASK_NAME-4-1)
2358 {
2359 strcpy(str,buffer->services[j].name);
2360 if( (ptr = strstr(str,"/CLIENT_LIST")) )
2361 {
2362 *ptr = '\0';
2363 strcpy(sname,str);
2364 }
2365 }
2366 }
2367 }
2368 if (!(servp = find_server(buffer->server.node,buffer->server.pid)))
2369 /*
2370 if(!(servp = (SERVER *)sll_search((SLL *)Server_head,
2371 (char *)&buffer->server, MAX_NODE_NAME+MAX_TASK_NAME-4)))
2372 */
2373 {
2374 if(n_services)
2375 {
2376 servp = (SERVER *)malloc(sizeof(SERVER));
2377 strcpy(servp->name,sname);
2378 servp->next = 0;
2379 servp->button_id = 0;
2380 servp->pop_widget_id[0] = 0;
2381 servp->pop_widget_id[1] = 0;
2382 servp->busy = 0;
2383 servp->server.n_services = 0;
2384 servp->service_ptr = 0;
2385 sll_insert_queue((SLL *)Server_head,(SLL *)servp);
2386 }
2387 }
2388 if(n_services != 0)
2389 {
2390 if(n_services == servp->server.n_services)
2391 {
2392 return;
2393 }
2394 if(servp->server.n_services == 0)
2395 N_servers++;
2396 if(servp->server.n_services != -1)
2397 N_services -= servp->server.n_services;
2398 memcpy(&servp->server,&buffer->server,sizeof(DNS_SERVER_INFO));
2399 if(servp->service_ptr)
2400 {
2401 free(servp->service_ptr);
2402 servp->service_ptr = 0;
2403 }
2404 if(n_services != -1)
2405 {
2406 service_size = n_services*(int)sizeof(DNS_SERVICE_INFO);
2407 servp->service_ptr = (DNS_SERVICE_INFO *)malloc((size_t)service_size);
2408 memcpy(servp->service_ptr, buffer->services, (size_t)service_size);
2409 N_services += n_services;
2410 }
2411 servp->busy = 1;
2412 }
2413 else
2414 {
2415 if(servp)
2416 {
2417 N_servers--;
2418 if(servp->server.n_services != -1)
2419 {
2420 N_services -= servp->server.n_services;
2421 }
2422 else
2423 Force_update = 1;
2424 servp->server.n_services = 0;
2425 servp->busy = -1;
2426 }
2427 }
2428}
2429
2430void show_servers()
2431{
2432SERVER *servp;
2433void update_show_servers();
2434void remove_all_buttons();
2435void put_label();
2436
2437 if(!Matrix_id[Curr_matrix])
2438 return;
2439 remove_all_buttons();
2440
2441#ifndef linux
2442 switch_matrix();
2443#endif
2444 put_label();
2445 servp = Server_head;
2446 while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
2447 {
2448 servp->busy = 1;
2449 }
2450 Force_update = 1;
2451}
2452
2453void update_show_servers(void *tag, unsigned long *reason)
2454{
2455DNS_SERVER_INFO *server_ptr;
2456DNS_SERVICE_INFO *service_ptr;
2457int i, j, found, n_done = 0;
2458Widget w, create_button();
2459SERVER *servp, *prevp;
2460static int old_n_services = 0;
2461char node[MAX_NODE_NAME], par[MAX_NODE_NAME], *ptr;
2462void remove_button();
2463void remove_all_buttons();
2464void put_label();
2465
2466 DISABLE_AST
2467 if(tag){}
2468 if(reason){}
2469 if((N_services != old_n_services) || (Force_update))
2470 {
2471 if(!Matrix_id[Curr_matrix])
2472 {
2473 XtAppAddTimeOut(app_context, 1000, update_show_servers, 0);
2474 ENABLE_AST
2475 return;
2476 }
2477 if(!N_servers)
2478 {
2479 remove_all_buttons();
2480 if(! No_link_button_id)
2481 {
2482 No_link_button_id = create_button("DNS is down", 0);
2483 set_color(No_link_button_id, XmNbackground, RED);
2484 get_something(No_link_button_id,XmNuserData,&w);
2485 set_color(w, XmNbackground, RED);
2486 XtSetSensitive(No_link_button_id, False);
2487 }
2488 while(!sll_empty((SLL *)Server_head))
2489 {
2490 servp = (SERVER *)sll_remove_head((SLL *)Server_head);
2491 if(servp->service_ptr)
2492 free(servp->service_ptr);
2493 free(servp);
2494 }
2495 put_label();
2496 old_n_services = N_services;
2497 Force_update = 0;
2498 XtAppAddTimeOut(app_context, 1000, update_show_servers, 0);
2499 ENABLE_AST
2500 return;
2501 }
2502 if(No_link_button_id)
2503 {
2504 XtDestroyWidget(No_link_button_id);
2505 /*
2506 XFlush(XtDisplay(No_link_button_id));
2507 */
2508 No_link_button_id = 0;
2509 }
2510 servp = Server_head;
2511 prevp = 0;
2512 while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
2513 {
2514 if(prevp)
2515 {
2516 free(prevp);
2517 prevp = 0;
2518 }
2519 if(n_done == 10)
2520 {
2521 if(!Force_update)
2522 put_label();
2523 XtAppAddTimeOut(app_context, 100, update_show_servers, 0);
2524 ENABLE_AST
2525 return;
2526 }
2527 server_ptr = &servp->server;
2528 if(servp->busy == 1)
2529 {
2530 if(!servp->button_id)
2531 {
2532 switch(Curr_view_opt)
2533 {
2534 case 1 :
2535 servp->button_id = create_button(/*server_ptr->task*/servp->name, servp);
2536 n_done++;
2537 break;
2538 case 0 :
2539 strcpy(node, server_ptr->node);
2540 strcpy(par, Curr_view_opt_par);
2541 if(!isdigit(node[0]))
2542 {
2543 ptr = strchr(node, '.');
2544 if(ptr)
2545 *ptr = '\0';
2546 ptr = strchr(par,'.');
2547 if(ptr)
2548 *ptr = '\0';
2549 }
2550 ptr = node;
2551 for(i = 0; i < (int)strlen(ptr); i++)
2552 ptr[i] = (char)tolower((int)ptr[i]);
2553 ptr = par;
2554 for(i = 0; i < (int)strlen(ptr); i++)
2555 ptr[i] = (char)tolower((int)ptr[i]);
2556 if(!strcmp(/*server_ptr->*/node, /*Curr_view_opt_*/par))
2557 {
2558 servp->button_id = create_button(/*server_ptr->task*/servp->name, servp);
2559 n_done++;
2560 }
2561 break;
2562 case 2 :
2563 found = 0;
2564 if(!(service_ptr = servp->service_ptr))
2565 break;
2566 for(j = 0; j < server_ptr->n_services; j++)
2567 {
2568 if(strstr(service_ptr->name, Curr_view_opt_par) > (char *)0)
2569 {
2570 found = 1;
2571 break;
2572 }
2573 service_ptr++;
2574 }
2575 if (found)
2576 {
2577 servp->button_id = create_button(/*server_ptr->task*/servp->name, servp);
2578 n_done++;
2579 }
2580 break;
2581 case 3 :
2582 if(server_ptr->n_services == -1)
2583 {
2584 servp->button_id = create_button(/*server_ptr->task*/servp->name, servp);
2585 n_done++;
2586 }
2587 else
2588 {
2589 if(servp->button_id)
2590 remove_button(servp);
2591 }
2592 n_done++;
2593 break;
2594 }
2595 }
2596 servp->busy = 2;
2597 if(servp->button_id)
2598 {
2599 if(Curr_view_opt != -1)
2600 {
2601 if (server_ptr->n_services == -1)
2602 {
2603 set_color(servp->button_id, XmNbackground, RED);
2604 get_something(servp->button_id,XmNuserData,&w);
2605 set_color(w, XmNbackground, RED);
2606 }
2607 else
2608 {
2609 set_color(servp->button_id, XmNbackground, GREEN);
2610 get_something(servp->button_id,XmNuserData,&w);
2611 set_color(w, XmNbackground, GREEN);
2612 }
2613 }
2614 }
2615 }
2616 else if (servp->busy == -1)
2617 {
2618 remove_button(servp);
2619 sll_remove((SLL *)Server_head, (SLL *)servp);
2620 if(servp->service_ptr)
2621 {
2622 free(servp->service_ptr);
2623 servp->service_ptr = 0;
2624 }
2625 prevp = servp;
2626 n_done++;
2627 }
2628 }
2629 if(prevp)
2630 {
2631 free(prevp);
2632 prevp = 0;
2633 }
2634 put_label();
2635 old_n_services = N_services;
2636 Force_update = 0;
2637 }
2638 XtAppAddTimeOut(app_context, 1000, update_show_servers, 0);
2639 ENABLE_AST
2640}
2641
2642Widget create_button(char *name, SERVER *servp)
2643{
2644Arg arglist[10];
2645int n;
2646/*
2647int n_services = -1;
2648*/
2649Widget w, ww, w_id;
2650void activate_services(), activate_clients();
2651char w_name[MAX_NAME];
2652
2653 w_name[0] = 0;
2654/*
2655 if(servp)
2656 n_services = servp->server.n_services;
2657*/
2658 strcpy(w_name,name);
2659 if(strlen(w_name) >= MAX_TASK_NAME - 4)
2660 w_name[16] = '\0';
2661 n = 0;
2662 XtSetArg(arglist[n], XmNorientation, XmVERTICAL); n++;
2663 XtSetArg(arglist[n], XmNentryAlignment, XmALIGNMENT_CENTER); n++;
2664 w_id = w = XmCreateMenuBar(Matrix_id[Curr_matrix],
2665 (String)XmStringCreateLtoR ( w_name,XmSTRING_DEFAULT_CHARSET),
2666 arglist,(Cardinal)n);
2667/*
2668 if(n_services == -1)
2669 set_color(w, XmNbackground, RED);
2670 else
2671 set_color(w, XmNbackground, GREEN);
2672*/
2673 XtManageChild(w);
2674 strcat(w_name,"1");
2675 n = 0;
2676 XtSetArg(arglist[n], XmNalignment, XmALIGNMENT_CENTER); n++;
2677 XtSetArg(arglist[n], XmNfontList, did_server_font); n++;
2678 w = XmCreateCascadeButton(w,
2679 (String)XmStringCreateLtoR ( w_name,XmSTRING_DEFAULT_CHARSET),
2680 arglist,(Cardinal)n);
2681 set_something(w,XmNlabelString,name);
2682 set_something(w,XmNalignment,XmALIGNMENT_CENTER);
2683/*
2684 if(n_services == -1)
2685 set_color(w, XmNbackground, RED);
2686 else
2687 set_color(w, XmNbackground, GREEN);
2688*/
2689 set_something(w_id,XmNuserData,w);
2690 strcat(w_name,"1");
2691 n = 0;
2692 ww = XmCreatePulldownMenu(w_id,
2693 (String)XmStringCreateLtoR ( w_name,XmSTRING_DEFAULT_CHARSET),
2694 arglist,(Cardinal)n);
2695 set_something(w,XmNsubMenuId,ww);
2696 XtManageChild(w);
2697 strcat(w_name,"1");
2698 n = 0;
2699 XtSetArg(arglist[n], XmNfontList, did_default_font); n++;
2700 w = XmCreatePushButton(ww,
2701 (String)XmStringCreateLtoR ( w_name,XmSTRING_DEFAULT_CHARSET),
2702 arglist,(Cardinal)n);
2703
2704 set_something(w,XmNlabelString,"Services");
2705 if(servp)
2706 {
2707 XtAddCallback(w,XmNactivateCallback, activate_services, servp);
2708 XtManageChild(w);
2709 strcat(w_name,"1");
2710 n = 0;
2711 XtSetArg(arglist[n], XmNfontList, did_default_font); n++;
2712 w = XmCreatePushButton(ww,
2713 (String)XmStringCreateLtoR ( w_name,XmSTRING_DEFAULT_CHARSET),
2714 arglist,(Cardinal)n);
2715
2716 set_something(w,XmNlabelString,"Clients");
2717 XtAddCallback(w,XmNactivateCallback, activate_clients, servp);
2718 XtManageChild(w);
2719 /*
2720 servp->popping = 0;
2721 create_client_popup(servp);
2722 */
2723 }
2724 return(w_id);
2725}
2726
2727void remove_all_buttons()
2728{
2729SERVER *servp;
2730
2731 servp = Server_head;
2732 while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
2733 {
2734 if(servp->button_id)
2735 {
2736 XtDestroyWidget(servp->button_id);
2737 servp->button_id = 0;
2738 servp->busy = 0;
2739 }
2740 }
2741}
2742
2743void remove_button(SERVER *servp)
2744{
2745
2746 if(servp->button_id)
2747 {
2748 XtDestroyWidget(servp->button_id);
2749 servp->button_id = 0;
2750 servp->busy = 0;
2751 }
2752}
2753
2754void activate_services(Widget w, SERVER *servp, unsigned long *reason)
2755{
2756DNS_SERVER_INFO *ptr;
2757char str[MAX_NAME];
2758Widget id,sel_id;
2759void got_service_list();
2760void kick_it();
2761
2762 if(w){}
2763 if(reason){}
2764 if(servp->pop_widget_id[0])
2765 {
2766 XtDestroyWidget(servp->pop_widget_id[0]);
2767 servp->pop_widget_id[0] = 0;
2768 /*
2769 return;
2770 */
2771 }
2772 Curr_servp = servp;
2773 ptr = &servp->server;
2774
2775 sel_id = put_popup(servp, 0,"Service Info");
2776
2777 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_OK_BUTTON);
2778 XtUnmanageChild(id);
2779
2780 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_LIST_LABEL);
2781 if (ptr->pid > 0x1000000)
2782 sprintf(str,"Server %s (pid = %X) on node %s\n\nprovides %d services :\n",
2783 servp->name, ptr->pid, ptr->node, ptr->n_services);
2784 else
2785 sprintf(str,"Server %s (pid = %d) on node %s\n\nprovides %d services :\n",
2786 servp->name, ptr->pid, ptr->node, ptr->n_services);
2787 set_something(sel_id,XmNlistLabelString,str);
2788
2789 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_LIST);
2790 Curr_service_list_id = id;
2791
2792 XmListAddItem(id,create_str(
2793 "Ordering services alphabeticaly, please be patient..."),1);
2794
2795 set_something(id,XmNlistItemCount,1);
2796 set_something(id,XmNlistVisibleItemCount,1);
2797
2798 sprintf(str,"%s/SERVICE_LIST",/*ptr->task*/servp->name);
2799 dic_info_service(str,ONCE_ONLY,20,0,0,
2800 got_service_list,(long)servp,"None",5);
2801 /*
2802#ifdef solaris
2803 */
2804 /*
2805 XtAppAddTimeOut(app_context, 1000, kick_it, 0);
2806 */
2807 /*
2808#endif
2809 */
2810}
2811
2812void kick_it()
2813{
2814 printf("kick_it\n");
2815}
2816
2817typedef char DID_SLOT[MAX_NAME];
2818
2819void got_service_list(SERVER **servp_ptr, char *buffer, int *size)
2820{
2821SERVER *servp;
2822void do_got_service_list();
2823
2824 if(size){}
2825 servp = *servp_ptr;
2826 if(Curr_service_list)
2827 free(Curr_service_list);
2828 Curr_service_list = malloc(strlen(buffer)+1);
2829 strcpy(Curr_service_list, buffer);
2830 /*
2831#ifdef solaris
2832 */
2833 Got_Service_List = servp;
2834 /*
2835#else
2836 do_got_service_list(servp);
2837#endif
2838 */
2839}
2840
2841void do_got_service_list(SERVER *servp)
2842{
2843char cmd_str[256], svc_str[256];
2844DNS_SERVER_INFO *ptr;
2845DNS_SERVICE_INFO *service_ptr;
2846Widget id;
2847char *curr_str, max_str[MAX_NAME], *sptr;
2848DID_SLOT *service_list;
2849int i, j, curr_index = 0, n_services;
2850XmString xstr;
2851void delete_str();
2852
2853 ptr = &servp->server;
2854 id = Curr_service_list_id;
2855
2856 XmListDeleteAllItems(id);
2857
2858 strcpy(cmd_str,"CMD: ");
2859 strcpy(svc_str,"SVC: ");
2860
2861 service_ptr = servp->service_ptr;
2862 service_list = (DID_SLOT *)malloc((size_t)(ptr->n_services * MAX_NAME));
2863 n_services = ptr->n_services;
2864
2865 for(i=0;i<n_services; i++)
2866 {
2867 strcpy(service_list[i],service_ptr->name);
2868 service_ptr++;
2869 }
2870 strcpy(max_str,"zzzzzzzzzzzzzzzzzzzzzzzzzzzz");
2871 for(i=0;i<n_services; i++)
2872 {
2873 curr_str = max_str;
2874 for(j=0;j<n_services; j++)
2875 {
2876 sptr = service_list[j];
2877 if(!*sptr)
2878 continue;
2879
2880 if(strcmp(sptr,curr_str) < 0)
2881 {
2882 curr_str = sptr;
2883 curr_index = j;
2884 }
2885 }
2886 service_list[curr_index][0] = '\0';
2887 service_ptr = &(servp->service_ptr[curr_index]);
2888 if(service_ptr->type)
2889 {
2890 strcpy(&cmd_str[5],service_ptr->name);
2891 xstr = create_str(cmd_str);
2892 XmListAddItem(id,xstr,i+1);
2893 delete_str(xstr);
2894 }
2895 else
2896 {
2897 strcpy(&svc_str[5],service_ptr->name);
2898 xstr = create_str(svc_str);
2899 XmListAddItem(id,xstr,i+1);
2900 delete_str(xstr);
2901 }
2902 }
2903 free(service_list);
2904
2905 set_something(id,XmNlistItemCount,i);
2906 set_something(id,XmNlistVisibleItemCount,(i < 20) ? i : 20);
2907}
2908
2909void show_clients(SERVER **servp_ptr, char *buffer, int *size)
2910{
2911SERVER *servp;
2912void do_show_clients();
2913
2914 if(size){}
2915 servp = *servp_ptr;
2916 if(Curr_client_list)
2917 free(Curr_client_list);
2918 Curr_client_list = malloc(strlen(buffer)+1);
2919 strcpy(Curr_client_list, buffer);
2920 /*
2921#ifdef solaris
2922 */
2923 Got_Client_List = servp;
2924 /*
2925#else
2926 do_show_clients(servp);
2927#endif
2928 */
2929}
2930
2931void do_show_clients(SERVER *servp)
2932{
2933int i = 0;
2934char str[2048], *strp, *strp1;
2935XmString xstr;
2936void delete_str();
2937
2938/*
2939DNS_SERVER_INFO *ptr;
2940 ptr = &servp->server;
2941 sel_id = servp->pop_widget_id[1];
2942 id = (Widget)XmSelectionBoxGetChild(sel_id,XmDIALOG_LIST_LABEL);
2943*/
2944 if(servp){}
2945 if(Curr_client_list[0] == -1)
2946 {
2947 sprintf(str,"Information not available\n");
2948 XmListAddItem(Curr_client_id,create_str(str),i+1);
2949 /*
2950 set_something(sel_id,XmNlistLabelString,str);
2951 */
2952 return;
2953 }
2954 /*
2955 sprintf(str,"Clients of %s are : \n",
2956 ptr->task);
2957 set_something(sel_id,XmNlistLabelString,str);
2958
2959 id = (Widget)XmSelectionBoxGetChild(sel_id,XmDIALOG_LIST);
2960 XmListDeleteAllItems(id);
2961 */
2962 strp1 = Curr_client_list;
2963 while(strp1)
2964 {
2965 if(!*strp1)
2966 break;
2967 sprintf(str,"Process ");
2968 strp = strp1;
2969 strp1 = strchr(strp,'@');
2970 *strp1 = '\0';
2971 strp1++;
2972 strcat(str,strp);
2973 strcat(str," on node ");
2974 strp = strp1;
2975 if( (strp1 = strchr(strp,'|')) )
2976 {
2977 *strp1 = '\0';
2978 strp1++;
2979 }
2980 strcat(str,strp);
2981 xstr = create_str(str);
2982 XmListAddItem(Curr_client_id,xstr,i+1);
2983 delete_str(xstr);
2984 i++;
2985 }
2986 if(!i)
2987 {
2988 sprintf(str,"NONE");
2989 xstr = create_str(str);
2990 XmListAddItem(Curr_client_id,xstr,i+1);
2991 delete_str(xstr);
2992 }
2993 /*
2994 set_something(id,XmNlistItemCount,i);
2995 */
2996 /*
2997 if(Matrix_id[Curr_matrix])
2998 XFlush(XtDisplay(Matrix_id[Curr_matrix]));
2999 */
3000}
3001
3002void activate_clients(Widget w, SERVER *servp, unsigned long *reason)
3003{
3004/*
3005DNS_SERVER_INFO *ptr;
3006*/
3007char str[100];
3008void show_clients();
3009void kick_it_again();
3010Widget id,sel_id;
3011
3012 if(w) {}
3013 if(reason){}
3014 Curr_servp = servp;
3015/*
3016 ptr = &servp->server;
3017*/
3018 if(servp->pop_widget_id[1])
3019 {
3020 XtDestroyWidget(servp->pop_widget_id[1]);
3021 servp->pop_widget_id[1] = 0;
3022 }
3023 sel_id = put_popup(servp,1,"Client Info");
3024
3025 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_HELP_BUTTON);
3026 XtUnmanageChild(id);
3027
3028 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_APPLY_BUTTON);
3029 XtUnmanageChild(id);
3030
3031 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_CANCEL_BUTTON);
3032 XtUnmanageChild(id);
3033
3034 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_TEXT);
3035 XtUnmanageChild(id);
3036
3037 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_SELECTION_LABEL);
3038 XtUnmanageChild(id);
3039 /*
3040 id = (Widget)XmSelectionBoxGetChild(sel_id,XmDIALOG_LIST_LABEL);
3041 */
3042 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_LIST);
3043 XmListDeleteAllItems(id);
3044
3045 Curr_client_id = id;
3046 sprintf(str,"Clients of %s are : \n",
3047 servp->name);
3048 set_something(sel_id,XmNlistLabelString,str);
3049
3050 sprintf(str,"%s/CLIENT_LIST",/*ptr->task*/servp->name);
3051 dic_info_service(str,ONCE_ONLY,10,0,0,
3052 show_clients,(long)servp,&no_link,1);
3053 /*
3054#ifdef solaris
3055 */
3056 /*
3057 XtAppAddTimeOut(app_context, 1000, kick_it_again, 0);
3058 */
3059 /*
3060#endif
3061 */
3062}
3063
3064void kick_it_again()
3065{
3066 printf("kick_it_again\n");
3067}
3068
3069Widget put_popup(SERVER *servp, int type, char *title)
3070{
3071 Widget id;
3072 void activate_services(), activate_clients();
3073 extern void set_title();
3074
3075 if(type)
3076 {
3077 id = create_client_dialog();
3078 /*
3079 XtAddCallback(id,XmNokCallback, activate_clients, servp);
3080 XtAddCallback(id,XmNcancelCallback, activate_clients, servp);
3081 */
3082 }
3083 else
3084 {
3085 id = create_server_dialog();
3086 /*
3087 XtAddCallback(id,XmNcancelCallback, activate_services, servp);
3088 */
3089 }
3090 servp->pop_widget_id[type] = id;
3091 /*
3092 }
3093 */
3094 XtManageChild(id);
3095 set_title(XtParent(id),title);
3096 return(id);
3097}
3098
3099Widget put_selection(int tag, char *title)
3100{
3101 Widget id = 0;
3102 extern void set_title();
3103
3104 if(pop_widget_id[tag])
3105 {
3106 XtDestroyWidget(pop_widget_id[tag]);
3107 }
3108 switch(tag)
3109 {
3110 case DID_SEL_NODE:
3111 id = create_node_selection();
3112 break;
3113 case DID_SEL_SERVICE:
3114 id = create_service_selection();
3115 break;
3116 case DID_KILL_ALL:
3117 id = create_kill_confirmation();
3118 break;
3119 case DID_SERVICE:
3120 id = create_service_dialog();
3121 break;
3122 case DID_COMMAND:
3123 id = create_send_command();
3124 break;
3125 }
3126
3127 pop_widget_id[tag] = id;
3128 XtManageChild(id);
3129 set_title(XtParent(id),title);
3130 return(id);
3131}
3132
3133void check_put_label(int tag)
3134{
3135 static int old_n_services = 0;
3136/*
3137 static int changing = 0;
3138*/
3139 void put_label();
3140
3141 if(tag){}
3142 if(N_services != old_n_services)
3143 {
3144 put_label();
3145/*
3146 if(N_services > old_n_services)
3147 changing = 1;
3148*/
3149 old_n_services = N_services;
3150
3151#ifdef linux
3152 show_servers();
3153#endif
3154 }
3155/*
3156 else
3157 {
3158 if(changing)
3159 {
3160 show_servers();
3161 changing = 0;
3162 }
3163 }
3164*/
3165}
3166
3167void put_label()
3168{
3169 char str[MAX_NAME], str1[MAX_NAME];
3170
3171 DISABLE_AST
3172 sprintf(str,"%d Servers known - %d Services Available\n",
3173 N_servers,N_services);
3174 switch(Curr_view_opt)
3175 {
3176 case 1 :
3177 strcat(str,"Displaying ALL Servers");
3178 break;
3179 case 0 :
3180 sprintf(str1,"Displaying Servers on node %s",Curr_view_opt_par);
3181 strcat(str,str1);
3182 break;
3183 case 2 :
3184 sprintf(str1,"Displaying Servers providing Service *%s*",
3185 Curr_view_opt_par);
3186 strcat(str,str1);
3187 break;
3188 case 3 :
3189 strcat(str,"Displaying Servers in ERROR");
3190 break;
3191 case -1 :
3192 strcat(str,"Please Select Viewing Option");
3193 break;
3194 }
3195 set_something(Label_id,XmNlabelString,str);
3196 XFlush(XtDisplay(Label_id));
3197 ENABLE_AST
3198}
3199
3200Widget create_client_dialog()
3201{
3202 Widget id;
3203 id = create_selection_dialog("Dismiss","","","","",DID_CLIENTS, 3);
3204 return(id);
3205
3206}
3207
3208Widget create_server_dialog()
3209{
3210 Widget id;
3211 id = create_selection_dialog("","View / Send","Dismiss","",
3212 "Service / Command :",
3213 DID_SERVICES, 20);
3214 return(id);
3215}
3216
3217Widget create_node_selection()
3218{
3219 Widget id;
3220 id = create_selection_dialog("","","","Nodes :","Selected Node :",DID_SEL_NODE, 8);
3221 return(id);
3222
3223}
3224
3225Widget create_service_selection()
3226{
3227 Widget id;
3228 /*
3229 id = create_prompt_dialog("Enter Service Name :",DID_SEL_SERVICE);
3230 */
3231 id = create_selection_dialog("","","","","Enter Service Name (or search string):",DID_SEL_SERVICE, 0);
3232 return(id);
3233
3234}
3235
3236Widget create_send_command()
3237{
3238 Widget id;
3239 char str[256], str1[256];
3240
3241 sprintf(str,"Command to %s (%s)\n\n",
3242 Curr_service_name, Curr_service_format);
3243
3244 id = create_selection_dialog("","","",str,"Command:",DID_COMMAND, 1);
3245
3246 strcpy(str1,"Please enter items separated by spaces:\n(for example: 2 0x123 'A' 23.4 \"a text\")");
3247
3248 set_something(id,XmNselectionLabelString,str1);
3249
3250 return(id);
3251
3252}
3253
3254Widget create_kill_confirmation()
3255{
3256 Widget id;
3257 id = create_question_dialog("Do you really want to kill ALL DIM servers ?",
3258 DID_KILL_ALL);
3259 return(id);
3260
3261}
3262
3263Widget create_selection_dialog(char *ok, char *apply, char *cancel, char *list, char *sel,
3264 long tag, int items)
3265{
3266Widget sd;
3267XmString xmOk, xmApply, xmCancel, xmList, xmSelection;
3268Arg ar[20];
3269int n;
3270
3271 xmList = create_str(list);
3272 xmOk = create_str(ok);
3273 xmApply = create_str(apply);
3274 xmCancel = create_str (cancel);
3275 xmSelection = create_str (sel);
3276
3277 n = 0;
3278 /*
3279 XtSetArg(ar[n],XmNdialogStyle,XmDIALOG_FULL_APPLICATION_MODAL); n++;
3280 XtSetArg(ar[n],XmNmwmFunctions,MWM_FUNC_MOVE); n++;
3281 */
3282 XtSetArg(ar[n],XmNtitle,"Selection"); n++;
3283 XtSetArg(ar[n],XmNlabelFontList, did_default_font); n++;
3284 XtSetArg(ar[n],XmNbuttonFontList, did_default_font); n++;
3285 XtSetArg(ar[n],XmNtextFontList, did_small_font); n++;
3286 XtSetArg(ar[n],XmNborderWidth, 1); n++;
3287 XtSetArg(ar[n],XmNlistLabelString, xmList); n++;
3288 XtSetArg(ar[n],XmNlistVisibleItemCount,items); n++;
3289 if(ok[0])
3290 {
3291 XtSetArg(ar[n],XmNokLabelString, xmOk); n++;
3292 }
3293 if(apply[0])
3294 {
3295 XtSetArg(ar[n],XmNapplyLabelString, xmApply); n++;
3296 }
3297 if(cancel[0])
3298 {
3299 XtSetArg(ar[n],XmNcancelLabelString, xmCancel); n++;
3300 }
3301 if(sel[0])
3302 {
3303 XtSetArg(ar[n],XmNselectionLabelString, xmSelection); n++;
3304 }
3305 sd = XmCreateSelectionDialog ( toplevel_widget, "Selection", ar, (Cardinal)n );
3306 XmStringFree(xmList);
3307 XmStringFree(xmOk);
3308 XmStringFree(xmApply);
3309 XmStringFree(xmCancel);
3310 XmStringFree(xmSelection);
3311 if(tag >= 0)
3312 {
3313 XtAddCallback ( sd, XmNcancelCallback,
3314 (XtCallbackProc)cancel_pop_up, (XtPointer)tag );
3315 XtAddCallback ( sd, XmNapplyCallback,
3316 (XtCallbackProc)ok_pop_up, (XtPointer)tag );
3317 XtAddCallback ( sd, XmNokCallback,
3318 (XtCallbackProc)ok_pop_up, (XtPointer)tag );
3319 }
3320 return(sd);
3321}
3322
3323Widget create_file_selection_dialog(long type)
3324{
3325Widget sd;
3326XmString xm1;
3327Arg ar[20];
3328int n;
3329
3330 xm1 = create_str ("");
3331 n = 0;
3332 /*
3333 XtSetArg(ar[n],XmNdialogStyle,XmDIALOG_FULL_APPLICATION_MODAL); n++;
3334 XtSetArg(ar[n],XmNmwmFunctions,MWM_FUNC_MOVE); n++;
3335 */
3336 XtSetArg(ar[n],XmNtitle,"FileSelection"); n++;
3337 XtSetArg(ar[n],XmNlabelFontList, did_default_font); n++;
3338 XtSetArg(ar[n],XmNbuttonFontList, did_default_font); n++;
3339 XtSetArg(ar[n],XmNtextFontList, did_default_font); n++;
3340 XtSetArg(ar[n],XmNborderWidth, 1); n++;
3341 XtSetArg(ar[n],XmNwidth, 500); n++;
3342 XtSetArg(ar[n],XmNdirMask, xm1); n++;
3343 sd = XmCreateFileSelectionDialog ( toplevel_widget, "FileSelection", ar, (Cardinal)n );
3344
3345 XmStringFree(xm1);
3346
3347 XtAddCallback ( sd, XmNcancelCallback,
3348 (XtCallbackProc)cancel_pop_up, (XtPointer)type );
3349 XtAddCallback ( sd, XmNokCallback,
3350 (XtCallbackProc)ok_pop_up, (XtPointer)type );
3351
3352 return(sd);
3353}
3354
3355Widget create_prompt_dialog(char *label, long tag)
3356{
3357Widget sd;
3358XmString xm1;
3359Arg ar[20];
3360int n;
3361
3362 xm1 = create_str (label);
3363 n = 0;
3364 XtSetArg(ar[n],XmNlabelFontList, did_default_font); n++;
3365 XtSetArg(ar[n],XmNbuttonFontList, did_default_font); n++;
3366 XtSetArg(ar[n],XmNborderWidth, 1); n++;
3367 /*
3368 XtSetArg(ar[n],XmNwidth, 450); n++;
3369 XtSetArg(ar[n],XmNresizePolicy, XmRESIZE_NONE); n++;
3370 */
3371 XtSetArg(ar[n],XmNselectionLabelString, xm1); n++;
3372 sd = XmCreatePromptDialog ( toplevel_widget, "Prompt", ar, (Cardinal)n );
3373
3374 XmStringFree(xm1);
3375
3376 XtAddCallback ( sd, XmNcancelCallback,
3377 (XtCallbackProc)cancel_pop_up, (XtPointer)tag );
3378 XtAddCallback ( sd, XmNokCallback,
3379 (XtCallbackProc)ok_pop_up, (XtPointer)tag );
3380
3381 return(sd);
3382}
3383
3384Widget create_question_dialog(char *label, long tag)
3385{
3386Widget sd;
3387XmString xm1;
3388Arg ar[20];
3389int n;
3390
3391 xm1 = create_str (label);
3392 n = 0;
3393 XtSetArg(ar[n],XmNlabelFontList, did_default_font); n++;
3394 XtSetArg(ar[n],XmNbuttonFontList, did_default_font); n++;
3395 XtSetArg(ar[n],XmNborderWidth, 1); n++;
3396 /*
3397 XtSetArg(ar[n],XmNwidth, 450); n++;
3398 XtSetArg(ar[n],XmNresizePolicy, XmRESIZE_NONE); n++;
3399 */
3400 XtSetArg(ar[n],XmNmessageString, xm1); n++;
3401 sd = XmCreateQuestionDialog ( toplevel_widget, "Question", ar, (Cardinal)n );
3402
3403 XmStringFree(xm1);
3404
3405 XtAddCallback ( sd, XmNcancelCallback,
3406 (XtCallbackProc)cancel_pop_up, (XtPointer)tag );
3407 XtAddCallback ( sd, XmNokCallback,
3408 (XtCallbackProc)ok_pop_up, (XtPointer)tag );
3409
3410 return(sd);
3411}
3412
3413Widget create_service_dialog()
3414{
3415Widget fd, rc, sw, lb, rc1;
3416XmString xm1;
3417Arg ar[20];
3418int n, par;
3419unsigned long reason;
3420
3421 n = 0;
3422 XtSetArg(ar[n],XmNborderWidth, 1); n++;
3423 XtSetArg(ar[n],XmNresizePolicy, XmRESIZE_ANY); n++;
3424 fd = XmCreateFormDialog ( toplevel_widget, "Form", ar, (Cardinal)n );
3425 XtManageChild(fd);
3426
3427 /* create rowcolumn */
3428 n = 0;
3429 XtSetArg(ar[n],XmNborderWidth, 1); n++;
3430 XtSetArg(ar[n],XmNentryAlignment, XmALIGNMENT_CENTER); n++;
3431 XtSetArg(ar[n],XmNbottomAttachment, XmATTACH_FORM); n++;
3432 XtSetArg(ar[n],XmNbottomOffset, 0); n++;
3433 XtSetArg(ar[n],XmNrightAttachment, XmATTACH_FORM); n++;
3434 XtSetArg(ar[n],XmNrightOffset, 0); n++;
3435 XtSetArg(ar[n],XmNtopAttachment, XmATTACH_FORM); n++;
3436 XtSetArg(ar[n],XmNtopOffset, 0); n++;
3437 XtSetArg(ar[n],XmNleftAttachment, XmATTACH_FORM); n++;
3438 XtSetArg(ar[n],XmNleftOffset, 0); n++;
3439 rc = XmCreateRowColumn ( fd, "rowcol", ar, (Cardinal)n );
3440 XtManageChild(rc);
3441
3442 /* create scrolled window */
3443 n = 0;
3444 XtSetArg ( ar[n], XmNwidth, 770); n++;
3445 XtSetArg ( ar[n], XmNheight, 350); n++;
3446 XtSetArg ( ar[n], XmNscrollBarDisplayPolicy, XmAS_NEEDED); n++;
3447 XtSetArg ( ar[n], XmNscrollingPolicy, XmAUTOMATIC); n++;
3448
3449 sw = XmCreateScrolledWindow ( rc, "ScrollWin", ar, (Cardinal)n );
3450 XtManageChild ( sw );
3451
3452 /* create label */
3453 n = 0;
3454 xm1 = create_str(" ");
3455 XtSetArg(ar[n],XmNfontList, did_small_font); n++;
3456 XtSetArg(ar[n],XmNlabelString, xm1); n++;
3457 XtSetArg(ar[n],XmNalignment, XmALIGNMENT_BEGINNING); n++;
3458 lb = XmCreateLabel ( sw, "label", ar, (Cardinal)n );
3459 XtManageChild(lb);
3460 XmStringFree(xm1);
3461 par = 1;
3462 reason = 0;
3463 create_label(lb, &par, &reason);
3464
3465 /* create button rowcolumn */
3466 n = 0;
3467 XtSetArg(ar[n],XmNborderWidth, 0); n++;
3468 XtSetArg(ar[n],XmNentryAlignment, XmALIGNMENT_CENTER); n++;
3469 XtSetArg(ar[n],XmNorientation, XmVERTICAL); n++;
3470 XtSetArg(ar[n],XmNnumColumns, 3); n++;
3471 XtSetArg(ar[n],XmNpacking, XmPACK_COLUMN); n++;
3472 rc1 = XmCreateRowColumn ( rc, "buttons", ar, (Cardinal)n );
3473 XtManageChild(rc1);
3474 /*
3475 create_push_button(rc1,"View Standard",MAX_POP_UPS+1);
3476 create_push_button(rc1,"View Float",MAX_POP_UPS+2);
3477 create_push_button(rc1,"View Double",MAX_POP_UPS+3);
3478 */
3479 SubscribeButton = create_push_button(rc1," Subscribe (On Change) ",
3480 MAX_POP_UPS+5);
3481 Subscribe10Button = create_push_button(rc1," Subscribe (Update Rate 10 seconds) ",
3482 MAX_POP_UPS+4);
3483 create_push_button(rc1,"Dismiss",DID_SERVICE);
3484 Curr_service_print_type = 0;
3485
3486 return(fd);
3487}
3488
3489Widget create_push_button(Widget parent, char *str, long tag)
3490{
3491Widget b;
3492XmString xm1;
3493Arg ar[20];
3494int n;
3495
3496 n = 0;
3497 xm1 = create_str(str);
3498 XtSetArg(ar[n],XmNalignment, XmALIGNMENT_CENTER); n++;
3499 XtSetArg(ar[n],XmNfontList, did_default_font); n++;
3500 XtSetArg(ar[n],XmNlabelString, xm1); n++;
3501 b = XmCreatePushButton ( parent, "button", ar, (Cardinal)n );
3502
3503 XtManageChild(b);
3504 XmStringFree(xm1);
3505
3506 XtAddCallback ( b, XmNactivateCallback,
3507 (XtCallbackProc)cancel_pop_up, (XtPointer)tag );
3508 return(b);
3509}
3510
Note: See TracBrowser for help on using the repository browser.