Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/xpcom/components/nsServiceManagerUtils.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=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
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef nsServiceManagerUtils_h__
8
#define nsServiceManagerUtils_h__
9
10
#include "nsIServiceManager.h"
11
#include "nsCOMPtr.h"
12
#include "nsString.h"
13
14
inline const nsGetServiceByCID
15
do_GetService(const nsCID& aCID)
16
{
17
  return nsGetServiceByCID(aCID);
18
}
19
20
inline const nsGetServiceByCIDWithError
21
do_GetService(const nsCID& aCID, nsresult* aError)
22
{
23
  return nsGetServiceByCIDWithError(aCID, aError);
24
}
25
26
inline const nsGetServiceByContractID
27
do_GetService(const char* aContractID)
28
{
29
  return nsGetServiceByContractID(aContractID);
30
}
31
32
inline const nsGetServiceByContractIDWithError
33
do_GetService(const char* aContractID, nsresult* aError)
34
{
35
  return nsGetServiceByContractIDWithError(aContractID, aError);
36
}
37
38
class MOZ_STACK_CLASS nsGetServiceFromCategory final : public nsCOMPtr_helper
39
{
40
public:
41
  nsGetServiceFromCategory(const nsACString& aCategory, const nsACString& aEntry,
42
                           nsresult* aErrorPtr)
43
    : mCategory(aCategory)
44
    , mEntry(aEntry)
45
    , mErrorPtr(aErrorPtr)
46
1
  {
47
1
  }
48
49
  virtual nsresult NS_FASTCALL operator()(const nsIID&, void**) const
50
    override;
51
protected:
52
  const nsCString             mCategory;
53
  const nsCString             mEntry;
54
  nsresult*                   mErrorPtr;
55
};
56
57
inline const nsGetServiceFromCategory
58
do_GetServiceFromCategory(const nsACString& aCategory, const nsACString& aEntry,
59
                          nsresult* aError = 0)
60
1
{
61
1
  return nsGetServiceFromCategory(aCategory, aEntry, aError);
62
1
}
63
64
nsresult CallGetService(const nsCID& aClass, const nsIID& aIID, void** aResult);
65
66
nsresult CallGetService(const char* aContractID, const nsIID& aIID,
67
                        void** aResult);
68
69
// type-safe shortcuts for calling |GetService|
70
template<class DestinationType>
71
inline nsresult
72
CallGetService(const nsCID& aClass,
73
               DestinationType** aDestination)
74
{
75
  MOZ_ASSERT(aDestination, "null parameter");
76
77
  return CallGetService(aClass,
78
                        NS_GET_TEMPLATE_IID(DestinationType),
79
                        reinterpret_cast<void**>(aDestination));
80
}
81
82
template<class DestinationType>
83
inline nsresult
84
CallGetService(const char* aContractID,
85
               DestinationType** aDestination)
86
0
{
87
0
  MOZ_ASSERT(aContractID, "null parameter");
88
0
  MOZ_ASSERT(aDestination, "null parameter");
89
0
90
0
  return CallGetService(aContractID,
91
0
                        NS_GET_TEMPLATE_IID(DestinationType),
92
0
                        reinterpret_cast<void**>(aDestination));
93
0
}
94
95
#endif