Commit 75598af8 authored by Romain Rouvoy's avatar Romain Rouvoy

Adding an example demonstrating the generation of JNA interfaces from native libraries.

parent c3ec12c1
============================================================================
OW2 FraSCAti Examples: HelloWorld JNA
Copyright (C) 2010 INRIA, University of Lille 1
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: frascati@ow2.org
Author: Romain Rouvoy
Contributor:
============================================================================
HelloWorld JNA example:
------------------------
This example shows how to build an SCA application with a client POJO and a
system library. The client is bound to the library via the JNA binding and
running the client lead to call the printf operation provided by the OS.
Compilation with Maven:
-----------------------
mvn install
Execution with Maven:
---------------------
mvn -Prun (standalone execution)
mvn -Pexplorer (with FraSCAti Explorer)
Compilation and execution with the FraSCAti script:
---------------------------------------------------
frascati compile src helloworld-binding-jna
frascati run helloworld-jna -libpath helloworld-binding-jna.jar -s r -m run
<?xml version="1.0"?>
<!--
* OW2 FraSCAti Examples: HelloWorld with JNA binding
*
* Copyright (c) 2010 INRIA, University of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Romain Rouvoy
*
* Contributor(s): Philippe Merle
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- ===================== -->
<!-- General Information -->
<!-- ===================== -->
<parent>
<groupId>org.ow2.frascati.examples.native</groupId>
<artifactId>parent</artifactId>
<version>1.3-SNAPSHOT</version>
</parent>
<artifactId>helloworld-native</artifactId>
<packaging>jar</packaging>
<name>OW2 FraSCAti Examples: HelloWorld Native</name>
<!-- ============ -->
<!-- Properties -->
<!-- ============ -->
<properties>
<service.name>r</service.name>
<method.name>run</method.name>
</properties>
<profiles>
<profile>
<id>Unix</id>
<activation>
<os>
<family>unix</family>
</os>
</activation>
<properties>
<composite.file>helloworld-native</composite.file>
</properties>
</profile>
<profile>
<id>Windows</id>
<activation>
<os>
<family>Windows</family>
</os>
</activation>
<properties>
<composite.file>helloworld-native-windows</composite.file>
</properties>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.ow2.frascati.native</groupId>
<artifactId>frascati-interface-native</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
/***
* OW2 FraSCAti Examples: HelloWorld with JNA
* Copyright (C) 2010 INRIA, University of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Romain Rouvoy
*
* Contributor(s):
*
*/
package native_.hw;
import org.osoa.sca.annotations.Reference;
import stdio.StdioLibrary;
/**
* Simple example of a SCA component declaring and using a native library to
* display an hello, world! message.
*
* @Author <a href="romain.rouvoy@lifl.fr">Romain Rouvoy</a>
*/
public class Client implements Runnable {
@Reference
private StdioLibrary service ;
public void run() {
service.printf("Hello, World!\n");
}
}
\ No newline at end of file
<?xml version="1.0" encoding="ISO-8859-15"?>
<!-- OW2 FraSCAti Examples: HelloWorld with Native binding -->
<!-- Copyright (C) 2010 INRIA, University of Lille 1 -->
<!-- -->
<!-- This library is free software; you can redistribute it and/or -->
<!-- modify it under the terms of the GNU Lesser General Public -->
<!-- License as published by the Free Software Foundation; either -->
<!-- version 2 of the License, or (at your option) any later version. -->
<!-- -->
<!-- This library 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 -->
<!-- Lesser General Public License for more details. -->
<!-- -->
<!-- You should have received a copy of the GNU Lesser General Public -->
<!-- License along with this library; if not, write to the Free Software -->
<!-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -->
<!-- -->
<!-- Contact: frascati@ow2.org -->
<!-- -->
<!-- Author: Romain Rouvoy -->
<!-- -->
<!-- Contributor(s): -->
<composite name="helloworld-native" xmlns="http://www.osoa.org/xmlns/sca/1.0">
<service name="r" promote="client/run"/>
<component name="client">
<implementation.java class="native_.hw.Client"/>
<service name="run">
<interface.java interface="java.lang.Runnable"/>
</service>
<reference name="service" xmlns:native="http://frascati.ow2.org/xmlns/native/1.0">
<native:interface.native descriptor="/usr/include/stdio.h"/>
<native:binding.jna library="c"/> <!-- for Linux and Mac OS X. -->
</reference>
</component>
</composite>
......@@ -53,8 +53,8 @@
<!-- ======= -->
<modules>
<module>helloworld-jna</module>
<module>helloworld-native</module>
<module>helloworld-binding-jna</module>
<module>helloworld-binding-native</module>
</modules>
<!-- ============ -->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment