File: xmpi_dtype.c

package info (click to toggle)
xmpi 2.2-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,232 kB
  • ctags: 1,656
  • sloc: ansic: 13,738; sh: 1,799; makefile: 233
file content (547 lines) | stat: -rw-r--r-- 12,007 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
/*
 * Copyright 1998-1999, University of Notre Dame.
 * Authors: Brian W. Barrett, Arun F. Rodrigues, Jeffrey M. Squyres,
 * 	 and Andrew Lumsdaine
 *
 * This file is part of XMPI
 *
 * You should have received a copy of the License Agreement for XMPI 
 * along with the software; see the file LICENSE.  If not, contact 
 * Office of Research, University of Notre Dame, Notre Dame, IN 46556.
 *
 * Permission to modify the code and to distribute modified code is
 * granted, provided the text of this NOTICE is retained, a notice that
 * the code was modified is included with the above COPYRIGHT NOTICE and
 * with the COPYRIGHT NOTICE in the LICENSE file, and that the LICENSE
 * file is distributed with the modified code.
 *
 * LICENSOR MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.
 * By way of example, but not limitation, Licensor MAKES NO
 * REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY
 * PARTICULAR PURPOSE OR THAT THE USE OF THE LICENSED SOFTWARE COMPONENTS
 * OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, TRADEMARKS
 * OR OTHER RIGHTS.
 *
 * Additional copyrights may follow.

 *
 *      $Id: xmpi_dtype.c,v 1.5 1999/11/10 21:32:33 arodrig6 Exp $
 * 
 *	Function:	- Datatype subwindow
 */

#define _NO_PROTO
#define XMPI_NORANK	(-1)			/* indicates no process */

#include <Xm/Text.h>
#include <Xm/Form.h>
#include <Xm/DialogS.h>

#include <stdio.h>
#include <stdlib.h>

#include "mpitrace.h"
#include "xmpi.h"
#include "xmpi_dbase.h"

#include "Bitmaps/blank.xbm"
#include "Bitmaps/light.xbm"
#include "Bitmaps/tack.xbm"
#include "Bitmaps/mesg.xbm"

/*
 * public functions
 */
void			xmpi_dt_create();
void			xmpi_dt_update();
void			xmpi_dt_clear();
void			xmpi_dt_msg();
void			xmpi_dt_proc();
void			xmpi_dt_setrank();
void			xmpi_dt_popdown();
void			xmpi_dt_busy();
void			xmpi_dt_unbusy();

/*
 * external functions
 */
extern void		*xmpi_sys_dtype();
extern void		xmpi_dtypeprint();

/*
 * private functions
 */
static void		createpixlabels();
static void		tack_cb();
static void		print_type();

/*
 * external variables
 */
extern int		fl_dbase;		/* driven by dbase flag */
extern struct _gps	*xmpi_app_procs;	/* application GPS array */

/*
 * local variables
 */
static int		dt_proc = -1;		/* process rank */
static int		dt_dtype = -1;		/* datatype label */
static char		fmtbuf[2048];		/* large buffer */
static Pixmap		blankpix = XmUNSPECIFIED_PIXMAP;
static Pixmap		trafficpix = XmUNSPECIFIED_PIXMAP;
static Pixmap		mesgpix = XmUNSPECIFIED_PIXMAP;
static Pixmap		tackpix = XmUNSPECIFIED_PIXMAP;
static Pixmap		armtackpix = XmUNSPECIFIED_PIXMAP;
static Widget		dtw = 0;
static Widget		dtw_form;
static Widget		dtw_dtype;
static Widget		dtw_hdr;
static Widget		dtw_pix;
static int		dtw_rank = XMPI_NORANK;
static int		dtw_show = XMPI_SHOWNONE;

/*
 *	xmpi_dt_msg
 *
 *	Function:	- set the message datatype
 *	Accepts:	- process global rank
 *			- focus entry
 *			- ignore cache flag (1 => ignore cache)
 */
void
xmpi_dt_msg(rank, pfocus, nocache)

int			rank;
struct xmfocus		*pfocus;
int			nocache;

