Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/DBusHelpers.h
Line
Count
Source (jump to first uncovered line)
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
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5
 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef mozilla_DBusHelpers_h
8
#define mozilla_DBusHelpers_h
9
10
#include <dbus/dbus.h>
11
#include "mozilla/UniquePtr.h"
12
13
namespace mozilla {
14
15
template<>
16
struct RefPtrTraits<DBusMessage>
17
{
18
0
  static void AddRef(DBusMessage* aMessage) {
19
0
    MOZ_ASSERT(aMessage);
20
0
    dbus_message_ref(aMessage);
21
0
  }
22
0
  static void Release(DBusMessage* aMessage) {
23
0
    MOZ_ASSERT(aMessage);
24
0
    dbus_message_unref(aMessage);
25
0
  }
26
};
27
28
template<>
29
struct RefPtrTraits<DBusPendingCall>
30
{
31
0
  static void AddRef(DBusPendingCall* aPendingCall) {
32
0
    MOZ_ASSERT(aPendingCall);
33
0
    dbus_pending_call_ref(aPendingCall);
34
0
  }
35
0
  static void Release(DBusPendingCall* aPendingCall) {
36
0
    MOZ_ASSERT(aPendingCall);
37
0
    dbus_pending_call_unref(aPendingCall);
38
0
  }
39
};
40
41
/*
42
 * |RefPtrTraits<DBusConnection>| specializes |RefPtrTraits<>|
43
 * for managing |DBusConnection| with |RefPtr|.
44
 *
45
 * |RefPtrTraits<DBusConnection>| will _not_ close the DBus
46
 * connection upon the final unref. The caller is responsible
47
 * for closing the connection.
48
 */
49
template<>
50
struct RefPtrTraits<DBusConnection>
51
{
52
0
  static void AddRef(DBusConnection* aConnection) {
53
0
    MOZ_ASSERT(aConnection);
54
0
    dbus_connection_ref(aConnection);
55
0
  }
56
0
  static void Release(DBusConnection* aConnection) {
57
0
    MOZ_ASSERT(aConnection);
58
0
    dbus_connection_unref(aConnection);
59
0
  }
60
};
61
62
/*
63
 * |DBusConnectionDelete| is a deleter for managing instances
64
 * of |DBusConnection| in |UniquePtr|. Upon destruction, it
65
 * will close an open connection before unref'ing the data
66
 * structure.
67
 *
68
 * Do not use |UniquePtr| with shared DBus connections. For
69
 * shared connections, use |RefPtr|.
70
 */
71
class DBusConnectionDelete
72
{
73
public:
74
  constexpr DBusConnectionDelete()
75
0
  { }
76
77
  void operator()(DBusConnection* aConnection) const
78
0
  {
79
0
    MOZ_ASSERT(aConnection);
80
0
    if (dbus_connection_get_is_connected(aConnection)) {
81
0
      dbus_connection_close(aConnection);
82
0
    }
83
0
    dbus_connection_unref(aConnection);
84
0
  }
85
};
86
87
} // namespace mozilla
88
89
#endif // mozilla_DBusHelpers_h