From 8740771506ad4a1c068292dd959f20a08a9493a5 Mon Sep 17 00:00:00 2001 From: newhall Date: Fri, 11 Mar 1994 19:56:10 +0000 Subject: [PATCH] test routines for visi library --- visi/test/Makefile | 140 +++++++++++++++ visi/test/README | 97 +++++++++++ visi/test/client1.C | 204 ++++++++++++++++++++++ visi/test/sample.input.client | 116 +++++++++++++ visi/test/server1.C | 133 +++++++++++++++ visi/test/xtext.C | 382 +++++++++++++++++++++++++++++++++++++++++ visi/test/xtext2.C | 387 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 1459 insertions(+) create mode 100644 visi/test/Makefile create mode 100644 visi/test/README create mode 100644 visi/test/client1.C create mode 100644 visi/test/sample.input.client create mode 100644 visi/test/server1.C create mode 100644 visi/test/xtext.C create mode 100644 visi/test/xtext2.C diff --git a/visi/test/Makefile b/visi/test/Makefile new file mode 100644 index 0000000..b7cc1a4 --- /dev/null +++ b/visi/test/Makefile @@ -0,0 +1,140 @@ + +include ../../make.config + +CFLAGS += -I./util/h -I../sparc-sun-sunos4.1.3 +CC = /usr/psup/bin/g++ +AS = /bin/as + +VPATH = ../src +LIBRARY = visilib.a + +SRVROBJ = server1.o + +CLNTOBJS = client1.o + +OBJS = client1.o server1.o xtext.o xtext2.o + +SRCS = client1.C server1.C xtext.C xtext.C + +PRINT = pr + +all: client1 server1 xtext xtext2 + + + +server1: $(SRVROBJ) + /usr/sup/purify/purify -g++ -collector=/usr/sup/purify/collect2 $(CC) -static $(CFLAGS) $(LIBDIR) -o server1 $(SRVROBJ) -lm $(LIBDIR) -lutil -lvisi + +client1: $(CLNTOBJS) + /usr/sup/purify/purify -g++ -collector=/usr/sup/purify/collect2 $(CC) -static $(CFLAGS) $(LIBDIR) -o client1 $(CLNTOBJS) -lm $(LIBDIR) -lutil -lvisi + +xtext: xtext.o + $(CC) xtext.o -o xtext -lXaw -lXmu -lXt -lX11 -lm $(LIBDIR) -lutil -lvisi + +xtext2: xtext2.o + $(CC) xtext2.o -o xtext2 -lXaw -lXmu -lXt -lX11 -lm $(LIBDIR) -lutil -lvisi + + +clean: + rm -f $(OBJS) server1 client1 xtext xtext2 *pure* + +depend: $(SRCS) + @echo "Building dependancies" + /usr/sup/X11/bin/makedepend $(SRCS) $(CFLAGS) + +library: $(LIBRARY) + +tags: $(HDRS) $(SRCS); @ctags $(HDRS) $(SRCS) + +update: $(DEST)/$(LIBRARY) + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +client1.o: ../src/visithread.h ../sparc-sun-sunos4.1.3/visi.CLNT.h +client1.o: ../sparc-sun-sunos4.1.3/visi.h ../../util/h/rpcUtil.h +client1.o: /usr/include/stdio.h /usr/include/strings.h /usr/include/string.h +client1.o: /usr/include/sys/stdtypes.h /usr/include/stdlib.h +client1.o: /usr/include/errno.h /usr/include/sys/errno.h +client1.o: /usr/include/assert.h /usr/include/fcntl.h +client1.o: /usr/include/sys/fcntlcom.h /usr/include/sys/stat.h +client1.o: /usr/include/sys/types.h /usr/include/sys/sysmacros.h +client1.o: /usr/include/memory.h /usr/include/sys/socket.h +client1.o: /usr/include/netinet/in.h /usr/include/netdb.h +client1.o: /usr/include/sys/time.h /usr/include/sys/time.h +client1.o: /usr/include/unistd.h /usr/include/sys/file.h +client1.o: /usr/include/rpc/types.h /usr/include/malloc.h +client1.o: /usr/include/rpc/xdr.h +server1.o: ../src/visualization.h ../src/datagrid.h /usr/include/string.h +server1.o: /usr/include/sys/stdtypes.h /usr/include/math.h +server1.o: /usr/include/floatingpoint.h /usr/include/sys/ieeefp.h +server1.o: /usr/include/values.h ../src/error.h /usr/include/stdio.h +server1.o: ../sparc-sun-sunos4.1.3/visi.h ../../util/h/rpcUtil.h +server1.o: /usr/include/strings.h /usr/include/stdlib.h /usr/include/errno.h +server1.o: /usr/include/sys/errno.h /usr/include/assert.h +server1.o: /usr/include/fcntl.h /usr/include/sys/fcntlcom.h +server1.o: /usr/include/sys/stat.h /usr/include/sys/types.h +server1.o: /usr/include/sys/sysmacros.h /usr/include/memory.h +server1.o: /usr/include/sys/socket.h /usr/include/netinet/in.h +server1.o: /usr/include/netdb.h /usr/include/sys/time.h +server1.o: /usr/include/sys/time.h /usr/include/unistd.h +server1.o: /usr/include/sys/file.h /usr/include/rpc/types.h +server1.o: /usr/include/malloc.h /usr/include/rpc/xdr.h ../src/mrlist.h +server1.o: ../sparc-sun-sunos4.1.3/visi.SRVR.h +xtext.o: /usr/include/stdio.h /usr/include/X11/Intrinsic.h +xtext.o: /usr/include/X11/Xlib.h /usr/include/sys/types.h +xtext.o: /usr/include/sys/stdtypes.h /usr/include/sys/sysmacros.h +xtext.o: /usr/include/X11/X.h /usr/include/X11/Xfuncproto.h +xtext.o: /usr/include/X11/Xosdefs.h /usr/include/stddef.h +xtext.o: /usr/include/X11/Xutil.h /usr/include/X11/Xresource.h +xtext.o: /usr/include/string.h /usr/include/X11/Core.h +xtext.o: /usr/include/X11/Composite.h /usr/include/X11/Constraint.h +xtext.o: /usr/include/X11/Object.h /usr/include/X11/RectObj.h +xtext.o: /usr/include/X11/StringDefs.h /usr/include/X11/Xaw/AsciiText.h +xtext.o: /usr/include/X11/Xaw/Text.h /usr/include/X11/Xaw/TextSink.h +xtext.o: /usr/include/X11/Xaw/TextSrc.h /usr/include/X11/Xaw/AsciiSrc.h +xtext.o: /usr/include/X11/Xaw/AsciiSink.h /usr/include/X11/Xaw/Command.h +xtext.o: /usr/include/X11/Xaw/Label.h /usr/include/X11/Xaw/Simple.h +xtext.o: /usr/include/X11/Xmu/Converters.h /usr/include/X11/Xaw/Paned.h +xtext.o: /usr/include/X11/Xaw/Cardinals.h ../src/visualization.h +xtext.o: ../src/datagrid.h /usr/include/math.h /usr/include/floatingpoint.h +xtext.o: /usr/include/sys/ieeefp.h /usr/include/values.h ../src/error.h +xtext.o: ../sparc-sun-sunos4.1.3/visi.h ../../util/h/rpcUtil.h +xtext.o: /usr/include/strings.h /usr/include/stdlib.h /usr/include/errno.h +xtext.o: /usr/include/sys/errno.h /usr/include/assert.h /usr/include/fcntl.h +xtext.o: /usr/include/sys/fcntlcom.h /usr/include/sys/stat.h +xtext.o: /usr/include/memory.h /usr/include/sys/socket.h +xtext.o: /usr/include/netinet/in.h /usr/include/netdb.h +xtext.o: /usr/include/sys/time.h /usr/include/sys/time.h +xtext.o: /usr/include/unistd.h /usr/include/sys/file.h +xtext.o: /usr/include/rpc/types.h /usr/include/malloc.h +xtext.o: /usr/include/rpc/xdr.h ../src/mrlist.h +xtext.o: ../sparc-sun-sunos4.1.3/visi.SRVR.h +xtext.o: /usr/include/stdio.h /usr/include/X11/Intrinsic.h +xtext.o: /usr/include/X11/Xlib.h /usr/include/sys/types.h +xtext.o: /usr/include/sys/stdtypes.h /usr/include/sys/sysmacros.h +xtext.o: /usr/include/X11/X.h /usr/include/X11/Xfuncproto.h +xtext.o: /usr/include/X11/Xosdefs.h /usr/include/stddef.h +xtext.o: /usr/include/X11/Xutil.h /usr/include/X11/Xresource.h +xtext.o: /usr/include/string.h /usr/include/X11/Core.h +xtext.o: /usr/include/X11/Composite.h /usr/include/X11/Constraint.h +xtext.o: /usr/include/X11/Object.h /usr/include/X11/RectObj.h +xtext.o: /usr/include/X11/StringDefs.h /usr/include/X11/Xaw/AsciiText.h +xtext.o: /usr/include/X11/Xaw/Text.h /usr/include/X11/Xaw/TextSink.h +xtext.o: /usr/include/X11/Xaw/TextSrc.h /usr/include/X11/Xaw/AsciiSrc.h +xtext.o: /usr/include/X11/Xaw/AsciiSink.h /usr/include/X11/Xaw/Command.h +xtext.o: /usr/include/X11/Xaw/Label.h /usr/include/X11/Xaw/Simple.h +xtext.o: /usr/include/X11/Xmu/Converters.h /usr/include/X11/Xaw/Paned.h +xtext.o: /usr/include/X11/Xaw/Cardinals.h ../src/visualization.h +xtext.o: ../src/datagrid.h /usr/include/math.h /usr/include/floatingpoint.h +xtext.o: /usr/include/sys/ieeefp.h /usr/include/values.h ../src/error.h +xtext.o: ../sparc-sun-sunos4.1.3/visi.h ../../util/h/rpcUtil.h +xtext.o: /usr/include/strings.h /usr/include/stdlib.h /usr/include/errno.h +xtext.o: /usr/include/sys/errno.h /usr/include/assert.h /usr/include/fcntl.h +xtext.o: /usr/include/sys/fcntlcom.h /usr/include/sys/stat.h +xtext.o: /usr/include/memory.h /usr/include/sys/socket.h +xtext.o: /usr/include/netinet/in.h /usr/include/netdb.h +xtext.o: /usr/include/sys/time.h /usr/include/sys/time.h +xtext.o: /usr/include/unistd.h /usr/include/sys/file.h +xtext.o: /usr/include/rpc/types.h /usr/include/malloc.h +xtext.o: /usr/include/rpc/xdr.h ../src/mrlist.h +xtext.o: ../sparc-sun-sunos4.1.3/visi.SRVR.h diff --git a/visi/test/README b/visi/test/README new file mode 100644 index 0000000..29940b9 --- /dev/null +++ b/visi/test/README @@ -0,0 +1,97 @@ +directions to incorporate a visualization (an example is in xtext.C) +----------------------------------------- +in main(): +--------- +(1) call visiInit() + +(2) register callback routines associated with certain Paradyn events + by calling RegistrationCallback(): these are routines written by the + visualization writer to be called by the visi_callback routine when + the specified event occurs. + the event types (type msgTag) are defined in ../src/error.h + + Most of the work involved in integrating the visualization has to + do with writing these callback routines. In most cases this will + involve changing a callback routine in the X application that initially + read data from a file descriptor, to get data from the interface's + data structures: in most cases this involves invoking dataGrid method + functions. An example of a change to an existing call back routine + is the function "fd_input" in xtext.C. + + dataGrid method functions are defined in ~paradyn/core/visi/src/datagrid.h + visualization interface routines and global variables are in + ~paradyn/core/visi/src/visualization.[Ch] + +(3) optional: call StartVisi(argc,argv) with the args to main(): each + visualization is started with two command line arguments--a metric + list and a resource list. For visualizations that do not invoke + the upcalls provided by the visi interface this is the only opportunity + to start data collection. + + Steps 3a and 3b: for handling upcalls to Paradyn side: + ------------------------------------------------------ +(3a) create a widget associated with the upcall +(3b) use XtAddCallback to register your handler routine for events assoc. + with this widget + +(4) register the paradyn file descriptor (returned by VisiInit) and + the paradyn callback routine "visi_callback" with the appropriate + add application routine. (ie. for Xt use XtAddApp) + +(5) call Xt main loop + + + +interface test programs +----------------------- + + client1: is a pseudo visi-thread program + it has one command line argument which is a visualization to fork + the client forks a server process + + to run client1 with xtext2: client1 xtext2 + to run client1 with xtext: client1 xtext + to run client1 with server1: client1 server1 m r + + client1 is an interactive test + sample input for each option is in file "sample.input.client" + + server and client both print output to stderr + server's output is prefaced by @@@@ + upcall output from server to client is preface by ## + + a typical session starts with choosing "add m/r" option, followed + by the "data values" option to add send some initial data values + + at this point the upcalls are not completely implemented--the call + is made, and a msg that it is made is printed to stderr, but no + action is invoked on the client side + + also, options 4, 5 are not fully implemented and option 3 is only + implemented for the initial metric and resource case--adding additional + metrics and resources to an existing data grid is not supported + + option 6 is only useful for the server1 test program as a way to get + the server process to print datagrid values to stderr (for test programs + xtext and xtext2 datagrid values are printed to window as a result + of choosing fold and data values options) + +xtext +----- + xtext includes examples of adding callbacks to the Paradyn handler for + certain Paradyn events (DATAVALUES,FOLD,ADDMETRICSRESROURCES). Also, + it includes an example of adding an upcall to Paradyn by creating a widget + which will invoke an upcall to Paradyn (ex. GetMetricsResources) + + code that was added to the original xtext application to add it to Paradyn + is surrounded by "///////////////////////////////" in xtext.C + +xtext2 +------ + is an extention to xtext that includes callbacks for all Paradyn events + and upcalls. + +server1 +------- + is a psuedo x application the tests all calls and upcalls in the + visualization--Paradyn interface diff --git a/visi/test/client1.C b/visi/test/client1.C new file mode 100644 index 0000000..04bd8a9 --- /dev/null +++ b/visi/test/client1.C @@ -0,0 +1,204 @@ +#include "../src/visithread.h" + +#define TESTMETRIC "blah,blah blah,metric 3,metric 4,last metric" +#define TESTRESOURCE "resource1/blah1/foo1,resource2/foo2,resource3" + + +main(int argc,char *argv[]){ + +int i=0; +int fd,pid; +visualizationUser *vup; +char **arg_list; +char temp[128], temp2[128]; +int wch; + +int done; +metricType *metrics; +metricType_Array mets; +resourceType *resources; +resourceType_Array res; +dataValue *data; +dataValue_Array blah; +int mId,rId,bNum,bWidth,nval; +float num,num2; +int nMets,nRes; + + + if(argc < 2){ + fprintf(stdout,"incorrect num arguments: client1 server_executable\n"); + exit(-1); + } + fprintf(stderr,"in client\n"); + arg_list = new char*[argc+1]; + arg_list[i++] = strdup(argv[1]); + if(argc > 2){ + sprintf(temp,"%s",TESTMETRIC); + arg_list[i++] = strdup(temp); + sprintf(temp,"%s",TESTRESOURCE); + arg_list[i++] = strdup(temp); + } + arg_list[i++] = 0; + + + fprintf(stderr,"in client before RPCprocessCreate\n"); + fd = RPCprocessCreate(&pid, "localhost", "", argv[1],arg_list); + if (fd < 0) { + perror("process Create"); + exit(-1); + } + + + fprintf(stderr,"in client before new visualizationUser\n"); + vup = new visualizationUser(fd,NULL,NULL); + + fprintf(stderr,"in client before while loop\n"); + done = 0; + while(!done){ + + // check for upcall + // these don't do anything yet + if(RPC_readReady(fd)) + vup->awaitResponce(-1); + + wch = -1; + while((wch < 0) || (wch > 7)){ + fprintf(stdout,"\n---------------------------------------------\n"); + fprintf(stdout,"enter number of operation to perform:\n"); + fprintf(stdout,"---------------------------------------------\n"); + fprintf(stdout,"0:data values 1:fold 2:invalid m/r 3:add m/r\n"); + fprintf(stdout,"4:new m/r 5:phase 6:print 7:quit\n"); + fprintf(stdout,"---------------------------------------------\n\n"); + scanf("%d",&wch); + } + switch(wch){ + case 0: + fprintf(stdout,"\nSend Data values to server process:\n"); + fprintf(stdout,"enter number of dataValues\n"); + scanf("%d",&nval); + data = (dataValue *)malloc(sizeof(dataValue)*nval); + for(i=0;iData(blah); + free(data); + break; + case 1: + fprintf(stdout,"\nFold:\n"); + fprintf(stdout,"enter new bucket width value (float)\n"); + scanf("%f",&num); + vup->Fold(num); + break; + case 2: + fprintf(stdout,"\nInvalidate Metric and Resources:\n"); + fprintf(stdout,"enter metricId (int)\n"); + scanf("%d",&mId); + fprintf(stdout,"enter resourceId (int)\n"); + scanf("%d",&rId); + vup->InvalidMR(mId,rId); + break; + case 3: + fprintf(stdout,"\nAdd Metrics and Resorces:\n"); + fprintf(stdout,"enter number of metrics (int)\n"); + scanf("%d",&nMets); + metrics = (metricType *)malloc(sizeof(metricType)*nMets); + for(i=0;iAddMetricsResources(mets,res,bWidth,bNum); + for(i=0;iNewMetricsResources(mets,res); + for(i=0;iPhase(num,num2,temp); + break; + case 6: + vup->Phase(3.4,4.5,"blah"); + break; + case 7: + done = 1; + break; + + } + + } + for(i=0;iGetMetricResource("metrics test string","r test string",0); + fprintf(stderr,"@@@@after upcall: GetMetricResource\n"); + fprintf(stderr,"@@@@before upcall: StopMetricResource\n"); + vp->StopMetricResource(3,2); + fprintf(stderr,"@@@@after upcall: StopMetricResource\n"); + fprintf(stderr,"@@@@before upcall: PhaseName\n"); + vp->PhaseName(3.0,2.0,"phase test string"); + fprintf(stderr,"@@@@after upcall: PhaseName\n"); + return(OK); +} + +int pn(){ +int i,j,k,noBins,noMetrics,noResources; + + fprintf(stderr,"@@@@call back routine for PHASENAME\n"); + + noMetrics = dataGrid.NumMetrics(); + noResources = dataGrid.NumResources(); + noBins = dataGrid.NumBins(); + + fprintf(stderr,"\n"); + for(i = 0; i < noMetrics; i++){ + fprintf(stderr,"@@@@metric %d: Id = %d, name = %s, units = %s\n",i,dataGrid.MetricId(i),dataGrid.MetricName(i),dataGrid.MetricUnits(i)); + } + + for(j = 0; j < noResources; j++) + fprintf(stderr,"@@@@resource %d: Id = %d, name = %s\n",j,dataGrid.ResourceId(j),dataGrid.ResourceName(j)); + + fprintf(stderr,"\n"); + for(i = 0; i < noMetrics; i++) + for(j = 0; j < noResources; j++){ + for(k = 0; k < noBins; k++) + fprintf(stderr,"@@@@dataGrid[%d,%d,%d] = %f\n",i,j,k,dataGrid[i][j][k]); + printf("\n"); + } + return(OK); +} + +int f(){ + fprintf(stderr,"@@@@call back routine for FOLD\n"); + return(OK); +} + + + + +main(int argc, char *argv[]){ + +int ok; + + // call VisiInit + if((ok = VisiInit()) != OK){ + exit(-1); + } + + // register event callbacks + + ok = RegistrationCallback(DATAVALUES,dv); + fprintf(stderr,"@@@@ok = %d after call to RegistrationCallback\n",ok); + ok = RegistrationCallback(INVALIDMETRICSRESOURCES,imr); + fprintf(stderr,"@@@@ok = %d after call to RegistrationCallback\n",ok); + ok = RegistrationCallback(ADDMETRICSRESOURCES,amr); + fprintf(stderr,"@@@@ok = %d after call to RegistrationCallback\n",ok); + ok = RegistrationCallback(NEWMETRICSRESOURCES,nmr); + fprintf(stderr,"@@@@ok = %d after call to RegistrationCallback\n",ok); + ok = RegistrationCallback(PHASENAME,pn); + fprintf(stderr,"@@@@ok = %d after call to RegistrationCallback\n",ok); + ok = RegistrationCallback(FOLD,f); + fprintf(stderr,"@@@@ok = %d after call to RegistrationCallback\n",ok); + + + // start visi: calls GetMetricResources() with initial metric/resource + // lists: this is not necessary, but for viisualizaitons that + // don't do upcalls its the only method of starting data collection + ok = StartVisi(argc,argv); + fprintf(stderr,"@@@@ok=%d after call to StartVisi()\n",ok); + + // register fd and callback using appropreate X routine + // then enter X main loop + + + // pseudo X main loop + while(1){ + ok = visi_callback(); + if(ok < 0){ + //client has exited, die + exit(-1); + } + } +} diff --git a/visi/test/xtext.C b/visi/test/xtext.C new file mode 100644 index 0000000..88d0741 --- /dev/null +++ b/visi/test/xtext.C @@ -0,0 +1,382 @@ +/* + * xtext.c + * + * This an example of how to use the Text and Paned widgets. + * + * November 14, 1989 - Chris D. Peterson + * + * Updated to also demonstrate XtAppAddInput() -- Bruce Irvin 3/8/94 + */ + +/* + * $XConsortium: xtext.c,v 1.16 91/05/16 14:56:23 swick Exp $ + * + * Copyright 1989 Massachusetts Institute of Technology + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. M.I.T. makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T. + * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include + +#include +#include +#include + +#include + +////////////////////////////////// +#include "../src/visualization.h" +////////////////////////////////// + +static void ClearText(Widget w,XtPointer text_ptr,XtPointer call_data); +static void PrintText(Widget w,XtPointer text_ptr,XtPointer call_data); +static void QuitProgram(Widget w,XtAppContext app_con,XtPointer call_data); +static void Syntax(XtAppContext app_con,char *call); + +////////////////////////////// +XtAppContext app_con; +Widget toplevel, paned, clear, print, quit, text; +Widget getMR; +////////////////////////////// + +// extern int fprintf(), bcopy(), read(), perror(), printf(); + +String fallback_resources[] = { + "*input: True", + "*showGrip: off", + "?.?.text.preferredPaneSize: 200", + "?.?.text.width: 200", + "?.?.text.textSource.editType: edit", + "?.?.text.scrollVertical: whenNeeded", + "?.?.text.scrollHorizontal: whenNeeded", + "?.?.text.autoFill: on", + "*clear*label: Clear", + "*print*label: Print", + "*quit*label: Quit", + NULL, +}; + +///////////////////////////////////////////////////////////// +//void fd_input(XtPointer client_data,int *fid,XtInputId *id) +//{ +// Widget text = (Widget) client_data; +// Arg args[1]; +// XawTextPosition pos; +// XawTextBlock tb; +// char buf[10000]; +// int nbytes; +// +// XtSetArg(args[0], XtNinsertPosition, &pos); +// XtGetValues(text, args, ONE); +// +// if ((nbytes = read(*fid, buf, BUFSIZ)) == -1) +// perror("fd_input"); +// else if (nbytes > 0) { +// tb.firstPos = 0; +// tb.length = nbytes; +// tb.ptr = buf; +// tb.format = FMT8BIT; +// +// if (XawTextReplace(text,pos,pos+nbytes-1,&tb) != XawEditDone) { +// fprintf(stderr,"XawTextReplace returned error\n"); +// } +// +// pos += nbytes; +// XtSetArg(args[0], XtNinsertPosition, pos); +// XtSetValues(text, args, ONE); +// } +//} + +// callback routine for FOLD and DATAVALUES +int fd_input(){ + + Arg args[1]; + XawTextPosition pos; + XawTextBlock tb; + char buf[100]; + int i,j,k; + int noMetrics,noResources,noBins; + int size; + float value; + + XtSetArg(args[0], XtNinsertPosition, &pos); + XtGetValues(text, args, ONE); + + + noMetrics = dataGrid.NumMetrics(); + noResources = dataGrid.NumResources(); + noBins = dataGrid.NumBins(); + for(i=0;i < noMetrics; i++) + for(j=0;jGetMetricResource(" "," ",0); + fprintf(stderr,"@@@@ in GetMetsRes after call\n"); +} +///////////////////////////////////// + + + + +int main(int argc,char **argv) +{ + // XtAppContext app_con; + // Widget toplevel, paned, clear, print, quit, text; + Arg args[1]; + +////////////////////////////////////// +// variables added for paradyn integration + int ok, fd; +////////////////////////////////////// + + toplevel = XtAppInitialize(&app_con, "Xtext", NULL, ZERO, + &argc, argv, fallback_resources, + NULL, ZERO); + + /* + * Check to see that all arguments were processed, and if not then + * report an error and exit. + */ + + if (argc != 1) + Syntax(app_con, argv[0]); + +////////////////////////////////////// +// call VisiInit: step (1) from README file + + if((fd = VisiInit()) < 0){ + exit(-1); + } +////////////////////////////////////// + + +////////////////////////////////////// +// register event callbacks: step (2) from README file + + ok = RegistrationCallback(ADDMETRICSRESOURCES,fd_input2); + ok = RegistrationCallback(DATAVALUES,fd_input); + ok = RegistrationCallback(FOLD,fd_input); + +// start visi: get initial metric and resource choices: step (3) from README + + ok = StartVisi(0,0); +////////////////////////////////////// + + paned = XtCreateManagedWidget("paned", panedWidgetClass, toplevel, + NULL, ZERO); + clear = XtCreateManagedWidget("clear", commandWidgetClass, paned, + NULL, ZERO); + print = XtCreateManagedWidget("print", commandWidgetClass, paned, + NULL, ZERO); + quit = XtCreateManagedWidget("quit", commandWidgetClass, paned, + NULL, ZERO); + +////////////////////////////////////// +// this is for an upcall to Paradyn: step (3a) from README + + getMR = XtCreateManagedWidget("Get Metric Resource",commandWidgetClass, + paned,NULL,ZERO); +////////////////////////////////////// + + + XtSetArg(args[0], XtNstring, "This is a test.\n"); + + text = XtCreateManagedWidget("text", asciiTextWidgetClass, paned, + args, ONE); + + XtAddCallback(clear, XtNcallback, ClearText, (XtPointer) text); + XtAddCallback(print, XtNcallback, PrintText, (XtPointer) text); + XtAddCallback(quit, XtNcallback, QuitProgram, (XtPointer) app_con); + +/////////////////////////////////////// +// Add callbacks for upcalls to Paradyn: step (3b) from README + + XtAddCallback(getMR, XtNcallback, GetMetsRes, (XtPointer) app_con); +////////////////////////////////////// + +////////////////////////////////////// +// register function to handle that input +// XtAppAddInput(app_con, fileno(stdin), (XtPointer) XtInputReadMask, +// (XtInputCallbackProc) fd_input, text); +////////////////////////////////////// + + +////////////////////////////////////// +// register visi_callback routine as callback on events assoc. w/ file desc +// step (4) from README file + + XtAppAddInput(app_con,fd,(XtPointer) XtInputReadMask, + (XtInputCallbackProc) visi_callback, text); +////////////////////////////////////// + + + XtRealizeWidget(toplevel); + XtAppMainLoop(app_con); +} + +/* Function Name: ClearText + * Description: This function clears all text out of the text widget. + * Arguments: w - *** UNUSED *** + * text_ptr - a pointer to the text widget. + * call_data - *** UNUSED ***. + * Returns: none. + */ + +/* ARGSUSED */ +static void ClearText(Widget w,XtPointer text_ptr,XtPointer call_data) +{ + Widget text = (Widget) text_ptr; + Arg args[1]; + + XtSetArg(args[0], XtNstring, ""); + XtSetValues(text, args, ONE); +} + +/* Function Name: PrintText + * Description: This function clears all text out of the text widget. + * Arguments: w - *** UNUSED *** + * text_ptr - a pointer to the text widget. + * call_data - *** UNUSED ***. + * Returns: none. + */ + +/* ARGSUSED */ +static void PrintText(Widget w,XtPointer text_ptr,XtPointer call_data) +{ + Widget text = (Widget) text_ptr; + Arg args[1]; + String str; + + XtSetArg(args[0], XtNstring, &str); + XtGetValues(text, args, ONE); + + fprintf(stderr, "Text String is:\n--------\n%s\n--------\n", str); +} + +/* Function Name: QuitProgram + * Description: This function exits the program + * Arguments: w - *** UNUSED *** + * text_ptr - a pointer to the text widget. + * call_data - *** UNUSED ***. + * Returns: none. + */ + +/* ARGSUSED */ +static void QuitProgram(Widget w,XtAppContext app_con,XtPointer call_data) +{ + fprintf(stderr, "Bye!\n"); + XtDestroyApplicationContext(app_con); + exit(0); +} + +/* Function Name: Syntax + * Description: Prints a the calling syntax for this function to stdout. + * Arguments: app_con - the application context. + * call - the name of the application. + * Returns: none - exits tho. + */ + +static void Syntax(XtAppContext app_con,char *call) +{ + XtDestroyApplicationContext(app_con); + fprintf( stderr, "Usage: %s \n", call); + exit(1); +} + diff --git a/visi/test/xtext2.C b/visi/test/xtext2.C new file mode 100644 index 0000000..5289d78 --- /dev/null +++ b/visi/test/xtext2.C @@ -0,0 +1,387 @@ +/* + * xtext.c + * + * This an example of how to use the Text and Paned widgets. + * + * November 14, 1989 - Chris D. Peterson + * + * Updated to also demonstrate XtAppAddInput() -- Bruce Irvin 3/8/94 + */ + +/* + * $XConsortium: xtext.c,v 1.16 91/05/16 14:56:23 swick Exp $ + * + * Copyright 1989 Massachusetts Institute of Technology + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of M.I.T. not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. M.I.T. makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T. + * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include + +#include +#include +#include + +#include + +////////////////////////////////// +#include "../src/visualization.h" +////////////////////////////////// + +static void ClearText(Widget w,XtPointer text_ptr,XtPointer call_data); +static void PrintText(Widget w,XtPointer text_ptr,XtPointer call_data); +static void QuitProgram(Widget w,XtAppContext app_con,XtPointer call_data); +static void Syntax(XtAppContext app_con,char *call); +////////////////////////////// +XtAppContext app_con; +Widget toplevel, paned, clear, print, quit, text; +Widget getMR, stopMR, phaseN; +////////////////////////////// + +// extern int fprintf(), bcopy(), read(), perror(), printf(); + +String fallback_resources[] = { + "*input: True", + "*showGrip: off", + "?.?.text.preferredPaneSize: 200", + "?.?.text.width: 200", + "?.?.text.textSource.editType: edit", + "?.?.text.scrollVertical: whenNeeded", + "?.?.text.scrollHorizontal: whenNeeded", + "?.?.text.autoFill: on", + "*clear*label: Clear", + "*print*label: Print", + "*quit*label: Quit", + NULL, +}; + +// callback routine for FOLD and DATAVALUES +int fd_input(){ + + Arg args[1]; + XawTextPosition pos; + XawTextBlock tb; + char buf[100]; + int i,j,k; + int noMetrics,noResources,noBins; + int size; + float value; + + XtSetArg(args[0], XtNinsertPosition, &pos); + XtGetValues(text, args, ONE); + + + noMetrics = dataGrid.NumMetrics(); + noResources = dataGrid.NumResources(); + noBins = dataGrid.NumBins(); + for(i=0;i < noMetrics; i++) + for(j=0;jGetMetricResource(" "," ",0); + fprintf(stderr,"@@@@ in GetMetsRes after call\n"); +} + +static void StopMetsRes(Widget w,XtAppContext app_con,XtPointer call_data){ + + fprintf(stderr,"@@@@ in StopMetsRes before call\n"); + vp->StopMetricResource(0,0); + fprintf(stderr,"@@@@ in StopMetsRes after call\n"); +} + +static void PName(Widget w,XtAppContext app_con,XtPointer call_data){ + + fprintf(stderr,"@@@@ in PName before call\n"); + vp->PhaseName(0.0,1.0," "); + fprintf(stderr,"@@@@ in PName after call\n"); +} +///////////////////////////////////// + + +int main(int argc,char **argv) +{ + // XtAppContext app_con; + // Widget toplevel, paned, clear, print, quit, text; + Arg args[1]; + +///////////////////////////////////// +// variables added for paradyn integration + int ok, fd; +///////////////////////////////////// + + toplevel = XtAppInitialize(&app_con, "Xtext", NULL, ZERO, + &argc, argv, fallback_resources, + NULL, ZERO); + + /* + * Check to see that all arguments were processed, and if not then + * report an error and exit. + */ + + if (argc != 1) + Syntax(app_con, argv[0]); + +////////////////////////////////////// +// call VisiInit: step (1) from README file + + if((fd = VisiInit()) < 0){ + exit(-1); + } +////////////////////////////////////// + +////////////////////////////////////// +// register event callbacks: step (2) from README file + + ok = RegistrationCallback(ADDMETRICSRESOURCES,fd_input2); + ok = RegistrationCallback(DATAVALUES,fd_input); + ok = RegistrationCallback(FOLD,fd_input); + ok = RegistrationCallback(INVALIDMETRICSRESOURCES,fd_input); + ok = RegistrationCallback(NEWMETRICSRESOURCES,fd_input3); + ok = RegistrationCallback(PHASENAME,fd_input3); +////////////////////////////////////// + +////////////////////////////////////// +// start visi: get initial metric and resource choices: step (3) from README + + ok = StartVisi(0,0); +////////////////////////////////////// + + paned = XtCreateManagedWidget("paned", panedWidgetClass, toplevel, + NULL, ZERO); + clear = XtCreateManagedWidget("clear", commandWidgetClass, paned, + NULL, ZERO); + print = XtCreateManagedWidget("print", commandWidgetClass, paned, + NULL, ZERO); + quit = XtCreateManagedWidget("quit", commandWidgetClass, paned, + NULL, ZERO); +////////////////////////////////////// +// this is for an upcall to Paradyn: step (3a) from README + + getMR = XtCreateManagedWidget("Get Metric Resource",commandWidgetClass, + paned,NULL,ZERO); + stopMR = XtCreateManagedWidget("Stop Metric Resource",commandWidgetClass, + paned,NULL,ZERO); + phaseN = XtCreateManagedWidget("Name a Phase",commandWidgetClass, + paned,NULL,ZERO); + +////////////////////////////////////// + + XtSetArg(args[0], XtNstring, "This is a test.\n"); + + text = XtCreateManagedWidget("text", asciiTextWidgetClass, paned, + args, ONE); + + XtAddCallback(clear, XtNcallback, ClearText, (XtPointer) text); + XtAddCallback(print, XtNcallback, PrintText, (XtPointer) text); + XtAddCallback(quit, XtNcallback, QuitProgram, (XtPointer) app_con); + +/////////////////////////////////////// +// Add callbacks for upcalls to Paradyn: step (3b) from README + + XtAddCallback(getMR, XtNcallback, GetMetsRes, (XtPointer) app_con); + XtAddCallback(stopMR, XtNcallback, StopMetsRes, (XtPointer) app_con); + XtAddCallback(phaseN, XtNcallback, PName, (XtPointer) app_con); +////////////////////////////////////// + +////////////////////////////////////// +// register visi_callback routine as callback on events assoc. w/ file desc +// step (4) from README file + + XtAppAddInput(app_con,fd,(XtPointer) XtInputReadMask, + (XtInputCallbackProc) visi_callback, text); +////////////////////////////////////// + + XtRealizeWidget(toplevel); + XtAppMainLoop(app_con); +} + +/* Function Name: ClearText + * Description: This function clears all text out of the text widget. + * Arguments: w - *** UNUSED *** + * text_ptr - a pointer to the text widget. + * call_data - *** UNUSED ***. + * Returns: none. + */ + +/* ARGSUSED */ +static void ClearText(Widget w,XtPointer text_ptr,XtPointer call_data) +{ + Widget text = (Widget) text_ptr; + Arg args[1]; + + XtSetArg(args[0], XtNstring, ""); + XtSetValues(text, args, ONE); +} + +/* Function Name: PrintText + * Description: This function clears all text out of the text widget. + * Arguments: w - *** UNUSED *** + * text_ptr - a pointer to the text widget. + * call_data - *** UNUSED ***. + * Returns: none. + */ + +/* ARGSUSED */ +static void PrintText(Widget w,XtPointer text_ptr,XtPointer call_data) +{ + Widget text = (Widget) text_ptr; + Arg args[1]; + String str; + + XtSetArg(args[0], XtNstring, &str); + XtGetValues(text, args, ONE); + + fprintf(stderr, "Text String is:\n--------\n%s\n--------\n", str); +} + +/* Function Name: QuitProgram + * Description: This function exits the program + * Arguments: w - *** UNUSED *** + * text_ptr - a pointer to the text widget. + * call_data - *** UNUSED ***. + * Returns: none. + */ + +/* ARGSUSED */ +static void QuitProgram(Widget w,XtAppContext app_con,XtPointer call_data) +{ + fprintf(stderr, "Bye!\n"); + XtDestroyApplicationContext(app_con); + exit(0); +} + +/* Function Name: Syntax + * Description: Prints a the calling syntax for this function to stdout. + * Arguments: app_con - the application context. + * call - the name of the application. + * Returns: none - exits tho. + */ + +static void Syntax(XtAppContext app_con,char *call) +{ + XtDestroyApplicationContext(app_con); + fprintf( stderr, "Usage: %s \n", call); + exit(1); +} + -- 1.8.3.1