dbus-cxx logo
message.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2007,2009,2010 by Rick L. Vinyard, Jr. *
3  * rvinyard@cs.nmsu.edu *
4  * *
5  * This file is part of the dbus-cxx library. *
6  * *
7  * The dbus-cxx library is free software; you can redistribute it and/or *
8  * modify it under the terms of the GNU General Public License *
9  * version 3 as published by the Free Software Foundation. *
10  * *
11  * The dbus-cxx library is distributed in the hope that it will be *
12  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty *
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with this software. If not see <http://www.gnu.org/licenses/>. *
18  ***************************************************************************/
19 #include <string>
20 #include <vector>
21 #include <map>
22 
23 #include <dbus/dbus.h>
24 
25 #include <dbus-cxx/pointer.h>
28 
29 #ifndef DBUSCXX_MESSAGE_H
30 #define DBUSCXX_MESSAGE_H
31 
32 namespace DBus
33 {
34 
35  class ReturnMessage;
36 
50  // TODO support
51  // - dbus_message_type_from_string
52  // - dbus_message_type_to_string
53  // - dbus_message_marshal
54  // - dbus_message_demarshal
55 
56  class Message
57  {
58  public:
59 
60  typedef DBusCxxPointer<Message> pointer;
61 
62  typedef DBusCxxPointer<const Message> const_pointer;
63 
64  typedef DBusCxxWeakPointer<Message> weak_pointer;
65 
66  protected:
67 
69 
70  Message( DBusMessage* cobj=NULL, CreateMethod m = CREATE_ALIAS );
71 
73 
75 
76  public:
77 
79 
81 
82  static pointer create( MessageType type );
83 
84  static pointer create( DBusMessage* cobj=NULL, CreateMethod m = CREATE_ALIAS );
85 
86  static pointer create( Message::pointer other, CreateMethod m = CREATE_ALIAS );
87 
88  static pointer create( Message::const_pointer other, CreateMethod m = CREATE_ALIAS );
89 
90  DBusCxxPointer<ReturnMessage> create_reply() const;
91 
92  virtual ~Message();
93 
94  Message& operator = ( const Message& m );
95 
96  bool operator == ( const Message& other );
97 
98  bool is_valid() const;
99 
100  void invalidate();
101 
102  operator bool() const;
103 
104  uint32_t serial() const;
105 
106 // Message copy();
107 
108  int type() const;
109 
110  void set_auto_start( bool auto_start);
111 
112  bool auto_start();
113 
114  bool set_destination( const std::string& s );
115 
116  const char* destination() const;
117 
118  bool set_sender( const std::string& s );
119 
120  const char* sender() const;
121 
122  bool is_call( const std::string& interface, const std::string& method ) const;
123 
124  bool is_signal( const std::string& interface, const std::string& signal_name ) const;
125 
126  bool is_error( const std::string& error_name ) const;
127 
128  bool has_destination( const std::string& name ) const;
129 
130  bool has_sender( const std::string& name ) const;
131 
132  template <typename T>
133  iterator operator>>( T& value ) const
134  {
135  iterator iter = this->begin();
136  iter >> value;
137  return iter;
138  }
139 
140  template <typename T>
141  append_iterator operator<<( const T& value )
142  {
143  append_iterator aiter( *this );
144  aiter << value;
145  return aiter;
146  }
147 
148  iterator begin() const;
149 
150  iterator end() const;
151 
152  append_iterator append();
153 
154  DBusMessage* cobj() const;
155 
156  protected:
157 
158  friend void init(bool);
159 
160  DBusMessage* m_cobj;
161 
162  bool m_valid;
163 
164  };
165 
166 }
167 
168 template <typename T>
169 inline
171 {
172  if ( not ptr ) throw -1;
173  return (*ptr) >> value;
174 }
175 
176 template <typename T>
177 inline
179 {
180  if ( not ptr ) throw -1;
181  return (*ptr) << value;
182 }
183 
184 #endif
DBus::Message::append_iterator operator<<(DBus::Message::pointer ptr, const T &value)
Definition: message.h:178
bool has_sender(const std::string &name) const
Definition: message.cpp:240
void invalidate()
Definition: message.cpp:152
bool set_sender(const std::string &s)
Definition: message.cpp:204
DBusMessage * cobj() const
Definition: message.cpp:261
DBusCxxPointer< Message > pointer
Definition: message.h:60
Definition: accumulators.h:24
MessageAppendIterator append_iterator
Definition: message.h:80
bool set_destination(const std::string &s)
Definition: message.cpp:192
bool is_error(const std::string &error_name) const
Definition: message.cpp:228
iterator begin() const
Definition: message.cpp:246
const char * destination() const
Definition: message.cpp:198
int type() const
Definition: message.cpp:174
static pointer create(MessageType type)
Definition: message.cpp:91
MessageType
Definition: enums.h:71
DBusMessage * m_cobj
Definition: message.h:160
Definition: enums.h:37
append_iterator operator<<(const T &value)
Definition: message.h:141
bool is_call(const std::string &interface, const std::string &method) const
Definition: message.cpp:216
This class represents a basic DBus message and also serves as a base class for the specialized messag...
Definition: message.h:56
bool operator==(const Message &other)
Definition: message.cpp:140
friend void init(bool)
Initializes the dbus-cxx library.
Definition: utility.cpp:40
append_iterator append()
Definition: message.cpp:256
DBusCxxPointer< ReturnMessage > create_reply() const
Definition: message.cpp:111
DBus::Message::iterator operator>>(DBus::Message::const_pointer ptr, T &value)
Definition: message.h:170
CreateMethod
Definition: enums.h:35
Message & operator=(const Message &m)
Definition: message.cpp:129
const char * sender() const
Definition: message.cpp:210
bool m_valid
Definition: message.h:162
DBusCxxWeakPointer< Message > weak_pointer
Definition: message.h:64
Insertion iterator allow values to be appended to a message.
Definition: messageappenditerator.h:43
virtual ~Message()
Definition: message.cpp:124
void set_auto_start(bool auto_start)
Definition: message.cpp:180
bool is_signal(const std::string &interface, const std::string &signal_name) const
Definition: message.cpp:222
iterator end() const
Definition: message.cpp:251
bool is_valid() const
Definition: message.cpp:145
uint32_t serial() const
Definition: message.cpp:162
Extraction iterator allowing values to be retrieved from a message.
Definition: messageiterator.h:37
bool has_destination(const std::string &name) const
Definition: message.cpp:234
DBusCxxPointer< const Message > const_pointer
Definition: message.h:62
MessageIterator iterator
Definition: message.h:78
iterator operator>>(T &value) const
Definition: message.h:133
bool auto_start()
Definition: message.cpp:186
Message(MessageType type)
Definition: message.cpp:29

Generated on Sun Mar 19 2017 14:54:27 for dbus-cxx by doxygen 1.8.8