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

Last change on this file since 14698 was 14698, checked in by tbretz, 12 years ago
Updated to v20r4
File size: 78.2 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,"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] = toupper(*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], max_str[MAX_NODE_NAME];
1036char *ptr, *nodeptrs[MAX_CONNS], *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 for(j = 0; j < (int)strlen(sptr); j++)
1055 sptr[j] = tolower(sptr[j]);
1056 *ptr++ = '\0';
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,(int)(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(1024 + (*size)*16);
1186 Service_buffer = malloc(*size);
1187 memcpy(Service_buffer, (char *)buffer, *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/sizeof(int);
1306 else
1307 size = num;
1308 psize = size * 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/sizeof(int);
1316 else
1317 size = num;
1318 psize = size * 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/sizeof(short);
1326 else
1327 size = num;
1328 psize = size * 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/sizeof(float);
1336 else
1337 size = num;
1338 psize = size * 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/sizeof(double);
1346 else
1347 size = num;
1348 psize = size * 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/sizeof(longlong);
1356 else
1357 size = num;
1358 psize = size * 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(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 = strlen(strp)+1;
2146 strncpy((char *)ptr,strp,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 = 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 = 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*sizeof(DNS_SERVICE_INFO);
2407 servp->service_ptr = (DNS_SERVICE_INFO *)malloc(service_size);
2408 memcpy(servp->service_ptr, buffer->services, 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 ptr = strchr(node, '.');
2542 if(ptr)
2543 *ptr = '\0';
2544 ptr = strchr(par,'.');
2545 if(ptr)
2546 *ptr = '\0';
2547 ptr = node;
2548 for(i = 0; i < (int)strlen(ptr); i++)
2549 ptr[i] = tolower(ptr[i]);
2550 ptr = par;
2551 for(i = 0; i < (int)strlen(ptr); i++)
2552 ptr[i] = tolower(ptr[i]);
2553 if(!strcmp(/*server_ptr->*/node, /*Curr_view_opt_*/par))
2554 {
2555 servp->button_id = create_button(/*server_ptr->task*/servp->name, servp);
2556 n_done++;
2557 }
2558 break;
2559 case 2 :
2560 found = 0;
2561 if(!(service_ptr = servp->service_ptr))
2562 break;
2563 for(j = 0; j < server_ptr->n_services; j++)
2564 {
2565 if(strstr(service_ptr->name, Curr_view_opt_par) > (char *)0)
2566 {
2567 found = 1;
2568 break;
2569 }
2570 service_ptr++;
2571 }
2572 if (found)
2573 {
2574 servp->button_id = create_button(/*server_ptr->task*/servp->name, servp);
2575 n_done++;
2576 }
2577 break;
2578 case 3 :
2579 if(server_ptr->n_services == -1)
2580 {
2581 servp->button_id = create_button(/*server_ptr->task*/servp->name, servp);
2582 n_done++;
2583 }
2584 else
2585 {
2586 if(servp->button_id)
2587 remove_button(servp);
2588 }
2589 n_done++;
2590 break;
2591 }
2592 }
2593 servp->busy = 2;
2594 if(servp->button_id)
2595 {
2596 if(Curr_view_opt != -1)
2597 {
2598 if (server_ptr->n_services == -1)
2599 {
2600 set_color(servp->button_id, XmNbackground, RED);
2601 get_something(servp->button_id,XmNuserData,&w);
2602 set_color(w, XmNbackground, RED);
2603 }
2604 else
2605 {
2606 set_color(servp->button_id, XmNbackground, GREEN);
2607 get_something(servp->button_id,XmNuserData,&w);
2608 set_color(w, XmNbackground, GREEN);
2609 }
2610 }
2611 }
2612 }
2613 else if (servp->busy == -1)
2614 {
2615 remove_button(servp);
2616 sll_remove((SLL *)Server_head, (SLL *)servp);
2617 if(servp->service_ptr)
2618 {
2619 free(servp->service_ptr);
2620 servp->service_ptr = 0;
2621 }
2622 prevp = servp;
2623 n_done++;
2624 }
2625 }
2626 if(prevp)
2627 {
2628 free(prevp);
2629 prevp = 0;
2630 }
2631 put_label();
2632 old_n_services = N_services;
2633 Force_update = 0;
2634 }
2635 XtAppAddTimeOut(app_context, 1000, update_show_servers, 0);
2636 ENABLE_AST
2637}
2638
2639Widget create_button(char *name, SERVER *servp)
2640{
2641Arg arglist[10];
2642int n;
2643/*
2644int n_services = -1;
2645*/
2646Widget w, ww, w_id;
2647void activate_services(), activate_clients();
2648char w_name[MAX_NAME];
2649
2650 w_name[0] = 0;
2651/*
2652 if(servp)
2653 n_services = servp->server.n_services;
2654*/
2655 strcpy(w_name,name);
2656 if(strlen(w_name) >= MAX_TASK_NAME - 4)
2657 w_name[16] = '\0';
2658 n = 0;
2659 XtSetArg(arglist[n], XmNorientation, XmVERTICAL); n++;
2660 XtSetArg(arglist[n], XmNentryAlignment, XmALIGNMENT_CENTER); n++;
2661 w_id = w = XmCreateMenuBar(Matrix_id[Curr_matrix],
2662 (String)XmStringCreateLtoR ( w_name,XmSTRING_DEFAULT_CHARSET),
2663 arglist,n);
2664/*
2665 if(n_services == -1)
2666 set_color(w, XmNbackground, RED);
2667 else
2668 set_color(w, XmNbackground, GREEN);
2669*/
2670 XtManageChild(w);
2671 strcat(w_name,"1");
2672 n = 0;
2673 XtSetArg(arglist[n], XmNalignment, XmALIGNMENT_CENTER); n++;
2674 XtSetArg(arglist[n], XmNfontList, did_server_font); n++;
2675 w = XmCreateCascadeButton(w,
2676 (String)XmStringCreateLtoR ( w_name,XmSTRING_DEFAULT_CHARSET),
2677 arglist,n);
2678 set_something(w,XmNlabelString,name);
2679 set_something(w,XmNalignment,XmALIGNMENT_CENTER);
2680/*
2681 if(n_services == -1)
2682 set_color(w, XmNbackground, RED);
2683 else
2684 set_color(w, XmNbackground, GREEN);
2685*/
2686 set_something(w_id,XmNuserData,w);
2687 strcat(w_name,"1");
2688 n = 0;
2689 ww = XmCreatePulldownMenu(w_id,
2690 (String)XmStringCreateLtoR ( w_name,XmSTRING_DEFAULT_CHARSET),
2691 arglist,n);
2692 set_something(w,XmNsubMenuId,ww);
2693 XtManageChild(w);
2694 strcat(w_name,"1");
2695 n = 0;
2696 XtSetArg(arglist[n], XmNfontList, did_default_font); n++;
2697 w = XmCreatePushButton(ww,
2698 (String)XmStringCreateLtoR ( w_name,XmSTRING_DEFAULT_CHARSET),
2699 arglist,n);
2700
2701 set_something(w,XmNlabelString,"Services");
2702 if(servp)
2703 {
2704 XtAddCallback(w,XmNactivateCallback, activate_services, servp);
2705 XtManageChild(w);
2706 strcat(w_name,"1");
2707 n = 0;
2708 XtSetArg(arglist[n], XmNfontList, did_default_font); n++;
2709 w = XmCreatePushButton(ww,
2710 (String)XmStringCreateLtoR ( w_name,XmSTRING_DEFAULT_CHARSET),
2711 arglist,n);
2712
2713 set_something(w,XmNlabelString,"Clients");
2714 XtAddCallback(w,XmNactivateCallback, activate_clients, servp);
2715 XtManageChild(w);
2716 /*
2717 servp->popping = 0;
2718 create_client_popup(servp);
2719 */
2720 }
2721 return(w_id);
2722}
2723
2724void remove_all_buttons()
2725{
2726SERVER *servp;
2727
2728 servp = Server_head;
2729 while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
2730 {
2731 if(servp->button_id)
2732 {
2733 XtDestroyWidget(servp->button_id);
2734 servp->button_id = 0;
2735 servp->busy = 0;
2736 }
2737 }
2738}
2739
2740void remove_button(SERVER *servp)
2741{
2742
2743 if(servp->button_id)
2744 {
2745 XtDestroyWidget(servp->button_id);
2746 servp->button_id = 0;
2747 servp->busy = 0;
2748 }
2749}
2750
2751void activate_services(Widget w, SERVER *servp, unsigned long *reason)
2752{
2753DNS_SERVER_INFO *ptr;
2754char str[MAX_NAME];
2755Widget id,sel_id;
2756void got_service_list();
2757void kick_it();
2758
2759 if(w){}
2760 if(reason){}
2761 if(servp->pop_widget_id[0])
2762 {
2763 XtDestroyWidget(servp->pop_widget_id[0]);
2764 servp->pop_widget_id[0] = 0;
2765 /*
2766 return;
2767 */
2768 }
2769 Curr_servp = servp;
2770 ptr = &servp->server;
2771
2772 sel_id = put_popup(servp, 0,"Service Info");
2773
2774 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_OK_BUTTON);
2775 XtUnmanageChild(id);
2776
2777 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_LIST_LABEL);
2778 if (ptr->pid > 0x1000000)
2779 sprintf(str,"Server %s (pid = %X) on node %s\n\nprovides %d services :\n",
2780 servp->name, ptr->pid, ptr->node, ptr->n_services);
2781 else
2782 sprintf(str,"Server %s (pid = %d) on node %s\n\nprovides %d services :\n",
2783 servp->name, ptr->pid, ptr->node, ptr->n_services);
2784 set_something(sel_id,XmNlistLabelString,str);
2785
2786 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_LIST);
2787 Curr_service_list_id = id;
2788
2789 XmListAddItem(id,create_str(
2790 "Ordering services alphabeticaly, please be patient..."),1);
2791
2792 set_something(id,XmNlistItemCount,1);
2793 set_something(id,XmNlistVisibleItemCount,1);
2794
2795 sprintf(str,"%s/SERVICE_LIST",/*ptr->task*/servp->name);
2796 dic_info_service(str,ONCE_ONLY,20,0,0,
2797 got_service_list,(long)servp,"None",5);
2798 /*
2799#ifdef solaris
2800 */
2801 /*
2802 XtAppAddTimeOut(app_context, 1000, kick_it, 0);
2803 */
2804 /*
2805#endif
2806 */
2807}
2808
2809void kick_it()
2810{
2811 printf("kick_it\n");
2812}
2813
2814typedef char DID_SLOT[MAX_NAME];
2815
2816void got_service_list(SERVER **servp_ptr, char *buffer, int *size)
2817{
2818SERVER *servp;
2819void do_got_service_list();
2820
2821 if(size){}
2822 servp = *servp_ptr;
2823 if(Curr_service_list)
2824 free(Curr_service_list);
2825 Curr_service_list = malloc(strlen(buffer)+1);
2826 strcpy(Curr_service_list, buffer);
2827 /*
2828#ifdef solaris
2829 */
2830 Got_Service_List = servp;
2831 /*
2832#else
2833 do_got_service_list(servp);
2834#endif
2835 */
2836}
2837
2838void do_got_service_list(SERVER *servp)
2839{
2840char cmd_str[256], svc_str[256];
2841DNS_SERVER_INFO *ptr;
2842DNS_SERVICE_INFO *service_ptr;
2843Widget id;
2844char *curr_str, max_str[MAX_NAME], *sptr;
2845DID_SLOT *service_list;
2846int i, j, curr_index = 0, n_services;
2847XmString xstr;
2848void delete_str();
2849
2850 ptr = &servp->server;
2851 id = Curr_service_list_id;
2852
2853 XmListDeleteAllItems(id);
2854
2855 strcpy(cmd_str,"CMD: ");
2856 strcpy(svc_str,"SVC: ");
2857
2858 service_ptr = servp->service_ptr;
2859 service_list = (DID_SLOT *)malloc(ptr->n_services * MAX_NAME);
2860 n_services = ptr->n_services;
2861
2862 for(i=0;i<n_services; i++)
2863 {
2864 strcpy(service_list[i],service_ptr->name);
2865 service_ptr++;
2866 }
2867 strcpy(max_str,"zzzzzzzzzzzzzzzzzzzzzzzzzzzz");
2868 for(i=0;i<n_services; i++)
2869 {
2870 curr_str = max_str;
2871 for(j=0;j<n_services; j++)
2872 {
2873 sptr = service_list[j];
2874 if(!*sptr)
2875 continue;
2876
2877 if(strcmp(sptr,curr_str) < 0)
2878 {
2879 curr_str = sptr;
2880 curr_index = j;
2881 }
2882 }
2883 service_list[curr_index][0] = '\0';
2884 service_ptr = &(servp->service_ptr[curr_index]);
2885 if(service_ptr->type)
2886 {
2887 strcpy(&cmd_str[5],service_ptr->name);
2888 xstr = create_str(cmd_str);
2889 XmListAddItem(id,xstr,i+1);
2890 delete_str(xstr);
2891 }
2892 else
2893 {
2894 strcpy(&svc_str[5],service_ptr->name);
2895 xstr = create_str(svc_str);
2896 XmListAddItem(id,xstr,i+1);
2897 delete_str(xstr);
2898 }
2899 }
2900 free(service_list);
2901
2902 set_something(id,XmNlistItemCount,i);
2903 set_something(id,XmNlistVisibleItemCount,(i < 20) ? i : 20);
2904}
2905
2906void show_clients(SERVER **servp_ptr, char *buffer, int *size)
2907{
2908SERVER *servp;
2909void do_show_clients();
2910
2911 if(size){}
2912 servp = *servp_ptr;
2913 if(Curr_client_list)
2914 free(Curr_client_list);
2915 Curr_client_list = malloc(strlen(buffer)+1);
2916 strcpy(Curr_client_list, buffer);
2917 /*
2918#ifdef solaris
2919 */
2920 Got_Client_List = servp;
2921 /*
2922#else
2923 do_show_clients(servp);
2924#endif
2925 */
2926}
2927
2928void do_show_clients(SERVER *servp)
2929{
2930int i = 0;
2931char str[2048], *strp, *strp1;
2932XmString xstr;
2933void delete_str();
2934
2935/*
2936DNS_SERVER_INFO *ptr;
2937 ptr = &servp->server;
2938 sel_id = servp->pop_widget_id[1];
2939 id = (Widget)XmSelectionBoxGetChild(sel_id,XmDIALOG_LIST_LABEL);
2940*/
2941 if(servp){}
2942 if(Curr_client_list[0] == -1)
2943 {
2944 sprintf(str,"Information not available\n");
2945 XmListAddItem(Curr_client_id,create_str(str),i+1);
2946 /*
2947 set_something(sel_id,XmNlistLabelString,str);
2948 */
2949 return;
2950 }
2951 /*
2952 sprintf(str,"Clients of %s are : \n",
2953 ptr->task);
2954 set_something(sel_id,XmNlistLabelString,str);
2955
2956 id = (Widget)XmSelectionBoxGetChild(sel_id,XmDIALOG_LIST);
2957 XmListDeleteAllItems(id);
2958 */
2959 strp1 = Curr_client_list;
2960 while(strp1)
2961 {
2962 if(!*strp1)
2963 break;
2964 sprintf(str,"Process ");
2965 strp = strp1;
2966 strp1 = strchr(strp,'@');
2967 *strp1 = '\0';
2968 strp1++;
2969 strcat(str,strp);
2970 strcat(str," on node ");
2971 strp = strp1;
2972 if( (strp1 = strchr(strp,'|')) )
2973 {
2974 *strp1 = '\0';
2975 strp1++;
2976 }
2977 strcat(str,strp);
2978 xstr = create_str(str);
2979 XmListAddItem(Curr_client_id,xstr,i+1);
2980 delete_str(xstr);
2981 i++;
2982 }
2983 if(!i)
2984 {
2985 sprintf(str,"NONE");
2986 xstr = create_str(str);
2987 XmListAddItem(Curr_client_id,xstr,i+1);
2988 delete_str(xstr);
2989 }
2990 /*
2991 set_something(id,XmNlistItemCount,i);
2992 */
2993 /*
2994 if(Matrix_id[Curr_matrix])
2995 XFlush(XtDisplay(Matrix_id[Curr_matrix]));
2996 */
2997}
2998
2999void activate_clients(Widget w, SERVER *servp, unsigned long *reason)
3000{
3001/*
3002DNS_SERVER_INFO *ptr;
3003*/
3004char str[100];
3005void show_clients();
3006void kick_it_again();
3007Widget id,sel_id;
3008
3009 if(w) {}
3010 if(reason){}
3011 Curr_servp = servp;
3012/*
3013 ptr = &servp->server;
3014*/
3015 if(servp->pop_widget_id[1])
3016 {
3017 XtDestroyWidget(servp->pop_widget_id[1]);
3018 servp->pop_widget_id[1] = 0;
3019 }
3020 sel_id = put_popup(servp,1,"Client Info");
3021
3022 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_HELP_BUTTON);
3023 XtUnmanageChild(id);
3024
3025 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_APPLY_BUTTON);
3026 XtUnmanageChild(id);
3027
3028 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_CANCEL_BUTTON);
3029 XtUnmanageChild(id);
3030
3031 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_TEXT);
3032 XtUnmanageChild(id);
3033
3034 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_SELECTION_LABEL);
3035 XtUnmanageChild(id);
3036 /*
3037 id = (Widget)XmSelectionBoxGetChild(sel_id,XmDIALOG_LIST_LABEL);
3038 */
3039 id = XmSelectionBoxGetChild(sel_id,XmDIALOG_LIST);
3040 XmListDeleteAllItems(id);
3041
3042 Curr_client_id = id;
3043 sprintf(str,"Clients of %s are : \n",
3044 servp->name);
3045 set_something(sel_id,XmNlistLabelString,str);
3046
3047 sprintf(str,"%s/CLIENT_LIST",/*ptr->task*/servp->name);
3048 dic_info_service(str,ONCE_ONLY,10,0,0,
3049 show_clients,(long)servp,&no_link,1);
3050 /*
3051#ifdef solaris
3052 */
3053 /*
3054 XtAppAddTimeOut(app_context, 1000, kick_it_again, 0);
3055 */
3056 /*
3057#endif
3058 */
3059}
3060
3061void kick_it_again()
3062{
3063 printf("kick_it_again\n");
3064}
3065
3066Widget put_popup(SERVER *servp, int type, char *title)
3067{
3068 Widget id;
3069 void activate_services(), activate_clients();
3070 extern void set_title();
3071
3072 if(type)
3073 {
3074 id = create_client_dialog();
3075 /*
3076 XtAddCallback(id,XmNokCallback, activate_clients, servp);
3077 XtAddCallback(id,XmNcancelCallback, activate_clients, servp);
3078 */
3079 }
3080 else
3081 {
3082 id = create_server_dialog();
3083 /*
3084 XtAddCallback(id,XmNcancelCallback, activate_services, servp);
3085 */
3086 }
3087 servp->pop_widget_id[type] = id;
3088 /*
3089 }
3090 */
3091 XtManageChild(id);
3092 set_title(XtParent(id),title);
3093 return(id);
3094}
3095
3096Widget put_selection(int tag, char *title)
3097{
3098 Widget id = 0;
3099 extern void set_title();
3100
3101 if(pop_widget_id[tag])
3102 {
3103 XtDestroyWidget(pop_widget_id[tag]);
3104 }
3105 switch(tag)
3106 {
3107 case DID_SEL_NODE:
3108 id = create_node_selection();
3109 break;
3110 case DID_SEL_SERVICE:
3111 id = create_service_selection();
3112 break;
3113 case DID_KILL_ALL:
3114 id = create_kill_confirmation();
3115 break;
3116 case DID_SERVICE:
3117 id = create_service_dialog();
3118 break;
3119 case DID_COMMAND:
3120 id = create_send_command();
3121 break;
3122 }
3123
3124 pop_widget_id[tag] = id;
3125 XtManageChild(id);
3126 set_title(XtParent(id),title);
3127 return(id);
3128}
3129
3130void check_put_label(int tag)
3131{
3132 static int old_n_services = 0;
3133/*
3134 static int changing = 0;
3135*/
3136 void put_label();
3137
3138 if(tag){}
3139 if(N_services != old_n_services)
3140 {
3141 put_label();
3142/*
3143 if(N_services > old_n_services)
3144 changing = 1;
3145*/
3146 old_n_services = N_services;
3147
3148#ifdef linux
3149 show_servers();
3150#endif
3151 }
3152/*
3153 else
3154 {
3155 if(changing)
3156 {
3157 show_servers();
3158 changing = 0;
3159 }
3160 }
3161*/
3162}
3163
3164void put_label()
3165{
3166 char str[MAX_NAME], str1[MAX_NAME];
3167
3168 DISABLE_AST
3169 sprintf(str,"%d Servers known - %d Services Available\n",
3170 N_servers,N_services);
3171 switch(Curr_view_opt)
3172 {
3173 case 1 :
3174 strcat(str,"Displaying ALL Servers");
3175 break;
3176 case 0 :
3177 sprintf(str1,"Displaying Servers on node %s",Curr_view_opt_par);
3178 strcat(str,str1);
3179 break;
3180 case 2 :
3181 sprintf(str1,"Displaying Servers providing Service *%s*",
3182 Curr_view_opt_par);
3183 strcat(str,str1);
3184 break;
3185 case 3 :
3186 strcat(str,"Displaying Servers in ERROR");
3187 break;
3188 case -1 :
3189 strcat(str,"Please Select Viewing Option");
3190 break;
3191 }
3192 set_something(Label_id,XmNlabelString,str);
3193 XFlush(XtDisplay(Label_id));
3194 ENABLE_AST
3195}
3196
3197Widget create_client_dialog()
3198{
3199 Widget id;
3200 id = create_selection_dialog("Dismiss","","","","",DID_CLIENTS, 3);
3201 return(id);
3202
3203}
3204
3205Widget create_server_dialog()
3206{
3207 Widget id;
3208 id = create_selection_dialog("","View / Send","Dismiss","",
3209 "Service / Command :",
3210 DID_SERVICES, 20);
3211 return(id);
3212}
3213
3214Widget create_node_selection()
3215{
3216 Widget id;
3217 id = create_selection_dialog("","","","Nodes :","Selected Node :",DID_SEL_NODE, 8);
3218 return(id);
3219
3220}
3221
3222Widget create_service_selection()
3223{
3224 Widget id;
3225 /*
3226 id = create_prompt_dialog("Enter Service Name :",DID_SEL_SERVICE);
3227 */
3228 id = create_selection_dialog("","","","","Enter Service Name (or search string):",DID_SEL_SERVICE, 0);
3229 return(id);
3230
3231}
3232
3233Widget create_send_command()
3234{
3235 Widget id;
3236 char str[256], str1[256];
3237
3238 sprintf(str,"Command to %s (%s)\n\n",
3239 Curr_service_name, Curr_service_format);
3240
3241 id = create_selection_dialog("","","",str,"Command:",DID_COMMAND, 1);
3242
3243 strcpy(str1,"Please enter items separated by spaces:\n(for example: 2 0x123 'A' 23.4 \"a text\")");
3244
3245 set_something(id,XmNselectionLabelString,str1);
3246
3247 return(id);
3248
3249}
3250
3251Widget create_kill_confirmation()
3252{
3253 Widget id;
3254 id = create_question_dialog("Do you really want to kill ALL DIM servers ?",
3255 DID_KILL_ALL);
3256 return(id);
3257
3258}
3259
3260Widget create_selection_dialog(char *ok, char *apply, char *cancel, char *list, char *sel,
3261 long tag, int items)
3262{
3263Widget sd;
3264XmString xmOk, xmApply, xmCancel, xmList, xmSelection;
3265Arg ar[20];
3266int n;
3267
3268 xmList = create_str(list);
3269 xmOk = create_str(ok);
3270 xmApply = create_str(apply);
3271 xmCancel = create_str (cancel);
3272 xmSelection = create_str (sel);
3273
3274 n = 0;
3275 /*
3276 XtSetArg(ar[n],XmNdialogStyle,XmDIALOG_FULL_APPLICATION_MODAL); n++;
3277 XtSetArg(ar[n],XmNmwmFunctions,MWM_FUNC_MOVE); n++;
3278 */
3279 XtSetArg(ar[n],XmNtitle,"Selection"); n++;
3280 XtSetArg(ar[n],XmNlabelFontList, did_default_font); n++;
3281 XtSetArg(ar[n],XmNbuttonFontList, did_default_font); n++;
3282 XtSetArg(ar[n],XmNtextFontList, did_small_font); n++;
3283 XtSetArg(ar[n],XmNborderWidth, 1); n++;
3284 XtSetArg(ar[n],XmNlistLabelString, xmList); n++;
3285 XtSetArg(ar[n],XmNlistVisibleItemCount,items); n++;
3286 if(ok[0])
3287 {
3288 XtSetArg(ar[n],XmNokLabelString, xmOk); n++;
3289 }
3290 if(apply[0])
3291 {
3292 XtSetArg(ar[n],XmNapplyLabelString, xmApply); n++;
3293 }
3294 if(cancel[0])
3295 {
3296 XtSetArg(ar[n],XmNcancelLabelString, xmCancel); n++;
3297 }
3298 if(sel[0])
3299 {
3300 XtSetArg(ar[n],XmNselectionLabelString, xmSelection); n++;
3301 }
3302 sd = XmCreateSelectionDialog ( toplevel_widget, "Selection", ar, n );
3303 XmStringFree(xmList);
3304 XmStringFree(xmOk);
3305 XmStringFree(xmApply);
3306 XmStringFree(xmCancel);
3307 XmStringFree(xmSelection);
3308 if(tag >= 0)
3309 {
3310 XtAddCallback ( sd, XmNcancelCallback,
3311 (XtCallbackProc)cancel_pop_up, (XtPointer)tag );
3312 XtAddCallback ( sd, XmNapplyCallback,
3313 (XtCallbackProc)ok_pop_up, (XtPointer)tag );
3314 XtAddCallback ( sd, XmNokCallback,
3315 (XtCallbackProc)ok_pop_up, (XtPointer)tag );
3316 }
3317 return(sd);
3318}
3319
3320Widget create_file_selection_dialog(long type)
3321{
3322Widget sd;
3323XmString xm1;
3324Arg ar[20];
3325int n;
3326
3327 xm1 = create_str ("");
3328 n = 0;
3329 /*
3330 XtSetArg(ar[n],XmNdialogStyle,XmDIALOG_FULL_APPLICATION_MODAL); n++;
3331 XtSetArg(ar[n],XmNmwmFunctions,MWM_FUNC_MOVE); n++;
3332 */
3333 XtSetArg(ar[n],XmNtitle,"FileSelection"); n++;
3334 XtSetArg(ar[n],XmNlabelFontList, did_default_font); n++;
3335 XtSetArg(ar[n],XmNbuttonFontList, did_default_font); n++;
3336 XtSetArg(ar[n],XmNtextFontList, did_default_font); n++;
3337 XtSetArg(ar[n],XmNborderWidth, 1); n++;
3338 XtSetArg(ar[n],XmNwidth, 500); n++;
3339 XtSetArg(ar[n],XmNdirMask, xm1); n++;
3340 sd = XmCreateFileSelectionDialog ( toplevel_widget, "FileSelection", ar, n );
3341
3342 XmStringFree(xm1);
3343
3344 XtAddCallback ( sd, XmNcancelCallback,
3345 (XtCallbackProc)cancel_pop_up, (XtPointer)type );
3346 XtAddCallback ( sd, XmNokCallback,
3347 (XtCallbackProc)ok_pop_up, (XtPointer)type );
3348
3349 return(sd);
3350}
3351
3352Widget create_prompt_dialog(char *label, long tag)
3353{
3354Widget sd;
3355XmString xm1;
3356Arg ar[20];
3357int n;
3358
3359 xm1 = create_str (label);
3360 n = 0;
3361 XtSetArg(ar[n],XmNlabelFontList, did_default_font); n++;
3362 XtSetArg(ar[n],XmNbuttonFontList, did_default_font); n++;
3363 XtSetArg(ar[n],XmNborderWidth, 1); n++;
3364 /*
3365 XtSetArg(ar[n],XmNwidth, 450); n++;
3366 XtSetArg(ar[n],XmNresizePolicy, XmRESIZE_NONE); n++;
3367 */
3368 XtSetArg(ar[n],XmNselectionLabelString, xm1); n++;
3369 sd = XmCreatePromptDialog ( toplevel_widget, "Prompt", ar, n );
3370
3371 XmStringFree(xm1);
3372
3373 XtAddCallback ( sd, XmNcancelCallback,
3374 (XtCallbackProc)cancel_pop_up, (XtPointer)tag );
3375 XtAddCallback ( sd, XmNokCallback,
3376 (XtCallbackProc)ok_pop_up, (XtPointer)tag );
3377
3378 return(sd);
3379}
3380
3381Widget create_question_dialog(char *label, long tag)
3382{
3383Widget sd;
3384XmString xm1;
3385Arg ar[20];
3386int n;
3387
3388 xm1 = create_str (label);
3389 n = 0;
3390 XtSetArg(ar[n],XmNlabelFontList, did_default_font); n++;
3391 XtSetArg(ar[n],XmNbuttonFontList, did_default_font); n++;
3392 XtSetArg(ar[n],XmNborderWidth, 1); n++;
3393 /*
3394 XtSetArg(ar[n],XmNwidth, 450); n++;
3395 XtSetArg(ar[n],XmNresizePolicy, XmRESIZE_NONE); n++;
3396 */
3397 XtSetArg(ar[n],XmNmessageString, xm1); n++;
3398 sd = XmCreateQuestionDialog ( toplevel_widget, "Question", ar, n );
3399
3400 XmStringFree(xm1);
3401
3402 XtAddCallback ( sd, XmNcancelCallback,
3403 (XtCallbackProc)cancel_pop_up, (XtPointer)tag );
3404 XtAddCallback ( sd, XmNokCallback,
3405 (XtCallbackProc)ok_pop_up, (XtPointer)tag );
3406
3407 return(sd);
3408}
3409
3410Widget create_service_dialog()
3411{
3412Widget fd, rc, sw, lb, rc1;
3413XmString xm1;
3414Arg ar[20];
3415int n, par;
3416unsigned long reason;
3417
3418 n = 0;
3419 XtSetArg(ar[n],XmNborderWidth, 1); n++;
3420 XtSetArg(ar[n],XmNresizePolicy, XmRESIZE_ANY); n++;
3421 fd = XmCreateFormDialog ( toplevel_widget, "Form", ar, n );
3422 XtManageChild(fd);
3423
3424 /* create rowcolumn */
3425 n = 0;
3426 XtSetArg(ar[n],XmNborderWidth, 1); n++;
3427 XtSetArg(ar[n],XmNentryAlignment, XmALIGNMENT_CENTER); n++;
3428 XtSetArg(ar[n],XmNbottomAttachment, XmATTACH_FORM); n++;
3429 XtSetArg(ar[n],XmNbottomOffset, 0); n++;
3430 XtSetArg(ar[n],XmNrightAttachment, XmATTACH_FORM); n++;
3431 XtSetArg(ar[n],XmNrightOffset, 0); n++;
3432 XtSetArg(ar[n],XmNtopAttachment, XmATTACH_FORM); n++;
3433 XtSetArg(ar[n],XmNtopOffset, 0); n++;
3434 XtSetArg(ar[n],XmNleftAttachment, XmATTACH_FORM); n++;
3435 XtSetArg(ar[n],XmNleftOffset, 0); n++;
3436 rc = XmCreateRowColumn ( fd, "rowcol", ar, n );
3437 XtManageChild(rc);
3438
3439 /* create scrolled window */
3440 n = 0;
3441 XtSetArg ( ar[n], XmNwidth, 770); n++;
3442 XtSetArg ( ar[n], XmNheight, 350); n++;
3443 XtSetArg ( ar[n], XmNscrollBarDisplayPolicy, XmAS_NEEDED); n++;
3444 XtSetArg ( ar[n], XmNscrollingPolicy, XmAUTOMATIC); n++;
3445
3446 sw = XmCreateScrolledWindow ( rc, "ScrollWin", ar, n );
3447 XtManageChild ( sw );
3448
3449 /* create label */
3450 n = 0;
3451 xm1 = create_str(" ");
3452 XtSetArg(ar[n],XmNfontList, did_small_font); n++;
3453 XtSetArg(ar[n],XmNlabelString, xm1); n++;
3454 XtSetArg(ar[n],XmNalignment, XmALIGNMENT_BEGINNING); n++;
3455 lb = XmCreateLabel ( sw, "label", ar, n );
3456 XtManageChild(lb);
3457 XmStringFree(xm1);
3458 par = 1;
3459 reason = 0;
3460 create_label(lb, &par, &reason);
3461
3462 /* create button rowcolumn */
3463 n = 0;
3464 XtSetArg(ar[n],XmNborderWidth, 0); n++;
3465 XtSetArg(ar[n],XmNentryAlignment, XmALIGNMENT_CENTER); n++;
3466 XtSetArg(ar[n],XmNorientation, XmVERTICAL); n++;
3467 XtSetArg(ar[n],XmNnumColumns, 3); n++;
3468 XtSetArg(ar[n],XmNpacking, XmPACK_COLUMN); n++;
3469 rc1 = XmCreateRowColumn ( rc, "buttons", ar, n );
3470 XtManageChild(rc1);
3471 /*
3472 create_push_button(rc1,"View Standard",MAX_POP_UPS+1);
3473 create_push_button(rc1,"View Float",MAX_POP_UPS+2);
3474 create_push_button(rc1,"View Double",MAX_POP_UPS+3);
3475 */
3476 SubscribeButton = create_push_button(rc1," Subscribe (On Change) ",
3477 MAX_POP_UPS+5);
3478 Subscribe10Button = create_push_button(rc1," Subscribe (Update Rate 10 seconds) ",
3479 MAX_POP_UPS+4);
3480 create_push_button(rc1,"Dismiss",DID_SERVICE);
3481 Curr_service_print_type = 0;
3482
3483 return(fd);
3484}
3485
3486Widget create_push_button(Widget parent, char *str, long tag)
3487{
3488Widget b;
3489XmString xm1;
3490Arg ar[20];
3491int n;
3492
3493 n = 0;
3494 xm1 = create_str(str);
3495 XtSetArg(ar[n],XmNalignment, XmALIGNMENT_CENTER); n++;
3496 XtSetArg(ar[n],XmNfontList, did_default_font); n++;
3497 XtSetArg(ar[n],XmNlabelString, xm1); n++;
3498 b = XmCreatePushButton ( parent, "button", ar, n );
3499
3500 XtManageChild(b);
3501 XmStringFree(xm1);
3502
3503 XtAddCallback ( b, XmNactivateCallback,
3504 (XtCallbackProc)cancel_pop_up, (XtPointer)tag );
3505 return(b);
3506}
3507
3508
3509
3510
Note: See TracBrowser for help on using the repository browser.