dbus-cxx logo

message.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007,2009,2010 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 #include <string>
00020 #include <vector>
00021 #include <map>
00022 
00023 #include <dbus/dbus.h>
00024 
00025 #include <dbus-cxx/pointer.h>
00026 #include <dbus-cxx/messageiterator.h>
00027 #include <dbus-cxx/messageappenditerator.h>
00028 
00029 #ifndef DBUSCXX_MESSAGE_H
00030 #define DBUSCXX_MESSAGE_H
00031 
00032 namespace DBus
00033 {
00034 
00035   class ReturnMessage;
00036 
00050   // TODO support
00051   //  - dbus_message_type_from_string
00052   //  - dbus_message_type_to_string
00053   //  - dbus_message_marshal
00054   //  - dbus_message_demarshal
00055   
00056   class Message
00057   {
00058     public:
00059 
00060       typedef DBusCxxPointer<Message> pointer;
00061 
00062       typedef DBusCxxPointer<const Message> const_pointer;
00063 
00064       typedef DBusCxxWeakPointer<Message> weak_pointer;
00065 
00066     protected:
00067       
00068       Message( MessageType type );
00069 
00070       Message( DBusMessage* cobj=NULL, CreateMethod m = CREATE_ALIAS );
00071 
00072       Message( Message::pointer other, CreateMethod m = CREATE_ALIAS );
00073 
00074       Message( Message::const_pointer other, CreateMethod m = CREATE_ALIAS );
00075 
00076     public:
00077 
00078       typedef MessageIterator iterator;
00079 
00080       typedef MessageAppendIterator append_iterator;
00081 
00082       static pointer create( MessageType type );
00083 
00084       static pointer create( DBusMessage* cobj=NULL, CreateMethod m = CREATE_ALIAS );
00085 
00086       static pointer create( Message::pointer other, CreateMethod m = CREATE_ALIAS );
00087 
00088       static pointer create( Message::const_pointer other, CreateMethod m = CREATE_ALIAS );
00089 
00090       DBusCxxPointer<ReturnMessage> create_reply() const;
00091 
00092       virtual ~Message();
00093 
00094       Message& operator = ( const Message& m );
00095 
00096       bool operator == ( const Message& other );
00097 
00098       bool is_valid() const;
00099 
00100       void invalidate();
00101 
00102       operator bool() const;
00103 
00104       uint32_t serial() const;
00105 
00106 //       Message copy();
00107 
00108       int type() const;
00109 
00110       void set_auto_start( bool auto_start);
00111 
00112       bool auto_start();
00113 
00114       bool set_destination( const std::string& s );
00115 
00116       const char* destination() const;
00117 
00118       bool set_sender( const std::string& s );
00119 
00120       const char* sender() const;
00121 
00122       bool is_call( const std::string& interface, const std::string& method ) const;
00123 
00124       bool is_signal( const std::string& interface, const std::string& signal_name ) const;
00125 
00126       bool is_error( const std::string& error_name ) const;
00127 
00128       bool has_destination( const std::string& name ) const;
00129 
00130       bool has_sender( const std::string& name ) const;
00131 
00132       template <typename T>
00133       iterator operator>>( T& value ) const
00134       {
00135         iterator iter = this->begin();
00136         iter >> value;
00137         return iter;
00138       }
00139       
00140       template <typename T>
00141       append_iterator operator<<( const T& value )
00142       {
00143         append_iterator aiter( *this );
00144         aiter << value;
00145         return aiter;
00146       }
00147 
00148       iterator begin() const;
00149 
00150       iterator end() const;
00151 
00152       append_iterator append();
00153 
00154       DBusMessage* cobj() const;
00155 
00156     protected:
00157 
00158       friend void init(bool);
00159 
00160       DBusMessage* m_cobj;
00161 
00162       bool m_valid;
00163 
00164   };
00165 
00166 }
00167 
00168 template <typename T>
00169 inline
00170 DBus::Message::iterator operator>>( DBus::Message::const_pointer ptr, T& value )
00171 {
00172   if ( not ptr ) throw -1;
00173   return (*ptr) >> value;
00174 }
00175 
00176 template <typename T>
00177 inline
00178 DBus::Message::append_iterator operator<<( DBus::Message::pointer ptr, const T& value )
00179 {
00180   if ( not ptr ) throw -1;
00181   return (*ptr) << value;
00182 }
00183 
00184 #endif

Generated on Thu Mar 18 09:30:54 2010 for dbus-cxx by doxygen 1.6.1