~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/clients/qmon/qmon_matrix.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*___INFO__MARK_BEGIN__*/
 
2
/*************************************************************************
 
3
 * 
 
4
 *  The Contents of this file are made available subject to the terms of
 
5
 *  the Sun Industry Standards Source License Version 1.2
 
6
 * 
 
7
 *  Sun Microsystems Inc., March, 2001
 
8
 * 
 
9
 * 
 
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
 
16
 * 
 
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.
 
23
 * 
 
24
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
25
 * 
 
26
 *   Copyright: 2001 by Sun Microsystems, Inc.
 
27
 * 
 
28
 *   All Rights Reserved.
 
29
 * 
 
30
 ************************************************************************/
 
31
/*___INFO__MARK_END__*/
 
32
#include <ctype.h>
 
33
#include <stdlib.h>
 
34
#include <stdio.h>
 
35
#include <string.h>
 
36
 
 
37
#include <Xmt/Xmt.h>
 
38
#include <Xmt/WidgetType.h>
 
39
#include <Xmt/InputField.h>
 
40
#include <Xmt/Procedures.h>
 
41
 
 
42
#include "sge_usageL.h"
 
43
 
 
44
#include "cull.h"
 
45
#include "gdi/sge_gdi.h"
 
46
#include "sge_parse_num_par.h"
 
47
#include "sge_complex_schedd.h"
 
48
#include "sge_range.h"
 
49
#include "sge_answer.h"
 
50
#include "sge_job.h"
 
51
#include "sge_qinstance.h"
 
52
#include "sge_subordinate.h"
 
53
#include "sge_centry.h"
 
54
#include "sge_var.h"
 
55
#include "sge_host.h"
 
56
#include "sge_mailrec.h"
 
57
 
 
58
#include "qmon_rmon.h"
 
59
#include "qmon_quarks.h"
 
60
#include "qmon_matrix.h"
 
61
#include "qmon_load.h"
 
62
#include "qmon_message.h"
 
63
#include "qmon_util.h"
 
64
 
 
65
 
 
66
static Widget CreateMatrixSimple(Widget parent, String name, ArgList arglist, Cardinal argcount);
 
67
static Widget CreateMatrix(Widget parent, String name, ArgList arglist, Cardinal argcount);
 
68
static void qmonMatrixLoseFocus(Widget w, XtPointer cld, XtPointer cad);
 
69
static void qmonMatrixTraverse(Widget w, XtPointer cld, XtPointer cad);
 
70
static void DeleteLines(Widget w, XtPointer cld, XtPointer cad);
 
71
static void ColumnZeroNoEdit(Widget w, XtPointer cld, XtPointer cad);
 
72
static void ColumnNoEdit(Widget w, XtPointer cld, XtPointer cad);
 
73
static void set_2xN(Widget w, XtPointer address, XrmQuark type, Cardinal size);
 
74
static void get_2xN(Widget w, XtPointer address, XrmQuark type, Cardinal size);
 
75
static void set_CE_Type(Widget w, XtPointer address, XrmQuark type, Cardinal size);
 
76
static Boolean getCE_TypeValues(lListElem *ep, const char **ce_entry); 
 
77
static Boolean setCE_TypeValues(lListElem *ep, char **ce_entry);
 
78
static void set_CX_Type(Widget w, XtPointer address, XrmQuark type, Cardinal size);
 
79
static void get_CX_Type(Widget w, XtPointer address, XrmQuark type, Cardinal size);
 
80
 
 
81
 
 
82
 
 
83
static XmtWidgetType widgets[] = {
 
84
   {
 
85
      "Matrix_2xN",        /* name     */
 
86
      NULL,                   /* class    */
 
87
      CreateMatrix,       /* constructor */
 
88
      set_2xN,            /* procedure to set a value on widget */
 
89
      get_2xN,            /* procedure to get a value from widget */
 
90
      False                   /* not a popup widget */
 
91
   },
 
92
   {
 
93
      "UserMatrix",        /* name     */
 
94
      NULL,                   /* class    */
 
95
      CreateMatrix,       /* constructor */
 
96
      NULL,            /* procedure to set a value on widget */
 
97
      NULL,            /* procedure to get a value from widget */
 
98
      False                   /* not a popup widget */
 
99
   },
 
100
   {
 
101
      "CE_TypeMatrix",         
 
102
      NULL,
 
103
      CreateMatrixSimple,
 
104
      set_CE_Type,
 
105
      NULL,
 
106
      False
 
107
   },
 
108
   {
 
109
      "CX_TypeMatrix",         
 
110
      NULL,
 
111
      CreateMatrix,
 
112
      set_CX_Type,
 
113
      get_CX_Type,
 
114
      False
 
115
   },
 
116
   {
 
117
      "UU_TypeMatrix",         
 
118
      NULL,
 
119
      CreateMatrixSimple,
 
120
      set_2xN,
 
121
      get_2xN,
 
122
      False
 
123
   },
 
124
   {
 
125
      "LoadMatrix",         
 
126
      NULL,
 
127
      CreateMatrixSimple,
 
128
      NULL,
 
129
      NULL,
 
130
      False
 
131
   }
 
132
};
 
133
 
 
134
/*-------------------------------------------------------------------------*/
 
135
/*   P U B L I C                                                           */
 
136
/*-------------------------------------------------------------------------*/
 
137
void QmonRegisterMatrixWidgets(void)
 
138
{
 
139
   QmonInitQuarks();   /* initialize the quarks */
 
140
   XmtRegisterWidgetTypes(widgets, XtNumber(widgets));
 
141
}
 
142
   
 
143
/*-------------------------------------------------------------------------*/
 
144
/*   P R I V A T E                                                         */
 
145
/*-------------------------------------------------------------------------*/
 
