3 import Analysis.TaskStateAnalysis.*;
8 public class WebInterface {
9 TaskAnalysis taskanalysis;
12 Hashtable flagstatemap;
13 Hashtable taskgraphmap;
14 Hashtable sourcenodemap; //to hold the filenames for each of the pages linked to the source nodes.
15 Hashtable taskmap; // to hold the filenames for each of the pages linked to tasks in the program.
16 GarbageAnalysis garbageanalysis;
18 public WebInterface(State state, TaskAnalysis taskanalysis, TaskGraph taskgraph, GarbageAnalysis garbageanalysis) {
20 this.taskanalysis=taskanalysis;
21 this.taskgraph=taskgraph;
22 this.garbageanalysis=garbageanalysis;
24 flagstatemap=new Hashtable();
25 taskgraphmap=new Hashtable();
26 taskmap = new Hashtable();
27 sourcenodemap=new Hashtable();
28 for(Iterator it_tasks=state.getTaskSymbolTable().getDescriptorsIterator();it_tasks.hasNext();){
29 TaskDescriptor td=(TaskDescriptor)it_tasks.next();
30 taskmap.put("/"+td.getSymbol()+".html",td);
32 for(Iterator it_classes=state.getClassSymbolTable().getDescriptorsIterator();it_classes.hasNext();) {
33 ClassDescriptor cd=(ClassDescriptor) it_classes.next();
34 Vector rootnodes=taskanalysis.getRootNodes(cd);
36 for(Iterator it_rootnodes=rootnodes.iterator();it_rootnodes.hasNext();){
37 FlagState root=(FlagState)it_rootnodes.next();
38 Vector cd_nodeid=new Vector(); //Vector is designed to contain only 2 elements: ClassDescriptor,Node label
39 // Both the values are required to correctly resolve the rootnode.
40 // Should think of a better way to do this, instead of using a vector(maybe a class)
41 cd_nodeid.addElement(cd); //adding the ClassDescriptor
42 cd_nodeid.addElement(root.getLabel()); //adding the Node label
43 sourcenodemap.put("/"+cd.getSymbol()+"_"+root.getLabel()+".html",cd_nodeid);
48 public boolean specialRequest(String filename) {
49 System.out.println(filename);
50 if (filename.equals("/index.html"))
52 if (flagstatemap.containsKey(filename))
54 if (taskgraphmap.containsKey(filename))
56 if (taskmap.containsKey(filename))
58 if (sourcenodemap.containsKey(filename))
63 public String handleresponse(String filename, OutputStream out, HTTPResponse resp) {
64 if (filename.equals("/index.html"))
65 return indexpage(out, resp);
66 if (flagstatemap.containsKey(filename))
67 return flagstate((ClassDescriptor) flagstatemap.get(filename), out, resp);
68 if (taskgraphmap.containsKey(filename))
69 return taskstate((ClassDescriptor) taskgraphmap.get(filename), out, resp);
70 if (taskmap.containsKey(filename))
71 return task((TaskDescriptor)taskmap.get(filename),out,resp);
72 if (sourcenodemap.containsKey(filename))
73 return sourcenode((Vector) sourcenodemap.get(filename), out, resp);
77 private String task(TaskDescriptor td, OutputStream out, HTTPResponse resp){
79 PrintWriter pw=new PrintWriter(out);
80 pw.println("<br><br><h3>Task: "+td.toString()+"</h3><br>");
83 } catch (Exception e) {e.printStackTrace();System.exit(-1);}
87 private String printTask(TaskDescriptor td, PrintWriter pw){
90 for(int i=0; i < td.numParameters();i++){
91 pw.println("FlagState Graph: <a href=\"/"+td.getParamType(i)+".html\">"+td.getParamType(i)+"</a><br>");
92 pw.println("Task Graph: <a href=\"/"+td.getParamType(i)+"-t.html\">"
93 +td.getParamType(i)+"</a><br>");
96 }catch(Exception e) {e.printStackTrace();System.exit(-1);}
100 private String sourcenode(Vector cd_nodeid,OutputStream out, HTTPResponse resp){
101 Vector rootnodes=taskanalysis.getRootNodes((ClassDescriptor)cd_nodeid.elementAt(0));
102 for(Iterator it_rootnodes=rootnodes.iterator();it_rootnodes.hasNext();){
103 FlagState root=(FlagState)it_rootnodes.next();
104 if (root.getLabel().equals((String)cd_nodeid.elementAt(1))){
106 PrintWriter pw=new PrintWriter(out);
107 pw.println("<br><br><h3>Allocating tasks for "+root.getTextLabel()+":</h3><br>");
108 Vector tasks=root.getAllocatingTasks();
109 for(Iterator it_tasks=tasks.iterator();it_tasks.hasNext();){
110 TaskDescriptor td=(TaskDescriptor)it_tasks.next();
111 pw.println("<br><strong>Task: "+td.toString()+"</strong><br>");
115 } catch (Exception e) {e.printStackTrace();System.exit(-1);}
123 private String flagstate(ClassDescriptor cd, OutputStream out, HTTPResponse resp) {
124 Set objects=taskanalysis.getFlagStates(cd);
125 File file=new File(cd.getSymbol()+".dot");
128 Vector namers=new Vector();
129 namers.add(new Namer());
130 namers.add(garbageanalysis);
131 namers.add(new Allocations());
132 namers.add(new TaskEdges());
135 Runtime r=Runtime.getRuntime();
137 FileOutputStream dotstream=new FileOutputStream(file,false);
138 FlagState.DOTVisitor.visit(dotstream, objects, namers);
140 Process p=r.exec("dot -Tcmapx -o"+cd.getSymbol()+".map -Tjpg -o"+cd.getSymbol()+".jpg "+cd.getSymbol()+".dot");
142 p=r.exec("dot -Tps "+cd.getSymbol()+".dot -o"+cd.getSymbol()+".ps");
145 mapfile=new File(cd.getSymbol()+".map");
146 BufferedReader mapbr=new BufferedReader(new FileReader(mapfile));
147 PrintWriter pw=new PrintWriter(out);
148 pw.println("<a href=\"/"+ cd.getSymbol()+".ps\">ps</a><br>");
149 //pw.println("<a href=\"/"+ cd.getSymbol()+".map\"><img src=\"/"+ cd.getSymbol()+".gif\" ismap=\"ismap\"></A>");
150 pw.println("<img src=\""+cd.getSymbol()+".jpg\" usemap=\"#dotvisitor\" />");
151 while((str=mapbr.readLine())!=null){
156 } catch (Exception e) {e.printStackTrace();System.exit(-1);}
160 private String taskstate(ClassDescriptor cd, OutputStream out, HTTPResponse resp) {
161 Set objects=taskgraph.getTaskNodes(cd);
162 File file=new File(cd.getSymbol()+"-t.dot");
165 Vector namers=new Vector();
166 namers.add(new Namer());
167 namers.add(new TaskNodeNamer());
171 Runtime r=Runtime.getRuntime();
172 FileOutputStream dotstream=new FileOutputStream(file,false);
173 FlagState.DOTVisitor.visit(dotstream, objects,namers);
175 Process p=r.exec("dot -Tcmapx -o"+cd.getSymbol()+"-t.map -Tjpg -o"+cd.getSymbol()+"-t.jpg "+cd.getSymbol()+"-t.dot");
177 p=r.exec("dot -Tps "+cd.getSymbol()+".dot -o"+cd.getSymbol()+"-t.ps");
181 mapfile=new File(cd.getSymbol()+"-t.map");
182 BufferedReader mapbr=new BufferedReader(new FileReader(mapfile));
183 PrintWriter pw=new PrintWriter(out);
184 pw.println("<a href=\"/"+ cd.getSymbol()+"-t.ps\">ps</a><br>");
185 // pw.println("<a href=\"/"+ cd.getSymbol()+"-t.map\"><img src=\"/"+ cd.getSymbol()+"-t.gif\" ismap=\"ismap\"></A>");
186 pw.println("<img src=\""+cd.getSymbol()+"-t.jpg\" usemap=\"#dotvisitor\" />");
188 while((str=mapbr.readLine())!=null){
192 } catch (Exception e) {e.printStackTrace();System.exit(-1);}
196 /* public void taskgraph(
199 private String indexpage(OutputStream out, HTTPResponse resp) {
201 PrintWriter pw=new PrintWriter(out);
202 for(Iterator it_classes=state.getClassSymbolTable().getDescriptorsIterator();it_classes.hasNext();) {
203 ClassDescriptor cd=(ClassDescriptor) it_classes.next();
204 if (taskanalysis.getFlagStates(cd)!=null) {
205 pw.println("<a href=\""+cd.getSymbol()+".html\">"+ cd.getSymbol() +"</a>");
207 flagstatemap.put("/"+cd.getSymbol()+".html", cd);
209 if (taskgraph.getTaskNodes(cd)!=null) {
210 pw.println("<a href=\""+cd.getSymbol()+"-t.html\">Task Graph "+ cd.getSymbol() +"</a>");
212 taskgraphmap.put("/"+cd.getSymbol()+"-t.html", cd);