Line data Source code
1 : /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
2 : /* vim: set ts=2 et sw=2 tw=80: */
3 : /*
4 : ** Copyright 2006, The Android Open Source Project
5 : **
6 : ** Licensed under the Apache License, Version 2.0 (the "License");
7 : ** you may not use this file except in compliance with the License.
8 : ** You may obtain a copy of the License at
9 : **
10 : ** http://www.apache.org/licenses/LICENSE-2.0
11 : **
12 : ** Unless required by applicable law or agreed to in writing, software
13 : ** distributed under the License is distributed on an "AS IS" BASIS,
14 : ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 : ** See the License for the specific language governing permissions and
16 : ** limitations under the License.
17 : */
18 :
19 : #ifndef mozilla_ipc_dbus_dbusutils_h__
20 : #define mozilla_ipc_dbus_dbusutils_h__
21 :
22 : #include <dbus/dbus.h>
23 : #include "mozilla/RefPtr.h"
24 : #include "nsISupportsImpl.h"
25 :
26 : // LOGE and free a D-Bus error
27 : // Using #define so that __FUNCTION__ resolves usefully
28 : #define LOG_AND_FREE_DBUS_ERROR_WITH_MSG(err, msg) log_and_free_dbus_error(err, __FUNCTION__, msg);
29 : #define LOG_AND_FREE_DBUS_ERROR(err) log_and_free_dbus_error(err, __FUNCTION__);
30 :
31 : namespace mozilla {
32 : namespace ipc {
33 :
34 : class DBusMessageRefPtr
35 : {
36 : public:
37 : explicit DBusMessageRefPtr(DBusMessage* aMsg);
38 : ~DBusMessageRefPtr();
39 :
40 : operator DBusMessage* ()
41 : {
42 : return mMsg;
43 : }
44 :
45 : DBusMessage* get()
46 : {
47 : return mMsg;
48 : }
49 :
50 : private:
51 : DBusMessage* mMsg;
52 : };
53 :
54 : /**
55 : * DBusReplyHandler represents a handler for DBus reply messages. Inherit
56 : * from this class and implement the Handle method. The method Callback
57 : * should be passed to the DBus send function, with the class instance as
58 : * user-data argument.
59 : */
60 : class DBusReplyHandler
61 : {
62 : public:
63 0 : NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DBusReplyHandler)
64 :
65 : /**
66 : * Implements a call-back function for DBus. The supplied value for
67 : * aData must be a pointer to an instance of DBusReplyHandler.
68 : */
69 : static void Callback(DBusMessage* aReply, void* aData);
70 :
71 : /**
72 : * Call-back method for handling the reply message from DBus.
73 : */
74 : virtual void Handle(DBusMessage* aReply) = 0;
75 :
76 : protected:
77 : DBusReplyHandler()
78 : {
79 : }
80 :
81 : DBusReplyHandler(const DBusReplyHandler& aHandler)
82 : {
83 : }
84 :
85 : DBusReplyHandler& operator = (const DBusReplyHandler& aRhs)
86 : {
87 : return *this;
88 : }
89 :
90 : virtual ~DBusReplyHandler()
91 : {
92 : }
93 : };
94 :
95 : void log_and_free_dbus_error(DBusError* err,
96 : const char* function,
97 : DBusMessage* msg = nullptr);
98 :
99 : int dbus_returns_int32(DBusMessage *reply);
100 :
101 : }
102 : }
103 :
104 : #endif
105 :
|