sbDBus.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 :miv */
3 /*
4  *=BEGIN SONGBIRD GPL
5  *
6  * This file is part of the Songbird web player.
7  *
8  * Copyright(c) 2005-2010 POTI, Inc.
9  * http://www.songbirdnest.com
10  *
11  * This file may be licensed under the terms of of the
12  * GNU General Public License Version 2 (the ``GPL'').
13  *
14  * Software distributed under the License is distributed
15  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
16  * express or implied. See the GPL for the specific language
17  * governing rights and limitations.
18  *
19  * You should have received a copy of the GPL along with this
20  * program. If not, go to http://www.gnu.org/licenses/gpl.html
21  * or write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23  *
24  *=END SONGBIRD GPL
25  */
26 
27 #ifndef _SB_DBUS_H_
28 #define _SB_DBUS_H_
29 
30 //------------------------------------------------------------------------------
31 //------------------------------------------------------------------------------
32 //
33 // Songbird D-Bus service defs.
34 //
35 // For D-Bus API documentation, see
36 // http://dbus.freedesktop.org/doc/api/html/index.html.
37 //
38 //------------------------------------------------------------------------------
39 //------------------------------------------------------------------------------
40 
46 //------------------------------------------------------------------------------
47 //
48 // Songbird D-Bus imported services.
49 //
50 //------------------------------------------------------------------------------
51 
52 // Mozilla imports.
53 #include <nsStringGlue.h>
54 
55 // D-Bus imports.
56 #include <dbus/dbus.h>
57 
58 
59 //------------------------------------------------------------------------------
60 //
61 // Songbird D-Bus service classes.
62 //
63 //------------------------------------------------------------------------------
64 
70 {
71  //----------------------------------------------------------------------------
72  //
73  // Public interface.
74  //
75  //----------------------------------------------------------------------------
76 
77 public:
78 
90  static nsresult NewMethodCall(sbDBusMessage** aMessage,
91  const char* aDestination,
92  const char* aPath,
93  const char* aInterface,
94  const char* aMethod);
95 
102  nsresult GetArgs(int aFirstArgType,
103  ...);
104 
111  void Assign(DBusMessage* aMessage);
112 
118  DBusMessage* get() const
119  {
120  return mBaseMessage;
121  }
122 
127  sbDBusMessage(DBusMessage* aMessage = NULL) : mBaseMessage(aMessage) {}
128 
132  virtual ~sbDBusMessage();
133 
134 
135  //----------------------------------------------------------------------------
136  //
137  // Private interface.
138  //
139  //----------------------------------------------------------------------------
140 
141 private:
142 
143  //
144  // mBaseMessage Base D-Bus message data record.
145  //
146 
147  DBusMessage* mBaseMessage;
148 };
149 
150 
156 {
157  //----------------------------------------------------------------------------
158  //
159  // Public interface.
160  //
161  //----------------------------------------------------------------------------
162 
163 public:
164 
177  static nsresult New(sbDBusConnection** aConnection,
178  DBusBusType aBusType,
179  const char* aDestination,
180  const char* aPath,
181  const char* aInterface);
182 
195  nsresult InvokeMethod(const char* aMethod,
196  sbDBusMessage** aReply,
197  int aFirstArgType,
198  ...);
199 
205  DBusConnection* get() const
206  {
207  return mBaseConnection;
208  }
209 
213  virtual ~sbDBusConnection();
214 
215 
216  //----------------------------------------------------------------------------
217  //
218  // Private interface.
219  //
220  //----------------------------------------------------------------------------
221 
222 private:
223 
224  //
225  // Private constants.
226  //
227  // sMethodCallTimeoutMS Amount of time in milliseconds to wait for
228  // D-Bus method calls to complete.
229  //
230 
231  static const PRUint32 sMethodCallTimeoutMS = 1000;
232 
233 
234  //
235  // Private fields.
236  //
237  // mBaseConnection Base D-Bus connection data record.
238  // mDestination Default message destination.
239  // mPath Default message path.
240  // mInterface Default message interface.
241  //
242 
243  DBusConnection* mBaseConnection;
244  nsCString mDestination;
245  nsCString mPath;
246  nsCString mInterface;
247 
258  nsresult Initialize(DBusBusType aBusType,
259  const char* aDestination,
260  const char* aPath,
261  const char* aInterface);
262 
267 };
268 
269 
274 class sbDBusError : public DBusError
275 {
276 public:
277 
278  sbDBusError();
279 
280  virtual ~sbDBusError();
281 };
282 
283 
284 //------------------------------------------------------------------------------
285 //
286 // Songbird D-Bus service macros.
287 //
288 //------------------------------------------------------------------------------
289 
298 #if defined(DEBUG)
299 
300 #define SB_DBUS_ENSURE_SUCCESS_BODY(aError, aReturnValue) \
301  char* msg = PR_smprintf("SB_DBUS_ENSURE_SUCCESS(%s, %s) failed with " \
302  "result %s", \
303  #aError, \
304  #aReturnValue, \
305  aError.message); \
306  NS_WARNING(msg); \
307  PR_smprintf_free(msg);
308 
309 #else
310 
311 #define SB_DBUS_ENSURE_SUCCESS_BODY(aError, aReturnValue) \
312  NS_WARNING("SB_DBUS_ENSURE_SUCCESS(" #aError ", " #aReturnValue ") failed");
313 
314 #endif
315 
316 
326 #define SB_DBUS_ENSURE_SUCCESS(aError, aReturnValue) \
327  PR_BEGIN_MACRO \
328  if (dbus_error_is_set(&aError)) { \
329  SB_DBUS_ENSURE_SUCCESS_BODY(aError, aReturnValue) \
330  return aReturnValue; \
331  } \
332  PR_END_MACRO
333 
334 
335 #endif // _SB_DBUS_H_
336 
nsresult GetArgs(int aFirstArgType,...)
Definition: sbDBus.cpp:116
static nsresult New(sbDBusConnection **aConnection, DBusBusType aBusType, const char *aDestination, const char *aPath, const char *aInterface)
Definition: sbDBus.cpp:157
_updateCookies aPath
nsresult InvokeMethod(const char *aMethod, sbDBusMessage **aReply, int aFirstArgType,...)
Definition: sbDBus.cpp:217
static nsresult NewMethodCall(sbDBusMessage **aMessage, const char *aDestination, const char *aPath, const char *aInterface, const char *aMethod)
Definition: sbDBus.cpp:65
virtual ~sbDBusError()
Definition: sbDBus.cpp:328
sbDBusMessage(DBusMessage *aMessage=NULL)
Definition: sbDBus.h:127
void Assign(DBusMessage *aMessage)
Definition: sbDBus.cpp:99
virtual ~sbDBusMessage()
Definition: sbDBus.cpp:137
virtual ~sbDBusConnection()
Definition: sbDBus.cpp:297