java-gobject-introspection r2 - in trunk: . src src/org src/org/gnome src/org/gnome/gir src/org/gnome/gir/compiler src/org/gnome/gir/gobject src/org/gnome/gir/gobject/annotation src/org/gnome/gir/repository
- From: walters svn gnome org
- To: svn-commits-list gnome org
- Subject: java-gobject-introspection r2 - in trunk: . src src/org src/org/gnome src/org/gnome/gir src/org/gnome/gir/compiler src/org/gnome/gir/gobject src/org/gnome/gir/gobject/annotation src/org/gnome/gir/repository
- Date: Sat, 30 Aug 2008 22:06:49 +0000 (UTC)
Author: walters
Date: Sat Aug 30 22:06:49 2008
New Revision: 2
URL: http://svn.gnome.org/viewvc/java-gobject-introspection?rev=2&view=rev
Log:
Initial import from gitorious into GNOME SVN
Added:
trunk/COPYING
trunk/MAINTAINERS
trunk/Makefile
trunk/README
trunk/TODO
trunk/configure (contents, props changed)
trunk/copying-header.txt
trunk/gtktest.js
trunk/gtktest.py
trunk/run.sh (contents, props changed)
trunk/src/
trunk/src/jgir-compile-all.in
trunk/src/org/
trunk/src/org/gnome/
trunk/src/org/gnome/gir/
trunk/src/org/gnome/gir/compiler/
trunk/src/org/gnome/gir/compiler/CodeFactory.java
trunk/src/org/gnome/gir/compiler/Test.java
trunk/src/org/gnome/gir/gobject/
trunk/src/org/gnome/gir/gobject/BooleanByReference.java
trunk/src/org/gnome/gir/gobject/Closure.java
trunk/src/org/gnome/gir/gobject/ComplexReturn.java
trunk/src/org/gnome/gir/gobject/EnumMapper.java
trunk/src/org/gnome/gir/gobject/GBoxed.java
trunk/src/org/gnome/gir/gobject/GBoxedAPI.java
trunk/src/org/gnome/gir/gobject/GClosure.java
trunk/src/org/gnome/gir/gobject/GErrorException.java
trunk/src/org/gnome/gir/gobject/GErrorStruct.java
trunk/src/org/gnome/gir/gobject/GInitiallyUnowned.java
trunk/src/org/gnome/gir/gobject/GList.java
trunk/src/org/gnome/gir/gobject/GMainContext.java
trunk/src/org/gnome/gir/gobject/GModuleAPI.java
trunk/src/org/gnome/gir/gobject/GNative.java
trunk/src/org/gnome/gir/gobject/GObject.java
trunk/src/org/gnome/gir/gobject/GObjectAPI.java
trunk/src/org/gnome/gir/gobject/GObjectGlobals.java
trunk/src/org/gnome/gir/gobject/GOptionContext.java
trunk/src/org/gnome/gir/gobject/GOptionEntry.java
trunk/src/org/gnome/gir/gobject/GOptionGroup.java
trunk/src/org/gnome/gir/gobject/GParamFlags.java
trunk/src/org/gnome/gir/gobject/GQuark.java
trunk/src/org/gnome/gir/gobject/GSList.java
trunk/src/org/gnome/gir/gobject/GScanner.java
trunk/src/org/gnome/gir/gobject/GSignalAPI.java
trunk/src/org/gnome/gir/gobject/GSignalFlags.java
trunk/src/org/gnome/gir/gobject/GSignalQuery.java
trunk/src/org/gnome/gir/gobject/GSource.java
trunk/src/org/gnome/gir/gobject/GString.java
trunk/src/org/gnome/gir/gobject/GTimeVal.java
trunk/src/org/gnome/gir/gobject/GType.java
trunk/src/org/gnome/gir/gobject/GTypeInstance.java
trunk/src/org/gnome/gir/gobject/GTypeMapper.java
trunk/src/org/gnome/gir/gobject/GTypeModule.java
trunk/src/org/gnome/gir/gobject/GTypePlugin.java
trunk/src/org/gnome/gir/gobject/GValue.java
trunk/src/org/gnome/gir/gobject/GValueAPI.java
trunk/src/org/gnome/gir/gobject/GlibAPI.java
trunk/src/org/gnome/gir/gobject/Handle.java
trunk/src/org/gnome/gir/gobject/IntPtr.java
trunk/src/org/gnome/gir/gobject/IntegerEnum.java
trunk/src/org/gnome/gir/gobject/MainLoop.java
trunk/src/org/gnome/gir/gobject/NativeEnum.java
trunk/src/org/gnome/gir/gobject/NativeObject.java
trunk/src/org/gnome/gir/gobject/NativeValue.java
trunk/src/org/gnome/gir/gobject/RefCountedObject.java
trunk/src/org/gnome/gir/gobject/Util.java
trunk/src/org/gnome/gir/gobject/ZeroTerminatedArray.java
trunk/src/org/gnome/gir/gobject/annotation/
trunk/src/org/gnome/gir/gobject/annotation/ConstField.java
trunk/src/org/gnome/gir/gobject/annotation/IncRef.java
trunk/src/org/gnome/gir/gobject/annotation/Invalidate.java
trunk/src/org/gnome/gir/gobject/annotation/RepositoryId.java
trunk/src/org/gnome/gir/gobject/annotation/Return.java
trunk/src/org/gnome/gir/gobject/annotation/ReturnContainer.java
trunk/src/org/gnome/gir/repository/
trunk/src/org/gnome/gir/repository/ArgInfo.java
trunk/src/org/gnome/gir/repository/Argument.java
trunk/src/org/gnome/gir/repository/BaseInfo.java
trunk/src/org/gnome/gir/repository/BoxedInfo.java
trunk/src/org/gnome/gir/repository/CallableInfo.java
trunk/src/org/gnome/gir/repository/CallbackInfo.java
trunk/src/org/gnome/gir/repository/ConstantInfo.java
trunk/src/org/gnome/gir/repository/Direction.java
trunk/src/org/gnome/gir/repository/EnumInfo.java
trunk/src/org/gnome/gir/repository/ErrorDomainInfo.java
trunk/src/org/gnome/gir/repository/FieldInfo.java
trunk/src/org/gnome/gir/repository/FieldInfoFlags.java
trunk/src/org/gnome/gir/repository/FlagsInfo.java
trunk/src/org/gnome/gir/repository/FunctionInfo.java
trunk/src/org/gnome/gir/repository/FunctionInfoFlags.java
trunk/src/org/gnome/gir/repository/GIntrospectionAPI.java
trunk/src/org/gnome/gir/repository/InfoType.java
trunk/src/org/gnome/gir/repository/InterfaceInfo.java
trunk/src/org/gnome/gir/repository/ObjectInfo.java
trunk/src/org/gnome/gir/repository/PropertyInfo.java
trunk/src/org/gnome/gir/repository/RegisteredTypeInfo.java
trunk/src/org/gnome/gir/repository/Repository.java
trunk/src/org/gnome/gir/repository/SignalInfo.java
trunk/src/org/gnome/gir/repository/StructInfo.java
trunk/src/org/gnome/gir/repository/Transfer.java
trunk/src/org/gnome/gir/repository/TypeInfo.java
trunk/src/org/gnome/gir/repository/TypeTag.java
trunk/src/org/gnome/gir/repository/UnionInfo.java
trunk/src/org/gnome/gir/repository/UnresolvedException.java
trunk/src/org/gnome/gir/repository/VFuncInfo.java
trunk/src/org/gnome/gir/repository/VFuncInfoFlags.java
trunk/src/org/gnome/gir/repository/ValueInfo.java
trunk/waf (contents, props changed)
trunk/wscript
Added: trunk/COPYING
==============================================================================
--- (empty file)
+++ trunk/COPYING Sat Aug 30 22:06:49 2008
@@ -0,0 +1,482 @@
+ GNU LIBRARY GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 library GPL. It is
+ numbered 2 because it goes with version 2 of the ordinary GPL.]
+
+ 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 Library General Public License, applies to some
+specially designated Free Software Foundation software, and to any
+other libraries whose authors decide to use it. You can use it for
+your libraries, too.
+
+ When we speak of free software, we are referring to freedom, 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 or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the 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 a program 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.
+
+ Our method of protecting your rights has two steps: (1) copyright
+the library, and (2) offer you this license which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ Also, for each distributor's protection, we want to make certain
+that everyone understands that there is no warranty for this free
+library. If the library is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original
+version, so that any problems introduced by others will not reflect on
+the original authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that companies distributing free
+software will individually obtain patent licenses, thus in effect
+transforming the program into proprietary software. To prevent this,
+we have made it clear that any patent must be licensed for everyone's
+free use or not licensed at all.
+
+ Most GNU software, including some libraries, is covered by the ordinary
+GNU General Public License, which was designed for utility programs. This
+license, the GNU Library General Public License, applies to certain
+designated libraries. This license is quite different from the ordinary
+one; be sure to read it in full, and don't assume that anything in it is
+the same as in the ordinary license.
+
+ The reason we have a separate public license for some libraries is that
+they blur the distinction we usually make between modifying or adding to a
+program and simply using it. Linking a program with a library, without
+changing the library, is in some sense simply using the library, and is
+analogous to running a utility program or application program. However, in
+a textual and legal sense, the linked executable is a combined work, a
+derivative of the original library, and the ordinary General Public License
+treats it as such.
+
+ Because of this blurred distinction, using the ordinary General
+Public License for libraries did not effectively promote software
+sharing, because most developers did not use the libraries. We
+concluded that weaker conditions might promote sharing better.
+
+ However, unrestricted linking of non-free programs would deprive the
+users of those programs of all benefit from the free status of the
+libraries themselves. This Library General Public License is intended to
+permit developers of non-free programs to use free libraries, while
+preserving your freedom as a user of such programs to change the free
+libraries that are incorporated in them. (We have not seen how to achieve
+this as regards changes in header files, but we have achieved it as regards
+changes in the actual functions of the Library.) The hope is that this
+will lead to faster development of free libraries.
+
+ 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, while the latter only
+works together with the library.
+
+ Note that it is possible for a library to be covered by the ordinary
+General Public License rather than by this special one.
+
+ GNU LIBRARY GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library which
+contains a notice placed by the copyright holder or other authorized
+party saying it may be distributed under the terms of this Library
+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 compile 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) 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.
+
+ c) 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.
+
+ d) 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 source code 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 to
+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 Library 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.
+
+ <one line to give the library's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307 USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+ <signature of Ty Coon>, 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
Added: trunk/MAINTAINERS
==============================================================================
--- (empty file)
+++ trunk/MAINTAINERS Sat Aug 30 22:06:49 2008
@@ -0,0 +1,3 @@
+Full Name
+E-mail: walters verbum org
+Userid: walters
\ No newline at end of file
Added: trunk/Makefile
==============================================================================
--- (empty file)
+++ trunk/Makefile Sat Aug 30 22:06:49 2008
@@ -0,0 +1,5 @@
+all:
+ python ./waf build
+
+install: all
+ python ./waf install --destdir=$(DESTDIR)
\ No newline at end of file
Added: trunk/README
==============================================================================
--- (empty file)
+++ trunk/README Sat Aug 30 22:06:49 2008
@@ -0,0 +1,24 @@
+== About java-gobject-introspection ==
+
+The most up-to-date information is likely to be found on the GNOME
+wiki page: http://live.gnome.org/JGIR
+
+= BUILDING =
+
+You must have gobject-introspection and Python >= 2.3 installed.
+Internally, the waf (http://code.google.com/p/waf/) build system is
+used, but a simple "configure" and "Makefile" wrapper is provided.
+You may use the standard:
+
+./configure --prefix=...
+make
+sudo make install
+
+= Using =
+
+After installation, you can run the script:
+
+jgir-compile-all
+
+This will generate .jar files for each .typelib file you have
+installed.
\ No newline at end of file
Added: trunk/TODO
==============================================================================
--- (empty file)
+++ trunk/TODO Sat Aug 30 22:06:49 2008
@@ -0,0 +1,3 @@
+- Documentation on mapping (FooGlobals, signals. etc)
+- Investigate mapping gtk-doc to Javadoc somehow
+- Handle out parameters
Added: trunk/configure
==============================================================================
--- (empty file)
+++ trunk/configure Sat Aug 30 22:06:49 2008
@@ -0,0 +1,2 @@
+#!/bin/sh
+exec python ./waf configure "$@"
\ No newline at end of file
Added: trunk/copying-header.txt
==============================================================================
--- (empty file)
+++ trunk/copying-header.txt Sat Aug 30 22:06:49 2008
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2008 Colin Walters <walters verbum org>
+ *
+ * This file is part of java-gobject-introspection.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307 USA.
+ *
+ */
+
Added: trunk/gtktest.js
==============================================================================
--- (empty file)
+++ trunk/gtktest.js Sat Aug 30 22:06:49 2008
@@ -0,0 +1,9 @@
+print("hello");
+var gtkPkg=Packages.org.gnome.gir.dynamic.Gtk;
+importPackage(gtkPkg);
+print(gtkPkg.Window);
+var win = Window(WindowType.TOPLEVEL);
+var button = Button("hello!");
+win.add(button);
+win.showAll();
+GtkGlobals.main();
Added: trunk/gtktest.py
==============================================================================
--- (empty file)
+++ trunk/gtktest.py Sat Aug 30 22:06:49 2008
@@ -0,0 +1,15 @@
+from org.gnome.gir.dynamic.WebKit import *
+from org.gnome.gir.dynamic.Gtk import *
+from org.gnome.gir.gobject import *
+
+GObjectGlobals.init()
+GtkGlobals.initCheck(None, None)
+win = Window(WindowType.TOPLEVEL);
+sw = ScrolledWindow(None, None)
+win.add(sw)
+wv = WebView()
+wv.open("http://www.gnome.org")
+sw.add(wv)
+win.setSizeRequest(640, 480)
+win.showAll();
+GtkGlobals.main();
Added: trunk/run.sh
==============================================================================
--- (empty file)
+++ trunk/run.sh Sat Aug 30 22:06:49 2008
@@ -0,0 +1,10 @@
+#!/bin/bash
+JGIRSRC=/src/build/gi/share/gitypelibs
+JARS=
+for j in ${JGIRSRC}/*.jar; do
+ JARS="$JARS:$j"
+done
+CLASSPATH=$(build-classpath jna objectweb-asm/asm objectweb-asm/asm-{util,analysis,tree}):${JGIRSRC}/bin:${JARS}
+export CLASSPATH
+echo "CLASSPATH=$CLASSPATH"
+exec env GIREPOPATH=${JGIRSRC}/tests jhbuild run "$@"
\ No newline at end of file
Added: trunk/src/jgir-compile-all.in
==============================================================================
--- (empty file)
+++ trunk/src/jgir-compile-all.in Sat Aug 30 22:06:49 2008
@@ -0,0 +1,2 @@
+#!/bin/sh
+exec ${DEBUG} java ${JAVA_OPTS} -cp "@CLASSPATH@" org.gnome.gir.compiler.CodeFactory "$@"
\ No newline at end of file
Added: trunk/src/org/gnome/gir/compiler/CodeFactory.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/compiler/CodeFactory.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,1597 @@
+package org.gnome.gir.compiler;
+
+import static org.objectweb.asm.Opcodes.AASTORE;
+import static org.objectweb.asm.Opcodes.ACC_ABSTRACT;
+import static org.objectweb.asm.Opcodes.ACC_ENUM;
+import static org.objectweb.asm.Opcodes.ACC_FINAL;
+import static org.objectweb.asm.Opcodes.ACC_INTERFACE;
+import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
+import static org.objectweb.asm.Opcodes.ACC_PROTECTED;
+import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
+import static org.objectweb.asm.Opcodes.ACC_STATIC;
+import static org.objectweb.asm.Opcodes.ACC_SUPER;
+import static org.objectweb.asm.Opcodes.ACC_SYNTHETIC;
+import static org.objectweb.asm.Opcodes.ACONST_NULL;
+import static org.objectweb.asm.Opcodes.ALOAD;
+import static org.objectweb.asm.Opcodes.ANEWARRAY;
+import static org.objectweb.asm.Opcodes.ARETURN;
+import static org.objectweb.asm.Opcodes.ARRAYLENGTH;
+import static org.objectweb.asm.Opcodes.ASTORE;
+import static org.objectweb.asm.Opcodes.ATHROW;
+import static org.objectweb.asm.Opcodes.BIPUSH;
+import static org.objectweb.asm.Opcodes.CHECKCAST;
+import static org.objectweb.asm.Opcodes.DUP;
+import static org.objectweb.asm.Opcodes.GETSTATIC;
+import static org.objectweb.asm.Opcodes.ICONST_0;
+import static org.objectweb.asm.Opcodes.IFNE;
+import static org.objectweb.asm.Opcodes.IFNONNULL;
+import static org.objectweb.asm.Opcodes.ILOAD;
+import static org.objectweb.asm.Opcodes.INVOKESPECIAL;
+import static org.objectweb.asm.Opcodes.INVOKESTATIC;
+import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL;
+import static org.objectweb.asm.Opcodes.ISTORE;
+import static org.objectweb.asm.Opcodes.LRETURN;
+import static org.objectweb.asm.Opcodes.NEW;
+import static org.objectweb.asm.Opcodes.POP;
+import static org.objectweb.asm.Opcodes.PUTSTATIC;
+import static org.objectweb.asm.Opcodes.RETURN;
+import static org.objectweb.asm.Opcodes.V1_6;
+import gnu.getopt.Getopt;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import java.util.zip.ZipOutputStream;
+
+import org.gnome.gir.gobject.GErrorException;
+import org.gnome.gir.gobject.GList;
+import org.gnome.gir.gobject.GObjectAPI;
+import org.gnome.gir.gobject.GSList;
+import org.gnome.gir.repository.ArgInfo;
+import org.gnome.gir.repository.BaseInfo;
+import org.gnome.gir.repository.BoxedInfo;
+import org.gnome.gir.repository.CallableInfo;
+import org.gnome.gir.repository.Direction;
+import org.gnome.gir.repository.EnumInfo;
+import org.gnome.gir.repository.FlagsInfo;
+import org.gnome.gir.repository.FunctionInfo;
+import org.gnome.gir.repository.FunctionInfoFlags;
+import org.gnome.gir.repository.InterfaceInfo;
+import org.gnome.gir.repository.ObjectInfo;
+import org.gnome.gir.repository.RegisteredTypeInfo;
+import org.gnome.gir.repository.Repository;
+import org.gnome.gir.repository.SignalInfo;
+import org.gnome.gir.repository.StructInfo;
+import org.gnome.gir.repository.TypeInfo;
+import org.gnome.gir.repository.TypeTag;
+import org.gnome.gir.repository.ValueInfo;
+import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.FieldVisitor;
+import org.objectweb.asm.Label;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Type;
+
+import com.sun.jna.Pointer;
+import com.sun.jna.PointerType;
+import com.sun.jna.ptr.ByteByReference;
+import com.sun.jna.ptr.FloatByReference;
+import com.sun.jna.ptr.IntByReference;
+import com.sun.jna.ptr.LongByReference;
+import com.sun.jna.ptr.PointerByReference;
+import com.sun.jna.ptr.ShortByReference;
+
+public class CodeFactory {
+
+ private static final Logger logger = Logger.getLogger("org.gnome.gir.Compiler");
+
+ private static final Map<String,String> overrides = new HashMap<String,String>() {
+ private static final long serialVersionUID = 1L;
+
+ {
+ put("GLib.Value", "org/gnome/gir/gobject/GValue");
+ put("GLib.List", "org/gnome/gir/gobject/GList");
+ put("GLib.SList", "org/gnome/gir/gobject/GSList");
+
+ put("GLib.Closure", "org/gnome/gir/gobject/GClosure");
+ put("GLib.Quark", "org/gnome/gir/gobject/GQuark");
+ put("GLib.TimeVal", "org/gnome/gir/gobject/GTimeVal");
+ put("GLib.Scanner", "org/gnome/gir/gobject/GScanner");
+ put("GLib.OptionContext", "org/gnome/gir/gobject/GOptionContext");
+ put("GLib.OptionGroup", "org/gnome/gir/gobject/GOptionGroup");
+ put("GLib.OptionEntry", "org/gnome/gir/gobject/GOptionEntry");
+ put("GLib.String", "org/gnome/gir/gobject/GString");
+ put("GLib.Callback", "com/sun/jna/Callback");
+
+ put("GObject.ParamSpec", "org/gnome/gir/gobject/GObjectAPI$GParamSpec");
+ put("GObject.Object", "org/gnome/gir/gobject/GObject");
+ put("GObject.InitiallyUnowned", "org/gnome/gir/gobject/GInitiallyUnowned");
+ put("GObject.Type", "org/gnome/gir/gobject/GType");
+ put("GObject.TypePlugin", "org/gnome/gir/gobject/GTypePlugin");
+ put("GObject.TypeModule", "org/gnome/gir/gobject/GTypeModule");
+ put("GObject.ObjectClass", "org/gnome/gir/gobject/GObjectAPI$GObjectClass");
+ put("GObject.TypeDebugFlags", "org/gnome/gir/gobject/GObjectAPI$GTypeDebugFlags");
+
+ for (String name : new String[] { "Context" }) {
+ put("Cairo." + name, "com/sun/jna/Pointer");
+ }
+ }
+ };
+
+ public static Type toJava(TypeTag tag) {
+ if (tag == TypeTag.LONG || tag == TypeTag.ULONG ||
+ tag == TypeTag.SSIZE || tag == TypeTag.SIZE)
+ return Type.getType(Long.class);
+ if (tag == TypeTag.ARRAY)
+ return Type.getType(List.class);
+ if (tag == TypeTag.GLIST)
+ return Type.getType(GList.class);
+ if (tag == TypeTag.GSLIST)
+ return Type.getType(GSList.class);
+ if (tag == TypeTag.GHASH)
+ return Type.getType(Map.class);
+ return toTypeBase(tag);
+ }
+
+ public static Type toJava(ArgInfo arg) {
+ //Transfer transfer = arg.getOwnershipTransfer();
+ TypeInfo type = arg.getType();
+ TypeTag tag = type.getTag();
+ if (!type.isPointer() || (tag.equals(TypeTag.UTF8) || tag.equals(TypeTag.FILENAME))) {
+ return toTypeBase(tag);
+ } else if (type.isPointer()) {
+ return toJavaRef(tag);
+ } else {
+ return toTypeBase(tag);
+ }
+ }
+
+ public static Type toJavaRef(TypeTag tag) {
+ Type t = toJava(tag);
+ if (t.equals(Type.getType(Integer.class)))
+ return Type.getType(IntByReference.class);
+ if (t.equals(Type.getType(Long.class)))
+ return Type.getType(LongByReference.class);
+ if (t.equals(Type.getType(Boolean.class)))
+ return Type.getType(IntByReference.class);
+ if (t.equals(Type.getType(Byte.class)))
+ return Type.getType(ByteByReference.class);
+ if (t.equals(Type.getType(Short.class)))
+ return Type.getType(ShortByReference.class);
+ if (t.equals(Type.getType(Float.class)))
+ return Type.getType(FloatByReference.class);
+ if (t.equals(Type.getType(Double.class)))
+ return Type.getType(Double.class);
+ if (t.equals(Type.getType(String.class)) || t.equals(Type.getType(File.class)))
+ return Type.getType(PointerByReference.class);
+ return t;
+ }
+
+ private static Type toTypeBase(TypeTag tag) {
+ if (tag == TypeTag.VOID)
+ return Type.VOID_TYPE;
+ if (tag == TypeTag.BOOLEAN)
+ return Type.getType(Boolean.class);
+ if (tag == TypeTag.INT8 || tag == TypeTag.UINT8)
+ return Type.getType(Byte.class);
+ if (tag == TypeTag.INT16 || tag == TypeTag.UINT16)
+ return Type.getType(Short.class);
+ if (tag == TypeTag.INT32 || tag == TypeTag.UINT32 ||
+ tag == TypeTag.INT || tag == TypeTag.UINT)
+ return Type.getType(Integer.class);
+ if (tag == TypeTag.INT64 || tag == TypeTag.UINT64)
+ return Type.getType(Long.class);
+ if (tag == TypeTag.FLOAT)
+ return Type.getType(Float.class);
+ if (tag == TypeTag.DOUBLE)
+ return Type.getType(Double.class);
+ if (tag == TypeTag.UTF8)
+ return Type.getType(String.class);
+ if (tag == TypeTag.FILENAME)
+ return Type.getType(File.class);
+ return null;
+ }
+
+ private static final String dynamicNamespace = "org/gnome/gir/dynamic/";
+ private static final String publicDynamicNamespace = "org.gnome.gir.dynamic.";
+
+ private Type getCallableReturn(CallableInfo callable) {
+ TypeInfo info = callable.getReturnType();
+ if (info.getTag().equals(TypeTag.INTERFACE)) {
+ if (!requireNamespaceOf(info.getInterface()))
+ return Type.getType(Pointer.class);
+ else
+ return typeFromInterface(info);
+ }
+ return toJava(info.getTag());
+ }
+
+ private Type typeFromInterface(TypeInfo info) {
+ BaseInfo interfaceInfo = info.getInterface();
+ return typeFromInfo(interfaceInfo);
+ }
+
+ private Type typeFromInfo(BaseInfo info) {
+ requireNamespaceOf(info);
+ return Type.getObjectType(getInternalNameMapped(info.getNamespace(), info.getName()));
+ }
+
+ private List<Type> getCallableArgs(CallableInfo callable, boolean isMethod,
+ boolean allowError) {
+ ArgInfo[] args = callable.getArgs();
+ List<Type> types = new ArrayList<Type>();
+ boolean skipFirst = isMethod;
+ for (int i = 0; i < args.length; i++) {
+ ArgInfo arg = args[i];
+ Type t;
+ TypeInfo info = arg.getType();
+ TypeTag tag = info.getTag();
+ if (tag.equals(TypeTag.ERROR)) {
+ if (allowError)
+ continue;
+ return null;
+ }
+ if (arg.getDirection() == Direction.IN) {
+ if (tag.equals(TypeTag.INTERFACE)) {
+ t = typeFromInterface(info);
+ } else {
+ t = toJava(arg);
+ }
+ } else {
+ t = Type.getType(PointerType.class);
+ }
+ if (t == null)
+ return null;
+ if (t.equals(Type.VOID_TYPE))
+ return null;
+ if (skipFirst)
+ skipFirst = false;
+ else
+ types.add(t);
+ }
+
+ return types;
+ }
+
+ public static final class RepositoryClassSet {
+ Map<String,byte[]> klasses;
+
+ public RepositoryClassSet() {
+ }
+
+ public Map<String, byte[]> getKlasses() {
+ return Collections.unmodifiableMap(klasses);
+ }
+ }
+
+ private static String getInternalNameMapped(String namespace, String name) {
+ String key = namespace + "." + name;
+ String val = overrides.get(key);
+ if (val != null)
+ return val;
+ return getInternalName(namespace, name);
+ }
+
+ private static String getInternalName(String namespace, String name) {
+ String caps = name.substring(0, 1).toUpperCase() + name.substring(1);
+ return dynamicNamespace + namespace + "/" + caps;
+ }
+
+ private static String getPublicName(String namespace, String name) {
+ String caps = name.substring(0, 1).toUpperCase() + name.substring(1);
+ return publicDynamicNamespace + namespace + "." + caps;
+ }
+
+ public interface StubClass {
+ public String getNamespace();
+ public String getPublicName();
+ public byte[] getBytes();
+ }
+
+ private static final class InnerClassCompilation implements StubClass {
+ String namespace;
+ String baseName;
+ String internalName;
+ ClassWriter writer;
+ public InnerClassCompilation(String namespace, String baseName) {
+ this.namespace = namespace;
+ this.baseName = baseName;
+ this.internalName = getInternalName(namespace, baseName);
+ this.writer = new ClassWriter(0);
+ }
+ @Override
+ public byte[] getBytes() {
+ return writer.toByteArray();
+ }
+
+ @Override
+ public String getNamespace() {
+ return namespace;
+ }
+
+ @Override
+ public String getPublicName() {
+ return CodeFactory.getPublicName(namespace, baseName);
+ }
+ }
+
+ private static final class ClassCompilation implements StubClass {
+ ClassWriter writer;
+ Set<InnerClassCompilation> innerClasses;
+ String namespace;
+ String baseName;
+ String publicName;
+ String internalName;
+ private boolean closed = false;
+
+ public ClassCompilation(String namespace,
+ String name) {
+ this.writer = new ClassWriter(0);
+ this.innerClasses = new HashSet<InnerClassCompilation>();
+ this.namespace = namespace;
+ this.baseName = name.substring(0, 1).toUpperCase() + name.substring(1);
+ this.publicName = CodeFactory.getPublicName(namespace, name);
+ this.internalName = getInternalName(namespace, name);
+ }
+
+ public InnerClassCompilation newInner() {
+ int size = innerClasses.size();
+ InnerClassCompilation cw = new InnerClassCompilation(namespace, baseName + "$" + size+1);
+ innerClasses.add(cw);
+ return cw;
+ }
+
+ public InnerClassCompilation newInner(String name) {
+ InnerClassCompilation cw = new InnerClassCompilation(namespace, baseName + "$" + name);
+ innerClasses.add(cw);
+ return cw;
+ }
+
+ public void close() {
+ if (!closed) {
+ writer.visitEnd();
+ closed = true;
+ }
+ }
+
+ @Override
+ public byte[] getBytes() {
+ return writer.toByteArray();
+ }
+
+ @Override
+ public String getNamespace() {
+ return namespace;
+ }
+
+ @Override
+ public String getPublicName() {
+ return publicName;
+ }
+ }
+
+ private class InfoCompilation {
+ public ClassCompilation peer;
+ public ClassCompilation api;
+
+ private Set<String> definedApiSymbols = new HashSet<String>();
+
+ protected InfoCompilation(ClassCompilation peer, ClassCompilation api) {
+ this.peer = peer;
+ this.api = api;
+ }
+
+ public boolean tryDefineApi(String symbol, String descriptor) {
+ String dualString = symbol + "/" + descriptor;
+ if (definedApiSymbols.contains(dualString))
+ return false;
+ definedApiSymbols.add(dualString);
+ return true;
+ }
+ }
+
+ public InfoCompilation getCompilation(String namespace, String name) {
+ String peerInternalName = getInternalName(namespace, name);
+ InfoCompilation ret = writers.get(peerInternalName);
+ if (ret == null) {
+ String peerName = name + "$1";
+ ClassCompilation peer = new ClassCompilation(namespace, name);
+ ClassCompilation api = new ClassCompilation(namespace, peerName);
+ ret = new InfoCompilation(peer, api);
+ writers.put(peerInternalName, ret);
+ }
+ return ret;
+ }
+
+ public InfoCompilation getCompilation(BaseInfo info) {
+ return getCompilation(info.getNamespace(), info.getName());
+ }
+
+ public String getGlobalsName(String namespace) {
+ return getInternalName(namespace, namespace+"Globals");
+ }
+
+ public InfoCompilation getGlobals(String namespace) {
+ return getCompilation(namespace, namespace + "Globals");
+ }
+
+ public String getInternals(BaseInfo info) {
+ return getGlobalsName(info.getNamespace()) + "$Internals";
+ }
+
+ public InfoCompilation getCompilation(FunctionInfo info) {
+ return getGlobals(info.getNamespace());
+ }
+
+ private final Repository repo;
+ private final Set<String> alreadyCompiled = new HashSet<String>();
+ private final Set<String> loadFailed = new HashSet<String>();
+ private final Set<String> pendingCompilation = new HashSet<String>();
+ private final Map<String, InfoCompilation> writers = new HashMap<String, InfoCompilation>();
+ private final Map<String, InfoCompilation> globals = new HashMap<String, InfoCompilation>();
+ private final Map<String,String> namespaceShlibMapping = new HashMap<String, String>();
+
+ private CodeFactory(Repository repo) {
+ this.repo = repo;
+ this.alreadyCompiled.add("GLib");
+ }
+
+ private static final Map<Repository,List<StubClass>> loadedRepositories
+ = new WeakHashMap<Repository, List<StubClass>>();
+
+ private static String getInternalName(BaseInfo info) {
+ return getInternalName(info.getNamespace(), info.getName());
+ }
+
+ private static String getInternalNameMapped(BaseInfo info) {
+ return getInternalNameMapped(info.getNamespace(), info.getName());
+ }
+
+ @SuppressWarnings("unused")
+ private static String getPublicName(BaseInfo info) {
+ return getPublicName(info.getNamespace(), info.getName());
+ }
+
+ private String enumNameToUpper(String nick) {
+ return nick.replace("-", "_").toUpperCase();
+ }
+
+ private void compile(EnumInfo info) {
+ InfoCompilation compilation = getCompilation(info);
+ compilation.peer.writer.visit(V1_6, ACC_PUBLIC + ACC_FINAL + ACC_SUPER + ACC_ENUM, compilation.peer.internalName,
+ "Ljava/lang/Enum<L" + compilation.peer.internalName + ";>;", "java/lang/Enum", null);
+ ValueInfo[] values = info.getValueInfo();
+ for (ValueInfo valueInfo : values) {
+ String name = enumNameToUpper(valueInfo.getName());
+ FieldVisitor fv = compilation.peer.writer.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC + ACC_ENUM,
+ name, "L" + compilation.peer.internalName + ";", null, null);
+ fv.visitEnd();
+ }
+
+ /* And now a HUGE chunk of stuff to comply with the enum spec */
+
+ String arrayDescriptor = "[L" + compilation.peer.internalName + ";";
+
+ FieldVisitor fv = compilation.peer.writer.visitField(ACC_PRIVATE + ACC_FINAL + ACC_STATIC + ACC_SYNTHETIC,
+ "ENUM$VALUES", arrayDescriptor, null, null);
+ fv.visitEnd();
+
+ MethodVisitor mv = compilation.peer.writer.visitMethod(ACC_PRIVATE, "<init>", "(Ljava/lang/String;I)V", null, null);
+ mv.visitCode();
+ Label l0 = new Label();
+ mv.visitLabel(l0);
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitVarInsn(ALOAD, 1);
+ mv.visitVarInsn(ILOAD, 2);
+ mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Enum", "<init>", "(Ljava/lang/String;I)V");
+ mv.visitInsn(RETURN);
+ Label l1 = new Label();
+ mv.visitLabel(l1);
+ mv.visitLocalVariable("this", arrayDescriptor, null, l0, l1, 0);
+ mv.visitMaxs(3, 3);
+ mv.visitEnd();
+
+ mv = compilation.peer.writer.visitMethod(ACC_STATIC, "<clinit>", "()V", null, null);
+ mv.visitCode();
+ l0 = new Label();
+ mv.visitLabel(l0);
+ int i = 0;
+ for (ValueInfo valueInfo : values) {
+ String name = enumNameToUpper(valueInfo.getName());
+ mv.visitTypeInsn(NEW, compilation.peer.internalName);
+ mv.visitInsn(DUP);
+ mv.visitLdcInsn(name);
+ mv.visitIntInsn(BIPUSH, i);
+ i++;
+ mv.visitMethodInsn(INVOKESPECIAL, compilation.peer.internalName, "<init>", "(Ljava/lang/String;I)V");
+ mv.visitFieldInsn(PUTSTATIC, compilation.peer.internalName,
+ name, "L" + compilation.peer.internalName+ ";");
+ }
+ mv.visitIntInsn(BIPUSH, values.length);
+ mv.visitTypeInsn(ANEWARRAY, compilation.peer.internalName);
+ i = 0;
+ for (ValueInfo valueInfo : values) {
+ String name = enumNameToUpper(valueInfo.getName());
+ mv.visitInsn(DUP);
+ mv.visitIntInsn(BIPUSH, i);
+ i++;
+ mv.visitFieldInsn(GETSTATIC, compilation.peer.internalName, name,
+ "L" + compilation.peer.internalName + ";");
+ mv.visitInsn(AASTORE);
+ }
+ mv.visitFieldInsn(PUTSTATIC, compilation.peer.internalName, "ENUM$VALUES", arrayDescriptor);
+ mv.visitInsn(RETURN);
+ mv.visitMaxs(4, 0);
+ mv.visitEnd();
+
+ mv = compilation.peer.writer.visitMethod(ACC_PUBLIC + ACC_STATIC, "values", "()" + arrayDescriptor, null, null);
+ mv.visitCode();
+ l0 = new Label();
+ mv.visitLabel(l0);
+ mv.visitFieldInsn(GETSTATIC, compilation.peer.internalName, "ENUM$VALUES", arrayDescriptor);
+ mv.visitInsn(DUP);
+ mv.visitVarInsn(ASTORE, 0);
+ mv.visitInsn(ICONST_0);
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitInsn(ARRAYLENGTH);
+ mv.visitInsn(DUP);
+ mv.visitVarInsn(ISTORE, 1);
+ mv.visitTypeInsn(ANEWARRAY, compilation.peer.internalName);
+ mv.visitInsn(DUP);
+ mv.visitVarInsn(ASTORE, 2);
+ mv.visitInsn(ICONST_0);
+ mv.visitVarInsn(ILOAD, 1);
+ mv.visitMethodInsn(INVOKESTATIC, "java/lang/System", "arraycopy", "(Ljava/lang/Object;ILjava/lang/Object;II)V");
+ mv.visitVarInsn(ALOAD, 2);
+ mv.visitInsn(ARETURN);
+ mv.visitMaxs(5, 3);
+ mv.visitEnd();
+
+ mv = compilation.peer.writer.visitMethod(ACC_PUBLIC + ACC_STATIC, "valueOf", "(Ljava/lang/String;)L" + compilation.peer.internalName + ";", null, null);
+ mv.visitCode();
+ l0 = new Label();
+ mv.visitLabel(l0);
+ mv.visitLdcInsn(Type.getType("L" + compilation.peer.internalName + ";"));
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitMethodInsn(INVOKESTATIC, "java/lang/Enum", "valueOf", "(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;");
+ mv.visitTypeInsn(CHECKCAST, compilation.peer.internalName);
+ mv.visitInsn(ARETURN);
+ mv.visitMaxs(2, 1);
+ mv.visitEnd();
+
+ compilation.peer.close();
+ }
+
+ private void compile(FlagsInfo info) {
+ InfoCompilation compilation = getCompilation(info);
+ compilation.peer.writer.visit(V1_6, ACC_PUBLIC + ACC_ABSTRACT + ACC_INTERFACE, compilation.peer.internalName, null, "java/lang/Object", null);
+ ValueInfo[] values = info.getValueInfo();
+ for (ValueInfo valueInfo : values) {
+ FieldVisitor fv = compilation.peer.writer.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC,
+ enumNameToUpper(valueInfo.getName()), "I", null, null);
+ fv.visitEnd();
+ }
+ compilation.peer.close();
+ }
+
+ private String ucaseToCamel(String ucase) {
+ String[] components = ucase.split("_");
+ for (int i = 1; i < components.length; i++)
+ components[i] = "" + Character.toUpperCase(components[i].charAt(0)) + components[i].substring(1);
+ StringBuilder builder = new StringBuilder();
+ for (String component : components)
+ builder.append(component);
+ return builder.toString();
+ }
+
+ private String ucaseToPascal(String ucase) {
+ String camel = ucaseToCamel(ucase);
+ return Character.toUpperCase(camel.charAt(0)) + camel.substring(1);
+ }
+
+ private void compileDefaultConstructor(ObjectInfo info, InfoCompilation compilation) {
+ BaseInfo parent = info.getParent();
+ String parentInternalType = getInternalNameMapped(parent);
+
+ MethodVisitor mv = compilation.peer.writer.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
+ mv.visitCode();
+ Label l0 = new Label();
+ mv.visitLabel(l0);
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitMethodInsn(INVOKESTATIC, compilation.peer.internalName, "getGType", "()Lorg/gnome/gir/gobject/GType;");
+ mv.visitInsn(ACONST_NULL);
+ mv.visitMethodInsn(INVOKESPECIAL, parentInternalType, "<init>", "(Lorg/gnome/gir/gobject/GType;[Ljava/lang/Object;)V");
+ Label l1 = new Label();
+ mv.visitLabel(l1);
+ mv.visitInsn(RETURN);
+ Label l2 = new Label();
+ mv.visitLabel(l2);
+ mv.visitLocalVariable("this", "L" + compilation.peer.internalName + ";", null, l0, l2, 0);
+ mv.visitMaxs(3, 1);
+ mv.visitEnd();
+
+ mv = compilation.peer.writer.visitMethod(ACC_PUBLIC, "<init>", "([Ljava/lang/Object;)V", null, null);
+ mv.visitCode();
+ l0 = new Label();
+ mv.visitLabel(l0);
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitMethodInsn(INVOKESTATIC, compilation.peer.internalName, "getGType", "()Lorg/gnome/gir/gobject/GType;");
+ mv.visitVarInsn(ALOAD, 1);
+ mv.visitMethodInsn(INVOKESPECIAL, parentInternalType, "<init>", "(Lorg/gnome/gir/gobject/GType;[Ljava/lang/Object;)V");
+ l1 = new Label();
+ mv.visitLabel(l1);
+ mv.visitInsn(RETURN);
+ l2 = new Label();
+ mv.visitLabel(l2);
+ mv.visitLocalVariable("this", "L"+ compilation.peer.internalName + ";", null, l0, l2, 0);
+ mv.visitLocalVariable("args", "[Ljava/lang/Object;", null, l0, l2, 1);
+ mv.visitMaxs(3, 2);
+ mv.visitEnd();
+
+ mv = compilation.peer.writer.visitMethod(ACC_PROTECTED, "<init>", "(Lorg/gnome/gir/gobject/GType;[Ljava/lang/Object;)V", null, null);
+ mv.visitCode();
+ l0 = new Label();
+ mv.visitLabel(l0);
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitVarInsn(ALOAD, 1);
+ mv.visitVarInsn(ALOAD, 2);
+ mv.visitMethodInsn(INVOKESPECIAL, parentInternalType, "<init>", "(Lorg/gnome/gir/gobject/GType;[Ljava/lang/Object;)V");
+ l1 = new Label();
+ mv.visitLabel(l1);
+ mv.visitInsn(RETURN);
+ l2 = new Label();
+ mv.visitLabel(l2);
+ mv.visitLocalVariable("this", "L"+ compilation.peer.internalName + ";", null, l0, l2, 0);
+ mv.visitLocalVariable("gtype", "Lorg/gnome/gir/gobject/GType;", null, l0, l2, 1);
+ mv.visitLocalVariable("args", "[Ljava/lang/Object;", null, l0, l2, 2);
+ mv.visitMaxs(3, 3);
+ mv.visitEnd();
+ }
+
+ private void compileStaticConstructor(ObjectInfo info, InfoCompilation compilation, FunctionInfo fi) {
+ String globalInternalsName = getInternals(info);
+
+ ArgInfo[] argInfos = fi.getArgs();
+ List<Type> args = getCallableArgs(fi, false, false);
+ String descriptor = Type.getMethodDescriptor(Type.VOID_TYPE, args.toArray(new Type[0]));
+
+ int nArgs = args.size();
+
+ String name = ucaseToCamel(fi.getName());
+ MethodVisitor mv = compilation.peer.writer.visitMethod(ACC_PUBLIC + ACC_STATIC + ACC_FINAL, name, descriptor, null, null);
+ mv.visitCode();
+ Label l0 = new Label();
+ mv.visitLabel(l0);
+ mv.visitTypeInsn(NEW, compilation.peer.internalName);
+ mv.visitInsn(DUP);
+ mv.visitFieldInsn(GETSTATIC, globalInternalsName, "library", "Lcom/sun/jna/NativeLibrary;");
+ mv.visitLdcInsn(fi.getSymbol());
+ mv.visitMethodInsn(INVOKEVIRTUAL, "com/sun/jna/NativeLibrary", "getFunction", "(Ljava/lang/String;)Lcom/sun/jna/Function;");
+ mv.visitLdcInsn(Type.getType("Lcom/sun/jna/Pointer;"));
+ mv.visitIntInsn(BIPUSH, args.size());
+ mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
+ for (int i = 0; i < nArgs; i++) {
+ mv.visitInsn(DUP);
+ mv.visitIntInsn(BIPUSH, i);
+ mv.visitVarInsn(ALOAD, i);
+ mv.visitInsn(AASTORE);
+ }
+ mv.visitFieldInsn(GETSTATIC, globalInternalsName, "invocationOptions", "Ljava/util/Map;");
+ mv.visitMethodInsn(INVOKEVIRTUAL, "com/sun/jna/Function", "invoke", "(Ljava/lang/Class;[Ljava/lang/Object;Ljava/util/Map;)Ljava/lang/Object;");
+ mv.visitTypeInsn(CHECKCAST, "com/sun/jna/Pointer");
+ mv.visitMethodInsn(INVOKESTATIC, compilation.peer.internalName, "initializer",
+ "(Lcom/sun/jna/Pointer;)Lorg/gnome/gir/gobject/Handle$Initializer;");
+ mv.visitMethodInsn(INVOKESPECIAL, compilation.peer.internalName, "<init>", "(Lorg/gnome/gir/gobject/Handle$Initializer;)V");
+ mv.visitInsn(ARETURN);
+ Label l4 = new Label();
+ mv.visitLabel(l4);
+ for (int i = 0; i < nArgs; i++) {
+ mv.visitLocalVariable(argInfos[i].getName(), args.get(i).toString(), null, l0, l4, i);
+ }
+ mv.visitMaxs(8, nArgs);
+ mv.visitEnd();
+ }
+
+ private void compileConstructor(ObjectInfo info, InfoCompilation compilation, FunctionInfo fi) {
+ String globalInternalsName = getInternals(info);
+
+ ArgInfo[] argInfos = fi.getArgs();
+ List<Type> args = getCallableArgs(fi, false, false);
+ BaseInfo parent = info.getParent();
+ String parentInternalType = getInternalNameMapped(parent);
+ String descriptor = Type.getMethodDescriptor(Type.VOID_TYPE, args.toArray(new Type[0]));
+
+ int nArgs = args.size();
+
+ MethodVisitor mv = compilation.peer.writer.visitMethod(ACC_PUBLIC, "<init>", descriptor, null, null);
+ mv.visitCode();
+ Label l0 = new Label();
+ mv.visitLabel(l0);
+ mv.visitVarInsn(ALOAD, 0);
+ Label l2 = new Label();
+ mv.visitLabel(l2);
+ mv.visitFieldInsn(GETSTATIC, globalInternalsName, "library", "Lcom/sun/jna/NativeLibrary;");
+ mv.visitLdcInsn(fi.getSymbol());
+ mv.visitMethodInsn(INVOKEVIRTUAL, "com/sun/jna/NativeLibrary", "getFunction", "(Ljava/lang/String;)Lcom/sun/jna/Function;");
+ mv.visitLdcInsn(Type.getType("Lcom/sun/jna/Pointer;"));
+ mv.visitIntInsn(BIPUSH, args.size());
+ mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
+ for (int i = 0; i < nArgs; i++) {
+ mv.visitInsn(DUP);
+ mv.visitIntInsn(BIPUSH, i);
+ mv.visitVarInsn(ALOAD, i+1);
+ mv.visitInsn(AASTORE);
+ }
+ mv.visitFieldInsn(GETSTATIC, globalInternalsName, "invocationOptions", "Ljava/util/Map;");
+ mv.visitMethodInsn(INVOKEVIRTUAL, "com/sun/jna/Function", "invoke", "(Ljava/lang/Class;[Ljava/lang/Object;Ljava/util/Map;)Ljava/lang/Object;");
+ mv.visitTypeInsn(CHECKCAST, "com/sun/jna/Pointer");
+ mv.visitMethodInsn(INVOKESTATIC, compilation.peer.internalName, "initializer",
+ "(Lcom/sun/jna/Pointer;)Lorg/gnome/gir/gobject/Handle$Initializer;");
+ mv.visitMethodInsn(INVOKESPECIAL, parentInternalType, "<init>", "(Lorg/gnome/gir/gobject/Handle$Initializer;)V");
+ Label l3 = new Label();
+ mv.visitLabel(l3);
+ mv.visitInsn(RETURN);
+ Label l4 = new Label();
+ mv.visitLabel(l4);
+ mv.visitLocalVariable("this", "L" + compilation.peer.internalName + ";", null, l0, l4, 0);
+ for (int i = 0; i < nArgs; i++) {
+ mv.visitLocalVariable(argInfos[i].getName(), args.get(i).toString(), null, l0, l3, i+1);
+ }
+ mv.visitMaxs(9, 1+nArgs);
+ mv.visitEnd();
+ }
+
+ private void compileSignal(ObjectInfo info, InfoCompilation compilation, CallableCompilationContext ctx, SignalInfo sig) {
+ String rawSigName = sig.getName();
+ String sigName = rawSigName.replace('-', '_');
+ String sigClass = ucaseToPascal(sigName);
+ String sigHandlerName = "on" + sigClass;
+ InnerClassCompilation sigCompilation = compilation.peer.newInner(sigClass);
+ compilation.peer.writer.visitInnerClass(sigCompilation.internalName, compilation.peer.internalName, sigClass,
+ ACC_PUBLIC + ACC_ABSTRACT + ACC_STATIC + ACC_INTERFACE);
+ sigCompilation.writer.visit(V1_6, ACC_PUBLIC + ACC_ABSTRACT + ACC_INTERFACE,
+ sigCompilation.internalName, null, "java/lang/Object", new String[] { "org/gnome/gir/gobject/Closure" });
+ sigCompilation.writer.visitInnerClass(sigCompilation.internalName, compilation.peer.internalName,
+ sigClass, ACC_PUBLIC + ACC_STATIC + ACC_ABSTRACT + ACC_INTERFACE);
+
+
+ /* public static final String METHOD_NAME = */
+ FieldVisitor fv = sigCompilation.writer.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC,
+ "METHOD_NAME", "Ljava/lang/String;", null, sigHandlerName);
+ fv.visitEnd();
+
+ String descriptor = Type.getMethodDescriptor(ctx.returnType, ctx.argTypes.toArray(new Type[0]));
+
+ MethodVisitor mv = sigCompilation.writer.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, sigHandlerName, descriptor, null, null);
+ mv.visitEnd();
+
+ /* public final long connect(SIGCLASS proxy) */
+ mv = compilation.peer.writer.visitMethod(ACC_PUBLIC + ACC_FINAL, "connect", "(L"+ sigCompilation.internalName + ";)J", null, null);
+ mv.visitCode();
+ Label l0 = new Label();
+ mv.visitLabel(l0);
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitLdcInsn(rawSigName);
+ mv.visitVarInsn(ALOAD, 1);
+ mv.visitMethodInsn(INVOKEVIRTUAL, compilation.peer.internalName, "connect", "(Ljava/lang/String;Lorg/gnome/gir/gobject/Closure;)J");
+ mv.visitInsn(LRETURN);
+ Label l1 = new Label();
+ mv.visitLabel(l1);
+ mv.visitLocalVariable("this", "L"+ compilation.peer.internalName + ";", null, l0, l1, 0);
+ mv.visitLocalVariable("c", "L" + sigCompilation.internalName + ";", null, l0, l1, 1);
+ mv.visitMaxs(3, 2);
+ mv.visitEnd();
+
+ sigCompilation.writer.visitEnd();
+ }
+
+ private void compile(ObjectInfo info) {
+ Label l0, l1, l2;
+ InfoCompilation compilation = getCompilation(info);
+
+ if (info.getNamespace().equals("GObject") && info.getName().equals("Object"))
+ return;
+
+ String internalName = getInternalName(info);
+ BaseInfo parent = info.getParent();
+ String parentInternalName;
+
+ requireNamespaceOf(parent);
+ parentInternalName = getInternalNameMapped(parent);
+
+ String[] interfaces = null;
+ InterfaceInfo[] giInterfaces = info.getInterfaces();
+ if (giInterfaces.length > 0) {
+ interfaces = new String[giInterfaces.length];
+ }
+ for (int i = 0; i < giInterfaces.length; i++) {
+ interfaces[i] = getInternalNameMapped(giInterfaces[i]);
+ }
+
+ compilation.peer.writer.visit(V1_6, ACC_PUBLIC + ACC_SUPER, internalName, null, parentInternalName, interfaces);
+
+ for (SignalInfo sig : info.getSignals()) {
+ CallableCompilationContext ctx = tryCompileCallable(sig);
+ if (ctx == null)
+ continue;
+ compileSignal(info, compilation, ctx, sig);
+ }
+
+ writeGetGType(info, compilation);
+
+ MethodVisitor mv = compilation.peer.writer.visitMethod(ACC_PROTECTED, "<init>", "(Lorg/gnome/gir/gobject/Handle$Initializer;)V", null, null);
+ mv.visitCode();
+ l0 = new Label();
+ mv.visitLabel(l0);
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitVarInsn(ALOAD, 1);
+ mv.visitMethodInsn(INVOKESPECIAL, parentInternalName, "<init>", "(Lorg/gnome/gir/gobject/Handle$Initializer;)V");
+ l1 = new Label();
+ mv.visitLabel(l1);
+ mv.visitInsn(RETURN);
+ l2 = new Label();
+ mv.visitLabel(l2);
+ mv.visitLocalVariable("this", "L" + internalName + ";", null, l0, l2, 0);
+ mv.visitLocalVariable("init", "Lorg/gnome/gir/gobject/Handle$Initializer;", null, l0, l2, 1);
+ mv.visitMaxs(2, 2);
+ mv.visitEnd();
+
+ compileDefaultConstructor(info, compilation);
+
+ Map<String,Set<FunctionInfo>> ctors = new HashMap<String, Set<FunctionInfo>>();
+
+ // First gather the set of all constructors; we need to avoid name clashes
+ for (FunctionInfo fi : info.getMethods()) {
+ boolean isConstructor = (fi.getFlags() & FunctionInfoFlags.IS_CONSTRUCTOR) != 0;
+ if (!isConstructor)
+ continue;
+ List<Type> args = getCallableArgs(fi, false, false);
+ if (args == null) {
+ logger.warning("Skipping constructor with unhandled arg signature: " + fi.getSymbol());
+ continue;
+ }
+ if (args.size() == 0) {
+ logger.fine("Skipping 0-args constructor: " + fi.getName());
+ continue;
+ }
+ String descriptor = Type.getMethodDescriptor(Type.VOID_TYPE, args.toArray(new Type[0]));
+ if (!ctors.containsKey(descriptor)) {
+ ctors.put(descriptor, new HashSet<FunctionInfo>());
+ }
+ Set<FunctionInfo> set = ctors.get(descriptor);
+ set.add(fi);
+ }
+
+ for (Set<FunctionInfo> ctorGroup : ctors.values()) {
+ FunctionInfo first = ctorGroup.iterator().next();
+ if (ctorGroup.size() == 1) {
+ compileConstructor(info, compilation, first);
+ } else {
+ logger.info("Constructor name " + first.getSymbol() + " clashes");
+ for (FunctionInfo ctor : ctorGroup) {
+ compileStaticConstructor(info, compilation, ctor);
+ }
+ }
+ }
+
+ // Now do methods
+ Set<String> sigs = new HashSet<String>();
+ for (FunctionInfo fi : info.getMethods()) {
+ boolean isConstructor = (fi.getFlags() & FunctionInfoFlags.IS_CONSTRUCTOR) != 0;
+ if (isConstructor)
+ continue;
+ CallableCompilationContext ctx = tryCompileCallable(fi, sigs);
+ if (ctx == null)
+ continue;
+ writeCallable(ACC_PUBLIC, info, compilation, fi, ctx);
+ }
+ for (InterfaceInfo iface : giInterfaces) {
+ for (FunctionInfo fi: iface.getMethods()) {
+ CallableCompilationContext ctx = tryCompileCallable(fi, sigs);
+ if (ctx == null)
+ continue;
+ ctx.isInterfaceMethod = true;
+ ctx.targetInterface = iface;
+ writeCallable(ACC_PUBLIC, info, compilation, fi, ctx);
+ }
+ }
+ compilation.peer.close();
+ }
+
+ private void compile(InterfaceInfo info) {
+ InfoCompilation compilation = getCompilation(info);
+
+ String internalName = getInternalName(info);
+
+ compilation.peer.writer.visit(V1_6, ACC_PUBLIC + ACC_ABSTRACT + ACC_INTERFACE, internalName, null, "java/lang/Object", null);
+ Set<String> sigs = new HashSet<String>();
+ for (FunctionInfo fi : info.getMethods()) {
+ CallableCompilationContext ctx = tryCompileCallable(fi, sigs);
+ if (ctx == null)
+ continue;
+ String name = ucaseToCamel(fi.getName());
+ String descriptor = Type.getMethodDescriptor(ctx.returnType, ctx.argTypes.toArray(new Type[0]));
+ MethodVisitor mv = compilation.peer.writer.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, name, descriptor, null, null);
+ mv.visitEnd();
+ }
+ compilation.peer.close();
+ }
+
+ private static final class CallableCompilationContext {
+ Type returnType;
+ ArgInfo[] args;
+ List<Type> argTypes;
+ boolean throwsGError;
+ boolean isInterfaceMethod = false;
+ InterfaceInfo targetInterface = null;
+ public CallableCompilationContext(Type returnType, ArgInfo[] args,
+ List<Type> argTypes, boolean throwsGError) {
+ this.returnType = returnType;
+ this.args = args;
+ this.argTypes = argTypes;
+ this.throwsGError = throwsGError;
+ }
+ }
+
+ private CallableCompilationContext tryCompileCallable(SignalInfo si) {
+ Type returnType = getCallableReturn(si);
+ if (returnType == null) {
+ logger.warning("Skipping signal with unhandled return signature: " + si.getName());
+ return null;
+ }
+ ArgInfo[] argInfos = si.getArgs();
+ List<Type> args = getCallableArgs(si, false, false);
+ if (args == null) {
+ logger.warning("Skipping signal with unhandled arg signature: " + si.getName());
+ return null;
+ }
+ return new CallableCompilationContext(returnType, argInfos, args, false);
+ }
+
+ private CallableCompilationContext tryCompileCallable(FunctionInfo fi, Set<String> seenSignatures) {
+ Type returnType = getCallableReturn(fi);
+ if (returnType == null) {
+ logger.warning("Skipping function with unhandled return signature: " + fi.getSymbol());
+ return null;
+ }
+ ArgInfo[] argInfos = fi.getArgs();
+ boolean throwsGError = argInfos.length > 0 &&
+ argInfos[argInfos.length-1].getType().getTag().equals(TypeTag.ERROR);
+ List<Type> args = getCallableArgs(fi, (fi.getFlags() & FunctionInfoFlags.IS_METHOD) > 0,
+ throwsGError);
+ if (args == null) {
+ logger.warning("Skipping function with unhandled arg signature: " + fi.getSymbol());
+ return null;
+ }
+ StringBuilder builder = new StringBuilder(fi.getName());
+ builder.append("(");
+ for (Type arg: args)
+ builder.append(arg.getDescriptor());
+ builder.append(")");
+ builder.append(returnType.getDescriptor());
+ String signature = builder.toString();
+ if (seenSignatures.contains(signature)) {
+ logger.warning("Function " + fi.getSymbol() + " duplicates signature: "
+ + signature);
+ return null;
+ }
+ seenSignatures.add(signature);
+ return new CallableCompilationContext(returnType, argInfos, args, throwsGError);
+ }
+
+ private void writeCallable(int accessFlags,
+ RegisteredTypeInfo parent, InfoCompilation compilation, FunctionInfo fi,
+ CallableCompilationContext ctx) {
+ String descriptor = Type.getMethodDescriptor(ctx.returnType, ctx.argTypes.toArray(new Type[0]));
+ String name = ucaseToCamel(fi.getName());
+
+ String[] exceptions = null;
+ if (ctx.throwsGError) {
+ exceptions = new String[] { "org/gnome/gir/gobject/GErrorException" };
+ }
+ MethodVisitor mv = compilation.peer.writer.visitMethod(accessFlags,
+ name, descriptor, null, exceptions);
+
+ String globalInternalsName = getInternals(fi);
+ boolean includeThis = (fi.getFlags() & FunctionInfoFlags.IS_METHOD) > 0;
+ String symbol = fi.getSymbol();
+
+ mv.visitCode();
+ int nArgs = ctx.argTypes.size();
+ int nInvokeArgs = nArgs;
+ if (includeThis)
+ nInvokeArgs += 1;
+ int functionOffset = nInvokeArgs+1;
+ int arrayOffset = functionOffset+1;
+ int resultOffset = arrayOffset+1;
+ int errorOffset = resultOffset;
+ if (ctx.throwsGError)
+ errorOffset += 1;
+ Label jtarget;
+ Label l0 = new Label();
+ mv.visitLabel(l0);
+ if (ctx.throwsGError) {
+ mv.visitTypeInsn(NEW, "com/sun/jna/ptr/PointerByReference");
+ mv.visitInsn(DUP);
+ mv.visitInsn(ACONST_NULL);
+ mv.visitMethodInsn(INVOKESPECIAL, "com/sun/jna/ptr/PointerByReference", "<init>", "(Lcom/sun/jna/Pointer;)V");
+ mv.visitVarInsn(ASTORE, errorOffset);
+ }
+ mv.visitFieldInsn(GETSTATIC, globalInternalsName, "library", "Lcom/sun/jna/NativeLibrary;");
+ mv.visitLdcInsn(symbol);
+ mv.visitMethodInsn(INVOKEVIRTUAL, "com/sun/jna/NativeLibrary", "getFunction", "(Ljava/lang/String;)Lcom/sun/jna/Function;");
+ mv.visitVarInsn(ASTORE, functionOffset);
+ Label l1 = new Label();
+ mv.visitLabel(l1);
+ mv.visitIntInsn(BIPUSH, nInvokeArgs + (ctx.throwsGError ? 1 : 0));
+ mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
+ if (ctx.isInterfaceMethod) {
+ mv.visitInsn(DUP);
+ mv.visitIntInsn(BIPUSH, 0);
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitMethodInsn(INVOKEVIRTUAL, compilation.peer.internalName, "handle", "()Lcom/sun/jna/Pointer;");
+ mv.visitMethodInsn(INVOKESTATIC, getInternalName(ctx.targetInterface),
+ "getGType", "()Lorg/gnome/gir/gobject/GType;");
+ mv.visitMethodInsn(INVOKESTATIC, "org/gnome/gir/gobject/GTypeInstance",
+ "peekInterface", "(Lcom/sun/jna/Pointer;Lorg/gnome/gir/gobject/GType;)Lcom/sun/jna/Pointer;");
+ mv.visitInsn(AASTORE);
+ }
+ for (int i = ctx.isInterfaceMethod ? 1 : 0; i < nInvokeArgs; i++) {
+ mv.visitInsn(DUP);
+ mv.visitIntInsn(BIPUSH, i);
+ mv.visitVarInsn(ALOAD, i);
+ mv.visitInsn(AASTORE);
+ }
+ if (ctx.throwsGError) {
+ mv.visitInsn(DUP);
+ mv.visitIntInsn(BIPUSH, nInvokeArgs);
+ mv.visitVarInsn(ALOAD, errorOffset);
+ mv.visitInsn(AASTORE);
+ }
+ mv.visitVarInsn(ASTORE, arrayOffset);
+ Label l2 = new Label();
+ mv.visitLabel(l2);
+ mv.visitVarInsn(ALOAD, functionOffset);
+ if (ctx.returnType.equals(Type.VOID_TYPE)) {
+ mv.visitLdcInsn(Type.getType(Void.class));
+ } else {
+ mv.visitLdcInsn(ctx.returnType);
+ }
+ mv.visitVarInsn(ALOAD, arrayOffset);
+ mv.visitFieldInsn(GETSTATIC, globalInternalsName, "invocationOptions", "Ljava/util/Map;");
+ mv.visitMethodInsn(INVOKEVIRTUAL, "com/sun/jna/Function", "invoke", "(Ljava/lang/Class;[Ljava/lang/Object;Ljava/util/Map;)Ljava/lang/Object;");
+ Label l3 = new Label();
+ mv.visitLabel(l3);
+ if (!ctx.throwsGError) {
+ if (ctx.returnType.equals(Type.VOID_TYPE)) {
+ mv.visitInsn(POP);
+ mv.visitInsn(RETURN);
+ } else {
+ mv.visitTypeInsn(CHECKCAST, ctx.returnType.getInternalName());
+ mv.visitInsn(ARETURN);
+ }
+ } else {
+ jtarget = new Label();
+ mv.visitTypeInsn(CHECKCAST, ctx.returnType.getInternalName());
+ mv.visitInsn(DUP);
+ mv.visitVarInsn(ASTORE, resultOffset);
+ mv.visitInsn(DUP);
+ if (ctx.returnType.equals(Type.getType(Boolean.class))) {
+ mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z");
+ mv.visitJumpInsn(IFNE, jtarget);
+ } else {
+ mv.visitJumpInsn(IFNONNULL, jtarget);
+ }
+ mv.visitTypeInsn(NEW, "org/gnome/gir/gobject/GErrorException");
+ mv.visitInsn(DUP);
+ mv.visitTypeInsn(NEW, "org/gnome/gir/gobject/GErrorStruct");
+ mv.visitInsn(DUP);
+ mv.visitVarInsn(ALOAD, errorOffset);
+ mv.visitMethodInsn(INVOKEVIRTUAL, "com/sun/jna/ptr/PointerByReference", "getValue", "()Lcom/sun/jna/Pointer;");
+ mv.visitMethodInsn(INVOKESPECIAL, "org/gnome/gir/gobject/GErrorStruct", "<init>", "(Lcom/sun/jna/Pointer;)V");
+ mv.visitMethodInsn(INVOKESPECIAL, "org/gnome/gir/gobject/GErrorException", "<init>", "(Lorg/gnome/gir/gobject/GErrorStruct;)V");
+ mv.visitInsn(ATHROW);
+ mv.visitLabel(jtarget);
+ mv.visitVarInsn(ALOAD, resultOffset);
+ mv.visitInsn(ARETURN);
+ }
+ Label l4 = new Label();
+ mv.visitLabel(l4);
+ if (includeThis)
+ mv.visitLocalVariable("this", "L" + compilation.peer.internalName + ";", null, l0, l4, 0);
+ int off = includeThis ? 1 : 0;
+ for (int i = 0; i < nArgs; i++) {
+ mv.visitLocalVariable(ctx.args[i+off].getName(), ctx.argTypes.get(i).toString(), null, l0, l4, i+off);
+ }
+ mv.visitLocalVariable("f", "Lcom/sun/jna/Function;", null, l1, l4, functionOffset);
+ mv.visitLocalVariable("args", "[Ljava/lang/Object;", null, l2, l4, arrayOffset);
+ if (!ctx.returnType.equals(Type.VOID_TYPE)) {
+ mv.visitLocalVariable("result", "L" + ctx.returnType.getInternalName() + ";", null, l2, l4, resultOffset);
+ }
+ mv.visitMaxs(8, errorOffset+1);
+ }
+
+ private void writeGetGType(RegisteredTypeInfo rti, InfoCompilation compilation) {
+ String globalInternalsName = getInternals(rti);
+ MethodVisitor mv = compilation.peer.writer.visitMethod(ACC_PUBLIC + ACC_STATIC, "getGType", "()Lorg/gnome/gir/gobject/GType;", null, null);
+ mv.visitCode();
+ Label l0 = new Label();
+ mv.visitLabel(l0);
+ mv.visitFieldInsn(GETSTATIC, globalInternalsName, "library", "Lcom/sun/jna/NativeLibrary;");
+ mv.visitLdcInsn(rti.getTypeInit());
+ mv.visitMethodInsn(INVOKEVIRTUAL, "com/sun/jna/NativeLibrary", "getFunction", "(Ljava/lang/String;)Lcom/sun/jna/Function;");
+ mv.visitLdcInsn(Type.getType("Lorg/gnome/gir/gobject/GType;"));
+ mv.visitInsn(ICONST_0);
+ mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
+ mv.visitFieldInsn(GETSTATIC, globalInternalsName, "invocationOptions", "Ljava/util/Map;");
+ mv.visitMethodInsn(INVOKEVIRTUAL, "com/sun/jna/Function", "invoke", "(Ljava/lang/Class;[Ljava/lang/Object;Ljava/util/Map;)Ljava/lang/Object;");
+ mv.visitTypeInsn(CHECKCAST, "org/gnome/gir/gobject/GType");
+ mv.visitInsn(ARETURN);
+ mv.visitMaxs(4, 0);
+ mv.visitEnd();
+ }
+
+ private void compileGlobal(InfoCompilation compilation, FunctionInfo fi,
+ Set<String> globalSigs) {
+ CallableCompilationContext ctx = tryCompileCallable(fi, globalSigs);
+ if (ctx == null)
+ return;
+ writeCallable(ACC_PUBLIC + ACC_STATIC + ACC_FINAL, null, compilation, fi, ctx);
+ }
+
+ private void compile(StructInfo info) {
+ InfoCompilation compilation = getCompilation(info);
+
+ String internalName = getInternalName(info);
+ compilation.peer.writer.visit(V1_6, ACC_PUBLIC + ACC_SUPER, internalName, null, "com/sun/jna/Structure", null);
+
+ Set<String> sigs = new HashSet<String>();
+ for (FunctionInfo fi : info.getMethods()) {
+ CallableCompilationContext ctx = tryCompileCallable(fi, sigs);
+ if (ctx == null)
+ continue;
+ writeCallable(ACC_PUBLIC, info, compilation, fi, ctx);
+ }
+ compilation.peer.close();
+ }
+
+ private void compile(BoxedInfo info) {
+ InfoCompilation compilation = getCompilation(info);
+
+ String internalName = getInternalName(info);
+ compilation.peer.writer.visit(V1_6, ACC_PUBLIC + ACC_SUPER, internalName, null, "org/gnome/gir/gobject/GBoxed", null);
+
+ MethodVisitor mv = compilation.peer.writer.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
+ mv.visitCode();
+ Label l0 = new Label();
+ mv.visitLabel(l0);
+ mv.visitLineNumber(6, l0);
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitMethodInsn(INVOKESPECIAL, "org/gnome/gir/gobject/GBoxed", "<init>", "()V");
+ mv.visitInsn(RETURN);
+ Label l1 = new Label();
+ mv.visitLabel(l1);
+ mv.visitLocalVariable("this", "L" + compilation.peer.internalName + ";", null, l0, l1, 0);
+ mv.visitMaxs(1, 1);
+ mv.visitEnd();
+
+ compilation.peer.close();
+ }
+
+ private boolean requireNamespaceOf(BaseInfo info) {
+ return requireNamespace(info.getNamespace());
+ }
+
+ private boolean requireNamespace(String namespace) {
+ if (alreadyCompiled.contains(namespace))
+ return true;
+ try {
+ repo.require(namespace);
+ } catch (GErrorException e) {
+ if (!loadFailed.contains(namespace)) {
+ logger.log(Level.SEVERE, "Failed to load namespace=" + namespace, e);
+ loadFailed.add(namespace);
+ return false;
+ }
+ return false;
+ }
+ pendingCompilation.add(namespace);
+ return true;
+ }
+
+ private void compileNamespaceComponents(String namespace) {
+ BaseInfo[] infos = repo.getInfos(namespace);
+ Set<String> globalSigs = new HashSet<String>();
+ for (BaseInfo baseInfo : infos) {
+ logger.fine("Compiling " + baseInfo);
+ if (baseInfo instanceof EnumInfo) {
+ compile((EnumInfo) baseInfo);
+ } else if (baseInfo instanceof FlagsInfo) {
+ compile((FlagsInfo) baseInfo);
+ } else if (baseInfo instanceof ObjectInfo) {
+ compile((ObjectInfo) baseInfo);
+ } else if (baseInfo instanceof FunctionInfo) {
+ compileGlobal(getGlobals(namespace), (FunctionInfo) baseInfo, globalSigs);
+ } else if (baseInfo instanceof StructInfo) {
+ compile((StructInfo) baseInfo);
+ } else if (baseInfo instanceof BoxedInfo) {
+ compile((BoxedInfo) baseInfo);
+ } else if (baseInfo instanceof InterfaceInfo) {
+ compile((InterfaceInfo) baseInfo);
+ } else {
+ logger.warning("unhandled info " + baseInfo.getName());
+ }
+ }
+ }
+
+ private void initGlobalsClass(InfoCompilation globals) {
+ Label l0, l1, l2, l3;
+ MethodVisitor mv;
+
+ /* We have two inner classes - one is Internals, and one is an anonymous HashMap inside Internals */
+ InnerClassCompilation internals = globals.peer.newInner("Internals");
+ InnerClassCompilation internalsInner = globals.peer.newInner("Internals$1");
+
+ globals.peer.writer.visitInnerClass(internals.internalName, globals.peer.internalName, "Internals", ACC_PUBLIC + ACC_FINAL + ACC_STATIC);
+ internals.writer.visit(V1_6, ACC_PUBLIC + ACC_FINAL + ACC_SUPER,
+ internals.internalName, null, "java/lang/Object", null);
+ internals.writer.visitInnerClass(internals.internalName, globals.peer.internalName, "Internals", ACC_PUBLIC + ACC_FINAL + ACC_STATIC);
+
+ internals.writer.visitInnerClass(internalsInner.internalName, null, null, 0);
+ internalsInner.writer.visit(V1_6, ACC_FINAL + ACC_SUPER, internalsInner.internalName,
+ "Ljava/util/HashMap<Ljava/lang/Object;Ljava/lang/Object;>;", "java/util/HashMap", null);
+ internalsInner.writer.visitOuterClass(internals.internalName, null, null);
+ internalsInner.writer.visitInnerClass(internalsInner.internalName, null, null, 0);
+
+
+ /* private constructor */
+ mv = globals.peer.writer.visitMethod(ACC_PRIVATE, "<init>", "()V", null, null);
+ mv.visitCode();
+ l0 = new Label();
+ mv.visitLabel(l0);
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
+ mv.visitInsn(RETURN);
+ l1 = new Label();
+ mv.visitLabel(l1);
+ mv.visitLocalVariable("this", "L" + globals.peer.internalName + ";", null, l0, l1, 0);
+ mv.visitMaxs(1, 1);
+ mv.visitEnd();
+
+ /*
+ public static final class Internals {
+ public static final NativeLibrary library = NativeLibrary.getInstance("gtk-2.0");
+ public static final Repository repo = Repository.getDefault();
+ public static final String namespace = "Gtk";
+ public static final Map<Object,Object> invocationOptions = new HashMap<Object,Object>() {
+ private static final long serialVersionUID = 1L;
+
+ {
+ put(Library.OPTION_TYPE_MAPPER, new GTypeMapper());
+ }
+ };
+ };
+ */
+
+ FieldVisitor fv = globals.peer.writer.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "library", "Lcom/sun/jna/NativeLibrary;", null, null);
+ fv.visitEnd();
+
+ fv = internals.writer.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "library", "Lcom/sun/jna/NativeLibrary;", null, null);
+ fv.visitEnd();
+
+ fv = internals.writer.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "repo", "Lorg/gnome/gir/repository/Repository;", null, null);
+ fv.visitEnd();
+
+ fv = internals.writer.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "namespace", "Ljava/lang/String;", null, globals.peer.namespace);
+ fv.visitEnd();
+
+ fv = internals.writer.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "invocationOptions",
+ "Ljava/util/Map;", "Ljava/util/Map<Ljava/lang/Object;Ljava/lang/Object;>;", null);
+ fv.visitEnd();
+
+ mv = internals.writer.visitMethod(ACC_STATIC, "<clinit>", "()V", null, null);
+ mv.visitCode();
+ l0 = new Label();
+ mv.visitLabel(l0);
+ /* The JNA NativeLibrary expects it without the .so */
+ String shlib = repo.getSharedLibrary(globals.peer.namespace);
+ if (shlib == null)
+ shlib = namespaceShlibMapping.get(globals.peer.namespace);
+ if (shlib.endsWith(".so"))
+ shlib = shlib.substring(0, shlib.length()-3);
+ mv.visitLdcInsn(shlib);
+ mv.visitMethodInsn(INVOKESTATIC, "com/sun/jna/NativeLibrary", "getInstance", "(Ljava/lang/String;)Lcom/sun/jna/NativeLibrary;");
+ mv.visitFieldInsn(PUTSTATIC, internals.internalName, "library", "Lcom/sun/jna/NativeLibrary;");
+ l1 = new Label();
+ mv.visitLabel(l1);
+ mv.visitMethodInsn(INVOKESTATIC, "org/gnome/gir/repository/Repository", "getDefault", "()Lorg/gnome/gir/repository/Repository;");
+ mv.visitFieldInsn(PUTSTATIC, internals.internalName, "repo", "Lorg/gnome/gir/repository/Repository;");
+ l2 = new Label();
+ mv.visitLabel(l2);
+ mv.visitTypeInsn(NEW, internalsInner.internalName);
+ mv.visitInsn(DUP);
+ mv.visitMethodInsn(INVOKESPECIAL, internalsInner.internalName, "<init>", "()V");
+ mv.visitFieldInsn(PUTSTATIC, internals.internalName, "invocationOptions", "Ljava/util/Map;");
+ l3 = new Label();
+ mv.visitLabel(l3);
+ mv.visitInsn(RETURN);
+ mv.visitMaxs(2, 0);
+ mv.visitEnd();
+
+
+ mv = internalsInner.writer.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
+ mv.visitCode();
+ l0 = new Label();
+ mv.visitLabel(l0);
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitMethodInsn(INVOKESPECIAL, "java/util/HashMap", "<init>", "()V");
+ l1 = new Label();
+ mv.visitLabel(l1);
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitLdcInsn("type-mapper");
+ mv.visitTypeInsn(NEW, "org/gnome/gir/gobject/GTypeMapper");
+ mv.visitInsn(DUP);
+ mv.visitMethodInsn(INVOKESPECIAL, "org/gnome/gir/gobject/GTypeMapper", "<init>", "()V");
+ mv.visitMethodInsn(INVOKEVIRTUAL, internalsInner.internalName, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
+ mv.visitInsn(POP);
+ l2 = new Label();
+ mv.visitLabel(l2);
+ mv.visitInsn(RETURN);
+ l3 = new Label();
+ mv.visitLabel(l3);
+ mv.visitLocalVariable("this", "L" + internalsInner.internalName + ";", null, l0, l3, 0);
+ mv.visitMaxs(4, 1);
+ mv.visitEnd();
+
+ mv = internals.writer.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
+ mv.visitCode();
+ l0 = new Label();
+ mv.visitLabel(l0);
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
+ mv.visitInsn(RETURN);
+ l1 = new Label();
+ mv.visitLabel(l1);
+ mv.visitLocalVariable("this", "L" + internals.internalName + ";", null, l0, l1, 0);
+ mv.visitMaxs(1, 1);
+ mv.visitEnd();
+
+ internalsInner.writer.visitEnd();
+ internals.writer.visitEnd();
+ }
+
+ private void compileNamespaceSingle(String namespace) {
+ alreadyCompiled.add(namespace);
+
+ try {
+ repo.require(namespace);
+ logger.info("Loaded typelib from " + repo.getTypelibPath(namespace));
+ } catch (GErrorException e) {
+ throw new RuntimeException(e);
+ }
+
+ InfoCompilation global = getGlobals(namespace);
+ global.peer.writer.visit(V1_6, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, global.peer.internalName, null, "java/lang/Object", null);
+ initGlobalsClass(global);
+ globals.put(namespace, global);
+
+ compileNamespaceComponents(namespace);
+
+ global.peer.close();
+ }
+
+ private List<StubClass> compileNamespace(String namespace) {
+ compileNamespaceSingle(namespace);
+ return finish();
+ }
+
+ private List<StubClass> finish() {
+ logger.info("Compiled " + writers.size() + " info objects");
+ List<StubClass> ret = new LinkedList<StubClass>();
+ for (InfoCompilation infoc : writers.values()) {
+ infoc.peer.close();
+ ret.add(infoc.peer);
+ for (InnerClassCompilation inner : infoc.peer.innerClasses) {
+ ret.add(inner);
+ }
+ }
+ return ret;
+ }
+
+ private List<StubClass> compileNamespaceRecursive(String namespace) {
+ pendingCompilation.add(namespace);
+ while (pendingCompilation.size() > 0) {
+ String pending = pendingCompilation.iterator().next();
+ logger.info("Namespace: " + pending);
+ requireNamespace(pending);
+ compileNamespaceSingle(pending);
+ pendingCompilation.remove(pending);
+ }
+ logger.info("Compiled " + writers.size() + " info objects");
+ return finish();
+ }
+
+ private static List<StubClass> getStubsUnlocked(Repository repo, String namespace) {
+ List<StubClass> ret = loadedRepositories.get(namespace);
+ if (ret != null) {
+ return ret;
+ }
+
+ logger.info("Starting from namespace: " + namespace);
+
+ CodeFactory cf = new CodeFactory(repo);
+ ret = cf.compileNamespaceRecursive(namespace);
+ loadedRepositories.put(repo, ret);
+
+ return ret;
+ }
+
+ public static List<StubClass> getNativeStubs(Repository repo, String namespace) {
+ synchronized (loadedRepositories) {
+ return getStubsUnlocked(repo, namespace);
+ }
+ }
+
+ public static List<StubClass> compile(Repository repo, String namespace) {
+ CodeFactory cf = new CodeFactory(repo);
+ return cf.compileNamespace(namespace);
+ }
+
+ public static ClassLoader getLoader(List<StubClass> stubs) {
+ final Map<String,byte[]> map = new HashMap<String,byte[]>();
+ for (StubClass stub: stubs)
+ map.put(stub.getPublicName(), stub.getBytes());
+ return new ClassLoader() {
+ @Override
+ public Class<?> findClass(String name) throws ClassNotFoundException {
+ byte[] bytes = map.get(name);
+ if (bytes == null)
+ return super.findClass(name);
+ return defineClass(name, bytes);
+ }
+
+ protected Class<?> defineClass(String name, byte[] bytes) {
+ return defineClass(name, bytes, 0, bytes.length);
+ }
+ };
+ }
+
+ public static File generateJar(String namespace, String version, boolean validate) throws GErrorException, IOException {
+ Repository repo = Repository.getDefault();
+ File destFile = null;
+
+ repo.require(namespace);
+ String typelibPathName = repo.getTypelibPath(namespace);
+ File typelibPath = new File(typelibPathName);
+ long typelibLastModified = typelibPath.lastModified();
+
+ if (destFile == null) {
+ destFile = new File(typelibPath.getParent(), namespace+".jar");
+ logger.info("Will install to: " + destFile);
+ }
+
+ if (destFile.exists() && destFile.lastModified() > typelibLastModified) {
+ logger.info("Skipping already-compiled namespace: " + namespace);
+ return destFile;
+ }
+
+ logger.info("Compiling namespace: " + namespace);
+ List<StubClass> stubs;
+ stubs = CodeFactory.compile(repo, namespace);
+
+ Set<String> classNames = new HashSet<String>();
+ ZipOutputStream zo = new ZipOutputStream(new FileOutputStream(destFile));
+ for (StubClass stub : stubs) {
+ byte[] code = stub.getBytes();
+ String className = stub.getPublicName().replace('.', '/');
+ classNames.add(className);
+ String classFilename = className + ".class";
+ zo.putNextEntry(new ZipEntry(classFilename));
+ zo.write(code);
+ zo.closeEntry();
+ }
+ zo.close();
+ return destFile;
+ }
+
+ public static void verifyJarFiles(Set<File> jarPaths) throws IOException {
+ Set<URL> urls = new HashSet<URL>();
+ Set<String> allClassnames = new HashSet<String>();
+ logger.info("Verifying " + jarPaths.size() + " jar paths");
+ for (File jarPath : jarPaths) {
+ try {
+ urls.add(jarPath.toURI().toURL());
+ } catch (MalformedURLException e) {
+ throw new RuntimeException(e);
+ }
+ ZipFile zf = new ZipFile(jarPath);
+ for (Enumeration<? extends ZipEntry> e = zf.entries(); e.hasMoreElements();) {
+ String name = e.nextElement().getName();
+ if (name.endsWith(".class"))
+ allClassnames.add(name.replace('/', '.').substring(0, name.length()-6));
+ }
+ }
+ for (String className : allClassnames) {
+ try {
+ new URLClassLoader(urls.toArray(new URL[] {})) {
+ public void loadVerify(String name) throws ClassNotFoundException {
+ loadClass(name, true);
+ }
+ }.loadVerify(className);
+ } catch (ClassNotFoundException e) {
+ logger.severe("Failed to verify class " + className);
+ e.printStackTrace();
+ break;
+ }
+ }
+ }
+
+ public static void compileAll(boolean validate) throws IOException, GErrorException, ClassNotFoundException {
+ /* Freedesktop/Unix specific */
+ String datadirsPath = System.getenv("XDG_DATA_DIRS");
+ String dataDirs[];
+ if (datadirsPath != null)
+ dataDirs = datadirsPath.split(":");
+ else
+ dataDirs = new String[] { "/usr/share" };
+ Set<File> jarPaths = new HashSet<File>();
+ for (String dir : dataDirs) {
+ File typelibsDir = new File(dir, "girepository");
+ for (String filename : typelibsDir.list()) {
+ String namespace;
+ String version = null;
+ int dashIdx = filename.lastIndexOf('-');
+ int dot = filename.lastIndexOf('.'); // for typelib
+ if (dashIdx < 0)
+ namespace = filename.substring(0, dot);
+ else {
+ namespace = filename.substring(0, dashIdx);
+ version = filename.substring(dashIdx+1, dot);
+ }
+ /* Skip GObject+below for now, we manually bind */
+ if (!(namespace.equals("GLib") || namespace.equals("GObject"))) {
+ jarPaths.add(generateJar(namespace, version, validate));
+ }
+ }
+ }
+ verifyJarFiles(jarPaths);
+ }
+
+ public static void main(String[] args) throws Exception {
+ GObjectAPI.gobj.g_type_init();
+
+ boolean validate = false;
+
+ Getopt g = new Getopt("jgir-compiler", args, "V");
+ int c;
+ while ((c = g.getopt()) != -1) {
+ switch (c) {
+ case 'V':
+ validate = true;
+ break;
+ case '?':
+ break; // getopt() already printed an error
+ default:
+ System.err.print("getopt() returned " + c + "\n");
+ }
+ }
+
+ compileAll(validate);
+ }
+}
Added: trunk/src/org/gnome/gir/compiler/Test.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/compiler/Test.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,126 @@
+package org.gnome.gir.compiler;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.gnome.gir.gobject.Closure;
+import org.gnome.gir.gobject.GErrorException;
+import org.gnome.gir.gobject.GErrorStruct;
+import org.gnome.gir.gobject.GObject;
+import org.gnome.gir.gobject.GType;
+import org.gnome.gir.gobject.GTypeInstance;
+import org.gnome.gir.gobject.GTypeMapper;
+import org.gnome.gir.repository.Direction;
+import org.gnome.gir.repository.Repository;
+
+import com.sun.jna.Function;
+import com.sun.jna.Library;
+import com.sun.jna.NativeLibrary;
+import com.sun.jna.Pointer;
+import com.sun.jna.Structure;
+import com.sun.jna.ptr.PointerByReference;
+
+public class Test extends GObject {
+
+ public void foo(String x, Double y, Integer z) throws GErrorException {
+ PointerByReference error = new PointerByReference(null);
+ Function target = Internals.library.getFunction("gtk_foo_bar");
+ Object[] args = new Object[] { x, y, z };
+ Boolean result = (Boolean) target.invoke(Boolean.class, args, Internals.invocationOptions);
+ if (!result) {
+ throw new GErrorException(new GErrorStruct(error.getValue()));
+ }
+ }
+
+ public Test baz(Double x, Integer z) throws GErrorException {
+ PointerByReference error = new PointerByReference(null);
+ Function target = Internals.library.getFunction("glib_baz");
+ Object[] args = new Object[] { x, z };
+ Test result = (Test) target.invoke(Integer.class, args, Internals.invocationOptions);
+ if (result == null) {
+ throw new GErrorException(new GErrorStruct(error.getValue()));
+ }
+ return result;
+ }
+
+ public static Test newWithFoo(String blah) {
+ return new Test(initializer((Pointer) Internals.library.getFunction("gtk_test_new_with_foo").invoke(Pointer.class, new Object[] { blah }, Internals.invocationOptions)));
+ }
+
+ public static GType getGType() {
+ return (GType) Internals.library.getFunction("gtk_test_get_type").invoke(GType.class, new Object[] {}, Internals.invocationOptions);
+ }
+
+ public Test(Direction dir, Integer foo, String blah) {
+ super(initializer((Pointer) Internals.library.getFunction("gtk_test2_new")
+ .invoke(Pointer.class, new Object[] { dir, foo, blah }, Internals.invocationOptions)));
+ }
+
+ public interface Clicked extends Closure {
+ public static final String METHOD_NAME = "onClicked";
+ public void onClicked(Test t);
+ }
+
+ public long connect(Clicked c) {
+ return connect("clicked", c);
+ }
+
+ public Test() {
+ super(getGType(), null);
+ }
+
+ public Test(Object[] args) {
+ super(getGType(), args);
+ }
+
+ protected Test(Initializer init) {
+ super(init);
+ }
+
+ protected Test(GType gtype, Object[] args) {
+ super(gtype, args);
+ }
+
+ public static final class Internals {
+ public static final NativeLibrary library = NativeLibrary.getInstance("gtk-2.0");
+ public static final Repository repo = Repository.getDefault();
+ public static final String namespace = "Gtk";
+ public static final Map<Object,Object> invocationOptions = new HashMap<Object,Object>() {
+ private static final long serialVersionUID = 1L;
+
+ {
+ put(Library.OPTION_TYPE_MAPPER, new GTypeMapper());
+ }
+ };
+ };
+
+ public static final void init() {
+ Function f = Internals.library.getFunction("gtk_init");
+ Object[] args = new Object[] {};
+ f.invoke(Void.class, args, Internals.invocationOptions);
+ }
+
+ public static final Boolean eventsPending() {
+ Function f = Internals.library.getFunction("gtk_events_pending");
+ Object[] args = new Object[] {};
+ return (Boolean) f.invoke(Boolean.class, args, Internals.invocationOptions);
+ }
+
+ public static final void propagateEvent(Pointer widget, Structure event) {
+ Function f = Internals.library.getFunction("gtk_propagate_event");
+ Object[] args = new Object[] { widget, event };
+ f.invoke(Void.class, args, Internals.invocationOptions);
+ }
+
+ public void foo(Pointer widget, Structure event) {
+ Function f = Internals.library.getFunction("gtk_propagate_event");
+ Object[] args = new Object[] { this, widget, event };
+ f.invoke(Void.class, args, Internals.invocationOptions);
+ }
+
+ public void ifaceFoo(String blah) {
+ Function f = Internals.library.getFunction("gtk_propagate_event");
+ Object[] args = new Object[] { GTypeInstance.peekInterface(this.handle(), Test.getGType()), blah };
+ f.invoke(Void.class, args, Internals.invocationOptions);
+ }
+}
Added: trunk/src/org/gnome/gir/gobject/BooleanByReference.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/BooleanByReference.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,23 @@
+package org.gnome.gir.gobject;
+
+import com.sun.jna.ptr.ByReference;
+
+public class BooleanByReference extends ByReference {
+
+ protected BooleanByReference() {
+ this(false);
+ }
+
+ public BooleanByReference(boolean b) {
+ super(4);
+ setValue(b);
+ }
+
+ public void setValue(boolean b) {
+ getPointer().setInt(0, b ? 1 : 0);
+ }
+
+ public boolean getValue() {
+ return getPointer().getInt(0) != 0;
+ }
+}
Added: trunk/src/org/gnome/gir/gobject/Closure.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/Closure.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2008 Wayne Meissner
+ *
+ * This file was originally part of gstreamer-java; modified for use in
+ * jgir. By permission of author, this file has been relicensed from LGPLv3
+ * to the license of jgir; see below.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307 USA.
+ */
+
+package org.gnome.gir.gobject;
+
+/**
+ * A signal callback.
+ * <p>
+ * Each closure should have exactly one method named 'invoke' which will be invoked
+ * when the signal is triggered from GObject.
+ * </p>
+ */
+public interface Closure {
+ /**
+ * The name of the method to invoke.
+ */
+ public static final String METHOD_NAME = "invoke";
+
+}
Added: trunk/src/org/gnome/gir/gobject/ComplexReturn.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/ComplexReturn.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,8 @@
+package org.gnome.gir.gobject;
+
+import org.gnome.gir.repository.Transfer;
+
+public interface ComplexReturn<T> {
+ public void dispose(Transfer trans);
+ public Object convert(Class<T> klass);
+}
Added: trunk/src/org/gnome/gir/gobject/EnumMapper.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/EnumMapper.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2007 Wayne Meissner
+ *
+ * This file was originally part of gstreamer-java; modified for use in
+ * jgir. By permission of author, this file has been relicensed from LGPLv3
+ * to the license of jgir; see below.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307 USA.
+ */
+
+package org.gnome.gir.gobject;
+
+import java.util.EnumSet;
+
+/**
+ * Maps to and from native int and an Enum value.
+ * @author wayne
+ */
+public class EnumMapper {
+ private static final EnumMapper mapper = new EnumMapper();
+ public static EnumMapper getInstance() {
+ return mapper;
+ }
+
+ public int intValue(Enum<?> value) {
+ return value instanceof IntegerEnum ? ((IntegerEnum) value).intValue() : value.ordinal();
+ }
+ public <E extends Enum<E>> E valueOf(int value, Class<E> enumClass) {
+ //
+ // Just loop around all the enum values and find one that matches.
+ // Storing the values in a Map might be faster, but by the time you deal
+ // with locking overhead, its hardly worth it for small enums.
+ //
+ if (IntegerEnum.class.isAssignableFrom(enumClass)) {
+ for (E e : EnumSet.allOf(enumClass)) {
+ if (((IntegerEnum) e).intValue() == value) {
+ return e;
+ }
+ }
+ } else {
+ for (E e : EnumSet.allOf(enumClass)) {
+ if (e.ordinal() == value) {
+ return e;
+ }
+ }
+ }
+ //
+ // No value found - try to find the default value for unknown values.
+ // This is useful for enums that aren't fixed in stone and/or where you
+ // don't want to throw an Exception for an unknown value.
+ //
+ try {
+ //for (Field f : enumClass.getDeclaredFields()) {
+ // if (f.getAnnotation(DefaultEnumValue.class) != null) {
+ // return Enum.valueOf(enumClass, f.getName());
+ // }
+ //}
+ throw new IllegalArgumentException();
+ } catch (IllegalArgumentException ex) {
+ //
+ // No default, so just give up and throw an exception
+ //
+ throw new IllegalArgumentException("No known Enum mapping for "
+ + enumClass.getName() + " value=" + value);
+ }
+ }
+}
Added: trunk/src/org/gnome/gir/gobject/GBoxed.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GBoxed.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,7 @@
+package org.gnome.gir.gobject;
+
+import com.sun.jna.PointerType;
+
+public abstract class GBoxed extends PointerType {
+ public abstract GType getType();
+}
Added: trunk/src/org/gnome/gir/gobject/GBoxedAPI.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GBoxedAPI.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2007 Wayne Meissner
+ *
+ * This file was originally part of gstreamer-java; modified for use in
+ * jgir. By permission of author, this file has been relicensed from LGPLv3
+ * to the license of jgir; see below.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307 USA.
+ */
+
+package org.gnome.gir.gobject;
+
+import java.util.HashMap;
+
+import com.sun.jna.Library;
+
+/**
+ *
+ */
+public interface GBoxedAPI extends Library {
+ static GBoxedAPI gboxed = GNative.loadLibrary("gobject-2.0", GBoxedAPI.class, new HashMap<String, Object>() {
+ private static final long serialVersionUID = 1L;
+ {
+ put(Library.OPTION_TYPE_MAPPER, new GTypeMapper());
+ }
+ });
+
+ GType g_closure_get_type();
+}
Added: trunk/src/org/gnome/gir/gobject/GClosure.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GClosure.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,7 @@
+package org.gnome.gir.gobject;
+
+public class GClosure extends GBoxed {
+ public GType getType() {
+ return GBoxedAPI.gboxed.g_closure_get_type();
+ }
+}
Added: trunk/src/org/gnome/gir/gobject/GErrorException.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GErrorException.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,30 @@
+
+package org.gnome.gir.gobject;
+
+public class GErrorException extends Exception {
+ private static final long serialVersionUID = 1L;
+ private int domain;
+ private int code;
+ private String message;
+ public GErrorException() {
+ }
+ public GErrorException(GErrorStruct error) {
+ super(error.message);
+ this.domain = error.getDomain();
+ this.code = error.getCode();
+ this.message = error.getMessage();
+ }
+
+ public int getDomain() {
+ return domain;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+ @Override
+ public String getMessage() {
+ return message;
+ }
+}
\ No newline at end of file
Added: trunk/src/org/gnome/gir/gobject/GErrorStruct.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GErrorStruct.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,24 @@
+package org.gnome.gir.gobject;
+
+import com.sun.jna.Pointer;
+
+public class GErrorStruct extends com.sun.jna.Structure {
+ public int domain; /* GQuark */
+ public int code;
+ public String message;
+
+ /** Creates a new instance of GError */
+ public GErrorStruct() { clear(); }
+ public GErrorStruct(Pointer ptr) {
+ useMemory(ptr);
+ }
+ public int getCode() {
+ return (Integer) readField("code");
+ }
+ public String getMessage() {
+ return (String) readField("message");
+ }
+ public int getDomain() {
+ return (Integer) readField("domain");
+ }
+}
Added: trunk/src/org/gnome/gir/gobject/GInitiallyUnowned.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GInitiallyUnowned.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,19 @@
+package org.gnome.gir.gobject;
+
+
+public abstract class GInitiallyUnowned extends GObject {
+
+ public GInitiallyUnowned(Initializer init) {
+ super(init);
+ }
+
+ @Override
+ protected void ref() {
+ GObjectAPI.gobj.g_object_ref_sink(this);
+ }
+
+ protected GInitiallyUnowned(GType gtype, Object[] args) {
+ super(gtype, args);
+ }
+
+}
Added: trunk/src/org/gnome/gir/gobject/GList.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GList.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,7 @@
+package org.gnome.gir.gobject;
+
+import com.sun.jna.PointerType;
+
+public class GList extends PointerType {
+
+}
Added: trunk/src/org/gnome/gir/gobject/GMainContext.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GMainContext.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2007 Wayne Meissner
+ *
+ * This file was originally part of gstreamer-java; modified for use in
+ * jgir. By permission of author, this file has been relicensed from LGPLv3
+ * to the license of jgir; see below.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307 USA.
+ */
+
+package org.gnome.gir.gobject;
+
+import com.sun.jna.Pointer;
+
+/**
+ *
+ */
+public class GMainContext extends RefCountedObject {
+ private static GlibAPI glib = GlibAPI.glib;
+
+ public GMainContext() {
+ this(initializer(glib.g_main_context_new()));
+ }
+ private GMainContext(Initializer init) {
+ super(init);
+ }
+ public int attach(GSource source) {
+ return glib.g_source_attach(source, this);
+ }
+ public static GMainContext getDefaultContext() {
+ return new GMainContext(initializer(glib.g_main_context_default(), false, false));
+ }
+
+ protected void ref() {
+ glib.g_main_context_ref(handle());
+ }
+ protected void unref() {
+ glib.g_main_context_unref(handle());
+ }
+
+ @Override
+ protected void disposeNativeHandle(Pointer ptr) {
+ glib.g_main_context_unref(ptr);
+ }
+}
Added: trunk/src/org/gnome/gir/gobject/GModuleAPI.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GModuleAPI.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,19 @@
+package org.gnome.gir.gobject;
+import java.util.HashMap;
+
+import com.sun.jna.Library;
+import com.sun.jna.Pointer;
+
+/**
+ *
+ */
+public interface GModuleAPI extends Library {
+ static GModuleAPI gmodule = GNative.loadLibrary("gmodule-2.0", GModuleAPI.class, new HashMap<String, Object>() {
+ private static final long serialVersionUID = 1L;
+ {
+ put(Library.OPTION_TYPE_MAPPER, new GTypeMapper());
+ }
+ });
+ Pointer g_module_open(String path, int options);
+ String g_module_name(Pointer p);
+}
Added: trunk/src/org/gnome/gir/gobject/GNative.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GNative.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,251 @@
+/*
+ * Copyright (c) 2007 Wayne Meissner
+ *
+ * This file was originally part of gstreamer-java; modified for use in
+ * jgir. By permission of author, this file has been relicensed from LGPLv3
+ * to the license of jgir; see below.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307 USA.
+ */
+
+package org.gnome.gir.gobject;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Map;
+
+import com.sun.jna.Library;
+import com.sun.jna.Native;
+import com.sun.jna.NativeLibrary;
+import com.sun.jna.Platform;
+
+/**
+ *
+ */
+public final class GNative {
+ static {
+ // We never want to know about errors, and preserving them just slows things down.
+ com.sun.jna.Native.setPreserveLastError(false);
+ }
+ private GNative() {
+ }
+
+ public static <T extends Library> T loadLibrary(String name, Class<T> interfaceClass, Map<String, ?> options) {
+ if (Platform.isWindows()) {
+ return loadWin32Library(name, interfaceClass, options);
+ }
+ return loadNativeLibrary(name, interfaceClass, options);
+ }
+ private static <T extends Library> T loadNativeLibrary(String name, Class<T> interfaceClass, Map<String, ?> options) {
+ T library = interfaceClass.cast(Native.loadLibrary(name, interfaceClass, options));
+ boolean needCustom = false;
+ for (Method m : interfaceClass.getMethods()) {
+ for (Class<?> cls : m.getParameterTypes()) {
+ if (cls.isArray() && getConverter(cls.getComponentType()) != null) {
+ needCustom = true;
+ }
+ }
+ }
+
+ //
+ // If no custom conversions are needed, just return the JNA proxy
+ //
+ if (!needCustom) {
+ return library;
+ } else {
+// System.out.println("Using custom library proxy for " + interfaceClass.getName());
+ return interfaceClass.cast(Proxy.newProxyInstance(interfaceClass.getClassLoader(),
+ new Class[]{ interfaceClass }, new Handler<T>(library, options)));
+ }
+ }
+ private static <T extends Library> T loadWin32Library(String name, Class<T> interfaceClass, Map<String, ?> options) {
+ //
+ // gstreamer on win32 names the dll files one of foo.dll, libfoo.dll and libfoo-0.dll
+ //
+ String[] nameFormats = {
+ "%s", "lib%s", "lib%s-0",
+ };
+ for (int i = 0; i < nameFormats.length; ++i) {
+ try {
+ return interfaceClass.cast(loadNativeLibrary(String.format(nameFormats[i], name), interfaceClass, options));
+ } catch (UnsatisfiedLinkError ex) {
+ continue;
+ }
+ }
+ throw new UnsatisfiedLinkError("Could not load library " + name);
+ }
+ private static NativeLibrary getWin32NativeLibrary(String name) {
+ //
+ // gstreamer on win32 names the dll files one of foo.dll, libfoo.dll and libfoo-0.dll
+ //
+ String[] nameFormats = {
+ "%s", "lib%s", "lib%s-0",
+ };
+ for (int i = 0; i < nameFormats.length; ++i) {
+ try {
+ return NativeLibrary.getInstance(String.format(nameFormats[i], name));
+ } catch (UnsatisfiedLinkError ex) {
+ continue;
+ }
+ }
+ throw new UnsatisfiedLinkError("Could not load library " + name);
+ }
+ public static NativeLibrary getNativeLibrary(String name) {
+ if (Platform.isWindows()) {
+ return getWin32NativeLibrary(name);
+ }
+ return NativeLibrary.getInstance(name);
+ }
+ private static interface Converter {
+ Class<?> nativeType();
+ Object toNative(Object value);
+ Object fromNative(Object value, Class<?> javaType);
+ }
+ private static final Converter enumConverter = new Converter() {
+
+ public Class<?> nativeType() {
+ return int.class;
+ }
+
+ public Object toNative(Object value) {
+ return value != null ? EnumMapper.getInstance().intValue((Enum<?>) value) : 0;
+ }
+ @SuppressWarnings(value = "unchecked")
+ public Object fromNative(Object value, Class javaType) {
+ return EnumMapper.getInstance().valueOf((Integer) value, javaType);
+ }
+
+ };
+ private static final Converter booleanConverter = new Converter() {
+
+ public Class<?> nativeType() {
+ return int.class;
+ }
+
+ public Object toNative(Object value) {
+ return value != null ? Boolean.TRUE.equals(value) ? 1 : 0 : 0;
+ }
+ @SuppressWarnings(value = "unchecked")
+ public Object fromNative(Object value, Class javaType) {
+ return value != null ? ((Integer) value).intValue() != 0 : 0;
+ }
+
+ };
+ private static Converter getConverter(Class<?> javaType) {
+ if (Enum.class.isAssignableFrom(javaType)) {
+ return enumConverter;
+ } else if (boolean.class == javaType || Boolean.class == javaType) {
+ return booleanConverter;
+ }
+ return null;
+ }
+ private static class Handler<T> implements InvocationHandler {
+ private final InvocationHandler proxy;
+ @SuppressWarnings("unused")
+ private final T library;
+
+ public Handler(T library, Map<String, ?> options) {
+ this.library = library;
+ this.proxy = Proxy.getInvocationHandler(library);
+ }
+
+ public Object invoke(Object self, Method method, Object[] args) throws Throwable {
+ int lastArg = args != null ? args.length : 0;
+ if (method.isVarArgs()) {
+ --lastArg;
+ }
+ Runnable[] postInvoke = null;
+ int postCount = 0;
+ for (int i = 0; i < lastArg; ++i) {
+ if (args[i] == null) {
+ continue;
+ }
+ final Class<?> cls = args[i].getClass();
+ if (!cls.isArray() || cls.getComponentType().isPrimitive() || cls.getComponentType() == String.class) {
+ continue;
+ }
+ final Converter converter = getConverter(cls.getComponentType());
+ if (converter != null) {
+ final Object[] src = (Object[]) args[i];
+ final Object dst = java.lang.reflect.Array.newInstance(converter.nativeType(), src.length);
+ final ArrayIO io = getArrayIO(converter.nativeType());
+ for (int a = 0; a < src.length; ++a) {
+ io.set(dst, a, converter.toNative(src[a]));
+ }
+ if (postInvoke == null) {
+ postInvoke = new Runnable[lastArg];
+ }
+ postInvoke[postCount++] = new Runnable() {
+
+ public void run() {
+ for (int a = 0; a < src.length; ++a) {
+ src[a] = converter.fromNative(io.get(dst, a), cls.getComponentType());
+ }
+ }
+ };
+ args[i] = dst;
+ }
+ }
+ Object retval = proxy.invoke(self, method, args);
+ //
+ // Reload any native arrays into java arrays
+ //
+ for (int i = 0; i < postCount; ++i) {
+ postInvoke[i].run();
+ }
+ return retval;
+ }
+
+
+ Class<?> getNativeClass(Class<?> cls) {
+ if (cls == Integer.class) {
+ return int.class;
+ } else if (cls == Long.class) {
+ return long.class;
+ }
+ return cls;
+ }
+ private static interface ArrayIO {
+ public void set(Object array, int index, Object data);
+ public Object get(Object array, int index);
+ }
+ private static final ArrayIO intArrayIO = new ArrayIO() {
+ public void set(Object array, int index, Object data) {
+ java.lang.reflect.Array.setInt(array, index, data != null ? (Integer) data : 0);
+ }
+ public Object get(Object array, int index) {
+ return java.lang.reflect.Array.getInt(array, index);
+ }
+ };
+ private static final ArrayIO longArrayIO = new ArrayIO() {
+ public void set(Object array, int index, Object data) {
+ java.lang.reflect.Array.setLong(array, index, data != null ? (Long) data : 0);
+ }
+ public Object get(Object array, int index) {
+ return java.lang.reflect.Array.getLong(array, index);
+ }
+ };
+ private static ArrayIO getArrayIO(final Class<?> cls) {
+ if (cls == int.class || cls == Integer.class) {
+ return intArrayIO;
+ } else if (cls == long.class || cls == Long.class) {
+ return longArrayIO;
+ }
+ throw new IllegalArgumentException("No such conversion");
+ }
+ }
+}
Added: trunk/src/org/gnome/gir/gobject/GObject.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GObject.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,572 @@
+/*
+ * Copyright (c) 2007 Wayne Meissner
+ *
+ * This file was originally part of gstreamer-java; modified for use in
+ * jgir. By permission of author, this file has been relicensed from LGPLv3
+ * to the license of jgir; see below.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307 USA.
+ */
+
+package org.gnome.gir.gobject;
+
+import java.lang.reflect.Method;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.gnome.gir.gobject.GObjectAPI.GParamSpec;
+import org.gnome.gir.gobject.GObjectAPI.GToggleNotify;
+
+import com.sun.jna.Callback;
+import com.sun.jna.NativeLong;
+import com.sun.jna.NativeMapped;
+import com.sun.jna.NativeMappedConverter;
+import com.sun.jna.Pointer;
+
+/**
+ * This is an abstract class providing some GObject-like facilities in a common
+ * base class. Not intended for direct use.
+ */
+public abstract class GObject extends RefCountedObject {
+ private static final Map<GObject, Boolean> strongReferences = new ConcurrentHashMap<GObject, Boolean>();
+
+ private Map<Class<?>, Map<Object, SignalCallback>> signalListeners;
+ private Map<String, Map<Closure, ClosureProxy>> signalClosures;
+
+ private final IntPtr objectID = new IntPtr(System.identityHashCode(this));
+
+ public GObject(Initializer init) {
+ super(init.needRef ? initializer(init.ptr, false, init.ownsHandle) : init);
+ if (init.ownsHandle) {
+ strongReferences.put(this, Boolean.TRUE);
+ GObjectAPI.gobj.g_object_add_toggle_ref(init.ptr, toggle, objectID);
+ if (!init.needRef) {
+ unref();
+ }
+ }
+ }
+
+ private static Object[] extendInitArgs(Object[] args) {
+ Object[] ret;
+ if (args == null) {
+ ret = new Object[1];
+ ret[0] = null;
+ } else {
+ if ((args.length % 2) != 0)
+ throw new IllegalArgumentException("Number of construct parameters must be even");
+ ret = new Object[args.length+1];
+ System.arraycopy(args, 0, ret, 0, args.length);
+ ret[args.length] = null;
+ }
+ return ret;
+ }
+
+ protected GObject(GType gtype, Object[] args) {
+ this(new Initializer(GObjectAPI.gobj.g_object_new(gtype, extendInitArgs(args))));
+ }
+
+ GType getType(Class<?> klass) {
+ return GType.OBJECT;
+ }
+
+ /**
+ * Sets the value of a <tt>GObject</tt> property.
+ *
+ * @param property The property to set.
+ * @param data The value for the property. This must be of the type expected
+ * by gstreamer.
+ */
+ public void set(String property, Object data) {
+ GParamSpec propertySpec = findProperty(property);
+ if (propertySpec == null) {
+ throw new IllegalArgumentException("Unknown property: " + property);
+ }
+ final GType propType = propertySpec.value_type;
+
+ GValue propValue = new GValue();
+ GValueAPI.gvalue.g_value_init(propValue, propType);
+ if (propType.equals(GType.INT)) {
+ GValueAPI.gvalue.g_value_set_int(propValue, intValue(data));
+ } else if (propType.equals(GType.UINT)) {
+ GValueAPI.gvalue.g_value_set_uint(propValue, intValue(data));
+ } else if (propType.equals(GType.CHAR)) {
+ GValueAPI.gvalue.g_value_set_char(propValue, (byte) intValue(data));
+ } else if (propType.equals(GType.UCHAR)) {
+ GValueAPI.gvalue.g_value_set_uchar(propValue, (byte) intValue(data));
+ } else if (propType.equals(GType.LONG)) {
+ GValueAPI.gvalue.g_value_set_long(propValue, new NativeLong(longValue(data)));
+ } else if (propType.equals(GType.ULONG)) {
+ GValueAPI.gvalue.g_value_set_ulong(propValue, new NativeLong(longValue(data)));
+ } else if (propType.equals(GType.INT64)) {
+ GValueAPI.gvalue.g_value_set_int64(propValue, longValue(data));
+ } else if (propType.equals(GType.UINT64)) {
+ GValueAPI.gvalue.g_value_set_uint64(propValue, longValue(data));
+ } else if (propType.equals(GType.BOOLEAN)) {
+ GValueAPI.gvalue.g_value_set_boolean(propValue, booleanValue(data));
+ } else if (propType.equals(GType.FLOAT)) {
+ GValueAPI.gvalue.g_value_set_float(propValue, floatValue(data));
+ } else if (propType.equals(GType.DOUBLE)) {
+ GValueAPI.gvalue.g_value_set_double(propValue, doubleValue(data));
+ } else if (propType.equals(GType.STRING)) {
+ //
+ // Special conversion of java URI to gstreamer compatible uri
+ //
+ if (data instanceof URI) {
+ URI uri = (URI) data;
+ String uriString = uri.toString();
+ // Need to fixup file:/ to be file:/// for gstreamer
+ if ("file".equals(uri.getScheme()) && uri.getHost() == null) {
+ final String path = uri.getRawPath();
+ if (com.sun.jna.Platform.isWindows()) {
+ uriString = "file:/" + path;
+ } else {
+ uriString = "file://" + path;
+ }
+ }
+ GValueAPI.gvalue.g_value_set_string(propValue, uriString);
+ } else {
+ GValueAPI.gvalue.g_value_set_string(propValue, data.toString());
+ }
+ } else if (propType.equals(GType.OBJECT)) {
+ GValueAPI.gvalue.g_value_set_object(propValue, (GObject) data);
+ } else if (GValueAPI.gvalue.g_value_type_transformable(GType.INT64, propType)) {
+ transform(data, GType.INT64, propValue);
+ } else if (GValueAPI.gvalue.g_value_type_transformable(GType.LONG, propType)) {
+ transform(data, GType.LONG, propValue);
+ } else if (GValueAPI.gvalue.g_value_type_transformable(GType.INT, propType)) {
+ transform(data, GType.INT, propValue);
+ } else if (GValueAPI.gvalue.g_value_type_transformable(GType.DOUBLE, propType)) {
+ transform(data, GType.DOUBLE, propValue);
+ } else if (GValueAPI.gvalue.g_value_type_transformable(GType.FLOAT, propType)) {
+ transform(data, GType.FLOAT, propValue);
+ } else {
+ // Old behaviour
+ GObjectAPI.gobj.g_object_set(this, property, data);
+ return;
+ }
+ GObjectAPI.gobj.g_object_set_property(this, property, propValue);
+ GValueAPI.gvalue.g_value_unset(propValue); // Release any memory
+ }
+
+ /**
+ * Gets the current value of a <tt>GObject</tt> property.
+ *
+ * @param property The name of the property to get.
+ *
+ * @return A java value representing the <tt>GObject</tt> property value.
+ */
+ public Object get(String property) {
+ GObjectAPI.GParamSpec propertySpec = findProperty(property);
+ if (propertySpec == null) {
+ throw new IllegalArgumentException("Unknown property: " + property);
+ }
+ final GType propType = propertySpec.value_type;
+ GValue propValue = new GValue();
+ GValueAPI.gvalue.g_value_init(propValue, propType);
+ GObjectAPI.gobj.g_object_get_property(this, property, propValue);
+ if (propType.equals(GType.INT)) {
+ return GValueAPI.gvalue.g_value_get_int(propValue);
+ } else if (propType.equals(GType.UINT)) {
+ return GValueAPI.gvalue.g_value_get_uint(propValue);
+ } else if (propType.equals(GType.CHAR)) {
+ return Integer.valueOf(GValueAPI.gvalue.g_value_get_char(propValue));
+ } else if (propType.equals(GType.UCHAR)) {
+ return Integer.valueOf(GValueAPI.gvalue.g_value_get_uchar(propValue));
+ } else if (propType.equals(GType.LONG)) {
+ return GValueAPI.gvalue.g_value_get_long(propValue).longValue();
+ } else if (propType.equals(GType.ULONG)) {
+ return GValueAPI.gvalue.g_value_get_ulong(propValue).longValue();
+ } else if (propType.equals(GType.INT64)) {
+ return GValueAPI.gvalue.g_value_get_int64(propValue);
+ } else if (propType.equals(GType.UINT64)) {
+ return GValueAPI.gvalue.g_value_get_uint64(propValue);
+ } else if (propType.equals(GType.BOOLEAN)) {
+ return GValueAPI.gvalue.g_value_get_boolean(propValue);
+ } else if (propType.equals(GType.FLOAT)) {
+ return GValueAPI.gvalue.g_value_get_float(propValue);
+ } else if (propType.equals(GType.DOUBLE)) {
+ return GValueAPI.gvalue.g_value_get_double(propValue);
+ } else if (propType.equals(GType.STRING)) {
+ return GValueAPI.gvalue.g_value_get_string(propValue);
+ } else if (propType.equals(GType.OBJECT)) {
+ return GValueAPI.gvalue.g_value_dup_object(propValue);
+ } else if (GValueAPI.gvalue.g_value_type_transformable(propType, GType.OBJECT)) {
+ return GValueAPI.gvalue.g_value_dup_object(transform(propValue, GType.OBJECT));
+ } else if (GValueAPI.gvalue.g_value_type_transformable(propType, GType.INT)) {
+ return GValueAPI.gvalue.g_value_get_int(transform(propValue, GType.INT));
+ } else if (GValueAPI.gvalue.g_value_type_transformable(propType, GType.INT64)) {
+ return GValueAPI.gvalue.g_value_get_int64(transform(propValue, GType.INT64));
+ } else {
+ throw new IllegalArgumentException("Unknown conversion from GType=" + propType);
+ }
+ }
+ private static GValue transform(GValue src, GType dstType) {
+ GValue dst = new GValue();
+ GValueAPI.gvalue.g_value_init(dst, dstType);
+ GValueAPI.gvalue.g_value_transform(src, dst);
+ return dst;
+ }
+ private static void transform(Object data, GType type, GValue dst) {
+ GValue src = new GValue();
+ GValueAPI.gvalue.g_value_init(src, type);
+ setGValue(src, type, data);
+ GValueAPI.gvalue.g_value_transform(src, dst);
+ }
+ private static boolean setGValue(GValue value, GType type, Object data) {
+ if (type.equals(GType.INT)) {
+ GValueAPI.gvalue.g_value_set_int(value, intValue(data));
+ } else if (type.equals(GType.UINT)) {
+ GValueAPI.gvalue.g_value_set_uint(value, intValue(data));
+ } else if (type.equals(GType.CHAR)) {
+ GValueAPI.gvalue.g_value_set_char(value, (byte) intValue(data));
+ } else if (type.equals(GType.UCHAR)) {
+ GValueAPI.gvalue.g_value_set_uchar(value, (byte) intValue(data));
+ } else if (type.equals(GType.LONG)) {
+ GValueAPI.gvalue.g_value_set_long(value, new NativeLong(longValue(data)));
+ } else if (type.equals(GType.ULONG)) {
+ GValueAPI.gvalue.g_value_set_ulong(value, new NativeLong(longValue(data)));
+ } else if (type.equals(GType.INT64)) {
+ GValueAPI.gvalue.g_value_set_int64(value, longValue(data));
+ } else if (type.equals(GType.UINT64)) {
+ GValueAPI.gvalue.g_value_set_uint64(value, longValue(data));
+ } else if (type.equals(GType.BOOLEAN)) {
+ GValueAPI.gvalue.g_value_set_boolean(value, booleanValue(data));
+ } else if (type.equals(GType.FLOAT)) {
+ GValueAPI.gvalue.g_value_set_float(value, floatValue(data));
+ } else if (type.equals(GType.DOUBLE)) {
+ GValueAPI.gvalue.g_value_set_double(value, doubleValue(data));
+ } else {
+ return false;
+ }
+ return true;
+ }
+ private static boolean booleanValue(Object value) {
+ if (value instanceof Boolean) {
+ return ((Boolean) value).booleanValue();
+ } else if (value instanceof Number) {
+ return ((Number) value).intValue() != 0;
+ } else if (value instanceof String) {
+ return Boolean.parseBoolean((String) value);
+ }
+ throw new IllegalArgumentException("Expected boolean value, not " + value.getClass());
+ }
+ private static int intValue(Object value) {
+ if (value instanceof Number) {
+ return ((Number) value).intValue();
+ } else if (value instanceof String) {
+ return Integer.parseInt((String) value);
+ }
+ throw new IllegalArgumentException("Expected integer value, not " + value.getClass());
+ }
+ private static long longValue(Object value) {
+ if (value instanceof Number) {
+ return ((Number) value).longValue();
+ } else if (value instanceof String) {
+ return Long.parseLong((String) value);
+ }
+ throw new IllegalArgumentException("Expected long value, not " + value.getClass());
+ }
+ private static float floatValue(Object value) {
+ if (value instanceof Number) {
+ return ((Number) value).floatValue();
+ } else if (value instanceof String) {
+ return Float.parseFloat((String) value);
+ }
+ throw new IllegalArgumentException("Expected float value, not " + value.getClass());
+ }
+ private static double doubleValue(Object value) {
+ if (value instanceof Number) {
+ return ((Number) value).doubleValue();
+ } else if (value instanceof String) {
+ return Double.parseDouble((String) value);
+ }
+ throw new IllegalArgumentException("Expected double value, not " + value.getClass());
+ }
+
+ protected void disposeNativeHandle(Pointer ptr) {
+ GObjectAPI.gobj.g_object_remove_toggle_ref(ptr, toggle, objectID);
+ }
+ @Override
+ protected void ref() {
+ GObjectAPI.gobj.g_object_ref(this);
+ }
+
+ @Override
+ protected void unref() {
+ GObjectAPI.gobj.g_object_unref(this);
+ }
+ protected void invalidate() {
+ try {
+ // Need to increase the ref count before removing the toggle ref, so
+ // ensure the native object is not destroyed.
+ if (ownsHandle.get()) {
+ ref();
+
+ // Disconnect the callback.
+ GObjectAPI.gobj.g_object_remove_toggle_ref(handle(), toggle, objectID);
+ }
+ strongReferences.remove(this);
+ } finally {
+ super.invalidate();
+ }
+ }
+
+ protected NativeLong g_signal_connect(String signal, Callback callback) {
+ return GObjectAPI.gobj.g_signal_connect_data(this, signal, callback, null, null, 0);
+ }
+ private class SignalCallback {
+
+ protected SignalCallback(String signal, Callback cb) {
+ this.cb = cb;
+ id = g_signal_connect(signal, cb);
+ if (id.intValue() == 0) {
+ throw new IllegalArgumentException(String.format("Failed to connect signal '%s'", signal));
+ }
+ }
+ synchronized protected void disconnect() {
+ if (id != null && id.intValue() != 0) {
+ GObjectAPI.gobj.g_signal_handler_disconnect(GObject.this, id);
+ id = null;
+ }
+ }
+ protected void finalize() {
+ // Ensure the native callback is removed
+ disconnect();
+ }
+ Callback cb;
+ NativeLong id;
+ }
+ private synchronized final Map<Class<?>, Map<Object, SignalCallback>> getListenerMap() {
+ if (signalListeners == null) {
+ signalListeners = new ConcurrentHashMap<Class<?>, Map<Object, SignalCallback>>();
+ }
+ return signalListeners;
+ }
+ private synchronized final Map<String, Map<Closure, ClosureProxy>> getClosureMap() {
+ if (signalClosures == null) {
+ signalClosures = new ConcurrentHashMap<String, Map<Closure, ClosureProxy>>();
+ }
+ return signalClosures;
+ }
+
+ public <T> void connect(Class<T> listenerClass, T listener, Callback cb) {
+ String signal = listenerClass.getSimpleName().toLowerCase().replaceAll("_", "-");
+ connect(signal, listenerClass, listener, cb);
+ }
+
+ public synchronized <T> void connect(String signal, Class<T> listenerClass, T listener, Callback cb) {
+ final Map<Class<?>, Map<Object, SignalCallback>> signals = getListenerMap();
+ Map<Object, SignalCallback> m = signals.get(listenerClass);
+ if (m == null) {
+ m = new HashMap<Object, SignalCallback>();
+ signals.put(listenerClass, m);
+ }
+ m.put(listener, new SignalCallback(signal, cb));
+ }
+
+ public synchronized <T> void disconnect(Class<T> listenerClass, T listener) {
+ final Map<Class<?>, Map<Object, SignalCallback>> signals = getListenerMap();
+ Map<Object, SignalCallback> map = signals.get(listenerClass);
+ if (map != null) {
+ SignalCallback cb = map.remove(listener);
+ if (cb != null) {
+ cb.disconnect();
+ }
+ if (map.isEmpty()) {
+ signals.remove(listenerClass);
+ if (signalListeners.isEmpty()) {
+ signalListeners = null;
+ }
+ }
+ }
+ }
+ private final class ClosureProxy implements GSignalAPI.GSignalCallbackProxy {
+ private final Closure closure;
+ @SuppressWarnings("unused")
+ private final String signal;
+ private final Method method;
+ private final Class<?>[] parameterTypes;
+ NativeLong id;
+
+ protected ClosureProxy(String signal, Closure closure) {
+ this.closure = closure;
+ this.signal = signal;
+ Method invoke = null;
+ for (Method m : closure.getClass().getDeclaredMethods()) {
+ if (m.getName().startsWith("on")) {
+ invoke = m;
+ break;
+ }
+ }
+ if (invoke == null) {
+ throw new IllegalArgumentException(closure.getClass()
+ + " does not have an invoke method");
+ }
+ invoke.setAccessible(true);
+ this.method = invoke;
+ //
+ // The closure does not have a 'user_data' pointer, so push it in as the
+ // last arg. The last arg will be dropped later in callback()
+ //
+ parameterTypes = new Class[method.getParameterTypes().length + 1];
+ parameterTypes[parameterTypes.length - 1] = Pointer.class;
+ for (int i = 0; i < method.getParameterTypes().length; ++i) {
+ Class<?> paramType = method.getParameterTypes()[i];
+ Class<?> nativeType = paramType;
+ if (NativeObject.class.isAssignableFrom(paramType)) {
+ nativeType = Pointer.class;
+ } else if (Enum.class.isAssignableFrom(paramType)) {
+ nativeType = int.class;
+ } else if (String.class.isAssignableFrom(paramType)) {
+ nativeType = Pointer.class;
+ } else if (Boolean.class.isAssignableFrom(paramType)) {
+ nativeType = int.class;
+ }
+ parameterTypes[i] = nativeType;
+ }
+ NativeLong connectID = GSignalAPI.gsignal.g_signal_connect_data(GObject.this,
+ signal, this, null, null, 0);
+ if (connectID.intValue() == 0) {
+ throw new IllegalArgumentException(String.format("Failed to connect signal '%s'", signal));
+ }
+ this.id = connectID;
+ }
+ synchronized protected void disconnect() {
+ if (id != null && id.intValue() != 0) {
+ GObjectAPI.gobj.g_signal_handler_disconnect(GObject.this, id);
+ id = null;
+ }
+ }
+ @Override
+ protected void finalize() {
+ // Ensure the native callback is removed
+ disconnect();
+ }
+ @SuppressWarnings("unchecked")
+ public Object callback(Object[] parameters) {
+
+ try {
+ // Drop the last arg - it is the 'user_data' pointer
+ Object[] methodParameters = new Object[parameters.length - 1];
+
+ for (int i = 0; i < methodParameters.length; ++i) {
+ Class paramType = method.getParameterTypes()[i];
+ Object nativeParam = parameters[i];
+ Object javaParam = nativeParam;
+ if (nativeParam == null) {
+ continue;
+ }
+ if (NativeObject.class.isAssignableFrom(paramType)) {
+ javaParam = NativeObject.objectFor((Pointer) nativeParam,
+ paramType, 1, true);
+ } else if (Enum.class.isAssignableFrom(paramType)) {
+ javaParam = EnumMapper.getInstance().valueOf((Integer) nativeParam,
+ paramType);
+ } else if (String.class.isAssignableFrom(paramType)) {
+ javaParam = ((Pointer) nativeParam).getString(0);
+ } else if (Boolean.class.isAssignableFrom(paramType)) {
+ javaParam = Boolean.valueOf(((Integer) nativeParam).intValue() != 0);
+ } else if (NativeMapped.class.isAssignableFrom(paramType)) {
+ javaParam = NativeMappedConverter.getInstance(paramType).fromNative(nativeParam, null);
+ } else {
+ javaParam = nativeParam;
+ }
+ methodParameters[i] = javaParam;
+ }
+
+ return method.invoke(closure, methodParameters);
+ } catch (Throwable t) {
+ return Integer.valueOf(0);
+ }
+ }
+
+ public Class<?>[] getParameterTypes() {
+ return parameterTypes;
+ }
+
+ public Class<?> getReturnType() {
+ return method.getReturnType();
+ }
+ }
+ public synchronized long connect(String signal, Closure closure) {
+ final Map<String, Map<Closure, ClosureProxy>> signals = getClosureMap();
+ Map<Closure, ClosureProxy> m = signals.get(signal);
+ if (m == null) {
+ m = new HashMap<Closure, ClosureProxy>();
+ signals.put(signal, m);
+ }
+ ClosureProxy cp = new ClosureProxy(signal, closure);
+ m.put(closure, cp);
+ return cp.id.longValue();
+ }
+ public synchronized void disconnect(String signal, Closure closure) {
+ final Map<String, Map<Closure, ClosureProxy>> signals = signalClosures;
+ if (signals == null) {
+ return;
+ }
+ Map<Closure, ClosureProxy> map = signals.get(signal);
+ if (map != null) {
+ ClosureProxy cb = map.remove(signal);
+ if (cb != null) {
+ cb.disconnect();
+ }
+ if (map.isEmpty()) {
+ signals.remove(signal);
+ if (signalClosures.isEmpty()) {
+ signalClosures = null;
+ }
+ }
+ }
+ }
+
+ public static GObject objectFor(Pointer ptr, Class<? extends GObject> defaultClass) {
+ return GObject.objectFor(ptr, defaultClass, true);
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T extends GObject> T objectFor(Pointer ptr, Class<T> defaultClass, boolean needRef) {
+ return NativeObject.objectFor(ptr, defaultClass, needRef);
+ }
+
+ private GObjectAPI.GParamSpec findProperty(String propertyName) {
+ return GObjectAPI.gobj.g_object_class_find_property(handle().getPointer(0), propertyName);
+ }
+ /*
+ * Hooks to/from native disposal
+ */
+ private static final GToggleNotify toggle = new GToggleNotify() {
+ public void callback(Pointer data, Pointer ptr, boolean is_last_ref) {
+ /*
+ * Manage the strong reference to this instance. When this is the last
+ * reference to the underlying object, remove the strong reference so
+ * it can be garbage collected. If it is owned by someone else, then make
+ * it a strong ref, so the java GObject for the underlying C object can
+ * be retained for later retrieval
+ */
+ GObject o = (GObject) NativeObject.instanceFor(ptr);
+ if (o == null) {
+ return;
+ }
+ if (is_last_ref) {
+ strongReferences.remove(o);
+ } else {
+ strongReferences.put(o, Boolean.TRUE);
+ }
+ }
+ };
+}
Added: trunk/src/org/gnome/gir/gobject/GObjectAPI.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GObjectAPI.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,239 @@
+/*
+ * Copyright (c) 2007 Wayne Meissner
+ *
+ * This file was originally part of gstreamer-java; modified for use in
+ * jgir. By permission of author, this file has been relicensed from LGPLv3
+ * to the license of jgir; see below.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307 USA.
+ */
+
+package org.gnome.gir.gobject;
+
+import java.util.HashMap;
+
+import com.sun.jna.Callback;
+import com.sun.jna.Library;
+import com.sun.jna.NativeLong;
+import com.sun.jna.Pointer;
+
+/**
+ *
+ */
+public interface GObjectAPI extends Library {
+ static GObjectAPI gobj = GNative.loadLibrary("gobject-2.0", GObjectAPI.class, new HashMap<String, Object>() {
+ private static final long serialVersionUID = 1L;
+ {
+ put(Library.OPTION_TYPE_MAPPER, new GTypeMapper());
+ }
+ });
+
+ GType g_object_get_type();
+ void g_object_set_property(GObject obj, String property, GValue data);
+ void g_object_get_property(GObject obj, String property, GValue data);
+ void g_object_set(GObject obj, String propertyName, Object... data);
+ void g_object_get(GObject obj, String propertyName, Object... data);
+ Pointer g_object_new(GType object_type, Object... args);
+
+ interface GClosureNotify extends Callback {
+ void callback(Pointer data, Pointer closure);
+ }
+ NativeLong g_signal_connect_data(GObject obj, String signal, Callback callback, Pointer data,
+ GClosureNotify destroy_data, int connect_flags);
+ void g_signal_handler_disconnect(GObject obj, NativeLong id);
+ boolean g_object_is_floating(GObject obj);
+ interface GToggleNotify extends Callback {
+ void callback(Pointer data, Pointer obj, boolean is_last_ref);
+ }
+ void g_object_add_toggle_ref(Pointer object, GToggleNotify notify, IntPtr data);
+ void g_object_remove_toggle_ref(Pointer object, GToggleNotify notify, IntPtr data);
+ interface GWeakNotify extends Callback {
+ void callback(IntPtr data, Pointer obj);
+ }
+ void g_object_weak_ref(GObject object, GWeakNotify notify, IntPtr data);
+ void g_object_weak_unref(GObject object, GWeakNotify notify, IntPtr data);
+ Pointer g_object_ref(GObject object);
+ void g_object_ref_sink(GObject object);
+ void g_object_unref(GObject object);
+
+ GParamSpec g_object_class_find_property(GObjectClass oclass, String property_name);
+ GParamSpec g_object_class_find_property(Pointer oclass, String property_name);
+ GQuark g_quark_try_string(String string);
+ GQuark g_quark_from_static_string(String string);
+ GQuark g_quark_from_string(String string);
+ String g_quark_to_string(GQuark quark);
+
+ String g_intern_string(String string);
+ String g_intern_static_string(String string);
+
+ void g_type_init();
+ void g_type_init_with_debug_flags(int flags);
+ String g_type_name(GType type);
+ //GQuark g_type_qname (GType type);
+ GType g_type_from_name(String name);
+ GType g_type_parent(GType type);
+ int g_type_depth(GType type);
+ Pointer g_type_create_instance(GType type);
+ void g_type_free_instance(Pointer instance);
+
+ Pointer g_type_interface_peek(Pointer g_class, GType type);
+
+ GType g_type_register_static(GType parent_type, String type_name,
+ GTypeInfo info, /* GTypeFlags */ int flags);
+ GType g_type_register_static(GType parent_type, Pointer type_name,
+ GTypeInfo info, /* GTypeFlags */ int flags);
+ GType g_type_register_static_simple(GType parent_type, String type_name,
+ int class_size, GClassInitFunc class_init, int instance_size,
+ GInstanceInitFunc instance_init, /* GTypeFlags */ int flags);
+ GType g_type_register_static_simple(GType parent_type, Pointer type_name,
+ int class_size, GClassInitFunc class_init, int instance_size,
+ GInstanceInitFunc instance_init, /* GTypeFlags */ int flags);
+ /*
+ * Basic Type Structures
+ */
+ public static final class GTypeClass extends com.sun.jna.Structure {
+
+ /*< private >*/
+ public volatile GType g_type;
+ }
+
+ public static final class GTypeInstance extends com.sun.jna.Structure {
+
+ /*< private >*/
+ public volatile Pointer g_class;
+ }
+
+ static class GObjectStruct extends com.sun.jna.Structure {
+ public volatile GTypeInstance g_type_instance;
+ public volatile int ref_count;
+ public volatile Pointer qdata;
+ public GObjectStruct() {}
+ public GObjectStruct(GObject obj) {
+ useMemory(obj.handle());
+ read();
+ }
+ }
+ static public class GObjectConstructParam {
+ public volatile Pointer spec;
+ public volatile Pointer value;
+ }
+ public static final class GObjectClass extends com.sun.jna.Structure {
+ public volatile GTypeClass g_type_class;
+ public volatile Pointer construct_properties;
+ public Constructor constructor;
+ public SetProperty set_property;
+ public GetProperty get_property;
+ public Dispose dispose;
+ public Finalize finalize;
+ public volatile Pointer dispatch_properties_changed;
+ public Notify notify;
+ public volatile byte[] p_dummy = new byte[8 * Pointer.SIZE];
+
+ public static interface Constructor extends Callback {
+ public Pointer callback(GType type, int n_construct_properties,
+ GObjectConstructParam properties);
+ };
+ public static interface SetProperty extends Callback {
+ public void callback(GObject object, int property_id, Pointer value, Pointer spec);
+ }
+ public static interface GetProperty extends Callback {
+ public void callback(GObject object, int property_id, Pointer value, Pointer spec);
+ }
+ public static interface Dispose extends Callback {
+ public void callback(GObject object);
+ }
+ public static interface Finalize extends Callback {
+ public void callback(GObject object);
+ }
+ public static interface Notify extends Callback {
+ public void callback(GObject object, Pointer spec);
+ }
+
+ public GObjectClass() {}
+ public GObjectClass(Pointer ptr) {
+ useMemory(ptr);
+ read();
+ }
+ }
+
+
+ public static interface GBaseInitFunc extends Callback {
+ public void callback(Pointer g_class);
+ }
+
+ public static interface GBaseFinalizeFunc extends Callback {
+ public void callback(Pointer g_class);
+ }
+
+ public static interface GClassInitFunc extends Callback {
+ public void callback(Pointer g_class, Pointer class_data);
+ }
+
+ public static interface GClassFinalizeFunc extends Callback {
+ public void callback(Pointer g_class, Pointer class_data);
+ }
+ public static interface GInstanceInitFunc extends Callback {
+ void callback(GTypeInstance instance, Pointer g_class);
+ }
+ public static final class GTypeInfo extends com.sun.jna.Structure {
+ public GTypeInfo() {
+ clear();
+ }
+ public GTypeInfo(Pointer ptr) {
+ useMemory(ptr);
+ read();
+ }
+ /* interface types, classed types, instantiated types */
+ public short class_size;
+ public GBaseInitFunc base_init;
+ public GBaseFinalizeFunc base_finalize;
+ /* interface types, classed types, instantiated types */
+ public GClassInitFunc class_init;
+ public GClassFinalizeFunc class_finalize;
+ public Pointer class_data;
+ /* instantiated types */
+ public short instance_size;
+ public short n_preallocs;
+
+ public GInstanceInitFunc instance_init;
+
+ /* value handling */
+ public volatile /* GTypeValueTable */ Pointer value_table;
+ }
+
+ static class GParamSpec extends com.sun.jna.Structure {
+ public volatile GTypeInstance g_type_instance;
+ public volatile String g_name;
+ public volatile /* GParamFlags */ int g_flags;
+ public volatile GType value_type;
+ public volatile GType owner_type;
+ /*< private >*/
+ public volatile Pointer _nick;
+ public volatile Pointer _blurb;
+ public volatile Pointer qdata;
+ public volatile int ref_count;
+ public volatile int param_id; /* sort-criteria */
+
+ public GParamSpec() {}
+ }
+
+ public interface GTypeDebugFlags {
+ public static final int NONE = 0;
+ public static final int OBJECTS = 1 << 0;
+ public static final int SIGNALS = 1 << 1;
+ public static final int MASK = 0x03;
+ }
+}
Added: trunk/src/org/gnome/gir/gobject/GObjectGlobals.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GObjectGlobals.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,54 @@
+package org.gnome.gir.gobject;
+
+import com.sun.jna.Function;
+import com.sun.jna.NativeLibrary;
+import com.sun.jna.Pointer;
+
+
+public final class GObjectGlobals {
+ private GObjectGlobals() {}
+
+ private static Function backtrace = null;
+ private static Function backtraceSymbolsFd = null;
+
+ private static final void glibcBacktrace() {
+ if (backtrace == null)
+ return;
+ Pointer[] backtraceData = new Pointer[100];
+ long size = backtrace.invokeLong(new Object[] { backtraceData, backtraceData.length });
+ backtraceSymbolsFd.invoke(new Object[] { backtraceData, size, Integer.valueOf(2) });
+ }
+
+ private static boolean initialized = false;
+
+ public static synchronized void init() {
+ if (initialized)
+ return;
+ final GlibAPI.GLogFunc handler = new GlibAPI.GLogFunc() {
+ @Override
+ public void callback(String log_domain, int log_level,
+ String message, Pointer data) {
+ if (((log_level & GlibAPI.GLogLevelFlags.CRITICAL) > 0) ||
+ ((log_level & GlibAPI.GLogLevelFlags.ERROR) > 0) ||
+ ((log_level & GlibAPI.GLogLevelFlags.WARNING) > 0)) {
+ String msg = "GLib Failure: " + log_domain + " " + message;
+ System.err.println(msg);
+ System.err.println("--- glibc backtrace follows ---");
+ glibcBacktrace();
+ System.err.println("--- glibc backtrace ends ---");
+ throw new RuntimeException(msg);
+ }
+ }
+ };
+ try {
+ NativeLibrary libc = NativeLibrary.getInstance("c");
+ backtrace = libc.getFunction("backtrace");
+ backtraceSymbolsFd = libc.getFunction("backtrace_symbols_fd");
+ } catch (Throwable t) {
+ }
+
+ GlibAPI.glib.g_log_set_default_handler(handler, null);
+ GObjectAPI.gobj.g_type_init();
+ initialized = true;
+ }
+}
Added: trunk/src/org/gnome/gir/gobject/GOptionContext.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GOptionContext.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,7 @@
+package org.gnome.gir.gobject;
+
+import com.sun.jna.PointerType;
+
+public class GOptionContext extends PointerType {
+
+}
Added: trunk/src/org/gnome/gir/gobject/GOptionEntry.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GOptionEntry.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,16 @@
+package org.gnome.gir.gobject;
+
+import com.sun.jna.Pointer;
+import com.sun.jna.Structure;
+
+public class GOptionEntry extends Structure {
+ public String long_name;
+ public byte short_name;
+ public int flags;
+
+ public int arg;
+ public Pointer arg_data;
+
+ public String description;
+ public String arg_description;
+}
Added: trunk/src/org/gnome/gir/gobject/GOptionGroup.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GOptionGroup.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,7 @@
+package org.gnome.gir.gobject;
+
+import com.sun.jna.PointerType;
+
+public class GOptionGroup extends PointerType {
+
+}
Added: trunk/src/org/gnome/gir/gobject/GParamFlags.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GParamFlags.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,16 @@
+package org.gnome.gir.gobject;
+
+public enum GParamFlags implements NativeEnum {
+ READABLE,
+ WRITABLE,
+ CONSTRUCT,
+ CONSTRUCT_ONLY,
+ LAX_VALIDATION,
+ STATIC_NAME,
+ STATIC_NICK,
+ STATIC_BLURB;
+
+ public int getNative() {
+ return 1 << this.ordinal();
+ };
+}
Added: trunk/src/org/gnome/gir/gobject/GQuark.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GQuark.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,35 @@
+package org.gnome.gir.gobject;
+
+import com.sun.jna.FromNativeContext;
+import com.sun.jna.NativeMapped;
+
+public class GQuark implements NativeMapped {
+ private final int value;
+ public GQuark(int value) {
+ this.value = value;
+ }
+ public int intValue() {
+ return value;
+ }
+
+ public GQuark valueOf(String quark) {
+ return GObjectAPI.gobj.g_quark_from_string(quark);
+ }
+
+ @Override
+ public String toString() {
+ return GObjectAPI.gobj.g_quark_to_string(this);
+ }
+ @Override
+ public Object fromNative(Object nativeValue, FromNativeContext context) {
+ return new GQuark((Integer) nativeValue);
+ }
+ @Override
+ public Class<?> nativeType() {
+ return Integer.class;
+ }
+ @Override
+ public Object toNative() {
+ return new Integer(value);
+ }
+}
Added: trunk/src/org/gnome/gir/gobject/GSList.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GSList.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,7 @@
+package org.gnome.gir.gobject;
+
+import com.sun.jna.PointerType;
+
+public class GSList extends PointerType {
+
+}
Added: trunk/src/org/gnome/gir/gobject/GScanner.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GScanner.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,7 @@
+package org.gnome.gir.gobject;
+
+import com.sun.jna.PointerType;
+
+public class GScanner extends PointerType {
+
+}
Added: trunk/src/org/gnome/gir/gobject/GSignalAPI.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GSignalAPI.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2008 Wayne Meissner
+ *
+ * This file was originally part of gstreamer-java; modified for use in
+ * jgir. By permission of author, this file has been relicensed from LGPLv3
+ * to the license of jgir; see below.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307 USA.
+ */
+
+package org.gnome.gir.gobject;
+
+import com.sun.jna.Callback;
+import com.sun.jna.Library;
+import com.sun.jna.NativeLong;
+import com.sun.jna.Pointer;
+import java.util.HashMap;
+
+import org.gnome.gir.gobject.GObjectAPI.GClosureNotify;
+
+/**
+ *
+ * @author wayne
+ */
+public interface GSignalAPI extends Library {
+ static GSignalAPI gsignal = GNative.loadLibrary("gobject-2.0", GSignalAPI.class, new HashMap<String, Object>() {
+ private static final long serialVersionUID = 1L;
+ {
+ put(Library.OPTION_TYPE_MAPPER, new GTypeMapper());
+ }
+ });
+
+ public interface GSignalFlags {
+ public static final int RUN_FIRST = 1 << 0;
+ public static final int RUN_LAST = 1 << 1;
+ public static final int RUN_CLEANUP = 1 << 2;
+ public static final int NO_RECURSE = 1 << 3;
+ public static final int DETAILED = 1 << 4;
+ public static final int ACTION = 1 << 5;
+ public static final int NO_HOOKS = 1 << 6;
+ };
+
+ public static int G_CONNECT_AFTER = 1 << 0;
+ public static int G_CONNECT_SWAPPED = 1 << 1;
+
+ NativeLong g_signal_connect_data(GObject obj, String signal, Callback callback, Pointer data,
+ GClosureNotify destroy_data, int connect_flags);
+ void g_signal_handler_disconnect(GObject obj, NativeLong id);
+
+ int g_signal_lookup(String name, GType itype);
+ String g_signal_name(int signal_id);
+ void g_signal_query(int signal_id, GSignalQuery query);
+ int g_signal_list_ids(GType itype, int[] n_ids);
+
+ // Do nothing, but provide a base Callback class that gets automatic type conversion
+ public static interface GSignalCallbackProxy extends com.sun.jna.CallbackProxy {}
+}
Added: trunk/src/org/gnome/gir/gobject/GSignalFlags.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GSignalFlags.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,15 @@
+package org.gnome.gir.gobject;
+
+public enum GSignalFlags implements NativeEnum {
+ RUN_FIRST,
+ RUN_LAST,
+ RUN_CLEANUP,
+ NO_RECURSE,
+ DETAILED,
+ ACTION,
+ NO_HOOKS;
+
+ public int getNative() {
+ return 1 << this.ordinal();
+ };
+}
Added: trunk/src/org/gnome/gir/gobject/GSignalQuery.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GSignalQuery.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,16 @@
+/**
+ *
+ */
+package org.gnome.gir.gobject;
+
+import com.sun.jna.Pointer;
+
+public final class GSignalQuery extends com.sun.jna.Structure {
+ public int signal_id;
+ public String signal_name;
+ public GType itype;
+ public int /* GSignalFlags */ signal_flags;
+ public GType return_type; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
+ public int n_params;
+ public Pointer param_types; /* mangled with G_SIGNAL_TYPE_STATIC_SCOPE flag */
+}
\ No newline at end of file
Added: trunk/src/org/gnome/gir/gobject/GSource.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GSource.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2007 Wayne Meissner
+ *
+ * This file was originally part of gstreamer-java; modified for use in
+ * jgir. By permission of author, this file has been relicensed from LGPLv3
+ * to the license of jgir; see below.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307 USA.
+ */
+
+package org.gnome.gir.gobject;
+
+import java.util.concurrent.Callable;
+
+import com.sun.jna.Pointer;
+
+/**
+ *
+ */
+public class GSource extends RefCountedObject {
+
+ public GSource(Initializer init) {
+ super(init);
+ }
+ public int attach(GMainContext context) {
+ return GlibAPI.glib.g_source_attach(this, context);
+ }
+ public void setCallback(final Callable<Boolean> call) {
+ this.callback = new GlibAPI.GSourceFunc() {
+ public boolean callback(Pointer data) {
+ if (GlibAPI.glib.g_source_is_destroyed(handle())) {
+ return false;
+ }
+ try {
+ return call.call().booleanValue();
+ } catch (Exception ex) {
+ return false;
+ }
+ }
+ };
+ GlibAPI.glib.g_source_set_callback(this, callback, null, null);
+ }
+ private GlibAPI.GSourceFunc callback;
+
+ protected void ref() {
+ GlibAPI.glib.g_source_ref(handle());
+ }
+ protected void unref() {
+ GlibAPI.glib.g_source_unref(handle());
+ }
+
+ @Override
+ protected void disposeNativeHandle(Pointer ptr) {
+ GlibAPI.glib.g_source_destroy(ptr);
+ GlibAPI.glib.g_source_unref(ptr);
+ }
+}
Added: trunk/src/org/gnome/gir/gobject/GString.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GString.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,10 @@
+package org.gnome.gir.gobject;
+
+import com.sun.jna.NativeLong;
+import com.sun.jna.Structure;
+
+public class GString extends Structure {
+ public String str;
+ public NativeLong len;
+ public NativeLong allocated_len;
+}
Added: trunk/src/org/gnome/gir/gobject/GTimeVal.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GTimeVal.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,9 @@
+package org.gnome.gir.gobject;
+
+import com.sun.jna.NativeLong;
+import com.sun.jna.Structure;
+
+public class GTimeVal extends Structure {
+ public NativeLong tv_sec;
+ public NativeLong tv_usec;
+}
Added: trunk/src/org/gnome/gir/gobject/GType.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GType.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2007 Wayne Meissner
+ *
+ * This file was originally part of gstreamer-java; modified for use in
+ * jgir. By permission of author, this file has been relicensed from LGPLv3
+ * to the license of jgir; see below.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307 USA.
+ */
+
+package org.gnome.gir.gobject;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import com.sun.jna.FromNativeContext;
+import com.sun.jna.NativeLong;
+import com.sun.jna.Pointer;
+
+/**
+ *
+ */
+public class GType extends NativeLong {
+ private static final long serialVersionUID = 1L;
+
+ private static final Map<Pointer, Class<? extends NativeObject>> instanceMap
+ = new ConcurrentHashMap<Pointer, Class<? extends NativeObject>>();
+ private static final Map<GType, Class<? extends NativeObject>> typeMap
+ = new HashMap<GType, Class<? extends NativeObject>>();
+
+ public static final Class<? extends NativeObject> classFor(Pointer ptr) {
+ Pointer g_class = ptr.getPointer(0);
+ Class<? extends NativeObject> cls;
+ cls = instanceMap.get(g_class);
+ if (cls != null) {
+ return cls;
+ }
+ return cls;
+ };
+
+ public static final void registerMapped(GType type, Class<? extends NativeObject> klass) {
+ typeMap.put(type, klass);
+ };
+
+ public static final void init() {
+ GObjectAPI.gobj.g_type_init();
+ }
+
+ private static final GType[] cache;
+ static {
+ cache = new GType[21];
+ for (int i = 0; i < cache.length; ++i) {
+ cache[i] = new GType(i << 2);
+ }
+ };
+ public static final GType INVALID = initFundamental(0);
+ public static final GType NONE = initFundamental(1);
+ public static final GType INTERFACE = initFundamental(2);
+ public static final GType CHAR = initFundamental(3);
+ public static final GType UCHAR = initFundamental(4);
+ public static final GType BOOLEAN = initFundamental(5);
+ public static final GType INT = initFundamental(6);
+ public static final GType UINT = initFundamental(7);
+ public static final GType LONG = initFundamental(8);
+ public static final GType ULONG = initFundamental(9);
+ public static final GType INT64 = initFundamental(10);
+ public static final GType UINT64 = initFundamental(11);
+ public static final GType ENUM = initFundamental(12);
+ public static final GType FLAGS = initFundamental(13);
+ public static final GType FLOAT = initFundamental(14);
+ public static final GType DOUBLE = initFundamental(15);
+ public static final GType STRING = initFundamental(16);
+ public static final GType POINTER = initFundamental(17);
+ public static final GType BOXED = initFundamental(18);
+ public static final GType PARAM = initFundamental(19);
+ public static final GType OBJECT = initFundamental(20);
+
+ private static GType initFundamental(int v) {
+ return valueOf(v << 2);
+ }
+ GType(long t) {
+ super(t);
+ }
+ public GType() {
+ super(0);
+ }
+ public static GType valueOf(long value) {
+ if (value >= 0 && (value >> 2) < cache.length) {
+ return cache[(int)value >> 2];
+ }
+ return new GType(value);
+ }
+ public static GType valueOf(Class<?> javaType) {
+ if (Integer.class == javaType || int.class == javaType) {
+ return INT;
+ } else if (Long.class == javaType || long.class == javaType) {
+ return INT64;
+ } else if (Float.class == javaType || float.class == javaType) {
+ return FLOAT;
+ } else if (Double.class == javaType || double.class == javaType) {
+ return DOUBLE;
+ } else if (String.class == javaType) {
+ return STRING;
+ } else {
+ throw new IllegalArgumentException("No GType for " + javaType);
+ }
+ }
+ @Override
+ public Object fromNative(Object nativeValue, FromNativeContext context) {
+ return valueOf(((Number) nativeValue).longValue());
+ }
+}
Added: trunk/src/org/gnome/gir/gobject/GTypeInstance.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GTypeInstance.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2007 Wayne Meissner
+ *
+ * This file was originally part of gstreamer-java; modified for use in
+ * jgir. By permission of author, this file has been relicensed from LGPLv3
+ * to the license of jgir; see below.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307 USA.
+ */
+
+package org.gnome.gir.gobject;
+
+import com.sun.jna.Pointer;
+import com.sun.jna.Structure;
+
+/**
+ *
+ */
+public class GTypeInstance extends Structure {
+ public Pointer g_class;
+ public void write() { }
+
+ public static Pointer peekInterface(Pointer pointer, GType type) {
+ GTypeInstance instance = new GTypeInstance();
+ instance.useMemory(pointer);
+ return GObjectAPI.gobj.g_type_interface_peek(instance.g_class, type);
+ }
+}
Added: trunk/src/org/gnome/gir/gobject/GTypeMapper.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GTypeMapper.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,281 @@
+/*
+ * Copyright (c) 2007 Wayne Meissner
+ *
+ * This file was originally part of gstreamer-java; modified for use in
+ * jgir. By permission of author, this file has been relicensed from LGPLv3
+ * to the license of jgir; see below.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307 USA.
+ */
+
+package org.gnome.gir.gobject;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.net.URI;
+
+import org.gnome.gir.gobject.annotation.Return;
+import org.gnome.gir.gobject.annotation.ConstField;
+import org.gnome.gir.gobject.annotation.IncRef;
+import org.gnome.gir.gobject.annotation.Invalidate;
+
+import com.sun.jna.CallbackParameterContext;
+import com.sun.jna.FromNativeContext;
+import com.sun.jna.FromNativeConverter;
+import com.sun.jna.FunctionResultContext;
+import com.sun.jna.MethodParameterContext;
+import com.sun.jna.MethodResultContext;
+import com.sun.jna.Pointer;
+import com.sun.jna.StructureReadContext;
+import com.sun.jna.ToNativeContext;
+import com.sun.jna.ToNativeConverter;
+import com.sun.jna.TypeConverter;
+
+/**
+ *
+ * @author wayne
+ */
+public class GTypeMapper extends com.sun.jna.DefaultTypeMapper {
+ public GTypeMapper() {
+ addToNativeConverter(URI.class, uriConverter);
+ }
+
+ private static ToNativeConverter nativeValueArgumentConverter = new ToNativeConverter() {
+
+ public Object toNative(Object arg, ToNativeContext context) {
+ return arg != null ? ((NativeValue) arg).nativeValue() : null;
+ }
+
+ public Class<?> nativeType() {
+ return Void.class; // not really correct, but not used in this instance
+ }
+ };
+
+ private static TypeConverter nativeObjectConverter = new TypeConverter() {
+ public Object toNative(Object arg, ToNativeContext context) {
+ if (arg == null) {
+ return null;
+ }
+ Pointer ptr = ((NativeObject) arg).handle();
+
+ //
+ // Deal with any adjustments to the proxy neccessitated by gstreamer
+ // breaking their reference-counting idiom with special cases
+ //
+ if (context instanceof MethodParameterContext) {
+ MethodParameterContext mcontext = (MethodParameterContext) context;
+ Method method = mcontext.getMethod();
+ int index = mcontext.getParameterIndex();
+ Annotation[][] parameterAnnotations = method.getParameterAnnotations();
+ if (index < parameterAnnotations.length) {
+ Annotation[] annotations = parameterAnnotations[index];
+ for (int i = 0; i < annotations.length; ++i) {
+ if (annotations[i] instanceof Invalidate) {
+ ((Handle) arg).invalidate();
+ break;
+ } else if (annotations[i] instanceof IncRef) {
+ ((RefCountedObject) arg).ref();
+ break;
+ }
+ }
+ }
+ }
+ return ptr;
+ }
+
+ @SuppressWarnings(value = "unchecked")
+ public Object fromNative(Object result, FromNativeContext context) {
+ if (result == null) {
+ return null;
+ }
+ if (context instanceof MethodResultContext) {
+ //
+ // By default, gstreamer increments the refcount on objects
+ // returned from functions, so drop a ref here
+ //
+ boolean ownsHandle = ((MethodResultContext) context).getMethod().isAnnotationPresent(Return.class);
+ int refadj = ownsHandle ? -1 : 0;
+ return NativeObject.objectFor((Pointer) result, context.getTargetType(), refadj, ownsHandle);
+ }
+ if (context instanceof CallbackParameterContext) {
+ return NativeObject.objectFor((Pointer) result, context.getTargetType(), 1, true);
+ }
+ if (context instanceof StructureReadContext) {
+ StructureReadContext sctx = (StructureReadContext) context;
+ boolean ownsHandle = sctx.getField().getAnnotation(ConstField.class) == null;
+ return NativeObject.objectFor((Pointer) result, context.getTargetType(), 1, ownsHandle);
+ }
+ if (context instanceof FunctionResultContext) {
+ return NativeObject.objectFor((Pointer) result, context.getTargetType(), 0, true);
+ }
+ throw new IllegalStateException("Cannot convert to NativeObject from " + context);
+ }
+
+ public Class<?> nativeType() {
+ return Pointer.class;
+ }
+ };
+ private static TypeConverter enumConverter = new TypeConverter() {
+
+ @SuppressWarnings(value = "unchecked")
+ public Object fromNative(Object value, FromNativeContext context) {
+ return EnumMapper.getInstance().valueOf((Integer) value, context.getTargetType());
+ }
+
+ public Class<?> nativeType() {
+ return Integer.class;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object toNative(Object arg, ToNativeContext context) {
+ if (arg == null) {
+ return null;
+ }
+ return EnumMapper.getInstance().intValue((Enum) arg);
+ }
+ };
+
+ private TypeConverter stringConverter = new TypeConverter() {
+
+ public Object fromNative(Object result, FromNativeContext context) {
+ if (result == null) {
+ return null;
+ }
+ if (context instanceof MethodResultContext) {
+ MethodResultContext functionContext = (MethodResultContext) context;
+ Method method = functionContext.getMethod();
+ Pointer ptr = (Pointer) result;
+ String s = ptr.getString(0);
+ if (method.isAnnotationPresent(Return.class)) {
+ GlibAPI.glib.g_free(ptr);
+ }
+ return s;
+ } else {
+ return ((Pointer) result).getString(0);
+ }
+ }
+
+ public Class<?> nativeType() {
+ return Pointer.class;
+ }
+
+ public Object toNative(Object arg, ToNativeContext context) {
+ // Let the default String -> native conversion handle it
+ return arg;
+ }
+ };
+
+ private TypeConverter booleanConverter = new TypeConverter() {
+ public Object toNative(Object arg, ToNativeContext context) {
+ return Integer.valueOf(Boolean.TRUE.equals(arg) ? 1 : 0);
+ }
+
+ public Object fromNative(Object arg0, FromNativeContext arg1) {
+ return Boolean.valueOf(((Integer)arg0).intValue() != 0);
+ }
+
+ public Class<?> nativeType() {
+ return Integer.class;
+ }
+ };
+ private TypeConverter gquarkConverter = new TypeConverter() {
+
+ public Object fromNative(Object arg0, FromNativeContext arg1) {
+ return new GQuark((Integer) arg0);
+ }
+
+ public Class<?> nativeType() {
+ return Integer.class;
+ }
+
+ public Object toNative(Object arg0, ToNativeContext arg1) {
+ return ((GQuark) arg0).intValue();
+ }
+ };
+
+ private TypeConverter intptrConverter = new TypeConverter() {
+
+ public Object toNative(Object arg, ToNativeContext context) {
+ return ((IntPtr)arg).value;
+ }
+
+ public Object fromNative(Object arg0, FromNativeContext arg1) {
+ return new IntPtr(((Number) arg0).intValue());
+ }
+
+ public Class<?> nativeType() {
+ return Pointer.SIZE == 8 ? Long.class : Integer.class;
+ }
+ };
+ private static ToNativeConverter uriConverter = new ToNativeConverter() {
+
+ public Object toNative(Object arg0, ToNativeContext arg1) {
+ URI uri = (URI) arg0;
+ String uriString = uri.toString();
+ // Need to fixup file:/ to be file:/// for gstreamer
+ if ("file".equals(uri.getScheme()) && uri.getHost() == null) {
+ final String path = uri.getRawPath();
+ if (com.sun.jna.Platform.isWindows()) {
+ uriString = "file:/" + path;
+ } else {
+ uriString = "file://" + path;
+ }
+ }
+ return uriString;
+ }
+
+ public Class<?> nativeType() {
+ return String.class;
+ }
+ };
+ @SuppressWarnings("unchecked")
+ public FromNativeConverter getFromNativeConverter(Class type) {
+ if (Enum.class.isAssignableFrom(type)) {
+ return enumConverter;
+ } else if (NativeObject.class.isAssignableFrom(type)) {
+ return nativeObjectConverter;
+ } else if (Boolean.class == type || boolean.class == type) {
+ return booleanConverter;
+ } else if (String.class == type) {
+ return stringConverter;
+ } else if (IntPtr.class == type) {
+ return intptrConverter;
+ } else if (GQuark.class == type) {
+ return gquarkConverter;
+ }
+ return super.getFromNativeConverter(type);
+ }
+
+ @SuppressWarnings("unchecked")
+ public ToNativeConverter getToNativeConverter(Class type) {
+ if (NativeObject.class.isAssignableFrom(type)) {
+ return nativeObjectConverter;
+ } else if (NativeValue.class.isAssignableFrom(type)) {
+ return nativeValueArgumentConverter;
+ } else if (Enum.class.isAssignableFrom(type)) {
+ return enumConverter;
+ } else if (Boolean.class == type || boolean.class == type) {
+ return booleanConverter;
+ } else if (String.class == type) {
+ return stringConverter;
+ } else if (IntPtr.class == type) {
+ return intptrConverter;
+ } else if (GQuark.class == type) {
+ return gquarkConverter;
+ }
+ return super.getToNativeConverter(type);
+ }
+}
Added: trunk/src/org/gnome/gir/gobject/GTypeModule.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GTypeModule.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,8 @@
+
+package org.gnome.gir.gobject;
+
+public class GTypeModule extends GObject {
+ protected GTypeModule(GType gtype, Object[] args) {
+ super(gtype, args);
+ }
+}
\ No newline at end of file
Added: trunk/src/org/gnome/gir/gobject/GTypePlugin.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GTypePlugin.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,6 @@
+
+package org.gnome.gir.gobject;
+
+public interface GTypePlugin {
+
+}
\ No newline at end of file
Added: trunk/src/org/gnome/gir/gobject/GValue.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GValue.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2007 Wayne Meissner
+ *
+ * This file was originally part of gstreamer-java; modified for use in
+ * jgir. By permission of author, this file has been relicensed from LGPLv3
+ * to the license of jgir; see below.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307 USA.
+ */
+
+package org.gnome.gir.gobject;
+
+import com.sun.jna.Pointer;
+
+public class GValue extends com.sun.jna.Structure {
+ /*< private >*/
+ public volatile GType g_type;
+
+ /* public for GTypeValueTable methods */
+ public static class GValueData extends com.sun.jna.Union {
+ public volatile int v_int;
+ public volatile long v_long;
+ public volatile long v_int64;
+ public volatile float v_float;
+ public volatile double v_double;
+ public volatile Pointer v_pointer;
+ }
+
+ public volatile GValueData data[] = new GValueData[2];
+}
Added: trunk/src/org/gnome/gir/gobject/GValueAPI.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GValueAPI.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2008 Wayne Meissner
+ *
+ * This file was originally part of gstreamer-java; modified for use in
+ * jgir. By permission of author, this file has been relicensed from LGPLv3
+ * to the license of jgir; see below.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307 USA.
+ */
+
+package org.gnome.gir.gobject;
+
+import java.util.HashMap;
+
+import org.gnome.gir.gobject.annotation.Return;
+import org.gnome.gir.gobject.annotation.Invalidate;
+
+import com.sun.jna.Library;
+import com.sun.jna.NativeLong;
+
+/**
+ *
+ * @author wayne
+ */
+public interface GValueAPI extends Library {
+ static GValueAPI gvalue = GNative.loadLibrary("gobject-2.0", GValueAPI.class, new HashMap<String, Object>() {
+ private static final long serialVersionUID = 1L;
+ {
+ put(Library.OPTION_TYPE_MAPPER, new GTypeMapper());
+ }
+ });
+
+ GValue g_value_init(GValue value, GType g_type);
+ GValue g_value_reset(GValue value);
+ void g_value_unset(GValue value);
+ void g_value_set_char(GValue value, byte v_char);
+ byte g_value_get_char(GValue value);
+ void g_value_set_uchar(GValue value, byte v_uchar);
+ byte g_value_get_uchar(GValue value);
+ void g_value_set_boolean(GValue value, boolean v_boolean);
+ boolean g_value_get_boolean(GValue value);
+ void g_value_set_int(GValue value, int v_int);
+ int g_value_get_int(GValue value);
+ void g_value_set_uint(GValue value, int v_int);
+ int g_value_get_uint(GValue value);
+ void g_value_set_long(GValue value, NativeLong v_long);
+ NativeLong g_value_get_long(GValue value);
+ void g_value_set_ulong(GValue value, NativeLong v_long);
+ NativeLong g_value_get_ulong(GValue value);
+ void g_value_set_int64(GValue value, long v_int64);
+ long g_value_get_int64(GValue value);
+ void g_value_set_uint64(GValue value, long v_uint64);
+ long g_value_get_uint64(GValue value);
+ void g_value_set_float(GValue value, float v_float);
+ float g_value_get_float(GValue value);
+ void g_value_set_double(GValue value, double v_double);
+ double g_value_get_double(GValue value);
+ void g_value_set_enum(GValue value, int v_enum);
+ int g_value_get_enum(GValue value);
+ void g_value_set_string(GValue value, String v_string);
+ void g_value_set_static_string (GValue value, String v_string);
+ String g_value_get_string(GValue value);
+ boolean g_value_type_compatible(GType src_type, GType dest_type);
+ boolean g_value_type_transformable(GType src_type, GType dest_type);
+ boolean g_value_transform(GValue src_value, GValue dest_value);
+
+ void g_value_set_object(GValue value, GObject v_object);
+ void g_value_take_object(GValue value, @Invalidate GObject v_object);
+ GObject g_value_get_object(GValue value);
+ @Return GObject g_value_dup_object(GValue value);
+}
Added: trunk/src/org/gnome/gir/gobject/GlibAPI.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/GlibAPI.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2007 Wayne Meissner
+ *
+ * This file was originally part of gstreamer-java; modified for use in
+ * jgir. By permission of author, this file has been relicensed from LGPLv3
+ * to the license of jgir; see below.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307 USA.
+ */
+
+package org.gnome.gir.gobject;
+import java.util.HashMap;
+
+import org.gnome.gir.gobject.annotation.Return;
+
+import com.sun.jna.Callback;
+import com.sun.jna.Library;
+import com.sun.jna.NativeLong;
+import com.sun.jna.Pointer;
+import com.sun.jna.ptr.PointerByReference;
+
+/**
+ *
+ */
+public interface GlibAPI extends Library {
+ static GlibAPI glib = GNative.loadLibrary("glib-2.0", GlibAPI.class, new HashMap<String, Object>() {
+ private static final long serialVersionUID = 1L;
+ {
+ put(Library.OPTION_TYPE_MAPPER, new GTypeMapper());
+ }
+ });
+ Pointer g_main_loop_new(GMainContext context, boolean running);
+ void g_main_loop_run(MainLoop loop);
+ boolean g_main_loop_is_running(MainLoop loop);
+ @Return GMainContext g_main_loop_get_context(MainLoop loop);
+ void g_main_loop_quit(MainLoop loop);
+ void g_main_loop_ref(MainLoop ptr);
+ void g_main_loop_unref(MainLoop ptr);
+ void g_main_loop_unref(Pointer ptr);
+
+ /*
+ * GMainContext functions
+ */
+
+ Pointer g_main_context_new();
+ void g_main_context_ref(Pointer context);
+ void g_main_context_unref(Pointer context);
+ Pointer g_main_context_default();
+ boolean g_main_context_pending(GMainContext ctx);
+ boolean g_main_context_acquire(GMainContext ctx);
+ void g_main_context_release(GMainContext ctx);
+ boolean g_main_context_is_owner(GMainContext ctx);
+ boolean g_main_context_wait(GMainContext ctx);
+
+ @Return GSource g_idle_source_new();
+ @Return GSource g_timeout_source_new(int interval);
+ @Return GSource g_timeout_source_new_seconds(int interval);
+ int g_source_attach(GSource source, GMainContext context);
+ void g_source_destroy(Pointer source);
+ void g_source_destroy(GSource source);
+ Pointer g_source_ref(Pointer source);
+ void g_source_unref(Pointer source);
+ void g_source_set_callback(GSource source, GSourceFunc callback, Object data, GDestroyNotify destroy);
+ boolean g_source_is_destroyed(Pointer source);
+ boolean g_source_is_destroyed(GSource source);
+ /*
+ * GThread functions
+ */
+ interface GThreadFunc extends Callback {
+ Pointer callback(Pointer data);
+ }
+ Pointer g_thread_create(GThreadFunc func, Pointer data, boolean joinable, PointerByReference error);
+ Pointer g_thread_self();
+ Pointer g_thread_join(Pointer thread);
+ void g_thread_yield();
+ void g_thread_set_priority(Pointer thread, int priority);
+ void g_thread_exit(Pointer retval);
+
+
+
+ interface GSourceFunc extends Callback {
+ boolean callback(Pointer data);
+ }
+ NativeLong g_idle_add(GSourceFunc function, Pointer data);
+ interface GDestroyNotify extends Callback {
+ void callback(Pointer data);
+ }
+
+ int g_timeout_add(int interval, GSourceFunc function, Pointer data);
+ int g_timeout_add_full(int priority, int interval, GSourceFunc function,
+ Pointer data, GDestroyNotify notify);
+ int g_timeout_add_seconds(int interval, GSourceFunc function, Pointer data);
+ void g_error_free(Pointer error);
+ void g_error_free(GErrorStruct error);
+
+ void g_source_remove(int id);
+ void g_free(Pointer ptr);
+
+ Pointer g_date_new();
+ Pointer g_date_new_dmy(int day, int month, int year);
+ Pointer g_date_new_julian(int julian_day);
+ void g_date_free(Pointer date);
+
+ public interface GLogLevelFlags {
+ public static final int RECURSION = 1 << 0;
+ public static final int FATAL = 1 << 1;
+ /* GLib log levels */
+ public static final int ERROR = 1 << 2; /* always fatal */
+ public static final int CRITICAL = 1 << 3;
+ public static final int WARNING = 1 << 4;
+ public static final int MESSAGE = 1 << 5;
+ public static final int INFO = 1 << 6;
+ public static final int DEBUG = 1 << 7;
+ public static final int MASK = ~(RECURSION | FATAL);
+ }
+
+ public interface GLogFunc extends Callback {
+ void callback (String log_domain, int log_level, String message, Pointer data);
+ }
+
+ int g_log_set_handler(String log_domain, int levels, GLogFunc handler, Pointer user_data);
+ void g_log_default_handler (String log_domain, int log_level, String message, Pointer unused_data);
+ Pointer g_log_set_default_handler(GLogFunc log_func, Pointer user_data);
+
+ public final static class GList extends com.sun.jna.Structure {
+ public volatile Pointer data;
+ public volatile Pointer _next;
+ public volatile Pointer _prev;
+ public GList() {
+ }
+ private GList(Pointer pointer) {
+ useMemory(pointer);
+ read();
+ }
+ private static GList valueOf(Pointer ptr) {
+ return ptr != null ? new GList(ptr) : null;
+ }
+ public GList next() {
+ return valueOf(_next);
+ }
+ public GList prev() {
+ return valueOf(_prev);
+ }
+ }
+}
Added: trunk/src/org/gnome/gir/gobject/Handle.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/Handle.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2007 Wayne Meissner
+ *
+ * This file was originally part of gstreamer-java; modified for use in
+ * jgir. By permission of author, this file has been relicensed from LGPLv3
+ * to the license of jgir; see below.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307 USA.
+ */
+
+package org.gnome.gir.gobject;
+
+import com.sun.jna.Pointer;
+
+abstract public class Handle extends NativeValue {
+ // Use this to propagate low level pointer arguments up the constructor chain
+ protected static class Initializer {
+ public final Pointer ptr;
+ public final boolean needRef, ownsHandle;
+ public Initializer() {
+ this.ptr = null;
+ this.needRef = false;
+ this.ownsHandle = false;
+ }
+ public Initializer(Pointer ptr) {
+ this(ptr, false, true);
+ }
+ public Initializer(Pointer ptr, boolean needRef, boolean ownsHandle) {
+ if (ptr == null)
+ throw new RuntimeException("Invalid NULL pointer for initializer");
+ this.ptr = ptr;
+ this.needRef = needRef;
+ this.ownsHandle = ownsHandle;
+ }
+ }
+
+ protected static final Initializer defaultInit = new Initializer();
+
+ public Handle() {
+ }
+ abstract protected void invalidate();
+}
Added: trunk/src/org/gnome/gir/gobject/IntPtr.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/IntPtr.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2007 Wayne Meissner
+ *
+ * This file was originally part of gstreamer-java; modified for use in
+ * jgir. By permission of author, this file has been relicensed from LGPLv3
+ * to the license of jgir; see below.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307 USA.
+ */
+package org.gnome.gir.gobject;
+
+import com.sun.jna.Pointer;
+
+public class IntPtr extends Number {
+ private static final long serialVersionUID = 1L;
+ public final Number value;
+ public IntPtr(int value) {
+ this.value = Pointer.SIZE == 8 ? new Long(value) : new Integer(value);
+ }
+
+ public String toString() {
+ return Integer.toHexString(intValue());
+ }
+
+ public int intValue() {
+ return value.intValue();
+ }
+
+ public long longValue() {
+ return value.longValue();
+ }
+
+ public float floatValue() {
+ return value.floatValue();
+ }
+
+ public double doubleValue() {
+ return value.doubleValue();
+ }
+}
Added: trunk/src/org/gnome/gir/gobject/IntegerEnum.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/IntegerEnum.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2007 Wayne Meissner
+ *
+ * This file was originally part of gstreamer-java; modified for use in
+ * jgir. By permission of author, this file has been relicensed from LGPLv3
+ * to the license of jgir; see below.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307 USA.
+ */
+
+package org.gnome.gir.gobject;
+
+/**
+ * Interface for int enums that are non-contiguous (i.e. can't just use Enum.ordinal())
+ * to find the native value.
+ */
+public interface IntegerEnum {
+ public int intValue();
+}
Added: trunk/src/org/gnome/gir/gobject/MainLoop.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/MainLoop.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,195 @@
+/*
+ * Copyright (c) 2007 Wayne Meissner
+ *
+ * This file was originally part of gstreamer-java; modified for use in
+ * jgir. By permission of author, this file has been relicensed from LGPLv3
+ * to the license of jgir; see below.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307 USA.
+ */
+
+package org.gnome.gir.gobject;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.FutureTask;
+
+import com.sun.jna.Pointer;
+
+/**
+ * The GLib main loop.
+ */
+public class MainLoop extends RefCountedObject {
+ private static final List<Runnable> bgTasks = new LinkedList<Runnable>();
+
+ /**
+ * Creates a new instance of { code MainLoop}
+ *
+ * <p> This will create a new main loop on the default main context.
+ *
+ */
+ public MainLoop() {
+ super(initializer(GlibAPI.glib.g_main_loop_new(null, false)));
+ }
+
+ /**
+ * Creates a new instance of { code MainLoop}
+ *
+ * <p> This variant is used internally.
+ *
+ * @param init internal initialization data.
+ */
+ public MainLoop(Initializer init) {
+ super(init);
+ }
+
+ /**
+ * Instructs a main loop to stop processing and return from { link #run}.
+ */
+ public void quit() {
+ invokeLater(new Runnable() {
+ public void run() {
+ GlibAPI.glib.g_main_loop_quit(MainLoop.this);
+ }
+ });
+ }
+
+ /**
+ * Enter a loop, processing all events.
+ * <p> The loop will continue processing events until { link #quit} is
+ * called.
+ */
+ public void run() {
+ GlibAPI.glib.g_main_loop_run(this);
+ }
+
+ /**
+ * Returns whether this main loop is currently processing or not.
+ *
+ * @return <tt>true</tt> if the main loop is currently being run.
+ */
+ public boolean isRunning() {
+ return GlibAPI.glib.g_main_loop_is_running(this);
+ }
+
+ /**
+ * Gets the main context for this main loop.
+ *
+ * @return a main context.
+ */
+ public GMainContext getMainContext() {
+ return GlibAPI.glib.g_main_loop_get_context(this);
+ }
+
+ /**
+ * Runs the main loop in a background thread.
+ */
+ public void startInBackground() {
+ bgThread = new java.lang.Thread(new Runnable() {
+
+ public void run() {
+ MainLoop.this.run();
+ }
+ });
+ bgThread.setDaemon(true);
+ bgThread.setName("gmainloop");
+ bgThread.start();
+ }
+
+ /**
+ * Invokes a task on the main loop thread.
+ * <p> This method will wait until the task has completed before returning.
+ *
+ * @param r the task to invoke.
+ */
+ public void invokeAndWait(Runnable r) {
+ FutureTask<Object> task = new FutureTask<Object>(r, null);
+ invokeLater(task);
+ try {
+ task.get();
+ } catch (InterruptedException ex) {
+ throw new RuntimeException(ex.getCause());
+ } catch (ExecutionException ex) {
+ throw new RuntimeException(ex.getCause());
+ }
+ }
+ private static final GlibAPI.GSourceFunc bgCallback = new GlibAPI.GSourceFunc() {
+ public boolean callback(Pointer source) {
+ List<Runnable> tasks = new ArrayList<Runnable>();
+ synchronized (bgTasks) {
+ tasks.addAll(bgTasks);
+ bgTasks.clear();
+ }
+ for (Runnable r : tasks) {
+ r.run();
+ }
+ GlibAPI.glib.g_source_unref(source);
+ return false;
+ }
+ };
+ /**
+ * Invokes a task on the main loop thread.
+ * <p> This method returns immediately, without waiting for the task to
+ * complete.
+ *
+ * @param r the task to invoke.
+ */
+ public void invokeLater(final Runnable r) {
+ synchronized (bgTasks) {
+ boolean empty = bgTasks.isEmpty();
+ bgTasks.add(r);
+ // Only trigger the callback if there were no existing elements in the list
+ // otherwise it is already triggered
+ if (empty) {
+ GSource source = GlibAPI.glib.g_idle_source_new();
+ GlibAPI.glib.g_source_set_callback(source, bgCallback, source, null);
+ source.attach(getMainContext());
+ source.disown(); // gets destroyed in the callback
+ }
+ }
+ }
+
+ //--------------------------------------------------------------------------
+ // protected methods
+ //
+ /**
+ * Increases the reference count on the native { code GMainLoop}
+ */
+ protected void ref() {
+ GlibAPI.glib.g_main_loop_ref(this);
+ }
+
+ /**
+ * Decreases the reference count on the native { code GMainLoop}
+ */
+ protected void unref() {
+ GlibAPI.glib.g_main_loop_unref(this);
+ }
+
+ /**
+ * Frees the native { code GMainLoop}
+ */
+ protected void disposeNativeHandle(Pointer ptr) {
+ GlibAPI.glib.g_main_loop_unref(ptr);
+ }
+
+ //--------------------------------------------------------------------------
+ // Instance variables
+ //
+ private Thread bgThread;
+}
Added: trunk/src/org/gnome/gir/gobject/NativeEnum.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/NativeEnum.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,5 @@
+package org.gnome.gir.gobject;
+
+public interface NativeEnum {
+ public int getNative();
+}
Added: trunk/src/org/gnome/gir/gobject/NativeObject.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/NativeObject.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,221 @@
+/*
+ * Copyright (c) 2007 Wayne Meissner
+ *
+ * This file was originally part of gstreamer-java; modified for use in
+ * jgir. By permission of author, this file has been relicensed from LGPLv3
+ * to the license of jgir; see below.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307 USA.
+ */
+
+package org.gnome.gir.gobject;
+
+import java.lang.ref.WeakReference;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.gnome.gir.repository.BaseInfo;
+
+import com.sun.jna.Pointer;
+
+/**
+ *
+ */
+public abstract class NativeObject extends Handle {
+ private final AtomicBoolean disposed = new AtomicBoolean(false);
+ private final AtomicBoolean valid = new AtomicBoolean(true);
+ private final Pointer handle;
+ protected final AtomicBoolean ownsHandle = new AtomicBoolean(false);
+ private final NativeRef nativeRef;
+
+ private static final ConcurrentMap<Pointer, NativeRef> instanceMap = new ConcurrentHashMap<Pointer, NativeRef>();
+
+ static class NativeRef extends WeakReference<NativeObject> {
+ public NativeRef(NativeObject obj) {
+ super(obj);
+ }
+ }
+
+ /*
+ * The default for new objects is to not need a refcount increase, and that
+ * they own the native object. Special cases can use the other constructor.
+ */
+ protected static Initializer initializer(Pointer ptr) {
+ return initializer(ptr, false, true);
+ }
+ protected static Initializer initializer(Pointer ptr, boolean needRef, boolean ownsHandle) {
+ if (ptr == null) {
+ throw new IllegalArgumentException("Invalid native pointer");
+ }
+ return new Initializer(ptr, needRef, ownsHandle);
+ }
+ /** Creates a new instance of NativeObject */
+ protected NativeObject(final Initializer init) {
+ if (init == null) {
+ throw new IllegalArgumentException("Initializer cannot be null");
+ }
+ nativeRef = new NativeRef(this);
+ this.handle = init.ptr;
+ this.ownsHandle.set(init.ownsHandle);
+
+ //
+ // Only store this object in the map if we can tell when it has been disposed
+ // (i.e. must be at least a GObject - MiniObject and other NativeObject subclasses
+ // don't signal destruction, so it is impossible to know if the instance
+ // is stale or not
+ //
+ if (GObject.class.isAssignableFrom(getClass())) {
+ instanceMap.put(init.ptr, nativeRef);
+ }
+
+ }
+
+ abstract protected void disposeNativeHandle(Pointer ptr);
+
+ public void dispose() {
+ if (!disposed.getAndSet(true)) {
+ instanceMap.remove(handle, nativeRef);
+ if (ownsHandle.get()) {
+ disposeNativeHandle(handle);
+ }
+ valid.set(false);
+ }
+ }
+
+ protected void invalidate() {
+ instanceMap.remove(handle(), nativeRef);
+ disposed.set(true);
+ ownsHandle.set(false);
+ valid.set(false);
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ try {
+ dispose();
+ } finally {
+ super.finalize();
+ }
+ }
+ protected Object nativeValue() {
+ return handle();
+ }
+ protected Pointer handle() {
+ if (!valid.get()) {
+ throw new IllegalStateException("Native object has been disposed");
+ }
+ return handle;
+ }
+ public Pointer getNativeAddress() {
+ return handle;
+ }
+ protected boolean isDisposed() {
+ return disposed.get();
+ }
+ protected static NativeObject instanceFor(Pointer ptr) {
+ WeakReference<NativeObject> ref = instanceMap.get(ptr);
+
+ //
+ // If the reference was there, but the object it pointed to had been collected, remove it from the map
+ //
+ if (ref != null && ref.get() == null) {
+ instanceMap.remove(ptr);
+ }
+ return ref != null ? ref.get() : null;
+ }
+ public static <T extends NativeObject> T objectFor(Pointer ptr, Class<T> cls, boolean needRef) {
+ return objectFor(ptr, cls, needRef, true);
+ }
+ public static <T extends NativeObject> T objectFor(Pointer ptr, Class<T> cls, boolean needRef, boolean ownsHandle) {
+ return objectFor(ptr, cls, needRef ? 1 : 0, ownsHandle);
+ }
+
+ public static <T extends NativeObject> T objectFor(Pointer ptr, Class<T> cls, int refAdjust, boolean ownsHandle) {
+ // Ignore null pointers
+ if (ptr == null) {
+ return null;
+ }
+ NativeObject obj = null;
+ if (BaseInfo.class.isAssignableFrom(cls))
+ obj = BaseInfo.newInstanceFor(ptr);
+ else if (GObject.class.isAssignableFrom(cls))
+ obj = NativeObject.instanceFor(ptr);
+ if (obj != null && cls.isInstance(obj)) {
+ if (refAdjust < 0) {
+ ((RefCountedObject) obj).unref(); // Lose the extra ref added by gstreamer
+ }
+ return cls.cast(obj);
+ }
+
+ //
+ // If it is a GObject or MiniObject, read the g_class field to find
+ // the most exact class match
+ //
+ // || MiniObject.class.isAssignableFrom(cls)
+ if (GObject.class.isAssignableFrom(cls)) {
+ cls = classFor(ptr, cls);
+ }
+ try {
+ Constructor<T> constructor = cls.getDeclaredConstructor(Initializer.class);
+ constructor.setAccessible(true);
+ T retVal = constructor.newInstance(initializer(ptr, refAdjust > 0, ownsHandle));
+ //retVal.initNativeHandle(ptr, refAdjust > 0, ownsHandle);
+ return retVal;
+ } catch (SecurityException ex) {
+ throw new RuntimeException(ex);
+ } catch (IllegalAccessException ex) {
+ throw new RuntimeException(ex);
+ } catch (InstantiationException ex) {
+ throw new RuntimeException(ex);
+ } catch (NoSuchMethodException ex) {
+ throw new RuntimeException(ex);
+ } catch (InvocationTargetException ex) {
+ throw new RuntimeException(ex);
+ }
+
+ }
+
+ @SuppressWarnings("unchecked")
+ protected static <T extends NativeObject> Class<T> classFor(Pointer ptr, Class<T> defaultClass) {
+ Class<? extends NativeObject> cls = GType.classFor(ptr);
+ return (cls != null && defaultClass.isAssignableFrom(cls)) ? (Class<T>) cls : defaultClass;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ return o instanceof NativeObject && ((NativeObject) o).handle.equals(handle);
+ }
+
+ @Override
+ public int hashCode() {
+ return handle.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + "(" + handle() + ")";
+ }
+
+ //
+ // No longer want to garbage collect this object
+ //
+ public void disown() {
+ ownsHandle.set(false);
+ }
+}
Added: trunk/src/org/gnome/gir/gobject/NativeValue.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/NativeValue.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2007 Wayne Meissner
+ *
+ * This file was originally part of gstreamer-java; modified for use in
+ * jgir. By permission of author, this file has been relicensed from LGPLv3
+ * to the license of jgir; see below.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307 USA.
+ */
+
+package org.gnome.gir.gobject;
+
+/**
+ *
+ */
+public abstract class NativeValue {
+
+ protected NativeValue() {
+ }
+ abstract protected Object nativeValue();
+}
Added: trunk/src/org/gnome/gir/gobject/RefCountedObject.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/RefCountedObject.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2007, 2008 Wayne Meissner
+ *
+ * This file was originally part of gstreamer-java; modified for use in
+ * jgir. By permission of author, this file has been relicensed from LGPLv3
+ * to the license of jgir; see below.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307 USA.
+ */
+
+package org.gnome.gir.gobject;
+
+/**
+ * A { link NativeObject} that has an associated reference count
+ * @author wayne
+ */
+abstract public class RefCountedObject extends NativeObject {
+ /** Creates a new instance of RefCountedObject */
+ protected RefCountedObject(Initializer init) {
+ super(init);
+ if (init.ownsHandle && init.needRef) {
+ ref();
+ }
+ }
+ // overridden in subclasses
+ abstract protected void ref();
+ abstract protected void unref();
+}
Added: trunk/src/org/gnome/gir/gobject/Util.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/Util.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,22 @@
+package org.gnome.gir.gobject;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public class Util {
+ public static final <T> List<T> toList(Iterable<T> iterable) {
+ List<T> ret = new ArrayList<T>();
+ for (T it : iterable)
+ ret.add(it);
+ return ret;
+ }
+
+ public static final <T> Set<T> toSet(Iterable<T> iterable) {
+ Set<T> ret = new HashSet<T>();
+ for (T it : iterable)
+ ret.add(it);
+ return ret;
+ }
+}
Added: trunk/src/org/gnome/gir/gobject/ZeroTerminatedArray.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/ZeroTerminatedArray.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,66 @@
+package org.gnome.gir.gobject;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.gnome.gir.repository.Transfer;
+
+import com.sun.jna.Pointer;
+import com.sun.jna.PointerType;
+
+public class ZeroTerminatedArray<T> extends PointerType implements ComplexReturn<T> {
+ public Iterable<Pointer> iterComponents() {
+ return new Iterable<Pointer>() {
+ @Override
+ public Iterator<Pointer> iterator() {
+ return new Iterator<Pointer>() {
+ private int idx = 0;
+
+ private Pointer getCurrent() {
+ return ZeroTerminatedArray.this.getPointer().getPointer(idx * Pointer.SIZE);
+ }
+
+ @Override
+ public boolean hasNext() {
+ return getCurrent() != null;
+ }
+
+ @Override
+ public Pointer next() {
+ Pointer ret = getCurrent();
+ idx++;
+ return ret;
+ }
+
+ @Override
+ public void remove() {
+ throw new RuntimeException();
+ }
+ };
+ }
+ };
+ };
+
+ public void dispose(Transfer trans) {
+ if (trans == Transfer.EVERYTHING) {
+ for (Pointer p : iterComponents()){
+ GlibAPI.glib.g_free(p);
+ }
+ }
+ if (trans == Transfer.EVERYTHING || trans == Transfer.CONTAINER)
+ GlibAPI.glib.g_free(this.getPointer());
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<T> convert(Class<T> klass) {
+ List<T> ret = new ArrayList<T>();
+ for (Pointer p : iterComponents()) {
+ if (klass.equals(String.class))
+ ret.add((T) p.getString(0));
+ else
+ throw new UnsupportedOperationException();
+ }
+ return ret;
+ }
+}
Added: trunk/src/org/gnome/gir/gobject/annotation/ConstField.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/annotation/ConstField.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2008 Wayne Meissner
+ *
+ * This file was originally part of gstreamer-java; modified for use in
+ * jgir. By permission of author, this file has been relicensed from LGPLv3
+ * to the license of jgir; see below.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307 USA.
+ */
+
+package org.gnome.gir.gobject.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ *
+ * @author wayne
+ */
+ Retention(RetentionPolicy.RUNTIME)
+ Target(ElementType.FIELD)
+public @interface ConstField {
+
+}
Added: trunk/src/org/gnome/gir/gobject/annotation/IncRef.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/annotation/IncRef.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2007 Wayne Meissner
+ *
+ * This file was originally part of gstreamer-java; modified for use in
+ * jgir. By permission of author, this file has been relicensed from LGPLv3
+ * to the license of jgir; see below.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307 USA.
+ */
+
+package org.gnome.gir.gobject.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Signal that the Handle parameter's refcount should be incremented
+ */
+ Retention(RetentionPolicy.RUNTIME)
+ Target(ElementType.PARAMETER)
+public @interface IncRef {
+
+}
Added: trunk/src/org/gnome/gir/gobject/annotation/Invalidate.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/annotation/Invalidate.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2007 Wayne Meissner
+ *
+ * This file was originally part of gstreamer-java; modified for use in
+ * jgir. By permission of author, this file has been relicensed from LGPLv3
+ * to the license of jgir; see below.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307 USA.
+ */
+
+package org.gnome.gir.gobject.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Signal that the Handle parameter should be invalidated (not used after this call)
+ */
+ Retention(RetentionPolicy.RUNTIME)
+ Target(ElementType.PARAMETER)
+public @interface Invalidate {
+
+}
Added: trunk/src/org/gnome/gir/gobject/annotation/RepositoryId.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/annotation/RepositoryId.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,13 @@
+package org.gnome.gir.gobject.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+ Retention(RetentionPolicy.RUNTIME)
+ Target(ElementType.METHOD)
+public @interface RepositoryId {
+ String namespace();
+ String name();
+}
Added: trunk/src/org/gnome/gir/gobject/annotation/Return.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/annotation/Return.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,14 @@
+package org.gnome.gir.gobject.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.gnome.gir.repository.Transfer;
+
+ Retention(RetentionPolicy.RUNTIME)
+ Target(ElementType.METHOD)
+public @interface Return {
+ public Transfer transfer() default Transfer.NOTHING;
+}
Added: trunk/src/org/gnome/gir/gobject/annotation/ReturnContainer.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/gobject/annotation/ReturnContainer.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,18 @@
+package org.gnome.gir.gobject.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.gnome.gir.repository.Transfer;
+import org.gnome.gir.repository.TypeTag;
+
+ Retention(RetentionPolicy.RUNTIME)
+ Target(ElementType.METHOD)
+public @interface ReturnContainer {
+ public Transfer transfer() default Transfer.NOTHING;
+ public TypeTag containerType() default TypeTag.ARRAY;
+ public TypeTag paramType();
+ public boolean zeroTerminated() default false;
+}
Added: trunk/src/org/gnome/gir/repository/ArgInfo.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/ArgInfo.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,30 @@
+package org.gnome.gir.repository;
+
+
+public class ArgInfo extends BaseInfo {
+ protected ArgInfo(Initializer init) {
+ super(init);
+ }
+ public Direction getDirection() {
+ return Repository.getNativeLibrary().g_arg_info_get_direction(this);
+ }
+ public boolean isDipper() {
+ return Repository.getNativeLibrary().g_arg_info_is_dipper(this);
+ }
+ public boolean isReturnValue() {
+ return Repository.getNativeLibrary().g_arg_info_is_return_value(this);
+ }
+ public boolean isOptional() {
+ return Repository.getNativeLibrary().g_arg_info_is_optional(this);
+ }
+ public boolean mayBeNull() {
+ return Repository.getNativeLibrary().g_arg_info_may_be_null(this);
+ }
+ public Transfer getOwnershipTransfer() {
+ return Repository.getNativeLibrary().g_arg_info_get_ownership_transfer(this);
+ }
+
+ public TypeInfo getType() {
+ return Repository.getNativeLibrary().g_arg_info_get_type(this);
+ }
+}
Added: trunk/src/org/gnome/gir/repository/Argument.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/Argument.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,18 @@
+/**
+ *
+ */
+package org.gnome.gir.repository;
+
+import com.sun.jna.Pointer;
+import com.sun.jna.Union;
+
+public class Argument extends Union {
+ public Byte v_int8;
+ public Short v_int16;
+ public Integer v_int32;
+ public Long v_int64;
+ public Float v_float;
+ public Double v_double;
+ public String v_string;
+ public Pointer v_pointer;
+}
\ No newline at end of file
Added: trunk/src/org/gnome/gir/repository/BaseInfo.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/BaseInfo.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,65 @@
+package org.gnome.gir.repository;
+
+import org.gnome.gir.gobject.RefCountedObject;
+
+import com.sun.jna.Pointer;
+
+public class BaseInfo extends RefCountedObject {
+ protected BaseInfo(Initializer init) {
+ super(init);
+ }
+
+ public static BaseInfo newInstanceFor(Pointer ptr) {
+ int itype = GIntrospectionAPI.gi.g_base_info_get_type(ptr);
+ if (itype == InfoType.UNRESOLVED.ordinal()) {
+ String namespace = GIntrospectionAPI.gi.g_base_info_get_namespace(ptr);
+ String name = GIntrospectionAPI.gi.g_base_info_get_name(ptr);
+ throw new UnresolvedException(namespace, name);
+ }
+ Initializer init = new Initializer(ptr, false, false);
+ if (itype == InfoType.ENUM.ordinal())
+ return new EnumInfo(init);
+ if (itype == InfoType.FLAGS.ordinal())
+ return new FlagsInfo(init);
+ if (itype == InfoType.OBJECT.ordinal())
+ return new ObjectInfo(init);
+ if (itype == InfoType.FUNCTION.ordinal())
+ return new FunctionInfo(init);
+ if (itype == InfoType.STRUCT.ordinal())
+ return new StructInfo(init);
+ if (itype == InfoType.BOXED.ordinal())
+ return new BoxedInfo(init);
+ if (itype == InfoType.INTERFACE.ordinal())
+ return new InterfaceInfo(init);
+ if (itype == InfoType.CALLBACK.ordinal())
+ return new CallbackInfo(init);
+ return new BaseInfo(new Initializer(ptr));
+ }
+
+ @Override
+ public void ref() {
+ Repository.getNativeLibrary().g_base_info_ref(this);
+ }
+
+ @Override
+ public void unref() {
+ //Repository.getNativeLibrary().g_base_info_unref(this);
+ }
+
+ public String getName() {
+ return Repository.getNativeLibrary().g_base_info_get_name(this.handle());
+ }
+
+ @Override
+ protected void disposeNativeHandle(Pointer ptr) {
+ unref();
+ }
+
+ public String getNamespace() {
+ return GIntrospectionAPI.gi.g_base_info_get_namespace(this.handle());
+ }
+
+ public String toString() {
+ return "<" + getClass().getSimpleName() + " ns=" + getNamespace() + " name=" + getName() + ">";
+ }
+}
Added: trunk/src/org/gnome/gir/repository/BoxedInfo.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/BoxedInfo.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,8 @@
+package org.gnome.gir.repository;
+
+
+public class BoxedInfo extends BaseInfo {
+ protected BoxedInfo(Initializer init) {
+ super(init);
+ }
+}
Added: trunk/src/org/gnome/gir/repository/CallableInfo.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/CallableInfo.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,31 @@
+
+package org.gnome.gir.repository;
+
+public class CallableInfo extends BaseInfo {
+ protected CallableInfo(Initializer init) {
+ super(init);
+ }
+ public TypeInfo getReturnType() {
+ return Repository.getNativeLibrary().g_callable_info_get_return_type(this);
+ }
+ public Transfer getCallerOwns() {
+ return Repository.getNativeLibrary().g_callable_info_get_caller_owns(this);
+ }
+ public boolean getMayReturnNull() {
+ return Repository.getNativeLibrary().g_callable_info_get_may_return_null(this);
+ }
+ public int getNArgs() {
+ return Repository.getNativeLibrary().g_callable_info_get_n_args(this);
+ }
+ public ArgInfo getArg(int n) {
+ return Repository.getNativeLibrary().g_callable_info_get_arg(this, n);
+ }
+
+ public ArgInfo[] getArgs() {
+ int n = getNArgs();
+ ArgInfo[] ret = new ArgInfo[n];
+ for (int i = 0; i < n; i++)
+ ret[i] = getArg(i);
+ return ret;
+ }
+}
\ No newline at end of file
Added: trunk/src/org/gnome/gir/repository/CallbackInfo.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/CallbackInfo.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,8 @@
+
+package org.gnome.gir.repository;
+
+public class CallbackInfo extends CallableInfo {
+ protected CallbackInfo(Initializer init) {
+ super(init);
+ }
+}
\ No newline at end of file
Added: trunk/src/org/gnome/gir/repository/ConstantInfo.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/ConstantInfo.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,7 @@
+package org.gnome.gir.repository;
+
+import com.sun.jna.PointerType;
+
+public class ConstantInfo extends PointerType {
+
+}
Added: trunk/src/org/gnome/gir/repository/Direction.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/Direction.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,10 @@
+/**
+ *
+ */
+package org.gnome.gir.repository;
+
+public enum Direction {
+ IN,
+ OUT,
+ INOUT,
+}
\ No newline at end of file
Added: trunk/src/org/gnome/gir/repository/EnumInfo.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/EnumInfo.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,15 @@
+package org.gnome.gir.repository;
+
+
+public class EnumInfo extends RegisteredTypeInfo {
+ protected EnumInfo(Initializer init) {
+ super(init);
+ }
+ public ValueInfo[] getValueInfo() {
+ int n = GIntrospectionAPI.gi.g_enum_info_get_n_values(this);
+ ValueInfo[] ret= new ValueInfo[n];
+ for (int i = 0; i < n; i++)
+ ret[i] = GIntrospectionAPI.gi.g_enum_info_get_value(this, i);
+ return ret;
+ }
+}
Added: trunk/src/org/gnome/gir/repository/ErrorDomainInfo.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/ErrorDomainInfo.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,13 @@
+package org.gnome.gir.repository;
+
+import com.sun.jna.PointerType;
+
+public class ErrorDomainInfo extends PointerType {
+ String getQuark() {
+ return Repository.getNativeLibrary().g_error_domain_info_get_quark(this);
+ }
+
+ InterfaceInfo getInterfaceInfo() {
+ return Repository.getNativeLibrary().g_error_domain_info_get_codes(this);
+ }
+}
Added: trunk/src/org/gnome/gir/repository/FieldInfo.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/FieldInfo.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,22 @@
+
+package org.gnome.gir.repository;
+
+import com.sun.jna.PointerType;
+
+public class FieldInfo extends PointerType {
+ public FieldInfoFlags getFlags() {
+ return Repository.getNativeLibrary().g_field_info_get_flags(this);
+ }
+
+ public int getSize() {
+ return Repository.getNativeLibrary().g_field_info_get_size(this);
+ }
+
+ public int getOffset() {
+ return Repository.getNativeLibrary().g_field_info_get_offset(this);
+ }
+
+ public TypeInfo getType() {
+ return Repository.getNativeLibrary().g_field_info_get_type(this);
+ }
+}
\ No newline at end of file
Added: trunk/src/org/gnome/gir/repository/FieldInfoFlags.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/FieldInfoFlags.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,14 @@
+package org.gnome.gir.repository;
+
+import org.gnome.gir.gobject.NativeEnum;
+
+public enum FieldInfoFlags implements NativeEnum{
+ IS_READABLE,
+ IS_WRITABLE;
+
+ @Override
+ public int getNative() {
+ return 1 << ordinal();
+ }
+
+}
\ No newline at end of file
Added: trunk/src/org/gnome/gir/repository/FlagsInfo.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/FlagsInfo.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,15 @@
+package org.gnome.gir.repository;
+
+
+public class FlagsInfo extends RegisteredTypeInfo {
+ protected FlagsInfo(Initializer init) {
+ super(init);
+ }
+ public ValueInfo[] getValueInfo() {
+ int n = GIntrospectionAPI.gi.g_enum_info_get_n_values(this);
+ ValueInfo[] ret= new ValueInfo[n];
+ for (int i = 0; i < n; i++)
+ ret[i] = GIntrospectionAPI.gi.g_enum_info_get_value(this, i);
+ return ret;
+ }
+}
Added: trunk/src/org/gnome/gir/repository/FunctionInfo.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/FunctionInfo.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,16 @@
+
+package org.gnome.gir.repository;
+
+public class FunctionInfo extends CallableInfo {
+ protected FunctionInfo(Initializer init) {
+ super(init);
+ }
+
+ public String getSymbol() {
+ return Repository.getNativeLibrary().g_function_info_get_symbol(this);
+ }
+
+ public int getFlags() {
+ return Repository.getNativeLibrary().g_function_info_get_flags(this);
+ }
+}
\ No newline at end of file
Added: trunk/src/org/gnome/gir/repository/FunctionInfoFlags.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/FunctionInfoFlags.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,12 @@
+/**
+ *
+ */
+package org.gnome.gir.repository;
+
+public interface FunctionInfoFlags {
+ public static final int IS_METHOD = (1 << 0);
+ public static final int IS_CONSTRUCTOR = (1 << 1);
+ public static final int IS_SETTER = (1 << 2);
+ public static final int IS_GETTER = (1 << 3);
+ public static final int WRAPS_VFUNC = (1 << 4);
+}
\ No newline at end of file
Added: trunk/src/org/gnome/gir/repository/GIntrospectionAPI.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/GIntrospectionAPI.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,185 @@
+/**
+ *
+ */
+package org.gnome.gir.repository;
+
+import java.util.HashMap;
+
+import org.gnome.gir.gobject.GParamFlags;
+import org.gnome.gir.gobject.GType;
+import org.gnome.gir.gobject.GTypeMapper;
+import org.gnome.gir.gobject.ZeroTerminatedArray;
+import org.gnome.gir.gobject.annotation.RepositoryId;
+
+import com.sun.jna.Library;
+import com.sun.jna.Native;
+import com.sun.jna.NativeLong;
+import com.sun.jna.Pointer;
+import com.sun.jna.ptr.PointerByReference;
+
+interface GIntrospectionAPI extends Library {
+ public static final GIntrospectionAPI gi = (GIntrospectionAPI) Native.loadLibrary("girepository", GIntrospectionAPI.class, new HashMap<String, Object>() {
+ private static final long serialVersionUID = 1L;
+ {
+ put(Library.OPTION_TYPE_MAPPER, new GTypeMapper());
+ }
+ });
+
+ Repository g_irepository_get_default();
+ int g_irepository_get_n_infos(Repository repo, String namespace);
+ boolean g_irepository_is_registered (Repository repository, String namespace);
+ boolean g_irepository_require(Repository repo, String namespace, int flags, PointerByReference error);
+ BaseInfo g_irepository_find_by_name(Repository repo, String namespace, String name);
+ @RepositoryId(namespace="girepository", name="get_namespaces") ZeroTerminatedArray<String> g_irepository_get_namespaces(Repository repo);
+ BaseInfo g_irepository_get_info(Repository repo, String namespace, int idx);
+ String g_irepository_get_shared_library(Repository repository, String namespace);
+ String g_irepository_get_typelib_path(Repository repository, String namespace);
+
+ void g_base_info_ref(BaseInfo info);
+ void g_base_info_unref(BaseInfo info);
+ int g_base_info_get_type(Pointer info);
+ String g_base_info_get_name(Pointer info);
+ String g_base_info_get_namespace(Pointer info);
+ String g_base_info_get_annotation(BaseInfo info, String anno);
+ BaseInfo g_base_info_get_container(BaseInfo info);
+
+ String g_function_info_get_symbol(FunctionInfo info);
+ int g_function_info_get_flags(FunctionInfo info);
+ PropertyInfo g_function_info_get_property_info(FunctionInfo info);
+ VFuncInfo g_function_info_get_vfunc(FunctionInfo info);
+
+ boolean g_function_info_invoke(FunctionInfo info, Argument[] in, int n_in_args,
+ Argument[] out, int n_out_args, Argument retval,
+ PointerByReference error);
+
+ TypeInfo g_callable_info_get_return_type(CallableInfo info);
+ Transfer g_callable_info_get_caller_owns(CallableInfo info);
+ boolean g_callable_info_get_may_return_null(CallableInfo info);
+ int g_callable_info_get_n_args(CallableInfo info);
+ ArgInfo g_callable_info_get_arg(CallableInfo info, int n);
+
+ Direction g_arg_info_get_direction (ArgInfo info);
+ boolean g_arg_info_is_dipper (ArgInfo info);
+ boolean g_arg_info_is_return_value (ArgInfo info);
+ boolean g_arg_info_is_optional (ArgInfo info);
+ boolean g_arg_info_may_be_null (ArgInfo info);
+ Transfer g_arg_info_get_ownership_transfer (ArgInfo info);
+ TypeInfo g_arg_info_get_type (ArgInfo info);
+
+ boolean g_type_info_is_pointer (TypeInfo info);
+ TypeTag g_type_info_get_tag (TypeInfo info);
+ TypeInfo g_type_info_get_param_type (TypeInfo info,
+ int n);
+ BaseInfo g_type_info_get_interface (TypeInfo info);
+ int g_type_info_get_array_length (TypeInfo info);
+ boolean g_type_info_is_zero_terminated (TypeInfo info);
+
+ int g_type_info_get_n_error_domains (TypeInfo info);
+ ErrorDomainInfo g_type_info_get_error_domain (TypeInfo info,
+ int n);
+
+ String g_error_domain_info_get_quark (ErrorDomainInfo info);
+ InterfaceInfo g_error_domain_info_get_codes (ErrorDomainInfo info);
+
+ NativeLong g_value_info_get_value (ValueInfo info);
+
+ FieldInfoFlags g_field_info_get_flags (FieldInfo info);
+ int g_field_info_get_size (FieldInfo info);
+ int g_field_info_get_offset (FieldInfo info);
+ TypeInfo g_field_info_get_type (FieldInfo info);
+
+ int g_union_info_get_n_fields (UnionInfo info);
+ FieldInfo g_union_info_get_field (UnionInfo info,
+ int n);
+ int g_union_info_get_n_methods (UnionInfo info);
+ FunctionInfo g_union_info_get_method (UnionInfo info,
+ int n);
+ boolean g_union_info_is_discriminated (UnionInfo info);
+ int g_union_info_get_discriminator_offset (UnionInfo info);
+ TypeInfo g_union_info_get_discriminator_type (UnionInfo info);
+ ConstantInfo g_union_info_get_discriminator (UnionInfo info,
+ int n);
+
+ int g_struct_info_get_n_fields (StructInfo info);
+ FieldInfo g_struct_info_get_field (StructInfo info,
+ int n);
+ int g_struct_info_get_n_methods (StructInfo info);
+ FunctionInfo g_struct_info_get_method (StructInfo info,
+ int n);
+ FunctionInfo g_struct_info_find_method (StructInfo info,
+ String name);
+
+ String g_registered_type_info_get_type_name (RegisteredTypeInfo info);
+ String g_registered_type_info_get_type_init (RegisteredTypeInfo info);
+ GType g_registered_type_info_get_g_type (RegisteredTypeInfo info);
+
+ int g_enum_info_get_n_values (EnumInfo info);
+ ValueInfo g_enum_info_get_value (EnumInfo info,
+ int n);
+ int g_enum_info_get_n_values (FlagsInfo info);
+ ValueInfo g_enum_info_get_value (FlagsInfo info,
+ int n);
+
+ String g_object_info_get_type_name (ObjectInfo info);
+ String g_object_info_get_type_init (ObjectInfo info);
+ BaseInfo g_object_info_get_parent (ObjectInfo info);
+ int g_object_info_get_n_interfaces (ObjectInfo info);
+ InterfaceInfo g_object_info_get_interface (ObjectInfo info,
+ int n);
+ int g_object_info_get_n_fields (ObjectInfo info);
+ FieldInfo g_object_info_get_field (ObjectInfo info,
+ int n);
+ int g_object_info_get_n_properties (ObjectInfo info);
+ PropertyInfo g_object_info_get_property (ObjectInfo info,
+ int n);
+ int g_object_info_get_n_methods (ObjectInfo info);
+ FunctionInfo g_object_info_get_method (ObjectInfo info,
+ int n);
+ FunctionInfo g_object_info_find_method (ObjectInfo info,
+ String name);
+ int g_object_info_get_n_signals (ObjectInfo info);
+ SignalInfo g_object_info_get_signal (ObjectInfo info,
+ int n);
+ int g_object_info_get_n_vfuncs (ObjectInfo info);
+ VFuncInfo g_object_info_get_vfunc (ObjectInfo info,
+ int n);
+ int g_object_info_get_n_constants (ObjectInfo info);
+ ConstantInfo g_object_info_get_constant (ObjectInfo info,
+ int n);
+
+ int g_interface_info_get_n_prerequisites (InterfaceInfo info);
+ BaseInfo g_interface_info_get_prerequisite (InterfaceInfo info,
+ int n);
+ int g_interface_info_get_n_properties (InterfaceInfo info);
+ PropertyInfo g_interface_info_get_property (InterfaceInfo info,
+ int n);
+ int g_interface_info_get_n_methods (InterfaceInfo info);
+ FunctionInfo g_interface_info_get_method (InterfaceInfo info,
+ int n);
+ FunctionInfo g_interface_info_find_method (InterfaceInfo info,
+ String name);
+ int g_interface_info_get_n_signals (InterfaceInfo info);
+ SignalInfo g_interface_info_get_signal (InterfaceInfo info,
+ int n);
+ int g_interface_info_get_n_vfuncs (InterfaceInfo info);
+ VFuncInfo g_interface_info_get_vfunc (InterfaceInfo info,
+ int n);
+ int g_interface_info_get_n_constants (InterfaceInfo info);
+ ConstantInfo g_interface_info_get_constant (InterfaceInfo info,
+ int n);
+
+ GParamFlags g_property_info_get_flags (PropertyInfo info);
+ TypeInfo g_property_info_get_type (PropertyInfo info);
+
+ int g_signal_info_get_flags (SignalInfo info);
+ VFuncInfo g_signal_info_get_class_closure (SignalInfo info);
+ boolean g_signal_info_true_stops_emit (SignalInfo info);
+
+ VFuncInfoFlags g_vfunc_info_get_flags (VFuncInfo info);
+ int g_vfunc_info_get_offset (VFuncInfo info);
+ SignalInfo g_vfunc_info_get_signal (VFuncInfo info);
+
+ TypeInfo g_constant_info_get_type (ConstantInfo info);
+ int g_constant_info_get_value (ConstantInfo info,
+ Argument value);
+}
\ No newline at end of file
Added: trunk/src/org/gnome/gir/repository/InfoType.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/InfoType.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,28 @@
+/**
+ *
+ */
+package org.gnome.gir.repository;
+
+public enum InfoType
+{
+ INVALID,
+ FUNCTION,
+ CALLBACK,
+ STRUCT,
+ BOXED,
+ ENUM,
+ FLAGS,
+ OBJECT,
+ INTERFACE,
+ CONSTANT,
+ ERROR_DOMAIN,
+ UNION,
+ VALUE,
+ SIGNAL,
+ VFUNC,
+ PROPERTY,
+ FIELD,
+ ARG,
+ TYPE,
+ UNRESOLVED
+}
\ No newline at end of file
Added: trunk/src/org/gnome/gir/repository/InterfaceInfo.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/InterfaceInfo.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,56 @@
+package org.gnome.gir.repository;
+
+
+public class InterfaceInfo extends RegisteredTypeInfo {
+ protected InterfaceInfo(Initializer init) {
+ super(init);
+ }
+
+ public BaseInfo[] getPrerequisites() {
+ int n = GIntrospectionAPI.gi.g_interface_info_get_n_prerequisites(this);
+ BaseInfo[] ret= new BaseInfo[n];
+ for (int i = 0; i < n; i++)
+ ret[i] = GIntrospectionAPI.gi.g_interface_info_get_prerequisite(this, i);
+ return ret;
+ }
+
+ public PropertyInfo[] getProperties() {
+ int n = GIntrospectionAPI.gi.g_interface_info_get_n_properties(this);
+ PropertyInfo[] ret= new PropertyInfo[n];
+ for (int i = 0; i < n; i++)
+ ret[i] = GIntrospectionAPI.gi.g_interface_info_get_property(this, i);
+ return ret;
+ }
+
+ public FunctionInfo[] getMethods() {
+ int n = GIntrospectionAPI.gi.g_interface_info_get_n_methods(this);
+ FunctionInfo[] ret= new FunctionInfo[n];
+ for (int i = 0; i < n; i++)
+ ret[i] = GIntrospectionAPI.gi.g_interface_info_get_method(this, i);
+ return ret;
+ }
+
+ public SignalInfo[] getSignals() {
+ int n = GIntrospectionAPI.gi.g_interface_info_get_n_signals(this);
+ SignalInfo[] ret= new SignalInfo[n];
+ for (int i = 0; i < n; i++)
+ ret[i] = GIntrospectionAPI.gi.g_interface_info_get_signal(this, i);
+ return ret;
+ }
+
+ public VFuncInfo[] getVFuncs() {
+ int n = GIntrospectionAPI.gi.g_interface_info_get_n_vfuncs(this);
+ VFuncInfo[] ret= new VFuncInfo[n];
+ for (int i = 0; i < n; i++)
+ ret[i] = GIntrospectionAPI.gi.g_interface_info_get_vfunc(this, i);
+ return ret;
+ }
+
+ public ConstantInfo[] getContants() {
+ int n = GIntrospectionAPI.gi.g_interface_info_get_n_constants(this);
+ ConstantInfo[] ret= new ConstantInfo[n];
+ for (int i = 0; i < n; i++)
+ ret[i] = GIntrospectionAPI.gi.g_interface_info_get_constant(this, i);
+ return ret;
+ }
+}
Added: trunk/src/org/gnome/gir/repository/ObjectInfo.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/ObjectInfo.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,58 @@
+package org.gnome.gir.repository;
+
+
+public class ObjectInfo extends RegisteredTypeInfo {
+ protected ObjectInfo(Initializer init) {
+ super(init);
+ }
+
+ public String getTypeName() {
+ return GIntrospectionAPI.gi.g_object_info_get_type_name(this);
+ }
+
+ public BaseInfo getParent() {
+ return GIntrospectionAPI.gi.g_object_info_get_parent(this);
+ }
+
+ public boolean isAssignableFrom(ObjectInfo other) {
+ if (other == this)
+ return true;
+ BaseInfo otherBase = other;
+ while (true) {
+ if (otherBase == null)
+ return false;
+ if (otherBase.getNamespace().equals(getNamespace()) &&
+ otherBase.getName().equals(getName()))
+ return true;
+ otherBase = ((ObjectInfo)otherBase).getParent();
+ }
+ }
+
+ public FunctionInfo[] getMethods() {
+ int n = GIntrospectionAPI.gi.g_object_info_get_n_methods(this);
+ FunctionInfo[] ret= new FunctionInfo[n];
+ for (int i = 0; i < n; i++)
+ ret[i] = GIntrospectionAPI.gi.g_object_info_get_method(this, i);
+ return ret;
+ }
+
+ public SignalInfo[] getSignals() {
+ int n = GIntrospectionAPI.gi.g_object_info_get_n_signals(this);
+ SignalInfo[] ret= new SignalInfo[n];
+ for (int i = 0; i < n; i++)
+ ret[i] = GIntrospectionAPI.gi.g_object_info_get_signal(this, i);
+ return ret;
+ }
+
+ public InterfaceInfo[] getInterfaces() {
+ int n = GIntrospectionAPI.gi.g_object_info_get_n_interfaces(this);
+ InterfaceInfo[] ret= new InterfaceInfo[n];
+ for (int i = 0; i < n; i++)
+ ret[i] = GIntrospectionAPI.gi.g_object_info_get_interface(this, i);
+ return ret;
+ }
+
+ public String getTypeInit() {
+ return GIntrospectionAPI.gi.g_object_info_get_type_init(this);
+ }
+}
Added: trunk/src/org/gnome/gir/repository/PropertyInfo.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/PropertyInfo.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,10 @@
+package org.gnome.gir.repository;
+
+import com.sun.jna.Pointer;
+import com.sun.jna.PointerType;
+
+public class PropertyInfo extends PointerType {
+ protected PropertyInfo(Pointer pointer) {
+ super(pointer);
+ }
+}
Added: trunk/src/org/gnome/gir/repository/RegisteredTypeInfo.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/RegisteredTypeInfo.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,12 @@
+package org.gnome.gir.repository;
+
+
+public class RegisteredTypeInfo extends BaseInfo {
+ protected RegisteredTypeInfo(Initializer init) {
+ super(init);
+ }
+
+ public String getTypeInit() {
+ return GIntrospectionAPI.gi.g_registered_type_info_get_type_init(this);
+ }
+}
Added: trunk/src/org/gnome/gir/repository/Repository.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/Repository.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,62 @@
+package org.gnome.gir.repository;
+
+import java.util.List;
+
+import org.gnome.gir.gobject.GErrorException;
+import org.gnome.gir.gobject.GErrorStruct;
+import org.gnome.gir.gobject.GObjectGlobals;
+import org.gnome.gir.gobject.ZeroTerminatedArray;
+
+import com.sun.jna.PointerType;
+import com.sun.jna.ptr.PointerByReference;
+
+public class Repository extends PointerType {
+
+ public BaseInfo findByName(String namespace, String name) {
+ return GIntrospectionAPI.gi.g_irepository_find_by_name(this, namespace, name);
+ }
+
+ public void require(String namespace) throws GErrorException {
+ PointerByReference error = new PointerByReference(null);
+ if (!GIntrospectionAPI.gi.g_irepository_require(this, namespace, 0, error)) {
+ throw new GErrorException(new GErrorStruct(error.getValue()));
+ }
+ }
+
+ public BaseInfo[] getInfos(String namespace) {
+ int nInfos = GIntrospectionAPI.gi.g_irepository_get_n_infos(this, namespace);
+ BaseInfo[] ret = new BaseInfo[nInfos];
+ for (int i = 0; i < nInfos; i++) {
+ ret[i] = GIntrospectionAPI.gi.g_irepository_get_info(this, namespace, i);
+ }
+ return ret;
+ }
+
+ public String getSharedLibrary(String namespace) {
+ return GIntrospectionAPI.gi.g_irepository_get_shared_library(this, namespace);
+ }
+
+ public String getTypelibPath(String namespace) {
+ return GIntrospectionAPI.gi.g_irepository_get_typelib_path(this, namespace);
+ }
+
+ public List<String> getNamespaces() {
+ ZeroTerminatedArray<String> z = GIntrospectionAPI.gi.g_irepository_get_namespaces(this);
+ List<String> ret = z.convert(String.class);
+ z.dispose(Transfer.EVERYTHING);
+ return ret;
+ }
+
+ public boolean isRegistered(String targetNamespace) {
+ return GIntrospectionAPI.gi.g_irepository_is_registered(this, targetNamespace);
+ }
+
+ static GIntrospectionAPI getNativeLibrary() {
+ return GIntrospectionAPI.gi;
+ }
+
+ public static synchronized Repository getDefault() {
+ GObjectGlobals.init();
+ return getNativeLibrary().g_irepository_get_default();
+ }
+}
Added: trunk/src/org/gnome/gir/repository/SignalInfo.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/SignalInfo.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,19 @@
+package org.gnome.gir.repository;
+
+
+public class SignalInfo extends CallableInfo {
+ protected SignalInfo(Initializer init) {
+ super(init);
+ }
+ public int getFlags() {
+ return GIntrospectionAPI.gi.g_signal_info_get_flags(this);
+ }
+
+ public VFuncInfo getClassClosure() {
+ return GIntrospectionAPI.gi.g_signal_info_get_class_closure(this);
+ }
+
+ public boolean trueStopsEmit() {
+ return GIntrospectionAPI.gi.g_signal_info_true_stops_emit(this);
+ }
+}
Added: trunk/src/org/gnome/gir/repository/StructInfo.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/StructInfo.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,23 @@
+package org.gnome.gir.repository;
+
+
+public class StructInfo extends RegisteredTypeInfo {
+ protected StructInfo(Initializer init) {
+ super(init);
+ }
+ public FieldInfo[] getFields() {
+ int n = GIntrospectionAPI.gi.g_struct_info_get_n_fields(this);
+ FieldInfo[] ret = new FieldInfo[n];
+ for (int i = 0; i < n; i++)
+ ret[i] = GIntrospectionAPI.gi.g_struct_info_get_field(this, i);
+ return ret;
+ }
+
+ public FunctionInfo[] getMethods() {
+ int n = GIntrospectionAPI.gi.g_struct_info_get_n_methods(this);
+ FunctionInfo[] ret = new FunctionInfo[n];
+ for (int i = 0; i < n; i++)
+ ret[i] = GIntrospectionAPI.gi.g_struct_info_get_method(this, i);
+ return ret;
+ }
+}
Added: trunk/src/org/gnome/gir/repository/Transfer.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/Transfer.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,10 @@
+/**
+ *
+ */
+package org.gnome.gir.repository;
+
+public enum Transfer {
+ NOTHING,
+ CONTAINER,
+ EVERYTHING,
+}
\ No newline at end of file
Added: trunk/src/org/gnome/gir/repository/TypeInfo.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/TypeInfo.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,31 @@
+
+package org.gnome.gir.repository;
+
+import com.sun.jna.PointerType;
+
+public class TypeInfo extends PointerType {
+ public boolean isPointer() {
+ return Repository.getNativeLibrary().g_type_info_is_pointer(this);
+ }
+ public TypeTag getTag() {
+ return Repository.getNativeLibrary().g_type_info_get_tag(this);
+ }
+ public TypeInfo getParamType(int n) {
+ return Repository.getNativeLibrary().g_type_info_get_param_type(this, n);
+ }
+ public BaseInfo getInterface() {
+ return Repository.getNativeLibrary().g_type_info_get_interface(this);
+ }
+ public int getArrayLength() {
+ return Repository.getNativeLibrary().g_type_info_get_array_length(this);
+ }
+ public boolean isZeroTerminated() {
+ return Repository.getNativeLibrary().g_type_info_is_zero_terminated(this);
+ }
+ public int getNErrorDomains() {
+ return Repository.getNativeLibrary().g_type_info_get_n_error_domains(this);
+ }
+ public ErrorDomainInfo getErrorDomainInfo(int n) {
+ return Repository.getNativeLibrary().g_type_info_get_error_domain(this, n);
+ }
+}
\ No newline at end of file
Added: trunk/src/org/gnome/gir/repository/TypeTag.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/TypeTag.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,33 @@
+/**
+ *
+ */
+package org.gnome.gir.repository;
+
+public enum TypeTag {
+ VOID,
+ BOOLEAN,
+ INT8,
+ UINT8,
+ INT16,
+ UINT16,
+ INT32,
+ UINT32,
+ INT64,
+ UINT64,
+ INT,
+ UINT,
+ LONG,
+ ULONG,
+ SSIZE,
+ SIZE,
+ FLOAT,
+ DOUBLE,
+ UTF8,
+ FILENAME,
+ ARRAY,
+ INTERFACE,
+ GLIST,
+ GSLIST,
+ GHASH,
+ ERROR,
+}
\ No newline at end of file
Added: trunk/src/org/gnome/gir/repository/UnionInfo.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/UnionInfo.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,7 @@
+package org.gnome.gir.repository;
+
+import com.sun.jna.PointerType;
+
+public class UnionInfo extends PointerType {
+
+}
Added: trunk/src/org/gnome/gir/repository/UnresolvedException.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/UnresolvedException.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,9 @@
+package org.gnome.gir.repository;
+
+public class UnresolvedException extends RuntimeException {
+ private static final long serialVersionUID = 1L;
+
+ public UnresolvedException(String namespace, String name) {
+ super("ns=" + namespace + ",name=" + name + " is not loaded");
+ }
+}
Added: trunk/src/org/gnome/gir/repository/VFuncInfo.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/VFuncInfo.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,7 @@
+package org.gnome.gir.repository;
+
+import com.sun.jna.PointerType;
+
+public class VFuncInfo extends PointerType {
+
+}
Added: trunk/src/org/gnome/gir/repository/VFuncInfoFlags.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/VFuncInfoFlags.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,17 @@
+/**
+ *
+ */
+package org.gnome.gir.repository;
+
+import org.gnome.gir.gobject.NativeEnum;
+
+public enum VFuncInfoFlags implements NativeEnum {
+ MUST_CHAIN_UP,
+ MUST_OVERRIDE,
+ MUST_NOT_OVERRIDE;
+
+ @Override
+ public int getNative() {
+ return 1 << ordinal();
+ }
+}
\ No newline at end of file
Added: trunk/src/org/gnome/gir/repository/ValueInfo.java
==============================================================================
--- (empty file)
+++ trunk/src/org/gnome/gir/repository/ValueInfo.java Sat Aug 30 22:06:49 2008
@@ -0,0 +1,11 @@
+package org.gnome.gir.repository;
+
+
+public class ValueInfo extends BaseInfo {
+ protected ValueInfo(Initializer init) {
+ super(init);
+ }
+ public long getValue() {
+ return Repository.getNativeLibrary().g_value_info_get_value(this).longValue();
+ }
+}
Added: trunk/waf
==============================================================================
Binary files (empty file) and trunk/waf Sat Aug 30 22:06:49 2008 differ
Added: trunk/wscript
==============================================================================
--- (empty file)
+++ trunk/wscript Sat Aug 30 22:06:49 2008
@@ -0,0 +1,87 @@
+#! /usr/bin/env python
+# -*- coding: utf-8; indent-tabs-mode: nil; python-indent: 2 -*-
+
+import os
+
+import Task,TaskGen,Node
+from TaskGen import *
+
+# the following two variables are used by the target "waf dist"
+VERSION='0.1.0'
+APPNAME='jgir'
+
+# these variables are mandatory ('/' are converted automatically)
+srcdir = '.'
+blddir = 'build'
+
+ taskgen
+def add_gir_file(self, filename):
+ if not hasattr(self, 'gir_lst'): self.gir_lst = []
+ self.meths.add('process_gir')
+ self.gir_lst.append([filename])
+
+ taskgen
+ before('apply_core')
+def process_gir(self):
+ for i in getattr(self, 'gir_lst', []):
+ env = self.env.copy()
+ node = self.path.find_resource(i[0])
+
+ if not node:
+ raise Utils.WafError('file not found on gir obj '+i[0])
+
+ tgt_name = os.path.splitext(node.name)[0] + '-metadata.c'
+ tgt_node = self.path.find_or_declare(tgt_name)
+ self.allnodes.append(tgt_node)
+ task = self.create_task('gir_compiler', env)
+ task.set_inputs(node)
+ task.set_outputs(tgt_node)
+
+Task.simple_task_type('gir_scanner', 'g-ir-scanner -v ${INCLUDES} --namespace=${NAMESPACE} --library=${LIB} ${SRC} --output ${TGT}', color='BLUE')
+Task.simple_task_type('gir_compiler', 'g-ir-compiler ${SRC} -o ${TGT}', color='BLUE')
+Task.simple_task_type('jgir_compile', 'jgir-compile ${SHLIB} ${NAMESPACE} ${TGT}', color='BLUE')
+
+def set_options(opt):
+ pass
+
+def configure(conf):
+ conf.check_tool('gcc gnome java misc')
+ conf.check_pkg('gobject-introspection-1.0', destvar='GI', mandatory=True)
+ conf.require_java_class('java.lang.Object')
+ asm_deps = ['asm', 'asm-util', 'asm-tree', 'asm-commons', 'asm-analysis']
+ for dep in asm_deps:
+ conf.require_jpackage_module('objectweb-asm/%s' % (dep,))
+ conf.require_jpackage_module('jna')
+ conf.require_jpackage_module('junit')
+ conf.require_jpackage_module('gnu.getopt')
+ print "Using CLASSPATH: %r" % (conf.env['CLASSPATH'],)
+
+def build(bld):
+ jsrc = bld.new_task_gen('java')
+ jsrc.install_path = '${PREFIX}/share/java'
+ jsrc.source = '.*java$'
+ jsrc.jarname = 'jgir.jar'
+ jsrc.source_root = 'src'
+
+ compscript = bld.new_task_gen('subst')
+ compscript.install_path = "${PREFIX}/bin"
+ compscript.chmod = 0755
+ compscript.source = 'src/jgir-compile-all.in'
+ compscript.target = 'jgir-compile-all'
+ compscript.dict = {'CLASSPATH': bld.env['CLASSPATH'] + ':' + bld.env['PREFIX'] + '/share/java/jgir.jar'}
+
+ #libinvoke = bld.new_task_gen('cc', 'shlib')
+ #libinvoke.packages = ['gobject-introspection-1.0']
+ #libinvoke.source = ['tests/invoke/testfns.c']
+ #libinvoke.target = 'testfns'
+ #libinvoke.add_gir_file('tests/invoke/testfns.gir')
+ #libinvoke.uselib = 'GI'
+
+ #testinvoke = bld.new_task_gen('java')
+ #testinvoke.source = '.*java$'
+ #testinvoke.source_root = 'tests/invoke'
+ #testinvoke.jarname = 'testinvoke.jar'
+ #testinvoke.unit_test = 1
+
+def shutdown():
+ pass
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]