2 // customized (for barchart) version of DGclient.C in tclVisi directory
5 /* Revision 1.15 1996/01/19 20:56:06 newhall
6 /* changes due to visiLib interface changes
8 * Revision 1.14 1996/01/17 18:31:14 newhall
9 * changes due to new visiLib
11 * Revision 1.13 1996/01/10 21:11:15 tamches
12 * added METRICAVEUNITS, METRICSUMUNITS
14 * Revision 1.12 1995/11/29 00:40:07 tamches
17 * Revision 1.11 1995/11/17 17:39:32 newhall
18 * changed Dg start command, and call to GetMetsRes
20 * Revision 1.10 1995/11/17 17:32:27 newhall
21 * changed Dg start command to take no arguments, replaced call to MetricUnits
22 * with call to MetricLabel
24 * Revision 1.9 1995/09/22 19:23:41 tamches
25 * removed warnings under g++ 2.7.0
27 * Revision 1.8 1995/08/06 22:11:48 tamches
28 * removed some warnings by using myTclEval
30 * Revision 1.7 1995/02/26 02:01:48 newhall
31 * added callback functions for new visiLib phase info.
33 * Revision 1.6 1994/11/06 10:24:04 tamches
34 * minor cleanups (especially commenting)
36 * Revision 1.5 1994/10/11 21:59:47 tamches
37 * Removed extra StartVisi() bug.
38 * Implemented dataGrid[][].Enabled()
40 * Revision 1.4 1994/10/10 23:08:47 tamches
41 * preliminary changes on the way to swapping the x and y axes
43 * Revision 1.3 1994/10/10 14:36:18 tamches
44 * fixed some resizing bugs
46 * Revision 1.2 1994/09/29 20:05:39 tamches
49 * Revision 1.1 1994/09/29 19:52:25 tamches
50 * initial implementation.
51 * This is a modified version of DGclient.C (tclVisi/src), specially
52 * tuned for the barchart program.
56 // An updated version of DGClient.C for barchart2.C
57 // Contains several **deletions** to remove blt_barchart influences
59 #include <stdlib.h> // exit()
64 #include "tkTools.h" // myTclEval()
67 #include "visi/h/visualization.h"
68 #include "barChartTcl.h"
71 void my_visi_callback(void*, int*, long unsigned int*) {
72 if (visi_callback() == -1)
76 int Dg2AddMetricsCallback(int) {
77 myTclEval(MainInterp, "DgConfigCallback");
79 // if necessary, the tcl program will call xAxisHasChanged and/or
80 // yAxisHasChanged, which are commands we implement in barChart.C.
81 // We take action then.
87 myTclEval(MainInterp, "DgFoldCallback");
91 int Dg2InvalidMetricsOrResources(int) {
92 myTclEval(MainInterp, "DgInvalidCallback");
96 int Dg2PhaseNameCallback(int) {
97 myTclEval(MainInterp, "DgPhaseCallback");
105 #define METRICUNITS 4
106 #define METRICAVEUNITS 5
107 #define METRICSUMUNITS 6
110 #define NUMRESOURCES 9
111 #define DEFINEPHASE 10
112 #define RESOURCENAME 11
113 #define STARTSTREAM 12
114 #define STOPSTREAM 13
120 #define LASTBUCKET 19
121 #define FIRSTBUCKET 20
129 static struct cmdTabEntry Dg_Cmds[] = {
130 {"aggregate", AGGREGATE, 2},
131 {"binwidth", BINWIDTH, 0},
132 {"firstbucket", FIRSTBUCKET, 2},
133 {"foldmethod", FOLDMETHOD, 2},
134 {"lastbucket", LASTBUCKET, 2},
135 {"metricname", METRICNAME, 1},
136 {"metricunits", METRICUNITS, 1},
137 {"metricaveunits", METRICAVEUNITS,1},
138 {"metricsumunits", METRICSUMUNITS,1},
139 {"numbins", NUMBINS, 0},
140 {"nummetrics", NUMMETRICS, 0},
141 {"numresources", NUMRESOURCES, 0},
142 {"phase", DEFINEPHASE, 3},
143 {"resourcename", RESOURCENAME, 1},
144 {"start", STARTSTREAM, 2},
145 {"stop", STOPSTREAM, 2},
147 {"valid", DGVALID, 2},
148 {"enabled", DGENABLED, 2},
153 int findCommand(Tcl_Interp *interp,
158 sprintf(interp->result, "USAGE: Dg <option> [args...]\n");
162 for (cmdTabEntry *C = Dg_Cmds; C->cmdname!=NULL; C++) {
163 if (strcmp(argv[0], C->cmdname) == 0) {
164 if (argc-1 == C->numargs)
165 return C->index; // successful parsing
167 sprintf(interp->result,
168 "%s: wrong number of args (%d). Should be %d\n",
169 argv[0], argc-1, C->numargs);
174 sprintf(interp->result, "unknown option (%s)\n", argv[0]);
178 int Dg_TclCommand(ClientData,
180 int argc, char *argv[]) {
181 // entrypoint to the tcl "Dg" command we've installed
182 // all the sprintf()'s are rather slow...
184 // parse the arguments, using global vrble Dg_Cmds[] to tell what's what.
185 int cmdDex = findCommand(interp, argc-1, argv+1);
186 if (cmdDex == CMDERROR)
189 int m, r, buck; // metric number, resource number, bucket number
195 sprintf(interp->result,"%g", visi_AverageValue(m,r));
199 sprintf(interp->result, "%g", visi_BucketWidth());
205 sprintf(interp->result,"%d", visi_FirstValidBucket(m,r));
211 sprintf(interp->result,"%d", visi_LastBucketFilled(m,r));
216 strcpy(interp->result, visi_MetricName(m));
221 strcpy(interp->result, visi_MetricLabel(m));
226 strcpy(interp->result, visi_MetricAveLabel(m));
231 strcpy(interp->result, visi_MetricSumLabel(m));
235 sprintf(interp->result, "%d", visi_NumBuckets());
239 sprintf(interp->result, "%d", visi_NumMetrics());
243 sprintf(interp->result, "%d", visi_NumResources());
247 visi_DefinePhase(NULL);
252 strcpy(interp->result, visi_ResourceName(r));
256 visi_GetMetsRes(argv[2],0);
262 visi_StopMetRes(m, r);
268 sprintf(interp->result,"%g", visi_SumValue(m,r));
274 sprintf(interp->result, "%d", visi_Valid(m,r));
280 sprintf(interp->result, "%d", visi_Enabled(m,r));
281 // sprintf(interp->result, "%d", Enabled(m,r));
287 buck = atoi(argv[4]);
288 sprintf(interp->result,"%g", visi_DataValue(m,r,buck));
292 sprintf(interp->result, "Internal error (func findCommand)\n");
296 void (*UsersNewDataCallbackRoutine)(int firstBucket, int lastBucket);
297 // we will call this routine for you when we get a new-data callback
298 // from the visi lib (first, we do a bit of processing for you, such
299 // as determining what the range is buckets you haven't seen yet is).
301 int Dg2_Init(Tcl_Interp *interp) {
302 // initialize with the visi lib
303 int fd = visi_Init();
305 cerr << "Dg2_Init() -- could not initialize with the visi lib" << endl;
309 // Register C++ Callback routines with the visi lib when
310 // certain events happen. The most important (performance-wise)
311 // is the DATAVALUES callback, which signals the arrival of
312 // new barchart data. We must process this callback very quickly,
313 // in order to perturb the system as little as possible.
315 if (visi_RegistrationCallback(ADDMETRICSRESOURCES,Dg2AddMetricsCallback)!=0)
316 panic("Dg2_Init() -- couldn't install ADDMETRICSRESOURCES callback");
318 if (visi_RegistrationCallback(FOLD, Dg2Fold) != 0)
319 panic("Dg2_Init() -- couldn't install FOLD callback");
321 if (visi_RegistrationCallback(INVALIDMETRICSRESOURCES, Dg2InvalidMetricsOrResources) != 0)
322 panic("Dg2_Init() -- couldn't install INVALID callback");
324 if (visi_RegistrationCallback(PHASESTART, Dg2PhaseNameCallback) != 0)
325 panic("Dg2_Init() -- couldn't install PHASENAME callback");
327 if (visi_RegistrationCallback(DATAVALUES, Dg2NewDataCallback) != 0)
328 panic("Dg2_Init() -- couldn't install DATAVALUES callback");
330 // install "Dg" as a new tcl command; Dg_TclCommand() will be invoked when
331 // a tcl script calls Dg
332 Tcl_CreateCommand(interp, "Dg", Dg_TclCommand,
333 (ClientData *) NULL,(Tcl_CmdDeleteProc *) NULL);
335 // Arrange for my_visi_callback() to be called whenever data is waiting
336 // to be read off of descriptor "fd". Extremely important! [tcl book
338 Tk_CreateFileHandler(fd, TK_READABLE, (Tk_FileProc *) my_visi_callback, 0);