dbus-cxx logo

message.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007,2009 by Rick L. Vinyard, Jr.                       *
00003  *   rvinyard@cs.nmsu.edu                                                  *
00004  *                                                                         *
00005  *   This file is part of the dbus-cxx library.                            *
00006  *                                                                         *
00007  *   The dbus-cxx library is free software; you can redistribute it and/or *
00008  *   modify it under the terms of the GNU General Public License           *
00009  *   version 3 as published by the Free Software Foundation.               *
00010  *                                                                         *
00011  *   The dbus-cxx library is distributed in the hope that it will be       *
00012  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty   *
00013  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
00014  *   General Public License for more details.                              *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU General Public License     *
00017  *   along with this software. If not see <http://www.gnu.org/licenses/>.  *
00018  ***************************************************************************/
00019 
00020 #ifndef DBUSCXXMESSAGE_H
00021 #define DBUSCXXMESSAGE_H
00022 
00023 #include <string>
00024 #include <vector>
00025 #include <map>
00026 
00027 #include <dbus/dbus.h>
00028 
00029 #include <dbus-cxx/pointer.h>
00030 #include <dbus-cxx/messageiterator.h>
00031 #include <dbus-cxx/messageappenditerator.h>
00032 
00033 // #include <dbus-cxx/util.h>
00034 
00035 namespace DBus
00036 {
00037 
00038   class ReturnMessage;
00039 
00053   // TODO support
00054   //  - dbus_message_type_from_string
00055   //  - dbus_message_type_to_string
00056   //  - dbus_message_marshal
00057   //  - dbus_message_demarshal
00058   
00059   class Message
00060   {
00061     public:
00062 
00063       typedef DBusCxxPointer<Message> pointer;
00064 
00065       typedef DBusCxxPointer<const Message> const_pointer;
00066 
00067       typedef DBusCxxWeakPointer<Message> weak_pointer;
00068 
00069     protected:
00070       
00071       Message( MessageType type );
00072 
00073       Message( DBusMessage* cobj=NULL, CreateMethod m = CREATE_ALIAS );
00074 
00075       Message( Message::pointer other, CreateMethod m = CREATE_ALIAS );
00076 
00077       Message( Message::const_pointer other, CreateMethod m = CREATE_ALIAS );
00078 
00079     public:
00080 
00081       typedef MessageIterator iterator;
00082 
00083       typedef MessageAppendIterator append_iterator;
00084 
00085       static pointer create( MessageType type );
00086 
00087       static pointer create( DBusMessage* cobj=NULL, CreateMethod m = CREATE_ALIAS );
00088 
00089       static pointer create( Message::pointer other, CreateMethod m = CREATE_ALIAS );
00090 
00091       static pointer create( Message::const_pointer other, CreateMethod m = CREATE_ALIAS );
00092 
00093       DBusCxxPointer<ReturnMessage> create_reply() const;
00094 
00095       virtual ~Message();
00096 
00097       Message& operator = ( const Message& m );
00098 
00099       bool operator == ( const Message& other );
00100 
00101       bool is_valid() const;
00102 
00103       void invalidate();
00104 
00105       operator bool() const;
00106 
00107       uint32_t serial() const;
00108 
00109       Message copy();
00110 
00111       int type() const;
00112 
00113       void set_auto_start( bool auto_start);
00114 
00115       bool auto_start();
00116 
00117       bool set_destination( const std::string& s );
00118 
00119       const char* destination() const;
00120 
00121       bool set_sender( const std::string& s );
00122 
00123       const char* sender() const;
00124 
00125       bool is_call( const std::string& interface, const std::string& method ) const;
00126 
00127       bool is_signal( const std::string& interface, const std::string& signal_name ) const;
00128 
00129       bool is_error( const std::string& error_name ) const;
00130 
00131       bool has_destination( const std::string& name ) const;
00132 
00133       bool has_sender( const std::string& name ) const;
00134 
00135       iterator operator>>( bool& value ) const;
00136       iterator operator>>( uint8_t& value ) const;
00137       iterator operator>>( int16_t& value ) const;
00138       iterator operator>>( uint16_t& value ) const;
00139       iterator operator>>( int32_t& value ) const;
00140       iterator operator>>( uint32_t& value ) const;
00141       iterator operator>>( int64_t& value ) const;
00142       iterator operator>>( uint64_t& value ) const;
00143       iterator operator>>( double& value ) const;
00144       iterator operator>>( const char*& value ) const;
00145       iterator operator>>( std::string& value ) const;
00146       
00147       append_iterator operator<<( bool value );
00148       append_iterator operator<<( uint8_t value );
00149       append_iterator operator<<( int16_t value );
00150       append_iterator operator<<( uint16_t value );
00151       append_iterator operator<<( int32_t value );
00152       append_iterator operator<<( uint32_t value );
00153       append_iterator operator<<( int64_t value );
00154       append_iterator operator<<( uint64_t value );
00155       append_iterator operator<<( double value );
00156       append_iterator operator<<( const char* value );
00157       append_iterator operator<<( const std::string& value );
00158 
00159       iterator begin() const;
00160 
00161       iterator end() const;
00162 
00163       append_iterator append();
00164 
00165       DBusMessage* cobj() const;
00166 
00167     protected:
00168 
00169       friend void init(bool);
00170 
00171       DBusMessage* m_cobj;
00172 
00173       bool m_valid;
00174 
00175   };
00176 
00177   template <typename T>
00178   inline
00179   Message::iterator operator>>( Message::const_pointer ptr, T& value )
00180   {
00181     if ( not ptr ) throw -1;
00182     return ptr->operator>>( value );
00183   }
00184       
00185   template <typename T>
00186   inline
00187   Message::append_iterator operator<<( Message::pointer ptr, T& value )
00188   {
00189     if ( not ptr ) throw -1;
00190     return ptr->operator<<( value );
00191   }
00192 
00193 }
00194 
00195 #endif

Generated on Thu May 28 16:50:50 2009 for dbus-cxx by doxygen 1.5.7.1