added newMetricMaxValCallbackCommand
[dyninst.git] / visiClients / barchart / src / barChartDriver.C
1 // barChartDriver.C
2
3 /* $Log: barChartDriver.C,v $
4 /* Revision 1.14  1996/05/15 18:03:15  tamches
5 /* added newMetricMaxValCallbackCommand
6 /*
7  * Revision 1.13  1996/01/11 01:52:53  tamches
8  * added command long2shortFocusName
9  *
10  * Revision 1.12  1996/01/10 02:25:34  tamches
11  * added --xsynch and --debug command-line options
12  * installed getMetricColorNameCommand
13  *
14  * Revision 1.11  1995/12/20 18:37:59  newhall
15  * matherr.h does not need to be included by visis
16  *
17  * Revision 1.10  1995/11/29 00:39:48  tamches
18  * now include tkTools.h, pdLogo.h
19  * Now hardcode the pdLogo
20  *
21  * Revision 1.9  1995/11/08 21:17:12  naim
22  * Adding matherr exception handler function to avoid error message when
23  * computing the "not a number" (NaN) value - naim
24  *
25  * Revision 1.8  1995/11/08  02:17:06  tamches
26  * minor cleanups
27  *
28  * Revision 1.7  1995/09/22 19:25:04  tamches
29  * removed warnings under g++ 2.7.0
30  *
31  * Revision 1.6  1995/08/06  22:11:13  tamches
32  * barChart now uses tcl2c.
33  * Now needs no command-line args.
34  *
35  * Revision 1.5  1995/07/06  18:55:31  tamches
36  * Now contains a main program suitable for tk4.0
37  *
38  * Revision 1.4  1994/10/13  00:52:36  tamches
39  * Minor additions to support a new command related to sorting
40  * of resources
41  *
42  * Revision 1.3  1994/10/10  23:08:43  tamches
43  * preliminary changes on the way to swapping the x and y axes
44  *
45  * Revision 1.2  1994/09/29  20:05:36  tamches
46  * minor cvs fixes
47  *
48  * Revision 1.1  1994/09/29  19:50:51  tamches
49  * initial implementation.
50  * entrypoint for barchart C++ program.  we create new tcl
51  * commands (which will eventually call back to barChartTcl.C
52  * and from there barChart.C) and then launch barChart.tcl.
53  *
54 */
55
56 #include <assert.h>
57 #include <stdlib.h>
58 #include <iostream.h>
59
60 #include "tcl.h"
61 #include "tk.h"
62 #include "tkTools.h"
63
64 #include "pdLogo.h"
65 #include "paradyn/xbm/logo.xbm"
66
67 #include "dg2.h"
68 #include "barChartTcl.h"
69
70 void panic(const char *msg) {
71    cerr << msg << endl;
72    exit(5);
73 }
74
75 Tcl_Interp *MainInterp = NULL; // needed by Dg
76 bool xsynchFlag = false;
77
78 int main(int argc, char **argv) {
79    // Loop through the arguments:
80    for (argc--, argv++; argc > 0; argc--, argv++) {
81       if (0==strcmp(*argv, "--xsynch"))
82          xsynchFlag = true;
83       else if (0==strcmp(*argv, "--debug")) {
84          xsynchFlag = true;
85          cout << "barChart pid " << getpid() << " at sigpause..." << endl;
86          sigpause(0);
87       }
88       else {
89          cerr << "barChart: unrecognized argument \"" << *argv << "\"" << endl;
90          return 5;
91       }
92    }
93
94    // barChart no longer requires any arguments, thanks to tcl2c.
95    if (argc == 2)
96       panic("barChart: argc should be 1");
97
98    MainInterp = Tcl_CreateInterp();
99    assert(MainInterp);
100
101    Tk_Window mainTkWindow = Tk_CreateMainWindow(MainInterp, NULL,
102                                                 "barChart",
103                                                 "BarChart");
104    if (mainTkWindow == NULL)
105       tclpanic(MainInterp, "Could not Tk_CreateMainWindow()");
106
107    if (TCL_OK != Tcl_Init(MainInterp))
108       tclpanic(MainInterp, "Could not Tcl_Init()");
109
110    if (TCL_OK != Tk_Init(MainInterp))
111       tclpanic(MainInterp, "Could not Tk_Init");
112
113    if (TCL_OK != Dg2_Init(MainInterp))
114       tclpanic(MainInterp, "Could not Dg2_Init()");
115
116    Tcl_SetVar(MainInterp, "tcl_interactive", "0", TCL_GLOBAL_ONLY);
117
118    // Install our new tcl commands
119    Tcl_CreateCommand(MainInterp, "resizeCallback", resizeCallbackCommand,
120                      NULL, // ClientData
121                      deleteDummyProc);
122
123    Tcl_CreateCommand(MainInterp, "exposeCallback", exposeCallbackCommand,
124                      NULL, // ClientData
125                      deleteDummyProc);
126
127    Tcl_CreateCommand(MainInterp, "resourcesAxisHasChanged",
128                      resourcesAxisHasChangedCommand,
129                      NULL, // ClientData
130                      deleteDummyProc);
131
132    Tcl_CreateCommand(MainInterp, "metricsAxisHasChanged", metricsAxisHasChangedCommand,
133                      NULL, // ClientData
134                      deleteDummyProc);
135
136    Tcl_CreateCommand(MainInterp, "newScrollPosition", newScrollPositionCommand,
137                      NULL, // ClientData
138                      deleteDummyProc);
139
140    Tcl_CreateCommand(MainInterp, "dataFormatHasChanged", dataFormatHasChangedCommand,
141                      NULL, // ClientData
142                      deleteDummyProc);
143
144    Tcl_CreateCommand(MainInterp, "rethinkIndirectResourcesCallback",
145                      rethinkIndirectResourcesCommand,
146                      NULL, // ClientData
147                      deleteDummyProc);
148
149    Tcl_CreateCommand(MainInterp, "getMetricColorName",
150                      getMetricColorNameCommand,
151                      NULL, // ClientData
152                      deleteDummyProc);
153
154    Tcl_CreateCommand(MainInterp, "long2shortFocusName", long2shortFocusNameCommand,
155                      NULL, // ClientData
156                      deleteDummyProc);
157
158    Tcl_CreateCommand(MainInterp, "newMetricMaxValCallback", newMetricMaxValCallbackCommand,
159                      NULL, // ClientData
160                      deleteDummyProc);
161
162    Tcl_CreateCommand(MainInterp, "launchBarChart", launchBarChartCommand,
163                      NULL, // ClientData
164                      deleteLaunchBarChartCommand);
165
166    // Krishna's tcl2c stuff gets loaded here:
167    // (initialize_tcl_sources() was auto-generated by 'tcl2c')
168    extern int initialize_tcl_sources(Tcl_Interp *);
169    if (TCL_OK != initialize_tcl_sources(MainInterp))
170       tclpanic(MainInterp, "barChart: could not initialize_tcl_sources");
171
172 //if (TCL_OK != Tcl_EvalFile(MainInterp, "/p/paradyn/development/tamches/core/visiClients/barchart/barChart.tcl"))
173 //   tclpanic(MainInterp, "could not source barChart.tcl manually");
174
175    pdLogo::install_fixed_logo("paradynLogo", logo_bits, logo_width, logo_height);
176    tcl_cmd_installer createPdLogo(MainInterp, "makeLogo",
177                                   pdLogo::makeLogoCommand,
178                                   (ClientData)mainTkWindow);
179
180    myTclEval(MainInterp, "init_barchart_window");
181    myTclEval(MainInterp, "Initialize");
182
183    Tk_MainLoop(); // returns when all tk windows are closed
184
185    // shouldn't we be doing some cleanup here?
186 }