Add dbus-1-tqt to this SVN tree

Please keep it in sync with the master at svn.trinitydesktop.org
This is revision 167 from that source


git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/dependencies/dbus-1-tqt@1228687 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
v3.5.13-sru
tpearson 13 years ago
commit d2cf7fa569

@ -0,0 +1,5 @@
Harald Fernengel <harry@kdevelop.org>
Original developer
Kevin Krammer <kevin.krammer@gmx.at>
Initial port, current maintainer

@ -0,0 +1,103 @@
#################################################
#
# (C) 2010-2011 Serghei Amelian
# serghei (DOT) amelian (AT) gmail.com
#
# Improvements and feedback are welcome
#
# This file is released under GPL >= 2
#
#################################################
project( dbus-1-tqt )
##### cmake setup ###############################
cmake_minimum_required( VERSION 2.8 )
include( FindPkgConfig )
include( CheckCXXSourceCompiles )
set( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules" )
include( TDEMacros )
include( ConfigureChecks.cmake )
##### install paths setup #######################
tde_setup_install_path( EXEC_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" )
tde_setup_install_path( BIN_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/bin" )
tde_setup_install_path( LIB_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/lib${LIB_SUFFIX}" )
tde_setup_install_path( INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include/${CMAKE_PROJECT_NAME}" )
tde_setup_install_path( PKGCONFIG_INSTALL_DIR "${LIB_INSTALL_DIR}/pkgconfig" )
##### install headers ###########################
install( FILES
tqdbuserror.h tqdbusmessage.h tqdbusconnection.h
tqdbusvariant.h tqdbusobject.h tqdbusproxy.h
tqdbusmacros.h tqdbusdata.h tqdbusdatalist.h
tqdbusdatamap.h tqdbusobjectpath.h tqdbusdataconverter.h
DESTINATION ${INCLUDE_INSTALL_DIR} )
##### install other data ########################
##### write pkgconfig file ######################
string( REGEX REPLACE "^${CMAKE_INSTALL_PREFIX}" "\${prefix}" PC_EXEC_PREFIX ${EXEC_INSTALL_PREFIX} )
string( REGEX REPLACE "^${CMAKE_INSTALL_PREFIX}" "\${prefix}" PC_INCLUDE_DIR ${INCLUDE_INSTALL_DIR} )
string( REGEX REPLACE "^${CMAKE_INSTALL_PREFIX}" "\${prefix}" PC_LIB_DIR ${LIB_INSTALL_DIR} )
configure_file( dbus-1-tqt.pc.cmake dbus-1-tqt.pc @ONLY )
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/dbus-1-tqt.pc DESTINATION ${PKGCONFIG_INSTALL_DIR} )
##### build setup ###############################
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include tqt.h" )
set( CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined" )
add_definitions(
-DDBUS_COMPILATION
-DQT_THREAD_SUPPORT
${TQT_CFLAGS_OTHER}
)
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${TQT_INCLUDE_DIRS}
${DBUS_INCLUDE_DIRS}
)
link_directories(
${TQT_LIBRARY_DIRS}
)
##### dbus-1-tqt (shared) #########################
tde_add_library( dbus-1-tqt SHARED AUTOMOC
SOURCES ${dbus_tqt_MOCS}
tqdbusconnection.cpp tqdbuserror.cpp tqdbusintegrator.cpp
tqdbusmarshall.cpp tqdbusmessage.cpp tqdbusserver.cpp
tqdbusproxy.cpp tqdbusdata.cpp tqdbusdatalist.cpp
tqdbusobjectpath.cpp tqdbusdataconverter.cpp
VERSION 0.0.0
LINK ${TQT_LIBRARIES} ${DBUS_LIBRARIES}
DESTINATION ${LIB_INSTALL_DIR}
)
##### dbusxml2qt3 (executable) ##################
tde_add_executable( dbusxml2qt3
SOURCES
tools/dbusxml2qt3/classgen.cpp
tools/dbusxml2qt3/main.cpp
tools/dbusxml2qt3/methodgen.cpp
LINK ${TQT_LIBRARIES}
DESTINATION ${BIN_INSTALL_DIR}
)

@ -0,0 +1,10 @@
The software of this project is distributed under the terms of three
licenses.
The Qt3 D-Bus bindings library is distributed under the terms of
the Academic Free License version 2.1 (see COPYING.AFL for details)
as well as the GNU Public License 2.1 (or at your option any later version,
see COPYING.GPL for details)
The binding generator tool dbusxml2q3 is distributed under the terms
of the MIT licence (see tools/dbusxml2qt3/LICENSE for details)

@ -0,0 +1,54 @@
# Larry Rosen has ceased to use or recommend any version
# of the Academic Free License below version 2.1
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.

@ -0,0 +1,346 @@
NOTE! The GPL below is copyrighted by the Free Software Foundation, but
the instance of code that it refers to (the kde programs) are copyrighted
by the authors who actually wrote it.
---------------------------------------------------------------------------
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, 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 software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, 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 redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which tqcontains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
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 give any other recipients of the Program a copy of this License
along with the Program.
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 Program or any portion
of it, thus forming a work based on the Program, 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) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part tqcontains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
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 Program, 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 Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) 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; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it tqcontains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. 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.
If distribution of executable or 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 counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program 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.
5. 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 Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program 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.
7. 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 Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program 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 Program.
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.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program 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.
9. The Free Software Foundation may publish revised and/or new versions
of the 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 Program
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 Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, 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
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "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 PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. 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 PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), 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 Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. 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 program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; 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.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

@ -0,0 +1,51 @@
2008-06-05 krake: Updating changelog after forgetting about it for a long
time. Rather incomplete list, listing only major changes.
* Added dbusxml2qt3 code generation tool for creating client and server side
code based on D-Bus XML introspection data
* Added cross-bindings test suite support
* Added QDBusDataConverter template to build helper classes for
transforming native C++ types into QDBusData objects and vice versa
* Added support for nested containers
* Added support for empty containers
* Added support for D-Bus variant
* Handling D-Bus object path different than String
2006-01-28 krake:
* Added a default constructor to QDBusConnection which creates empty/null
connections suitable for variable initialization
* Fixed initialization of the connection member in QDBusProxy
* Use pkg-config to determine linker flags for the D-BUS base library
when building examples
* Added documentation on object registering to the service overview docs
* Added documentation on requesting service names to overview docs
* Added documentation on handling interfaces to service overview docs
* Added table of contents to client and service overview docs
2006-01-25 krake:
* Fixed pkg-config input files and got them installed
* Fixed build files to use new package name dbus-1-qt3 instead of the too
generic qdbus
2006-01-22 krake:
* API docs for QDBusMessage
2006-01-21 krake:
* API docs for QDBusProxy and overview documentation for using the bindings
in a client.
* Adjusted example programs to changed build situation
* Changed example programs to use non-GUI QApplication
* API docs for QDBusError, QDBusObjectBase and overview documentation for
using the bindings to provide services.
* Fixed service example
* API docs for QDBusConnection
2006-01-20 krake:
* Changed build files to be able to build with KDE 3.5 admin/ directory
2006-01-19 krake:
* Changed library name to from dbus-qt3-1 dbus-1-qt3. Seems more logical to
to me having the DBus version number closer to "dbus"
2006-01-17 krake:
* Imported my backport to the SVN directory originally created by Will
* Fixed licences (FSF address, missing licence in examle files)

@ -0,0 +1,19 @@
#################################################
#
# (C) 2010-2011 Serghei Amelian
# serghei (DOT) amelian (AT) gmail.com
#
# Improvements and feedback are welcome
#
# This file is released under GPL >= 2
#
#################################################
# dbus-1
pkg_search_module( DBUS dbus-1 )
if( NOT DBUS_FOUND )
tde_message_fatal( "dbus-1 is required, but was not found on your system" )
endif( )
# tqt
find_package( TQt )

@ -0,0 +1,184 @@
Basic Installation
==================
These are generic installation instructions.
The `configure' shell script attempts to guess correct values for
various system-dependent variables used during compilation. It uses
those values to create a `Makefile' in each directory of the package.
It may also create one or more `.h' files containing system-dependent
definitions. Finally, it creates a shell script `config.status' that
you can run in the future to recreate the current configuration, a file
`config.cache' that saves the results of its tests to speed up
reconfiguring, and a file `config.log' containing compiler output
(useful mainly for debugging `configure').
If you need to do unusual things to compile the package, please try
to figure out how `configure' could check whether to do them, and mail
diffs or instructions to the address given in the `README' so they can
be considered for the next release. If at some point `config.cache'
tqcontains results you don't want to keep, you may remove or edit it.
The file `configure.in' is used to create `configure' by a program
called `autoconf'. You only need `configure.in' if you want to change
it or regenerate `configure' using a newer version of `autoconf'.
The simplest way to compile this package is:
1. `cd' to the directory containing the package's source code and type
`./configure' to configure the package for your system. If you're
using `csh' on an old version of System V, you might need to type
`sh ./configure' instead to prevent `csh' from trying to execute
`configure' itself.
Running `configure' takes a while. While running, it prints some
messages telling which features it is checking for.
2. Type `gmake' to compile the package. Or if you're using a Linux
powered machine, or if make is GNU make, type `make'. You can
check with make --version. KDE requires GNU make to build, if
gmake is appropriate, tqreplace any instance below of make with gmake.
It will give output similar to:
#make --version
GNU Make version 3.78.1, by Richard Stallman and Roland McGrath.
Built for i386--freebsd4.0
Copyright (C) 1988, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99
...
3. Optionally, type `make check' to run any self-tests that come with
the package.
4. Type `make install' to install the programs and any data files and
documentation.
5. You can remove the program binaries and object files from the
source code directory by typing `make clean'. To also remove the
files that `configure' created (so you can compile the package for
a different kind of computer), type `make distclean'. There is
also a `make maintainer-clean' target, but that is intended mainly
for the package's developers. If you use it, you may have to get
all sorts of other programs in order to regenerate files that came
with the distribution.
Compilers and Options
=====================
Some systems require unusual options for compilation or linking that
the `configure' script does not know about. You can give `configure'
initial values for variables by setting them in the environment. Using
a Bourne-compatible shell, you can do that on the command line like
this:
CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
Or on systems that have the `env' program, you can do it like this:
env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
Compiling For Multiple Architectures
====================================
You can compile the package for more than one kind of computer at the
same time, by placing the object files for each architecture in their
own directory. To do this, you must use a version of `make' that
supports the `VPATH' variable, such as GNU `make'. `cd' to the
directory where you want the object files and executables to go and run
the `configure' script. `configure' automatically checks for the
source code in the directory that `configure' is in and in `..'.
If you have to use a `make' that does not supports the `VPATH'
variable, you have to compile the package for one architecture at a time
in the source code directory. After you have installed the package for
one architecture, use `make distclean' before reconfiguring for another
architecture.
Installation Names
==================
By default, `make install' will install the package's files in
`/usr/local/kde/bin', `/usr/local/kde/lib', etc. You can specify an
installation prefix other than `/usr/local/kde' by giving `configure'
the option `--prefix=PATH'.
You can specify separate installation prefixes for
architecture-specific files and architecture-independent files. If you
give `configure' the option `--exec-prefix=PATH', the package will use
PATH as the prefix for installing programs and libraries.
Documentation and other data files will still use the regular prefix.
If the package supports it, you can cause programs to be installed
with an extra prefix or suffix on their names by giving `configure' the
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
Optional Features
=================
Some packages pay attention to `--enable-FEATURE' options to
`configure', where FEATURE indicates an optional part of the package.
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
is something like `gnu-as' or `x' (for the X Window System). The
`README' should mention any `--enable-' and `--with-' options that the
package recognizes.
For packages that use the X Window System, `configure' can usually
tqfind the X include and library files automatically, but if it doesn't,
you can use the `configure' options `--x-includes=DIR' and
`--x-libraries=DIR' to specify their locations.
Specifying the System Type
==========================
There may be some features `configure' can not figure out
automatically, but needs to determine by the type of host the package
will run on. Usually `configure' can figure that out, but if it prints
a message saying it can not guess the host type, give it the
`--host=TYPE' option. TYPE can either be a short name for the system
type, such as `sun4', or a canonical name with three fields:
CPU-COMPANY-SYSTEM
See the file `config.sub' for the possible values of each field. If
`config.sub' isn't included in this package, then this package doesn't
need to know the host type.
If you are building compiler tools for cross-compiling, you can also
use the `--target=TYPE' option to select the type of system they will
produce code for and the `--build=TYPE' option to select the type of
system on which you are compiling the package.
Sharing Defaults
================
If you want to set default values for `configure' scripts to share,
you can create a site shell script called `config.site' that gives
default values for variables like `CC', `cache_file', and `prefix'.
`configure' looks for `PREFIX/share/config.site' if it exists, then
`PREFIX/etc/config.site' if it exists. Or, you can set the
`CONFIG_SITE' environment variable to the location of the site script.
A warning: not all `configure' scripts look for a site script.
Operation Controls
==================
`configure' recognizes the following options to control how it
operates.
`--cache-file=FILE'
Use and save the results of the tests in FILE instead of
`./config.cache'. Set FILE to `/dev/null' to disable caching, for
debugging `configure'.
`--help'
Print a summary of the options to `configure', and exit.
`--quiet'
`--silent'
`-q'
Do not print messages saying which checks are being made.
`--srcdir=DIR'
Look for the package's source code in directory DIR. Usually
`configure' can determine that directory automatically.
`--version'
Print the version of Autoconf used to generate the `configure'
script, and exit.
`configure' also accepts some other, not widely useful, options.

@ -0,0 +1,20 @@
This is a backport of Harald Fernengel's Qt4 D-Bus bindings.
Some Qt4 based code had no direct equivalent in Qt3. Cases where this
transition to Qt3 might not be fully correct are marked with FIXME-QT4
Depending on the use case it might be necessary to extend QDBusMesssage
to allow marshalling/de-marshalling based on an application provided
helper as the Qt3 QVariant can not handle all cases the Qt4 pendant can
(user defined types, etc)
In order to build you need to copy or symlink the kde-common/admin directory
into this directory and then run
make -f Makefile.cvs
to generate the configure script.

11
TODO

@ -0,0 +1,11 @@
- Have someone with Qt4 experience check the code marked with FIXME-QT4
- Port the Qt4 bindings' unit tests to something available for Qt3
- Add static methods for D-BUS standard errors to QDBusError.
At least for those a service implementation might need more often
- Check possibility of a QObject adapter implementation of QDBusObjectBase,
i.e. a making an QObject's Q_SLOTS callable through D-BUS

@ -0,0 +1,10 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=@PC_EXEC_PREFIX@
libdir=@PC_LIB_DIR@
includedir=@PC_INCLUDE_DIR@
Name: dbus-tqt
Description: DBUS bindings for the Trinity Qt [TQt] interface
Version: 0.9.0
Libs: -L${libdir} -ldbus-1-tqt
Cflags: -I${includedir}

@ -0,0 +1,4 @@
admin
dbus
debian
tools

@ -0,0 +1,18 @@
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.

File diff suppressed because it is too large Load Diff

@ -0,0 +1,54 @@
/*
* Copyright (C) 2007 Kevin Krammer <kevin.krammer@gmx.at>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#if !defined(CLASSGEN_H_INCLUDED)
#define CLASSGEN_H_INCLUDED
// forward declarations
class Class;
class TQDomElement;
class TQTextStream;
template<typename T> class TQValueList;
class ClassGenerator
{
public:
static bool initStreams(const TQString& baseName,
TQTextStream& headerStream, TQTextStream& sourceStream);
static bool finishStreams(const TQString& baseName,
TQTextStream& headerStream, TQTextStream& sourceStream);
static bool extractClass(const TQDomElement& interfaceElement, Class& classData);
static bool generateInterface(const Class& classData,
TQTextStream& headerStream,
TQTextStream& sourceStream);
static bool generateProxy(const Class& classData,
TQTextStream& headerStream, TQTextStream& sourceStream);
static bool generateNode(const Class& classData,
const TQValueList<Class>& interfaces,
TQTextStream& headerStream, TQTextStream& sourceStream);
};
#endif
// End of File

@ -0,0 +1,637 @@
/*
* Copyright (C) 2007 Kevin Krammer <kevin.krammer@gmx.at>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// standard includes
#include <iostream>
#include <cstdlib>
// TQt includes
#include <tqdom.h>
#include <tqfile.h>
#include <tqmap.h>
#include <tqtextstream.h>
// local includes
#include "classgen.h"
#include "methodgen.h"
typedef TQMap<TQString, TQString> OptionMap;
void usage();
OptionMap parseOptions(int argc, char** argv);
bool checkForOption(const OptionMap& options, const TQString& option)
{
return options.tqfind(option) != options.end();
}
int main(int argc, char** argv)
{
const OptionMap options = parseOptions(argc, argv);
if (!checkForOption(options, "filename"))
{
std::cerr << "dbusxml2qt3: introspection data file missing" << std::endl;
usage();
exit(1);
}
TQString fileName = options["filename"];
TQFile file(fileName);
if (!file.exists())
{
std::cerr << "dbusxml2qt3: introspection data file '"
<< fileName.local8Bit().data()
<< "' does not exist" << std::endl;
exit(2);
}
if (!file.open(IO_ReadOnly))
{
std::cerr << "dbusxml2qt3: introspection data file '"
<< fileName.local8Bit().data()
<< "' cannot be read" << std::endl;
exit(2);
}
TQDomDocument document;
if (!document.setContent(&file))
{
file.close();
std::cerr << "dbusxml2qt3: introspection data file '"
<< fileName.local8Bit().data()
<< "' cannot be parsed" << std::endl;
exit(2);
}
file.close();
TQDomElement rootElement = document.documentElement();
if (rootElement.isNull() || rootElement.tagName() != "node")
{
std::cerr << "dbusxml2qt3: introspection data file '"
<< fileName.local8Bit().data()
<< "' does not have a 'node' element as its root node"
<< std::endl;
exit(2);
}
TQValueList<Class> interfaces;
bool hasIntrospectable = false;
TQDomNode child = rootElement.firstChild();
for (; !child.isNull(); child = child.nextSibling())
{
if (!child.isElement()) continue;
TQDomElement element = child.toElement();
if (element.tagName() == "interface")
{
if (!element.attribute("name").isEmpty())
{
Class classData;
if (ClassGenerator::extractClass(element, classData))
{
if (classData.dbusName == "org.freedesktop.DBus.Introspectable")
hasIntrospectable = true;
else
interfaces << classData;
}
}
}
}
if (interfaces.isEmpty())
{
std::cerr << "dbusxml2qt3: introspection data file '"
<< fileName.local8Bit().data()
<< "' does not contain any valid interface descriptions"
<< std::endl;
exit(3);
}
bool generateProxies = checkForOption(options, "proxy");
bool generateInterfaces = checkForOption(options, "interface");
bool generateNode = checkForOption(options, "node");
// if no specific option is selected, we generate everything
bool generateAll = !(generateProxies || generateInterfaces || generateNode);
if (checkForOption(options, "classname"))
{
// class name only useful for single interfaces or just node
if (interfaces.count() > 1 && (generateAll || generateInterfaces || generateProxies))
{
std::cerr << "dbusxml2qt3: class name option specified but "
<< "introspection data file '"
<< fileName.local8Bit().data()
<< "' contains more than one interface description"
<< std::endl;
exit(3);
}
// class name for node is handled differently later on
if (!generateNode)
{
TQStringList nameParts = TQStringList::split("::", options["classname"]);
interfaces[0].name = nameParts.back();
nameParts.pop_back();
interfaces[0].namespaces = nameParts;
}
}
if (checkForOption(options, "namespace"))
{
TQStringList nameParts = TQStringList::split("::", options["namespace"]);
TQValueList<Class>::iterator it = interfaces.begin();
TQValueList<Class>::iterator endIt = interfaces.end();
for (; it != endIt; ++it)
{
(*it).namespaces = nameParts;
}
}
if (generateInterfaces || generateAll)
{
TQTextStream headerStream;
TQTextStream sourceStream;
TQString baseName = options["interface"];
if (!baseName.isEmpty())
{
if (!ClassGenerator::initStreams(baseName, headerStream, sourceStream))
{
std::cerr << "dbusxml2qt3: proxy files, using base name '"
<< baseName.local8Bit().data()
<< "', could not be opened for writing"
<< std::endl;
exit(4);
}
}
TQValueList<Class>::const_iterator it = interfaces.begin();
TQValueList<Class>::const_iterator endIt = interfaces.end();
for (; it != endIt; ++it)
{
if (baseName.isEmpty())
{
if (!ClassGenerator::initStreams((*it).name.lower() + "interface",
headerStream, sourceStream))
{
std::cerr << "dbusxml2qt3: interface files, using base name '"
<< baseName.local8Bit().data()
<< "', could not be opened for writing"
<< std::endl;
exit(4);
}
}
ClassGenerator::generateInterface(*it, headerStream, sourceStream);
if (baseName.isEmpty())
{
ClassGenerator::finishStreams((*it).name.lower() + "interface",
headerStream, sourceStream);
}
}
if (!baseName.isEmpty())
ClassGenerator::finishStreams(baseName, headerStream, sourceStream);
}
if (generateProxies || generateAll)
{
TQTextStream headerStream;
TQTextStream sourceStream;
TQString baseName = options["proxy"];
if (!baseName.isEmpty())
{
if (!ClassGenerator::initStreams(baseName, headerStream, sourceStream))
{
std::cerr << "dbusxml2qt3: proxy files, using base name '"
<< baseName.local8Bit().data()
<< "', could not be opened for writing"
<< std::endl;
exit(4);
}
}
TQValueList<Class>::const_iterator it = interfaces.begin();
TQValueList<Class>::const_iterator endIt = interfaces.end();
for (; it != endIt; ++it)
{
if (baseName.isEmpty())
{
if (!ClassGenerator::initStreams((*it).name.lower() + "proxy",
headerStream, sourceStream))
{
std::cerr << "dbusxml2qt3: proxy files, using base name '"
<< baseName.local8Bit().data()
<< "', could not be opened for writing"
<< std::endl;
exit(4);
}
}
ClassGenerator::generateProxy(*it, headerStream, sourceStream);
if (baseName.isEmpty())
{
ClassGenerator::finishStreams((*it).name.lower() + "proxy",
headerStream, sourceStream);
}
}
if (!baseName.isEmpty())
ClassGenerator::finishStreams(baseName, headerStream, sourceStream);
}
if (generateNode || generateAll)
{
if (!hasIntrospectable)
{
qDebug("Generating org.freedesktop.DBus.Introspectable on demand");
Class classData;
classData.name = "Introspectable";
classData.dbusName = "org.freedesktop.DBus.Introspectable";
classData.namespaces << "org" << "freedesktop" << "DBus";
Method method;
method.name = "Introspect";
method.noReply = false;
method.async = false;
Argument argument;
argument.name = "data";
argument.direction = Argument::Out;
argument.signature = "TQString";
argument.accessor = "String";
argument.isPrimitive = false;
argument.dbusSignature = "s";
argument.forwardDeclarations << "class TQString";
argument.sourceIncludes["TQt"].append("<tqstring.h>");
method.arguments << argument;
classData.methods << method;
TQTextStream headerStream;
TQTextStream sourceStream;
if (!ClassGenerator::initStreams(classData.name.lower() + "interface",
headerStream, sourceStream))
{
std::cerr << "dbusxml2qt3: interface files, using base name '"
<< classData.name.lower().local8Bit().data() << "interface"
<< "', could not be opened for writing"
<< std::endl;
exit(4);
}
ClassGenerator::generateInterface(classData,
headerStream, sourceStream);
ClassGenerator::finishStreams(classData.name.lower() + "interface",
headerStream, sourceStream);
}
TQString nodeClassName = options["classname"];
if (nodeClassName.isEmpty())
{
nodeClassName = rootElement.attribute("name");
if (nodeClassName.startsWith("/")) nodeClassName = nodeClassName.mid(1);
if (nodeClassName.isEmpty())
{
std::cerr << "dbusxml2qt3: cannot generate node without class name."
<< std::endl;
exit(3);
}
nodeClassName.tqreplace('/', "_");
}
TQStringList nameParts = TQStringList::split("::", nodeClassName);
Class classData;
classData.name = nameParts.back();
nameParts.pop_back();
classData.namespaces = nameParts;
if (checkForOption(options, "namespace"))
{
nameParts = TQStringList::split("::", options["namespace"]);
classData.namespaces = nameParts;
}
TQTextStream headerStream;
TQTextStream sourceStream;
TQString baseName = options["node"];
if (baseName.isEmpty()) baseName = classData.name.lower() + "node";
if (!ClassGenerator::initStreams(baseName, headerStream, sourceStream))
{
std::cerr << "dbusxml2qt3: interface files, using base name '"
<< baseName.local8Bit().data()
<< "', could not be opened for writing"
<< std::endl;
exit(4);
}
ClassGenerator::generateNode(classData, interfaces,
headerStream, sourceStream);
ClassGenerator::finishStreams(baseName, headerStream, sourceStream);
}
return 0;
}
void usage()
{
std::cout << "usage: dbusxml2qt3 [options] <introspectionfile>" << std::endl;
std::cout << std::endl;
std::cout << "Options:" << std::endl;
std::cout << "-h, --help" << std::endl;
std::cout << "\tDisplay this help" << std::endl;
std::cout << std::endl;
std::cout << "-c <classname>, --class <classname>" << std::endl;
std::cout << "\tUse 'classname' instead of last string in interface name"
<< std::endl;
std::cout << std::endl;
std::cout << "-N [namespace], --namespace [namespace]" << std::endl;
std::cout << "\tOverride namespaces. If provided, use 'namespace' instead, otherwise ignore namespaces"
<< std::endl;
std::cout << std::endl;
std::cout << "-i [basename], --interface [basename]" << std::endl;
std::cout << "\tGenerate interface files. If provided, use 'basename' for filenames"
<< std::endl;
std::cout << std::endl;
std::cout << "-p [basename], --proxy [basename]" << std::endl;
std::cout << "\tGenerate proxy files. If provided, use 'basename' for filenames"
<< std::endl;
std::cout << std::endl;
std::cout << "-n [basename], --node [basename]" << std::endl;
std::cout << "\tGenerate node files. If provided, use 'basename' for filenames"
<< std::endl;
std::cout << std::endl;
std::cout << "Examples:" << std::endl;
std::cout << "dbusxml2qt3 myinterface.xml" << std::endl;
std::cout << "\tGenerates as much as possible, i.e. interfaces, proxies and, "
<< "if a node name is specified in 'myinterface.xml', the node files"
<< std::endl;
std::cout << "\tUses lowercased interface names as plus type specific suffix "
<< "for the file names" << std::endl;
std::cout << std::endl;
std::cout << "dbusxml2qt3 myinterface.xml -N" << std::endl;
std::cout << "\tSame as first example but does not use namespaces"
<< std::endl;
std::cout << std::endl;
std::cout << "dbusxml2qt3 myinterface.xml -N org::myorg" << std::endl;
std::cout << "\tSame as first example but overrides namespaces with 'org::myorg'"
<< std::endl;
std::cout << std::endl;
std::cout << "dbusxml2qt3 myinterface.xml -n mynode -c MyNode" << std::endl;
std::cout << "\tGenerate only node files, use 'mynode' as the file basename "
<< "and classname 'MyClass'"
<< std::endl;
std::cout << std::endl;
std::cout << "dbusxml2qt3 myinterface.xml -p" << std::endl;
std::cout << "\tGenerate only proxy files, use default file basename"
<< std::endl;
std::cout << std::endl;
std::cout << "dbusxml2qt3 myinterface.xml -p myproxy" << std::endl;
std::cout << "\tGenerate only proxy files, use 'myproxy' as the file basename"
<< std::endl;
std::cout << std::endl;
}
bool testAndSetOption(OptionMap& options, const TQString& option, const TQString& value)
{
OptionMap::iterator it = options.tqfind(option);
if (it == options.end())
{
options.insert(option, value);
return true;
}
return false;
}
OptionMap parseOptions(int argc, char** argv)
{
TQStringList args;
for (int i = 1; i < argc; ++i)
{
args << TQString::fromLocal8Bit(argv[i]);
}
OptionMap options;
while (!args.isEmpty())
{
TQString arg = args.front();
args.pop_front();
if (arg.startsWith("-"))
{
if (arg.endsWith("help"))
{
usage();
exit(0);
}
else if (arg == "-p" || arg == "--proxy")
{
// test for optional argument
TQString value;
if (!args.isEmpty() > 0 && !args[0].startsWith("-"))
{
value = args.front();
args.pop_front();
}
if (!testAndSetOption(options, "proxy", value))
{
std::cerr << "Error while parsing command line argument '"
<< arg.local8Bit().data() << "'";
if (!value.isEmpty())
std::cerr << ", value '" << value.local8Bit().data() << "':";
else
std::cerr << ":";
std::cerr << " already set to '"
<< options["proxy"].local8Bit().data() << std::endl;
}
}
else if (arg == "-i" || arg == "--interface")
{
// test for optional argument
TQString value;
if (!args.isEmpty() > 0 && !args[0].startsWith("-"))
{
value = args.front();
args.pop_front();
}
if (!testAndSetOption(options, "interface", value))
{
std::cerr << "Error while parsing command line argument '"
<< arg.local8Bit().data() << "'";
if (!value.isEmpty())
std::cerr << ", value '" << value.local8Bit().data() << "':";
else
std::cerr << ":";
std::cerr << " already set to '"
<< options["interface"].local8Bit().data() << std::endl;
}
}
else if (arg == "-n" || arg == "--node")
{
// test for optional argument
TQString value;
if (!args.isEmpty() > 0 && !args[0].startsWith("-"))
{
value = args.front();
args.pop_front();
}
if (!testAndSetOption(options, "node", value))
{
std::cerr << "Error while parsing command line argument '"
<< arg.local8Bit().data() << "'";
if (!value.isEmpty())
std::cerr << ", value '" << value.local8Bit().data() << "':";
else
std::cerr << ":";
std::cerr << " already set to '"
<< options["node"].local8Bit().data() << std::endl;
}
}
else if (arg == "-N" || arg == "--namespace")
{
// test for optional argument
TQString value;
if (!args.isEmpty() > 0 && !args[0].startsWith("-"))
{
value = args.front();
args.pop_front();
}
if (!testAndSetOption(options, "namespace", value))
{
std::cerr << "Error while parsing command line argument '"
<< arg.local8Bit().data() << "'";
if (!value.isEmpty())
std::cerr << ", value '" << value.local8Bit().data() << "':";
else
std::cerr << ":";
std::cerr << " already set to '"
<< options["namespace"].local8Bit().data() << std::endl;
}
}
else if (arg == "-c" || arg == "--class")
{
// test for mandatory argument
if (args.isEmpty() || args[0].startsWith("-"))
{
std::cerr << "Error while parsing command line argument '"
<< arg.local8Bit().data()
<< "': mandatory parameter missing" << std::endl;
usage();
exit(1);
}
TQString value = args.front();
args.pop_front();
if (!testAndSetOption(options, "classname", value))
{
std::cerr << "Error while parsing command line argument '"
<< arg.local8Bit().data() << "'";
if (!value.isEmpty())
std::cerr << ", value '" << value.local8Bit().data() << "':";
else
std::cerr << ":";
std::cerr << " already set to '"
<< options["classname"].local8Bit().data() << std::endl;
}
}
else
{
std::cerr << "Error while parsing command line argument '"
<< arg.local8Bit().data()
<< "': unknown option" << std::endl;
usage();
exit(1);
}
}
else
{
if (!testAndSetOption(options, "filename", arg))
{
std::cerr << "Error while parsing command line argument '"
<< arg.local8Bit().data()
<< "': introspection file already given as '"
<< options["filename"].local8Bit().data() << std::endl;
usage();
exit(1);
}
}
}
return options;
}
// End of File

File diff suppressed because it is too large Load Diff

@ -0,0 +1,153 @@
/*
* Copyright (C) 2007 Kevin Krammer <kevin.krammer@gmx.at>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#if !defined(METHODGEN_H_INCLUDED)
#define METHODGEN_H_INCLUDED
// TQt includes
#include <tqmap.h>
#include <tqstringlist.h>
// forward declarations
class TQTextStream;
class Argument
{
public:
enum Direction
{
In,
Out
};
TQString name;
TQString annotatedType;
TQString signature;
TQString accessor;
TQString subAccessor;
TQString containerClass;
Direction direction;
bool isPrimitive;
TQStringList forwardDeclarations;
TQMap<TQString, TQStringList> headerIncludes;
TQMap<TQString, TQStringList> sourceIncludes;
TQString dbusSignature;
};
class Method
{
public:
TQString name;
TQValueList<Argument> arguments;
bool noReply;
bool async;
};
class Property : public Argument
{
public:
bool read;
bool write;
};
class Class
{
public:
enum Role
{
Interface,
Proxy,
Node
};
TQString name;
TQString dbusName;
TQStringList namespaces;
TQValueList<Method> methods;
TQValueList<Method> msignals;
TQValueList<Property> properties;
TQValueList<Method> asyncMethods;
TQValueList<Method> asyncReplySignals;
TQValueList<Method> asyncReplyMethods;
};
class MethodGenerator
{
public:
static bool extractMethods(const TQDomElement& interfaceElement,
Class& classData);
static void writeMethodDeclaration(const Method& method, bool pureVirtual,
bool withError, TQTextStream& stream);
static void writePropertyDeclaration(const Property& property, bool pureVirtual,
TQTextStream& stream);
static void writeMethodCallDeclaration(const Method& method,
TQTextStream& stream);
static void writeMethodCall(const Class& classData, const Method& method,
TQTextStream& stream);
static void writeSignalEmitter(const Class& classData, const Method& method,
TQTextStream& stream);
static void writeInterfaceAsyncReplyHandler(const Class& classData,
const Method& method,
TQTextStream& stream);
static void writeInterfaceMainMethod(const Class& classData,
TQTextStream& stream);
static void writeSignalHandler(const Class& classData, TQTextStream& stream);
static void writeProxyBegin(const Class& classData, TQTextStream& stream);
static void writeProxyMethod(const TQString& className, const Method& method,
TQTextStream& stream);
static void writeProxyGenericProperty(const Class& classData,
TQTextStream& stream);
static void writeProxyProperty(const Class& classData, const Property& property,
TQTextStream& stream);
static void writeProxyAsyncReplyHandler(const Class& classData,
TQTextStream& stream);
static void writeIntrospectionDataMethod(const Class& classData,
TQTextStream& stream);
static void writeNodePrivate(const Class& classData, TQTextStream& stream);
static void writeNodeBegin(const Class& classData, TQTextStream& stream);
static void writeNodeMethods(const Class& classData,
const TQValueList<Class>& interfaces, TQTextStream& stream);
};
#endif
// End of File

@ -0,0 +1,40 @@
/* qdbusatomic.h Dummy reference counter
*
* Copyright (C) 2005 Kevin Krammer <kevin.krammer@gmx.at>
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*/
#ifndef ATOMIC_H
#define ATOMIC_H
class Atomic
{
public:
Atomic(int value);
void ref();
bool deref();
private:
int m_value;
};
#endif

@ -0,0 +1,396 @@
/* qdbusconnection.cpp
*
* Copyright (C) 2005 Harald Fernengel <harry@kdevelop.org>
* Copyright (C) 2005-2007 Kevin Krammer <kevin.krammer@gmx.at>
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*/
#include <tqapplication.h>
#include "tqdbusconnection.h"
#include "tqdbuserror.h"
#include "tqdbusmessage.h"
#include "tqdbusconnection_p.h"
QT_STATIC_CONST_IMPL char *TQT_DBusConnection::default_connection_name = "qt_dbus_default_connection";
class TQT_DBusConnectionManager
{
public:
TQT_DBusConnectionManager(): default_connection(0) {}
~TQT_DBusConnectionManager();
void bindToApplication();
TQT_DBusConnectionPrivate *connection(const TQString &name) const;
void removeConnection(const TQString &name);
void setConnection(const TQString &name, TQT_DBusConnectionPrivate *c);
static TQT_DBusConnectionManager* instance() {
if (managerInstance == 0) managerInstance = new TQT_DBusConnectionManager();
return managerInstance;
}
private:
TQT_DBusConnectionPrivate *default_connection;
// FIXME-QT4 TQHash<TQString, TQT_DBusConnectionPrivate *> connectionHash;
typedef TQMap<TQString, TQT_DBusConnectionPrivate*> ConnectionHash;
ConnectionHash connectionHash;
static TQT_DBusConnectionManager* managerInstance;
};
// FIXME-QT4 TQ_GLOBAL_STATIC(TQT_DBusConnectionManager, manager);
TQT_DBusConnectionManager* TQT_DBusConnectionManager::managerInstance = 0;
TQT_DBusConnectionManager* manager() {
return TQT_DBusConnectionManager::instance();
}
TQT_DBusConnectionPrivate *TQT_DBusConnectionManager::connection(const TQString &name) const
{
if (name == TQString::tqfromLatin1(TQT_DBusConnection::default_connection_name))
return default_connection;
ConnectionHash::const_iterator it = connectionHash.tqfind(name);
return (it != connectionHash.end() ? it.data() : 0);
}
void TQT_DBusConnectionManager::removeConnection(const TQString &name)
{
TQT_DBusConnectionPrivate *d = 0;
if (name == TQString::tqfromLatin1(TQT_DBusConnection::default_connection_name)) {
d = default_connection;
default_connection = 0;
} else {
ConnectionHash::iterator it = connectionHash.tqfind(name);
if (it == connectionHash.end())
return;
d = it.data();
connectionHash.erase(it);
}
if (!d->ref.deref())
delete d;
}
TQT_DBusConnectionManager::~TQT_DBusConnectionManager()
{
if (default_connection) {
delete default_connection;
default_connection = 0;
}
/* FIXME-QT4
for (TQHash<TQString, TQT_DBusConnectionPrivate *>::const_iterator it = connectionHash.constBegin();
it != connectionHash.constEnd(); ++it) {
delete it.value();
}*/
for (ConnectionHash::const_iterator it = connectionHash.constBegin();
it != connectionHash.constEnd(); ++it)
{
delete it.data();
}
connectionHash.clear();
}
void TQT_DBusConnectionManager::bindToApplication()
{
if (default_connection) {
default_connection->bindToApplication();
}
/* FIXME-QT4
for (TQHash<TQString, TQT_DBusConnectionPrivate *>::const_iterator it = connectionHash.constBegin();
it != connectionHash.constEnd(); ++it) {
(*it)->bindToApplication();
}*/
for (ConnectionHash::const_iterator it = connectionHash.constBegin();
it != connectionHash.constEnd(); ++it)
{
it.data()->bindToApplication();
}
}
void qDBusBindToApplication()
{
manager()->bindToApplication();
}
void TQT_DBusConnectionManager::setConnection(const TQString &name, TQT_DBusConnectionPrivate *c)
{
if (name == TQString::tqfromLatin1(TQT_DBusConnection::default_connection_name))
default_connection = c;
else
connectionHash[name] = c;
}
TQT_DBusConnection::TQT_DBusConnection() : d(0)
{
}
TQT_DBusConnection::TQT_DBusConnection(const TQString &name)
{
d = manager()->connection(name);
if (d)
d->ref.ref();
}
TQT_DBusConnection::TQT_DBusConnection(const TQT_DBusConnection &other)
{
d = other.d;
if (d)
d->ref.ref();
}
TQT_DBusConnection::~TQT_DBusConnection()
{
if (d && !d->ref.deref())
delete d;
}
TQT_DBusConnection &TQT_DBusConnection::operator=(const TQT_DBusConnection &other)
{
if (other.d)
other.d->ref.ref();
/* FIXME-QT4
TQT_DBusConnectionPrivate *old = static_cast<TQT_DBusConnectionPrivate *>(
q_atomic_set_ptr(&d, other.d));*/
TQT_DBusConnectionPrivate* old = d;
d = other.d;
if (old && !old->ref.deref())
delete old;
return *this;
}
TQT_DBusConnection TQT_DBusConnection::sessionBus()
{
return addConnection(TQT_DBusConnection::SessionBus);
}
TQT_DBusConnection TQT_DBusConnection::systemBus()
{
return addConnection(TQT_DBusConnection::SystemBus);
}
TQT_DBusConnection TQT_DBusConnection::addConnection(BusType type, const TQString &name)
{
// Q_ASSERT_X(TQCoreApplication::instance(), "TQT_DBusConnection::addConnection",
// "Cannot create connection without a Q[Core]Application instance");
TQT_DBusConnectionPrivate *d = manager()->connection(name);
if (d)
return TQT_DBusConnection(name);
d = new TQT_DBusConnectionPrivate;
DBusConnection *c = 0;
switch (type) {
case SystemBus:
c = dbus_bus_get(DBUS_BUS_SYSTEM, &d->error);
break;
case SessionBus:
c = dbus_bus_get(DBUS_BUS_SESSION, &d->error);
break;
case ActivationBus:
c = dbus_bus_get(DBUS_BUS_STARTER, &d->error);
break;
}
d->setConnection(c); //setConnection does the error handling for us
manager()->setConnection(name, d);
return TQT_DBusConnection(name);
}
TQT_DBusConnection TQT_DBusConnection::addConnection(const TQString &address,
const TQString &name)
{
// Q_ASSERT_X(TQCoreApplication::instance(), "TQT_DBusConnection::addConnection",
// "Cannot create connection without a Q[Core]Application instance");
TQT_DBusConnectionPrivate *d = manager()->connection(name);
if (d)
return TQT_DBusConnection(name);
d = new TQT_DBusConnectionPrivate;
// setConnection does the error handling for us
d->setConnection(dbus_connection_open(address.utf8().data(), &d->error));
manager()->setConnection(name, d);
return TQT_DBusConnection(name);
}
void TQT_DBusConnection::closeConnection(const TQString &name)
{
manager()->removeConnection(name);
}
void TQT_DBusConnectionPrivate::timerEvent(TQTimerEvent *e)
{
DBusTimeout *timeout = timeouts[e->timerId()];
dbus_timeout_handle(timeout);
}
bool TQT_DBusConnection::send(const TQT_DBusMessage &message) const
{
if (!d || !d->connection)
return false;
DBusMessage *msg = message.toDBusMessage();
if (!msg)
return false;
bool isOk = dbus_connection_send(d->connection, msg, 0);
dbus_message_unref(msg);
return isOk;
}
int TQT_DBusConnection::sendWithAsyncReply(const TQT_DBusMessage &message, TQObject *receiver,
const char *method) const
{
if (!d || !d->connection)
return 0;
return d->sendWithReplyAsync(message, receiver, method);
}
TQT_DBusMessage TQT_DBusConnection::sendWithReply(const TQT_DBusMessage &message, TQT_DBusError *error) const
{
if (!d || !d->connection)
return TQT_DBusMessage::fromDBusMessage(0);
DBusMessage *msg = message.toDBusMessage();
if (!msg)
return TQT_DBusMessage::fromDBusMessage(0);
DBusMessage *reply = dbus_connection_send_with_reply_and_block(d->connection, msg,
-1, &d->error);
if (d->handleError() && error)
*error = d->lastError;
dbus_message_unref(msg);
return TQT_DBusMessage::fromDBusMessage(reply);
}
void TQT_DBusConnection::flush() const
{
if (!d || !d->connection) return;
d->flush();
}
void TQT_DBusConnection::dispatch() const
{
if (!d || !d->connection) return;
d->dispatch();
}
void TQT_DBusConnection::scheduleDispatch() const
{
if (!d || !d->connection) return;
d->scheduleDispatch();
}
bool TQT_DBusConnection::connect(TQObject* object, const char* slot)
{
if (!d || !d->connection || !object || !slot)
return false;
bool ok = object->connect(d, TQT_SIGNAL(dbusSignal(const TQT_DBusMessage&)), slot);
return ok;
}
bool TQT_DBusConnection::disconnect(TQObject* object, const char* slot)
{
if (!d || !d->connection || !object || !slot)
return false;
bool ok = d->disconnect(object, slot);
return ok;
}
bool TQT_DBusConnection::registerObject(const TQString& path, TQT_DBusObjectBase* object)
{
if (!d || !d->connection || !object || path.isEmpty())
return false;
TQT_DBusConnectionPrivate::ObjectMap::const_iterator it = d->registeredObjects.tqfind(path);
if (it != d->registeredObjects.end())
return false;
d->registeredObjects.insert(path, object);
return true;
}
void TQT_DBusConnection::unregisterObject(const TQString &path)
{
if (!d || !d->connection || path.isEmpty())
return;
TQT_DBusConnectionPrivate::ObjectMap::iterator it = d->registeredObjects.tqfind(path);
if (it == d->registeredObjects.end())
return ;
d->registeredObjects.erase(it);
}
bool TQT_DBusConnection::isConnected( ) const
{
return d && d->connection && dbus_connection_get_is_connected(d->connection);
}
TQT_DBusError TQT_DBusConnection::lastError() const
{
return d ? d->lastError : TQT_DBusError();
}
TQString TQT_DBusConnection::uniqueName() const
{
return d && d->connection ?
TQString::fromUtf8(dbus_bus_get_unique_name(d->connection))
: TQString();
}
bool TQT_DBusConnection::requestName(const TQString &name, int modeFlags)
{
Q_ASSERT(modeFlags >= 0);
if (!d || !d->connection)
return false;
if (modeFlags < 0)
return false;
int dbusFlags = 0;
if (modeFlags & AllowReplace)
dbusFlags |= DBUS_NAME_FLAG_ALLOW_REPLACEMENT;
if (modeFlags & ReplaceExisting)
dbusFlags |= DBUS_NAME_FLAG_REPLACE_EXISTING;
dbus_bus_request_name(d->connection, name.utf8(), dbusFlags, &d->error);
return !d->handleError();
}
#include "tqdbusconnection.moc"

@ -0,0 +1,662 @@
/* qdbusconnection.h TQT_DBusConnection object
*
* Copyright (C) 2005 Harald Fernengel <harry@kdevelop.org>
* Copyright (C) 2005-2007 Kevin Krammer <kevin.krammer@gmx.at>
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*/
#ifndef TQDBUSCONNECTION_H
#define TQDBUSCONNECTION_H
/**
* @mainpage TQt3 Bindings for D-Bus
*
* D-Bus is an IPC (inter process communication) technology designed to allow
* applications to interoperate without requiring tight coupling.
*
* For more information about D-Bus itself see its website:
* http://www.freedesktop.org/wiki/Software_2fdbus
*
* The TQt3 D-Bus bindings described here are a TQt3 style API around the base
* implementation to enable TQt3 developers to use D-Bus in their applications
* without requiring them to know about the details of the C based D-Bus API.
*
* The two main use cases are:
* - using the API to access service implemented in other applications.
* See section @ref dbusclient for an introduction on this
*
* - using the API to provide access to services implemented in your application
* See section @ref dbusservice for an introduction on this
*
* Of course an application can do both at the same time.
*/
/**
* @page dbusconventions Naming and syntax conventions in D-Bus
*
* @section dbusconventions-servicename Service names
*
* The service name is D-Bus application identifier, i.e. either
* the unique name handed out to the peer application by the bus on connect
* (see TQT_DBusConnection::uniqueName()) or, more likely, a well known name the
* peer application has requested, see TQT_DBusConnection::requestName()
*
* Such well known names have the form of word separated by dots, like
* Internet domain names but in reverse order.
*
* For example the name for the bus itself (the D-Bus daemon) would be
* @code
* "org.freedesktop.DBus"
* @endcode
*
* @section dbusconventions-objectpath Object paths
*
* The object path is like an address within the peer host application.
* The path format looks like a Unix file path, i.e. words separated by
* slash @c '/' characters.
*
* For example the path for the bus itself (the D-Bus daemon's main object)
* would be
* @code
* "/org/freedesktop/DBus"
* @endcode
*
* @section dbusconventions-interfacename Interface names
*
* The interface name specifies which group of methods and signals
* implemented by the peer service object is used in proxy operations.
*
* Interface names have the form of word separated by dots, like Internet
* domain names but in reverse order or like a fully qualified Java class name.
*
* For example the interface for the bus itself (the D-Bus daemon's main
* interface) would be
* @code
* "org.freedesktop.DBus"
* @endcode
*
* @section dbusconventions-errorname Error names
*
* A D-Bus error name is a sequence of words separated by dots, similar
* to D-Bus service names or interface names, or like a fully qualified
* Java class name.
*
* For example if a D-Bus service does not handle a method invocation sent
* to it because it doesn't know about the method it will return a D-Bus
* error named
* @code
* "org.freedesktop.DBus.Error.UnknownMethod"
* @endcode
* TQT_DBusError can create some of the more common errors based on a type value
* and decode their names into the type respectively. See TQT_DBusError#ErrorType
*
* @section dbusconventions-membername Method and signal names
*
* There is no mandatory convention for member names, neither for methods nor
* for signals.
*
* However, using the standard interfaces of D-Bus as a hint, it is recommended
* to use "camel case" names starting with an uppercase letter, for example
* @code
* "GetConnectionUnixUser"
* @endcode
*/
#include "tqdbusmacros.h"
#include <tqstring.h>
class TQT_DBusConnectionPrivate;
class TQT_DBusError;
class TQT_DBusMessage;
class TQT_DBusObjectBase;
class TQObject;
/**
* @brief Provides access to a specific D-Bus bus
*
* In order to access a D-Bus message bus an application has to connect to it.
* This is very similar to connecting to an FTP server using TQFtp, where any
* number of commands can be sent in sequence over the same connection.
*
* Additionally to the asynchronous command execution provided by TQFtp a
* TQT_DBusConnection can also execute synchronous (blocking) calls so the
* code around those calls stays closer to in-process method incovations.
*
* However it is recommended to only perform blocking calls on D-Bus service
* methods that are likely to be processed fast.
*
* TQT_DBusConnection implements a shared resource, i.e. if you create a
* connection with a specific name in one part of your code and then
* create one with the same name somewhere else, the second creation will
* actually return the same shared connection object the first caller created.
*
* The application can be connected to more than one message bus simultaniously
* using one or more connections per bus, however the most common case is to
* have one connection per bus.
*
* The two main bus types are:
* - System bus: a bus connecting applications on one system across user
* or session boundaries, for example allowing to communicate
* with system services like printer spoolers, etc
*
* - Session bus: a bus connecting applications within one user session, for
* example started at login or by a session manager. Use cases
* or this kind of bus would be accessing user specific
* resources like addressbooks, retrieving user settings or
* controlling session services (e.g. disabling screensaver
* in a video player application during playback)
*
* While TQT_DBusConnection provides the basic API to access D-Bus services
* it is more convenient to use TQT_DBusProxy on top of the connection.
*
* See sections @ref dbusclient and @ref dbusservice for examples
*/
class TQDBUS_EXPORT TQT_DBusConnection
{
public:
/**
* DBus bus types
*/
enum BusType
{
/**
* The session bus is a user and user session specific message
* channel. It will usually be started by a login script or a
* session manager.
*/
SessionBus,
/**
* The system bus is a message channel bridging user level and
* system level process boundaries, e.g. it can allow a user process
* with normal user access restrictions to perform a limited subset
* of operations on a process running with elevated rights.
*
* @warning if an applications exposed services on the system bus, i.e.
* registers objects using registerObject(), it should be
* carefully examined on potential security issues
*/
SystemBus,
// TODO tqfind out about ActivationBus purpose
ActivationBus
};
/**
* @brief Creates an empty/disconnected connection handle
*
* This is mainly used for initializing variables of this type, i.e. like
* the default TQString constructor.
*
* A variable set to such an empty connection can be assigned a working
* connection at any time.
*/
TQT_DBusConnection();
/**
* @brief Creates a connection handle to a named connection
*
* This will result in an disconnected connection handle if no
* connection with that name has been created by addConnection before.
*
* Therefore it is recommended to use addConnection() instead to get a
* connection handle.
*
* @param name identifier of the shared connection object
*/
TQT_DBusConnection(const TQString &name);
/**
* @brief Creates a shallow copy of the given connection
*
* Allows to pass connection handles around by value, similar to TQString
* thus avoiding problems like dangling pointers in application code
*
* @param other the connection to copy from
*/
TQT_DBusConnection(const TQT_DBusConnection &other);
/**
* @brief Destroys the connection handle
*
* If this handle is the last one referencing the shared connection object
* it will delete it, disconnecting it from any objects it was
* collaborating with
*/
~TQT_DBusConnection();
/**
* @brief Creates a shallow copy of the given connection
*
* Allows to pass connection handles around by value, similar to TQString
* thus avoiding problems like dangling pointers in application code
*
* @param other the connection to copy from
*
* @return a reference to this instance as required by assigment operator
* semantics
*/
TQT_DBusConnection &operator=(const TQT_DBusConnection &other);
/**
* @brief Returns whether the connection is connected to a bus
*
* @return @c true if the connection can be used, @c false if the handle
* does not have access to a shared connection object or if the
* connection to the bus could not be established or broke
*/
bool isConnected() const;
/**
* @brief Returns the last error seen by the connection
*
* This can be a connection error, e.g. attempt to connect failed, or a
* transmission error or an error reported by a method call
*
* @return the last error seen by the connection
*/
TQT_DBusError lastError() const;
/**
* @brief Flags for controlling the behavior name collision handling
*
* @see requestName()
*/
enum NameRequestMode
{
/**
* Do not allow others to take over a name requested by this
* application
*/
NoReplace = 0,
/**
* Allow other applications that request the same name to get it,
* i.e. allow the bus to transfer the name from this application
* to the one requesting it
*/
AllowReplace = 1,
/**
* Try to get the name transferred from the current owner to this
* application. This will only work if the other application as
* requested the name using the AllowReplace flag
*/
ReplaceExisting = 2
};
/**
* @brief Requests to be addressable on the bus by a given name
*
* Each connection to a bus gets a unique name once the connection is
* established. This is similar to getting an IP address when connecting
* to the Internet.
*
* If an application's purpose is to provide services to other applications
* the other applications require to know how to address the service
* provider. Similar to a domain name on the Internet D-Bus allows to
* register names on the bus and be addressed through those names instead
* of the connection identifier.
*
* @note this is not required if the application only needs to acccess
* services or only implements generic service APIs
*
* If more than one application request the same name, D-Bus will try
* to resolve this conflict as good as possible.
* The #NameRequestMode flags allow to control how an application prefers
* to be treated in such a conflict.
*
* @param name the name the connection should be addressable with. See
* section @ref dbusconventions-servicename
* @param modeFlags an OR'ed combination of #NameRequestMode flags
*
* @return @c true if the name request was successfull, @c false if
* the connection is not connected to a bus or the name is already
* taken and cannot be tranferred
*
* @see uniqueName()
*/
bool requestName(const TQString &name, int modeFlags = NoReplace);
/**
* @brief Returns the connection identifier assigned at connect
*
* The unique name is the connection address or identifier the bus assigned
* to this connection when it got established.
*
* @return the connection's unique bus identifier
*
* @see requestName()
*/
TQString uniqueName() const;
/**
* @brief Sends a message over the bus
*
* Sends a message composed through the TQT_DBusMessage API to the bus.
* This is the main method for service objects (see TQT_DBusObjectBase) to
* send replies and errors for method calls they accepted or for sending
* D-Bus signals.
*
* @note for doing method calls it is more convenient to use TQT_DBusProxy,
* see TQT_DBusProxy::send()
*
* @param message the message to send
*
* @return @c true if sending succeeded, @c false if the connection is not
* connected, if the message lacks information about the recepient
* or if sending fails a at a lower level in the communication
* stack
*
* @see lastError()
*/
bool send(const TQT_DBusMessage &message) const;
/**
* @brief Sends a message over the bus and waits for the reply
*
* Sends a message composed through the TQT_DBusMessage API to the bus.
* It then blocks and waits until the associated reply is received.
* Any message received in between is stored and can be processed
* by calling dispatch() or scheduleDispatch()
*
* @note for doing method calls it is more convenient to use TQT_DBusProxy,
* see TQT_DBusProxy::sendWithReply()
*
* @param message the message to send
* @param error an optional parameter to directly get any error that might
* occur during processing of the call
*
* @return a message containing either the call's reply or an invalid
* message in case the call failed
*
* @see lastError()
*/
TQT_DBusMessage sendWithReply(const TQT_DBusMessage &message, TQT_DBusError *error = 0) const;
/**
* @brief Sends a message over the bus, specifying a receiver object for
* replies
*
* Sends a message composed through the TQT_DBusMessage API to the bus and
* returns an identifier number to associate with the reply once it is
* received by the given receiver.
* See TQT_DBusMessage::replySerialNumber()
*
* The required slot signature is
* @code
* void slotname(const TQT_DBusMessage&);
* @endcode
*
* @note for doing method calls it is more convenient to use TQT_DBusProxy,
* see TQT_DBusProxy::sendWithAsyncReply()
*
* @param message the message to send
* @param receiver the TQObject to relay the reply to
* @param slot the slot to invoke for the reply
*
* @return a numeric identifier for association with the reply or @c 0 if
* sending failed
*
* @see lastError()
*/
int sendWithAsyncReply(const TQT_DBusMessage &message, TQObject *receiver,
const char *slot) const;
/**
* @brief Flushes buffered outgoing message
*
* Attempts to send all enqueued outgoing messages before returning.
*/
void flush() const;
/**
* @brief Processes buffered inbound messages
*
* Attempts to process all enqueued inbound messages, e.g. replies to
* method calls or received signals.
*
* @warning dispatching message can result in TQt signals being emitted
* before this method returns. In case you just want to make sure
* no inbound message is forgotten, call scheduleDispatch() which
* will execute the dispatch delayed through the event loop.
*/
void dispatch() const;
/**
* @brief Request a delayed check for inbound buffer processing
*
* Similar to dispatch() but delayed by a single shot timer to ensure
* the method has returned before the processing is started.
*
* If a asynchronous method call is followed by a synchronous call without
* returning to the event loop in between, a call to scheduleDispatch()
* ensures that a pending reply to the asynchronous call is processed
* as soon as possible
*/
void scheduleDispatch() const;
/**
* @brief Connects an object to receive D-Bus signals
*
* This provides a basic access to all D-Bus signals received on this
* connection.
* For every D-Bus signal processed by the connection object a TQt signal
* is emitted and thus delivered to all receiver objects connected
* through this method.
*
* The required slot signature is
* @code
* void slotname(const TQT_DBusMessage&);
* @endcode
*
* so a suitable receiver could look like this
* @code
* class DBusSignalReceiver : public TQObject
* {
* TQ_OBJECT
* public slots:
* void dbusSignal(const TQT_DBusMessage&);
* };
* @endcode
*
* and would be connected like this
* @code
* // assuming the following variables
* TQT_DBusConnection connection;
* DBusSignalReceiver* receiver;
*
* connection.connect(receiver, TQT_SLOT(dbusSignal(const TQT_DBusMessage&)));
* @endcode
*
* See TQT_DBusProxy::dbusSignal() for a more obvious way of connecting slots.
*
* @param object the receiver object
* @param slot the receiver slot (or signal for signal->signal connections)
*
* @return @c true if the connection was successfull, otherwise @c false
*
* @see disconnect()
*/
bool connect(TQObject* object, const char* slot);
/**
* @brief Disconnects a given receiver from the D-Bus signal handling
*
* @param object the receiver object to disconnect from
* @param slot the receiver slot (or signal for signal->signal connections)
*
* @return @c true if the disconnect was successfull, otherwise @c false
*
* @see connect()
*/
bool disconnect(TQObject* object, const char* slot);
/**
* @brief Registers a service object for a given path
*
* In order to receive method calls over the D-Bus connection the service
* objects path within its host application has to be registered with the
* connection. See section @ref dbusconventions-objectpath for details.
*
* Only one objects can be registered for a single object path, i.e.
* the path -> object mapping is unambiguous, similar to mapping of
* filesystem paths to files.
*
* If a service object offers more than one interface it is up to the
* service implementation if all are implemented in the object path to this
* method or if the passed object is just another demultiplexer which
* relays the message to the interface implementor.
*
* @param path the object path to register the object for
* @param object the service implementation object for that path
*
* @return @c true if the given object is now registered for the given path
* or @c false if path is empty, object is null or another object
* is already registered for this path
*
* @see unregisterObject()
*/
bool registerObject(const TQString& path, TQT_DBusObjectBase* object);
/**
* @brief Unregister a service object on a given path
*
* Removes any mapping of object path to service object previously
* registered by registerObject().
* See section @ref dbusconventions-objectpath for details.
*
* @warning always(!) unregister a service object before deleting it
*
* @param path the object path of the object to unregister
*
* @see registerObject()
*/
void unregisterObject(const TQString &path);
/**
* @brief Gets a connection to the session bus
*
* Convenience overload for creating the default shared connection to the
* D-Bus session bus.
*
* Equivalent to calling addConnection(SessionBus);
*
* @return a connection handle. Check isConnected() to tqfind out if the
* connection attempt has been successfull
*
* @see addConnection(BusType,const TQString&);
*/
static TQT_DBusConnection sessionBus();
/**
* @brief Gets a connection to the system bus
*
* Convenience overload for creating the default shared connection to the
* D-Bus system bus.
*
* Equivalent to calling addConnection(SystemBus);
*
* @return a connection handle. Check isConnected() to tqfind out if the
* connection attempt has been successfull
*
* @see addConnection(BusType,const TQString&);
*/
static TQT_DBusConnection systemBus();
/**
* @brief Add a connection to a bus with a specific bus type
*
* This is a factory method as it will create a connection for the given
* name if its not available yet, but return a previously created
* connection for that name if available.
*
* Depending on the #BusType the D-Bus library will connect to the address
* configured for that type, so this is the recommended way to create
* connection to D-Bus.
*
* @code
* // Associate the default connection name with a connection to the user's
* // session bus
* TQT_DBusConnection con = TQT_DBusConnection::addConnection(TQT_DBusConnection::SessionBus);
*
* // check if we are connected and which uniqueName we got
* if (con.isConnected())
* {
* qDebug("Connected to session bus. We got uniqueName %s",
* con.uniqueName().local8Bit().data());
* }
* @endcode
* For the common use cases see also sessionBus() and systemBus()
*
* @param type the #BusType of the bus to connect to
* @param name the name to use for TQT_DBusConnection's connection sharing
*
* @return a connection handle. Check isConnected() to tqfind out if the
* connection attempt has been successfull
*
* @see closeConnection()
*/
static TQT_DBusConnection addConnection(BusType type,
const TQString &name = default_connection_name);
/**
* @brief Add a connection to a bus at a specific address
*
* This is a factory method as it will create a connection for the given
* name if its not available yet, but return a previously created
* connection for that name if available.
*
* @note this requires to know the address of a D-Bus daemon to connect to
*
* @param address the address of the D-Bus daemon. Usually a Unix domain
* socket address
* @param name the name to use for TQT_DBusConnection's connection sharing
*
* @return a connection handle. Check isConnected() to tqfind out if the
* connection attempt has been successfull
*
* @see closeConnection()
*/
static TQT_DBusConnection addConnection(const TQString &address,
const TQString &name = default_connection_name);
// TODO check why this doesn't close the D-Bus connection
/**
* @brief Closes a connection with a given name
*
* Removes the name from the pool of shared connections, i.e. a call to
* addConnection() with the same name afterwards will create a new
* connection.
*
* @param name the connection name as used in addConnection()
*/
static void closeConnection(const TQString &name = default_connection_name);
/**
* String used as the default parameter for connection names
*/
QT_STATIC_CONST char *default_connection_name;
private:
TQT_DBusConnectionPrivate *d;
};
#endif

@ -0,0 +1,149 @@
/* qdbusconnection_p.h TQT_DBusConnection private object
*
* Copyright (C) 2005 Harald Fernengel <harry@kdevelop.org>
* Copyright (C) 2005 Kevin Krammer <kevin.krammer@gmx.at>
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*/
//
// W A R N I N G
// -------------
//
// This file is not part of the public API. This header file may
// change from version to version without notice, or even be
// removed.
//
// We mean it.
//
//
#ifndef TQDBUSCONNECTION_P_H
#define TQDBUSCONNECTION_P_H
#include <tqguardedptr.h>
#include <tqmap.h>
#include <tqobject.h>
#include <tqvaluelist.h>
#include <dbus/dbus.h>
#include "tqdbusatomic.h"
#include "tqdbuserror.h"
#include "tqdbusobject.h"
class TQT_DBusMessage;
class TQSocketNotifier;
class TQTimer;
class TQTimerEvent;
struct DBusConnection;
struct DBusServer;
class TQT_DBusConnectionPrivate: public TQObject
{
Q_OBJECT
TQ_OBJECT
public:
TQT_DBusConnectionPrivate(TQObject *tqparent = 0);
~TQT_DBusConnectionPrivate();
void bindToApplication();
void setConnection(DBusConnection *connection);
void setServer(DBusServer *server);
void closeConnection();
void timerEvent(TQTimerEvent *e);
bool handleSignal(DBusMessage *msg);
bool handleObjectCall(DBusMessage *message);
bool handleError();
void emitPendingCallReply(const TQT_DBusMessage& message);
signals:
void dbusSignal(const TQT_DBusMessage& message);
void dbusPendingCallReply(const TQT_DBusMessage& message);
public slots:
void socketRead(int);
void socketWrite(int);
void objectDestroyed(TQObject* object);
void purgeRemovedWatches();
void scheduleDispatch();
void dispatch();
public:
DBusError error;
TQT_DBusError lastError;
enum ConnectionMode { InvalidMode, ServerMode, ClientMode };
// FIXME TQAtomic ref;
Atomic ref;
ConnectionMode mode;
DBusConnection *connection;
DBusServer *server;
TQTimer* dispatcher;
static int messageMetaType;
static int registerMessageMetaType();
int sendWithReplyAsync(const TQT_DBusMessage &message, TQObject *receiver,
const char *method);
void flush();
struct Watcher
{
Watcher(): watch(0), read(0), write(0) {}
DBusWatch *watch;
TQSocketNotifier *read;
TQSocketNotifier *write;
};
// FIXME typedef TQMultiHash<int, Watcher> WatcherHash;
typedef TQValueList<Watcher> WatcherList;
WatcherList removedWatches;
typedef TQMap<int, WatcherList> WatcherHash;
WatcherHash watchers;
// FIXME typedef TQHash<int, DBusTimeout *> TimeoutHash;
typedef TQMap<int, DBusTimeout*> TimeoutHash;
TimeoutHash timeouts;
typedef TQMap<TQString, TQT_DBusObjectBase*> ObjectMap;
ObjectMap registeredObjects;
TQValueList<DBusTimeout *> pendingTimeouts;
struct TQT_DBusPendingCall
{
TQGuardedPtr<TQObject> receiver;
TQCString method;
DBusPendingCall *pending;
};
typedef TQMap<DBusPendingCall*, TQT_DBusPendingCall*> PendingCallMap;
PendingCallMap pendingCalls;
};
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,143 @@
/* qdbusdataconverter.cpp TQT_DBusDataConverter template
*
* Copyright (C) 2007 Kevin Krammer <kevin.krammer@gmx.at>
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*/
#include "tqdbusdataconverter.h"
#include "tqdbusdata.h"
#include <tqpoint.h>
#include <tqrect.h>
#include <tqsize.h>
#include <tqvaluelist.h>
template <>
TQT_DBusDataConverter::Result TQT_DBusDataConverter::convertFromTQT_DBusData<TQRect>(const TQT_DBusData& dbusData, TQRect& typeData)
{
if (dbusData.type() != TQT_DBusData::Struct) return InvalidSignature;
TQValueList<TQT_DBusData> members = dbusData.toStruct();
if (members.count() != 4) return InvalidSignature;
TQ_INT32 values[4];
TQValueList<TQT_DBusData>::const_iterator it = members.begin();
TQValueList<TQT_DBusData>::const_iterator endIt = members.end();
for (uint i = 0; it != endIt; ++it, ++i)
{
bool ok = false;
values[i] = (*it).toInt32(&ok);
if (!ok) return InvalidSignature;
}
typeData = TQRect(values[0], values[1], values[2], values[3]);
return Success;
}
template <>
TQT_DBusDataConverter::Result TQT_DBusDataConverter::convertToTQT_DBusData<TQRect>(const TQRect& typeData, TQT_DBusData& dbusData)
{
TQValueList<TQT_DBusData> members;
members << TQT_DBusData::fromInt32(typeData.x());
members << TQT_DBusData::fromInt32(typeData.y());
members << TQT_DBusData::fromInt32(typeData.width());
members << TQT_DBusData::fromInt32(typeData.height());
dbusData = TQT_DBusData::fromStruct(members);
return Success;
}
template <>
TQT_DBusDataConverter::Result TQT_DBusDataConverter::convertFromTQT_DBusData<TQPoint>(const TQT_DBusData& dbusData, TQPoint& typeData)
{
if (dbusData.type() != TQT_DBusData::Struct) return InvalidSignature;
TQValueList<TQT_DBusData> members = dbusData.toStruct();
if (members.count() != 2) return InvalidSignature;
TQ_INT32 values[2];
TQValueList<TQT_DBusData>::const_iterator it = members.begin();
TQValueList<TQT_DBusData>::const_iterator endIt = members.end();
for (uint i = 0; it != endIt; ++it, ++i)
{
bool ok = false;
values[i] = (*it).toInt32(&ok);
if (!ok) return InvalidSignature;
}
typeData = TQPoint(values[0], values[1]);
return Success;
}
template <>
TQT_DBusDataConverter::Result TQT_DBusDataConverter::convertToTQT_DBusData<TQPoint>(const TQPoint& typeData, TQT_DBusData& dbusData)
{
TQValueList<TQT_DBusData> members;
members << TQT_DBusData::fromInt32(typeData.x());
members << TQT_DBusData::fromInt32(typeData.y());
dbusData = TQT_DBusData::fromStruct(members);
return Success;
}
template <>
TQT_DBusDataConverter::Result TQT_DBusDataConverter::convertFromTQT_DBusData<TQSize>(const TQT_DBusData& dbusData, TQSize& typeData)
{
if (dbusData.type() != TQT_DBusData::Struct) return InvalidSignature;
TQValueList<TQT_DBusData> members = dbusData.toStruct();
if (members.count() != 2) return InvalidSignature;
TQ_INT32 values[2];
TQValueList<TQT_DBusData>::const_iterator it = members.begin();
TQValueList<TQT_DBusData>::const_iterator endIt = members.end();
for (uint i = 0; it != endIt; ++it, ++i)
{
bool ok = false;
values[i] = (*it).toInt32(&ok);
if (!ok) return InvalidSignature;
}
typeData = TQSize(values[0], values[1]);
return Success;
}
template <>
TQT_DBusDataConverter::Result TQT_DBusDataConverter::convertToTQT_DBusData<TQSize>(const TQSize& typeData, TQT_DBusData& dbusData)
{
TQValueList<TQT_DBusData> members;
members << TQT_DBusData::fromInt32(typeData.width());
members << TQT_DBusData::fromInt32(typeData.height());
dbusData = TQT_DBusData::fromStruct(members);
return Success;
}

@ -0,0 +1,207 @@
/* qdbusdataconverter.h TQT_DBusDataConverter template
*
* Copyright (C) 2007 Kevin Krammer <kevin.krammer@gmx.at>
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*/
#ifndef TQDBUSDATACONVERTER_H
#define TQDBUSDATACONVERTER_H
#include "tqdbusmacros.h"
class TQT_DBusData;
/**
* @brief Template based converter for getting complex data into or from TQT_DBusData objects
*
* Any data to transport over D-Bus, i.e. method/signal paramaters or properties, need
* to be converted into a TQT_DBusData instance.
*
* For complex types, e.g. structures or nested containers, this can be quite some code,
* and will likely be needed for more than one call.
* Therefore it is more convenient to implement the conversions once per complex type.
*
* Example: sending and recieving a TQRect over D-Bus.
* In D-Bus terminology a TQRect is a struct of four 32-bit signed integers. The code to do
* this manually looks like this:
* @code
* TQRect rect(0, 0, 100, 100);
*
* TQValueList<TQT_DBusData> structMembers;
* structMembers << TQT_DBusData::fromInt32(rect.x());
* structMembers << TQT_DBusData::fromInt32(rect.y());
* structMembers << TQT_DBusData::fromInt32(rect.wdth());
* structMembers << TQT_DBusData::fromInt32(rect.height());
*
* TQT_DBusData rectStruct = TQT_DBusData::fromStruct(structMembers);
* @endcode
* and reverse (without the error checking)
* @code
* TQT_DBusData dbusData; // assume we got this from a D-Bus call
*
* TQValueList<TQT_DBusData> structMembers = dbudData.toStruct();
*
* int x = structMembers[0].toInt32();
* int y = structMembers[1].toInt32();
* int w = structMembers[2].toInt32();
* int h = structMembers[3].toInt32();
*
* TQRect rect(x, y, w, h);
* @endcode
*
* Rather than implementing it in the method which performs the D-Bus call, basically the same
* code can be used as a spezialisation of the TQT_DBusDataConverter methods and then used like this:
* @code
* TQRect rect(0, 0, 100, 100);
* TQT_DBusData rectStruct;
*
* TQT_DBusDataConverter::convertToTQT_DBusData<TQRect>(rect, rectStruct);
* @endcode
* and
* @code
* TQRect rect;
* TQT_DBusData dbusData; // assume we got this from a D-Bus call
*
* TQT_DBusDataConverter::convertFromTQT_DBusData<TQRect>(dbusData, rect);
* @endcode
*
* @note The bindings library tqcontains the spezialisations for TQRect, TQPoint and TQSize.
*/
class TQDBUS_EXPORT TQT_DBusDataConverter
{
public:
/**
* @brief Conversion result values
*/
enum Result
{
/**
* Conversion successfull
*/
Success,
/**
* Conversion failed because the passed TQT_DBusData instance does not contain data
* of the needed signature, e.g. too few to too many members for a struct or wrong types.
*
* @see TQT_DBusError::stdInvalidSignature()
*/
InvalidSignature,
/**
* Conversion failed because the passed TQT_DBusData contained values which are not allowed,
* e.g. out of range for a numerical type used a an enum or flags.
*
* @see TQT_DBusError::stdInvalidArgs()
*/
InvalidArgument
};
/**
* @brief Conversion from a filled TQT_DBusData instance to a native type
*
* For example the implementation for TQPoint looks like this:
* @code
* template <>
* TQT_DBusDataConverter::Result
* TQT_DBusDataConverter::convertFromTQT_DBusData<TQPoint>(const TQT_DBusData& dbusData, TQPoint& typeData)
* {
* if (dbusData.type() != TQT_DBusData::Struct) return InvalidSignature;
*
* TQValueList<TQT_DBusData> members = dbusData.toStruct();
* if (members.count() != 2) return InvalidSignature;
*
* bool ok = false;
* int x = members[0].toInt32(&ok);
* if (!ok) return InvalidSignature;
*
* int y = members[1].toInt32(&ok);
* if (!ok) return InvalidSignature;
*
* typeData = TQPoint(x, y);
*
* return Success;
* }
* @endcode
*
* And then can be used like this:
* @code
* TQT_DBusMessage reply; // assume we got this as a D-Bus call reply
* TQPoint point;
*
* if (TQT_DBusDataConverter::convertFromTQT_DBusData(reply[0], point) != TQT_DBusDataConverter::Success)
* {
* // error handling
* }
* @endcode
*
* @param dbusData the binding's data instance to get the content from
* @param typeData the native type instance to put the content into
*
* @return the conversion result value
*/
template <class T>
static Result convertFromTQT_DBusData(const TQT_DBusData& dbusData, T& typeData);
/**
* @brief Conversion from a native type to a TQT_DBusData instance
*
* For example the implementation for TQPoint looks like this:
* @code
* template <>
* TQT_DBusDataConversion::Result
* TQT_DBusDataConversion::convertToTQT_DBusData<TQPoint>(const TQPoint& typeData, TQT_DBusData& dbusData)
* {
* TQValueList<TQT_DBusData> members;
* members << TQT_DBusData::fromInt32(typeData.x());
* members << TQT_DBusData::fromInt32(typeData.y());
*
* dbusData = TQT_DBusData::fromStruct(members);
*
* return Success;
* }
* @endcode
*
* And then can be used like this:
* @code
* TQPoint point(-10, 100);
* TQT_DBusMessage methodCall; // assume created by TQBusMessage::methodCall()
*
* TQT_DBusData dbusData;
* if (TQT_DBusDataConverter::convertToTQT_DBusData<TQPoint>(point, dbusData) != TQT_DBusDataConverter::Success)
* {
* // error handling
* }
* else
* {
* methodCall << dbusData;
* }
* @endcode
*
* @param typeData the native type instance to get the content from
* @param dbusData the binding's data instance to put the content into
*
* @return the conversion result value
*/
template <class T>
static Result convertToTQT_DBusData(const T& typeData, TQT_DBusData& dbusData);
};
#endif

@ -0,0 +1,748 @@
/* qdbusdatalist.cpp list of DBUS data transport type
*
* Copyright (C) 2007 Kevin Krammer <kevin.krammer@gmx.at>
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*/
#include "tqdbusdatalist.h"
#include "tqdbusobjectpath.h"
#include "tqdbusvariant.h"
#include <tqstringlist.h>
class TQT_DBusDataList::Private
{
public:
Private() : type(TQT_DBusData::Invalid) {}
public:
TQT_DBusData::Type type;
TQT_DBusData containerItem;
TQValueList<TQT_DBusData> list;
};
TQT_DBusDataList::TQT_DBusDataList() : d(new Private())
{
}
TQT_DBusDataList::TQT_DBusDataList(TQT_DBusData::Type simpleItemType) : d(new Private())
{
d->type = simpleItemType;
}
TQT_DBusDataList::TQT_DBusDataList(const TQT_DBusData& containerItemType) : d(new Private())
{
d->type = containerItemType.type();
switch(d->type)
{
case TQT_DBusData::List: // fall through
case TQT_DBusData::Struct: // fall through
case TQT_DBusData::Map:
d->containerItem = containerItemType;
break;
default: // not a container
break;
}
}
TQT_DBusDataList::TQT_DBusDataList(const TQT_DBusDataList& other) : d(new Private())
{
d->type = other.d->type;
d->list = other.d->list;
d->containerItem = other.d->containerItem;
}
TQT_DBusDataList::TQT_DBusDataList(const TQValueList<TQT_DBusData>& other) : d(new Private())
{
if (other.isEmpty()) return;
TQValueList<TQT_DBusData>::const_iterator it = other.begin();
TQValueList<TQT_DBusData>::const_iterator endIt = other.end();
d->type = (*it).type();
TQCString elementSignature;
if (hasContainerItemType())
{
d->containerItem = other[0]; // would be nice to get an empty one
elementSignature = d->containerItem.buildDBusSignature();
}
for (++it; it != endIt; ++it)
{
if (d->type != (*it).type())
{
d->type = TQT_DBusData::Invalid;
d->containerItem = TQT_DBusData();
return;
}
else if (hasContainerItemType())
{
if ((*it).buildDBusSignature() != elementSignature)
{
d->type = TQT_DBusData::Invalid;
d->containerItem = TQT_DBusData();
return;
}
}
}
d->list = other;
}
TQT_DBusDataList::TQT_DBusDataList(const TQValueList<bool>& other) : d(new Private())
{
d->type = TQT_DBusData::Bool;
if (other.isEmpty()) return;
TQValueList<bool>::const_iterator it = other.begin();
TQValueList<bool>::const_iterator endIt = other.end();
for (; it != endIt; ++it)
{
d->list << TQT_DBusData::fromBool(*it);
}
}
TQT_DBusDataList::TQT_DBusDataList(const TQValueList<TQ_UINT8>& other) : d(new Private())
{
d->type = TQT_DBusData::Byte;
if (other.isEmpty()) return;
TQValueList<TQ_UINT8>::const_iterator it = other.begin();
TQValueList<TQ_UINT8>::const_iterator endIt = other.end();
for (; it != endIt; ++it)
{
d->list << TQT_DBusData::fromByte(*it);
}
}
TQT_DBusDataList::TQT_DBusDataList(const TQValueList<TQ_INT16>& other) : d(new Private())
{
d->type = TQT_DBusData::Int16;
if (other.isEmpty()) return;
TQValueList<TQ_INT16>::const_iterator it = other.begin();
TQValueList<TQ_INT16>::const_iterator endIt = other.end();
for (; it != endIt; ++it)
{
d->list << TQT_DBusData::fromInt16(*it);
}
}
TQT_DBusDataList::TQT_DBusDataList(const TQValueList<TQ_UINT16>& other) : d(new Private())
{
d->type = TQT_DBusData::UInt16;
if (other.isEmpty()) return;
TQValueList<TQ_UINT16>::const_iterator it = other.begin();
TQValueList<TQ_UINT16>::const_iterator endIt = other.end();
for (; it != endIt; ++it)
{
d->list << TQT_DBusData::fromUInt16(*it);
}
}
TQT_DBusDataList::TQT_DBusDataList(const TQValueList<TQ_INT32>& other) : d(new Private())
{
d->type = TQT_DBusData::Int32;
if (other.isEmpty()) return;
TQValueList<TQ_INT32>::const_iterator it = other.begin();
TQValueList<TQ_INT32>::const_iterator endIt = other.end();
for (; it != endIt; ++it)
{
d->list << TQT_DBusData::fromInt32(*it);
}
}
TQT_DBusDataList::TQT_DBusDataList(const TQValueList<TQ_UINT32>& other) : d(new Private())
{
d->type = TQT_DBusData::UInt32;
if (other.isEmpty()) return;
TQValueList<TQ_UINT32>::const_iterator it = other.begin();
TQValueList<TQ_UINT32>::const_iterator endIt = other.end();
for (; it != endIt; ++it)
{
d->list << TQT_DBusData::fromUInt32(*it);
}
}
TQT_DBusDataList::TQT_DBusDataList(const TQValueList<TQ_INT64>& other) : d(new Private())
{
d->type = TQT_DBusData::Int64;
if (other.isEmpty()) return;
TQValueList<TQ_INT64>::const_iterator it = other.begin();
TQValueList<TQ_INT64>::const_iterator endIt = other.end();
for (; it != endIt; ++it)
{
d->list << TQT_DBusData::fromInt64(*it);
}
}
TQT_DBusDataList::TQT_DBusDataList(const TQValueList<TQ_UINT64>& other) : d(new Private())
{
d->type = TQT_DBusData::UInt64;
if (other.isEmpty()) return;
TQValueList<TQ_UINT64>::const_iterator it = other.begin();
TQValueList<TQ_UINT64>::const_iterator endIt = other.end();
for (; it != endIt; ++it)
{
d->list << TQT_DBusData::fromUInt64(*it);
}
}
TQT_DBusDataList::TQT_DBusDataList(const TQValueList<double>& other) : d(new Private())
{
d->type = TQT_DBusData::Double;
if (other.isEmpty()) return;
TQValueList<double>::const_iterator it = other.begin();
TQValueList<double>::const_iterator endIt = other.end();
for (; it != endIt; ++it)
{
d->list << TQT_DBusData::fromDouble(*it);
}
}
TQT_DBusDataList::TQT_DBusDataList(const TQValueList<TQT_DBusVariant>& other)
: d(new Private())
{
d->type = TQT_DBusData::Variant;
if (other.isEmpty()) return;
TQValueList<TQT_DBusVariant>::const_iterator it = other.begin();
TQValueList<TQT_DBusVariant>::const_iterator endIt = other.end();
for (; it != endIt; ++it)
{
d->list << TQT_DBusData::fromVariant(*it);
}
}
TQT_DBusDataList::TQT_DBusDataList(const TQStringList& other) : d(new Private())
{
d->type = TQT_DBusData::String;
if (other.isEmpty()) return;
TQStringList::const_iterator it = other.begin();
TQStringList::const_iterator endIt = other.end();
for (; it != endIt; ++it)
{
d->list << TQT_DBusData::fromString(*it);
}
}
TQT_DBusDataList::TQT_DBusDataList(const TQValueList<TQT_DBusObjectPath>& other)
: d(new Private())
{
d->type = TQT_DBusData::ObjectPath;
if (other.isEmpty()) return;
TQValueList<TQT_DBusObjectPath>::const_iterator it = other.begin();
TQValueList<TQT_DBusObjectPath>::const_iterator endIt = other.end();
for (; it != endIt; ++it)
{
d->list << TQT_DBusData::fromObjectPath(*it);
}
}
TQT_DBusDataList::~TQT_DBusDataList()
{
delete d;
}
TQT_DBusDataList& TQT_DBusDataList::operator=(const TQT_DBusDataList& other)
{
if (&other == this) return *this;
d->type = other.d->type;
d->list = other.d->list;
d->containerItem = other.d->containerItem;
return *this;
}
TQT_DBusDataList& TQT_DBusDataList::operator=(const TQValueList<TQT_DBusData>& other)
{
d->list.clear();
d->type = TQT_DBusData::Invalid;
d->containerItem = TQT_DBusData();
if (other.isEmpty()) return *this;
TQValueList<TQT_DBusData>::const_iterator it = other.begin();
TQValueList<TQT_DBusData>::const_iterator endIt = other.end();
d->type = (*it).type();
TQCString elementSignature;
if (hasContainerItemType())
{
d->containerItem = other[0]; // would be nice to get an empty one
elementSignature = d->containerItem.buildDBusSignature();
}
for (++it; it != endIt; ++it)
{
if (d->type != (*it).type())
{
d->type = TQT_DBusData::Invalid;
d->containerItem = TQT_DBusData();
return *this;
}
else if (hasContainerItemType())
{
if ((*it).buildDBusSignature() != elementSignature)
{
d->type = TQT_DBusData::Invalid;
d->containerItem = TQT_DBusData();
return *this;
}
}
}
d->list = other;
return *this;
}
TQT_DBusDataList& TQT_DBusDataList::operator=(const TQStringList& other)
{
d->list.clear();
d->type = TQT_DBusData::String;
d->containerItem = TQT_DBusData();
TQStringList::const_iterator it = other.begin();
TQStringList::const_iterator endIt = other.end();
for (; it != endIt; ++it)
{
d->list << TQT_DBusData::fromString(*it);
}
return *this;
}
TQT_DBusData::Type TQT_DBusDataList::type() const
{
return d->type;
}
bool TQT_DBusDataList::hasContainerItemType() const
{
return d->type == TQT_DBusData::List || d->type == TQT_DBusData::Map
|| d->type == TQT_DBusData::Struct;
}
TQT_DBusData TQT_DBusDataList::containerItemType() const
{
return d->containerItem;
}
bool TQT_DBusDataList::isEmpty() const
{
return d->list.isEmpty();
}
uint TQT_DBusDataList::count() const
{
return d->list.count();
}
bool TQT_DBusDataList::operator==(const TQT_DBusDataList& other) const
{
if (&other == this) return true;
if (d == other.d) return true;
bool containerEqual = true;
if (hasContainerItemType())
{
if (other.hasContainerItemType())
{
containerEqual = d->containerItem.buildDBusSignature() ==
other.d->containerItem.buildDBusSignature();
}
else
containerEqual = false;
}
else if (other.hasContainerItemType())
containerEqual = false;
return d->type == other.d->type && containerEqual && d->list == other.d->list;
}
bool TQT_DBusDataList::operator!=(const TQT_DBusDataList& other) const
{
if (&other == this) return false;
if (d == other.d) return false;
bool containerEqual = true;
if (hasContainerItemType())
{
if (other.hasContainerItemType())
{
containerEqual = d->containerItem.buildDBusSignature() ==
other.d->containerItem.buildDBusSignature();
}
else
containerEqual = false;
}
else if (other.hasContainerItemType())
containerEqual = false;
return d->type != other.d->type || !containerEqual || d->list != other.d->list;
}
void TQT_DBusDataList::clear()
{
d->list.clear();
}
TQT_DBusDataList& TQT_DBusDataList::operator<<(const TQT_DBusData& data)
{
if (data.type() == TQT_DBusData::Invalid) return *this;
if (d->type == TQT_DBusData::Invalid)
{
d->type = data.type();
// check if we are now have container items
if (hasContainerItemType()) d->containerItem = data;
d->list << data;
}
else if (d->type != data.type())
{
qWarning("TQT_DBusDataList: trying to add data of type %s to list of type %s",
data.typeName(), TQT_DBusData::typeName(d->type));
}
else if (hasContainerItemType())
{
TQCString ourSignature = d->containerItem.buildDBusSignature();
TQCString dataSignature = data.buildDBusSignature();
if (ourSignature != dataSignature)
{
qWarning("TQT_DBusDataList: trying to add data with signature %s "
"to list with item signature %s",
dataSignature.data(), ourSignature.data());
}
else
d->list << data;
}
else
d->list << data;
return *this;
}
TQValueList<TQT_DBusData> TQT_DBusDataList::toTQValueList() const
{
return d->list;
}
TQStringList TQT_DBusDataList::toTQStringList(bool* ok) const
{
if (d->type != TQT_DBusData::String)
{
if (ok != 0) *ok = false;
return TQStringList();
}
TQStringList result;
TQValueList<TQT_DBusData>::const_iterator it = d->list.begin();
TQValueList<TQT_DBusData>::const_iterator endIt = d->list.end();
for (; it != endIt; ++it)
{
result << (*it).toString();
}
if (ok != 0) *ok = true;
return result;
}
TQValueList<bool> TQT_DBusDataList::toBoolList(bool* ok) const
{
if (d->type != TQT_DBusData::Bool)
{
if (ok != 0) *ok = false;
return TQValueList<bool>();
}
TQValueList<bool> result;
TQValueList<TQT_DBusData>::const_iterator it = d->list.begin();
TQValueList<TQT_DBusData>::const_iterator endIt = d->list.end();
for (; it != endIt; ++it)
{
result << (*it).toBool();
}
if (ok != 0) *ok = true;
return result;
}
TQValueList<TQ_UINT8> TQT_DBusDataList::toByteList(bool* ok) const
{
if (d->type != TQT_DBusData::Byte)
{
if (ok != 0) *ok = false;
return TQValueList<TQ_UINT8>();
}
TQValueList<TQ_UINT8> result;
TQValueList<TQT_DBusData>::const_iterator it = d->list.begin();
TQValueList<TQT_DBusData>::const_iterator endIt = d->list.end();
for (; it != endIt; ++it)
{
result << (*it).toByte();
}
if (ok != 0) *ok = true;
return result;
}
TQValueList<TQ_INT16> TQT_DBusDataList::toInt16List(bool* ok) const
{
if (d->type != TQT_DBusData::Int16)
{
if (ok != 0) *ok = false;
return TQValueList<TQ_INT16>();
}
TQValueList<TQ_INT16> result;
TQValueList<TQT_DBusData>::const_iterator it = d->list.begin();
TQValueList<TQT_DBusData>::const_iterator endIt = d->list.end();
for (; it != endIt; ++it)
{
result << (*it).toInt16();
}
if (ok != 0) *ok = true;
return result;
}
TQValueList<TQ_UINT16> TQT_DBusDataList::toUInt16List(bool* ok) const
{
if (d->type != TQT_DBusData::UInt16)
{
if (ok != 0) *ok = false;
return TQValueList<TQ_UINT16>();
}
TQValueList<TQ_UINT16> result;
TQValueList<TQT_DBusData>::const_iterator it = d->list.begin();
TQValueList<TQT_DBusData>::const_iterator endIt = d->list.end();
for (; it != endIt; ++it)
{
result << (*it).toUInt16();
}
if (ok != 0) *ok = true;
return result;
}
TQValueList<TQ_INT32> TQT_DBusDataList::toInt32List(bool* ok) const
{
if (d->type != TQT_DBusData::Int32)
{
if (ok != 0) *ok = false;
return TQValueList<TQ_INT32>();
}
TQValueList<TQ_INT32> result;
TQValueList<TQT_DBusData>::const_iterator it = d->list.begin();
TQValueList<TQT_DBusData>::const_iterator endIt = d->list.end();
for (; it != endIt; ++it)
{
result << (*it).toInt32();
}
if (ok != 0) *ok = true;
return result;
}
TQValueList<TQ_UINT32> TQT_DBusDataList::toUInt32List(bool* ok) const
{
if (d->type != TQT_DBusData::UInt32)
{
if (ok != 0) *ok = false;
return TQValueList<TQ_UINT32>();
}
TQValueList<TQ_UINT32> result;
TQValueList<TQT_DBusData>::const_iterator it = d->list.begin();
TQValueList<TQT_DBusData>::const_iterator endIt = d->list.end();
for (; it != endIt; ++it)
{
result << (*it).toUInt32();
}
if (ok != 0) *ok = true;
return result;
}
TQValueList<TQ_INT64> TQT_DBusDataList::toInt64List(bool* ok) const
{
if (d->type != TQT_DBusData::Int64)
{
if (ok != 0) *ok = false;
return TQValueList<TQ_INT64>();
}
TQValueList<TQ_INT64> result;
TQValueList<TQT_DBusData>::const_iterator it = d->list.begin();
TQValueList<TQT_DBusData>::const_iterator endIt = d->list.end();
for (; it != endIt; ++it)
{
result << (*it).toInt64();
}
if (ok != 0) *ok = true;
return result;
}
TQValueList<TQ_UINT64> TQT_DBusDataList::toUInt64List(bool* ok) const
{
if (d->type != TQT_DBusData::UInt64)
{
if (ok != 0) *ok = false;
return TQValueList<TQ_UINT64>();
}
TQValueList<TQ_UINT64> result;
TQValueList<TQT_DBusData>::const_iterator it = d->list.begin();
TQValueList<TQT_DBusData>::const_iterator endIt = d->list.end();
for (; it != endIt; ++it)
{
result << (*it).toUInt64();
}
if (ok != 0) *ok = true;
return result;
}
TQValueList<double> TQT_DBusDataList::toDoubleList(bool* ok) const
{
if (d->type != TQT_DBusData::Double)
{
if (ok != 0) *ok = false;
return TQValueList<double>();
}
TQValueList<double> result;
TQValueList<TQT_DBusData>::const_iterator it = d->list.begin();
TQValueList<TQT_DBusData>::const_iterator endIt = d->list.end();
for (; it != endIt; ++it)
{
result << (*it).toDouble();
}
if (ok != 0) *ok = true;
return result;
}
TQValueList<TQString> TQT_DBusDataList::toStringList(bool* ok) const
{
return toTQStringList(ok);
}
TQValueList<TQT_DBusObjectPath> TQT_DBusDataList::toObjectPathList(bool* ok) const
{
if (d->type != TQT_DBusData::ObjectPath)
{
if (ok != 0) *ok = false;
return TQValueList<TQT_DBusObjectPath>();
}
TQValueList<TQT_DBusObjectPath> result;
TQValueList<TQT_DBusData>::const_iterator it = d->list.begin();
TQValueList<TQT_DBusData>::const_iterator endIt = d->list.end();
for (; it != endIt; ++it)
{
result << (*it).toObjectPath();
}
if (ok != 0) *ok = true;
return result;
}
TQValueList<TQT_DBusVariant> TQT_DBusDataList::toVariantList(bool* ok) const
{
if (d->type != TQT_DBusData::Variant)
{
if (ok != 0) *ok = false;
return TQValueList<TQT_DBusVariant>();
}
TQValueList<TQT_DBusVariant> result;
TQValueList<TQT_DBusData>::const_iterator it = d->list.begin();
TQValueList<TQT_DBusData>::const_iterator endIt = d->list.end();
for (; it != endIt; ++it)
{
result << (*it).toVariant();
}
if (ok != 0) *ok = true;
return result;
}

@ -0,0 +1,725 @@
/* qdbusdatalist.h list of DBUS data transport type
*
* Copyright (C) 2007 Kevin Krammer <kevin.krammer@gmx.at>
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*/
#ifndef TQDBUSDATALIST_H
#define TQDBUSDATALIST_H
#include "tqdbusdata.h"
template <typename T> class TQValueList;
class TQT_DBusObjectPath;
class TQT_DBusVariant;
class TQString;
class TQStringList;
/**
* @brief Class to transport lists of D-Bus data types
*
* \note while the D-Bus data type is actually called @c array this bindings
* use the term @c list since the behavior and characteristics of the
* implementation is more list like.
*
* There are basically two ways to create TQT_DBusDataList objects:
* - non-empty from content
* - empty by specifying the desired element type
*
* Example for creating a filled list from content
* @code
* TQValueList<TQ_INT16> intList;
* list << 2 << 3 << 5 << 7;
*
* TQT_DBusDataList dbusList(intList);
* TQT_DBusData data = TQT_DBusData::fromList(dbusList);
*
* // or even shorter, using implicit conversion
* TQT_DBusData other = TQT_DBusData::fromList(intList);
* @endcode
*
* Example for creating an empty list
* @code
* // empty list for a simple type
* TQT_DBusDataList list(TQT_DBusData::Double);
*
* // empty list for a list of string lists
* TQT_DBusData elementType = TQT_DBusData::fromList(TQT_DBusDataList(TQT_DBusData::String));
* TQT_DBusDataList outerList(elementType);
* @endcode
*
* @see TQT_DBusDataMap
*/
class TQDBUS_EXPORT TQT_DBusDataList
{
public:
/**
* @brief Creates an empty and invalid list
*
* @see TQT_DBusData::Invalid
*/
TQT_DBusDataList();
/**
* @brief Creates an empty list with the given simple type for elements
*
* The given type has be one of the non-container types, i.e. any other than
* TQT_DBusData::Map, TQT_DBusData::List or TQT_DBusData::Struct
*
* For creating a list with elements which are containers themselves, use
* TQT_DBusDataList(const TQT_DBusData&);
*
* @param simpleItemType the type of the elements in the new list
*/
explicit TQT_DBusDataList(TQT_DBusData::Type simpleItemType);
/**
* @brief Creates an empty list with the given container type for elements
*
* For creating a list with simple elements you can also use
* TQT_DBusDataList(TQT_DBusData::Type);
*
* @param containerItemType the type of the elements in the new list
*
* @see hasContainerItemType()
*/
explicit TQT_DBusDataList(const TQT_DBusData& containerItemType);
/**
* @brief Creates a list from the given @p other list
*
* This behaves basically like copying a TQValueList through its copy
* constructor, i.e. no value are actually copied at this time.
*
* @param other the other list object to copy from
*/
TQT_DBusDataList(const TQT_DBusDataList& other);
/**
* @brief Creates a list from the given TQValueList of TQT_DBusData objects
*
* If the @p other list is empty, this will behave like TQT_DBusDataList(),
* i.e. create an empty and invalid list object.
*
* Type information for the list object, i.e. element type and, if applicable,
* container item type, will be derived from the @p other list's elements.
*
* \warning if the elements of the @p other list do not all have the same
* type, the list object will also be empty and invalid
*
* @param other the TQValueList of TQT_DBusData objects to copy from
*
* @see toTQValueList()
*/
TQT_DBusDataList(const TQValueList<TQT_DBusData>& other);
/**
* @brief Creates a list from the given TQValueList of boolean values
*
* Type information for the list object will be set to TQT_DBusData::Bool
* also when the @p other list is empty, i.e. this allows to create an
* empty but valid list object, comparable to using
* TQT_DBusDataList(TQT_DBusData::Type) with TQT_DBusData::Bool
*
* @param other the TQValueList of boolean values to copy from
*
* @see toBoolList()
*/
TQT_DBusDataList(const TQValueList<bool>& other);
/**
* @brief Creates a list from the given TQValueList of byte (unsigned char) values
*
* Type information for the list object will be set to TQT_DBusData::Byte
* also when the @p other list is empty, i.e. this allows to create an
* empty but valid list object, comparable to using
* TQT_DBusDataList(TQT_DBusData::Type) with TQT_DBusData::Byte
*
* @param other the TQValueList of byte (unsigned char) values to copy from
*
* @see toByteList()
*/
TQT_DBusDataList(const TQValueList<TQ_UINT8>& other);
/**
* @brief Creates a list from the given TQValueList of signed 16-bit integer values
*
* Type information for the list object will be set to TQT_DBusData::Int16
* also when the @p other list is empty, i.e. this allows to create an
* empty but valid list object, comparable to using
* TQT_DBusDataList(TQT_DBusData::Type) with TQT_DBusData::Int16
*
* @param other the TQValueList of signed 16-bit integer values to copy from
*
* @see toInt16List()
*/
TQT_DBusDataList(const TQValueList<TQ_INT16>& other);
/**
* @brief Creates a list from the given TQValueList of unsigned 16-bit integer values
*
* Type information for the list object will be set to TQT_DBusData::UInt16
* also when the @p other list is empty, i.e. this allows to create an
* empty but valid list object, comparable to using
* TQT_DBusDataList(TQT_DBusData::Type) with TQT_DBusData::UInt16
*
* @param other the TQValueList of unsigned 16-bit integer values to copy from
*
* @see toUInt16List()
*/
TQT_DBusDataList(const TQValueList<TQ_UINT16>& other);
/**
* @brief Creates a list from the given TQValueList of signed 32-bit integer values
*
* Type information for the list object will be set to TQT_DBusData::Int32
* also when the @p other list is empty, i.e. this allows to create an
* empty but valid list object, comparable to using
* TQT_DBusDataList(TQT_DBusData::Type) with TQT_DBusData::Int32
*
* @param other the TQValueList of signed 32-bit integer values to copy from
*
* @see toInt32List()
*/
TQT_DBusDataList(const TQValueList<TQ_INT32>& other);
/**
* @brief Creates a list from the given TQValueList of unsigned 32-bit integer values
*
* Type information for the list object will be set to TQT_DBusData::UInt16
* also when the @p other list is empty, i.e. this allows to create an
* empty but valid list object, comparable to using
* TQT_DBusDataList(TQT_DBusData::Type) with TQT_DBusData::UInt32
*
* @param other the TQValueList of unsigned 32-bit integer values to copy from
*
* @see toUInt32List()
*/
TQT_DBusDataList(const TQValueList<TQ_UINT32>& other);
/**
* @brief Creates a list from the given TQValueList of signed 64-bit integer values
*
* Type information for the list object will be set to TQT_DBusData::Int64
* also when the @p other list is empty, i.e. this allows to create an
* empty but valid list object, comparable to using
* TQT_DBusDataList(TQT_DBusData::Type) with TQT_DBusData::Int64
*
* @param other the TQValueList of signed 64-bit integer values to copy from
*
* @see toInt64List()
*/
TQT_DBusDataList(const TQValueList<TQ_INT64>& other);
/**
* @brief Creates a list from the given TQValueList of unsigned 64-bit integer values
*
* Type information for the list object will be set to TQT_DBusData::UInt64
* also when the @p other list is empty, i.e. this allows to create an
* empty but valid list object, comparable to using
* TQT_DBusDataList(TQT_DBusData::Type) with TQT_DBusData::UInt64
*
* @param other the TQValueList of unsigned 64-bit integer values to copy from
*
* @see toUInt64List()
*/
TQT_DBusDataList(const TQValueList<TQ_UINT64>& other);
/**
* @brief Creates a list from the given TQValueList of double values
*
* Type information for the list object will be set to TQT_DBusData::Double
* also when the @p other list is empty, i.e. this allows to create an
* empty but valid list object, comparable to using
* TQT_DBusDataList(TQT_DBusData::Type) with TQT_DBusData::Double
*
* @param other the TQValueList of double values to copy from
*
* @see toDoubleList()
*/
TQT_DBusDataList(const TQValueList<double>& other);
/**
* @brief Creates a list from the given TQValueList of TQT_DBusVariant values
*
* Type information for the list object will be set to TQT_DBusData::Variant
* also when the @p other list is empty, i.e. this allows to create an
* empty but valid list object, comparable to using
* TQT_DBusDataList(TQT_DBusData::Type) with TQT_DBusData::Variant
*
* @param other the TQValueList of variant values to copy from
*
* @see toVariantList()
*/
TQT_DBusDataList(const TQValueList<TQT_DBusVariant>& other);
/**
* @brief Creates a list from the given TQStringList's values
*
* Type information for the list object will be set to TQT_DBusData::String
* also when the @p other list is empty, i.e. this allows to create an
* empty but valid list object, comparable to using
* TQT_DBusDataList(TQT_DBusData::Type) with TQT_DBusData::String
*
* @param other the TQStringList to copy from
*
* @see toTQStringList()
*/
TQT_DBusDataList(const TQStringList& other);
/**
* @brief Creates a list from the given TQValueList of object path values
*
* Type information for the list object will be set to TQT_DBusData::ObjectPath
* also when the @p other list is empty, i.e. this allows to create an
* empty but valid list object, comparable to using
* TQT_DBusDataList(TQT_DBusData::Type) with TQT_DBusData::ObjectPath
*
* @param other the TQValueList of object path values to copy from
*
* @see toObjectPathList()
*/
TQT_DBusDataList(const TQValueList<TQT_DBusObjectPath>& other);
/**
* @brief Destroys the list object
*/
~TQT_DBusDataList();
/**
* @brief Copies from the given @p other list
*
* This behaves basically like copying a TQValueList through its assignment
* operator, i.e. no value are actually copied at this time.
*
* @param other the other list object to copy from
*
* @return a reference to this list object
*/
TQT_DBusDataList& operator=(const TQT_DBusDataList& other);
/**
* @brief Copies from the given @p other list
*
* This behaves basically like copying a TQValueList through its assignment
* operator, i.e. no value are actually copied at this time.
*
* \warning the elements of the given @p other list have to be of the same
* type. If they aren't this list's content will cleared and the
* type will be set to TQT_DBusData::Invalid
*
* @param other the other list object to copy from
*
* @return a reference to this list object
*/
TQT_DBusDataList& operator=(const TQValueList<TQT_DBusData>& other);
/**
* @brief Copies from the given @p other list
*
* Convenience overload as TQStringList is a very common data type in
* TQt and D-Bus methods also use "arrays of strings" quite often.
*
* The list object's type will be set to TQT_DBusData::String. If the object
* previously had a container as its element type, this will be reset, i.e.
* hasContainerItemType() will return @c false
*
* @param other the stringlist to copy from
*
* @return a reference to this list object
*/
TQT_DBusDataList& operator=(const TQStringList& other);
/**
* @brief Returns the element type of the list object
*
* @return one of the values of the TQT_DBusData#Type enum
*
* @see hasContainerItemType()
* @see containerItemType()
*/
TQT_DBusData::Type type() const;
/**
* @brief Checks whether the element type is a data container itself
*
* If the elements of the list are containers as well, this will return
* @c true
* In this case containerItemType() will return a prototype for such a
* container.
*
* @return @c true if the element type is either TQT_DBusData::Map,
* TQT_DBusData::List or TQT_DBusData::Struct, otherwise @c false
*
* @see TQT_DBusDataList(const TQT_DBusData&)
*/
bool hasContainerItemType() const;
/**
* @brief Returns a container prototype for the list's element type
*
* Lists which have containers as their elements, i.e. hasContainerItemType()
* returns @c true this will actually specify the details for the use
* container, i.e. the returned data object can be queried for type and
* possible further subtypes.
*
* @return a data object detailing the element type or an invalid data object
* if the list does not have a container as its element type
*
* @see TQT_DBusDataList(const TQT_DBusData&);
* @see type()
* @see TQT_DBusData::Invalid
*/
TQT_DBusData containerItemType() const;
/**
* @brief Checks whether this list object has a valid element type
*
* This is equal to checking type() for not being TQT_DBusData::Invalid
*
* @return @c true if the list object is valid, otherwise @c false
*/
inline bool isValid() const { return type() != TQT_DBusData::Invalid; }
/**
* @brief Checks whether this list object has any elements
*
* @return @c true if there are no elements in this list, otherwise @c false
*
* @see count()
*/
bool isEmpty() const;
/**
* @brief Returns the number of elements of this list object
*
* @return the number of elements
*
* @see isEmpty()
*/
uint count() const;
/**
* @brief Checks whether the given @p other list is equal to this one
*
* Two lists are considered equal when they have the same type (and same
* container item type if the have one) and the element lists are equal
* as well.
*
* @param other the other list object to compare with
*
* @return @c true if the lists are equal, otherwise @c false
*
* @see TQT_DBusData::operator==()
*/
bool operator==(const TQT_DBusDataList& other) const;
/**
* @brief Checks whether the given @p other list is different from this one
*
* Two lists are considered different when they have the different type (or
* different container item type if the have one) or the element lists are
* equal are different.
*
* @param other the other list object to compare with
*
* @return @c true if the lists are different, otherwise @c false
*
* @see TQT_DBusData::operator!=()
*/
bool operator!=(const TQT_DBusDataList& other) const;
/**
* @brief Clears the list
*
* Type and, if applicable, container element type will stay untouched.
*/
void clear();
/**
* @brief Appends a given value to the list
*
* Basically works like the respective TQValueList operator, but checks if
* type of the new value matches the type of the list.
* Lists that are invalid will accept any new type and will then be
* typed accordingly.
*
* If @p data is invalid itself, it will not be appended at any time.
*
* \note the more common use case is to work with a TQValueList and then
* use the respective constructor to create the TQT_DBusDataList object
*
* @param data the data item to append to the list
*
* @return a reference to this list object
*/
TQT_DBusDataList& operator<<(const TQT_DBusData& data);
/**
* @brief Converts the list object into a TQValueList with TQT_DBusData elements
*
* @return the values of the list object as a TQValueList
*/
TQValueList<TQT_DBusData> toTQValueList() const;
/**
* @brief Tries to get the list object's elements as a TQStringList
*
* This is a convenience overload for the case when the list is of
* type TQT_DBusData::String.
*
* @param ok optional pointer to a bool variable to store the
* success information in, i.e. will be set to @c true on success
* and to @c false if the conversion failed (not of type
* TQT_DBusData::String)
*
* @return a TQStringList containing the list object's string elements or
* an empty list when converting fails
*
* @see toStringList()
* @see TQT_DBusData::toString()
*/
TQStringList toTQStringList(bool* ok = 0) const;
/**
* @brief Tries to get the list object's elements as a TQValueList of bool
*
* This is a convenience overload for the case when the list is of
* type TQT_DBusData::Bool.
*
* @param ok optional pointer to a bool variable to store the
* success information in, i.e. will be set to @c true on success
* and to @c false if the conversion failed (not of type
* TQT_DBusData::Bool)
*
* @return a TQValueList of bool containing the list object's boolean
* elements or an empty list when converting fails
*
* @see TQT_DBusData::toBool()
*/
TQValueList<bool> toBoolList(bool* ok = 0) const;
/**
* @brief Tries to get the list object's elements as a TQValueList of TQ_UINT8
*
* This is a convenience overload for the case when the list is of
* type TQT_DBusData::Byte.
*
* @param ok optional pointer to a bool variable to store the
* success information in, i.e. will be set to @c true on success
* and to @c false if the conversion failed (not of type
* TQT_DBusData::Byte)
*
* @return a TQValueList of TQ_UINT8 containing the list object's byte
* elements or an empty list when converting fails
*
* @see TQT_DBusData::toByte()
*/
TQValueList<TQ_UINT8> toByteList(bool* ok = 0) const;
/**
* @brief Tries to get the list object's elements as a TQValueList of TQ_INT16
*
* This is a convenience overload for the case when the list is of
* type TQT_DBusData::Int16.
*
* @param ok optional pointer to a bool variable to store the
* success information in, i.e. will be set to @c true on success
* and to @c false if the conversion failed (not of type
* TQT_DBusData::Int16)
*
* @return a TQValueList of TQ_INT16 containing the list object's
* signed 16-bit integer elements or an empty list when converting
* fails
*
* @see TQT_DBusData::toInt16()
*/
TQValueList<TQ_INT16> toInt16List(bool* ok = 0) const;
/**
* @brief Tries to get the list object's elements as a TQValueList of TQ_UINT16
*
* This is a convenience overload for the case when the list is of
* type TQT_DBusData::UInt16.
*
* @param ok optional pointer to a bool variable to store the
* success information in, i.e. will be set to @c true on success
* and to @c false if the conversion failed (not of type
* TQT_DBusData::UInt16)
*
* @return a TQValueList of TQ_UINT16 containing the list object's
* unsigned 16-bit integer elements or an empty list when converting
* fails
*
* @see TQT_DBusData::toUInt16()
*/
TQValueList<TQ_UINT16> toUInt16List(bool* ok = 0) const;
/**
* @brief Tries to get the list object's elements as a TQValueList of TQ_INT32
*
* This is a convenience overload for the case when the list is of
* type TQT_DBusData::Int32.
*
* @param ok optional pointer to a bool variable to store the
* success information in, i.e. will be set to @c true on success
* and to @c false if the conversion failed (not of type
* TQT_DBusData::Int32)
*
* @return a TQValueList of TQ_INT32 containing the list object's
* signed 32-bit integer elements or an empty list when converting
* fails
*
* @see TQT_DBusData::toInt32()
*/
TQValueList<TQ_INT32> toInt32List(bool* ok = 0) const;
/**
* @brief Tries to get the list object's elements as a TQValueList of TQ_UINT32
*
* This is a convenience overload for the case when the list is of
* type TQT_DBusData::UInt32.
*
* @param ok optional pointer to a bool variable to store the
* success information in, i.e. will be set to @c true on success
* and to @c false if the conversion failed (not of type
* TQT_DBusData::UInt32)
*
* @return a TQValueList of TQ_UINT32 containing the list object's
* unsigned 32-bit integer elements or an empty list when converting
* fails
*
* @see TQT_DBusData::toUInt32()
*/
TQValueList<TQ_UINT32> toUInt32List(bool* ok = 0) const;
/**
* @brief Tries to get the list object's elements as a TQValueList of TQ_INT64
*
* This is a convenience overload for the case when the list is of
* type TQT_DBusData::Int64.
*
* @param ok optional pointer to a bool variable to store the
* success information in, i.e. will be set to @c true on success
* and to @c false if the conversion failed (not of type
* TQT_DBusData::Int64)
*
* @return a TQValueList of TQ_INT64 containing the list object's
* signed 64-bit integer elements or an empty list when converting
* fails
*
* @see TQT_DBusData::toInt64()
*/
TQValueList<TQ_INT64> toInt64List(bool* ok = 0) const;
/**
* @brief Tries to get the list object's elements as a TQValueList of TQ_UINT64
*
* This is a convenience overload for the case when the list is of
* type TQT_DBusData::UInt64.
*
* @param ok optional pointer to a bool variable to store the
* success information in, i.e. will be set to @c true on success
* and to @c false if the conversion failed (not of type
* TQT_DBusData::UInt64)
*
* @return a TQValueList of TQ_UINT64 containing the list object's
* unsigned 64-bit integer elements or an empty list when converting
* fails
*
* @see TQT_DBusData::toUInt64()
*/
TQValueList<TQ_UINT64> toUInt64List(bool* ok = 0) const;
/**
* @brief Tries to get the list object's elements as a TQValueList of double
*
* This is a convenience overload for the case when the list is of
* type TQT_DBusData::Double.
*
* @param ok optional pointer to a bool variable to store the
* success information in, i.e. will be set to @c true on success
* and to @c false if the conversion failed (not of type
* TQT_DBusData::Double)
*
* @return a TQValueList of double containing the list object's double
* elements or an empty list when converting fails
*
* @see TQT_DBusData::toDouble()
*/
TQValueList<double> toDoubleList(bool* ok = 0) const;
/**
* @brief Tries to get the list object's elements as a TQValueList of TQString
*
* This is a convenience overload for the case when the list is of
* type TQT_DBusData::String, see also toTQStringList().
*
* @param ok optional pointer to a bool variable to store the
* success information in, i.e. will be set to @c true on success
* and to @c false if the conversion failed (not of type
* TQT_DBusData::String)
*
* @return a TQValueList of TQString containing the list object's string
* elements or an empty list when converting fails
*
* @see TQT_DBusData::toString()
*/
TQValueList<TQString> toStringList(bool* ok = 0) const;
/**
* @brief Tries to get the list object's elements as a TQValueList of object paths
*
* @param ok optional pointer to a bool variable to store the
* success information in, i.e. will be set to @c true on success
* and to @c false if the conversion failed (not of type
* TQT_DBusData::ObjectPath)
*
* @return a TQValueList of object paths containing the list object's object path
* elements or an empty list when converting fails
*
* @see TQT_DBusData::toObjectPath()
*/
TQValueList<TQT_DBusObjectPath> toObjectPathList(bool* ok = 0) const;
/**
* @brief Tries to get the list object's elements as a TQValueList of TQT_DBusVariant
*
* This is a convenience overload for the case when the list is of
* type TQT_DBusData::Variant.
*
* @param ok optional pointer to a bool variable to store the
* success information in, i.e. will be set to @c true on success
* and to @c false if the conversion failed (not of type
* TQT_DBusData::Variant)
*
* @return a TQValueList of TQT_DBusVariant containing the list object's
* TQT_DBusVariant elements or an empty list when converting fails
*
* @see TQT_DBusData::toVariant()
*/
TQValueList<TQT_DBusVariant> toVariantList(bool* ok = 0) const;
private:
class Private;
Private* d;
};
#endif

File diff suppressed because it is too large Load Diff

@ -0,0 +1,216 @@
/* qdbuserror.cpp TQT_DBusError object
*
* Copyright (C) 2005 Harald Fernengel <harry@kdevelop.org>
* Copyright (C) 2005-2007 Kevin Krammer <kevin.krammer@gmx.at>
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*/
#include "tqdbuserror.h"
#include <dbus/dbus.h>
#include <tqmap.h>
typedef TQMap<TQString, TQT_DBusError::ErrorType> ErrorNameMap;
static ErrorNameMap errorTypesByName;
static TQString qDBusErrorNameForType(TQT_DBusError::ErrorType type)
{
switch (type)
{
case TQT_DBusError::InvalidError:
Q_ASSERT(false);
return TQString();
case TQT_DBusError::Failed:
return TQString::fromUtf8(DBUS_ERROR_FAILED);
case TQT_DBusError:: NoMemory:
return TQString::fromUtf8(DBUS_ERROR_NO_MEMORY);
case TQT_DBusError:: ServiceUnknown:
return TQString::fromUtf8(DBUS_ERROR_SERVICE_UNKNOWN);
case TQT_DBusError:: NameHasNoOwner:
return TQString::fromUtf8(DBUS_ERROR_NAME_HAS_NO_OWNER);
case TQT_DBusError:: NoReply:
return TQString::fromUtf8(DBUS_ERROR_NO_REPLY);
case TQT_DBusError:: IOError:
return TQString::fromUtf8(DBUS_ERROR_IO_ERROR);
case TQT_DBusError:: BadAddress:
return TQString::fromUtf8(DBUS_ERROR_BAD_ADDRESS);
case TQT_DBusError:: NotSupported:
return TQString::fromUtf8(DBUS_ERROR_NOT_SUPPORTED);
case TQT_DBusError:: LimitsExceeded:
return TQString::fromUtf8(DBUS_ERROR_LIMITS_EXCEEDED);
case TQT_DBusError:: AccessDenied:
return TQString::fromUtf8(DBUS_ERROR_ACCESS_DENIED);
case TQT_DBusError:: AuthFailed:
return TQString::fromUtf8(DBUS_ERROR_AUTH_FAILED);
case TQT_DBusError:: NoServer:
return TQString::fromUtf8(DBUS_ERROR_NO_SERVER);
case TQT_DBusError:: Timeout:
return TQString::fromUtf8(DBUS_ERROR_TIMEOUT);
case TQT_DBusError:: NoNetwork:
return TQString::fromUtf8(DBUS_ERROR_NO_NETWORK);
case TQT_DBusError:: Disconnected:
return TQString::fromUtf8(DBUS_ERROR_DISCONNECTED);
case TQT_DBusError:: InvalidArgs:
return TQString::fromUtf8(DBUS_ERROR_INVALID_ARGS);
case TQT_DBusError:: FileNotFound:
return TQString::fromUtf8(DBUS_ERROR_FILE_NOT_FOUND);
case TQT_DBusError:: FileExists:
return TQString::fromUtf8(DBUS_ERROR_FILE_EXISTS);
case TQT_DBusError:: UnknownMethod:
return TQString::fromUtf8(DBUS_ERROR_UNKNOWN_METHOD);
case TQT_DBusError:: TimedOut:
return TQString::fromUtf8(DBUS_ERROR_TIMED_OUT);
case TQT_DBusError:: InvalidSignature:
return TQString::fromUtf8(DBUS_ERROR_INVALID_SIGNATURE);
case TQT_DBusError::UserDefined:
Q_ASSERT(false);
return TQString();
}
Q_ASSERT(false);
return TQString();
}
static void qDBusErrorSetupNameMapping()
{
for (int i = TQT_DBusError::InvalidError + 1; i < TQT_DBusError::UserDefined; ++i)
{
TQT_DBusError::ErrorType type = static_cast<TQT_DBusError::ErrorType>(i);
errorTypesByName[qDBusErrorNameForType(type)] = type;
}
}
static TQT_DBusError::ErrorType qDBusErrorTypeForName(const TQString& name)
{
if (name.isEmpty()) return TQT_DBusError::InvalidError;
if (errorTypesByName.isEmpty())
qDBusErrorSetupNameMapping();
ErrorNameMap::const_iterator it = errorTypesByName.tqfind(name);
if (it != errorTypesByName.end()) return it.data();
return TQT_DBusError::UserDefined;
}
TQT_DBusError::TQT_DBusError() : errorType(InvalidError)
{
}
TQT_DBusError::TQT_DBusError(const DBusError *error) : errorType(InvalidError)
{
if (!error || !dbus_error_is_set(error))
return;
nm = TQString::fromUtf8(error->name);
msg = TQString::fromUtf8(error->message);
errorType = qDBusErrorTypeForName(nm);
}
TQT_DBusError::TQT_DBusError(const TQString& error, const TQString& message)
: errorType(UserDefined), nm(error), msg(message)
{
errorType = qDBusErrorTypeForName(nm);
}
bool TQT_DBusError::isValid() const
{
return errorType != InvalidError && !nm.isEmpty() && !msg.isEmpty();
}
TQT_DBusError::TQT_DBusError(ErrorType type, const TQString& message)
: errorType(type), msg(message)
{
nm = qDBusErrorNameForType(type);
}
TQT_DBusError TQT_DBusError::stdFailed(const TQString& message)
{
return TQT_DBusError(TQT_DBusError::Failed, message);
}
TQT_DBusError TQT_DBusError::stdNoMemory(const TQString& message)
{
return TQT_DBusError(TQT_DBusError::NoMemory, message);
}
TQT_DBusError TQT_DBusError::stdNoReply(const TQString& message)
{
return TQT_DBusError(TQT_DBusError::NoReply, message);
}
TQT_DBusError TQT_DBusError::stdIOError(const TQString& message)
{
return TQT_DBusError(TQT_DBusError::IOError, message);
}
TQT_DBusError TQT_DBusError::stdNotSupported(const TQString& message)
{
return TQT_DBusError(TQT_DBusError::NotSupported, message);
}
TQT_DBusError TQT_DBusError::stdLimitsExceeded(const TQString& message)
{
return TQT_DBusError(TQT_DBusError::LimitsExceeded, message);
}
TQT_DBusError TQT_DBusError::stdAccessDenied(const TQString& message)
{
return TQT_DBusError(TQT_DBusError::AccessDenied, message);
}
TQT_DBusError TQT_DBusError::stdAuthFailed(const TQString& message)
{
return TQT_DBusError(TQT_DBusError::AuthFailed, message);
}
TQT_DBusError TQT_DBusError::stdTimeout(const TQString& message)
{
return TQT_DBusError(TQT_DBusError::Timeout, message);
}
TQT_DBusError TQT_DBusError::stdInvalidArgs(const TQString& message)
{
return TQT_DBusError(TQT_DBusError::InvalidArgs, message);
}
TQT_DBusError TQT_DBusError::stdFileNotFound(const TQString& message)
{
return TQT_DBusError(TQT_DBusError::FileNotFound, message);
}
TQT_DBusError TQT_DBusError::stdFileExists(const TQString& message)
{
return TQT_DBusError(TQT_DBusError::FileExists, message);
}
TQT_DBusError TQT_DBusError::stdUnknownMethod(const TQString& message)
{
return TQT_DBusError(TQT_DBusError::UnknownMethod, message);
}
TQT_DBusError TQT_DBusError::stdInvalidSignature(const TQString& message)
{
return TQT_DBusError(TQT_DBusError::InvalidSignature, message);
}

@ -0,0 +1,461 @@
/* qdbuserror.h TQT_DBusError object
*
* Copyright (C) 2005 Harald Fernengel <harry@kdevelop.org>
* Copyright (C) 2005 Kevin Krammer <kevin.krammer@gmx.at>
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*/
#ifndef TQDBUSERROR_H
#define TQDBUSERROR_H
#include "tqdbusmacros.h"
#include <tqstring.h>
struct DBusError;
/**
* @brief Class for transporting D-Bus errors
*
* A D-Bus error has two parts: an error name (see section
* @ref dbusconventions-errorname) and a message string detailing the error in
* human presentable form.
*/
class TQDBUS_EXPORT TQT_DBusError
{
public:
/**
* @brief Enum of standard D-Bus error types
*
* D-Bus defines a list of common error types and their names.
* The values of this enum map to those an application is likely to encounter
* and likely to create itself.
*
* Standard errors can either be created by specifying the D-Bus error name
* or, as a convenience, by using factory methods of this class for the
* most common ones.
*
* All D-Bus standard error names are within the @c "org.freedesktop.DBus.Error"
* namespace.
*
* @see name()
*/
enum ErrorType
{
/**
* @brief TQT_DBusError specific value, to represent invalid error objects.
*
* @see isValid()
*/
InvalidError,
/**
* @brief Generic failure cause
*
* Can be used whenever the other predefined errors do no match. Basically
* just meaning "something when wrong, see message() for details"
*
* @see stdFailed()
*/
Failed,
/**
* @brief An operation could not allocate enough memory
*
* @see stdNoMemory()
*/
NoMemory,
/**
* @brief An addressed service is neither connected nor can it be activated
*/
ServiceUnknown,
/**
* @brief A non-unique name used in a message is not known
*
* If a message addresses a D-Bus connection through a non-unique
* (requested) name and the D-Bus does not have a mapping to any of the
* unique names.
*/
NameHasNoOwner,
/**
* @brief An call failed to send a reply but one was expected
*
* @see stdNoReply()
*/
NoReply,
/**
* @brief An IO error occured during an operation
*
* Generic indicator that some kind of IO operation failed, e.g.
* reading from a socket.
*
* @see stdIOError()
*/
IOError,
/**
* @brief Caused by trying to connect to a malformed address
*
* Returned by TQT_DBusConnection's addConnection if the specified address
* isn't a valid D-Bus bus address.
*
* @see TQT_DBusConnection::addConnection(const TQString&,const TQString&);
*/
BadAddress,
/**
* @brief An otherwise valid operation request could not be handled
*
* Primarily useful when a service implements a specific interface but
* does not (yet) handle all possible situations.
*
* @see stdNotSupported()
*/
NotSupported,
/**
* @brief Use of a limited resource reached its limit
*
* @see stdLimitsExceeded()
*/
LimitsExceeded,
/**
* @brief Caused by security restrictions denying an operation
*
* Primarily useful when a client tries to manipulate resources a service
* has associated with a different client and which should not be changable
* by anyone else.
*
* @see stdAccessDenied()
*/
AccessDenied,
/**
* @brief An authentification mechanism failed
*
* @see stdAuthFailed()
*/
AuthFailed,
/**
* @brief Connection to a D-Bus server failed
*/
NoServer,
/**
* @brief An timeout occured during an operation
*
* @warning D-Bus defined to quite similar errors but does not detail
* when either one can occur. See #TimedOut
*
* @see stdTimeout()
*/
Timeout,
/**
* @brief The network intended as a transport channel is not available
*/
NoNetwork,
/**
* @brief Caused by trying to use an unconnected D-Bus connection
*
* @see TQT_DBusConnection::isConnected()
*/
Disconnected,
/**
* @brief Caused by invalid arguments passed to a method call
*
* Primarily usefull for service implementations when the incoming
* call does not transport the expected parameters, e.g. wrong types
* or wrong values.
*
* @see stdInvalidArgs()
*/
InvalidArgs,
/**
* @brief A file necessary for an operation is not avaiable
*
* @see stdFileNotFound()
*/
FileNotFound,
/**
* @brief Target file exists but operation does not allow overwriting
*
* @see stdFileExists()
*/
FileExists,
/**
* @brief A method call addresses and unknown method
*
* @see stdUnknownMethod()
*/
UnknownMethod,
/**
* @brief An operation timed out
*
* @warning D-Bus defined to quite similar errors but does not detail
* when either one can occur. See #Timeout
*/
TimedOut,
/**
* @brief An type signature is not valid
*
* A possible cause is a TQT_DBusVariant with an invalid signature, i.e.
* the transported signature is empty, tqcontains unknown type characters
* or has mismatched container enclosings.
*
* @note in case a service implementation wants to indicate that a method
* call did not transport the correct parameter types, use
* #InvalidArgs instead
*
* @see stdInvalidSignature()
*/
InvalidSignature,
/**
* @brief Generic type for all errors not matching on of the other predefined
*
* @see TQT_DBusError(const TQString&,const TQString&);
*/
UserDefined
};
/**
* @brief Creates an empty and invalid error object
*/
TQT_DBusError();
/**
* @brief Creates an error object from an C API D-Bus error object
*
* @param error a pointer to the C API D-Bus error
*/
TQT_DBusError(const DBusError *error);
/**
* @brief Creates an error object for its two given components
*
* @param error a D-Bus error name
* @param message the potentially i18n'ed error description message
*
* @see name()
*/
TQT_DBusError(const TQString& error, const TQString& message);
/**
* @brief Returns the D-Bus error name
*
* See section @ref dbusconventions-errorname for details.
*
* @return the D-Bus error name
*
* @see message()
*/
inline TQString name() const { return nm; }
/**
* @brief Returns a string describing the error
*
* The message is meant to further detail or describe the error.
* It is usually a translated error message meant for direct
* presentation to the user.
*
* @return the error's message
*
* @see name()
*/
inline TQString message() const { return msg; }
/**
* @brief Returns a type for checking of standard errors
*
* D-Bus specifies a couple of standard error names, which are mapped to
* TQT_DBusError types in order to make creating and checking for them easier.
*
* @return the error's type
*
* @see name()
*/
inline ErrorType type() const { return errorType; }
/**
* @brief Returns whether the error object is valid
*
* A TQT_DBusError is considered valid if both name and message are set.
*
* @return @c true if neither name nor message is @c TQString() and the
* error type is a valid type
*/
bool isValid() const;
/**
* @brief Creates a D-Bus standard error for generic failure
*
* @param message the message detailing the encountered problem
*
* @return an error object of type #Failed with the given @p message
*/
static TQT_DBusError stdFailed(const TQString& message);
/**
* @brief Creates a D-Bus standard error for out of memory situations
*
* @param message the message detailing the encountered problem
*
* @return an error object of type #NoMemory with the given @p message
*/
static TQT_DBusError stdNoMemory(const TQString& message);
/**
* @brief Creates a D-Bus standard error for expected reply missing
*
* @param message the message detailing the encountered problem
*
* @return an error object of type #NoReply with the given @p message
*/
static TQT_DBusError stdNoReply(const TQString& message);
/**
* @brief Creates a D-Bus standard error for generic IO errors
*
* @param message the message detailing the encountered problem
*
* @return an error object of type #IOError with the given @p message
*/
static TQT_DBusError stdIOError(const TQString& message);
/**
* @brief Creates a D-Bus standard error for unsupported operations
*
* @param message the message detailing the encountered problem
*
* @return an error object of type #NotSupported with the given @p message
*/
static TQT_DBusError stdNotSupported(const TQString& message);
/**
* @brief Creates a D-Bus standard error for exceeding a limited resource
*
* @param message the message detailing the encountered problem
*
* @return an error object of type #LimitsExceeded with the given @p message
*/
static TQT_DBusError stdLimitsExceeded(const TQString& message);
/**
* @brief Creates a D-Bus standard error for access to a resource being denied
*
* @param message the message detailing the encountered problem
*
* @return an error object of type #AccessDenied with the given @p message
*/
static TQT_DBusError stdAccessDenied(const TQString& message);
/**
* @brief Creates a D-Bus standard error for failed authentification
*
* @param message the message detailing the encountered problem
*
* @return an error object of type #AuthFailed with the given @p message
*/
static TQT_DBusError stdAuthFailed(const TQString& message);
/**
* @brief Creates a D-Bus standard error for timeouts during operations
*
* @param message the message detailing the encountered problem
*
* @return an error object of type #Timeout with the given @p message
*/
static TQT_DBusError stdTimeout(const TQString& message);
/**
* @brief Creates a D-Bus standard error for call arguments being invalid
*
* @param message the message detailing the encountered problem
*
* @return an error object of type #InvalidArgs with the given @p message
*/
static TQT_DBusError stdInvalidArgs(const TQString& message);
/**
* @brief Creates a D-Bus standard error for a file not being available
*
* @param message the message detailing the encountered problem
*
* @return an error object of type #FileNotFound with the given @p message
*/
static TQT_DBusError stdFileNotFound(const TQString& message);
/**
* @brief Creates a D-Bus standard error for a file being in the way
*
* @param message the message detailing the encountered problem
*
* @return an error object of type #FileExists with the given @p message
*/
static TQT_DBusError stdFileExists(const TQString& message);
/**
* @brief Creates a D-Bus standard error for an unknown methods being called
*
* @param message the message detailing the encountered problem
*
* @return an error object of type #UnknownMethod with the given @p message
*/
static TQT_DBusError stdUnknownMethod(const TQString& message);
/**
* @brief Creates a D-Bus standard error for D-Bus type signature not valid
*
* @param message the message detailing the encountered problem
*
* @return an error object of type #InvalidSignature with the given @p message
*/
static TQT_DBusError stdInvalidSignature(const TQString& message);
private:
ErrorType errorType;
TQString nm, msg;
/**
* @brief Creates an error object for one of the standard D-Bus errors
*
* @param type one of the standard error causes
* @param message the potentially i18n'ed error description message
*
* @see ErrorType
*/
TQT_DBusError(ErrorType type, const TQString& message);
};
#endif

@ -0,0 +1,626 @@
/* qdbusintegrator.cpp TQT_DBusConnection private implementation
*
* Copyright (C) 2005 Harald Fernengel <harry@kdevelop.org>
* Copyright (C) 2005 Kevin Krammer <kevin.krammer@gmx.at>
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*/
#include <tqapplication.h>
#include <tqevent.h>
#include <tqmetaobject.h>
#include <tqsocketnotifier.h>
#include <tqtimer.h>
#include "tqdbusconnection_p.h"
#include "tqdbusmessage.h"
Atomic::Atomic(int value) : m_value(value)
{
}
void Atomic::ref()
{
m_value++;
}
bool Atomic::deref()
{
m_value--;
return m_value > 0;
}
int TQT_DBusConnectionPrivate::messageMetaType = 0;
static dbus_bool_t qDBusAddTimeout(DBusTimeout *timeout, void *data)
{
Q_ASSERT(timeout);
Q_ASSERT(data);
// qDebug("addTimeout %d", dbus_timeout_get_interval(timeout));
TQT_DBusConnectionPrivate *d = static_cast<TQT_DBusConnectionPrivate *>(data);
if (!dbus_timeout_get_enabled(timeout))
return true;
if (!tqApp) {
d->pendingTimeouts.append(timeout);
return true;
}
int timerId = d->startTimer(dbus_timeout_get_interval(timeout));
if (!timerId)
return false;
d->timeouts[timerId] = timeout;
return true;
}
static void qDBusRemoveTimeout(DBusTimeout *timeout, void *data)
{
Q_ASSERT(timeout);
Q_ASSERT(data);
// qDebug("removeTimeout");
TQT_DBusConnectionPrivate *d = static_cast<TQT_DBusConnectionPrivate *>(data);
for (TQValueList<DBusTimeout*>::iterator it = d->pendingTimeouts.begin();
it != d->pendingTimeouts.end();) {
if ((*it) == timeout) {
it = d->pendingTimeouts.erase(it);
}
else
++it;
}
TQT_DBusConnectionPrivate::TimeoutHash::iterator it = d->timeouts.begin();
while (it != d->timeouts.end()) {
if (it.data() == timeout) {
d->killTimer(it.key());
TQT_DBusConnectionPrivate::TimeoutHash::iterator copyIt = it;
++it;
d->timeouts.erase(copyIt);
} else {
++it;
}
}
}
static void qDBusToggleTimeout(DBusTimeout *timeout, void *data)
{
Q_ASSERT(timeout);
Q_ASSERT(data);
//qDebug("ToggleTimeout");
qDBusRemoveTimeout(timeout, data);
qDBusAddTimeout(timeout, data);
}
static dbus_bool_t qDBusAddWatch(DBusWatch *watch, void *data)
{
Q_ASSERT(watch);
Q_ASSERT(data);
TQT_DBusConnectionPrivate *d = static_cast<TQT_DBusConnectionPrivate *>(data);
int flags = dbus_watch_get_flags(watch);
int fd = dbus_watch_get_unix_fd(watch);
TQT_DBusConnectionPrivate::Watcher watcher;
if (flags & DBUS_WATCH_READABLE) {
bool enabled = dbus_watch_get_enabled(watch);
//qDebug("addReadWatch %d %s", fd, (enabled ? "enabled" : "disabled"));
watcher.watch = watch;
if (tqApp) {
watcher.read = new TQSocketNotifier(fd, TQSocketNotifier::Read, d);
if (!enabled) watcher.read->setEnabled(false);
d->connect(watcher.read, TQT_SIGNAL(activated(int)), TQT_SLOT(socketRead(int)));
}
}
if (flags & DBUS_WATCH_WRITABLE) {
bool enabled = dbus_watch_get_enabled(watch);
//qDebug("addWriteWatch %d %s", fd, (enabled ? "enabled" : "disabled"));
watcher.watch = watch;
if (tqApp) {
watcher.write = new TQSocketNotifier(fd, TQSocketNotifier::Write, d);
if (!enabled) watcher.write->setEnabled(false);
d->connect(watcher.write, TQT_SIGNAL(activated(int)), TQT_SLOT(socketWrite(int)));
}
}
// FIXME-QT4 d->watchers.insertMulti(fd, watcher);
TQT_DBusConnectionPrivate::WatcherHash::iterator it = d->watchers.tqfind(fd);
if (it == d->watchers.end())
{
it = d->watchers.insert(fd, TQT_DBusConnectionPrivate::WatcherList());
}
it.data().append(watcher);
return true;
}
static void qDBusRemoveWatch(DBusWatch *watch, void *data)
{
Q_ASSERT(watch);
Q_ASSERT(data);
//qDebug("remove watch");
TQT_DBusConnectionPrivate *d = static_cast<TQT_DBusConnectionPrivate *>(data);
int fd = dbus_watch_get_unix_fd(watch);
TQT_DBusConnectionPrivate::WatcherHash::iterator it = d->watchers.tqfind(fd);
if (it != d->watchers.end())
{
TQT_DBusConnectionPrivate::WatcherList& list = *it;
for (TQT_DBusConnectionPrivate::WatcherList::iterator wit = list.begin();
wit != list.end(); ++wit)
{
if ((*wit).watch == watch)
{
// migth be called from a function triggered by a socket listener
// so just disconnect them and schedule their delayed deletion.
d->removedWatches.append(*wit);
if ((*wit).read)
{
(*wit).read->disconnect(d);
(*wit).read = 0;
}
if ((*wit).write)
{
(*wit).write->disconnect(d);
(*wit).write = 0;
}
(*wit).watch = 0;
}
}
}
if (d->removedWatches.count() > 0)
TQTimer::singleShot(0, d, TQT_SLOT(purgeRemovedWatches()));
}
static void qDBusToggleWatch(DBusWatch *watch, void *data)
{
Q_ASSERT(watch);
Q_ASSERT(data);
//qDebug("toggle watch");
TQT_DBusConnectionPrivate *d = static_cast<TQT_DBusConnectionPrivate *>(data);
int fd = dbus_watch_get_unix_fd(watch);
TQT_DBusConnectionPrivate::WatcherHash::iterator it = d->watchers.tqfind(fd);
if (it != d->watchers.end()) {
TQT_DBusConnectionPrivate::WatcherList& list = *it;
for (TQT_DBusConnectionPrivate::WatcherList::iterator wit = list.begin(); wit != list.end();
++wit)
{
if ((*wit).watch == watch) {
bool enabled = dbus_watch_get_enabled(watch);
int flags = dbus_watch_get_flags(watch);
// qDebug("toggle watch %d to %d (write: %d, read: %d)",
// dbus_watch_get_unix_fd(watch), enabled,
// flags & DBUS_WATCH_WRITABLE, flags & DBUS_WATCH_READABLE);
if (flags & DBUS_WATCH_READABLE && (*wit).read)
(*wit).read->setEnabled(enabled);
if (flags & DBUS_WATCH_WRITABLE && (*wit).write)
(*wit).write->setEnabled(enabled);
return;
}
}
}
}
static void qDBusNewConnection(DBusServer *server, DBusConnection *c, void *data)
{
Q_ASSERT(data); Q_ASSERT(server); Q_ASSERT(c);
qDebug("SERVER: GOT A NEW CONNECTION"); // TODO
}
static DBusHandlerResult qDBusSignalFilter(DBusConnection *connection,
DBusMessage *message, void *data)
{
Q_ASSERT(data);
Q_UNUSED(connection);
TQT_DBusConnectionPrivate *d = static_cast<TQT_DBusConnectionPrivate *>(data);
if (d->mode == TQT_DBusConnectionPrivate::InvalidMode)
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
int msgType = dbus_message_get_type(message);
bool handled = false;
//TQT_DBusMessage amsg = TQT_DBusMessage::fromDBusMessage(message);
//qDebug() << "got message: " << dbus_message_get_type(message) << amsg;
if (msgType == DBUS_MESSAGE_TYPE_SIGNAL) {
handled = d->handleSignal(message);
} else if (msgType == DBUS_MESSAGE_TYPE_METHOD_CALL) {
handled = d->handleObjectCall(message);
}
return handled ? DBUS_HANDLER_RESULT_HANDLED :
DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
int TQT_DBusConnectionPrivate::registerMessageMetaType()
{
// FIXME-QT4 int tp = messageMetaType = qRegisterMetaType<TQT_DBusMessage>("TQT_DBusMessage");
int tp = 0;
return tp;
}
TQT_DBusConnectionPrivate::TQT_DBusConnectionPrivate(TQObject *tqparent)
: TQObject(tqparent), ref(1), mode(InvalidMode), connection(0), server(0),
dispatcher(0)
{
static const int msgType = registerMessageMetaType();
Q_UNUSED(msgType);
dbus_error_init(&error);
dispatcher = new TQTimer(this);
TQObject::connect(dispatcher, TQT_SIGNAL(timeout()), this, TQT_SLOT(dispatch()));
}
TQT_DBusConnectionPrivate::~TQT_DBusConnectionPrivate()
{
if (dbus_error_is_set(&error))
dbus_error_free(&error);
closeConnection();
}
void TQT_DBusConnectionPrivate::closeConnection()
{
ConnectionMode oldMode = mode;
mode = InvalidMode; // prevent reentrancy
if (oldMode == ServerMode) {
if (server) {
dbus_server_disconnect(server);
dbus_server_unref(server);
server = 0;
}
} else if (oldMode == ClientMode) {
if (connection) {
// closing shared connections is forbidden
#if 0
dbus_connection_close(connection);
// send the "close" message
while (dbus_connection_dispatch(connection) == DBUS_DISPATCH_DATA_REMAINS);
#endif
dbus_connection_unref(connection);
connection = 0;
}
}
}
bool TQT_DBusConnectionPrivate::handleError()
{
lastError = TQT_DBusError(&error);
if (dbus_error_is_set(&error))
dbus_error_free(&error);
return lastError.isValid();
}
void TQT_DBusConnectionPrivate::emitPendingCallReply(const TQT_DBusMessage& message)
{
emit dbusPendingCallReply(message);
}
void TQT_DBusConnectionPrivate::bindToApplication()
{
// Yay, now that we have an application we are in business
// Re-add all watchers
WatcherHash oldWatchers = watchers;
watchers.clear();
// FIXME-QT4 TQHashIterator<int, TQT_DBusConnectionPrivate::Watcher> it(oldWatchers);
for (WatcherHash::const_iterator it = oldWatchers.begin(); it != oldWatchers.end(); ++it)
{
const WatcherList& list = *it;
for (WatcherList::const_iterator wit = list.begin(); wit != list.end(); ++wit)
{
if (!(*wit).read && !(*wit).write) {
qDBusAddWatch((*wit).watch, this);
}
}
}
// Re-add all timeouts
while (!pendingTimeouts.isEmpty()) {
qDBusAddTimeout(pendingTimeouts.first(), this);
pendingTimeouts.pop_front();
}
}
void TQT_DBusConnectionPrivate::socketRead(int fd)
{
// FIXME-QT4 TQHashIterator<int, TQT_DBusConnectionPrivate::Watcher> it(watchers);
WatcherHash::const_iterator it = watchers.tqfind(fd);
if (it != watchers.end()) {
const WatcherList& list = *it;
for (WatcherList::const_iterator wit = list.begin(); wit != list.end(); ++wit) {
if ((*wit).read && (*wit).read->isEnabled()) {
if (!dbus_watch_handle((*wit).watch, DBUS_WATCH_READABLE))
qDebug("OUT OF MEM");
}
}
}
if (mode == ClientMode)
scheduleDispatch();
}
void TQT_DBusConnectionPrivate::socketWrite(int fd)
{
// FIXME-QT4 TQHashIterator<int, TQT_DBusConnectionPrivate::Watcher> it(watchers);
WatcherHash::const_iterator it = watchers.tqfind(fd);
if (it != watchers.end()) {
const WatcherList& list = *it;
for (WatcherList::const_iterator wit = list.begin(); wit != list.end(); ++wit) {
if ((*wit).write && (*wit).write->isEnabled()) {
if (!dbus_watch_handle((*wit).watch, DBUS_WATCH_WRITABLE))
qDebug("OUT OF MEM");
}
}
}
}
void TQT_DBusConnectionPrivate::objectDestroyed(TQObject* object)
{
//qDebug("Object destroyed");
for (PendingCallMap::iterator it = pendingCalls.begin(); it != pendingCalls.end();)
{
TQObject* receiver = (TQObject*) it.data()->receiver;
if (receiver == object || receiver == 0)
{
PendingCallMap::iterator copyIt = it;
++it;
dbus_pending_call_cancel(copyIt.key());
dbus_pending_call_unref(copyIt.key());
delete copyIt.data();
pendingCalls.erase(copyIt);
}
else
++it;
}
}
void TQT_DBusConnectionPrivate::purgeRemovedWatches()
{
if (removedWatches.isEmpty()) return;
WatcherList::iterator listIt = removedWatches.begin();
for (; listIt != removedWatches.end(); ++listIt)
{
delete (*listIt).read;
delete (*listIt).write;
}
removedWatches.clear();
uint count = 0;
WatcherHash::iterator it = watchers.begin();
while (it != watchers.end())
{
WatcherList& list = *it;
listIt = list.begin();
while (listIt != list.end())
{
if (!((*listIt).read) && !((*listIt).write))
{
listIt = list.erase(listIt);
++count;
}
}
if (list.isEmpty())
{
WatcherHash::iterator copyIt = it;
++it;
watchers.erase(copyIt);
}
else
++it;
}
}
void TQT_DBusConnectionPrivate::scheduleDispatch()
{
dispatcher->start(0);
}
void TQT_DBusConnectionPrivate::dispatch()
{
if (mode == ClientMode)
{
if (dbus_connection_dispatch(connection) != DBUS_DISPATCH_DATA_REMAINS)
{
// stop dispatch timer
dispatcher->stop();
}
}
}
bool TQT_DBusConnectionPrivate::handleObjectCall(DBusMessage *message)
{
TQT_DBusMessage msg = TQT_DBusMessage::fromDBusMessage(message);
ObjectMap::iterator it = registeredObjects.tqfind(msg.path());
if (it == registeredObjects.end())
return false;
return it.data()->handleMethodCall(msg);
}
bool TQT_DBusConnectionPrivate::handleSignal(DBusMessage *message)
{
TQT_DBusMessage msg = TQT_DBusMessage::fromDBusMessage(message);
// yes, it is a single "|" below...
// FIXME-QT4
//return handleSignal(TQString(), msg) | handleSignal(msg.path(), msg);
dbusSignal(msg);
return true;
}
static dbus_int32_t server_slot = -1;
void TQT_DBusConnectionPrivate::setServer(DBusServer *s)
{
if (!server) {
handleError();
return;
}
server = s;
mode = ServerMode;
dbus_server_allocate_data_slot(&server_slot);
if (server_slot < 0)
return;
dbus_server_set_watch_functions(server, qDBusAddWatch, qDBusRemoveWatch,
qDBusToggleWatch, this, 0); // ### check return type?
dbus_server_set_timeout_functions(server, qDBusAddTimeout, qDBusRemoveTimeout,
qDBusToggleTimeout, this, 0);
dbus_server_set_new_connection_function(server, qDBusNewConnection, this, 0);
dbus_server_set_data(server, server_slot, this, 0);
}
void TQT_DBusConnectionPrivate::setConnection(DBusConnection *dbc)
{
if (!dbc) {
handleError();
return;
}
connection = dbc;
mode = ClientMode;
dbus_connection_set_exit_on_disconnect(connection, false);
dbus_connection_set_watch_functions(connection, qDBusAddWatch, qDBusRemoveWatch,
qDBusToggleWatch, this, 0);
dbus_connection_set_timeout_functions(connection, qDBusAddTimeout, qDBusRemoveTimeout,
qDBusToggleTimeout, this, 0);
// dbus_bus_add_match(connection, "type='signal',interface='com.trolltech.dbus.Signal'", &error);
// dbus_bus_add_match(connection, "type='signal'", &error);
dbus_bus_add_match(connection, "type='signal'", &error);
if (handleError()) {
closeConnection();
return;
}
const char *service = dbus_bus_get_unique_name(connection);
if (service) {
TQCString filter;
filter += "destination='";
filter += service;
filter += "\'";
dbus_bus_add_match(connection, filter.data(), &error);
if (handleError()) {
closeConnection();
return;
}
} else {
qWarning("TQT_DBusConnectionPrivate::SetConnection: Unable to get unique name");
}
dbus_connection_add_filter(connection, qDBusSignalFilter, this, 0);
//qDebug("unique name: %s", service);
}
static void qDBusResultReceived(DBusPendingCall *pending, void *user_data)
{
//qDebug("Pending Call Result received");
TQT_DBusConnectionPrivate* d = reinterpret_cast<TQT_DBusConnectionPrivate*>(user_data);
TQT_DBusConnectionPrivate::PendingCallMap::iterator it = d->pendingCalls.tqfind(pending);
DBusMessage *dbusReply = dbus_pending_call_steal_reply(pending);
dbus_set_error_from_message(&d->error, dbusReply);
d->handleError();
if (it != d->pendingCalls.end())
{
TQT_DBusMessage reply = TQT_DBusMessage::fromDBusMessage(dbusReply);
TQObject::connect(d, TQT_SIGNAL(dbusPendingCallReply(const TQT_DBusMessage&)),
it.data()->receiver, it.data()->method.data());
d->emitPendingCallReply(reply);
TQObject::disconnect(d, TQT_SIGNAL(dbusPendingCallReply(const TQT_DBusMessage&)),
it.data()->receiver, it.data()->method.data());
}
dbus_message_unref(dbusReply);
dbus_pending_call_unref(pending);
delete it.data();
d->pendingCalls.erase(it);
}
int TQT_DBusConnectionPrivate::sendWithReplyAsync(const TQT_DBusMessage &message, TQObject *receiver,
const char *method)
{
if (!receiver || !method)
return 0;
if (!TQObject::connect(receiver, TQT_SIGNAL(destroyed(TQObject*)),
this, TQT_SLOT(objectDestroyed(TQObject*))))
return false;
DBusMessage *msg = message.toDBusMessage();
if (!msg)
return 0;
DBusPendingCall *pending = 0;
if (dbus_connection_send_with_reply(connection, msg, &pending, message.timeout())) {
TQT_DBusPendingCall *pcall = new TQT_DBusPendingCall;
pcall->receiver = receiver;
pcall->method = method;
pcall->pending = dbus_pending_call_ref(pending);
pendingCalls.insert(pcall->pending, pcall);
dbus_pending_call_set_notify(pending, qDBusResultReceived, this, 0);
return dbus_message_get_serial(msg);
}
return 0;
}
void TQT_DBusConnectionPrivate::flush()
{
if (!connection) return;
dbus_connection_flush(connection);
}
#include "tqdbusconnection_p.moc"

@ -0,0 +1,31 @@
/* qdbusmacros TQDBUS macro definitions
*
* Copyright (C) 2005 Kevin Krammer <kevin.krammer@gmx.at>
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*/
#ifndef TQDBUSMACROS_H
#define TQDBUSMACROS_H
#include <tqglobal.h>
#define TQDBUS_EXPORT TQ_EXPORT
#endif

File diff suppressed because it is too large Load Diff

@ -0,0 +1,40 @@
/* qdbusmarshall.h TQT_DBusMarshall object
*
* Copyright (C) 2005 Harald Fernengel <harry@kdevelop.org>
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*/
#ifndef TQDBUSMARSHALL_H
#define TQDBUSMARSHALL_H
struct DBusMessage;
class TQT_DBusData;
template <typename T> class TQValueList;
class TQT_DBusMarshall
{
public:
static void listToMessage(const TQValueList<TQT_DBusData> &list, DBusMessage* message);
static void messageToList(TQValueList<TQT_DBusData>& list, DBusMessage* message);
};
#endif

@ -0,0 +1,263 @@
/* qdbusmessage.cpp
*
* Copyright (C) 2005 Harald Fernengel <harry@kdevelop.org>
* Copyright (C) 2005 Kevin Krammer <kevin.krammer@gmx.at>
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*/
#include "tqdbusmessage.h"
#include <tqstringlist.h>
#include <dbus/dbus.h>
#include "tqdbusmarshall.h"
#include "tqdbusmessage_p.h"
TQT_DBusMessagePrivate::TQT_DBusMessagePrivate(TQT_DBusMessage *qq)
: msg(0), reply(0), q(qq), type(DBUS_MESSAGE_TYPE_INVALID), timeout(-1), ref(1)
{
}
TQT_DBusMessagePrivate::~TQT_DBusMessagePrivate()
{
if (msg)
dbus_message_unref(msg);
if (reply)
dbus_message_unref(reply);
}
///////////////
TQT_DBusMessage TQT_DBusMessage::signal(const TQString &path, const TQString &interface,
const TQString &member)
{
TQT_DBusMessage message;
message.d->type = DBUS_MESSAGE_TYPE_SIGNAL;
message.d->path = path;
message.d->interface = interface;
message.d->member = member;
return message;
}
TQT_DBusMessage TQT_DBusMessage::methodCall(const TQString &service, const TQString &path,
const TQString &interface, const TQString &method)
{
TQT_DBusMessage message;
message.d->type = DBUS_MESSAGE_TYPE_METHOD_CALL;
message.d->service = service;
message.d->path = path;
message.d->interface = interface;
message.d->member = method;
return message;
}
TQT_DBusMessage TQT_DBusMessage::methodReply(const TQT_DBusMessage &other)
{
Q_ASSERT(other.d->msg);
TQT_DBusMessage message;
message.d->type = DBUS_MESSAGE_TYPE_METHOD_RETURN;
message.d->reply = dbus_message_ref(other.d->msg);
return message;
}
TQT_DBusMessage TQT_DBusMessage::methodError(const TQT_DBusMessage &other, const TQT_DBusError& error)
{
Q_ASSERT(other.d->msg);
TQT_DBusMessage message;
if (!error.isValid())
{
qWarning("TQT_DBusMessage: error passed to methodError() is not valid!");
return message;
}
message.d->type = DBUS_MESSAGE_TYPE_ERROR;
message.d->reply = dbus_message_ref(other.d->msg);
message.d->error = error;
return message;
}
TQT_DBusMessage::TQT_DBusMessage()
{
d = new TQT_DBusMessagePrivate(this);
}
TQT_DBusMessage::TQT_DBusMessage(const TQT_DBusMessage &other)
: TQValueList<TQT_DBusData>(other)
{
d = other.d;
d->ref.ref();
}
TQT_DBusMessage::~TQT_DBusMessage()
{
if (!d->ref.deref())
delete d;
}
TQT_DBusMessage &TQT_DBusMessage::operator=(const TQT_DBusMessage &other)
{
TQValueList<TQT_DBusData>::operator=(other);
// FIXME-QT4 qAtomicAssign(d, other.d);
if (other.d) other.d->ref.ref();
TQT_DBusMessagePrivate* old = d;
d = other.d;
if (old && !old->ref.deref())
delete old;
return *this;
}
DBusMessage *TQT_DBusMessage::toDBusMessage() const
{
DBusMessage *msg = 0;
switch (d->type) {
case DBUS_MESSAGE_TYPE_METHOD_CALL:
msg = dbus_message_new_method_call(d->service.utf8().data(),
d->path.utf8().data(), d->interface.utf8().data(),
d->member.utf8().data());
break;
case DBUS_MESSAGE_TYPE_SIGNAL:
msg = dbus_message_new_signal(d->path.utf8().data(),
d->interface.utf8().data(), d->member.utf8().data());
break;
case DBUS_MESSAGE_TYPE_METHOD_RETURN:
msg = dbus_message_new_method_return(d->reply);
break;
case DBUS_MESSAGE_TYPE_ERROR:
msg = dbus_message_new_error(d->reply, d->error.name().utf8().data(),
d->error.message().utf8().data());
break;
}
if (!msg)
return 0;
TQT_DBusMarshall::listToMessage(*this, msg);
return msg;
}
TQT_DBusMessage TQT_DBusMessage::fromDBusMessage(DBusMessage *dmsg)
{
TQT_DBusMessage message;
if (!dmsg)
return message;
message.d->type = dbus_message_get_type(dmsg);
message.d->path = TQString::fromUtf8(dbus_message_get_path(dmsg));
message.d->interface = TQString::fromUtf8(dbus_message_get_interface(dmsg));
message.d->member = TQString::fromUtf8(dbus_message_get_member(dmsg));
message.d->sender = TQString::fromUtf8(dbus_message_get_sender(dmsg));
message.d->msg = dbus_message_ref(dmsg);
DBusError dbusError;
dbus_error_init(&dbusError);
if (dbus_set_error_from_message(&dbusError, dmsg))
{
message.d->error = TQT_DBusError(&dbusError);
}
TQT_DBusMarshall::messageToList(message, dmsg);
return message;
}
TQString TQT_DBusMessage::path() const
{
return d->path;
}
TQString TQT_DBusMessage::interface() const
{
return d->interface;
}
TQString TQT_DBusMessage::member() const
{
return d->member;
}
TQString TQT_DBusMessage::sender() const
{
return d->sender;
}
TQT_DBusError TQT_DBusMessage::error() const
{
return d->error;
}
int TQT_DBusMessage::timeout() const
{
return d->timeout;
}
void TQT_DBusMessage::setTimeout(int ms)
{
d->timeout = ms;
}
/*!
Returns the unique serial number assigned to this message
or 0 if the message was not sent yet.
*/
int TQT_DBusMessage::serialNumber() const
{
if (!d->msg)
return 0;
return dbus_message_get_serial(d->msg);
}
/*!
Returns the unique serial number assigned to the message
that triggered this reply message.
If this message is not a reply to another message, 0
is returned.
*/
int TQT_DBusMessage::replySerialNumber() const
{
if (!d->msg)
return 0;
return dbus_message_get_reply_serial(d->msg);
}
TQT_DBusMessage::MessageType TQT_DBusMessage::type() const
{
switch (d->type) {
case DBUS_MESSAGE_TYPE_METHOD_CALL:
return MethodCallMessage;
case DBUS_MESSAGE_TYPE_METHOD_RETURN:
return ReplyMessage;
case DBUS_MESSAGE_TYPE_ERROR:
return ErrorMessage;
case DBUS_MESSAGE_TYPE_SIGNAL:
return SignalMessage;
default:
return InvalidMessage;
}
}

@ -0,0 +1,514 @@
/* qdbusmessage.h TQT_DBusMessage object
*
* Copyright (C) 2005 Harald Fernengel <harry@kdevelop.org>
* Copyright (C) 2005-2007 Kevin Krammer <kevin.krammer@gmx.at>
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*/
#ifndef TQDBUSMESSAGE_H
#define TQDBUSMESSAGE_H
#include "tqdbusmacros.h"
#include "tqdbusdata.h"
#include <tqvaluelist.h>
#include <limits.h>
class TQT_DBusError;
class TQT_DBusMessagePrivate;
struct DBusMessage;
/**
* @brief A message converts and transports data over D-Bus
*
* A TQT_DBusMessage is implicitly shared, similar to a TQString, i.e. copying
* a message creates just a shallow copy.
*
* The TQT_DBusMessage is the TQt3 bindings means of encapsulating data for a
* method call, a method reply or an error.
*
* Data specifying the sender and receipient is directly accessible through
* getter methods, while data, e.g. method parameters or return values, are
* managed as a list of TQT_DBusData.
*
* To create a message suitable for sending use one of the static factory
* methods:
* - signal() for creating a D-Bus signal message
*
* - methodCall() for creating a D-Bus method calls to a service object
*
* - methodReply() for creating a method reply on success
*
* - methodError() for creating a method reply on error
*
* @note for applications that just want to perform method calls and/or receive
* signals, it is usually more convenient to use TQT_DBusProxy instead.
*
* Message sending is achieved through TQT_DBusConnection
*
* Example:
* @code
* TQT_DBusConnection con = TQT_DBusConnection::sessionBus();
*
* // receipient service is the bus' main interface
*
* TQString service = "org.freedesktop.DBus";
* TQString path = "/org/freedesktop/DBus";
* TQString interface = "org.freedesktop.DBus";
*
* TQT_DBusMessage msg = TQBusMessage::methodCall(service, path, interface, "ListNames");
*
* TQT_DBusMessage reply = con.sendWithReply(msg);
*
* // awaiting for a message list
*
* if (reply.type() != TQT_DBusMessage::ReplyMessage || reply.count() != 2 ||
* reply[0].type() != TQT_DBusData::List)
* {
* // error handling here
* }
* else
* {
* TQStringList list = reply[0].toTQStringList();
*
* // reply handling here
* }
* @endcode
*
* A service returning such a reply would do something like this
* @code
* bool Service::handleMethodCall(const TQT_DBusMessage& call)
* {
* // checks for correctness, i.e. correct interface, member,
* // would usually haven been placed here
*
* TQStringList result;
* result << "Foo" << "Bar";
*
* TQT_DBusMessage reply = TQT_DBusMessage::methodReply(call);
* reply << TQT_DBusData::fromList(result);
*
* connection.send(reply);
*
* return true;
* }
* @endcode
*/
class TQDBUS_EXPORT TQT_DBusMessage: public TQValueList<TQT_DBusData>
{
friend class TQT_DBusConnection;
public:
/**
* @brief Anonymous enum for timeout constants
*
* @see timeout()
* @see setTimeout()
*/
enum
{
/**
* Use whatever D-Bus has as default timeout
*/
DefaultTimeout = -1,
/**
* Use no timeout at all, i.e. wait as long as necessary
*/
NoTimeout = INT_MAX
};
/**
* @brief D-Bus message types
*
* A message of a specific type can be created using the respective factory
* method. A message created by the default constructor becomes an
* InvalidMessage
*
* @see type()
* @see signal()
* @see methodCall()
* @see methodReply()
* @see methodError()
*/
enum MessageType
{
/**
* An invalid message cannot be sent over D-Bus. This type serves for
* initializing message variables without requiring a "real" message
*/
InvalidMessage,
/**
* A message for doing method calls on remote service objects
*
* @see methodCall()
*/
MethodCallMessage,
/**
* A message for replying to a method call in case of success
*
* @see methodReply()
*/
ReplyMessage,
/**
* A message for replying to a method call in case of failure
*
* @see methodError()
*/
ErrorMessage,
/**
* A message for emitting D-Bus signals
*
* @see signal()
*/
SignalMessage
};
/**
* @brief Creates an empty and invalid message
*
* To create a message suitable for sending through D-Bus see the factory
* methods signal(), methodCall(), methodReply() and methodError()
*
* @see #InvalidMessage
*/
TQT_DBusMessage();
/**
* @brief Creates a shallow copy of the given message
*
* This instance will become a handle to the same message data the other
* message is using, including #MessageType
*
* @param other the message to copy
*/
TQT_DBusMessage(const TQT_DBusMessage &other);
/**
* @brief Destroys a message
*
* If this message handle is the last one using this respective message
* content, the message content will be deleted as well
*/
~TQT_DBusMessage();
/**
* @brief Creates a shallow copy of the given message
*
* This instance will become a handle to the same message data the other
* message is usingm including #MessageType
*
* Any content used in this instance will be deleted if this instance was
* the last handle using that content
*
* @param other the message to copy
*
* @return a reference to this instance as required by assignment operator
* semantics
*/
TQT_DBusMessage &operator=(const TQT_DBusMessage &other);
/**
* @brief Creates a message for sending a D-Bus signal
*
* Sending/emitting a signal over D-Bus requires a message of type
* #SignalMessage as well as the information where it is coming from, i.e.
* which interface of which object is sending it.
* See @ref dbusconventions for recommendations on those parameters.
*
* @param path the object path of the service object
* @param interface the object's interface to which the signal belongs
* @param member the signal's name
*
* @return a message suitable for appending arguments and for sending
*
* @see TQT_DBusConnection::send()
*/
static TQT_DBusMessage signal(const TQString &path, const TQString &interface,
const TQString &member);
/**
* @brief Creates a message for sending a D-Bus method call
*
* Invoking a method over D-Bus requires a message of type
* #MethodCallMessage as well as the information where it should be sent
* to, e.g which interface of which object in which service.
* See @ref dbusconventions for recommendations on those parameters.
*
* @param service the D-Bus name of the application hosting the service
* object
* @param path the object path of the service object
* @param interface the object's interface to which the method belongs
* @param method the method's name
*
* @return a message suitable for appending arguments and for sending
*
* @see methodReply()
* @see methodError()
* @see TQT_DBusConnection::send()
*/
static TQT_DBusMessage methodCall(const TQString &service, const TQString &path,
const TQString &interface, const TQString &method);
/**
* @brief Creates a message for replying to a D-Bus method call
*
* Replying to a D-Bus method call in the case of success requires a message
* of type #ReplyMessage as well as the information to which method call it
* is replying to.
*
* @param other the method call message it is replying to
*
* @return a message suitable for appending arguments and for sending
*
* @see methodCall()
* @see methodError()
* @see TQT_DBusConnection::send()
*/
static TQT_DBusMessage methodReply(const TQT_DBusMessage &other);
/**
* @brief Creates a message for replying to a D-Bus method call
*
* Replying to a D-Bus method call in the case of failure requires a message
* of type #ErrorMessage as well as the information to which method call it
* is replying to and which error occured.
*
* @param other the method call message it is replying to
* @param error the error which occured during during the method call
*
* @return a message suitable for appending arguments and for sending
*
* @see methodCall()
* @see methodReply()
* @see TQT_DBusConnection::send()
*/
static TQT_DBusMessage methodError(const TQT_DBusMessage &other, const TQT_DBusError& error);
/**
* @brief Returns the message's object path
*
* See section @ref dbusconventions-objectpath for details.
*
* The context of the object path depends on the message type:
* - #SignalMessage: the path of the service object which emits the signal
* - #MethodCallMessage: the path of the service object the call is sent to
* - #ReplyMessage: the path of the object which is replying
* - #ErrorMessage: the path of the object which is replying
*
* @return a non-empty object path or @c TQString()
*
* @see interface()
* @see member()
* @see sender()
*/
TQString path() const;
/**
* @brief Returns the message's interface name
*
* See section @ref dbusconventions-interfacename for details.
*
* The context of the interface name depends on the message type:
* - #SignalMessage: the name of the interface which emits the signal
* - #MethodCallMessage: the name of the interface the call is sent to
* - #ReplyMessage: the name of the interface to which the method belonged
* - #ErrorMessage: the name of the interface to which the method belonged
*
* @return a non-empty interface name or @c TQString()
*
* @see path()
* @see member()
* @see sender()
*/
TQString interface() const;
/**
* @brief Returns the message's member name
*
* See section @ref dbusconventions-membername for details.
*
* The context of the member name depends on the message type:
* - #SignalMessage: the name of the emitted signal
* - #MethodCallMessage: the name of the method to call
* - #ReplyMessage: the name of the method which replies
* - #ErrorMessage: the name of the method which replies
*
* @return a non-empty member name or @c TQString()
*
* @see path()
* @see interface()
* @see sender()
*/
TQString member() const;
/**
* @brief Returns the name of the message sender
*
* The message sender name or address used on the D-Bus message bus
* to refer to the application which sent this message.
*
* See section @ref dbusconventions-servicename for details.
*
* This can either be a unique name as handed out by the bus, see
* TQT_DBusConnection::uniqueName() or a name registered with
* TQT_DBusConnection::requestName()
*
* @return a non-empty D-Bus sender name or @c TQString()
*
* @see path()
* @see interface()
* @see member()
*/
TQString sender() const;
/**
* @brief Returns the error of an error message
*
* If this message is of type #ErrorMessage, this method can be used
* to retrieve the respective error object
*
* @return the transported error object. Will be empty if this is not an
* error message
*
* @see type()
*/
TQT_DBusError error() const;
/**
* @brief Returns which kind of message this is
*
* @return the message's type
*/
MessageType type() const;
/**
* @brief Returns the message's timeout
*
* @return the asynchronous wait timeout in milliseconds
*
* @see setTimeout()
*/
int timeout() const;
/**
* @brief Sets the message's timeout
*
* The timeout is the number of milliseconds the D-Bus connection will
* wait for the reply of an asynchronous call.
*
* If no reply is received in time, an error message will be delivered to
* the asynchronous reply receiver.
*
* If no timeout is set explicitly, #DefaultTimeout is assumed, which is
* usually the best option
*
* @return the asynchronous wait timeout in milliseconds
*
* @param ms timeout in milliseconds
*
* @see timeout()
* @see #DefaultTimeout
* @see #NoTimeout
*/
void setTimeout(int ms);
/**
* @brief Returns the message's serial number
*
* The serial number is some kind of short term identifier for messages
* travelling the same connection.
*
* It can be used to associate a reply or error message with a method
* call message.
*
* @return the message's serial number or @c 0 if the message hasn't been
* send yets
*
* @see replySerialNumber()
*/
int serialNumber() const;
/**
* @brief Returns the message's reply serial number
*
* The reply serial number is the serial number of the method call message
* this message is a reply to.
*
* If this is neither a message of type #ReplyMessage or #ErrorMessage, the
* returned value will be @c 0
*
* It can be used to associate a reply or error message with a method
* call message.
*
* @return the serial number of the associated method call message or @c 0
* if this message is not a reply message
*
* @see serialNumber()
* @see methodReply()
* @see methodError()
* @see TQT_DBusConnection::sendWithAsyncReply()
* @see TQT_DBusProxy::sendWithAsyncReply()
*/
int replySerialNumber() const;
//protected:
/**
* @brief Creates a raw D-Bus message from this TQt3-bindings message
*
* Marshalls data contained in the message's value list into D-Bus data
* format and creates a low level API D-Bus message for it.
*
* @note ownership of the returned message is transferred to the caller,
* i.e. it has to be deleted using dbus_message_unref()
*
* @return a C API D-Bus message or @c 0 if this is an #InvalidMessage
* or marshalling failed
*/
DBusMessage *toDBusMessage() const;
/**
* @brief Creates a TQt3-bindings message from the given raw D-Bus message
*
* De-marshalls data contained in the message to a list of TQT_DBusData.
*
* @note ownership of the given message is shared between the caller and
* the returned message, i.e. the message as increased the reference
* counter and will still have access to the raw message even if the
* caller "deleted" it using dbus_message_unref()
*
* @param dmsg a C API D-Bus message
*
* @return a TQt3 bindings message. Can be an #InvalidMessage if the given
* message was @c 0 or if de-marshalling failed
*/
static TQT_DBusMessage fromDBusMessage(DBusMessage *dmsg);
private:
TQT_DBusMessagePrivate *d;
};
#endif

@ -0,0 +1,52 @@
/* qdbusmessage.h TQT_DBusMessage private object
*
* Copyright (C) 2005 Harald Fernengel <harry@kdevelop.org>
* Copyright (C) 2005 Kevin Krammer <kevin.krammer@gmx.at>
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*/
#ifndef TQDBUSMESSAGE_P_H
#define TQDBUSMESSAGE_P_H
#include <tqstring.h>
#include "tqdbusatomic.h"
#include "tqdbuserror.h"
struct DBusMessage;
class TQT_DBusMessagePrivate
{
public:
TQT_DBusMessagePrivate(TQT_DBusMessage *qq);
~TQT_DBusMessagePrivate();
TQString path, interface, member, service, sender;
TQT_DBusError error;
DBusMessage *msg;
DBusMessage *reply;
TQT_DBusMessage *q;
int type;
int timeout;
// FIXME-QT4 TQAtomic ref;
Atomic ref;
};
#endif

@ -0,0 +1,372 @@
/* qdbusobject.h DBUS service object interface
*
* Copyright (C) 2005-2007 Kevin Krammer <kevin.krammer@gmx.at>
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*/
#ifndef TQDBUSOBJECT_H
#define TQDBUSOBJECT_H
/**
* @page dbusservice Providing services over D-Bus
*
* Contents:
* - @ref dbusservice-introduction
* - @ref dbusservice-example
* - @ref dbusservice-requestname
* - @ref dbusservice-registerobjects
* - @ref dbusservice-interfaces
*
* @section dbusservice-introduction Introduction
*
* The TQt3 bindings do not support autogeneration of service objects yet. In
* order to provide interfaces over D-Bus, an application has to implement the
* TQT_DBusObjectBase interface and register an instance of the resulting class
* with the TQT_DBusConnection.
*
* @section dbusservice-example A simple D-Bus client example
*
* @code
* #include <dbus/tqdbusconnection.h>;
* #include <dbus/tqdbusobject.h>;
*
* class TQStringList;
*
* class TestService : public TQT_DBusObjectBase
* {
* public:
* TestService(const TQT_DBusConnection& connection);
* virtual ~TestService();
*
* protected:
* virtual bool handleMethodCall(const TQT_DBusMessage& message);
*
* private:
* TQT_DBusConnection m_connection;
*
* private:
* TQStringList sortStrings(const TQStringList& list);
* };
* @endcode
* @code
*
* #include <tqstringlist.h>;
*
* #include <dbus/tqdbuserror.h>;
* #include <dbus/tqdbusmessage.h>;
*
* TestService::TestService(const TQT_DBusConnection& connection) : m_connection(connection)
* {
* m_connection.registerObject("/ListSorter", this);
* }
*
* TestService::~TestService()
* {
* m_connection.unregisterObject("/ListSorter");
* }
*
* // return false to let D-Bus send a standard error message that the method is unknown
*
* bool TestService::handleMethod(const TQT_DBusMessage& message)
* {
* if (message.interface() != "org.example.Sort") return false;
*
* if (message.member() == "Strings")
* {
* // check parameters
*
* if (message.count() != 1 || message[0].type() != TQT_DBusData::List)
* {
* // method signature not what we expected
*
* TQT_DBusError error = TQT_DBusError::stdInvalidArgs(
* "Expected one argument of type array of string");
*
* TQT_DBusMessage reply = TQT_DBusMessage::methodError(message, error);
*
* // send error
*
* m_connection.send(reply);
*
* // tell D-Bus we did handle the call
*
* return true;
* }
*
* // call implementation
*
* TQStringList result = sortStrings(message[0].toTQStringList());
*
* // prepare reply
*
* TQT_DBusMessage reply = TQT_DBusMessage::methodReply(message);
*
* reply << TQT_DBusData::fromList(result);
*
* // send reply
*
* m_connection.send(reply);
*
* // tell D-Bus we did handle the call
*
* return true;
* }
*
* return false;
* }
*
* TQStringList TestService::sortStrings(const TQStringList& list)
* {
* TQStringList result = list;
*
* result.sort();
*
* return result;
* }
* @endcode
* @code
* int main(int argc, char** argv)
* {
* TQApplication app(argc, argv, false);
*
* TQT_DBusConnection connection = TQT_DBusConnection::sessionBus();
* if (!connection.isConnected())
* qFatal("Cannot connect to session bus");
*
* // try to get a specific service name
* if (!connection.requestName("org.example.SortService"))
* {
* qWarning("Requesting name 'org.example.SortService' failed. "
* "Will only be addressable through unique name '%s'",
* connection.uniqueName().local8Bit().data());
* }
* else
* {
* qDebug("Requesting name 'org.example.SortService' successfull");
* }
*
* TestService service(connection);
*
* return app.exec();
* }
* @endcode
*
* @section dbusservice-requestname Requesting service name
*
* When an application connects to D-Bus it gets a unique name generated by
* the bus daemon.
*
* However, an application providing service will often want to be reachable
* under a fixed name, like a webserver being reachable through a domain name
* independent from its actual IP address.
* See section @ref dbusconventions-servicename for details on service names.
*
* In order to get such a specific name an application has to request it
* using TQT_DBusConnection::requestName()
*
* The example above request @c "org.example.SortService" but continues with
* the default unique name in the case some other application is currently
* owning that name.
*
* @section dbusservice-registerobjects Registering objects
*
* To make service objects available to other applications on the same
* bus the application has to register the objects instances with the
* connection to the bus using TQT_DBusConnection::registerObject()
*
* Registering means to specify an object path where the object will be
* located, i.e. how it can be unambiguously be addressed in method calls.
* See section @ref dbusconventions-objectpath for details on object paths.
*
* If the applications has introspectable objects it is recommended to
* register an introspectable root object, i.e. using @c "/" as the path, so
* other applications have a common place to start asking for introspection
* data.
*
* In the example above a service object providing sorting services on lists is
* registered on the path @c "/ListSorter"
*
* @section dbusservice-interfaces Service interfaces
*
* D-Bus methods and signals of a service object a grouped into interfaces.
*
* See section @ref dbusconventions-interfacename for details on interface
* naming.
*
* An object can implement any number of interfaces, for example the interface
* for the functionality it wants to provide and a D-Bus standard interface like
* @c "org.freedesktop.DBus.Introspectable" for providing an XML description of
* all its interfaces.
*
*
* The service object of the example above implements just one interface
* @c "org.example.Sort" and its handleMethodCall() explicitly checks all
* received messages and rejects any messsage not sent to this particular
* interface by returning @c false and thus telling the D-Bus layer to
* generate a standard error response.
*
* Multiple interfaces can of course be directly implemented in one C++ class,
* however it might sometimes be wise to delegate calls for different
* interfaces to different implementations:
* @code
* class Interface1 : public TQT_DBusObjectBase
* {
* public:
* Interface1(const TQT_DBusConnection&);
*
* protected:
* virtual bool handleMethodCall(const TQT_DBusMessage&);
* };
*
* class Interface2 : public TQT_DBusObjectBase
* {
* public:
* Interface2(const TQT_DBusConnection&);
*
* protected:
* virtual bool handleMethodCall(const TQT_DBusMessage&);
* };
*
* class MultiInterfaceService : public TQT_DBusObjectBase
* {
* public:
* MultiInterfaceService(const TQT_DBusConnection&);
*
* protected:
* virtual bool handleMethodCall(const TQT_DBusMessage&);
*
* private:
* TQMap<TQString, TQT_DBusObjectBase*> m_interfaces;
* };
*
* MultiInterfaceService::MultiInterfaceService(const TQT_DBusConnection& connection)
* {
* m_interfaces.insert("org.example.Interface1", new Interface1(connection));
* m_interfaces.insert("org.example.Interface2", new Interface2(connection));
* }
*
* bool MultiInterfaceService::handleMethodCall(const TQT_DBusMessage& message)
* {
* // delegate call to its interface handler
* TQT_DBusObjectBase* handler = m_interfaces[message.interface()];
* if (handler != 0)
* return delegateMethodCall->(message, handler);
* else
* return false; // no such interface
* }
* @endcode
*/
/**
* @include example-service.h
* @example example-service.cpp
*/
#include "tqdbusmacros.h"
class TQT_DBusMessage;
/**
* @brief Base interface for D-Bus service objects
*
* In order to register a service object with the TQT_DBusConnection it needs to
* implement the interface specified by this class.
*
* The connection will forward all method calls that have a path equivalent
* to the path the service object was registered with to the object's
* handleMethodCall() method. See TQT_DBusConnection::registerObject()
*
* If for some reason, e.g. the call is not meant for this interface, or the
* method is unknown, the implementation can just return @c false and the
* connection will handle the rest.
*
* See section @ref dbusservice for documentation on how to use TQT_DBusObjectBase
*/
class TQDBUS_EXPORT TQT_DBusObjectBase
{
friend class TQT_DBusConnectionPrivate;
public:
/**
* @brief Destroys the object
*/
virtual ~TQT_DBusObjectBase() {}
protected:
/**
* @brief Method call entry point
*
* This method has to be implemented to handle method calls sent to the
* service object.
* An object implementation can handle all its interfaces in one class or
* again forward the method call to interface implementators.
*
* If for some reason, e.g. the call is not meant for this interface, or
* the method is unknown, the implementation can just return @c false and
* the connection will handle the rest.
*
* If an error occurs during the method call, e.g. the number of parameters
* or their types are not what would be expected, the service object
* should reply with a TQT_DBusMessage of type TQT_DBusMessage::ErrorMessage
* which in turn should include the D-Bus error describing the problem.
* See TQT_DBusConnection::send() for sending reply messages.
*
* See TQT_DBusMessage::methodError() and TQT_DBusMessage::methodReply() on
* how to create suitable reply messages for the given method call.
*
* @param message the method call to handle
*
* @return @c true if the message can be handled independent if handling
* resulted in an error. In this case implementations should an
* error reply. Returns @c false only if interface or method are
* unknown
*/
virtual bool handleMethodCall(const TQT_DBusMessage& message) = 0;
/**
* @brief Delegate a method call to another object
*
* When a service object is built as a collection of separated interface
* class instances, i.e. each interface of the object is implemented in
* its own TQT_DBusObjectBase subclass and the main object just wanst to pass
* on the method calls to the respective interface implementations, it
* can do so by calling this base class method.
*
* Since it is a method of the base class, it can call the otherwise
* protected handleMethodCall() of the interface implementor.
*
* See @ref dbusservice-interfaces for an example.
*
* @param message the method call to delegate
* @param delegate the object which should handle the call instead
*
* @return @c true if the message can be handled independent if handling
* resulted in an error. In this case implementations should an
* error reply. Returns @c false only if interface or method are
* unknown
*
*/
bool delegateMethodCall(const TQT_DBusMessage& message, TQT_DBusObjectBase* delegate)
{
return delegate->handleMethodCall(message);
}
};
#endif

@ -0,0 +1,79 @@
/* qdbusobjectpath.cpp DBUS object path data type
*
* Copyright (C) 2007 Kevin Krammer <kevin.krammer@gmx.at>
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*/
#include "tqdbusobjectpath.h"
TQT_DBusObjectPath::TQT_DBusObjectPath() : TQCString()
{
}
TQT_DBusObjectPath::TQT_DBusObjectPath(const TQT_DBusObjectPath& other) : TQCString(static_cast<const TQCString&>(other))
{
}
TQT_DBusObjectPath::TQT_DBusObjectPath(const TQCString& other) : TQCString(static_cast<const TQCString&>(other))
{
}
TQT_DBusObjectPath::TQT_DBusObjectPath(const TQT_DBusObjectPath& tqparentNode,
const TQCString& nodeName)
: TQCString(static_cast<const TQCString&>(tqparentNode))
{
if (tqparentNode.length() != 1) append("/");
append(nodeName);
}
bool TQT_DBusObjectPath::isValid() const
{
return (validate(*this) == -1);
}
TQT_DBusObjectPath TQT_DBusObjectPath::tqparentNode() const
{
if (length() == 1) return TQT_DBusObjectPath();
int index = tqfindRev('/');
if (index == -1) return TQT_DBusObjectPath();
if (index == 0) return left(1);
return left(index);
}
int TQT_DBusObjectPath::validate(const TQCString& path)
{
if (path.isEmpty()) return 0;
if (path[0] != '/') return 0;
// TODO add additional checks
uint len = path.length();
// only root node allowed to end in slash
if (path[len - 1] == '/' && len > 1) return (len - 1);
return -1;
}

@ -0,0 +1,118 @@
/* qdbusobjectpath.h DBUS object path data type
*
* Copyright (C) 2007 Kevin Krammer <kevin.krammer@gmx.at>
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*/
#ifndef TQDBUSOBJECTPATH_H
#define TQDBUSOBJECTPATH_H
#include <tqcstring.h>
/**
* @brief Class for representing D-Bus object paths
*
* This data type is necessary to correctly represent object paths in the
* context of D-Bus messages, since normal strings have a different D-Bus
* signature than object paths.
*
* @see @ref dbusconventions-objectpath
*/
class TQT_DBusObjectPath : public TQCString
{
public:
/**
* @brief Creates an empty and invalid object path
*/
TQT_DBusObjectPath();
/**
* @brief Creates copy of the given @p other object path
*
* @param other the object path to copy
*/
TQT_DBusObjectPath(const TQT_DBusObjectPath& other);
/**
* @brief Creates copy of the given @p other object path
*
* @param other the object path to copy
*/
TQT_DBusObjectPath(const TQCString& other);
/**
* @brief Creates an object path for an object as a child of the tqparent node
*
* This is basically like specifying a directory and a file name to create
* the file's full path.
*
* Example:
* @code
* TQT_DBusObjectPath rootNode("/"); // => "/"
*
* TQT_DBusObjectPath childNod(rootNode, "child"); // => "/child"
*
* TQT_DBusObjectPath grandChildNode(childNode, "grandchild"); // => "/child/grandchild"
* @endcode
*
* @param tqparentNode the object path to create the child on
* @param nodeName the name of the child node
*/
TQT_DBusObjectPath(const TQT_DBusObjectPath& tqparentNode, const TQCString& nodeName);
/**
* @brief Returns whether the current content is considered a valid object path
*
* @note Calls validate() to perform a check on the current content
*
* @return \c true if the object's content describe a valid object path,
* otherwise @c false
*
* @see @ref dbusconventions-objectpath
*/
bool isValid() const;
/**
* @brief Returns the object path of this path's tqparent node
*
* This is basically like getting the directory of an file path
*
* @return the tqparent node's object path or an empty and invalid object
* if this is already the root node
*/
TQT_DBusObjectPath tqparentNode() const;
/**
* @brief Checks the given string for validity as a D-Bus object path
*
* See section @ref dbusconventions-objectpath for information on object
* path formatting.
*
* @param path the string to check
*
* @return @c -1 if the object path is valid, otherwise the index of the
* first violating character
*
* @see isValid()
*/
static int validate(const TQCString& path);
};
#endif

@ -0,0 +1,209 @@
/* qdbusproxy.cpp DBUS Object proxy
*
* Copyright (C) 2005 Kevin Krammer <kevin.krammer@gmx.at>
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*/
#include "tqdbuserror.h"
#include "tqdbusconnection.h"
#include "tqdbusmessage.h"
#include "tqdbusproxy.h"
class TQT_DBusProxy::Private
{
public:
Private() : canSend(false) {}
~Private() {}
void checkCanSend()
{
canSend = !path.isEmpty() && !service.isEmpty() && !interface.isEmpty();
}
public:
TQT_DBusConnection connection;
TQString service;
TQString path;
TQString interface;
bool canSend;
TQT_DBusError error;
};
TQT_DBusProxy::TQT_DBusProxy(TQObject* tqparent, const char* name)
: TQObject(tqparent, (name ? name : "TQT_DBusProxy")),
d(new Private())
{
}
TQT_DBusProxy::TQT_DBusProxy(const TQT_DBusConnection& connection,
TQObject* tqparent, const char* name)
: TQObject(tqparent, (name ? name : "TQT_DBusProxy")),
d(new Private())
{
setConnection(connection);
}
TQT_DBusProxy::TQT_DBusProxy(const TQString& service, const TQString& path,
const TQString& interface, const TQT_DBusConnection& connection,
TQObject* tqparent, const char* name)
: TQObject(tqparent, (name ? name : "TQT_DBusProxy")),
d(new Private())
{
setConnection(connection);
d->service = service;
d->path = path;
d->interface = interface;
d->checkCanSend();
}
TQT_DBusProxy::~TQT_DBusProxy()
{
delete d;
}
bool TQT_DBusProxy::setConnection(const TQT_DBusConnection& connection)
{
d->connection.disconnect(this, TQT_SLOT(handleDBusSignal(const TQT_DBusMessage&)));
d->connection = connection;
return d->connection.connect(this, TQT_SLOT(handleDBusSignal(const TQT_DBusMessage&)));
}
const TQT_DBusConnection& TQT_DBusProxy::connection() const
{
return d->connection;
}
void TQT_DBusProxy::setService(const TQString& service)
{
d->service = service;
d->checkCanSend();
}
TQString TQT_DBusProxy::service() const
{
return d->service;
}
void TQT_DBusProxy::setPath(const TQString& path)
{
d->path = path;
d->checkCanSend();
}
TQString TQT_DBusProxy::path() const
{
return d->path;
}
void TQT_DBusProxy::setInterface(const TQString& interface)
{
d->interface = interface;
d->checkCanSend();
}
TQString TQT_DBusProxy::interface() const
{
return d->interface;
}
bool TQT_DBusProxy::canSend() const
{
return d->canSend && d->connection.isConnected();
}
bool TQT_DBusProxy::send(const TQString& method, const TQValueList<TQT_DBusData>& params) const
{
if (!d->canSend || method.isEmpty() || !d->connection.isConnected())
return false;
TQT_DBusMessage message = TQT_DBusMessage::methodCall(d->service, d->path,
d->interface, method);
message += params;
return d->connection.send(message);
}
TQT_DBusMessage TQT_DBusProxy::sendWithReply(const TQString& method,
const TQValueList<TQT_DBusData>& params,
TQT_DBusError* error) const
{
if (!d->canSend || method.isEmpty() || !d->connection.isConnected())
return TQT_DBusMessage();
TQT_DBusMessage message = TQT_DBusMessage::methodCall(d->service, d->path,
d->interface, method);
message += params;
TQT_DBusMessage reply = d->connection.sendWithReply(message, &d->error);
if (error)
*error = d->error;
return reply;
}
int TQT_DBusProxy::sendWithAsyncReply(const TQString& method, const TQValueList<TQT_DBusData>& params)
{
if (!d->canSend || method.isEmpty() || !d->connection.isConnected())
return 0;
TQT_DBusMessage message = TQT_DBusMessage::methodCall(d->service, d->path,
d->interface, method);
message += params;
return d->connection.sendWithAsyncReply(message, this,
TQT_SLOT(handleAsyncReply(const TQT_DBusMessage&)));
}
TQT_DBusError TQT_DBusProxy::lastError() const
{
return d->error;
}
void TQT_DBusProxy::handleDBusSignal(const TQT_DBusMessage& message)
{
if (!d->path.isEmpty() && d->path != message.path())
return;
// only filter by service name if the name is a unique name
// because signals are always coming from a connection's unique name
// and filtering by a generic name would reject all signals
if (d->service.startsWith(":") && d->service != message.sender())
return;
if (!d->interface.isEmpty() && d->interface != message.interface())
return;
emit dbusSignal(message);
}
void TQT_DBusProxy::handleAsyncReply(const TQT_DBusMessage& message)
{
d->error = message.error();
emit asyncReply(message.replySerialNumber(), message);
}
#include "tqdbusproxy.moc"

@ -0,0 +1,584 @@
/* qdbusproxy.h DBUS Object proxy
*
* Copyright (C) 2005-2007 Kevin Krammer <kevin.krammer@gmx.at>
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*/
#ifndef TQDBUSPROXY_H
#define TQDBUSPROXY_H
/**
* @page dbusclient Using D-Bus as a client
*
* Contents:
* - @ref dbusclient-introduction
*
* - @ref dbusclient-example
*
* - @ref dbusclient-initialization
*
* - @ref dbusclient-methodcall
* - @ref dbusclient-synccall
* - @ref dbusclient-asynccall
*
* - @ref dbusclient-signals
* - @ref dbusclient-signals-example
*
* @section dbusclient-introduction Introduction
*
* While it is of course possible to just exchange D-Bus messages with a
* D-Bus service, it is a lot more comfortable to use TQT_DBusProxy.
*
* With TQT_DBusProxy you only need to specify the service object once, i.e.
* its D-Bus name, path and interface, and just provide the method and its
* parameters when initiating an invokation.
*
* Additionally the proxy transforms D-Bus signals from the proxy's peer
* (the D-Bus service object's interface it is associated with) to TQObject
* signal carrying the original signal's content.
*
* @section dbusclient-example A simple D-Bus client example
*
* @code
* #include <dbus/tqdbusconnection.h>
* #include <dbus/tqdbusmessage.h>
* #include <dbus/tqdbusproxy.h>
*
* int main()
* {
* // establish a connection to the session bus
*
* TQT_DBusConnection connection = TQT_DBusConnection::sessionBus();
* if (!connection.isConnected())
* qFatal("Failed to connect to session bus");
*
* // create a proxy object for method calls
*
* TQT_DBusProxy proxy(connection);
* proxy.setService("org.freedesktop.DBus"); // who we work with
* proxy.setPath("/org/freedesktop/DBus"); // which object inside the peer work with
* proxy.setInterface("org.freedesktop.DBus"); // which of its interfaces we will use
*
* // call the "ListNames" method. It returns an array of string, in TQt3 terms
* // a TQStringList, it expects no parameters
*
* TQValueList<TQT_DBusData> params;
* TQT_DBusMessage reply = proxy.sendWithReply("ListNames", params);
*
* if (reply.type() != TQT_DBusMessage::ReplyMessage)
* qFatal("Call failed");
*
* if (reply.count() != 1 || reply[0].type() != TQT_DBusData::List)
* qFatal("Unexpected reply");
*
* bool ok = false;
* TQStringList names = reply[0].toTQStringList(&ok);
*
* if (!ok) qFatal("Unexpected reply");
*
* for (TQStringList::iterator it = names.begin(); it != names.end(); ++it)
* {
* qDebug("%s", (*it).local8Bit().data());
* }
*
* return 0;
* }
* @endcode
*
* @section dbusclient-initialization Program initialization
*
* A connection to the bus is acquired using TQT_DBusConnection::sessionBus()
*
* Next, a proxy is created for the object @c "/org/freedesktop/DBus" with
* interface @c "org.freedesktop.DBus" on the service @c "org.freedesktop.DBus"
*
* This is a proxy for the message bus itself.
*
* @section dbusclient-methodcall Method invocation
*
* There are two choices for method invocation:
* - sychronous (blocking) calls
* - asynchronous (non-blocking) calls
*
* @subsection dbusclient-synccall Synchronous method calls
*
* As seen in the example code above, a synchronous method call can be achieved
* by TQT_DBusProxy::sendWithReply(). It sends a method call to the remote object,
* and blocks until reply is received. The outgoing arguments are specified as
* a list of TQT_DBusData.
*
* @subsection dbusclient-asynccall Asynchronous method calls
*
* To invoke a method asynchronously, connect the proxy's signal
* TQT_DBusProxy::asyncReply(int, const TQT_DBusMessage&) to a suitable slot like
* with any other TQt Signal-Slot connection.
*
* Then call TQT_DBusProxy::sendWithAsyncReply()
* It returns a numerical identifier of the call, so it can be related in the
* slot once the result is available.
*
* The slot's first argument is the reveived reply's call identifier as
* returned by the method call. The second parameter is the reply message
* similar to the one in the synchronous call.
*
* @note For asynchronous calls you'll need a running event loop, i.e. a
* TQApplication object and its exec() having been invoked.
*
* @section dbusclient-signals Connecting to D-Bus signals
*
* To receive D-BUS signals just connect to the TQT_DBusProxy's signal
* TQT_DBusProxy::dbusSignal(const TQT_DBusMessage&)
*
* It will be emitted whenever a D-Bus signal message is received from the peer
* object.
* Filtering of signals is based on the value set for @c service, @c path and
* @c interface
*
* @note Filtering for @c service will only happen if @c service is a unique
* D-Bus name, i.e. if it starts with a colon @c ":" since D-Bus signals
* carry the sender's unique name and filtering by a requested name
* would reject all signals
*
* Usually a proxy will be also be used to send to the peer object, thus having
* them all set. However if a proxy is only needed for signals, any of the
* three properties can be omitted (e.g. set to @c TQString() ), in which
* case only the available properties will be checked against the respective
* message field when deciding about dropping or emitting the message.
* See TQT_DBusProxy::handleDBusSignal()
*
* If you want all signal travelling on the bus, or apply filtering for
* different criteria, e.g. get all signals coming from interfaces starting
* with @c "org.", use @c TQT_DBusConnection::connect() instead.
* The signature of the slot stays the same.
*
* @subsection dbusclient-signals-example Signal example
*
* First declare a receiver class:
* @code
* class MyReceiver : public TQObject
* {
* TQ_OBJECT
* public slots:
* void handleDBusSignal(const TQT_DBusMessage&);
* };
* @endcode
* Then somewhere else in a source file:
* @code
* TQT_DBusConnection connection = TQT_DBusConnection::sessionBus();
*
* MyReceiver* receiver1 = new MyReceiver();
*
* connection.connect(receiver1, TQT_SLOT(handleDBusSignal(const TQT_DBusMessage&)));
* @endcode
* @c receiver1 will get all signals on this connection
*
* @code
* TQT_DBusProxy* proxy = new TQT_DBusProxy(connection);
* proxy->setService("org.freedesktop.DBus"); // who we work with
* proxy->setPath("/org/freedesktop/DBus"); // which object inside the peer work with
* proxy->setInterface("org.freedesktop.DBus"); // which of its interfaces we will use
*
* MyReceiver* receiver2 = new MyReceiver();
*
* TQObject::connect(proxy, TQT_SIGNAL(dbusSignal(const TQT_DBusMessage&)),
* receiver2, TQT_SLOT(handleDBusSignal(const TQT_DBusMessage&)));
* @endcode
* @c receiver2 will only get signals coming from the proxy's peer interface
*/
/**
* @include example-client.h
* @example example-client.cpp
*/
#include <tqobject.h>
#include "tqdbusmacros.h"
class TQT_DBusConnection;
class TQT_DBusData;
class TQT_DBusError;
class TQT_DBusMessage;
template <class T> class TQValueList;
/**
* @brief Client interface to a remote service object
*
* TQT_DBusProxy provides a convenience interface for working with D-Bus services,
* or more precisely, interfaces of D-Bus service objects.
*
* A D-Bus service object is identified through the name of its host application
* on the bus and its path (logical location) within the host application.
* Such a service object can implement any number of interfaces, i.e. groups
* methods and signals, and can create a TQT_DBusProxy instance for every one
* your application needs to work with.
*
* See section @ref dbusclient for documentation on how to use TQT_DBusProxy
*/
class TQDBUS_EXPORT TQT_DBusProxy : public TQObject
{
Q_OBJECT
TQ_OBJECT
public:
/**
* @brief Creates a proxy without binding it to a service or connection
*
* This basic constructor allows to create a proxy and specify the peer
* object and interface later on.
*
* @param tqparent TQObject tqparent
* @param name TQObject name
*/
TQT_DBusProxy(TQObject* tqparent = 0, const char* name = 0);
/**
* @brief Creates a proxy on a given connection without binding it to a
* service
*
* Similar to the above constructor, it does not yet specify and details
* about the proxy's peer, but already specifies which connection to work
* on.
*
* This can be useful to monitor all signal on a connection without
* filtering for a specific peer.
*
* @param connection the D-Bus connection to work on
* @param tqparent TQObject tqparent
* @param name TQObject name
*/
TQT_DBusProxy(const TQT_DBusConnection& connection, TQObject* tqparent = 0,
const char* name = 0);
/**
* @brief Creates a proxy for a given peer on a given connection
*
* This creates a proxy for a specific peer object-interface combination
* It is equvalent to creating an "empty" proxy and calling setConnection(),
* setService(), setPath() and setInterface() manually.
*
* @param service the name the peer's host application uses on the bus
* @param path the peer object's path within its host application
* @param interface the interface to work with
* @param connection the D-Bus connection to work on
* @param tqparent TQObject tqparent
* @param name TQObject name
*/
TQT_DBusProxy(const TQString& service, const TQString& path,
const TQString& interface, const TQT_DBusConnection& connection,
TQObject* tqparent = 0, const char* name = 0);
/**
* @brief Destroys the proxy instance
*/
virtual ~TQT_DBusProxy();
/**
* @brief Sets the D-Bus connection to work on
*
* Disconnects from any previously used connection and connects
* to the new connection's signal distribution.
* If no peer information has been provided at creation time or through
* the other set methods, the instance's signal dbusSignal() will emit
* all signals received on the given connection.
*
* @param connection the D-Bus connection to work on
*
* @return @c true if connecting to the new connection's signal succeeded,
* @c false if it failed, e.g. if the connection is a "null"
* connection
*
* @see connection()
* @see setService()
* @see setPath()
* @see setInterface()
*/
bool setConnection(const TQT_DBusConnection& connection);
/**
* @brief Returns the currently used D-Bus connection
*
* @see setConnection()
*/
const TQT_DBusConnection& connection() const;
/**
* @brief Sets the peer's service name
*
* A non-empty service name is required if the proxy is to be used for
* method calls. See section @ref dbusconventions-servicename for details.
*
* If a string other than @c TQString() is set, it will be used to
* filter signals, i.e. a signal received by the proxy will only be emitted
* if the service name matches.
*
* @param service the peer's name on the bus
*
* @see service()
* @see setPath()
* @see setInterface()
*/
void setService(const TQString& service);
/**
* @brief Returns the peer's service name
*
* @return the peer object's service name
*
* @see setService()
*/
TQString service() const;
/**
* @brief Sets the peer's object path
*
* A non-empty object path is required if the proxy is to be used for
* method calls. See section @ref dbusconventions-objectpath for details.
*
* If a string other than @c TQString() is set, it will be used to
* filter signals, i.e. a signal received by the proxy will only be emitted
* if the object path matches.
*
* @param path the peer's object path inside its host application
* (logical address)
*
* @see path()
* @see setService()
* @see setInterface()
*/
void setPath(const TQString& path);
/**
* @brief Returns the peer's object path
*
* @return the peer object's path
*
* @see setPath()
*/
TQString path() const;
/**
* @brief Sets the name of the peer interface
*
* A non-empty interface name is required if the proxy is to be used for
* method calls. See section @ref dbusconventions-interfacename for
* details.
*
* If a string other than @c TQString() is set, it will be used to
* filter signals, i.e. a signal received by the proxy will only be emitted
* if the interface name matches.
*
* @param interface the peer's interface to work with
*
* @see interface()
* @see setService()
* @see setPath()
*/
void setInterface(const TQString& interface);
/**
* @brief Returns the name of the peer interface
*
* @return the peer object's interface
*
* @see setInterface()
*/
TQString interface() const;
/**
* @brief Returns whether the proxy can be used to send method calls
*
* The capabilitly to send method calls depends on having all necessary
* base information:
* - Service name, see setService()
* - Object path, see setPath()
* - Interface, see setInterface()
*
* and a working connection, see setConnection()
*
* @return @c true if method calls can be sent, @c false if any of the three
* base information is missing or if the connection is not connected
*
* @see send()
* @see sendWithReply()
* @see sendWithAsyncReply()
*/
bool canSend() const;
/**
* @brief Sends a method call to the peer object
*
* This is roughly equivalent to calling a C++ method with no return value
* or like ignoring the it.
*
* @param method the name of the method to invoke
* @param params the method parameters. Use an empty list if the method
* does not require parameters
*
* @return @c true if sending succeeded, @c false if sending failed,
* the method name was empty or any of the conditions for
* successfull sending as described for canSend() are not met
*
* @see lastError()
* @see sendWithReply()
* @see sendWithAsyncReply()
* @see @ref dbusconventions-membername
*/
bool send(const TQString& method, const TQValueList<TQT_DBusData>& params) const;
/**
* @brief Sends a method call to the peer object and waits for the reply
*
* This is roughly equivalent to calling a C++ method on a local object.
*
* @param method the name of the method to invoke
* @param params the method parameters. Use an empty list if the method
* does not require parameters
* @param error optional parameter to get any error directly
*
* @return a TQT_DBusMessage containing any return values of the invoked method.
* Will be an invalid message if an error occurs. The error can be
* accessed through the optional paramater @p error or through
* lastError()
*
* @see canSend()
* @see send()
* @see sendWithAsyncReply()
* @see @ref dbusconventions-membername
*/
TQT_DBusMessage sendWithReply(const TQString& method,
const TQValueList<TQT_DBusData>& params, TQT_DBusError* error = 0) const;
/**
* @brief Sends a method call to the peer object but does not wait for an
* answer
*
* This is roughly equivalent to calling a C++ method on a local TQt
* event loop driven object, where the result of the method call is
* delivered later through a signal.
*
* @note as with TQt's asychronous classes this needs a running event loop
*
* @param method the name of the method to invoke
* @param params the method parameters. Use an empty list if the method
* does not require parameters
*
* @return a serial number to easily identify the reply once it is received
* or 0 if the call is not possible, i.e. the method name is empty
* or any of the conditions for canSend() are not met
*
* @warning if a asynchronous call is followed by a synchronous call, e.g.
* using sendWithReply(), without returning to the event loop,
* is recommended to call TQT_DBusConnection::scheduleDispatch()
* after the synchronous call to make sure any reply received
* during the blocking call is delivered
*
* @see asyncReply()
* @see send()
* @see sendWithReply()
* @see @ref dbusconventions-membername
*/
int sendWithAsyncReply(const TQString& method, const TQValueList<TQT_DBusData>& params);
/**
* @brief Returns the last error seen by the proxy
*
* The last error can a connection error, e.g. sending a message failed due
* connection being lost, or the error of the last call to sendWithReply or
* the error of the last received asyncReply()
*
* @return the last dbus error seen by this proxy
*/
TQT_DBusError lastError() const;
signals:
/**
* @brief Signal emitted for D-Bus signals from the peer
*
* Signals received on the proxy's connection are filtered by
* handleDBusSignal() for all proxy properties that are not empty.
*
* @param message the signal's content
*
* @see TQT_DBusMessage::SignalMessage
*/
void dbusSignal(const TQT_DBusMessage& message);
/**
* @brief Signal emitted for received replies to asynchronous method calls
*
* If a method invoked by using sendWithAsyncReply() send a response, e.g.
* method return value or errors, this signal is emitted to notify the
* proxy's user.
*
* @param callID the method call's serial number as returned by
* sendWithAsyncReply()
* @param message the reply's content
*
* @see handleAsyncReply()
* @see TQT_DBusMessage::replySerialNumber()
*/
void asyncReply(int callID, const TQT_DBusMessage& message);
protected slots:
/**
* @brief Handles D-Bus signals received on the proxy's connection
*
* The base implementation checks each non-empty property, i.e. service
* name, object path and interface, with the respective field of the
* signal's D-Bus message.
*
* If all available matches succeed, the message is emitted by
* dbusSignal(), otherwise it is discarded.
*
* @note Filtering for @c service will only happen if @c service is a
* unique D-Bus name, i.e. if it starts with a colon @c ":" since
* D-Bus signals carry the sender's unique name and filtering by a
* requested name would reject all signals.
*
* @param message the D-Bus signal message as received
*
* @see TQT_DBusMessage::SignalMessage
*/
virtual void handleDBusSignal(const TQT_DBusMessage& message);
/**
* @brief Handles replies to asynchronous method calls
*
* The base implementation simply extracts the reply's error and makes
* it available for lastError(). It then emits asyncReply()
*
* @param message the D-Bus reply message as received
*
* @see TQT_DBusMessage::replySerialNumber()
*/
virtual void handleAsyncReply(const TQT_DBusMessage& message);
private:
class Private;
Private* d;
private:
TQT_DBusProxy(const TQT_DBusProxy&);
TQT_DBusProxy& operator=(const TQT_DBusProxy&);
};
#endif

@ -0,0 +1,60 @@
/* qdbusserver.cpp
*
* Copyright (C) 2005 Harald Fernengel <harry@kdevelop.org>
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*/
#include "tqdbusserver.h"
#include "tqdbusconnection_p.h"
TQT_DBusServer::TQT_DBusServer(const TQString &addr, TQObject *tqparent)
: TQObject(tqparent)
{
d = new TQT_DBusConnectionPrivate(this);
if (addr.isEmpty())
return;
d->setServer(dbus_server_listen(addr.utf8().data(), &d->error));
}
bool TQT_DBusServer::isConnected() const
{
return d->server && dbus_server_get_is_connected(d->server);
}
TQT_DBusError TQT_DBusServer::lastError() const
{
return d->lastError;
}
TQString TQT_DBusServer::address() const
{
TQString addr;
if (d->server) {
char *c = dbus_server_get_address(d->server);
addr = TQString::fromUtf8(c);
dbus_free(c);
}
return addr;
}
#include "tqdbusserver.moc"

@ -0,0 +1,53 @@
/* qdbusserver.h TQT_DBusServer object
*
* Copyright (C) 2005 Harald Fernengel <harry@kdevelop.org>
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*/
#ifndef TQDBUSSERVER_H
#define TQDBUSSERVER_H
#include "tqdbusmacros.h"
#include <tqobject.h>
class TQString;
class TQT_DBusConnectionPrivate;
class TQT_DBusError;
class TQDBUS_EXPORT TQT_DBusServer: public TQObject
{
Q_OBJECT
TQ_OBJECT
public:
TQT_DBusServer(const TQString &address, TQObject *tqparent = 0);
bool isConnected() const;
TQT_DBusError lastError() const;
TQString address() const;
private:
TQT_DBusServer(const TQT_DBusServer&);
TQT_DBusServer& operator=(const TQT_DBusServer&);
TQT_DBusConnectionPrivate *d;
};
#endif

@ -0,0 +1,120 @@
/* qdbusvariant.h DBUS variant struct
*
* Copyright (C) 2005 Harald Fernengel <harry@kdevelop.org>
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*/
#ifndef TQDBUSVARIANT_H
#define TQDBUSVARIANT_H
#include "tqdbusmacros.h"
#include "tqdbusdata.h"
#include <tqstring.h>
/**
* @brief Data type for representing a D-Bus variant
*
* When D-Bus methods or signal require that a paramater can have any of the
* D-Bus data types, a D-Bus variant can be used.
*
* Basically a D-Bus variant includes the actual data and a D-Bus data signature
* to allow a receiver to determine the contents.
*
* Since the TQT_DBusVariant's #value member will already be fully de-marshalled,
* a receiver using this bindings can savely ignore the signature if it doesn't
* need it for a different purpose (e.g. logging).
*
* However, when creating a TQT_DBusVariant object for sending, make sure the
* #signature member is correctly setup, for example by using the #value
* member's buildDBusSignature() method.
*
* @code
* TQT_DBusVariant variant;
*
* variant.value = TQT_DBusData::fromInt32(131719);
* variant.signature = variant.value.buildDBusSignature();
* @endcode
*/
class TQDBUS_EXPORT TQT_DBusVariant
{
public:
/**
* @brief Creates an empty variant object
*/
TQT_DBusVariant() {}
/**
* @brief Copies the given @p other variant object
*
* @param other the variant object to copy from
*/
TQT_DBusVariant(const TQT_DBusVariant& other)
{
signature = other.signature;
value = other.value;
}
/**
* @brief Checks if the given @p other variant is equal to this one
*
* @param other the variant object to compare with
*
* @return @c true if both #signature and #value are equal, otherwise
* @c false
*/
inline bool operator==(const TQT_DBusVariant& other) const
{
if (&other == this) return true;
return signature == other.signature && value == other.value;
}
/**
* @brief Checks if the given @p other variant is not equal to this one
*
* @param other the variant object to compare with
*
* @return @c true if either #signature or #value is different, otherwise
* @c false
*/
inline bool operator!=(const TQT_DBusVariant& other) const
{
if (&other == this) return false;
return signature != other.signature || value != other.value;
}
public:
/**
* @brief The D-Bus data signature of the data contained in #value
*
* @see TQT_DBusData::buildDBusSignature()
*/
TQString signature;
/**
* @brief The D-Bus data type to transport as a variant
*/
TQT_DBusData value;
};
#endif
Loading…
Cancel
Save