{
	struct xmmsg	*pmsg;			/* message entry */

	if (dtw_show != XMPI_SHOWMESG || dtw_rank != rank) return;
/*
 * If no messages, blank the datatype.
 */
	pmsg = pfocus->xmf_proc->xmp_curmsg;

	if (pmsg == 0 || pmsg->xmm_dtype == 0) {
		dt_dtype = -1;
		XmTextSetString(dtw_dtype, " ");
	}
/*
 * If the datatype is not in the cache, fetch it and display it.
 */
	else if (nocache || pmsg->xmm_dtype != dt_dtype
			|| pmsg->xmm_gsrc != dt_proc) {

		dt_dtype = pmsg->xmm_dtype;
		dt_proc = pmsg->xmm_gsrc;

		print_type(dt_proc, dt_dtype, fmtbuf);
		XmTextSetString(dtw_dtype, fmtbuf);
	}
}

/*
 *	xmpi_dt_proc
 *
 *	Function:	- set the process datatype
 *	Accepts:	- process global rank
 *			- focus entry
 *			- ignore cache flag (1 => ignore cache)
 */
void
xmpi_dt_proc(rank, pfocus, nocache)

int			rank;
struct xmfocus		*pfocus;
int			nocache;

{
	struct xmproc	*pproc;			/* process entry */

	if (dtw_show != XMPI_SHOWPROC || dtw_rank != rank) return;
/*
 * If process running or done, blank the datatype.
 */
	pproc = pfocus->xmf_proc;

	if (pproc->xmp_state == XMPI_SRUN
		|| pproc->xmp_state == XMPI_SUNDEF || pproc->xmp_dtype == 0) {

		dt_dtype = -1;
		XmTextSetString(dtw_dtype, " ");
	}
/*
 * If datatype not in cache, fetch it and display it.
 */ 
	else if (nocache || pproc->xmp_dtype != dt_dtype || rank != dt_proc) {

		dt_dtype = pproc->xmp_dtype;
		dt_proc = rank;

		print_type(dt_proc, dt_dtype, fmtbuf);
		XmTextSetString(dtw_dtype, fmtbuf);
	}
}

/*
 *	xmpi_dt_create
 *
 *	Function:	- create and initialize Datatype subwindow
 *	Accepts:	- parent window
 */
void
xmpi_dt_create(parent_w)

Widget			parent_w;

