2 // customized (for barchart) version of DGclient.C in tclVisi directory
5 /* Revision 1.12 1995/11/29 00:40:07 tamches
8 * Revision 1.11 1995/11/17 17:39:32 newhall
9 * changed Dg start command, and call to GetMetsRes
11 * Revision 1.10 1995/11/17 17:32:27 newhall
12 * changed Dg start command to take no arguments, replaced call to MetricUnits
13 * with call to MetricLabel
15 * Revision 1.9 1995/09/22 19:23:41 tamches
16 * removed warnings under g++ 2.7.0
18 * Revision 1.8 1995/08/06 22:11:48 tamches
19 * removed some warnings by using myTclEval
21 * Revision 1.7 1995/02/26 02:01:48 newhall
22 * added callback functions for new visiLib phase info.
24 * Revision 1.6 1994/11/06 10:24:04 tamches
25 * minor cleanups (especially commenting)
27 * Revision 1.5 1994/10/11 21:59:47 tamches
28 * Removed extra StartVisi() bug.
29 * Implemented dataGrid[][].Enabled()
31 * Revision 1.4 1994/10/10 23:08:47 tamches
32 * preliminary changes on the way to swapping the x and y axes
34 * Revision 1.3 1994/10/10 14:36:18 tamches
35 * fixed some resizing bugs
37 * Revision 1.2 1994/09/29 20:05:39 tamches
40 * Revision 1.1 1994/09/29 19:52:25 tamches
41 * initial implementation.
42 * This is a modified version of DGclient.C (tclVisi/src), specially
43 * tuned for the barchart program.
47 // An updated version of DGClient.C for barchart2.C
48 // Contains several **deletions** to remove blt_barchart influences
50 #include <stdlib.h> // exit()
55 #include "tkTools.h" // myTclEval()
58 #include "visi/h/visualization.h"
59 #include "barChartTcl.h"
62 void my_visi_callback(void*, int*, long unsigned int*) {
63 if (visi_callback() == -1)
67 //void myTclEval(Tcl_Interp *interp, const char *cmd) {
68 // if (TCL_OK != Tcl_Eval(interp, cmd)) {
69 // cerr << interp->result << endl;
74 int Dg2AddMetricsCallback(int) {
75 myTclEval(MainInterp, "DgConfigCallback");
77 // if necessary, the tcl program will call xAxisHasChanged and/or
78 // yAxisHasChanged, which are commands we implement in barChart.C.
79 // We take action then.
85 myTclEval(MainInterp, "DgFoldCallback");
89 int Dg2InvalidMetricsOrResources(int) {
90 myTclEval(MainInterp, "DgInvalidCallback");
94 int Dg2PhaseNameCallback(int) {
95 myTclEval(MainInterp, "DgPhaseCallback");
103 #define METRICUNITS 4
106 #define NUMRESOURCES 7
107 #define DEFINEPHASE 8
108 #define RESOURCENAME 9
109 #define STARTSTREAM 10
110 #define STOPSTREAM 11
116 #define LASTBUCKET 17
117 #define FIRSTBUCKET 18
125 static struct cmdTabEntry Dg_Cmds[] = {
126 {"aggregate", AGGREGATE, 2},
127 {"binwidth", BINWIDTH, 0},
128 {"firstbucket", FIRSTBUCKET, 2},
129 {"foldmethod", FOLDMETHOD, 2},
130 {"lastbucket", LASTBUCKET, 2},
131 {"metricname", METRICNAME, 1},
132 {"metricunits", METRICUNITS, 1},
133 {"numbins", NUMBINS, 0},
134 {"nummetrics", NUMMETRICS, 0},
135 {"numresources", NUMRESOURCES, 0},
136 {"phase", DEFINEPHASE, 3},
137 {"resourcename", RESOURCENAME, 1},
138 {"start", STARTSTREAM, 0},
139 {"stop", STOPSTREAM, 2},
141 {"valid", DGVALID, 2},
142 {"enabled", DGENABLED, 2},
147 int findCommand(Tcl_Interp *interp,
152 sprintf(interp->result, "USAGE: Dg <option> [args...]\n");
156 for (cmdTabEntry *C = Dg_Cmds; C->cmdname!=NULL; C++) {
157 if (strcmp(argv[0], C->cmdname) == 0) {
158 if (argc-1 == C->numargs)
159 return C->index; // successful parsing
161 sprintf(interp->result,
162 "%s: wrong number of args (%d). Should be %d\n",
163 argv[0], argc-1, C->numargs);
168 sprintf(interp->result, "unknown option (%s)\n", argv[0]);
172 int Dg_TclCommand(ClientData,
174 int argc, char *argv[]) {
175 // entrypoint to the tcl "Dg" command we've installed
176 // all the sprintf()'s are rather slow...
178 // parse the arguments, using global vrble Dg_Cmds[] to tell what's what.
179 int cmdDex = findCommand(interp, argc-1, argv+1);
180 if (cmdDex == CMDERROR)
183 int m, r, buck; // metric number, resource number, bucket number
189 sprintf(interp->result,"%g", dataGrid.AggregateValue(m,r));
193 sprintf(interp->result, "%g", dataGrid.BinWidth());
199 sprintf(interp->result,"%d", dataGrid[m][r].FirstValidBucket());
204 sprintf(interp->result,"%d", dataGrid.FoldMethod(m));
210 sprintf(interp->result,"%d", dataGrid[m][r].LastBucketFilled());
215 sprintf(interp->result, "%s", dataGrid.MetricName(m));
220 sprintf(interp->result, "%s", dataGrid.MetricLabel(m));
224 sprintf(interp->result, "%d", dataGrid.NumBins());
228 sprintf(interp->result, "%d", dataGrid.NumMetrics());
232 sprintf(interp->result, "%d", dataGrid.NumResources());
236 DefinePhase(-1.0,NULL);
241 sprintf(interp->result, "%s", dataGrid.ResourceName(r));
257 sprintf(interp->result,"%g", dataGrid.SumValue(m,r));
263 sprintf(interp->result, "%d", dataGrid.Valid(m,r));
269 sprintf(interp->result, "%d", dataGrid[m][r].Enabled());
270 // sprintf(interp->result, "%d", dataGrid.Enabled(m,r));
276 buck = atoi(argv[4]);
277 sprintf(interp->result,"%g", dataGrid[m][r].Value(buck));
281 sprintf(interp->result, "Internal error (func findCommand)\n");
285 void (*UsersNewDataCallbackRoutine)(int firstBucket, int lastBucket);
286 // we will call this routine for you when we get a new-data callback
287 // from the visi lib (first, we do a bit of processing for you, such
288 // as determining what the range is buckets you haven't seen yet is).
290 int Dg2_Init(Tcl_Interp *interp) {
291 // initialize with the visi lib
294 cerr << "Dg2_Init() -- could not initialize with the visi lib" << endl;
298 // Register C++ Callback routines with the visi lib when
299 // certain events happen. The most important (performance-wise)
300 // is the DATAVALUES callback, which signals the arrival of
301 // new barchart data. We must process this callback very quickly,
302 // in order to perturb the system as little as possible.
304 if (RegistrationCallback(ADDMETRICSRESOURCES, Dg2AddMetricsCallback) != 0)
305 panic("Dg2_Init() -- couldn't install ADDMETRICSRESOURCES callback");
307 if (RegistrationCallback(FOLD, Dg2Fold) != 0)
308 panic("Dg2_Init() -- couldn't install FOLD callback");
310 if (RegistrationCallback(INVALIDMETRICSRESOURCES, Dg2InvalidMetricsOrResources) != 0)
311 panic("Dg2_Init() -- couldn't install INVALID callback");
313 if (RegistrationCallback(PHASESTART, Dg2PhaseNameCallback) != 0)
314 panic("Dg2_Init() -- couldn't install PHASENAME callback");
316 if (RegistrationCallback(DATAVALUES, Dg2NewDataCallback) != 0)
317 panic("Dg2_Init() -- couldn't install DATAVALUES callback");
319 // install "Dg" as a new tcl command; Dg_TclCommand() will be invoked when
320 // a tcl script calls Dg
321 Tcl_CreateCommand(interp, "Dg", Dg_TclCommand,
322 (ClientData *) NULL,(Tcl_CmdDeleteProc *) NULL);
324 // Arrange for my_visi_callback() to be called whenever data is waiting
325 // to be read off of descriptor "fd". Extremely important! [tcl book
327 Tk_CreateFileHandler(fd, TK_READABLE, (Tk_FileProc *) my_visi_callback, 0);