[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r2987 - in freeway: native src/org/gnu/freeway/cwrappers/ut
From: |
mdonoughe |
Subject: |
[GNUnet-SVN] r2987 - in freeway: native src/org/gnu/freeway/cwrappers/util src/org/gnu/freeway/services/impl |
Date: |
Thu, 8 Jun 2006 16:13:53 -0700 (PDT) |
Author: mdonoughe
Date: 2006-06-08 16:13:48 -0700 (Thu, 08 Jun 2006)
New Revision: 2987
Added:
freeway/src/org/gnu/freeway/cwrappers/util/MethodLister.java
Removed:
freeway/src/org/gnu/freeway/cwrappers/util/InterfaceImplementor.java
Modified:
freeway/native/switch-table.c
freeway/native/switch-table.h
freeway/src/org/gnu/freeway/cwrappers/util/SwitchTableGenerator.java
freeway/src/org/gnu/freeway/services/impl/StatsService.java
Log:
Reverted to the class reflection method.
Changed InterfaceImplementor to MethodLister.
Methods in impl classes are now in the correct order.
Modified: freeway/native/switch-table.c
===================================================================
--- freeway/native/switch-table.c 2006-06-08 22:39:23 UTC (rev 2986)
+++ freeway/native/switch-table.c 2006-06-08 23:13:48 UTC (rev 2987)
@@ -10,6 +10,27 @@
}
}
switch (functionType) {
+ case 13: {
+ void * carg0 = convObjectToPtr(jargs[0], env);
+ int cret = ((FunctionType13)
((void**)m->modulePtr)[functionOffset])(carg0);
+ updateObjectFromPtr(jargs[0], carg0, env);
+ oret = convIntToCInt(cret, env);
+ }
+ case 60: {
+ int carg0 = convCIntToInt(jargs[0], env);
+ long long carg1 = convCLongToLong(jargs[1], env);
+ ((FunctionType60) ((void**)m->modulePtr)[functionOffset])(carg0, carg1);
+ }
+ case 42: {
+ int carg0 = convCIntToInt(jargs[0], env);
+ int carg1 = convCIntToInt(jargs[1], env);
+ ((FunctionType42) ((void**)m->modulePtr)[functionOffset])(carg0, carg1);
+ }
+ case 10: {
+ int carg0 = convCIntToInt(jargs[0], env);
+ long long cret = ((FunctionType10)
((void**)m->modulePtr)[functionOffset])(carg0);
+ oret = convLongToCLong(cret, env);
+ }
default:
GNUNET_ASSERT(0);
}
Modified: freeway/native/switch-table.h
===================================================================
--- freeway/native/switch-table.h 2006-06-08 22:39:23 UTC (rev 2986)
+++ freeway/native/switch-table.h 2006-06-08 23:13:48 UTC (rev 2987)
@@ -1 +1,5 @@
// This file was autogenerated by SwitchTableGenerator
+typedef int (*FunctionType13)(void * arg0);
+typedef void (*FunctionType60)(int arg0, long long arg1);
+typedef void (*FunctionType42)(int arg0, int arg1);
+typedef long long (*FunctionType10)(int arg0);
Deleted: freeway/src/org/gnu/freeway/cwrappers/util/InterfaceImplementor.java
===================================================================
--- freeway/src/org/gnu/freeway/cwrappers/util/InterfaceImplementor.java
2006-06-08 22:39:23 UTC (rev 2986)
+++ freeway/src/org/gnu/freeway/cwrappers/util/InterfaceImplementor.java
2006-06-08 23:13:48 UTC (rev 2987)
@@ -1,86 +0,0 @@
- /*
- This file is part of Freeway
-
- Freeway is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 2, or (at your
- option) any later version.
-
- Freeway is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Freeway; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
- */
-
-package org.gnu.freeway.cwrappers.util;
-
-import org.gnu.freeway.support.javaparser.visitors.Visitor;
-import org.gnu.freeway.support.javaparser.visitors.DepthFirstVisitor;
-import java.io.InputStream;
-import java.io.Writer;
-import java.io.IOException;
-import java.util.Set;
-import org.gnu.freeway.support.javaparser.*;
-
-/**
- * @file InterfaceImplementor.java
- * @brief
- * @author mdonoughe
- */
-public class InterfaceImplementor extends DepthFirstVisitor implements Visitor
{
- //alias the constructor since an instance of this class is useless to
others
- public static void implement(InputStream in, Writer out, Set
functionTypes) throws IOException, ParseException {
- new InterfaceImplementor(in, out, functionTypes);
- }
-
- private InputStream in;
- private Writer out;
- private Set functionTypes;
- private StringBuffer output;
-
- private static final String[] INDENT = {"", " ", " ", " "};
-
- protected InterfaceImplementor(InputStream in, Writer out, Set
functionTypes) throws IOException, ParseException {
- this.in = in;
- this.out = out;
- this.functionTypes = functionTypes;
- output = new StringBuffer();
- JavaParser parser = new JavaParser(in);
- CompilationUnit cu = parser.CompilationUnit();
- output.append("//This class was autogenerated by
InterfaceImplentor\n");
- cu.accept(this);
- out.write(output.toString());
- }
-
- //start overriding DepthFirstVisitor
-
- public void visit(PackageDeclaration n) {
- output.append(n.f0.tokenImage + " " + n.f1.f0.tokenImage);
- for(int i = 0; i < n.f1.f1.size(); i++) {
- output.append("." + ((NodeToken) ((NodeSequence)
n.f1.f1.elementAt(i)).nodes.get(1)).tokenImage);
- }
- output.append(".impl" + n.f2.tokenImage + "\n\n");
- n.f0.accept(this);
- n.f1.accept(this);
- n.f2.accept(this);
- }
-
- public void visit(ImportDeclaration n) {
- output.append(n.f0.tokenImage + " " + n.f1.f0.tokenImage);
- for(int i = 0; i < n.f1.f1.size(); i++) {
- output.append("." + ((NodeToken) ((NodeSequence)
n.f1.f1.elementAt(i)).nodes.get(1)).tokenImage);
- }
- if(n.f2.present())
- output.append("." + ((NodeSequence)
n.f2.node).nodes.get(1));
- output.append(n.f3.tokenImage + "\n");
- n.f0.accept(this);
- n.f1.accept(this);
- n.f2.accept(this);
- n.f3.accept(this);
- }
-}
Added: freeway/src/org/gnu/freeway/cwrappers/util/MethodLister.java
===================================================================
--- freeway/src/org/gnu/freeway/cwrappers/util/MethodLister.java
2006-06-08 22:39:23 UTC (rev 2986)
+++ freeway/src/org/gnu/freeway/cwrappers/util/MethodLister.java
2006-06-08 23:13:48 UTC (rev 2987)
@@ -0,0 +1,59 @@
+ /*
+ This file is part of Freeway
+
+ Freeway is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ Freeway is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Freeway; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+ */
+
+package org.gnu.freeway.cwrappers.util;
+
+import org.gnu.freeway.support.javaparser.visitors.Visitor;
+import org.gnu.freeway.support.javaparser.visitors.DepthFirstVisitor;
+import java.io.InputStream;
+import org.gnu.freeway.support.javaparser.*;
+import java.util.ArrayList;
+
+/**
+ * @file InterfaceImplementor.java
+ * @brief
+ * @author mdonoughe
+ */
+public class MethodLister extends DepthFirstVisitor implements Visitor {
+ //alias the constructor since an instance of this class is useless to
others
+ public static ArrayList list(InputStream in) throws ParseException {
+ MethodLister lister = new MethodLister(in);
+ return lister.go();
+ }
+
+ private InputStream in;
+ private CompilationUnit cu;
+ private ArrayList list;
+
+ private MethodLister(InputStream in) throws ParseException {
+ this.in = in;
+ JavaParser parser = new JavaParser(in);
+ cu = parser.CompilationUnit();
+ }
+
+ private synchronized ArrayList go() {
+ list = new ArrayList();
+ cu.accept(this);
+ return list;
+ }
+
+ public void visit(MethodDeclarator n) {
+ list.add(n.f0.tokenImage);
+ }
+}
Modified: freeway/src/org/gnu/freeway/cwrappers/util/SwitchTableGenerator.java
===================================================================
--- freeway/src/org/gnu/freeway/cwrappers/util/SwitchTableGenerator.java
2006-06-08 22:39:23 UTC (rev 2986)
+++ freeway/src/org/gnu/freeway/cwrappers/util/SwitchTableGenerator.java
2006-06-08 23:13:48 UTC (rev 2987)
@@ -62,7 +62,7 @@
* @param args
*/
public static void main(String[] args) {
- //StringBuffer clsPrefix = new StringBuffer();
+ StringBuffer clsPrefix = new StringBuffer();
StringBuffer srcPrefix = new StringBuffer();
StringBuffer natPrefix = new StringBuffer();
HashSet functionTypeSet = new HashSet();
@@ -74,9 +74,9 @@
for(i = 0; i < args.length; i++)
if(args[i].startsWith("-"))
if(currentArg == null)
-// if(args[i].equals("-c") &&
clsPrefix.length() == 0)
-// currentArg = clsPrefix;
- if(args[i].equals("-s") &&
srcPrefix.length() == 0)
+ if(args[i].equals("-c") &&
clsPrefix.length() == 0)
+ currentArg = clsPrefix;
+ else if(args[i].equals("-s") &&
srcPrefix.length() == 0)
currentArg = srcPrefix;
else if(args[i].equals("-n") &&
natPrefix.length() == 0)
currentArg = natPrefix;
@@ -90,8 +90,8 @@
} else
break;
//use defaults
- //if(clsPrefix.length() == 0)
- // clsPrefix.append("build");
+ if(clsPrefix.length() == 0)
+ clsPrefix.append("build");
if(srcPrefix.length() == 0)
srcPrefix.append("src");
if(natPrefix.length() == 0)
@@ -102,21 +102,21 @@
System.err.println("a source code generator for
Freeway");
System.err.println();
System.err.println("usage: SwitchTableGenerator [-c
<directory>] [-s <directory>] [-n <directory>]");
- //System.err.println(" -c path to class files
(default: build)");
+ System.err.println(" -c path to class files
(default: build)");
System.err.println(" -s path to java source files
(default: src)");
System.err.println(" -n path to c source files
(default: native)");
return;
}
- //if(!clsPrefix.toString().endsWith(File.separator))
- // clsPrefix.append(File.separatorChar);
+ if(!clsPrefix.toString().endsWith(File.separator))
+ clsPrefix.append(File.separatorChar);
if(!srcPrefix.toString().endsWith(File.separator))
srcPrefix.append(File.separatorChar);
if(!natPrefix.toString().endsWith(File.separator))
natPrefix.append(File.separatorChar);
String servicesSubpath = "org" + File.separator + "gnu" +
File.separator + "freeway" + File.separator + "services";
- //File classesDir = new File(clsPrefix + servicesSubpath);
+ File classesDir = new File(clsPrefix + servicesSubpath);
File sourcesDir = new File(srcPrefix + servicesSubpath);
File nativeCDir = new File(natPrefix.toString());
@@ -132,104 +132,7 @@
}
}
- //process every interface
- File inputFiles[] = sourcesDir.listFiles(new
SourceFilesFilter());
- for(i = 0; i < inputFiles.length; i++) {
- //get an input stream for the interface file
- BufferedInputStream inputSourceStream = null;
- try {
- inputSourceStream = new BufferedInputStream(new
FileInputStream(inputFiles[i]));
- } catch(IOException e) {
- e.printStackTrace();
- try {
- System.err.println("Could not read
source file \"" + inputFiles[i].getCanonicalPath() + "\".");
- } catch(IOException ee) {
- System.err.println("Could not read
source file \"" + inputFiles[i].getAbsolutePath() + "\".");
- }
- continue;
- }
-
- //create empty output files
- File outputSource = new File(implDir,
inputFiles[i].getName());
- try {
- if(!outputSource.createNewFile()) {
- if(!outputSource.delete()) {
- try {
-
System.err.println("Could not delete existing source file \"" +
outputSource.getCanonicalPath() + "\".");
- } catch(IOException ee) {
-
System.err.println("Could not delete existing source file \"" +
outputSource.getAbsolutePath() + "\".");
- }
- continue;
- }
- if(!outputSource.createNewFile()) {
- try {
-
System.err.println("Could not create source file \"" +
outputSource.getCanonicalPath() + "\".");
- } catch(IOException ee) {
-
System.err.println("Could not create source file \"" +
outputSource.getAbsolutePath() + "\".");
- }
- continue;
- }
- }
- } catch(Exception e) {
- e.printStackTrace();
- try {
- System.err.println("Could not create
source file \"" + outputSource.getCanonicalPath() + "\".");
- } catch(IOException ee) {
- System.err.println("Could not create
source file \"" + outputSource.getAbsolutePath() + "\".");
- }
- continue;
- }
-
- //get a writer
- BufferedWriter outputSourceWriter = null;
- try {
- outputSourceWriter = new BufferedWriter(new
FileWriter(outputSource));
- } catch(IOException e) {
- e.printStackTrace();
- try {
- System.err.println("Could not open
source file \"" + outputSource.getCanonicalPath() + "\".");
- } catch(IOException ee) {
- System.err.println("Could not open
source file \"" + outputSource.getAbsolutePath() + "\".");
- }
- continue;
- }
-
- //write code
- try {
-
InterfaceImplementor.implement(inputSourceStream, outputSourceWriter,
functionTypeSet);
- } catch(IOException e) {
- e.printStackTrace();
- try {
- System.err.println("Could not write
source file \"" + outputSource.getCanonicalPath() + "\".");
- } catch(IOException ee) {
- System.err.println("Could not write
source file \"" + outputSource.getAbsolutePath() + "\".");
- }
- continue;
- } catch(ParseException e) {
- e.printStackTrace();
- try {
- System.err.println("Could not parse
source file \"" + inputFiles[i].getCanonicalPath() + "\".");
- } catch(IOException ee) {
- System.err.println("Could not parse
source file \"" + inputFiles[i].getAbsolutePath() + "\".");
- }
- continue;
- } finally {
- try {
- outputSourceWriter.flush();
- } catch(IOException e) {
- e.printStackTrace();
- }
- try {
- outputSourceWriter.close();
- } catch(IOException e) {
- e.printStackTrace();
- }
- }
- }
-
-
- //the old reflection way that got all the stuff backwards
- /*//check for classes folder
+ //check for classes folder
if(!classesDir.exists()) {
try {
System.err.println("Could not find the classes
folder \"" + classesDir.getCanonicalPath() + "\".");
@@ -281,10 +184,10 @@
continue;
}
- //run the parser
- JavaParser interfaceParser = new
JavaParser(inputSourceStream);
- try{
- interfaceParser.CompilationUnit().accept(new
DepthFirstVisitor());
+ //get the method list
+ ArrayList methodList = null;
+ try {
+ methodList =
MethodLister.list(inputSourceStream);
} catch(ParseException e) {
e.printStackTrace();
try {
@@ -342,7 +245,7 @@
//write code
try {
- implementClass(inputClass, outputSourceWriter,
functionTypeSet);
+ implementClass(inputClass, outputSourceWriter,
functionTypeSet, methodList);
} catch(IOException e) {
e.printStackTrace();
try {
@@ -365,7 +268,7 @@
e.printStackTrace();
}
}
- }*/
+ }
//begin working on the C side
//create native folder
@@ -630,7 +533,7 @@
writer.write(typedef.toString() + ");\n");
}
- public static void implementClass(Class c, Writer writer, HashSet
functionTypeSet) throws IOException, IllegalArgumentException {
+ public static void implementClass(Class c, Writer writer, HashSet
functionTypeSet, ArrayList order) throws IOException, IllegalArgumentException {
if(!c.isInterface()) {
throw new IllegalArgumentException();
}
@@ -640,7 +543,7 @@
cleanClassName("org.gnu.freeway.server.CPluginLoader", imports);
Method[] methods = c.getMethods();
- ArrayList methodList = new ArrayList();
+ HashMap methodList = new HashMap();
// write every method to the buffer
for(int i = 0; i < methods.length; i++) {
@@ -672,7 +575,7 @@
buffer.append("loader.callC(handle, \"" +
methods[i].getName() + "\", this, new Object[] {" + arrayBuffer + "});\n");
buffer.append(" }");
functionTypeSet.add(new
Integer(getFunctionType(methods[i])));
- methodList.add(buffer.toString());
+ methodList.put(methods[i].getName(), buffer.toString());
}
writer.write("// This class was autogenerated by
SwitchTableGenerator\n");
@@ -686,8 +589,8 @@
writer.write(" private CPluginLoader loader;\n");
writer.write(" private CPluginLoader.Handle handle;\n");
writer.write("\n");
- for(Iterator i = methodList.iterator(); i.hasNext(); )
- writer.write((String) i.next() + "\n\n");
+ for(Iterator i = order.iterator(); i.hasNext(); )
+ writer.write((String) methodList.get(i.next()) +
"\n\n");
writer.write(" public " + stripPackage(c.getName()) +
"(CPluginLoader loader) {\n");
writer.write(" this.loader = loader;\n");
writer.write(" handle = loader.loadService(\"" +
classToLibraryName(c.getName()) + "\");\n");
@@ -778,7 +681,7 @@
}
}
- /*private static class ClassFilesFilter implements FilenameFilter {
+ private static class ClassFilesFilter implements FilenameFilter {
public boolean accept(File dir, String name) {
if(name == null || !name.endsWith(".class"))
return false;
@@ -787,5 +690,5 @@
public ClassFilesFilter() {
}
- }*/
+ }
}
Modified: freeway/src/org/gnu/freeway/services/impl/StatsService.java
===================================================================
--- freeway/src/org/gnu/freeway/services/impl/StatsService.java 2006-06-08
22:39:23 UTC (rev 2986)
+++ freeway/src/org/gnu/freeway/services/impl/StatsService.java 2006-06-08
23:13:48 UTC (rev 2987)
@@ -1,9 +1,39 @@
-//This class was autogenerated by InterfaceImplentor
+// This class was autogenerated by SwitchTableGenerator
package org.gnu.freeway.services.impl;
-import org.gnu.freeway.cwrappers.ConstCString;
-import org.gnu.freeway.cwrappers.ConstCInt;
+import org.gnu.freeway.cwrappers.CInt;
import org.gnu.freeway.cwrappers.ConstCLong;
import org.gnu.freeway.cwrappers.CLong;
-import org.gnu.freeway.cwrappers.CInt;
-import org.gnu.freeway.cwrappers.*;
+import org.gnu.freeway.cwrappers.ConstCInt;
+import org.gnu.freeway.cwrappers.ConstCString;
+import org.gnu.freeway.server.CPluginLoader;
+
+public class StatsService implements org.gnu.freeway.services.StatsService {
+ private CPluginLoader loader;
+ private CPluginLoader.Handle handle;
+
+ public CInt create(ConstCString arg0) {
+ return (CInt) loader.callC(handle, "create", this, new Object[]
{arg0});
+ }
+
+ public void set(ConstCInt arg0, ConstCLong arg1) {
+ loader.callC(handle, "set", this, new Object[] {arg0, arg1});
+ }
+
+ public CLong get(ConstCInt arg0) {
+ return (CLong) loader.callC(handle, "get", this, new Object[]
{arg0});
+ }
+
+ public void change(ConstCInt arg0, ConstCInt arg1) {
+ loader.callC(handle, "change", this, new Object[] {arg0, arg1});
+ }
+
+ public StatsService(CPluginLoader loader) {
+ this.loader = loader;
+ handle = loader.loadService("module_stats");
+ }
+
+ protected void finalize() {
+ loader.unloadService(handle);
+ }
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r2987 - in freeway: native src/org/gnu/freeway/cwrappers/util src/org/gnu/freeway/services/impl,
mdonoughe <=