Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

20151209宿題 #361

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ install:
- sudo apt-get update -qq
- sudo apt-get install -qq -y ros-hydro-desktop ros-hydro-roscpp-tutorials ros-hydro-rostest ros-hydro-catkin python-catkin-tools
- sudo apt-get install -qq -y ros-hydro-roseus
- sudo apt-get install -qq -y liborbit2 liborbit2-dev
- sudo apt-get install -qq -y ros-hydro-move-base-msgs
- sudo apt-get install -qq -y swi-prolog
- source /opt/ros/hydro/setup.bash
before_script:
- ls
- for dir in 20*; do echo "checking $dir"; pkg_dir=`catkin_topological_order $dir`; pkg="${pkg_dir% *}"; src="${pkg_dir##* }"; if [ -e "$dir/$src" ] ; then cp $dir/check*.* $dir/$src; fi; done;
- for dir in 20*; do echo "checking $dir"; pkg_dir=`catkin_topological_order $dir`; pkg="${pkg_dir% *}"; src="${pkg_dir##* }"; check=`ls $dir/check*.* 2>/dev/null`; if [ -e "$dir/$src" -a "$check" ] ; then cp $dir/check*.* $dir/$src; fi; done;
- find . -iname *.test
- rdir=`pwd`
script:
- for dir in 20*; do echo "checking $dir"; pkg_dir=`catkin_topological_order $dir`; pkg="${pkg_dir% *}"; src="${pkg_dir##* }"; if [ -e "$dir/$src" ] ; then source /opt/ros/hydro/setup.bash; cd $dir; catkin build -v -i; source devel/setup.bash; rospack list; cd $src; EXIT_STATUS=0; for test_file in check*.test; do rostest $pkg $test_file || EXIT_STATUS=1; done; cd $rdir; fi; done; [ $EXIT_STATUS == 0 ]
- for dir in 20*; do echo "checking $dir"; pkg_dir=`catkin_topological_order $dir`; pkg="${pkg_dir% *}"; src="${pkg_dir##* }"; check=`ls $dir/check*.* 2>/dev/null`; if [ -e "$dir/$src" -a "$check" ] ; then source /opt/ros/hydro/setup.bash; cd $dir; catkin build -v -i; source devel/setup.bash; rospack list; cd $src; EXIT_STATUS=0; for test_file in check*.test; do rostest $pkg $test_file || EXIT_STATUS=1; done; cd $rdir; fi; done; [ $EXIT_STATUS == 0 ]
after_failure:
- find src/ -type d -name .git -prune -o -type f -exec ls -l {} \;
- rostest -t beginner_tutorials check1.test
Expand Down
10 changes: 10 additions & 0 deletions 20151111/src/enshu_20151111/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 2.8.3)
project(enshu_20151111)

find_package(catkin REQUIRED COMPONENTS)
catkin_package()

execute_process(COMMAND make -C ${PROJECT_SOURCE_DIR})



8 changes: 8 additions & 0 deletions 20151111/src/enshu_20151111/ExampleMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public class ExampleMain {
public static void main(String[] args) {
System.loadLibrary("ffi-class_wrap");
Example e = new Example();
e.Hello("world");
e.Sinc(1.0);
}
}
16 changes: 16 additions & 0 deletions 20151111/src/enshu_20151111/ExampleMain2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import com.sun.jna.Library;
import com.sun.jna.Native;

public class ExampleMain2 {
public interface CLibrary extends Library {
CLibrary INSTANCE = (CLibrary)
Native.loadLibrary("ffi-c", CLibrary.class);
void hello(String str);
double sinc(double x);
}

public static void main( String[] args) {
CLibrary.INSTANCE.hello("world");
System.out.println("sinc(1.0) = " + CLibrary.INSTANCE.sinc(1.0));
}
}
63 changes: 63 additions & 0 deletions 20151111/src/enshu_20151111/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
all: ffi-c libffiJava.so ffi-c.so callc.so

ffi-c++.o: ffi-c++.cpp
gcc -c ffi-c++.cpp

ffi-c++-main.o: ffi-c++-main.c
gcc -c ffi-c++-main.c

ffi-c: ffi-c++.o ffi-c++-main.o
gcc -o ffi-c $^ -lm

ffiJava.class:
javac ffiJava.java

ffiJava.h: ffiJava.class
javah -jni ffiJava

JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64/
libffiJava.so: ffiJava.h
gcc -shared -fPIC -I${JAVA_HOME}/include -o libffiJava.so ffiJava.c
LD_LIBRARY_PATH=./:${LD_LIBRARY_PATH} java ffiJava

