diff --git a/.classpath b/.classpath
deleted file mode 100644
index 3ed2f53..0000000
--- a/.classpath
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
/* * Copyright (c) 2013, intarsys consulting GmbH * @@ -330,13 +302,13 @@ bc. */-h2. Service & Support +## Service & Support -Service&support should be funneled through the tools available with Github. +Service & support should be funneled through the tools available with Github. If you need further assistance, contact us. -bc. +
intarsys consulting GmbH Kriegstrasse 100 76135 Karlsruhe @@ -344,3 +316,4 @@ Fon +49 721 38479-0 Fax +49 721 38479-60 info@intarsys.de www.intarsys.de +diff --git a/deploy/is-native-c.jar b/deploy/is-native-c.jar deleted file mode 100644 index 63fb007..0000000 Binary files a/deploy/is-native-c.jar and /dev/null differ diff --git a/doc/jna_license.txt b/doc/jna_license.txt deleted file mode 100644 index 7282b28..0000000 --- a/doc/jna_license.txt +++ /dev/null @@ -1,5 +0,0 @@ -This program uses jna (https://github.com/twall/jna). - -jna is governed by the LGPL license, available in this directory. - -jna source code is available at https://github.com/twall/jna. \ No newline at end of file diff --git a/doc/lgpl-2.1.txt b/doc/lgpl-2.1.txt deleted file mode 100644 index 602bfc9..0000000 --- a/doc/lgpl-2.1.txt +++ /dev/null @@ -1,504 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - -
- * Use this to indicate on a native call parameter or return type that you will
- * deal with the platforms wide string capabilities.
- *
- */
final public class CWideString {
- private final String string;
-
- public CWideString(String string) {
- super();
- this.string = string;
- }
+ private final String string;
- public String getString() {
- return string;
- }
+ public CWideString(String string) {
+ super();
+ this.string = string;
+ }
+ public String getString() {
+ return string;
+ }
}
diff --git a/src/de/intarsys/nativec/api/ICallback.java b/nativec-api/src/main/java/de/intarsys/nativec/api/ICallback.java
similarity index 77%
rename from src/de/intarsys/nativec/api/ICallback.java
rename to nativec-api/src/main/java/de/intarsys/nativec/api/ICallback.java
index 715b11e..8731899 100644
--- a/src/de/intarsys/nativec/api/ICallback.java
+++ b/nativec-api/src/main/java/de/intarsys/nativec/api/ICallback.java
@@ -1,20 +1,23 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
- *
+ *
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
- *
+ *
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* - Neither the name of intarsys nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -26,23 +29,23 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
+ * #L%
*/
package de.intarsys.nativec.api;
public interface ICallback {
- @Deprecated
- public static final Object CallingConventionCdecl = INativeFunction.CallingConventionCdecl;
+ @Deprecated
+ Object CallingConventionCdecl = INativeFunction.CallingConventionCdecl;
- @Deprecated
- public static final Object CallingConventionStdcall = INativeFunction.CallingConventionCdecl;
+ @Deprecated
+ Object CallingConventionStdcall = INativeFunction.CallingConventionCdecl;
- public Object getCallingConvention();
+ Object getCallingConvention();
- public Class>[] getParameterTypes();
+ Class>[] getParameterTypes();
- public Class> getReturnType();
-
- public Object invoke(Object[] objects);
+ Class> getReturnType();
+ Object invoke(Object[] objects);
}
diff --git a/src/de/intarsys/nativec/api/INativeCallback.java b/nativec-api/src/main/java/de/intarsys/nativec/api/INativeCallback.java
similarity index 91%
rename from src/de/intarsys/nativec/api/INativeCallback.java
rename to nativec-api/src/main/java/de/intarsys/nativec/api/INativeCallback.java
index 2711d75..b1f2ab9 100644
--- a/src/de/intarsys/nativec/api/INativeCallback.java
+++ b/nativec-api/src/main/java/de/intarsys/nativec/api/INativeCallback.java
@@ -1,20 +1,23 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
- *
+ *
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
- *
+ *
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* - Neither the name of intarsys nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -26,9 +29,10 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
+ * #L%
*/
package de.intarsys.nativec.api;
public interface INativeCallback {
- // no methods
+ // no methods
}
diff --git a/src/de/intarsys/nativec/api/INativeFunction.java b/nativec-api/src/main/java/de/intarsys/nativec/api/INativeFunction.java
similarity index 74%
rename from src/de/intarsys/nativec/api/INativeFunction.java
rename to nativec-api/src/main/java/de/intarsys/nativec/api/INativeFunction.java
index 6e81ec4..233ef10 100644
--- a/src/de/intarsys/nativec/api/INativeFunction.java
+++ b/nativec-api/src/main/java/de/intarsys/nativec/api/INativeFunction.java
@@ -1,20 +1,23 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
- *
+ *
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
- *
+ *
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* - Neither the name of intarsys nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -26,25 +29,21 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
+ * #L%
*/
package de.intarsys.nativec.api;
-
-/**
- * The representation of a native function.
- */
public interface INativeFunction {
- public static final Object CallingConventionCdecl = new Object();
- public static final Object CallingConventionStdcall = new Object();
+ Object CallingConventionCdecl = new Object();
+ Object CallingConventionStdcall = new Object();
- /**
- * Invoke the native function.
- *
- * @param returnType
- * The expected return type.
- * @param objects
- * The arguments to the function
- * @return The result of executing the function
- */
- public
+ * You can not access bytes from outside the range defined by getAdddress +
+ * size.
+ */
+ int getSize();
+
+ /**
+ * Set the valid size for the handle to
+ * You can not access bytes from outside the range defined by getAdddress +
+ * size.
+ *
+ * @param count The size of the memory managed by the {@link INativeHandle}
+ */
+ void setSize(int count);
+
+ /**
+ * Marshal the data at byte offset
+ * There is no special handling for the 0 address!
+ *
+ * @param address The function pointer.
+ *
+ * @return The function object.
+ */
+ INativeFunction createFunction(long address);
+
+ INativeFunction createFunction(long address, Object callingConvention);
+
+ /**
+ * Create a void {@link INativeHandle} to a memory address.
+ *
+ * There is no special handling for the 0 address!
+ *
+ * @param address The memory address.
+ *
+ * @return The handle to the memory address.
+ */
+ INativeHandle createHandle(long address);
+
+ /**
+ * Load a new {@link INativeLibrary}.
+ *
+ * @param name The name of the library to load.
+ *
+ * @return The new {@link INativeLibrary}
+ */
+ INativeLibrary createLibrary(String name);
+
+ /**
+ * Load a new {@link INativeLibrary}.
+ *
+ * @param name The name of the library to load.
+ * @param callingConvention The calling convention to use as default for functions in this
+ * library.
+ *
+ * @return The new {@link INativeLibrary}
+ */
+ INativeLibrary createLibrary(String name, Object callingConvention);
+
+ /**
+ * The platform long size.
+ *
+ * @return The platform long size.
+ */
+ int longSize();
+
+ /**
+ * The platform pointer size.
+ *
+ * @return The platform pointer size.
+ */
+ int pointerSize();
+
+ /**
+ * The platform wide char size.
+ *
+ * @return The platform wide char size.
+ */
+ int wideCharSize();
+}
diff --git a/src/de/intarsys/nativec/api/INativeLibrary.java b/nativec-api/src/main/java/de/intarsys/nativec/api/INativeLibrary.java
similarity index 74%
rename from src/de/intarsys/nativec/api/INativeLibrary.java
rename to nativec-api/src/main/java/de/intarsys/nativec/api/INativeLibrary.java
index 7d8b474..3e01517 100644
--- a/src/de/intarsys/nativec/api/INativeLibrary.java
+++ b/nativec-api/src/main/java/de/intarsys/nativec/api/INativeLibrary.java
@@ -1,20 +1,23 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
- *
+ *
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
- *
+ *
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* - Neither the name of intarsys nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -26,29 +29,26 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
+ * #L%
*/
package de.intarsys.nativec.api;
-
-/**
- * A native library (DLL or shared library).
- *
- */
public interface INativeLibrary {
- /**
- * Lookup a {@link INativeFunction} from the library.
- *
- * @param name
- * The function name
- * @return The {@link INativeFunction}
- */
- public INativeFunction getFunction(String name);
- /**
- * Lookup a global in the library.
- *
- * @param symbolName
- * The global name
- * @return The {@link INativeHandle} to the global.
- */
- public INativeHandle getGlobal(String symbolName);
+ /**
+ * Lookup a {@link INativeFunction} from the library.
+ *
+ * @param name The function name
+ *
+ * @return The {@link INativeFunction}
+ */
+ INativeFunction getFunction(String name);
+
+ /**
+ * Lookup a global in the library.
+ *
+ * @param symbolName The global name
+ *
+ * @return The {@link INativeHandle} to the global.
+ */
+ INativeHandle getGlobal(String symbolName);
}
diff --git a/src/de/intarsys/nativec/api/IValueHolder.java b/nativec-api/src/main/java/de/intarsys/nativec/api/IValueHolder.java
similarity index 80%
rename from src/de/intarsys/nativec/api/IValueHolder.java
rename to nativec-api/src/main/java/de/intarsys/nativec/api/IValueHolder.java
index 5f503ef..e2c2695 100644
--- a/src/de/intarsys/nativec/api/IValueHolder.java
+++ b/nativec-api/src/main/java/de/intarsys/nativec/api/IValueHolder.java
@@ -1,20 +1,23 @@
-/*
- * Copyright (c) 2007, intarsys consulting GmbH
- *
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
- *
+ *
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
- *
+ *
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* - Neither the name of intarsys nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -26,26 +29,24 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
+ * #L%
*/
package de.intarsys.nativec.api;
-
-/**
- * Generic interface for objects holding references to others.
- */
public interface IValueHolder
+ Here we define the API's and the VM singleton access to native c.
+
+ The component itself was built, as we didn't (once again) find anything
+ around that satisfied our needs. We wanted:
+
- * The {@link INativeObject} has a reference to c memory (the
- * {@link INativeHandle} and "marshalling" methods "getValue" and "setValue" to
- * get and set the Java representation.
- *
- */
-public interface INativeObject {
+ /**
+ * Create an array type from this.
+ *
+ * @param size The predefined size for the array.
+ *
+ * @return The derived type.
+ */
+ INativeType Array(int size);
- /**
- * The bytes that make up the {@link INativeObject}.
- *
- * @return The bytes that make up the {@link INativeObject}.
- */
- public byte[] getBytes();
+ /**
+ * Create an {@link INativeObject} for this type from the Java object.
+ *
+ * @param value
+ *
+ * @return The new {@link INativeObject}
+ */
+ INativeObject createNative(Object value);
- /**
- * The {@link INativeHandle} to the c memory for the object.
- *
- * @return The {@link INativeHandle} to the c memory for the object.
- */
- public INativeHandle getNativeHandle();
+ /**
+ * Create a new {@link INativeObject} from a {@link INativeHandle}.
+ *
+ * @param handle The handle to memory.
+ *
+ * @return The new {@link INativeObject}
+ */
+ INativeObject createNative(INativeHandle handle);
- /**
- * The {@link INativeType} for the object.
- *
- * @return The {@link INativeType} for the object.
- */
- public INativeType getNativeType();
+ /**
+ * The boundary where this type as a struct member would want to be aligned.
+ * A structure can override this value with packing.
+ *
+ * @return The preferred alignment boundary.
+ */
+ int getPreferredBoundary();
- /**
- * A Java side representation from the memory.
- *
- * @return A Java side representation for the {@link INativeObject}.
- */
- public Object getValue();
+ /**
+ * The size of the type in c memory.
+ *
+ * @return The size of the type in c memory.
+ */
+ int getByteCount();
- /**
- * Assign (and marshall to memory) the Java side representation.
- *
- * @param value
- * The new Java value.
- */
- public void setValue(Object value);
+ /**
+ * Create a reference type to this.
+ *
+ * @return The derived type.
+ */
+ INativeType Ref();
}
diff --git a/src/de/intarsys/nativec/type/NativeAbstractStringType.java b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeAbstractStringType.java
similarity index 65%
rename from src/de/intarsys/nativec/type/NativeAbstractStringType.java
rename to nativec-api/src/main/java/de/intarsys/nativec/type/NativeAbstractStringType.java
index 887ef1d..2fcf203 100644
--- a/src/de/intarsys/nativec/type/NativeAbstractStringType.java
+++ b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeAbstractStringType.java
@@ -1,20 +1,23 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
- *
+ *
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
- *
+ *
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* - Neither the name of intarsys nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -26,49 +29,45 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
+ * #L%
*/
package de.intarsys.nativec.type;
import de.intarsys.nativec.api.NativeInterface;
-
-/**
- * A meta class implementation
- */
public class NativeAbstractStringType extends NativeType {
- private final int characterSize;
- private final int stringSize;
-
- protected NativeAbstractStringType(int pCharacterSize) {
- super();
- characterSize = pCharacterSize;
- stringSize = 0;
- }
+ private final int characterSize;
+ private final int stringSize;
- protected NativeAbstractStringType(int pStringSize, int pCharacterSize) {
- super();
- characterSize = pCharacterSize;
- stringSize = pStringSize;
- }
+ protected NativeAbstractStringType(int pCharacterSize) {
+ super();
+ characterSize = pCharacterSize;
+ stringSize = 0;
+ }
- @Override
- public int getByteCount() {
- if (stringSize == 0) {
- throw new IllegalStateException();
- }
- return stringSize * characterSize;
- }
+ protected NativeAbstractStringType(int pStringSize, int pCharacterSize) {
+ super();
+ characterSize = pCharacterSize;
+ stringSize = pStringSize;
+ }
- public int getPreferredBoundary() {
- return NativeInterface.get().pointerSize();
- }
+ @Override
+ public int getByteCount() {
+ if (stringSize == 0) {
+ throw new IllegalStateException();
+ }
+ return stringSize * characterSize;
+ }
- public int getStringSize() {
- return stringSize;
- }
+ public int getPreferredBoundary() {
+ return NativeInterface.get().pointerSize();
+ }
- public boolean hasByteCount() {
- return stringSize != 0;
- }
+ public int getStringSize() {
+ return stringSize;
+ }
-}
\ No newline at end of file
+ public boolean hasByteCount() {
+ return stringSize != 0;
+ }
+}
diff --git a/nativec-api/src/main/java/de/intarsys/nativec/type/NativeArray.java b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeArray.java
new file mode 100644
index 0000000..c54d57e
--- /dev/null
+++ b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeArray.java
@@ -0,0 +1,176 @@
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * #L%
+ */
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
+public class NativeArray extends NativeObject {
+
+ /**
+ * The meta class instance
+ */
+ public static final NativeArrayType META = new NativeArrayType(
+ NativeVoid.META, 0);
+
+ static {
+ NativeType.register(NativeArray.class, META);
+ }
+
+ private INativeObject[] values;
+ private NativeArrayType type;
+
+ protected NativeArray(NativeArrayType type) {
+ this.type = type;
+ allocate();
+ }
+
+ protected NativeArray(NativeArrayType type, INativeHandle handle) {
+ super(handle);
+ this.type = type;
+ }
+
+ public static NativeArray create(INativeType baseType, int size) {
+ NativeArrayType type = new NativeArrayType(baseType, size);
+ return new NativeArray(type);
+ }
+
+ public INativeType getBaseType() {
+ return type.getBaseType();
+ }
+
+ public void setBaseType(INativeType baseType) {
+ type = NativeArrayType.create(baseType, type.getArraySize());
+ this.values = null;
+ handle.setSize(getByteCount());
+ }
+
+ @Override
+ public int getByteCount() {
+ return type.getByteCount();
+ }
+
+ /**
+ * The {@link INativeObject} at index in the sequence (the index'th element
+ * of the array).
+ *
+ * @param index The index of the element to be reported.
+ *
+ * @return The NativeObject at index
+ */
+ synchronized public INativeObject getNativeObject(int index) {
+ if (values == null) {
+ values = new INativeObject[getSize()];
+ }
+ INativeObject result = values[index];
+ if (result == null) {
+ int elementOffset = index * type.getBaseSize();
+ result = type.getBaseType().createNative(
+ handle.offset(elementOffset));
+ values[index] = result;
+ }
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see de.intarsys.graphic.freetype.NativeObject#getMetaClass()
+ */
+ @Override
+ public INativeType getNativeType() {
+ return type;
+ }
+
+ /**
+ * The number of NativeObject instances in the sequence represented by this
+ * (in other terms the array size).
+ *
+ * @return The number of NativeObject instances in the sequence represented
+ * by this
+ */
+ public int getSize() {
+ return type.getArraySize();
+ }
+
+ public void setSize(int size) {
+ type = NativeArrayType.create(type.getBaseType(), size);
+ this.values = null;
+ handle.setSize(getByteCount());
+ }
+
+ public Object getValue() {
+ throw new UnsupportedOperationException(
+ "getValue not implemented for NativeArray");
+ }
+
+ public void setValue(Object value) {
+ throw new UnsupportedOperationException(
+ "setValue not implemented for NativeArray");
+ }
+
+ public Object getValue(int index) {
+ return getNativeObject(index).getValue();
+ }
+
+ public void setValue(int index, Object value) {
+ getNativeObject(index).setValue(value);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see de.intarsys.graphic.freetype.NativeObject#toNestedString()
+ */
+ @Override
+ public String toNestedString() {
+ return "[...]";
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("[");
+ for (int i = 0; i < getSize(); i++) {
+ // NativeObject element = get(i);
+ // sb.append(element.toString());
+ // sb.append(", ");
+ }
+ sb.append("]");
+ return sb.toString();
+ }
+}
diff --git a/src/de/intarsys/nativec/type/NativeArrayType.java b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeArrayType.java
similarity index 53%
rename from src/de/intarsys/nativec/type/NativeArrayType.java
rename to nativec-api/src/main/java/de/intarsys/nativec/type/NativeArrayType.java
index 361f132..ee19103 100644
--- a/src/de/intarsys/nativec/type/NativeArrayType.java
+++ b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeArrayType.java
@@ -1,20 +1,23 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
- *
+ *
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
- *
+ *
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* - Neither the name of intarsys nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -26,74 +29,68 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
+ * #L%
*/
package de.intarsys.nativec.type;
import de.intarsys.nativec.api.INativeHandle;
-
-/**
- * The type for a {@link NativeArray}
- */
public class NativeArrayType extends NativeType {
- public static NativeArrayType create(INativeType baseType, int size) {
- return new NativeArrayType(baseType, size);
- }
-
- private final int arraySize;
-
- /**
- * The size of the base type of the array.
- */
- private final int baseSize;
-
- /**
- * The base type of the array.
- */
- private final INativeType baseType;
+ private final int arraySize;
+ /**
+ * The size of the base type of the array.
+ */
+ private final int baseSize;
+ /**
+ * The base type of the array.
+ */
+ private final INativeType baseType;
- protected NativeArrayType(INativeType baseDeclaration, int arraySize) {
- super();
- this.baseType = baseDeclaration;
- this.baseSize = baseDeclaration.getByteCount();
- this.arraySize = arraySize;
- }
+ protected NativeArrayType(INativeType baseDeclaration, int arraySize) {
+ super();
+ this.baseType = baseDeclaration;
+ this.baseSize = baseDeclaration.getByteCount();
+ this.arraySize = arraySize;
+ }
- @Override
- public INativeObject createNative(INativeHandle handle) {
- NativeArray array = new NativeArray(this, handle);
- if (arraySize > 0) {
- array.setSize(arraySize);
- }
- return array;
- }
+ public static NativeArrayType create(INativeType baseType, int size) {
+ return new NativeArrayType(baseType, size);
+ }
- @Override
- public INativeObject createNative(Object value) {
- NativeArray array = new NativeArray(this);
- return array;
- }
+ @Override
+ public INativeObject createNative(INativeHandle handle) {
+ NativeArray array = new NativeArray(this, handle);
+ if (arraySize > 0) {
+ array.setSize(arraySize);
+ }
+ return array;
+ }
- public int getArraySize() {
- return arraySize;
- }
+ @Override
+ public INativeObject createNative(Object value) {
+ NativeArray array = new NativeArray(this);
+ return array;
+ }
- public int getBaseSize() {
- return baseSize;
- }
+ public int getArraySize() {
+ return arraySize;
+ }
- public INativeType getBaseType() {
- return baseType;
- }
+ public int getBaseSize() {
+ return baseSize;
+ }
- @Override
- public int getByteCount() {
- // todo take into account alignment / packing?
- return arraySize * baseSize;
- }
+ public INativeType getBaseType() {
+ return baseType;
+ }
- public int getPreferredBoundary() {
- return baseType.getPreferredBoundary();
- }
+ @Override
+ public int getByteCount() {
+ // todo take into account alignment / packing?
+ return arraySize * baseSize;
+ }
+ public int getPreferredBoundary() {
+ return baseType.getPreferredBoundary();
+ }
}
diff --git a/nativec-api/src/main/java/de/intarsys/nativec/type/NativeBuffer.java b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeBuffer.java
new file mode 100644
index 0000000..576b5b2
--- /dev/null
+++ b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeBuffer.java
@@ -0,0 +1,117 @@
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * #L%
+ */
+package de.intarsys.nativec.type;
+
+import java.nio.ByteBuffer;
+
+import de.intarsys.nativec.api.INativeHandle;
+import de.intarsys.nativec.api.NativeInterface;
+public class NativeBuffer extends NativeObject {
+
+ /**
+ * The meta class instance
+ */
+ public static final NativeBufferType META = new NativeBufferType();
+
+ static {
+ NativeType.register(NativeBuffer.class, META);
+ }
+
+ private NativeBufferType type;
+
+ public NativeBuffer(byte[] bytes) {
+ type = new NativeBufferType(bytes.length);
+ handle = NativeInterface.get().allocate(bytes.length);
+ handle.setByteArray(0, bytes, 0, bytes.length);
+ }
+
+ protected NativeBuffer(INativeHandle handle) {
+ super(handle);
+ }
+
+ public NativeBuffer(int pSize) {
+ type = new NativeBufferType(pSize);
+ handle = NativeInterface.get().allocate(pSize);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see de.intarsys.tools.nativec.NativeObject#getByteCount()
+ */
+ @Override
+ public int getByteCount() {
+ // todo alignment?
+ return type.getByteCount();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see de.intarsys.graphic.freetype.NativeObject#getMetaClass()
+ */
+ @Override
+ public INativeType getNativeType() {
+ return META;
+ }
+
+ /**
+ * The number of elements in the NativeBuffer
+ *
+ * @return The number of elements in the NativeBuffer
+ */
+ public int getSize() {
+ return type.getByteCount();
+ }
+
+ public void setSize(int size) {
+ type = new NativeBufferType(size);
+ handle.setSize(getByteCount());
+ }
+
+ public Object getValue() {
+ return getBytes();
+ }
+
+ public void setValue(Object value) {
+ if (value instanceof byte[]) {
+ byte[] data = (byte[]) value;
+ setByteArray(0, data, 0, data.length);
+ } else if (value instanceof ByteBuffer) {
+ byte[] data = new byte[getSize()];
+ ((ByteBuffer) value).get(data);
+ setByteArray(0, data, 0, data.length);
+ }
+ }
+}
diff --git a/src/de/intarsys/nativec/type/NativeBufferType.java b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeBufferType.java
similarity index 64%
rename from src/de/intarsys/nativec/type/NativeBufferType.java
rename to nativec-api/src/main/java/de/intarsys/nativec/type/NativeBufferType.java
index 0c8e1ae..1b1673e 100644
--- a/src/de/intarsys/nativec/type/NativeBufferType.java
+++ b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeBufferType.java
@@ -1,20 +1,23 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
- *
+ *
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
- *
+ *
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* - Neither the name of intarsys nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -26,54 +29,50 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
+ * #L%
*/
package de.intarsys.nativec.type;
import de.intarsys.nativec.api.INativeHandle;
-
-/**
- * The meta class implementation
- */
public class NativeBufferType extends NativeType {
- public static NativeBufferType create(int size) {
- return new NativeBufferType(size);
- }
-
- final private int bufferSize;
+ final private int bufferSize;
- protected NativeBufferType() {
- super();
- this.bufferSize = 0;
- }
+ protected NativeBufferType() {
+ super();
+ this.bufferSize = 0;
+ }
- protected NativeBufferType(int bufferSize) {
- super();
- this.bufferSize = bufferSize;
- }
+ protected NativeBufferType(int bufferSize) {
+ super();
+ this.bufferSize = bufferSize;
+ }
- @Override
- public INativeObject createNative(INativeHandle handle) {
- NativeBuffer buffer;
+ public static NativeBufferType create(int size) {
+ return new NativeBufferType(size);
+ }
- buffer = new NativeBuffer(handle);
- // setSize() creates a new type object
- // TODO create constructor to use the existing one?
- buffer.setSize(bufferSize);
- return buffer;
- }
+ @Override
+ public INativeObject createNative(INativeHandle handle) {
+ NativeBuffer buffer;
- public int getBufferSize() {
- return bufferSize;
- }
+ buffer = new NativeBuffer(handle);
+ // setSize() creates a new type object
+ // TODO create constructor to use the existing one?
+ buffer.setSize(bufferSize);
+ return buffer;
+ }
- @Override
- public int getByteCount() {
- return bufferSize;
- }
+ public int getBufferSize() {
+ return bufferSize;
+ }
- public int getPreferredBoundary() {
- return 1;
- }
+ @Override
+ public int getByteCount() {
+ return bufferSize;
+ }
-}
\ No newline at end of file
+ public int getPreferredBoundary() {
+ return 1;
+ }
+}
diff --git a/src/de/intarsys/nativec/type/NativeByte.java b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeByte.java
similarity index 50%
rename from src/de/intarsys/nativec/type/NativeByte.java
rename to nativec-api/src/main/java/de/intarsys/nativec/type/NativeByte.java
index e92bb98..caa6d28 100644
--- a/src/de/intarsys/nativec/type/NativeByte.java
+++ b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeByte.java
@@ -1,20 +1,23 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
- *
+ *
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
- *
+ *
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* - Neither the name of intarsys nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -26,96 +29,94 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
+ * #L%
*/
package de.intarsys.nativec.type;
import de.intarsys.nativec.api.INativeHandle;
import de.intarsys.nativec.api.NativeTools;
-
-/**
- * A wrapper for a primitive byte.
- *
- */
public class NativeByte extends NativeNumber {
- /** The meta class instance */
- public static final NativeByteType META = new NativeByteType();
-
- static {
- NativeType.register(NativeByte.class, META);
- }
-
- static public NativeByte createFromAddress(long address) {
- return (NativeByte) NativeByte.META.createNative(NativeTools
- .toHandle(address));
- }
-
- /**
- * Create a new wrapper
- */
- public NativeByte() {
- allocate();
- }
-
- /**
- * Create a new wrapper
- */
- public NativeByte(byte value) {
- allocate();
- setValue(value);
- }
-
- protected NativeByte(INativeHandle handle) {
- super(handle);
- }
-
- @Override
- public byte byteValue() {
- return handle.getByte(0);
- }
-
- @Override
- public INativeType getNativeType() {
- return META;
- }
-
- @Override
- public Object getValue() {
- return new Byte(byteValue());
- }
-
- @Override
- public int intValue() {
- return byteValue();
- }
-
- @Override
- public long longValue() {
- return byteValue();
- }
-
- public void setValue(byte value) {
- handle.setByte(0, value);
- }
-
- @Override
- public void setValue(Object value) {
- setValue(((Number) value).byteValue());
- }
-
- @Override
- public short shortValue() {
- return byteValue();
- }
-
- @Override
- public String toString() {
- if (getNativeHandle() == null) {
- return "nope - no handle"; //$NON-NLS-1$
- }
- if (getNativeHandle().getAddress() == 0) {
- return "nope - null pointer"; //$NON-NLS-1$
- }
- return String.valueOf(byteValue());
- }
+ /**
+ * The meta class instance
+ */
+ public static final NativeByteType META = new NativeByteType();
+
+ static {
+ NativeType.register(NativeByte.class, META);
+ }
+
+ /**
+ * Create a new wrapper
+ */
+ public NativeByte() {
+ allocate();
+ }
+
+ /**
+ * Create a new wrapper
+ */
+ public NativeByte(byte value) {
+ allocate();
+ setValue(value);
+ }
+
+ protected NativeByte(INativeHandle handle) {
+ super(handle);
+ }
+
+ static public NativeByte createFromAddress(long address) {
+ return (NativeByte) NativeByte.META.createNative(NativeTools
+ .toHandle(address));
+ }
+
+ @Override
+ public byte byteValue() {
+ return handle.getByte(0);
+ }
+
+ @Override
+ public INativeType getNativeType() {
+ return META;
+ }
+
+ @Override
+ public Object getValue() {
+ return new Byte(byteValue());
+ }
+
+ public void setValue(byte value) {
+ handle.setByte(0, value);
+ }
+
+ @Override
+ public void setValue(Object value) {
+ setValue(((Number) value).byteValue());
+ }
+
+ @Override
+ public int intValue() {
+ return byteValue();
+ }
+
+ @Override
+ public long longValue() {
+ return byteValue();
+ }
+
+ @Override
+ public short shortValue() {
+ return byteValue();
+ }
+
+ @Override
+ public String toString() {
+ if (getNativeHandle() == null) {
+ return "nope - no handle"; //$NON-NLS-1$
+ }
+ if (getNativeHandle().getAddress() == 0) {
+ return "nope - null pointer"; //$NON-NLS-1$
+ }
+ return String.valueOf(byteValue());
+ }
}
diff --git a/src/de/intarsys/nativec/type/NativeByteType.java b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeByteType.java
similarity index 76%
rename from src/de/intarsys/nativec/type/NativeByteType.java
rename to nativec-api/src/main/java/de/intarsys/nativec/type/NativeByteType.java
index e446a6b..076ec2e 100644
--- a/src/de/intarsys/nativec/type/NativeByteType.java
+++ b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeByteType.java
@@ -1,20 +1,23 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
- *
+ *
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
- *
+ *
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* - Neither the name of intarsys nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -26,32 +29,29 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
+ * #L%
*/
package de.intarsys.nativec.type;
import de.intarsys.nativec.api.INativeHandle;
-
-/**
- * The meta class implementation
- */
public class NativeByteType extends NativeNumberType {
- protected NativeByteType() {
- super();
- }
+ protected NativeByteType() {
+ super();
+ }
- @Override
- public INativeObject createNative(INativeHandle handle) {
- return new NativeByte(handle);
- }
+ @Override
+ public INativeObject createNative(INativeHandle handle) {
+ return new NativeByte(handle);
+ }
- @Override
- public INativeObject createNative(Object value) {
- return new NativeByte(((Number) value).byteValue());
- }
+ @Override
+ public INativeObject createNative(Object value) {
+ return new NativeByte(((Number) value).byteValue());
+ }
- @Override
- public int getByteCount() {
- return NativeByte.SIZE_BYTE;
- }
-}
\ No newline at end of file
+ @Override
+ public int getByteCount() {
+ return NativeByte.SIZE_BYTE;
+ }
+}
diff --git a/nativec-api/src/main/java/de/intarsys/nativec/type/NativeFunction.java b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeFunction.java
new file mode 100644
index 0000000..48cbc91
--- /dev/null
+++ b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeFunction.java
@@ -0,0 +1,77 @@
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * #L%
+ */
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeFunction;
+import de.intarsys.nativec.api.INativeHandle;
+import de.intarsys.nativec.api.NativeInterface;
+
+public class NativeFunction extends NativeVoid {
+
+ public static final NativeFunctionType META = new NativeFunctionType();
+ private Object callingConvention;
+ private INativeFunction function;
+ protected NativeFunction(INativeHandle handle) {
+ super(handle);
+ callingConvention = INativeFunction.CallingConventionCdecl;
+ }
+
+ public Object getCallingConvention() {
+ return callingConvention;
+ }
+
+ public void setCallingConvention(Object callingConvention) {
+ if (function != null) {
+ throw new IllegalStateException();
+ }
+ this.callingConvention = callingConvention;
+ }
+
+ public INativeFunction getFunction() {
+ // TODO do we want to check if handle has changed?
+ if (function == null) {
+ function = NativeInterface.get().createFunction(
+ getNativeHandle().getAddress(), callingConvention);
+ }
+ return function;
+ }
+
+ public static class NativeFunctionType extends NativeVoidType {
+
+ @Override
+ public INativeObject createNative(INativeHandle handle) {
+ return new NativeFunction(handle);
+ }
+ }
+}
diff --git a/src/de/intarsys/nativec/type/NativeGenericStruct.java b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeGenericStruct.java
similarity index 71%
rename from src/de/intarsys/nativec/type/NativeGenericStruct.java
rename to nativec-api/src/main/java/de/intarsys/nativec/type/NativeGenericStruct.java
index e894a52..88bdd2c 100644
--- a/src/de/intarsys/nativec/type/NativeGenericStruct.java
+++ b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeGenericStruct.java
@@ -1,20 +1,23 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
- *
+ *
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
- *
+ *
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* - Neither the name of intarsys nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -26,43 +29,38 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
+ * #L%
*/
package de.intarsys.nativec.type;
import de.intarsys.nativec.api.INativeHandle;
-
-/**
- * The generic struct may change its type at runtime.
- *
- */
public class NativeGenericStruct extends NativeStruct {
- private NativeStructType type;
-
- protected NativeGenericStruct(NativeStructType type) {
- super();
- this.type = type;
- allocate();
- }
+ private NativeStructType type;
- protected NativeGenericStruct(NativeStructType type, INativeHandle handle) {
- super(handle);
- this.type = type;
- }
+ protected NativeGenericStruct(NativeStructType type) {
+ super();
+ this.type = type;
+ allocate();
+ }
- @Override
- public INativeType getNativeType() {
- return type;
- }
+ protected NativeGenericStruct(NativeStructType type, INativeHandle handle) {
+ super(handle);
+ this.type = type;
+ }
- @Override
- public NativeStructType getStructType() {
- return type;
- }
+ @Override
+ public INativeType getNativeType() {
+ return type;
+ }
- public void setNativeType(NativeStructType type) {
- this.type = type;
- this.values = null;
- }
+ public void setNativeType(NativeStructType type) {
+ this.type = type;
+ this.values = null;
+ }
+ @Override
+ public NativeStructType getStructType() {
+ return type;
+ }
}
diff --git a/src/de/intarsys/nativec/type/NativeInt.java b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeInt.java
similarity index 50%
rename from src/de/intarsys/nativec/type/NativeInt.java
rename to nativec-api/src/main/java/de/intarsys/nativec/type/NativeInt.java
index e87ec2a..a469874 100644
--- a/src/de/intarsys/nativec/type/NativeInt.java
+++ b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeInt.java
@@ -1,20 +1,23 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
- *
+ *
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
- *
+ *
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* - Neither the name of intarsys nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -26,96 +29,94 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
+ * #L%
*/
package de.intarsys.nativec.type;
import de.intarsys.nativec.api.INativeHandle;
import de.intarsys.nativec.api.NativeTools;
-
-/**
- * A wrapper for a primitive int (which is always 4 bytes except on ILP64
- * systems which can be treated as non-existent for our purposes).
- */
public class NativeInt extends NativeNumber {
- /** The meta class instance */
- public static final NativeIntType META = new NativeIntType();
-
- static {
- NativeType.register(NativeInt.class, META);
- }
-
- static public NativeInt createFromAddress(long address) {
- return (NativeInt) NativeInt.META.createNative(NativeTools
- .toHandle(address));
- }
-
- /**
- * Create a new wrapper
- */
- public NativeInt() {
- allocate();
- }
-
- protected NativeInt(INativeHandle handle) {
- super(handle);
- }
-
- /**
- * Create a new wrapper
- */
- public NativeInt(long value) {
- allocate();
- setValue(value);
- }
-
- @Override
- public byte byteValue() {
- return (byte) intValue();
- }
-
- @Override
- public INativeType getNativeType() {
- return META;
- }
-
- @Override
- public Object getValue() {
- return new Integer(intValue());
- }
-
- @Override
- public int intValue() {
- return handle.getInt(0);
- }
-
- @Override
- public long longValue() {
- return intValue();
- }
-
- public void setValue(int value) {
- handle.setInt(0, value);
- }
-
- @Override
- public void setValue(Object value) {
- setValue(((Number) value).intValue());
- }
-
- @Override
- public short shortValue() {
- return (short) intValue();
- }
-
- @Override
- public String toString() {
- if (getNativeHandle() == null) {
- return "nope - no handle"; //$NON-NLS-1$
- }
- if (getNativeHandle().getAddress() == 0) {
- return "nope - null pointer"; //$NON-NLS-1$
- }
- return String.valueOf(intValue());
- }
+ /**
+ * The meta class instance
+ */
+ public static final NativeIntType META = new NativeIntType();
+
+ static {
+ NativeType.register(NativeInt.class, META);
+ }
+
+ /**
+ * Create a new wrapper
+ */
+ public NativeInt() {
+ allocate();
+ }
+
+ protected NativeInt(INativeHandle handle) {
+ super(handle);
+ }
+
+ /**
+ * Create a new wrapper
+ */
+ public NativeInt(long value) {
+ allocate();
+ setValue(value);
+ }
+
+ static public NativeInt createFromAddress(long address) {
+ return (NativeInt) NativeInt.META.createNative(NativeTools
+ .toHandle(address));
+ }
+
+ @Override
+ public byte byteValue() {
+ return (byte) intValue();
+ }
+
+ @Override
+ public INativeType getNativeType() {
+ return META;
+ }
+
+ @Override
+ public Object getValue() {
+ return new Integer(intValue());
+ }
+
+ public void setValue(int value) {
+ handle.setInt(0, value);
+ }
+
+ @Override
+ public void setValue(Object value) {
+ setValue(((Number) value).intValue());
+ }
+
+ @Override
+ public int intValue() {
+ return handle.getInt(0);
+ }
+
+ @Override
+ public long longValue() {
+ return intValue();
+ }
+
+ @Override
+ public short shortValue() {
+ return (short) intValue();
+ }
+
+ @Override
+ public String toString() {
+ if (getNativeHandle() == null) {
+ return "nope - no handle"; //$NON-NLS-1$
+ }
+ if (getNativeHandle().getAddress() == 0) {
+ return "nope - null pointer"; //$NON-NLS-1$
+ }
+ return String.valueOf(intValue());
+ }
}
diff --git a/src/de/intarsys/nativec/type/NativeIntType.java b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeIntType.java
similarity index 76%
rename from src/de/intarsys/nativec/type/NativeIntType.java
rename to nativec-api/src/main/java/de/intarsys/nativec/type/NativeIntType.java
index 45b55cf..211f6ce 100644
--- a/src/de/intarsys/nativec/type/NativeIntType.java
+++ b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeIntType.java
@@ -1,20 +1,23 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
- *
+ *
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
- *
+ *
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* - Neither the name of intarsys nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -26,32 +29,29 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
+ * #L%
*/
package de.intarsys.nativec.type;
import de.intarsys.nativec.api.INativeHandle;
-
-/**
- * The meta class implementation
- */
public class NativeIntType extends NativeNumberType {
- protected NativeIntType() {
- super();
- }
+ protected NativeIntType() {
+ super();
+ }
- @Override
- public INativeObject createNative(INativeHandle handle) {
- return new NativeInt(handle);
- }
+ @Override
+ public INativeObject createNative(INativeHandle handle) {
+ return new NativeInt(handle);
+ }
- @Override
- public INativeObject createNative(Object value) {
- return new NativeInt(((Number) value).longValue());
- }
+ @Override
+ public INativeObject createNative(Object value) {
+ return new NativeInt(((Number) value).longValue());
+ }
- @Override
- public int getByteCount() {
- return NativeInt.SIZE_INT;
- }
-}
\ No newline at end of file
+ @Override
+ public int getByteCount() {
+ return NativeInt.SIZE_INT;
+ }
+}
diff --git a/src/de/intarsys/nativec/type/NativeLong.java b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeLong.java
similarity index 50%
rename from src/de/intarsys/nativec/type/NativeLong.java
rename to nativec-api/src/main/java/de/intarsys/nativec/type/NativeLong.java
index 319cdc3..e8bbe3f 100644
--- a/src/de/intarsys/nativec/type/NativeLong.java
+++ b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeLong.java
@@ -1,20 +1,23 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
- *
+ *
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
- *
+ *
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* - Neither the name of intarsys nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -26,96 +29,94 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
+ * #L%
*/
package de.intarsys.nativec.type;
import de.intarsys.nativec.api.INativeHandle;
import de.intarsys.nativec.api.NativeTools;
-
-/**
- * A wrapper for a primitive long. The size of a long depends on the platform;
- * on a 64-bit Linux or Mac OS X we have 8 byte longs...
- */
public class NativeLong extends NativeNumber {
- /** The meta class instance */
- public static final NativeLongType META = new NativeLongType();
-
- static {
- NativeType.register(NativeLong.class, META);
- }
-
- static public NativeLong createFromAddress(long address) {
- return (NativeLong) NativeLong.META.createNative(NativeTools
- .toHandle(address));
- }
-
- /**
- * Create a new wrapper
- */
- public NativeLong() {
- allocate();
- }
-
- protected NativeLong(INativeHandle handle) {
- super(handle);
- }
-
- /**
- * Create a new wrapper
- */
- public NativeLong(long value) {
- allocate();
- setValue(value);
- }
-
- @Override
- public byte byteValue() {
- return (byte) intValue();
- }
-
- @Override
- public INativeType getNativeType() {
- return META;
- }
-
- @Override
- public Object getValue() {
- return new Long(longValue());
- }
-
- @Override
- public int intValue() {
- return (int) longValue();
- }
-
- @Override
- public long longValue() {
- return handle.getCLong(0);
- }
-
- public void setValue(long value) {
- handle.setCLong(0, value);
- }
-
- @Override
- public void setValue(Object value) {
- setValue(((Number) value).longValue());
- }
-
- @Override
- public short shortValue() {
- return (short) longValue();
- }
-
- @Override
- public String toString() {
- if (getNativeHandle() == null) {
- return "nope - no handle"; //$NON-NLS-1$
- }
- if (getNativeHandle().getAddress() == 0) {
- return "nope - null pointer"; //$NON-NLS-1$
- }
- return String.valueOf(longValue());
- }
+ /**
+ * The meta class instance
+ */
+ public static final NativeLongType META = new NativeLongType();
+
+ static {
+ NativeType.register(NativeLong.class, META);
+ }
+
+ /**
+ * Create a new wrapper
+ */
+ public NativeLong() {
+ allocate();
+ }
+
+ protected NativeLong(INativeHandle handle) {
+ super(handle);
+ }
+
+ /**
+ * Create a new wrapper
+ */
+ public NativeLong(long value) {
+ allocate();
+ setValue(value);
+ }
+
+ static public NativeLong createFromAddress(long address) {
+ return (NativeLong) NativeLong.META.createNative(NativeTools
+ .toHandle(address));
+ }
+
+ @Override
+ public byte byteValue() {
+ return (byte) intValue();
+ }
+
+ @Override
+ public INativeType getNativeType() {
+ return META;
+ }
+
+ @Override
+ public Object getValue() {
+ return new Long(longValue());
+ }
+
+ public void setValue(long value) {
+ handle.setCLong(0, value);
+ }
+
+ @Override
+ public void setValue(Object value) {
+ setValue(((Number) value).longValue());
+ }
+
+ @Override
+ public int intValue() {
+ return (int) longValue();
+ }
+
+ @Override
+ public long longValue() {
+ return handle.getCLong(0);
+ }
+
+ @Override
+ public short shortValue() {
+ return (short) longValue();
+ }
+
+ @Override
+ public String toString() {
+ if (getNativeHandle() == null) {
+ return "nope - no handle"; //$NON-NLS-1$
+ }
+ if (getNativeHandle().getAddress() == 0) {
+ return "nope - null pointer"; //$NON-NLS-1$
+ }
+ return String.valueOf(longValue());
+ }
}
diff --git a/nativec-api/src/main/java/de/intarsys/nativec/type/NativeLongLP64.java b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeLongLP64.java
new file mode 100644
index 0000000..3d92d75
--- /dev/null
+++ b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeLongLP64.java
@@ -0,0 +1,129 @@
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * #L%
+ */
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
+import de.intarsys.nativec.api.NativeTools;
+public class NativeLongLP64 extends NativeNumber {
+
+ /**
+ * The meta class instance
+ */
+ public static final NativeLongLP64Type META = new NativeLongLP64Type();
+
+ static {
+ NativeType.register(NativeLongLP64.class, META);
+ }
+
+ /**
+ * Create a new wrapper
+ */
+ public NativeLongLP64() {
+ allocate();
+ }
+
+ protected NativeLongLP64(INativeHandle handle) {
+ super(handle);
+ }
+
+ /**
+ * Create a new wrapper
+ */
+ public NativeLongLP64(long value) {
+ allocate();
+ setValue(value);
+ }
+
+ static public NativeLongLP64 createFromAddress(long address) {
+ return (NativeLongLP64) NativeLongLP64.META.createNative(NativeTools
+ .toHandle(address));
+ }
+
+ @Override
+ public byte byteValue() {
+ return (byte) intValue();
+ }
+
+ @Override
+ public INativeType getNativeType() {
+ return META;
+ }
+
+ @Override
+ public Object getValue() {
+ return new Long(longValue());
+ }
+
+ public void setValue(long value) {
+ if (NativeObject.SIZE_PTR == 4) {
+ handle.setInt(0, (int) value);
+ return;
+ }
+ handle.setLong(0, value);
+ }
+
+ @Override
+ public void setValue(Object value) {
+ setValue(((Number) value).longValue());
+ }
+
+ @Override
+ public int intValue() {
+ return (int) longValue();
+ }
+
+ @Override
+ public long longValue() {
+ if (NativeObject.SIZE_PTR == 4) {
+ return handle.getInt(0);
+ }
+ return handle.getLong(0);
+ }
+
+ @Override
+ public short shortValue() {
+ return (short) longValue();
+ }
+
+ @Override
+ public String toString() {
+ if (getNativeHandle() == null) {
+ return "nope - no handle"; //$NON-NLS-1$
+ }
+ if (getNativeHandle().getAddress() == 0) {
+ return "nope - null pointer"; //$NON-NLS-1$
+ }
+ return String.valueOf(longValue());
+ }
+}
diff --git a/src/de/intarsys/nativec/type/NativeLongLP64Type.java b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeLongLP64Type.java
similarity index 61%
rename from src/de/intarsys/nativec/type/NativeLongLP64Type.java
rename to nativec-api/src/main/java/de/intarsys/nativec/type/NativeLongLP64Type.java
index 46eb639..e1235e9 100644
--- a/src/de/intarsys/nativec/type/NativeLongLP64Type.java
+++ b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeLongLP64Type.java
@@ -1,20 +1,23 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
- *
+ *
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
- *
+ *
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* - Neither the name of intarsys nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -26,54 +29,51 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
+ * #L%
*/
package de.intarsys.nativec.type;
import de.intarsys.nativec.api.INativeHandle;
-
-/**
- * The meta class implementation
- */
public class NativeLongLP64Type extends NativeNumberType {
- /**
- * Utility method: return the given number as another number object with
- * compatible byte size
- */
- public static Object coerce(Number value) {
- if (NativeObject.SIZE_PTR == 4) {
- return value.intValue();
- }
- return value.longValue();
- }
+ protected NativeLongLP64Type() {
+ super();
+ }
- /**
- * Utility method: return the java class whose instances have compatible
- * byte size
- */
- public static Class extends Number> primitiveClass() {
- if (NativeObject.SIZE_PTR == 4) {
- return Integer.class;
- }
- return Long.class;
- }
+ /**
+ * Utility method: return the given number as another number object with
+ * compatible byte size
+ */
+ public static Object coerce(Number value) {
+ if (NativeObject.SIZE_PTR == 4) {
+ return value.intValue();
+ }
+ return value.longValue();
+ }
- protected NativeLongLP64Type() {
- super();
- }
+ /**
+ * Utility method: return the java class whose instances have compatible
+ * byte size
+ */
+ public static Class extends Number> primitiveClass() {
+ if (NativeObject.SIZE_PTR == 4) {
+ return Integer.class;
+ }
+ return Long.class;
+ }
- @Override
- public INativeObject createNative(INativeHandle handle) {
- return new NativeLongLP64(handle);
- }
+ @Override
+ public INativeObject createNative(INativeHandle handle) {
+ return new NativeLongLP64(handle);
+ }
- @Override
- public INativeObject createNative(Object value) {
- return new NativeLongLP64(((Number) value).longValue());
- }
+ @Override
+ public INativeObject createNative(Object value) {
+ return new NativeLongLP64(((Number) value).longValue());
+ }
- @Override
- public int getByteCount() {
- return NativeObject.SIZE_PTR;
- }
-}
\ No newline at end of file
+ @Override
+ public int getByteCount() {
+ return NativeObject.SIZE_PTR;
+ }
+}
diff --git a/src/de/intarsys/nativec/type/NativeLongType.java b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeLongType.java
similarity index 76%
rename from src/de/intarsys/nativec/type/NativeLongType.java
rename to nativec-api/src/main/java/de/intarsys/nativec/type/NativeLongType.java
index 0f107d8..271cd5a 100644
--- a/src/de/intarsys/nativec/type/NativeLongType.java
+++ b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeLongType.java
@@ -1,20 +1,23 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
- *
+ *
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
- *
+ *
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* - Neither the name of intarsys nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -26,32 +29,29 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
+ * #L%
*/
package de.intarsys.nativec.type;
import de.intarsys.nativec.api.INativeHandle;
-
-/**
- * The meta class implementation
- */
public class NativeLongType extends NativeNumberType {
- protected NativeLongType() {
- super();
- }
+ protected NativeLongType() {
+ super();
+ }
- @Override
- public INativeObject createNative(INativeHandle handle) {
- return new NativeLong(handle);
- }
+ @Override
+ public INativeObject createNative(INativeHandle handle) {
+ return new NativeLong(handle);
+ }
- @Override
- public INativeObject createNative(Object value) {
- return new NativeLong(((Number) value).longValue());
- }
+ @Override
+ public INativeObject createNative(Object value) {
+ return new NativeLong(((Number) value).longValue());
+ }
- @Override
- public int getByteCount() {
- return NativeLong.SIZE_LONG;
- }
-}
\ No newline at end of file
+ @Override
+ public int getByteCount() {
+ return NativeLong.SIZE_LONG;
+ }
+}
diff --git a/src/de/intarsys/nativec/type/NativeNumber.java b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeNumber.java
similarity index 65%
rename from src/de/intarsys/nativec/type/NativeNumber.java
rename to nativec-api/src/main/java/de/intarsys/nativec/type/NativeNumber.java
index 6259626..4ef3a59 100644
--- a/src/de/intarsys/nativec/type/NativeNumber.java
+++ b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeNumber.java
@@ -1,20 +1,23 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
- *
+ *
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
- *
+ *
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* - Neither the name of intarsys nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -26,51 +29,48 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
+ * #L%
*/
package de.intarsys.nativec.type;
import de.intarsys.nativec.api.INativeHandle;
-
-/**
- * An abstract superclass for the implementation of number
- * {@link NativeSimple}.
- */
public abstract class NativeNumber extends NativeSimple {
- /**
- * Create a wrapper
- */
- protected NativeNumber() {
- }
- protected NativeNumber(INativeHandle handle) {
- super(handle);
- }
+ /**
+ * Create a wrapper
+ */
+ protected NativeNumber() {
+ }
+
+ protected NativeNumber(INativeHandle handle) {
+ super(handle);
+ }
- /**
- * This as a java primitive byte value.
- *
- * @return This as a java primitive byte value.
- */
- public abstract byte byteValue();
+ /**
+ * This as a java primitive byte value.
+ *
+ * @return This as a java primitive byte value.
+ */
+ public abstract byte byteValue();
- /**
- * This as a java primitive int value.
- *
- * @return This as a java primitive int value.
- */
- public abstract int intValue();
+ /**
+ * This as a java primitive int value.
+ *
+ * @return This as a java primitive int value.
+ */
+ public abstract int intValue();
- /**
- * This as a java primitive long value.
- *
- * @return This as a java primitive long value.
- */
- public abstract long longValue();
+ /**
+ * This as a java primitive long value.
+ *
+ * @return This as a java primitive long value.
+ */
+ public abstract long longValue();
- /**
- * This as a java primitive short value.
- *
- * @return This as a java primitive short value.
- */
- public abstract short shortValue();
+ /**
+ * This as a java primitive short value.
+ *
+ * @return This as a java primitive short value.
+ */
+ public abstract short shortValue();
}
diff --git a/src/de/intarsys/nativec/type/NativeNumberType.java b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeNumberType.java
similarity index 89%
rename from src/de/intarsys/nativec/type/NativeNumberType.java
rename to nativec-api/src/main/java/de/intarsys/nativec/type/NativeNumberType.java
index ef64399..c2c6c7c 100644
--- a/src/de/intarsys/nativec/type/NativeNumberType.java
+++ b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeNumberType.java
@@ -1,20 +1,23 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
- *
+ *
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
- *
+ *
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* - Neither the name of intarsys nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -26,15 +29,12 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
+ * #L%
*/
package de.intarsys.nativec.type;
-
-/**
- * The meta class implementation
- */
public class NativeNumberType extends NativeSimpleType {
- protected NativeNumberType() {
- super();
- }
-}
\ No newline at end of file
+ protected NativeNumberType() {
+ super();
+ }
+}
diff --git a/nativec-api/src/main/java/de/intarsys/nativec/type/NativeObject.java b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeObject.java
new file mode 100644
index 0000000..0e67bed
--- /dev/null
+++ b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeObject.java
@@ -0,0 +1,277 @@
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * #L%
+ */
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
+import de.intarsys.nativec.api.NativeInterface;
+public abstract class NativeObject implements INativeObject {
+
+ public static final int SIZE_BYTE = 1;
+
+ public static final int SIZE_INT = 4;
+
+ public static final int SHIFT_INT = 2;
+
+ public static final int SIZE_LONGLONG = 8;
+
+ public static final int SHIFT_LONGLONG = 3;
+
+ public static final int SIZE_LONG = NativeInterface.get().longSize();
+
+ public static final int SHIFT_LONG = SIZE_LONG == 4 ? 2 : 3;
+
+ public static final int SIZE_PTR = NativeInterface.get().pointerSize();
+
+ public static final int SIZE_SHORT = 2;
+
+ /**
+ * DEBUG flag
+ */
+ public static boolean DEBUG = true;
+
+ /**
+ * The handle to the memory chunk used by this object. While in fact this is
+ * final, Java language semantics does not allow to declare so!
+ *
+ * The handle should only be assigned in the constructor, via parameter or
+ * "allocate".
+ */
+ protected INativeHandle handle;
+
+ /**
+ *
+ */
+ protected NativeObject() {
+ //
+ }
+
+ /**
+ * Create a new NativeObject in C-Memory at pointer "handle". The bytes
+ * belonging to this object may already have been copied from C-Memory and
+ * made available in bytes at location offset.
+ *
+ * @param handle The pointer in C-memory
+ */
+ protected NativeObject(INativeHandle handle) {
+ this.handle = handle;
+ }
+
+ /**
+ * Manage the objects memory in Java. C memory will be valid at least as
+ * long as we hold a reference to the buffer. C memory is undefined (but not
+ * a memory leak) and may be reclaimed at any time after dropping our
+ * pointer to the buffer.
+ */
+ protected void allocate() {
+ int size = getByteCount();
+ handle = NativeInterface.get().allocate(size);
+ }
+
+ /**
+ * This is a special form of the "createNative" signature, implementing a
+ * "type cast" on the same memory location.
+ *
+ * @param declaration The new base declaration type.
+ *
+ * @return The {@link INativeObject} at the same memory location as this,
+ * but of a different type.
+ */
+ public INativeObject cast(INativeType declaration) {
+ return declaration.createNative(handle);
+ }
+
+ public INativeObject createReference() {
+ NativeReference ref = NativeReference.create(getNativeType());
+ ref.setValue(this);
+ return ref;
+ }
+
+ /**
+ * The byte at index as a byte.
+ *
+ * @param index The index of the element to be reported.
+ *
+ * @return The element at index as a native byte.
+ */
+ public byte getByte(int index) {
+ return handle.getByte(index);
+ }
+
+ /**
+ * The element at index as an array of bytes with dimension count. This is a
+ * lightweight optimization.
+ *
+ * @param index The index of the element to be reported.
+ *
+ * @return The element at index as an array of native byte with dimension
+ * count.
+ */
+ public byte[] getByteArray(int index, int count) {
+ return handle.getByteArray(index, count);
+ }
+
+ /**
+ * The number of bytes occupied by this.
+ *
+ * @return The number of bytes occupied by this.
+ */
+ public abstract int getByteCount();
+
+ /**
+ * The bytes copied from C-memory that represent this.
+ *
+ * @return The bytes copied from C-memory that represent this.
+ */
+ public byte[] getBytes() {
+ return handle.getByteArray(0, getByteCount());
+ }
+
+ /**
+ * The element at index as a native long. Only the "platform" number of
+ * bytes are read.
+ *
+ * @param index The index of the element to be reported.
+ *
+ * @return The element at index as a native long.
+ */
+ public long getCLong(int index) {
+ return handle.getCLong(index);
+ }
+
+ /**
+ * The element at index as a native int.
+ *
+ * @param index The index of the element to be reported.
+ *
+ * @return The element at index as a native int.
+ */
+ public int getInt(int index) {
+ return handle.getInt(index);
+ }
+
+ /**
+ * The C-Pointer where the associated memory is found.
+ *
+ * @return The C-Pointer where the associated memory is found.
+ */
+ public INativeHandle getNativeHandle() {
+ return handle;
+ }
+
+ public INativeHandle getNativeHandle(int index) {
+ return handle.getNativeHandle(index);
+ }
+
+ /**
+ * The meta information and behavior for the NativeObject.
+ *
+ * There is exactly one meta instance for all NativeObject instances of a
+ * certain type.
+ *
+ * @return The meta information and behavior for the NativeObject.
+ */
+ abstract public INativeType getNativeType();
+
+ /**
+ * The element at index as a native short. This is a lightweight
+ * optimization.
+ *
+ * @param index The index of the element to be reported.
+ *
+ * @return The element at index as a native short.
+ */
+ public short getShort(int index) {
+ return handle.getShort(index);
+ }
+
+ public String getString(int index) {
+ return handle.getString(index);
+ }
+
+ public String getWideString(int index) {
+ return handle.getWideString(index);
+ }
+
+ /**
+ * Answer
+ * The marshalling is delegated to the StructMember in the
+ * StructDeclaration.
+ *
+ * @param name The name of the slot in the structure.
+ *
+ * @return The NativeObject at the named slot name.
+ */
+ public INativeObject getNativeObject(String name) {
+ return getStructType().getNativeObject(this, name);
+ }
+
+ protected StructMember getStructField(String name) {
+ return getStructType().getField(name);
+ }
+
+ public NativeStructType getStructType() {
+ return (NativeStructType) getNativeType();
+ }
+
+ public Object getValue() {
+ throw new UnsupportedOperationException(
+ "getValue not implemented for NativeStruct");
+ }
+
+ public void setValue(Object value) {
+ throw new UnsupportedOperationException(
+ "getValue not implemented for NativeStruct");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see de.intarsys.tools.nativec.NativeObject#toNestedString()
+ */
+ @Override
+ public String toNestedString() {
+ return "Struct " + getClass().getName();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(getClass().getName());
+ sb.append("\n");
+ for (Iterator it = getStructType().getFields().iterator(); it.hasNext(); ) {
+ StructMember field = (StructMember) it.next();
+ sb.append(field.getName());
+ sb.append("=");
+ try {
+ sb.append(getNativeObject(field.getName()).toString());
+ } catch (RuntimeException e) {
+ sb.append("**error**");
+ }
+ sb.append("\n");
+ }
+ return sb.toString();
+ }
+}
diff --git a/nativec-api/src/main/java/de/intarsys/nativec/type/NativeStructType.java b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeStructType.java
new file mode 100644
index 0000000..23846d4
--- /dev/null
+++ b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeStructType.java
@@ -0,0 +1,171 @@
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * #L%
+ */
+package de.intarsys.nativec.type;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import de.intarsys.nativec.api.NativeInterface;
+public class NativeStructType extends NativeType {
+
+ /**
+ * The named members of the structure definition
+ */
+ private final Map
+ * In our point of view, JNA has the power of deploying all what we wanted to
+ * have, but is ill designed in some key hot spots - so we worked around and
+ * built on top of our own interfaces.
+ */
+public class JnaNativeInterface implements INativeInterface {
+
+ private static Constructor extends Pointer> pointerFactory;
+
+ static {
+ /*
+ * Ugly hack - multithreaded loading caused a deadlock here as
+ * com.sun.jna.Native requests a native library which later requires a
+ * lock on the class loader, while another piece of code
+ * (Security.addProvider) first locks the class loader and later on
+ * requests the runtime to load a native library. We try here to
+ * provide the same ordering (which is based on a lot of assumptions...)
+ */
+ ClassLoader loader = JnaNativeInterface.class.getClassLoader();
+ synchronized (loader) {
+ try {
+ Class.forName("com.sun.jna.Native", true, loader);
+ } catch (ClassNotFoundException e) {
+ throw new InternalError("can not load JNA");
+ }
+ }
+
+ /*
+ * Another hack. We *can* use a stripped down version of the Memory
+ * class if available. If not simply fallback...
+ */
+ try {
+ Class clazz = Class.forName("com.sun.jna.FastMemory", true, loader);
+ pointerFactory = clazz.getConstructor(Integer.TYPE);
+ } catch (Exception e) {
+ try {
+ pointerFactory = Memory.class.getConstructor(Long.TYPE);
+ } catch (Exception e1) {
+ throw new InternalError("can not load JNA");
+ }
+ }
+ }
+
+ private List
- * The handle combines an address and a memory chunk of a specified size.
- */
-public interface INativeHandle {
-
- /**
- * The start address of the memory chunk
- *
- * @return The start address of the memory chunk
- */
- public long getAddress();
-
- /**
- * Marshal the data at byte offset
- * You can not access bytes from outside the range defined by getAdddress +
- * size.
- *
- */
- public int getSize();
-
- /**
- * Marshal the data at byte offset
- * You can not access bytes from outside the range defined by getAdddress +
- * size.
- *
- * @param count
- * The size of the memory managed by the {@link INativeHandle}
- */
- public void setSize(int count);
-
- /**
- * Write a String to the memory at byte offset
- * There is no special handling for the 0 address!
- *
- * @param address
- * The function pointer.
- * @return The function object.
- */
- public INativeFunction createFunction(long address);
-
- public INativeFunction createFunction(long address, Object callingConvention);
-
- /**
- * Create a void {@link INativeHandle} to a memory address.
- *
- * There is no special handling for the 0 address!
- *
- * @param address
- * The memory address.
- * @return The handle to the memory address.
- */
- public INativeHandle createHandle(long address);
-
- /**
- * Load a new {@link INativeLibrary}.
- *
- * @param name
- * The name of the library to load.
- * @return The new {@link INativeLibrary}
- */
- public INativeLibrary createLibrary(String name);
-
- /**
- * Load a new {@link INativeLibrary}.
- *
- * @param name
- * The name of the library to load.
- * @param callingConvention
- * The calling convention to use as default for functions in this
- * library.
- * @return The new {@link INativeLibrary}
- */
- public INativeLibrary createLibrary(String name, Object callingConvention);
-
- /**
- * The platform long size.
- *
- * @return The platform long size.
- */
- public int longSize();
-
- /**
- * The platform pointer size.
- *
- * @return The platform pointer size.
- */
- public int pointerSize();
-
- /**
- * The platform wide char size.
- *
- * @return The platform wide char size.
- */
- public int wideCharSize();
-
-}
diff --git a/src/de/intarsys/nativec/api/NativeInterface.java b/src/de/intarsys/nativec/api/NativeInterface.java
deleted file mode 100644
index 51aab5f..0000000
--- a/src/de/intarsys/nativec/api/NativeInterface.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.nativec.api;
-
-import java.util.Iterator;
-import java.util.ServiceLoader;
-
-/**
- * Access the VM singleton for {@link INativeInterface}.
- *
- * To make this work, just do one of the following:
- *
-Here we define the API's and the VM singleton access to native c.
-
-The component itself was built, as we didn't (once again) find anything
-around that satisfied our needs. We wanted:
-
- * In our point of view, JNA has the power of deploying all what we wanted to
- * have, but is ill designed in some key hot spots - so we worked around and
- * built on top of our own interfaces.
- *
- */
-public class JnaNativeInterface implements INativeInterface {
-
- private static Constructor extends Pointer> pointerFactory;
-
- static {
- /*
- * Ugly hack - multithreaded loading caused a deadlock here as
- * com.sun.jna.Native requests a native library which later requires a
- * lock on the class loader, while another piece of code
- * (Security.addProvider) first locks the class loader and later on
- * requests the runtime to load a native library. We try here to
- * provide the same ordering (which is based on a lot of assumptions...)
- */
- ClassLoader loader = JnaNativeInterface.class.getClassLoader();
- synchronized (loader) {
- try {
- Class.forName("com.sun.jna.Native", true, loader);
- } catch (ClassNotFoundException e) {
- throw new InternalError("can not load JNA");
- }
- }
-
- /*
- * Another hack. We *can* use a stripped down version of the Memory
- * class if available. If not simply fallback...
- */
- try {
- Class clazz = Class.forName("com.sun.jna.FastMemory", true, loader);
- pointerFactory = clazz.getConstructor(Integer.TYPE);
- } catch (Exception e) {
- try {
- pointerFactory = Memory.class.getConstructor(Long.TYPE);
- } catch (Exception e1) {
- throw new InternalError("can not load JNA");
- }
- }
- }
-
- private List
- * A type has declaration style method to create more complex types.
- *
- */
-public interface INativeType {
-
- /**
- * Create an array type from this.
- *
- * @param size
- * The predefined size for the array.
- *
- * @return The derived type.
- */
- public INativeType Array(int size);
-
- /**
- * Create an {@link INativeObject} for this type from the Java object.
- *
- * @param value
- *
- * @return The new {@link INativeObject}
- */
- public INativeObject createNative(Object value);
-
- /**
- * Create a new {@link INativeObject} from a {@link INativeHandle}.
- *
- * @param handle
- * The handle to memory.
- * @return The new {@link INativeObject}
- */
- public INativeObject createNative(INativeHandle handle);
-
- /**
- * The boundary where this type as a struct member would want to be aligned.
- * A structure can override this value with packing.
- *
- * @return The preferred alignment boundary.
- */
- public int getPreferredBoundary();
-
- /**
- * The size of the type in c memory.
- *
- * @return The size of the type in c memory.
- */
- public int getByteCount();
-
- /**
- * Create a reference type to this.
- *
- * @return The derived type.
- */
- public INativeType Ref();
-
-}
diff --git a/src/de/intarsys/nativec/type/NativeArray.java b/src/de/intarsys/nativec/type/NativeArray.java
deleted file mode 100644
index 56779a8..0000000
--- a/src/de/intarsys/nativec/type/NativeArray.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.nativec.type;
-
-import de.intarsys.nativec.api.INativeHandle;
-
-/**
- * An {@link INativeObject} that represents a homogeneous (this means of equal
- * length and type) sequence of other {@link INativeObject} instances.
- */
-public class NativeArray extends NativeObject {
-
- /** The meta class instance */
- public static final NativeArrayType META = new NativeArrayType(
- NativeVoid.META, 0);
-
- static {
- NativeType.register(NativeArray.class, META);
- }
-
- public static NativeArray create(INativeType baseType, int size) {
- NativeArrayType type = new NativeArrayType(baseType, size);
- return new NativeArray(type);
- }
-
- private INativeObject[] values;
-
- private NativeArrayType type;
-
- protected NativeArray(NativeArrayType type) {
- this.type = type;
- allocate();
- }
-
- protected NativeArray(NativeArrayType type, INativeHandle handle) {
- super(handle);
- this.type = type;
- }
-
- public INativeType getBaseType() {
- return type.getBaseType();
- }
-
- @Override
- public int getByteCount() {
- return type.getByteCount();
- }
-
- /**
- * The {@link INativeObject} at index in the sequence (the index'th element
- * of the array).
- *
- * @param index
- * The index of the element to be reported.
- *
- * @return The NativeObject at index
- */
- synchronized public INativeObject getNativeObject(int index) {
- if (values == null) {
- values = new INativeObject[getSize()];
- }
- INativeObject result = values[index];
- if (result == null) {
- int elementOffset = index * type.getBaseSize();
- result = type.getBaseType().createNative(
- handle.offset(elementOffset));
- values[index] = result;
- }
- return result;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see de.intarsys.graphic.freetype.NativeObject#getMetaClass()
- */
- @Override
- public INativeType getNativeType() {
- return type;
- }
-
- /**
- * The number of NativeObject instances in the sequence represented by this
- * (in other terms the array size).
- *
- * @return The number of NativeObject instances in the sequence represented
- * by this
- */
- public int getSize() {
- return type.getArraySize();
- }
-
- public Object getValue() {
- throw new UnsupportedOperationException(
- "getValue not implemented for NativeArray");
- }
-
- public Object getValue(int index) {
- return getNativeObject(index).getValue();
- }
-
- public void setBaseType(INativeType baseType) {
- type = NativeArrayType.create(baseType, type.getArraySize());
- this.values = null;
- handle.setSize(getByteCount());
- }
-
- public void setSize(int size) {
- type = NativeArrayType.create(type.getBaseType(), size);
- this.values = null;
- handle.setSize(getByteCount());
- }
-
- public void setValue(int index, Object value) {
- getNativeObject(index).setValue(value);
- }
-
- public void setValue(Object value) {
- throw new UnsupportedOperationException(
- "setValue not implemented for NativeArray");
- }
-
- /*
- * (non-Javadoc)
- *
- * @see de.intarsys.graphic.freetype.NativeObject#toNestedString()
- */
- @Override
- public String toNestedString() {
- return "[...]";
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append("[");
- for (int i = 0; i < getSize(); i++) {
- // NativeObject element = get(i);
- // sb.append(element.toString());
- // sb.append(", ");
- }
- sb.append("]");
- return sb.toString();
- }
-
-}
diff --git a/src/de/intarsys/nativec/type/NativeBuffer.java b/src/de/intarsys/nativec/type/NativeBuffer.java
deleted file mode 100644
index 349d5f0..0000000
--- a/src/de/intarsys/nativec/type/NativeBuffer.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.nativec.type;
-
-import java.nio.ByteBuffer;
-
-import de.intarsys.nativec.api.INativeHandle;
-import de.intarsys.nativec.api.NativeInterface;
-
-/**
- * A wrapper for a sequence of bytes.
- *
- */
-public class NativeBuffer extends NativeObject {
-
- /** The meta class instance */
- public static final NativeBufferType META = new NativeBufferType();
-
- static {
- NativeType.register(NativeBuffer.class, META);
- }
-
- private NativeBufferType type;
-
- public NativeBuffer(byte[] bytes) {
- type = new NativeBufferType(bytes.length);
- handle = NativeInterface.get().allocate(bytes.length);
- handle.setByteArray(0, bytes, 0, bytes.length);
- }
-
- protected NativeBuffer(INativeHandle handle) {
- super(handle);
- }
-
- public NativeBuffer(int pSize) {
- type = new NativeBufferType(pSize);
- handle = NativeInterface.get().allocate(pSize);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see de.intarsys.tools.nativec.NativeObject#getByteCount()
- */
- @Override
- public int getByteCount() {
- // todo alignment?
- return type.getByteCount();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see de.intarsys.graphic.freetype.NativeObject#getMetaClass()
- */
- @Override
- public INativeType getNativeType() {
- return META;
- }
-
- /**
- * The number of elements in the NativeBuffer
- *
- * @return The number of elements in the NativeBuffer
- */
- public int getSize() {
- return type.getByteCount();
- }
-
- public Object getValue() {
- return getBytes();
- }
-
- public void setSize(int size) {
- type = new NativeBufferType(size);
- handle.setSize(getByteCount());
- }
-
- public void setValue(Object value) {
- if (value instanceof byte[]) {
- byte[] data = (byte[]) value;
- setByteArray(0, data, 0, data.length);
- } else if (value instanceof ByteBuffer) {
- byte[] data = new byte[getSize()];
- ((ByteBuffer) value).get(data);
- setByteArray(0, data, 0, data.length);
- }
- }
-}
diff --git a/src/de/intarsys/nativec/type/NativeFunction.java b/src/de/intarsys/nativec/type/NativeFunction.java
deleted file mode 100644
index 862bbfe..0000000
--- a/src/de/intarsys/nativec/type/NativeFunction.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package de.intarsys.nativec.type;
-
-import de.intarsys.nativec.api.INativeFunction;
-import de.intarsys.nativec.api.INativeHandle;
-import de.intarsys.nativec.api.NativeInterface;
-
-public class NativeFunction extends NativeVoid {
-
- public static class NativeFunctionType extends NativeVoidType {
-
- @Override
- public INativeObject createNative(INativeHandle handle) {
- return new NativeFunction(handle);
- }
-
- }
-
- public static final NativeFunctionType META = new NativeFunctionType();
-
- private Object callingConvention;
- private INativeFunction function;
-
- protected NativeFunction(INativeHandle handle) {
- super(handle);
- callingConvention = INativeFunction.CallingConventionCdecl;
- }
-
- public Object getCallingConvention() {
- return callingConvention;
- }
-
- public INativeFunction getFunction() {
- // TODO do we want to check if handle has changed?
- if (function == null) {
- function = NativeInterface.get().createFunction(
- getNativeHandle().getAddress(), callingConvention);
- }
- return function;
- }
-
- public void setCallingConvention(Object callingConvention) {
- if(function != null) {
- throw new IllegalStateException();
- }
- this.callingConvention = callingConvention;
- }
-}
diff --git a/src/de/intarsys/nativec/type/NativeLongLP64.java b/src/de/intarsys/nativec/type/NativeLongLP64.java
deleted file mode 100644
index 7dd44a2..0000000
--- a/src/de/intarsys/nativec/type/NativeLongLP64.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.nativec.type;
-
-import de.intarsys.nativec.api.INativeHandle;
-import de.intarsys.nativec.api.NativeTools;
-
-/**
- * A wrapper for the Windows type LONG_PTR. This type has the same size as a
- * pointer but is semantically a simple integer. (same as NativeLong on LP64
- * platforms size-wise)
- */
-public class NativeLongLP64 extends NativeNumber {
-
- /** The meta class instance */
- public static final NativeLongLP64Type META = new NativeLongLP64Type();
-
- static {
- NativeType.register(NativeLongLP64.class, META);
- }
-
- static public NativeLongLP64 createFromAddress(long address) {
- return (NativeLongLP64) NativeLongLP64.META.createNative(NativeTools
- .toHandle(address));
- }
-
- /**
- * Create a new wrapper
- */
- public NativeLongLP64() {
- allocate();
- }
-
- protected NativeLongLP64(INativeHandle handle) {
- super(handle);
- }
-
- /**
- * Create a new wrapper
- */
- public NativeLongLP64(long value) {
- allocate();
- setValue(value);
- }
-
- @Override
- public byte byteValue() {
- return (byte) intValue();
- }
-
- @Override
- public INativeType getNativeType() {
- return META;
- }
-
- @Override
- public Object getValue() {
- return new Long(longValue());
- }
-
- @Override
- public int intValue() {
- return (int) longValue();
- }
-
- @Override
- public long longValue() {
- if (NativeObject.SIZE_PTR == 4) {
- return handle.getInt(0);
- }
- return handle.getLong(0);
- }
-
- public void setValue(long value) {
- if (NativeObject.SIZE_PTR == 4) {
- handle.setInt(0, (int) value);
- return;
- }
- handle.setLong(0, value);
- }
-
- @Override
- public void setValue(Object value) {
- setValue(((Number) value).longValue());
- }
-
- @Override
- public short shortValue() {
- return (short) longValue();
- }
-
- @Override
- public String toString() {
- if (getNativeHandle() == null) {
- return "nope - no handle"; //$NON-NLS-1$
- }
- if (getNativeHandle().getAddress() == 0) {
- return "nope - null pointer"; //$NON-NLS-1$
- }
- return String.valueOf(longValue());
- }
-
-}
diff --git a/src/de/intarsys/nativec/type/NativeObject.java b/src/de/intarsys/nativec/type/NativeObject.java
deleted file mode 100644
index 2e46c0e..0000000
--- a/src/de/intarsys/nativec/type/NativeObject.java
+++ /dev/null
@@ -1,290 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.nativec.type;
-
-import de.intarsys.nativec.api.INativeHandle;
-import de.intarsys.nativec.api.NativeInterface;
-
-/**
- * An instance of an external (C memory) represented object. The C-object is
- * represented using the handle (the pointer to the object in C memory) and its
- * type {@link INativeType}.
- *
- * Supported data types are
- *
- * The handle should only be assigned in the constructor, via parameter or
- * "allocate".
- */
- protected INativeHandle handle;
-
- /**
- *
- */
- protected NativeObject() {
- //
- }
-
- /**
- * Create a new NativeObject in C-Memory at pointer "handle". The bytes
- * belonging to this object may already have been copied from C-Memory and
- * made available in bytes at location offset.
- *
- * @param handle
- * The pointer in C-memory
- */
- protected NativeObject(INativeHandle handle) {
- this.handle = handle;
- }
-
- /**
- * Manage the objects memory in Java. C memory will be valid at least as
- * long as we hold a reference to the buffer. C memory is undefined (but not
- * a memory leak) and may be reclaimed at any time after dropping our
- * pointer to the buffer.
- */
- protected void allocate() {
- int size = getByteCount();
- handle = NativeInterface.get().allocate(size);
- }
-
- /**
- * This is a special form of the "createNative" signature, implementing a
- * "type cast" on the same memory location.
- *
- * @param declaration
- * The new base declaration type.
- * @return The {@link INativeObject} at the same memory location as this,
- * but of a different type.
- */
- public INativeObject cast(INativeType declaration) {
- return declaration.createNative(handle);
- }
-
- public INativeObject createReference() {
- NativeReference ref = NativeReference.create(getNativeType());
- ref.setValue(this);
- return ref;
- }
-
- /**
- * The byte at index as a byte.
- *
- * @param index
- * The index of the element to be reported.
- * @return The element at index as a native byte.
- */
- public byte getByte(int index) {
- return handle.getByte(index);
- }
-
- /**
- * The element at index as an array of bytes with dimension count. This is a
- * lightweight optimization.
- *
- * @param index
- * The index of the element to be reported.
- * @return The element at index as an array of native byte with dimension
- * count.
- */
- public byte[] getByteArray(int index, int count) {
- return handle.getByteArray(index, count);
- }
-
- /**
- * The number of bytes occupied by this.
- *
- * @return The number of bytes occupied by this.
- */
- public abstract int getByteCount();
-
- /**
- * The bytes copied from C-memory that represent this.
- *
- * @return The bytes copied from C-memory that represent this.
- */
- public byte[] getBytes() {
- return handle.getByteArray(0, getByteCount());
- }
-
- /**
- * The element at index as a native long. Only the "platform" number of
- * bytes are read.
- *
- * @param index
- * The index of the element to be reported.
- * @return The element at index as a native long.
- */
- public long getCLong(int index) {
- return handle.getCLong(index);
- }
-
- /**
- * The element at index as a native int.
- *
- * @param index
- * The index of the element to be reported.
- * @return The element at index as a native int.
- */
- public int getInt(int index) {
- return handle.getInt(index);
- }
-
- /**
- * The C-Pointer where the associated memory is found.
- *
- * @return The C-Pointer where the associated memory is found.
- */
- public INativeHandle getNativeHandle() {
- return handle;
- }
-
- public INativeHandle getNativeHandle(int index) {
- return handle.getNativeHandle(index);
- }
-
- /**
- * The meta information and behavior for the NativeObject.
- *
- * There is exactly one meta instance for all NativeObject instances of a
- * certain type.
- *
- * @return The meta information and behavior for the NativeObject.
- *
- */
- abstract public INativeType getNativeType();
-
- /**
- * The element at index as a native short. This is a lightweight
- * optimization.
- *
- * @param index
- * The index of the element to be reported.
- * @return The element at index as a native short.
- */
- public short getShort(int index) {
- return handle.getShort(index);
- }
-
- public String getString(int index) {
- return handle.getString(index);
- }
-
- public String getWideString(int index) {
- return handle.getWideString(index);
- }
-
- /**
- * Answer
- * The marshalling is delegated to the StructMember in the
- * StructDeclaration.
- *
- * @param name
- * The name of the slot in the structure.
- *
- * @return The NativeObject at the named slot name.
- */
- public INativeObject getNativeObject(String name) {
- return getStructType().getNativeObject(this, name);
- }
-
- protected StructMember getStructField(String name) {
- return getStructType().getField(name);
- }
-
- public NativeStructType getStructType() {
- return (NativeStructType) getNativeType();
- }
-
- public Object getValue() {
- throw new UnsupportedOperationException(
- "getValue not implemented for NativeStruct");
- }
-
- public void setValue(Object value) {
- throw new UnsupportedOperationException(
- "getValue not implemented for NativeStruct");
- }
-
- /*
- * (non-Javadoc)
- *
- * @see de.intarsys.tools.nativec.NativeObject#toNestedString()
- */
- @Override
- public String toNestedString() {
- return "Struct " + getClass().getName();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append(getClass().getName());
- sb.append("\n");
- for (Iterator it = getStructType().getFields().iterator(); it.hasNext();) {
- StructMember field = (StructMember) it.next();
- sb.append(field.getName());
- sb.append("=");
- try {
- sb.append(getNativeObject(field.getName()).toString());
- } catch (RuntimeException e) {
- sb.append("**error**");
- }
- sb.append("\n");
- }
- return sb.toString();
- }
-}
diff --git a/src/de/intarsys/nativec/type/NativeStructType.java b/src/de/intarsys/nativec/type/NativeStructType.java
deleted file mode 100644
index c48befe..0000000
--- a/src/de/intarsys/nativec/type/NativeStructType.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.nativec.type;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import de.intarsys.nativec.api.NativeInterface;
-
-/**
- * The meta class implementation
- */
-public class NativeStructType extends NativeType {
-
- /**
- * The boundary where the struct as a member of another struct would want to
- * be aligned.
- */
- private int byteBoundary = 1;
-
- /**
- * The offset where theoretically a new member could be placed. Where it
- * will actually be placed depends on the member itself.
- */
- private int byteOffset = 0;
-
- /** The size in bytes of the member collection */
- private int byteSize = 0;
-
- /** The named members of the structure definition */
- private final Mapindex from the start of the
+ * memory chunk to a byte.
+ *
+ * @param index The byte offset from the start of the memory chunk
+ *
+ * @return A byte marshaled from the memory chunk
+ */
+ byte getByte(int index);
+
+ /**
+ * Marshal the data at byte offset index from the start of the
+ * memory chunk to a byte array of length count.
+ *
+ * @param index The byte offset from the start of the memory chunk
+ * @param count The size of the byte array
+ *
+ * @return A byte array marshaled from the memory chunk
+ */
+ byte[] getByteArray(int index, int count);
+
+ /**
+ * Marshal the data at byte offset index from the start of the
+ * memory chunk to a long. Get only the "platform" number of bytes.
+ *
+ * @param index The byte offset from the start of the memory chunk
+ *
+ * @return A long marshaled from the memory chunk
+ */
+ long getCLong(int index);
+
+ /**
+ * Marshal the data at byte offset index from the start of the
+ * memory chunk to an int.
+ *
+ * @param index The byte offset from the start of the memory chunk
+ *
+ * @return An int marshaled from the memory chunk
+ */
+ int getInt(int index);
+
+ /**
+ * Marshal the data at byte offset index from the start of the
+ * memory chunk to a long value (which is always 8 byte).
+ *
+ * @param index The byte offset from the start of the memory chunk
+ *
+ * @return A long marshaled from the memory chunk
+ */
+ long getLong(int index);
+
+ /**
+ * Marshal the data at byte offset index from the start of the
+ * memory chunk to an {@link INativeHandle}.
+ *
+ * @param index The byte offset from the start of the memory chunk
+ *
+ * @return An {@link INativeHandle} marshaled from the memory chunk
+ */
+ INativeHandle getNativeHandle(int index);
+
+ /**
+ * Marshal the data at byte offset index from the start of the
+ * memory chunk to a short.
+ *
+ * @param index The byte offset from the start of the memory chunk
+ *
+ * @return A short marshaled from the memory chunk
+ */
+ short getShort(int index);
+
+ /**
+ * The size for the handle in bytes.
+ * count bytes.
+ * index from the start of the
+ * memory chunk to a String.
+ *
+ * @param index The byte offset from the start of the memory chunk
+ *
+ * @return A String marshaled from the memory chunk
+ */
+ String getString(int index);
+
+ /**
+ * Marshal the data at byte offset index from the start of the
+ * memory chunk to a String using the platform wide character conversion.
+ *
+ * @param index The byte offset from the start of the memory chunk
+ *
+ * @return A String marshaled from the memory chunk
+ */
+ String getWideString(int index);
+
+ /**
+ * Create a new {@link INativeHandle}, offset from this by
+ * offset bytes.
+ *
+ * @param offset The byte offset from the start of the memory chunk
+ *
+ * @return A new {@link INativeHandle} pointing to "getAddress() + offset".
+ */
+ INativeHandle offset(int offset);
+
+ /**
+ * Write a byte to the memory at byte offset index from the
+ * start of the memory chunk.
+ *
+ * @param index The byte offset from the start of the memory chunk
+ * @param value The value to write.
+ */
+ void setByte(int index, byte value);
+
+ /**
+ * Write a byte array to the memory at byte offset index from
+ * the start of the memory chunk. The method will write
+ * valueCount bytes from value starting at
+ * valueOffset.
+ *
+ * @param index The byte offset from the start of the memory chunk
+ * @param value The value to write.
+ */
+ void setByteArray(int index, byte[] value, int valueOffset,
+ int valueCount);
+
+ /**
+ * Write a long to the memory at byte offset index from the
+ * start of the memory chunk. Write only the "platform" number of bytes. The
+ * caller is responsible for observing the value range.
+ *
+ * @param index The byte offset from the start of the memory chunk
+ * @param value The value to write.
+ */
+ void setCLong(int index, long value);
+
+ /**
+ * Write an int to the memory at byte offset index from the
+ * start of the memory chunk.
+ *
+ * @param index The byte offset from the start of the memory chunk
+ * @param value The value to write.
+ */
+ void setInt(int index, int value);
+
+ /**
+ * Write a long to the memory at byte offset index from the
+ * start of the memory chunk.
+ *
+ * @param index The byte offset from the start of the memory chunk
+ * @param value The value to write.
+ */
+ void setLong(int index, long value);
+
+ /**
+ * Write an {@link INativeHandle} to the memory at byte offset
+ * index from the start of the memory chunk.
+ *
+ * @param index The byte offset from the start of the memory chunk
+ * @param valueHandle The value to write.
+ */
+ void setNativeHandle(int index, INativeHandle valueHandle);
+
+ /**
+ * Write a short to the memory at byte offset index from the
+ * start of the memory chunk.
+ *
+ * @param index The byte offset from the start of the memory chunk
+ * @param value The value to write.
+ */
+ void setShort(int index, short value);
+
+ /**
+ * Write a String to the memory at byte offset indexfrom the
+ * start of the memory chunk.
+ *
+ * @param index The byte offset from the start of the memory chunk
+ * @param value The value to write.
+ */
+ void setString(int index, String value);
+
+ /**
+ * Write a String to the memory at byte offset indexfrom the
+ * start of the memory chunk using the platform wide character conversion.
+ *
+ * @param index The byte offset from the start of the memory chunk
+ * @param value The value to write.
+ */
+ void setWideString(int index, String value);
+}
diff --git a/nativec-api/src/main/java/de/intarsys/nativec/api/INativeInterface.java b/nativec-api/src/main/java/de/intarsys/nativec/api/INativeInterface.java
new file mode 100644
index 0000000..3ebf6b2
--- /dev/null
+++ b/nativec-api/src/main/java/de/intarsys/nativec/api/INativeInterface.java
@@ -0,0 +1,119 @@
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * #L%
+ */
+package de.intarsys.nativec.api;
+public interface INativeInterface {
+
+ /**
+ * Add a directory to the search path.
+ *
+ * @param path The path to be added;
+ */
+ void addSearchPath(String path);
+
+ /**
+ * Allocate c memory and return the respective {@link INativeHandle}.
+ *
+ * @param size The size in bytes.
+ *
+ * @return The new allocated {@link INativeHandle}
+ */
+ INativeHandle allocate(int size);
+
+ INativeCallback createCallback(ICallback callback);
+
+ /**
+ * Create an {@link INativeFunction} from a function pointer.
+ *
+
+
+So we created an API and a data structure component and mapped it to JNA, which has
+great ideas (but in our opinion is to sealed off and has not well done on the
+data structure side) and can serve as a good foundation.
+
+There are some topics we didn't care about yet - this means they may be working or may
+not, its simply not tested. JNA brings a lot of basic features...
+
+
+
+
+64 bit implementation is under way.
+
+
+
diff --git a/nativec-api/src/main/java/de/intarsys/nativec/type/INativeObject.java b/nativec-api/src/main/java/de/intarsys/nativec/type/INativeObject.java
new file mode 100644
index 0000000..0ff9f66
--- /dev/null
+++ b/nativec-api/src/main/java/de/intarsys/nativec/type/INativeObject.java
@@ -0,0 +1,73 @@
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * #L%
+ */
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
+public interface INativeObject {
+
+ /**
+ * The bytes that make up the {@link INativeObject}.
+ *
+ * @return The bytes that make up the {@link INativeObject}.
+ */
+ byte[] getBytes();
+
+ /**
+ * The {@link INativeHandle} to the c memory for the object.
+ *
+ * @return The {@link INativeHandle} to the c memory for the object.
+ */
+ INativeHandle getNativeHandle();
+
+ /**
+ * The {@link INativeType} for the object.
+ *
+ * @return The {@link INativeType} for the object.
+ */
+ INativeType getNativeType();
+
+ /**
+ * A Java side representation from the memory.
+ *
+ * @return A Java side representation for the {@link INativeObject}.
+ */
+ Object getValue();
+
+ /**
+ * Assign (and marshall to memory) the Java side representation.
+ *
+ * @param value The new Java value.
+ */
+ void setValue(Object value);
+}
diff --git a/src/de/intarsys/nativec/type/INativeObject.java b/nativec-api/src/main/java/de/intarsys/nativec/type/INativeType.java
similarity index 56%
rename from src/de/intarsys/nativec/type/INativeObject.java
rename to nativec-api/src/main/java/de/intarsys/nativec/type/INativeType.java
index 5378686..19db0a7 100644
--- a/src/de/intarsys/nativec/type/INativeObject.java
+++ b/nativec-api/src/main/java/de/intarsys/nativec/type/INativeType.java
@@ -1,20 +1,23 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
- *
+ *
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
- *
+ *
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* - Neither the name of intarsys nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -26,54 +29,59 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
+ * #L%
*/
package de.intarsys.nativec.type;
import de.intarsys.nativec.api.INativeHandle;
+public interface INativeType {
-/**
- * The Java object representation of a c memory construct.
- * true if this is "null". This means the associated
+ * C-pointer is pointing to 0.
+ *
+ * @return Answer true if this is "null".
+ */
+ public boolean isNull() {
+ return handle == null || handle.getAddress() == 0;
+ }
+
+ public void setByte(int index, byte value) {
+ handle.setByte(index, value);
+ }
+
+ public void setByteArray(int index, byte[] value, int valueOffset,
+ int valueCount) {
+ handle.setByteArray(index, value, valueOffset, valueCount);
+ }
+
+ public void setCLong(int index, long value) {
+ handle.setCLong(index, value);
+ }
+
+ public void setInt(int index, int value) {
+ handle.setInt(index, value);
+ }
+
+ public void setNativeHandle(int index, INativeHandle value) {
+ handle.setNativeHandle(index, value);
+ }
+
+ public void setShort(int index, short value) {
+ handle.setShort(index, value);
+ }
+
+ public void setString(int index, String value) {
+ handle.setString(index, value);
+ }
+
+ public void setWideString(int index, String value) {
+ handle.setWideString(index, value);
+ }
+
+ /**
+ * A string for debugging purposes.
+ *
+ * @return A string for debugging purposes.
+ */
+ public String toNestedString() {
+ return toString();
+ }
+}
diff --git a/nativec-api/src/main/java/de/intarsys/nativec/type/NativeReference.java b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeReference.java
new file mode 100644
index 0000000..4b5b369
--- /dev/null
+++ b/nativec-api/src/main/java/de/intarsys/nativec/type/NativeReference.java
@@ -0,0 +1,130 @@
+/*-
+ * #%L
+ * Nazgul Project: nativec-api
+ * %%
+ * Copyright (C) 2013 - 2022 Intarsys Consulting GmbH
+ * %%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * - Neither the name of intarsys nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ * #L%
+ */
+package de.intarsys.nativec.type;
+
+import de.intarsys.nativec.api.INativeHandle;
+import de.intarsys.nativec.api.NativeInterface;
+public class NativeReferenceindex from the start of the
- * memory chunk to a byte.
- *
- * @param index
- * The byte offset from the start of the memory chunk
- * @return A byte marshaled from the memory chunk
- */
- public byte getByte(int index);
-
- /**
- * Marshal the data at byte offset index from the start of the
- * memory chunk to a byte array of length count.
- *
- * @param index
- * The byte offset from the start of the memory chunk
- * @param count
- * The size of the byte array
- * @return A byte array marshaled from the memory chunk
- */
- public byte[] getByteArray(int index, int count);
-
- /**
- * Marshal the data at byte offset index from the start of the
- * memory chunk to a long. Get only the "platform" number of bytes.
- *
- * @param index
- * The byte offset from the start of the memory chunk
- * @return A long marshaled from the memory chunk
- */
- public long getCLong(int index);
-
- /**
- * Marshal the data at byte offset index from the start of the
- * memory chunk to an int.
- *
- * @param index
- * The byte offset from the start of the memory chunk
- * @return An int marshaled from the memory chunk
- */
- public int getInt(int index);
-
- /**
- * Marshal the data at byte offset index from the start of the
- * memory chunk to a long value (which is always 8 byte).
- *
- * @param index
- * The byte offset from the start of the memory chunk
- * @return A long marshaled from the memory chunk
- */
- public long getLong(int index);
-
- /**
- * Marshal the data at byte offset index from the start of the
- * memory chunk to an {@link INativeHandle}.
- *
- * @param index
- * The byte offset from the start of the memory chunk
- * @return An {@link INativeHandle} marshaled from the memory chunk
- */
- public INativeHandle getNativeHandle(int index);
-
- /**
- * Marshal the data at byte offset index from the start of the
- * memory chunk to a short.
- *
- * @param index
- * The byte offset from the start of the memory chunk
- * @return A short marshaled from the memory chunk
- */
- public short getShort(int index);
-
- /**
- * The size for the handle in bytes.
- * index from the start of the
- * memory chunk to a String.
- *
- * @param index
- * The byte offset from the start of the memory chunk
- * @return A String marshaled from the memory chunk
- */
- public String getString(int index);
-
- /**
- * Marshal the data at byte offset index from the start of the
- * memory chunk to a String using the platform wide character conversion.
- *
- * @param index
- * The byte offset from the start of the memory chunk
- * @return A String marshaled from the memory chunk
- */
- public String getWideString(int index);
-
- /**
- * Create a new {@link INativeHandle}, offset from this by
- * offset bytes.
- *
- * @param offset
- * The byte offset from the start of the memory chunk
- * @return A new {@link INativeHandle} pointing to "getAddress() + offset".
- */
- public INativeHandle offset(int offset);
-
- /**
- * Write a byte to the memory at byte offset index from the
- * start of the memory chunk.
- *
- * @param index
- * The byte offset from the start of the memory chunk
- * @param value
- * The value to write.
- */
- public void setByte(int index, byte value);
-
- /**
- * Write a byte array to the memory at byte offset index from
- * the start of the memory chunk. The method will write
- * valueCount bytes from value starting at
- * valueOffset.
- *
- * @param index
- * The byte offset from the start of the memory chunk
- * @param value
- * The value to write.
- */
- public void setByteArray(int index, byte[] value, int valueOffset,
- int valueCount);
-
- /**
- * Write a long to the memory at byte offset index from the
- * start of the memory chunk. Write only the "platform" number of bytes. The
- * caller is responsible for observing the value range.
- *
- * @param index
- * The byte offset from the start of the memory chunk
- * @param value
- * The value to write.
- */
- public void setCLong(int index, long value);
-
- /**
- * Write an int to the memory at byte offset index from the
- * start of the memory chunk.
- *
- * @param index
- * The byte offset from the start of the memory chunk
- * @param value
- * The value to write.
- */
- public void setInt(int index, int value);
-
- /**
- * Write a long to the memory at byte offset index from the
- * start of the memory chunk.
- *
- * @param index
- * The byte offset from the start of the memory chunk
- * @param value
- * The value to write.
- */
- public void setLong(int index, long value);
-
- /**
- * Write an {@link INativeHandle} to the memory at byte offset
- * index from the start of the memory chunk.
- *
- * @param index
- * The byte offset from the start of the memory chunk
- * @param valueHandle
- * The value to write.
- */
- public void setNativeHandle(int index, INativeHandle valueHandle);
-
- /**
- * Write a short to the memory at byte offset index from the
- * start of the memory chunk.
- *
- * @param index
- * The byte offset from the start of the memory chunk
- * @param value
- * The value to write.
- */
- public void setShort(int index, short value);
-
- /**
- * Set the valid size for the handle to count bytes.
- * indexfrom the
- * start of the memory chunk.
- *
- * @param index
- * The byte offset from the start of the memory chunk
- * @param value
- * The value to write.
- */
- public void setString(int index, String value);
-
- /**
- * Write a String to the memory at byte offset indexfrom the
- * start of the memory chunk using the platform wide character conversion.
- *
- * @param index
- * The byte offset from the start of the memory chunk
- * @param value
- * The value to write.
- */
- public void setWideString(int index, String value);
-
-}
diff --git a/src/de/intarsys/nativec/api/INativeInterface.java b/src/de/intarsys/nativec/api/INativeInterface.java
deleted file mode 100644
index b803b4c..0000000
--- a/src/de/intarsys/nativec/api/INativeInterface.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.nativec.api;
-
-/**
- * The abstraction of a generic interface to c native code.
- */
-public interface INativeInterface {
-
- /**
- * Add a directory to the search path.
- *
- * @param path
- * The path to be added;
- */
- public void addSearchPath(String path);
-
- /**
- * Allocate c memory and return the respective {@link INativeHandle}.
- *
- * @param size
- * The size in bytes.
- * @return The new allocated {@link INativeHandle}
- */
- public INativeHandle allocate(int size);
-
- public INativeCallback createCallback(ICallback callback);
-
- /**
- * Create an {@link INativeFunction} from a function pointer.
- *
- *
- *
- */
-public class NativeInterface {
-
- private static INativeInterface ACTIVE;
-
- private static String NAME;
-
- public static INativeHandle NULL;
-
- public static final String PROP_NATIVEINTERFACE = "de.intarsys.nativec.api.INativeInterface"; //$NON-NLS-1$
-
- static protected INativeInterface createNativeInterface() {
- String className = getName();
- if (className == null) {
- className = System.getProperty(PROP_NATIVEINTERFACE);
- }
- if (className != null) {
- try {
- Class clazz = Class.forName(className);
- return (INativeInterface) clazz.newInstance();
- } catch (Exception e) {
- throw new NoClassDefFoundError(className);
- }
- }
- return findNativeInterface();
- }
-
- static protected INativeInterface findNativeInterface() {
- ServiceLoader
-
-
-So we created an API and a data structure component and mapped it to JNA, which has
-great ideas (but in our opinion is to sealed off and has not well done on the
-data structure side) and can serve as a good foundation.
-
-There are some topics we didn't care about yet - this means they may be working or may
-not, its simply not tested. JNA brings a lot of basic features...
-
-
-
-
-64 bit implementation is under way.
-
-
-
\ No newline at end of file
diff --git a/src/de/intarsys/nativec/jna/JNATools.java b/src/de/intarsys/nativec/jna/JNATools.java
deleted file mode 100644
index 57fa5ff..0000000
--- a/src/de/intarsys/nativec/jna/JNATools.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package de.intarsys.nativec.jna;
-
-import com.sun.jna.Pointer;
-
-public class JNATools {
-
- public static long getPeer(Pointer p) {
- if (p == null) {
- return 0;
- }
- return Pointer.nativeValue(p);
- }
-
-}
diff --git a/src/de/intarsys/nativec/jna/JnaNativeCallback.java b/src/de/intarsys/nativec/jna/JnaNativeCallback.java
deleted file mode 100644
index 38770ca..0000000
--- a/src/de/intarsys/nativec/jna/JnaNativeCallback.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.nativec.jna;
-
-import com.sun.jna.CallbackProxy;
-import com.sun.jna.NativeLong;
-import com.sun.jna.Pointer;
-import com.sun.jna.WString;
-
-import de.intarsys.nativec.api.CLong;
-import de.intarsys.nativec.api.CWideString;
-import de.intarsys.nativec.api.ICallback;
-import de.intarsys.nativec.api.INativeCallback;
-import de.intarsys.nativec.api.INativeHandle;
-import de.intarsys.nativec.type.INativeType;
-import de.intarsys.nativec.type.NativeObject;
-import de.intarsys.nativec.type.NativeType;
-
-abstract public class JnaNativeCallback implements INativeCallback,
- CallbackProxy {
-
- public static Class> translateType(Class> type) {
- // TODO implement more elegant type translation
- if (CWideString.class.isAssignableFrom(type)) {
- return WString.class;
- } else if (CLong.class.isAssignableFrom(type)) {
- return NativeLong.class;
- } else if (NativeObject.class.isAssignableFrom(type)) {
- return Pointer.class;
- } else if (INativeHandle.class.isAssignableFrom(type)) {
- return Pointer.class;
- }
- return type;
- }
-
- private ICallback callback;
-
- public JnaNativeCallback(ICallback pCallback) {
- callback = pCallback;
- }
-
- public Object callback(Object[] args) {
- for (int index = 0; index < args.length; index++) {
- Class> parameterType;
- Object object;
-
- parameterType = callback.getParameterTypes()[index];
- if (CWideString.class.isAssignableFrom(parameterType)) {
- WString wstring = (WString) args[index];
- object = new CWideString(wstring.toString());
- } else if (CLong.class.isAssignableFrom(parameterType)) {
- Number nativeNumber = (Number) args[index];
- object = new CLong(nativeNumber.longValue());
- } else if (NativeObject.class.isAssignableFrom(parameterType)) {
- Pointer pointer = (Pointer) args[index];
- if (pointer == null) {
- object = null;
- } else {
- INativeHandle handle = new JnaNativeHandle(pointer);
- INativeType type = NativeType.lookup(parameterType);
- if (type == null) {
- throw new IllegalArgumentException("no type for '"
- + parameterType + "'");
- }
- object = type.createNative(handle);
- }
- } else if (INativeHandle.class.isAssignableFrom(parameterType)) {
- Pointer pointer = (Pointer) args[index];
- if (pointer == null) {
- object = null;
- } else {
- object = new JnaNativeHandle(pointer);
- }
- } else {
- object = args[index];
- }
- args[index] = object;
- }
- // TODO map return value too
- return callback.invoke(args);
- }
-
- public Class>[] getParameterTypes() {
- Class>[] genericParameterTypes;
- Class>[] nativeParameterTypes;
-
- genericParameterTypes = callback.getParameterTypes();
- nativeParameterTypes = new Class>[genericParameterTypes.length];
-
- for (int index = 0; index < genericParameterTypes.length; index++) {
- nativeParameterTypes[index] = translateType(genericParameterTypes[index]);
- }
- return nativeParameterTypes;
- }
-
- public Class> getReturnType() {
- return translateType(callback.getReturnType());
- }
-
-}
diff --git a/src/de/intarsys/nativec/jna/JnaNativeCallbackAlt.java b/src/de/intarsys/nativec/jna/JnaNativeCallbackAlt.java
deleted file mode 100644
index a1a4cda..0000000
--- a/src/de/intarsys/nativec/jna/JnaNativeCallbackAlt.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package de.intarsys.nativec.jna;
-
-import com.sun.jna.AltCallingConvention;
-
-import de.intarsys.nativec.api.ICallback;
-
-public class JnaNativeCallbackAlt extends JnaNativeCallback implements
- AltCallingConvention {
-
- public JnaNativeCallbackAlt(ICallback pCallback) {
- super(pCallback);
- }
-
-}
diff --git a/src/de/intarsys/nativec/jna/JnaNativeCallbackStd.java b/src/de/intarsys/nativec/jna/JnaNativeCallbackStd.java
deleted file mode 100644
index 34002da..0000000
--- a/src/de/intarsys/nativec/jna/JnaNativeCallbackStd.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package de.intarsys.nativec.jna;
-
-import de.intarsys.nativec.api.ICallback;
-
-public class JnaNativeCallbackStd extends JnaNativeCallback {
-
- public JnaNativeCallbackStd(ICallback pCallback) {
- super(pCallback);
- }
-
-}
diff --git a/src/de/intarsys/nativec/jna/JnaNativeFunction.java b/src/de/intarsys/nativec/jna/JnaNativeFunction.java
deleted file mode 100644
index db3c867..0000000
--- a/src/de/intarsys/nativec/jna/JnaNativeFunction.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.nativec.jna;
-
-import com.sun.jna.Function;
-import com.sun.jna.NativeLong;
-import com.sun.jna.Pointer;
-import com.sun.jna.WString;
-
-import de.intarsys.nativec.api.CLong;
-import de.intarsys.nativec.api.INativeFunction;
-import de.intarsys.nativec.api.INativeHandle;
-import de.intarsys.nativec.api.CWideString;
-import de.intarsys.nativec.type.INativeObject;
-import de.intarsys.nativec.type.INativeType;
-import de.intarsys.nativec.type.NativeObject;
-import de.intarsys.nativec.type.NativeType;
-
-public class JnaNativeFunction implements INativeFunction {
-
- private Function function;
-
- public JnaNativeFunction(Function function) {
- this.function = function;
- }
-
- protected Function getFunction() {
- return function;
- }
-
- public
- *
- * true if this is "null". This means the associated
- * C-pointer is pointing to 0.
- *
- * @return Answer true if this is "null".
- */
- public boolean isNull() {
- return handle == null || handle.getAddress() == 0;
- }
-
- public void setByte(int index, byte value) {
- handle.setByte(index, value);
- }
-
- public void setByteArray(int index, byte[] value, int valueOffset,
- int valueCount) {
- handle.setByteArray(index, value, valueOffset, valueCount);
- }
-
- public void setCLong(int index, long value) {
- handle.setCLong(index, value);
- }
-
- public void setInt(int index, int value) {
- handle.setInt(index, value);
- }
-
- public void setNativeHandle(int index, INativeHandle value) {
- handle.setNativeHandle(index, value);
- }
-
- public void setShort(int index, short value) {
- handle.setShort(index, value);
- }
-
- public void setString(int index, String value) {
- handle.setString(index, value);
- }
-
- public void setWideString(int index, String value) {
- handle.setWideString(index, value);
- }
-
- /**
- * A string for debugging purposes.
- *
- * @return A string for debugging purposes.
- */
- public String toNestedString() {
- return toString();
- }
-
-}
\ No newline at end of file
diff --git a/src/de/intarsys/nativec/type/NativeReference.java b/src/de/intarsys/nativec/type/NativeReference.java
deleted file mode 100644
index 7460bc2..0000000
--- a/src/de/intarsys/nativec/type/NativeReference.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Copyright (c) 2008, intarsys consulting GmbH
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * - Neither the name of intarsys nor the names of its contributors may be used
- * to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-package de.intarsys.nativec.type;
-
-import de.intarsys.nativec.api.INativeHandle;
-import de.intarsys.nativec.api.NativeInterface;
-
-/**
- * An object representing a reference to another object ("pointer").
- */
-public class NativeReference