146
static Widget CreateMatrixSimple(
 
147
Widget parent,
 
148
String name,
 
149
ArgList arglist,
 
150
Cardinal argcount 
 
151
) {
 
152
   Widget matrix;
 
153
#ifndef TEXTCHILD_BUG
 
154
   Widget textChild;
 
155
#endif
 
156
   
 
157
   matrix = XtCreateWidget(name, xbaeMatrixWidgetClass, parent,
 
158
                              arglist, argcount);
 
159
 
 
160
#ifndef TEXTCHILD_BUG
 
161
   XtVaGetValues(matrix, XmNtextField, &textChild, NULL);
 
162
   XtAddCallback(textChild, XmNlosingFocusCallback,
 
163
                  qmonMatrixLoseFocus, (XtPointer) matrix);
 
164
#endif
 
165
   /*
 
166
   ** register callback procedures
 
167
   */
 
168
   XmtVaRegisterCallbackProcedures(
 
169
         "DeleteLines", DeleteLines, XtRWidget,
 
170
         "ColumnZeroNoEdit", ColumnZeroNoEdit, NULL,
 
171
         "ColumnNoEdit", ColumnNoEdit, NULL,
 
172
         NULL);
 
173
 
 
174
   return matrix;
 
175
}
 
176
 
 
177
 
 
178
/*-------------------------------------------------------------------------*/
 
179
static Widget CreateMatrix(
 
180
Widget parent,
 
181
String name,
 
182
ArgList arglist,
 
183
Cardinal argcount 
 
184
) {
 
185
   Widget matrix;
 
186
   Widget textChild;
 
187
   
 
188
   matrix = XtCreateWidget(name, xbaeMatrixWidgetClass, parent,
 
189
                              arglist, argcount);
 
190
 
 
191
#ifndef TEXTCHILD_BUG
 
192
   XtVaGetValues(matrix, XmNtextField, &textChild, NULL);
 
193
   XtAddCallback(textChild, XmNlosingFocusCallback,
 
194
                  qmonMatrixLoseFocus, (XtPointer) matrix);
 
195
#endif
 
196
   XtAddCallback(matrix, XmNtraverseCellCallback, 
 
197
                     qmonMatrixTraverse, NULL);
 
198
   XtAddCallback(matrix, XmNselectCellCallback, 
 
199
                     qmonMatrixSelect, NULL);
 
200
   /*
 
201
   ** register callback procedures
 
202
   */
 
203
   XmtVaRegisterCallbackProcedures(
 
204
         "DeleteLines", DeleteLines, XtRWidget,
 
205
         "ColumnZeroNoEdit", ColumnZeroNoEdit, NULL,
 
206
         "ColumnNoEdit", ColumnNoEdit, NULL,
 
207
         NULL);
 
208
 
 
209
   return matrix;
 
210
}
 
211
 
 
212
/*-------------------------------------------------------------------------*/
 
213
void qmonMatrixSelect(Widget w, XtPointer cld, XtPointer cad)
 
214
{
 
215
   XbaeMatrixSelectCellCallbackStruct *cbs = 
 
216
               (XbaeMatrixSelectCellCallbackStruct*) cad;
 
217
   int select_begin=0;
 
218
   int i;
 
219
   Widget* matrices = (Widget*) cld;
 
220
 
 
221
   DENTER(GUI_LAYER, "qmonMatrixSelect");
 
222
 
 
223
   if (cbs->params && !strcmp(cbs->params[0], "begin")) {
 
224
      XbaeMatrixDeselectAll(w);
 
225
      while (matrices && *matrices) {
 
226
         XbaeMatrixDeselectAll(*matrices);
 
227
         matrices++;
 
228
      }
 
229
      XbaeMatrixSelectRow(w, cbs->row);
 
230
   }
 
231
 
 
232
   if (cbs->params && !strcmp(cbs->params[0], "end")) {
 
233
      while (matrices && *matrices) {
 
234
         XbaeMatrixDeselectAll(*matrices);
 
235
         matrices++;
 
236
      }
 
237
      select_begin = XbaeMatrixFirstSelectedRow(w);
 
238
      if (select_begin == -1) {
 
239
         XbaeMatrixSelectRow(w, cbs->row);
 
240
         DEXIT;
 
241
         return;
 
242
      }
 
243
      if (cbs->row < select_begin) {
 
244
         for (i=cbs->row; i<select_begin; i++)
 
245
            XbaeMatrixSelectRow(w, i);
 
246
      }
 
247
      else {
 
248
         for (i=select_begin; i<=cbs->row; i++)
 
249
            XbaeMatrixSelectRow(w, i);
 
250
      }
 
251
   }
 
252
   if (cbs->params && !strcmp(cbs->params[0], "toggle")) {
 
253
      if (XbaeMatrixIsRowSelected(w, cbs->row)) {
 
254
         DPRINTF(("XbaeMatrixDeselectRow\n"));
 
255
         XbaeMatrixDeselectRow(w, cbs->row);
 
256
      }
 
257
      else {
 
258
         XbaeMatrixSelectRow(w, cbs->row);
 
259
         DPRINTF(("XbaeMatrixSelectRow\n"));
 
260
      }
 
261
   }
 
262
 
 
263
   if (cbs->params && !strcmp(cbs->params[0], "editall")) {
 
264
      XbaeMatrixEditCell(w, cbs->row, cbs->column);
 
265
   }
 
266
 
 
267
   if (cbs->params && !strcmp(cbs->params[0], "edit") && cbs->column != 0) {
 
268
      XbaeMatrixEditCell(w, cbs->row, cbs->column);
 
269
   }
 
270
 
 
271
   DEXIT;
 
272
}
 
273
 
 
274
 
 
275
/*-------------------------------------------------------------------------*/
 
276
static void DeleteLines(Widget w, XtPointer cld, XtPointer cad)
 