{
	Widget		lbl_w;
	Widget		w;

	if (dtw != 0) return;
/*
 * Create the Datatype window.
 */
	dtw = XtVaCreatePopupShell("dt_win",
		xmDialogShellWidgetClass, parent_w,
		XmNdefaultPosition, False,
		XmNmappedWhenManaged, False,
		XmNdeleteResponse, XmUNMAP,
		XmNtitle, "XMPI Datatype",
		NULL);
/*
 * Create the high-level form.
 */
	dtw_form = XtVaCreateWidget("dt_mgr",
		xmFormWidgetClass, dtw,
		XmNmarginHeight, 2,
		XmNmarginWidth, 2,
		XmNverticalSpacing, 2,
		NULL);
/*
 * Create the label area window.
 */
	lbl_w = XtVaCreateWidget("dt_label",
		xmFormWidgetClass, dtw_form,
		XmNtopAttachment, XmATTACH_FORM,
		XmNleftAttachment, XmATTACH_FORM,
		XmNrightAttachment, XmATTACH_FORM,
		NULL);
/*
 * tack button (cache and re-use pixmaps)
 */
	if (tackpix == XmUNSPECIFIED_PIXMAP) {
		w = xmpi_mkpixbutton(lbl_w, tack_cb, NULL,
			(void (*)()) 0, NULL, (void (*)()) 0, NULL,
			tack_bits, tack_width, tack_height, False);

		XtVaGetValues(w, XmNlabelPixmap, &tackpix,
			XmNarmPixmap, &armtackpix, NULL);
	} else {
		w = xmpi_mkpixbutton(lbl_w, tack_cb, NULL,
			(void (*)()) 0, NULL, (void (*)()) 0, NULL,
			NULL, 0, 0, False);

		XtVaSetValues(w, XmNlabelType, XmPIXMAP,
			XmNlabelPixmap, tackpix,
			XmNarmPixmap, armtackpix, NULL);
	}

	XtVaSetValues(w, XmNtopAttachment, XmATTACH_FORM,
		XmNleftAttachment, XmATTACH_FORM,
		XmNbottomAttachment, XmATTACH_FORM, NULL);

	xmpi_add_pophelp(w, "Dismiss datatype window");
/*
 * header label
 */
	dtw_hdr = xmpi_mklabel(lbl_w, "banner", XmALIGNMENT_CENTER, False);

	XtVaSetValues(dtw_hdr,
		XmNtopAttachment, XmATTACH_FORM,
		XmNbottomAttachment, XmATTACH_FORM,
		XmNrightAttachment, XmATTACH_FORM,
		XmNleftAttachment, XmATTACH_WIDGET,
		XmNleftWidget, w,
		XmNleftOffset, 3,
		NULL);

	sprintf(fmtbuf, "%s", "DT Test");
	xmpi_setlabel(dtw_hdr, fmtbuf);

	XtManageChild(lbl_w);
/*
 * Create the pixmaps and datatype pixmap window.
 */
	createpixlabels(dtw_form);
	dtw_pix = xmpi_mklabel(dtw_form, "traffic_lbl",
		XmALIGNMENT_CENTER, False);
	XtVaSetValues(dtw_pix,
		XmNlabelType, XmPIXMAP,
		XmNlabelPixmap, blankpix,
		XmNtopAttachment, XmATTACH_WIDGET,
		XmNtopWidget, lbl_w,
		XmNbottomAttachment, XmATTACH_FORM,
		XmNbottomOffset, 2,
		XmNleftAttachment, XmATTACH_FORM,
		XmNleftOffset, 2,
		NULL);
/*
 * Create the datatype scrolled window.
 */
	dtw_dtype = XtVaCreateManagedWidget("dt_dtype",
		xmTextWidgetClass, dtw_form,
		XmNeditable, False,
		XmNeditMode, XmMULTI_LINE_EDIT,
		XmNautoShowCursorPosition, False,
		XmNcursorPositionVisible, False,
		XmNcolumns, 32,
		XmNrows, 8,
		XmNtopAttachment, XmATTACH_WIDGET,
		XmNtopWidget, lbl_w,
		XmNbottomAttachment, XmATTACH_FORM,
		XmNbottomOffset, 2,
		XmNrightAttachment, XmATTACH_FORM,
		XmNleftAttachment, XmATTACH_WIDGET,
		XmNleftWidget, dtw_pix,
		XmNleftOffset, 2,
		NULL);

	XtManageChild(dtw_form);

#ifdef AIX
/*
 * AIX Motif 1.2 does not seem to honor the alignment resource
 * of child labels unless we force a resize!?
 */
        {
                Dimension       w;
                XtVaGetValues(dtw, XmNwidth, &w, NULL);
                XtVaSetValues(dtw, XmNwidth, w+2, NULL);
        }
#endif
}

/*
 *	xmpi_dt_update
 *
 *	Function:	- updates the datatype display window
 *	Accepts:	- rank
 *			- focus entry
 *			- show process or message type
 */
void
xmpi_dt_update(rank, pfocus, show)

int			rank;
struct xmfocus		*pfocus;
int			show;

{
	int		nocache;	/* set on if cache is no good */
	struct xmproc	*pproc;		/* process entry */

/*
 * Update the rank in the header.  Keep the format consistent with
 * xmpi_fo_update().
 */
	if (rank != dtw_rank) {
		pproc = pfocus->xmf_proc;
		if ((pproc->xmp_state == XMPI_SRUN) ||
				(pproc->xmp_state == XMPI_SUNDEF)) {
			sprintf(fmtbuf, "%d   %s", rank, pproc->xmp_prog);
		} else {
			sprintf(fmtbuf, "%d / %d   %s", rank,
				pproc->xmp_lrank, pproc->xmp_prog);
		}
		xmpi_setlabel(dtw_hdr, fmtbuf);
	}
/*
 * Update the pixmap.
 */
	if (show != dtw_show) {
		if (show == XMPI_SHOWMESG) {
			XtVaSetValues(dtw_pix, XmNlabelPixmap, mesgpix, NULL);
		} else if (show == XMPI_SHOWPROC) {
			XtVaSetValues(dtw_pix,
				XmNlabelPixmap, trafficpix, NULL);
		} else {
			XtVaSetValues(dtw_pix, XmNlabelPixmap, blankpix, NULL);
		}
	}
/*
 * Update state. Must be done before text update.
 */
	nocache = (dtw_rank != rank || dtw_show != show);
	dtw_show = show;
	dtw_rank = rank;
/*
 * Update the data type text.
 */
	if (show == XMPI_SHOWMESG) {
		xmpi_dt_msg(rank, pfocus, nocache);
	}
	else if (show == XMPI_SHOWPROC) {
		xmpi_dt_proc(rank, pfocus, nocache);
	}

	XtPopup(dtw, XtGrabNone);
	XtManageChild(dtw_form);
}		