ffi-c.so: ffi-c.c
gcc -shared -fPIC -o ffi-c.so ffi-c.c -lm
python ffi_python.py
eusgl ffi.l

callc.so: callc.c
gcc -fPIC -shared -o callc.so callc.c
eusgl callc.l

_ffi_c.so:
swig -python ffi-c.i
gcc -I/usr/include/python2.7 -shared -fPIC -o _ffi_c.so ffi-c.c ffi-c_wrap.c
python -c 'import ffi_c; ffi_c.hello("hello"); print ffi_c.sinc(1.0)'

ffi_c.java:
swig -java ffi-c.i
gcc -shared -fPIC -I${JAVA_HOME}/include -o libffi-c_wrap.so ffi-c_wrap.c ffi-c.c
javac ffi_c.java
javac ffi_main.java
LD_LIBRARY_PATH=./:${LD_LIBRARY_PATH} java ffi_main

libffi-class_wrap.so:
swig -c++ -java ffi-class.i
g++ -shared -fPIC -I ./ -I${JAVA_HOME}/include -o libffi-class_wrap.so ffi-class_wrap.cxx ffi-class.cpp -lm -lstdc++
javac ffi_class.java ffi_classJNI.java
javac ExampleMain.java
LD_LIBRARY_PATH=./:${LD_LIBRARY_PATH} java ExampleMain

libffi-c.so:
gcc -shared -fPIC -o libffi-c.so ffi-c.c -lm
javac -classpath .:/usr/share/java/jna-3.2.7.jar ExampleMain2.java
LD_LIBRARY_PATH=./:${LD_LIBRARY_PATH} java -classpath .:/usr/share/java/jna-3.2.7.jar ExampleMain2

ffi_cython.so:
python setup.py build_ext --inplace
python -c 'import ffi_cython; ffi_cython.hello2("world"); ffi_cython.sinc2(1.0)'

.PHONY: callc.c

clean:
rm *.so *.o *.class ffi_c.java ffiJava.h ffi-c_wrap.c ffi_c.java ffi_cJNI.java ffi_class.java ffi_classJNI.java Example.java libffi-c.so ffi_cython.so ffi-c ffi-class_wrap.cxx ffi_c.py ffi_c.pyc ffi_cython.c
10 changes: 10 additions & 0 deletions 20151111/src/enshu_20151111/callc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
static int (*g)();

int setlfunc(int (*f)()) {
g = f;
}

int callfunc(x)
{
return ((*g)(x));
}
12 changes: 12 additions & 0 deletions 20151111/src/enshu_20151111/callc.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(setq m (load-foreign "./callc.so"))

(defforeign setlfunc m "setlfunc" (:integer) :integer)
(defforeign callfunc m "callfunc" (:integer) :integer)

(defun-c-callable TEST ((a :integer)) :integer
(format t "TEST is called, arg is ~A~%" a)
(* a a))

(setlfunc (pod-address (intern "TEST")))
(callfunc 12)
(exit)
9 changes: 9 additions & 0 deletions 20151111/src/enshu_20151111/ffi-c++-main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <stdio.h>

double sinc(double x);

int main () {
double f = 1.0;
fprintf(stderr, "sinc(%f) = %f\n", f, sinc(f));
return 0;
}
11 changes: 11 additions & 0 deletions 20151111/src/enshu_20151111/ffi-c++.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <math.h>

int f (int) { return 0; }
int f (void) { return 1; }
int g (void) { int i = f(), j = f(0); }

extern "C" {
double sinc(double x) {
return(sin(x)/x);
}
}
10 changes: 10 additions & 0 deletions 20151111/src/enshu_20151111/ffi-c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <math.h>
#include <stdio.h>

void hello(char *str) {
fprintf(stdout, "%s !!\n", str);
}

double sinc(double x) {
return(sin(x)/x);
}
7 changes: 7 additions & 0 deletions 20151111/src/enshu_20151111/ffi-c.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%module ffi_c
%{
extern void hello(char *str);
extern double sinc(double x);
%}
%include "ffi-c.c"

18 changes: 18 additions & 0 deletions 20151111/src/enshu_20151111/ffi-class.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* ffi-class.cpp */
#include <iostream>
#include <string>
#include <math.h>