277
{
 
278
   Widget matrix = (Widget) cld;
 
279
   int rows;
 
280
   int i;
 
281
   int rows_to_delete = 0;
 
282
   int rows_old;
 
283
   int max_rows = 7;
 
284
   
 
285
 
 
286
   DENTER(GUI_LAYER, "DeleteLines");
 
287
 
 
288
   if (!matrix) {
 
289
      DEXIT;
 
290
      return;
 
291
   }
 
292
 
 
293
   /* max_rows = XbaeMatrixVisibleRows(matrix); */
 
294
 
 
295
   rows = rows_old = XbaeMatrixNumRows(matrix);
 
296
 
 
297
   for (i=0; i<rows; i++)
 
298
      if (XbaeMatrixIsRowSelected(matrix, i))
 
299
         rows_to_delete++;
 
300
 
 
301
   i = 0;
 
302
   while (i<rows) {
 
303
      if (XbaeMatrixIsRowSelected(matrix, i)) {
 
304
         XbaeMatrixDeleteRows(matrix, i, 1);
 
305
         rows--;
 
306
      }
 
307
      else
 
308
         i++;
 
309
   }
 
310
 
 
311
   if ((rows_old - rows_to_delete) < max_rows) 
 
312
      XbaeMatrixAddRows(matrix, rows, NULL, NULL, NULL, (max_rows - rows));
 
313
 
 
314
   /* reset attribute line */
 
315
   XbaeMatrixDeselectAll(matrix);
 
316
 
 
317
   /* refresh the matrix */
 
318
   XbaeMatrixRefresh(matrix);
 
319
 
 
320
   
 
321
   DEXIT;
 
322
}
 
323
 
 
324
/*-------------------------------------------------------------------------*/
 
325
static void ColumnZeroNoEdit(Widget w, XtPointer cld, XtPointer cad)
 
326
{
 
327
   XbaeMatrixEnterCellCallbackStruct *cbs = 
 
328
            (XbaeMatrixEnterCellCallbackStruct*) cad;
 
329
 
 
330
   DENTER(GUI_LAYER, "ColumnZeroNoEdit");
 
331
 
 
332
   if (cbs->column == 0)
 
333
      cbs->doit = False;
 
334
   
 
335
   DEXIT;
 
336
}
 
337
 
 
338
/*-------------------------------------------------------------------------*/
 
339
static void ColumnNoEdit(Widget w, XtPointer cld, XtPointer cad)
 
340
{
 
341
   XbaeMatrixEnterCellCallbackStruct *cbs = 
 
342
            (XbaeMatrixEnterCellCallbackStruct*) cad;
 
343
 
 
344
   DENTER(GUI_LAYER, "ColumnNoEdit");
 
345
 
 
346
   cbs->doit = False;
 
347
   
 
348
   DEXIT;
 
349
}
 
350
 
 
351
 
 
352
 
 
353
 
 
354
/*-------------------------------------------------------------------------*/
 
355
static void qmonMatrixTraverse(Widget w, XtPointer cld, XtPointer cad)
 
356
{
 
357
   XbaeMatrixTraverseCellCallbackStruct *cbs = 
 
358
            (XbaeMatrixTraverseCellCallbackStruct*) cad;
 
359
   static XrmQuark QDown = NULLQUARK;
 
360
   static XrmQuark QRight = NULLQUARK;
 
361
   static XrmQuark QUp = NULLQUARK;
 
362
   
 
363
   DENTER(GUI_LAYER, "qmonMatrixTraverse");
 
364
 
 
365
   /*
 
366
    * Get the Quarks we care about
 
367
    */
 
368
   if (QDown == NULLQUARK) {
 
369
      QDown = XrmStringToQuark("Down");
 
370
      QUp = XrmStringToQuark("Up");
 
371
      QRight = XrmStringToQuark("Right");
 
372
   }
 
373
 
 
374
   /*
 
375
   ** if we are moving up don't jump to last row when we are in row 0
 
376
   */
 
377
   if ((cbs->qparam == QUp && cbs->row == 0)) {
 
378
      cbs->next_row = cbs->row;
 
379
   }
 
380
 
 
381
   /*
 
382
    * If we are moving down, and we are at the last row, add a new row
 
383
    * and traverse to it.
 
384
    */
 
385
   if ((cbs->qparam == QDown && cbs->row == cbs->num_rows - 1) ||
 
386
       (cbs->qparam == QRight && cbs->row == cbs->num_rows - 1 &&
 
387
            cbs->column == cbs->num_columns)) {
 
388
      XbaeMatrixAddRows(w, cbs->num_rows, NULL, NULL, NULL, 1);
 
389
      cbs->next_row = cbs->num_rows;
 
390
      cbs->next_column = cbs->column;
 
391
   }
 
392
 
 
393
   DEXIT;
 
394
}
 
395
 
 
396
/*-------------------------------------------------------------------------*/
 
397
static void qmonMatrixLoseFocus(Widget w, XtPointer cld, XtPointer cad)
 
398
{
 
399
   Widget matrix = (Widget) cld;
 
400
   XbaeMatrixCommitEdit(matrix, False);
 
401
}
 
402
 
 
403
/*-------------------------------------------------------------------------*/
 