/*
 *	xmpi_dt_clear
 *
 *	Function:	- clear and pop down Datatype window
 */
void
xmpi_dt_clear()

{
	if (dtw == 0) return;

	dtw_rank = -1;
	dtw_show = -1;
	xmpi_setlabel(dtw_hdr, "");
	XmTextSetString(dtw_dtype, "");
	XtVaSetValues(dtw_pix, XmNlabelPixmap, blankpix, NULL);
	XtPopdown(dtw);
}

/*
 *	xmpi_dt_setrank
 *
 *	Function:	- set rank in Datatype window header
 *	Accepts:	- rank
 *			- text form of rank
 */
void
xmpi_dt_setrank(rank, text)

int			rank;
char			*text;

{
	if (dtw_rank == rank) xmpi_setlabel(dtw_hdr, text);
}

/*
 *	xmpi_dt_popdown
 *
 *	Function:	- unmap the Datatype window
 */
void
xmpi_dt_popdown()

{
	if (dtw) XtPopdown(dtw);
}

/*
 *	tack_cb
 *
 *	Function:	- callback to unmap the Datatype window
 */
static void
tack_cb()

{
	XtPopdown(dtw);
}

/*
 *	createpixlabels
 *
 *	Function:	- create pixmaps for labels
 *			- blank, traffic light & message
 *	Accepts:	- parent widget
 */
static void
createpixlabels(w)

Widget			w;

{
	unsigned int	depth;			/* screen depth */
	Display		*disp;			/* display */
	Drawable	root;			/* root window */
	Pixel		fg, bg;			/* fore/background colours */

	if (blankpix != XmUNSPECIFIED_PIXMAP) return;

	disp = XtDisplay(w);
	root = RootWindowOfScreen(XtScreen(w)),
	depth = DefaultDepthOfScreen(XtScreen(w));
	XtVaGetValues(w, XmNforeground, &fg, XmNbackground, &bg, NULL);
/*
 * Create the static pixmaps.
 */
	trafficpix = XCreatePixmapFromBitmapData(disp, root,
		(char*)light_bits, light_width, light_height, fg, bg, depth);

	mesgpix = XCreatePixmapFromBitmapData(disp, root,
		(char*)mesg_bits, mesg_width, mesg_height, fg, bg, depth);

	blankpix = XCreatePixmapFromBitmapData(disp, root,
		(char*)blank_bits, blank_width, blank_height, fg, bg, depth);
}

/*
 *	xmpi_dt_busy
 *
 *	Function:	- set the busy cursor for the Datatype window
 */
void
xmpi_dt_busy()

{
	if (dtw) xmpi_busy_widget(dtw);
}

/*
 *	xmpi_dt_unbusy
 *
 *	Function:	- set the normal cursor for the Datatype window
 */
void
xmpi_dt_unbusy()

{
	if (dtw) xmpi_unbusy_widget(dtw);
}

/*
 *	print_type
 *
 *	Function:	- textual representation of a datatype
 *	Accepts:	- process which defined the datatype
 *			- datatype label
 *			- textual representation (out)
 */
static void
print_type(proc, dtype, buf)

int			proc;
int			dtype;
char			*buf;

{
	void		*trace;

	if (dtype < 0) {
		sprintf(buf, "invalid datatype: %d", dtype);
	}
	else {
		trace = (fl_dbase) ? xmpi_db_getdtype(proc, dtype)
				: xmpi_sys_dtype(xmpi_app_procs + proc, dtype);

		if (trace == (void *) -1) {
			sprintf(buf, "unknown datatype: %d", dtype);
		} else {
			xmpi_dtypeprint(dtype, trace, XMPI_DTINDENT, "", buf);
			if (!fl_dbase && trace) free((char *) trace);
		}
	}
}