class Example
{
public:
Example(void) {};
~Example(void) {};

void Hello(char *str) {
std::cerr << "hello " << str << "!!" << std::endl;
}
void Sinc(double x){
std::cerr << "sinc = " << sin(x)/x << std::endl;
}
};
5 changes: 5 additions & 0 deletions 20151111/src/enshu_20151111/ffi-class.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
%module ffi_class
%{
#include "ffi-class.cpp"
%}
%include "ffi-class.cpp"
10 changes: 10 additions & 0 deletions 20151111/src/enshu_20151111/ffi.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env eusgl

(setq m (load-foreign "./ffi-c.so"))
(defforeign sinc m "sinc" (:float) :float)
(defforeign hello m "hello" (:string) :integer)
(format t "sinc=~A~%" (sinc 1.0))
(format t "hello ")(finish-output t)
(hello "world")
(exit)

15 changes: 15 additions & 0 deletions 20151111/src/enshu_20151111/ffiJava.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "ffiJava.h"
#include <math.h>

JNIEXPORT jdouble JNICALL Java_ffiJava_sinc
(JNIEnv * env, jobject obj, jdouble d) {
d = sin(d)/d;
return d;
}

JNIEXPORT void JNICALL Java_ffiJava_hello
(JNIEnv *env, jobject obj, jstring s) {
const char *str = (*env)->GetStringUTFChars(env, s, 0);
fprintf(stdout, "%s !\n", str);
(*env)->ReleaseStringUTFChars(env, s, str);
}
13 changes: 13 additions & 0 deletions 20151111/src/enshu_20151111/ffiJava.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import java.io.*;

public class ffiJava {
private native double sinc(double d);
private native void hello(String str);

public static void main(String argv[]){
ffiJava t = new ffiJava();
System.loadLibrary("ffiJava");
System.out.print("hello "); t.hello("world");
System.out.println("sinc(1) = " + t.sinc(1.0f));
}
}
11 changes: 11 additions & 0 deletions 20151111/src/enshu_20151111/ffi_cython.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cdef extern int hello( char *)
cdef extern double sinc(double)

def hello2(name):
bname = name.encode("utf-8")
cdef char * cname = bname
hello(cname)


def sinc2(x):
return sinc(x)
6 changes: 6 additions & 0 deletions 20151111/src/enshu_20151111/ffi_euslisp.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(setq m (load-foreign "./ffi-c.so"))
(defforeign sinc m "sinc" (:float) :float)
(defforeign hello m "hello" (:string) :integer)
(format t "sinc~A~%" (sinc 1.0))
(format t "hello ")
(hello "world")
8 changes: 8 additions & 0 deletions 20151111/src/enshu_20151111/ffi_main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// ffi_main.java
public class ffi_main {
public static void main(String[] args) {
System.loadLibrary("ffi-c_wrap");
ffi_c.hello("world");
System.out.println("sinc(1) = " + ffi_c.sinc(1.0));
}
}
10 changes: 10 additions & 0 deletions 20151111/src/enshu_20151111/ffi_python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env python

import ctypes
ffi = ctypes.CDLL('./ffi-c.so')
print "hello ",
ffi.hello("world")

ffi.sinc.argtypes = [ctypes.c_double]
ffi.sinc.restype = ctypes.c_double
print ffi.sinc(1.0)
34 changes: 34 additions & 0 deletions 20151111/src/enshu_20151111/glut/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.SUFFIXES: .c .exe

OS = $(shell /bin/uname | sed s/-.*//)

ifeq ($(OS),Cygwin)
CFLAGS = -I/usr/X11R6/include
LIBDIR = -L/usr/X11R6/lib
GLLIBS = -lX11 -L/usr/X11R6/lib -lgl -lglu -lglut
else
CFLAGS = -I/usr/X11R6/include
LIBDIR = -L/usr/X11R6/lib
GLLIBS = -lX11 -L/usr/X11R6/lib -lGL -lGLU -lglut -lm
endif

all: auxdemo.exe auxdemo-offline.exe cube.exe scube.exe dinoshade.exe

.l.c:
@echo "";

.c.exe:
gcc -g -o $@ $(CFLAGS) $< $(LIBDIR) $(GLLIBS)

auxdemo-offline.exe: auxdemo.c
gcc -g -o $@ -DOFFLINE_RENDERING $(CFLAGS) $< $(LIBDIR) $(GLLIBS)
auxdemo.exe: auxdemo.c
cube.exe: cube.c
scube.exe: scube.c
dinoshade.exe: dinoshade.c
screendoor.exe: screendoor.c
molehil.exe: molehil.c

clean:
rm -f *~ *.exe *.exe.stackdump *.ppm
chmod a-x *
Loading