404
static void set_2xN(
 
405
Widget w,
 
406
XtPointer address,
 
407
XrmQuark type,
 
408
Cardinal size 
 
409
) {
 
410
   lList *lp = NULL;
 
411
 
 
412
   if (type != QmonQVA_Type && type != QmonQCE2_Type &&
 
413
       type != QmonQHS_Type && type != QmonQMR_Type &&
 
414
       type != QmonQPN_Type && type != QmonQAT_Type &&
 
415
       type != QmonQSO_Type && type != QmonQUA_Type) {
 
416
      XmtWarningMsg("XmtDialogSetDialogValues", "XbaeMatrix",
 
417
         "Type Mismatch: Widget '%s':\n\tCan't set widget values"
 
418
         " from a resource of type '%s'",
 
419
          XtName(w), XrmQuarkToString(type));
 
420
 
 
421
      return;
 
422
   }
 
423
 
 
424
   if (size == sizeof(lList*))
 
425
      lp = *(lList**) address;
 
426
   else
 
427
      return;
 
428
 
 
429
   if (type == QmonQVA_Type) 
 
430
      qmonSet2xN(w, lp, VA_variable, VA_value);
 
431
   else if ( type == QmonQCE2_Type ) 
 
432
      qmonSet2xN(w, lp, CE_name, CE_stringval);
 
433
   else if ( type ==  QmonQHS_Type )
 
434
      qmonSet2xN(w, lp, HS_name, HS_value);
 
435
   else if ( type == QmonQMR_Type )
 
436
      qmonSet2xN(w, lp, MR_user, MR_host);
 
437
   else if ( type == QmonQPN_Type )
 
438
      qmonSet2xN(w, lp, PN_path, PN_host);
 
439
   else if ( type == QmonQAT_Type )
 
440
      qmonSet2xN(w, lp, AT_account, AT_cell);
 
441
   else if ( type == QmonQSO_Type )
 
442
      qmonSet2xN(w, lp, SO_name, SO_threshold);
 
443
   else if ( type == QmonQUA_Type )
 
444
      qmonSet2xN(w, lp, UA_name, UA_value);
 
445
      
 
446
}
 
447
 
 
448
 
 
449
/*-------------------------------------------------------------------------*/
 
450
static void get_2xN(
 
451
Widget w,
 
452
XtPointer address,
 
453
XrmQuark type,
 
454
Cardinal size 
 
455
) {
 
456
   lList *lp = NULL;
 
457
   
 
458
   if (type != QmonQVA_Type && type != QmonQCE2_Type &&
 
459
       type != QmonQHS_Type && type != QmonQMR_Type &&
 
460
       type != QmonQPN_Type && type != QmonQAT_Type && 
 
461
       type != QmonQSO_Type && type != QmonQUA_Type) {
 
462
      XmtWarningMsg("XmtDialogGetDialogValues", "XbaeMatrix",
 
463
         "Type Mismatch: Widget '%s':\n\tCan't get widget values"
 
464
         " from a resource of type '%s'",
 
465
          XtName(w), XrmQuarkToString(type));
 
466
 
 
467
      return;
 
468
   }
 
469
 
 
470
   if (type == QmonQVA_Type) 
 
471
      lp = qmonGet2xN(w, VA_Type, VA_variable, VA_value);
 
472
   else if ( type == QmonQCE2_Type ) 
 
473
      lp = qmonGet2xN(w, CE_Type, CE_name, CE_stringval);
 
474
   else if ( type ==  QmonQHS_Type )
 
475
      lp = qmonGet2xN(w, HS_Type, HS_name, HS_value);
 
476
   else if ( type == QmonQMR_Type ) 
 
477
      lp = qmonGet2xN(w, MR_Type, MR_user, MR_host);
 
478
   else if ( type == QmonQPN_Type )
 
479
      lp = qmonGet2xN(w, PN_Type, PN_path, PN_host);
 
480
   else if ( type == QmonQAT_Type )
 
481
      lp = qmonGet2xN(w, AT_Type, AT_account, AT_cell);
 
482
   else if ( type == QmonQSO_Type )
 
483
      lp = qmonGet2xN(w, SO_Type, SO_name, SO_threshold);
 
484
   else if ( type == QmonQUA_Type )
 
485
      lp = qmonGet2xN(w, UA_Type, UA_name, UA_value);
 
486
 
 
487
   *(lList**)address = lp;
 
488
}
 
489
 
 
490
 
 
491
/*-------------------------------------------------------------------------*/
 
492
void qmonSetNxN(
 
493
Widget w,
 
494
lList *lp,
 
495
int num_fields,
 
496
...
 
497
) {
 
498
   lListElem *ep;
 
499
   int i, row;
 
500
   int max_rows;
 
501
   int val;
 
502
   double dval;
 
503
   char buf[128];
 
504
   int *field;
 
505
   const char **col;
 
506
   va_list ap;
 
507
   
 
508
   DENTER(GUI_LAYER, "qmonSetNxN");
 
509
   
 
510
   /* clear the area */
 
511
   XtVaSetValues(w, XmNcells, NULL, NULL);
 
512
   
 
513
   if (!lp) {
 
514
      DEXIT;
 
515
      return;
 
516
   }
 
517
 
 
518
   field = (int *)malloc(num_fields*sizeof(int));
 
519
   col = (const char **)malloc(num_fields*sizeof(char *));
 
520
   if (field == NULL || col == NULL) {
 
521
      abort();
 
522
   }
 
523
 
 
524
   va_start(ap, num_fields);
 
525
   for(i=0; i<num_fields; i++)
 
526
      field[i] = va_arg(ap, int);
 
527
 
 
528
   XtVaGetValues(w, XmNrows, &max_rows, NULL);
 
529
 
 
530
   for (ep = lFirst(lp), row = 0; ep; ep = lNext(ep), row++) {
 
531
      if (row == max_rows) {
 
532
         XbaeMatrixAddRows(w, 
 
533
                           max_rows, 
 
534
                           NULL,       /* empty rows  */
 
535
                           NULL,       /* no lables   */
 
536
                           NULL,       /* no different colors */
 
537
                           1);         /* we add 1 rows      */
 
538
         max_rows++;
 
539
      }
 
540
 
 
541
      memset(col, 0, num_fields*sizeof(char *));
 
542
 
 
543
      /*
 
544
       * get column values
 
545
       */
 
546
 
 
547
      for(i=0; i<num_fields; i++) {
 
548
 
 
549
         switch (lGetType(lGetListDescr(lp), field[i])) {
 
550
            case lStringT:
 
551
               col[i] = (StringConst)lGetString(ep, field[i]);
 
552
               break;
 
553
            case lHostT:
 
554
               col[i] = (StringConst)lGetHost(ep,field[i]);
 
555
               break;
 
556
            case lUlongT:
 
557
               val = (int)lGetUlong(ep, field[i]);
 
558
#if 0
 
559
               if (val) {
 
560
                  sprintf(buf, "%d", val);
 
561
                  col[i] = buf;
 
562
               }
 
563
               else
 
564
                  col[i] = NULL;
 
565
#else
 
566
               sprintf(buf, "%d", val);
 
567
               col[i] = buf;
 
568
#endif
 
569
               break;
 
570
            case lDoubleT:
 
571
               dval = lGetDouble(ep, field[i]);
 
572
               sprintf(buf, "%.2f", dval);
 
573
               col[i] = buf;
 
574
               break;
 
575
         }
 
576
      }
 
577
 
 
578
      if (col[0]) {
 
579
         /* FIX_CONST_GUI */
 
580
         for(i=0; i<num_fields; i++)
 
581
            XbaeMatrixSetCell(w, row, i, col[i] ? (String)col[i] : "");
 
582
      }
 
583
   }
 
584
 
 
585
   free(field);
 
586
   free(col);
 
587
       
 
588
   DEXIT;
 
589
}
 
