|
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 "mozilla/RefPtr.h" |
|
23 |
|
24 // LOGE and free a D-Bus error |
|
25 // Using #define so that __FUNCTION__ resolves usefully |
|
26 #define LOG_AND_FREE_DBUS_ERROR_WITH_MSG(err, msg) log_and_free_dbus_error(err, __FUNCTION__, msg); |
|
27 #define LOG_AND_FREE_DBUS_ERROR(err) log_and_free_dbus_error(err, __FUNCTION__); |
|
28 |
|
29 struct DBusError; |
|
30 struct DBusMessage; |
|
31 |
|
32 namespace mozilla { |
|
33 namespace ipc { |
|
34 |
|
35 class DBusMessageRefPtr |
|
36 { |
|
37 public: |
|
38 DBusMessageRefPtr(DBusMessage* aMsg); |
|
39 ~DBusMessageRefPtr(); |
|
40 |
|
41 operator DBusMessage* () |
|
42 { |
|
43 return mMsg; |
|
44 } |
|
45 |
|
46 DBusMessage* get() |
|
47 { |
|
48 return mMsg; |
|
49 } |
|
50 |
|
51 private: |
|
52 DBusMessage* mMsg; |
|
53 }; |
|
54 |
|
55 /** |
|
56 * DBusReplyHandler represents a handler for DBus reply messages. Inherit |
|
57 * from this class and implement the Handle method. The method Callback |
|
58 * should be passed to the DBus send function, with the class instance as |
|
59 * user-data argument. |
|
60 */ |
|
61 class DBusReplyHandler |
|
62 { |
|
63 public: |
|
64 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DBusReplyHandler) |
|
65 |
|
66 /** |
|
67 * Implements a call-back function for DBus. The supplied value for |
|
68 * aData must be a pointer to an instance of DBusReplyHandler. |
|
69 */ |
|
70 static void Callback(DBusMessage* aReply, void* aData); |
|
71 |
|
72 /** |
|
73 * Call-back method for handling the reply message from DBus. |
|
74 */ |
|
75 virtual void Handle(DBusMessage* aReply) = 0; |
|
76 |
|
77 protected: |
|
78 DBusReplyHandler() |
|
79 { |
|
80 } |
|
81 |
|
82 DBusReplyHandler(const DBusReplyHandler& aHandler) |
|
83 { |
|
84 } |
|
85 |
|
86 DBusReplyHandler& operator = (const DBusReplyHandler& aRhs) |
|
87 { |
|
88 return *this; |
|
89 } |
|
90 |
|
91 virtual ~DBusReplyHandler() |
|
92 { |
|
93 } |
|
94 }; |
|
95 |
|
96 void log_and_free_dbus_error(DBusError* err, |
|
97 const char* function, |
|
98 DBusMessage* msg = nullptr); |
|
99 |
|
100 int dbus_returns_int32(DBusMessage *reply); |
|
101 |
|
102 } |
|
103 } |
|
104 |
|
105 #endif |
|
106 |