diff options
author | U-TTG\pego <pego@NL2W7L-101492.ttg.global> | 2014-07-14 16:53:47 +0200 |
---|---|---|
committer | U-TTG\pego <pego@NL2W7L-101492.ttg.global> | 2014-07-14 16:53:47 +0200 |
commit | 0263c6b40d4cc843efa34baf05d4d7d77b8ce53e (patch) | |
tree | d642bfe8f614e8158d167de11f10697505947678 /src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java | |
parent | 83af236086378785cbec01e1d70863a5d2382fbc (diff) | |
download | poi-service-0263c6b40d4cc843efa34baf05d4d7d77b8ce53e.tar.gz |
Initial version of TrafficIncidentsService API, documentation and PoC
Diffstat (limited to 'src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java')
130 files changed, 19320 insertions, 0 deletions
diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/AUTHORS b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/AUTHORS new file mode 100755 index 0000000..9b7699e --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/AUTHORS @@ -0,0 +1,37 @@ +The D-Bus Java implementation was written by: + +Matthew Johnson <dbus -at matthew -dot- ath -dot- cx> + +Bug fixes/reports and other suggestions from: + +Remi Emonet <remi.emonet -at- inrialpes -dot- fr> +Simon McVittie <simon -dot- mcvittie -at- collabora -dot- co -dot- uk> +Dick Hollenbeck <dick -at- softplc -dot- com> +Joshua Nichols <nichoj -at- gentoo -dot- org> +Ralf Kistner <ralf.kistner -at- gmail -dot- com> +Henrik Petander <henrik -dot- petander -at- iki -dot- fi> +Luigi Paioro <luigi -at- lambrate -dot- it> +Roberto Francisco Arroyo Moreno <robfram -at- ugr -dot- es> +Steve Crane <Steve -dot Crane -at- rococosoft -dot- com> +Philippe Marschall <philippe -dot- marschall -at- gmail -dot- com> +Daniel Machado <cdanielmachado -at- gmail -dot- com> +Anibal Sanchez <anibal -dot- sanchez -at- sunya -dot- com -dot- ar> +Jan Kümmel <freedesktop -at- snorc -dot- org> +Johannes Felten <johannesfelten -at- googlemail -dot- com> +Tom Walsh <walshtc -at- gmail -dot- com> +Ed Wei <Edward.Wei.03 -at- alum -dot- dartmouth -dot- org> +Sveinung Kvilhaugsvik <sveinung84 -at- users -dot- sourceforge -dot- net> +Hugues Moreau <hmoreau -at- gmail -dot- com> +Viktar Vauchkevich <vctr -at- yandex -dot- ru> +Serkan Kaba <serkan_kaba -at- yahoo -dot- com> +Adam Bennett <cruxic -at- gmail -dot- com> +Frank Benoit <benoit -at- tionex -dot- de> +Gunnar Aastrand Grimnes <gunnar -dot- grimnes -at- dfki -dot- de> + +The included Viewer application was originally written by: + +Peter Cox <petercox -at- gawab -dot- com> + +with patches from: + +Zsombor Gegesy <gzsombor -at- gmail -dot- com> diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/COPYING b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/COPYING new file mode 100755 index 0000000..d651143 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/COPYING @@ -0,0 +1,680 @@ +The D-Bus Java implementation is licensed to you under your choice of the +Academic Free License version 2.1, or the GNU Lesser/Library General Public License +version 2. Both licenses are included here. Each source code file is marked +with the proper copyright information. + +The Academic Free License +v. 2.1 + +This Academic Free License (the "License") applies to any original work of +authorship (the "Original Work") whose owner (the "Licensor") has placed the +following notice immediately following the copyright notice for the Original +Work: + +Licensed under the Academic Free License version 2.1 + +1) Grant of Copyright License. Licensor hereby grants You a world-wide, +royalty-free, non-exclusive, perpetual, sublicenseable license to do the +following: + +a) to reproduce the Original Work in copies; + +b) to prepare derivative works ("Derivative Works") based upon the Original +Work; + +c) to distribute copies of the Original Work and Derivative Works to the +public; + +d) to perform the Original Work publicly; and + +e) to display the Original Work publicly. + +2) Grant of Patent License. Licensor hereby grants You a world-wide, +royalty-free, non-exclusive, perpetual, sublicenseable license, under patent +claims owned or controlled by the Licensor that are embodied in the Original +Work as furnished by the Licensor, to make, use, sell and offer for sale the +Original Work and Derivative Works. + +3) Grant of Source Code License. The term "Source Code" means the preferred +form of the Original Work for making modifications to it and all available +documentation describing how to modify the Original Work. Licensor hereby +agrees to provide a machine-readable copy of the Source Code of the Original +Work along with each copy of the Original Work that Licensor distributes. +Licensor reserves the right to satisfy this obligation by placing a +machine-readable copy of the Source Code in an information repository +reasonably calculated to permit inexpensive and convenient access by You for as +long as Licensor continues to distribute the Original Work, and by publishing +the address of that information repository in a notice immediately following +the copyright notice that applies to the Original Work. + +4) Exclusions From License Grant. Neither the names of Licensor, nor the names +of any contributors to the Original Work, nor any of their trademarks or +service marks, may be used to endorse or promote products derived from this +Original Work without express prior written permission of the Licensor. Nothing +in this License shall be deemed to grant any rights to trademarks, copyrights, +patents, trade secrets or any other intellectual property of Licensor except as +expressly stated herein. No patent license is granted to make, use, sell or +offer to sell embodiments of any patent claims other than the licensed claims +defined in Section 2. No right is granted to the trademarks of Licensor even if +such marks are included in the Original Work. Nothing in this License shall be +interpreted to prohibit Licensor from licensing under different terms from this +License any Original Work that Licensor otherwise would have a right to +license. + +5) This section intentionally omitted. + +6) Attribution Rights. You must retain, in the Source Code of any Derivative +Works that You create, all copyright, patent or trademark notices from the +Source Code of the Original Work, as well as any notices of licensing and any +descriptive text identified therein as an "Attribution Notice." You must cause +the Source Code for any Derivative Works that You create to carry a prominent +Attribution Notice reasonably calculated to inform recipients that You have +modified the Original Work. + +7) Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that +the copyright in and to the Original Work and the patent rights granted herein +by Licensor are owned by the Licensor or are sublicensed to You under the terms +of this License with the permission of the contributor(s) of those copyrights +and patent rights. Except as expressly stated in the immediately proceeding +sentence, the Original Work is provided under this License on an "AS IS" BASIS +and WITHOUT WARRANTY, either express or implied, including, without limitation, +the warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. +This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No +license to Original Work is granted hereunder except under this disclaimer. + +8) Limitation of Liability. Under no circumstances and under no legal theory, +whether in tort (including negligence), contract, or otherwise, shall the +Licensor be liable to any person for any direct, indirect, special, incidental, +or consequential damages of any character arising as a result of this License +or the use of the Original Work including, without limitation, damages for loss +of goodwill, work stoppage, computer failure or malfunction, or any and all +other commercial damages or losses. This limitation of liability shall not +apply to liability for death or personal injury resulting from Licensor's +negligence to the extent applicable law prohibits such limitation. Some +jurisdictions do not allow the exclusion or limitation of incidental or +consequential damages, so this exclusion and limitation may not apply to You. + +9) Acceptance and Termination. If You distribute copies of the Original Work or +a Derivative Work, You must make a reasonable effort under the circumstances to +obtain the express assent of recipients to the terms of this License. Nothing +else but this License (or another written agreement between Licensor and You) +grants You permission to create Derivative Works based upon the Original Work +or to exercise any of the rights granted in Section 1 herein, and any attempt +to do so except under the terms of this License (or another written agreement +between Licensor and You) is expressly prohibited by U.S. copyright law, the +equivalent laws of other countries, and by international treaty. Therefore, by +exercising any of the rights granted to You in Section 1 herein, You indicate +Your acceptance of this License and all of its terms and conditions. + +10) Termination for Patent Action. This License shall terminate automatically +and You may no longer exercise any of the rights granted to You by this License +as of the date You commence an action, including a cross-claim or counterclaim, +against Licensor or any licensee alleging that the Original Work infringes a +patent. This termination provision shall not apply for an action alleging +patent infringement by combinations of the Original Work with other software or +hardware. + +11) Jurisdiction, Venue and Governing Law. Any action or suit relating to this +License may be brought only in the courts of a jurisdiction wherein the +Licensor resides or in which Licensor conducts its primary business, and under +the laws of that jurisdiction excluding its conflict-of-law provisions. The +application of the United Nations Convention on Contracts for the International +Sale of Goods is expressly excluded. Any use of the Original Work outside the +scope of this License or after its termination shall be subject to the +requirements and penalties of the U.S. Copyright Act, 17 U.S.C. § 101 et seq., +the equivalent laws of other countries, and international treaty. This section +shall survive the termination of this License. + +12) Attorneys Fees. In any action to enforce the terms of this License or +seeking damages relating thereto, the prevailing party shall be entitled to +recover its costs and expenses, including, without limitation, reasonable +attorneys' fees and costs incurred in connection with such action, including +any appeal of such action. This section shall survive the termination of this +License. + +13) Miscellaneous. This License represents the complete agreement concerning +the subject matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent necessary to +make it enforceable. + +14) Definition of "You" in This License. "You" throughout this License, whether +in upper or lower case, means an individual or a legal entity exercising rights +under, and complying with all of the terms of, this License. For legal +entities, "You" includes any entity that controls, is controlled by, or is +under common control with you. For purposes of this definition, "control" means +(i) the power, direct or indirect, to cause the direction or management of such +entity, whether by contract or otherwise, or (ii) ownership of fifty percent +(50%) or more of the outstanding shares, or (iii) beneficial ownership of such +entity. + +15) Right to Use. You may use the Original Work in all ways not otherwise +restricted or conditioned by this License or by law, and Licensor promises not +to interfere with or be responsible for such uses by You. + +This license is Copyright (C) 2003-2004 Lawrence E. Rosen. All rights reserved. +Permission is hereby granted to copy and distribute this license without +modification. This license may not be modified without the express written +permission of its copyright owner. + + +-- +END OF ACADEMIC FREE LICENSE. The following is intended to describe the +essential differences between the Academic Free License (AFL) version 1.0 and +other open source licenses: + +The Academic Free License is similar to the BSD, MIT, UoI/NCSA and Apache +licenses in many respects but it is intended to solve a few problems with those +licenses. + +* The AFL is written so as to make it clear what software is being +licensed (by the inclusion of a statement following the copyright notice in the +software). This way, the license functions better than a template license. The +BSD, MIT and UoI/NCSA licenses apply to unidentified software. + +* The AFL contains a complete copyright grant to the software. The BSD +and Apache licenses are vague and incomplete in that respect. + +* The AFL contains a complete patent grant to the software. The BSD, MIT, +UoI/NCSA and Apache licenses rely on an implied patent license and contain no +explicit patent grant. + +* The AFL makes it clear that no trademark rights are granted to the +licensor's trademarks. The Apache license contains such a provision, but the +BSD, MIT and UoI/NCSA licenses do not. + +* The AFL includes the warranty by the licensor that it either owns the +copyright or that it is distributing the software under a license. None of the +other licenses contain that warranty. All other warranties are disclaimed, as +is the case for the other licenses. + +* The AFL is itself copyrighted (with the right granted to copy and distribute +without modification). This ensures that the owner of the copyright to the +license will control changes. The Apache license contains a copyright notice, +but the BSD, MIT and UoI/NCSA licenses do not. + +-- +START OF GNU LIBRARY GENERAL PUBLIC LICENSE +-- + + GNU LIBRARY GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1991 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 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! diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/CreateInterface.bat b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/CreateInterface.bat new file mode 100755 index 0000000..8275e45 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/CreateInterface.bat @@ -0,0 +1,10 @@ +@echo off
+setlocal
+set debug=%DEBUG%
+set version=%VERSION%
+set jarpath=%WINJARPATH%
+set javaunixjarpath=%WINUNIXJARPATH%
+
+java -DVersion=%version% -cp %javaunixjarpath%debug-%debug%.jar;%javaunixjarpath%hexdump.jar;%jarpath%dbus.jar;%jarpath%dbus-bin.jar org.freedesktop.dbus.bin.CreateInterface %*
+
+endlocal diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/CreateInterface.sgml b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/CreateInterface.sgml new file mode 100755 index 0000000..44ad676 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/CreateInterface.sgml @@ -0,0 +1,182 @@ +<!doctype refentry PUBLIC "-//OASIS//DTD DocBook V4.1//EN" [ + +<!-- Process this file with docbook-to-man to generate an nroff manual + page: `docbook-to-man manpage.sgml > manpage.1'. You may view + the manual page with: `docbook-to-man manpage.sgml | nroff -man | + less'. A typical entry in a Makefile or Makefile.am is: + +manpage.1: manpage.sgml + docbook-to-man $< > $@ + + + The docbook-to-man binary is found in the docbook-to-man package. + Please remember that if you create the nroff version in one of the + debian/rules file targets (such as build), you will need to include + docbook-to-man in your Build-Depends control field. + + --> + + <!-- Fill in your name for FIRSTNAME and SURNAME. --> + <!ENTITY dhfirstname "<firstname>Matthew</firstname>"> + <!ENTITY dhsurname "<surname>Johnson</surname>"> + <!-- Please adjust the date whenever revising the manpage. --> + <!ENTITY dhdate "<date>January 10, 2006</date>"> + <!-- SECTION should be 1-8, maybe w/ subsection other parameters are + allowed: see man(7), man(1). --> + <!ENTITY dhsection "<manvolnum>1</manvolnum>"> + <!ENTITY dhemail "<email><debian@matthew.ath.cx></email>"> + <!ENTITY dhusername "Matthew Johnson"> + <!ENTITY dhucpackage "<refentrytitle>DBUS-JAVA</refentrytitle>"> + <!ENTITY dhpackage "CreateInterface"> + + <!ENTITY debian "<productname>Debian</productname>"> + <!ENTITY gnu "<acronym>GNU</acronym>"> + <!ENTITY gpl "&gnu; <acronym>GPL</acronym>"> +]> + +<refentry> + <refentryinfo> + <address> + &dhemail; + </address> + <author> + &dhfirstname; + &dhsurname; + </author> + <copyright> + <year>2006</year> + <holder>&dhusername;</holder> + </copyright> + &dhdate; + </refentryinfo> + <refmeta> + &dhucpackage; + + &dhsection; + </refmeta> + <refnamediv> + <refname>&dhpackage;</refname> + + <refpurpose>Create a Java Interface definition from DBus + introspection data.</refpurpose> + </refnamediv> + <refsynopsisdiv> + <cmdsynopsis> + <command>&dhpackage;</command> + <arg><option><replaceable>introspection.xml</replaceable></option></arg> + <arg><option><replaceable>busname</replaceable> <replaceable>objectname</replaceable></option></arg> + <arg><option>-y </option></arg> + <arg><option>--system </option></arg> + <arg><option>-s </option></arg> + <arg><option>--session </option></arg> + <arg><option>-f </option></arg> + <arg><option>--create-files </option></arg> + <arg><option>-h </option></arg> + <arg><option>--help</option></arg> + + </cmdsynopsis> + </refsynopsisdiv> + <refsect1> + <title>DESCRIPTION</title> + + <para>This manual page documents briefly the + <command>&dhpackage;</command> command.</para> + + <para><command>&dhpackage;</command> takes DBus introspection data, + either as an XML file or by calling the Introspect() method on the Bus, + and converts it into a Java interface file. This is either written + to the standard output or to the correct file structure for the + Java packages. + </para> + + + </refsect1> + <refsect1> + <title>OPTIONS</title> + + <para>These programs follow the usual &gnu; command line syntax, + with long options starting with two dashes (`-'). A summary of + options is included below. + </para> + + <variablelist> + <varlistentry> + <term><option>-s</option> + <option>--session</option> + </term> + <listitem> + <para>Use the Session Bus to query introspection data + (This is the Default)</para> + </listitem> + </varlistentry> + <varlistentry> + <term><option>-y</option> + <option>--system</option> + </term> + <listitem> + <para>Use the System Bus to query introspection data + (Default is Session)</para> + </listitem> + </varlistentry> + <varlistentry> + <term><option>-f</option> + <option>--create-files</option> + </term> + <listitem> + <para>Writes introspection data into files rather than to stdout. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term> + <option>--no-ignore-builtin</option> + </term> + <listitem> + <para>Do not ignore builtin (org.freedesktop.DBus) + interfaces while parsing introspection data</para> + </listitem> + </varlistentry> + <varlistentry> + <term><option>-h</option> + <option>--help</option> + </term> + <listitem> + <para>Show summary of options.</para> + </listitem> + </varlistentry> + </variablelist> + </refsect1> + <refsect1> + <title>AUTHOR</title> + + <para>This manual page was written by &dhusername; &dhemail;. Permission is + granted to copy, distribute and/or modify this document under + the terms of the &gnu; Lesser General Public License, Version 2 as + published by the Free Software Foundation. + </para> + <para> + On Debian systems, the complete text of the GNU Lesser General Public + License can be found in /usr/share/common-licenses/LGPL-2. + </para> + + </refsect1> +</refentry> + +<!-- Keep this comment at the end of the file +Local variables: +mode: sgml +sgml-omittag:t +sgml-shorttag:t +sgml-minimize-attributes:nil +sgml-always-quote-attributes:t +sgml-indent-step:2 +sgml-indent-data:t +sgml-parent-document:nil +sgml-default-dtd-file:nil +sgml-exposed-tags:nil +sgml-local-catalogs:nil +sgml-local-ecat-files:nil +End: +--> + + diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/CreateInterface.sh b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/CreateInterface.sh new file mode 100755 index 0000000..863d1a3 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/CreateInterface.sh @@ -0,0 +1,10 @@ +#!/bin/sh -- + +JAVA=%JAVA% +DEBUG=%DEBUG% +VERSION=%VERSION% +JARPATH=%JARPATH% +JAVAUNIXLIBPATH=%JAVAUNIXLIBPATH% +JAVAUNIXJARPATH=%JAVAUNIXJARPATH% + +exec $JAVA -DPid=$$ -DVersion=$VERSION -Djava.library.path=$JAVAUNIXLIBPATH -cp $JAVAUNIXJARPATH/unix.jar:$JAVAUNIXJARPATH/debug-$DEBUG.jar:$JAVAUNIXJARPATH/hexdump.jar:$JARPATH/dbus.jar:$JARPATH/dbus-bin.jar org.freedesktop.dbus.bin.CreateInterface "$@" diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/DBusCall.bat b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/DBusCall.bat new file mode 100755 index 0000000..2489048 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/DBusCall.bat @@ -0,0 +1,10 @@ +@echo off
+setlocal
+set debug=%DEBUG%
+set version=%VERSION%
+set jarpath=%WINJARPATH%
+set javaunixjarpath=%WINUNIXJARPATH%
+
+java -DVersion=%version% -cp %javaunixjarpath%debug-%debug%.jar;%javaunixjarpath%hexdump.jar;%jarpath%dbus.jar;%jarpath%dbus-bin.jar org.freedesktop.dbus.bin.Caller %*
+
+endlocal diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/DBusCall.sgml b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/DBusCall.sgml new file mode 100755 index 0000000..9efd4f0 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/DBusCall.sgml @@ -0,0 +1,126 @@ +<!doctype refentry PUBLIC "-//OASIS//DTD DocBook V4.1//EN" [ + +<!-- Process this file with docbook-to-man to generate an nroff manual + page: `docbook-to-man manpage.sgml > manpage.1'. You may view + the manual page with: `docbook-to-man manpage.sgml | nroff -man | + less'. A typical entry in a Makefile or Makefile.am is: + +manpage.1: manpage.sgml + docbook-to-man $< > $@ + + + The docbook-to-man binary is found in the docbook-to-man package. + Please remember that if you create the nroff version in one of the + debian/rules file targets (such as build), you will need to include + docbook-to-man in your Build-Depends control field. + + --> + + <!-- Fill in your name for FIRSTNAME and SURNAME. --> + <!ENTITY dhfirstname "<firstname>Matthew</firstname>"> + <!ENTITY dhsurname "<surname>Johnson</surname>"> + <!-- Please adjust the date whenever revising the manpage. --> + <!ENTITY dhdate "<date>January 10, 2006</date>"> + <!-- SECTION should be 1-8, maybe w/ subsection other parameters are + allowed: see man(7), man(1). --> + <!ENTITY dhsection "<manvolnum>1</manvolnum>"> + <!ENTITY dhemail "<email><debian@matthew.ath.cx></email>"> + <!ENTITY dhusername "Matthew Johnson"> + <!ENTITY dhucpackage "<refentrytitle>DBUS-JAVA</refentrytitle>"> + <!ENTITY dhpackage "DBusCall"> + + <!ENTITY debian "<productname>Debian</productname>"> + <!ENTITY gnu "<acronym>GNU</acronym>"> + <!ENTITY gpl "&gnu; <acronym>GPL</acronym>"> +]> + +<refentry> + <refentryinfo> + <address> + &dhemail; + </address> + <author> + &dhfirstname; + &dhsurname; + </author> + <copyright> + <year>2007</year> + <holder>&dhusername;</holder> + </copyright> + &dhdate; + </refentryinfo> + <refmeta> + &dhucpackage; + + &dhsection; + </refmeta> + <refnamediv> + <refname>&dhpackage;</refname> + + <refpurpose>Calls methods on DBus</refpurpose> + </refnamediv> + <refsynopsisdiv> + <cmdsynopsis> + <command>&dhpackage;</command> + <arg><replaceable>dest</replaceable></arg> + <arg><replaceable>path</replaceable></arg> + <arg><replaceable>interface</replaceable></arg> + <arg><replaceable>method</replaceable></arg> + <arg><option><replaceable>sig</replaceable></option></arg> + <arg><option><replaceable>args</replaceable></option></arg> + </cmdsynopsis> + </refsynopsisdiv> + <refsect1> + <title>DESCRIPTION</title> + + <para>This manual page documents briefly the + <command>&dhpackage;</command> command.</para> + + <para><command>&dhpackage;</command> calls arbitrary methods on the bus + </para> + + + </refsect1> + <refsect1> + <title>OPTIONS</title> + + <para>These programs follow the usual &gnu; command line syntax, + with long options starting with two dashes (`-'). A summary of + options is included below. + </para> + + </refsect1> + <refsect1> + <title>AUTHOR</title> + + <para>This manual page was written by &dhusername; &dhemail;. Permission is + granted to copy, distribute and/or modify this document under + the terms of the &gnu; Lesser General Public License, Version 2 as + published by the Free Software Foundation. + </para> + <para> + On Debian systems, the complete text of the GNU Lesser General Public + License can be found in /usr/share/common-licenses/LGPL-2. + </para> + + </refsect1> +</refentry> + +<!-- Keep this comment at the end of the file +Local variables: +mode: sgml +sgml-omittag:t +sgml-shorttag:t +sgml-minimize-attributes:nil +sgml-always-quote-attributes:t +sgml-indent-step:2 +sgml-indent-data:t +sgml-parent-document:nil +sgml-default-dtd-file:nil +sgml-exposed-tags:nil +sgml-local-catalogs:nil +sgml-local-ecat-files:nil +End: +--> + + diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/DBusCall.sh b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/DBusCall.sh new file mode 100755 index 0000000..23f2fe5 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/DBusCall.sh @@ -0,0 +1,10 @@ +#!/bin/sh -- + +JAVA=%JAVA% +DEBUG=%DEBUG% +VERSION=%VERSION% +JARPATH=%JARPATH% +JAVAUNIXLIBPATH=%JAVAUNIXLIBPATH% +JAVAUNIXJARPATH=%JAVAUNIXJARPATH% + +exec $JAVA -DPid=$$ -DVersion=$VERSION -Djava.library.path=$JAVAUNIXLIBPATH -cp $JAVAUNIXJARPATH/unix.jar:$JAVAUNIXJARPATH/debug-$DEBUG.jar:$JAVAUNIXJARPATH/hexdump.jar:$JARPATH/dbus.jar:$JARPATH/dbus-bin.jar org.freedesktop.dbus.bin.Caller "$@" diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/DBusDaemon.bat b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/DBusDaemon.bat new file mode 100755 index 0000000..e9c1b71 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/DBusDaemon.bat @@ -0,0 +1,10 @@ +@echo off
+setlocal
+set debug=%DEBUG%
+set version=%VERSION%
+set jarpath=%WINJARPATH%
+set javaunixjarpath=%WINUNIXJARPATH%
+
+java -DVersion=%version% -cp %javaunixjarpath%debug-%debug%.jar;%javaunixjarpath%hexdump.jar;%jarpath%dbus.jar;%jarpath%dbus-bin.jar org.freedesktop.dbus.bin.DBusDaemon %*
+
+endlocal diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/DBusDaemon.sgml b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/DBusDaemon.sgml new file mode 100755 index 0000000..eeee64d --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/DBusDaemon.sgml @@ -0,0 +1,212 @@ +<!doctype refentry PUBLIC "-//OASIS//DTD DocBook V4.1//EN" [ + +<!-- Process this file with docbook-to-man to generate an nroff manual + page: `docbook-to-man manpage.sgml > manpage.1'. You may view + the manual page with: `docbook-to-man manpage.sgml | nroff -man | + less'. A typical entry in a Makefile or Makefile.am is: + +manpage.1: manpage.sgml + docbook-to-man $< > $@ + + + The docbook-to-man binary is found in the docbook-to-man package. + Please remember that if you create the nroff version in one of the + debian/rules file targets (such as build), you will need to include + docbook-to-man in your Build-Depends control field. + + --> + + <!-- Fill in your name for FIRSTNAME and SURNAME. --> + <!ENTITY dhfirstname "<firstname>Matthew</firstname>"> + <!ENTITY dhsurname "<surname>Johnson</surname>"> + <!-- Please adjust the date whenever revising the manpage. --> + <!ENTITY dhdate "<date>January 10, 2006</date>"> + <!-- SECTION should be 1-8, maybe w/ subsection other parameters are + allowed: see man(7), man(1). --> + <!ENTITY dhsection "<manvolnum>1</manvolnum>"> + <!ENTITY dhemail "<email><debian@matthew.ath.cx></email>"> + <!ENTITY dhusername "Matthew Johnson"> + <!ENTITY dhucpackage "<refentrytitle>DBUS-JAVA</refentrytitle>"> + <!ENTITY dhpackage "DBusDaemon"> + + <!ENTITY debian "<productname>Debian</productname>"> + <!ENTITY gnu "<acronym>GNU</acronym>"> + <!ENTITY gpl "&gnu; <acronym>GPL</acronym>"> +]> + +<refentry> + <refentryinfo> + <address> + &dhemail; + </address> + <author> + &dhfirstname; + &dhsurname; + </author> + <copyright> + <year>2006</year> + <holder>&dhusername;</holder> + </copyright> + &dhdate; + </refentryinfo> + <refmeta> + &dhucpackage; + + &dhsection; + </refmeta> + <refnamediv> + <refname>&dhpackage;</refname> + + <refpurpose>Runs a D-Bus Daemon</refpurpose> + </refnamediv> + <refsynopsisdiv> + <cmdsynopsis> + <command>&dhpackage;</command> + <arg><option>--version</option></arg> + <arg><option>-v</option></arg> + <arg><option>--help</option></arg> + <arg><option>-h</option></arg> + <arg><option>--print-address</option></arg> + <arg><option>-r</option></arg> + <arg><option>--unix</option></arg> + <arg><option>-u</option></arg> + <arg><option>--tcp</option></arg> + <arg><option>-t</option></arg> + <arg><option>--listen</option> <replaceable>address</replaceable></arg> + <arg><option>-l</option> <replaceable>address</replaceable></arg> + <arg><option>--addressfile</option> <replaceable>file</replaceable></arg> + <arg><option>-a</option> <replaceable>file</replaceable></arg> + <arg><option>--pidfile</option> <replaceable>file</replaceable></arg> + <arg><option>-p</option> <replaceable>file</replaceable></arg> + + </cmdsynopsis> + </refsynopsisdiv> + <refsect1> + <title>DESCRIPTION</title> + + <para>This manual page documents briefly the + <command>&dhpackage;</command> command.</para> + + <para><command>&dhpackage;</command> provides a D-Bus daemon for applications to communicate. + </para> + + + </refsect1> + <refsect1> + <title>OPTIONS</title> + + <para>These programs follow the usual &gnu; command line syntax, + with long options starting with two dashes (`-'). A summary of + options is included below. + </para> + + <variablelist> + <varlistentry> + <term> + <option>-v</option> + <option>--version</option> + </term> + <listitem> + <para>Print the version</para> + </listitem> + </varlistentry> + <varlistentry> + <term> + <option>-h</option> + <option>--help</option> + </term> + <listitem> + <para>Print the syntax</para> + </listitem> + </varlistentry> + <varlistentry> + <term> + <option>-r</option> + <option>--print-address</option> + </term> + <listitem> + <para>Print the address</para> + </listitem> + </varlistentry> + <varlistentry> + <term> + <option>-u</option> + <option>--unix</option> + </term> + <listitem> + <para>Generate random Unix Socket address</para> + </listitem> + </varlistentry> + <varlistentry> + <term> + <option>-t</option> + <option>--tcp</option> + </term> + <listitem> + <para>Generate random local TCP address</para> + </listitem> + </varlistentry> + <varlistentry> + <term> + <option>-l</option> <replaceable>address</replaceable> + <option>--listen</option> <replaceable>address</replaceable> + </term> + <listitem> + <para>Listen on the specified address</para> + </listitem> + </varlistentry> + <varlistentry> + <term> + <option>-a</option> <replaceable>file</replaceable> + <option>--addressfile</option> <replaceable>file</replaceable> + </term> + <listitem> + <para>Print address to specified file</para> + </listitem> + </varlistentry> + <varlistentry> + <term> + <option>-p</option> <replaceable>file</replaceable> + <option>--pidfile</option> <replaceable>file</replaceable> + </term> + <listitem> + <para>Print address to specified file</para> + </listitem> + </varlistentry> + + </variablelist> + </refsect1> + <refsect1> + <title>AUTHOR</title> + + <para>This manual page was written by &dhusername; &dhemail;. Permission is + granted to copy, distribute and/or modify this document under + the terms of the &gnu; Lesser General Public License, Version 2 as + published by the Free Software Foundation. + </para> + <para> + On Debian systems, the complete text of the GNU Lesser General Public + License can be found in /usr/share/common-licenses/LGPL-2. + </para> + + </refsect1> +</refentry> + +<!-- Keep this comment at the end of the file +Local variables: +mode: sgml +sgml-omittag:t +sgml-shorttag:t +sgml-minimize-attributes:nil +sgml-always-quote-attributes:t +sgml-indent-step:2 +sgml-indent-data:t +sgml-parent-document:nil +sgml-default-dtd-file:nil +sgml-exposed-tags:nil +sgml-local-catalogs:nil +sgml-local-ecat-files:nil +End: +--> + + diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/DBusDaemon.sh b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/DBusDaemon.sh new file mode 100755 index 0000000..7de5000 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/DBusDaemon.sh @@ -0,0 +1,10 @@ +#!/bin/sh -- + +JAVA=%JAVA% +DEBUG=%DEBUG% +VERSION=%VERSION% +JARPATH=%JARPATH% +JAVAUNIXLIBPATH=%JAVAUNIXLIBPATH% +JAVAUNIXJARPATH=%JAVAUNIXJARPATH% + +exec $JAVA -DPid=$$ -DVersion=$VERSION -Djava.library.path=$JAVAUNIXLIBPATH -cp $JAVAUNIXJARPATH/unix.jar:$JAVAUNIXJARPATH/debug-$DEBUG.jar:$JAVAUNIXJARPATH/hexdump.jar:$JARPATH/dbus.jar:$JARPATH/dbus-bin.jar org.freedesktop.dbus.bin.DBusDaemon "$@" diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/DBusViewer.bat b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/DBusViewer.bat new file mode 100755 index 0000000..f180fba --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/DBusViewer.bat @@ -0,0 +1,10 @@ +@echo off
+setlocal
+set debug=%DEBUG%
+set version=%VERSION%
+set jarpath=%WINJARPATH%
+set javaunixjarpath=%WINUNIXJARPATH%
+
+java -DVersion=%version% -cp %javaunixjarpath%debug-%debug%.jar;%javaunixjarpath%hexdump.jar;%jarpath%dbus.jar;%jarpath%dbus-viewer.jar;%jarpath%dbus-bin.jar org.freedesktop.dbus.viewer.DBusViewer %*
+
+endlocal diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/DBusViewer.sgml b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/DBusViewer.sgml new file mode 100755 index 0000000..65535b2 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/DBusViewer.sgml @@ -0,0 +1,107 @@ +<!doctype refentry PUBLIC "-//OASIS//DTD DocBook V4.1//EN" [ + +<!-- Process this file with docbook-to-man to generate an nroff manual + page: `docbook-to-man manpage.sgml > manpage.1'. You may view + the manual page with: `docbook-to-man manpage.sgml | nroff -man | + less'. A typical entry in a Makefile or Makefile.am is: + +manpage.1: manpage.sgml + docbook-to-man $< > $@ + + + The docbook-to-man binary is found in the docbook-to-man package. + Please remember that if you create the nroff version in one of the + debian/rules file targets (such as build), you will need to include + docbook-to-man in your Build-Depends control field. + + --> + + <!-- Fill in your name for FIRSTNAME and SURNAME. --> + <!ENTITY dhfirstname "<firstname>Matthew</firstname>"> + <!ENTITY dhsurname "<surname>Johnson</surname>"> + <!-- Please adjust the date whenever revising the manpage. --> + <!ENTITY dhdate "<date>January 10, 2006</date>"> + <!-- SECTION should be 1-8, maybe w/ subsection other parameters are + allowed: see man(7), man(1). --> + <!ENTITY dhsection "<manvolnum>1</manvolnum>"> + <!ENTITY dhemail "<email><debian@matthew.ath.cx></email>"> + <!ENTITY dhusername "Matthew Johnson"> + <!ENTITY dhucpackage "<refentrytitle>DBUS-JAVA</refentrytitle>"> + <!ENTITY dhpackage "DBusViewer"> + + <!ENTITY debian "<productname>Debian</productname>"> + <!ENTITY gnu "<acronym>GNU</acronym>"> + <!ENTITY gpl "&gnu; <acronym>GPL</acronym>"> +]> + +<refentry> + <refentryinfo> + <address> + &dhemail; + </address> + <author> + &dhfirstname; + &dhsurname; + </author> + <copyright> + <year>2006</year> + <holder>&dhusername;</holder> + </copyright> + &dhdate; + </refentryinfo> + <refmeta> + &dhucpackage; + + &dhsection; + </refmeta> + <refnamediv> + <refname>&dhpackage;</refname> + + <refpurpose>Show connections to the Bus and introspect on them.</refpurpose> + </refnamediv> + <refsect1> + <title>DESCRIPTION</title> + + <para>This manual page documents briefly the + <command>&dhpackage;</command> command.</para> + + <para><command>&dhpackage;</command> shows connections to the Bus in a + window. It allows you to introspect on them and save the corresponding Java + interface definitions. </para> + + + </refsect1> + <refsect1> + <title>AUTHOR</title> + + <para>This manual page was written by &dhusername; &dhemail;. Permission is + granted to copy, distribute and/or modify this document under + the terms of the &gnu; Lesser General Public License, Version 2 as + published by the Free Software Foundation. + </para> + <para> + On Debian systems, the complete text of the GNU Lesser General Public + License can be found in /usr/share/common-licenses/LGPL-2. + </para> + + </refsect1> +</refentry> + +<!-- Keep this comment at the end of the file +Local variables: +mode: sgml +sgml-omittag:t +sgml-shorttag:t +sgml-minimize-attributes:nil +sgml-always-quote-attributes:t +sgml-indent-step:2 +sgml-indent-data:t +sgml-parent-document:nil +sgml-default-dtd-file:nil +sgml-exposed-tags:nil +sgml-local-catalogs:nil +sgml-local-ecat-files:nil +End: +--> + + diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/DBusViewer.sh b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/DBusViewer.sh new file mode 100755 index 0000000..c060b36 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/DBusViewer.sh @@ -0,0 +1,10 @@ +#!/bin/sh -- + +JAVA=%JAVA% +DEBUG=%DEBUG% +VERSION=%VERSION% +JARPATH=%JARPATH% +JAVAUNIXLIBPATH=%JAVAUNIXLIBPATH% +JAVAUNIXJARPATH=%JAVAUNIXJARPATH% + +exec $JAVA -DPid=$$ -DVersion=$VERSION -Djava.library.path=$JAVAUNIXLIBPATH -cp $JAVAUNIXJARPATH/unix.jar:$JAVAUNIXJARPATH/debug-$DEBUG.jar:$JAVAUNIXJARPATH/hexdump.jar:$JARPATH/dbus.jar:$JARPATH/dbus-bin.jar:$JARPATH/dbus-viewer.jar org.freedesktop.dbus.viewer.DBusViewer "$@" diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/INSTALL b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/INSTALL new file mode 100755 index 0000000..a6c5fb8 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/INSTALL @@ -0,0 +1,101 @@ +D-Bus Java installation guide +----------------------------- + +Prerequisites +------------- + +To compile and install the library you will need: + + A Java 1.5-compliant VM and Compiler (at time of writing + only the Sun VM and Compiler is known to work). + The unix socket, debug and hexdump libraries from http://www.matthew.ath.cx/projects/java/ (version 0.6 or later) + GNU gettext + +To build and install the documentation you will also need: + + A LaTeX environment + tex4ht + docbook + +Compiling the Library +--------------------- + +Simply invoke `make' in the top level directory to compile the library. +Depending on your JDK installation you may need to export JAVA_HOME +appropriately. The location of the unix-socket library can be set with +JAVAUNIXLIBDIR and JAVAUNIXJARDIR. Explicit paths to the javac, jar, java and +javadoc binaries can be set with the JAVAC, JAR, JAVA and JAVADOC variables. + +The library will be installed into /usr/local by invoking `make install'. If +you wish to install them anywhere else then run make with the PREFIX variable +set to another location. More fine grained control of the installation +directories can be achieved using the BINDIR etc variables. For more detail +read the Makefile. DESTDIR can be used for packaging to install with the +correct hierarchy into a temporary folder. + +NOTE: if you set PREFIX in `make install' you should also set it when invoking +just `make'. PREFIX is to create the binary wrappers with the correct paths to +the installed library. + +Documentation for the library can be built with `make doc' and installed with +`make install-doc install-man', with the same provisos for installation paths. + +Using the Library +----------------- + +The documentation which is by default installed into +/usr/local/share/doc/libdbus-java/ gives detailed instructions on how to call +D-Bus programs using the Java implementation and a full API reference. + +To run a Java program using D-Bus you need to have the libdbus-java, +libunix-java and libdebug jar files in your classpath and the libunix-java +shared library in your library path. With the default install paths you may +have to do something like: + +java -cp /usr/local/share/java/dbus.jar:/usr/local/share/java/unix.jar:/usr/local/share/java/debug-disable.jar -Djava.library.path=/usr/local/lib/jni + +Windows +------- + +The Java D-Bus implementation can be used under Windows with TCP Sockets. There +are several windows batch scripts provided to ease use on Windows. + +If the library is being compiled in a unix environment (including cygwin) the +normal Makefile can be used to create batch files under win/ with `make win'. +These batch files are wrapper scripts to run the included programs (DBusDaemon, +CreateInterface, ...) under windows. There is also a make target which creates +a zip file containing all the jars, wrapper scripts and dependency jars. + +If you are compiling on windows there is a script, compile.bat, which will +create all the jars. You may have to alter the variables defined in it +depending where you have installed the dependencies and your Java compiler. +The other .bat files are the wrapper scripts which will need variables setting +appropriately before use. + +Debugging +--------- + +It is possible to enable debugging during the build. This will be a lot slower, +but can print a lot of useful information for debugging your program. + +To enable a debug build compile with DEBUG=enable. This will then need to be +enabled at runtime by using the debug jar with debugging enabled (usually +installed as debug-enable.jar alongside the normal jar). + +Running a program which uses this library will print some informative messages. +More verbose debug information can be got by supplying a custom debug +configuration file. This should be placed in the file `debug.conf' and has the +format: + +classname = LEVEL + +Where classname is either the special word `ALL' or a full class name like +`org.freedesktop.dbus' and LEVEL is one of NONE, CRIT, ERR, WARN, INFO, DEBUG, +VERBOSE, YES, ALL or TRUE. This will set the debug level for a particular +class. Any messages from that class at that level or higher will be printed. +Verbose debugging is extremely verbose. + +In addition, the environment variable DBUS_JAVA_EXCEPTION_DEBUG will cause all +exceptions which are handled internally to have their stack trace printed when +they are handled. This will happen unless debugging has been disabled for that +class. diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/ListDBus.bat b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/ListDBus.bat new file mode 100755 index 0000000..2dd6439 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/ListDBus.bat @@ -0,0 +1,10 @@ +@echo off
+setlocal
+set debug=%DEBUG%
+set version=%VERSION%
+set jarpath=%WINJARPATH%
+set javaunixjarpath=%WINUNIXJARPATH%
+
+java -DVersion=%version% -cp %javaunixjarpath%debug-%debug%.jar;%javaunixjarpath%hexdump.jar;%jarpath%dbus.jar;%jarpath%dbus-bin.jar org.freedesktop.dbus.bin.ListDBus %*
+
+endlocal diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/ListDBus.sgml b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/ListDBus.sgml new file mode 100755 index 0000000..4be1e95 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/ListDBus.sgml @@ -0,0 +1,177 @@ +<!doctype refentry PUBLIC "-//OASIS//DTD DocBook V4.1//EN" [ + +<!-- Process this file with docbook-to-man to generate an nroff manual + page: `docbook-to-man manpage.sgml > manpage.1'. You may view + the manual page with: `docbook-to-man manpage.sgml | nroff -man | + less'. A typical entry in a Makefile or Makefile.am is: + +manpage.1: manpage.sgml + docbook-to-man $< > $@ + + + The docbook-to-man binary is found in the docbook-to-man package. + Please remember that if you create the nroff version in one of the + debian/rules file targets (such as build), you will need to include + docbook-to-man in your Build-Depends control field. + + --> + + <!-- Fill in your name for FIRSTNAME and SURNAME. --> + <!ENTITY dhfirstname "<firstname>Matthew</firstname>"> + <!ENTITY dhsurname "<surname>Johnson</surname>"> + <!-- Please adjust the date whenever revising the manpage. --> + <!ENTITY dhdate "<date>January 10, 2006</date>"> + <!-- SECTION should be 1-8, maybe w/ subsection other parameters are + allowed: see man(7), man(1). --> + <!ENTITY dhsection "<manvolnum>1</manvolnum>"> + <!ENTITY dhemail "<email><debian@matthew.ath.cx></email>"> + <!ENTITY dhusername "Matthew Johnson"> + <!ENTITY dhucpackage "<refentrytitle>DBUS-JAVA</refentrytitle>"> + <!ENTITY dhpackage "ListDBus"> + + <!ENTITY debian "<productname>Debian</productname>"> + <!ENTITY gnu "<acronym>GNU</acronym>"> + <!ENTITY gpl "&gnu; <acronym>GPL</acronym>"> +]> + +<refentry> + <refentryinfo> + <address> + &dhemail; + </address> + <author> + &dhfirstname; + &dhsurname; + </author> + <copyright> + <year>2006</year> + <holder>&dhusername;</holder> + </copyright> + &dhdate; + </refentryinfo> + <refmeta> + &dhucpackage; + + &dhsection; + </refmeta> + <refnamediv> + <refname>&dhpackage;</refname> + + <refpurpose>List the names on a DBus</refpurpose> + </refnamediv> + <refsynopsisdiv> + <cmdsynopsis> + <command>&dhpackage;</command> + <arg><option>-y </option></arg> + <arg><option>--system </option></arg> + <arg><option>-s </option></arg> + <arg><option>--session </option></arg> + <arg><option>-o </option></arg> + <arg><option>--owners </option></arg> + <arg><option>-u </option></arg> + <arg><option>--uids </option></arg> + <arg><option>-h </option></arg> + <arg><option>--help</option></arg> + + </cmdsynopsis> + </refsynopsisdiv> + <refsect1> + <title>DESCRIPTION</title> + + <para>This manual page documents briefly the + <command>&dhpackage;</command> command.</para> + + <para><command>&dhpackage;</command> lists all the names on DBus. + </para> + + + </refsect1> + <refsect1> + <title>OPTIONS</title> + + <para>These programs follow the usual &gnu; command line syntax, + with long options starting with two dashes (`-'). A summary of + options is included below. + </para> + + <variablelist> + <varlistentry> + <term><option>-s</option> + <option>--session</option> + </term> + <listitem> + <para>List the Session Bus + (This is the Default)</para> + </listitem> + </varlistentry> + <varlistentry> + <term><option>-y</option> + <option>--system</option> + </term> + <listitem> + <para>List the System Bus + (Default is Session)</para> + </listitem> + </varlistentry> + <varlistentry> + <term><option>-u</option> + <option>--uids</option> + </term> + <listitem> + <para>Give the UIDs which own each name + </para> + </listitem> + </varlistentry> + <varlistentry> + <term><option>-o</option> + <option>--owners</option> + </term> + <listitem> + <para>Resolve any well-known names to their owners + </para> + </listitem> + </varlistentry> + <varlistentry> + <term><option>-h</option> + <option>--help</option> + </term> + <listitem> + <para>Show summary of options.</para> + </listitem> + </varlistentry> + </variablelist> + </refsect1> + <refsect1> + <title>AUTHOR</title> + + <para>This manual page was written by &dhusername; &dhemail;. Permission is + granted to copy, distribute and/or modify this document under + the terms of the &gnu; Lesser General Public License, Version 2 as + published by the Free Software Foundation. + </para> + <para> + On Debian systems, the complete text of the GNU Lesser General Public + License can be found in /usr/share/common-licenses/LGPL-2. + </para> + + </refsect1> +</refentry> + +<!-- Keep this comment at the end of the file +Local variables: +mode: sgml +sgml-omittag:t +sgml-shorttag:t +sgml-minimize-attributes:nil +sgml-always-quote-attributes:t +sgml-indent-step:2 +sgml-indent-data:t +sgml-parent-document:nil +sgml-default-dtd-file:nil +sgml-exposed-tags:nil +sgml-local-catalogs:nil +sgml-local-ecat-files:nil +End: +--> + + diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/ListDBus.sh b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/ListDBus.sh new file mode 100755 index 0000000..4fdfb39 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/ListDBus.sh @@ -0,0 +1,10 @@ +#!/bin/sh -- + +JAVA=%JAVA% +DEBUG=%DEBUG% +VERSION=%VERSION% +JARPATH=%JARPATH% +JAVAUNIXLIBPATH=%JAVAUNIXLIBPATH% +JAVAUNIXJARPATH=%JAVAUNIXJARPATH% + +exec $JAVA -DPid=$$ -DVersion=$VERSION -Djava.library.path=$JAVAUNIXLIBPATH -cp $JAVAUNIXJARPATH/unix.jar:$JAVAUNIXJARPATH/debug-$DEBUG.jar:$JAVAUNIXJARPATH/hexdump.jar:$JARPATH/dbus.jar:$JARPATH/dbus-bin.jar org.freedesktop.dbus.bin.ListDBus "$@" diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/Makefile b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/Makefile new file mode 100755 index 0000000..65bff86 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/Makefile @@ -0,0 +1,328 @@ +# +# For profiling/debug builds use: +# +# make CFLAGS="" STRIP=touch JCFLAGS="-Xlint:all" +# JFLAGS="-Xrunhprof:heap=sites,cpu=samples,monitor=y,thread=y,doe=y -classic" check +# + +# Variables controlling compilation. May be overridden on the command line for +# debug builds etc + +# Programs +JAVAC?=javac +JAVA?=java +JAVADOC?=javadoc +JAR?=jar +MAKE?=make +MSGFMT?=msgfmt +DOCBOOKTOMAN?=docbook-to-man + +# Program parameters +CPFLAG?=-classpath +JCFLAGS?=-Xlint:all -O -g:none +JFLAGS+=-Djava.library.path=$(JAVAUNIXLIBDIR) + +# Source/Class locations +SRCDIR=org/freedesktop +CLASSDIR=classes/org/freedesktop/dbus + +# Installation variables. Controls the location of make install. May be +# overridden in the make command line to install to different locations +# +PREFIX?=/usr/local +JARPREFIX?=$(PREFIX)/share/java +BINPREFIX?=$(PREFIX)/bin +DOCPREFIX?=$(PREFIX)/share/doc/libdbus-java +MANPREFIX?=$(PREFIX)/share/man/man1 +# allows overriding the javadoc install location from command line +JAVADOCPREFIX?=$(DOCPREFIX) + +# Installation directory of the java-unix libraries +JAVAUNIXLIBDIR?=/usr/lib/jni +# Installation directory of the java-unix jars +JAVAUNIXJARDIR?=/usr/share/java +DEBUG=disable + +# Version numbering +VERSION = $(shell sed -n '1s/.* \(.*\):/\1/p' changelog) +RELEASEVERSION = $(shell sed -n '/^Version/s/.* \(.*\):/\1/p' changelog | sed -n '2p') + +DISTFILES=dbus-java.tex Makefile org tmp-session.conf CreateInterface.sgml DBusDaemon.sgml ListDBus.sgml DBusViewer.sgml changelog AUTHORS COPYING README INSTALL CreateInterface.sh DBusDaemon.sh ListDBus.sh DBusViewer.sh DBusDaemon.bat CreateInterface.bat ListDBus.bat DBusViewer.bat compile.bat DBusCall.bat DBusCall.sh DBusCall.sgml translations + +all: bin doc man +bin: libdbus-java-$(VERSION).jar dbus-java-viewer-$(VERSION).jar bin/DBusDaemon bin/ListDBus bin/CreateInterface bin/DBusViewer dbus-java-bin-$(VERSION).jar bin/DBusCall +man: CreateInterface.1 ListDBus.1 DBusDaemon.1 DBusViewer.1 DBusCall.1 +doc: doc/dbus-java.dvi doc/dbus-java.ps doc/dbus-java.pdf doc/dbus-java/index.html doc/api/index.html + +clean: + rm -rf doc bin classes testbin win + rm -f *.1 *.o *.so *.h .dist .classes .testclasses .doc *.jar *.log pid address tmp-session-bus *.gz .viewerclasses .bin .testbin .win .binclasses Manifest + rm -rf dbus-java-$(VERSION) + rm -rf dbus-java-$(RELEASEVERSION) + +classes: .classes +testclasses: .testclasses +viewerclasses: .viewerclasses +binclasses: .binclasses +.testclasses: $(SRCDIR)/dbus/test/*.java .classes + mkdir -p classes + $(JAVAC) -cp classes:${JAVAUNIXJARDIR}/debug-$(DEBUG).jar:${JAVAUNIXJARDIR}/hexdump.jar:$(CLASSPATH) -d classes $(JCFLAGS) $(SRCDIR)/dbus/test/*.java + touch .testclasses +.viewerclasses: $(SRCDIR)/dbus/viewer/*.java .classes .binclasses + mkdir -p classes + $(JAVAC) -cp classes:$(CLASSPATH):${JAVAUNIXJARDIR}/unix.jar:${JAVAUNIXJARDIR}/debug-$(DEBUG).jar:${JAVAUNIXJARDIR}/hexdump.jar -d classes $(JCFLAGS) $(SRCDIR)/dbus/viewer/*.java + touch .viewerclasses +.binclasses: $(SRCDIR)/dbus/bin/*.java .classes + mkdir -p classes + $(JAVAC) -cp classes:$(CLASSPATH):${JAVAUNIXJARDIR}/unix.jar:${JAVAUNIXJARDIR}/debug-$(DEBUG).jar:${JAVAUNIXJARDIR}/hexdump.jar -d classes $(JCFLAGS) $(SRCDIR)/dbus/bin/*.java + touch .binclasses +.classes: $(SRCDIR)/*.java $(SRCDIR)/dbus/*.java $(SRCDIR)/dbus/exceptions/*.java $(SRCDIR)/dbus/types/*.java translations/*.po + mkdir -p classes + $(JAVAC) -d classes -cp classes:${JAVAUNIXJARDIR}/unix.jar:${JAVAUNIXJARDIR}/debug-$(DEBUG).jar:${JAVAUNIXJARDIR}/hexdump.jar:$(CLASSPATH) $(JCFLAGS) $(SRCDIR)/*.java $(SRCDIR)/dbus/*.java $(SRCDIR)/dbus/exceptions/*.java $(SRCDIR)/dbus/types/*.java + (cd translations; for i in *.po; do $(MSGFMT) --java2 -r dbusjava_localized -d ../classes -l $${i%.po} $$i; done) + $(MSGFMT) --java2 -r dbusjava_localized -d classes translations/en_GB.po + touch .classes + +translations/en_GB.po: $(SRCDIR)/*.java $(SRCDIR)/dbus/*.java $(SRCDIR)/dbus/exceptions/*.java $(SRCDIR)/dbus/types/*.java $(SRCDIR)/dbus/bin/*.java $(SRCDIR)/dbus/viewer/*.java + echo "#java-format" > $@ + sed -n '/_(/s/.*_("\([^"]*\)").*/\1/p' $^ | sort -u | sed 's/\(.*\)/msgid "\1"\nmsgstr "\1"/' >> $@ + +libdbus-java-$(VERSION).jar: .classes + echo "Class-Path: ${JAVAUNIXJARDIR}/unix.jar ${JAVAUNIXJARDIR}/hexdump.jar ${JAVAUNIXJARDIR}/debug-$(DEBUG).jar" > Manifest + (cd classes; $(JAR) -cfm ../$@ ../Manifest org/freedesktop/dbus/*.class org/freedesktop/*.class org/freedesktop/dbus/types/*.class org/freedesktop/dbus/exceptions/*.class *localized*class) +dbus-java-test-$(VERSION).jar: .testclasses + echo "Class-Path: ${JARPREFIX}/libdbus-java-$(VERSION).jar" > Manifest + (cd classes; $(JAR) -cfm ../$@ ../Manifest org/freedesktop/dbus/test/*.class) +dbus-java-viewer-$(VERSION).jar: .viewerclasses + echo "Class-Path: ${JARPREFIX}/libdbus-java-$(VERSION).jar" > Manifest + (cd classes; $(JAR) -cfm ../$@ ../Manifest org/freedesktop/dbus/viewer/*.class) +dbus-java-bin-$(VERSION).jar: .binclasses + echo "Class-Path: ${JARPREFIX}/libdbus-java-$(VERSION).jar" > Manifest + (cd classes; $(JAR) -cfm ../$@ ../Manifest org/freedesktop/dbus/bin/*.class) +dbus.jar: libdbus-java-$(VERSION).jar + ln -sf $< $@ +dbus-bin.jar: dbus-java-bin-$(VERSION).jar + ln -sf $< $@ +dbus-viewer.jar: dbus-java-viewer-$(VERSION).jar + ln -sf $< $@ + +jar: libdbus-java-$(VERSION).jar + +.doc: + mkdir -p doc + mkdir -p doc/dbus-java + touch .doc +.win: + mkdir -p win + touch .win +.bin: + mkdir -p bin + touch .bin +.testbin: + mkdir -p testbin + touch .testbin +doc/dbus-java.dvi: dbus-java.tex .doc + (cd doc; latex ../dbus-java.tex) + (cd doc; latex ../dbus-java.tex) + (cd doc; latex ../dbus-java.tex) +doc/dbus-java.ps: doc/dbus-java.dvi .doc + (cd doc; dvips -o dbus-java.ps dbus-java.dvi) +doc/dbus-java.pdf: doc/dbus-java.dvi .doc + (cd doc; pdflatex ../dbus-java.tex) +doc/dbus-java/index.html: dbus-java.tex .doc + mkdir -p doc/dbus-java/ + (cd doc/dbus-java; TEX4HTENV=/etc/tex4ht/tex4ht.env htlatex ../../dbus-java.tex "xhtml,2" "" "-cvalidate") + rm -f doc/dbus-java/*{4ct,4tc,aux,dvi,idv,lg,log,tmp,xref} + cp doc/dbus-java/dbus-java.html doc/dbus-java/index.html +doc/api/index.html: $(SRCDIR)/*.java $(SRCDIR)/dbus/*.java .doc + $(JAVADOC) -quiet -author -link http://java.sun.com/j2se/1.5.0/docs/api/ -classpath $(JAVAUNIXJARDIR)/unix.jar:$(JAVAUNIXJARDIR)/hexdump.jar:$(JAVAUNIXJARDIR)/debug-$(DEBUG).jar -d doc/api $(SRCDIR)/*.java $(SRCDIR)/dbus/*.java $(SRCDIR)/dbus/types/*.java $(SRCDIR)/dbus/exceptions/*.java + +%.1: %.sgml + $(DOCBOOKTOMAN) $< > $@ + +bin/%: %.sh .bin + sed 's,\%JARPATH\%,$(JARPREFIX),;s,\%JAVAUNIXJARPATH\%,$(JAVAUNIXJARDIR),;s,\%JAVAUNIXLIBPATH\%,$(JAVAUNIXLIBDIR),;s,\%VERSION\%,$(VERSION),;s,\%DEBUG\%,$(DEBUG),;s,\%JAVA\%,$(JAVA),' < $< > $@ + +win/%.bat: %.bat .win + sed 's,\%WINJARPATH\%,$(JARPREFIX),;s,\%WINUNIXJARPATH\%,$(JAVAUNIXJARDIR),;s,\%VERSION\%,$(VERSION),;s,\%DEBUG\%,$(DEBUG),' < $< > $@ + +testbin/%: %.sh .testbin libdbus-java-$(VERSION).jar dbus-java-bin-$(VERSION).jar dbus-bin.jar dbus.jar dbus-viewer.jar + sed 's,\%JARPATH\%,.,;s,\%JAVAUNIXJARPATH\%,$(JAVAUNIXJARDIR),;s,\%JAVAUNIXLIBPATH\%,$(JAVAUNIXLIBDIR),;s,\%VERSION\%,$(VERSION),;s,\%DEBUG\%,$(DEBUG),;s,\%JAVA\%,$(JAVA),' < $< > $@ + chmod 755 $@ + +testrun: libdbus-java-$(VERSION).jar dbus-java-test-$(VERSION).jar + $(JAVA) $(JFLAGS) $(CPFLAG) $(CLASSPATH):$(JAVAUNIXJARDIR)/unix.jar:$(JAVAUNIXJARDIR)/hexdump.jar:$(JAVAUNIXJARDIR)/debug-$(DEBUG).jar:libdbus-java-$(VERSION).jar:dbus-java-test-$(VERSION).jar org.freedesktop.dbus.test.test + +low-level-run: libdbus-java-$(VERSION).jar dbus-java-test-$(VERSION).jar + $(JAVA) $(JFLAGS) $(CPFLAG) $(CLASSPATH):$(JAVAUNIXJARDIR)/unix.jar:$(JAVAUNIXJARDIR)/hexdump.jar:$(JAVAUNIXJARDIR)/debug-$(DEBUG).jar:libdbus-java-$(VERSION).jar:dbus-java-test-$(VERSION).jar org.freedesktop.dbus.test.test_low_level + +cross-test-server: libdbus-java-$(VERSION).jar dbus-java-test-$(VERSION).jar + $(JAVA) $(JFLAGS) $(CPFLAG) $(CLASSPATH):$(JAVAUNIXJARDIR)/unix.jar:$(JAVAUNIXJARDIR)/hexdump.jar:$(JAVAUNIXJARDIR)/debug-$(DEBUG).jar:libdbus-java-$(VERSION).jar:dbus-java-test-$(VERSION).jar org.freedesktop.dbus.test.cross_test_server + +cross-test-client: libdbus-java-$(VERSION).jar dbus-java-test-$(VERSION).jar + $(JAVA) $(JFLAGS) $(CPFLAG) $(CLASSPATH):$(JAVAUNIXJARDIR)/unix.jar:$(JAVAUNIXJARDIR)/hexdump.jar:$(JAVAUNIXJARDIR)/debug-$(DEBUG).jar:libdbus-java-$(VERSION).jar:dbus-java-test-$(VERSION).jar org.freedesktop.dbus.test.cross_test_client + +peer-server: libdbus-java-$(VERSION).jar dbus-java-test-$(VERSION).jar + $(JAVA) $(JFLAGS) $(CPFLAG) $(CLASSPATH):$(JAVAUNIXJARDIR)/unix.jar:$(JAVAUNIXJARDIR)/hexdump.jar:$(JAVAUNIXJARDIR)/debug-$(DEBUG).jar:libdbus-java-$(VERSION).jar:dbus-java-test-$(VERSION).jar org.freedesktop.dbus.test.test_p2p_server + +peer-client: libdbus-java-$(VERSION).jar dbus-java-test-$(VERSION).jar + $(JAVA) $(JFLAGS) $(CPFLAG) $(CLASSPATH):$(JAVAUNIXJARDIR)/unix.jar:$(JAVAUNIXJARDIR)/hexdump.jar:$(JAVAUNIXJARDIR)/debug-$(DEBUG).jar:libdbus-java-$(VERSION).jar:dbus-java-test-$(VERSION).jar org.freedesktop.dbus.test.test_p2p_client + +two-part-server: libdbus-java-$(VERSION).jar dbus-java-test-$(VERSION).jar + $(JAVA) $(JFLAGS) $(CPFLAG) $(CLASSPATH):$(JAVAUNIXJARDIR)/unix.jar:$(JAVAUNIXJARDIR)/hexdump.jar:$(JAVAUNIXJARDIR)/debug-$(DEBUG).jar:libdbus-java-$(VERSION).jar:dbus-java-test-$(VERSION).jar org.freedesktop.dbus.test.two_part_test_server + +two-part-client: libdbus-java-$(VERSION).jar dbus-java-test-$(VERSION).jar + $(JAVA) $(JFLAGS) $(CPFLAG) $(CLASSPATH):$(JAVAUNIXJARDIR)/unix.jar:$(JAVAUNIXJARDIR)/hexdump.jar:$(JAVAUNIXJARDIR)/debug-$(DEBUG).jar:libdbus-java-$(VERSION).jar:dbus-java-test-$(VERSION).jar org.freedesktop.dbus.test.two_part_test_client + +profilerun: libdbus-java-$(VERSION).jar dbus-java-test-$(VERSION).jar + $(JAVA) $(JFLAGS) $(CPFLAG) $(CLASSPATH):$(JAVAUNIXJARDIR)/unix.jar:$(JAVAUNIXJARDIR)/hexdump.jar:$(JAVAUNIXJARDIR)/debug-$(DEBUG).jar:libdbus-java-$(VERSION).jar:dbus-java-test-$(VERSION).jar org.freedesktop.dbus.test.profile $(PROFILE) + +viewer: libdbus-java-$(VERSION).jar dbus-java-viewer-$(VERSION).jar + $(JAVA) $(JFLAGS) $(CPFLAG) $(CLASSPATH):$(JAVAUNIXJARDIR)/unix.jar:$(JAVAUNIXJARDIR)/hexdump.jar:$(JAVAUNIXJARDIR)/debug-$(DEBUG).jar:libdbus-java-$(VERSION).jar:dbus-java-viewer-$(VERSION).jar org.freedesktop.dbus.viewer.DBusViewer + +#dbus-daemon --config-file=tmp-session.conf --print-pid --print-address=5 --fork >pid 5>address ; \ + +low-level: libdbus-java-$(VERSION).jar dbus-java-test-$(VERSION).jar testbin/DBusDaemon dbus.jar dbus-java-bin-$(VERSION).jar dbus-bin.jar + ( testbin/DBusDaemon --addressfile address --pidfile pid & \ + sleep 1; \ + export DBUS_SESSION_BUS_ADDRESS=$$(cat address) ;\ + $(MAKE) DBUS_JAVA_FLOATS=true low-level-run ;\ + kill $$(cat pid)) + +checktcp: libdbus-java-$(VERSION).jar dbus-java-test-$(VERSION).jar testbin/DBusDaemon dbus.jar dbus-java-bin-$(VERSION).jar dbus-bin.jar + ( PASS=false; \ + testbin/DBusDaemon --tcp --addressfile address --pidfile pid 2> server.log&\ + sleep 1; \ + export DBUS_SESSION_BUS_ADDRESS=$$(cat address) ;\ + dbus-monitor >> monitor.log &\ + if $(MAKE) DBUS_JAVA_FLOATS=true DEBUG=$(DEBUG) testrun 2>&1 | tee client.log; then export PASS=true; fi ; \ + kill $$(cat pid) ; \ + if [ "$$PASS" = "true" ]; then exit 0; else exit 1; fi ) + + +check: libdbus-java-$(VERSION).jar dbus-java-test-$(VERSION).jar testbin/DBusDaemon dbus.jar dbus-java-bin-$(VERSION).jar dbus-bin.jar + ( PASS=false; \ + testbin/DBusDaemon --addressfile address --pidfile pid 2> server.log&\ + sleep 1; \ + export DBUS_SESSION_BUS_ADDRESS=$$(cat address) ;\ + dbus-monitor >> monitor.log &\ + if $(MAKE) DBUS_JAVA_FLOATS=true DEBUG=$(DEBUG) testrun 2>&1 | tee client.log; then export PASS=true; fi ; \ + kill $$(cat pid) ; \ + if [ "$$PASS" = "true" ]; then exit 0; else exit 1; fi ) + +cross-test-compile: libdbus-java-$(VERSION).jar dbus-java-test-$(VERSION).jar + +internal-cross-test: libdbus-java-$(VERSION).jar dbus-java-test-$(VERSION).jar testbin/DBusDaemon dbus.jar dbus-java-bin-$(VERSION).jar dbus-bin.jar + ( testbin/DBusDaemon --addressfile address --pidfile pid &\ + sleep 1; \ + export DBUS_SESSION_BUS_ADDRESS=$$(cat address) ;\ + $(MAKE) DEBUG=$(DEBUG) DBUS_JAVA_FLOATS=true -s cross-test-server | tee server.log &\ + sleep 1;\ + $(MAKE) DEBUG=$(DEBUG) DBUS_JAVA_FLOATS=true -s cross-test-client | tee client1.log &\ + $(MAKE) DEBUG=$(DEBUG) DBUS_JAVA_FLOATS=true -s cross-test-client | tee client2.log ;\ + kill $$(cat pid) ; ) + +peer-to-peer-test: libdbus-java-$(VERSION).jar dbus-java-test-$(VERSION).jar + ( $(MAKE) DEBUG=$(DEBUG) DBUS_JAVA_FLOATS=true -s peer-server 2>&1 | tee server.log &\ + sleep 1;\ + $(MAKE) DEBUG=$(DEBUG) DBUS_JAVA_FLOATS=true -s peer-client 2>&1 | tee client.log ) + +two-part-test: libdbus-java-$(VERSION).jar dbus-java-test-$(VERSION).jar testbin/DBusDaemon dbus.jar dbus-java-bin-$(VERSION).jar dbus-bin.jar + ( testbin/DBusDaemon --addressfile address --pidfile pid &\ + sleep 1; \ + export DBUS_SESSION_BUS_ADDRESS=$$(cat address) ;\ + $(MAKE) DEBUG=$(DEBUG) DBUS_JAVA_FLOATS=true -s two-part-server | tee server.log &\ + sleep 1;\ + $(MAKE) DEBUG=$(DEBUG) DBUS_JAVA_FLOATS=true -s two-part-client | tee client.log ;\ + kill $$(cat pid) ; ) + +profile: libdbus-java-$(VERSION).jar dbus-java-test-$(VERSION).jar testbin/DBusDaemon dbus.jar dbus-java-bin-$(VERSION).jar dbus-bin.jar + ( PASS=false; \ + testbin/DBusDaemon --addressfile address --pidfile pid &\ + sleep 1; \ + export DBUS_SESSION_BUS_ADDRESS=$$(cat address) ;\ + if $(MAKE) DEBUG=$(DEBUG) DBUS_JAVA_FLOATS=true profilerun ; then export PASS=true; fi ; \ + kill $$(cat pid) ; \ + if [ "$$PASS" = "true" ]; then exit 0; else exit 1; fi ) + +uninstall: + rm -f $(DESTDIR)$(JARPREFIX)/dbus.jar $(DESTDIR)$(JARPREFIX)/dbus-$(VERSION).jar $(DESTDIR)$(JARPREFIX)/dbus-viewer.jar $(DESTDIR)$(JARPREFIX)/dbus-viewer-$(VERSION).jar $(DESTDIR)$(JARPREFIX)/dbus-bin.jar $(DESTDIR)$(JARPREFIX)/dbus-bin-$(VERSION).jar + rm -rf $(DESTDIR)$(DOCPREFIX) + rm -f $(DESTDIR)$(MANPREFIX)/CreateInterface.1 $(DESTDIR)$(MANPREFIX)/ListDBus.1 $(DESTDIR)$(MANPREFIX)/DBusViewer.1 $(DESTDIR)$(MANPREFIX)/DBusDaemon.1 $(DESTDIR)$(MANPREFIX)/DBusCall.1 + rm -f $(DESTDIR)$(BINPREFIX)/CreateInterface $(DESTDIR)$(BINPREFIX)/ListDBus $(DESTDIR)$(BINPREFIX)/DBusViewer $(DESTDIR)$(BINPREFIX)/DBusDaemon $(DESTDIR)$(BINPREFIX)/DBusCall + +install: install-bin install-man install-doc + +install-bin: dbus-java-viewer-$(VERSION).jar libdbus-java-$(VERSION).jar bin/CreateInterface bin/ListDBus bin/DBusViewer bin/DBusDaemon dbus-java-bin-$(VERSION).jar bin/DBusCall + install -d $(DESTDIR)$(JARPREFIX) + install -m 644 libdbus-java-$(VERSION).jar $(DESTDIR)$(JARPREFIX)/dbus-$(VERSION).jar + install -m 644 dbus-java-viewer-$(VERSION).jar $(DESTDIR)$(JARPREFIX)/dbus-viewer-$(VERSION).jar + install -m 644 dbus-java-bin-$(VERSION).jar $(DESTDIR)$(JARPREFIX)/dbus-bin-$(VERSION).jar + ln -sf dbus-$(VERSION).jar $(DESTDIR)$(JARPREFIX)/dbus.jar + ln -sf dbus-viewer-$(VERSION).jar $(DESTDIR)$(JARPREFIX)/dbus-viewer.jar + ln -sf dbus-bin-$(VERSION).jar $(DESTDIR)$(JARPREFIX)/dbus-bin.jar + install -d $(DESTDIR)$(BINPREFIX) + install bin/DBusViewer $(DESTDIR)$(BINPREFIX) + install bin/DBusCall $(DESTDIR)$(BINPREFIX) + install bin/CreateInterface $(DESTDIR)$(BINPREFIX) + install bin/ListDBus $(DESTDIR)$(BINPREFIX) + install bin/DBusDaemon $(DESTDIR)$(BINPREFIX) + +install-man: CreateInterface.1 ListDBus.1 DBusDaemon.1 DBusViewer.1 changelog AUTHORS COPYING README INSTALL DBusCall.1 + install -d $(DESTDIR)$(DOCPREFIX) + install -m 644 changelog $(DESTDIR)$(DOCPREFIX) + install -m 644 COPYING $(DESTDIR)$(DOCPREFIX) + install -m 644 AUTHORS $(DESTDIR)$(DOCPREFIX) + install -m 644 README $(DESTDIR)$(DOCPREFIX) + install -m 644 INSTALL $(DESTDIR)$(DOCPREFIX) + install -d $(DESTDIR)$(MANPREFIX) + install -m 644 CreateInterface.1 $(DESTDIR)$(MANPREFIX)/CreateInterface.1 + install -m 644 ListDBus.1 $(DESTDIR)$(MANPREFIX)/ListDBus.1 + install -m 644 DBusDaemon.1 $(DESTDIR)$(MANPREFIX)/DBusDaemon.1 + install -m 644 DBusViewer.1 $(DESTDIR)$(MANPREFIX)/DBusViewer.1 + install -m 644 DBusCall.1 $(DESTDIR)$(MANPREFIX)/DBusCall.1 + +install-doc: doc + install -d $(DESTDIR)$(DOCPREFIX) + install -m 644 doc/dbus-java.dvi $(DESTDIR)$(DOCPREFIX) + install -m 644 doc/dbus-java.ps $(DESTDIR)$(DOCPREFIX) + install -m 644 doc/dbus-java.pdf $(DESTDIR)$(DOCPREFIX) + install -d $(DESTDIR)$(DOCPREFIX)/dbus-java + install -m 644 doc/dbus-java/*.html $(DESTDIR)$(DOCPREFIX)/dbus-java + install -m 644 doc/dbus-java/*.css $(DESTDIR)$(DOCPREFIX)/dbus-java + install -d $(DESTDIR)$(JAVADOCPREFIX)/api + cp -a doc/api/* $(DESTDIR)$(JAVADOCPREFIX)/api + +dist: .dist +.dist: $(DISTFILES) + mkdir -p dbus-java-$(VERSION) + cp -fa $^ dbus-java-$(VERSION) + touch .dist +tar: dbus-java-$(VERSION).tar.gz + +distclean: + rm -rf dbus-java-$(VERSION) + rm -rf dbus-java-$(VERSION).tar.gz + rm -f .dist + +libdbus-java-$(VERSION): .dist + +dbus-java-$(VERSION).tar.gz: .dist + tar zcf $@ dbus-java-$(VERSION) +dbus-java-$(VERSION).zip: .dist + zip -r $@ dbus-java-$(VERSION)/ + +dbus-java-$(RELEASEVERSION).tar.gz: $(DISTFILES) + mkdir -p dbus-java-$(RELEASEVERSION)/ + cp -fa $^ dbus-java-$(RELEASEVERSION)/ + tar zcf $@ dbus-java-$(RELEASEVERSION) + +dbus-java-win-$(VERSION).zip: dbus-java-bin-$(VERSION).jar libdbus-java-$(VERSION).jar win/CreateInterface.bat win/DBusDaemon.bat win/DBusViewer.bat win/ListDBus.bat $(JAVAUNIXJARDIR)/hexdump.jar $(JAVAUNIXJARDIR)/debug-$(DEBUG).jar dbus-java-viewer-$(VERSION).jar win/DBusCall.bat + mkdir -p dbus-java-win-$(VERSION) + cp -fa dbus-java-bin-$(VERSION).jar dbus-java-win-$(VERSION)/dbus-bin.jar + cp -fa dbus-java-viewer-$(VERSION).jar dbus-java-win-$(VERSION)/dbus-viewer.jar + cp -fa libdbus-java-$(VERSION).jar dbus-java-win-$(VERSION)/dbus.jar + cp -fa win/* dbus-java-win-$(VERSION)/ + cp -faL $(JAVAUNIXJARDIR)/hexdump.jar dbus-java-win-$(VERSION)/ + cp -faL $(JAVAUNIXJARDIR)/debug-$(DEBUG).jar dbus-java-win-$(VERSION)/ + zip -r $@ dbus-java-win-$(VERSION)/ diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/README b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/README new file mode 100755 index 0000000..9c88f8c --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/README @@ -0,0 +1,32 @@ +D-Bus Java README +----------------- + +Compilation and installation is described in the INSTALL file. + +This will install two jar files, three binaries and some documentation in the +form of an HTML/PDF guide to writing D-Bus Java programs, JavaDoc API for the +library and man pages for the supplied programs. Read the documentation, it's +there for a reason. + +The installed programs are documented in their respective man pages. + +CreateInterface is a tool for creating interface stubs for D-Bus programs. It +will connect to services running on the bus and introspect on them to find +their API. This will then be written as Java interface definitions suitable for +importing into your program. A file containing the introspection data can be +used instead. + +ListDBus lists the names currently connected to a bus. + +DBusViewer is a graphical tool which combines the two tools. It will list the +names on a bus and allow you to introspect on them and save the result as Java +interface files. This currently only introspects on the root object, however. + +To run a Java program using D-Bus you need to have the libdbus-java, +libunix-java and libdebug jar files in your classpath and the libunix-java +shared library in your library path. With the default install paths you may +have to do something like: + +java -cp /usr/local/share/java/dbus.jar:/usr/local/share/java/unix.jar:/usr/local/share/java/debug-disable.jar -Djava.library.path=/usr/local/lib/jni + + diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/changelog b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/changelog new file mode 100755 index 0000000..f3675f7 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/changelog @@ -0,0 +1,342 @@ +Version 2.7: + + * Fix bug in disconnected signal/exception handling (Spotted by Serkan Kaba + <serkan_kaba -at- yahoo -dot- com>) + * Fix bug in empty signals (Spotted by Daniel Wagner <Daniel -dot- Wagner + -at- bmw-carit -dot- de>) + * Fix bug in maps containing complex types (Spotted by Tim Court <tim -dot- + court -at- venture3systems -dot- com>) + * Fix signal handling bug in DBusDaemon (Spotted by Markus Gaebelein + <Markus -dot- Gaebelein -at- fiducia -dot- de>) + * Make MessageReader/Writer use Buffered streams to try and improve + performance + * Support reading session bus address from file in $HOME + * Fix TCP cookie timestamp problems (Report/fix from Johannes Felten + <johannesfelten -at- googlemail -dot- com>) + * Add handleError() method to callbacks (breaks backwards source compatibility) + +Version 2.6: + + * Add DBusConnection.releaseBusName API + * Add DBusConnection.PeerSet for tracking peer lifetimes + * Fix bug where DBusDaemon never sends NameOwnerChanged/NameLost + signals + * Patches from Omair Majid <omajid -at- redhat -dot- com> to fix + DBusCall manpage and allow alternative docbook-to-man implementations. + * Fix dependency on unix.jar even in tcp mode + * Fix Path/ObjectPath cast issues (reported by Greg DeAngelis + <gdeangel -at- gmail -dot- com>) + * Fix behavior when disconnected (spotted by Christopher + Armstrong <carmstrong -at- fastmail -dot- com -dot- au>) + +Version 2.5.1: + + * Fix for possible NPex in DBusDaemon + * Add hexdump.jar to Class-Path for libdbus-java.jar + * Add GetAll to properties interface (Patch from + Sveinung Kvilhaugsvik <sveinung84 -at- users -dot- sourceforge -dot- net>) + * Make signals with renamed interfaces and member names work + if they are explicitly listened for (Partially fixes: #18257). + Also make the error reporting better when it doesn't work. + * Add test for signal with renamed interface. + * Fix clearing of string buffer during marshalling (Fixes: #17362) + * Fix array marshalling bug (Fixes: #13291) + +Version 2.5: + + * Patch from Omair Majid <omajid -at- redhat -dot- com> to + have seperate javadoc installation directory + * Patch from Omair Majid <omajid -at- redhat -dot- com> to + have make all build the manpages. + * ... but as serkan_kaba requested, also provide a bin target which doesn't + * Fix returning DBusSerializables (Spotted by Johannes Felten + <johannesfelten -at- googlemail -dot- com>) + * Fix CreateInterface (Spotted by Tom Walsh <walshtc -at- gmail -dot- com>) + * Fix serial assignment race condition (Spotted by Ed Wei + <Edward.Wei.03 -at- alum -dot- dartmouth -dot- org>) + * Fix dynamic introspection of objects which export the same + interface multiple times (Patch from Sveinung Kvilhaugsvik + <sveinung84 -at- users -dot- sourceforge -dot- net>) + * Fix CreateInterface to mangle names which are reserved words + (Spotted by Sveinung Kvilhaugsvik <sveinung84 -at- users -dot- + sourceforge -dot- net>) + * Fix DBusDaemon to not crash on bad tcp connections (Patch from + Hugues Moreau <hmoreau -at- gmail -dot- com>) + * Relicence to LGPL or AFL. + +Version 2.4: + + * Add DBusMemberName to force method names or signal names to something + other than the Java name (suggested by Viktar Vauchkevich <vctr -at- + yandex -dot- ru>) + * Don't respond to Introspect/Ping except on the right interface + (pointed out by Serkan Kaba <serkan_kaba -at- yahoo -dot- com>) + * Automatically unexport objects which go out of scope in the + parent program (don't hold a strong reference). This is now + optional and not the default for 1. sanity and 2. a possible + bug in the WeakReference workings in Sun. + * Add fallback objects---a single object can be called for any + object under a given path prefix. + * Add support for localization of strings via gettext. + * Throw a nicer error when signals are not declared as part of an + interface. + * .viewerclasses needs to depend on .binclasses + * Use libunixsocket-java support for writing multiple byte arrays at + once to write message vectors + * check that the unix-socket-received uid matches for connections to + DBusDaemon + * Update to use libunixsocket-java syntax which works on BSDs + * Fix utf-8 characters used in test to actually be the same character... + * Add code to preallocate the buffer array array (Suggested by Adam + Bennett <cruxic -at- gmail -dot- com>) + * Fix warnings when building with gcj (fixes a bug in Peer handling and + DBusSerializable handling) + +Version 2.3.2: + + * Fix empty array/map bug (reported by Jan Kümmel + <freedesktop -at- snorc -dot- org>) + * Add licence headers to files missing them + * Fix minor bug in AbstractConnection.java (reported by Frank Benoit + <benoit -at- tionex -dot- de>) + * Make Marshalling more verbose and descriptive in the presence of + mismatched parameter lists (suggested by Anibal Sanchez + <anibal -dot- sanchez -at- sunya -dot- com -dot- ar>) + * Fix struct type parsing error (spotted by Gunnar Aastrand Grimnes + <gunnar -dot- grimnes -at- dfki -dot- de> and Frank Benoit + <keinfarbton -at- googlemail -dot- com>) + * Fix parsing of serializable classes + * Anonymous SASL (needs testing) + +Version 2.3.1: + + * Fix regression in normal array handling (spotted by Anibal Sanchez + <anibal -dot- sanchez -at- sunya -dot- com -dot- ar>) + +Version 2.3: + + * Apply recursive-path patch for DBusViewer (written by Zsombor Gegesy + <gzsombor -at- gmail -dot- com>) + * Add Class-Path to jar manifests + * Update documentation for nested classes + * Documentation build fix + * Add test for arrays-of-structs + * Fix arrays-of-structs bug (spotted by Daniel Machado + <cdanielmachado -at- gmail -dot- com>) + * Fix bashism in Makefile + * add DBusInterfaceName annotation to override the Java interface name as + the name exported on the bus. + +Version 2.2: + + * Fix cross-test to pass. + * Fix DBusViewer.sh *again* (Spotted by Serkan Kaba <serkan_kaba + -at- yahoo -dot- com>) + * Add DBusCall + * fix CreateInterface to put DBusException in the right package in import + statements. Spotted by Steve Crane <Steve -dot- Crane -at- rococosoft + -dot- com> + * Update Cross-test to new spec + * Change casting and return types for get{Peer,}RemoteObject calls to + use generics so you don't need explicit casts on return types. + Suggested by Philippe Marschall <philippe -dot- marschall -at- gmail + -dot- com>. + * Test with multiple requested (same actual) connection + * Add async-with-callback API. + +Version 2.1: + + * make scripts with $JAVA + * fix DBusViewer.sh (Spotted by Luigi Paioro <luigi -at- lambrate -dot- + inaf -dot- it> + +Version 2.0: + + * Remove libdbus-1 dependency and talk the wire protocol directly + * Add dependency on http://www.matthew.ath.cx/projects/java/ unix, debug + and hexdump libraries + * API changes: + * Exceptions (including DBusException and DBusExecutionException) moved + to the org.freedesktop.dbus.exceptions package. + * Convert/deserialize and dbus<->java type conversion code moved from + org.freedesktop.dbus.DBusConnection to org.freedesktop.dbus.Marshalling. + * Types moved to the org.freedesktop.dbus.types package. + * All message metadata methods have been moved to the superclass and + getObjectPath() has been renamed to getPath(). + * Deprecated method registerService has been removed. + * getUniqueName() and getNames() methods added to get the bus names + associated with this connection. + * Access to the low-level API added. + * Change all documentation to refer to 'implementation' not 'binding' + * Add peer 2 peer support with DirectConnection class + * add peer to peer test + * split some code from DBusConnection into common super-class + AbstractConnection + * Support float ('f') type with tests + * Degrade floats to doubles when DBUS_JAVA_FLOATS is not set + * add DBus.Peer interface to standard introspection data + * Document peer to peer and low level. + * Fix TCP and SHA-1 auth + * fix wrapper scripts with new depends + * add a DBusDaemon + * Make daemon multithreaded; performance improvements + * Add sending thread to library, move to blocking IO + * Ensure key directory exists when serving cookie auth + * Add TCP support to daemon + * Remove dependency on dbus-daemon for tests + * add --version support for other programs + * Add windows wrapper scripts + * Test working on Windows + * Add makefile target to build zip file for windows + * Add windows compile script + * DBusDaemon can generate random TCP ports to listen on + +Version 1.13: + + * add AccessDenied signal + * fix deadlock issue when sending objectpaths in signals, spotted by Mathis + * add Path type which can be used for non-auto OBJECT_PATH handling, spotted by Mathis + * fix some freebsd build issues: + * remove explicit recursive make calls + * parameterize /usr/lib as DBUSLIBDIR + Spotted by Roberto Francisco Arroyo Moreno <robfram -at- ugr -dot- es> + * rejig build system to replace variables in wrapper in make stage and + use DESTDIR properly, hence removing the RUNPREFIX stuff. + * add checks and documentation for DBusInterfaces not being in a package. + Spotted by Henrik Petander <henrik -dot- petander -at- iki -dot- fi> + +Version 1.12: + + * fix internal-cross-test bugs and increase error verbosity + * add org.freedesktop.DBus.Error.NoReply, change to that from my own + * add -pedantic -std=c99 flags to GCC + * remove supplied Hal classes as they are out of date + * change to using tex4ht rather than latex2html + +Version 1.11: + + * fix script replacement directories to be different to install directories + * split install-doc and install-man to allow easy split -doc package + +Version 1.10: + + * fix URLs to point to fdo + * check for signal path validity in Java + * fix NameAcquired spelling + * check array lengths and name lengths + * support method calls with empty interfaces + * support for non-activating remote objects + * remove errant debug statemant left in 1.9 + * Fix List<List<Integer>> bug spotted by Remi Emonet + <remi.emonet -at- inrialpes -dot- fr> + * Fix OBJECT_PATH handling; bug spotted by Remi Emonet + <remi.emonet -at- inrialpes -dot- fr> + * added getRemoteObject and getPeerRemoteObject methods with + introspection support to guess interfaces. + * changed introspection to recurse over the exported object tree + and show sub-objects. + * compare maps unordered in tests; spotted by Simon McVittie + <simon -dot- mcvittie -at- collabora -dot- co -dot- uk> + * implement UInt64 with BigInteger to allow full-range UInt64s + * fix $ in introspection data for nested interfaces + * fix the required dbus version in the docs + * can now send DBUS_TYPE_SIGNATURE as Type[] + * rewrite Variant handling to work with complex types + * add $JAVA_HOME/include and $JAVA_HOME/include/linux to CFLAGS + (Fix from Joshua Nichols <nichoj -at- gentoo -dot- org>) + * remove unneccessary build warnings + (Fix from Joshua Nichols <nichoj -at- gentoo -dot- org>) + * seperate install and install-doc targets + (Suggested by Ralf Kistner <ralf.kistner -at- gmail -dot- com>) + * add -fno-stack-protector flag (only for gcc 4.1 or later) + (Suggested by Ralf Kistner <ralf.kistner -at- gmail -dot- com>) + * Revamp tuples + * Build without DBUS_API_SUBJECT_TO_CHANGE set + * fix LDFLAGS to work properly with --as-needed + (Suggested by TFKyle) + * Update CreateInterface to new API + * More speed fixes with type introspection + * Add README and INSTALL files + * Change wrappers to point to installed locations + +Version 1.9: + + * Map and List handling optimisations + * Struct optimisations + * Canonicalise D-Bus spelling in documentation + * Update documentation + * Implement cross-bindings test suite + * add getPeerRemoteObject method + * add addSigHandler methods which filter on sender and path + * Signal handling optimisations + * deprecating service in favour of bus name. Deprecated registerService in + favour of requestBusName + +Version 1.8: + + * stop dvips printing on wierd systems + * Doc patches from Dick Hollenbeck <dick -at- softplc -dot- com> + * reduce TIMEOUT to 1ms and check for outbound messages in the JNI; reduces + RTT from 100ms to ~1ms + * Remove two java collections which were doing a lot of allocation and + deallocation and replace with data structures based on arrays. + * add removeSigHandler method + * add profiling application + * handle incoming & outgoing native array types natively (biiiig savings + here) + +Version 1.7: + + * compiles with -Xlint:all + * fixed struct/nested struct creation + * compile with -Os -O -Wall -Werror -g:none and strip + * allow overloading methods by argument type + * getJavaType bugfix from Antoine Perdaens + * nulls in Variant fix from Antoine Perdaens + * Variant parameter checking in <init> + * CreateInterface now maintains order of parameters to signals + +Version 1.6: + + * Custom serializable objects + * Thread pool model + * CreateInterfaces updated to handle new Structs, annotations, Signals etc + +Version 1.5: + + * Remove static library dependency + +Version 1.4: + + * provide call info to called methods + * check for disconnections and throw + * complete rewrite of Structs + * add message send/receive debugging + +Version 1.3: + + * Annotation and throws support + * proper noreply support + * asynchronous method call support + * strip InternalErrorMessage reference from JNI + +Version 1.2: + + * Make sure pending messages are sent on disconnect + * Import of viewer application (Peter Cox <petercox -at- gawab -dot- com>) + * Make CreateInterface usable in other apps. + * Import extra functions that weren't documented into DBus.java + * Implement throwing and catching of specific exception types + +Version 1.1: + + * Fix connections to multiple busses + * Allow connections by bus address + * Stricter error checking in looking up connection object + +Version 1.0: + + * 1.x is a java 1.5 version, 0.x is a java 1.4 version + * introspect on the root object + * support for nested nodes in CreateInterface + diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/compile.bat b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/compile.bat new file mode 100755 index 0000000..92099f0 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/compile.bat @@ -0,0 +1,17 @@ +@echo off
+setlocal
+REM set to true for debug builds
+set debug=disable
+REM set to empty for debug builds
+set jcflags=-O -g:none -Xlint:all +REM set to the location you installed unix.jar, debug-*.jar and hexdump.jar
+set jarpath=
+REM set to the Java installation location
+REM set JAVA_HOME=
+
+%JAVA_HOME%\bin\javac -cp .;%jarpath%unix.jar;%jarpath%debug-%debug%.jar;%jarpath%hexdump.jar;%CLASSPATH% %jcflags% org\freedesktop\*.java org\freedesktop\dbus\*.java org\freedesktop\dbus\bin\*.java org\freedesktop\dbus\exceptions\*.java org\freedesktop\dbus\types\*.java org\freedesktop\dbus\viewer\*.java
+%JAVA_HOME%\bin\jar -cf dbus.jar org\freedesktop\*.class org\freedesktop\dbus\*.class org\freedesktop\dbus\exceptions\*.class org\freedesktop\dbus\types\*.class
+%JAVA_HOME%\bin\jar -cf dbus-bin.jar org\freedesktop\dbus\bin\*.class
+%JAVA_HOME%\bin\jar -cf dbus-viewer.jar org\freedesktop\dbus\viewer\*.class
+
+endlocal diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/dbus-java.tex b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/dbus-java.tex new file mode 100755 index 0000000..980a77b --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/dbus-java.tex @@ -0,0 +1,1266 @@ +\documentclass[a4paper,12pt]{article} + +% +% D-Bus Java Implementation +% Copyright (c) 2005-2006 Matthew Johnson +% +% This program is free software; you can redistribute it and/or modify it +% under the terms of either the GNU Lesser General Public License Version 2 or the +% Academic Free Licence Version 2.1. +% +% Full licence texts are included in the COPYING file with this program. +% + +\usepackage{fullpage} +\usepackage{ifthen} + +\ifx\pdfoutput\undefined + \usepackage{hyperref} +\else + \usepackage[ + bookmarks, + bookmarksopen, + bookmarksnumbered=false, + colorlinks, + pdfpagemode=None, + urlcolor=black, + citecolor=black, + linkcolor=black, + pagecolor=black, + plainpages=false, + pdfpagelabels, + ]{hyperref} +\fi + +\author{Matthew Johnson\\dbus@matthew.ath.cx} +\title{D-Bus programming in Java 1.5} + +\begin{document} + +\def\javadocroot/{http://dbus.freedesktop.org/doc/dbus-java/api/} + +\maketitle + +\tableofcontents +\listoffigures +\listoftables + +\section{Introduction} + +This document describes how to use the Java implementation of D-Bus. D-Bus is +an IPC mechanism which at a low level uses message passing over Unix Sockets or +IP. D-Bus models its messages as either function calls on remote objects, or +signals emitted from them. + +Java is an object-oriented language and this implementation attempts to match +the D-Bus IPC model to the Java object model. The implementation also make +heavy use of threads and exceptions. The programmer should be careful to take +care of synchronisation issues in their code. All method calls by remote +programs on exported objects and all signal handlers are run in new threads. +Any calls on remote objects may throw {\tt DBusExecutionException}, which is a +runtime exception and so the compiler will not remind you to handle it. + +The Java D-Bus API is also documented in the JavaDoc\footnote{\url{\javadocroot/}}, +D-Bus is described in the +specification\footnote{http://dbus.freedesktop.org/doc/dbus-specification.html} +and the API documentation\footnote{http://dbus.freedesktop.org/doc/api/html/}. + +\subsection{Protocol Implementation} + +This library is a native Java implementation of the D-Bus protocol and not +a wrapper around the C reference implementation. + +\subsection{Dependencies} + +This library requires Java 1.5-compatible VM and compiler (either Sun, or +ecj+jamvm with classpath-generics newer than 0.19) and the unix socket, debug +and hexdump libraries from \url{http://www.matthew.ath.cx/projects/java/}. + +\subsection{D-Bus Terminology} + +D-Bus has several notions which are exposed to the users of the Java +implementation. + +\subsubsection{Bus Names} + +Programs on the bus are issued a unique identifier by the bus. This +is guaranteed to be unique within one run of the bus, but is +assigned sequentially to each new connection. + +There are also so called well-known bus names which a device can +request on the bus. These are of the form {\em ``org.freedesktop.DBus''}, +and any program can request them if they are not already owned. + +\subsubsection{Interfaces} + +All method calls and signals are specified using an interface, +similar to those in Java. When executing a method or sending a +signal you specify the interface the method belongs to. These are of +the form {\em ``org.freedesktop.DBus''}. + +\subsubsection{Object Paths} + +A program may expose more than one object which implements an +interface. Object paths of the form {\em ``/org/freedesktop/DBus''} +are used to distinguish objects. + +\subsubsection{Member Names} + +Methods and Signals have names which identify them within an +interface. D-Bus does not support method overloading, only one +method or signal should exist with each name. + +\subsubsection{Errors} + +A reply to any message may be an error condition. In which case you reply with +an error message which has a name of the form {\em + ``org.freedesktop.DBus.Error.ServiceUnknown''}. + +\section{DBusConnection} + +The {\tt +DBusConnection\footnote{\url{\javadocroot/org/freedesktop/dbus/DBusConnection.html}}} +class provides methods for connecting to the bus, exporting objects, +sending signals and getting references to remote objects. + +{\tt DBusConnection} is a singleton class, multiple calls to {\tt +getConnection} will return the same bus connection. + +\begin{verbatim} +conn = DBusConnection.getConnection(DBusConnection.SESSION); +\end{verbatim} + +This creates a connection to the session bus, or returns the +existing connection. + +\begin{verbatim} +conn.addSigHandler(TestSignalInterface.TestSignal.class, + new SignalHandler()); +\end{verbatim} + +This sets up a signal handler for the given signal type. +SignalHandler.handle will be called in a new thread with an instance +of TestSignalInterface.TestSignal when that signal is recieved. + +\begin{verbatim} +conn.sendSignal(new TestSignalInterface.TestSignal( + "/foo/bar/com/Wibble", + "Bar", + new UInt32(42))); +\end{verbatim} + +This sends a signal of type {\tt TestSignalInterface.TestSignal}, +from the object {\em ``/foo/bar/com/Wibble''} with the arguments {\em +``Bar''} and {\tt UInt32(42)}. + +\begin{verbatim} +conn.exportObject("/Test", new testclass()); +\end{verbatim} + +This exports the {\tt testclass} object on the path {\em ``/Test''} + +\begin{verbatim} +Introspectable intro = (Introspectable) conn.getRemoteObject( + "foo.bar.Test", "/Test", + Introspectable.class); +\end{verbatim} + +This gets a reference to the {\em ``/Test''} object on the process with the +name {\em ``foo.bar.Test''} . The object implements the {\tt Introspectable} +interface, and calls may be made to methods in that interface as if it was a +local object. + +\begin{verbatim} +String data = intro.Introspect(); +\end{verbatim} + +The Runtime Exception {\tt DBusExecutionException} may be thrown +by any remote method if any part of the execution fails. + +\subsection{Asynchronous Calls} + +Calling a method on a remote object is synchronous, that is the thread will +block until it has a reply. If you do not want to block you can use an +asynchronous call. + +There are two ways of making asynchronous calls. You can either call the {\tt +callMethodAsync} function on the connection object, in which case you are +returned a {\tt +DBusAsyncReply\footnote{\url{\javadocroot/org/freedesktop/dbus/DBusAsyncReply.html}}} +object which can be used to check for a reply and get the return value. This +is demonstrated in figure \ref{fig:async}. + +\begin{figure}[htb] +\begin{center} +\begin{verbatim} +DBusAsyncReply<Boolean> stuffreply = + conn.callMethodAsync(remoteObject, "methodname", arg1, arg2); +... +if (stuffreply.hasReply()) { + Boolean b = stuffreply.getReply(); + ... +} +\end{verbatim} +\end{center} +\caption{Calling an asynchronous method} +\label{fig:async} +\end{figure} + +Alternatively, you can register a callback with the connection using the {\tt +callWithCallback} function on the connection object. In this case, your +callback class (implementing the {\tt +CallbackHandler\footnote{\url{\javadocroot/org/freedesktop/dbus/CallbackHandler.html}}} +interface will be called when the reply is returned from the bus. + +\section{DBusInterface} + +To call methods or expose methods on D-Bus you need to define them with their +exact signature in a Java interface. The full name of this interface must be +the same as the D-Bus interface they represent. In addition, D-Bus interface +names must contain at least one period. This means that DBusInterfaces cannot +be declared without being in a package. + +For example, if I want to expose methods on the interface {\em +``org.freedesktop.DBus''} I would define a Java interface in the package {\tt +org.freedesktop} called {\tt DBus}. This would be in the file {\tt +org/freedesktop/DBus.java} as normal. Any object wanting to export these +methods would implement {\tt org.freedesktop.DBus}. + +Any interfaces which can be exported over D-Bus must extend {\tt +DBusInterface\footnote{\url{\javadocroot/org/freedesktop/dbus/DBusInterface.html}}}. +A class may implement more than one exportable interface, all public methods +declared in an interface which extend {\tt DBusInterface} will be exported. + +A sample interface definition is given in figure~\ref{fig:interface}, and a +class which implements it in figure~\ref{fig:class}. More complicated +definitions can be seen in the test +classes\footnote{\url{\javadocroot/org/freedesktop/dbus/test/TestRemoteInterface2.java} +\url{\javadocroot/org/freedesktop/dbus/test/TestRemoteInterface.java}}. + +All method calls by other programs on objects you export over D-Bus +are executed in their own thread. + +{\tt DBusInterface} itself specifies one method \verb&boolean isRemote()&. If +this is executed on a remote object it will always return true. Local objects +implementing a remote interface must implement this method to return false. + +\begin{figure}[htb] +\begin{center} +\begin{verbatim} +package org.freedesktop; +import org.freedesktop.dbus.UInt32; +import org.freedesktop.dbus.DBusInterface; + +public interface DBus extends DBusInterface +{ + public boolean NameHasOwner(String name); + public UInt32 RequestName(String name, UInt32 flags); +} +\end{verbatim} +\end{center} +\caption{An interface which exposes two methods} +\label{fig:interface} +\end{figure} + +\begin{figure}[htb] +\begin{center} +\begin{verbatim} +package my.real.implementation; +import org.freedesktop.dbus.DBus; +import org.freedesktop.dbus.UInt32; + +public class DBusImpl implements DBus +{ + Vector<String> names; + public boolean NameHasOwner(String name) + { + if (names.contains(name)) return true; + else return false; + } + public UInt32 RequestName(String name, UInt32 flags) + { + names.add(name); + return new UInt32(0); + } + public boolean isRemote() { return false; } +} +\end{verbatim} +\end{center} +\caption{A class providing a real implementation which can be exported} +\label{fig:class} +\end{figure} + +\subsection{Interface name overriding} + +It is highly recommended that the Java interface and package name match the +D-Bus interface. However, if, for some reason, this is not possible then the +name can be overridden by use of an Annotation. + +To override the Java interface name you should add an annotation to the +interface of {\tt +DBusInterfaceName\footnote{\url{\javadocroot/org/freedesktop/dbus/DBusInterfaceName.html}}} +with a value of the desired D-Bus interface name. An example of this can be seen in +figure \ref{fig:interfacename}. + +\begin{figure}[htb] +\begin{center} +\begin{verbatim} +package my.package; +import org.freedesktop.dbus.DBusInterface; +import org.freedesktop.dbus.DBusInterfaceName; + +@DBusInterfaceName("my.otherpackage.Remote") +public interface Remote extends DBusInterface +{ + ... +} +\end{verbatim} +\end{center} +\caption{Overloading the name of an interface.} +\label{fig:interfacename} +\end{figure} + +If you have signals which are declared in a renamed interface (see below for +signals) then when adding a signal handler you {\em must} use an {\tt +addSigHandler} method which takes a class object corresponding to that signal. +If you do not then receiving the signal will fail. + +\section{DBusSignal} + +Signals are also declared as part of an interface. The Java API models these as +inner classes within an interface. The containing interface must extend {\tt +DBusInterface}, and the inner classes representing the signals must extend {\tt +DBusSignal\footnote{\url{\javadocroot/org/freedesktop/dbus/DBusSignal.html}}}. +The Signal name is derived from the name of this inner class, and the interface +from its containing interface. + +Signals can take parameters as methods can (although they cannot return +anything). For the reflection to work, a Signal declare a single constructor of +the correct type. The constructor must take the object path they are being +emitted from as their first (String) argument, followed by the other parameters +in order. They must also call the superclass constructor with the same +parameters. A full definition of a signal can be seen in +figure~\ref{fig:signal}. Again, more complicated definitions are available in +the test +classes\footnote{\url{\javadocroot/org/freedesktop/dbus/test/TestSignalInterface.html}}. + +\begin{figure}[htb] +\begin{center} +\begin{verbatim} +package org.freedesktop; +import org.freedesktop.dbus.DBusInterface; +import org.freedesktop.dbus.DBusSignal; +import org.freedesktop.dbus.exceptions.DBusException; + +public interface DBus extends DBusInterface +{ + public class NameAcquired extends DBusSignal + { + public final String name; + public NameAcquired(String path, String name) + throws DBusException + { + super(path, name); + this.name = name; + } + } +} +\end{verbatim} +\end{center} +\caption{A Signal with one parameter} +\label{fig:signal} +\end{figure} + +\section{DBusExecutionException} + +If you wish to report an error condition in a method call you can throw an +instance of {\tt +DBusExecutionException\footnote{\url{\javadocroot/org/freedesktop/dbus/DBusExecutionException.html}}}. +This will be sent back to the caller as an error message, and the error name is +taken from the class name of the exception. For example, if you wanted to +report an unknown method you would define an exception as in figure +\ref{fig:exceptiondef} and then throw it in your method as in figure +\ref{fig:exceptioncall}. + +\begin{figure}[htb] +\begin{center} +\begin{verbatim} +package org.freedesktop.DBus.Error; +import org.freedesktop.dbus.exceptions.DBusExecutionException; + +public class UnknownMethod extends DBusExecutionException +{ + public UnknownMethod(String message) + { + super(message); + } +} +\end{verbatim} +\end{center} +\caption{An Exception} +\label{fig:exceptiondef} +\end{figure} + +\begin{figure}[htb] +\begin{center} +\begin{verbatim} +... +public void throwme() throws org.freedesktop.DBus.Error.UnknownMethod +{ + throw new org.freedesktop.DBus.Error.UnknownMethod("hi"); +} +... +\end{verbatim} +\end{center} +\caption{Throwing An Exception} +\label{fig:exceptioncall} +\end{figure} + +If you are calling a remote method and you want to handle such an error you can +simply catch the exception as in figure \ref{fig:exceptioncatch}. + +\begin{figure}[htb] +\begin{center} +\begin{verbatim} +... +try { + remote.throwme(); +} catch (org.freedesktop.DBus.Error.UnknownMethod UM) { + ... +} +... +\end{verbatim} +\end{center} +\caption{Catching An Exception} +\label{fig:exceptioncatch} +\end{figure} + +\section{DBusSigHandler} + +To handle incoming signals from other programs on the Bus you must register a +signal handler. This must implement {\tt +DBusSigHandler\footnote{\url{\javadocroot/org/freedesktop/dbus/DBusSigHandler.html}}} +and provide an implementation for the handle method. An example Signal Handler +is in figure~\ref{fig:handler}. Signal handlers should be parameterised with +the signal they are handling. If you want a signal handler to handle multiple +signals you can leave out the parameterisation and use {\tt instanceof} to +check the type of signal you are handling. Signal handlers will be run in their +own thread. + +\begin{figure}[htb] +\begin{center} +\begin{verbatim} +import org.freedesktop.dbus.DBusSignal; +import org.freedesktop.dbus.DBusSigHandler; + +public class Handler extends DBusSigHandler<DBus.NameAcquired> +{ + public void handle(DBus.NameAcquired sig) + { + ... + } +} +\end{verbatim} +\end{center} +\caption{A Signal Handler} +\label{fig:handler} +\end{figure} + + +\section{D-Bus Types} + +D-Bus supports a number of types in its messages, some which Java +supports natively, and some which it doesn't. This library provides +a way of modelling the extra D-Bus Types in Java. The full list of +types and what D-Bus type they map to is in table \ref{table:types}. + +\subsection{Basic Types} + +All of Java's basic types are supported as parameters and return types to methods, and as parameters to signals. These can be used in either their primitive or wrapper types. + +\subsubsection{Unsigned Types} + +D-Bus, like C and similar languages, has a notion of unsigned numeric +types. The library supplies {\tt +UInt16\footnote{\url{\javadocroot/org/freedesktop/dbus/UInt16.html}}}, {\tt +UInt32} and {\tt UInt64} classes to represent these new basic types. + +\subsection{Strings} + +D-Bus also supports sending Strings. When mentioned below, Strings +count as a basic type. + +\subsubsection{String Comparisons} + +There may be some problems with comparing strings received over D-Bus with +strings generated locally when using the String.equals method. This is due to +how the Strings are generated from a UTF8 encoding. The recommended way to +compare strings which have been sent over D-Bus is with the {\tt +java.text.Collator} class. Figure \ref{fig:collator} demonstrates its use. + +\begin{figure}[htb] +\begin{center} +\begin{verbatim} +String rname = remote.getName(); +Collator col = Collator.getInstance(); +col.setDecomposition(Collator.FULL_DECOMPOSITION); +col.setStrength(Collator.PRIMARY); +if (0 != col.compare("Name", rname)) + fail("getName return value incorrect"); +\end{verbatim} +\end{center} +\caption{Comparing strings with {\tt java.text.Collator}.} +\label{fig:collator} +\end{figure} + +\subsection{Arrays} + +You can send arrays of any valid D-Bus Type over D-Bus. These can either be +declared in Java as arrays (e.g. \verb&Integer[]& or \verb&int[]&) or as Lists +(e.g. \verb&List<String>&). All lists {\bf must} be parameterised with their +type in the source (reflection on this is used by the library to determine +their type). Also note that arrays cannot be used as part of more complex type, +only Lists (for example \verb&List<List<String>>&). + +\subsection{Maps} + +D-Bus supports a dictionary type analogous to the Java Map type. This +has the additional restriction that only basic types can be used as +the key (including String). Any valid D-Bus type can be the value. As +with lists, maps must be fully parameterised. (e.g. +\verb&Map<Integer, String>&). + +\subsection{Variants} + +D-Bus has support for a Variant type. This is similar to declaring that a +method takes a parameter of type {\tt Object}, in that a Variant may contain +any other type. Variants can either be declared using the {\tt +Variant\footnote{\url{\javadocroot/org/freedesktop/dbus/Variant.html}}} class, or as +a Type Variable. In the latter case the value is automatically unwrapped and +passed to the function. Variants in compound types (Arrays, Maps, etc) must be +declared using the Variant class with the full type passed to the Variant +constructor and manually unwrapped. + +Both these methods use variants: + +\begin{verbatim} +public void display(Variant v); +public <T> int hash(T v); +\end{verbatim} + +\subsection{Structs} + +D-Bus has a struct type, which is a collection of other types. Java +does not have an analogue of this other than fields in classes, and +due to the limitation of Java reflection this is not sufficient. The +library declares a {\tt +Struct\footnote{\url{\javadocroot/org/freedesktop/dbus/Struct.html}}} class which can be used to create structs. +To define a struct you extend the {\tt Struct} class and define fields for each member of the struct. +These fields then need to be annotated in the order which they appear in the struct (class fields do not have a defined order). You must also define a single constructor which takes the contents of he struct in order. This is best demonstrated by an example. +Figure~\ref{fig:struct} shows a Struct definition, and +figure~\ref{fig:structmethod} shows this being used as a parameter +to a method. + +\begin{figure}[htb] +\begin{center} +\begin{verbatim} +package org.freedesktop.dbus.test; + +import org.freedesktop.dbus.DBusException; +import org.freedesktop.dbus.Position; +import org.freedesktop.dbus.Struct; + +public final class TestStruct extends Struct +{ + @Position(0) + public final String a; + @Position(1) + public final int b; + @Position(2) + public final String c; + public Struct3(String a, int b, String c) + { + this.a = a; + this.b = b; + this.c = c; + } +} +\end{verbatim} +\end{center} +\caption{A Struct with three elements} +\label{fig:struct} +\end{figure} + +\begin{figure}[htb] +\begin{center} +\begin{verbatim} +public void do(TestStruct data); +\end{verbatim} +\end{center} +\caption{A struct as a parameter to a method} +\label{fig:structmethod} +\end{figure} + + +Section~\ref{sec:create} describes how these can be automatically +generated from D-Bus introspection data. + +\subsection{Objects} + +You can pass references to exportable objects round using their object paths. +To do this in Java you declare a type of {\tt DBusInterface}. When the library +receive- an object path it will automatically convert it into the object you +are exporting with that object path. You can pass remote objects back to their +processes in a similar fashion. + +Using a parameter of type {\tt DBusInterface} can cause the automatic creation +of a proxy object using introspection. If the remote app does not support +introspection, or the object does not exist at the time you receive the message +then this will fail. In that case the parameter can be declared to be of type +{\tt Path}. In this case no automatic creation will be performed and you can +get the path as a string with either the {\tt getPath} or {\tt toString} methods +on the {\tt Path} object. + + +\subsection{Multiple Return Values} + +D-Bus also allows functions to return multiple values, a concept not supported +by Java. This has been solved in a fashion similar to the struct, using a {\tt +Tuple\footnote{\url{\javadocroot/org/freedesktop/dbus/Tuple.html}}} +class. Tuples are defined as generic tuples which can be parameterised for +different types and just need to be defined of the appropriate length. This can +be seen in figure~\ref{fig:tuple} and a call in figure~\ref{fig:tuplemethod}. +Again, these can be automatically generated from introspection data. + +\begin{figure}[htb] +\begin{center} +\begin{verbatim} +import org.freedesktop.dbus.Tuple; + +public final class TestTuple<A, B, C> extends Tuple +{ + public final A a; + public final B b; + public final C c; + public TestTuple(A a, B b, C c) + { + this.a = a; + this.b = b; + this.c = c; + } +} +\end{verbatim} +\end{center} +\caption{A 3-tuple} +\label{fig:tuple} +\end{figure} + +\begin{figure}[htb] +\begin{center} +\begin{verbatim} +public ThreeTuple<String, Integer, Boolean> status(int item); +\end{verbatim} +\end{center} +\caption{A Tuple being returned from a method} +\label{fig:tuplemethod} +\end{figure} + +\subsection{Full list of types} + +Table \ref{table:types} contains a full list of all the Java types and their corresponding D-Bus types. + +\begin{table} +\begin{center} +\begin{tabular}{l|l} +\bf Java Type & \bf D-Bus Type \\ +\hline +Byte & DBUS\_TYPE\_BYTE \\ +byte & DBUS\_TYPE\_BYTE \\ +Boolean & DBUS\_TYPE\_BOOLEAN \\ +boolean & DBUS\_TYPE\_BOOLEAN \\ +Short & DBUS\_TYPE\_INT16 \\ +short & DBUS\_TYPE\_INT16 \\ +UInt16 & DBUS\_TYPE\_UINT16 \\ +int & DBUS\_TYPE\_INT32 \\ +Integer & DBUS\_TYPE\_INT32 \\ +UInt32 & DBUS\_TYPE\_UINT32 \\ +long & DBUS\_TYPE\_INT64 \\ +Long & DBUS\_TYPE\_INT64 \\ +UInt64 & DBUS\_TYPE\_UINT64 \\ +double & DBUS\_TYPE\_DOUBLE \\ +Double & DBUS\_TYPE\_DOUBLE \\ +String & DBUS\_TYPE\_STRING \\ +Path & DBUS\_TYPE\_OBJECT\_PATH \\ +$<$T$>$ & DBUS\_TYPE\_VARIANT \\ +Variant & DBUS\_TYPE\_VARIANT \\ +? extends Struct & DBUS\_TYPE\_STRUCT \\ +?$[$~$]$ & DBUS\_TYPE\_ARRAY \\ +? extends List & DBUS\_TYPE\_ARRAY \\ +? extends Map & DBUS\_TYPE\_DICT \\ +? extends DBusInterface & DBUS\_TYPE\_OBJECT\_PATH \\ +Type$[$~$]$ & DBUS\_TYPE\_SIGNATURE \\ +\end{tabular} +\end{center} +\caption{Mapping between Java types and D-Bus types} +\label{table:types} +\end{table} + +\subsubsection{float} + +Currently the D-Bus reference implementation does not support a native +single-precision floating point type. Along with the C\# implementation of the +protocol, the Java implementation supports this extension to the protocol. By +default, however, the library operates in compatibility mode and converts all +floats to the double type. To disable compatibility mode export the environment +variable {\tt DBUS\_JAVA\_FLOATS=true}. + +\section{Annotations} + +You can annotate your D-Bus methods as in figure \ref{fig:annotation} to provide hints to other users of your API. Common annotations are listed in table \ref{tab:annotations}. + +\begin{figure}[htb] +\begin{center} +\begin{verbatim} +package org.freedesktop; +import org.freedesktop.dbus.UInt32; +import org.freedesktop.dbus.DBusInterface; + +@org.freedesktop.DBus.Description("Some Methods"); +public interface DBus extends DBusInterface +{ + @org.freedesktop.DBus.Description("Check if the name has an owner") + public boolean NameHasOwner(String name); + @org.freedesktop.DBus.Description("Request a name") + @org.freedesktop.DBus.Deprecated() + public UInt32 RequestName(String name, UInt32 flags); +} +\end{verbatim} +\end{center} +\caption{An annotated method} +\label{fig:annotation} +\end{figure} + + +\begin{table}[htb] +\begin{tabular}{l|l} +{\bf Name} & {\bf Meaning} \\ +\hline +org.freedesktop.DBus.Description & Provide a short 1-line description \\ + & of the method or interface. \\ +org.freedesktop.DBus.Deprecated & This method or interface is Deprecated. \\ +org.freedesktop.DBus.Method.NoReply & This method may be called and returned \\ + & without waiting for a reply. \\ +org.freedesktop.DBus.Method.Error & This method may throw the listed Exception\\ + & in addition to the standard ones. \\ +\end{tabular} +\caption{Common Annotations} +\label{tab:annotations} +\end{table} + +\section{DBusSerializable} + +Some people may want to be able to pass their own objects over D-Bus. Obviously +only raw D-Bus types can be sent on the message bus itself, but the Java +implementation allows the creation of serializable objects which can be passed to +D-Bus functions and will be converted to/from D-Bus types by the library. + +To create such a class you must implement the {\tt +DBusSerializable\footnote{\url{\javadocroot/org/freedesktop/dbus/DBusSerializable.html}}} +class and provide two methods and a zero-argument constructor. The first method +has the signature {\tt public Object\[\] serialize() throws DBusException} and +the second must be called {\tt deserialize}, return {\tt null} and take as it's +arguments exactly all the dbus types that are being serialized to {\em in +order} and {\em with parameterization}. The serialize method should return the +class properties you wish to serialize, correctly formatted for the wire ({\tt +DBusConnection.convertParameters()} can help with this), in order in an Object +array. + +An example of a serializable class can be seen in figure~\ref{fig:serializable}. + + +\begin{figure}[htb] +\begin{center} +\begin{verbatim} +import java.lang.reflect.Type; + +import java.util.List; +import java.util.Vector; + +import org.freedesktop.dbus.DBusConnection; +import org.freedesktop.dbus.DBusSerializable; + +public class TestSerializable implements DBusSerializable +{ + private int a; + private String b; + private Vector<Integer> c; + public TestSerializable(int a, String b, Vector<Integer> c) + { + this.a = a; + this.b = b.toString(); + this.c = c; + } + public TestSerializable() {} + public void deserialize(int a, String b, List<Integer> c) + { + this.a = a; + this.b = b; + this.c = new Vector<Integer>(c); + } + public Object[] serialize() + { + return new Object[] { a, b, c }; + } + public int getInt() { return a; } + public String getString() { return b; } + public Vector<Integer> getVector() { return c; } + public String toString() + { + return "TestSerializable{"+a+","+b+","+c+"}"; + } +} +\end{verbatim} +\end{center} +\caption{A serializable class} +\label{fig:serializable} +\end{figure} + + + +\section{CreateInterface} +\label{sec:create} + +D-Bus provides a method to get introspection data on a remote object, which +describes the interfaces, methods and signals it provides. This introspection +data is in XML +format\footnote{http://dbus.freedesktop.org/doc/dbus-specification.html\#introspection-format}. +The library automatically provides XML introspection data on all objects which +are exported by it. Introspection data can be used to create Java interface +definitions automatically. + +The {\tt +CreateInterface\footnote{\url{\javadocroot/org/freedesktop/dbus/CreateInterface.html}}} +class will automatically create Java source files from an XML file +containing the introspection data, or by querying the remote object +over D-Bus. CreateInterface can be called from Java code, or can be run as a +stand alone program. + +The syntax for the CreateInterface program is + +\begin{verbatim} +CreateInterface [--system] [--session] [--create-files] + <bus name> <object> +CreateInterface [--create-files] <introspection-file.xml> +\end{verbatim} + +The Java source code interfaces will be written to the standard ouput. If the +{\tt --create-files} option is specified the correct files in the +correct directory structure will be created. + +\subsection{Nested Interfaces} + +In some cases there are nested interfaces. In this case CreateInterface will +not correctly create the Java equivalent. This is because Java cannot have both +a class and a package with the same name. The solution to this is to create +nested classes in the same file. + +An example would be the Hal interface: + +\begin{verbatim} +<interface name="org.freedesktop.Hal.Device"> + ... +</interface> +<interface name="org.freedesktop.Hal.Device.Volume"> + ... +</interface> +\end{verbatim} + +When converted to Java you would just have one file {\tt +org/freedesktop/Hal/Device.java} in the package {\tt org.freedesktop.Hal}, +which would contain one class and one nested class: + +\begin{verbatim} +public interface Device extends DBusInterface { + public interface Volume extends DBusInterface { + ... methods in Volume ... + } + ... methods in Device ... +} +\end{verbatim} + +\section{Debugging} + +It is possible to enable debugging in the library. This will be a lot slower, +but can print a lot of useful information for debugging your program. + +To enable a debug build compile with {\tt DEBUG=enable}. This will then need to be +enabled at runtime by using the debug jar with debugging enabled (usually +installed as debug-enable.jar alongside the normal jar). + +Running a program which uses this library will print some informative messages. +More verbose debug information can be got by supplying a custom debug +configuration file. This should be placed in the file {\tt debug.conf} and has the +format: + +\begin{verbatim} +classname = LEVEL +\end{verbatim} + +Where {\tt classname} is either the special word {\tt ALL} or a full class name +like {\tt org.freedesktop.dbus} and {\tt LEVEL} is one of {\tt NONE}, {\tt +CRIT}, {\tt ERR}, {\tt WARN}, {\tt INFO}, {\tt DEBUG}, {\tt VERBOSE}, {\tt +YES}, {\tt ALL} or {\tt TRUE}. This will set the debug level for a particular +class. Any messages from that class at that level or higher will be printed. +Verbose debugging is extremely verbose. + +In addition, setting the environment variable {\tt +DBUS\_JAVA\_EXCEPTION\_DEBUG} will cause all exceptions which are handled +internally to have their stack trace printed when they are handled. This will +happen unless debugging has been disabled for that class. + +\section{Peer to Peer} + +It is possible to connect two applications together directly without using a +bus. D-Bus calls this a peer-to-peer connection. + +The Java implementation provides an alternative to the {\tt DBusConnection} +class, the {\tt +DirectConnection\footnote{\url{\javadocroot/org/freedesktop/dbus/DirectConnection.html}}} +class. This allows you to connect two applications together directly without +the need of a bus. + +When using a DirectConnection rather than a DBusConnection most operations are +the same. The only things which differ are how you connect and the operations +which depend on a bus. Since peer connections are only one-to-one there is no +destination or source address to messages. There is also no {\tt +org.freedesktop.DBus} service running on the bus. + +\subsection{Connecting to another application} + +To connect with a peer connection one of the two applications must be listening +on the socket and the other connecting. Both of these use the same method to +instantiate the {\tt DirectConnection} but with different addresses. To listen +rather than connect you add the {\em ``listen=true''} parameter to the address. +Listening and connecting can be seen in figures \ref{fig:p2plisten} and +\ref{fig:p2pconnect} respectively. Listening will block at creating the +connection until the other application has connected. + +{\tt DirectConnection} also provides a {\tt createDynamicSession} method which +generates a random abstract unix socket address to use. + +\begin{figure}[htb] +\begin{center} +\begin{verbatim} +DirectConnection dc = new DirectConnection("unix:path=/tmp/dbus-ABCXYZ,listen=true"); +\end{verbatim} +\end{center} +\caption{Listening for a peer connection} +\label{fig:p2plisten} +\end{figure} + +\begin{figure}[htb] +\begin{center} +\begin{verbatim} +DirectConnection dc = new DirectConnection("unix:path=/tmp/dbus-ABCXYZ"); +\end{verbatim} +\end{center} +\caption{Connecting to a peer connection} +\label{fig:p2pconnect} +\end{figure} + +\subsection{Getting Remote Objects} + +Getting a remote object is essentially the same as with a bus connection, +except that you do not have to specify a bus name, only an object path. There +is also no {\tt getPeerRemoteObject} method, since there can only be one peer +on this connection. + +\begin{figure}[htb] +\begin{center} +\begin{verbatim} +RemoteInterface remote = dc.getRemoteObject("/Path"); +remote.doStuff(); +\end{verbatim} +\end{center} +\caption{Getting a remote object on a peer connection} +\label{fig:p2premote} +\end{figure} + +The rest of the API is the same for peer connections as bus connections, +ommiting any bus addresses. + +\section{Low-level API} + +In very rare circumstances it may be neccessary to deal directly with messages +on the bus, rather than with objects and method calls. This implementation +gives the programmer access to this low-level API but its use is strongly +recommended against. + +To use the low-level API you use a different set of classes than with the +normal API. + +\subsection{Transport} + +The {\tt Transport\footnote{\url{\javadocroot/org/freedesktop/dbus/Transport.html}}} +class is used to connect to the underlying transport with a bus address and to +send and receive messages. + +You connect by either creating a {\tt Transport} object with the bus address as +the parameter, or by calling {\tt connect} with the address later. Addresses +are represented using the {\tt BusAddress} class. + +Messages can be read by calling {\tt transport.min.readMessage()} and written +by using the {\tt transport.mout.writeMessage(m)} methods. + +\subsection{Message} + +{\tt Message\footnote{\url{\javadocroot/org/freedesktop/dbus/Message.html}}} is the +superclass of all the classes representing a message. To send a message you +need to create a subclass of this object. Possible message types are: {\tt +MethodCall}, {\tt MethodReturn}, {\tt Error} and {\tt DBusSignal}. Constructors +for these vary, but they are basically similar to the {\tt MethodCall} class. + +All the constructors have variadic parameter lists with the last of the +parameters being the signature of the message body and the parameters which +make up the body. If the message has an empty body then the last parameter must +be null. Reading and writing messages is not thread safe. + +Messages can be read either in blocking or non-blocking mode. When reading a +message in non-blocking mode, if a full message has not yet been read from the +transport the method will return null. Messages are instantiated as the correct +message type, so {\tt instanceof} will work on the returned object. Blocking +mode can be enabled with an extra parameter to the Transport constructor. + +Figure \ref{fig:lowlevel} shows how to connect to a bus, send the (required) +initial `Hello' message and +call a method with two parameters. + +\begin{figure}[htb] +\begin{center} +\begin{verbatim} +BusAddress address = new BusAddress( + System.getenv("DBUS_SESSION_BUS_ADDRESS")); +Transport conn = new Transport(address, true); + +Message m = new MethodCall("org.freedesktop.DBus", "/org/freedesktop/DBus", + "org.freedesktop. DBus", "Hello", (byte) 0, null); +conn.mout.writeMessage(m); + +m = conn.min.readMessage(); +System.out.println("Response to Hello is: "+m); + +m = new MethodCall("org.freedesktop.DBus", "/org/freedesktop/DBus", + "org.freedesktop.DBus", "RequestName", (byte) 0, + "su", "org.testname", 0); +conn.mout.writeMessage(m); + +conn.disconnect(); +\end{verbatim} +\end{center} +\caption{Low-level usage} +\label{fig:lowlevel} +\end{figure} + +\section{Examples} + +As an example here are a complete set of interfaces for the +bluemon\footnote{http://www.matthew.ath.cx/projects/bluemon} daemon, +which communicates over D-Bus. These interfaces were all created by +querying introspection data over the bus. + +\newpage + +\begin{figure}[!h] +\begin{center} +\begin{verbatim} +package cx.ath.matthew.bluemon; +import org.freedesktop.dbus.DBusInterface; +import org.freedesktop.dbus.UInt32; +public interface Bluemon extends DBusInterface +{ + public Triplet<String, Boolean, UInt32> + Status(String address); +} +\end{verbatim} +\end{center} +\caption{cx/ath/matthew/bluemon/Bluemon.java} +\end{figure} + +\newpage + +\begin{figure}[!h] +\begin{center} +\begin{verbatim} +package cx.ath.matthew.bluemon; +import org.freedesktop.dbus.DBusInterface; +import org.freedesktop.dbus.DBusSignal; +import org.freedesktop.dbus.exceptions.DBusException; +public interface ProximitySignal extends DBusInterface +{ + public static class Connect extends DBusSignal + { + public final String address; + public Connect(String path, String address) + throws DBusException + { + super(path, address); + this.address = address; + } + } + public static class Disconnect extends DBusSignal + { + public final String address; + public Disconnect(String path, String address) + throws DBusException + { + super(path, address); + this.address = address; + } + } +} +\end{verbatim} +\end{center} +\caption{cx/ath/matthew/bluemon/ProximitySignal.java} +\end{figure} + +\newpage + +\begin{figure}[!h] +\begin{center} +\begin{verbatim} +package cx.ath.matthew.bluemon; +import org.freedesktop.dbus.Tuple; +/** Just a typed container class */ +public final class Triplet <A,B,C> extends Tuple +{ + public final A a; + public final B b; + public final C c; + public Triplet(A a, B b, C c) + { + super(a, b, c); + this.a = a; + this.b = b; + this.c = c; + } +} +\end{verbatim} +\end{center} +\caption{cx/ath/matthew/bluemon/Triplet.java} +\end{figure} + +\newpage + +\begin{figure}[!h] +\begin{center} +\begin{verbatim} +package cx.ath.matthew.bluemon; +import org.freedesktop.dbus.DBusConnection; +import org.freedesktop.dbus.DBusSigHandler; +import org.freedesktop.dbus.DBusSignal; +import org.freedesktop.dbus.UInt32; +import org.freedesktop.dbus.exceptions.DBusException; + +public class Query { + public static void main(String[] args) { + String btid; + Triplet<String, Boolean, UInt32> rv = null; + + if (0 == args.length) btid = ""; + else btid = args[0]; + + DBusConnection conn = null; + try { + conn = DBusConnection.getConnection(DBusConnection.SYSTEM); + } catch (DBusException De) { + System.exit(1); + } + Bluemon b = (Bluemon) conn.getRemoteObject( + "cx.ath.matthew.bluemon.server", + "/cx/ath/matthew/bluemon/Bluemon", Bluemon.class); + try { + rv = b.Status(btid); + } catch (RuntimeException Re) { + System.exit(1); + } + String address = rv.a; + boolean status = rv.b; + int level = rv.c.intValue(); + + if (status) + System.out.println("Device "+address+ + " connected with level "+level); + else + System.out.println("Device "+address+" not connected"); + conn.disconnect(); + } +} +\end{verbatim} +\end{center} +\caption{cx/ath/matthew/bluemon/Query.java} +\end{figure} + +\newpage + +\begin{figure}[!h] +\begin{center} +\begin{verbatim} +/* cx/ath/matthew/bluemon/Client.java */ +package cx.ath.matthew.bluemon; + +import org.freedesktop.dbus.DBusConnection; +import org.freedesktop.dbus.DBusSigHandler; +import org.freedesktop.dbus.DBusSignal; +import org.freedesktop.dbus.exceptions.DBusException; + +public class Client implements DBusSigHandler +{ + public void handle(DBusSignal s) + { + if (s instanceof ProximitySignal.Connect) + System.out.println("Got a connect for " + +((ProximitySignal.Connect) s).address); + else if (s instanceof ProximitySignal.Disconnect) + System.out.println("Got a disconnect for " + +((ProximitySignal.Disconnect) s).address); + } + public static void main(String[] args) + { + System.out.println("Creating Connection"); + DBusConnection conn = null; + try { + conn = DBusConnection + .getConnection(DBusConnection.SYSTEM); + } catch (DBusException DBe) { + System.out.println("Could not connect to bus"); + System.exit(1); + } + + try { + conn.addSigHandler(ProximitySignal.Connect.class, + new Client()); + conn.addSigHandler(ProximitySignal.Disconnect.class, + new Client()); + } catch (DBusException DBe) { + conn.disconnect(); + System.exit(1); + } + } +} +\end{verbatim} +\end{center} +\caption{cx/ath/matthew/bluemon/Client.java} +\end{figure} + +\newpage + +\section{Credits} + +This document and the Java API were written by and are copyright to +Matthew Johnson. Much help and advice was provided by the members of +the \#dbus irc channel. Comments, corrections and patches can be sent +to dbus-java@matthew.ath.cx. + +\end{document} + + diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/DBus.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/DBus.java new file mode 100755 index 0000000..5d99a64 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/DBus.java @@ -0,0 +1,490 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import java.util.Map; +import java.util.List; + +import org.freedesktop.dbus.DBusInterface; +import org.freedesktop.dbus.DBusSignal; +import org.freedesktop.dbus.Position; +import org.freedesktop.dbus.Struct; +import org.freedesktop.dbus.Tuple; +import org.freedesktop.dbus.UInt16; +import org.freedesktop.dbus.UInt32; +import org.freedesktop.dbus.UInt64; +import org.freedesktop.dbus.Variant; +import org.freedesktop.dbus.exceptions.DBusException; +import org.freedesktop.dbus.exceptions.DBusExecutionException; + +public interface DBus extends DBusInterface +{ + public static final int DBUS_NAME_FLAG_ALLOW_REPLACEMENT = 0x01; + public static final int DBUS_NAME_FLAG_REPLACE_EXISTING = 0x02; + public static final int DBUS_NAME_FLAG_DO_NOT_QUEUE = 0x04; + public static final int DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER = 1; + public static final int DBUS_REQUEST_NAME_REPLY_IN_QUEUE = 2; + public static final int DBUS_REQUEST_NAME_REPLY_EXISTS = 3; + public static final int DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER = 4; + public static final int DBUS_RELEASE_NAME_REPLY_RELEASED = 1; + public static final int DBUS_RELEASE_NAME_REPLY_NON_EXISTANT = 2; + public static final int DBUS_RELEASE_NAME_REPLY_NOT_OWNER = 3; + public static final int DBUS_START_REPLY_SUCCESS = 1; + public static final int DBUS_START_REPLY_ALREADY_RUNNING = 2; + /** + * All DBus Applications should respond to the Ping method on this interface + */ + public interface Peer extends DBusInterface + { + public void Ping(); + } + /** + * Objects can provide introspection data via this interface and method. + * See the <a href="http://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format">Introspection Format</a>. + */ + public interface Introspectable extends DBusInterface + { + /** + * @return The XML introspection data for this object + */ + public String Introspect(); + } + /** + * A standard properties interface. + */ + public interface Properties extends DBusInterface + { + /** + * Get the value for the given property. + * @param interface_name The interface this property is associated with. + * @param property_name The name of the property. + * @return The value of the property (may be any valid DBus type). + */ + public <A> A Get (String interface_name, String property_name); + /** + * Set the value for the given property. + * @param interface_name The interface this property is associated with. + * @param property_name The name of the property. + * @param value The new value of the property (may be any valid DBus type). + */ + public <A> void Set (String interface_name, String property_name, A value); + /** + * Get all properties and values. + * @param interface_name The interface the properties is associated with. + * @return The properties mapped to their values. + */ + public Map<String, Variant> GetAll (String interface_name); + } + /** + * Messages generated locally in the application. + */ + public interface Local extends DBusInterface + { + public class Disconnected extends DBusSignal + { + public Disconnected(String path) throws DBusException + { + super(path); + } + } + } + + /** + * Initial message to register ourselves on the Bus. + * @return The unique name of this connection to the Bus. + */ + public String Hello(); + /** + * Lists all connected names on the Bus. + * @return An array of all connected names. + */ + public String[] ListNames(); + /** + * Determine if a name has an owner. + * @param name The name to query. + * @return true if the name has an owner. + */ + public boolean NameHasOwner(String name); + /** + * Get the connection unique name that owns the given name. + * @param name The name to query. + * @return The connection which owns the name. + */ + public String GetNameOwner(String name); + /** + * Get the Unix UID that owns a connection name. + * @param connection_name The connection name. + * @return The Unix UID that owns it. + */ + public UInt32 GetConnectionUnixUser(String connection_name); + /** + * Start a service. If the given service is not provided + * by any application, it will be started according to the .service file + * for that service. + * @param name The service name to start. + * @param flags Unused. + * @return DBUS_START_REPLY constants. + */ + public UInt32 StartServiceByName(String name, UInt32 flags); + /** + * Request a name on the bus. + * @param name The name to request. + * @param flags DBUS_NAME flags. + * @return DBUS_REQUEST_NAME_REPLY constants. + */ + public UInt32 RequestName(String name, UInt32 flags); + /** + * Release a name on the bus. + * @param name The name to release. + * @return DBUS_RELEASE_NAME_REPLY constants. + */ + public UInt32 ReleaseName(String name); + + /** + * Add a match rule. + * Will cause you to receive messages that aren't directed to you which + * match this rule. + * @param matchrule The Match rule as a string. Format Undocumented. + */ + public void AddMatch(String matchrule) throws Error.MatchRuleInvalid; + + /** + * Remove a match rule. + * Will cause you to stop receiving messages that aren't directed to you which + * match this rule. + * @param matchrule The Match rule as a string. Format Undocumented. + */ + public void RemoveMatch(String matchrule) throws Error.MatchRuleInvalid; + + /** + * List the connections currently queued for a name. + * @param name The name to query + * @return A list of unique connection IDs. + */ + public String[] ListQueuedOwners(String name); + + /** + * Returns the proccess ID associated with a connection. + * @param connection_name The name of the connection + * @return The PID of the connection. + */ + public UInt32 GetConnectionUnixProcessID(String connection_name); + + /** + * Does something undocumented. + */ + public Byte[] GetConnectionSELinuxSecurityContext(String a); + + /** + * Does something undocumented. + */ + public void ReloadConfig(); + + /** + * Signal sent when the owner of a name changes + */ + public class NameOwnerChanged extends DBusSignal + { + public final String name; + public final String old_owner; + public final String new_owner; + public NameOwnerChanged(String path, String name, String old_owner, String new_owner) throws DBusException + { + super(path, new Object[] { name, old_owner, new_owner }); + this.name = name; + this.old_owner = old_owner; + this.new_owner = new_owner; + } + } + /** + * Signal sent to a connection when it loses a name + */ + public class NameLost extends DBusSignal + { + public final String name; + public NameLost(String path, String name) throws DBusException + { + super(path, name); + this.name = name; + } + } + /** + * Signal sent to a connection when it aquires a name + */ + public class NameAcquired extends DBusSignal + { + public final String name; + public NameAcquired(String path, String name) throws DBusException + { + super(path, name); + this.name = name; + } + } + /** + * Contains standard errors that can be thrown from methods. + */ + public interface Error + { + /** + * Thrown if the method called was unknown on the remote object + */ + @SuppressWarnings("serial") + public class UnknownMethod extends DBusExecutionException + { + public UnknownMethod(String message) + { + super(message); + } + } + /** + * Thrown if the object was unknown on a remote connection + */ + @SuppressWarnings("serial") + public class UnknownObject extends DBusExecutionException + { + public UnknownObject(String message) + { + super(message); + } + } + /** + * Thrown if the requested service was not available + */ + @SuppressWarnings("serial") + public class ServiceUnknown extends DBusExecutionException + { + public ServiceUnknown(String message) + { + super(message); + } + } + /** + * Thrown if the match rule is invalid + */ + @SuppressWarnings("serial") + public class MatchRuleInvalid extends DBusExecutionException + { + public MatchRuleInvalid(String message) + { + super(message); + } + } + /** + * Thrown if there is no reply to a method call + */ + @SuppressWarnings("serial") + public class NoReply extends DBusExecutionException + { + public NoReply(String message) + { + super(message); + } + } + /** + * Thrown if a message is denied due to a security policy + */ + @SuppressWarnings("serial") + public class AccessDenied extends DBusExecutionException + { + public AccessDenied(String message) + { + super(message); + } + } + } + /** + * Description of the interface or method, returned in the introspection data + */ + @Retention(RetentionPolicy.RUNTIME) + public @interface Description + { + String value(); + } + /** + * Indicates that a DBus interface or method is deprecated + */ + @Retention(RetentionPolicy.RUNTIME) + public @interface Deprecated {} + /** + * Contains method-specific annotations + */ + public interface Method + { + /** + * Methods annotated with this do not send a reply + */ + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + public @interface NoReply {} + /** + * Give an error that the method can return + */ + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + public @interface Error + { + String value(); + } + } + /** + * Contains GLib-specific annotations + */ + public interface GLib + { + /** + * Define a C symbol to map to this method. Used by GLib only + */ + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + public @interface CSymbol + { + String value(); + } + } + /** + * Contains Binding-test interfaces + */ + public interface Binding + { + public interface SingleTests extends DBusInterface + { + @Description("Returns the sum of the values in the input list") + public UInt32 Sum(byte[] a); + } + public interface TestClient extends DBusInterface + { + @Description("when the trigger signal is received, this method should be called on the sending process/object.") + public void Response(UInt16 a, double b); + @Description("Causes a callback") + public static class Trigger extends DBusSignal + { + public final UInt16 a; + public final double b; + public Trigger(String path, UInt16 a, double b) throws DBusException + { + super(path, a, b); + this.a = a; + this.b = b; + } + } + + } + public interface Tests extends DBusInterface + { + @Description("Returns whatever it is passed") + public <T> Variant<T> Identity(Variant<T> input); + @Description("Returns whatever it is passed") + public byte IdentityByte(byte input); + @Description("Returns whatever it is passed") + public boolean IdentityBool(boolean input); + @Description("Returns whatever it is passed") + public short IdentityInt16(short input); + @Description("Returns whatever it is passed") + public UInt16 IdentityUInt16(UInt16 input); + @Description("Returns whatever it is passed") + public int IdentityInt32(int input); + @Description("Returns whatever it is passed") + public UInt32 IdentityUInt32(UInt32 input); + @Description("Returns whatever it is passed") + public long IdentityInt64(long input); + @Description("Returns whatever it is passed") + public UInt64 IdentityUInt64(UInt64 input); + @Description("Returns whatever it is passed") + public double IdentityDouble(double input); + @Description("Returns whatever it is passed") + public String IdentityString(String input); + @Description("Returns whatever it is passed") + public <T> Variant<T>[] IdentityArray(Variant<T>[] input); + @Description("Returns whatever it is passed") + public byte[] IdentityByteArray(byte[] input); + @Description("Returns whatever it is passed") + public boolean[] IdentityBoolArray(boolean[] input); + @Description("Returns whatever it is passed") + public short[] IdentityInt16Array(short[] input); + @Description("Returns whatever it is passed") + public UInt16[] IdentityUInt16Array(UInt16[] input); + @Description("Returns whatever it is passed") + public int[] IdentityInt32Array(int[] input); + @Description("Returns whatever it is passed") + public UInt32[] IdentityUInt32Array(UInt32[] input); + @Description("Returns whatever it is passed") + public long[] IdentityInt64Array(long[] input); + @Description("Returns whatever it is passed") + public UInt64[] IdentityUInt64Array(UInt64[] input); + @Description("Returns whatever it is passed") + public double[] IdentityDoubleArray(double[] input); + @Description("Returns whatever it is passed") + public String[] IdentityStringArray(String[] input); + @Description("Returns the sum of the values in the input list") + public long Sum(int[] a); + @Description("Given a map of A => B, should return a map of B => a list of all the As which mapped to B") + public Map<String, List<String>> InvertMapping(Map<String, String> a); + @Description("This method returns the contents of a struct as separate values") + public Triplet<String, UInt32, Short> DeStruct(TestStruct a); + @Description("Given any compound type as a variant, return all the primitive types recursively contained within as an array of variants") + public List<Variant<Object>> Primitize(Variant<Object> a); + @Description("inverts it's input") + public boolean Invert(boolean a); + @Description("triggers sending of a signal from the supplied object with the given parameter") + public void Trigger(String a, UInt64 b); + @Description("Causes the server to exit") + public void Exit(); + } + public interface TestSignals extends DBusInterface + { + @Description("Sent in response to a method call") + public static class Triggered extends DBusSignal + { + public final UInt64 a; + public Triggered(String path, UInt64 a) throws DBusException + { + super(path, a); + this.a = a; + } + } + } + public final class Triplet<A,B,C> extends Tuple + { + @Position(0) + public final A a; + @Position(1) + public final B b; + @Position(2) + public final C c; + public Triplet(A a, B b, C c) + { + this.a = a; + this.b = b; + this.c = c; + } + } + public final class TestStruct extends Struct + { + @Position(0) + public final String a; + @Position(1) + public final UInt32 b; + @Position(2) + public final Short c; + public TestStruct(String a, UInt32 b, Short c) + { + this.a = a; + this.b = b; + this.c = c; + } + } + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/AbstractConnection.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/AbstractConnection.java new file mode 100755 index 0000000..3c2607e --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/AbstractConnection.java @@ -0,0 +1,1075 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import static org.freedesktop.dbus.Gettext._; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Type; + +import java.io.File; +import java.io.IOException; + +import java.text.MessageFormat; +import java.text.ParseException; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Map; +import java.util.Properties; +import java.util.Vector; + +import java.util.regex.Pattern; + +import org.freedesktop.DBus; +import org.freedesktop.dbus.exceptions.NotConnected; +import org.freedesktop.dbus.exceptions.DBusException; +import org.freedesktop.dbus.exceptions.DBusExecutionException; +import org.freedesktop.dbus.exceptions.FatalDBusException; +import org.freedesktop.dbus.exceptions.FatalException; + +import cx.ath.matthew.debug.Debug; + + +/** Handles a connection to DBus. + */ +public abstract class AbstractConnection +{ + protected class FallbackContainer + { + private Map<String[], ExportedObject> fallbacks = new HashMap<String[], ExportedObject>(); + public synchronized void add(String path, ExportedObject eo) + { + if (Debug.debug) Debug.print(Debug.DEBUG, "Adding fallback on "+path+" of "+eo); + fallbacks.put(path.split("/"), eo); + } + public synchronized void remove(String path) + { + if (Debug.debug) Debug.print(Debug.DEBUG, "Removing fallback on "+path); + fallbacks.remove(path.split("/")); + } + public synchronized ExportedObject get(String path) + { + int best = 0; + int i = 0; + ExportedObject bestobject = null; + String[] pathel = path.split("/"); + for (String[] fbpath: fallbacks.keySet()) { + if (Debug.debug) Debug.print(Debug.VERBOSE, "Trying fallback path "+Arrays.deepToString(fbpath)+" to match "+Arrays.deepToString(pathel)); + for (i = 0; i < pathel.length && i < fbpath.length; i++) + if (!pathel[i].equals(fbpath[i])) break; + if (i > 0 && i == fbpath.length && i > best) + bestobject = fallbacks.get(fbpath); + if (Debug.debug) Debug.print(Debug.VERBOSE, "Matches "+i+" bestobject now "+bestobject); + } + if (Debug.debug) Debug.print(Debug.DEBUG, "Found fallback for "+path+" of "+bestobject); + return bestobject; + } + } + protected class _thread extends Thread + { + public _thread() + { + setName("DBusConnection"); + } + public void run() + { + try { + Message m = null; + while (_run) { + m = null; + + // read from the wire + try { + // this blocks on outgoing being non-empty or a message being available. + m = readIncoming(); + if (m != null) { + if (Debug.debug) Debug.print(Debug.VERBOSE, "Got Incoming Message: "+m); + synchronized (this) { notifyAll(); } + + if (m instanceof DBusSignal) + handleMessage((DBusSignal) m); + else if (m instanceof MethodCall) + handleMessage((MethodCall) m); + else if (m instanceof MethodReturn) + handleMessage((MethodReturn) m); + else if (m instanceof Error) + handleMessage((Error) m); + + m = null; + } + } catch (Exception e) { + e.printStackTrace(); + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, e); + if (e instanceof FatalException) { + disconnect(); + } + } + + } + synchronized (this) { notifyAll(); } + } catch (Exception e) { + e.printStackTrace(); + if (Debug.debug && EXCEPTION_DEBUG) Debug.print(Debug.ERR, e); + } + } + } + private class _globalhandler implements org.freedesktop.DBus.Peer, org.freedesktop.DBus.Introspectable + { + private String objectpath; + public _globalhandler() + { + this.objectpath = null; + } + public _globalhandler(String objectpath) + { + this.objectpath = objectpath; + } + public boolean isRemote() { return false; } + public void Ping() { return; } + public String Introspect() + { + String intro = objectTree.Introspect(objectpath); + if (null == intro) { + ExportedObject eo = fallbackcontainer.get(objectpath); + if (null != eo) intro = eo.introspectiondata; + } + if (null == intro) + throw new DBus.Error.UnknownObject("Introspecting on non-existant object"); + else return + "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\" "+ + "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"+intro; + } + } + protected class _workerthread extends Thread + { + private boolean _run = true; + public void halt() + { + _run = false; + } + public void run() + { + while (_run) { + Runnable r = null; + synchronized (runnables) { + while (runnables.size() == 0 && _run) + try { runnables.wait(); } catch (InterruptedException Ie) {} + if (runnables.size() > 0) + r = runnables.removeFirst(); + } + if (null != r) r.run(); + } + } + } + private class _sender extends Thread + { + public _sender() + { + setName("Sender"); + } + public void run() + { + Message m = null; + + if (Debug.debug) Debug.print(Debug.INFO, "Monitoring outbound queue"); + // block on the outbound queue and send from it + while (_run) { + if (null != outgoing) synchronized (outgoing) { + if (Debug.debug) Debug.print(Debug.VERBOSE, "Blocking"); + while (outgoing.size() == 0 && _run) + try { outgoing.wait(); } catch (InterruptedException Ie) {} + if (Debug.debug) Debug.print(Debug.VERBOSE, "Notified"); + if (outgoing.size() > 0) + m = outgoing.remove(); + if (Debug.debug) Debug.print(Debug.DEBUG, "Got message: "+m); + } + if (null != m) + sendMessage(m); + m = null; + } + + if (Debug.debug) Debug.print(Debug.INFO, "Flushing outbound queue and quitting"); + // flush the outbound queue before disconnect. + if (null != outgoing) do { + EfficientQueue ogq = outgoing; + synchronized (ogq) { + outgoing = null; + } + if (!ogq.isEmpty()) + m = ogq.remove(); + else m = null; + sendMessage(m); + } while (null != m); + + // close the underlying streams + } + } + /** + * Timeout in us on checking the BUS for incoming messages and sending outgoing messages + */ + protected static final int TIMEOUT = 100000; + /** Initial size of the pending calls map */ + private static final int PENDING_MAP_INITIAL_SIZE = 10; + static final String BUSNAME_REGEX = "^[-_a-zA-Z][-_a-zA-Z0-9]*(\\.[-_a-zA-Z][-_a-zA-Z0-9]*)*$"; + static final String CONNID_REGEX = "^:[0-9]*\\.[0-9]*$"; + static final String OBJECT_REGEX = "^/([-_a-zA-Z0-9]+(/[-_a-zA-Z0-9]+)*)?$"; + static final byte THREADCOUNT = 4; + static final int MAX_ARRAY_LENGTH = 67108864; + static final int MAX_NAME_LENGTH = 255; + + public static String currentSender = null; // pego + + protected Map<String,ExportedObject> exportedObjects; + private ObjectTree objectTree; + private _globalhandler _globalhandlerreference; + protected Map<DBusInterface,RemoteObject> importedObjects; + protected Map<SignalTuple,Vector<DBusSigHandler<? extends DBusSignal>>> handledSignals; + protected EfficientMap pendingCalls; + protected Map<MethodCall, CallbackHandler<? extends Object>> pendingCallbacks; + protected Map<MethodCall, DBusAsyncReply<? extends Object>> pendingCallbackReplys; + protected LinkedList<Runnable> runnables; + protected LinkedList<_workerthread> workers; + protected FallbackContainer fallbackcontainer; + protected boolean _run; + EfficientQueue outgoing; + LinkedList<Error> pendingErrors; + private static final Map<Thread,DBusCallInfo> infomap = new HashMap<Thread,DBusCallInfo>(); + protected _thread thread; + protected _sender sender; + protected Transport transport; + protected String addr; + protected boolean weakreferences = false; + static final Pattern dollar_pattern = Pattern.compile("[$]"); + public static final boolean EXCEPTION_DEBUG; + static final boolean FLOAT_SUPPORT; + protected boolean connected = false; + static { + FLOAT_SUPPORT = (null != System.getenv("DBUS_JAVA_FLOATS")); + EXCEPTION_DEBUG = (null != System.getenv("DBUS_JAVA_EXCEPTION_DEBUG")); + if (EXCEPTION_DEBUG) { + Debug.print("Debugging of internal exceptions enabled"); + Debug.setThrowableTraces(true); + } + if (Debug.debug) { + File f = new File("debug.conf"); + if (f.exists()) { + Debug.print("Loading debug config file: "+f); + try { + Debug.loadConfig(f); + } catch (IOException IOe) {} + } else { + Properties p = new Properties(); + p.setProperty("ALL", "INFO"); + Debug.print("debug config file "+f+" does not exist, not loading."); + } + Debug.setHexDump(true); + } + } + + protected AbstractConnection(String address) throws DBusException + { + exportedObjects = new HashMap<String,ExportedObject>(); + importedObjects = new HashMap<DBusInterface,RemoteObject>(); + _globalhandlerreference = new _globalhandler(); + synchronized (exportedObjects) { + exportedObjects.put(null, new ExportedObject(_globalhandlerreference, weakreferences)); + } + handledSignals = new HashMap<SignalTuple,Vector<DBusSigHandler<? extends DBusSignal>>>(); + pendingCalls = new EfficientMap(PENDING_MAP_INITIAL_SIZE); + outgoing = new EfficientQueue(PENDING_MAP_INITIAL_SIZE); + pendingCallbacks = new HashMap<MethodCall, CallbackHandler<? extends Object>>(); + pendingCallbackReplys = new HashMap<MethodCall, DBusAsyncReply<? extends Object>>(); + pendingErrors = new LinkedList<Error>(); + runnables = new LinkedList<Runnable>(); + workers = new LinkedList<_workerthread>(); + objectTree = new ObjectTree(); + fallbackcontainer = new FallbackContainer(); + synchronized (workers) { + for (int i = 0; i < THREADCOUNT; i++) { + _workerthread t = new _workerthread(); + t.start(); + workers.add(t); + } + } + _run = true; + addr = address; + } + + protected void listen() + { + // start listening + thread = new _thread(); + thread.start(); + sender = new _sender(); + sender.start(); + } + + /** + * Change the number of worker threads to receive method calls and handle signals. + * Default is 4 threads + * @param newcount The new number of worker Threads to use. + */ + public void changeThreadCount(byte newcount) + { + synchronized (workers) { + if (workers.size() > newcount) { + int n = workers.size() - newcount; + for (int i = 0; i < n; i++) { + _workerthread t = workers.removeFirst(); + t.halt(); + } + } else if (workers.size() < newcount) { + int n = newcount-workers.size(); + for (int i = 0; i < n; i++) { + _workerthread t = new _workerthread(); + t.start(); + workers.add(t); + } + } + } + } + private void addRunnable(Runnable r) + { + synchronized(runnables) { + runnables.add(r); + runnables.notifyAll(); + } + } + + String getExportedObject(DBusInterface i) throws DBusException + { + synchronized (exportedObjects) { + for (String s: exportedObjects.keySet()) + if (i.equals(exportedObjects.get(s).object.get())) + return s; + } + + String s = importedObjects.get(i).objectpath; + if (null != s) return s; + + throw new DBusException("Not an object exported or imported by this connection"); + } + + abstract DBusInterface getExportedObject(String source, String path) throws DBusException; + + /** + * Returns a structure with information on the current method call. + * @return the DBusCallInfo for this method call, or null if we are not in a method call. + */ + public static DBusCallInfo getCallInfo() + { + DBusCallInfo info; + synchronized (infomap) { + info = infomap.get(Thread.currentThread()); + } + return info; + } + + /** + * If set to true the bus will not hold a strong reference to exported objects. + * If they go out of scope they will automatically be unexported from the bus. + * The default is to hold a strong reference, which means objects must be + * explicitly unexported before they will be garbage collected. + */ + public void setWeakReferences(boolean weakreferences) + { + this.weakreferences = weakreferences; + } + + /** + * Export an object so that its methods can be called on DBus. + * @param objectpath The path to the object we are exposing. MUST be in slash-notation, like "/org/freedesktop/Local", + * and SHOULD end with a capitalised term. Only one object may be exposed on each path at any one time, but an object + * may be exposed on several paths at once. + * @param object The object to export. + * @throws DBusException If the objectpath is already exporting an object. + * or if objectpath is incorrectly formatted, + */ + public void exportObject(String objectpath, DBusInterface object) throws DBusException + { + if (null == objectpath || "".equals(objectpath)) + throw new DBusException(_("Must Specify an Object Path")); + if (!objectpath.matches(OBJECT_REGEX)||objectpath.length() > MAX_NAME_LENGTH) + throw new DBusException(_("Invalid object path: ")+objectpath); + synchronized (exportedObjects) { + if (null != exportedObjects.get(objectpath)) + throw new DBusException(_("Object already exported")); + ExportedObject eo = new ExportedObject(object, weakreferences); + exportedObjects.put(objectpath, eo); + objectTree.add(objectpath, eo, eo.introspectiondata); + } + } + /** + * Export an object as a fallback object. + * This object will have it's methods invoked for all paths starting + * with this object path. + * @param objectprefix The path below which the fallback handles calls. + * MUST be in slash-notation, like "/org/freedesktop/Local", + * @param object The object to export. + * @throws DBusException If the objectpath is incorrectly formatted, + */ + public void addFallback(String objectprefix, DBusInterface object) throws DBusException + { + if (null == objectprefix || "".equals(objectprefix)) + throw new DBusException(_("Must Specify an Object Path")); + if (!objectprefix.matches(OBJECT_REGEX)||objectprefix.length() > MAX_NAME_LENGTH) + throw new DBusException(_("Invalid object path: ")+objectprefix); + ExportedObject eo = new ExportedObject(object, weakreferences); + fallbackcontainer.add(objectprefix, eo); + } + /** + * Remove a fallback + * @param objectprefix The prefix to remove the fallback for. + */ + public void removeFallback(String objectprefix) + { + fallbackcontainer.remove(objectprefix); + } + /** + * Stop Exporting an object + * @param objectpath The objectpath to stop exporting. + */ + public void unExportObject(String objectpath) + { + synchronized (exportedObjects) { + exportedObjects.remove(objectpath); + objectTree.remove(objectpath); + } + } + /** + * Return a reference to a remote object. + * This method will resolve the well known name (if given) to a unique bus name when you call it. + * This means that if a well known name is released by one process and acquired by another calls to + * objects gained from this method will continue to operate on the original process. + * @param busname The bus name to connect to. Usually a well known bus name in dot-notation (such as "org.freedesktop.local") + * or may be a DBus address such as ":1-16". + * @param objectpath The path on which the process is exporting the object.$ + * @param type The interface they are exporting it on. This type must have the same full class name and exposed method signatures + * as the interface the remote object is exporting. + * @return A reference to a remote object. + * @throws ClassCastException If type is not a sub-type of DBusInterface + * @throws DBusException If busname or objectpath are incorrectly formatted or type is not in a package. + */ + /** + * Send a signal. + * @param signal The signal to send. + */ + public void sendSignal(DBusSignal signal) + { + queueOutgoing(signal); + } + void queueOutgoing(Message m) + { + synchronized (outgoing) { + if (null == outgoing) return; + outgoing.add(m); + if (Debug.debug) Debug.print(Debug.DEBUG, "Notifying outgoing thread"); + outgoing.notifyAll(); + } + } + /** + * Remove a Signal Handler. + * Stops listening for this signal. + * @param type The signal to watch for. + * @throws DBusException If listening for the signal on the bus failed. + * @throws ClassCastException If type is not a sub-type of DBusSignal. + */ + public <T extends DBusSignal> void removeSigHandler(Class<T> type, DBusSigHandler<T> handler) throws DBusException + { + if (!DBusSignal.class.isAssignableFrom(type)) throw new ClassCastException(_("Not A DBus Signal")); + removeSigHandler(new DBusMatchRule(type), handler); + } + /** + * Remove a Signal Handler. + * Stops listening for this signal. + * @param type The signal to watch for. + * @param object The object emitting the signal. + * @throws DBusException If listening for the signal on the bus failed. + * @throws ClassCastException If type is not a sub-type of DBusSignal. + */ + public <T extends DBusSignal> void removeSigHandler(Class<T> type, DBusInterface object, DBusSigHandler<T> handler) throws DBusException + { + if (!DBusSignal.class.isAssignableFrom(type)) throw new ClassCastException(_("Not A DBus Signal")); + String objectpath = importedObjects.get(object).objectpath; + if (!objectpath.matches(OBJECT_REGEX)||objectpath.length() > MAX_NAME_LENGTH) + throw new DBusException(_("Invalid object path: ")+objectpath); + removeSigHandler(new DBusMatchRule(type, null, objectpath), handler); + } + + protected abstract <T extends DBusSignal> void removeSigHandler(DBusMatchRule rule, DBusSigHandler<T> handler) throws DBusException; + /** + * Add a Signal Handler. + * Adds a signal handler to call when a signal is received which matches the specified type and name. + * @param type The signal to watch for. + * @param handler The handler to call when a signal is received. + * @throws DBusException If listening for the signal on the bus failed. + * @throws ClassCastException If type is not a sub-type of DBusSignal. + */ + @SuppressWarnings("unchecked") + public <T extends DBusSignal> void addSigHandler(Class<T> type, DBusSigHandler<T> handler) throws DBusException + { + if (!DBusSignal.class.isAssignableFrom(type)) throw new ClassCastException(_("Not A DBus Signal")); + addSigHandler(new DBusMatchRule(type), (DBusSigHandler<? extends DBusSignal>) handler); + } + /** + * Add a Signal Handler. + * Adds a signal handler to call when a signal is received which matches the specified type, name and object. + * @param type The signal to watch for. + * @param object The object from which the signal will be emitted + * @param handler The handler to call when a signal is received. + * @throws DBusException If listening for the signal on the bus failed. + * @throws ClassCastException If type is not a sub-type of DBusSignal. + */ + @SuppressWarnings("unchecked") + public <T extends DBusSignal> void addSigHandler(Class<T> type, DBusInterface object, DBusSigHandler<T> handler) throws DBusException + { + if (!DBusSignal.class.isAssignableFrom(type)) throw new ClassCastException(_("Not A DBus Signal")); + String objectpath = importedObjects.get(object).objectpath; + if (!objectpath.matches(OBJECT_REGEX)||objectpath.length() > MAX_NAME_LENGTH) + throw new DBusException(_("Invalid object path: ")+objectpath); + addSigHandler(new DBusMatchRule(type, null, objectpath), (DBusSigHandler<? extends DBusSignal>) handler); + } + + protected abstract <T extends DBusSignal> void addSigHandler(DBusMatchRule rule, DBusSigHandler<T> handler) throws DBusException; + + // pego was protedted, made public + public <T extends DBusSignal> void addSigHandlerWithoutMatch(Class<? extends DBusSignal> signal, DBusSigHandler<T> handler) throws DBusException + { + DBusMatchRule rule = new DBusMatchRule(signal); + SignalTuple key = new SignalTuple(rule.getInterface(), rule.getMember(), rule.getObject(), rule.getSource()); + synchronized (handledSignals) { + Vector<DBusSigHandler<? extends DBusSignal>> v = handledSignals.get(key); + if (null == v) { + v = new Vector<DBusSigHandler<? extends DBusSignal>>(); + v.add(handler); + handledSignals.put(key, v); + } else + v.add(handler); + } + } + + /** + * Disconnect from the Bus. + */ + public void disconnect() + { + connected = false; + if (Debug.debug) Debug.print(Debug.INFO, "Sending disconnected signal"); + try { + handleMessage(new org.freedesktop.DBus.Local.Disconnected("/")); + } catch (Exception ee) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, ee); + } + + if (Debug.debug) Debug.print(Debug.INFO, "Disconnecting Abstract Connection"); + // run all pending tasks. + while (runnables.size() > 0) + synchronized (runnables) { + runnables.notifyAll(); + } + + // stop the main thread + _run = false; + + // unblock the sending thread. + synchronized (outgoing) { + outgoing.notifyAll(); + } + + // disconnect from the trasport layer + try { + if (null != transport) { + transport.disconnect(); + transport = null; + } + } catch (IOException IOe) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, IOe); + } + + // stop all the workers + synchronized(workers) { + for (_workerthread t: workers) + t.halt(); + } + + // make sure none are blocking on the runnables queue still + synchronized (runnables) { + runnables.notifyAll(); + } + } + + public void finalize() + { + disconnect(); + } + /** + * Return any DBus error which has been received. + * @return A DBusExecutionException, or null if no error is pending. + */ + public DBusExecutionException getError() + { + synchronized (pendingErrors) { + if (pendingErrors.size() == 0) return null; + else + return pendingErrors.removeFirst().getException(); + } + } + + /** + * Call a method asynchronously and set a callback. + * This handler will be called in a separate thread. + * @param object The remote object on which to call the method. + * @param m The name of the method on the interface to call. + * @param callback The callback handler. + * @param parameters The parameters to call the method with. + */ + @SuppressWarnings("unchecked") + public <A> void callWithCallback(DBusInterface object, String m, CallbackHandler<A> callback, Object... parameters) + { + if (Debug.debug) Debug.print(Debug.VERBOSE, "callWithCallback("+object+","+m+", "+callback); + Class[] types = new Class[parameters.length]; + for (int i = 0; i < parameters.length; i++) + types[i] = parameters[i].getClass(); + RemoteObject ro = importedObjects.get(object); + + try { + Method me = null; + if (null == ro.iface) + me = object.getClass().getMethod(m, types); + else { + Method[] methods = ro.iface.getMethods(); + for (Method method: methods) { +// System.out.println(method.getName()); + for (Class<?> parameterType: method.getParameterTypes()) { +// System.out.println("parameter: " + parameterType.getName()); + } + if (method.getName().equals(m)) { + me = method; + } + } +// Following code doesn't work: if actual paremeter is BasicEList and definition of parameter is List, the method is not found +// try { +// Method me2 = ro.iface.getMethod(m, types); +// } catch (NoSuchMethodException e) { +// System.out.println("NoSuchMethodException: method name = " + m); +// for (Class type: types) { +// System.out.println("type = " + type.getName()); +// } +// } + } + RemoteInvocationHandler.executeRemoteMethod(ro, me, this, RemoteInvocationHandler.CALL_TYPE_CALLBACK, callback, parameters); + } catch (DBusExecutionException DBEe) { + DBEe.printStackTrace(); + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, DBEe); + throw DBEe; + } catch (Exception e) { + e.printStackTrace(); + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, e); + throw new DBusExecutionException(e.getMessage()); + } + } + + /** + * Call a method asynchronously and get a handle with which to get the reply. + * @param object The remote object on which to call the method. + * @param m The name of the method on the interface to call. + * @param parameters The parameters to call the method with. + * @return A handle to the call. + */ + @SuppressWarnings("unchecked") + public DBusAsyncReply callMethodAsync(DBusInterface object, String m, Object... parameters) + { + Class<?>[] types = new Class[parameters.length]; + for (int i = 0; i < parameters.length; i++) + types[i] = parameters[i].getClass(); + RemoteObject ro = importedObjects.get(object); + + try { + Method me = null; + if (null == ro.iface) { +// System.out.println("ro.iface == null"); + me = object.getClass().getMethod(m, types); + } else { +// System.out.println("ro.iface != null"); + Method[] methods = ro.iface.getMethods(); + for (Method method: methods) { +// System.out.println(method.getName()); +// for (Class<?> parameterType: method.getParameterTypes()) { +// System.out.println("parameter: " + parameterType.getName()); +// } + if (method.getName().equals(m)) { + me = method; + } + } +// me = ro.iface.getMethod(m, types); +// System.out.println("me = " + me); + } + return (DBusAsyncReply) RemoteInvocationHandler.executeRemoteMethod(ro, me, this, RemoteInvocationHandler.CALL_TYPE_ASYNC, null, parameters); + } catch (DBusExecutionException DBEe) { + DBEe.printStackTrace(); + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, DBEe); + throw DBEe; + } catch (Exception e) { + e.printStackTrace(); + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, e); + throw new DBusExecutionException(e.getMessage()); + } + } + + private void handleMessage(final MethodCall m) throws DBusException + { + if (Debug.debug) Debug.print(Debug.DEBUG, "Handling incoming method call: "+m); + + currentSender = m.getSource(); // pego + ExportedObject eo = null; + Method meth = null; + Object o = null; + + if (null == m.getInterface() || + m.getInterface().equals("org.freedesktop.DBus.Peer") || + m.getInterface().equals("org.freedesktop.DBus.Introspectable")) { + synchronized (exportedObjects) { + eo = exportedObjects.get(null); + } + if (null != eo && null == eo.object.get()) { + unExportObject(null); + eo = null; + } + if (null != eo) { + meth = eo.methods.get(new MethodTuple(m.getName(), m.getSig())); + } + if (null != meth) + o = new _globalhandler(m.getPath()); + else + eo = null; + } + if (null == o) { + // now check for specific exported functions + + synchronized (exportedObjects) { + eo = exportedObjects.get(m.getPath()); + } + if (null != eo && null == eo.object.get()) { + if (Debug.debug) Debug.print(Debug.INFO, "Unexporting "+m.getPath()+" implicitly"); + unExportObject(m.getPath()); + eo = null; + } + + if (null == eo) { + eo = fallbackcontainer.get(m.getPath()); + } + + if (null == eo) { + try { + queueOutgoing(new Error(m, new DBus.Error.UnknownObject(m.getPath()+_(" is not an object provided by this process.")))); + } catch (DBusException DBe) {} + return; + } + if (Debug.debug) { + Debug.print(Debug.VERBOSE, "Searching for method "+m.getName()+" with signature "+m.getSig()); + Debug.print(Debug.VERBOSE, "List of methods on "+eo+":"); + for (MethodTuple mt: eo.methods.keySet()) + Debug.print(Debug.VERBOSE, " "+mt+" => "+eo.methods.get(mt)); + } + meth = eo.methods.get(new MethodTuple(m.getName(), m.getSig())); + if (null == meth) { + try { + queueOutgoing(new Error(m, new DBus.Error.UnknownMethod(MessageFormat.format(_("The method `{0}.{1}' does not exist on this object."), new Object[] { m.getInterface(), m.getName() })))); + } catch (DBusException DBe) {} + return; + } + o = eo.object.get(); + } + + // now execute it + final Method me = meth; + final Object ob = o; + final boolean noreply = (1 == (m.getFlags() & Message.Flags.NO_REPLY_EXPECTED)); + final DBusCallInfo info = new DBusCallInfo(m); + final AbstractConnection conn = this; + if (Debug.debug) Debug.print(Debug.VERBOSE, "Adding Runnable for method "+meth); + addRunnable(new Runnable() + { + private boolean run = false; + public synchronized void run() + { + if (run) return; + run = true; + if (Debug.debug) Debug.print(Debug.DEBUG, "Running method "+me+" for remote call"); + try { + Type[] ts = me.getGenericParameterTypes(); + m.setArgs(Marshalling.deSerializeParameters(m.getParameters(), ts, conn)); + if (Debug.debug) Debug.print(Debug.VERBOSE, "Deserialised "+Arrays.deepToString(m.getParameters())+" to types "+Arrays.deepToString(ts)); + } catch (Exception e) { + e.printStackTrace(); + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, e); + try { + conn.queueOutgoing(new Error(m, new DBus.Error.UnknownMethod(_("Failure in de-serializing message: ")+e))); + } catch (DBusException DBe) {} + return; + } + + try { + synchronized (infomap) { + infomap.put(Thread.currentThread(), info); + } + Object result; + try { + if (Debug.debug) Debug.print(Debug.VERBOSE, "Invoking Method: "+me+" on "+ob+" with parameters "+Arrays.deepToString(m.getParameters())); + result = me.invoke(ob, m.getParameters()); + } catch (InvocationTargetException ITe) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, ITe.getCause()); + throw ITe.getCause(); + } + synchronized (infomap) { + infomap.remove(Thread.currentThread()); + } + if (!noreply) { + MethodReturn reply; + if (Void.TYPE.equals(me.getReturnType())) + reply = new MethodReturn(m, null); + else { + StringBuffer sb = new StringBuffer(); + for (String s: Marshalling.getDBusType(me.getGenericReturnType())) + sb.append(s); + Object[] nr = Marshalling.convertParameters(new Object[] { result }, new Type[] {me.getGenericReturnType()}, conn); + + reply = new MethodReturn(m, sb.toString(),nr); + } + conn.queueOutgoing(reply); + } + } catch (DBusExecutionException DBEe) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, DBEe); + try { + conn.queueOutgoing(new Error(m, DBEe)); + } catch (DBusException DBe) {} + } catch (Throwable e) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, e); + try { + conn.queueOutgoing(new Error(m, new DBusExecutionException(MessageFormat.format(_("Error Executing Method {0}.{1}: {2}"), new Object[] { m.getInterface(), m.getName(), e.getMessage() })))); + } catch (DBusException DBe) {} + } + } + }); + } + @SuppressWarnings({"unchecked","deprecation"}) + private void handleMessage(final DBusSignal s) + { + if (Debug.debug) Debug.print(Debug.DEBUG, "Handling incoming signal: "+s); + Vector<DBusSigHandler<? extends DBusSignal>> v = new Vector<DBusSigHandler<? extends DBusSignal>>(); + synchronized(handledSignals) { + Vector<DBusSigHandler<? extends DBusSignal>> t; + t = handledSignals.get(new SignalTuple(s.getInterface(), s.getName(), null, null)); + if (null != t) v.addAll(t); + t = handledSignals.get(new SignalTuple(s.getInterface(), s.getName(), s.getPath(), null)); + if (null != t) v.addAll(t); + t = handledSignals.get(new SignalTuple(s.getInterface(), s.getName(), null, s.getSource())); + if (null != t) v.addAll(t); + t = handledSignals.get(new SignalTuple(s.getInterface(), s.getName(), s.getPath(), s.getSource())); + if (null != t) v.addAll(t); + } + if (0 == v.size()) return; + final AbstractConnection conn = this; + for (final DBusSigHandler<? extends DBusSignal> h: v) { + if (Debug.debug) Debug.print(Debug.VERBOSE, "Adding Runnable for signal "+s+" with handler "+h); + addRunnable(new Runnable() { + private boolean run = false; + public synchronized void run() + { + if (run) return; + run = true; + try { + DBusSignal rs; + if (s instanceof DBusSignal.internalsig || s.getClass().equals(DBusSignal.class)) + rs = s.createReal(conn); + else + rs = s; + ((DBusSigHandler<DBusSignal>)h).handle(rs); + } catch (DBusException DBe) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, DBe); + try { + conn.queueOutgoing(new Error(s, new DBusExecutionException("Error handling signal "+s.getInterface()+"."+s.getName()+": "+DBe.getMessage()))); + } catch (DBusException DBe2) {} + } + } + }); + } + } + private void handleMessage(final Error err) + { + if (Debug.debug) Debug.print(Debug.DEBUG, "Handling incoming error: "+err); + MethodCall m = null; + if (null == pendingCalls) return; + synchronized (pendingCalls) { + if (pendingCalls.contains(err.getReplySerial())) + m = pendingCalls.remove(err.getReplySerial()); + } + if (null != m) { + m.setReply(err); + CallbackHandler cbh = null; + DBusAsyncReply asr = null; + synchronized (pendingCallbacks) { + cbh = pendingCallbacks.remove(m); + if (Debug.debug) Debug.print(Debug.VERBOSE, cbh+" = pendingCallbacks.remove("+m+")"); + asr = pendingCallbackReplys.remove(m); + } + // queue callback for execution + if (null != cbh) { + final CallbackHandler fcbh = cbh; + if (Debug.debug) Debug.print(Debug.VERBOSE, "Adding Error Runnable with callback handler "+fcbh); + addRunnable(new Runnable() { + private boolean run = false; + public synchronized void run() + { + if (run) return; + run = true; + try { + if (Debug.debug) Debug.print(Debug.VERBOSE, "Running Error Callback for "+err); + DBusCallInfo info = new DBusCallInfo(err); + synchronized (infomap) { + infomap.put(Thread.currentThread(), info); + } + + fcbh.handleError(err.getException()); + synchronized (infomap) { + infomap.remove(Thread.currentThread()); + } + + } catch (Exception e) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, e); + } + } + }); + } + + } + else + synchronized (pendingErrors) { + pendingErrors.addLast(err); } + } + @SuppressWarnings("unchecked") + private void handleMessage(final MethodReturn mr) + { + if (Debug.debug) Debug.print(Debug.DEBUG, "Handling incoming method return: "+mr); + MethodCall m = null; + if (null == pendingCalls) return; + synchronized (pendingCalls) { + if (pendingCalls.contains(mr.getReplySerial())) + m = pendingCalls.remove(mr.getReplySerial()); + } + if (null != m) { + m.setReply(mr); + mr.setCall(m); + CallbackHandler cbh = null; + DBusAsyncReply asr = null; + synchronized (pendingCallbacks) { + cbh = pendingCallbacks.remove(m); + if (Debug.debug) Debug.print(Debug.VERBOSE, cbh+" = pendingCallbacks.remove("+m+")"); + asr = pendingCallbackReplys.remove(m); + } + // queue callback for execution + if (null != cbh) { + final CallbackHandler fcbh = cbh; + final DBusAsyncReply fasr = asr; + if (Debug.debug) Debug.print(Debug.VERBOSE, "Adding Runnable for method "+fasr.getMethod()+" with callback handler "+fcbh); + addRunnable(new Runnable() { + private boolean run = false; + public synchronized void run() + { + if (run) return; + run = true; + try { + if (Debug.debug) Debug.print(Debug.VERBOSE, "Running Callback for "+mr); + DBusCallInfo info = new DBusCallInfo(mr); + synchronized (infomap) { + infomap.put(Thread.currentThread(), info); + } + + fcbh.handle(RemoteInvocationHandler.convertRV(mr.getSig(), mr.getParameters(), fasr.getMethod(), fasr.getConnection())); + synchronized (infomap) { + infomap.remove(Thread.currentThread()); + } + + } catch (Exception e) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, e); + } + } + }); + } + + } else + try { + queueOutgoing(new Error(mr, new DBusExecutionException(_("Spurious reply. No message with the given serial id was awaiting a reply.")))); + } catch (DBusException DBe) {} + } + protected void sendMessage(Message m) + { + try { + if (!connected) throw new NotConnected(_("Disconnected")); + if (m instanceof DBusSignal) + ((DBusSignal) m).appendbody(this); + + if (m instanceof MethodCall) { + if (0 == (m.getFlags() & Message.Flags.NO_REPLY_EXPECTED)) + if (null == pendingCalls) + ((MethodCall) m).setReply(new Error("org.freedesktop.DBus.Local", "org.freedesktop.DBus.Local.Disconnected", 0, "s", new Object[] { _("Disconnected") })); + else synchronized (pendingCalls) { + pendingCalls.put(m.getSerial(),(MethodCall) m); + } + } + + transport.mout.writeMessage(m); + + } catch (Exception e) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, e); + if (m instanceof MethodCall && e instanceof NotConnected) + try { + ((MethodCall) m).setReply(new Error("org.freedesktop.DBus.Local", "org.freedesktop.DBus.Local.Disconnected", 0, "s", new Object[] { _("Disconnected") })); + } catch (DBusException DBe) {} + if (m instanceof MethodCall && e instanceof DBusExecutionException) + try { + ((MethodCall)m).setReply(new Error(m, e)); + } catch (DBusException DBe) {} + else if (m instanceof MethodCall) + try { + if (Debug.debug) Debug.print(Debug.INFO, "Setting reply to "+m+" as an error"); + ((MethodCall)m).setReply(new Error(m, new DBusExecutionException(_("Message Failed to Send: ")+e.getMessage()))); + } catch (DBusException DBe) {} + else if (m instanceof MethodReturn) + try { + transport.mout.writeMessage(new Error(m, e)); + } catch(IOException IOe) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, IOe); + } catch(DBusException IOe) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, e); + } + if (e instanceof IOException) disconnect(); + } + } + private Message readIncoming() throws DBusException + { + if (!connected) throw new NotConnected(_("No transport present")); + Message m = null; + try { + m = transport.min.readMessage(); + } catch (IOException IOe) { + throw new FatalDBusException(IOe.getMessage()); + } + return m; + } + /** + * Returns the address this connection is connected to. + */ + public BusAddress getAddress() throws ParseException { return new BusAddress(addr); } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/ArrayFrob.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/ArrayFrob.java new file mode 100755 index 0000000..978b198 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/ArrayFrob.java @@ -0,0 +1,173 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import static org.freedesktop.dbus.Gettext._; + +import java.lang.reflect.Array; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Hashtable; +import java.util.List; + +import cx.ath.matthew.debug.Debug; + +class ArrayFrob +{ + static Hashtable<Class<? extends Object>, Class<? extends Object>> primitiveToWrapper = new Hashtable<Class<? extends Object>, Class<? extends Object>>(); + static Hashtable<Class<? extends Object>, Class<? extends Object>> wrapperToPrimitive = new Hashtable<Class<? extends Object>, Class<? extends Object>>(); + static { + primitiveToWrapper.put( Boolean.TYPE, Boolean.class ); + primitiveToWrapper.put( Byte.TYPE, Byte.class ); + primitiveToWrapper.put( Short.TYPE, Short.class ); + primitiveToWrapper.put( Character.TYPE, Character.class ); + primitiveToWrapper.put( Integer.TYPE, Integer.class ); + primitiveToWrapper.put( Long.TYPE, Long.class ); + primitiveToWrapper.put( Float.TYPE, Float.class ); + primitiveToWrapper.put( Double.TYPE, Double.class ); + wrapperToPrimitive.put( Boolean.class, Boolean.TYPE ); + wrapperToPrimitive.put( Byte.class, Byte.TYPE ); + wrapperToPrimitive.put( Short.class, Short.TYPE ); + wrapperToPrimitive.put( Character.class, Character.TYPE ); + wrapperToPrimitive.put( Integer.class, Integer.TYPE ); + wrapperToPrimitive.put( Long.class, Long.TYPE ); + wrapperToPrimitive.put( Float.class, Float.TYPE ); + wrapperToPrimitive.put( Double.class, Double.TYPE ); + + } + @SuppressWarnings("unchecked") + public static <T> T[] wrap(Object o) throws IllegalArgumentException + { + Class<? extends Object> ac = o.getClass(); + if (!ac.isArray()) throw new IllegalArgumentException(_("Not an array")); + Class<? extends Object> cc = ac.getComponentType(); + Class<? extends Object> ncc = primitiveToWrapper.get(cc); + if (null == ncc) throw new IllegalArgumentException(_("Not a primitive type")); + T[] ns = (T[]) Array.newInstance(ncc, Array.getLength(o)); + for (int i = 0; i < ns.length; i++) + ns[i] = (T) Array.get(o, i); + return ns; + } + @SuppressWarnings("unchecked") + public static <T> Object unwrap(T[] ns) throws IllegalArgumentException + { + Class<? extends T[]> ac = (Class<? extends T[]>) ns.getClass(); + Class<T> cc = (Class<T>) ac.getComponentType(); + Class<? extends Object> ncc = wrapperToPrimitive.get(cc); + if (null == ncc) throw new IllegalArgumentException(_("Not a wrapper type")); + Object o = Array.newInstance(ncc, ns.length); + for (int i = 0; i < ns.length; i++) + Array.set(o, i, ns[i]); + return o; + } + public static <T> List<T> listify(T[] ns) throws IllegalArgumentException + { + return Arrays.asList(ns); + } + @SuppressWarnings("unchecked") + public static <T> List<T> listify(Object o) throws IllegalArgumentException + { + if (o instanceof Object[]) return listify((T[]) o); + if (!o.getClass().isArray()) throw new IllegalArgumentException(_("Not an array")); + List<T> l = new ArrayList<T>(Array.getLength(o)); + for (int i = 0; i < Array.getLength(o); i++) + l.add((T)Array.get(o, i)); + return l; + } + @SuppressWarnings("unchecked") + public static <T> T[] delist(List<T> l, Class<T> c) throws IllegalArgumentException + { + return l.toArray((T[]) Array.newInstance(c, 0)); + } + public static <T> Object delistprimitive(List<T> l, Class<T> c) throws IllegalArgumentException + { + Object o = Array.newInstance(c, l.size()); + for (int i = 0; i < l.size(); i++) + Array.set(o, i, l.get(i)); + return o; + } + @SuppressWarnings("unchecked") + public static Object convert(Object o, Class<? extends Object> c) throws IllegalArgumentException + { + /* Possible Conversions: + * + ** List<Integer> -> List<Integer> + ** List<Integer> -> int[] + ** List<Integer> -> Integer[] + ** int[] -> int[] + ** int[] -> List<Integer> + ** int[] -> Integer[] + ** Integer[] -> Integer[] + ** Integer[] -> int[] + ** Integer[] -> List<Integer> + */ + try { + // List<Integer> -> List<Integer> + if (List.class.equals(c) + && o instanceof List) + return o; + + // int[] -> List<Integer> + // Integer[] -> List<Integer> + if (List.class.equals(c) + && o.getClass().isArray()) + return listify(o); + + // int[] -> int[] + // Integer[] -> Integer[] + if (o.getClass().isArray() + && c.isArray() + && o.getClass().getComponentType().equals(c.getComponentType())) + return o; + + // int[] -> Integer[] + if (o.getClass().isArray() + && c.isArray() + && o.getClass().getComponentType().isPrimitive()) + return wrap(o); + + // Integer[] -> int[] + if (o.getClass().isArray() + && c.isArray() + && c.getComponentType().isPrimitive()) + return unwrap((Object[]) o); + + // List<Integer> -> int[] + if (o instanceof List + && c.isArray() + && c.getComponentType().isPrimitive()) + return delistprimitive((List<Object>) o, (Class<Object>) c.getComponentType()); + + // List<Integer> -> Integer[] + if (o instanceof List + && c.isArray()) + return delist((List<Object>) o, (Class<Object>) c.getComponentType()); + + if (o.getClass().isArray() + && c.isArray()) + return type((Object[]) o, (Class<Object>) c.getComponentType()); + + } catch (Exception e) { + if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, e); + throw new IllegalArgumentException(e); + } + + throw new IllegalArgumentException(MessageFormat.format(_("Not An Expected Convertion type from {0} to {1}"), new Object[] { o.getClass(), c})); + } + public static Object[] type(Object[] old, Class<Object> c) + { + Object[] ns = (Object[]) Array.newInstance(c, old.length); + for (int i = 0; i < ns.length; i++) + ns[i] = old[i]; + return ns; + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/BusAddress.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/BusAddress.java new file mode 100755 index 0000000..84594da --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/BusAddress.java @@ -0,0 +1,41 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; +import static org.freedesktop.dbus.Gettext._; +import java.text.ParseException; +import java.util.Map; +import java.util.HashMap; +import cx.ath.matthew.debug.Debug; + +public class BusAddress +{ + private String type; + private Map<String,String> parameters; + public BusAddress(String address) throws ParseException + { + if (null == address || "".equals(address)) throw new ParseException(_("Bus address is blank"), 0); + if (Debug.debug) Debug.print(Debug.VERBOSE, "Parsing bus address: "+address); + String[] ss = address.split(":", 2); + if (ss.length < 2) throw new ParseException(_("Bus address is invalid: ")+address, 0); + type = ss[0]; + if (Debug.debug) Debug.print(Debug.VERBOSE, "Transport type: "+type); + String[] ps = ss[1].split(","); + parameters = new HashMap<String,String>(); + for (String p: ps) { + String[] kv = p.split("=", 2); + parameters.put(kv[0], kv[1]); + } + if (Debug.debug) Debug.print(Debug.VERBOSE, "Transport options: "+parameters); + } + public String getType() { return type; } + public String getParameter(String key) { return parameters.get(key); } + public String toString() { return type+": "+parameters; } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/CallbackHandler.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/CallbackHandler.java new file mode 100755 index 0000000..b05b500 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/CallbackHandler.java @@ -0,0 +1,22 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import org.freedesktop.dbus.exceptions.DBusExecutionException; + +/** + * Interface for callbacks in async mode + */ +public interface CallbackHandler<ReturnType> +{ + public void handle(ReturnType r); + public void handleError(DBusExecutionException e); +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Container.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Container.java new file mode 100755 index 0000000..d2efb67 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Container.java @@ -0,0 +1,88 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.lang.reflect.Field; +import java.lang.reflect.Type; + +/** + * This class is the super class of both Structs and Tuples + * and holds common methods. + */ +abstract class Container +{ + private static Map<Type,Type[]> typecache = new HashMap<Type,Type[]>(); + static void putTypeCache(Type k, Type[] v) + { + typecache.put(k, v); + } + static Type[] getTypeCache(Type k) + { + return typecache.get(k); + } + private Object[] parameters = null; + public Container() {} + private void setup() + { + Field[] fs = getClass().getDeclaredFields(); + Object[] args = new Object[fs.length]; + + int diff = 0; + for (Field f : fs) { + Position p = f.getAnnotation(Position.class); + if (null == p) { + diff++; + continue; + } + try { + args[p.value()] = f.get(this); + } catch (IllegalAccessException IAe) {} + } + + this.parameters = new Object[args.length - diff]; + System.arraycopy(args, 0, parameters, 0, parameters.length); + } + /** + * Returns the struct contents in order. + * @throws DBusException If there is a problem doing this. + */ + public final Object[] getParameters() + { + if (null != parameters) return parameters; + setup(); + return parameters; + } + /** Returns this struct as a string. */ + public final String toString() + { + String s = getClass().getName()+"<"; + if (null == parameters) + setup(); + if (0 == parameters.length) + return s+">"; + for (Object o: parameters) + s += o+", "; + return s.replaceAll(", $", ">"); + } + public final boolean equals(Object other) + { + if (other instanceof Container) { + Container that = (Container) other; + if (this.getClass().equals(that.getClass())) + return Arrays.equals(this.getParameters(), that.getParameters()); + else return false; + } + else return false; + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusAsyncReply.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusAsyncReply.java new file mode 100755 index 0000000..252cf07 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusAsyncReply.java @@ -0,0 +1,111 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import static org.freedesktop.dbus.Gettext._; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; + +import org.freedesktop.DBus.Error.NoReply; +import org.freedesktop.dbus.exceptions.DBusException; +import org.freedesktop.dbus.exceptions.DBusExecutionException; + +import cx.ath.matthew.debug.Debug; + +/** + * A handle to an asynchronous method call. + */ +public class DBusAsyncReply<ReturnType> +{ + /** + * Check if any of a set of asynchronous calls have had a reply. + * @param replies A Collection of handles to replies to check. + * @return A Collection only containing those calls which have had replies. + */ + public static Collection<DBusAsyncReply<? extends Object>> hasReply(Collection<DBusAsyncReply<? extends Object>> replies) + { + Collection<DBusAsyncReply<? extends Object>> c = new ArrayList<DBusAsyncReply<? extends Object>>(replies); + Iterator<DBusAsyncReply<? extends Object>> i = c.iterator(); + while (i.hasNext()) + if (!i.next().hasReply()) i.remove(); + return c; + } + + private ReturnType rval = null; + private DBusExecutionException error = null; + private MethodCall mc; + private Method me; + private AbstractConnection conn; + DBusAsyncReply(MethodCall mc, Method me, AbstractConnection conn) + { + this.mc = mc; + this.me = me; + this.conn = conn; + } + @SuppressWarnings("unchecked") + private synchronized void checkReply() + { + if (mc.hasReply()) { + Message m = mc.getReply(); + if (m instanceof Error) + error = ((Error) m).getException(); + else if (m instanceof MethodReturn) { + try { + rval = (ReturnType) RemoteInvocationHandler.convertRV(m.getSig(), m.getParameters(), me, conn); + } catch (DBusExecutionException DBEe) { + error = DBEe; + } catch (DBusException DBe) { + if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, DBe); + error = new DBusExecutionException(DBe.getMessage()); + } + } + } + } + + /** + * Check if we've had a reply. + * @return True if we have a reply + */ + public boolean hasReply() + { + if (null != rval || null != error) return true; + checkReply(); + return null != rval || null != error; + } + + /** + * Get the reply. + * @return The return value from the method. + * @throws DBusExecutionException if the reply to the method was an error. + * @throws NoReply if the method hasn't had a reply yet + */ + public ReturnType getReply() throws DBusExecutionException + { + if (null != rval) return rval; + else if (null != error) throw error; + checkReply(); + if (null != rval) return rval; + else if (null != error) throw error; + else throw new NoReply(_("Async call has not had a reply")); + } + + public String toString() + { + return _("Waiting for: ")+mc; + } + Method getMethod() { return me; } + AbstractConnection getConnection() { return conn; } + MethodCall getCall() { return mc; } +} + diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusCallInfo.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusCallInfo.java new file mode 100755 index 0000000..d34ef4e --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusCallInfo.java @@ -0,0 +1,51 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +/** + * Holds information on a method call + */ +public class DBusCallInfo +{ + /** + * Indicates the caller won't wait for a reply (and we won't send one). + */ + public static final int NO_REPLY = Message.Flags.NO_REPLY_EXPECTED; + public static final int ASYNC = 0x100; + private String source; + private String destination; + private String objectpath; + private String iface; + private String method; + private int flags; + DBusCallInfo(Message m) + { + this.source = m.getSource(); + this.destination = m.getDestination(); + this.objectpath = m.getPath(); + this.iface = m.getInterface(); + this.method = m.getName(); + this.flags = m.getFlags(); + } + + /** Returns the BusID which called the method */ + public String getSource() { return source; } + /** Returns the name with which we were addressed on the Bus */ + public String getDestination() { return destination; } + /** Returns the object path used to call this method */ + public String getObjectPath() { return objectpath; } + /** Returns the interface this method was called with */ + public String getInterface() { return iface; } + /** Returns the method name used to call this method */ + public String getMethod() { return method; } + /** Returns any flags set on this method call */ + public int getFlags() { return flags; } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusConnection.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusConnection.java new file mode 100755 index 0000000..6609833 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusConnection.java @@ -0,0 +1,780 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import static org.freedesktop.dbus.Gettext._; + +import java.lang.reflect.Proxy; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +import java.text.MessageFormat; +import java.text.ParseException; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import java.util.Vector; + +import org.freedesktop.DBus; +import org.freedesktop.dbus.exceptions.DBusException; +import org.freedesktop.dbus.exceptions.DBusExecutionException; +import org.freedesktop.dbus.exceptions.NotConnected; + +import cx.ath.matthew.debug.Debug; + +/** Handles a connection to DBus. + * <p> + * This is a Singleton class, only 1 connection to the SYSTEM or SESSION busses can be made. + * Repeated calls to getConnection will return the same reference. + * </p> + * <p> + * Signal Handlers and method calls from remote objects are run in their own threads, you MUST handle the concurrency issues. + * </p> + */ +public class DBusConnection extends AbstractConnection +{ + /** + * Add addresses of peers to a set which will watch for them to + * disappear and automatically remove them from the set. + */ + public class PeerSet implements Set<String>, DBusSigHandler<DBus.NameOwnerChanged> + { + private Set<String> addresses; + public PeerSet() + { + addresses = new TreeSet<String>(); + try { + addSigHandler(new DBusMatchRule(DBus.NameOwnerChanged.class, null, null), this); + } catch (DBusException DBe) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, DBe); + } + } + public void handle(DBus.NameOwnerChanged noc) + { + if (Debug.debug) + Debug.print(Debug.DEBUG, "Received NameOwnerChanged("+noc.name+","+noc.old_owner+","+noc.new_owner+")"); + if ("".equals(noc.new_owner) && addresses.contains(noc.name)) + remove(noc.name); + } + public boolean add(String address) + { + if (Debug.debug) + Debug.print(Debug.DEBUG, "Adding "+address); + synchronized (addresses) { + return addresses.add(address); + } + } + public boolean addAll(Collection<? extends String> addresses) + { + synchronized (this.addresses) { + return this.addresses.addAll(addresses); + } + } + public void clear() + { + synchronized (addresses) { + addresses.clear(); + } + } + public boolean contains(Object o) + { + return addresses.contains(o); + } + public boolean containsAll(Collection<?> os) + { + return addresses.containsAll(os); + } + public boolean equals(Object o) + { + if (o instanceof PeerSet) + return ((PeerSet) o).addresses.equals(addresses); + else return false; + } + public int hashCode() + { + return addresses.hashCode(); + } + public boolean isEmpty() + { + return addresses.isEmpty(); + } + public Iterator<String> iterator() + { + return addresses.iterator(); + } + public boolean remove(Object o) + { + if (Debug.debug) + Debug.print(Debug.DEBUG, "Removing "+o); + synchronized(addresses) { + return addresses.remove(o); + } + } + public boolean removeAll(Collection<?> os) + { + synchronized(addresses) { + return addresses.removeAll(os); + } + } + public boolean retainAll(Collection<?> os) + { + synchronized(addresses) { + return addresses.retainAll(os); + } + } + public int size() + { + return addresses.size(); + } + public Object[] toArray() + { + synchronized(addresses) { + return addresses.toArray(); + } + } + public <T> T[] toArray(T[] a) + { + synchronized(addresses) { + return addresses.toArray(a); + } + } + } + private class _sighandler implements DBusSigHandler<DBusSignal> + { + public void handle(DBusSignal s) + { + if (s instanceof org.freedesktop.DBus.Local.Disconnected) { + if (Debug.debug) Debug.print(Debug.WARN, "Handling Disconnected signal from bus"); + try { + Error err = new Error( + "org.freedesktop.DBus.Local" , "org.freedesktop.DBus.Local.Disconnected", 0, "s", new Object[] { _("Disconnected") }); + if (null != pendingCalls) synchronized (pendingCalls) { + long[] set = pendingCalls.getKeys(); + for (long l: set) if (-1 != l) { + MethodCall m = pendingCalls.remove(l); + if (null != m) + m.setReply(err); + } + } + synchronized (pendingErrors) { + pendingErrors.add(err); + } + } catch (DBusException DBe) {} + } else if (s instanceof org.freedesktop.DBus.NameAcquired) { + busnames.add(((org.freedesktop.DBus.NameAcquired) s).name); + } + } + } + + /** + * System Bus + */ + public static final int SYSTEM = 0; + /** + * Session Bus + */ + public static final int SESSION = 1; + + public static final String DEFAULT_SYSTEM_BUS_ADDRESS = "unix:path=/var/run/dbus/system_bus_socket"; + + private List<String> busnames; + + private static final Map<Object,DBusConnection> conn = new HashMap<Object,DBusConnection>(); + private int _refcount = 0; + private Object _reflock = new Object(); + private DBus _dbus; + + /** + * Connect to the BUS. If a connection already exists to the specified Bus, a reference to it is returned. + * @param address The address of the bus to connect to + * @throws DBusException If there is a problem connecting to the Bus. + */ + public static DBusConnection getConnection(String address) throws DBusException + { + synchronized (conn) { + DBusConnection c = conn.get(address); + if (null != c) { + synchronized (c._reflock) { c._refcount++; } + return c; + } + else { + c = new DBusConnection(address); + conn.put(address, c); + return c; + } + } + } + /** + * Connect to the BUS. If a connection already exists to the specified Bus, a reference to it is returned. + * @param bustype The Bus to connect to. + * @see #SYSTEM + * @see #SESSION + * @throws DBusException If there is a problem connecting to the Bus. + */ + public static DBusConnection getConnection(int bustype) throws DBusException + { + synchronized (conn) { + String s = null; + switch (bustype) { + case SYSTEM: + s = System.getenv("DBUS_SYSTEM_BUS_ADDRESS"); + if (null == s) s = DEFAULT_SYSTEM_BUS_ADDRESS; + break; + case SESSION: + s = System.getenv("DBUS_SESSION_BUS_ADDRESS"); + if (null == s) { + // address gets stashed in $HOME/.dbus/session-bus/`dbus-uuidgen --get`-`sed 's/:\(.\)\..*/\1/' <<< $DISPLAY` + String display = System.getenv("DISPLAY"); + if (null == display) throw new DBusException(_("Cannot Resolve Session Bus Address")); + File uuidfile = new File("/var/lib/dbus/machine-id"); + if (!uuidfile.exists()) throw new DBusException(_("Cannot Resolve Session Bus Address")); + try { + BufferedReader r = new BufferedReader(new FileReader(uuidfile)); + String uuid = r.readLine(); + String homedir = System.getProperty("user.home"); + File addressfile = new File(homedir + "/.dbus/session-bus", + uuid + "-" + display.replaceAll(":([0-9]*)\\..*", "$1")); + if (!addressfile.exists()) throw new DBusException(_("Cannot Resolve Session Bus Address")); + r = new BufferedReader(new FileReader(addressfile)); + String l; + while (null != (l = r.readLine())) { + if (Debug.debug) Debug.print(Debug.VERBOSE, "Reading D-Bus session data: "+l); + if (l.matches("DBUS_SESSION_BUS_ADDRESS.*")) { + s = l.replaceAll("^[^=]*=", ""); + if (Debug.debug) Debug.print(Debug.VERBOSE, "Parsing "+l+" to "+s); + } + } + if (null == s || "".equals(s)) throw new DBusException(_("Cannot Resolve Session Bus Address")); + if (Debug.debug) Debug.print(Debug.INFO, "Read bus address "+s+" from file "+addressfile.toString()); + } catch (Exception e) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, e); + throw new DBusException(_("Cannot Resolve Session Bus Address")); + } + } + break; + default: + throw new DBusException(_("Invalid Bus Type: ")+bustype); + } + DBusConnection c = conn.get(s); + if (Debug.debug) Debug.print(Debug.VERBOSE, "Getting bus connection for "+s+": "+c); + if (null != c) { + synchronized (c._reflock) { c._refcount++; } + return c; + } + else { + if (Debug.debug) Debug.print(Debug.DEBUG, "Creating new bus connection to: "+s); + c = new DBusConnection(s); + conn.put(s, c); + return c; + } + } + } + @SuppressWarnings("unchecked") + private DBusConnection(String address) throws DBusException + { + super(address); + busnames = new Vector<String>(); + + synchronized (_reflock) { + _refcount = 1; + } + + try { + transport = new Transport(addr, AbstractConnection.TIMEOUT); + connected = true; + } catch (IOException IOe) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, IOe); + disconnect(); + throw new DBusException(_("Failed to connect to bus ")+IOe.getMessage()); + } catch (ParseException Pe) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, Pe); + disconnect(); + throw new DBusException(_("Failed to connect to bus ")+Pe.getMessage()); + } + + // start listening for calls + listen(); + + // register disconnect handlers + DBusSigHandler h = new _sighandler(); + addSigHandlerWithoutMatch(org.freedesktop.DBus.Local.Disconnected.class, h); + addSigHandlerWithoutMatch(org.freedesktop.DBus.NameAcquired.class, h); + + // register ourselves + _dbus = getRemoteObject("org.freedesktop.DBus", "/org/freedesktop/DBus", DBus.class); + try { + busnames.add(_dbus.Hello()); + } catch (DBusExecutionException DBEe) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, DBEe); + throw new DBusException(DBEe.getMessage()); + } + } + + @SuppressWarnings("unchecked") + DBusInterface dynamicProxy(String source, String path) throws DBusException + { + if (Debug.debug) Debug.print(Debug.INFO, "Introspecting "+path+" on "+source+" for dynamic proxy creation"); + try { + DBus.Introspectable intro = getRemoteObject(source, path, DBus.Introspectable.class); + String data = intro.Introspect(); + if (Debug.debug) Debug.print(Debug.VERBOSE, "Got introspection data: "+data); + String[] tags = data.split("[<>]"); + Vector<String> ifaces = new Vector<String>(); + for (String tag: tags) { + if (tag.startsWith("interface")) { + ifaces.add(tag.replaceAll("^interface *name *= *['\"]([^'\"]*)['\"].*$", "$1")); + } + } + Vector<Class<? extends Object>> ifcs = new Vector<Class<? extends Object>>(); + for(String iface: ifaces) { + if (Debug.debug) Debug.print(Debug.DEBUG, "Trying interface "+iface); + int j = 0; + while (j >= 0) { + try { + Class ifclass = Class.forName(iface); + if (!ifcs.contains(ifclass)) + ifcs.add(ifclass); + break; + } catch (Exception e) {} + j = iface.lastIndexOf("."); + char[] cs = iface.toCharArray(); + if (j >= 0) { + cs[j] = '$'; + iface = String.valueOf(cs); + } + } + } + + if (ifcs.size() == 0) throw new DBusException(_("Could not find an interface to cast to")); + + RemoteObject ro = new RemoteObject(source, path, null, false); + DBusInterface newi = (DBusInterface) + Proxy.newProxyInstance(ifcs.get(0).getClassLoader(), + ifcs.toArray(new Class[0]), + new RemoteInvocationHandler(this, ro)); + importedObjects.put(newi, ro); + return newi; + } catch (Exception e) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, e); + throw new DBusException(MessageFormat.format(_("Failed to create proxy object for {0} exported by {1}. Reason: {2}"), new Object[] { path, source, e.getMessage() })); + } + } + + DBusInterface getExportedObject(String source, String path) throws DBusException + { + ExportedObject o = null; + synchronized (exportedObjects) { + o = exportedObjects.get(path); + } + if (null != o && null == o.object.get()) { + unExportObject(path); + o = null; + } + if (null != o) return o.object.get(); + if (null == source) throw new DBusException(_("Not an object exported by this connection and no remote specified")); + return dynamicProxy(source, path); + } + + /** + * Release a bus name. + * Releases the name so that other people can use it + * @param busname The name to release. MUST be in dot-notation like "org.freedesktop.local" + * @throws DBusException If the busname is incorrectly formatted. + */ + public void releaseBusName(String busname) throws DBusException + { + if (!busname.matches(BUSNAME_REGEX)||busname.length() > MAX_NAME_LENGTH) + throw new DBusException(_("Invalid bus name")); + synchronized (this.busnames) { + UInt32 rv; + try { + rv = _dbus.ReleaseName(busname); + } catch (DBusExecutionException DBEe) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, DBEe); + throw new DBusException(DBEe.getMessage()); + } + this.busnames.remove(busname); + } + } + /** + * Request a bus name. + * Request the well known name that this should respond to on the Bus. + * @param busname The name to respond to. MUST be in dot-notation like "org.freedesktop.local" + * @throws DBusException If the register name failed, or our name already exists on the bus. + * or if busname is incorrectly formatted. + */ + public void requestBusName(String busname) throws DBusException + { + if (!busname.matches(BUSNAME_REGEX)||busname.length() > MAX_NAME_LENGTH) + throw new DBusException(_("Invalid bus name")); + synchronized (this.busnames) { + UInt32 rv; + try { + rv = _dbus.RequestName(busname, + new UInt32(DBus.DBUS_NAME_FLAG_REPLACE_EXISTING | + DBus.DBUS_NAME_FLAG_DO_NOT_QUEUE)); + } catch (DBusExecutionException DBEe) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, DBEe); + throw new DBusException(DBEe.getMessage()); + } + switch (rv.intValue()) { + case DBus.DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER: break; + case DBus.DBUS_REQUEST_NAME_REPLY_IN_QUEUE: throw new DBusException(_("Failed to register bus name")); + case DBus.DBUS_REQUEST_NAME_REPLY_EXISTS: throw new DBusException(_("Failed to register bus name")); + case DBus.DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER: break; + default: break; + } + this.busnames.add(busname); + } + } + + /** + * Returns the unique name of this connection. + */ + public String getUniqueName() + { + return busnames.get(0); + } + /** + * Returns all the names owned by this connection. + */ + public String[] getNames() + { + Set<String> names = new TreeSet<String>(); + names.addAll(busnames); + return names.toArray(new String[0]); + } + public <I extends DBusInterface> I getPeerRemoteObject(String busname, String objectpath, Class<I> type) throws DBusException + { + return getPeerRemoteObject(busname, objectpath, type, true); + } + /** + * Return a reference to a remote object. + * This method will resolve the well known name (if given) to a unique bus name when you call it. + * This means that if a well known name is released by one process and acquired by another calls to + * objects gained from this method will continue to operate on the original process. + * + * This method will use bus introspection to determine the interfaces on a remote object and so + * <b>may block</b> and <b>may fail</b>. The resulting proxy object will, however, be castable + * to any interface it implements. It will also autostart the process if applicable. Also note + * that the resulting proxy may fail to execute the correct method with overloaded methods + * and that complex types may fail in interesting ways. Basically, if something odd happens, + * try specifying the interface explicitly. + * + * @param busname The bus name to connect to. Usually a well known bus name in dot-notation (such as "org.freedesktop.local") + * or may be a DBus address such as ":1-16". + * @param objectpath The path on which the process is exporting the object.$ + * @return A reference to a remote object. + * @throws ClassCastException If type is not a sub-type of DBusInterface + * @throws DBusException If busname or objectpath are incorrectly formatted. + */ + public DBusInterface getPeerRemoteObject(String busname, String objectpath) throws DBusException + { + if (null == busname) throw new DBusException(_("Invalid bus name: null")); + + if ((!busname.matches(BUSNAME_REGEX) && !busname.matches(CONNID_REGEX)) + || busname.length() > MAX_NAME_LENGTH) + throw new DBusException(_("Invalid bus name: ")+busname); + + String unique = _dbus.GetNameOwner(busname); + + return dynamicProxy(unique, objectpath); + } + + /** + * Return a reference to a remote object. + * This method will always refer to the well known name (if given) rather than resolving it to a unique bus name. + * In particular this means that if a process providing the well known name disappears and is taken over by another process + * proxy objects gained by this method will make calls on the new proccess. + * + * This method will use bus introspection to determine the interfaces on a remote object and so + * <b>may block</b> and <b>may fail</b>. The resulting proxy object will, however, be castable + * to any interface it implements. It will also autostart the process if applicable. Also note + * that the resulting proxy may fail to execute the correct method with overloaded methods + * and that complex types may fail in interesting ways. Basically, if something odd happens, + * try specifying the interface explicitly. + * + * @param busname The bus name to connect to. Usually a well known bus name name in dot-notation (such as "org.freedesktop.local") + * or may be a DBus address such as ":1-16". + * @param objectpath The path on which the process is exporting the object. + * @return A reference to a remote object. + * @throws ClassCastException If type is not a sub-type of DBusInterface + * @throws DBusException If busname or objectpath are incorrectly formatted. + */ + public DBusInterface getRemoteObject(String busname, String objectpath) throws DBusException + { + if (null == busname) throw new DBusException(_("Invalid bus name: null")); + if (null == objectpath) throw new DBusException(_("Invalid object path: null")); + + if ((!busname.matches(BUSNAME_REGEX) && !busname.matches(CONNID_REGEX)) + || busname.length() > MAX_NAME_LENGTH) + throw new DBusException(_("Invalid bus name: ")+busname); + + if (!objectpath.matches(OBJECT_REGEX) || objectpath.length() > MAX_NAME_LENGTH) + throw new DBusException(_("Invalid object path: ")+objectpath); + + return dynamicProxy(busname, objectpath); + } + + /** + * Return a reference to a remote object. + * This method will resolve the well known name (if given) to a unique bus name when you call it. + * This means that if a well known name is released by one process and acquired by another calls to + * objects gained from this method will continue to operate on the original process. + * @param busname The bus name to connect to. Usually a well known bus name in dot-notation (such as "org.freedesktop.local") + * or may be a DBus address such as ":1-16". + * @param objectpath The path on which the process is exporting the object.$ + * @param type The interface they are exporting it on. This type must have the same full class name and exposed method signatures + * as the interface the remote object is exporting. + * @param autostart Disable/Enable auto-starting of services in response to calls on this object. + * Default is enabled; when calling a method with auto-start enabled, if the destination is a well-known name + * and is not owned the bus will attempt to start a process to take the name. When disabled an error is + * returned immediately. + * @return A reference to a remote object. + * @throws ClassCastException If type is not a sub-type of DBusInterface + * @throws DBusException If busname or objectpath are incorrectly formatted or type is not in a package. + */ + public <I extends DBusInterface> I getPeerRemoteObject(String busname, String objectpath, Class<I> type, boolean autostart) throws DBusException + { + if (null == busname) throw new DBusException(_("Invalid bus name: null")); + + if ((!busname.matches(BUSNAME_REGEX) && !busname.matches(CONNID_REGEX)) + || busname.length() > MAX_NAME_LENGTH) + throw new DBusException(_("Invalid bus name: ")+busname); + + String unique = _dbus.GetNameOwner(busname); + + return getRemoteObject(unique, objectpath, type, autostart); + } + /** + * Return a reference to a remote object. + * This method will always refer to the well known name (if given) rather than resolving it to a unique bus name. + * In particular this means that if a process providing the well known name disappears and is taken over by another process + * proxy objects gained by this method will make calls on the new proccess. + * @param busname The bus name to connect to. Usually a well known bus name name in dot-notation (such as "org.freedesktop.local") + * or may be a DBus address such as ":1-16". + * @param objectpath The path on which the process is exporting the object. + * @param type The interface they are exporting it on. This type must have the same full class name and exposed method signatures + * as the interface the remote object is exporting. + * @return A reference to a remote object. + * @throws ClassCastException If type is not a sub-type of DBusInterface + * @throws DBusException If busname or objectpath are incorrectly formatted or type is not in a package. + */ + public <I extends DBusInterface> I getRemoteObject(String busname, String objectpath, Class<I> type) throws DBusException + { + return getRemoteObject(busname, objectpath, type, true); + } + /** + * Return a reference to a remote object. + * This method will always refer to the well known name (if given) rather than resolving it to a unique bus name. + * In particular this means that if a process providing the well known name disappears and is taken over by another process + * proxy objects gained by this method will make calls on the new proccess. + * @param busname The bus name to connect to. Usually a well known bus name name in dot-notation (such as "org.freedesktop.local") + * or may be a DBus address such as ":1-16". + * @param objectpath The path on which the process is exporting the object. + * @param type The interface they are exporting it on. This type must have the same full class name and exposed method signatures + * as the interface the remote object is exporting. + * @param autostart Disable/Enable auto-starting of services in response to calls on this object. + * Default is enabled; when calling a method with auto-start enabled, if the destination is a well-known name + * and is not owned the bus will attempt to start a process to take the name. When disabled an error is + * returned immediately. + * @return A reference to a remote object. + * @throws ClassCastException If type is not a sub-type of DBusInterface + * @throws DBusException If busname or objectpath are incorrectly formatted or type is not in a package. + */ + @SuppressWarnings("unchecked") + public <I extends DBusInterface> I getRemoteObject(String busname, String objectpath, Class<I> type, boolean autostart) throws DBusException + { + if (null == busname) throw new DBusException(_("Invalid bus name: null")); + if (null == objectpath) throw new DBusException(_("Invalid object path: null")); + if (null == type) throw new ClassCastException(_("Not A DBus Interface")); + + if ((!busname.matches(BUSNAME_REGEX) && !busname.matches(CONNID_REGEX)) + || busname.length() > MAX_NAME_LENGTH) + throw new DBusException(_("Invalid bus name: ")+busname); + + if (!objectpath.matches(OBJECT_REGEX) || objectpath.length() > MAX_NAME_LENGTH) + throw new DBusException(_("Invalid object path: ")+objectpath); + + if (!DBusInterface.class.isAssignableFrom(type)) throw new ClassCastException(_("Not A DBus Interface")); + + // don't let people import things which don't have a + // valid D-Bus interface name + if (type.getName().equals(type.getSimpleName())) + throw new DBusException(_("DBusInterfaces cannot be declared outside a package")); + + RemoteObject ro = new RemoteObject(busname, objectpath, type, autostart); + I i = (I) Proxy.newProxyInstance(type.getClassLoader(), + new Class[] { type }, new RemoteInvocationHandler(this, ro)); + importedObjects.put(i, ro); + return i; + } + /** + * Remove a Signal Handler. + * Stops listening for this signal. + * @param type The signal to watch for. + * @param source The source of the signal. + * @throws DBusException If listening for the signal on the bus failed. + * @throws ClassCastException If type is not a sub-type of DBusSignal. + */ + public <T extends DBusSignal> void removeSigHandler(Class<T> type, String source, DBusSigHandler<T> handler) throws DBusException + { + if (!DBusSignal.class.isAssignableFrom(type)) throw new ClassCastException(_("Not A DBus Signal")); + if (source.matches(BUSNAME_REGEX)) throw new DBusException(_("Cannot watch for signals based on well known bus name as source, only unique names.")); + if (!source.matches(CONNID_REGEX)||source.length() > MAX_NAME_LENGTH) + throw new DBusException(_("Invalid bus name: ")+source); + removeSigHandler(new DBusMatchRule(type, source, null), handler); + } + /** + * Remove a Signal Handler. + * Stops listening for this signal. + * @param type The signal to watch for. + * @param source The source of the signal. + * @param object The object emitting the signal. + * @throws DBusException If listening for the signal on the bus failed. + * @throws ClassCastException If type is not a sub-type of DBusSignal. + */ + public <T extends DBusSignal> void removeSigHandler(Class<T> type, String source, DBusInterface object, DBusSigHandler<T> handler) throws DBusException + { + if (!DBusSignal.class.isAssignableFrom(type)) throw new ClassCastException(_("Not A DBus Signal")); + if (source.matches(BUSNAME_REGEX)) throw new DBusException(_("Cannot watch for signals based on well known bus name as source, only unique names.")); + if (!source.matches(CONNID_REGEX)||source.length() > MAX_NAME_LENGTH) + throw new DBusException(_("Invalid bus name: ")+source); + String objectpath = importedObjects.get(object).objectpath; + if (!objectpath.matches(OBJECT_REGEX)||objectpath.length() > MAX_NAME_LENGTH) + throw new DBusException(_("Invalid object path: ")+objectpath); + removeSigHandler(new DBusMatchRule(type, source, objectpath), handler); + } + protected <T extends DBusSignal> void removeSigHandler(DBusMatchRule rule, DBusSigHandler<T> handler) throws DBusException + { + + SignalTuple key = new SignalTuple(rule.getInterface(), rule.getMember(), rule.getObject(), rule.getSource()); + synchronized (handledSignals) { + Vector<DBusSigHandler<? extends DBusSignal>> v = handledSignals.get(key); + if (null != v) { + v.remove(handler); + if (0 == v.size()) { + handledSignals.remove(key); + try { + _dbus.RemoveMatch(rule.toString()); + } catch (NotConnected NC) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, NC); + } catch (DBusExecutionException DBEe) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, DBEe); + throw new DBusException(DBEe.getMessage()); + } + } + } + } + } + /** + * Add a Signal Handler. + * Adds a signal handler to call when a signal is received which matches the specified type, name and source. + * @param type The signal to watch for. + * @param source The process which will send the signal. This <b>MUST</b> be a unique bus name and not a well known name. + * @param handler The handler to call when a signal is received. + * @throws DBusException If listening for the signal on the bus failed. + * @throws ClassCastException If type is not a sub-type of DBusSignal. + */ + @SuppressWarnings("unchecked") + public <T extends DBusSignal> void addSigHandler(Class<T> type, String source, DBusSigHandler<T> handler) throws DBusException + { + if (!DBusSignal.class.isAssignableFrom(type)) throw new ClassCastException(_("Not A DBus Signal")); + if (source.matches(BUSNAME_REGEX)) throw new DBusException(_("Cannot watch for signals based on well known bus name as source, only unique names.")); + if (!source.matches(CONNID_REGEX)||source.length() > MAX_NAME_LENGTH) + throw new DBusException(_("Invalid bus name: ")+source); + addSigHandler(new DBusMatchRule(type, source, null), (DBusSigHandler<? extends DBusSignal>) handler); + } + /** + * Add a Signal Handler. + * Adds a signal handler to call when a signal is received which matches the specified type, name, source and object. + * @param type The signal to watch for. + * @param source The process which will send the signal. This <b>MUST</b> be a unique bus name and not a well known name. + * @param object The object from which the signal will be emitted + * @param handler The handler to call when a signal is received. + * @throws DBusException If listening for the signal on the bus failed. + * @throws ClassCastException If type is not a sub-type of DBusSignal. + */ + @SuppressWarnings("unchecked") + public <T extends DBusSignal> void addSigHandler(Class<T> type, String source, DBusInterface object, DBusSigHandler<T> handler) throws DBusException + { + if (!DBusSignal.class.isAssignableFrom(type)) throw new ClassCastException(_("Not A DBus Signal")); + if (source.matches(BUSNAME_REGEX)) throw new DBusException(_("Cannot watch for signals based on well known bus name as source, only unique names.")); + if (!source.matches(CONNID_REGEX)||source.length() > MAX_NAME_LENGTH) + throw new DBusException(_("Invalid bus name: ")+source); + String objectpath = importedObjects.get(object).objectpath; + if (!objectpath.matches(OBJECT_REGEX)||objectpath.length() > MAX_NAME_LENGTH) + throw new DBusException(_("Invalid object path: ")+objectpath); + addSigHandler(new DBusMatchRule(type, source, objectpath), (DBusSigHandler<? extends DBusSignal>) handler); + } + protected <T extends DBusSignal> void addSigHandler(DBusMatchRule rule, DBusSigHandler<T> handler) throws DBusException + { + try { + _dbus.AddMatch(rule.toString()); + } catch (DBusExecutionException DBEe) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, DBEe); + throw new DBusException(DBEe.getMessage()); + } + SignalTuple key = new SignalTuple(rule.getInterface(), rule.getMember(), rule.getObject(), rule.getSource()); + synchronized (handledSignals) { + Vector<DBusSigHandler<? extends DBusSignal>> v = handledSignals.get(key); + if (null == v) { + v = new Vector<DBusSigHandler<? extends DBusSignal>>(); + v.add(handler); + handledSignals.put(key, v); + } else + v.add(handler); + } + } + /** + * Disconnect from the Bus. + * This only disconnects when the last reference to the bus has disconnect called on it + * or has been destroyed. + */ + public void disconnect() + { + synchronized (conn) { + synchronized (_reflock) { + if (0 == --_refcount) { + if (Debug.debug) Debug.print(Debug.INFO, "Disconnecting DBusConnection"); + // Set all pending messages to have an error. + try { + Error err = new Error( + "org.freedesktop.DBus.Local" , "org.freedesktop.DBus.Local.Disconnected", 0, "s", new Object[] { _("Disconnected") }); + synchronized (pendingCalls) { + long[] set = pendingCalls.getKeys(); + for (long l: set) if (-1 != l) { + MethodCall m = pendingCalls.remove(l); + if (null != m) + m.setReply(err); + } + pendingCalls = null; + } + synchronized (pendingErrors) { + pendingErrors.add(err); + } + } catch (DBusException DBe) {} + + conn.remove(addr); + super.disconnect(); + } + } + } + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusInterface.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusInterface.java new file mode 100755 index 0000000..7b0d30a --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusInterface.java @@ -0,0 +1,31 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; +/** + * Denotes a class as exportable or a remote interface which can be called. + * <p> + * Any interface which should be exported or imported should extend this + * interface. All public methods from that interface are exported/imported + * with the given method signatures. + * </p> + * <p> + * All method calls on exported objects are run in their own threads. + * Application writers are responsible for any concurrency issues. + * </p> + */ +public interface DBusInterface +{ + /** + * Returns true on remote objects. + * Local objects implementing this interface MUST return false. + */ + public boolean isRemote(); +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusInterfaceName.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusInterfaceName.java new file mode 100755 index 0000000..5400a92 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusInterfaceName.java @@ -0,0 +1,27 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Force the interface name to be different to the Java class name. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface DBusInterfaceName +{ + /** The replacement interface name. */ + String value(); +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusMap.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusMap.java new file mode 100755 index 0000000..b9d06d7 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusMap.java @@ -0,0 +1,152 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import java.util.Vector; + +class DBusMap<K, V> implements Map<K, V> +{ + Object[][] entries; + public DBusMap(Object[][] entries) + { + this.entries=entries; + } + class Entry implements Map.Entry<K,V>, Comparable<Entry> + { + private int entry; + public Entry(int i) + { + this.entry = i; + } + public boolean equals(Object o) + { + if (null == o) return false; + if (!(o instanceof DBusMap.Entry)) return false; + return this.entry == ((Entry) o).entry; + } + @SuppressWarnings("unchecked") + public K getKey() + { + return (K) entries[entry][0]; + } + @SuppressWarnings("unchecked") + public V getValue() + { + return (V) entries[entry][1]; + } + public int hashCode() + { + return entries[entry][0].hashCode(); + } + public V setValue(V value) + { + throw new UnsupportedOperationException(); + } + public int compareTo(Entry e) + { + return entry - e.entry; + } + } + + public void clear() + { + throw new UnsupportedOperationException(); + } + public boolean containsKey(Object key) + { + for (int i = 0; i < entries.length; i++) + if (key == entries[i][0] || (key != null && key.equals(entries[i][0]))) + return true; + return false; + } + public boolean containsValue(Object value) + { + for (int i = 0; i < entries.length; i++) + if (value == entries[i][1] || (value != null && value.equals(entries[i][1]))) + return true; + return false; + } + public Set<Map.Entry<K,V>> entrySet() + { + Set<Map.Entry<K,V>> s = new TreeSet<Map.Entry<K,V>>(); + for (int i = 0; i < entries.length; i++) + s.add(new Entry(i)); + return s; + } + @SuppressWarnings("unchecked") + public V get(Object key) + { + for (int i = 0; i < entries.length; i++) + if (key == entries[i][0] || (key != null && key.equals(entries[i][0]))) + return (V) entries[i][1]; + return null; + } + public boolean isEmpty() + { + return entries.length == 0; + } + @SuppressWarnings("unchecked") + public Set<K> keySet() + { + Set<K> s = new TreeSet<K>(); + for (Object[] entry: entries) + s.add((K) entry[0]); + return s; + } + public V put(K key, V value) + { + throw new UnsupportedOperationException(); + } + public void putAll(Map<? extends K,? extends V> t) + { + throw new UnsupportedOperationException(); + } + public V remove(Object key) + { + throw new UnsupportedOperationException(); + } + public int size() + { + return entries.length; + } + @SuppressWarnings("unchecked") + public Collection<V> values() + { + List<V> l = new Vector<V>(); + for (Object[] entry: entries) + l.add((V) entry[1]); + return l; + } + public int hashCode() + { + return Arrays.deepHashCode(entries); + } + @SuppressWarnings("unchecked") + public boolean equals(Object o) + { + if (null == o) return false; + if (!(o instanceof Map)) return false; + return ((Map<K,V>) o).entrySet().equals(entrySet()); + } + public String toString() + { + String s = "{ "; + for (int i = 0; i < entries.length; i++) + s += entries[i][0] + " => " + entries[i][1] + ","; + return s.replaceAll(".$", " }"); + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusMatchRule.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusMatchRule.java new file mode 100755 index 0000000..fa1e0ca --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusMatchRule.java @@ -0,0 +1,143 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import static org.freedesktop.dbus.Gettext._; + +import org.freedesktop.dbus.exceptions.DBusException; +import org.freedesktop.dbus.exceptions.DBusExecutionException; + +import java.util.HashMap; + +public class DBusMatchRule +{ + /* signal, error, method_call, method_reply */ + private String type; + private String iface; + private String member; + private String object; + private String source; + private static HashMap<String, Class<? extends DBusSignal>> signalTypeMap = + new HashMap<String, Class<? extends DBusSignal>>(); + static Class<? extends DBusSignal> getCachedSignalType(String type) + { + return signalTypeMap.get(type); + } + public DBusMatchRule(String type, String iface, String member) + { + this.type = type; + this.iface = iface; + this.member = member; + } + public DBusMatchRule(DBusExecutionException e) throws DBusException + { + this(e.getClass()); + member = null; + type = "error"; + } + public DBusMatchRule(Message m) + { + iface = m.getInterface(); + member = m.getName(); + if (m instanceof DBusSignal) + type = "signal"; + else if (m instanceof Error) { + type = "error"; + member = null; + } + else if (m instanceof MethodCall) + type = "method_call"; + else if (m instanceof MethodReturn) + type = "method_reply"; + } + public DBusMatchRule(Class<? extends DBusInterface> c, String method) throws DBusException + { + this(c); + member = method; + type = "method_call"; + } + public DBusMatchRule(Class<? extends Object> c, String source, String object) throws DBusException + { + this(c); + this.source = source; + this.object = object; + } + @SuppressWarnings("unchecked") + public DBusMatchRule(Class<? extends Object> c) throws DBusException + { + if (DBusInterface.class.isAssignableFrom(c)) { + if (null != c.getAnnotation(DBusInterfaceName.class)) + iface = c.getAnnotation(DBusInterfaceName.class).value(); + else + iface = AbstractConnection.dollar_pattern.matcher(c.getName()).replaceAll("."); + if (!iface.matches(".*\\..*")) + throw new DBusException(_("DBusInterfaces must be defined in a package.")); + member = null; + type = null; + } + else if (DBusSignal.class.isAssignableFrom(c)) { + if (null == c.getEnclosingClass()) + throw new DBusException(_("Signals must be declared as a member of a class implementing DBusInterface which is the member of a package.")); + else + if (null != c.getEnclosingClass().getAnnotation(DBusInterfaceName.class)) + iface = c.getEnclosingClass().getAnnotation(DBusInterfaceName.class).value(); + else + iface = AbstractConnection.dollar_pattern.matcher(c.getEnclosingClass().getName()).replaceAll("."); + // Don't export things which are invalid D-Bus interfaces + if (!iface.matches(".*\\..*")) + throw new DBusException(_("DBusInterfaces must be defined in a package.")); + if (c.isAnnotationPresent(DBusMemberName.class)) + member = c.getAnnotation(DBusMemberName.class).value(); + else + member = c.getSimpleName(); + signalTypeMap.put(iface+'$'+member, (Class<? extends DBusSignal>) c); + type = "signal"; + } + else if (Error.class.isAssignableFrom(c)) { + if (null != c.getAnnotation(DBusInterfaceName.class)) + iface = c.getAnnotation(DBusInterfaceName.class).value(); + else + iface = AbstractConnection.dollar_pattern.matcher(c.getName()).replaceAll("."); + if (!iface.matches(".*\\..*")) + throw new DBusException(_("DBusInterfaces must be defined in a package.")); + member = null; + type = "error"; + } + else if (DBusExecutionException.class.isAssignableFrom(c)) { + if (null != c.getClass().getAnnotation(DBusInterfaceName.class)) + iface = c.getClass().getAnnotation(DBusInterfaceName.class).value(); + else + iface = AbstractConnection.dollar_pattern.matcher(c.getClass().getName()).replaceAll("."); + if (!iface.matches(".*\\..*")) + throw new DBusException(_("DBusInterfaces must be defined in a package.")); + member = null; + type = "error"; + } + else + throw new DBusException(_("Invalid type for match rule: ")+c); + } + public String toString() + { + String s = null; + if (null != type) s = null == s ? "type='"+type+"'" : s + ",type='"+type+"'"; + if (null != member) s = null == s ? "member='"+member+"'" : s + ",member='"+member+"'"; + if (null != iface) s = null == s ? "interface='"+iface+"'" : s + ",interface='"+iface+"'"; + if (null != source) s = null == s ? "sender='"+source+"'" : s + ",sender='"+source+"'"; + if (null != object) s = null == s ? "path='"+object+"'" : s + ",path='"+object+"'"; + return s; + } + public String getType() { return type; } + public String getInterface() { return iface; } + public String getMember() { return member; } + public String getSource() { return source; } + public String getObject() { return object; } + +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusMemberName.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusMemberName.java new file mode 100755 index 0000000..da7f8fd --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusMemberName.java @@ -0,0 +1,27 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Force the member (method/signal) name on the bus to be different to the Java name. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE,ElementType.METHOD}) +public @interface DBusMemberName +{ + /** The replacement member name. */ + String value(); +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusSerializable.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusSerializable.java new file mode 100755 index 0000000..8e31137 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusSerializable.java @@ -0,0 +1,38 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; +import org.freedesktop.dbus.exceptions.DBusException; +/** + * Custom classes may be sent over DBus if they implement this interface. + * <p> + * In addition to the serialize method, classes <b>MUST</b> implement + * a deserialize method which returns null and takes as it's arguments + * all the DBus types the class will be serialied to <i>in order</i> and + * <i>with type parameterisation</i>. They <b>MUST</b> also provide a + * zero-argument constructor. + * </p> + * <p> + * The serialize method should return the class properties you wish to + * serialize, correctly formatted for the wire + * (DBusConnection.convertParameters() can help with this), in order in an + * Object array. + * </p> + * <p> + * The deserialize method will be called once after the zero-argument + * constructor. This should contain all the code to initialise the object + * from the types. + * </p> + */ +public interface DBusSerializable +{ + public Object[] serialize() throws DBusException; +} + diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusSigHandler.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusSigHandler.java new file mode 100755 index 0000000..a56d845 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusSigHandler.java @@ -0,0 +1,25 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; +/** Handle a signal on DBus. + * All Signal handlers are run in their own Thread. + * Application writers are responsible for managing any concurrency issues. + */ +public interface DBusSigHandler<T extends DBusSignal> +{ + /** + * Handle a signal. + * @param s The signal to handle. If such a class exists, the + * signal will be an instance of the class with the correct type signature. + * Otherwise it will be an instance of DBusSignal + */ + public void handle(T s); +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusSignal.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusSignal.java new file mode 100755 index 0000000..a776027 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DBusSignal.java @@ -0,0 +1,276 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import static org.freedesktop.dbus.Gettext._; + +import java.lang.reflect.Constructor; +import java.lang.reflect.GenericDeclaration; +import java.lang.reflect.Type; +import java.lang.reflect.TypeVariable; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.StringTokenizer; +import java.util.Vector; + +import org.freedesktop.dbus.exceptions.DBusException; +import org.freedesktop.dbus.exceptions.MessageFormatException; + +import cx.ath.matthew.debug.Debug; + +public class DBusSignal extends Message +{ + DBusSignal() { } + public DBusSignal(String source, String path, String iface, String member, String sig, Object... args) throws DBusException + { + super(Message.Endian.BIG, Message.MessageType.SIGNAL, (byte) 0); + + if (null == path || null == member || null == iface) + throw new MessageFormatException(_("Must specify object path, interface and signal name to Signals.")); + headers.put(Message.HeaderField.PATH,path); + headers.put(Message.HeaderField.MEMBER,member); + headers.put(Message.HeaderField.INTERFACE,iface); + + Vector<Object> hargs = new Vector<Object>(); + hargs.add(new Object[] { Message.HeaderField.PATH, new Object[] { ArgumentType.OBJECT_PATH_STRING, path } }); + hargs.add(new Object[] { Message.HeaderField.INTERFACE, new Object[] { ArgumentType.STRING_STRING, iface } }); + hargs.add(new Object[] { Message.HeaderField.MEMBER, new Object[] { ArgumentType.STRING_STRING, member } }); + + if (null != source) { + headers.put(Message.HeaderField.SENDER,source); + hargs.add(new Object[] { Message.HeaderField.SENDER, new Object[] { ArgumentType.STRING_STRING, source } }); + } + + if (null != sig) { + hargs.add(new Object[] { Message.HeaderField.SIGNATURE, new Object[] { ArgumentType.SIGNATURE_STRING, sig } }); + headers.put(Message.HeaderField.SIGNATURE,sig); + setArgs(args); + } + + blen = new byte[4]; + appendBytes(blen); + append("ua(yv)", ++serial, hargs.toArray()); + pad((byte)8); + + long c = bytecounter; + if (null != sig) append(sig, args); + marshallint(bytecounter-c, blen, 0, 4); + bodydone = true; + } + static class internalsig extends DBusSignal + { + public internalsig(String source, String objectpath, String type, String name, String sig, Object[] parameters, long serial) throws DBusException + { + super(source, objectpath, type, name, sig, parameters, serial); + } + } + private static Map<Class<? extends DBusSignal>, Type[]> typeCache = new HashMap<Class<? extends DBusSignal>, Type[]>(); + private static Map<String, Class<? extends DBusSignal>> classCache = new HashMap<String, Class<? extends DBusSignal>>(); + private static Map<Class<? extends DBusSignal>, Constructor<? extends DBusSignal>> conCache = new HashMap<Class<? extends DBusSignal>, Constructor<? extends DBusSignal>>(); + private static Map<String, String> signames = new HashMap<String, String>(); + private static Map<String, String> intnames = new HashMap<String, String>(); + private Class<? extends DBusSignal> c; + private boolean bodydone = false; + private byte[] blen; + + static void addInterfaceMap(String java, String dbus) + { + intnames.put(dbus, java); + } + static void addSignalMap(String java, String dbus) + { + signames.put(dbus, java); + } + + static DBusSignal createSignal(Class<? extends DBusSignal> c, String source, String objectpath, String sig, long serial, Object... parameters) throws DBusException + { + String type = ""; + if (null != c.getEnclosingClass()) { + if (null != c.getEnclosingClass().getAnnotation(DBusInterfaceName.class)) + type = c.getEnclosingClass().getAnnotation(DBusInterfaceName.class).value(); + else + type = AbstractConnection.dollar_pattern.matcher(c.getEnclosingClass().getName()).replaceAll("."); + + } else + throw new DBusException(_("Signals must be declared as a member of a class implementing DBusInterface which is the member of a package.")); + DBusSignal s = new internalsig(source, objectpath, type, c.getSimpleName(), sig, parameters, serial); + s.c = c; + return s; + } + @SuppressWarnings("unchecked") + private static Class<? extends DBusSignal> createSignalClass(String intname, String signame) throws DBusException + { + String name = intname+'$'+signame; + Class<? extends DBusSignal> c = classCache.get(name); + if (null == c) c = DBusMatchRule.getCachedSignalType(name); + if (null != c) return c; + do { + try { + c = (Class<? extends DBusSignal>) Class.forName(name); + } catch (ClassNotFoundException CNFe) {} + name = name.replaceAll("\\.([^\\.]*)$", "\\$$1"); + } while (null == c && name.matches(".*\\..*")); + if (null == c) + throw new DBusException(_("Could not create class from signal ")+intname+'.'+signame); + classCache.put(name, c); + return c; + } + @SuppressWarnings("unchecked") + DBusSignal createReal(AbstractConnection conn) throws DBusException + { + String intname = intnames.get(getInterface()); + String signame = signames.get(getName()); + if (null == intname) intname = getInterface(); + if (null == signame) signame = getName(); + if (null == c) + c = createSignalClass(intname,signame); + if (Debug.debug) Debug.print(Debug.DEBUG, "Converting signal to type: "+c); + Type[] types = typeCache.get(c); + Constructor<? extends DBusSignal> con = conCache.get(c); + if (null == types) { + con = (Constructor<? extends DBusSignal>) c.getDeclaredConstructors()[0]; + conCache.put(c, con); + Type[] ts = con.getGenericParameterTypes(); + types = new Type[ts.length-1]; + for (int i = 1; i < ts.length; i++) + if (ts[i] instanceof TypeVariable) + for (Type b: ((TypeVariable<GenericDeclaration>) ts[i]).getBounds()) + types[i-1] = b; + else + types[i-1] = ts[i]; + typeCache.put(c, types); + } + + try { + DBusSignal s; + Object[] args = Marshalling.deSerializeParameters(getParameters(), types, conn); + if (null == args) s = (DBusSignal) con.newInstance(getPath()); + else { + Object[] params = new Object[args.length + 1]; + params[0] = getPath(); + System.arraycopy(args, 0, params, 1, args.length); + + if (Debug.debug) Debug.print(Debug.DEBUG, "Creating signal of type "+c+" with parameters "+Arrays.deepToString(params)); + s = (DBusSignal) con.newInstance(params); + } + s.headers = headers; + s.wiredata = wiredata; + s.bytecounter = wiredata.length; + return s; + } catch (Exception e) { + if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, e); + throw new DBusException(e.getMessage()); + } + } + /** + * Create a new signal. + * This contructor MUST be called by all sub classes. + * @param objectpath The path to the object this is emitted from. + * @param args The parameters of the signal. + * @throws DBusException This is thrown if the subclass is incorrectly defined. + */ + @SuppressWarnings("unchecked") + protected DBusSignal(String objectpath, Object... args) throws DBusException + { + super(Message.Endian.BIG, Message.MessageType.SIGNAL, (byte) 0); + + String destination = null; // pego + StringTokenizer tokens = new StringTokenizer(objectpath, "&"); // pego + if (tokens.countTokens() > 1) { // pego + objectpath = tokens.nextToken(); // pego + destination = tokens.nextToken(); // pego +// System.out.println("DBusSignal: destination specified: objectpath = " + objectpath + ", destination = " + destination); + } else { // pego +// System.out.println("DBusSignal: NO destination specified: objectpath = " + objectpath); // pego + } // pego + + if (!objectpath.matches(AbstractConnection.OBJECT_REGEX)) throw new DBusException(_("Invalid object path: ")+objectpath); + + Class<? extends DBusSignal> tc = getClass(); + String member; + if (tc.isAnnotationPresent(DBusMemberName.class)) + member = tc.getAnnotation(DBusMemberName.class).value(); + else + member = tc.getSimpleName(); + String iface = null; + Class<? extends Object> enc = tc.getEnclosingClass(); + if (null == enc || + !DBusInterface.class.isAssignableFrom(enc) || + enc.getName().equals(enc.getSimpleName())) + throw new DBusException(_("Signals must be declared as a member of a class implementing DBusInterface which is the member of a package.")); + else + if (null != enc.getAnnotation(DBusInterfaceName.class)) + iface = enc.getAnnotation(DBusInterfaceName.class).value(); + else + iface = AbstractConnection.dollar_pattern.matcher(enc.getName()).replaceAll("."); + + if (destination != null) { // pego + headers.put(Message.HeaderField.DESTINATION, destination); // pego + } // pego + headers.put(Message.HeaderField.PATH,objectpath); + headers.put(Message.HeaderField.MEMBER,member); + headers.put(Message.HeaderField.INTERFACE,iface); + + Vector<Object> hargs = new Vector<Object>(); + if (destination != null) { // pego + hargs.add(new Object[] { Message.HeaderField.DESTINATION, new Object[] { ArgumentType.STRING_STRING, destination } }); + } // pego + hargs.add(new Object[] { Message.HeaderField.PATH, new Object[] { ArgumentType.OBJECT_PATH_STRING, objectpath } }); + hargs.add(new Object[] { Message.HeaderField.INTERFACE, new Object[] { ArgumentType.STRING_STRING, iface } }); + hargs.add(new Object[] { Message.HeaderField.MEMBER, new Object[] { ArgumentType.STRING_STRING, member } }); + + String sig = null; + if (0 < args.length) { + try { + Type[] types = typeCache.get(tc); + if (null == types) { + Constructor<? extends DBusSignal> con = (Constructor<? extends DBusSignal>) tc.getDeclaredConstructors()[0]; + conCache.put(tc, con); + Type[] ts = con.getGenericParameterTypes(); + types = new Type[ts.length-1]; + for (int i = 1; i <= types.length; i++) + if (ts[i] instanceof TypeVariable) + types[i-1] = ((TypeVariable<GenericDeclaration>) ts[i]).getBounds()[0]; + else + types[i-1] = ts[i]; + typeCache.put(tc, types); + } + sig = Marshalling.getDBusType(types); + hargs.add(new Object[] { Message.HeaderField.SIGNATURE, new Object[] { ArgumentType.SIGNATURE_STRING, sig } }); + headers.put(Message.HeaderField.SIGNATURE,sig); + setArgs(args); + } catch (Exception e) { + if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, e); + throw new DBusException(_("Failed to add signal parameters: ")+e.getMessage()); + } + } + + blen = new byte[4]; + appendBytes(blen); + append("ua(yv)", ++serial, hargs.toArray()); + pad((byte)8); + } + void appendbody(AbstractConnection conn) throws DBusException + { + if (bodydone) return; + + Type[] types = typeCache.get(getClass()); + Object[] args = Marshalling.convertParameters(getParameters(), types, conn); + setArgs(args); + String sig = getSig(); + + long c = bytecounter; + if (null != args && 0 < args.length) append(sig, args); + marshallint(bytecounter-c, blen, 0, 4); + bodydone = true; + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DirectConnection.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DirectConnection.java new file mode 100755 index 0000000..93ec03f --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/DirectConnection.java @@ -0,0 +1,251 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import static org.freedesktop.dbus.Gettext._; + +import java.lang.reflect.Proxy; +import java.io.File; +import java.io.IOException; +import java.net.ServerSocket; +import java.text.MessageFormat; +import java.text.ParseException; +import java.util.Random; +import java.util.Vector; + +import org.freedesktop.DBus; +import org.freedesktop.dbus.exceptions.DBusException; + +import cx.ath.matthew.debug.Debug; + +/** Handles a peer to peer connection between two applications withou a bus daemon. + * <p> + * Signal Handlers and method calls from remote objects are run in their own threads, you MUST handle the concurrency issues. + * </p> + */ +public class DirectConnection extends AbstractConnection +{ + /** + * Create a direct connection to another application. + * @param address The address to connect to. This is a standard D-Bus address, except that the additional parameter 'listen=true' should be added in the application which is creating the socket. + */ + public DirectConnection(String address) throws DBusException + { + super(address); + + try { + transport = new Transport(addr, AbstractConnection.TIMEOUT); + connected = true; + } catch (IOException IOe) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, IOe); + throw new DBusException(_("Failed to connect to bus ")+IOe.getMessage()); + } catch (ParseException Pe) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, Pe); + throw new DBusException(_("Failed to connect to bus ")+Pe.getMessage()); + } + + listen(); + } + + /** + * Creates a bus address for a randomly generated tcp port. + * @return a random bus address. + */ + public static String createDynamicTCPSession() + { + String address = "tcp:host=localhost"; + int port; + try { + ServerSocket s = new ServerSocket(); + s.bind(null); + port = s.getLocalPort(); + s.close(); + } catch (Exception e) { + Random r = new Random(); + port = 32768 + (Math.abs(r.nextInt()) % 28232); + } + address += ",port="+port; + address += ",guid="+Transport.genGUID(); + if (Debug.debug) Debug.print("Created Session address: "+address); + return address; + } + + /** + * Creates a bus address for a randomly generated abstract unix socket. + * @return a random bus address. + */ + public static String createDynamicSession() + { + String address = "unix:"; + String path = "/tmp/dbus-XXXXXXXXXX"; + Random r = new Random(); + do { + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < 10; i++) + sb.append((char) ((Math.abs(r.nextInt()) % 26) + 65)); + path = path.replaceAll("..........$", sb.toString()); + if (Debug.debug) Debug.print(Debug.VERBOSE, "Trying path "+path); + } while ((new File(path)).exists()); + address += "abstract="+path; + address += ",guid="+Transport.genGUID(); + if (Debug.debug) Debug.print("Created Session address: "+address); + return address; + } + DBusInterface dynamicProxy(String path) throws DBusException + { + try { + DBus.Introspectable intro = (DBus.Introspectable) getRemoteObject(path, DBus.Introspectable.class); + String data = intro.Introspect(); + String[] tags = data.split("[<>]"); + Vector<String> ifaces = new Vector<String>(); + for (String tag: tags) { + if (tag.startsWith("interface")) { + ifaces.add(tag.replaceAll("^interface *name *= *['\"]([^'\"]*)['\"].*$", "$1")); + } + } + Vector<Class<? extends Object>> ifcs = new Vector<Class<? extends Object>>(); + for(String iface: ifaces) { + int j = 0; + while (j >= 0) { + try { + ifcs.add(Class.forName(iface)); + break; + } catch (Exception e) {} + j = iface.lastIndexOf("."); + char[] cs = iface.toCharArray(); + if (j >= 0) { + cs[j] = '$'; + iface = String.valueOf(cs); + } + } + } + + if (ifcs.size() == 0) throw new DBusException(_("Could not find an interface to cast to")); + + RemoteObject ro = new RemoteObject(null, path, null, false); + DBusInterface newi = (DBusInterface) + Proxy.newProxyInstance(ifcs.get(0).getClassLoader(), + ifcs.toArray(new Class[0]), + new RemoteInvocationHandler(this, ro)); + importedObjects.put(newi, ro); + return newi; + } catch (Exception e) { + if (EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, e); + throw new DBusException(MessageFormat.format(_("Failed to create proxy object for {0}; reason: {1}."), new Object[] { path, e.getMessage()})); + } + } + + DBusInterface getExportedObject(String path) throws DBusException + { + ExportedObject o = null; + synchronized (exportedObjects) { + o = exportedObjects.get(path); + } + if (null != o && null == o.object.get()) { + unExportObject(path); + o = null; + } + if (null != o) return o.object.get(); + return dynamicProxy(path); + } + + /** + * Return a reference to a remote object. + * This method will always refer to the well known name (if given) rather than resolving it to a unique bus name. + * In particular this means that if a process providing the well known name disappears and is taken over by another process + * proxy objects gained by this method will make calls on the new proccess. + * + * This method will use bus introspection to determine the interfaces on a remote object and so + * <b>may block</b> and <b>may fail</b>. The resulting proxy object will, however, be castable + * to any interface it implements. It will also autostart the process if applicable. Also note + * that the resulting proxy may fail to execute the correct method with overloaded methods + * and that complex types may fail in interesting ways. Basically, if something odd happens, + * try specifying the interface explicitly. + * + * @param objectpath The path on which the process is exporting the object. + * @return A reference to a remote object. + * @throws ClassCastException If type is not a sub-type of DBusInterface + * @throws DBusException If busname or objectpath are incorrectly formatted. + */ + public DBusInterface getRemoteObject(String objectpath) throws DBusException + { + if (null == objectpath) throw new DBusException(_("Invalid object path: null")); + + if (!objectpath.matches(OBJECT_REGEX) || objectpath.length() > MAX_NAME_LENGTH) + throw new DBusException(_("Invalid object path: ")+objectpath); + + return dynamicProxy(objectpath); + } + + /** + * Return a reference to a remote object. + * This method will always refer to the well known name (if given) rather than resolving it to a unique bus name. + * In particular this means that if a process providing the well known name disappears and is taken over by another process + * proxy objects gained by this method will make calls on the new proccess. + * @param objectpath The path on which the process is exporting the object. + * @param type The interface they are exporting it on. This type must have the same full class name and exposed method signatures + * as the interface the remote object is exporting. + * @return A reference to a remote object. + * @throws ClassCastException If type is not a sub-type of DBusInterface + * @throws DBusException If busname or objectpath are incorrectly formatted or type is not in a package. + */ + public DBusInterface getRemoteObject(String objectpath, Class<? extends DBusInterface> type) throws DBusException + { + if (null == objectpath) throw new DBusException(_("Invalid object path: null")); + if (null == type) throw new ClassCastException(_("Not A DBus Interface")); + + if (!objectpath.matches(OBJECT_REGEX) || objectpath.length() > MAX_NAME_LENGTH) + throw new DBusException(_("Invalid object path: ")+objectpath); + + if (!DBusInterface.class.isAssignableFrom(type)) throw new ClassCastException(_("Not A DBus Interface")); + + // don't let people import things which don't have a + // valid D-Bus interface name + if (type.getName().equals(type.getSimpleName())) + throw new DBusException(_("DBusInterfaces cannot be declared outside a package")); + + RemoteObject ro = new RemoteObject(null, objectpath, type, false); + DBusInterface i = (DBusInterface) Proxy.newProxyInstance(type.getClassLoader(), + new Class[] { type }, new RemoteInvocationHandler(this, ro)); + importedObjects.put(i, ro); + return i; + } + protected <T extends DBusSignal> void removeSigHandler(DBusMatchRule rule, DBusSigHandler<T> handler) throws DBusException + { + SignalTuple key = new SignalTuple(rule.getInterface(), rule.getMember(), rule.getObject(), rule.getSource()); + synchronized (handledSignals) { + Vector<DBusSigHandler<? extends DBusSignal>> v = handledSignals.get(key); + if (null != v) { + v.remove(handler); + if (0 == v.size()) { + handledSignals.remove(key); + } + } + } + } + protected <T extends DBusSignal> void addSigHandler(DBusMatchRule rule, DBusSigHandler<T> handler) throws DBusException + { + SignalTuple key = new SignalTuple(rule.getInterface(), rule.getMember(), rule.getObject(), rule.getSource()); + synchronized (handledSignals) { + Vector<DBusSigHandler<? extends DBusSignal>> v = handledSignals.get(key); + if (null == v) { + v = new Vector<DBusSigHandler<? extends DBusSignal>>(); + v.add(handler); + handledSignals.put(key, v); + } else + v.add(handler); + } + } + DBusInterface getExportedObject(String source, String path) throws DBusException + { + return getExportedObject(path); + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/EfficientMap.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/EfficientMap.java new file mode 100755 index 0000000..67a2484 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/EfficientMap.java @@ -0,0 +1,116 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +/** + * Provides a long => MethodCall map which doesn't allocate objects + * on insertion/removal. Keys must be inserted in ascending order. */ +class EfficientMap +{ + private long[] kv; + private MethodCall[] vv; + private int start; + private int end; + private int init_size; + public EfficientMap(int initial_size) + { + init_size = initial_size; + shrink(); + } + private void grow() + { + // create new vectors twice as long + long[] oldkv = kv; + kv = new long[oldkv.length*2]; + MethodCall[] oldvv = vv; + vv = new MethodCall[oldvv.length*2]; + + // copy start->length to the start of the new vector + System.arraycopy(oldkv,start,kv,0,oldkv.length-start); + System.arraycopy(oldvv,start,vv,0,oldvv.length-start); + // copy 0->end to the next part of the new vector + if (end != (oldkv.length-1)) { + System.arraycopy(oldkv,0,kv,oldkv.length-start,end+1); + System.arraycopy(oldvv,0,vv,oldvv.length-start,end+1); + } + // reposition pointers + start = 0; + end = oldkv.length; + } + // create a new vector with just the valid keys in and return it + public long[] getKeys() + { + int size; + if (start < end) size = end-start; + else size = kv.length-(start-end); + long[] lv = new long[size]; + int copya; + if (size > kv.length-start) copya = kv.length-start; + else copya = size; + System.arraycopy(kv,start,lv,0,copya); + if (copya < size) { + System.arraycopy(kv,0,lv,copya,size-copya); + } + return lv; + } + private void shrink() + { + if (null != kv && kv.length == init_size) return; + // reset to original size + kv = new long[init_size]; + vv = new MethodCall[init_size]; + start = 0; + end = 0; + } + public void put(long l, MethodCall m) + { + // put this at the end + kv[end] = l; + vv[end] = m; + // move the end + if (end == (kv.length-1)) end = 0; else end++; + // if we are out of space, grow. + if (end == start) grow(); + } + public MethodCall remove(long l) + { + // find the item + int pos = find(l); + // if we don't have it return null + if (-1 == pos) return null; + // get the value + MethodCall m = vv[pos]; + // set it as unused + vv[pos] = null; + kv[pos] = -1; + // move the pointer to the first full element + while (-1 == kv[start]) { + if (start == (kv.length-1)) start = 0; else start++; + // if we have emptied the list, shrink it + if (start == end) { shrink(); break; } + } + return m; + } + public boolean contains(long l) + { + // check if find succeeds + return -1 != find(l); + } + /* could binary search, but it's probably the first one */ + private int find(long l) + { + int i = start; + while (i != end && kv[i] != l) + if (i == (kv.length-1)) i = 0; else i++; + if (i == end) return -1; + return i; + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/EfficientQueue.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/EfficientQueue.java new file mode 100755 index 0000000..5724730 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/EfficientQueue.java @@ -0,0 +1,107 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import cx.ath.matthew.debug.Debug; + +/** + * Provides a Message queue which doesn't allocate objects + * on insertion/removal. */ +class EfficientQueue +{ + private Message[] mv; + private int start; + private int end; + private int init_size; + public EfficientQueue(int initial_size) + { + init_size = initial_size; + shrink(); + } + private void grow() + { + if (Debug.debug) Debug.print(Debug.DEBUG, "Growing"); + // create new vectors twice as long + Message[] oldmv = mv; + mv = new Message[oldmv.length*2]; + + // copy start->length to the start of the new vector + System.arraycopy(oldmv,start,mv,0,oldmv.length-start); + // copy 0->end to the next part of the new vector + if (end != (oldmv.length-1)) { + System.arraycopy(oldmv,0,mv,oldmv.length-start,end+1); + } + // reposition pointers + start = 0; + end = oldmv.length; + } + // create a new vector with just the valid keys in and return it + public Message[] getKeys() + { + if (start == end) return new Message[0]; + Message[] lv; + if (start < end) { + int size = end-start; + lv = new Message[size]; + System.arraycopy(mv, start, lv, 0, size); + } else { + int size = mv.length-start+end; + lv = new Message[size]; + System.arraycopy(mv, start, lv, 0, mv.length-start); + System.arraycopy(mv, 0, lv, mv.length-start, end); + } + return lv; + } + private void shrink() + { + if (Debug.debug) Debug.print(Debug.DEBUG, "Shrinking"); + if (null != mv && mv.length == init_size) return; + // reset to original size + mv = new Message[init_size]; + start = 0; + end = 0; + } + public void add(Message m) + { + if (Debug.debug) Debug.print(Debug.DEBUG, "Enqueueing Message "+m); + // put this at the end + mv[end] = m; + // move the end + if (end == (mv.length-1)) end = 0; else end++; + // if we are out of space, grow. + if (end == start) grow(); + } + public Message remove() + { + if (start == end) return null; + // find the item + int pos = start; + // get the value + Message m = mv[pos]; + // set it as unused + mv[pos] = null; + if (start == (mv.length-1)) start = 0; else start++; + if (Debug.debug) Debug.print(Debug.DEBUG, "Dequeueing "+m); + return m; + } + public boolean isEmpty() + { + // check if find succeeds + return start == end; + } + public int size() + { + if (end >= start) + return end-start; + else + return mv.length-start+end; + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Error.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Error.java new file mode 100755 index 0000000..9db1e07 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Error.java @@ -0,0 +1,142 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import static org.freedesktop.dbus.Gettext._; + +import java.lang.reflect.Constructor; +import java.util.Vector; +import org.freedesktop.dbus.exceptions.DBusException; +import org.freedesktop.dbus.exceptions.DBusExecutionException; +import org.freedesktop.dbus.exceptions.MessageFormatException; +import org.freedesktop.dbus.exceptions.NotConnected; + +import cx.ath.matthew.debug.Debug; + +/** + * Error messages which can be sent over the bus. + */ +public class Error extends Message +{ + Error() { } + public Error(String dest, String errorName, long replyserial, String sig, Object... args) throws DBusException + { + this(null, dest, errorName, replyserial, sig, args); + } + public Error(String source, String dest, String errorName, long replyserial, String sig, Object... args) throws DBusException + { + super(Message.Endian.BIG, Message.MessageType.ERROR, (byte) 0); + + if (null == errorName) + throw new MessageFormatException(_("Must specify error name to Errors.")); + headers.put(Message.HeaderField.REPLY_SERIAL,replyserial); + headers.put(Message.HeaderField.ERROR_NAME,errorName); + + Vector<Object> hargs = new Vector<Object>(); + hargs.add(new Object[] { Message.HeaderField.ERROR_NAME, new Object[] { ArgumentType.STRING_STRING, errorName } }); + hargs.add(new Object[] { Message.HeaderField.REPLY_SERIAL, new Object[] { ArgumentType.UINT32_STRING, replyserial } }); + + if (null != source) { + headers.put(Message.HeaderField.SENDER,source); + hargs.add(new Object[] { Message.HeaderField.SENDER, new Object[] { ArgumentType.STRING_STRING, source } }); + } + + if (null != dest) { + headers.put(Message.HeaderField.DESTINATION,dest); + hargs.add(new Object[] { Message.HeaderField.DESTINATION, new Object[] { ArgumentType.STRING_STRING, dest } }); + } + + if (null != sig) { + hargs.add(new Object[] { Message.HeaderField.SIGNATURE, new Object[] { ArgumentType.SIGNATURE_STRING, sig } }); + headers.put(Message.HeaderField.SIGNATURE,sig); + setArgs(args); + } + + byte[] blen = new byte[4]; + appendBytes(blen); + append("ua(yv)", serial, hargs.toArray()); + pad((byte)8); + + long c = bytecounter; + if (null != sig) append(sig, args); + marshallint(bytecounter-c, blen, 0, 4); + } + public Error(String source, Message m, Throwable e) throws DBusException + { + this(source, m.getSource(), AbstractConnection.dollar_pattern.matcher(e.getClass().getName()).replaceAll("."), m.getSerial(), "s", e.getMessage()); + } + public Error(Message m, Throwable e) throws DBusException + { + this(m.getSource(), AbstractConnection.dollar_pattern.matcher(e.getClass().getName()).replaceAll("."), m.getSerial(), "s", e.getMessage()); + } + @SuppressWarnings("unchecked") + private static Class<? extends DBusExecutionException> createExceptionClass(String name) + { + if (name == "org.freedesktop.DBus.Local.Disconnected") return NotConnected.class; + Class<? extends DBusExecutionException> c = null; + do { + try { + c = (Class<? extends org.freedesktop.dbus.exceptions.DBusExecutionException>) Class.forName(name); + } catch (ClassNotFoundException CNFe) {} + name = name.replaceAll("\\.([^\\.]*)$", "\\$$1"); + } while (null == c && name.matches(".*\\..*")); + return c; + } + /** + * Turns this into an exception of the correct type + */ + public DBusExecutionException getException() + { + try { + Class<? extends DBusExecutionException> c = createExceptionClass(getName()); + if (null == c || !DBusExecutionException.class.isAssignableFrom(c)) c = DBusExecutionException.class; + Constructor<? extends DBusExecutionException> con = c.getConstructor(String.class); + DBusExecutionException ex; + Object[] args = getParameters(); + if (null == args || 0 == args.length) + ex = con.newInstance(""); + else { + String s = ""; + for (Object o: args) + s += o + " "; + ex = con.newInstance(s.trim()); + } + ex.setType(getName()); + return ex; + } catch (Exception e) { + if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, e); + if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug && null != e.getCause()) + Debug.print(Debug.ERR, e.getCause()); + DBusExecutionException ex; + Object[] args = null; + try { + args = getParameters(); + } catch (Exception ee) {} + if (null == args || 0 == args.length) + ex = new DBusExecutionException(""); + else { + String s = ""; + for (Object o: args) + s += o + " "; + ex = new DBusExecutionException(s.trim()); + } + ex.setType(getName()); + return ex; + } + } + /** + * Throw this as an exception of the correct type + */ + public void throwException() throws DBusExecutionException + { + throw getException(); + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/ExportedObject.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/ExportedObject.java new file mode 100755 index 0000000..3afa54b --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/ExportedObject.java @@ -0,0 +1,166 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import static org.freedesktop.dbus.Gettext._; + +import java.lang.ref.Reference; +import java.lang.ref.WeakReference; + +import java.lang.annotation.Annotation; +import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.HashMap; +import java.util.Map; + +import org.freedesktop.dbus.exceptions.DBusException; +import org.freedesktop.dbus.exceptions.DBusExecutionException; + +class ExportedObject +{ + @SuppressWarnings("unchecked") + private String getAnnotations(AnnotatedElement c) + { + String ans = ""; + for (Annotation a: c.getDeclaredAnnotations()) { + Class t = a.annotationType(); + String value = ""; + try { + Method m = t.getMethod("value"); + value = m.invoke(a).toString(); + } catch (NoSuchMethodException NSMe) { + } catch (InvocationTargetException ITe) { + } catch (IllegalAccessException IAe) {} + + ans += " <annotation name=\""+AbstractConnection.dollar_pattern.matcher(t.getName()).replaceAll(".")+"\" value=\""+value+"\" />\n"; + } + return ans; + } + @SuppressWarnings("unchecked") + private Map<MethodTuple,Method> getExportedMethods(Class c) throws DBusException + { + if (DBusInterface.class.equals(c)) return new HashMap<MethodTuple,Method>(); + Map<MethodTuple,Method> m = new HashMap<MethodTuple,Method>(); + for (Class i: c.getInterfaces()) + if (DBusInterface.class.equals(i)) { + // add this class's public methods + if (null != c.getAnnotation(DBusInterfaceName.class)) { + String name = ((DBusInterfaceName) c.getAnnotation(DBusInterfaceName.class)).value(); + introspectiondata += " <interface name=\""+name+"\">\n"; + DBusSignal.addInterfaceMap(c.getName(), name); + } else { + // don't let people export things which don't have a + // valid D-Bus interface name + if (c.getName().equals(c.getSimpleName())) + throw new DBusException(_("DBusInterfaces cannot be declared outside a package")); + if (c.getName().length() > DBusConnection.MAX_NAME_LENGTH) + throw new DBusException(_("Introspected interface name exceeds 255 characters. Cannot export objects of type ")+c.getName()); + else + introspectiondata += " <interface name=\""+AbstractConnection.dollar_pattern.matcher(c.getName()).replaceAll(".")+"\">\n"; + } + introspectiondata += getAnnotations(c); + for (Method meth: c.getDeclaredMethods()) + if (Modifier.isPublic(meth.getModifiers())) { + String ms = ""; + String name; + if (meth.isAnnotationPresent(DBusMemberName.class)) + name = meth.getAnnotation(DBusMemberName.class).value(); + else + name = meth.getName(); + if (name.length() > DBusConnection.MAX_NAME_LENGTH) + throw new DBusException(_("Introspected method name exceeds 255 characters. Cannot export objects with method ")+name); + introspectiondata += " <method name=\""+name+"\" >\n"; + introspectiondata += getAnnotations(meth); + for (Class ex: meth.getExceptionTypes()) + if (DBusExecutionException.class.isAssignableFrom(ex)) + introspectiondata += + " <annotation name=\"org.freedesktop.DBus.Method.Error\" value=\""+AbstractConnection.dollar_pattern.matcher(ex.getName()).replaceAll(".")+"\" />\n"; + for (Type pt: meth.getGenericParameterTypes()) + for (String s: Marshalling.getDBusType(pt)) { + introspectiondata += " <arg type=\""+s+"\" direction=\"in\"/>\n"; + ms += s; + } + if (!Void.TYPE.equals(meth.getGenericReturnType())) { + if (Tuple.class.isAssignableFrom((Class) meth.getReturnType())) { + ParameterizedType tc = (ParameterizedType) meth.getGenericReturnType(); + Type[] ts = tc.getActualTypeArguments(); + + for (Type t: ts) + if (t != null) + for (String s: Marshalling.getDBusType(t)) + introspectiondata += " <arg type=\""+s+"\" direction=\"out\"/>\n"; + } else if (Object[].class.equals(meth.getGenericReturnType())) { + throw new DBusException(_("Return type of Object[] cannot be introspected properly")); + } else + for (String s: Marshalling.getDBusType(meth.getGenericReturnType())) + introspectiondata += " <arg type=\""+s+"\" direction=\"out\"/>\n"; + } + introspectiondata += " </method>\n"; + m.put(new MethodTuple(name, ms), meth); + } + for (Class sig: c.getDeclaredClasses()) + if (DBusSignal.class.isAssignableFrom(sig)) { + String name; + if (sig.isAnnotationPresent(DBusMemberName.class)) { + name = ((DBusMemberName) sig.getAnnotation(DBusMemberName.class)).value(); + DBusSignal.addSignalMap(sig.getSimpleName(), name); + } else + name = sig.getSimpleName(); + if (name.length() > DBusConnection.MAX_NAME_LENGTH) + throw new DBusException(_("Introspected signal name exceeds 255 characters. Cannot export objects with signals of type ")+name); + introspectiondata += " <signal name=\""+name+"\">\n"; + Constructor con = sig.getConstructors()[0]; + Type[] ts = con.getGenericParameterTypes(); + for (int j = 1; j < ts.length; j++) + for (String s: Marshalling.getDBusType(ts[j])) + introspectiondata += " <arg type=\""+s+"\" direction=\"out\" />\n"; + introspectiondata += getAnnotations(sig); + introspectiondata += " </signal>\n"; + + } + introspectiondata += " </interface>\n"; + } else { + // recurse + m.putAll(getExportedMethods(i)); + } + return m; + } + Map<MethodTuple,Method> methods; + Reference<DBusInterface> object; + String introspectiondata; + public ExportedObject(DBusInterface object, boolean weakreferences) throws DBusException + { + if (weakreferences) + this.object = new WeakReference<DBusInterface>(object); + else + this.object = new StrongReference<DBusInterface>(object); + introspectiondata = ""; + methods = getExportedMethods(object.getClass()); + introspectiondata += + " <interface name=\"org.freedesktop.DBus.Introspectable\">\n"+ + " <method name=\"Introspect\">\n"+ + " <arg type=\"s\" direction=\"out\"/>\n"+ + " </method>\n"+ + " </interface>\n"; + introspectiondata += + " <interface name=\"org.freedesktop.DBus.Peer\">\n"+ + " <method name=\"Ping\">\n"+ + " </method>\n"+ + " </interface>\n"; + } +} + + diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Gettext.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Gettext.java new file mode 100755 index 0000000..5fd6de9 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Gettext.java @@ -0,0 +1,31 @@ +/* + * Pescetti Pseudo-Duplimate Generator + * + * Copyright (C) 2007 Matthew Johnson + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License Version 2 as published by + * the Free Software Foundation. This program is distributed in the hope that + * it will be useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. You should have received a + * copy of the GNU Lesser General Public License along with this program; if not, + * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * To Contact me, please email src@matthew.ath.cx + * + */ +package org.freedesktop.dbus; + +import java.util.ResourceBundle; + +public class Gettext +{ +// private static ResourceBundle myResources = +// ResourceBundle.getBundle("dbusjava_localized"); pego + public static String _(String s) { +// return myResources.getString(s); pego + return s; + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/InternalSignal.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/InternalSignal.java new file mode 100755 index 0000000..55954d5 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/InternalSignal.java @@ -0,0 +1,20 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; +import org.freedesktop.dbus.exceptions.DBusException; +class InternalSignal extends DBusSignal +{ + public InternalSignal(String source, String objectpath, String name, String iface, String sig, long serial, Object... parameters) throws DBusException + { + super(objectpath, iface, name, sig, parameters); + this.serial = serial; + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Marshalling.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Marshalling.java new file mode 100755 index 0000000..b561f19 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Marshalling.java @@ -0,0 +1,629 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import static org.freedesktop.dbus.Gettext._; + +import java.lang.reflect.Array; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.GenericArrayType; +import java.lang.reflect.Method; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.lang.reflect.TypeVariable; +import java.text.MessageFormat; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Vector; + +import org.freedesktop.dbus.exceptions.DBusException; +import org.freedesktop.dbus.types.DBusListType; +import org.freedesktop.dbus.types.DBusMapType; +import org.freedesktop.dbus.types.DBusStructType; + +import cx.ath.matthew.debug.Debug; + +/** + * Contains static methods for marshalling values. + */ +public class Marshalling +{ + private static Map<Type, String[]> typeCache = new HashMap<Type, String[]>(); + /** + * Will return the DBus type corresponding to the given Java type. + * Note, container type should have their ParameterizedType not their + * Class passed in here. + * @param c The Java types. + * @return The DBus types. + * @throws DBusException If the given type cannot be converted to a DBus type. + */ + public static String getDBusType(Type[] c) throws DBusException + { + StringBuffer sb = new StringBuffer(); + for (Type t: c) + for (String s: getDBusType(t)) + sb.append(s); + return sb.toString(); + } + /** + * Will return the DBus type corresponding to the given Java type. + * Note, container type should have their ParameterizedType not their + * Class passed in here. + * @param c The Java type. + * @return The DBus type. + * @throws DBusException If the given type cannot be converted to a DBus type. + */ + public static String[] getDBusType(Type c) throws DBusException + { + String[] cached = typeCache.get(c); + if (null != cached) return cached; + cached = getDBusType(c, false); + typeCache.put(c, cached); + return cached; + } + /** + * Will return the DBus type corresponding to the given Java type. + * Note, container type should have their ParameterizedType not their + * Class passed in here. + * @param c The Java type. + * @param basic If true enforces this to be a non-compound type. (compound types are Maps, Structs and Lists/arrays). + * @return The DBus type. + * @throws DBusException If the given type cannot be converted to a DBus type. + */ + public static String[] getDBusType(Type c, boolean basic) throws DBusException + { + return recursiveGetDBusType(c, basic, 0); + } + private static StringBuffer[] out = new StringBuffer[20]; // pego + @SuppressWarnings("unchecked") + public static String[] recursiveGetDBusType(Type c, boolean basic, int level) throws DBusException + { + if (out.length <= level) { + StringBuffer[] newout = new StringBuffer[out.length]; + System.arraycopy(out, 0, newout, 0, out.length); + out = newout; + } + if (null == out[level]) out[level] = new StringBuffer(); + else out[level].delete(0, out[level].length()); + + if (basic && !(c instanceof Class)) + throw new DBusException(c+_(" is not a basic type")); + + if (c instanceof TypeVariable) out[level].append((char) Message.ArgumentType.VARIANT); + else if (c instanceof GenericArrayType) { + out[level].append((char) Message.ArgumentType.ARRAY); + String[] s = recursiveGetDBusType(((GenericArrayType) c).getGenericComponentType(), false, level+1); + if (s.length != 1) throw new DBusException(_("Multi-valued array types not permitted")); + out[level].append(s[0]); + } else if ((c instanceof Class && + DBusSerializable.class.isAssignableFrom((Class<? extends Object>) c)) || + (c instanceof ParameterizedType && + DBusSerializable.class.isAssignableFrom((Class<? extends Object>) ((ParameterizedType) c).getRawType()))) { + // it's a custom serializable type + Type[] newtypes = null; + if (c instanceof Class) { + for (Method m: ((Class<? extends Object>) c).getDeclaredMethods()) + if (m.getName().equals("deserialize")) + newtypes = m.getGenericParameterTypes(); + } + else + for (Method m: ((Class<? extends Object>) ((ParameterizedType) c).getRawType()).getDeclaredMethods()) + if (m.getName().equals("deserialize")) + newtypes = m.getGenericParameterTypes(); + + if (null == newtypes) throw new DBusException(_("Serializable classes must implement a deserialize method")); + + String[] sigs = new String[newtypes.length]; + for (int j = 0; j < sigs.length; j++) { + String[] ss = recursiveGetDBusType(newtypes[j], false, level+1); + if (1 != ss.length) throw new DBusException(_("Serializable classes must serialize to native DBus types")); + sigs[j] = ss[0]; + } + return sigs; + } + else if (c instanceof ParameterizedType) { + ParameterizedType p = (ParameterizedType) c; + if (p.getRawType().equals(Map.class)) { + out[level].append("a{"); + Type[] t = p.getActualTypeArguments(); + try { + String[] s = recursiveGetDBusType(t[0], true, level+1); + if (s.length != 1) throw new DBusException(_("Multi-valued array types not permitted")); + out[level].append(s[0]); + s = recursiveGetDBusType(t[1], false, level+1); + if (s.length != 1) throw new DBusException(_("Multi-valued array types not permitted")); + out[level].append(s[0]); + } catch (ArrayIndexOutOfBoundsException AIOOBe) { + AIOOBe.printStackTrace(); // pego + if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, AIOOBe); + throw new DBusException(_("Map must have 2 parameters")); + } + out[level].append('}'); + } + else if (List.class.isAssignableFrom((Class<? extends Object>) p.getRawType())) { + for (Type t: p.getActualTypeArguments()) { + if (Type.class.equals(t)) + out[level].append((char) Message.ArgumentType.SIGNATURE); + else { + String[] s = recursiveGetDBusType(t, false, level+1); + if (s.length != 1) throw new DBusException(_("Multi-valued array types not permitted")); + out[level].append((char) Message.ArgumentType.ARRAY); + out[level].append(s[0]); + } + } + } + else if (p.getRawType().equals(Variant.class)) { + out[level].append((char) Message.ArgumentType.VARIANT); + } + else if (DBusInterface.class.isAssignableFrom((Class<? extends Object>) p.getRawType())) { + out[level].append((char) Message.ArgumentType.OBJECT_PATH); + } + else if (Tuple.class.isAssignableFrom((Class<? extends Object>) p.getRawType())) { + Type[] ts = p.getActualTypeArguments(); + Vector<String> vs = new Vector<String>(); + for (Type t: ts) + for (String s: recursiveGetDBusType(t, false, level+1)) + vs.add(s); + return vs.toArray(new String[0]); + } + else + throw new DBusException(_("Exporting non-exportable parameterized type ")+c); + } + + else if (c.equals(Byte.class)) out[level].append((char) Message.ArgumentType.BYTE); + else if (c.equals(Byte.TYPE)) out[level].append((char) Message.ArgumentType.BYTE); + else if (c.equals(Boolean.class)) out[level].append((char) Message.ArgumentType.BOOLEAN); + else if (c.equals(Boolean.TYPE)) out[level].append((char) Message.ArgumentType.BOOLEAN); + else if (c.equals(Short.class)) out[level].append((char) Message.ArgumentType.INT16); + else if (c.equals(Short.TYPE)) out[level].append((char) Message.ArgumentType.INT16); + else if (c.equals(UInt16.class)) out[level].append((char) Message.ArgumentType.UINT16); + else if (c.equals(Integer.class)) out[level].append((char) Message.ArgumentType.INT32); + else if (c.equals(Integer.TYPE)) out[level].append((char) Message.ArgumentType.INT32); + else if (c.equals(UInt32.class)) out[level].append((char) Message.ArgumentType.UINT32); + else if (c.equals(Long.class)) out[level].append((char) Message.ArgumentType.INT64); + else if (c.equals(Long.TYPE)) out[level].append((char) Message.ArgumentType.INT64); + else if (c.equals(UInt64.class)) out[level].append((char) Message.ArgumentType.UINT64); + else if (c.equals(Double.class)) out[level].append((char) Message.ArgumentType.DOUBLE); + else if (c.equals(Double.TYPE)) out[level].append((char) Message.ArgumentType.DOUBLE); + else if (c.equals(Float.class) && AbstractConnection.FLOAT_SUPPORT) out[level].append((char) Message.ArgumentType.FLOAT); + else if (c.equals(Float.class)) out[level].append((char) Message.ArgumentType.DOUBLE); + else if (c.equals(Float.TYPE) && AbstractConnection.FLOAT_SUPPORT) out[level].append((char) Message.ArgumentType.FLOAT); + else if (c.equals(Float.TYPE)) out[level].append((char) Message.ArgumentType.DOUBLE); + else if (c.equals(String.class)) out[level].append((char) Message.ArgumentType.STRING); + else if (c.equals(Variant.class)) out[level].append((char) Message.ArgumentType.VARIANT); + else if (c instanceof Class && + DBusInterface.class.isAssignableFrom((Class<? extends Object>) c)) out[level].append((char) Message.ArgumentType.OBJECT_PATH); + else if (c instanceof Class && + Path.class.equals((Class<? extends Object>) c)) out[level].append((char) Message.ArgumentType.OBJECT_PATH); + else if (c instanceof Class && + ObjectPath.class.equals((Class<? extends Object>) c)) out[level].append((char) Message.ArgumentType.OBJECT_PATH); + else if (c instanceof Class && + ((Class<? extends Object>) c).isArray()) { + if (Type.class.equals(((Class<? extends Object>) c).getComponentType())) + out[level].append((char) Message.ArgumentType.SIGNATURE); + else { + out[level].append((char) Message.ArgumentType.ARRAY); + String[] s = recursiveGetDBusType(((Class<? extends Object>) c).getComponentType(), false, level+1); + if (s.length != 1) throw new DBusException(_("Multi-valued array types not permitted")); + out[level].append(s[0]); + } + } else if (c instanceof Class && + Struct.class.isAssignableFrom((Class<? extends Object>) c)) { + out[level].append((char) Message.ArgumentType.STRUCT1); + Type[] ts = Container.getTypeCache(c); + if (null == ts) { + Field[] fs = ((Class<? extends Object>) c).getDeclaredFields(); + ts = new Type[fs.length]; + for (Field f : fs) { + Position p = f.getAnnotation(Position.class); + if (null == p) continue; + ts[p.value()] = f.getGenericType(); + } + Container.putTypeCache(c, ts); + } + + for (Type t: ts) + if (t != null) + for (String s: recursiveGetDBusType(t, false, level+1)) + out[level].append(s); + out[level].append(')'); + } else { + throw new DBusException(_("Exporting non-exportable type ")+c); + } + + if (Debug.debug) Debug.print(Debug.VERBOSE, "Converted Java type: "+c+" to D-Bus Type: "+out[level]); + + return new String[] { out[level].toString() }; + } + + /** + * Converts a dbus type string into Java Type objects, + * @param dbus The DBus type or types. + * @param rv Vector to return the types in. + * @param limit Maximum number of types to parse (-1 == nolimit). + * @return number of characters parsed from the type string. + */ + public static int getJavaType(String dbus, List<Type> rv, int limit) throws DBusException + { + if (null == dbus || "".equals(dbus) || 0 == limit) return 0; + + try { + int i = 0; + for (; i < dbus.length() && (-1 == limit || limit > rv.size()); i++) + switch(dbus.charAt(i)) { + case Message.ArgumentType.STRUCT1: + int j = i+1; + for (int c = 1; c > 0; j++) { + if (')' == dbus.charAt(j)) c--; + else if (Message.ArgumentType.STRUCT1 == dbus.charAt(j)) c++; + } + + Vector<Type> contained = new Vector<Type>(); + int c = getJavaType(dbus.substring(i+1, j-1), contained, -1); + rv.add(new DBusStructType(contained.toArray(new Type[0]))); + i = j; + break; + case Message.ArgumentType.ARRAY: + if (Message.ArgumentType.DICT_ENTRY1 == dbus.charAt(i+1)) { + contained = new Vector<Type>(); + c = getJavaType(dbus.substring(i+2), contained, 2); + rv.add(new DBusMapType(contained.get(0), contained.get(1))); + i += (c+2); + } else { + contained = new Vector<Type>(); + c = getJavaType(dbus.substring(i+1), contained, 1); + rv.add(new DBusListType(contained.get(0))); + i += c; + } + break; + case Message.ArgumentType.VARIANT: + rv.add(Variant.class); + break; + case Message.ArgumentType.BOOLEAN: + rv.add(Boolean.class); + break; + case Message.ArgumentType.INT16: + rv.add(Short.class); + break; + case Message.ArgumentType.BYTE: + rv.add(Byte.class); + break; + case Message.ArgumentType.OBJECT_PATH: + rv.add(DBusInterface.class); + break; + case Message.ArgumentType.UINT16: + rv.add(UInt16.class); + break; + case Message.ArgumentType.INT32: + rv.add(Integer.class); + break; + case Message.ArgumentType.UINT32: + rv.add(UInt32.class); + break; + case Message.ArgumentType.INT64: + rv.add(Long.class); + break; + case Message.ArgumentType.UINT64: + rv.add(UInt64.class); + break; + case Message.ArgumentType.DOUBLE: + rv.add(Double.class); + break; + case Message.ArgumentType.FLOAT: + rv.add(Float.class); + break; + case Message.ArgumentType.STRING: + rv.add(String.class); + break; + case Message.ArgumentType.SIGNATURE: + rv.add(Type[].class); + break; + case Message.ArgumentType.DICT_ENTRY1: + rv.add(Map.Entry.class); + contained = new Vector<Type>(); + c = getJavaType(dbus.substring(i+1), contained, 2); + i+=c+1; + break; + default: + throw new DBusException(MessageFormat.format(_("Failed to parse DBus type signature: {0} ({1})."), new Object[] { dbus, dbus.charAt(i) })); + } + return i; + } catch (IndexOutOfBoundsException IOOBe) { + IOOBe.printStackTrace(); // pego + if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, IOOBe); + throw new DBusException(_("Failed to parse DBus type signature: ")+dbus); + } + } + /** + * Recursively converts types for serialization onto DBus. + * @param parameters The parameters to convert. + * @param types The (possibly generic) types of the parameters. + * @return The converted parameters. + * @throws DBusException Thrown if there is an error in converting the objects. + */ + @SuppressWarnings("unchecked") + public static Object[] convertParameters(Object[] parameters, Type[] types, AbstractConnection conn) throws DBusException + { + if (null == parameters) return null; + for (int i = 0; i < parameters.length; i++) { + if (Debug.debug) Debug.print(Debug.VERBOSE,"Converting "+i+" from "+parameters[i]+" to "+types[i]); + if (null == parameters[i]) continue; + + if (parameters[i] instanceof DBusSerializable) { + for (Method m: parameters[i].getClass().getDeclaredMethods()) + if (m.getName().equals("deserialize")) { + Type[] newtypes = m.getParameterTypes(); + Type[] expand = new Type[types.length + newtypes.length - 1]; + System.arraycopy(types, 0, expand, 0, i); + System.arraycopy(newtypes, 0, expand, i, newtypes.length); + System.arraycopy(types, i+1, expand, i+newtypes.length, types.length-i-1); + types = expand; + Object[] newparams = ((DBusSerializable) parameters[i]).serialize(); + Object[] exparams = new Object[parameters.length + newparams.length - 1]; + System.arraycopy(parameters, 0, exparams, 0, i); + System.arraycopy(newparams, 0, exparams, i, newparams.length); + System.arraycopy(parameters, i+1, exparams, i+newparams.length, parameters.length-i-1); + parameters = exparams; + } + i--; + } else if (parameters[i] instanceof Tuple) { + Type[] newtypes = ((ParameterizedType) types[i]).getActualTypeArguments(); + Type[] expand = new Type[types.length + newtypes.length - 1]; + System.arraycopy(types, 0, expand, 0, i); + System.arraycopy(newtypes, 0, expand, i, newtypes.length); + System.arraycopy(types, i+1, expand, i+newtypes.length, types. length-i-1); + types = expand; + Object[] newparams = ((Tuple) parameters[i]).getParameters(); + Object[] exparams = new Object[parameters.length + newparams.length - 1]; + System.arraycopy(parameters, 0, exparams, 0, i); + System.arraycopy(newparams, 0, exparams, i, newparams.length); + System.arraycopy(parameters, i+1, exparams, i+newparams.length, parameters.length-i-1); + parameters = exparams; + if (Debug.debug) Debug.print(Debug.VERBOSE, "New params: "+Arrays.deepToString(parameters)+" new types: "+Arrays.deepToString(types)); + i--; + } else if (types[i] instanceof TypeVariable && + !(parameters[i] instanceof Variant)) + // its an unwrapped variant, wrap it + parameters[i] = new Variant<Object>(parameters[i]); + else if (parameters[i] instanceof DBusInterface) + parameters[i] = conn.getExportedObject((DBusInterface) parameters[i]); + } + return parameters; + } + @SuppressWarnings("unchecked") + static Object deSerializeParameter(Object parameter, Type type, AbstractConnection conn) throws Exception + { + if (Debug.debug) Debug.print(Debug.VERBOSE, "Deserializing from "+parameter.getClass()+" to "+type.getClass()); + if (null == parameter) + return null; + + // its a wrapped variant, unwrap it + if (type instanceof TypeVariable + && parameter instanceof Variant) { + parameter = ((Variant)parameter).getValue(); + } + + // Turn a signature into a Type[] + if (type instanceof Class + && ((Class) type).isArray() + && ((Class) type).getComponentType().equals(Type.class) + && parameter instanceof String) { + Vector<Type> rv = new Vector<Type>(); + getJavaType((String) parameter, rv, -1); + parameter = rv.toArray(new Type[0]); + } + + // its an object path, get/create the proxy + if (parameter instanceof ObjectPath) { + if (type instanceof Class && DBusInterface.class.isAssignableFrom((Class) type)) + parameter = conn.getExportedObject( + ((ObjectPath) parameter).source, + ((ObjectPath) parameter).path); + else + parameter = new Path(((ObjectPath) parameter).path); + } + + // it should be a struct. create it + if (parameter instanceof Object[] && + type instanceof Class && + Struct.class.isAssignableFrom((Class) type)) { + if (Debug.debug) Debug.print(Debug.VERBOSE, "Creating Struct "+type+" from "+parameter); + Type[] ts = Container.getTypeCache(type); + if (null == ts) { + Field[] fs = ((Class) type).getDeclaredFields(); + ts = new Type[fs.length]; + for (Field f : fs) { + Position p = f.getAnnotation(Position.class); + if (null == p) continue; + ts[p.value()] = f.getGenericType(); + } + Container.putTypeCache(type, ts); + } + + // recurse over struct contents + parameter = deSerializeParameters((Object[]) parameter, ts, conn); + for (Constructor con: ((Class) type).getDeclaredConstructors()) { + try { + parameter = con.newInstance((Object[]) parameter); + break; + } catch (IllegalArgumentException IAe) {} + } + } + + // recurse over arrays + if (parameter instanceof Object[]) { + Type[] ts = new Type[((Object[]) parameter).length]; + Arrays.fill(ts, parameter.getClass().getComponentType()); + parameter = deSerializeParameters((Object[]) parameter, + ts, conn); + } + if (parameter instanceof List) { + Type type2; + if (type instanceof ParameterizedType) + type2 = ((ParameterizedType) type).getActualTypeArguments()[0]; + else if (type instanceof GenericArrayType) + type2 = ((GenericArrayType) type).getGenericComponentType(); + else if (type instanceof Class && ((Class) type).isArray()) + type2 = ((Class) type).getComponentType(); + else + type2 = null; + if (null != type2) + parameter = deSerializeParameters((List) parameter, type2, conn); + } + + // correct floats if appropriate + if (type.equals(Float.class) || type.equals(Float.TYPE)) + if (!(parameter instanceof Float)) + parameter = ((Number) parameter).floatValue(); + + // make sure arrays are in the correct format + if (parameter instanceof Object[] || + parameter instanceof List || + parameter.getClass().isArray()) { + if (type instanceof ParameterizedType) + parameter = ArrayFrob.convert(parameter, + (Class<? extends Object>) ((ParameterizedType) type).getRawType()); + else if (type instanceof GenericArrayType) { + Type ct = ((GenericArrayType) type).getGenericComponentType(); + Class cc = null; + if (ct instanceof Class) + cc = (Class) ct; + if (ct instanceof ParameterizedType) + cc = (Class) ((ParameterizedType) ct).getRawType(); + Object o = Array.newInstance(cc, 0); + parameter = ArrayFrob.convert(parameter, + o.getClass()); + } else if (type instanceof Class && + ((Class) type).isArray()) { + Class cc = ((Class) type).getComponentType(); + if ((cc.equals(Float.class) || cc.equals(Float.TYPE)) + && (parameter instanceof double[])) { + double[] tmp1 = (double[]) parameter; + float[] tmp2 = new float[tmp1.length]; + for (int i = 0; i < tmp1.length; i++) + tmp2[i] = (float) tmp1[i]; + parameter = tmp2; + } + Object o = Array.newInstance(cc, 0); + parameter = ArrayFrob.convert(parameter, + o.getClass()); + } + } + if (parameter instanceof DBusMap) { + if (Debug.debug) Debug.print(Debug.VERBOSE, "Deserializing a Map"); + DBusMap dmap = (DBusMap) parameter; + Type[] maptypes = ((ParameterizedType) type).getActualTypeArguments(); + for (int i = 0; i < dmap.entries.length; i++) { + dmap.entries[i][0] = deSerializeParameter(dmap.entries[i][0], maptypes[0], conn); + dmap.entries[i][1] = deSerializeParameter(dmap.entries[i][1], maptypes[1], conn); + } + } + return parameter; + } + static List<Object> deSerializeParameters(List<Object> parameters, Type type, AbstractConnection conn) throws Exception + { + if (Debug.debug) Debug.print(Debug.VERBOSE, "Deserializing from "+parameters+" to "+type); + if (null == parameters) return null; + for (int i = 0; i < parameters.size(); i++) { + if (null == parameters.get(i)) continue; + + /* DO NOT DO THIS! IT'S REALLY NOT SUPPORTED! + * if (type instanceof Class && + DBusSerializable.class.isAssignableFrom((Class) types[i])) { + for (Method m: ((Class) types[i]).getDeclaredMethods()) + if (m.getName().equals("deserialize")) { + Type[] newtypes = m.getGenericParameterTypes(); + try { + Object[] sub = new Object[newtypes.length]; + System.arraycopy(parameters, i, sub, 0, newtypes.length); + sub = deSerializeParameters(sub, newtypes, conn); + DBusSerializable sz = (DBusSerializable) ((Class) types[i]).newInstance(); + m.invoke(sz, sub); + Object[] compress = new Object[parameters.length - newtypes.length + 1]; + System.arraycopy(parameters, 0, compress, 0, i); + compress[i] = sz; + System.arraycopy(parameters, i + newtypes.length, compress, i+1, parameters.length - i - newtypes.length); + parameters = compress; + } catch (ArrayIndexOutOfBoundsException AIOOBe) { + if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, AIOOBe); + throw new DBusException("Not enough elements to create custom object from serialized data ("+(parameters.size()-i)+" < "+(newtypes.length)+")"); + } + } + } else*/ + parameters.set(i, deSerializeParameter(parameters.get(i), type, conn)); + } + return parameters; + } + + @SuppressWarnings("unchecked") + static Object[] deSerializeParameters(Object[] parameters, Type[] types, AbstractConnection conn) throws Exception + { + if (Debug.debug) Debug.print(Debug.VERBOSE, "Deserializing from "+Arrays.deepToString(parameters)+" to "+Arrays.deepToString(types)); + if (null == parameters) return null; + + if (types.length == 1 && types[0] instanceof ParameterizedType + && Tuple.class.isAssignableFrom((Class) ((ParameterizedType) types[0]).getRawType())) { + types = ((ParameterizedType) types[0]).getActualTypeArguments(); + } + + for (int i = 0; i < parameters.length; i++) { + // CHECK IF ARRAYS HAVE THE SAME LENGTH <-- has to happen after expanding parameters + if (i >= types.length) { + if (Debug.debug) { + for (int j = 0; j < parameters.length; j++) { + Debug.print(Debug.ERR, String.format("Error, Parameters difference (%1d, '%2s')", j, parameters[j].toString())); + } + } + throw new DBusException(_("Error deserializing message: number of parameters didn't match receiving signature")); + } + if (null == parameters[i]) continue; + + if ((types[i] instanceof Class && + DBusSerializable.class.isAssignableFrom((Class<? extends Object>) types[i])) || + (types[i] instanceof ParameterizedType && + DBusSerializable.class.isAssignableFrom((Class<? extends Object>) ((ParameterizedType) types[i]).getRawType()))) { + Class<? extends DBusSerializable> dsc; + if (types[i] instanceof Class) + dsc = (Class<? extends DBusSerializable>) types[i]; + else + dsc = (Class<? extends DBusSerializable>) ((ParameterizedType) types[i]).getRawType(); + for (Method m: dsc.getDeclaredMethods()) + if (m.getName().equals("deserialize")) { + Type[] newtypes = m.getGenericParameterTypes(); + try { + Object[] sub = new Object[newtypes.length]; + System.arraycopy(parameters, i, sub, 0, newtypes.length); + sub = deSerializeParameters(sub, newtypes, conn); + DBusSerializable sz = dsc.newInstance(); + m.invoke(sz, sub); + Object[] compress = new Object[parameters.length - newtypes.length + 1]; + System.arraycopy(parameters, 0, compress, 0, i); + compress[i] = sz; + System.arraycopy(parameters, i + newtypes.length, compress, i+1, parameters.length - i - newtypes.length); + parameters = compress; + } catch (ArrayIndexOutOfBoundsException AIOOBe) { + AIOOBe.printStackTrace(); // pego + if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, AIOOBe); + throw new DBusException(MessageFormat.format(_("Not enough elements to create custom object from serialized data ({0} < {1})."), + new Object[] { parameters.length-i, newtypes.length })); + } + } + } else + parameters[i] = deSerializeParameter(parameters[i], types[i], conn); + } + return parameters; + } +} + + diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Message.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Message.java new file mode 100755 index 0000000..269ffab --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Message.java @@ -0,0 +1,1225 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import static org.freedesktop.dbus.Gettext._; + +import java.lang.reflect.Array; +import java.lang.reflect.Type; +import java.io.UnsupportedEncodingException; +import java.text.MessageFormat; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Vector; + +import cx.ath.matthew.debug.Debug; +import cx.ath.matthew.utils.Hexdump; + +import org.freedesktop.dbus.exceptions.DBusException; +import org.freedesktop.dbus.exceptions.MarshallingException; +import org.freedesktop.dbus.exceptions.UnknownTypeCodeException; + +/** + * Superclass of all messages which are sent over the Bus. + * This class deals with all the marshalling to/from the wire format. + */ +public class Message +{ + /** Defines constants representing the endianness of the message. */ + public static interface Endian { + public static final byte BIG = 'B'; + public static final byte LITTLE = 'l'; + } + /** Defines constants representing the flags which can be set on a message. */ + public static interface Flags { + public static final byte NO_REPLY_EXPECTED = 0x01; + public static final byte NO_AUTO_START = 0x02; + public static final byte ASYNC = 0x40; + } + /** Defines constants for each message type. */ + public static interface MessageType { + public static final byte METHOD_CALL = 1; + public static final byte METHOD_RETURN = 2; + public static final byte ERROR = 3; + public static final byte SIGNAL = 4; + } + /** The current protocol major version. */ + public static final byte PROTOCOL = 1; + /** Defines constants for each valid header field type. */ + public static interface HeaderField { + public static final byte PATH = 1; + public static final byte INTERFACE = 2; + public static final byte MEMBER = 3; + public static final byte ERROR_NAME = 4; + public static final byte REPLY_SERIAL = 5; + public static final byte DESTINATION = 6; + public static final byte SENDER = 7; + public static final byte SIGNATURE = 8; + } + /** Defines constants for each argument type. + * There are two constants for each argument type, + * as a byte or as a String (the _STRING version) */ + public static interface ArgumentType { + public static final String BYTE_STRING="y"; + public static final String BOOLEAN_STRING="b"; + public static final String INT16_STRING="n"; + public static final String UINT16_STRING="q"; + public static final String INT32_STRING="i"; + public static final String UINT32_STRING="u"; + public static final String INT64_STRING="x"; + public static final String UINT64_STRING="t"; + public static final String DOUBLE_STRING="d"; + public static final String FLOAT_STRING="f"; + public static final String STRING_STRING="s"; + public static final String OBJECT_PATH_STRING="o"; + public static final String SIGNATURE_STRING="g"; + public static final String ARRAY_STRING="a"; + public static final String VARIANT_STRING="v"; + public static final String STRUCT_STRING="r"; + public static final String STRUCT1_STRING="("; + public static final String STRUCT2_STRING=")"; + public static final String DICT_ENTRY_STRING="e"; + public static final String DICT_ENTRY1_STRING="{"; + public static final String DICT_ENTRY2_STRING="}"; + + public static final byte BYTE='y'; + public static final byte BOOLEAN='b'; + public static final byte INT16='n'; + public static final byte UINT16='q'; + public static final byte INT32='i'; + public static final byte UINT32='u'; + public static final byte INT64='x'; + public static final byte UINT64='t'; + public static final byte DOUBLE='d'; + public static final byte FLOAT='f'; + public static final byte STRING='s'; + public static final byte OBJECT_PATH='o'; + public static final byte SIGNATURE='g'; + public static final byte ARRAY='a'; + public static final byte VARIANT='v'; + public static final byte STRUCT='r'; + public static final byte STRUCT1='('; + public static final byte STRUCT2=')'; + public static final byte DICT_ENTRY='e'; + public static final byte DICT_ENTRY1='{'; + public static final byte DICT_ENTRY2='}'; + } + /** Keep a static reference to each size of padding array to prevent allocation. */ + private static byte[][] padding; + static { + padding = new byte[][] { + null, + new byte[1], + new byte[2], + new byte[3], + new byte[4], + new byte[5], + new byte[6], + new byte[7] }; + } + /** Steps to increment the buffer array. */ + private static final int BUFFERINCREMENT = 20; + + private boolean big; + protected byte[][] wiredata; + protected long bytecounter; + protected Map<Byte, Object> headers; + protected static long globalserial = 0; + protected long serial; + protected byte type; + protected byte flags; + protected byte protover; + private Object[] args; + private byte[] body; + private long bodylen = 0; + private int preallocated = 0; + private int paofs = 0; + private byte[] pabuf; + private int bufferuse = 0; + + /** + * Returns the name of the given header field. + */ + public static String getHeaderFieldName(byte field) + { + switch (field) { + case HeaderField.PATH: return "Path"; + case HeaderField.INTERFACE: return "Interface"; + case HeaderField.MEMBER: return "Member"; + case HeaderField.ERROR_NAME: return "Error Name"; + case HeaderField.REPLY_SERIAL: return "Reply Serial"; + case HeaderField.DESTINATION: return "Destination"; + case HeaderField.SENDER: return "Sender"; + case HeaderField.SIGNATURE: return "Signature"; + default: return "Invalid"; + } + } + + /** + * Create a message; only to be called by sub-classes. + * @param endian The endianness to create the message. + * @param type The message type. + * @param flags Any message flags. + */ + protected Message(byte endian, byte type, byte flags) throws DBusException + { + wiredata = new byte[BUFFERINCREMENT][]; + headers = new HashMap<Byte, Object>(); + big = (Endian.BIG == endian); + bytecounter = 0; + synchronized (Message.class) { + serial = ++globalserial; + } + if (Debug.debug) Debug.print(Debug.DEBUG, "Creating message with serial "+serial); + this.type = type; + this.flags = flags; + preallocate(4); + append("yyyy", endian, type, flags, Message.PROTOCOL); + } + /** + * Create a blank message. Only to be used when calling populate. + */ + protected Message() + { + wiredata = new byte[BUFFERINCREMENT][]; + headers = new HashMap<Byte, Object>(); + bytecounter = 0; + } + /** + * Create a message from wire-format data. + * @param msg D-Bus serialized data of type yyyuu + * @param headers D-Bus serialized data of type a(yv) + * @param body D-Bus serialized data of the signature defined in headers. + */ + @SuppressWarnings("unchecked") + void populate(byte[] msg, byte[] headers, byte[] body) throws DBusException + { + big = (msg[0] == Endian.BIG); + type = msg[1]; + flags = msg[2]; + protover = msg[3]; + wiredata[0] = msg; + wiredata[1] = headers; + wiredata[2] = body; + this.body = body; + bufferuse = 3; + bodylen = ((Number) extract(Message.ArgumentType.UINT32_STRING, msg, 4)[0]).longValue(); + serial = ((Number) extract(Message.ArgumentType.UINT32_STRING, msg, 8)[0]).longValue(); + bytecounter = msg.length+headers.length+body.length; + if (Debug.debug) Debug.print(Debug.VERBOSE, headers); + Object[] hs = extract("a(yv)", headers, 0); + if (Debug.debug) Debug.print(Debug.VERBOSE, Arrays.deepToString(hs)); + for (Object o: (Vector<Object>) hs[0]) { + this.headers.put((Byte) ((Object[])o)[0], ((Variant<Object>)((Object[])o)[1]).getValue()); + } + } + /** + * Create a buffer of num bytes. + * Data is copied to this rather than added to the buffer list. + */ + private void preallocate(int num) + { + preallocated = 0; + pabuf = new byte[num]; + appendBytes(pabuf); + preallocated = num; + paofs = 0; + } + /** + * Ensures there are enough free buffers. + * @param num number of free buffers to create. + */ + private void ensureBuffers(int num) + { + int increase = num - wiredata.length + bufferuse; + if (increase > 0) { + if (increase < BUFFERINCREMENT) increase = BUFFERINCREMENT; + if (Debug.debug) Debug.print(Debug.VERBOSE, "Resizing "+bufferuse); + byte[][] temp = new byte[wiredata.length+increase][]; + System.arraycopy(wiredata, 0, temp, 0, wiredata.length); + wiredata = temp; + } + } + /** + * Appends a buffer to the buffer list. + */ + protected void appendBytes(byte[] buf) + { + if (null == buf) return; + if (preallocated > 0) { + if (paofs+buf.length > pabuf.length) + throw new ArrayIndexOutOfBoundsException(MessageFormat.format(_("Array index out of bounds, paofs={0}, pabuf.length={1}, buf.length={2}."), new Object[] { paofs, pabuf.length, buf.length })); + System.arraycopy(buf, 0, pabuf, paofs, buf.length); + paofs += buf.length; + preallocated -= buf.length; + } else { + if (bufferuse == wiredata.length) { + if (Debug.debug) Debug.print(Debug.VERBOSE, "Resizing "+bufferuse); + byte[][] temp = new byte[wiredata.length+BUFFERINCREMENT][]; + System.arraycopy(wiredata, 0, temp, 0, wiredata.length); + wiredata = temp; + } + wiredata[bufferuse++] = buf; + bytecounter += buf.length; + } + } + /** + * Appends a byte to the buffer list. + */ + protected void appendByte(byte b) + { + if (preallocated > 0) { + pabuf[paofs++] = b; + preallocated--; + } else { + if (bufferuse == wiredata.length) { + if (Debug.debug) Debug.print(Debug.VERBOSE, "Resizing "+bufferuse); + byte[][] temp = new byte[wiredata.length+BUFFERINCREMENT][]; + System.arraycopy(wiredata, 0, temp, 0, wiredata.length); + wiredata = temp; + } + wiredata[bufferuse++] = new byte[] { b }; + bytecounter++; + } + } + /** + * Demarshalls an integer of a given width from a buffer. + * Endianness is determined from the format of the message. + * @param buf The buffer to demarshall from. + * @param ofs The offset to demarshall from. + * @param width The byte-width of the int. + */ + public long demarshallint(byte[] buf, int ofs, int width) + { return big ? demarshallintBig(buf,ofs,width) : demarshallintLittle(buf,ofs,width); } + /** + * Demarshalls an integer of a given width from a buffer. + * @param buf The buffer to demarshall from. + * @param ofs The offset to demarshall from. + * @param endian The endianness to use in demarshalling. + * @param width The byte-width of the int. + */ + public static long demarshallint(byte[] buf, int ofs, byte endian, int width) + { return endian==Endian.BIG ? demarshallintBig(buf,ofs,width) : demarshallintLittle(buf,ofs,width); } + /** + * Demarshalls an integer of a given width from a buffer using big-endian format. + * @param buf The buffer to demarshall from. + * @param ofs The offset to demarshall from. + * @param width The byte-width of the int. + */ + public static long demarshallintBig(byte[] buf, int ofs, int width) + { + long l = 0; + for (int i = 0; i < width; i++) { + l <<=8; + l |= (buf[ofs+i] & 0xFF); + } + return l; + } + /** + * Demarshalls an integer of a given width from a buffer using little-endian format. + * @param buf The buffer to demarshall from. + * @param ofs The offset to demarshall from. + * @param width The byte-width of the int. + */ + public static long demarshallintLittle(byte[] buf, int ofs, int width) + { + long l = 0; + for (int i = (width-1); i >= 0; i--) { + l <<=8; + l |= (buf[ofs+i] & 0xFF); + } + return l; + } + /** + * Marshalls an integer of a given width and appends it to the message. + * Endianness is determined from the message. + * @param l The integer to marshall. + * @param width The byte-width of the int. + */ + public void appendint(long l, int width) + { + byte[] buf = new byte[width]; + marshallint(l, buf, 0, width); + appendBytes(buf); + } + /** + * Marshalls an integer of a given width into a buffer. + * Endianness is determined from the message. + * @param l The integer to marshall. + * @param buf The buffer to marshall to. + * @param ofs The offset to marshall to. + * @param width The byte-width of the int. + */ + public void marshallint(long l, byte[] buf, int ofs, int width) + { + if (big) marshallintBig(l, buf, ofs, width); else marshallintLittle(l, buf, ofs, width); + if (Debug.debug) Debug.print(Debug.VERBOSE, "Marshalled int "+l+" to "+Hexdump.toHex(buf,ofs,width)); + } + /** + * Marshalls an integer of a given width into a buffer using big-endian format. + * @param l The integer to marshall. + * @param buf The buffer to marshall to. + * @param ofs The offset to marshall to. + * @param width The byte-width of the int. + */ + public static void marshallintBig(long l, byte[] buf, int ofs, int width) + { + for (int i = (width-1); i >= 0; i--) { + buf[i+ofs] = (byte) (l & 0xFF); + l >>= 8; + } + } + /** + * Marshalls an integer of a given width into a buffer using little-endian format. + * @param l The integer to marshall. + * @param buf The buffer to demarshall to. + * @param ofs The offset to demarshall to. + * @param width The byte-width of the int. + */ + public static void marshallintLittle(long l, byte[] buf, int ofs, int width) + { + for (int i = 0; i < width; i++) { + buf[i+ofs] = (byte) (l & 0xFF); + l >>= 8; + } + } + public byte[][] getWireData() + { + return wiredata; + } + /** + * Formats the message in a human-readable format. + */ + public String toString() + { + StringBuffer sb = new StringBuffer(); + sb.append(getClass().getSimpleName()); + sb.append ('('); + sb.append (flags); + sb.append (','); + sb.append(serial); + sb.append (')'); + sb.append (' '); + sb.append ('{'); + sb.append(' '); + if (headers.size() == 0) + sb.append('}'); + else { + for (Byte field: headers.keySet()) { + sb.append(getHeaderFieldName(field)); + sb.append('='); + sb.append('>'); + sb.append(headers.get(field).toString()); + sb.append(','); + sb.append(' '); + } + sb.setCharAt(sb.length()-2,' '); + sb.setCharAt(sb.length()-1,'}'); + } + sb.append(' '); + sb.append('{'); + sb.append(' '); + Object[] args = null; + try { + args = getParameters(); + } catch (DBusException DBe) { + DBe.printStackTrace(); // pego + if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, DBe); + } + if (null == args || 0 == args.length) + sb.append('}'); + else { + for (Object o: args) { + if (o instanceof Object[]) + sb.append(Arrays.deepToString((Object[]) o)); + else if (o instanceof byte[]) + sb.append(Arrays.toString((byte[]) o)); + else if (o instanceof int[]) + sb.append(Arrays.toString((int[]) o)); + else if (o instanceof short[]) + sb.append(Arrays.toString((short[]) o)); + else if (o instanceof long[]) + sb.append(Arrays.toString((long[]) o)); + else if (o instanceof boolean[]) + sb.append(Arrays.toString((boolean[]) o)); + else if (o instanceof double[]) + sb.append(Arrays.toString((double[]) o)); + else if (o instanceof float[]) + sb.append(Arrays.toString((float[]) o)); + else + if (o != null) { // pego + sb.append(o.toString()); + } else { // pego + sb.append("null"); // pego + } // pego + sb.append(','); + sb.append(' '); + } + sb.setCharAt(sb.length()-2,' '); + sb.setCharAt(sb.length()-1,'}'); + } + return sb.toString(); + } + /** + * Returns the value of the header field of a given field. + * @param type The field to return. + * @return The value of the field or null if unset. + */ + public Object getHeader(byte type) { return headers.get(type); } + /** + * Appends a value to the message. + * The type of the value is read from a D-Bus signature and used to marshall + * the value. + * @param sigb A buffer of the D-Bus signature. + * @param sigofs The offset into the signature corresponding to this value. + * @param data The value to marshall. + * @return The offset into the signature of the end of this value's type. + */ + @SuppressWarnings("unchecked") + private int appendone(byte[] sigb, int sigofs, Object data) throws DBusException + { + try { + int i = sigofs; + if (Debug.debug) Debug.print(Debug.VERBOSE, (Object) bytecounter); + if (Debug.debug) Debug.print(Debug.VERBOSE, "Appending type: "+((char)sigb[i])+" value: "+data); + + // pad to the alignment of this type. + pad(sigb[i]); + switch (sigb[i]) { + case ArgumentType.BYTE: + appendByte(((Number) data).byteValue()); + break; + case ArgumentType.BOOLEAN: + appendint(((Boolean) data).booleanValue() ? 1 : 0, 4); + break; + case ArgumentType.DOUBLE: + long l = Double.doubleToLongBits(((Number) data).doubleValue()); + appendint(l, 8); + break; + case ArgumentType.FLOAT: + int rf = Float.floatToIntBits(((Number) data).floatValue()); + appendint(rf, 4); + break; + case ArgumentType.UINT32: + appendint(((Number) data).longValue(), 4); + break; + case ArgumentType.INT64: + appendint(((Number) data).longValue(), 8); + break; + case ArgumentType.UINT64: + if (big) { + appendint(((UInt64) data).top(), 4); + appendint(((UInt64) data).bottom(), 4); + } else { + appendint(((UInt64) data).bottom(), 4); + appendint(((UInt64) data).top(), 4); + } + break; + case ArgumentType.INT32: + appendint(((Number) data).intValue(), 4); + break; + case ArgumentType.UINT16: + appendint(((Number) data).intValue(), 2); + break; + case ArgumentType.INT16: + appendint(((Number) data).shortValue(), 2); + break; + case ArgumentType.STRING: + case ArgumentType.OBJECT_PATH: + // Strings are marshalled as a UInt32 with the length, + // followed by the String, followed by a null byte. + String payload = data.toString(); + byte[] payloadbytes = null; + try { + payloadbytes = payload.getBytes("UTF-8"); + } catch (UnsupportedEncodingException UEe) { + UEe.printStackTrace(); // pego + if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug) Debug.print(UEe); + throw new DBusException(_("System does not support UTF-8 encoding")); + } + if (Debug.debug) Debug.print(Debug.VERBOSE, "Appending String of length "+payloadbytes.length); + appendint(payloadbytes.length, 4); + appendBytes(payloadbytes); + appendBytes(padding[1]); + //pad(ArgumentType.STRING);? do we need this? + break; + case ArgumentType.SIGNATURE: + // Signatures are marshalled as a byte with the length, + // followed by the String, followed by a null byte. + // Signatures are generally short, so preallocate the array + // for the string, length and null byte. + if (data instanceof Type[]) + payload = Marshalling.getDBusType((Type[]) data); + else + payload = (String) data; + byte[] pbytes = payload.getBytes(); + preallocate(2+pbytes.length); + appendByte((byte) pbytes.length); + appendBytes(pbytes); + appendByte((byte) 0); + break; + case ArgumentType.ARRAY: + // Arrays are given as a UInt32 for the length in bytes, + // padding to the element alignment, then elements in + // order. The length is the length from the end of the + // initial padding to the end of the last element. + if (Debug.debug) { + if (data instanceof Object[]) + Debug.print(Debug.VERBOSE, "Appending array: "+Arrays.deepToString((Object[])data)); + } + + byte[] alen = new byte[4]; + appendBytes(alen); + pad(sigb[++i]); + long c = bytecounter; + + // optimise primatives + if (data.getClass().isArray() && + data.getClass().getComponentType().isPrimitive()) { + byte[] primbuf; + int algn = getAlignment(sigb[i]); + int len = Array.getLength(data); + switch (sigb[i]) { + case ArgumentType.BYTE: + primbuf = (byte[]) data; + break; + case ArgumentType.INT16: + case ArgumentType.INT32: + case ArgumentType.INT64: + primbuf = new byte[len*algn]; + for (int j = 0, k = 0; j < len; j++, k += algn) + marshallint(Array.getLong(data, j), primbuf, k, algn); + break; + case ArgumentType.BOOLEAN: + primbuf = new byte[len*algn]; + for (int j = 0, k = 0; j < len; j++, k += algn) + marshallint(Array.getBoolean(data, j)?1:0, primbuf, k, algn); + break; + case ArgumentType.DOUBLE: + primbuf = new byte[len*algn]; + if (data instanceof float[]) + for (int j = 0, k = 0; j < len; j++, k += algn) + marshallint(Double.doubleToRawLongBits(((float[])data)[j]), + primbuf, k, algn); + else + for (int j = 0, k = 0; j < len; j++, k += algn) + marshallint(Double.doubleToRawLongBits(((double[])data)[j]), + primbuf, k, algn); + break; + case ArgumentType.FLOAT: + primbuf = new byte[len*algn]; + for (int j = 0, k = 0; j < len; j++, k += algn) + marshallint( + Float.floatToRawIntBits(((float[])data)[j]), + primbuf, k, algn); + break; + default: + throw new MarshallingException(_("Primative array being sent as non-primative array.")); + } + appendBytes(primbuf); + } else if (data instanceof List) { + Object[] contents = ((List) data).toArray(); + int diff = i; + ensureBuffers(contents.length*4); + for (Object o: contents) + diff = appendone(sigb, i, o); + i = diff; + if (contents.length == 0 && sigb[i] == '(') { // pego In case of zero length array of structs, the 'struct signature' still has to be skipped. +// System.out.println("PEGO: Going to skip signature for zero sized array."); + int nestingLevel = 1; + int sigSkipIndex = i; + boolean correspondingStruct2Found = false; + while (!correspondingStruct2Found) { + sigSkipIndex++; +// System.out.println("PEGO: sigSkipIndex = " + sigSkipIndex + ", byte = " + sigb[sigSkipIndex]); + switch (sigb[sigSkipIndex]) { + case ArgumentType.STRUCT1: + nestingLevel++; + break; + + case ArgumentType.STRUCT2: + nestingLevel--; + if (nestingLevel == 0) { + correspondingStruct2Found = true; + } + break; + + default: + // no action + } + } + i = sigSkipIndex; +// System.out.println("PEGO: setting i to: " + i); + } + } else if (data instanceof Map) { + int diff = i; + ensureBuffers(((Map) data).size()*6); + for (Map.Entry<Object,Object> o: ((Map<Object,Object>) data).entrySet()) + diff = appendone(sigb, i, o); + if (i == diff) { + // advance the type parser even on 0-size arrays. + Vector<Type> temp = new Vector<Type>(); + byte[] temp2 = new byte[sigb.length-diff]; + System.arraycopy(sigb, diff, temp2, 0, temp2.length); + String temp3 = new String(temp2); + int temp4 = Marshalling.getJavaType(temp3, temp, 1); + diff += temp4; + } + i = diff; + } else { + Object[] contents = (Object[]) data; + ensureBuffers(contents.length*4); + int diff = i; + for (Object o: contents) + diff = appendone(sigb, i, o); + i = diff; + } + if (Debug.debug) Debug.print(Debug.VERBOSE, "start: "+c+" end: "+bytecounter+" length: "+(bytecounter-c)); + marshallint(bytecounter-c, alen, 0, 4); + break; + case ArgumentType.STRUCT1: + // Structs are aligned to 8 bytes + // and simply contain each element marshalled in order + Object[] contents; + if (data instanceof Container) + contents = ((Container) data).getParameters(); + else + contents = (Object[]) data; + ensureBuffers(contents.length*4); + int j = 0; + for (i++; sigb[i] != ArgumentType.STRUCT2; i++) + i = appendone(sigb, i, contents[j++]); + break; + case ArgumentType.DICT_ENTRY1: + // Dict entries are the same as structs. + if (data instanceof Map.Entry) { + i++; + i = appendone(sigb, i, ((Map.Entry) data).getKey()); + i++; + i = appendone(sigb, i, ((Map.Entry) data).getValue()); + i++; + } else { + contents = (Object[]) data; + j = 0; + for (i++; sigb[i] != ArgumentType.DICT_ENTRY2; i++) + i = appendone(sigb, i, contents[j++]); + } + break; + case ArgumentType.VARIANT: + // Variants are marshalled as a signature + // followed by the value. + if (data instanceof Variant) { + Variant var = (Variant) data; + appendone(new byte[] {ArgumentType.SIGNATURE}, 0, var.getSig()); + appendone((var.getSig()).getBytes(), 0, var.getValue()); + } else if (data instanceof Object[]) { + contents = (Object[]) data; + appendone(new byte[] {ArgumentType.SIGNATURE}, 0, contents[0]); + appendone(((String) contents[0]).getBytes(), 0, contents[1]); + } else { + String sig = Marshalling.getDBusType(data.getClass())[0]; + appendone(new byte[] {ArgumentType.SIGNATURE}, 0, sig); + appendone((sig).getBytes(), 0, data); + } + break; + } + return i; + } catch (ClassCastException CCe) { + CCe.printStackTrace(); // pego + if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, CCe); + throw new MarshallingException(MessageFormat.format(_("Trying to marshall to unconvertable type (from {0} to {1})."), new Object[] { data.getClass().getName(), sigb[sigofs] })); + } + } + /** + * Pad the message to the proper alignment for the given type. + */ + public void pad(byte type) + { + if (Debug.debug) Debug.print(Debug.VERBOSE, "padding for "+(char)type); + int a = getAlignment(type); + if (Debug.debug) Debug.print(Debug.VERBOSE, preallocated+" "+paofs+" "+bytecounter+" "+a); + int b = (int) ((bytecounter-preallocated)%a); + if (0 == b) return; + a = (a-b); + if (preallocated > 0) { + paofs += a; + preallocated -= a; + } else + appendBytes(padding[a]); + if (Debug.debug) Debug.print(Debug.VERBOSE, preallocated+" "+paofs+" "+bytecounter+" "+a); + } + /** + * Return the alignment for a given type. + */ + public static int getAlignment(byte type) + { + switch (type) { + case 2: + case ArgumentType.INT16: + case ArgumentType.UINT16: + return 2; + case 4: + case ArgumentType.BOOLEAN: + case ArgumentType.FLOAT: + case ArgumentType.INT32: + case ArgumentType.UINT32: + case ArgumentType.STRING: + case ArgumentType.OBJECT_PATH: + case ArgumentType.ARRAY: + return 4; + case 8: + case ArgumentType.INT64: + case ArgumentType.UINT64: + case ArgumentType.DOUBLE: + case ArgumentType.STRUCT: + case ArgumentType.DICT_ENTRY: + case ArgumentType.STRUCT1: + case ArgumentType.DICT_ENTRY1: + case ArgumentType.STRUCT2: + case ArgumentType.DICT_ENTRY2: + return 8; + case 1: + case ArgumentType.BYTE: + case ArgumentType.SIGNATURE: + case ArgumentType.VARIANT: + default: + return 1; + } + } + /** + * Append a series of values to the message. + * @param sig The signature(s) of the value(s). + * @param data The value(s). + */ + public void append(String sig, Object... data) throws DBusException + { + if (Debug.debug) Debug.print(Debug.DEBUG, "Appending sig: "+sig+" data: "+Arrays.deepToString(data)); + byte[] sigb = sig.getBytes(); + int j = 0; + for (int i = 0; i < sigb.length; i++) { + if (Debug.debug) Debug.print(Debug.VERBOSE, "Appending item: "+i+" "+((char)sigb[i])+" "+j); + i = appendone(sigb, i, data[j++]); + } + } + /** + * Align a counter to the given type. + * @param current The current counter. + * @param type The type to align to. + * @return The new, aligned, counter. + */ + public int align(int current, byte type) + { + if (Debug.debug) Debug.print(Debug.VERBOSE, "aligning to "+(char)type); + int a = getAlignment(type); + if (0 == (current%a)) return current; + return current+(a-(current%a)); + } + /** + * Demarshall one value from a buffer. + * @param sigb A buffer of the D-Bus signature. + * @param buf The buffer to demarshall from. If null, no data will be read. + * This can be used to skip a part of the signature only, e.g. in + * case of a zero length array. pego + * @param ofs An array of two ints, the offset into the signature buffer + * and the offset into the data buffer. These values will be + * updated to the start of the next value after demarshalling. + * @param contained converts nested arrays to Lists + * @return The demarshalled value. + */ + private Object extractone(byte[] sigb, byte[] buf, int[] ofs, boolean contained) throws DBusException + { + if (Debug.debug) Debug.print(Debug.INFO, "Extracting type: "+((char)sigb[ofs[0]])+" from offset "+ofs[1]); + Object rv = null; + ofs[1] = align(ofs[1], sigb[ofs[0]]); + switch (sigb[ofs[0]]) { + case ArgumentType.BYTE: + if (buf != null) rv = buf[ofs[1]++]; + break; + case ArgumentType.UINT32: + if (buf != null) { + rv = new UInt32(demarshallint(buf, ofs[1], 4)); + ofs[1] += 4; + } + break; + case ArgumentType.INT32: + if (buf != null) { + rv = (int) demarshallint(buf, ofs[1], 4); + ofs[1] += 4; + } + break; + case ArgumentType.INT16: + if (buf != null) { + rv = (short) demarshallint(buf, ofs[1], 2); + ofs[1] += 2; + } + break; + case ArgumentType.UINT16: + if (buf != null) { + rv = new UInt16((int) demarshallint(buf, ofs[1], 2)); + ofs[1] += 2; + } + break; + case ArgumentType.INT64: + if (buf != null) { + rv = demarshallint(buf, ofs[1], 8); + ofs[1] += 8; + } + break; + case ArgumentType.UINT64: + if (buf != null) { + long top; + long bottom; + if (big) { + top = demarshallint(buf, ofs[1], 4); + ofs[1] += 4; + bottom = demarshallint(buf, ofs[1], 4); + } else { + bottom = demarshallint(buf, ofs[1], 4); + ofs[1] += 4; + top = demarshallint(buf, ofs[1], 4); + } + rv = new UInt64(top, bottom); + ofs[1] += 4; + } + break; + case ArgumentType.DOUBLE: + if (buf != null) { + long l = demarshallint(buf, ofs[1], 8); + ofs[1] += 8; + rv = Double.longBitsToDouble(l); + } + break; + case ArgumentType.FLOAT: + if (buf != null) { + int rf = (int) demarshallint(buf, ofs[1], 4); + ofs[1] += 4; + rv = Float.intBitsToFloat(rf); + } + break; + case ArgumentType.BOOLEAN: + if (buf != null) { + int rf = (int) demarshallint(buf, ofs[1], 4); + ofs[1] += 4; + rv = (1==rf)?Boolean.TRUE:Boolean.FALSE; + } + break; + case ArgumentType.ARRAY: + if (buf != null) { + long size = demarshallint(buf, ofs[1], 4); + if (Debug.debug) Debug.print(Debug.INFO, "Reading array of size: "+size); + ofs[1] += 4; + byte algn = (byte) getAlignment(sigb[++ofs[0]]); + ofs[1] = align(ofs[1], sigb[ofs[0]]); + int length = (int) (size / algn); + if (length > DBusConnection.MAX_ARRAY_LENGTH) + throw new MarshallingException(_("Arrays must not exceed ")+DBusConnection.MAX_ARRAY_LENGTH); + // optimise primatives + switch (sigb[ofs[0]]) { + case ArgumentType.BYTE: + rv = new byte[length]; + System.arraycopy(buf, ofs[1], rv, 0, length); + ofs[1] += size; + break; + case ArgumentType.INT16: + rv = new short[length]; + for (int j = 0; j < length; j++, ofs[1] += algn) + ((short[]) rv)[j] = (short) demarshallint(buf, ofs[1], algn); + break; + case ArgumentType.INT32: + rv = new int[length]; + for (int j = 0; j < length; j++, ofs[1] += algn) + ((int[]) rv)[j] = (int) demarshallint(buf, ofs[1], algn); + break; + case ArgumentType.INT64: + rv = new long[length]; + for (int j = 0; j < length; j++, ofs[1] += algn) + ((long[]) rv)[j] = demarshallint(buf, ofs[1], algn); + break; + case ArgumentType.BOOLEAN: + rv = new boolean[length]; + for (int j = 0; j < length; j++, ofs[1] += algn) + ((boolean[]) rv)[j] = (1 == demarshallint(buf, ofs[1], algn)); + break; + case ArgumentType.FLOAT: + rv = new float[length]; + for (int j = 0; j < length; j++, ofs[1] += algn) + ((float[]) rv)[j] = + Float.intBitsToFloat((int)demarshallint(buf, ofs[1], algn)); + break; + case ArgumentType.DOUBLE: + rv = new double[length]; + for (int j = 0; j < length; j++, ofs[1] += algn) + ((double[]) rv)[j] = + Double.longBitsToDouble(demarshallint(buf, ofs[1], algn)); + break; + case ArgumentType.DICT_ENTRY1: +// if (0 == size) { +// // advance the type parser even on 0-size arrays. +// Vector<Type> temp = new Vector<Type>(); +// byte[] temp2 = new byte[sigb.length-ofs[0]]; +// System.arraycopy(sigb, ofs[0], temp2, 0, temp2.length); +// String temp3 = new String(temp2); +// // ofs[0] gets incremented anyway. Leave one character on the stack +// int temp4 = Marshalling.getJavaType(temp3, temp, 1) - 1; +// ofs[0] += temp4; +// if (Debug.debug) Debug.print(Debug.VERBOSE, "Aligned type: "+temp3+" "+temp4+" "+ofs[0]); +// } + Vector<Object[]> entries = new Vector<Object[]>(); + if (size != 0) { + int ofssave = ofs[0]; + long end = ofs[1]+size; + while (ofs[1] < end) { + ofs[0] = ofssave; + entries.add((Object[]) extractone(sigb, buf, ofs, true)); + } + } else { + extractone(sigb, null, ofs, true); + } + rv = new DBusMap<Object, Object>(entries.toArray(new Object[0][])); + break; + default: +// if (0 == size) { +// // advance the type parser even on 0-size arrays. +// Vector<Type> temp = new Vector<Type>(); +// byte[] temp2 = new byte[sigb.length-ofs[0]]; +// System.arraycopy(sigb, ofs[0], temp2, 0, temp2.length); +// String temp3 = new String(temp2); +// // ofs[0] gets incremented anyway. Leave one character on the stack +// int temp4 = Marshalling.getJavaType(temp3, temp, 1) - 1; +// ofs[0] += temp4; +// if (temp3.startsWith("(")) { // pego +// ofs[0]--; +// System.out.println("Zero length array of structs, decrementing ofs[0]"); +// } +// if (Debug.debug) Debug.print(Debug.VERBOSE, "Aligned type: "+temp3+" "+temp4+" "+ofs[0]); +// } + Vector<Object> contents = new Vector<Object>(); + if (size != 0) { + int ofssave = ofs[0]; + long end = ofs[1]+size; + while (ofs[1] < end) { + ofs[0] = ofssave; + contents.add(extractone(sigb, buf, ofs, true)); + } + } else { + extractone(sigb, null, ofs, true); + } + rv = contents; + } + } else { + if (Debug.debug) Debug.print(Debug.INFO, "Skipping array"); + } + if (contained && rv != null && !(rv instanceof List) && !(rv instanceof Map)) + rv = ArrayFrob.listify(rv); + break; + case ArgumentType.STRUCT1: + if (buf != null) { + Vector<Object> contents = new Vector<Object>(); + while (sigb[++ofs[0]] != ArgumentType.STRUCT2) + contents.add(extractone(sigb, buf, ofs, true)); + rv = contents.toArray(); + } else { + while (sigb[++ofs[0]] != ArgumentType.STRUCT2) + extractone(sigb, null, ofs, true); + } + break; + case ArgumentType.DICT_ENTRY1: + if (buf != null) { + Object[] decontents = new Object[2]; + if (Debug.debug) Debug.print(Debug.INFO, "Extracting Dict Entry ("+Hexdump.toAscii(sigb,ofs[0],sigb.length-ofs[0])+") from: "+Hexdump.toHex(buf,ofs[1],buf.length-ofs[1])); + ofs[0]++; + decontents[0] = extractone(sigb, buf, ofs, true); + ofs[0]++; + decontents[1] = extractone(sigb, buf, ofs, true); + ofs[0]++; + rv = decontents; + } else { + if (Debug.debug) Debug.print(Debug.INFO, "Skipping Dict Entry ("+Hexdump.toAscii(sigb,ofs[0],sigb.length-ofs[0])+")"); + ofs[0]++; + extractone(sigb, null, ofs, true); + ofs[0]++; + extractone(sigb, null, ofs, true); + ofs[0]++; + } + break; + case ArgumentType.VARIANT: + if (buf != null) { + int[] newofs = new int[] { 0, ofs[1] }; + String sig = (String) extract(ArgumentType.SIGNATURE_STRING, buf, newofs)[0]; + newofs[0] = 0; + rv = new Variant<Object>(extract(sig, buf, newofs)[0] , sig); + ofs[1] = newofs[1]; + } + break; + case ArgumentType.STRING: + if (buf != null) { + int length = (int) demarshallint(buf, ofs[1], 4); + ofs[1] += 4; + try { + rv = new String(buf, ofs[1], length, "UTF-8"); + } catch (UnsupportedEncodingException UEe) { + UEe.printStackTrace(); // pego + if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug) Debug.print(UEe); + throw new DBusException(_("System does not support UTF-8 encoding")); + } + ofs[1] += length + 1; + } + break; + case ArgumentType.OBJECT_PATH: + if (buf != null) { + int length = (int) demarshallint(buf, ofs[1], 4); + ofs[1] += 4; + rv = new ObjectPath(getSource(), new String(buf, ofs[1], length)); + ofs[1] += length + 1; + } + break; + case ArgumentType.SIGNATURE: + if (buf != null) { + int length = (buf[ofs[1]++] & 0xFF); + rv = new String(buf, ofs[1], length); + ofs[1] += length + 1; + } + break; + default: + throw new UnknownTypeCodeException(sigb[ofs[0]]); + } + if (Debug.debug) if (rv instanceof Object[]) + Debug.print(Debug.INFO, "Extracted: "+Arrays.deepToString((Object[]) rv)+" (now at "+ofs[1]+")"); + else + Debug.print(Debug.INFO, "Extracted: "+rv+" (now at "+ofs[1]+")"); + return rv; + } + /** + * Demarshall values from a buffer. + * @param sig The D-Bus signature(s) of the value(s). + * @param buf The buffer to demarshall from. + * @param ofs The offset into the data buffer to start. + * @return The demarshalled value(s). + */ + public Object[] extract(String sig, byte[] buf, int ofs) throws DBusException + { + return extract(sig, buf, new int[] { 0, ofs }); + } + /** + * Demarshall values from a buffer. + * @param sig The D-Bus signature(s) of the value(s). + * @param buf The buffer to demarshall from. + * @param ofs An array of two ints, the offset into the signature + * and the offset into the data buffer. These values will be + * updated to the start of the next value ofter demarshalling. + * @return The demarshalled value(s). + */ + public Object[] extract(String sig, byte[] buf, int[] ofs) throws DBusException + { + if (Debug.debug) Debug.print(Debug.INFO, "extract("+sig+",#"+buf.length+", {"+ofs[0]+","+ofs[1]+"}"); + Vector<Object> rv = new Vector<Object>(); + byte[] sigb = sig.getBytes(); + for (int[] i = ofs; i[0] < sigb.length; i[0]++) { + rv.add(extractone(sigb, buf, i, false)); + } + return rv.toArray(); + } + /** + * Returns the Bus ID that sent the message. + */ + public String getSource() { return (String) headers.get(HeaderField.SENDER); } + /** + * Returns the destination of the message. + */ + public String getDestination() { return (String) headers.get(HeaderField.DESTINATION); } + /** + * Returns the interface of the message. + */ + public String getInterface() { return (String) headers.get(HeaderField.INTERFACE); } + /** + * Returns the object path of the message. + */ + public String getPath() + { + Object o = headers.get(HeaderField.PATH); + if (null == o) return null; + return o.toString(); + } + /** + * Returns the member name or error name this message represents. + */ + public String getName() + { + if (this instanceof Error) + return (String) headers.get(HeaderField.ERROR_NAME); + else + return (String) headers.get(HeaderField.MEMBER); + } + /** + * Returns the dbus signature of the parameters. + */ + public String getSig() { return (String) headers.get(HeaderField.SIGNATURE); } + /** + * Returns the message flags. + */ + public int getFlags() { return flags; } + /** + * Returns the message serial ID (unique for this connection) + * @return the message serial. + */ + public long getSerial() { return serial; } + /** + * If this is a reply to a message, this returns its serial. + * @return The reply serial, or 0 if it is not a reply. + */ + public long getReplySerial() + { + Number l = (Number) headers.get(HeaderField.REPLY_SERIAL); + if (null == l) return 0; + return l.longValue(); + } + /** + * Parses and returns the parameters to this message as an Object array. + */ + public Object[] getParameters() throws DBusException + { + if (null == args && null != body) { + String sig = (String) headers.get(HeaderField.SIGNATURE); + if (null != sig && 0 != body.length) { + args = extract(sig, body, 0); + } else args = new Object[0]; + } + return args; + } + protected void setArgs(Object[] args) { this.args = args; } + /** + * Warning, do not use this method unless you really know what you are doing. + */ + public void setSource(String source) throws DBusException + { + if (null != body) { + wiredata = new byte[BUFFERINCREMENT][]; + bufferuse = 0; + bytecounter = 0; + preallocate(12); + append("yyyyuu", big ? Endian.BIG : Endian.LITTLE, type, flags, protover, bodylen, serial); + headers.put(HeaderField.SENDER, source); + Object[][] newhead = new Object[headers.size()][]; + int i = 0; + for (Byte b: headers.keySet()) { + newhead[i] = new Object[2]; + newhead[i][0] = b; + newhead[i][1] = headers.get(b); + i++; + } + append("a(yv)", (Object) newhead); + pad((byte) 8); + appendBytes(body); + } + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/MessageReader.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/MessageReader.java new file mode 100755 index 0000000..49c69cd --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/MessageReader.java @@ -0,0 +1,175 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import static org.freedesktop.dbus.Gettext._; + +import java.io.BufferedInputStream; +import java.io.EOFException; +import java.io.InputStream; +import java.io.IOException; +import java.net.SocketTimeoutException; +import java.text.MessageFormat; + +import cx.ath.matthew.debug.Debug; +import cx.ath.matthew.utils.Hexdump; + +import org.freedesktop.dbus.exceptions.DBusException; +import org.freedesktop.dbus.exceptions.MessageTypeException; +import org.freedesktop.dbus.exceptions.MessageProtocolVersionException; + +public class MessageReader +{ + private InputStream in; + private byte[] buf = null; + private byte[] tbuf = null; + private byte[] header = null; + private byte[] body = null; + private int[] len = new int[4]; + public MessageReader(InputStream in) + { + this.in = new BufferedInputStream(in); + } + public Message readMessage() throws IOException, DBusException + { + int rv; + /* Read the 12 byte fixed header, retrying as neccessary */ + if (null == buf) { buf = new byte[12]; len[0] = 0; } + if (len[0] < 12) { + try { rv = in.read(buf, len[0], 12-len[0]); } + catch (SocketTimeoutException STe) { return null; } + if (-1 == rv) throw new EOFException(_("Underlying transport returned EOF")); + len[0] += rv; + } + if (len[0] == 0) return null; + if (len[0] < 12) { + if (Debug.debug) Debug.print(Debug.DEBUG, "Only got "+len[0]+" of 12 bytes of header"); + return null; + } + + /* Parse the details from the header */ + byte endian = buf[0]; + byte type = buf[1]; + byte protover = buf[3]; + if (protover > Message.PROTOCOL) { + buf = null; + throw new MessageProtocolVersionException(MessageFormat.format(_("Protocol version {0} is unsupported"), new Object[] { protover })); + } + + /* Read the length of the variable header */ + if (null == tbuf) { tbuf = new byte[4]; len[1] = 0; } + if (len[1] < 4) { + try { rv = in.read(tbuf, len[1], 4-len[1]); } + catch (SocketTimeoutException STe) { return null; } + if (-1 == rv) throw new EOFException(_("Underlying transport returned EOF")); + len[1] += rv; + } + if (len[1] < 4) { + if (Debug.debug) Debug.print(Debug.DEBUG, "Only got "+len[1]+" of 4 bytes of header"); + return null; + } + + /* Parse the variable header length */ + int headerlen = 0; + if (null == header) { + headerlen = (int) Message.demarshallint(tbuf, 0, endian, 4); + if (0 != headerlen % 8) + headerlen += 8-(headerlen%8); + } else + headerlen = header.length-8; + + /* Read the variable header */ + if (null == header) { + header = new byte[headerlen+8]; + System.arraycopy(tbuf, 0, header, 0, 4); + len[2] = 0; + } + if (len[2] < headerlen) { + try { rv = in.read(header, 8+len[2], headerlen-len[2]); } + catch (SocketTimeoutException STe) { return null; } + if (-1 == rv) throw new EOFException(_("Underlying transport returned EOF")); + len[2] += rv; + } + if (len[2] < headerlen) { + if (Debug.debug) Debug.print(Debug.DEBUG, "Only got "+len[2]+" of "+headerlen+" bytes of header"); + return null; + } + + /* Read the body */ + int bodylen = 0; + if (null == body) bodylen = (int) Message.demarshallint(buf, 4, endian, 4); + if (null == body) { body=new byte[bodylen]; len[3] = 0; } + if (len[3] < body.length) { + try { rv = in.read(body, len[3], body.length-len[3]); } + catch (SocketTimeoutException STe) { return null; } + if (-1 == rv) throw new EOFException(_("Underlying transport returned EOF")); + len[3] += rv; + } + if (len[3] < body.length) { + if (Debug.debug) Debug.print(Debug.DEBUG, "Only got "+len[3]+" of "+body.length+" bytes of body"); + return null; + } + + Message m; + switch (type) { + case Message.MessageType.METHOD_CALL: + m = new MethodCall(); + break; + case Message.MessageType.METHOD_RETURN: + m = new MethodReturn(); + break; + case Message.MessageType.SIGNAL: + m = new DBusSignal(); + break; + case Message.MessageType.ERROR: + m = new Error(); + break; + default: + throw new MessageTypeException(MessageFormat.format(_("Message type {0} unsupported"), new Object[] {type})); + } + if (Debug.debug) { + Debug.print(Debug.VERBOSE, Hexdump.format(buf)); + Debug.print(Debug.VERBOSE, Hexdump.format(tbuf)); + Debug.print(Debug.VERBOSE, Hexdump.format(header)); + Debug.print(Debug.VERBOSE, Hexdump.format(body)); + } + try { + m.populate(buf, header, body); + } catch (DBusException DBe) { + if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, DBe); + buf = null; + tbuf = null; + body = null; + header = null; + throw DBe; + } catch (RuntimeException Re) { + if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, Re); + buf = null; + tbuf = null; + body = null; + header = null; + throw Re; + } + if (Debug.debug) { + Debug.print(Debug.INFO, "=> "+m); + } + buf = null; + tbuf = null; + body = null; + header = null; + return m; + } + public void close() throws IOException + { + if (Debug.debug) Debug.print(Debug.INFO, "Closing Message Reader"); + in.close(); + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/MessageWriter.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/MessageWriter.java new file mode 100755 index 0000000..bb22108 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/MessageWriter.java @@ -0,0 +1,72 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import java.io.BufferedOutputStream; +import java.io.OutputStream; +import java.io.IOException; + +import cx.ath.matthew.debug.Debug; +import cx.ath.matthew.unix.USOutputStream; +import cx.ath.matthew.utils.Hexdump; + +public class MessageWriter +{ + private OutputStream out; + private boolean isunix; + public MessageWriter(OutputStream out) + { + this.out = out; + this.isunix = false; + try { + if (out instanceof USOutputStream) + this.isunix = true; + } catch (Throwable t) { + } + if (!this.isunix) + this.out = new BufferedOutputStream(this.out); + } + public void writeMessage(Message m) throws IOException + { + if (Debug.debug) { + Debug.print(Debug.INFO, "<= "+m); + } + if (null == m) return; + if (Debug.debug) Debug.print(Debug.INFO, "m in not null"); // pego + if (null == m.getWireData()) { + if (Debug.debug) Debug.print(Debug.WARN, "Message "+m+" wire-data was null!"); + return; + } + if (Debug.debug) Debug.print(Debug.INFO, "wire data in not null"); // pego + if (isunix) { + if (Debug.debug) { + Debug.print(Debug.INFO, "Writing all "+m.getWireData().length+" buffers simultaneously to Unix Socket"); + for (byte[] buf: m.getWireData()) + Debug.print(Debug.INFO, "("+buf+"):"+ (null==buf? "": Hexdump.format(buf))); + } + ((USOutputStream) out).write(m.getWireData()); + } else + for (byte[] buf: m.getWireData()) { + if (Debug.debug) + Debug.print(Debug.INFO, "("+buf+"):"+ (null==buf? "": Hexdump.format(buf))); + if (null == buf) break; + out.write(buf); + if (Debug.debug) Debug.print(Debug.INFO, "After write()"); // pego + } + out.flush(); + if (Debug.debug) Debug.print(Debug.INFO, "After flush()"); // pego + } + public void close() throws IOException + { + if (Debug.debug) Debug.print(Debug.INFO, "Closing Message Writer"); + out.close(); + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/MethodCall.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/MethodCall.java new file mode 100755 index 0000000..c10b1b0 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/MethodCall.java @@ -0,0 +1,126 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import static org.freedesktop.dbus.Gettext._; + +import java.util.Vector; +import org.freedesktop.dbus.exceptions.DBusException; +import org.freedesktop.dbus.exceptions.MessageFormatException; +import cx.ath.matthew.debug.Debug; +import cx.ath.matthew.utils.Hexdump; + +public class MethodCall extends Message +{ + MethodCall() { } + public MethodCall(String dest, String path, String iface, String member, byte flags, String sig, Object... args) throws DBusException + { + this(null, dest, path, iface, member, flags, sig, args); + } + public MethodCall(String source, String dest, String path, String iface, String member, byte flags, String sig, Object... args) throws DBusException + { + super(Message.Endian.BIG, Message.MessageType.METHOD_CALL, flags); + + if (null == member || null == path) + throw new MessageFormatException(_("Must specify destination, path and function name to MethodCalls.")); + headers.put(Message.HeaderField.PATH,path); + headers.put(Message.HeaderField.MEMBER,member); + + Vector<Object> hargs = new Vector<Object>(); + + hargs.add(new Object[] { Message.HeaderField.PATH, new Object[] { ArgumentType.OBJECT_PATH_STRING, path } }); + + if (null != source) { + headers.put(Message.HeaderField.SENDER,source); + hargs.add(new Object[] { Message.HeaderField.SENDER, new Object[] { ArgumentType.STRING_STRING, source } }); + } + + if (null != dest) { + headers.put(Message.HeaderField.DESTINATION,dest); + hargs.add(new Object[] { Message.HeaderField.DESTINATION, new Object[] { ArgumentType.STRING_STRING, dest } }); + } + + if (null != iface) { + hargs.add(new Object[] { Message.HeaderField.INTERFACE, new Object[] { ArgumentType.STRING_STRING, iface } }); + headers.put(Message.HeaderField.INTERFACE,iface); + } + + hargs.add(new Object[] { Message.HeaderField.MEMBER, new Object[] { ArgumentType. STRING_STRING, member } }); + + if (null != sig) { + if (Debug.debug) Debug.print(Debug.DEBUG, "Appending arguments with signature: "+sig); + hargs.add(new Object[] { Message.HeaderField.SIGNATURE, new Object[] { ArgumentType.SIGNATURE_STRING, sig } }); + headers.put(Message.HeaderField.SIGNATURE,sig); + setArgs(args); + } + + byte[] blen = new byte[4]; + appendBytes(blen); + append("ua(yv)", serial, hargs.toArray()); + pad((byte)8); + + long c = bytecounter; + if (null != sig) append(sig, args); + if (Debug.debug) Debug.print(Debug.DEBUG, "Appended body, type: "+sig+" start: "+c+" end: "+bytecounter+" size: "+(bytecounter-c)); + marshallint(bytecounter-c, blen, 0, 4); + if (Debug.debug) Debug.print("marshalled size ("+blen+"): "+Hexdump.format(blen)); + } + private static long REPLY_WAIT_TIMEOUT = 20000; + /** + * Set the default timeout for method calls. + * Default is 20s. + * @param timeout New timeout in ms. + */ + public static void setDefaultTimeout(long timeout) + { + REPLY_WAIT_TIMEOUT = timeout; + } + Message reply = null; + public synchronized boolean hasReply() + { + return null != reply; + } + /** + * Block (if neccessary) for a reply. + * @return The reply to this MethodCall, or null if a timeout happens. + * @param timeout The length of time to block before timing out (ms). + */ + public synchronized Message getReply(long timeout) + { + if (Debug.debug) Debug.print(Debug.VERBOSE, "Blocking on "+this); + if (null != reply) return reply; + try { + wait(timeout); + return reply; + } catch (InterruptedException Ie) { return reply; } + } + /** + * Block (if neccessary) for a reply. + * Default timeout is 20s, or can be configured with setDefaultTimeout() + * @return The reply to this MethodCall, or null if a timeout happens. + */ + public synchronized Message getReply() + { + if (Debug.debug) Debug.print(Debug.VERBOSE, "Blocking on "+this); + if (null != reply) return reply; + try { + wait(REPLY_WAIT_TIMEOUT); + return reply; + } catch (InterruptedException Ie) { return reply; } + } + protected synchronized void setReply(Message reply) + { + if (Debug.debug) Debug.print(Debug.VERBOSE, "Setting reply to "+this+" to "+reply); + this.reply = reply; + notifyAll(); + } + +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/MethodReturn.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/MethodReturn.java new file mode 100755 index 0000000..b0f719a --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/MethodReturn.java @@ -0,0 +1,69 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import java.util.Vector; +import org.freedesktop.dbus.exceptions.DBusException; + +public class MethodReturn extends Message +{ + MethodReturn() { } + public MethodReturn(String dest, long replyserial, String sig, Object... args) throws DBusException + { + this(null, dest, replyserial, sig, args); + } + public MethodReturn(String source, String dest, long replyserial, String sig, Object... args) throws DBusException + { + super(Message.Endian.BIG, Message.MessageType.METHOD_RETURN, (byte) 0); + + headers.put(Message.HeaderField.REPLY_SERIAL,replyserial); + + Vector<Object> hargs = new Vector<Object>(); + hargs.add(new Object[] { Message.HeaderField.REPLY_SERIAL, new Object[] { ArgumentType.UINT32_STRING, replyserial } }); + + if (null != source) { + headers.put(Message.HeaderField.SENDER,source); + hargs.add(new Object[] { Message.HeaderField.SENDER, new Object[] { ArgumentType.STRING_STRING, source } }); + } + + if (null != dest) { + headers.put(Message.HeaderField.DESTINATION,dest); + hargs.add(new Object[] { Message.HeaderField.DESTINATION, new Object[] { ArgumentType.STRING_STRING, dest } }); + } + + if (null != sig) { + hargs.add(new Object[] { Message.HeaderField.SIGNATURE, new Object[] { ArgumentType.SIGNATURE_STRING, sig } }); + headers.put(Message.HeaderField.SIGNATURE,sig); + setArgs(args); + } + + byte[] blen = new byte[4]; + appendBytes(blen); + append("ua(yv)", serial, hargs.toArray()); + pad((byte)8); + + long c = bytecounter; + if (null != sig) append(sig, args); + marshallint(bytecounter-c, blen, 0, 4); + } + public MethodReturn(MethodCall mc, String sig, Object... args) throws DBusException + { + this(null, mc, sig, args); + } + public MethodReturn(String source, MethodCall mc, String sig, Object... args) throws DBusException + { + this(source, mc.getSource(), mc.getSerial(), sig, args); + this.call = mc; + } + MethodCall call; + public MethodCall getCall() { return call; } + protected void setCall(MethodCall call) { this.call = call; } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/MethodTuple.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/MethodTuple.java new file mode 100755 index 0000000..dd2c4a9 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/MethodTuple.java @@ -0,0 +1,38 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import cx.ath.matthew.debug.Debug; + +class MethodTuple +{ + String name; + String sig; + public MethodTuple(String name, String sig) + { + this.name = name; + if (null != sig) + this.sig = sig; + else + this.sig = ""; + if (Debug.debug) Debug.print(Debug.VERBOSE, "new MethodTuple("+this.name+", "+this.sig+")"); + } + public boolean equals(Object o) + { + return o.getClass().equals(MethodTuple.class) + && ((MethodTuple) o).name.equals(this.name) + && ((MethodTuple) o).sig.equals(this.sig); + } + public int hashCode() + { + return name.hashCode()+sig.hashCode(); + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/ObjectPath.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/ObjectPath.java new file mode 100755 index 0000000..409d26d --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/ObjectPath.java @@ -0,0 +1,23 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +class ObjectPath extends Path +{ + public String source; +// public DBusConnection conn; + public ObjectPath(String source, String path/*, DBusConnection conn*/) + { + super(path); + this.source = source; + // this.conn = conn; + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/ObjectTree.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/ObjectTree.java new file mode 100755 index 0000000..f7d0591 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/ObjectTree.java @@ -0,0 +1,163 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import cx.ath.matthew.debug.Debug; + +import java.util.regex.Pattern; + +/** + * Keeps track of the exported objects for introspection data */ +class ObjectTree +{ + class TreeNode + { + String name; + ExportedObject object; + String data; + TreeNode right; + TreeNode down; + public TreeNode(String name) + { + this.name = name; + } + public TreeNode(String name, ExportedObject object, String data) + { + this.name = name; + this.object = object; + this.data = data; + } + } + private TreeNode root; + public ObjectTree() + { + root = new TreeNode(""); + } + public static final Pattern slashpattern = Pattern.compile("/"); + + private TreeNode recursiveFind(TreeNode current, String path) + { + if ("/".equals(path)) return current; + String[] elements = path.split("/", 2); + // this is us or a parent node + if (path.startsWith(current.name)) { + // this is us + if (path.equals(current.name)) { + return current; + } + // recurse down + else { + if (current.down == null) + return null; + else return recursiveFind(current.down, elements[1]); + } + } + else if (current.right == null) { + return null; + } + else if (0 > current.right.name.compareTo(elements[0])) { + return null; + } + // recurse right + else { + return recursiveFind(current.right, path); + } + } + private TreeNode recursiveAdd(TreeNode current, String path, ExportedObject object, String data) + { + String[] elements = slashpattern.split(path, 2); + // this is us or a parent node + if (path.startsWith(current.name)) { + // this is us + if (1 == elements.length || "".equals(elements[1])) { + current.object = object; + current.data = data; + } + // recurse down + else { + if (current.down == null) { + String[] el = elements[1].split("/", 2); + current.down = new TreeNode(el[0]); + } + current.down = recursiveAdd(current.down, elements[1], object, data); + } + } + // need to create a new sub-tree on the end + else if (current.right == null) { + current.right = new TreeNode(elements[0]); + current.right = recursiveAdd(current.right, path, object, data); + } + // need to insert here + else if (0 > current.right.name.compareTo(elements[0])) { + TreeNode t = new TreeNode(elements[0]); + t.right = current.right; + current.right = t; + current.right = recursiveAdd(current.right, path, object, data); + } + // recurse right + else { + current.right = recursiveAdd(current.right, path, object, data); + } + return current; + } + public void add(String path, ExportedObject object, String data) + { + if (Debug.debug) Debug.print(Debug.DEBUG, "Adding "+path+" to object tree"); + root = recursiveAdd(root, path, object, data); + } + public void remove(String path) + { + if (Debug.debug) Debug.print(Debug.DEBUG, "Removing "+path+" from object tree"); + TreeNode t = recursiveFind(root, path); + t.object = null; + t.data = null; + } + + public String Introspect(String path) + { + TreeNode t = recursiveFind(root, path); + if (null == t) return null; + StringBuilder sb = new StringBuilder(); + sb.append("<node name=\""); + sb.append(path); + sb.append("\">\n"); + if (null != t.data) sb.append(t.data); + t = t.down; + while (null != t) { + sb.append("<node name=\""); + sb.append(t.name); + sb.append("\"/>\n"); + t = t.right; + } + sb.append("</node>"); + return sb.toString(); + } + + private String recursivePrint(TreeNode current) + { + String s = ""; + if (null != current) { + s += current.name; + if (null != current.object) + s += "*"; + if (null != current.down) + s += "/{"+recursivePrint(current.down)+"}"; + if (null != current.right) + s += ", "+recursivePrint(current.right); + } + return s; + } + + public String toString() + { + return recursivePrint(root); + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Path.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Path.java new file mode 100755 index 0000000..baaa7a6 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Path.java @@ -0,0 +1,40 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +public class Path implements Comparable<Path> +{ + protected String path; + public Path(String path) + { + this.path = path; + } + public String getPath() + { + return path; + } + public String toString() + { + return path; + } + public boolean equals(Object other) + { + return (other instanceof Path) && path.equals(((Path) other).path); + } + public int hashCode() + { + return path.hashCode(); + } + public int compareTo(Path that) + { + return path.compareTo(that.path); + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Position.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Position.java new file mode 100755 index 0000000..45e68d8 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Position.java @@ -0,0 +1,28 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Position annotation, to annotate Struct fields + * to be sent over DBus. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface Position +{ + /** The order of this field in the Struct. */ + int value(); +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/RemoteInvocationHandler.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/RemoteInvocationHandler.java new file mode 100755 index 0000000..9e40495 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/RemoteInvocationHandler.java @@ -0,0 +1,191 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import static org.freedesktop.dbus.Gettext._; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.lang.reflect.Type; +import java.text.MessageFormat; +import java.util.Arrays; + +import org.freedesktop.DBus; +import org.freedesktop.dbus.exceptions.DBusException; +import org.freedesktop.dbus.exceptions.DBusExecutionException; +import org.freedesktop.dbus.exceptions.NotConnected; + +import cx.ath.matthew.debug.Debug; + +class RemoteInvocationHandler implements InvocationHandler +{ + public static final int CALL_TYPE_SYNC = 0; + public static final int CALL_TYPE_ASYNC = 1; + public static final int CALL_TYPE_CALLBACK = 2; + public static Object convertRV(String sig, Object[] rp, Method m, AbstractConnection conn) throws DBusException + { + Class<? extends Object> c = m.getReturnType(); + + if (null == rp) { + if(null == c || Void.TYPE.equals(c)) return null; + else throw new DBusExecutionException(_("Wrong return type (got void, expected a value)")); + } else { + try { + if (Debug.debug) Debug.print(Debug.VERBOSE, "Converting return parameters from "+Arrays.deepToString(rp)+" to type "+m.getGenericReturnType()); + rp = Marshalling.deSerializeParameters(rp, + new Type[] { m.getGenericReturnType() }, conn); + } + catch (Exception e) { + if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, e); + throw new DBusExecutionException(MessageFormat.format(_("Wrong return type (failed to de-serialize correct types: {0} )"), new Object[] { e.getMessage() })); + } + } + + switch (rp.length) { + case 0: + if (null == c || Void.TYPE.equals(c)) + return null; + else throw new DBusExecutionException(_("Wrong return type (got void, expected a value)")); + case 1: + return rp[0]; + default: + + // check we are meant to return multiple values + if (!Tuple.class.isAssignableFrom(c)) + throw new DBusExecutionException(_("Wrong return type (not expecting Tuple)")); + + Constructor<? extends Object> cons = c.getConstructors()[0]; + try { + return cons.newInstance(rp); + } catch (Exception e) { + if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, e); + throw new DBusException(e.getMessage()); + } + } + } + @SuppressWarnings("unchecked") + public static Object executeRemoteMethod(RemoteObject ro, Method m, AbstractConnection conn, int syncmethod, CallbackHandler callback, Object... args) throws DBusExecutionException + { + Type[] ts = m.getGenericParameterTypes(); + String sig = null; + if (ts.length > 0) try { + sig = Marshalling.getDBusType(ts); + args = Marshalling.convertParameters(args, ts, conn); + } catch (DBusException DBe) { + throw new DBusExecutionException(_("Failed to construct D-Bus type: ")+DBe.getMessage()); + } + MethodCall call; + byte flags = 0; + if (!ro.autostart) flags |= Message.Flags.NO_AUTO_START; + if (syncmethod == CALL_TYPE_ASYNC) flags |= Message.Flags.ASYNC; + if (m.isAnnotationPresent(DBus.Method.NoReply.class)) flags |= Message.Flags.NO_REPLY_EXPECTED; + try { + String name; + if (m.isAnnotationPresent(DBusMemberName.class)) + name = m.getAnnotation(DBusMemberName.class).value(); + else + name = m.getName(); + if (null == ro.iface) + call = new MethodCall(ro.busname, ro.objectpath, null, name,flags, sig, args); + else { + if (null != ro.iface.getAnnotation(DBusInterfaceName.class)) { + call = new MethodCall(ro.busname, ro.objectpath, ro.iface.getAnnotation(DBusInterfaceName.class).value(), name, flags, sig, args); + } else + call = new MethodCall(ro.busname, ro.objectpath, AbstractConnection.dollar_pattern.matcher(ro.iface.getName()).replaceAll("."), name, flags, sig, args); + } + } catch (DBusException DBe) { + if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, DBe); + throw new DBusExecutionException(_("Failed to construct outgoing method call: ")+DBe.getMessage()); + } + if (null == conn.outgoing) throw new NotConnected(_("Not Connected")); + + switch (syncmethod) { + case CALL_TYPE_ASYNC: + conn.queueOutgoing(call); + return new DBusAsyncReply(call, m, conn); + case CALL_TYPE_CALLBACK: + synchronized (conn.pendingCallbacks) { + if (Debug.debug) Debug.print(Debug.VERBOSE, "Queueing Callback "+callback+" for "+call); + conn.pendingCallbacks.put(call, callback); + conn.pendingCallbackReplys.put(call, new DBusAsyncReply(call, m, conn)); + } + conn.queueOutgoing(call); + return null; + case CALL_TYPE_SYNC: + conn.queueOutgoing(call); + break; + } + + // get reply + if (m.isAnnotationPresent(DBus.Method.NoReply.class)) return null; + + Message reply = call.getReply(); + if (null == reply) throw new DBus.Error.NoReply(_("No reply within specified time")); + + if (reply instanceof Error) + ((Error) reply).throwException(); + + try { + return convertRV(reply.getSig(), reply.getParameters(), m, conn); + } catch (DBusException e) { + if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, e); + throw new DBusExecutionException(e.getMessage()); + } + } + + AbstractConnection conn; + RemoteObject remote; + public RemoteInvocationHandler(AbstractConnection conn, RemoteObject remote) + { + this.remote = remote; + this.conn = conn; + } + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable + { + if (method.getName().equals("isRemote")) return true; + else if (method.getName().equals("clone")) return null; + else if (method.getName().equals("equals")) { + try { + if (1 == args.length) + return new Boolean(remote.equals(((RemoteInvocationHandler) Proxy.getInvocationHandler(args[0])).remote)); + } catch (IllegalArgumentException IAe) { + return Boolean.FALSE; + } + } + else if (method.getName().equals("finalize")) return null; + else if (method.getName().equals("getClass")) return DBusInterface.class; + else if (method.getName().equals("hashCode")) return remote.hashCode(); + else if (method.getName().equals("notify")) { + remote.notify(); + return null; + } else if (method.getName().equals("notifyAll")) { + remote.notifyAll(); + return null; + } else if (method.getName().equals("wait")) { + if (0 == args.length) remote.wait(); + else if (1 == args.length + && args[0] instanceof Long) remote.wait((Long) args[0]); + else if (2 == args.length + && args[0] instanceof Long + && args[1] instanceof Integer) + remote.wait((Long) args[0], (Integer) args[1]); + if (args.length <= 2) + return null; + } + else if (method.getName().equals("toString")) + return remote.toString(); + + return executeRemoteMethod(remote, method, conn, CALL_TYPE_SYNC, null, args); + } +} + diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/RemoteObject.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/RemoteObject.java new file mode 100755 index 0000000..8a1f620 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/RemoteObject.java @@ -0,0 +1,56 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +class RemoteObject +{ + String busname; + String objectpath; + Class<? extends DBusInterface> iface; + boolean autostart; + public RemoteObject(String busname, String objectpath, Class<? extends DBusInterface> iface, boolean autostart) + { + this.busname = busname; + this.objectpath = objectpath; + this.iface = iface; + this.autostart = autostart; + } + public boolean equals(Object o) + { + if (!(o instanceof RemoteObject)) return false; + RemoteObject them = (RemoteObject) o; + + if (!them.objectpath.equals(this.objectpath)) return false; + + if (null == this.busname && null != them.busname) return false; + if (null != this.busname && null == them.busname) return false; + if (null != them.busname && !them.busname.equals(this.busname)) return false; + + if (null == this.iface && null != them.iface) return false; + if (null != this.iface && null == them.iface) return false; + if (null != them.iface && !them.iface.equals(this.iface)) return false; + + return true; + } + public int hashCode() + { + return (null == busname ? 0 : busname.hashCode()) + objectpath.hashCode() + + (null == iface ? 0 : iface.hashCode()); + } + public boolean autoStarting() { return autostart; } + public String getBusName() { return busname; } + public String getObjectPath() { return objectpath; } + public Class<? extends DBusInterface> getInterface() { return iface; } + public String toString() + { + return busname+":"+objectpath+":"+iface; + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/SignalTuple.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/SignalTuple.java new file mode 100755 index 0000000..94cadee --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/SignalTuple.java @@ -0,0 +1,51 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; +class SignalTuple +{ + String type; + String name; + String object; + String source; + public SignalTuple(String type, String name, String object, String source) + { + this.type = type; + this.name = name; + this.object = object; + this.source = source; + } + public boolean equals(Object o) + { + if (!(o instanceof SignalTuple)) return false; + SignalTuple other = (SignalTuple) o; + if (null == this.type && null != other.type) return false; + if (null != this.type && !this.type.equals(other.type)) return false; + if (null == this.name && null != other.name) return false; + if (null != this.name && !this.name.equals(other.name)) return false; + if (null == this.object && null != other.object) return false; + if (null != this.object && !this.object.equals(other.object)) return false; + if (null == this.source && null != other.source) return false; + if (null != this.source && !this.source.equals(other.source)) return false; + return true; + } + public int hashCode() + { + return (null == type ? 0 : type.hashCode()) + + (null == name ? 0 : name.hashCode()) + + (null == source ? 0 : source.hashCode()) + + (null == object ? 0 : object.hashCode()); + } + public String toString() + { + return "SignalTuple("+type+","+name+","+object+","+source+")"; + } +} + diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/StrongReference.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/StrongReference.java new file mode 100755 index 0000000..c4d142d --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/StrongReference.java @@ -0,0 +1,43 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import java.lang.ref.WeakReference; + +/** + * An alternative to a WeakReference when you don't want + * that behaviour. + */ +public class StrongReference<T> extends WeakReference<T> +{ + T referant; + public StrongReference(T referant) + { + super(referant); + this.referant = referant; + } + public void clear() + { + referant = null; + } + public boolean enqueue() + { + return false; + } + public T get() + { + return referant; + } + public boolean isEnqueued() + { + return false; + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Struct.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Struct.java new file mode 100755 index 0000000..7d37ed0 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Struct.java @@ -0,0 +1,23 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +/** + * This class should be extended to create Structs. + * Any such class may be sent over DBus to a method which takes a Struct. + * All fields in the Struct which you wish to be serialized and sent to the + * remote method should be annotated with the org.freedesktop.dbus.Position + * annotation, in the order they should appear in to Struct to DBus. + */ +public abstract class Struct extends Container +{ + public Struct() {} +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Transport.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Transport.java new file mode 100755 index 0000000..ccde1e9 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Transport.java @@ -0,0 +1,825 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import static org.freedesktop.dbus.Gettext._; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.lang.reflect.Method; +import java.net.InetSocketAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.text.ParseException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.text.Collator; +import java.util.Arrays; +import java.util.Random; +import java.util.Vector; +import cx.ath.matthew.unix.UnixSocket; +import cx.ath.matthew.unix.UnixServerSocket; +import cx.ath.matthew.unix.UnixSocketAddress; +import cx.ath.matthew.utils.Hexdump; +import cx.ath.matthew.debug.Debug; + +public class Transport +{ + public static class SASL + { + public static class Command + { + private int command; + private int mechs; + private String data; + private String response; + public Command() + { + } + public Command(String s) throws IOException + { + String[] ss = s.split(" "); + if (Debug.debug) Debug.print(Debug.VERBOSE, "Creating command from: "+Arrays.toString(ss)); + if (0 == col.compare(ss[0], "OK")) { + command = COMMAND_OK; + data = ss[1]; + } else if (0 == col.compare(ss[0], "AUTH")) { + command = COMMAND_AUTH; + if (ss.length > 1) { + if (0 == col.compare(ss[1], "EXTERNAL")) + mechs = AUTH_EXTERNAL; + else if (0 == col.compare(ss[1], "DBUS_COOKIE_SHA1")) + mechs = AUTH_SHA; + else if (0 == col.compare(ss[1], "ANONYMOUS")) + mechs = AUTH_ANON; + } + if (ss.length > 2) + data = ss[2]; + } else if (0 == col.compare(ss[0], "DATA")) { + command = COMMAND_DATA; + data = ss[1]; + } else if (0 == col.compare(ss[0], "REJECTED")) { + command = COMMAND_REJECTED; + for (int i = 1; i < ss.length; i++) + if (0 == col.compare(ss[i], "EXTERNAL")) + mechs |= AUTH_EXTERNAL; + else if (0 == col.compare(ss[i], "DBUS_COOKIE_SHA1")) + mechs |= AUTH_SHA; + else if (0 == col.compare(ss[i], "ANONYMOUS")) + mechs |= AUTH_ANON; + } else if (0 == col.compare(ss[0], "BEGIN")) { + command = COMMAND_BEGIN; + } else if (0 == col.compare(ss[0], "CANCEL")) { + command = COMMAND_CANCEL; + } else if (0 == col.compare(ss[0], "ERROR")) { + command = COMMAND_ERROR; + data = ss[1]; + } else { + throw new IOException(_("Invalid Command ")+ss[0]); + } + if (Debug.debug) Debug.print(Debug.VERBOSE, "Created command: "+this); + } + public int getCommand() { return command; } + public int getMechs() { return mechs; } + public String getData() { return data; } + public String getResponse() { return response; } + public void setResponse(String s) { response = s; } + public String toString() + { + return "Command("+command+", "+mechs+", "+data+", "+null+")"; + } + } + private static Collator col = Collator.getInstance(); + static { + col.setDecomposition(Collator.FULL_DECOMPOSITION); + col.setStrength(Collator.PRIMARY); + } + public static final int LOCK_TIMEOUT = 1000; + public static final int NEW_KEY_TIMEOUT_SECONDS = 60 * 5; + public static final int EXPIRE_KEYS_TIMEOUT_SECONDS = NEW_KEY_TIMEOUT_SECONDS + (60 * 2); + public static final int MAX_TIME_TRAVEL_SECONDS = 60 * 5; + public static final int COOKIE_TIMEOUT = 240; + public static final String COOKIE_CONTEXT = "org_freedesktop_java"; + + private String findCookie(String context, String ID) throws IOException + { + String homedir = System.getProperty("user.home"); + File f = new File(homedir+"/.dbus-keyrings/"+context); + BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(f))); + String s = null; + String cookie = null; + long now = System.currentTimeMillis()/1000; + while (null != (s = r.readLine())) { + String[] line = s.split(" "); + long timestamp = Long.parseLong(line[1]); + if (line[0].equals(ID) && (! (timestamp < 0 || + (now + MAX_TIME_TRAVEL_SECONDS) < timestamp || + (now - EXPIRE_KEYS_TIMEOUT_SECONDS) > timestamp))) { + cookie = line[2]; + break; + } + } + r.close(); + return cookie; + } + private void addCookie(String context, String ID, long timestamp, String cookie) throws IOException + { + String homedir = System.getProperty("user.home"); + File keydir = new File(homedir+"/.dbus-keyrings/"); + File cookiefile = new File(homedir+"/.dbus-keyrings/"+context); + File lock = new File(homedir+"/.dbus-keyrings/"+context+".lock"); + File temp = new File(homedir+"/.dbus-keyrings/"+context+".temp"); + + // ensure directory exists + if (!keydir.exists()) keydir.mkdirs(); + + // acquire lock + long start = System.currentTimeMillis(); + while (!lock.createNewFile() && LOCK_TIMEOUT > (System.currentTimeMillis()-start)); + + // read old file + Vector<String> lines = new Vector<String>(); + if (cookiefile.exists()) { + BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(cookiefile))); + String s = null; + while (null != (s = r.readLine())) { + String[] line = s.split(" "); + long time = Long.parseLong(line[1]); + // expire stale cookies + if ((timestamp - time) < COOKIE_TIMEOUT) + lines.add(s); + } + r.close(); + } + + // add cookie + lines.add(ID+" "+timestamp+" "+cookie); + + // write temp file + PrintWriter w = new PrintWriter(new FileOutputStream(temp)); + for (String l: lines) + w.println(l); + w.close(); + + // atomically move to old file + if (!temp.renameTo(cookiefile)) { + cookiefile.delete(); + temp.renameTo(cookiefile); + } + + // remove lock + lock.delete(); + } + /** + * Takes the string, encodes it as hex and then turns it into a string again. + * No, I don't know why either. + */ + private String stupidlyEncode(String data) + { + return Hexdump.toHex(data.getBytes()).replaceAll(" ",""); + } + private String stupidlyEncode(byte[] data) + { + return Hexdump.toHex(data).replaceAll(" ",""); + } + private byte getNibble(char c) + { + switch (c) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + return (byte) (c-'0'); + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + return (byte) (c-'A'+10); + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + return (byte) (c-'a'+10); + default: + return 0; + } + } + private String stupidlyDecode(String data) + { + char[] cs = new char[data.length()]; + char[] res = new char[cs.length/2]; + data.getChars(0, data.length(), cs, 0); + for (int i = 0, j = 0; j < res.length; i += 2, j++) { + int b = 0; + b |= getNibble(cs[i])<<4; + b |= getNibble(cs[i+1]); + res[j] = (char) b; + } + return new String(res); + } + + public static final int MODE_SERVER=1; + public static final int MODE_CLIENT=2; + + public static final int AUTH_NONE=0; + public static final int AUTH_EXTERNAL=1; + public static final int AUTH_SHA=2; + public static final int AUTH_ANON=4; + + public static final int COMMAND_AUTH=1; + public static final int COMMAND_DATA=2; + public static final int COMMAND_REJECTED=3; + public static final int COMMAND_OK=4; + public static final int COMMAND_BEGIN=5; + public static final int COMMAND_CANCEL=6; + public static final int COMMAND_ERROR=7; + + public static final int INITIAL_STATE=0; + public static final int WAIT_DATA=1; + public static final int WAIT_OK=2; + public static final int WAIT_REJECT=3; + public static final int WAIT_AUTH=4; + public static final int WAIT_BEGIN=5; + public static final int AUTHENTICATED=6; + public static final int FAILED=7; + + public static final int OK=1; + public static final int CONTINUE=2; + public static final int ERROR=3; + public static final int REJECT=4; + + public Command receive(InputStream s) throws IOException + { + StringBuffer sb = new StringBuffer(); + top: while (true) { + int c = s.read(); + switch (c) { + case -1: + throw new IOException("Stream unexpectedly short (broken pipe)"); + case 0: + case '\r': + continue; + case '\n': + break top; + default: + sb.append((char) c); + } + } + if (Debug.debug) Debug.print(Debug.VERBOSE, "received: "+sb); + try { + return new Command(sb.toString()); + } catch (Exception e) { + if (Debug.debug && AbstractConnection.EXCEPTION_DEBUG) Debug.print(Debug.ERR, e); + return new Command(); + } + } + public void send(OutputStream out, int command, String... data) throws IOException + { + StringBuffer sb = new StringBuffer(); + switch (command) { + case COMMAND_AUTH: + sb.append("AUTH"); + break; + case COMMAND_DATA: + sb.append("DATA"); + break; + case COMMAND_REJECTED: + sb.append("REJECTED"); + break; + case COMMAND_OK: + sb.append("OK"); + break; + case COMMAND_BEGIN: + sb.append("BEGIN"); + break; + case COMMAND_CANCEL: + sb.append("CANCEL"); + break; + case COMMAND_ERROR: + sb.append("ERROR"); + break; + default: + return; + } + for (String s: data) { + sb.append(' '); + sb.append(s); + } + sb.append('\r'); + sb.append('\n'); + if (Debug.debug) Debug.print(Debug.VERBOSE, "sending: "+sb); + out.write(sb.toString().getBytes()); + } + public int do_challenge(int auth, Command c) throws IOException + { + switch (auth) { + case AUTH_SHA: + String[] reply=stupidlyDecode(c.getData()).split(" "); + if (Debug.debug) Debug.print(Debug.VERBOSE, Arrays.toString(reply)); + if (3 != reply.length) { + if (Debug.debug) Debug.print(Debug.DEBUG, "Reply is not length 3"); + return ERROR; + } + String context = reply[0]; + String ID = reply[1]; + String serverchallenge = reply[2]; + MessageDigest md = null; + try { + md = MessageDigest.getInstance("SHA"); + } catch (NoSuchAlgorithmException NSAe) { + if (Debug.debug && AbstractConnection.EXCEPTION_DEBUG) Debug.print(Debug.ERR, NSAe); + return ERROR; + } + byte[] buf = new byte[8]; + Message.marshallintBig(System.currentTimeMillis(), buf, 0, 8); + String clientchallenge = stupidlyEncode(md.digest(buf)); + md.reset(); + long start = System.currentTimeMillis(); + String cookie = null; + while (null == cookie && (System.currentTimeMillis()-start) < LOCK_TIMEOUT) + cookie = findCookie(context, ID); + if (null == cookie) { + if (Debug.debug) Debug.print(Debug.DEBUG, "Did not find a cookie in context "+context+" with ID "+ID); + return ERROR; + } + String response = serverchallenge+":"+clientchallenge+":"+cookie; + buf = md.digest(response.getBytes()); + if (Debug.debug) Debug.print(Debug.VERBOSE, "Response: "+response+" hash: "+Hexdump.format(buf)); + response = stupidlyEncode(buf); + c.setResponse(stupidlyEncode(clientchallenge+" "+response)); + return OK; + default: + if (Debug.debug) Debug.print(Debug.DEBUG, "Not DBUS_COOKIE_SHA1 authtype."); + return ERROR; + } + } + public String challenge = ""; + public String cookie = ""; + public int do_response(int auth, String Uid, String kernelUid, Command c) + { + MessageDigest md = null; + try { + md = MessageDigest.getInstance("SHA"); + } catch (NoSuchAlgorithmException NSAe) { + if (Debug.debug && AbstractConnection.EXCEPTION_DEBUG) Debug.print(Debug.ERR, NSAe); + return ERROR; + } + switch (auth) { + case AUTH_NONE: + switch (c.getMechs()) { + case AUTH_ANON: + return OK; + case AUTH_EXTERNAL: + if (0 == col.compare(Uid, c.getData()) && + (null == kernelUid || 0 == col.compare(Uid, kernelUid))) + return OK; + else + return ERROR; + case AUTH_SHA: + String context = COOKIE_CONTEXT; + long id = System.currentTimeMillis(); + byte[] buf = new byte[8]; + Message.marshallintBig(id, buf, 0, 8); + challenge = stupidlyEncode(md.digest(buf)); + Random r = new Random(); + r.nextBytes(buf); + cookie = stupidlyEncode(md.digest(buf)); + try { addCookie(context, ""+id, id/1000, cookie); + } catch (IOException IOe) { + if (Debug.debug && AbstractConnection.EXCEPTION_DEBUG) Debug.print(Debug.ERR, IOe); + } + if (Debug.debug) Debug.print(Debug.DEBUG, "Sending challenge: "+context+' '+id+' '+challenge); + c.setResponse(stupidlyEncode(context+' '+id+' '+challenge)); + return CONTINUE; + default: + return ERROR; + } + case AUTH_SHA: + String[] response = stupidlyDecode(c.getData()).split(" "); + if (response.length < 2) return ERROR; + String cchal = response[0]; + String hash = response[1]; + String prehash = challenge+":"+cchal+":"+cookie; + byte[] buf = md.digest(prehash.getBytes()); + String posthash = stupidlyEncode(buf); + if (Debug.debug) Debug.print(Debug.DEBUG, "Authenticating Hash; data="+prehash+" remote hash="+hash+" local hash="+posthash); + if (0 == col.compare(posthash, hash)) + return OK; + else + return ERROR; + default: + return ERROR; + } + } + public String[] getTypes(int types) + { + switch (types) { + case AUTH_EXTERNAL: + return new String[] { "EXTERNAL" }; + case AUTH_SHA: + return new String[] { "DBUS_COOKIE_SHA1" }; + case AUTH_ANON: + return new String[] { "ANONYMOUS" }; + case AUTH_SHA+AUTH_EXTERNAL: + return new String[] { "EXTERNAL", "DBUS_COOKIE_SHA1" }; + case AUTH_SHA+AUTH_ANON: + return new String[] { "ANONYMOUS", "DBUS_COOKIE_SHA1" }; + case AUTH_EXTERNAL+AUTH_ANON: + return new String[] { "ANONYMOUS", "EXTERNAL" }; + case AUTH_EXTERNAL+AUTH_ANON+AUTH_SHA: + return new String[] { "ANONYMOUS", "EXTERNAL", "DBUS_COOKIE_SHA1" }; + default: + return new String[] { }; + } + } + /** + * performs SASL auth on the given streams. + * Mode selects whether to run as a SASL server or client. + * Types is a bitmask of the available auth types. + * Returns true if the auth was successful and false if it failed. + */ + @SuppressWarnings("unchecked") + public boolean auth(int mode, int types, String guid, OutputStream out, InputStream in, UnixSocket us) throws IOException + { + String username = System.getProperty("user.name"); + String Uid = null; + String kernelUid = null; + try { + Class c = Class.forName("com.sun.security.auth.module.UnixSystem"); + Method m = c.getMethod("getUid"); + Object o = c.newInstance(); + long uid = (Long) m.invoke(o); + Uid = stupidlyEncode(""+uid); + } catch (Exception e) { + Uid = stupidlyEncode(username); + } + Command c; + int failed = 0; + int current = 0; + int state = INITIAL_STATE; + + while (state != AUTHENTICATED && state != FAILED) { + if (Debug.debug) Debug.print(Debug.VERBOSE, "AUTH state: "+state); + switch (mode) { + case MODE_CLIENT: + switch (state) { + case INITIAL_STATE: + if (null == us) + out.write(new byte[] { 0 }); + else + us.sendCredentialByte((byte) 0); + send(out, COMMAND_AUTH); + state = WAIT_DATA; + break; + case WAIT_DATA: + c = receive(in); + switch (c.getCommand()) { + case COMMAND_DATA: + switch (do_challenge(current, c)) { + case CONTINUE: + send(out, COMMAND_DATA, c.getResponse()); + break; + case OK: + send(out, COMMAND_DATA, c.getResponse()); + state = WAIT_OK; + break; + case ERROR: + send(out, COMMAND_ERROR, c.getResponse()); + break; + } + break; + case COMMAND_REJECTED: + failed |= current; + int available = c.getMechs() & (~failed); + if (0 != (available & AUTH_EXTERNAL)){ + send(out, COMMAND_AUTH, "EXTERNAL", Uid); + current = AUTH_EXTERNAL; + } else if (0 != (available & AUTH_SHA)) { + send(out, COMMAND_AUTH, "DBUS_COOKIE_SHA1", Uid); + current = AUTH_SHA; + } else if (0 != (available & AUTH_ANON)) { + send(out, COMMAND_AUTH, "ANONYMOUS"); + current = AUTH_ANON; + } + else state = FAILED; + break; + case COMMAND_ERROR: + send(out, COMMAND_CANCEL); + state = WAIT_REJECT; + break; + case COMMAND_OK: + send(out, COMMAND_BEGIN); + state = AUTHENTICATED; + break; + default: + send(out, COMMAND_ERROR, "Got invalid command"); + break; + } + break; + case WAIT_OK: + c = receive(in); + switch (c.getCommand()) { + case COMMAND_OK: + send(out, COMMAND_BEGIN); + state = AUTHENTICATED; + break; + case COMMAND_ERROR: + case COMMAND_DATA: + send(out, COMMAND_CANCEL); + state = WAIT_REJECT; + break; + case COMMAND_REJECTED: + failed |= current; + int available = c.getMechs() & (~failed); + state = WAIT_DATA; + if (0 != (available & AUTH_EXTERNAL)) { + send(out, COMMAND_AUTH, "EXTERNAL", Uid); + current = AUTH_EXTERNAL; + } else if (0 != (available & AUTH_SHA)) { + send(out, COMMAND_AUTH, "DBUS_COOKIE_SHA1", Uid); + current = AUTH_SHA; + } else if (0 != (available & AUTH_ANON)) { + send(out, COMMAND_AUTH, "ANONYMOUS"); + current = AUTH_ANON; + } + else state = FAILED; + break; + default: + send(out, COMMAND_ERROR, "Got invalid command"); + break; + } + break; + case WAIT_REJECT: + c = receive(in); + switch (c.getCommand()) { + case COMMAND_REJECTED: + failed |= current; + int available = c.getMechs() & (~failed); + if (0 != (available & AUTH_EXTERNAL)) { + send(out, COMMAND_AUTH, "EXTERNAL", Uid); + current = AUTH_EXTERNAL; + } else if (0 != (available & AUTH_SHA)) { + send(out, COMMAND_AUTH, "DBUS_COOKIE_SHA1", Uid); + current = AUTH_SHA; + } else if (0 != (available & AUTH_ANON)) { + send(out, COMMAND_AUTH, "ANONYMOUS"); + current = AUTH_ANON; + } + else state = FAILED; + break; + default: + state = FAILED; + break; + } + break; + default: + state = FAILED; + } + break; + case MODE_SERVER: + switch (state) { + case INITIAL_STATE: + byte[] buf = new byte[1]; + if (null == us) { + in.read(buf); + } else { + buf[0] = us.recvCredentialByte(); + int kuid = us.getPeerUID(); + if (kuid >= 0) + kernelUid = stupidlyEncode(""+kuid); + } + if (0 != buf[0]) state = FAILED; + else state = WAIT_AUTH; + break; + case WAIT_AUTH: + c = receive(in); + switch (c.getCommand()) { + case COMMAND_AUTH: + if (null == c.getData()) { + send(out, COMMAND_REJECTED, getTypes(types)); + } else { + switch (do_response(current, Uid, kernelUid, c)) { + case CONTINUE: + send(out, COMMAND_DATA, c.getResponse()); + current = c.getMechs(); + state = WAIT_DATA; + break; + case OK: + send(out, COMMAND_OK, guid); + state = WAIT_BEGIN; + current = 0; + break; + case REJECT: + send(out, COMMAND_REJECTED, getTypes(types)); + current = 0; + break; + } + } + break; + case COMMAND_ERROR: + send(out, COMMAND_REJECTED, getTypes(types)); + break; + case COMMAND_BEGIN: + state = FAILED; + break; + default: + send(out, COMMAND_ERROR, "Got invalid command"); + break; + } + break; + case WAIT_DATA: + c = receive(in); + switch (c.getCommand()) { + case COMMAND_DATA: + switch (do_response(current, Uid, kernelUid, c)) { + case CONTINUE: + send(out, COMMAND_DATA, c.getResponse()); + state = WAIT_DATA; + break; + case OK: + send(out, COMMAND_OK, guid); + state = WAIT_BEGIN; + current = 0; + break; + case REJECT: + send(out, COMMAND_REJECTED, getTypes(types)); + current = 0; + break; + } + break; + case COMMAND_ERROR: + case COMMAND_CANCEL: + send(out, COMMAND_REJECTED, getTypes(types)); + state = WAIT_AUTH; + break; + case COMMAND_BEGIN: + state = FAILED; + break; + default: + send(out, COMMAND_ERROR, "Got invalid command"); + break; + } + break; + case WAIT_BEGIN: + c = receive(in); + switch (c.getCommand()) { + case COMMAND_ERROR: + case COMMAND_CANCEL: + send(out, COMMAND_REJECTED, getTypes(types)); + state = WAIT_AUTH; + break; + case COMMAND_BEGIN: + state = AUTHENTICATED; + break; + default: + send(out, COMMAND_ERROR, "Got invalid command"); + break; + } + break; + default: + state = FAILED; + } + break; + default: + return false; + } + } + + return state == AUTHENTICATED; + } + } + public MessageReader min; + public MessageWriter mout; + public Transport() {} + public static String genGUID() + { + Random r = new Random(); + byte[] buf = new byte[16]; + r.nextBytes(buf); + String guid = Hexdump.toHex(buf); + return guid.replaceAll(" ", ""); + } + public Transport(BusAddress address) throws IOException + { + connect(address); + } + public Transport(String address) throws IOException, ParseException + { + connect(new BusAddress(address)); + } + public Transport(String address, int timeout) throws IOException, ParseException + { + connect(new BusAddress(address), timeout); + } + public void connect(String address) throws IOException, ParseException + { + connect(new BusAddress(address), 0); + } + public void connect(String address, int timeout) throws IOException, ParseException + { + connect(new BusAddress(address), timeout); + } + public void connect(BusAddress address) throws IOException + { + connect(address, 0); + } + public void connect(BusAddress address, int timeout) throws IOException + { + if (Debug.debug) Debug.print(Debug.INFO, "Connecting to "+address); + OutputStream out = null; + InputStream in = null; + UnixSocket us = null; + Socket s = null; + int mode = 0; + int types = 0; + if ("unix".equals(address.getType())) { + types = SASL.AUTH_EXTERNAL; + if (null != address.getParameter("listen")) { + mode = SASL.MODE_SERVER; + UnixServerSocket uss = new UnixServerSocket(); + if (null != address.getParameter("abstract")) + uss.bind(new UnixSocketAddress(address.getParameter("abstract"), true)); + else if (null != address.getParameter("path")) + uss.bind(new UnixSocketAddress(address.getParameter("path"), false)); + us = uss.accept(); + } else { + mode = SASL.MODE_CLIENT; + us = new UnixSocket(); + if (null != address.getParameter("abstract")) + us.connect(new UnixSocketAddress(address.getParameter("abstract"), true)); + else if (null != address.getParameter("path")) + us.connect(new UnixSocketAddress(address.getParameter("path"), false)); + } + us.setPassCred(true); + in = us.getInputStream(); + out = us.getOutputStream(); + } else if ("tcp".equals(address.getType())) { + types = SASL.AUTH_SHA; + if (null != address.getParameter("listen")) { + mode = SASL.MODE_SERVER; + ServerSocket ss = new ServerSocket(); + ss.bind(new InetSocketAddress(address.getParameter("host"), Integer.parseInt(address.getParameter("port")))); + s = ss.accept(); + } else { + mode = SASL.MODE_CLIENT; + s = new Socket(); + s.connect(new InetSocketAddress(address.getParameter("host"), Integer.parseInt(address.getParameter("port")))); + } + in = s.getInputStream(); + out = s.getOutputStream(); + } else { + throw new IOException(_("unknown address type ")+address.getType()); + } + + if (!(new SASL()).auth(mode, types, address.getParameter("guid"), out, in, us)) { + out.close(); + throw new IOException(_("Failed to auth")); + } + if (null != us) { + if (Debug.debug) Debug.print(Debug.VERBOSE, "Setting timeout to "+timeout+" on Socket"); + if (timeout == 1) + us.setBlocking(false); + else + us.setSoTimeout(timeout); + } + if (null != s) { + if (Debug.debug) Debug.print(Debug.VERBOSE, "Setting timeout to "+timeout+" on Socket"); + s.setSoTimeout(timeout); + } + mout = new MessageWriter(out); + min = new MessageReader(in); + } + public void disconnect() throws IOException + { + if (Debug.debug) Debug.print(Debug.INFO, "Disconnecting Transport"); + min.close(); + mout.close(); + } +} + + diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Tuple.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Tuple.java new file mode 100755 index 0000000..becfc60 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Tuple.java @@ -0,0 +1,24 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +/** + * This class should be extended to create Tuples. + * Any such class may be used as the return type for a method + * which returns multiple values. + * All fields in the Tuple which you wish to be serialized and sent to the + * remote method should be annotated with the org.freedesktop.dbus.Position + * annotation, in the order they should appear to DBus. + */ +public abstract class Tuple extends Container +{ + public Tuple() {} +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/TypeSignature.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/TypeSignature.java new file mode 100755 index 0000000..c297821 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/TypeSignature.java @@ -0,0 +1,37 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import java.lang.reflect.Type; +import org.freedesktop.dbus.exceptions.DBusException; + +public class TypeSignature +{ + String sig; + public TypeSignature(String sig) + { + this.sig = sig; + } + public TypeSignature(Type[] types) throws DBusException + { + StringBuffer sb = new StringBuffer(); + for (Type t: types) { + String[] ts = Marshalling.getDBusType(t); + for (String s: ts) + sb.append(s); + } + this.sig = sb.toString(); + } + public String getSig() + { + return sig; + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/UInt16.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/UInt16.java new file mode 100755 index 0000000..45af710 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/UInt16.java @@ -0,0 +1,79 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import static org.freedesktop.dbus.Gettext._; + +import java.text.MessageFormat; + +/** + * Class to represent 16-bit unsigned integers. + */ +@SuppressWarnings("serial") +public class UInt16 extends Number implements Comparable<UInt16> +{ + /** Maximum possible value. */ + public static final int MAX_VALUE = 65535; + /** Minimum possible value. */ + public static final int MIN_VALUE = 0; + private int value; + /** Create a UInt16 from an int. + * @param value Must be within MIN_VALUE–MAX_VALUE + * @throws NumberFormatException if value is not between MIN_VALUE and MAX_VALUE + */ + public UInt16(int value) + { + if (value < MIN_VALUE || value > MAX_VALUE) + throw new NumberFormatException(MessageFormat.format(_("{0} is not between {1} and {2}."), new Object[] { value, MIN_VALUE, MAX_VALUE})); + this.value = value; + } + /** Create a UInt16 from a String. + * @param value Must parse to a valid integer within MIN_VALUE–MAX_VALUE + * @throws NumberFormatException if value is not an integer between MIN_VALUE and MAX_VALUE + */ + public UInt16(String value) + { + this(Integer.parseInt(value)); + } + /** The value of this as a byte. */ + public byte byteValue() { return (byte) value; } + /** The value of this as a double. */ + public double doubleValue() { return (double) value; } + /** The value of this as a float. */ + public float floatValue() { return (float) value; } + /** The value of this as a int. */ + public int intValue() { return /*(int)*/ value; } + /** The value of this as a long. */ + public long longValue() { return (long) value; } + /** The value of this as a short. */ + public short shortValue(){ return (short) value; } + /** Test two UInt16s for equality. */ + public boolean equals(Object o) + { + return o instanceof UInt16 && ((UInt16) o).value == this.value; + } + public int hashCode() + { + return /*(int)*/ value; + } + /** Compare two UInt16s. + * @return 0 if equal, -ve or +ve if they are different. + */ + public int compareTo(UInt16 other) + { + return /*(int)*/ (this.value - other.value); + } + /** The value of this as a string. */ + public String toString() + { + return ""+value; + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/UInt32.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/UInt32.java new file mode 100755 index 0000000..17b9f07 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/UInt32.java @@ -0,0 +1,79 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import static org.freedesktop.dbus.Gettext._; + +import java.text.MessageFormat; + +/** + * Class to represent unsigned 32-bit numbers. + */ +@SuppressWarnings("serial") +public class UInt32 extends Number implements Comparable<UInt32> +{ + /** Maximum allowed value */ + public static final long MAX_VALUE = 4294967295L; + /** Minimum allowed value */ + public static final long MIN_VALUE = 0; + private long value; + /** Create a UInt32 from a long. + * @param value Must be a valid integer within MIN_VALUE–MAX_VALUE + * @throws NumberFormatException if value is not between MIN_VALUE and MAX_VALUE + */ + public UInt32(long value) + { + if (value < MIN_VALUE || value > MAX_VALUE) + throw new NumberFormatException(MessageFormat.format(_("{0} is not between {1} and {2}."), new Object[] { value, MIN_VALUE, MAX_VALUE})); + this.value = value; + } + /** Create a UInt32 from a String. + * @param value Must parse to a valid integer within MIN_VALUE–MAX_VALUE + * @throws NumberFormatException if value is not an integer between MIN_VALUE and MAX_VALUE + */ + public UInt32(String value) + { + this(Long.parseLong(value)); + } + /** The value of this as a byte. */ + public byte byteValue() { return (byte) value; } + /** The value of this as a double. */ + public double doubleValue() { return (double) value; } + /** The value of this as a float. */ + public float floatValue() { return (float) value; } + /** The value of this as a int. */ + public int intValue() { return (int) value; } + /** The value of this as a long. */ + public long longValue() { return /*(long)*/ value; } + /** The value of this as a short. */ + public short shortValue(){ return (short) value; } + /** Test two UInt32s for equality. */ + public boolean equals(Object o) + { + return o instanceof UInt32 && ((UInt32) o).value == this.value; + } + public int hashCode() + { + return (int) value; + } + /** Compare two UInt32s. + * @return 0 if equal, -ve or +ve if they are different. + */ + public int compareTo(UInt32 other) + { + return (int) (this.value - other.value); + } + /** The value of this as a string */ + public String toString() + { + return ""+value; + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/UInt64.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/UInt64.java new file mode 100755 index 0000000..b3e4cb9 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/UInt64.java @@ -0,0 +1,151 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import static org.freedesktop.dbus.Gettext._; + +import java.math.BigInteger; + +import java.text.MessageFormat; + +/** + * Class to represent unsigned 64-bit numbers. + * Warning: Any functions which take or return a <tt>long</tt> + * are restricted to the range of a signed 64bit number. + * Use the BigInteger methods if you wish access to the full + * range. + */ +@SuppressWarnings("serial") +public class UInt64 extends Number implements Comparable<UInt64> +{ + /** Maximum allowed value (when accessed as a long) */ + public static final long MAX_LONG_VALUE = Long.MAX_VALUE; + /** Maximum allowed value (when accessed as a BigInteger) */ + public static final BigInteger MAX_BIG_VALUE = new BigInteger("18446744073709551615"); + /** Minimum allowed value */ + public static final long MIN_VALUE = 0; + private BigInteger value; + private long top; + private long bottom; + /** Create a UInt64 from a long. + * @param value Must be a valid integer within MIN_VALUE–MAX_VALUE + * @throws NumberFormatException if value is not between MIN_VALUE and MAX_VALUE + */ + public UInt64(long value) + { + if (value < MIN_VALUE || value > MAX_LONG_VALUE) + throw new NumberFormatException(MessageFormat.format(_("{0} is not between {1} and {2}."), new Object[] { value, MIN_VALUE, MAX_LONG_VALUE})); + this.value = new BigInteger(""+value); + this.top = this.value.shiftRight(32).and(new BigInteger("4294967295")).longValue(); + this.bottom = this.value.and(new BigInteger("4294967295")).longValue(); + } + /** + * Create a UInt64 from two longs. + * @param top Most significant 4 bytes. + * @param bottom Least significant 4 bytes. + */ + public UInt64(long top, long bottom) + { + BigInteger a = new BigInteger(""+top); + a = a.shiftLeft(32); + a = a.add(new BigInteger(""+bottom)); + if (0 > a.compareTo(BigInteger.ZERO)) + throw new NumberFormatException(MessageFormat.format(_("{0} is not between {1} and {2}."), new Object[] { a, MIN_VALUE, MAX_BIG_VALUE})); + if (0 < a.compareTo(MAX_BIG_VALUE)) + throw new NumberFormatException(MessageFormat.format(_("{0} is not between {1} and {2}."), new Object[] { a, MIN_VALUE, MAX_BIG_VALUE})); + this.value = a; + this.top = top; + this.bottom = bottom; + } + /** Create a UInt64 from a BigInteger + * @param value Must be a valid BigInteger between MIN_VALUE–MAX_BIG_VALUE + * @throws NumberFormatException if value is not an integer between MIN_VALUE and MAX_BIG_VALUE + */ + public UInt64(BigInteger value) + { + if (null == value) + throw new NumberFormatException(MessageFormat.format(_("{0} is not between {1} and {2}."), new Object[] { value, MIN_VALUE, MAX_BIG_VALUE})); + if (0 > value.compareTo(BigInteger.ZERO)) + throw new NumberFormatException(MessageFormat.format(_("{0} is not between {1} and {2}."), new Object[] { value, MIN_VALUE, MAX_BIG_VALUE})); + if (0 < value.compareTo(MAX_BIG_VALUE)) + throw new NumberFormatException(MessageFormat.format(_("{0} is not between {1} and {2}."), new Object[] { value, MIN_VALUE, MAX_BIG_VALUE})); + this.value = value; + this.top = this.value.shiftRight(32).and(new BigInteger("4294967295")).longValue(); + this.bottom = this.value.and(new BigInteger("4294967295")).longValue(); + } + /** Create a UInt64 from a String. + * @param value Must parse to a valid integer within MIN_VALUE–MAX_BIG_VALUE + * @throws NumberFormatException if value is not an integer between MIN_VALUE and MAX_BIG_VALUE + */ + public UInt64(String value) + { + if (null == value) + throw new NumberFormatException(MessageFormat.format(_("{0} is not between {1} and {2}."), new Object[] { value, MIN_VALUE, MAX_BIG_VALUE})); + BigInteger a = new BigInteger(value); + if (0 > a.compareTo(BigInteger.ZERO)) + throw new NumberFormatException(MessageFormat.format(_("{0} is not between {1} and {2}."), new Object[] { value, MIN_VALUE, MAX_BIG_VALUE})); + if (0 < a.compareTo(MAX_BIG_VALUE)) + throw new NumberFormatException(MessageFormat.format(_("{0} is not between {1} and {2}."), new Object[] { value, MIN_VALUE, MAX_BIG_VALUE})); + this.value = a; + this.top = this.value.shiftRight(32).and(new BigInteger("4294967295")).longValue(); + this.bottom = this.value.and(new BigInteger("4294967295")).longValue(); + } + /** The value of this as a BigInteger. */ + public BigInteger value() { return value; } + /** The value of this as a byte. */ + public byte byteValue() { return value.byteValue(); } + /** The value of this as a double. */ + public double doubleValue() { return value.doubleValue(); } + /** The value of this as a float. */ + public float floatValue() { return value.floatValue(); } + /** The value of this as a int. */ + public int intValue() { return value.intValue(); } + /** The value of this as a long. */ + public long longValue() { return value.longValue(); } + /** The value of this as a short. */ + public short shortValue(){ return value.shortValue(); } + /** Test two UInt64s for equality. */ + public boolean equals(Object o) + { + return o instanceof UInt64 && this.value.equals(((UInt64) o).value); + } + public int hashCode() + { + return value.hashCode(); + } + /** Compare two UInt32s. + * @return 0 if equal, -ve or +ve if they are different. + */ + public int compareTo(UInt64 other) + { + return this.value.compareTo(other.value); + } + /** The value of this as a string. */ + public String toString() + { + return value.toString(); + } + /** + * Most significant 4 bytes. + */ + public long top() + { + return top; + } + /** + * Least significant 4 bytes. + */ + public long bottom() + { + return bottom; + } +} + diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Variant.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Variant.java new file mode 100755 index 0000000..621296a --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/Variant.java @@ -0,0 +1,112 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus; + +import static org.freedesktop.dbus.Gettext._; + +import java.lang.reflect.Type; +import java.text.MessageFormat; +import java.util.Vector; +import org.freedesktop.dbus.exceptions.DBusException; + +import cx.ath.matthew.debug.Debug; + +/** + * A Wrapper class for Variant values. + * A method on DBus can send or receive a Variant. + * This will wrap another value whose type is determined at runtime. + * The Variant may be parameterized to restrict the types it may accept. + */ +public class Variant<T> +{ + private final T o; + private final Type type; + private final String sig; + /** + * Create a Variant from a basic type object. + * @param o The wrapped value. + * @throws IllegalArugmentException If you try and wrap Null or an object of a non-basic type. + */ + public Variant(T o) throws IllegalArgumentException + { + if (null == o) throw new IllegalArgumentException(_("Can't wrap Null in a Variant")); + type = o.getClass(); + try { + String[] ss = Marshalling.getDBusType(o.getClass(), true); + if (ss.length != 1) + throw new IllegalArgumentException(_("Can't wrap a multi-valued type in a Variant: ")+type); + this.sig = ss[0]; + } catch (DBusException DBe) { + if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, DBe); + throw new IllegalArgumentException(MessageFormat.format(_("Can't wrap {0} in an unqualified Variant ({1})."), new Object[] { o.getClass(), DBe.getMessage() })); + } + this.o = o; + } + /** + * Create a Variant. + * @param o The wrapped value. + * @param type The explicit type of the value. + * @throws IllegalArugmentException If you try and wrap Null or an object which cannot be sent over DBus. + */ + public Variant(T o, Type type) throws IllegalArgumentException + { + if (null == o) throw new IllegalArgumentException(_("Can't wrap Null in a Variant")); + this.type = type; + try { + String[] ss = Marshalling.getDBusType(type); + if (ss.length != 1) + throw new IllegalArgumentException(_("Can't wrap a multi-valued type in a Variant: ")+type); + this.sig = ss[0]; + } catch (DBusException DBe) { + if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, DBe); + throw new IllegalArgumentException(MessageFormat.format(_("Can't wrap {0} in an unqualified Variant ({1})."), new Object[] { type, DBe.getMessage() })); + } + this.o = o; + } + /** + * Create a Variant. + * @param o The wrapped value. + * @param sig The explicit type of the value, as a dbus type string. + * @throws IllegalArugmentException If you try and wrap Null or an object which cannot be sent over DBus. + */ + public Variant(T o, String sig) throws IllegalArgumentException + { + if (null == o) throw new IllegalArgumentException(_("Can't wrap Null in a Variant")); + this.sig = sig; + try { + Vector<Type> ts = new Vector<Type>(); + Marshalling.getJavaType(sig, ts,1); + if (ts.size() != 1) + throw new IllegalArgumentException(_("Can't wrap multiple or no types in a Variant: ")+sig); + this.type = ts.get(0); + } catch (DBusException DBe) { + if (AbstractConnection.EXCEPTION_DEBUG && Debug.debug) Debug.print(Debug.ERR, DBe); + throw new IllegalArgumentException(MessageFormat.format(_("Can't wrap {0} in an unqualified Variant ({1})."), new Object[] { sig, DBe.getMessage() })); + } + this.o = o; + } + /** Return the wrapped value. */ + public T getValue() { return o; } + /** Return the type of the wrapped value. */ + public Type getType() { return type; } + /** Return the dbus signature of the wrapped value. */ + public String getSig() { return sig; } + /** Format the Variant as a string. */ + public String toString() { return "["+o+"]"; } + /** Compare this Variant with another by comparing contents */ + @SuppressWarnings("unchecked") + public boolean equals(Object other) + { + if (null == other) return false; + if (!(other instanceof Variant)) return false; + return this.o.equals(((Variant<? extends Object>)other).o); + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/Caller.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/Caller.java new file mode 100755 index 0000000..ecd6002 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/Caller.java @@ -0,0 +1,83 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.bin; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Type; +import java.util.Arrays; +import java.util.Vector; +import java.io.File; +import org.freedesktop.dbus.BusAddress; +import org.freedesktop.dbus.Error; +import org.freedesktop.dbus.Marshalling; +import org.freedesktop.dbus.Message; +import org.freedesktop.dbus.MethodCall; +import org.freedesktop.dbus.Transport; +import cx.ath.matthew.debug.Debug; + +public class Caller +{ + @SuppressWarnings("unchecked") + public static void main(String[] args) + { + try { + if (Debug.debug) { + Debug.setHexDump(true); + Debug.loadConfig(new File("debug.conf")); + } + if (args.length < 4) { + System.out.println ("Syntax: Caller <dest> <path> <interface> <method> [<sig> <args>]"); + System.exit(1); + } + String addr = System.getenv("DBUS_SESSION_BUS_ADDRESS"); + BusAddress address = new BusAddress(addr); + Transport conn = new Transport(address); + + Message m = new MethodCall("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "Hello", (byte) 0, null);; + conn.mout.writeMessage(m); + + if ("".equals(args[2])) args[2] = null; + if (args.length == 4) + m = new MethodCall(args[0], args[1], args[2], args[3], (byte) 0, null); + else { + Vector<Type> lts = new Vector<Type>(); + Marshalling.getJavaType(args[4],lts, -1); + Type[] ts = lts.toArray(new Type[0]); + Object[] os = new Object[args.length-5]; + for (int i = 5; i < args.length; i++) { + if (ts[i-5] instanceof Class) { + try { + Constructor c = ((Class) ts[i-5]).getConstructor(String.class); + os[i-5] = c.newInstance(args[i]); + } catch (Exception e) { + os[i-5] = args[i]; + } + } else + os[i-5] = args[i]; + } + m = new MethodCall(args[0], args[1], args[2], args[3], (byte) 0, args[4], os); + } + long serial = m.getSerial(); + conn.mout.writeMessage(m); + do { + m = conn.min.readMessage(); + } while (serial != m.getReplySerial()); + if (m instanceof Error) ((Error) m).throwException(); + else { + Object[] os = m.getParameters(); + System.out.println(Arrays.deepToString(os)); + } + } catch (Exception e) { + System.out.println (e.getClass().getSimpleName()+": "+e.getMessage()); + System.exit(1); + } + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/CreateInterface.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/CreateInterface.java new file mode 100755 index 0000000..18769f9 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/CreateInterface.java @@ -0,0 +1,711 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.bin; + +import static org.freedesktop.dbus.Gettext._; +import static org.freedesktop.dbus.bin.IdentifierMangler.mangle; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintStream; +import java.io.Reader; +import java.io.StringReader; +import java.text.MessageFormat; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import java.util.Vector; + +import java.lang.reflect.Field; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.freedesktop.DBus.Introspectable; +import org.freedesktop.dbus.DBusConnection; +import org.freedesktop.dbus.Marshalling; +import org.freedesktop.dbus.exceptions.DBusException; +import org.freedesktop.dbus.exceptions.DBusExecutionException; +import org.freedesktop.dbus.types.DBusStructType; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +/** + * Converts a DBus XML file into Java interface definitions. + */ +public class CreateInterface +{ + @SuppressWarnings("unchecked") + private static String collapseType(Type t, Set<String> imports, Map<StructStruct, Type[]> structs, boolean container, boolean fullnames) throws DBusException + { + if (t instanceof ParameterizedType) { + String s; + Class<? extends Object> c = (Class<? extends Object>) ((ParameterizedType) t).getRawType(); + if (null != structs && t instanceof DBusStructType) { + int num = 1; + String name = "Struct"; + while (null != structs.get(new StructStruct(name+num))) num++; + name = name+num; + structs.put(new StructStruct(name), ((ParameterizedType) t).getActualTypeArguments()); + return name; + } + if (null != imports) imports.add(c.getName()); + if (fullnames) return c.getName(); + else s = c.getSimpleName(); + s += '<'; + Type[] ts = ((ParameterizedType) t).getActualTypeArguments(); + for (Type st: ts) + s += collapseType(st, imports, structs, true, fullnames)+','; + s = s.replaceAll(",$", ">"); + return s; + } else if (t instanceof Class) { + Class<? extends Object> c = (Class<? extends Object>) t; + if (c.isArray()) { + return collapseType(c.getComponentType(), imports, structs, container, fullnames)+"[]"; + } else { + Package p = c.getPackage(); + if (null != imports && + !"java.lang".equals(p.getName())) imports.add(c.getName()); + if (container) { + if (fullnames) return c.getName(); + else return c.getSimpleName(); + } else { + try { + Field f = c.getField("TYPE"); + Class<? extends Object> d = (Class<? extends Object>) f.get(c); + return d.getSimpleName(); + } catch (Exception e) { + return c.getSimpleName(); + } + } + } + } else return ""; + } + private static String getJavaType(String dbus, Set<String> imports, Map<StructStruct,Type[]> structs, boolean container, boolean fullnames) throws DBusException + { + if (null == dbus || "".equals(dbus)) return ""; + Vector<Type> v = new Vector<Type>(); + int c = Marshalling.getJavaType(dbus, v, 1); + Type t = v.get(0); + return collapseType(t, imports, structs, container, fullnames); + } + public String comment = ""; + boolean builtin; + + public CreateInterface(PrintStreamFactory factory, boolean builtin) + { + this.factory = factory; + this.builtin = builtin; + } + @SuppressWarnings("fallthrough") + String parseReturns(Vector<Element> out, Set<String> imports, Map<String,Integer> tuples, Map<StructStruct, Type[]> structs) throws DBusException + { + String[] names = new String[] { "Pair", "Triplet", "Quad", "Quintuple", "Sextuple", "Septuple" }; + String sig = ""; + String name = null; + switch (out.size()) { + case 0: + sig += "void "; + break; + case 1: + sig += getJavaType(out.get(0).getAttribute("type"), imports, structs, false, false)+" "; + break; + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + name = names[out.size() - 2]; + default: + if (null == name) + name = "NTuple"+out.size(); + + tuples.put(name, out.size()); + sig += name + "<"; + for (Element arg: out) + sig += getJavaType(arg.getAttribute("type"), imports, structs, true, false)+", "; + sig = sig.replaceAll(", $","> "); + break; + } + return sig; + } + String parseMethod(Element meth, Set<String> imports, Map<String,Integer> tuples, Map<StructStruct, Type[]> structs, Set<String> exceptions, Set<String> anns) throws DBusException + { + Vector<Element> in = new Vector<Element>(); + Vector<Element> out = new Vector<Element>(); + if (null == meth.getAttribute("name") || + "".equals(meth.getAttribute("name"))) { + System.err.println(_("ERROR: Method name was blank, failed")); + System.exit(1); + } + String annotations = ""; + String throwses = null; + + for (Node a: new IterableNodeList(meth.getChildNodes())) { + + if (Node.ELEMENT_NODE != a.getNodeType()) continue; + + checkNode(a, "arg", "annotation"); + + if ("arg".equals(a.getNodeName())) { + Element arg = (Element) a; + + // methods default to in + if ("out".equals(arg.getAttribute("direction"))) + out.add(arg); + else + in.add(arg); + } + else if ("annotation".equals(a.getNodeName())) { + Element e = (Element) a; + if (e.getAttribute("name").equals("org.freedesktop.DBus.Method.Error")) { + if (null == throwses) + throwses = e.getAttribute("value"); + else + throwses += ", " + e.getAttribute("value"); + exceptions.add(e.getAttribute("value")); + } else + annotations += parseAnnotation(e, imports, anns); + } + } + + String sig = ""; + comment = ""; + sig += parseReturns(out, imports, tuples, structs); + + sig += mangle(meth.getAttribute("name"))+"("; + + char defaultname = 'a'; + String params = ""; + for (Element arg: in) { + String type = getJavaType(arg.getAttribute("type"), imports, structs, false, false); + String name = arg.getAttribute("name"); + if (null == name || "".equals(name)) name = ""+(defaultname++); + params += type+" "+mangle(name)+", "; + } + return ("".equals(comment) ? "" : " /**\n" + comment + " */\n") + + annotations + " public " + sig + + params.replaceAll("..$", "")+")"+ + (null == throwses? "": " throws "+throwses)+";"; + } + String parseSignal(Element signal, Set<String> imports, Map<StructStruct, Type[]> structs, Set<String> anns) throws DBusException + { + Map<String, String> params = new HashMap<String, String>(); + Vector<String> porder = new Vector<String>(); + char defaultname = 'a'; + imports.add("org.freedesktop.dbus.DBusSignal"); + imports.add("org.freedesktop.dbus.exceptions.DBusException"); + String annotations = ""; + for (Node a: new IterableNodeList(signal.getChildNodes())) { + + if (Node.ELEMENT_NODE != a.getNodeType()) continue; + + checkNode(a, "arg", "annotation"); + + if ("annotation".equals(a.getNodeName())) + annotations += parseAnnotation((Element) a, imports, anns); + else { + Element arg = (Element) a; + String type = getJavaType(arg.getAttribute("type"), imports, structs, false, false); + String name = arg.getAttribute("name"); + if (null == name || "".equals(name)) name = ""+(defaultname++); + params.put(mangle(name), type); + porder.add(mangle(name)); + } + } + + String out = ""; + out += annotations; + out += " public static class "+signal.getAttribute("name"); + out += " extends DBusSignal\n {\n"; + for (String name: porder) + out += " public final "+params.get(name)+" "+name+";\n"; + out += " public "+signal.getAttribute("name")+"(String path"; + for (String name: porder) + out += ", "+params.get(name)+" "+name; + out += ") throws DBusException\n {\n super(path"; + for (String name: porder) + out += ", "+name; + out += ");\n"; + for (String name: porder) + out += " this."+name+" = "+name+";\n"; + out += " }\n"; + + out += " }\n"; + return out; + } + + String parseAnnotation(Element ann, Set<String> imports, Set<String> annotations) + { + String s = " @"+ann.getAttribute("name").replaceAll(".*\\.([^.]*)$","$1")+"("; + if (null != ann.getAttribute("value") + && !"".equals(ann.getAttribute("value"))) + s += '"'+ann.getAttribute("value")+'"'; + imports.add(ann.getAttribute("name")); + annotations.add(ann.getAttribute("name")); + return s += ")\n"; + } + + void parseInterface(Element iface, PrintStream out, Map<String,Integer> tuples, Map<StructStruct, Type[]> structs, Set<String> exceptions, Set<String> anns) throws DBusException + { + if (null == iface.getAttribute("name") || + "".equals(iface.getAttribute("name"))) { + System.err.println(_("ERROR: Interface name was blank, failed")); + System.exit(1); + } + + out.println("package "+iface.getAttribute("name").replaceAll("\\.[^.]*$","")+";"); + + String methods = ""; + String signals = ""; + String annotations = ""; + Set<String> imports = new TreeSet<String>(); + imports.add("org.freedesktop.dbus.DBusInterface"); + for (Node meth: new IterableNodeList(iface.getChildNodes())) { + + if (Node.ELEMENT_NODE != meth.getNodeType()) continue; + + checkNode(meth, "method", "signal", "property", "annotation"); + + if ("method".equals(meth.getNodeName())) + methods += parseMethod((Element) meth, imports, tuples, structs, exceptions, anns) + "\n"; + else if ("signal".equals(meth.getNodeName())) + signals += parseSignal((Element) meth, imports, structs, anns); + else if ("property".equals(meth.getNodeName())) + System.err.println("WARNING: Ignoring property"); + else if ("annotation".equals(meth.getNodeName())) + annotations += parseAnnotation((Element) meth, imports, anns); + } + + if (imports.size() > 0) + for (String i: imports) + out.println("import "+i+";"); + + out.print(annotations); + out.print("public interface "+iface.getAttribute("name").replaceAll("^.*\\.([^.]*)$","$1")); + out.println(" extends DBusInterface"); + out.println("{"); + out.println(signals); + out.println(methods); + out.println("}"); + } + void createException(String name, String pack, PrintStream out) throws DBusException + { + out.println("package "+pack+";"); + out.println("import org.freedesktop.dbus.DBusExecutionException;"); + out.print("public class "+name); + out.println(" extends DBusExecutionException"); + out.println("{"); + out.println(" public "+name+"(String message)"); + out.println(" {"); + out.println(" super(message);"); + out.println(" }"); + out.println("}"); + } + void createAnnotation(String name, String pack, PrintStream out) throws DBusException + { + out.println("package "+pack+";"); + out.println("import java.lang.annotation.Retention;"); + out.println("import java.lang.annotation.RetentionPolicy;"); + out.println("@Retention(RetentionPolicy.RUNTIME)"); + out.println("public @interface "+name); + out.println("{"); + out.println(" String value();"); + out.println("}"); + } + void createStruct(String name, Type[] type, String pack, PrintStream out, Map<StructStruct, Type[]> existing) throws DBusException, IOException + { + out.println("package "+pack+";"); + + Set<String> imports = new TreeSet<String>(); + imports.add("org.freedesktop.dbus.Position"); + imports.add("org.freedesktop.dbus.Struct"); + Map<StructStruct, Type[]> structs = new HashMap<StructStruct, Type[]>(existing); + String[] types = new String[type.length]; + for (int i = 0; i < type.length; i++) + types[i] = collapseType(type[i], imports, structs, false, false); + + for (String im: imports) out.println("import "+im+";"); + + out.println("public final class "+name+" extends Struct"); + out.println("{"); + int i = 0; + char c = 'a'; + String params = ""; + for (String t: types) { + out.println(" @Position("+i++ +")"); + out.println(" public final "+t+" "+c+";"); + params += t+" "+c+", "; + c++; + } + out.println(" public "+name+"("+params.replaceAll("..$", "")+")"); + out.println(" {"); + for (char d = 'a'; d < c; d++) + out.println(" this."+d+" = "+d+";"); + + out.println(" }"); + out.println("}"); + + structs = StructStruct.fillPackages(structs, pack); + Map<StructStruct, Type[]> tocreate = new HashMap<StructStruct, Type[]>(structs); + for (StructStruct ss: existing.keySet()) tocreate.remove(ss); + createStructs(tocreate, structs); + } + void createTuple(String name, int num, String pack, PrintStream out) throws DBusException + { + out.println("package "+pack+";"); + out.println("import org.freedesktop.dbus.Position;"); + out.println("import org.freedesktop.dbus.Tuple;"); + out.println("/** Just a typed container class */"); + out.print("public final class "+name); + String types = " <"; + for (char v = 'A'; v < 'A'+num; v++) + types += v + ","; + out.print(types.replaceAll(",$","> ")); + out.println("extends Tuple"); + out.println("{"); + + char t = 'A'; + char n = 'a'; + for (int i = 0; i < num; i++,t++,n++) { + out.println(" @Position("+i+")"); + out.println(" public final "+t+" "+n+";"); + } + + out.print(" public "+name+"("); + String sig = ""; + t = 'A'; + n = 'a'; + for (int i = 0; i < num; i++,t++,n++) + sig += t+" "+n+", "; + out.println(sig.replaceAll(", $", ")")); + out.println(" {"); + for (char v = 'a'; v < 'a'+num; v++) + out.println(" this."+v+" = "+v+";"); + out.println(" }"); + + out.println("}"); + } + void parseRoot(Element root) throws DBusException, IOException + { + Map<StructStruct, Type[]> structs = new HashMap<StructStruct, Type[]>(); + Set<String> exceptions = new TreeSet<String>(); + Set<String> annotations = new TreeSet<String>(); + + for (Node iface: new IterableNodeList(root.getChildNodes())) { + + if (Node.ELEMENT_NODE != iface.getNodeType()) continue; + + checkNode(iface, "interface", "node"); + + if ("interface".equals(iface.getNodeName())) { + + Map<String, Integer> tuples = new HashMap<String, Integer>(); + String name = ((Element) iface).getAttribute("name"); + String file = name.replaceAll("\\.","/")+".java"; + String path = file.replaceAll("/[^/]*$", ""); + String pack = name.replaceAll("\\.[^.]*$",""); + + // don't create interfaces in org.freedesktop.DBus by default + if (pack.startsWith("org.freedesktop.DBus") && !builtin) continue; + + factory.init(file, path); + parseInterface((Element) iface, + factory.createPrintStream(file), tuples, structs, exceptions, annotations); + + structs = StructStruct.fillPackages(structs, pack); + createTuples(tuples, pack); + } + else if ("node".equals(iface.getNodeName())) + parseRoot((Element) iface); + else { + System.err.println(_("ERROR: Unknown node: ")+iface.getNodeName()); + System.exit(1); + } + } + + createStructs(structs, structs); + createExceptions(exceptions); + createAnnotations(annotations); + } + private void createAnnotations(Set<String> annotations) throws DBusException, IOException + { + for (String fqn: annotations) { + String name = fqn.replaceAll("^.*\\.([^.]*)$", "$1"); + String pack = fqn.replaceAll("\\.[^.]*$",""); + // don't create things in org.freedesktop.DBus by default + if (pack.startsWith("org.freedesktop.DBus") && !builtin) + continue; + String path = pack.replaceAll("\\.", "/"); + String file = name.replaceAll("\\.","/")+".java"; + factory.init(file, path); + createAnnotation(name, pack, + factory.createPrintStream(path, name)); + } + } + private void createExceptions(Set<String> exceptions) throws DBusException, IOException + { + for (String fqn: exceptions) { + String name = fqn.replaceAll("^.*\\.([^.]*)$", "$1"); + String pack = fqn.replaceAll("\\.[^.]*$",""); + // don't create things in org.freedesktop.DBus by default + if (pack.startsWith("org.freedesktop.DBus") && !builtin) + continue; + String path = pack.replaceAll("\\.", "/"); + String file = name.replaceAll("\\.","/")+".java"; + factory.init(file, path); + createException(name, pack, + factory.createPrintStream(path, name)); + } + } + private void createStructs(Map<StructStruct, Type[]> structs, Map<StructStruct, Type[]> existing) throws DBusException, IOException + { + for (StructStruct ss: structs.keySet()) { + String file = ss.name.replaceAll("\\.","/")+".java"; + String path = ss.pack.replaceAll("\\.", "/"); + factory.init(file, path); + createStruct(ss.name, structs.get(ss), ss.pack, + factory.createPrintStream(path, ss.name), existing); + } + } + + private void createTuples(Map<String, Integer> typeMap, String pack) throws DBusException, IOException + { + for (String tname: typeMap.keySet()) + createTuple(tname, typeMap.get(tname), pack, + factory.createPrintStream(pack.replaceAll("\\.","/"), tname)); + } + + public static abstract class PrintStreamFactory + { + + public abstract void init(String file, String path); + + /** + * @param path + * @param tname + * @return PrintStream + * @throws IOException + */ + public PrintStream createPrintStream(String path, String tname) throws IOException + { + final String file = path+"/"+tname+".java"; + return createPrintStream(file); + } + + /** + * @param file + * @return PrintStream + * @throws IOException + */ + public abstract PrintStream createPrintStream(final String file) throws IOException; + + } + static class ConsoleStreamFactory extends PrintStreamFactory + { + + @Override + public + void init(String file, String path) + { + } + + @Override + public + PrintStream createPrintStream(String file) throws IOException + { + System.out.println("/* File: "+file+" */"); + return System.out; + } + + public PrintStream createPrintStream(String path, String tname) throws IOException + { + return super.createPrintStream(path, tname); + } + + } + + static class FileStreamFactory extends PrintStreamFactory + { + public void init(String file, String path) + { + new File(path).mkdirs(); + } + + + /** + * @param file + * @return + * @throws IOException + */ + public PrintStream createPrintStream(final String file) throws IOException + { + return new PrintStream(new FileOutputStream(file)); + } + + } + + static void checkNode(Node n, String... names) + { + String expected = ""; + for (String name: names) { + if (name.equals(n.getNodeName())) return; + expected += name + " or "; + } + System.err.println(MessageFormat.format(_("ERROR: Expected {0}, got {1}, failed."), new Object[] { expected.replaceAll("....$", ""), n.getNodeName() })); + System.exit(1); + } + + private final PrintStreamFactory factory; + + static class Config + { + int bus = DBusConnection.SESSION; + String busname = null; + String object = null; + File datafile = null; + boolean printtree = false; + boolean fileout = false; + boolean builtin = false; + } + + static void printSyntax() + { + printSyntax(System.err); + } + static void printSyntax(PrintStream o) + { + o.println("Syntax: CreateInterface <options> [file | busname object]"); + o.println(" Options: --no-ignore-builtin --system -y --session -s --create-files -f --help -h --version -v"); + } + public static void version() + { + System.out.println("Java D-Bus Version "+System.getProperty("Version")); + System.exit(1); + } + + static Config parseParams(String[] args) + { + Config config = new Config(); + for (String p: args) { + if ("--system".equals(p) || "-y".equals(p)) + config.bus = DBusConnection.SYSTEM; + else if ("--session".equals(p) || "-s".equals(p)) + config.bus = DBusConnection.SESSION; + else if ("--no-ignore-builtin".equals(p)) + config.builtin = true; + else if ("--create-files".equals(p) || "-f".equals(p)) + config.fileout = true; + else if ("--print-tree".equals(p) || "-p".equals(p)) + config.printtree = true; + else if ("--help".equals(p) || "-h".equals(p)) { + printSyntax(System.out); + System.exit(0); + } else if ("--version".equals(p) || "-v".equals(p)) { + version(); + System.exit(0); + } else if (p.startsWith("-")) { + System.err.println(_("ERROR: Unknown option: ")+p); + printSyntax(); + System.exit(1); + } + else { + if (null == config.busname) config.busname = p; + else if (null == config.object) config.object = p; + else { + printSyntax(); + System.exit(1); + } + } + } + if (null == config.busname) { + printSyntax(); + System.exit(1); + } + else if (null == config.object) { + config.datafile = new File(config.busname); + config.busname = null; + } + return config; + } + + public static void main(String[] args) throws Exception + { + Config config = parseParams(args); + + Reader introspectdata = null; + + if (null != config.busname) try { + DBusConnection conn = DBusConnection.getConnection(config.bus); + Introspectable in = conn.getRemoteObject(config.busname, config.object, Introspectable.class); + String id = in.Introspect(); + if (null == id) { + System.err.println(_("ERROR: Failed to get introspection data")); + System.exit(1); + } + introspectdata = new StringReader(id); + conn.disconnect(); + } catch (DBusException DBe) { + System.err.println(_("ERROR: Failure in DBus Communications: ")+DBe.getMessage()); + System.exit(1); + } catch (DBusExecutionException DEe) { + System.err.println(_("ERROR: Failure in DBus Communications: ")+DEe.getMessage()); + System.exit(1); + + } else if (null != config.datafile) try { + introspectdata = new InputStreamReader(new FileInputStream(config.datafile)); + } catch (FileNotFoundException FNFe) { + System.err.println(_("ERROR: Could not find introspection file: ")+FNFe.getMessage()); + System.exit(1); + } + try { + PrintStreamFactory factory = config.fileout ? new FileStreamFactory() : new ConsoleStreamFactory(); + CreateInterface createInterface = new CreateInterface(factory, config.builtin); + createInterface.createInterface(introspectdata); + } catch (DBusException DBe) { + System.err.println("ERROR: "+DBe.getMessage()); + System.exit(1); + } + } + /** Output the interface for the supplied xml reader + * @param introspectdata The introspect data reader + * @throws ParserConfigurationException If the xml parser could not be configured + * @throws SAXException If a problem occurs reading the xml data + * @throws IOException If an IO error occurs + * @throws DBusException If the dbus related error occurs + */ + public void createInterface(Reader introspectdata) throws ParserConfigurationException, SAXException, IOException, DBusException + { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document document = builder.parse(new InputSource(introspectdata)); + + Element root = document.getDocumentElement(); + checkNode(root, "node"); + parseRoot(root); + + } +} + + diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/DBusDaemon.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/DBusDaemon.java new file mode 100755 index 0000000..1ecd77a --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/DBusDaemon.java @@ -0,0 +1,878 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.bin; + +import static org.freedesktop.dbus.Gettext._; + +import org.freedesktop.DBus; +import org.freedesktop.dbus.AbstractConnection; +import org.freedesktop.dbus.BusAddress; +import org.freedesktop.dbus.DBusSignal; +import org.freedesktop.dbus.DirectConnection; +import org.freedesktop.dbus.Error; +import org.freedesktop.dbus.Marshalling; +import org.freedesktop.dbus.Message; +import org.freedesktop.dbus.MessageReader; +import org.freedesktop.dbus.MessageWriter; +import org.freedesktop.dbus.MethodCall; +import org.freedesktop.dbus.MethodReturn; +import org.freedesktop.dbus.Transport; +import org.freedesktop.dbus.UInt32; +import org.freedesktop.dbus.exceptions.DBusException; +import org.freedesktop.dbus.exceptions.DBusExecutionException; +import org.freedesktop.dbus.exceptions.FatalException; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.ref.WeakReference; +import java.lang.reflect.InvocationTargetException; +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.text.MessageFormat; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.Vector; + +import cx.ath.matthew.debug.Debug; +import cx.ath.matthew.unix.UnixServerSocket; +import cx.ath.matthew.unix.UnixSocket; +import cx.ath.matthew.unix.UnixSocketAddress; + +/** + * A replacement DBusDaemon + */ +public class DBusDaemon extends Thread +{ + public static final int QUEUE_POLL_WAIT = 500; + static class Connstruct + { + public UnixSocket usock; + public Socket tsock; + public MessageReader min; + public MessageWriter mout; + public String unique; + public Connstruct(UnixSocket sock) + { + this.usock = sock; + min = new MessageReader(sock.getInputStream()); + mout = new MessageWriter(sock.getOutputStream()); + } + public Connstruct(Socket sock) throws IOException + { + this.tsock = sock; + min = new MessageReader(sock.getInputStream()); + mout = new MessageWriter(sock.getOutputStream()); + } + public String toString() + { + return null == unique ? ":?-?" : unique; + } + } + static class MagicMap<A, B> + { + private Map<A, LinkedList<B>> m; + private LinkedList<A> q; + private String name; + public MagicMap(String name) + { + m = new HashMap<A, LinkedList<B>>(); + q = new LinkedList<A>(); + this.name = name; + } + public A head() + { + return q.getFirst(); + } + public void putFirst(A a, B b) + { + if (Debug.debug) Debug.print("<"+name+"> Queueing {"+a+" => "+b+"}"); + if (m.containsKey(a)) + m.get(a).add(b); + else { + LinkedList<B> l = new LinkedList<B>(); + l.add(b); + m.put(a, l); + } + q.addFirst(a); + } + public void putLast(A a, B b) + { + if (Debug.debug) Debug.print("<"+name+"> Queueing {"+a+" => "+b+"}"); + if (m.containsKey(a)) + m.get(a).add(b); + else { + LinkedList<B> l = new LinkedList<B>(); + l.add(b); + m.put(a, l); + } + q.addLast(a); + } + public List<B> remove(A a) + { + if (Debug.debug) Debug.print("<"+name+"> Removing {"+a+"}"); + q.remove(a); + return m.remove(a); + } + public int size() + { + return q.size(); + } + } + public class DBusServer extends Thread implements DBus, DBus.Introspectable, DBus.Peer + { + public DBusServer() + { + setName("Server"); + } + public Connstruct c; + public Message m; + public boolean isRemote() { return false; } + public String Hello() + { + if (Debug.debug) Debug.print(Debug.DEBUG, "enter"); + synchronized (c) { + if (null != c.unique) + throw new org.freedesktop.DBus.Error.AccessDenied(_("Connection has already sent a Hello message")); + synchronized (unique_lock) { + c.unique = ":1."+(++next_unique); + } + } + synchronized (names) { + names.put(c.unique, c); + } + + if (Debug.debug) Debug.print(Debug.WARN, "Client "+c.unique+" registered"); + + try { + send(c, new DBusSignal("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "NameAcquired", "s", c.unique)); + DBusSignal s = new DBusSignal("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "NameOwnerChanged", "sss", c.unique, "", c.unique); + send(null, s); + } catch (DBusException DBe) { + if (Debug.debug && AbstractConnection.EXCEPTION_DEBUG) Debug.print(Debug.ERR, DBe); + } + if (Debug.debug) Debug.print(Debug.DEBUG, "exit"); + return c.unique; + } + public String[] ListNames() + { + if (Debug.debug) Debug.print(Debug.DEBUG, "enter"); + String[] ns; + synchronized (names) { + Set<String> nss = names.keySet(); + ns = nss.toArray(new String[0]); + } + if (Debug.debug) Debug.print(Debug.DEBUG, "exit"); + return ns; + } + + public boolean NameHasOwner(String name) + { + if (Debug.debug) Debug.print(Debug.DEBUG, "enter"); + boolean rv; + synchronized (names) { + rv = names.containsKey(name); + } + if (Debug.debug) Debug.print(Debug.DEBUG, "exit"); + return rv; + } + public String GetNameOwner(String name) + { + if (Debug.debug) Debug.print(Debug.DEBUG, "enter"); + Connstruct owner = names.get(name); + String o; + if (null == owner) + o = ""; + else + o = owner.unique; + if (Debug.debug) Debug.print(Debug.DEBUG, "exit"); + return o; + } + + public UInt32 GetConnectionUnixUser(String connection_name) + { + if (Debug.debug) Debug.print(Debug.DEBUG, "enter"); + if (Debug.debug) Debug.print(Debug.DEBUG, "exit"); + return new UInt32(0); + } + public UInt32 StartServiceByName(String name, UInt32 flags) + { + if (Debug.debug) Debug.print(Debug.DEBUG, "enter"); + if (Debug.debug) Debug.print(Debug.DEBUG, "exit"); + return new UInt32(0); + } + public UInt32 RequestName(String name, UInt32 flags) + { + if (Debug.debug) Debug.print(Debug.DEBUG, "enter"); + + boolean exists = false; + synchronized (names) { + if (!(exists = names.containsKey(name))) + names.put(name, c); + } + + int rv; + if (exists) { + rv = DBus.DBUS_REQUEST_NAME_REPLY_EXISTS; + } else { + if (Debug.debug) Debug.print(Debug.WARN, "Client "+c.unique+" acquired name "+name); + rv = DBus.DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER; + try { + send(c, new DBusSignal("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "NameAcquired", "s", name)); + send(null, new DBusSignal("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "NameOwnerChanged", "sss", name, "", c.unique)); + } catch (DBusException DBe) { + if (Debug.debug && AbstractConnection.EXCEPTION_DEBUG) Debug.print(Debug.ERR, DBe); + } + } + + if (Debug.debug) Debug.print(Debug.DEBUG, "exit"); + return new UInt32(rv); + } + + public UInt32 ReleaseName(String name) + { + if (Debug.debug) Debug.print(Debug.DEBUG, "enter"); + + boolean exists = false; + synchronized (names) { + if ((exists = (names.containsKey(name) && names.get(name).equals(c)))) + names.remove(name); + } + + int rv; + if (!exists) { + rv = DBus.DBUS_RELEASE_NAME_REPLY_NON_EXISTANT; + } else { + if (Debug.debug) Debug.print(Debug.WARN, "Client "+c.unique+" acquired name "+name); + rv = DBus.DBUS_RELEASE_NAME_REPLY_RELEASED; + try { + send(c, new DBusSignal("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "NameLost", "s", name)); + send(null, new DBusSignal("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "NameOwnerChanged", "sss", name, c.unique, "")); + } catch (DBusException DBe) { + if (Debug.debug && AbstractConnection.EXCEPTION_DEBUG) Debug.print(Debug.ERR, DBe); + } + } + + if (Debug.debug) Debug.print(Debug.DEBUG, "exit"); + return new UInt32(rv); + } + public void AddMatch(String matchrule) throws Error.MatchRuleInvalid + { + if (Debug.debug) Debug.print(Debug.DEBUG, "enter"); + if (Debug.debug) Debug.print(Debug.VERBOSE, "Adding match rule: "+matchrule); + synchronized (sigrecips) { + if (!sigrecips.contains(c)) + sigrecips.add(c); + } + if (Debug.debug) Debug.print(Debug.DEBUG, "exit"); + return; + } + public void RemoveMatch(String matchrule) throws Error.MatchRuleInvalid + { + if (Debug.debug) Debug.print(Debug.DEBUG, "enter"); + if (Debug.debug) Debug.print(Debug.VERBOSE, "Removing match rule: "+matchrule); + if (Debug.debug) Debug.print(Debug.DEBUG, "exit"); + return; + } + public String[] ListQueuedOwners(String name) + { + if (Debug.debug) Debug.print(Debug.DEBUG, "enter"); + if (Debug.debug) Debug.print(Debug.DEBUG, "exit"); + return new String[0]; + } + public UInt32 GetConnectionUnixProcessID(String connection_name) + { + if (Debug.debug) Debug.print(Debug.DEBUG, "enter"); + if (Debug.debug) Debug.print(Debug.DEBUG, "exit"); + return new UInt32(0); + } + public Byte[] GetConnectionSELinuxSecurityContext(String a) + { + if (Debug.debug) Debug.print(Debug.DEBUG, "enter"); + if (Debug.debug) Debug.print(Debug.DEBUG, "exit"); + return new Byte[0]; + } + public void ReloadConfig() + { + if (Debug.debug) Debug.print(Debug.DEBUG, "enter"); + if (Debug.debug) Debug.print(Debug.DEBUG, "exit"); + return; + } + @SuppressWarnings("unchecked") + private void handleMessage(Connstruct c, Message m) throws DBusException + { + if (Debug.debug) Debug.print(Debug.DEBUG, "enter"); + if (Debug.debug) Debug.print(Debug.VERBOSE, "Handling message "+m+" from "+c.unique); + if (!(m instanceof MethodCall)) return; + Object[] args = m.getParameters(); + + Class<? extends Object>[] cs = new Class[args.length]; + + for (int i = 0; i < cs.length; i++) + cs[i] = args[i].getClass(); + + java.lang.reflect.Method meth = null; + Object rv = null; + + try { + meth = DBusServer.class.getMethod(m.getName(), cs); + try { + this.c = c; + this.m = m; + rv = meth.invoke(dbus_server, args); + if (null == rv) { + send(c, new MethodReturn("org.freedesktop.DBus", (MethodCall) m, null), true); + } else { + String sig = Marshalling.getDBusType(meth.getGenericReturnType())[0]; + send(c, new MethodReturn("org.freedesktop.DBus", (MethodCall) m, sig, rv), true); + } + } catch (InvocationTargetException ITe) { + if (Debug.debug && AbstractConnection.EXCEPTION_DEBUG) Debug.print(Debug.ERR, ITe); + if (Debug.debug && AbstractConnection.EXCEPTION_DEBUG) Debug.print(Debug.ERR, ITe.getCause()); + send(c, new org.freedesktop.dbus.Error("org.freedesktop.DBus", m, ITe.getCause())); + } catch (DBusExecutionException DBEe) { + if (Debug.debug && AbstractConnection.EXCEPTION_DEBUG) Debug.print(Debug.ERR, DBEe); + send(c, new org.freedesktop.dbus.Error("org.freedesktop.DBus", m, DBEe)); + } catch (Exception e) { + if (Debug.debug && AbstractConnection.EXCEPTION_DEBUG) Debug.print(Debug.ERR, e); + send(c,new org.freedesktop.dbus.Error("org.freedesktop.DBus", c.unique, "org.freedesktop.DBus.Error.GeneralError", m.getSerial(), "s", _("An error occurred while calling ")+m.getName())); + } + } catch (NoSuchMethodException NSMe) { + send(c,new org.freedesktop.dbus.Error("org.freedesktop.DBus", c.unique, "org.freedesktop.DBus.Error.UnknownMethod", m.getSerial(), "s", _("This service does not support ")+m.getName())); + } + + if (Debug.debug) Debug.print(Debug.DEBUG, "exit"); + } + public String Introspect() + { + return "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"+ + "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"+ + "<node>\n"+ + " <interface name=\"org.freedesktop.DBus.Introspectable\">\n"+ + " <method name=\"Introspect\">\n"+ + " <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"+ + " </method>\n"+ + " </interface>\n"+ + " <interface name=\"org.freedesktop.DBus\">\n"+ + " <method name=\"RequestName\">\n"+ + " <arg direction=\"in\" type=\"s\"/>\n"+ + " <arg direction=\"in\" type=\"u\"/>\n"+ + " <arg direction=\"out\" type=\"u\"/>\n"+ + " </method>\n"+ + " <method name=\"ReleaseName\">\n"+ + " <arg direction=\"in\" type=\"s\"/>\n"+ + " <arg direction=\"out\" type=\"u\"/>\n"+ + " </method>\n"+ + " <method name=\"StartServiceByName\">\n"+ + " <arg direction=\"in\" type=\"s\"/>\n"+ + " <arg direction=\"in\" type=\"u\"/>\n"+ + " <arg direction=\"out\" type=\"u\"/>\n"+ + " </method>\n"+ + " <method name=\"Hello\">\n"+ + " <arg direction=\"out\" type=\"s\"/>\n"+ + " </method>\n"+ + " <method name=\"NameHasOwner\">\n"+ + " <arg direction=\"in\" type=\"s\"/>\n"+ + " <arg direction=\"out\" type=\"b\"/>\n"+ + " </method>\n"+ + " <method name=\"ListNames\">\n"+ + " <arg direction=\"out\" type=\"as\"/>\n"+ + " </method>\n"+ + " <method name=\"ListActivatableNames\">\n"+ + " <arg direction=\"out\" type=\"as\"/>\n"+ + " </method>\n"+ + " <method name=\"AddMatch\">\n"+ + " <arg direction=\"in\" type=\"s\"/>\n"+ + " </method>\n"+ + " <method name=\"RemoveMatch\">\n"+ + " <arg direction=\"in\" type=\"s\"/>\n"+ + " </method>\n"+ + " <method name=\"GetNameOwner\">\n"+ + " <arg direction=\"in\" type=\"s\"/>\n"+ + " <arg direction=\"out\" type=\"s\"/>\n"+ + " </method>\n"+ + " <method name=\"ListQueuedOwners\">\n"+ + " <arg direction=\"in\" type=\"s\"/>\n"+ + " <arg direction=\"out\" type=\"as\"/>\n"+ + " </method>\n"+ + " <method name=\"GetConnectionUnixUser\">\n"+ + " <arg direction=\"in\" type=\"s\"/>\n"+ + " <arg direction=\"out\" type=\"u\"/>\n"+ + " </method>\n"+ + " <method name=\"GetConnectionUnixProcessID\">\n"+ + " <arg direction=\"in\" type=\"s\"/>\n"+ + " <arg direction=\"out\" type=\"u\"/>\n"+ + " </method>\n"+ + " <method name=\"GetConnectionSELinuxSecurityContext\">\n"+ + " <arg direction=\"in\" type=\"s\"/>\n"+ + " <arg direction=\"out\" type=\"ay\"/>\n"+ + " </method>\n"+ + " <method name=\"ReloadConfig\">\n"+ + " </method>\n"+ + " <signal name=\"NameOwnerChanged\">\n"+ + " <arg type=\"s\"/>\n"+ + " <arg type=\"s\"/>\n"+ + " <arg type=\"s\"/>\n"+ + " </signal>\n"+ + " <signal name=\"NameLost\">\n"+ + " <arg type=\"s\"/>\n"+ + " </signal>\n"+ + " <signal name=\"NameAcquired\">\n"+ + " <arg type=\"s\"/>\n"+ + " </signal>\n"+ + " </interface>\n"+ + "</node>"; + } + public void Ping() {} + + public void run() + { + if (Debug.debug) Debug.print(Debug.DEBUG, "enter"); + while (_run) { + Message m; + List<WeakReference<Connstruct>> wcs; + // block on outqueue + synchronized (localqueue) { + while (localqueue.size() == 0) try { + localqueue.wait(); + } catch (InterruptedException Ie) { } + m = localqueue.head(); + wcs = localqueue.remove(m); + } + if (null != wcs) try { + for (WeakReference<Connstruct> wc: wcs) { + Connstruct c = wc.get(); + if (null != c) { + if (Debug.debug) Debug.print(Debug.VERBOSE, "<localqueue> Got message "+m+" from "+c); + handleMessage(c, m); + } + } + } catch (DBusException DBe) { + if (Debug.debug && AbstractConnection.EXCEPTION_DEBUG) Debug.print(Debug.ERR, DBe); + } + else if (Debug.debug) Debug.print(Debug.INFO, "Discarding "+m+" connection reaped"); + } + if (Debug.debug) Debug.print(Debug.DEBUG, "exit"); + } + } + public class Sender extends Thread + { + public Sender() + { + setName("Sender"); + } + public void run() + { + if (Debug.debug) Debug.print(Debug.DEBUG, "enter"); + while (_run) { + + if (Debug.debug) Debug.print(Debug.VERBOSE, "Acquiring lock on outqueue and blocking for data"); + Message m = null; + List<WeakReference<Connstruct>> wcs = null; + // block on outqueue + synchronized (outqueue) { + while (outqueue.size() == 0) try { + outqueue.wait(); + } catch (InterruptedException Ie) { } + + m = outqueue.head(); + wcs = outqueue.remove(m); + } + if (null != wcs) { + for (WeakReference<Connstruct> wc: wcs) { + Connstruct c = wc.get(); + if (null != c) { + if (Debug.debug) Debug.print(Debug.VERBOSE, "<outqueue> Got message "+m+" for "+c.unique); + if (Debug.debug) Debug.print(Debug.INFO, "Sending message "+m+" to "+c.unique); + try { + c.mout.writeMessage(m); + } + catch (IOException IOe) { + if (Debug.debug && AbstractConnection.EXCEPTION_DEBUG) Debug.print(Debug.ERR, IOe); + removeConnection(c); + } + } + } + } + else if (Debug.debug) Debug.print(Debug.INFO, "Discarding "+m+" connection reaped"); + } + if (Debug.debug) Debug.print(Debug.DEBUG, "exit"); + } + } + public class Reader extends Thread + { + private Connstruct conn; + private WeakReference<Connstruct> weakconn; + private boolean _lrun = true; + public Reader(Connstruct conn) + { + this.conn = conn; + weakconn = new WeakReference<Connstruct>(conn); + setName("Reader"); + } + public void stopRunning() + { + _lrun = false; + } + public void run() + { + if (Debug.debug) Debug.print(Debug.DEBUG, "enter"); + while (_run && _lrun) { + + Message m = null; + try { + m = conn.min.readMessage(); + } catch (IOException IOe) { + if (Debug.debug && AbstractConnection.EXCEPTION_DEBUG) Debug.print(Debug.ERR, IOe); + removeConnection(conn); + } catch (DBusException DBe) { + if (Debug.debug && AbstractConnection.EXCEPTION_DEBUG) Debug.print(Debug.ERR, DBe); + if (DBe instanceof FatalException) + removeConnection(conn); + } + + if (null != m) { + if (Debug.debug) Debug.print(Debug.INFO, "Read "+m+" from "+conn.unique); + synchronized (inqueue) { + inqueue.putLast(m, weakconn); + inqueue.notifyAll(); + } + } + } + conn = null; + if (Debug.debug) Debug.print(Debug.DEBUG, "exit"); + } + } + + private Map<Connstruct, Reader> conns = new HashMap<Connstruct, Reader>(); + private HashMap<String, Connstruct> names = new HashMap<String, Connstruct>(); + private MagicMap<Message, WeakReference<Connstruct>> outqueue = new MagicMap<Message, WeakReference<Connstruct>>("out"); + private MagicMap<Message, WeakReference<Connstruct>> inqueue = new MagicMap<Message, WeakReference<Connstruct>>("in"); + private MagicMap<Message, WeakReference<Connstruct>> localqueue = new MagicMap<Message, WeakReference<Connstruct>>("local"); + private List<Connstruct> sigrecips = new Vector<Connstruct>(); + private boolean _run = true; + private int next_unique = 0; + private Object unique_lock = new Object(); + DBusServer dbus_server = new DBusServer(); + Sender sender = new Sender(); + + public DBusDaemon() + { + setName("Daemon"); + synchronized (names) { + names.put("org.freedesktop.DBus", null); + } + } + @SuppressWarnings("unchecked") + private void send(Connstruct c, Message m) + { + send (c, m, false); + } + private void send(Connstruct c, Message m, boolean head) + { + if (Debug.debug){ + Debug.print(Debug.DEBUG, "enter"); + if (null == c) + Debug.print(Debug.VERBOSE, "Queing message "+m+" for all connections"); + else + Debug.print(Debug.VERBOSE, "Queing message "+m+" for "+c.unique); + } + // send to all connections + if (null == c) { + synchronized (conns) { + synchronized (outqueue) { + for (Connstruct d: conns.keySet()) + if (head) + outqueue.putFirst(m, new WeakReference<Connstruct>(d)); + else + outqueue.putLast(m, new WeakReference<Connstruct>(d)); + outqueue.notifyAll(); + } + } + } else { + synchronized (outqueue) { + if (head) + outqueue.putFirst(m, new WeakReference<Connstruct>(c)); + else + outqueue.putLast(m, new WeakReference<Connstruct>(c)); + outqueue.notifyAll(); + } + } + if (Debug.debug) Debug.print(Debug.DEBUG, "exit"); + } + @SuppressWarnings("unchecked") + private List<Connstruct> findSignalMatches(DBusSignal sig) + { + if (Debug.debug) Debug.print(Debug.DEBUG, "enter"); + List<Connstruct> l; + synchronized (sigrecips) { + l = new Vector<Connstruct>(sigrecips); + } + if (Debug.debug) Debug.print(Debug.DEBUG, "exit"); + return l; + } + @SuppressWarnings("unchecked") + public void run() + { + if (Debug.debug) Debug.print(Debug.DEBUG, "enter"); + while (_run) { + try { + Message m; + List<WeakReference<Connstruct>> wcs; + synchronized (inqueue) { + while (0 == inqueue.size()) try { + inqueue.wait(); + } catch (InterruptedException Ie) {} + + m = inqueue.head(); + wcs = inqueue.remove(m); + } + if (null != wcs) { + for (WeakReference<Connstruct> wc: wcs) { + Connstruct c = wc.get(); + if (null != c) { + if (Debug.debug) Debug.print(Debug.INFO, "<inqueue> Got message "+m+" from "+c.unique); + // check if they have hello'd + if (null == c.unique + && (!(m instanceof MethodCall) + || !"org.freedesktop.DBus".equals(m.getDestination()) + || !"Hello".equals(m.getName()))) { + send(c,new Error("org.freedesktop.DBus", null, "org.freedesktop.DBus.Error.AccessDenied", m.getSerial(), "s", _("You must send a Hello message"))); + } else { + try { + if (null != c.unique) m.setSource(c.unique); + } catch (DBusException DBe) { + if (Debug.debug && AbstractConnection.EXCEPTION_DEBUG) Debug.print(Debug.ERR, DBe); + send(c,new Error("org.freedesktop.DBus", null, "org.freedesktop.DBus.Error.GeneralError", m.getSerial(), "s", _("Sending message failed"))); + } + + if ("org.freedesktop.DBus".equals(m.getDestination())) { + synchronized (localqueue) { + localqueue.putLast(m, wc); + localqueue.notifyAll(); + } + } else { + if (m instanceof DBusSignal) { + List<Connstruct> list = findSignalMatches((DBusSignal) m); + for (Connstruct d: list) + send(d, m); + } else { + Connstruct dest = names.get(m.getDestination()); + + if (null == dest) { + send(c, new Error("org.freedesktop.DBus", null, "org.freedesktop.DBus.Error.ServiceUnknown", m.getSerial(), "s", MessageFormat.format(_("The name `{0}' does not exist"), new Object[] { m.getDestination() }))); + } else + send(dest, m); + } + } + } + } + } + } + } + catch (DBusException DBe) { + if (Debug.debug && AbstractConnection.EXCEPTION_DEBUG) Debug.print(Debug.ERR, DBe); + } + } + if (Debug.debug) Debug.print(Debug.DEBUG, "exit"); + } + private void removeConnection(Connstruct c) + { + if (Debug.debug) Debug.print(Debug.DEBUG, "enter"); + boolean exists; + synchronized(conns) { + if ((exists = conns.containsKey(c))) { + Reader r = conns.get(c); + r.stopRunning(); + conns.remove(c); + } + } + if (exists) { + try { + if (null != c.usock) c.usock.close(); + if (null != c.tsock) c.tsock.close(); + } catch (IOException IOe) {} + synchronized(names) { + List<String> toRemove = new Vector<String>(); + for (String name: names.keySet()) + if (names.get(name) == c) { + toRemove.add(name); + try { + send(null, new DBusSignal("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "NameOwnerChanged", "sss", name, c.unique, "")); + } catch (DBusException DBe) { + if (Debug.debug && AbstractConnection.EXCEPTION_DEBUG) Debug.print(Debug.ERR, DBe); + } + } + for (String name: toRemove) + names.remove(name); + } + } + if (Debug.debug) Debug.print(Debug.DEBUG, "exit"); + } + public void addSock(UnixSocket us) + { + if (Debug.debug) Debug.print(Debug.DEBUG, "enter"); + if (Debug.debug) Debug.print(Debug.WARN, "New Client"); + Connstruct c = new Connstruct(us); + Reader r = new Reader(c); + synchronized (conns) { + conns.put(c, r); + } + r.start(); + if (Debug.debug) Debug.print(Debug.DEBUG, "exit"); + } + public void addSock(Socket s) throws IOException + { + if (Debug.debug) Debug.print(Debug.DEBUG, "enter"); + if (Debug.debug) Debug.print(Debug.WARN, "New Client"); + Connstruct c = new Connstruct(s); + Reader r = new Reader(c); + synchronized (conns) { + conns.put(c, r); + } + r.start(); + if (Debug.debug) Debug.print(Debug.DEBUG, "exit"); + } + public static void syntax() + { + System.out.println("Syntax: DBusDaemon [--version] [-v] [--help] [-h] [--listen address] [-l address] [--print-address] [-r] [--pidfile file] [-p file] [--addressfile file] [-a file] [--unix] [-u] [--tcp] [-t] "); + System.exit(1); + } + public static void version() + { + System.out.println("D-Bus Java Version: "+System.getProperty("Version")); + System.exit(1); + } + public static void saveFile(String data, String file) throws IOException + { + PrintWriter w = new PrintWriter(new FileOutputStream(file)); + w.println(data); + w.close(); + } + public static void main(String args[]) throws Exception + { + if (Debug.debug && AbstractConnection.EXCEPTION_DEBUG) Debug.print(Debug.DEBUG, "enter"); + else if (Debug.debug) Debug.print(Debug.DEBUG, "enter"); + String addr = null; + String pidfile = null; + String addrfile = null; + boolean printaddress = false; + boolean unix = true; + boolean tcp = false; + + // parse options + try { + for (int i=0; i < args.length; i++) + if ("--help".equals(args[i]) || "-h".equals(args[i])) + syntax(); + else if ("--version".equals(args[i]) || "-v".equals(args[i])) + version(); + else if ("--listen".equals(args[i]) || "-l".equals(args[i])) + addr = args[++i]; + else if ("--pidfile".equals(args[i]) || "-p".equals(args[i])) + pidfile = args[++i]; + else if ("--addressfile".equals(args[i]) || "-a".equals(args[i])) + addrfile = args[++i]; + else if ("--print-address".equals(args[i]) || "-r".equals(args[i])) + printaddress = true; + else if ("--unix".equals(args[i]) || "-u".equals(args[i])) { + unix = true; + tcp = false; + } else if ("--tcp".equals(args[i]) || "-t".equals(args[i])) { + tcp = true; + unix = false; + } else syntax(); + } catch (ArrayIndexOutOfBoundsException AIOOBe) { + syntax(); + } + + // generate a random address if none specified + if (null == addr && unix) addr = DirectConnection.createDynamicSession(); + else if (null == addr && tcp) addr = DirectConnection.createDynamicTCPSession(); + + BusAddress address = new BusAddress(addr); + if (null == address.getParameter("guid")) { + addr += ",guid="+Transport.genGUID(); + address = new BusAddress(addr); + } + + // print address to stdout + if (printaddress) System.out.println(addr); + + // print address to file + if (null != addrfile) saveFile(addr, addrfile); + + // print PID to file + if (null != pidfile) saveFile(System.getProperty("Pid"), pidfile); + + // start the daemon + if (Debug.debug) Debug.print(Debug.WARN, "Binding to "+addr); + if ("unix".equals(address.getType())) + doUnix(address); + else if ("tcp".equals(address.getType())) + doTCP(address); + else throw new Exception("Unknown address type: "+address.getType()); + if (Debug.debug) Debug.print(Debug.DEBUG, "exit"); + } + private static void doUnix(BusAddress address) throws IOException + { + if (Debug.debug) Debug.print(Debug.DEBUG, "enter"); + UnixServerSocket uss; + if (null != address. getParameter("abstract")) + uss = new UnixServerSocket(new UnixSocketAddress(address.getParameter("abstract"), true)); + else + uss = new UnixServerSocket(new UnixSocketAddress(address.getParameter("path"), false)); + DBusDaemon d = new DBusDaemon(); + d.start(); + d.sender.start(); + d.dbus_server.start(); + + // accept new connections + while (d._run) { + UnixSocket s = uss.accept(); + if ((new Transport.SASL()).auth(Transport.SASL.MODE_SERVER, Transport.SASL.AUTH_EXTERNAL, address.getParameter("guid"), s.getOutputStream(), s.getInputStream(), s)) { + // s.setBlocking(false); + d.addSock(s); + } else + s.close(); + } + if (Debug.debug) Debug.print(Debug.DEBUG, "exit"); + } + private static void doTCP(BusAddress address) throws IOException + { + if (Debug.debug) Debug.print(Debug.DEBUG, "enter"); + ServerSocket ss = new ServerSocket(Integer.parseInt(address.getParameter("port")),10, InetAddress.getByName(address.getParameter("host"))); + DBusDaemon d = new DBusDaemon(); + d.start(); + d.sender.start(); + d.dbus_server.start(); + + // accept new connections + while (d._run) { + Socket s = ss.accept(); + boolean authOK=false; + try { + authOK = (new Transport.SASL()).auth(Transport.SASL.MODE_SERVER, Transport.SASL.AUTH_EXTERNAL, address.getParameter("guid"), s.getOutputStream(), s.getInputStream(), null); + } catch (Exception e) { + if (Debug.debug) Debug. print(Debug.DEBUG, e); + } + if (authOK) { + d.addSock(s); + } else + s.close(); + } + if (Debug.debug) Debug.print(Debug.DEBUG, "exit"); + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/IdentifierMangler.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/IdentifierMangler.java new file mode 100755 index 0000000..db596f4 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/IdentifierMangler.java @@ -0,0 +1,43 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.bin; + +import java.util.Arrays; + +/** + * Checks identifiers for keywords etc and mangles them if so. + */ +public class IdentifierMangler +{ + private static String[] keywords; + static { + keywords = new String[] { + "true","false","null", + "abstract","continue","for","new","switch", + "assert","default","goto","package","synchronized", + "boolean","do","if","private","this", + "break","double","implements","protected","throw", + "byte","else","import","public","throws", + "case","enum","instanceof","return","transient", + "catch","extends","int","short","try", + "char","final","interface","static","void", + "class","finally","long","strictfp","volatile", + "const","float","native","super","while" + }; + Arrays.sort(keywords); + } + public static String mangle(String name) + { + if (Arrays.binarySearch(keywords, name) >= 0) + name = "_"+name; + return name; + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/IterableNodeList.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/IterableNodeList.java new file mode 100755 index 0000000..ddd5884 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/IterableNodeList.java @@ -0,0 +1,29 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.bin; + +import java.util.Iterator; + +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +class IterableNodeList implements Iterable<Node> +{ + private NodeList nl; + public IterableNodeList(NodeList nl) + { + this.nl = nl; + } + public Iterator<Node> iterator() + { + return new NodeListIterator(nl); + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/ListDBus.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/ListDBus.java new file mode 100755 index 0000000..93d4ad5 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/ListDBus.java @@ -0,0 +1,74 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.bin; + +import org.freedesktop.DBus; +import org.freedesktop.dbus.DBusConnection; +import org.freedesktop.dbus.exceptions.DBusExecutionException; + +/** + * This class lists all the names currently connected on the bus + */ +public class ListDBus +{ + public static void syntax() + { + System.out.println("Syntax: ListDBus [--version] [-v] [--help] [-h] [--owners] [-o] [--uids] [-u] [--session] [-s] [--system] [-y]"); + System.exit(1); + } + public static void version() + { + System.out.println("Java D-Bus Version "+System.getProperty("Version")); + System.exit(1); + } + public static void main(String args[]) throws Exception + { + boolean owners = false; + boolean users = false; + int connection = DBusConnection.SESSION; + + for (String a: args) + if ("--help".equals(a)) syntax(); + else if ("-h".equals(a)) syntax(); + else if ("--version".equals(a)) version(); + else if ("-v".equals(a)) version(); + else if ("-u".equals(a)) users = true; + else if ("--uids".equals(a)) users = true; + else if ("-o".equals(a)) owners = true; + else if ("--owners".equals(a)) owners = true; + else if ("--session".equals(a)) connection = DBusConnection.SESSION; + else if ("-s".equals(a)) connection = DBusConnection.SESSION; + else if ("--system".equals(a)) connection = DBusConnection.SYSTEM; + else if ("-y".equals(a)) connection = DBusConnection.SYSTEM; + else syntax(); + + DBusConnection conn = DBusConnection.getConnection(connection); + DBus dbus = conn.getRemoteObject("org.freedesktop.DBus", "/org/freedesktop/DBus", DBus.class); + String[] names = dbus.ListNames(); + for (String s: names) { + if (users) + try { + System.out.print(dbus.GetConnectionUnixUser(s)+"\t"); + } catch (DBusExecutionException DBEe) { + System.out.print("\t"); + } + System.out.print(s); + if (!s.startsWith(":") && owners) { + try { + System.out.print("\t"+dbus.GetNameOwner(s)); + } catch (DBusExecutionException DBEe) { + } + } + System.out.println(); + } + conn.disconnect(); + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/NodeListIterator.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/NodeListIterator.java new file mode 100755 index 0000000..ea2d23a --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/NodeListIterator.java @@ -0,0 +1,38 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.bin; + +import java.util.Iterator; + +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +class NodeListIterator implements Iterator<Node> +{ + NodeList nl; + int i; + NodeListIterator(NodeList nl) + { + this.nl = nl; + i = 0; + } + public boolean hasNext() + { + return i < nl.getLength(); + } + public Node next() + { + Node n = nl.item(i); + i++; + return n; + } + public void remove() {}; +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/StructStruct.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/StructStruct.java new file mode 100755 index 0000000..f302f6d --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/bin/StructStruct.java @@ -0,0 +1,54 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.bin; + +import java.lang.reflect.Type; +import java.util.Map; +import java.util.HashMap; + +class StructStruct +{ + public static Map<StructStruct, Type[]> fillPackages(Map<StructStruct, Type[]> structs, String pack) + { + Map<StructStruct, Type[]> newmap = new HashMap<StructStruct, Type[]>(); + for (StructStruct ss: structs.keySet()) { + Type[] type = structs.get(ss); + if (null == ss.pack) ss.pack = pack; + newmap.put(ss, type); + } + return newmap; + } + public String name; + public String pack; + public StructStruct(String name) + { + this.name = name; + } + public StructStruct(String name, String pack) + { + this.name = name; + this.pack = pack; + } + public int hashCode() + { + return name.hashCode(); + } + public boolean equals(Object o) + { + if (!(o instanceof StructStruct)) return false; + if (!name.equals(((StructStruct) o).name)) return false; + return true; + } + public String toString() + { + return "<"+name+", "+pack+">"; + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/DBusException.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/DBusException.java new file mode 100755 index 0000000..15f46d0 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/DBusException.java @@ -0,0 +1,26 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.exceptions; + +/** + * An exception within DBus. + */ +@SuppressWarnings("serial") +public class DBusException extends Exception +{ + /** + * Create an exception with the specified message + */ + public DBusException(String message) + { + super(message); + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/DBusExecutionException.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/DBusExecutionException.java new file mode 100755 index 0000000..7dd54fd --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/DBusExecutionException.java @@ -0,0 +1,40 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.exceptions; + +/** + * An exception while running a remote method within DBus. + */ +@SuppressWarnings("serial") +public class DBusExecutionException extends RuntimeException +{ + private String type; + /** + * Create an exception with the specified message + */ + public DBusExecutionException(String message) + { + super(message); + } + public void setType(String type) + { + this.type = type; + } + /** + * Get the DBus type of this exception. Use if this + * was an exception we don't have a class file for. + */ + public String getType() + { + if (null == type) return getClass().getName(); + else return type; + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/FatalDBusException.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/FatalDBusException.java new file mode 100755 index 0000000..6f8d401 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/FatalDBusException.java @@ -0,0 +1,20 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.exceptions; + +@SuppressWarnings("serial") +public class FatalDBusException extends DBusException implements FatalException +{ + public FatalDBusException(String message) + { + super(message); + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/FatalException.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/FatalException.java new file mode 100755 index 0000000..d69efa5 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/FatalException.java @@ -0,0 +1,15 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.exceptions; + +public interface FatalException +{ +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/InternalMessageException.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/InternalMessageException.java new file mode 100755 index 0000000..4113bca --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/InternalMessageException.java @@ -0,0 +1,20 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.exceptions; + +@SuppressWarnings("serial") +public class InternalMessageException extends DBusExecutionException implements NonFatalException +{ + public InternalMessageException(String message) + { + super (message); + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/MarshallingException.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/MarshallingException.java new file mode 100755 index 0000000..cf60d3b --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/MarshallingException.java @@ -0,0 +1,20 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.exceptions; + +@SuppressWarnings("serial") +public class MarshallingException extends DBusException implements NonFatalException +{ + public MarshallingException(String message) + { + super(message); + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/MessageFormatException.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/MessageFormatException.java new file mode 100755 index 0000000..b7efcf7 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/MessageFormatException.java @@ -0,0 +1,23 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.exceptions; + +/** + * Thrown if a message is formatted incorrectly. + */ +@SuppressWarnings("serial") +public class MessageFormatException extends DBusException implements NonFatalException +{ + public MessageFormatException(String message) + { + super (message); + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/MessageProtocolVersionException.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/MessageProtocolVersionException.java new file mode 100755 index 0000000..9f6e44e --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/MessageProtocolVersionException.java @@ -0,0 +1,22 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.exceptions; + +import java.io.IOException; + +@SuppressWarnings("serial") +public class MessageProtocolVersionException extends IOException implements FatalException +{ + public MessageProtocolVersionException(String message) + { + super(message); + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/MessageTypeException.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/MessageTypeException.java new file mode 100755 index 0000000..b36f30e --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/MessageTypeException.java @@ -0,0 +1,22 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.exceptions; + +import java.io.IOException; + +@SuppressWarnings("serial") +public class MessageTypeException extends IOException implements NonFatalException +{ + public MessageTypeException(String message) + { + super(message); + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/NonFatalException.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/NonFatalException.java new file mode 100755 index 0000000..dc565f2 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/NonFatalException.java @@ -0,0 +1,15 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.exceptions; + +public interface NonFatalException +{ +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/NotConnected.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/NotConnected.java new file mode 100755 index 0000000..71b8d44 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/NotConnected.java @@ -0,0 +1,23 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.exceptions; + +/** + * Thrown if a DBus action is called when not connected to the Bus. + */ +@SuppressWarnings("serial") +public class NotConnected extends DBusExecutionException implements FatalException +{ + public NotConnected(String message) + { + super (message); + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/UnknownTypeCodeException.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/UnknownTypeCodeException.java new file mode 100755 index 0000000..9441e70 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/exceptions/UnknownTypeCodeException.java @@ -0,0 +1,21 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.exceptions; +import static org.freedesktop.dbus.Gettext._; + +@SuppressWarnings("serial") +public class UnknownTypeCodeException extends DBusException implements NonFatalException +{ + public UnknownTypeCodeException(byte code) + { + super(_("Not a valid D-Bus type code: ") + code); + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/ProfileStruct.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/ProfileStruct.java new file mode 100755 index 0000000..9fa963b --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/ProfileStruct.java @@ -0,0 +1,32 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.test; + +import org.freedesktop.dbus.Position; +import org.freedesktop.dbus.Struct; +import org.freedesktop.dbus.UInt32; + +public final class ProfileStruct extends Struct +{ + @Position(0) + public final String a; + @Position(1) + public final UInt32 b; + @Position(2) + public final long c; + + public ProfileStruct(String a, UInt32 b, long c) + { + this.a = a; + this.b = b; + this.c = c; + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/Profiler.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/Profiler.java new file mode 100755 index 0000000..efe9ab2 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/Profiler.java @@ -0,0 +1,40 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.test; + +import org.freedesktop.DBus.Method.NoReply; +import org.freedesktop.dbus.DBusInterface; +import org.freedesktop.dbus.DBusSignal; +import org.freedesktop.dbus.exceptions.DBusException; +import java.util.List; +import java.util.Map; + +public interface Profiler extends DBusInterface +{ + public class ProfileSignal extends DBusSignal + { + public ProfileSignal(String path) throws DBusException + { + super(path); + } + } + public void array(int[] v); + public void stringarray(String[] v); + public void map(Map<String,String> m); + public void list(List<String> l); + public void bytes(byte[] b); + public void struct(ProfileStruct ps); + public void string(String s); + public void NoReply(); + public void Pong(); +} + + diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/ProfilerInstance.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/ProfilerInstance.java new file mode 100755 index 0000000..b99d1b7 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/ProfilerInstance.java @@ -0,0 +1,28 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.test; + +import java.util.List; +import java.util.Map; + +public class ProfilerInstance implements Profiler +{ + public boolean isRemote() { return false; } + public void array(int[] v) { return; } + public void stringarray(String[] v) { return; } + public void map(Map<String,String> m) { return; } + public void list(List<String> l) { return; } + public void bytes(byte[] b) { return; } + public void struct(ProfileStruct ps) { return; } + public void string(String s) { return; } + public void NoReply() { return; } + public void Pong() { return; } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestException.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestException.java new file mode 100755 index 0000000..2314ec3 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestException.java @@ -0,0 +1,24 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.test; + +import org.freedesktop.DBus.Description; +import org.freedesktop.dbus.exceptions.DBusExecutionException; + +@Description("A test exception to throw over DBus") +@SuppressWarnings("serial") +public class TestException extends DBusExecutionException +{ + public TestException(String message) + { + super (message); + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestNewInterface.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestNewInterface.java new file mode 100755 index 0000000..4199403 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestNewInterface.java @@ -0,0 +1,26 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.test; + +import org.freedesktop.dbus.DBusInterface; +import org.freedesktop.DBus.Description; + +/** + * A sample remote interface which exports one method. + */ +public interface TestNewInterface extends DBusInterface +{ + /** + * A simple method with no parameters which returns a String + */ + @Description("Simple test method") + public String getName(); +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestRemoteInterface.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestRemoteInterface.java new file mode 100755 index 0000000..a24ef43 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestRemoteInterface.java @@ -0,0 +1,57 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.test; + +import org.freedesktop.dbus.DBusInterface; +import org.freedesktop.dbus.Path; +import org.freedesktop.dbus.UInt16; +import org.freedesktop.DBus.Description; +import org.freedesktop.DBus.Method; + +import java.lang.reflect.Type; + +import java.util.Map; +import java.util.List; +/** + * A sample remote interface which exports one method. + */ +public interface TestRemoteInterface extends DBusInterface +{ + /** + * A simple method with no parameters which returns a String + */ + @Description("Simple test method") + public String getName(); + public String getNameAndThrow(); + @Description("Test of nested maps") + public <T> int frobnicate(List<Long> n, Map<String,Map<UInt16,Short>> m, T v); + @Description("Throws a TestException when called") + public void throwme() throws TestException; + @Description("Waits then doesn't return") + @Method.NoReply() + public void waitawhile(); + @Description("Interface-overloaded method") + public int overload(); + @Description("Testing Type Signatures") + public void sig(Type[] s); + @Description("Testing object paths as Path objects") + public void newpathtest(Path p); + @Description("Testing the float type") + public float testfloat(float[] f); + @Description("Testing structs of structs") + public int[][] teststructstruct(TestStruct3 in); + @Description("Regression test for #13291") + public void reg13291(byte[] as, byte[] bs); + /* test lots of things involving Path */ + public Path pathrv(Path a); + public List<Path> pathlistrv(List<Path> a); + public Map<Path,Path> pathmaprv(Map<Path,Path> a); +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestRemoteInterface2.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestRemoteInterface2.java new file mode 100755 index 0000000..a44d627 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestRemoteInterface2.java @@ -0,0 +1,54 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.test; + +import org.freedesktop.dbus.DBusInterface; +import org.freedesktop.dbus.DBusInterfaceName; +import org.freedesktop.dbus.DBusMemberName; +import org.freedesktop.dbus.Variant; +import org.freedesktop.DBus.Description; + +import java.util.List; + +@Description("An example remote interface") +@DBusInterfaceName("org.freedesktop.dbus.test.AlternateTestInterface") +public interface TestRemoteInterface2 extends DBusInterface +{ + @Description("Test multiple return values and implicit variant parameters.") + public <A> TestTuple<String,List<Integer>,Boolean> show(A in); + @Description("Test passing structs and explicit variants, returning implicit variants") + public <T> T dostuff(TestStruct foo); + @Description("Test arrays, boxed arrays and lists.") + public List<Integer> sampleArray(List<String> l, Integer[] is, long[] ls); + @Description("Test passing objects as object paths.") + public DBusInterface getThis(DBusInterface t); + @Description("Test bools work") + @DBusMemberName("checkbool") + public boolean check(); + @Description("Test Serializable Object") + public TestSerializable<String> testSerializable(byte b, TestSerializable<String> s, int i); + @Description("Call another method on itself from within a call") + public String recursionTest(); + @Description("Parameter-overloaded method (string)") + public int overload(String s); + @Description("Parameter-overloaded method (byte)") + public int overload(byte b); + @Description("Parameter-overloaded method (void)") + public int overload(); + @Description("Nested List Check") + public List<List<Integer>> checklist(List<List<Integer>> lli); + @Description("Get new objects as object paths.") + public TestNewInterface getNew(); + @Description("Test Complex Variants") + public void complexv(Variant<? extends Object> v); + @Description("Test Introspect on a different interface") + public String Introspect(); +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestSerializable.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestSerializable.java new file mode 100755 index 0000000..8014299 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestSerializable.java @@ -0,0 +1,48 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.test; + +import java.util.List; +import java.util.Vector; + +import org.freedesktop.dbus.DBusSerializable; +import org.freedesktop.dbus.exceptions.DBusException; + +public class TestSerializable<A> implements DBusSerializable +{ + private int a; + private String b; + private Vector<Integer> c; + public TestSerializable(int a, A b, Vector<Integer> c) + { + this.a = a; + this.b = b.toString(); + this.c = c; + } + public TestSerializable() {} + public void deserialize(int a, String b, List<Integer> c) + { + this.a = a; + this.b = b; + this.c = new Vector<Integer>(c); + } + public Object[] serialize() throws DBusException + { + return new Object[] { a, b, c }; + } + public int getInt() { return a; } + public String getString() { return b; } + public Vector<Integer> getVector() { return c; } + public String toString() + { + return "TestSerializable{"+a+","+b+","+c+"}"; + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestSignalInterface.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestSignalInterface.java new file mode 100755 index 0000000..406ce36 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestSignalInterface.java @@ -0,0 +1,97 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.test; + +import org.freedesktop.DBus.Description; +import org.freedesktop.dbus.DBusInterface; +import org.freedesktop.dbus.DBusMemberName; +import org.freedesktop.dbus.DBusSignal; +import org.freedesktop.dbus.Path; +import org.freedesktop.dbus.UInt32; +import org.freedesktop.dbus.exceptions.DBusException; + +import java.util.List; +import java.util.Map; + +/** + * A sample signal with two parameters + */ +@Description("Test interface containing signals") +public interface TestSignalInterface extends DBusInterface +{ + @Description("Test basic signal") + public static class TestSignal extends DBusSignal + { + public final String value; + public final UInt32 number; + /** + * Create a signal. + */ + public TestSignal(String path, String value, UInt32 number) throws DBusException + { + super(path, value, number); + this.value = value; + this.number = number; + } + } + public static class StringSignal extends DBusSignal + { + public final String aoeu; + public StringSignal(String path, String aoeu) throws DBusException + { + super(path, aoeu); + this.aoeu = aoeu; + } + } + public static class EmptySignal extends DBusSignal + { + public EmptySignal(String path) throws DBusException + { + super(path); + } + } + @Description("Test signal with arrays") + public static class TestArraySignal extends DBusSignal + { + public final List<TestStruct2> v; + public final Map<UInt32, TestStruct2> m; + public TestArraySignal(String path, List<TestStruct2> v, Map<UInt32, TestStruct2> m) throws DBusException + { + super(path, v, m); + this.v = v; + this.m = m; + } + } + @Description("Test signal sending an object path") + @DBusMemberName("TestSignalObject") + public static class TestObjectSignal extends DBusSignal + { + public final DBusInterface otherpath; + public TestObjectSignal(String path, DBusInterface otherpath) throws DBusException + { + super(path, otherpath); + this.otherpath = otherpath; + } + } + public static class TestPathSignal extends DBusSignal + { + public final Path otherpath; + public final List<Path> pathlist; + public final Map<Path,Path> pathmap; + public TestPathSignal(String path, Path otherpath, List<Path> pathlist, Map<Path,Path> pathmap) throws DBusException + { + super(path, otherpath, pathlist, pathmap); + this.otherpath = otherpath; + this.pathlist = pathlist; + this.pathmap = pathmap; + } + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestSignalInterface2.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestSignalInterface2.java new file mode 100755 index 0000000..d5c9ac5 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestSignalInterface2.java @@ -0,0 +1,45 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.test; + +import org.freedesktop.DBus.Description; +import org.freedesktop.dbus.DBusInterface; +import org.freedesktop.dbus.DBusInterfaceName; +import org.freedesktop.dbus.DBusMemberName; +import org.freedesktop.dbus.DBusSignal; +import org.freedesktop.dbus.UInt32; +import org.freedesktop.dbus.exceptions.DBusException; + +import java.util.List; + +/** + * A sample signal with two parameters + */ +@Description("Test interface containing signals") +@DBusInterfaceName("some.other.interface.Name") +public interface TestSignalInterface2 extends DBusInterface +{ + @Description("Test basic signal") + public static class TestRenamedSignal extends DBusSignal + { + public final String value; + public final UInt32 number; + /** + * Create a signal. + */ + public TestRenamedSignal(String path, String value, UInt32 number) throws DBusException + { + super(path, value, number); + this.value = value; + this.number = number; + } + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestStruct.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestStruct.java new file mode 100755 index 0000000..ca5deac --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestStruct.java @@ -0,0 +1,32 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.test; + +import org.freedesktop.dbus.Position; +import org.freedesktop.dbus.Struct; +import org.freedesktop.dbus.UInt32; +import org.freedesktop.dbus.Variant; + +public final class TestStruct extends Struct +{ + @Position(0) + public final String a; + @Position(1) + public final UInt32 b; + @Position(2) + public final Variant<? extends Object> c; + public TestStruct(String a, UInt32 b, Variant<? extends Object> c) + { + this.a = a; + this.b = b; + this.c = c; + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestStruct2.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestStruct2.java new file mode 100755 index 0000000..5c8797b --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestStruct2.java @@ -0,0 +1,31 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.test; + +import org.freedesktop.dbus.Position; +import org.freedesktop.dbus.Struct; +import org.freedesktop.dbus.Variant; +import org.freedesktop.dbus.exceptions.DBusException; + +import java.util.List; + +public final class TestStruct2 extends Struct +{ + @Position(0) + public final List<String> a; + @Position(1) + public final Variant<? extends Object> b; + public TestStruct2(List<String> a, Variant<? extends Object> b) throws DBusException + { + this.a = a; + this.b = b; + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestStruct3.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestStruct3.java new file mode 100755 index 0000000..52edbe0 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestStruct3.java @@ -0,0 +1,30 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.test; + +import org.freedesktop.dbus.Position; +import org.freedesktop.dbus.Struct; +import org.freedesktop.dbus.exceptions.DBusException; + +import java.util.List; + +public final class TestStruct3 extends Struct +{ + @Position(0) + public final TestStruct2 a; + @Position(1) + public final List<List<Integer>> b; + public TestStruct3(TestStruct2 a, List<List<Integer>> b) throws DBusException + { + this.a = a; + this.b = b; + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestTuple.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestTuple.java new file mode 100755 index 0000000..1cf507a --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TestTuple.java @@ -0,0 +1,30 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.test; + +import org.freedesktop.dbus.Position; +import org.freedesktop.dbus.Tuple; + +public final class TestTuple<A,B,C> extends Tuple +{ + @Position(0) + public final A a; + @Position(1) + public final B b; + @Position(2) + public final C c; + public TestTuple(A a, B b, C c) + { + this.a = a; + this.b = b; + this.c = c; + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TwoPartInterface.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TwoPartInterface.java new file mode 100755 index 0000000..af214cf --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TwoPartInterface.java @@ -0,0 +1,29 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.test; + +import org.freedesktop.dbus.DBusInterface; +import org.freedesktop.dbus.DBusSignal; +import org.freedesktop.dbus.exceptions.DBusException; + +public interface TwoPartInterface extends DBusInterface +{ + public TwoPartObject getNew(); + public class TwoPartSignal extends DBusSignal + { + public final TwoPartObject o; + public TwoPartSignal(String path, TwoPartObject o) throws DBusException + { + super (path, o); + this.o = o; + } + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TwoPartObject.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TwoPartObject.java new file mode 100755 index 0000000..3c7237b --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/TwoPartObject.java @@ -0,0 +1,18 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.test; + +import org.freedesktop.dbus.DBusInterface; + +public interface TwoPartObject extends DBusInterface +{ + public String getName(); +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/cross_test_client.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/cross_test_client.java new file mode 100755 index 0000000..af0d053 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/cross_test_client.java @@ -0,0 +1,512 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.test; + +import java.lang.reflect.Array; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.Set; +import java.util.TreeSet; +import java.util.Vector; + +import org.freedesktop.DBus; +import org.freedesktop.dbus.DBusConnection; +import org.freedesktop.dbus.DBusInterface; +import org.freedesktop.dbus.DBusSigHandler; +import org.freedesktop.dbus.Struct; +import org.freedesktop.dbus.UInt16; +import org.freedesktop.dbus.UInt32; +import org.freedesktop.dbus.UInt64; +import org.freedesktop.dbus.Variant; +import org.freedesktop.dbus.exceptions.DBusException; +import org.freedesktop.dbus.exceptions.DBusExecutionException; +import org.freedesktop.dbus.types.DBusMapType; + +import cx.ath.matthew.debug.Debug; + +public class cross_test_client implements DBus.Binding.TestClient, DBusSigHandler<DBus.Binding.TestSignals.Triggered> +{ + private DBusConnection conn; + private static Set<String> passed = new TreeSet<String>(); + private static Map<String, List<String>> failed = new HashMap<String, List<String>>(); + private static cross_test_client ctc; + static { + List<String> l = new Vector<String>(); + l.add("Signal never arrived"); + failed.put("org.freedesktop.DBus.Binding.TestSignals.Triggered", l); + l = new Vector<String>(); + l.add("Method never called"); + failed.put("org.freedesktop.DBus.Binding.TestClient.Response", l); + } + public cross_test_client(DBusConnection conn) + { + this.conn = conn; + } + public boolean isRemote() { return false; } + public void handle(DBus.Binding.TestSignals.Triggered t) + { + failed.remove("org.freedesktop.DBus.Binding.TestSignals.Triggered"); + if (new UInt64(21389479283L).equals(t.a) && "/Test".equals(t.getPath())) + pass("org.freedesktop.DBus.Binding.TestSignals.Triggered"); + else if (!new UInt64(21389479283L).equals(t.a)) + fail("org.freedesktop.DBus.Binding.TestSignals.Triggered", "Incorrect signal content; expected 21389479283 got "+t.a); + else if (!"/Test".equals(t.getPath())) + fail("org.freedesktop.DBus.Binding.TestSignals.Triggered", "Incorrect signal source object; expected /Test got "+t.getPath()); + } + public void Response(UInt16 a, double b) + { + failed.remove("org.freedesktop.DBus.Binding.TestClient.Response"); + if (a.equals(new UInt16(15)) && (b == 12.5)) + pass("org.freedesktop.DBus.Binding.TestClient.Response"); + else + fail("org.freedesktop.DBus.Binding.TestClient.Response", "Incorrect parameters; expected 15, 12.5 got "+a+", "+b); + } + public static void pass(String test) + { + passed.add(test.replaceAll("[$]", ".")); + } + public static void fail(String test, String reason) + { + test = test.replaceAll("[$]", "."); + List<String> reasons = failed.get(test); + if (null == reasons) { + reasons = new Vector<String>(); + failed.put(test, reasons); + } + reasons.add(reason); + } + @SuppressWarnings("unchecked") + public static void test(Class<? extends DBusInterface> iface, Object proxy, String method, Object rv, Object... parameters) + { + try { + Method[] ms = iface.getMethods(); + Method m = null; + for (Method t: ms) { + if (t.getName().equals(method)) + m = t; + } + Object o = m.invoke(proxy, parameters); + + String msg = "Incorrect return value; sent ( "; + if (null != parameters) + for (Object po: parameters) + if (null != po) + msg += collapseArray(po) + ","; + msg = msg.replaceAll(".$",");"); + msg += " expected "+collapseArray(rv)+" got "+collapseArray(o); + + if (null != rv && rv.getClass().isArray()) { + compareArray(iface.getName()+"."+method, rv,o); + } else if (rv instanceof Map) { + if (o instanceof Map) { + Map<Object,Object> a = (Map<Object,Object>) o; + Map<Object,Object> b = (Map<Object,Object>) rv; + if (a.keySet().size() != b.keySet().size()) { + fail(iface.getName()+"."+method, msg); + } else for (Object k: a.keySet()) + if (a.get(k) instanceof List) { + if (b.get(k) instanceof List) + if (setCompareLists((List<Object>) a.get(k), (List<Object>) b.get(k))) + ; + else + fail(iface.getName()+"."+method, msg); + else + fail(iface.getName()+"."+method, msg); + } else if (!a.get(k).equals(b.get(k))) { + fail(iface.getName()+"."+method, msg); + return; + } + pass(iface.getName()+"."+method); + } else + fail(iface.getName()+"."+method, msg); + } else { + if (o == rv || (o != null && o.equals(rv))) + pass(iface.getName()+"."+method); + else + fail(iface.getName()+"."+method, msg); + } + } catch (DBusExecutionException DBEe) { + DBEe.printStackTrace(); + fail(iface.getName()+"."+method, "Error occurred during execution: "+DBEe.getClass().getName()+" "+DBEe.getMessage()); + } catch (InvocationTargetException ITe) { + ITe.printStackTrace(); + fail(iface.getName()+"."+method, "Error occurred during execution: "+ITe.getCause().getClass().getName()+" "+ITe.getCause().getMessage()); + } catch (Exception e) { + e.printStackTrace(); + fail(iface.getName()+"."+method, "Error occurred during execution: "+e.getClass().getName()+" "+e.getMessage()); + } + } + @SuppressWarnings("unchecked") + public static String collapseArray(Object array) + { + if (null == array) return "null"; + if (array.getClass().isArray()) { + String s = "{ "; + for (int i = 0; i < Array.getLength(array); i++) + s += collapseArray(Array.get(array, i))+","; + s = s.replaceAll(".$"," }"); + return s; + } else if (array instanceof List) { + String s = "{ "; + for (Object o: (List<Object>) array) + s += collapseArray(o)+","; + s = s.replaceAll(".$"," }"); + return s; + } else if (array instanceof Map) { + String s = "{ "; + for (Object o: ((Map<Object,Object>) array).keySet()) + s += collapseArray(o)+" => "+collapseArray(((Map<Object,Object>) array).get(o))+","; + s = s.replaceAll(".$"," }"); + return s; + } else return array.toString(); + } + public static <T> boolean setCompareLists(List<T> a, List<T> b) + { + if (a.size() != b.size()) return false; + for (Object v: a) + if (!b.contains(v)) return false; + return true; + } + @SuppressWarnings("unchecked") + public static List<Variant<Object>> PrimitizeRecurse(Object a, Type t) + { + List<Variant<Object>> vs = new Vector<Variant<Object>>(); + if (t instanceof ParameterizedType) { + Class<Object> c = (Class<Object>) ((ParameterizedType) t).getRawType(); + if (List.class.isAssignableFrom(c)) { + Object os; + if (a instanceof List) + os = ((List<Object>) a).toArray(); + else + os = a; + Type[] ts = ((ParameterizedType) t).getActualTypeArguments(); + for (int i = 0; i < Array.getLength(os); i++) + vs.addAll(PrimitizeRecurse(Array.get(os, i), ts[0])); + } else if (Map.class.isAssignableFrom(c)) { + Object[] os = ((Map) a).keySet().toArray(); + Object[] ks = ((Map) a).values().toArray(); + Type[] ts = ((ParameterizedType) t).getActualTypeArguments(); + for (int i = 0; i < ks.length; i++) + vs.addAll(PrimitizeRecurse(ks[i], ts[0])); + for (int i = 0; i < os.length; i++) + vs.addAll(PrimitizeRecurse(os[i], ts[1])); + } else if (Struct.class.isAssignableFrom(c)) { + Object[] os = ((Struct) a).getParameters(); + Type[] ts = ((ParameterizedType) t).getActualTypeArguments(); + for (int i = 0; i < os.length; i++) + vs.addAll(PrimitizeRecurse(os[i], ts[i])); + + } else if (Variant.class.isAssignableFrom(c)) { + vs.addAll(PrimitizeRecurse(((Variant) a).getValue(), ((Variant) a).getType())); + } + } else if (Variant.class.isAssignableFrom((Class) t)) + vs.addAll(PrimitizeRecurse(((Variant) a).getValue(), ((Variant) a).getType())); + else if (t instanceof Class && ((Class) t).isArray()) { + Type t2 = ((Class) t).getComponentType(); + for (int i = 0; i < Array.getLength(a); i++) + vs.addAll(PrimitizeRecurse(Array.get(a, i), t2)); + } + else vs.add(new Variant(a)); + + return vs; + } + + @SuppressWarnings("unchecked") + public static List<Variant<Object>> Primitize(Variant<Object> a) + { + return PrimitizeRecurse(a.getValue(), a.getType()); + } + + @SuppressWarnings("unchecked") + public static void primitizeTest(DBus.Binding.Tests tests, Object input) + { + Variant<Object> in = new Variant<Object>(input); + List<Variant<Object>> vs = Primitize(in); + List<Variant<Object>> res; + + try { + + res = tests.Primitize(in); + if (setCompareLists(res, vs)) + pass("org.freedesktop.DBus.Binding.Tests.Primitize"); + else + fail("org.freedesktop.DBus.Binding.Tests.Primitize", "Wrong Return Value; expected "+collapseArray(vs)+" got "+collapseArray(res)); + + } catch (Exception e) { + if (Debug.debug) Debug.print(e); + fail("org.freedesktop.DBus.Binding.Tests.Primitize", "Exception occurred during test: ("+e.getClass().getName()+") "+e.getMessage()); + } + } + public static void doTests(DBus.Peer peer, DBus.Introspectable intro, DBus.Introspectable rootintro, DBus.Binding.Tests tests, DBus.Binding.SingleTests singletests) + { + Random r = new Random(); + int i; + test(DBus.Peer.class, peer, "Ping", null); + + try { if (intro.Introspect().startsWith("<!DOCTYPE")) pass("org.freedesktop.DBus.Introspectable.Introspect"); + else fail("org.freedesktop.DBus.Introspectable.Introspect", "Didn't get valid xml data back when introspecting /Test"); + } catch (DBusExecutionException DBEe) { + if (Debug.debug) Debug.print(DBEe); + fail("org.freedesktop.DBus.Introspectable.Introspect", "Got exception during introspection on /Test ("+DBEe.getClass().getName()+"): "+DBEe.getMessage()); + } + + try { if (rootintro.Introspect().startsWith("<!DOCTYPE")) pass("org.freedesktop.DBus.Introspectable.Introspect"); + else fail("org.freedesktop.DBus.Introspectable.Introspect", "Didn't get valid xml data back when introspecting /"); + } catch (DBusExecutionException DBEe) { + if (Debug.debug) Debug.print(DBEe); + fail("org.freedesktop.DBus.Introspectable.Introspect", "Got exception during introspection on / ("+DBEe.getClass().getName()+"): "+DBEe.getMessage()); + } + + test(DBus.Binding.Tests.class, tests, "Identity", new Variant<Integer>(new Integer(1)), new Variant<Integer>(new Integer(1))); + test(DBus.Binding.Tests.class, tests, "Identity", new Variant<String>("Hello"), new Variant<String>("Hello")); + + test(DBus.Binding.Tests.class, tests, "IdentityBool", false, false); + test(DBus.Binding.Tests.class, tests, "IdentityBool", true, true); + + test(DBus.Binding.Tests.class, tests, "Invert", false, true); + test(DBus.Binding.Tests.class, tests, "Invert", true, false); + + test(DBus.Binding.Tests.class, tests, "IdentityByte", (byte) 0, (byte) 0); + test(DBus.Binding.Tests.class, tests, "IdentityByte", (byte) 1, (byte) 1); + test(DBus.Binding.Tests.class, tests, "IdentityByte", (byte) -1, (byte) -1); + test(DBus.Binding.Tests.class, tests, "IdentityByte", Byte.MAX_VALUE, Byte.MAX_VALUE); + test(DBus.Binding.Tests.class, tests, "IdentityByte", Byte.MIN_VALUE, Byte.MIN_VALUE); + i = r.nextInt(); + test(DBus.Binding.Tests.class, tests, "IdentityByte", (byte) i, (byte) i); + + test(DBus.Binding.Tests.class, tests, "IdentityInt16", (short) 0, (short) 0); + test(DBus.Binding.Tests.class, tests, "IdentityInt16", (short) 1, (short) 1); + test(DBus.Binding.Tests.class, tests, "IdentityInt16", (short) -1, (short) -1); + test(DBus.Binding.Tests.class, tests, "IdentityInt16", Short.MAX_VALUE, Short.MAX_VALUE); + test(DBus.Binding.Tests.class, tests, "IdentityInt16", Short.MIN_VALUE, Short.MIN_VALUE); + i = r.nextInt(); + test(DBus.Binding.Tests.class, tests, "IdentityInt16", (short) i, (short) i); + + test(DBus.Binding.Tests.class, tests, "IdentityInt32", 0, 0); + test(DBus.Binding.Tests.class, tests, "IdentityInt32", 1, 1); + test(DBus.Binding.Tests.class, tests, "IdentityInt32", -1, -1); + test(DBus.Binding.Tests.class, tests, "IdentityInt32", Integer.MAX_VALUE, Integer.MAX_VALUE); + test(DBus.Binding.Tests.class, tests, "IdentityInt32", Integer.MIN_VALUE, Integer.MIN_VALUE); + i = r.nextInt(); + test(DBus.Binding.Tests.class, tests, "IdentityInt32", i, i); + + + test(DBus.Binding.Tests.class, tests, "IdentityInt64", (long) 0, (long) 0); + test(DBus.Binding.Tests.class, tests, "IdentityInt64", (long) 1, (long) 1); + test(DBus.Binding.Tests.class, tests, "IdentityInt64", (long) -1, (long) -1); + test(DBus.Binding.Tests.class, tests, "IdentityInt64", Long.MAX_VALUE, Long.MAX_VALUE); + test(DBus.Binding.Tests.class, tests, "IdentityInt64", Long.MIN_VALUE, Long.MIN_VALUE); + i = r.nextInt(); + test(DBus.Binding.Tests.class, tests, "IdentityInt64", (long) i, (long) i); + + test(DBus.Binding.Tests.class, tests, "IdentityUInt16", new UInt16(0), new UInt16(0)); + test(DBus.Binding.Tests.class, tests, "IdentityUInt16", new UInt16(1), new UInt16(1)); + test(DBus.Binding.Tests.class, tests, "IdentityUInt16", new UInt16(UInt16.MAX_VALUE), new UInt16(UInt16.MAX_VALUE)); + test(DBus.Binding.Tests.class, tests, "IdentityUInt16", new UInt16(UInt16.MIN_VALUE), new UInt16(UInt16.MIN_VALUE)); + i = r.nextInt(); + i = i > 0 ? i : -i; + test(DBus.Binding.Tests.class, tests, "IdentityUInt16", new UInt16(i%UInt16.MAX_VALUE), new UInt16(i%UInt16.MAX_VALUE)); + + test(DBus.Binding.Tests.class, tests, "IdentityUInt32", new UInt32(0), new UInt32(0)); + test(DBus.Binding.Tests.class, tests, "IdentityUInt32", new UInt32(1), new UInt32(1)); + test(DBus.Binding.Tests.class, tests, "IdentityUInt32", new UInt32(UInt32.MAX_VALUE), new UInt32(UInt32.MAX_VALUE)); + test(DBus.Binding.Tests.class, tests, "IdentityUInt32", new UInt32(UInt32.MIN_VALUE), new UInt32(UInt32.MIN_VALUE)); + i = r.nextInt(); + i = i > 0 ? i : -i; + test(DBus.Binding.Tests.class, tests, "IdentityUInt32", new UInt32(i%UInt32.MAX_VALUE), new UInt32(i%UInt32.MAX_VALUE)); + + test(DBus.Binding.Tests.class, tests, "IdentityUInt64", new UInt64(0), new UInt64(0)); + test(DBus.Binding.Tests.class, tests, "IdentityUInt64", new UInt64(1), new UInt64(1)); + test(DBus.Binding.Tests.class, tests, "IdentityUInt64", new UInt64(UInt64.MAX_LONG_VALUE), new UInt64(UInt64.MAX_LONG_VALUE)); + test(DBus.Binding.Tests.class, tests, "IdentityUInt64", new UInt64(UInt64.MAX_BIG_VALUE), new UInt64(UInt64.MAX_BIG_VALUE)); + test(DBus.Binding.Tests.class, tests, "IdentityUInt64", new UInt64(UInt64.MIN_VALUE), new UInt64(UInt64.MIN_VALUE)); + i = r.nextInt(); + i = i > 0 ? i : -i; + test(DBus.Binding.Tests.class, tests, "IdentityUInt64", new UInt64(i%UInt64.MAX_LONG_VALUE), new UInt64(i%UInt64.MAX_LONG_VALUE)); + + test(DBus.Binding.Tests.class, tests, "IdentityDouble", 0.0, 0.0); + test(DBus.Binding.Tests.class, tests, "IdentityDouble", 1.0, 1.0); + test(DBus.Binding.Tests.class, tests, "IdentityDouble", -1.0, -1.0); + test(DBus.Binding.Tests.class, tests, "IdentityDouble", Double.MAX_VALUE, Double.MAX_VALUE); + test(DBus.Binding.Tests.class, tests, "IdentityDouble", Double.MIN_VALUE, Double.MIN_VALUE); + i = r.nextInt(); + test(DBus.Binding.Tests.class, tests, "IdentityDouble", (double) i, (double) i); + + test(DBus.Binding.Tests.class, tests, "IdentityString", "", ""); + test(DBus.Binding.Tests.class, tests, "IdentityString", "The Quick Brown Fox Jumped Over The Lazy Dog", "The Quick Brown Fox Jumped Over The Lazy Dog"); + + testArray(DBus.Binding.Tests.class, tests, "IdentityBoolArray", Boolean.TYPE, null); + testArray(DBus.Binding.Tests.class, tests, "IdentityByteArray", Byte.TYPE, null); + testArray(DBus.Binding.Tests.class, tests, "IdentityInt16Array", Short.TYPE, null); + testArray(DBus.Binding.Tests.class, tests, "IdentityInt32Array", Integer.TYPE, null); + testArray(DBus.Binding.Tests.class, tests, "IdentityInt64Array", Long.TYPE, null); + testArray(DBus.Binding.Tests.class, tests, "IdentityDoubleArray", Double.TYPE, null); + + testArray(DBus.Binding.Tests.class, tests, "IdentityArray", Variant.class, new Variant<String>("aoeu")); + testArray(DBus.Binding.Tests.class, tests, "IdentityUInt16Array", UInt16.class, new UInt16(12)); + testArray(DBus.Binding.Tests.class, tests, "IdentityUInt32Array", UInt32.class, new UInt32(190)); + testArray(DBus.Binding.Tests.class, tests, "IdentityUInt64Array", UInt64.class, new UInt64(103948)); + testArray(DBus.Binding.Tests.class, tests, "IdentityStringArray", String.class, "asdf"); + + int[] is = new int[0]; + test(DBus.Binding.Tests.class, tests, "Sum", 0L, is); + r = new Random(); + int len = (r.nextInt() % 100) + 15; + len = (len<0 ? -len: len)+15; + is = new int[len]; + long result = 0; + for (i = 0; i < len; i++) { + is[i] = r.nextInt(); + result += is[i]; + } + test(DBus.Binding.Tests.class, tests, "Sum", result, is); + + byte[] bs = new byte[0]; + test(DBus.Binding.SingleTests.class, singletests, "Sum", new UInt32(0), bs); + len = (r.nextInt() % 100); + len = (len<0 ? -len: len)+15; + bs = new byte[len]; + int res = 0; + for (i = 0; i < len; i++) { + bs[i] = (byte) r.nextInt(); + res += (bs[i] < 0 ? bs[i]+256 : bs[i]); + } + test(DBus.Binding.SingleTests.class, singletests, "Sum", new UInt32(res % (UInt32.MAX_VALUE+1)), bs); + + test(DBus.Binding.Tests.class, tests, "DeStruct", new DBus.Binding.Triplet<String,UInt32,Short>("hi", new UInt32(12), new Short((short) 99)), new DBus.Binding.TestStruct("hi", new UInt32(12), new Short((short) 99))); + + Map<String, String> in = new HashMap<String, String>(); + Map<String, List<String>> out = new HashMap<String, List<String>>(); + test(DBus.Binding.Tests.class, tests, "InvertMapping", out, in); + + in.put("hi", "there"); + in.put("to", "there"); + in.put("from", "here"); + in.put("in", "out"); + List<String> l = new Vector<String>(); + l.add("hi"); + l.add("to"); + out.put("there", l); + l = new Vector<String>(); + l.add("from"); + out.put("here", l); + l = new Vector<String>(); + l.add("in"); + out.put("out", l); + test(DBus.Binding.Tests.class, tests, "InvertMapping", out, in); + + primitizeTest(tests, new Integer(1)); + primitizeTest(tests, + new Variant<Variant<Variant<Variant<String>>>>( + new Variant<Variant<Variant<String>>>( + new Variant<Variant<String>>( + new Variant<String>("Hi"))))); + primitizeTest(tests, new Variant<Map<String,String>>(in, new DBusMapType(String.class,String.class))); + + test(DBus.Binding.Tests.class, tests, "Trigger", null, "/Test", new UInt64(21389479283L)); + + try { + ctc.conn.sendSignal(new DBus.Binding.TestClient.Trigger("/Test", new UInt16(15), 12.5)); + } catch (DBusException DBe) { + if (Debug.debug) Debug.print(DBe); + throw new DBusExecutionException(DBe.getMessage()); + } + + try { Thread.sleep(10000); } catch (InterruptedException Ie) {} + + test(DBus.Binding.Tests.class, tests, "Exit", null); + } + public static void testArray(Class<? extends DBusInterface> iface, Object proxy, String method, Class<? extends Object> arrayType, Object content) + { + Object array = Array.newInstance(arrayType, 0); + test(iface, proxy, method, array, array); + Random r = new Random(); + int l = (r.nextInt() % 100); + array = Array.newInstance(arrayType, (l < 0 ? -l : l) + 15); + if (null != content) + Arrays.fill((Object[]) array, content); + test(iface, proxy, method, array, array); + } + public static void compareArray(String test, Object a, Object b) + { + if (!a.getClass().equals(b.getClass())) { + fail(test, "Incorrect return type; expected "+a.getClass()+" got "+b.getClass()); + return; + } + boolean pass = false; + + if (a instanceof Object[]) + pass = Arrays.equals((Object[]) a, (Object[]) b); + else if (a instanceof byte[]) + pass = Arrays.equals((byte[]) a, (byte[]) b); + else if (a instanceof boolean[]) + pass = Arrays.equals((boolean[]) a, (boolean[]) b); + else if (a instanceof int[]) + pass = Arrays.equals((int[]) a, (int[]) b); + else if (a instanceof short[]) + pass = Arrays.equals((short[]) a, (short[]) b); + else if (a instanceof long[]) + pass = Arrays.equals((long[]) a, (long[]) b); + else if (a instanceof double[]) + pass = Arrays.equals((double[]) a, (double[]) b); + + if (pass) + pass(test); + else { + String s = "Incorrect return value; expected "; + s += collapseArray(a); + s += " got "; + s += collapseArray(b); + fail(test, s); + } + } + + public static void main(String[] args) + { try { + /* init */ + DBusConnection conn = DBusConnection.getConnection(DBusConnection.SESSION); + ctc = new cross_test_client(conn); + conn.exportObject("/Test", ctc); + conn.addSigHandler(DBus.Binding.TestSignals.Triggered.class, ctc); + DBus.Binding.Tests tests = conn.getRemoteObject("org.freedesktop.DBus.Binding.TestServer", "/Test", DBus.Binding.Tests.class); + DBus.Binding.SingleTests singletests = conn.getRemoteObject("org.freedesktop.DBus.Binding.TestServer", "/Test", DBus.Binding.SingleTests.class); + DBus.Peer peer = conn.getRemoteObject("org.freedesktop.DBus.Binding.TestServer", "/Test", DBus.Peer.class); + DBus.Introspectable intro = conn.getRemoteObject("org.freedesktop.DBus.Binding.TestServer", "/Test", DBus.Introspectable.class); + + DBus.Introspectable rootintro = conn.getRemoteObject("org.freedesktop.DBus.Binding.TestServer", "/", DBus.Introspectable.class); + + doTests(peer, intro, rootintro, tests, singletests); + + /* report results */ + for (String s: passed) + System.out.println(s+" pass"); + int i = 1; + for (String s: failed.keySet()) + for (String r: failed.get(s)) { + System.out.println(s+" fail "+i); + System.out.println("report "+i+": "+r); + i++; + } + + conn.disconnect(); + } catch (DBusException DBe) { + DBe.printStackTrace(); + System.exit(1); + }} +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/cross_test_server.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/cross_test_server.java new file mode 100755 index 0000000..acfb2fa --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/cross_test_server.java @@ -0,0 +1,344 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.test; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.TreeSet; +import java.util.Set; +import java.util.Vector; + +import org.freedesktop.DBus; +import org.freedesktop.dbus.DBusConnection; +import org.freedesktop.dbus.DBusSigHandler; +import org.freedesktop.dbus.UInt16; +import org.freedesktop.dbus.UInt32; +import org.freedesktop.dbus.UInt64; +import org.freedesktop.dbus.Variant; +import org.freedesktop.dbus.exceptions.DBusException; +import org.freedesktop.dbus.exceptions.DBusExecutionException; + +public class cross_test_server implements DBus.Binding.Tests, DBus.Binding.SingleTests, DBusSigHandler<DBus.Binding.TestClient.Trigger> +{ + private DBusConnection conn; + boolean run = true; + private Set<String> done = new TreeSet<String>(); + private Set<String> notdone = new TreeSet<String>(); + { + notdone.add("org.freedesktop.DBus.Binding.Tests.Identity"); + notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityByte"); + notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityBool"); + notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityInt16"); + notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt16"); + notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityInt32"); + notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt32"); + notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityInt64"); + notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt64"); + notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityDouble"); + notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityString"); + notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityArray"); + notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityByteArray"); + notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityBoolArray"); + notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityInt16Array"); + notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt16Array"); + notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityInt32Array"); + notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt32Array"); + notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityInt64Array"); + notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt64Array"); + notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityDoubleArray"); + notdone.add("org.freedesktop.DBus.Binding.Tests.IdentityStringArray"); + notdone.add("org.freedesktop.DBus.Binding.Tests.Sum"); + notdone.add("org.freedesktop.DBus.Binding.SingleTests.Sum"); + notdone.add("org.freedesktop.DBus.Binding.Tests.InvertMapping"); + notdone.add("org.freedesktop.DBus.Binding.Tests.DeStruct"); + notdone.add("org.freedesktop.DBus.Binding.Tests.Primitize"); + notdone.add("org.freedesktop.DBus.Binding.Tests.Invert"); + notdone.add("org.freedesktop.DBus.Binding.Tests.Trigger"); + notdone.add("org.freedesktop.DBus.Binding.Tests.Exit"); + notdone.add("org.freedesktop.DBus.Binding.TestClient.Trigger"); + } + + public cross_test_server(DBusConnection conn) + { + this.conn = conn; + } + public boolean isRemote() { return false; } + @SuppressWarnings("unchecked") + @DBus.Description("Returns whatever it is passed") + public <T> Variant<T> Identity(Variant<T> input) + { + done.add("org.freedesktop.DBus.Binding.Tests.Identity"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.Identity"); + return new Variant(input.getValue()); + } + @DBus.Description("Returns whatever it is passed") + public byte IdentityByte(byte input) + { + done.add("org.freedesktop.DBus.Binding.Tests.IdentityByte"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityByte"); + return input; + } + @DBus.Description("Returns whatever it is passed") + public boolean IdentityBool(boolean input) + { + done.add("org.freedesktop.DBus.Binding.Tests.IdentityBool"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityBool"); + return input; + } + @DBus.Description("Returns whatever it is passed") + public short IdentityInt16(short input) + { + done.add("org.freedesktop.DBus.Binding.Tests.IdentityInt16"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityInt16"); + return input; + } + @DBus.Description("Returns whatever it is passed") + public UInt16 IdentityUInt16(UInt16 input) + { + done.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt16"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityUInt16"); + return input; + } + @DBus.Description("Returns whatever it is passed") + public int IdentityInt32(int input) + { + done.add("org.freedesktop.DBus.Binding.Tests.IdentityInt32"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityInt32"); + return input; + } + @DBus.Description("Returns whatever it is passed") + public UInt32 IdentityUInt32(UInt32 input) + { + done.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt32"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityUInt32"); + return input; + } + @DBus.Description("Returns whatever it is passed") + public long IdentityInt64(long input) + { + done.add("org.freedesktop.DBus.Binding.Tests.IdentityInt64"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityInt64"); + return input; + } + @DBus.Description("Returns whatever it is passed") + public UInt64 IdentityUInt64(UInt64 input) + { + done.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt64"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityUInt64"); + return input; + } + @DBus.Description("Returns whatever it is passed") + public double IdentityDouble(double input) + { + done.add("org.freedesktop.DBus.Binding.Tests.IdentityDouble"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityDouble"); + return input; + } + @DBus.Description("Returns whatever it is passed") + public String IdentityString(String input) + { + done.add("org.freedesktop.DBus.Binding.Tests.IdentityString"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityString"); + return input; + } + @DBus.Description("Returns whatever it is passed") + public <T> Variant<T>[] IdentityArray(Variant<T>[] input) + { + done.add("org.freedesktop.DBus.Binding.Tests.IdentityArray"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityArray"); + return input; + } + @DBus.Description("Returns whatever it is passed") + public byte[] IdentityByteArray(byte[] input) + { + done.add("org.freedesktop.DBus.Binding.Tests.IdentityByteArray"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityByteArray"); + return input; + } + @DBus.Description("Returns whatever it is passed") + public boolean[] IdentityBoolArray(boolean[] input) + { + done.add("org.freedesktop.DBus.Binding.Tests.IdentityBoolArray"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityBoolArray"); + return input; + } + @DBus.Description("Returns whatever it is passed") + public short[] IdentityInt16Array(short[] input) + { + done.add("org.freedesktop.DBus.Binding.Tests.IdentityInt16Array"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityInt16Array"); + return input; + } + @DBus.Description("Returns whatever it is passed") + public UInt16[] IdentityUInt16Array(UInt16[] input) + { + done.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt16Array"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityUInt16Array"); + return input; + } + @DBus.Description("Returns whatever it is passed") + public int[] IdentityInt32Array(int[] input) + { + done.add("org.freedesktop.DBus.Binding.Tests.IdentityInt32Array"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityInt32Array"); + return input; + } + @DBus.Description("Returns whatever it is passed") + public UInt32[] IdentityUInt32Array(UInt32[] input) + { + done.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt32Array"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityUInt32Array"); + return input; + } + @DBus.Description("Returns whatever it is passed") + public long[] IdentityInt64Array(long[] input) + { + done.add("org.freedesktop.DBus.Binding.Tests.IdentityInt64Array"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityInt64Array"); + return input; + } + @DBus.Description("Returns whatever it is passed") + public UInt64[] IdentityUInt64Array(UInt64[] input) + { + done.add("org.freedesktop.DBus.Binding.Tests.IdentityUInt64Array"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityUInt64Array"); + return input; + } + @DBus.Description("Returns whatever it is passed") + public double[] IdentityDoubleArray(double[] input) + { + done.add("org.freedesktop.DBus.Binding.Tests.IdentityDoubleArray"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityDoubleArray"); + return input; + } + @DBus.Description("Returns whatever it is passed") + public String[] IdentityStringArray(String[] input) + { + done.add("org.freedesktop.DBus.Binding.Tests.IdentityStringArray"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.IdentityStringArray"); + return input; + } + @DBus.Description("Returns the sum of the values in the input list") + public long Sum(int[] a) + { + done.add("org.freedesktop.DBus.Binding.Tests.Sum"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.Sum"); + long sum = 0; + for (int b: a) sum += b; + return sum; + } + @DBus.Description("Returns the sum of the values in the input list") + public UInt32 Sum(byte[] a) + { + done.add("org.freedesktop.DBus.Binding.SingleTests.Sum"); + notdone.remove("org.freedesktop.DBus.Binding.SingleTests.Sum"); + int sum = 0; + for (byte b: a) sum += (b < 0 ? b+256 : b); + return new UInt32(sum % (UInt32.MAX_VALUE+1)); + } + @DBus.Description("Given a map of A => B, should return a map of B => a list of all the As which mapped to B") + public Map<String, List<String>> InvertMapping(Map<String, String> a) + { + done.add("org.freedesktop.DBus.Binding.Tests.InvertMapping"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.InvertMapping"); + HashMap<String, List<String>> m = new HashMap<String, List<String>>(); + for (String s: a.keySet()) { + String b = a.get(s); + List<String> l = m.get(b); + if (null == l) { + l = new Vector<String>(); + m.put(b, l); + } + l.add(s); + } + return m; + } + @DBus.Description("This method returns the contents of a struct as separate values") + public DBus.Binding.Triplet<String,UInt32,Short> DeStruct(DBus.Binding.TestStruct a) + { + done.add("org.freedesktop.DBus.Binding.Tests.DeStruct"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.DeStruct"); + return new DBus.Binding.Triplet<String,UInt32,Short>(a.a, a.b, a.c); + } + @DBus.Description("Given any compound type as a variant, return all the primitive types recursively contained within as an array of variants") + @SuppressWarnings("unchecked") + public List<Variant<Object>> Primitize(Variant<Object> a) + { + done.add("org.freedesktop.DBus.Binding.Tests.Primitize"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.Primitize"); + return cross_test_client.PrimitizeRecurse(a.getValue(), a.getType()); + } + @DBus.Description("inverts it's input") + public boolean Invert(boolean a) + { + done.add("org.freedesktop.DBus.Binding.Tests.Invert"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.Invert"); + return !a; + } + @DBus.Description("triggers sending of a signal from the supplied object with the given parameter") + public void Trigger(String a, UInt64 b) + { + done.add("org.freedesktop.DBus.Binding.Tests.Trigger"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.Trigger"); + try { + conn.sendSignal(new DBus.Binding.TestSignals.Triggered(a, b)); + } catch (DBusException DBe) { + throw new DBusExecutionException(DBe.getMessage()); + } + } + public void Exit() + { + done.add("org.freedesktop.DBus.Binding.Tests.Exit"); + notdone.remove("org.freedesktop.DBus.Binding.Tests.Exit"); + run = false; + synchronized (this) { + notifyAll(); + } + } + public void handle(DBus.Binding.TestClient.Trigger t) + { + done.add("org.freedesktop.DBus.Binding.TestClient.Trigger"); + notdone.remove("org.freedesktop.DBus.Binding.TestClient.Trigger"); + try { + DBus.Binding.TestClient cb = conn.getRemoteObject(t.getSource(), "/Test", DBus.Binding.TestClient.class); + cb.Response(t.a, t.b); + } catch (DBusException DBe) { + throw new DBusExecutionException(DBe.getMessage()); + } + } + + public static void main(String[] args) + { try { + DBusConnection conn = DBusConnection.getConnection(DBusConnection.SESSION); + conn.requestBusName("org.freedesktop.DBus.Binding.TestServer"); + cross_test_server cts = new cross_test_server(conn); + conn.addSigHandler(DBus.Binding.TestClient.Trigger.class, cts); + conn.exportObject("/Test", cts); + synchronized (cts) { + while (cts.run) { + try { + cts.wait(); + } catch (InterruptedException Ie) {} + } + } + for (String s: cts.done) + System.out.println(s+" ok"); + for (String s: cts.notdone) + System.out.println(s+" untested"); + conn.disconnect(); + System.exit(0); + } catch (DBusException DBe) { + DBe.printStackTrace(); + System.exit(1); + }} +} + diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/profile.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/profile.java new file mode 100755 index 0000000..f998fa2 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/profile.java @@ -0,0 +1,381 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.test; + +import java.util.Random; +import java.util.HashMap; +import java.util.Vector; + +import org.freedesktop.DBus.Peer; +import org.freedesktop.DBus.Introspectable; +import org.freedesktop.dbus.DBusConnection; +import org.freedesktop.dbus.DBusSigHandler; +import org.freedesktop.dbus.UInt32; + +class ProfileHandler implements DBusSigHandler<Profiler.ProfileSignal> +{ + public int c = 0; + public void handle(Profiler.ProfileSignal s) + { + if (0 == (c++%profile.SIGNAL_INNER)) System.out.print("-"); + } +} + +/** + * Profiling tests. + */ +public class profile +{ + public static final int SIGNAL_INNER = 100; + public static final int SIGNAL_OUTER = 100; + public static final int PING_INNER = 100; + public static final int PING_OUTER = 100; + public static final int BYTES = 2000000; + public static final int INTROSPECTION_OUTER = 100; + public static final int INTROSPECTION_INNER = 10; + public static final int STRUCT_OUTER = 100; + public static final int STRUCT_INNER = 10; + public static final int LIST_OUTER = 100; + public static final int LIST_INNER = 10; + public static final int LIST_LENGTH = 100; + public static final int MAP_OUTER = 100; + public static final int MAP_INNER = 10; + public static final int MAP_LENGTH = 100; + public static final int ARRAY_OUTER = 100; + public static final int ARRAY_INNER = 10; + public static final int ARRAY_LENGTH = 1000; + public static final int STRING_ARRAY_OUTER = 10; + public static final int STRING_ARRAY_INNER = 1; + public static final int STRING_ARRAY_LENGTH = 20000; + + public static class Log + { + private long last; + private int[] deltas; + private int current = 0; + public Log(int size) + { + deltas = new int[size]; + } + public void start() + { + last = System.currentTimeMillis(); + } + public void stop() + { + deltas[current] = (int) (System.currentTimeMillis()-last); + current++; + } + public double mean() + { + if (0 == current) return 0; + long sum = 0; + for (int i = 0; i < current; i++) + sum+=deltas[i]; + return sum /= current; + } + public long min() + { + int m = Integer.MAX_VALUE; + for (int i = 0; i < current; i++) + if (deltas[i] < m) m = deltas[i]; + return m; + } + public long max() + { + int m = 0; + for (int i = 0; i < current; i++) + if (deltas[i] > m) m = deltas[i]; + return m; + } + public double stddev() + { + double mean = mean(); + double sum = 0; + for (int i=0; i < current; i++) + sum += (deltas[i]-mean)*(deltas[i]-mean); + return Math.sqrt(sum / (current-1)); + } + } + public static void main(String[] args) + { + try { + if (0==args.length) { + System.out.println("You must specify a profile type."); + System.out.println("Syntax: profile <pings|arrays|introspect|maps|bytes|lists|structs|signals|rate|strings>"); + System.exit(1); + } + DBusConnection conn = DBusConnection.getConnection(DBusConnection.SESSION); + conn.requestBusName("org.freedesktop.DBus.java.profiler"); + if ("pings".equals(args[0])) { + int count = PING_INNER*PING_OUTER; + System.out.print("Sending "+count+" pings..."); + Peer p = conn.getRemoteObject("org.freedesktop.DBus.java.profiler", "/Profiler", Peer.class); + Log l = new Log(count); + long t = System.currentTimeMillis(); + for (int i = 0; i < PING_OUTER; i++) { + for (int j = 0; j < PING_INNER; j++) { + l.start(); + p.Ping(); + l.stop(); + } + System.out.print("."); + } + t = System.currentTimeMillis()-t; + System.out.println(" done."); + System.out.println("min/max/avg (ms): "+l.min()+"/"+l.max()+"/"+l.mean()); + System.out.println("deviation: "+l.stddev()); + System.out.println("Total time: "+t+"ms"); + } else if ("strings".equals(args[0])) { + int count = STRING_ARRAY_INNER*STRING_ARRAY_OUTER; + System.out.print("Sending array of "+STRING_ARRAY_LENGTH+" strings "+count+" times."); + ProfilerInstance pi = new ProfilerInstance(); + conn.exportObject("/Profiler", pi); + Profiler p = conn.getRemoteObject("org.freedesktop.DBus.java.profiler", "/Profiler", Profiler.class); + String[] v = new String[STRING_ARRAY_LENGTH]; + Random r = new Random(); + for (int i = 0; i < STRING_ARRAY_LENGTH; i++) v[i] = ""+r.nextInt(); + Log l = new Log(count); + long t = System.currentTimeMillis(); + for (int i = 0; i < STRING_ARRAY_OUTER; i++) { + for (int j = 0; j < STRING_ARRAY_INNER; j++) { + l.start(); + p.stringarray(v); + l.stop(); + } + System.out.print("."); + } + t = System.currentTimeMillis()-t; + System.out.println(" done."); + System.out.println("min/max/avg (ms): "+l.min()+"/"+l.max()+"/"+l.mean()); + System.out.println("deviation: "+l.stddev()); + System.out.println("Total time: "+t+"ms"); + } else if ("arrays".equals(args[0])) { + int count = ARRAY_INNER*ARRAY_OUTER; + System.out.print("Sending array of "+ARRAY_LENGTH+" ints "+count+" times."); + ProfilerInstance pi = new ProfilerInstance(); + conn.exportObject("/Profiler", pi); + Profiler p = conn.getRemoteObject("org.freedesktop.DBus.java.profiler", "/Profiler", Profiler.class); + int[] v = new int[ARRAY_LENGTH]; + Random r = new Random(); + for (int i = 0; i < ARRAY_LENGTH; i++) v[i] = r.nextInt(); + Log l = new Log(count); + long t = System.currentTimeMillis(); + for (int i = 0; i < ARRAY_OUTER; i++) { + for (int j = 0; j < ARRAY_INNER; j++) { + l.start(); + p.array(v); + l.stop(); + } + System.out.print("."); + } + t = System.currentTimeMillis()-t; + System.out.println(" done."); + System.out.println("min/max/avg (ms): "+l.min()+"/"+l.max()+"/"+l.mean()); + System.out.println("deviation: "+l.stddev()); + System.out.println("Total time: "+t+"ms"); + } else if ("maps".equals(args[0])) { + int count = MAP_INNER*MAP_OUTER; + System.out.print("Sending map of "+MAP_LENGTH+" string=>strings "+count+" times."); + ProfilerInstance pi = new ProfilerInstance(); + conn.exportObject("/Profiler", pi); + Profiler p = conn.getRemoteObject("org.freedesktop.DBus.java.profiler", "/Profiler", Profiler.class); + HashMap<String,String> m = new HashMap<String,String>(); + for (int i = 0; i < MAP_LENGTH; i++) + m.put(""+i, "hello"); + Log l = new Log(count); + long t = System.currentTimeMillis(); + for (int i = 0; i < MAP_OUTER; i++) { + for (int j=0; j < MAP_INNER; j++) { + l.start(); + p.map(m); + l.stop(); + } + System.out.print("."); + } + t = System.currentTimeMillis()-t; + System.out.println(" done."); + System.out.println("min/max/avg (ms): "+l.min()+"/"+l.max()+"/"+l.mean()); + System.out.println("deviation: "+l.stddev()); + System.out.println("Total time: "+t+"ms"); + } else if ("lists".equals(args[0])) { + int count = LIST_OUTER*LIST_INNER; + System.out.print("Sending list of "+LIST_LENGTH+" strings "+count+" times."); + ProfilerInstance pi = new ProfilerInstance(); + conn.exportObject("/Profiler", pi); + Profiler p = conn.getRemoteObject("org.freedesktop.DBus.java.profiler", "/Profiler", Profiler.class); + Vector<String> v = new Vector<String>(); + for (int i = 0; i < LIST_LENGTH; i++) + v.add("hello "+i); + Log l = new Log(count); + long t = System.currentTimeMillis(); + for (int i = 0; i < LIST_OUTER; i++) { + for (int j=0; j < LIST_INNER; j++) { + l.start(); + p.list(v); + l.stop(); + } + System.out.print("."); + } + t = System.currentTimeMillis()-t; + System.out.println(" done."); + System.out.println("min/max/avg (ms): "+l.min()+"/"+l.max()+"/"+l.mean()); + System.out.println("deviation: "+l.stddev()); + System.out.println("Total time: "+t+"ms"); + } else if ("structs".equals(args[0])) { + int count = STRUCT_OUTER*STRUCT_INNER; + System.out.print("Sending a struct "+count+" times."); + ProfilerInstance pi = new ProfilerInstance(); + conn.exportObject("/Profiler", pi); + Profiler p = conn.getRemoteObject("org.freedesktop.DBus.java.profiler", "/Profiler", Profiler.class); + ProfileStruct ps = new ProfileStruct("hello", new UInt32(18), 500L); + Log l = new Log(count); + long t = System.currentTimeMillis(); + for (int i = 0; i < STRUCT_OUTER; i++) { + for (int j=0; j < STRUCT_INNER; j++) { + l.start(); + p.struct(ps); + l.stop(); + } + System.out.print("."); + } + t = System.currentTimeMillis()-t; + System.out.println(" done."); + System.out.println("min/max/avg (ms): "+l.min()+"/"+l.max()+"/"+l.mean()); + System.out.println("deviation: "+l.stddev()); + System.out.println("Total time: "+t+"ms"); + } else if ("introspect".equals(args[0])) { + int count = INTROSPECTION_OUTER*INTROSPECTION_INNER; + System.out.print("Recieving introspection data "+count+" times."); + ProfilerInstance pi = new ProfilerInstance(); + conn.exportObject("/Profiler", pi); + Introspectable is = conn.getRemoteObject("org.freedesktop.DBus.java.profiler", "/Profiler", Introspectable.class); + Log l = new Log(count); + long t = System.currentTimeMillis(); + String s = null; + for (int i = 0; i < INTROSPECTION_OUTER; i++) { + for (int j = 0; j < INTROSPECTION_INNER; j++) { + l.start(); + s = is.Introspect(); + l.stop(); + } + System.out.print("."); + } + t = System.currentTimeMillis()-t; + System.out.println(" done."); + System.out.println("min/max/avg (ms): "+l.min()+"/"+l.max()+"/"+l.mean()); + System.out.println("deviation: "+l.stddev()); + System.out.println("Total time: "+t+"ms"); + System.out.println("Introspect data: "+s); + } else if ("bytes".equals(args[0])) { + System.out.print("Sending "+BYTES+" bytes"); + ProfilerInstance pi = new ProfilerInstance(); + conn.exportObject("/Profiler", pi); + Profiler p = conn.getRemoteObject("org.freedesktop.DBus.java.profiler", "/Profiler", Profiler.class); + byte[] bs = new byte[BYTES]; + for (int i = 0; i < BYTES; i++) + bs[i] = (byte) i; + long t = System.currentTimeMillis(); + p.bytes(bs); + System.out.println(" done in "+(System.currentTimeMillis()-t)+"ms."); + } else if ("rate".equals(args[0])) { + ProfilerInstance pi = new ProfilerInstance(); + conn.exportObject("/Profiler", pi); + Profiler p = conn.getRemoteObject("org.freedesktop.DBus.java.profiler", "/Profiler", Profiler.class); + Peer peer = conn.getRemoteObject("org.freedesktop.DBus.java.profiler", "/Profiler", Peer.class); + conn.changeThreadCount((byte)1); + + long start = System.currentTimeMillis(); + int count = 0; + do { + p.Pong(); + count++; + } while(count < 10000); + long end = System.currentTimeMillis(); + System.out.println("No payload: "+((count*1000)/(end-start))+" RT/second"); + start = System.currentTimeMillis(); + count = 0; + do { + p.Pong(); + count++; + } while(count < 10000); + peer.Ping(); + end = System.currentTimeMillis(); + System.out.println("No payload, One way: "+((count*1000)/(end-start))+" /second"); + int len = 256; + while (len <= 32768) { + byte[] bs = new byte[len]; + count = 0; + start = System.currentTimeMillis(); + do { + p.bytes(bs); + count++; + } while(count < 1000); + end = System.currentTimeMillis(); + long ms = end-start; + double cps = (count*1000)/ms; + double rate = (len*cps)/(1024.0*1024.0); + System.out.println(len+" byte array) "+(count*len)+" bytes in "+ms+"ms (in "+count+" calls / "+(int)cps+" CPS): "+rate+"MB/s"); + len <<= 1; + } + len = 256; + while (len <= 32768) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < len; i++) sb.append('a'); + String s = sb.toString(); + end = System.currentTimeMillis()+500; + count = 0; + do { + p.string(s); + count++; + } while(count < 1000); + long ms = end-start; + double cps = (count*1000)/ms; + double rate = (len*cps)/(1024.0*1024.0); + System.out.println(len+" string) "+(count*len)+" bytes in "+ms+"ms (in "+count+" calls / "+(int)cps+" CPS): "+rate+"MB/s"); + len <<= 1; + } + } else if ("signals".equals(args[0])) { + int count = SIGNAL_OUTER*SIGNAL_INNER; + System.out.print("Sending "+count+" signals"); + ProfileHandler ph = new ProfileHandler(); + conn.addSigHandler(Profiler.ProfileSignal.class, ph); + Log l = new Log(count); + Profiler.ProfileSignal ps = new Profiler.ProfileSignal("/"); + long t = System.currentTimeMillis(); + for (int i = 0; i < SIGNAL_OUTER; i++) { + for (int j = 0; j < SIGNAL_INNER; j++) { + l.start(); + conn.sendSignal(ps); + l.stop(); + } + System.out.print("."); + } + t = System.currentTimeMillis()-t; + System.out.println(" done."); + System.out.println("min/max/avg (ms): "+l.min()+"/"+l.max()+"/"+l.mean()); + System.out.println("deviation: "+l.stddev()); + System.out.println("Total time: "+t+"ms"); + while (ph.c < count) try { Thread.sleep(100); } + catch (InterruptedException Ie) {}; + } else { + conn.disconnect(); + System.out.println("Invalid profile ``"+args[0]+"''."); + System.out.println("Syntax: profile <pings|arrays|introspect|maps|bytes|lists|structs|signals>"); + System.exit(1); + } + conn.disconnect(); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/test.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/test.java new file mode 100755 index 0000000..4ccd696 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/test.java @@ -0,0 +1,965 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.test; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.Vector; + +import java.text.Collator; + +import org.freedesktop.dbus.CallbackHandler; +import org.freedesktop.dbus.DBusAsyncReply; +import org.freedesktop.dbus.DBusCallInfo; +import org.freedesktop.dbus.DBusConnection; +import org.freedesktop.dbus.DBusInterface; +import org.freedesktop.dbus.DBusSigHandler; +import org.freedesktop.dbus.DBusSignal; +import org.freedesktop.dbus.Marshalling; +import org.freedesktop.dbus.Path; +import org.freedesktop.dbus.UInt16; +import org.freedesktop.dbus.UInt32; +import org.freedesktop.dbus.UInt64; +import org.freedesktop.dbus.Variant; +import org.freedesktop.dbus.exceptions.DBusException; +import org.freedesktop.dbus.exceptions.DBusExecutionException; +import org.freedesktop.dbus.exceptions.NotConnected; + +import org.freedesktop.DBus; +import org.freedesktop.DBus.Error.MatchRuleInvalid; +import org.freedesktop.DBus.Error.ServiceUnknown; +import org.freedesktop.DBus.Error.UnknownObject; +import org.freedesktop.DBus.Peer; +import org.freedesktop.DBus.Introspectable; +import org.freedesktop.DBus.Properties; + +class testnewclass implements TestNewInterface +{ + public boolean isRemote() { return false; } + public String getName() + { + return toString(); + } +} + +class testclass implements TestRemoteInterface, TestRemoteInterface2, TestSignalInterface, TestSignalInterface2, Properties +{ + private DBusConnection conn; + public testclass(DBusConnection conn) + { + this.conn = conn; + } + public String Introspect() + { + return "Not XML"; + } + public int[][] teststructstruct(TestStruct3 in) + { + List<List<Integer>> lli = in.b; + int[][] out = new int[lli.size()][]; + for (int j = 0; j < out.length; j++) { + out[j] = new int[lli.get(j).size()]; + for (int k = 0; k < out[j].length; k++) + out[j][k] = lli.get(j).get(k); + } + return out; + } + public float testfloat(float[] f) + { + if (f.length < 4 || + f[0] != 17.093f || + f[1] != -23f || + f[2] != 0.0f || + f[3] != 31.42f) + test.fail("testfloat got incorrect array"); + return f[0]; + } + public void newpathtest(Path p) + { + if (!p.toString().equals("/new/path/test")) + test.fail("new path test got wrong path"); + } + public void waitawhile() + { + System.out.println("Sleeping."); + try { + Thread.sleep(1000); + } catch (InterruptedException Ie) {} + System.out.println("Done sleeping."); + } + public <A> TestTuple<String, List<Integer>, Boolean> show(A in) + { + System.out.println("Showing Stuff: "+in.getClass()+"("+in+")"); + if (!(in instanceof Integer) || ((Integer) in).intValue() != 234) + test.fail("show received the wrong arguments"); + DBusCallInfo info = DBusConnection.getCallInfo(); + List<Integer> l = new Vector<Integer>(); + l.add(1953); + return new TestTuple<String,List<Integer>, Boolean>(info.getSource(), l, true); + } + @SuppressWarnings("unchecked") + public <T> T dostuff(TestStruct foo) + { + System.out.println("Doing Stuff "+foo); + System.out.println(" -- ("+foo.a.getClass()+", "+foo.b.getClass()+", "+foo.c.getClass()+")"); + if (!(foo instanceof TestStruct) || + !(foo.a instanceof String) || + !(foo.b instanceof UInt32) || + !(foo.c instanceof Variant) || + !"bar".equals(foo.a) || + foo.b.intValue() != 52 || + !(foo.c.getValue() instanceof Boolean) || + ((Boolean) foo.c.getValue()).booleanValue() != true) + test.fail("dostuff received the wrong arguments"); + return (T) foo.c.getValue(); + } + /** Local classes MUST implement this to return false */ + public boolean isRemote() { return false; } + /** The method we are exporting to the Bus. */ + public List<Integer> sampleArray(List<String> ss, Integer[] is, long[] ls) + { + System.out.println("Got an array:"); + for (String s: ss) + System.out.println("--"+s); + if (ss.size()!= 5 || + !"hi".equals(ss.get(0)) || + !"hello".equals(ss.get(1)) || + !"hej".equals(ss.get(2)) || + !"hey".equals(ss.get(3)) || + !"aloha".equals(ss.get(4))) + test.fail("sampleArray, String array contents incorrect"); + System.out.println("Got an array:"); + for (Integer i: is) + System.out.println("--"+i); + if (is.length != 4 || + is[0].intValue() != 1 || + is[1].intValue() != 5 || + is[2].intValue() != 7 || + is[3].intValue() != 9) + test.fail("sampleArray, Integer array contents incorrect"); + System.out.println("Got an array:"); + for (long l: ls) + System.out.println("--"+l); + if (ls.length != 4 || + ls[0] != 2 || + ls[1] != 6 || + ls[2] != 8 || + ls[3] != 12) + test.fail("sampleArray, Integer array contents incorrect"); + Vector<Integer> v = new Vector<Integer>(); + v.add(-1); + v.add(-5); + v.add(-7); + v.add(-12); + v.add(-18); + return v; + } + public String getName() + { + return "This Is A UTF-8 Name: س !!"; + } + public String getNameAndThrow() throws TestException + { + throw new TestException("test"); + } + public boolean check() + { + System.out.println("Being checked"); + return false; + } + public <T> int frobnicate(List<Long> n, Map<String,Map<UInt16,Short>> m, T v) + { + if (null == n) + test.fail("List was null"); + if (n.size() != 3) + test.fail("List was wrong size (expected 3, actual "+n.size()+")"); + if (n.get(0) != 2L || + n.get(1) != 5L || + n.get(2) != 71L) + test.fail("List has wrong contents"); + if (!(v instanceof Integer)) + test.fail("v not an Integer"); + if (((Integer) v) != 13) + test.fail("v is incorrect"); + if (null == m) + test.fail("Map was null"); + if (m.size() != 1) + test.fail("Map was wrong size"); + if (!m.keySet().contains("stuff")) + test.fail("Incorrect key"); + Map<UInt16,Short> mus = m.get("stuff"); + if (null == mus) + test.fail("Sub-Map was null"); + if (mus.size() != 3) + test.fail("Sub-Map was wrong size"); + if (!(new Short((short)5).equals(mus.get(new UInt16(4))))) + test.fail("Sub-Map has wrong contents"); + if (!(new Short((short)6).equals(mus.get(new UInt16(5))))) + test.fail("Sub-Map has wrong contents"); + if (!(new Short((short)7).equals(mus.get(new UInt16(6))))) + test.fail("Sub-Map has wrong contents"); + return -5; + } + public DBusInterface getThis(DBusInterface t) + { + if (!t.equals(this)) + test.fail("Didn't get this properly"); + return this; + } + public void throwme() throws TestException + { + throw new TestException("test"); + } + public TestSerializable<String> testSerializable(byte b, TestSerializable<String> s, int i) + { + System.out.println("Recieving TestSerializable: "+s); + if ( b != 12 + || i != 13 + || !(s.getInt() == 1) + || !(s.getString().equals("woo")) + || !(s.getVector().size() == 3) + || !(s.getVector().get(0) == 1) + || !(s.getVector().get(1) == 2) + || !(s.getVector().get(2) == 3) ) + test.fail("Error in recieving custom synchronisation"); + return s; + } + public String recursionTest() + { + try { + TestRemoteInterface tri = conn.getRemoteObject("foo.bar.Test", "/Test", TestRemoteInterface.class); + return tri.getName(); + } catch (DBusException DBe) { + test.fail("Failed with error: "+DBe); + return ""; + } + } + public int overload(String s) + { + return 1; + } + public int overload(byte b) + { + return 2; + } + public int overload() + { + DBusCallInfo info = DBusConnection.getCallInfo(); + if ("org.freedesktop.dbus.test.AlternateTestInterface".equals(info.getInterface())) + return 3; + else if ("org.freedesktop.dbus.test.TestRemoteInterface".equals(info.getInterface())) + return 4; + else + return -1; + } + public List<List<Integer>> checklist(List<List<Integer>> lli) + { + return lli; + } + public TestNewInterface getNew() + { + testnewclass n = new testnewclass(); + try { + conn.exportObject("/new", n); + } catch (DBusException DBe) + { throw new DBusExecutionException(DBe.getMessage()); } + return n; + } + public void sig(Type[] s) + { + if (s.length != 2 + || !s[0].equals(Byte.class) + || ! (s[1] instanceof ParameterizedType) + || ! Map.class.equals(((ParameterizedType) s[1]).getRawType()) + || ((ParameterizedType) s[1]).getActualTypeArguments().length != 2 + || ! String.class.equals(((ParameterizedType) s[1]).getActualTypeArguments()[0]) + || ! Integer.class.equals(((ParameterizedType) s[1]).getActualTypeArguments()[1])) + test.fail("Didn't send types correctly"); + } + @SuppressWarnings("unchecked") + public void complexv(Variant<? extends Object> v) + { + if (!"a{ss}".equals(v.getSig()) + || ! (v.getValue() instanceof Map) + || ((Map<Object,Object>) v.getValue()).size() != 1 + || !"moo".equals(((Map<Object,Object>) v.getValue()).get("cow"))) + test.fail("Didn't send variant correctly"); + } + public void reg13291(byte[] as, byte[] bs) + { + if (as.length != bs.length) test.fail("didn't receive identical byte arrays"); + for (int i = 0; i < as.length; i++) + if (as[i] != bs[i]) test.fail("didn't receive identical byte arrays"); + } + @SuppressWarnings("unchecked") + public <A> A Get (String interface_name, String property_name) + { + return (A) new Path("/nonexistant/path"); + } + public <A> void Set (String interface_name, String property_name, A value) {} + public Map<String, Variant> GetAll (String interface_name) { return new HashMap<String,Variant>(); } + public Path pathrv(Path a) { return a; } + public List<Path> pathlistrv(List<Path> a) { return a; } + public Map<Path,Path> pathmaprv(Map<Path,Path> a) { return a; } +} + +/** + * Typed signal handler for renamed signal + */ +class renamedsignalhandler implements DBusSigHandler<TestSignalInterface2.TestRenamedSignal> +{ + /** Handling a signal */ + public void handle(TestSignalInterface2.TestRenamedSignal t) + { + if (false == test.done5) { + test.done5 = true; + } else { + test.fail("SignalHandler R has been run too many times"); + } + System.out.println("SignalHandler R Running"); + System.out.println("string("+t.value+") int("+t.number+")"); + if (!"Bar".equals(t.value) || !(new UInt32(42)).equals(t.number)) + test.fail("Incorrect TestRenamedSignal parameters"); + } +} + +/** + * Empty signal handler + */ +class emptysignalhandler implements DBusSigHandler<TestSignalInterface.EmptySignal> +{ + /** Handling a signal */ + public void handle(TestSignalInterface.EmptySignal t) + { + if (false == test.done7) { + test.done7 = true; + } else { + test.fail("SignalHandler E has been run too many times"); + } + System.out.println("SignalHandler E Running"); + } +} +/** + * Disconnect handler + */ +class disconnecthandler implements DBusSigHandler<DBus.Local.Disconnected> +{ + private DBusConnection conn; + private renamedsignalhandler sh; + public disconnecthandler(DBusConnection conn, renamedsignalhandler sh) + { + this.conn = conn; + this.sh = sh; + } + /** Handling a signal */ + public void handle(DBus.Local.Disconnected t) + { + if (false == test.done6) { + test.done6 = true; + System.out.println("Handling disconnect, unregistering handler"); + try { + conn.removeSigHandler(TestSignalInterface2.TestRenamedSignal.class, sh); + } catch (DBusException DBe) { + DBe.printStackTrace(); + test.fail("Disconnect handler threw an exception: "+DBe); + } + } + } +} + + +/** + * Typed signal handler + */ +class pathsignalhandler implements DBusSigHandler<TestSignalInterface.TestPathSignal> +{ + /** Handling a signal */ + public void handle(TestSignalInterface.TestPathSignal t) + { + System.out.println("Path sighandler: "+t); + } +} + +/** + * Typed signal handler + */ +class signalhandler implements DBusSigHandler<TestSignalInterface.TestSignal> +{ + /** Handling a signal */ + public void handle(TestSignalInterface.TestSignal t) + { + if (false == test.done1) { + test.done1 = true; + } else { + test.fail("SignalHandler 1 has been run too many times"); + } + System.out.println("SignalHandler 1 Running"); + System.out.println("string("+t.value+") int("+t.number+")"); + if (!"Bar".equals(t.value) || !(new UInt32(42)).equals(t.number)) + test.fail("Incorrect TestSignal parameters"); + } +} + +/** + * Untyped signal handler + */ +class arraysignalhandler implements DBusSigHandler<TestSignalInterface.TestArraySignal> +{ + /** Handling a signal */ + public void handle(TestSignalInterface.TestArraySignal t) + { + try { + if (false == test.done2) { + test.done2 = true; + } else { + test.fail("SignalHandler 2 has been run too many times"); + } + System.out.println("SignalHandler 2 Running"); + if (t.v.size() != 1) test.fail("Incorrect TestArraySignal array length: should be 1, actually "+t.v.size()); + System.out.println("Got a test array signal with Parameters: "); + for (String str: t.v.get(0).a) + System.out.println("--"+str); + System.out.println(t.v.get(0).b.getType()); + System.out.println(t.v.get(0).b.getValue()); + if (!(t.v.get(0).b.getValue() instanceof UInt64) || + 567L != ((UInt64) t.v.get(0).b.getValue()).longValue() || + t.v.get(0).a.size() != 5 || + !"hi".equals(t.v.get(0).a.get(0)) || + !"hello".equals(t.v.get(0).a.get(1)) || + !"hej".equals(t.v.get(0).a.get(2)) || + !"hey".equals(t.v.get(0).a.get(3)) || + !"aloha".equals(t.v.get(0).a.get(4))) + test.fail("Incorrect TestArraySignal parameters"); + + if (t.m.keySet().size() != 2) test.fail("Incorrect TestArraySignal map size: should be 2, actually "+t.m.keySet().size()); + if (!(t.m.get(new UInt32(1)).b.getValue() instanceof UInt64) || + 678L != ((UInt64) t.m.get(new UInt32(1)).b.getValue()).longValue() || + !(t.m.get(new UInt32(42)).b.getValue() instanceof UInt64) || + 789L != ((UInt64) t.m.get(new UInt32(42)).b.getValue()).longValue()) + test.fail("Incorrect TestArraySignal parameters"); + + } catch (Exception e) { + e.printStackTrace(); + test.fail("SignalHandler 2 threw an exception: "+e); + } + } +} + +/** + * Object path signal handler + */ +class objectsignalhandler implements DBusSigHandler<TestSignalInterface.TestObjectSignal> +{ + public void handle(TestSignalInterface.TestObjectSignal s) + { + if (false == test.done3) { + test.done3 = true; + } else { + test.fail("SignalHandler 3 has been run too many times"); + } + System.out.println(s.otherpath); + } +} + +/** + * handler which should never be called + */ +class badarraysignalhandler<T extends DBusSignal> implements DBusSigHandler<T> +{ + /** Handling a signal */ + public void handle(T s) + { + test.fail("This signal handler shouldn't be called"); + } +} + +/** + * Callback handler + */ +class callbackhandler implements CallbackHandler<String> +{ + public void handle(String r) + { + System.out.println("Handling callback: "+r); + Collator col = Collator.getInstance(); + col.setDecomposition(Collator.FULL_DECOMPOSITION); + col.setStrength(Collator.PRIMARY); + if (0 != col.compare("This Is A UTF-8 Name: ﺱ !!", r)) + test.fail("call with callback, wrong return value"); + if (test.done4) test.fail("Already ran callback handler"); + test.done4 = true; + } + public void handleError(DBusExecutionException e) + { + System.out.println("Handling error callback: "+e+" message = '"+e.getMessage()+"'"); + if (!(e instanceof TestException)) test.fail("Exception is of the wrong sort"); + Collator col = Collator.getInstance(); + col.setDecomposition(Collator.FULL_DECOMPOSITION); + col.setStrength(Collator.PRIMARY); + if (0 != col.compare("test", e.getMessage())) + test.fail("Exception has the wrong message"); + if (test.done8) test.fail("Already ran callback error handler"); + test.done8=true; + } +} + +/** + * This is a test program which sends and recieves a signal, implements, exports and calls a remote method. + */ +public class test +{ + public static boolean done1 = false; + public static boolean done2 = false; + public static boolean done3 = false; + public static boolean done4 = false; + public static boolean done5 = false; + public static boolean done6 = false; + public static boolean done7 = false; + public static boolean done8 = false; + public static void fail(String message) + { + System.out.println("Test Failed: "+message); + System.err.println("Test Failed: "+message); + if (null != serverconn) serverconn.disconnect(); + if (null != clientconn) clientconn.disconnect(); + System.exit(1); + } + static DBusConnection serverconn = null; + static DBusConnection clientconn = null; + @SuppressWarnings("unchecked") + public static void main(String[] args) + { try { + System.out.println("Creating Connection"); + serverconn = DBusConnection.getConnection(DBusConnection.SESSION); + clientconn = DBusConnection.getConnection(DBusConnection.SESSION); + serverconn.setWeakReferences(true); + clientconn.setWeakReferences(true); + + System.out.println("Registering Name"); + serverconn.requestBusName("foo.bar.Test"); + + /** This gets a remote object matching our bus name and exported object path. */ + Peer peer = clientconn.getRemoteObject("foo.bar.Test", "/Test", Peer.class); + DBus dbus = clientconn.getRemoteObject("org.freedesktop.DBus", "/org/freedesktop/DBus", DBus.class); + + System.out.print("Listening for signals..."); + signalhandler sigh = new signalhandler(); + renamedsignalhandler rsh = new renamedsignalhandler(); + try { + /** This registers an instance of the test class as the signal handler for the TestSignal class. */ + clientconn.addSigHandler(TestSignalInterface.EmptySignal.class, new emptysignalhandler()); + clientconn.addSigHandler(TestSignalInterface.TestSignal.class, sigh); + clientconn.addSigHandler(TestSignalInterface2.TestRenamedSignal.class, rsh); + clientconn.addSigHandler(DBus.Local.Disconnected.class, new disconnecthandler(clientconn, rsh)); + String source = dbus.GetNameOwner("foo.bar.Test"); + clientconn.addSigHandler(TestSignalInterface.TestArraySignal.class, source, peer, new arraysignalhandler()); + clientconn.addSigHandler(TestSignalInterface.TestObjectSignal.class, new objectsignalhandler()); + clientconn.addSigHandler(TestSignalInterface.TestPathSignal.class, new pathsignalhandler()); + badarraysignalhandler<TestSignalInterface.TestSignal> bash = new badarraysignalhandler<TestSignalInterface.TestSignal>(); + clientconn.addSigHandler(TestSignalInterface.TestSignal.class, bash); + clientconn.removeSigHandler(TestSignalInterface.TestSignal.class, bash); + System.out.println("done"); + } catch (MatchRuleInvalid MRI) { + test.fail("Failed to add handlers: "+MRI.getMessage()); + } catch (DBusException DBe) { + test.fail("Failed to add handlers: "+DBe.getMessage()); + } + + System.out.println("Listening for Method Calls"); + testclass tclass = new testclass(serverconn); + testclass tclass2 = new testclass(serverconn); + /** This exports an instance of the test class as the object /Test. */ + serverconn.exportObject("/Test", tclass); + serverconn.exportObject("/BadTest", tclass); + serverconn.exportObject("/BadTest2", tclass2); + serverconn.addFallback("/FallbackTest", tclass); + + // explicitly unexport object + serverconn.unExportObject("/BadTest"); + // implicitly unexport object + tclass2 = null; + System.gc(); + System.runFinalization(); + System.gc(); + System.runFinalization(); + System.gc(); + System.runFinalization(); + + System.out.println("Sending Signal"); + /** This creates an instance of the Test Signal, with the given object path, signal name and parameters, and broadcasts in on the Bus. */ + serverconn.sendSignal(new TestSignalInterface.TestSignal("/foo/bar/Wibble", "Bar", new UInt32(42))); + serverconn.sendSignal(new TestSignalInterface.EmptySignal("/foo/bar/Wibble")); + serverconn.sendSignal(new TestSignalInterface2.TestRenamedSignal("/foo/bar/Wibble", "Bar", new UInt32(42))); + + System.out.println("These things are on the bus:"); + String[] names = dbus.ListNames(); + for (String name: names) + System.out.println("\t"+name); + + System.out.println("Getting our introspection data"); + /** This gets a remote object matching our bus name and exported object path. */ + Introspectable intro = clientconn.getRemoteObject("foo.bar.Test", "/", Introspectable.class); + /** Get introspection data */ + String data;/* = intro.Introspect(); + if (null == data || !data.startsWith("<!DOCTYPE")) + fail("Introspection data invalid"); + System.out.println("Got Introspection Data: \n"+data);*/ + intro = clientconn.getRemoteObject("foo.bar.Test", "/Test", Introspectable.class); + /** Get introspection data */ + data = intro.Introspect(); + if (null == data || !data.startsWith("<!DOCTYPE")) + fail("Introspection data invalid"); + System.out.println("Got Introspection Data: \n"+data); + + // setup bus name set + Set<String> peers = serverconn.new PeerSet(); + peers.add("org.freedesktop.DBus"); + clientconn.requestBusName("test.testclient"); + peers.add("test.testclient"); + clientconn.releaseBusName("test.testclient"); + + System.out.println("Pinging ourselves"); + /** Call ping. */ + for (int i = 0; i < 10; i++) { + long then = System.currentTimeMillis(); + peer.Ping(); + long now = System.currentTimeMillis(); + System.out.println("Ping returned in "+(now-then)+"ms."); + } + + System.out.println("Calling Method0/1"); + /** This gets a remote object matching our bus name and exported object path. */ + TestRemoteInterface tri = (TestRemoteInterface) clientconn.getPeerRemoteObject("foo.bar.Test", "/Test"); + System.out.println("Got Remote Object: "+tri); + /** Call the remote object and get a response. */ + String rname = tri.getName(); + System.out.println("Got Remote Name: "+rname); + + Path path = new Path("/nonexistantwooooooo"); + Path p = tri.pathrv(path); + System.out.println(path.toString()+" => "+p.toString()); + if (!path.equals(p)) fail("pathrv incorrect"); + List<Path> paths = new Vector<Path>(); + paths.add(path); + List<Path> ps = tri.pathlistrv(paths); + System.out.println(paths.toString()+" => "+ps.toString()); + if (!paths.equals(ps)) fail("pathlistrv incorrect"); + Map<Path, Path> pathm = new HashMap<Path, Path>(); + pathm.put(path, path); + Map<Path, Path> pm = tri.pathmaprv(pathm); + System.out.println(pathm.toString()+" => "+pm.toString()); + System.out.println(pm.containsKey(path)+" "+pm.get(path)+" "+path.equals(pm.get(path))); + System.out.println(pm.containsKey(p)+" "+pm.get(p)+" "+p.equals(pm.get(p))); + for (Path q: pm.keySet()) { + System.out.println(q); + System.out.println(pm.get(q)); + } + if (!pm.containsKey(path) || !path.equals(pm.get(path))) fail("pathmaprv incorrect"); + + serverconn.sendSignal(new TestSignalInterface.TestPathSignal("/Test", path, paths, pathm)); + + Collator col = Collator.getInstance(); + col.setDecomposition(Collator.FULL_DECOMPOSITION); + col.setStrength(Collator.PRIMARY); + if (0 != col.compare("This Is A UTF-8 Name: ﺱ !!", rname)) + fail("getName return value incorrect"); + System.out.println("sending it to sleep"); + tri.waitawhile(); + System.out.println("testing floats"); + if (17.093f != tri.testfloat(new float[] { 17.093f, -23f, 0.0f, 31.42f })) + fail("testfloat returned the wrong thing"); + System.out.println("Structs of Structs"); + List<List<Integer>> lli = new Vector<List<Integer>>(); + List<Integer> li = new Vector<Integer>(); + li.add(1); + li.add(2); + li.add(3); + lli.add(li); + lli.add(li); + lli.add(li); + TestStruct3 ts3 = new TestStruct3(new TestStruct2(new Vector<String>(), new Variant<Integer>(0)), lli); + int[][] out = tri.teststructstruct(ts3); + if (out.length != 3) fail("teststructstruct returned the wrong thing: "+Arrays.deepToString(out)); + for (int[] o: out) + if (o.length != 3 + ||o[0] != 1 + ||o[1] != 2 + ||o[2] != 3) fail("teststructstruct returned the wrong thing: "+Arrays.deepToString(out)); + + System.out.println("frobnicating"); + List<Long> ls = new Vector<Long>(); + ls.add(2L); + ls.add(5L); + ls.add(71L); + Map<UInt16,Short> mus = new HashMap<UInt16,Short>(); + mus.put(new UInt16(4), (short) 5); + mus.put(new UInt16(5), (short) 6); + mus.put(new UInt16(6), (short) 7); + Map<String,Map<UInt16,Short>> msmus = new HashMap<String,Map<UInt16,Short>>(); + msmus.put("stuff", mus); + int rint = tri.frobnicate(ls, msmus, 13); + if (-5 != rint) + fail("frobnicate return value incorrect"); + + System.out.println("Doing stuff asynchronously with callback"); + clientconn.callWithCallback(tri, "getName", new callbackhandler()); + System.out.println("Doing stuff asynchronously with callback, which throws an error"); + clientconn.callWithCallback(tri, "getNameAndThrow", new callbackhandler()); + + /** call something that throws */ + try { + System.out.println("Throwing stuff"); + tri.throwme(); + test.fail("Method Execution should have failed"); + } catch (TestException Te) { + System.out.println("Remote Method Failed with: "+Te.getClass().getName()+" "+Te.getMessage()); + if (!Te.getMessage().equals("test")) + test.fail("Error message was not correct"); + } + + /* Test type signatures */ + Vector<Type> ts = new Vector<Type>(); + Marshalling.getJavaType("ya{si}", ts, -1); + tri.sig(ts.toArray(new Type[0])); + + tri.newpathtest(new Path("/new/path/test")); + + /** Try and call an invalid remote object */ + try { + System.out.println("Calling Method2"); + tri = clientconn.getRemoteObject("foo.bar.NotATest", "/Moofle", TestRemoteInterface.class); + System.out.println("Got Remote Name: "+tri.getName()); + test.fail("Method Execution should have failed"); + } catch (ServiceUnknown SU) { + System.out.println("Remote Method Failed with: "+SU.getClass().getName()+" "+SU.getMessage()); + } + + /** Try and call an invalid remote object */ + try { + System.out.println("Calling Method3"); + tri = clientconn.getRemoteObject("foo.bar.Test", "/Moofle", TestRemoteInterface.class); + System.out.println("Got Remote Name: "+tri.getName()); + test.fail("Method Execution should have failed"); + } catch (UnknownObject UO) { + System.out.println("Remote Method Failed with: "+UO.getClass().getName()+" "+UO.getMessage()); + } + + /** Try and call an explicitly unexported object */ + try { + System.out.println("Calling Method4"); + tri = clientconn.getRemoteObject("foo.bar.Test", "/BadTest", TestRemoteInterface.class); + System.out.println("Got Remote Name: "+tri.getName()); + test.fail("Method Execution should have failed"); + } catch (UnknownObject UO) { + System.out.println("Remote Method Failed with: "+UO.getClass().getName()+" "+UO.getMessage()); + } + + /** Try and call an implicitly unexported object */ + try { + System.out.println("Calling Method5"); + tri = clientconn.getRemoteObject("foo.bar.Test", "/BadTest2", TestRemoteInterface.class); + System.out.println("Got Remote Name: "+tri.getName()); + test.fail("Method Execution should have failed"); + } catch (UnknownObject UO) { + System.out.println("Remote Method Failed with: "+UO.getClass().getName()+" "+UO.getMessage()); + } + + System.out.println("Calling Method6"); + tri = clientconn.getRemoteObject("foo.bar.Test", "/FallbackTest/0/1", TestRemoteInterface.class); + intro = clientconn.getRemoteObject("foo.bar.Test", "/FallbackTest/0/4", Introspectable.class); + System.out.println("Got Fallback Name: "+tri.getName()); + System.out.println("Fallback Introspection Data: \n"+intro.Introspect()); + + System.out.println("Testing Properties returning Paths"); + Properties prop = clientconn.getRemoteObject("foo.bar.Test", "/Test", Properties.class); + Path prv = (Path) prop.Get("foo.bar", "foo"); + System.out.println("Got path "+prv); + System.out.println("Calling Method7--9"); + /** This gets a remote object matching our bus name and exported object path. */ + TestRemoteInterface2 tri2 = clientconn.getRemoteObject("foo.bar.Test", "/Test", TestRemoteInterface2.class); + System.out.print("Calling the other introspect method: "); + String intro2 = tri2.Introspect(); + System.out.println(intro2); + if (0 != col.compare("Not XML", intro2)) + fail("Introspect return value incorrect"); + + /** Call the remote object and get a response. */ + TestTuple<String,List<Integer>,Boolean> rv = tri2.show(234); + System.out.println("Show returned: "+rv); + if (!serverconn.getUniqueName().equals(rv.a) || + 1 != rv.b.size() || + 1953 != rv.b.get(0) || + true != rv.c.booleanValue()) + fail("show return value incorrect ("+rv.a+","+rv.b+","+rv.c+")"); + + System.out.println("Doing stuff asynchronously"); + DBusAsyncReply<Boolean> stuffreply = (DBusAsyncReply<Boolean>) clientconn.callMethodAsync(tri2, "dostuff", new TestStruct("bar", new UInt32(52), new Variant<Boolean>(new Boolean(true)))); + + System.out.println("Checking bools"); + if (tri2.check()) fail("bools are broken"); + + List<String> l = new Vector<String>(); + l.add("hi"); + l.add("hello"); + l.add("hej"); + l.add("hey"); + l.add("aloha"); + System.out.println("Sampling Arrays:"); + List<Integer> is = tri2.sampleArray(l, new Integer[] { 1, 5, 7, 9 }, new long[] { 2, 6, 8, 12 }); + System.out.println("sampleArray returned an array:"); + for (Integer i: is) + System.out.println("--"+i); + if (is.size() != 5 || + is.get(0).intValue() != -1 || + is.get(1).intValue() != -5 || + is.get(2).intValue() != -7 || + is.get(3).intValue() != -12 || + is.get(4).intValue() != -18) + fail("sampleArray return value incorrect"); + + System.out.println("Get This"); + if (!tclass.equals(tri2.getThis(tri2))) + fail("Didn't get the correct this"); + + Boolean b = stuffreply.getReply(); + System.out.println("Do stuff replied "+b); + if (true != b.booleanValue()) + fail("dostuff return value incorrect"); + + System.out.print("Sending Array Signal..."); + /** This creates an instance of the Test Signal, with the given object path, signal name and parameters, and broadcasts in on the Bus. */ + List<TestStruct2> tsl = new Vector<TestStruct2>(); + tsl.add(new TestStruct2(l, new Variant<UInt64>(new UInt64(567)))); + Map<UInt32, TestStruct2> tsm = new HashMap<UInt32, TestStruct2>(); + tsm.put(new UInt32(1), new TestStruct2(l, new Variant<UInt64>(new UInt64(678)))); + tsm.put(new UInt32(42), new TestStruct2(l, new Variant<UInt64>(new UInt64(789)))); + serverconn.sendSignal(new TestSignalInterface.TestArraySignal("/Test", tsl, tsm)); + + System.out.println("done"); + + System.out.print("testing custom serialization..."); + Vector<Integer> v = new Vector<Integer>(); + v.add(1); + v.add(2); + v.add(3); + TestSerializable<String> s = new TestSerializable<String>(1, "woo", v); + s = tri2.testSerializable((byte) 12, s, 13); + System.out.print("returned: "+s); + if (s.getInt() != 1 || + ! s.getString().equals("woo") || + s.getVector().size() != 3 || + s.getVector().get(0) != 1 || + s.getVector().get(1) != 2 || + s.getVector().get(2) != 3) + fail("Didn't get back the same TestSerializable"); + + System.out.println("done"); + + System.out.print("testing complex variants..."); + Map m = new HashMap(); + m.put("cow", "moo"); + tri2.complexv(new Variant(m, "a{ss}")); + System.out.println("done"); + + System.out.print("testing recursion..."); + + if (0 != col.compare("This Is A UTF-8 Name: ﺱ !!",tri2.recursionTest())) fail("recursion test failed"); + + System.out.println("done"); + + System.out.print("testing method overloading..."); + tri = clientconn.getRemoteObject("foo.bar.Test", "/Test", TestRemoteInterface.class); + if (1 != tri2.overload("foo")) test.fail("wrong overloaded method called"); + if (2 != tri2.overload((byte) 0)) test.fail("wrong overloaded method called"); + if (3 != tri2.overload()) test.fail("wrong overloaded method called"); + if (4 != tri.overload()) test.fail("wrong overloaded method called"); + System.out.println("done"); + + System.out.print("reg13291..."); + byte[] as = new byte[10]; + for (int i = 0; i < 10; i++) + as[i] = (byte) (100-i); + tri.reg13291(as, as); + System.out.println("done"); + + System.out.print("Testing nested lists..."); + lli = new Vector<List<Integer>>(); + li = new Vector<Integer>(); + li.add(1); + lli.add(li); + List<List<Integer>> reti = tri2.checklist(lli); + if (reti.size() != 1 || + reti.get(0).size() != 1 || + reti.get(0).get(0) != 1) + test.fail("Failed to check nested lists"); + System.out.println("done"); + + System.out.print("Testing dynamic object creation..."); + TestNewInterface tni = tri2.getNew(); + System.out.print(tni.getName()+" "); + System.out.println("done"); + + /* send an object in a signal */ + serverconn.sendSignal(new TestSignalInterface.TestObjectSignal("/foo/bar/Wibble", tclass)); + + /** Pause while we wait for the DBus messages to go back and forth. */ + Thread.sleep(1000); + + // check that bus name set has been trimmed + if (peers.size() != 1) fail("peers hasn't been trimmed"); + if (!peers.contains("org.freedesktop.DBus")) fail ("peers contains the wrong name"); + + System.out.println("Checking for outstanding errors"); + DBusExecutionException DBEe = serverconn.getError(); + if (null != DBEe) throw DBEe; + DBEe = clientconn.getError(); + if (null != DBEe) throw DBEe; + + System.out.println("Disconnecting"); + /** Disconnect from the bus. */ + clientconn.disconnect(); + serverconn.disconnect(); + + System.out.println("Trying to do things after disconnection"); + + /** Remove sig handler */ + clientconn.removeSigHandler(TestSignalInterface.TestSignal.class, sigh); + + /** Call a method when disconnected */ + try { + System.out.println("getName() suceeded and returned: "+tri.getName()); + fail("Should not succeed when disconnected"); + } catch (NotConnected NC) { + System.out.println("getName() failed with exception "+NC); + } + clientconn = null; + serverconn = null; + + if (!done1) fail("Signal handler 1 failed to be run"); + if (!done2) fail("Signal handler 2 failed to be run"); + if (!done3) fail("Signal handler 3 failed to be run"); + if (!done4) fail("Callback handler failed to be run"); + if (!done5) fail("Signal handler R failed to be run"); + if (!done6) fail("Disconnect handler failed to be run"); + if (!done7) fail("Signal handler E failed to be run"); + if (!done8) fail("Error callback handler failed to be run"); + + } catch (Exception e) { + e.printStackTrace(); + fail("Unexpected Exception Occurred: "+e); + }} +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/test_low_level.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/test_low_level.java new file mode 100755 index 0000000..e65956d --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/test_low_level.java @@ -0,0 +1,56 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.test; +import cx.ath.matthew.debug.Debug; +import org.freedesktop.dbus.BusAddress; +import org.freedesktop.dbus.DBusSignal; +import org.freedesktop.dbus.Message; +import org.freedesktop.dbus.MethodCall; +import org.freedesktop.dbus.Transport; + +public class test_low_level +{ + public static void main(String[] args) throws Exception + { + Debug.setHexDump(true); + String addr = System.getenv("DBUS_SESSION_BUS_ADDRESS"); + Debug.print(addr); + BusAddress address = new BusAddress(addr); + Debug.print(address); + + Transport conn = new Transport(address); + + Message m = new MethodCall("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "Hello", (byte) 0, null); + conn.mout.writeMessage(m); + m = conn.min.readMessage(); + Debug.print(m.getClass()); + Debug.print(m); + m = conn.min.readMessage(); + Debug.print(m.getClass()); + Debug.print(m); + m = conn.min.readMessage(); + Debug.print(""+m); + m = new MethodCall("org.freedesktop.DBus", "/", null, "Hello", (byte) 0, null); + conn.mout.writeMessage(m); + m = conn.min.readMessage(); + Debug.print(m); + + m = new MethodCall("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName", (byte) 0, "su", "org.testname", 0); + conn.mout.writeMessage(m); + m = conn.min.readMessage(); + Debug.print(m); + m = new DBusSignal(null, "/foo", "org.foo", "Foo", null); + conn.mout.writeMessage(m); + m = conn.min.readMessage(); + Debug.print(m); + conn.disconnect(); + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/test_p2p_client.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/test_p2p_client.java new file mode 100755 index 0000000..aafbca4 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/test_p2p_client.java @@ -0,0 +1,42 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.test; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.InputStreamReader; + +import org.freedesktop.DBus; +import org.freedesktop.dbus.DirectConnection; + +public class test_p2p_client +{ + public static void main(String[] args) throws Exception + { + BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream("address"))); + String address = r.readLine(); + DirectConnection dc = new DirectConnection(address); + System.out.println("Connected"); + TestRemoteInterface tri = (TestRemoteInterface) dc.getRemoteObject("/Test"); + System.out.println(tri.getName()); + System.out.println(tri.testfloat(new float[] { 17.093f, -23f, 0.0f, 31.42f })); + + try { + tri.throwme(); + } catch (TestException Te) { + System.out.println("Caught TestException"); + } + ((DBus.Peer) tri).Ping(); + System.out.println(((DBus.Introspectable) tri).Introspect()); + dc.disconnect(); + System.out.println("Disconnected"); + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/test_p2p_server.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/test_p2p_server.java new file mode 100755 index 0000000..6840694 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/test_p2p_server.java @@ -0,0 +1,94 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.test; + +import java.lang.reflect.Type; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.freedesktop.dbus.DirectConnection; +import org.freedesktop.dbus.Path; +import org.freedesktop.dbus.UInt16; + +public class test_p2p_server implements TestRemoteInterface +{ + public int[][] teststructstruct(TestStruct3 in) + { + List<List<Integer>> lli = in.b; + int[][] out = new int[lli.size()][]; + for (int j = 0; j < out.length; j++) { + out[j] = new int[lli.get(j).size()]; + for (int k = 0; k < out[j].length; k++) + out[j][k] = lli.get(j).get(k); + } + return out; + } + public String getNameAndThrow() + { + return getName(); + } + public String getName() + { + System.out.println("getName called"); + return "Peer2Peer Server"; + } + public <T> int frobnicate(List<Long> n, Map<String,Map<UInt16,Short>> m, T v) + { + return 3; + } + public void throwme() throws TestException + { + System.out.println("throwme called"); + throw new TestException("BOO"); + } + public void waitawhile() + { + return; + } + public int overload() + { + return 1; + } + public void sig(Type[] s) + { + } + public void newpathtest(Path p) + { + } + public void reg13291(byte[] as, byte[] bs) + { + } + public Path pathrv(Path a) { return a; } + public List<Path> pathlistrv(List<Path> a) { return a; } + public Map<Path,Path> pathmaprv(Map<Path,Path> a) { return a; } + public boolean isRemote() { return false; } + public float testfloat(float[] f) + { + System.out.println("got float: "+Arrays.toString(f)); + return f[0]; + } + + public static void main(String[] args) throws Exception + { + String address = DirectConnection.createDynamicSession(); + //String address = "tcp:host=localhost,port=12344,guid="+Transport.genGUID(); + PrintWriter w = new PrintWriter(new FileOutputStream("address")); + w.println(address); + w.flush(); + w.close(); + DirectConnection dc = new DirectConnection(address+",listen=true"); + System.out.println("Connected"); + dc.exportObject("/Test", new test_p2p_server()); + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/two_part_test_client.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/two_part_test_client.java new file mode 100755 index 0000000..f37e955 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/two_part_test_client.java @@ -0,0 +1,42 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.test; + +import org.freedesktop.dbus.DBusConnection; + +public class two_part_test_client +{ + public static class two_part_test_object implements TwoPartObject + { + public boolean isRemote() { return false; } + public String getName() + { + System.out.println("client name"); + return toString(); + } + } + public static void main(String[] args) throws Exception + { + System.out.println("get conn"); + DBusConnection conn = DBusConnection.getConnection(DBusConnection.SESSION); + System.out.println("get remote"); + TwoPartInterface remote = conn.getRemoteObject("org.freedesktop.dbus.test.two_part_server", "/", TwoPartInterface.class); + System.out.println("get object"); + TwoPartObject o = remote.getNew(); + System.out.println("get name"); + System.out.println(o.getName()); + two_part_test_object tpto = new two_part_test_object(); + conn.exportObject("/TestObject", tpto); + conn.sendSignal(new TwoPartInterface.TwoPartSignal("/FromObject", tpto)); + try { Thread.sleep(1000); } catch (InterruptedException Ie) {} + conn.disconnect(); + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/two_part_test_server.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/two_part_test_server.java new file mode 100755 index 0000000..7452303 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/test/two_part_test_server.java @@ -0,0 +1,55 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.test; + +import org.freedesktop.dbus.DBusConnection; +import org.freedesktop.dbus.DBusSigHandler; + +public class two_part_test_server implements TwoPartInterface, DBusSigHandler<TwoPartInterface.TwoPartSignal> +{ + public class two_part_test_object implements TwoPartObject + { + public boolean isRemote() { return false; } + public String getName() + { + System.out.println("give name"); + return toString(); + } + } + private DBusConnection conn; + public two_part_test_server(DBusConnection conn) + { + this.conn = conn; + } + public boolean isRemote() { return false; } + public TwoPartObject getNew() + { + TwoPartObject o = new two_part_test_object(); + System.out.println("export new"); + try { conn.exportObject("/12345", o); } catch (Exception e) {} + System.out.println("give new"); + return o; + } + public void handle(TwoPartInterface.TwoPartSignal s) + { + System.out.println("Got: "+s.o); + } + public static void main(String[] args) throws Exception + { + DBusConnection conn = DBusConnection.getConnection(DBusConnection.SESSION); + conn.requestBusName("org.freedesktop.dbus.test.two_part_server"); + two_part_test_server server = new two_part_test_server(conn); + conn.exportObject("/", server); + conn.addSigHandler(TwoPartInterface.TwoPartSignal.class, server); + while (true) try { Thread.sleep(10000); } catch (InterruptedException Ie) {} + } +} + diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/types/DBusListType.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/types/DBusListType.java new file mode 100755 index 0000000..f7711dc --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/types/DBusListType.java @@ -0,0 +1,44 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.types; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.List; + +/** + * The type of a list. + * Should be used whenever you need a Type variable for a list. + */ +public class DBusListType implements ParameterizedType +{ + private Type v; + /** + * Create a List type. + * @param v Type of the list contents. + */ + public DBusListType(Type v) + { + this.v = v; + } + public Type[] getActualTypeArguments() + { + return new Type[] { v }; + } + public Type getRawType() + { + return List.class; + } + public Type getOwnerType() + { + return null; + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/types/DBusMapType.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/types/DBusMapType.java new file mode 100755 index 0000000..825df7d --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/types/DBusMapType.java @@ -0,0 +1,47 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.types; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.Map; + +/** + * The type of a map. + * Should be used whenever you need a Type variable for a map. + */ +public class DBusMapType implements ParameterizedType +{ + private Type k; + private Type v; + /** + * Create a map type. + * @param k The type of the keys. + * @param v The type of the values. + */ + public DBusMapType(Type k, Type v) + { + this.k = k; + this.v = v; + } + public Type[] getActualTypeArguments() + { + return new Type[] { k, v }; + } + public Type getRawType() + { + return Map.class; + } + public Type getOwnerType() + { + return null; + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/types/DBusStructType.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/types/DBusStructType.java new file mode 100755 index 0000000..86d7533 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/types/DBusStructType.java @@ -0,0 +1,44 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.types; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import org.freedesktop.dbus.Struct; + +/** + * The type of a struct. + * Should be used whenever you need a Type variable for a struct. + */ +public class DBusStructType implements ParameterizedType +{ + private Type[] contents; + /** + * Create a struct type. + * @param contents The types contained in this struct. + */ + public DBusStructType(Type... contents) + { + this.contents = contents; + } + public Type[] getActualTypeArguments() + { + return contents; + } + public Type getRawType() + { + return Struct.class; + } + public Type getOwnerType() + { + return null; + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/DBusEntry.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/DBusEntry.java new file mode 100755 index 0000000..a71005e --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/DBusEntry.java @@ -0,0 +1,123 @@ +/* + D-Bus Java Viewer + Copyright (c) 2006 Peter Cox + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.viewer; + +import org.freedesktop.DBus.Introspectable; +import org.freedesktop.dbus.UInt32; + +/** A summary class for a dbus entry for use in a table model + * + * @author pete + * @since 10/02/2006 + */ +public class DBusEntry +{ + private String name; + + private String path; + + private UInt32 user; + + private String owner; + + private Introspectable introspectable; + + /** Assign the name + * + * @param name The name. + */ + public void setName(String name) + { + this.name = name; + } + + /** Retrieve the name + * + * @return The name. + */ + public String getName() + { + return name; + } + + /** Assign the user + * + * @param user The user. + */ + public void setUser(UInt32 user) + { + this.user = user; + } + + /** Retrieve the user + * + * @return The user. + */ + public UInt32 getUser() + { + return user; + } + + /** Assign the owner + * + * @param owner The owner. + */ + public void setOwner(String owner) + { + this.owner = owner; + } + + /** Retrieve the owner + * + * @return The owner. + */ + public String getOwner() + { + return owner; + } + + /** Assign the introspectable + * + * @param introspectable The introspectable. + */ + public void setIntrospectable(Introspectable introspectable) + { + this.introspectable = introspectable; + } + + /** Retrieve the introspectable + * + * @return The introspectable. + */ + public Introspectable getIntrospectable() + { + return introspectable; + } + + /** + * retrieve the path parameter + * + * @return + */ + public String getPath() { + return path; + } + + /** + * set the path parameter + * + * @param path + */ + public void setPath(String path) { + this.path = path; + } + +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/DBusTableModel.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/DBusTableModel.java new file mode 100755 index 0000000..d4363d4 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/DBusTableModel.java @@ -0,0 +1,127 @@ +/* + D-Bus Java Viewer + Copyright (c) 2006 Peter Cox + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.viewer; + +import java.util.ArrayList; +import java.util.List; + +import javax.swing.table.AbstractTableModel; + +@SuppressWarnings("serial") +class DBusTableModel extends AbstractTableModel +{ + private static final String INTROSPECTABLE = "introspectable?"; + + private static final String OWNER = "owner"; + + private static final String USER = "user"; + + private static final String NAME = "name"; + + private static final String PATH = "path"; + + final String[] columns = { NAME, PATH, USER, OWNER, INTROSPECTABLE }; + + private List<DBusEntry> entries = new ArrayList<DBusEntry>(); + + /** {@inheritDoc} */ + public int getRowCount() + { + return entries.size(); + } + /** Add a row to the table model + * + * @param entry The dbus entry to add + */ + public void add(DBusEntry entry) + { + entries.add(entry); + } + + /** {@inheritDoc} */ + public int getColumnCount() + { + return columns.length; + } + + /** {@inheritDoc} */ + @Override + public String getColumnName(int column) + { + return columns[column]; + } + + /** Get a row of the table + * @param row The row index + * @return The table row + */ + public DBusEntry getEntry(int row) + { + return entries.get(row); + } + + /** {@inheritDoc} */ + @Override + public Class<?> getColumnClass(int columnIndex) + { + String columnName = getColumnName(columnIndex); + if (columnName.equals(NAME)) + { + return String.class; + } + if (columnName.equals(PATH)) + { + return String.class; + } + else if (columnName.equals(USER)) + { + return Object.class; + } + else if (columnName.equals(OWNER)) + { + return String.class; + } + else if (columnName.equals(INTROSPECTABLE)) + { + return Boolean.class; + } + return super.getColumnClass(columnIndex); + } + + /** {@inheritDoc} */ + public Object getValueAt(int rowIndex, int columnIndex) + { + DBusEntry entry = getEntry(rowIndex); + String columnName = getColumnName(columnIndex); + if (columnName.equals(NAME)) + { + return entry.getName(); + } + if (columnName.equals(PATH)) + { + return entry.getPath(); + } + else if (columnName.equals(USER)) + { + return entry.getUser(); + } + else if (columnName.equals(OWNER)) + { + return entry.getOwner(); + } + else if (columnName.equals(INTROSPECTABLE)) + { + return entry.getIntrospectable() != null; + } + return null; + } + +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/DBusViewer.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/DBusViewer.java new file mode 100755 index 0000000..4d7e1b8 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/DBusViewer.java @@ -0,0 +1,363 @@ +/* + D-Bus Java Viewer + Copyright (c) 2006 Peter Cox + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.viewer; + +import static org.freedesktop.dbus.Gettext._; + +import java.awt.BorderLayout; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.io.IOException; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; +import javax.swing.JTable; +import javax.swing.SwingUtilities; +import javax.swing.table.TableModel; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.freedesktop.DBus; +import org.freedesktop.DBus.Introspectable; +import org.freedesktop.dbus.DBusConnection; +import org.freedesktop.dbus.UInt32; +import org.freedesktop.dbus.exceptions.DBusException; +import org.freedesktop.dbus.exceptions.DBusExecutionException; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +/** + * A viewer for DBus + * + * goal is to replicate the functionality of kdbus with Java smarts + * + * @author pete + * @since 29/01/2006 + */ +public class DBusViewer +{ + private static final Map<String, Integer> CONNECTION_TYPES = new HashMap<String, Integer>(); + + static + { + CONNECTION_TYPES.put("System", DBusConnection.SYSTEM); + CONNECTION_TYPES.put("Session", DBusConnection.SESSION); + } + + /** Create the DBusViewer + * + * @param connectionTypes The map of connection types + */ + public DBusViewer(final Map<String, Integer> connectionTypes) + { + connections = new ArrayList<DBusConnection>(connectionTypes.size()); + + SwingUtilities.invokeLater(new Runnable() + { + @SuppressWarnings("synthetic-access") + public void run() + { + + final JTabbedPane tabbedPane = new JTabbedPane(); + addTabs(tabbedPane, connectionTypes); + final JFrame frame = new JFrame("Dbus Viewer"); + frame.setContentPane(tabbedPane); + frame.setSize(600, 400); + frame.addWindowListener(new WindowAdapter() + { + @Override + public void windowClosing(WindowEvent e) + { + frame.dispose(); + for (DBusConnection connection : connections) + { + connection.disconnect(); + } + System.exit(0); + } + }); + frame.setVisible(true); + } + }); + } + + private List<DBusConnection> connections; + + /** + * @param args + */ + public static void main(String[] args) + { + new DBusViewer(CONNECTION_TYPES); + } + + /** Add tabs for each supplied connection type + * @param tabbedPane The tabbed pane + * @param connectionTypes The connection + */ + private void addTabs(final JTabbedPane tabbedPane, + final Map<String, Integer> connectionTypes) + { + for (final String key : connectionTypes.keySet()) + { + final JLabel label = new JLabel(_("Processing DBus for ") + key); + tabbedPane.addTab(key, label); + } + Runnable loader = new Runnable() + { + @SuppressWarnings("synthetic-access") + public void run() + { + boolean users = true, owners = true; + for (final String key : connectionTypes.keySet()) + { + try + { + DBusConnection conn = DBusConnection + .getConnection(connectionTypes.get(key)); + connections.add(conn); + + final TableModel tableModel = listDBusConnection(users, + owners, conn); + + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + int index = tabbedPane.indexOfTab(key); + final JTable table = new JTable(tableModel); + + + + JScrollPane scrollPane = new JScrollPane(table); + + JPanel tab = new JPanel(new BorderLayout()); + tab.add(scrollPane, BorderLayout.CENTER); + + JPanel southPanel = new JPanel(); + final JButton button = new JButton(new IntrospectAction(table)); + southPanel.add(button); + + tab.add(southPanel, BorderLayout.SOUTH); + + tabbedPane.setComponentAt(index, + tab); + + } + }); + } + catch (final DBusException e) + { + e.printStackTrace(); + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + int index = tabbedPane.indexOfTab(key); + JLabel label = (JLabel) tabbedPane + .getComponentAt(index); + label + .setText(_("Could not load Dbus information for ") + + key + ":" + e.getMessage()); + } + }); + } + catch (final DBusExecutionException e) + { + e.printStackTrace(); + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + int index = tabbedPane.indexOfTab(key); + JLabel label = (JLabel) tabbedPane + .getComponentAt(index); + label + .setText(_("Could not load Dbus information for ") + + key + ":" + e.getMessage()); + } + }); + } + } + } + }; + final Thread thread = new Thread(loader); + thread.setName("DBus Loader"); + thread.start(); + } + + /* based on code from org.freedesktop.dbus.ListDBus */ + private DBusTableModel listDBusConnection(boolean users, boolean owners, + DBusConnection conn) throws DBusException + { + DBusTableModel model = new DBusTableModel(); + + DBus dbus = conn.getRemoteObject("org.freedesktop.DBus", + "/org/freedesktop/DBus", DBus.class); + String[] names = dbus.ListNames(); + + ParsingContext p = new ParsingContext(conn); + + for (String name : names) + { + List<DBusEntry> results = new ArrayList<DBusEntry>(); + try + { + //String objectpath = '/' + name.replace('.', '/'); + + + p.visitNode(name,"/"); + } + catch (DBusException e) + { + e.printStackTrace(); + } + catch (DBusExecutionException e) + { + e.printStackTrace(); + } catch (SAXException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + results = p.getResult(); + p.reset(); + + if (results.size()>0) { + if (users) try + { + final UInt32 user = dbus.GetConnectionUnixUser(name); + for (DBusEntry entry : results) { + entry.setUser(user); + } + } + catch (DBusExecutionException DBEe) + { + } + if (!name.startsWith(":") && owners) + { + try + { + final String owner = dbus.GetNameOwner(name); + for (DBusEntry entry : results) { + entry.setOwner(owner); + } + } + catch (DBusExecutionException DBEe) + { + } + } + for (DBusEntry entry : results) { + model.add(entry); + } + } + } + return model; + } + private final static String DOC_TYPE = "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">"; + + class ParsingContext { + private DBusConnection conn; + private DocumentBuilder builder; + private List<DBusEntry> result; + + ParsingContext(DBusConnection conn) { + this.conn = conn; + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + try { + builder = factory.newDocumentBuilder(); + } catch (ParserConfigurationException e1) { + // TODO Auto-generated catch block + throw new RuntimeException(_("Error during parser init: ")+e1.getMessage(),e1); + } + reset(); + + } + + DBusEntry addEntry(String name, String path) throws DBusException { + DBusEntry entry = new DBusEntry(); + entry.setName(name); + entry.setPath(path); + Introspectable introspectable = conn.getRemoteObject(name, path, Introspectable.class); + entry.setIntrospectable(introspectable); + + result.add(entry); + + return entry; + } + + public void visitNode(String name, String path) throws DBusException, SAXException, IOException { + System.out.println("visit "+name+":"+path); + if ("/org/freedesktop/DBus/Local".equals(path)) { + // this will disconnects us. + return; + } + DBusEntry e = addEntry(name, path); + String introspectData = e.getIntrospectable().Introspect(); + + + Document document = builder.parse(new InputSource(new StringReader(introspectData.replace(DOC_TYPE, "")))); + Element root = document.getDocumentElement(); + + NodeList children = root.getChildNodes(); + for (int i=0;i<children.getLength();i++) { + Node node = children.item(i); + if (Node.ELEMENT_NODE != node.getNodeType()) { + continue; + } + if ("node".equals(node.getNodeName())) { + Node nameNode = node.getAttributes().getNamedItem("name"); + if (nameNode!=null) { + try { + if (path.endsWith("/")) { + visitNode(name, path + nameNode.getNodeValue()); + } else { + visitNode(name, path + '/' + nameNode.getNodeValue()); + } + } catch (DBusException ex) { + ex.printStackTrace(); + } + } + } + + } + + } + + public List<DBusEntry> getResult() { + return result; + } + + void reset() { + result = new ArrayList<DBusEntry>(); + } + + + } + + +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/FileSaver.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/FileSaver.java new file mode 100755 index 0000000..789aa65 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/FileSaver.java @@ -0,0 +1,191 @@ +/* + D-Bus Java Viewer + Copyright (c) 2006 Peter Cox + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.viewer; + +import static org.freedesktop.dbus.Gettext._; + +import java.awt.Component; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Iterator; + +import javax.swing.JOptionPane; + +final class FileSaver implements Runnable +{ + private static final String CANCEL = "Cancel"; + + private static final String SKIP_ALL = "Skip All"; + + private static final String SKIP = "Skip"; + + private static final String OVERWRITE = "Overwrite"; + + private static final String OVERWRITE_ALL = "Overwrite All"; + + private final File parentDirectory; + + private final Component parentComponent; + + private final Iterable<TextFile> textFiles; + + FileSaver(Component parentComponent, File parentDirectory, + Iterable<TextFile> files) + { + this.parentComponent = parentComponent; + this.parentDirectory = parentDirectory; + this.textFiles = files; + } + + /** {@inheritDoc} */ + public void run() + { + saveFiles(); + } + + private void saveFiles() + { + String overwritePolicy = null; + final Iterator<TextFile> iterator = textFiles.iterator(); + while (iterator.hasNext()) + { + final TextFile textFile = iterator.next(); + String fileName = textFile.getFileName(); + File fileToSave = new File(parentDirectory, fileName); + File parentFile = fileToSave.getParentFile(); + if (parentFile.exists() || parentFile.mkdirs()) + { + boolean doSave = !fileToSave.exists() + || OVERWRITE_ALL.equals(overwritePolicy); + if (!doSave && !SKIP_ALL.equals(overwritePolicy)) + { + String[] selectionValues; + if (iterator.hasNext()) + { + selectionValues = new String[] { OVERWRITE, + OVERWRITE_ALL, SKIP, SKIP_ALL, CANCEL }; + } + else + { + selectionValues = new String[] { OVERWRITE, CANCEL }; + } + int option = JOptionPane.showOptionDialog(parentComponent, + "File exists: " + fileName, "Save", + JOptionPane.YES_NO_CANCEL_OPTION, + JOptionPane.QUESTION_MESSAGE, null, + selectionValues, null); + if (option == -1) + { + break; + } + overwritePolicy = selectionValues[option]; + if (CANCEL.equals(overwritePolicy)) + { + break; + } + + doSave = OVERWRITE.equals(overwritePolicy) + || OVERWRITE_ALL.equals(overwritePolicy); + } + if (doSave) + { + try + { + String contents = textFile.getContents(); + writeFile(fileToSave, contents); + } + catch (final IOException ex) + { + /* Can't access parent directory for saving */ + final String errorMessage = "Could not save " + + fileName + ": " + ex.getLocalizedMessage(); + if (iterator.hasNext()) + { + + int confirm = JOptionPane.showConfirmDialog( + parentComponent, errorMessage + + ".\n"+_("Try saving other files?"), + _("Save Failed"), + JOptionPane.OK_CANCEL_OPTION, + JOptionPane.ERROR_MESSAGE); + if (confirm != JOptionPane.OK_OPTION) + { + break; + } + } + else + { + JOptionPane.showMessageDialog(parentComponent, + errorMessage + ".", _("Save Failed"), + JOptionPane.ERROR_MESSAGE); + } + } + } + } + else + { + + final String errorMessage = _("Could not access parent directory for ") + + fileName; + if (iterator.hasNext()) + { + + int confirm = JOptionPane.showConfirmDialog( + parentComponent, errorMessage + + ".\n"+_("Try saving other files?"), + _("Save Failed"), JOptionPane.OK_CANCEL_OPTION, + JOptionPane.ERROR_MESSAGE); + if (confirm != JOptionPane.OK_OPTION) + { + break; + } + } + else + { + JOptionPane.showMessageDialog(parentComponent, errorMessage + + ".", _("Save Failed"), JOptionPane.ERROR_MESSAGE); + } + } + } + } + + /** + * @param fileToSave + * @param contents + * @throws IOException + */ + private void writeFile(File fileToSave, String contents) throws IOException + { + FileWriter fileWriter = null; + try + { + fileWriter = new FileWriter(fileToSave); + BufferedWriter writer = new BufferedWriter(fileWriter); + writer.append(contents); + writer.flush(); + } + finally + { + if (fileWriter != null) + { + try + { + fileWriter.close(); + } + catch (IOException e1) + { + } + } + } + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/IntrospectAction.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/IntrospectAction.java new file mode 100755 index 0000000..d2110e9 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/IntrospectAction.java @@ -0,0 +1,148 @@ +/* + D-Bus Java Viewer + Copyright (c) 2006 Peter Cox + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.viewer; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.io.StringReader; + +import javax.swing.AbstractAction; +import javax.swing.JButton; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; +import javax.swing.JTable; +import javax.swing.JTextArea; +import javax.swing.ListSelectionModel; +import javax.swing.ScrollPaneConstants; +import javax.swing.SwingUtilities; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + +import org.freedesktop.DBus.Introspectable; +import org.freedesktop.dbus.bin.CreateInterface; + +@SuppressWarnings("serial") +final class IntrospectAction extends AbstractAction implements ListSelectionListener +{ + private final JTable table; + + IntrospectAction(JTable table) + { + super("Introspect"); + setEnabled(false); + this.table = table; + + + ListSelectionModel selectionModel = table.getSelectionModel(); + selectionModel.addListSelectionListener(this); + selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + } + + /** {@inheritDoc} */ + public void valueChanged(ListSelectionEvent e) + { + if (!e.getValueIsAdjusting()) + { + DBusTableModel model = (DBusTableModel) table.getModel(); + int selection = table.getSelectedRow(); + if (selection > -1 && selection < model.getRowCount()) + { + DBusEntry entry = model.getEntry(selection); + final Introspectable introspectable = entry.getIntrospectable(); + setEnabled(introspectable != null); + } + } + } + + /** {@inheritDoc} */ + public void actionPerformed(ActionEvent e) + { + + int row = table.getSelectedRow(); + DBusTableModel model = (DBusTableModel) table.getModel(); + if (row > -1 && row < model.getRowCount()) + { + DBusEntry entry = model.getEntry(row); + final String xmlFile = entry.getName() + ".xml"; + final Introspectable introspectable = entry.getIntrospectable(); + new Thread(new Runnable() + { + public void run() + { + + StringStreamFactory factory = new StringStreamFactory(); + CreateInterface createInterface = new CreateInterface(factory, false); + try + { + String xml = introspectable.Introspect(); + + String docType = "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">"; + + createInterface.createInterface(new StringReader(xml.replace(docType, ""))); + final JTabbedPane tabbedPane = new JTabbedPane(); + + tabbedPane.addTab(xmlFile, createSourceTab(xmlFile, xml)); + + for (String file : factory.streamMap.keySet()) + { + final String source = factory.streamMap.get(file).toString(); + + tabbedPane.addTab(file, createSourceTab(file, source)); + } + tabbedPane.setPreferredSize(new Dimension(600, 400)); + + final JPanel introspectionPanel = new JPanel(new BorderLayout()); + introspectionPanel.add(tabbedPane, BorderLayout.CENTER); + + JPanel southPanel = new JPanel(); + southPanel.add(new JButton(new SaveFileAction(tabbedPane))); + southPanel.add(new JButton(new SaveAllAction(tabbedPane))); + introspectionPanel.add(southPanel, BorderLayout.SOUTH); + + SwingUtilities.invokeLater(new Runnable() + { + @SuppressWarnings("synthetic-access") + public void run() + { + JOptionPane.showMessageDialog(table, introspectionPanel, "Introspection", JOptionPane.PLAIN_MESSAGE); + } + }); + + } + catch (final Exception e) + { + e.printStackTrace(); + SwingUtilities.invokeLater(new Runnable() + { + @SuppressWarnings("synthetic-access") + public void run() + { + JOptionPane.showMessageDialog(table, e.getMessage(), "Introspection Failed", JOptionPane.ERROR_MESSAGE); + } + }); + } + } + + private JScrollPane createSourceTab(String file, final String source) + { + JTextArea area = new JTextArea(source); + area.setLineWrap(true); + area.setWrapStyleWord(true); + return new JScrollPane(area, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); + } + }).start(); + + } + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/SaveAllAction.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/SaveAllAction.java new file mode 100755 index 0000000..d8bfb19 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/SaveAllAction.java @@ -0,0 +1,62 @@ +/* + D-Bus Java Viewer + Copyright (c) 2006 Peter Cox + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.viewer; + +import java.util.Iterator; +import java.util.NoSuchElementException; + +import javax.swing.JTabbedPane; + +@SuppressWarnings("serial") +class SaveAllAction extends TabbedSaveAction +{ + + private class TabIterator implements Iterator<TextFile> + { + private int i = 0; + /** {@inheritDoc} */ + public boolean hasNext() + { + return i < tabbedPane.getTabCount(); + } + + /** {@inheritDoc} */ + public TextFile next() + { + if (hasNext()) + { + int currentIndex = i; + i++; + return getTextFile(currentIndex); + } + throw new NoSuchElementException(); + } + + /** {@inheritDoc} */ + public void remove() + { + throw new UnsupportedOperationException(); + } + + } + + protected SaveAllAction(JTabbedPane tabbedPane) + { + super(tabbedPane, "Save All..."); + } + + /** {@inheritDoc} */ + public Iterator<TextFile> iterator() + { + return new TabIterator(); + } + +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/SaveFileAction.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/SaveFileAction.java new file mode 100755 index 0000000..487e22d --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/SaveFileAction.java @@ -0,0 +1,85 @@ +/* + D-Bus Java Viewer + Copyright (c) 2006 Peter Cox + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.viewer; + +import static org.freedesktop.dbus.Gettext._; + +import java.util.Iterator; +import java.util.NoSuchElementException; + +import javax.swing.Action; +import javax.swing.JTabbedPane; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +@SuppressWarnings("serial") +class SaveFileAction extends TabbedSaveAction implements ChangeListener +{ + private class SelectedTabIterator implements Iterator<TextFile> + { + boolean iterated = false; + /** {@inheritDoc} */ + public boolean hasNext() + { + return !iterated; + } + + /** {@inheritDoc} */ + public TextFile next() + { + if (iterated) + { + throw new NoSuchElementException(_("Already iterated")); + } + iterated = true; + return getTextFile(tabbedPane.getSelectedIndex()); + } + + /** {@inheritDoc} */ + public void remove() + { + throw new UnsupportedOperationException(); + } + + } + + SaveFileAction(JTabbedPane tabbedPane) + { + super(tabbedPane); + + enableAndSetName(); + + tabbedPane.addChangeListener(this); + } + + /** {@inheritDoc} */ + public void stateChanged(ChangeEvent e) + { + enableAndSetName(); + } + + /** + * Enable and set the name of the action based on the shown tab + */ + void enableAndSetName() + { + int selectedIndex = tabbedPane.getSelectedIndex(); + boolean enabled = selectedIndex > -1; + putValue(Action.NAME, _("Save ") + getFileName(selectedIndex) + "..."); + setEnabled(enabled); + } + + /** {@inheritDoc} */ + public Iterator<TextFile> iterator() + { + return new SelectedTabIterator(); + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/StringStreamFactory.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/StringStreamFactory.java new file mode 100755 index 0000000..b8c28ab --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/StringStreamFactory.java @@ -0,0 +1,47 @@ +/* + D-Bus Java Viewer + Copyright (c) 2006 Peter Cox + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.viewer; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.HashMap; +import java.util.Map; + +import org.freedesktop.dbus.bin.CreateInterface.PrintStreamFactory; + +/** + * A factory using a byte array input stream + * + * + * @author pete + * @since 10/02/2006 + */ +final class StringStreamFactory extends PrintStreamFactory +{ + Map<String, ByteArrayOutputStream> streamMap = new HashMap<String, ByteArrayOutputStream>(); + + /** {@inheritDoc} */ + public void init(String file, String path) + { + + } + + /** {@inheritDoc} */ + @SuppressWarnings("unused") + public PrintStream createPrintStream(final String file) throws IOException + { + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + streamMap.put(file, stream); + return new PrintStream(stream); + + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/TabbedSaveAction.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/TabbedSaveAction.java new file mode 100755 index 0000000..1f49c6a --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/TabbedSaveAction.java @@ -0,0 +1,108 @@ +/* + D-Bus Java Viewer + Copyright (c) 2006 Peter Cox + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.viewer; + +import static org.freedesktop.dbus.Gettext._; + +import java.awt.event.ActionEvent; +import java.io.File; + +import javax.swing.AbstractAction; +import javax.swing.JFileChooser; +import javax.swing.JOptionPane; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; +import javax.swing.text.JTextComponent; + +abstract class TabbedSaveAction extends AbstractAction implements Iterable<TextFile> +{ + /** File chooser component. + * Make static so that previous save location is stored + */ + private static JFileChooser chooser; + protected final JTabbedPane tabbedPane; + protected TabbedSaveAction(JTabbedPane tabbedPane) + { + super(); + this.tabbedPane = tabbedPane; + } + protected TabbedSaveAction(JTabbedPane tabbedPane, String name) + { + super(name); + this.tabbedPane = tabbedPane; + } + + /** Get the text file object associated with the supplied index + * @param index The tabbed pane index + * @return The text file object for the referenced tab + */ + protected TextFile getTextFile(int index) + { + JScrollPane scrollPane = (JScrollPane) tabbedPane.getComponentAt(index); + JTextComponent textComponent = (JTextComponent) scrollPane.getViewport().getView(); + final String sourceCode = textComponent.getText(); + + + + final String fileName = getFileName(index); + + + TextFile textFile = new TextFile(fileName, sourceCode); + return textFile; + } + + + /** Get the file name for the supplied index + * @param index The tabbed pane index + * @return The file name for the referenced tab + */ + protected String getFileName(int index) + { + return (index > -1) ? tabbedPane.getTitleAt(index) : ""; + } + + /** {@inheritDoc} */ + public final void actionPerformed(ActionEvent e) + { + + if (chooser == null) + { + /** Occurs on event dispatch thread, so no problems with lazy static init here */ + chooser = new JFileChooser(); + } + chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + chooser.setDialogTitle(_("Select parent directory for saving")); + + int result = chooser.showDialog(tabbedPane, "Select"); + + if (result == JFileChooser.APPROVE_OPTION) + { + File parentDirectory = chooser.getSelectedFile(); + if (parentDirectory.exists() || parentDirectory.mkdirs()) + { + if (parentDirectory.canWrite()) + { + Runnable runnable = new FileSaver(tabbedPane, parentDirectory, this); + + new Thread(runnable).start(); + } + else + { + JOptionPane.showMessageDialog(tabbedPane, _("Could not write to parent directory"), _("Invalid Parent Directory"), JOptionPane.ERROR_MESSAGE); + } + } + else + { + JOptionPane.showMessageDialog(tabbedPane, _("Could not access parent directory"), _("Invalid Parent Directory"), JOptionPane.ERROR_MESSAGE); + } + } + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/TextFile.java b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/TextFile.java new file mode 100755 index 0000000..ecff9a7 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/org/freedesktop/dbus/viewer/TextFile.java @@ -0,0 +1,49 @@ +/* + D-Bus Java Viewer + Copyright (c) 2006 Peter Cox + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU Lesser General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.viewer; + +/** A Text file abstraction + * + * + * @author pete + * @since 10/02/2006 + */ +class TextFile +{ + final String fileName; + final String contents; + /** Create the TextFile + * + * @param fileName The file name + * @param contents The contents + */ + public TextFile(String fileName, String contents) + { + this.fileName = fileName; + this.contents = contents; + } + /** Retrieve the fileName + * + * @return The fileName. + */ + String getFileName() + { + return fileName; + } + /** Retrieve the contents + * + * @return The contents. + */ + String getContents() + { + return contents; + } +} diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/tmp-session.conf b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/tmp-session.conf new file mode 100755 index 0000000..61279f0 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/tmp-session.conf @@ -0,0 +1,31 @@ +<!-- This configuration file controls the per-user-login-session message bus. + Add a session-local.conf and edit that rather than changing this + file directly. --> + +<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" + "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> +<busconfig> + <!-- Our well-known bus type, don't change this --> + <type>session</type> + + <listen>unix:path=./tmp-session-bus</listen> + <!--listen>tcp:port=12345</listen--> + + <servicedir>/usr/share/dbus-1/services</servicedir> + + <policy context="default"> + <!-- Allow everything to be sent --> + <allow send_destination="*"/> + <!-- Allow everything to be received --> + <allow eavesdrop="true"/> + <!-- Allow anyone to own anything --> + <allow own="*"/> + </policy> + + <!-- This is included last so local configuration can override what's + in this standard file --> + <include ignore_missing="yes">session-local.conf</include> + + <include if_selinux_enabled="yes" selinux_root_relative="yes">contexts/dbus_contexts</include> + +</busconfig> diff --git a/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/translations/en_GB.po b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/translations/en_GB.po new file mode 100755 index 0000000..d619633 --- /dev/null +++ b/src/traffic-incidents-service/org.genivi.trafficinfo.dbus-java/src/main/java/translations/en_GB.po @@ -0,0 +1,213 @@ +#java-format +msgid " is not a basic type" +msgstr " is not a basic type" +msgid " is not an object provided by this process." +msgstr " is not an object provided by this process." +msgid "Already iterated" +msgstr "Already iterated" +msgid "An error occurred while calling " +msgstr "An error occurred while calling " +msgid "Array index out of bounds, paofs={0}, pabuf.length={1}, buf.length={2}." +msgstr "Array index out of bounds, paofs={0}, pabuf.length={1}, buf.length={2}." +msgid "Arrays must not exceed " +msgstr "Arrays must not exceed " +msgid "Async call has not had a reply" +msgstr "Async call has not had a reply" +msgid "Bus address is blank" +msgstr "Bus address is blank" +msgid "Bus address is invalid: " +msgstr "Bus address is invalid: " +msgid "Can't wrap Null in a Variant" +msgstr "Can't wrap Null in a Variant" +msgid "Can't wrap a multi-valued type in a Variant: " +msgstr "Can't wrap a multi-valued type in a Variant: " +msgid "Can't wrap multiple or no types in a Variant: " +msgstr "Can't wrap multiple or no types in a Variant: " +msgid "Can't wrap {0} in an unqualified Variant ({1})." +msgstr "Can't wrap {0} in an unqualified Variant ({1})." +msgid "Cannot Resolve Session Bus Address" +msgstr "Cannot Resolve Session Bus Address" +msgid "Cannot watch for signals based on well known bus name as source, only unique names." +msgstr "Cannot watch for signals based on well known bus name as source, only unique names." +msgid "Connection has already sent a Hello message" +msgstr "Connection has already sent a Hello message" +msgid "Could not access parent directory for " +msgstr "Could not access parent directory for " +msgid "Could not create class from signal " +msgstr "Could not create class from signal " +msgid "Could not find an interface to cast to" +msgstr "Could not find an interface to cast to" +msgid "Could not load Dbus information for " +msgstr "Could not load Dbus information for " +msgid "DBusInterfaces cannot be declared outside a package" +msgstr "DBusInterfaces cannot be declared outside a package" +msgid "DBusInterfaces must be defined in a package." +msgstr "DBusInterfaces must be defined in a package." +msgid "Disconnected" +msgstr "Disconnected" +msgid "ERROR: Could not find introspection file: " +msgstr "ERROR: Could not find introspection file: " +msgid "ERROR: Expected {0}, got {1}, failed." +msgstr "ERROR: Expected {0}, got {1}, failed." +msgid "ERROR: Failed to get introspection data" +msgstr "ERROR: Failed to get introspection data" +msgid "ERROR: Failure in DBus Communications: " +msgstr "ERROR: Failure in DBus Communications: " +msgid "ERROR: Interface name was blank, failed" +msgstr "ERROR: Interface name was blank, failed" +msgid "ERROR: Method name was blank, failed" +msgstr "ERROR: Method name was blank, failed" +msgid "ERROR: Unknown node: " +msgstr "ERROR: Unknown node: " +msgid "ERROR: Unknown option: " +msgstr "ERROR: Unknown option: " +msgid "Error Executing Method {0}.{1}: {2}" +msgstr "Error Executing Method {0}.{1}: {2}" +msgid "Error deserializing message: number of parameters didn't match receiving signature" +msgstr "Error deserializing message: number of parameters didn't match receiving signature" +msgid "Error during parser init: " +msgstr "Error during parser init: " +msgid "Exporting non-exportable parameterized type " +msgstr "Exporting non-exportable parameterized type " +msgid "Exporting non-exportable type " +msgstr "Exporting non-exportable type " +msgid "Failed to add signal parameters: " +msgstr "Failed to add signal parameters: " +msgid "Failed to auth" +msgstr "Failed to auth" +msgid "Failed to connect to bus " +msgstr "Failed to connect to bus " +msgid "Failed to construct D-Bus type: " +msgstr "Failed to construct D-Bus type: " +msgid "Failed to construct outgoing method call: " +msgstr "Failed to construct outgoing method call: " +msgid "Failed to create proxy object for {0} exported by {1}. Reason: {2}" +msgstr "Failed to create proxy object for {0} exported by {1}. Reason: {2}" +msgid "Failed to create proxy object for {0}; reason: {1}." +msgstr "Failed to create proxy object for {0}; reason: {1}." +msgid "Failed to parse DBus type signature: " +msgstr "Failed to parse DBus type signature: " +msgid "Failed to parse DBus type signature: {0} ({1})." +msgstr "Failed to parse DBus type signature: {0} ({1})." +msgid "Failed to register bus name" +msgstr "Failed to register bus name" +msgid "Failure in de-serializing message: " +msgstr "Failure in de-serializing message: " +msgid "Introspected interface name exceeds 255 characters. Cannot export objects of type " +msgstr "Introspected interface name exceeds 255 characters. Cannot export objects of type " +msgid "Introspected method name exceeds 255 characters. Cannot export objects with method " +msgstr "Introspected method name exceeds 255 characters. Cannot export objects with method " +msgid "Introspected signal name exceeds 255 characters. Cannot export objects with signals of type " +msgstr "Introspected signal name exceeds 255 characters. Cannot export objects with signals of type " +msgid "Invalid Bus Type: " +msgstr "Invalid Bus Type: " +msgid "Invalid Command " +msgstr "Invalid Command " +msgid "Invalid Parent Directory" +msgstr "Invalid Parent Directory" +msgid "Invalid bus name" +msgstr "Invalid bus name" +msgid "Invalid bus name: " +msgstr "Invalid bus name: " +msgid "Invalid bus name: null" +msgstr "Invalid bus name: null" +msgid "Invalid object path: " +msgstr "Invalid object path: " +msgid "Invalid object path: null" +msgstr "Invalid object path: null" +msgid "Invalid type for match rule: " +msgstr "Invalid type for match rule: " +msgid "Map must have 2 parameters" +msgstr "Map must have 2 parameters" +msgid "Message Failed to Send: " +msgstr "Message Failed to Send: " +msgid "Message type {0} unsupported" +msgstr "Message type {0} unsupported" +msgid "Multi-valued array types not permitted" +msgstr "Multi-valued array types not permitted" +msgid "Must Specify an Object Path" +msgstr "Must Specify an Object Path" +msgid "Must specify destination, path and function name to MethodCalls." +msgstr "Must specify destination, path and function name to MethodCalls." +msgid "Must specify error name to Errors." +msgstr "Must specify error name to Errors." +msgid "Must specify object path, interface and signal name to Signals." +msgstr "Must specify object path, interface and signal name to Signals." +msgid "No reply within specified time" +msgstr "No reply within specified time" +msgid "No transport present" +msgstr "No transport present" +msgid "Not A DBus Interface" +msgstr "Not A DBus Interface" +msgid "Not A DBus Signal" +msgstr "Not A DBus Signal" +msgid "Not An Expected Convertion type from {0} to {1}" +msgstr "Not An Expected Convertion type from {0} to {1}" +msgid "Not Connected" +msgstr "Not Connected" +msgid "Not a primitive type" +msgstr "Not a primitive type" +msgid "Not a valid D-Bus type code: " +msgstr "Not a valid D-Bus type code: " +msgid "Not a wrapper type" +msgstr "Not a wrapper type" +msgid "Not an array" +msgstr "Not an array" +msgid "Not an object exported by this connection and no remote specified" +msgstr "Not an object exported by this connection and no remote specified" +msgid "Not enough elements to create custom object from serialized data ({0} < {1})." +msgstr "Not enough elements to create custom object from serialized data ({0} < {1})." +msgid "Object already exported" +msgstr "Object already exported" +msgid "Primative array being sent as non-primative array." +msgstr "Primative array being sent as non-primative array." +msgid "Processing DBus for " +msgstr "Processing DBus for " +msgid "Protocol version {0} is unsupported" +msgstr "Protocol version {0} is unsupported" +msgid "Return type of Object[] cannot be introspected properly" +msgstr "Return type of Object[] cannot be introspected properly" +msgid "Save " +msgstr "Save " +msgid "Save Failed" +msgstr "Save Failed" +msgid "Select parent directory for saving" +msgstr "Select parent directory for saving" +msgid "Sending message failed" +msgstr "Sending message failed" +msgid "Serializable classes must implement a deserialize method" +msgstr "Serializable classes must implement a deserialize method" +msgid "Serializable classes must serialize to native DBus types" +msgstr "Serializable classes must serialize to native DBus types" +msgid "Signals must be declared as a member of a class implementing DBusInterface which is the member of a package." +msgstr "Signals must be declared as a member of a class implementing DBusInterface which is the member of a package." +msgid "Spurious reply. No message with the given serial id was awaiting a reply." +msgstr "Spurious reply. No message with the given serial id was awaiting a reply." +msgid "System does not support UTF-8 encoding" +msgstr "System does not support UTF-8 encoding" +msgid "The method `{0}.{1}' does not exist on this object." +msgstr "The method `{0}.{1}' does not exist on this object." +msgid "The name `{0}' does not exist" +msgstr "The name `{0}' does not exist" +msgid "This service does not support " +msgstr "This service does not support " +msgid "Try saving other files?" +msgstr "Try saving other files?" +msgid "Trying to marshall to unconvertable type (from {0} to {1})." +msgstr "Trying to marshall to unconvertable type (from {0} to {1})." +msgid "Underlying transport returned EOF" +msgstr "Underlying transport returned EOF" +msgid "Waiting for: " +msgstr "Waiting for: " +msgid "Wrong return type (failed to de-serialize correct types: {0} )" +msgstr "Wrong return type (failed to de-serialize correct types: {0} )" +msgid "Wrong return type (got void, expected a value)" +msgstr "Wrong return type (got void, expected a value)" +msgid "Wrong return type (not expecting Tuple)" +msgstr "Wrong return type (not expecting Tuple)" +msgid "You must send a Hello message" +msgstr "You must send a Hello message" +msgid "unknown address type " +msgstr "unknown address type " +msgid "{0} is not between {1} and {2}." +msgstr "{0} is not between {1} and {2}." |