590
 
 
591
/*-------------------------------------------------------------------------*/
 
592
lList* qmonGetNxN(
 
593
Widget w,
 
594
lDescr *dp,
 
595
int num_fields,
 
596
...
 
597
) {
 
598
   lList *lp = NULL;
 
599
   lListElem *ep;
 
600
   int i, row;
 
601
   int max_rows;
 
602
   va_list ap;
 
603
   char **col;
 
604
   int *field;
 
605
 
 
606
   DENTER(GUI_LAYER, "qmonGetNxN");
 
607
 
 
608
   field = (int *)malloc(num_fields*sizeof(int));
 
609
   col = (char **)malloc(num_fields*sizeof(char *));
 
610
   if (field == NULL || col == NULL) {
 
611
      abort();
 
612
   }
 
613
 
 
614
   va_start(ap, num_fields);
 
615
   for(i=0; i<num_fields; i++)
 
616
      field[i] = va_arg(ap, int);
 
617
 
 
618
   XtVaGetValues(w, XmNrows, &max_rows, NULL);
 
619
   
 
620
   for (row=0; row<max_rows; row++) {
 
621
      memset(col, 0, num_fields*sizeof(char *));
 
622
      for(i=0; i<num_fields; i++)
 
623
         col[i] = XbaeMatrixGetCell(w, row, i);
 
624
      if (col[0] && col[0][0] != '\0') {
 
625
         if (!lp)
 
626
            lp = lCreateList(XtName(w), dp);
 
627
         ep = lCreateElem(dp);
 
628
         lAppendElem(lp, ep);
 
629
 
 
630
         /*
 
631
          * retrieve values from columns
 
632
          */
 
633
 
 
634
         for(i=0; i<num_fields; i++) {
 
635
            switch(lGetType(lGetListDescr(lp), field[i])) {
 
636
               case lStringT: 
 
637
                  lSetString(ep, field[i], col[i] ? col[i] : "" );
 
638
                  break;
 
639
               case lHostT:
 
640
                  lSetHost(ep, field[i], col[i] ? col[i] : "");
 
641
                  break;
 
642
               case lUlongT:
 
643
                  lSetUlong(ep, field[i], col[i] ? atoi(col[i]) : 0);
 
644
                  break;
 
645
               case lDoubleT:
 
646
                  lSetDouble(ep, field[i], col[i] ? atof(col[i]) : 0.0);
 
647
                  break;
 
648
            }
 
649
         }
 
650
      }
 
651
      else
 
652
         continue;
 
653
   }
 
654
 
 
655
   free(field);
 
656
   free(col);
 
657
 
 
658
   DEXIT;
 
659
   return lp;
 
660
}
 
661
 
 
662
   
 
663
#if 1
 
664
 
 
665
/*-------------------------------------------------------------------------*/
 
666
void qmonSet2xN(
 
667
Widget w,
 
668
lList *lp,
 
669
int field1,
 
670
int field2 
 
671
) {
 
672
   qmonSetNxN(w, lp, 2, field1, field2);
 
673
}
 
674
 
 
675
 
 
676
/*-------------------------------------------------------------------------*/
 
677
lList* qmonGet2xN(
 
678
Widget w,
 
679
lDescr *dp,
 
680
int field1,
 
681
int field2 
 
682
) {
 
683
   return qmonGetNxN(w, dp, 2, field1, field2);
 
684
}
 
685
 
 
686
#else
 
687
 
 
688
/*-------------------------------------------------------------------------*/
 
