2 // customized (for barchart) version of DGclient.C in tclVisi directory
5 /* Revision 1.16 1996/02/23 17:48:06 tamches
8 * Revision 1.15 1996/01/19 20:56:06 newhall
9 * changes due to visiLib interface changes
11 * Revision 1.14 1996/01/17 18:31:14 newhall
12 * changes due to new visiLib
14 * Revision 1.13 1996/01/10 21:11:15 tamches
15 * added METRICAVEUNITS, METRICSUMUNITS
17 * Revision 1.12 1995/11/29 00:40:07 tamches
20 * Revision 1.11 1995/11/17 17:39:32 newhall
21 * changed Dg start command, and call to GetMetsRes
23 * Revision 1.10 1995/11/17 17:32:27 newhall
24 * changed Dg start command to take no arguments, replaced call to MetricUnits
25 * with call to MetricLabel
27 * Revision 1.9 1995/09/22 19:23:41 tamches
28 * removed warnings under g++ 2.7.0
30 * Revision 1.8 1995/08/06 22:11:48 tamches
31 * removed some warnings by using myTclEval
33 * Revision 1.7 1995/02/26 02:01:48 newhall
34 * added callback functions for new visiLib phase info.
36 * Revision 1.6 1994/11/06 10:24:04 tamches
37 * minor cleanups (especially commenting)
39 * Revision 1.5 1994/10/11 21:59:47 tamches
40 * Removed extra StartVisi() bug.
41 * Implemented dataGrid[][].Enabled()
43 * Revision 1.4 1994/10/10 23:08:47 tamches
44 * preliminary changes on the way to swapping the x and y axes
46 * Revision 1.3 1994/10/10 14:36:18 tamches
47 * fixed some resizing bugs
49 * Revision 1.2 1994/09/29 20:05:39 tamches
52 * Revision 1.1 1994/09/29 19:52:25 tamches
53 * initial implementation.
54 * This is a modified version of DGclient.C (tclVisi/src), specially
55 * tuned for the barchart program.
59 // An updated version of DGClient.C for barchart2.C
60 // Contains several **deletions** to remove blt_barchart influences
62 #include <stdlib.h> // exit()
67 #include "tkTools.h" // myTclEval()
70 #include "visi/h/visualization.h"
71 #include "barChartTcl.h"
74 void my_visi_callback(void*, int*, long unsigned int*) {
75 if (visi_callback() == -1)
79 int Dg2AddMetricsCallback(int) {
80 myTclEval(MainInterp, "DgConfigCallback");
82 // if necessary, the tcl program will call xAxisHasChanged and/or
83 // yAxisHasChanged, which are commands we implement in barChart.C.
84 // We take action then.
90 myTclEval(MainInterp, "DgFoldCallback");
94 int Dg2InvalidMetricsOrResources(int) {
95 myTclEval(MainInterp, "DgInvalidCallback");
99 int Dg2PhaseNameCallback(int) {
100 myTclEval(MainInterp, "DgPhaseCallback");
108 #define METRICUNITS 4
109 #define METRICAVEUNITS 5
110 #define METRICSUMUNITS 6
113 #define NUMRESOURCES 9
114 #define RESOURCENAME 10
115 #define STARTSTREAM 11
116 #define STOPSTREAM 12
122 #define LASTBUCKET 18
123 #define FIRSTBUCKET 19
131 static struct cmdTabEntry Dg_Cmds[] = {
132 {"aggregate", AGGREGATE, 2},
133 {"binwidth", BINWIDTH, 0},
134 {"firstbucket", FIRSTBUCKET, 2},
135 {"foldmethod", FOLDMETHOD, 2},
136 {"lastbucket", LASTBUCKET, 2},
137 {"metricname", METRICNAME, 1},
138 {"metricunits", METRICUNITS, 1},
139 {"metricaveunits", METRICAVEUNITS,1},
140 {"metricsumunits", METRICSUMUNITS,1},
141 {"numbins", NUMBINS, 0},
142 {"nummetrics", NUMMETRICS, 0},
143 {"numresources", NUMRESOURCES, 0},
144 {"resourcename", RESOURCENAME, 1},
145 {"start", STARTSTREAM, 2},
146 {"stop", STOPSTREAM, 2},
148 {"valid", DGVALID, 2},
149 {"enabled", DGENABLED, 2},
154 int findCommand(Tcl_Interp *interp,
159 sprintf(interp->result, "USAGE: Dg <option> [args...]\n");
163 for (cmdTabEntry *C = Dg_Cmds; C->cmdname!=NULL; C++) {
164 if (strcmp(argv[0], C->cmdname) == 0) {
165 if (argc-1 == C->numargs)
166 return C->index; // successful parsing
168 sprintf(interp->result,
169 "%s: wrong number of args (%d). Should be %d\n",
170 argv[0], argc-1, C->numargs);
175 sprintf(interp->result, "unknown option (%s)\n", argv[0]);
179 int Dg_TclCommand(ClientData,
181 int argc, char *argv[]) {
182 // entrypoint to the tcl "Dg" command we've installed
183 // all the sprintf()'s are rather slow...
185 // parse the arguments, using global vrble Dg_Cmds[] to tell what's what.
186 int cmdDex = findCommand(interp, argc-1, argv+1);
187 if (cmdDex == CMDERROR)
190 int m, r, buck; // metric number, resource number, bucket number
196 sprintf(interp->result,"%g", visi_AverageValue(m,r));
200 sprintf(interp->result, "%g", visi_BucketWidth());
206 sprintf(interp->result,"%d", visi_FirstValidBucket(m,r));
212 sprintf(interp->result,"%d", visi_LastBucketFilled(m,r));
217 strcpy(interp->result, visi_MetricName(m));
222 strcpy(interp->result, visi_MetricLabel(m));
227 strcpy(interp->result, visi_MetricAveLabel(m));
232 strcpy(interp->result, visi_MetricSumLabel(m));
236 sprintf(interp->result, "%d", visi_NumBuckets());
240 sprintf(interp->result, "%d", visi_NumMetrics());
244 sprintf(interp->result, "%d", visi_NumResources());
249 strcpy(interp->result, visi_ResourceName(r));
253 visi_GetMetsRes(argv[2],0);
259 visi_StopMetRes(m, r);
265 sprintf(interp->result,"%g", visi_SumValue(m,r));
271 sprintf(interp->result, "%d", visi_Valid(m,r));
277 sprintf(interp->result, "%d", visi_Enabled(m,r));
278 // sprintf(interp->result, "%d", Enabled(m,r));
284 buck = atoi(argv[4]);
285 sprintf(interp->result,"%g", visi_DataValue(m,r,buck));
289 sprintf(interp->result, "Internal error (func findCommand)\n");
293 void (*UsersNewDataCallbackRoutine)(int firstBucket, int lastBucket);
294 // we will call this routine for you when we get a new-data callback
295 // from the visi lib (first, we do a bit of processing for you, such
296 // as determining what the range is buckets you haven't seen yet is).
298 int Dg2_Init(Tcl_Interp *interp) {
299 // initialize with the visi lib
300 int fd = visi_Init();
302 cerr << "Dg2_Init() -- could not initialize with the visi lib" << endl;
306 // Register C++ Callback routines with the visi lib when
307 // certain events happen. The most important (performance-wise)
308 // is the DATAVALUES callback, which signals the arrival of
309 // new barchart data. We must process this callback very quickly,
310 // in order to perturb the system as little as possible.
312 if (visi_RegistrationCallback(ADDMETRICSRESOURCES,Dg2AddMetricsCallback)!=0)
313 panic("Dg2_Init() -- couldn't install ADDMETRICSRESOURCES callback");
315 if (visi_RegistrationCallback(FOLD, Dg2Fold) != 0)
316 panic("Dg2_Init() -- couldn't install FOLD callback");
318 if (visi_RegistrationCallback(INVALIDMETRICSRESOURCES, Dg2InvalidMetricsOrResources) != 0)
319 panic("Dg2_Init() -- couldn't install INVALID callback");
321 if (visi_RegistrationCallback(PHASESTART, Dg2PhaseNameCallback) != 0)
322 panic("Dg2_Init() -- couldn't install PHASENAME callback");
324 if (visi_RegistrationCallback(DATAVALUES, Dg2NewDataCallback) != 0)
325 panic("Dg2_Init() -- couldn't install DATAVALUES callback");
327 // install "Dg" as a new tcl command; Dg_TclCommand() will be invoked when
328 // a tcl script calls Dg
329 Tcl_CreateCommand(interp, "Dg", Dg_TclCommand,
330 (ClientData *) NULL,(Tcl_CmdDeleteProc *) NULL);
332 // Arrange for my_visi_callback() to be called whenever data is waiting
333 // to be read off of descriptor "fd". Extremely important! [tcl book
335 Tk_CreateFileHandler(fd, TK_READABLE, (Tk_FileProc *) my_visi_callback, 0);