1
/*___INFO__MARK_BEGIN__*/
2
/*************************************************************************
4
* The Contents of this file are made available subject to the terms of
5
* the Sun Industry Standards Source License Version 1.2
7
* Sun Microsystems Inc., March, 2001
10
* Sun Industry Standards Source License Version 1.2
11
* =================================================
12
* The contents of this file are subject to the Sun Industry Standards
13
* Source License Version 1.2 (the "License"); You may not use this file
14
* except in compliance with the License. You may obtain a copy of the
15
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
17
* Software provided under this License is provided on an "AS IS" basis,
18
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
19
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
20
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
21
* See the License for the specific provisions governing your rights and
22
* obligations concerning the Software.
24
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
26
* Copyright: 2001 by Sun Microsystems, Inc.
28
* All Rights Reserved.
30
************************************************************************/
31
/*___INFO__MARK_END__*/
37
#include <Xm/DrawingA.h>
40
#include <Xmt/Dialogs.h>
41
#include <Xmt/Create.h>
42
#include <Xmt/Chooser.h>
43
#include <Xmt/InputField.h>
44
#include <Xmt/Pixmap.h>
45
#include <Xmt/WidgetType.h>
46
#include <Xmt/Layout.h>
47
#include <Xmt/LayoutG.h>
49
#include "qmon_rmon.h"
51
#include "gdi/sge_gdi.h"
53
#include "sge_all_listsL.h"
54
#include "qmon_cull.h"
55
#include "qmon_request.h"
56
#include "qmon_submit.h"
57
#include "qmon_globals.h"
58
#include "qmon_comm.h"
59
#include "qmon_init.h"
60
#include "qmon_util.h"
61
#include "qmon_message.h"
62
#include "AskForTime.h"
64
#include "uti/sge_string.h"
68
/*-------------------------------------------------------------------------*/
69
static void qmonRequestRemoveResource(Widget w, XtPointer cld, XtPointer cad);
70
static void qmonToggleHardSoft2(Widget w, XtPointer cld, XtPointer cad);
71
static void qmonRequestClear(Widget w, XtPointer cld, XtPointer cad);
72
static void qmonRequestOkay(Widget w, XtPointer cld, XtPointer cad);
73
static void qmonRequestCancel(Widget w, XtPointer cld, XtPointer cad);
74
static void qmonRequestEditResource(Widget w, XtPointer cld, XtPointer cad);
75
static int qmonCullToIconList(lList *cel, int how, IconListElement **ice, int *iceCount);
76
static Pixmap qmonFetchTypeIcon(int type);
79
/*-------------------------------------------------------------------------*/
80
static lList *hard_requests = 0;
81
static lList *soft_requests = 0;
83
static lListElem *fill_in_request;
85
static int hard_soft = 0;
86
static Widget request_dialog = 0;
87
static Widget request_rtype = 0;
88
static Widget request_rr = 0;
89
static Widget request_hr = 0;
90
static Widget request_sr = 0;
95
/*-------------------------------------------------------------------------*/
96
void qmonRequestPopup(Widget w, XtPointer cld, XtPointer cad)
98
Widget request_hardsoft, parent, request_clear, request_okay,
103
lListElem *ep = NULL;
104
lListElem *rp = NULL;
107
DENTER(GUI_LAYER, "qmonRequestPopup");
109
parent = XmtGetShell(w);
110
DPRINTF(("parent = %s\n", XtName(parent) ));
112
if (!request_dialog) {
113
request_dialog = XmtBuildQueryDialog(parent, "request_shell",
115
"request_rtype", &request_rtype,
116
"request_rr", &request_rr,
117
"request_hr", &request_hr,
118
"request_sr", &request_sr,
119
"request_hardsoft", &request_hardsoft,
120
"request_clear", &request_clear,
121
"request_okay", &request_okay,
122
"request_cancel", &request_cancel,
124
XtAddCallback(request_rr, XmNactivateCallback,
125
qmonRequestEditResource, (XtPointer)0);
126
XtAddCallback(request_hr, XmNactivateCallback,
127
qmonRequestEditResource, (XtPointer)1);
128
XtAddCallback(request_hr, XmNremoveCallback,
129
qmonRequestRemoveResource, NULL);
130
XtAddCallback(request_sr, XmNactivateCallback,
131
qmonRequestEditResource, (XtPointer)1);
132
XtAddCallback(request_sr, XmNremoveCallback,
133
qmonRequestRemoveResource, NULL);
135
XtAddCallback(request_hardsoft, XmtNvalueChangedCallback,
136
qmonToggleHardSoft2, NULL);
137
XtAddCallback(request_clear, XmNactivateCallback,
138
qmonRequestClear, NULL);
139
XtAddCallback(request_okay, XmNactivateCallback,
140
qmonRequestOkay, NULL);
141
XtAddCallback(request_cancel, XmNactivateCallback,
142
qmonRequestCancel, NULL);
144
XtAddEventHandler(XtParent(request_dialog), StructureNotifyMask, False,
145
SetMinShellSize, NULL);
150
** set the type labelString
152
XtVaSetValues(request_rtype, XmtNlabel, qmonSubmitRequestType(), NULL);
154
qmonMirrorMultiAnswer(CENTRY_T, &alp);
156
qmonMessageBox(w, alp, 0);
158
/* set normal cursor */
159
XmtDisplayDefaultCursor(w);
163
rll = qmonGetResources(qmonMirrorList(SGE_CENTRY_LIST),
164
REQUESTABLE_RESOURCES);
166
hrl = qmonSubmitHR();
167
lFreeList(&hard_requests);
169
hard_requests = lCopyList("hr", hrl);
170
for_each(ep, hard_requests) {
171
rp = lGetElemStr(rll, CE_name, lGetString(ep, CE_name));
173
rp = lGetElemStr(rll, CE_shortcut, lGetString(ep, CE_name));
175
lSetString(ep, CE_name, lGetString(rp, CE_name));
176
lSetString(ep, CE_default, NULL);
177
lSetUlong(ep, CE_valtype, lGetUlong(rp, CE_valtype));
182
srl = qmonSubmitSR();
183
lFreeList(&soft_requests);
185
soft_requests = lCopyList("sr", srl);
186
for_each(ep, soft_requests) {
187
rp = lGetElemStr(rll, CE_name, lGetString(ep, CE_name));
189
rp = lGetElemStr(rll, CE_shortcut, lGetString(ep, CE_name));
191
lSetString(ep, CE_name, lGetString(rp, CE_name));
192
lSetUlong(ep, CE_valtype, lGetUlong(rp, CE_valtype));
200
qmonRequestDraw(request_rr, rll, 0);
201
qmonRequestDraw(request_hr, hard_requests, 1);
202
qmonRequestDraw(request_sr, soft_requests, 1);
204
XtRealizeWidget(request_dialog);
206
xmui_manage(request_dialog);
211
/*-------------------------------------------------------------------------*/
212
void qmonRequestDraw(
217
IconListElement *items = NULL;
220
DENTER(GUI_LAYER, "qmonRequestDraw");
222
XmIconListGetItems(w, &items, &itemCount);
223
qmonCullToIconList(lp, how, &items, &itemCount);
224
XmIconListSetItems(w, items, itemCount);
230
/*-------------------------------------------------------------------------*/
231
static void qmonRequestRemoveResource(Widget w, XtPointer cld, XtPointer cad)
234
XmIconListCallbackStruct *cbs = (XmIconListCallbackStruct*) cad;
236
DENTER(GUI_LAYER, "qmonRequestRemoveResource");
240
lDelElemStr(&soft_requests, CE_name, cbs->element->string[0]);
241
qmonRequestDraw(request_sr, soft_requests, 1);
246
lDelElemStr(&hard_requests, CE_name, cbs->element->string[0]);
247
qmonRequestDraw(request_hr, hard_requests, 1);
255
/*-------------------------------------------------------------------------*/
256
static void qmonRequestClear(Widget w, XtPointer cld, XtPointer cad)
260
DENTER(GUI_LAYER, "qmonRequestClear");
264
lFreeList(&soft_requests);
265
qmonRequestDraw(request_sr, soft_requests, 1);
270
lFreeList(&hard_requests);
271
qmonRequestDraw(request_hr, hard_requests, 1);
279
/*-------------------------------------------------------------------------*/
280
static void qmonToggleHardSoft2(Widget w, XtPointer cld, XtPointer cad)
282
XmtChooserCallbackStruct *cbs = (XmtChooserCallbackStruct*) cad;
284
DENTER(GUI_LAYER, "qmonToggleHardSoft");
286
hard_soft = cbs->state;
288
XtSetSensitive(request_sr, True);
289
XtSetSensitive(request_hr, False);
292
XtSetSensitive(request_sr, False);
293
XtSetSensitive(request_hr, True);
299
/*-------------------------------------------------------------------------*/
300
static void qmonRequestOkay(Widget w, XtPointer cld, XtPointer cad)
303
DENTER(GUI_LAYER, "qmonRequestOkay");
305
xmui_unmanage(request_dialog);
308
** give the resources to the submit dialog
310
qmonSubmitSetResources(&hard_requests, &soft_requests);
316
/*-------------------------------------------------------------------------*/
317
static void qmonRequestCancel(Widget w, XtPointer cld, XtPointer cad)
320
DENTER(GUI_LAYER, "qmonRequestCancel");
322
xmui_unmanage(request_dialog);
329
/*-------------------------------------------------------------------------*/
330
lList *qmonGetResources(
335
lList *entries = NULL;
336
lCondition *where = NULL;
338
DENTER(GUI_LAYER, "qmonGetResources");
344
lp = lCopyList("CE_entries", entries);
347
lList *copy = lCopyList("CE_entries", entries);
352
lUniqStr(lp, CE_name);
354
if (how == REQUESTABLE_RESOURCES) {
355
where = lWhere("%T(%I == %u)", CE_Type, CE_requestable, REQU_YES);
357
lp = lSelectDestroy(lp, where);
365
/*-------------------------------------------------------------------------*/
366
static int qmonCullToIconList(
369
IconListElement **ice,
374
IconListElement *elements, *current;
378
DENTER(GUI_LAYER, "qmonCullToIconList");
380
count = lGetNumberOfElem(cel);
382
elements = (IconListElement*)XtMalloc(sizeof(IconListElement)*count);
386
str = (String*)XtMalloc(sizeof(String));
387
str[0] = XtNewString(lGetString(cep, CE_name));
388
current->string = str;
389
current->numStrings = 1;
392
str = (String*)XtMalloc(sizeof(String) * 3);
393
str[0] = XtNewString(lGetString(cep, CE_name));
394
str[1] = XtNewString("==");
395
str[2] = XtNewString(lGetString(cep, CE_stringval));
396
current->string = str;
397
current->numStrings = 3;
399
current->iconPixmap.pixmap =
400
qmonFetchTypeIcon((int)lGetUlong(cep, CE_valtype));
401
current->iconPixmap.mask = 0;
402
current->iconPixmap.isBitmap = False;
403
current->iconPixmap.width = 16;
404
current->iconPixmap.height = 16;
415
** free old IconListElement entrys
417
for (i=0; *ice && i<*iceCount; i++) {
418
if ((*ice)[i].string) {
419
for (j=0; j<(*ice)[i].numStrings; j++) {
420
if ((*ice)[i].string[j])
421
XtFree((*ice)[i].string[j]);
423
XtFree((char*)(*ice)[i].string);
428
/* attach new entries */
436
/*-------------------------------------------------------------------------*/
437
static Pixmap qmonFetchTypeIcon(
442
DENTER(GUI_LAYER, "qmonFetchTypeIcon");
447
pix = qmonGetIcon("int");
450
pix = qmonGetIcon("time");
453
pix = qmonGetIcon("str");
456
pix = qmonGetIcon("unknown");
458
pix = qmonGetIcon("bool");
461
pix = qmonGetIcon("mem");
464
pix = qmonGetIcon("host");
467
pix = qmonGetIcon("cstr");
470
pix = qmonGetIcon("unknown");
477
/*-------------------------------------------------------------------------*/
478
static void qmonRequestEditResource(Widget w, XtPointer cld, XtPointer cad)
480
XmIconListCallbackStruct *cbs = (XmIconListCallbackStruct*) cad;
481
long how = (long)cld;
484
char stringval[CL_MAXHOSTLEN];
487
lListElem *ep = NULL;
490
DENTER(GUI_LAYER, "qmonRequestEditResource");
492
rll = qmonGetResources(qmonMirrorList(SGE_CENTRY_LIST),
493
REQUESTABLE_RESOURCES);
496
fill_in_request = lGetElemStr(rll, CE_name, cbs->element->string[0]);
499
fill_in_request = lGetElemStr(hard_requests, CE_name,
500
cbs->element->string[0]);
502
fill_in_request = lGetElemStr(soft_requests, CE_name,
503
cbs->element->string[0]);
507
if (!fill_in_request) {
513
type = lGetUlong(fill_in_request, CE_valtype);
514
strval = lGetString(fill_in_request, CE_stringval);
515
sge_strlcpy(stringval, strval, CL_MAXHOSTLEN);
517
status = qmonRequestInput(w, type, cbs->element->string[0],
518
stringval, sizeof(stringval));
520
** put the value in the CE_Type elem
523
lSetString(fill_in_request, CE_stringval, stringval);
524
lSetString(fill_in_request, CE_default, NULL);
526
/* put it in the hard or soft resource list if necessary */
529
if (!soft_requests) {
530
soft_requests = lCreateList("soft_requests", CE_Type);
532
if (!(ep = lGetElemStr(soft_requests, CE_name,
533
cbs->element->string[0]))) {
534
lAppendElem(soft_requests, lCopyElem(fill_in_request));
536
lSetString(ep, CE_stringval, lGetString(fill_in_request, CE_stringval));
537
lSetString(ep, CE_default, NULL);
542
if (!hard_requests) {
543
hard_requests = lCreateList("hard_requests", CE_Type);
545
if (!(ep = lGetElemStr(hard_requests, CE_name,
546
cbs->element->string[0]))) {
547
lAppendElem(hard_requests, lCopyElem(fill_in_request));
549
lSetString(ep, CE_stringval, lGetString(fill_in_request, CE_stringval));
550
lSetString(ep, CE_default, NULL);
554
qmonRequestDraw(request_sr, soft_requests, 1);
555
qmonRequestDraw(request_hr, hard_requests, 1);
562
/*-------------------------------------------------------------------------*/
563
Boolean qmonRequestInput(
571
char unique[CL_MAXHOSTLEN];
573
Boolean status = False;
576
DENTER(GUI_LAYER, "qmonRequestInput");
579
** call the type specific dialog
580
** stringval contains the string that has to be displayed in
581
** the hard/soft resource list
585
status = XmtAskForInteger(w, NULL,
586
"@{Enter an integer value}", &intval, 0, 0,
588
sprintf(stringval, "%d", intval);
591
status = XmtAskForDouble(w, NULL,
592
"@{Enter a double value}", &dval, 0, 0,
594
sprintf(stringval, "%f", dval);
597
status = XmtAskForString(w, NULL, "@{Enter a string value}",
598
stringval, maxlen, NULL);
599
if (stringval[0] == '\0')
603
status = XmtAskForString(w, NULL, "@{Enter a uppercase string value}", stringval, maxlen, NULL);
604
if (stringval[0] == '\0')
608
status = XmtAskForString(w, NULL, "@{Enter a string value}", stringval, maxlen, NULL);
609
if (stringval[0] == '\0')
613
status = XmtAskForString(w, NULL, "@{Enter a valid hostname}", stringval, maxlen, NULL);
614
if (status && stringval[0] != '\0') {
615
/* try to resolve hostname */
616
ret=sge_resolve_hostname(stringval, unique, EH_name);
618
case CL_RETVAL_GETHOSTNAME_ERROR:
619
qmonMessageShow(w, True, "Can't resolve host '%s'", stringval);
623
strcpy(stringval, unique);
626
DPRINTF(("sge_resolve_hostname() failed resolving: %s\n", cl_get_error_text(ret)));
633
status = XmtAskForTime(w, NULL, "@{Enter a time value}", stringval, maxlen, NULL, True);
634
if (stringval[0] == '\0')
638
status = XmtAskForMemory(w, NULL, "@{Enter a memory value}", stringval, maxlen, NULL);
639
if (stringval[0] == '\0')
643
XmtAskForBoolean(w, NULL, "@{Click TRUE or FALSE}", "TRUE", "FALSE", NULL,
644
XmtYesButton, XmDIALOG_INFORMATION, False,
647
strcpy(stringval, "true");
649
strcpy(stringval, "false");