689
void qmonSet2xN(
 
690
Widget w,
 
691
lList *lp,
 
692
int field1,
 
693
int field2 
 
694
) {
 
695
   lListElem *ep;
 
696
   int row;
 
697
   int max_rows;
 
698
   const char *col1 = NULL, *col2 = NULL;
 
699
   int val;
 
700
   double dval;
 
701
   char buf[128];
 
702
   
 
703
   DENTER(GUI_LAYER, "qmonSet2xN");
 
704
   
 
705
   /* clear the area */
 
706
   XtVaSetValues(w, XmNcells, NULL, NULL);
 
707
   
 
708
   if (!lp) {
 
709
      DEXIT;
 
710
      return;
 
711
   }
 
712
      
 
713
   XtVaGetValues(w, XmNrows, &max_rows, NULL);
 
714
 
 
715
   for (ep = lFirst(lp), row = 0; ep; ep = lNext(ep), row++) {
 
716
      if (row == max_rows) {
 
717
         XbaeMatrixAddRows(w, 
 
718
                           max_rows, 
 
719
                           NULL,       /* empty rows  */
 
720
                           NULL,       /* no lables   */
 
721
                           NULL,       /* no different colors */
 
722
                           1);         /* we add 1 rows      */
 
723
         max_rows++;
 
724
      }
 
725
      /*
 
726
      ** the first column of the matrix can be string or host type
 
727
      **
 
728
      */
 
729
      switch (lGetType(lGetListDescr(lp), field1)) {
 
730
         case lStringT:
 
731
            col1 = (StringConst)lGetString(ep, field1);
 
732
            break;
 
733
         case lHostT:
 
734
            col1 = (StringConst)lGetHost(ep,field1);
 
735
            break;
 
736
      }
 
737
      /*
 
738
      ** the second column can be of different type
 
739
      */
 
740
      switch (lGetType(lGetListDescr(lp), field2)) {
 
741
         case lStringT:
 
742
            col2 = (StringConst)lGetString(ep, field2);
 
743
            break;
 
744
         case lHostT:
 
745
            col2 = (StringConst)lGetHost(ep,field2);
 
746
            break;
 
747
         case lUlongT:
 
748
            val = (int)lGetUlong(ep, field2);
 
749
            if (val) {
 
750
               sprintf(buf, "%d", val);
 
751
               col2 = buf;
 
752
            }
 
753
            else
 
754
               col2 = NULL;
 
755
            break;
 
756
         case lDoubleT:
 
757
            dval = lGetDouble(ep, field2);
 
758
            sprintf(buf, "%.2f", dval);
 
759
            col2 = buf;
 
760
            break;
 
761
      }
 
762
 
 
763
      if (col1) {
 
764
         /* FIX_CONST_GUI */
 
765
         XbaeMatrixSetCell(w, row, 0 , col1 ? (String)col1 : "");
 
766
         /* FIX_CONST_GUI */
 
767
         XbaeMatrixSetCell(w, row, 1 , col2 ? (String)col2 : "");
 
768
      }
 
769
   }
 
770
       
 
771
   DEXIT;
 
772
}
 
773
 
 
774
/*-------------------------------------------------------------------------*/
 
775
lList* qmonGet2xN(
 
776
Widget w,
 
777
lDescr *dp,
 
778
int field1,
 
779
int field2 
 
780
) {
 
781
   lList *lp = NULL;
 
782
   lListElem *ep;
 
783
   int row;
 
784
   int max_rows;
 
785
   char *col1, *col2;
 
786
 
 
787
   DENTER(GUI_LAYER, "qmonGet2xN");
 
788
 
 
789
   XtVaGetValues(w, XmNrows, &max_rows, NULL);
 
790
   
 
791
   for (row=0; row<max_rows; row++) {
 
792
      col1 = XbaeMatrixGetCell(w, row, 0);
 
793
      col2 = XbaeMatrixGetCell(w, row, 1);
 
794
      if (col1 && col1[0] != '\0') {
 
795
         if (!lp)
 
796
            lp = lCreateList(XtName(w), dp);
 
797
         ep = lCreateElem(dp);
 
798
         lAppendElem(lp, ep);
 
799
 
 
800
         /*
 
801
         ** the first field in the column can be host or string
 
802
         */
 
803
 
 
804
         switch(lGetType(lGetListDescr(lp), field1)) {
 
805
            case lStringT:
 
806
               lSetString(ep, field1, col1 ? col1 : "");
 
807
               break;
 
808
            case lHostT:
 
809
               lSetHost(ep, field1, col1 ? col1 : "");
 
810
               break;
 
811
         }
 
812
 
 
813
         /*
 
814
         ** the second field can be of different type
 
815
         */
 
816
         switch(lGetType(lGetListDescr(lp), field2)) {
 
817
            case lStringT: 
 
818
               lSetString(ep, field2, col2 ? col2 : "" );
 
819
               break;
 
820
            case lHostT:
 
821
               lSetHost(ep, field2, col2 ? col2 : "");
 
822
               break;
 
823
            case lUlongT:
 
824
               lSetUlong(ep, field2, col2 ? atoi(col2) : 0);
 
825
               break;
 
826
            case lDoubleT:
 
827
               lSetDouble(ep, field2, col2 ? atof(col2) : 0.0);
 
828
               break;
 
829
         }   
 
830
      }
 
831
      else
 
832
         continue;
 
833
   }
 
834
 
 
835
   DEXIT;
 
836
   return lp;
 
837
}
 
838
 
 
839
#endif
 
840
 
 
841
   
 
842
/*-------------------------------------------------------------------------*/
 
843
/*-------------------------------------------------------------------------*/
 
844
/*-------------------------------------------------------------------------*/
 
845
/*-------------------------------------------------------------------------*/
 
846
static void set_CE_Type(
 
847
Widget w,
 
848
XtPointer address,
 
849
XrmQuark type,
 
850
Cardinal size 
 
851
) {
 
852
   lList *lp = NULL;
 
853
 
 
854
   if (type != QmonQCE_Type) {
 
855
      XmtWarningMsg("XmtDialogSetDialogValues", "XbaeMatrix",
 
856
         "Type Mismatch: Widget '%s':\n\tCan't set widget values"
 
857
         " from a resource of type '%s'; QmonQCE_Type expected.",
 
858
          XtName(w), XrmQuarkToString(type));
 
859
 
 
860
      return;
 
861
   }
 
862
 
 
863
   if (size == sizeof(lList*))
 
864
      lp = *(lList**) address;
 
865
   else
 
866
      return;
 
867
 
 
868
   qmonSetCE_Type(w, lp, CE_TYPE_REDUCED);
 
869
 
 
870
}
 
871
 
 
872
/*-------------------------------------------------------------------------*/
 
873
void qmonSetCE_Type(
 
874
Widget w,
 
875
lList *lp,
 
876
int full 
 
877
) {
 
878
   lListElem *ep;
 
879
   int row;
 
880
   int max_rows;
 
881
   const char *ce_entry[CE_MAX];
 
882
   int i;
 
883
   
 
884
   DENTER(GUI_LAYER, "qmonSetCE_Type");
 
885
   
 
886
   XtVaGetValues(w, XmNrows, &max_rows, NULL);
 
887
   
 
888
   /* clear the area */
 
889
   XtVaSetValues(w, XmNcells, NULL, NULL);
 
890
   
 
891
   for (ep = lFirst(lp), row = 0; ep; ep = lNext(ep), row++) {
 
892
      if (row == max_rows) {
 
893
         XbaeMatrixAddRows(w, 
 
894
                           max_rows, 
 
895
                           NULL,       /* empty rows  */
 
896
                           NULL,       /* no lables   */
 
897
                           NULL,       /* no different colors */
 
898
                           1);         /* we add 1 row */
 
899
         max_rows++;
 
900
      }
 
901
      if (getCE_TypeValues(ep, ce_entry)) {
 
902
         if (full) {
 
903
            for (i=0; i<CE_MAX; i++) {
 
904
               /* FIX_CONST_GUI */
 
905
               XbaeMatrixSetCell(w, row, i, 
 
906
                  ce_entry[i] ? (String)ce_entry[i] : "");
 
907
            }
 
908
         }
 
909
         else {
 
910
            /* FIX_CONST_GUI */
 
911
            XbaeMatrixSetCell(w, row, 0, 
 
912
               ce_entry[CE_NAME] ? (String)ce_entry[CE_NAME] : "");
 
913
            /* FIX_CONST_GUI */
 
914
            XbaeMatrixSetCell(w, row, 1, 
 
915
               ce_entry[CE_TYPE] ? (String)ce_entry[CE_TYPE] : "");
 
916
            /* FIX_CONST_GUI */
 
917
            XbaeMatrixSetCell(w, row, 2, 
 
918
               ce_entry[CE_RELOP] ? (String)ce_entry[CE_RELOP] : "");
 
919
         }
 
920
      }
 
921
      else
 
922
         DPRINTF(("qmonSetCE_Type failure\n"));
 
923
   }
 
924
       
 
925
   DEXIT;
 
926
}
 
927
   
 
928
 
 
929
/*-------------------------------------------------------------------------*/
 
930
static Boolean getCE_TypeValues(
 
931
lListElem *ep,
 
932
StringConst *ce_entry 
 
933
) {
 
934
   DENTER(GUI_LAYER, "getCE_TypeValues");
 
935
   
 
936
   if (!ep || !ce_entry ) {
 
937
      DEXIT;
 
938
      return False;
 
939
   }
 
940
      
 
941
   /* name type relation value */ 
 
942
   ce_entry[CE_NAME] = (StringConst)lGetString(ep, CE_name);
 
943
   ce_entry[CE_SHORTCUT] = (StringConst)lGetString(ep, CE_shortcut);
 
944
   ce_entry[CE_TYPE] = (StringConst)map_type2str(lGetUlong(ep, CE_valtype));
 
945
 
 
946
   switch (lGetUlong(ep, CE_relop)) {
 
947
   case CMPLXLT_OP:
 
948
      ce_entry[CE_RELOP] = "<";
 
949
      break; 
 
950
   case CMPLXGT_OP:
 
951
      ce_entry[CE_RELOP] = ">";
 
952
      break; 
 
953
   case CMPLXLE_OP:
 
954
      ce_entry[CE_RELOP] = "<=";
 
955
      break; 
 
956
   case CMPLXGE_OP:
 
957
      ce_entry[CE_RELOP] = ">=";
 
958
      break; 
 
959
   case CMPLXEQ_OP:
 
960
      ce_entry[CE_RELOP] = "==";
 
961
      break; 
 
962
   case CMPLXNE_OP:
 
963
      ce_entry[CE_RELOP] = "!=";
 
964
      break; 
 
965
   default:
 
966
      ce_entry[CE_RELOP] = "??";
 
967
   }
 
968
   ce_entry[CE_REQUEST] = lGetUlong(ep, CE_requestable) == REQU_FORCED ? "FORCED" : 
 
969
                           (lGetUlong(ep, CE_requestable) == REQU_YES ? "YES" : "NO");
 
970
   ce_entry[CE_CONSUMABLE] = lGetBool(ep, CE_consumable) ? "YES" : "NO";
 
971
   ce_entry[CE_DEFAULT] = (StringConst)lGetString(ep, CE_default);
 
972
   ce_entry[CE_URGENCY] = (StringConst)lGetString(ep, CE_urgency_weight);
 
973
      
 
974
   DEXIT;
 
975
   return True;
 
976
}
 
977
 
 
978
/*-------------------------------------------------------------------------*/
 
979
static Boolean setCE_TypeValues(
 
980
lListElem *ep,
 
981
String *ce_entry 
 
982
) {
 
983
   int i, type, relop; 
 
984
   u_long32 requestable = REQU_NO;
 
985
 
 
986
   DENTER(GUI_LAYER, "setCE_TypeValues");
 
987
   
 
988
   if (!ep) {
 
989
      DEXIT;
 
990
      return False;
 
991
   }
 
992
      
 
993
   /* name type relation value */ 
 
994
   lSetString(ep, CE_name, ce_entry[CE_NAME] ? qmon_trim(ce_entry[CE_NAME]): "");
 
995
   lSetString(ep, CE_shortcut, ce_entry[CE_SHORTCUT] ? qmon_trim(ce_entry[CE_SHORTCUT]): "" );
 
996
 
 
997
   type = 0;
 
998
   for (i=TYPE_FIRST; !type && i<=TYPE_CE_LAST; i++) {
 
999
      if (!strcasecmp(ce_entry[CE_TYPE], map_type2str(i)))
 
1000
         type = i;
 
1001
   }
 
1002
   if (!type) {
 
1003
      DPRINTF(("setCE_TypeValues: unknown type\n"));
 
1004
      DEXIT;
 
1005
      return False;
 
1006
   }
 
1007
   lSetUlong(ep, CE_valtype, type);
 
1008
 
 
1009
   relop = 0;
 
1010
   for (i=CMPLXEQ_OP; !relop && i<=CMPLXNE_OP; i++) {
 
1011
      if (!strcmp(ce_entry[CE_RELOP], map_op2str(i)))
 
1012
         relop = i;
 
1013
   }
 
1014
   if (!relop) {
 
1015
      DPRINTF(("invalid relation operator: %s\n", ce_entry[CE_RELOP]));
 
1016
      DEXIT;
 
1017
      return False;
 
1018
   }
 
1019
   lSetUlong(ep, CE_relop, relop);
 
1020
 
 
1021
   if (!strcasecmp(ce_entry[CE_REQUEST], "y") 
 
1022
            || !strcasecmp(ce_entry[CE_REQUEST], "yes"))
 
1023
      requestable = REQU_YES;
 
1024
   else if (!strcasecmp(ce_entry[CE_REQUEST], "n") 
 
1025
            || !strcasecmp(ce_entry[CE_REQUEST], "no"))
 
1026
      requestable = REQU_NO;
 
1027
   else if (!strcasecmp(ce_entry[CE_REQUEST], "f") 
 
1028
            || !strcasecmp(ce_entry[CE_REQUEST], "forced")) {
 
1029
      requestable = REQU_FORCED;
 
1030
   }
 
1031
   else {
 
1032
      DPRINTF(("invalid requestable entry: %s\n", ce_entry[CE_REQUEST]));
 
1033
   }
 
1034
 
 
1035
   lSetUlong(ep, CE_requestable, requestable);
 
1036
 
 
1037
   if (!strcasecmp(ce_entry[CE_CONSUMABLE], "y") 
 
1038
            || !strcasecmp(ce_entry[CE_CONSUMABLE], "yes"))
 
1039
      lSetBool(ep, CE_consumable, true);
 
1040
   else if (!strcasecmp(ce_entry[CE_CONSUMABLE], "n") 
 
1041
            || !strcasecmp(ce_entry[CE_CONSUMABLE], "no"))
 
1042
      lSetBool(ep, CE_consumable, false);
 
1043
 
 
1044
   lSetString(ep, CE_default, ce_entry[CE_DEFAULT] ? qmon_trim(ce_entry[CE_DEFAULT]): "");
 
1045
   lSetString(ep, CE_urgency_weight, ce_entry[CE_URGENCY] ? qmon_trim(ce_entry[CE_URGENCY]): "");
 
1046
 
 
1047
   
 
1048
   DEXIT;
 
1049
   return True;
 
1050
}
 
1051
 
 
1052
/*-------------------------------------------------------------------------*/
 
1053
/*-------------------------------------------------------------------------*/
 
1054
/*-------------------------------------------------------------------------*/
 
1055
/*-------------------------------------------------------------------------*/
 
1056
static void set_CX_Type(
 
1057
Widget w,
 
1058
XtPointer address,
 
1059
XrmQuark type,
 
1060
Cardinal size 
 
1061
) {
 
1062
   lList *lp = NULL;
 
1063
 
 
1064
   if (type != QmonQCX_Type) {
 
1065
      XmtWarningMsg("XmtDialogSetDialogValues", "XbaeMatrix",
 
1066
         "Type Mismatch: Widget '%s':\n\tCan't set widget values"
 
1067
         " from a resource of type '%s'; QmonQCX_Type expected.",
 
1068
          XtName(w), XrmQuarkToString(type));
 
1069
 
 
1070
      return;
 
1071
   }
 
1072
 
 
1073
   if (size == sizeof(lList*))
 
1074
      lp = *(lList**) address;
 
1075
   else
 
1076
      return;
 
1077
 
 
1078
   qmonSetCE_Type(w, lp, CE_TYPE_FULL);
 
1079
 
 
1080
}
 
1081
 
 
1082
 
 
1083
/*-------------------------------------------------------------------------*/
 
1084
static void get_CX_Type(
 
1085
Widget w,
 
1086
XtPointer address,
 
1087
XrmQuark type,
 
1088
Cardinal size 
 
1089
) {
 
1090
   lList *lp = NULL;
 
1091
   
 
1092
   if (type != QmonQCX_Type) {
 
1093
      XmtWarningMsg("XmtDialogSetDialogValues", "XbaeMatrix",
 
1094
         "Type Mismatch: Widget '%s':\n\tCan't get widget values"
 
1095
         " from a resource of type '%s'; QmonQCX_Type expected.",
 
1096
          XtName(w), XrmQuarkToString(type));
 
1097
 
 
1098
      return;
 
1099
   }
 
1100
 
 
1101
   lp = qmonGetCE_Type(w);
 
1102
   
 
1103
   *(lList**)address = lp;
 
1104
}
 
1105
 
 
1106
 
 
1107
 
 
1108
/*-------------------------------------------------------------------------*/
 
1109
lList* qmonGetCE_Type(
 
1110
Widget w 
 
1111
) {
 
1112
   lList *lp = NULL;
 
1113
   lListElem *ep;
 
1114
   int row;
 
1115
   int max_rows;
 
1116
   char *ce_entry[CE_MAX]; 
 
1117
   int k;
 
1118
 
 
1119
   DENTER(GUI_LAYER, "qmonGetCE_Type");
 
1120
   
 
1121
   XtVaGetValues(w, XmNrows, &max_rows, NULL);
 
1122
   lp = lCreateList(XtName(w), CE_Type);
 
1123
   for (row=0; row<max_rows && lp; row++) {
 
1124
      for (k=0; k<CE_MAX; k++) 
 
1125
         ce_entry[k] = XbaeMatrixGetCell(w, row, k);
 
1126
      if (ce_entry[CE_NAME] && ce_entry[CE_NAME][0] != '\0') {
 
1127
         ep = lCreateElem(CE_Type);
 
1128
         setCE_TypeValues(ep, ce_entry);
 
1129
         lAppendElem(lp, ep);
 
1130
      }
 
1131
      else
 
1132
         break;
 
1133
   }
 
1134
 
 
1135
   DEXIT;
 
1136
   return lp;
 
1137
}
 
1138