ServiceDeclarationMacros.h
Go to the documentation of this file.
1 #ifndef art_Framework_Services_Registry_ServiceDeclarationMacros_h
2 #define art_Framework_Services_Registry_ServiceDeclarationMacros_h
3 
4 //
5 // ServiceDeclarationMacros - define the macros used to declare an art
6 // service or an interface to be implemented by an art service.
7 //
8 // Notes:
9 //
10 // * Unlike other types of plugin, services require macro invocations in
11 // their headers *and* their compile units.
12 //
13 // * In order to declare your service, you must specify your service
14 // with a scope value of LEGACY, or SHARED as follows:
15 //
16 // * LEGACY services are unaware of multi-threaded operation, and
17 // configuration of such a service precludes multi-threaded
18 // operation. Such services must have a constructor with one of two
19 // signatures:
20 //
21 // MyService(fhicl::ParameterSet const&,
22 // art::ActivityRegistry&);
23 //
24 // or
25 //
26 // MyService(fhicl::ParameterSet const&);
27 //
28 // If the former exists, it will be invoked without ambiguity
29 // regardless of the presence or otherwise of the latter.
30 //
31 // * SHARED services are expected to have the same signature as LEGACY
32 // services, but warrant additionally that it is safe to call their
33 // methods (including callbacks) from multiple threads at the same
34 // time. A global service may register for callbacks for per-
35 // schedule signals (however the same callback must be registered
36 // for all schedules per the ActivityRegistry interface).
37 //
38 // * PER_SCHEDULE services must provide a signature:
39 //
40 // MyService(fhicl::ParameterSet const&,
41 // art::ActivityRegistry&,
42 // art::ScheduleID);
43 //
44 // Note that Per-schedule services may register for global callbacks,
45 // but there will be n unique instances of the service (and
46 // therefore unique callbacks), one for each schedule.
47 ////////////////////////////////////////////////////////////////////////
48 //
49 // User-callable macros:
50 //
51 // DECLARE_ART_SERVICE(svc, scope)
52 // Declare (in the header) an art service of type <svc> with scope
53 // (see above).
54 //
55 ////////////////////////////////////
56 // DECLARE_ART_SERVICE_INTERFACE(iface, scope)
57 // Declare an interface to be used by services (must be invoked in the
58 // header for the interface, *not* any implementations thereof).
59 //
60 ////////////////////////////////////
61 // DECLARE_ART_SERVICE_INTERFACE_IMPL(svc, iface, scope)
62 // Declare (in the header) an art service of type <svc> implementing
63 // (inheriting from) interface <iface>, with scope <scope>.
64 //
65 ////////////////////////////////////////////////////////////////////////
66 
69 
70 // Courtesy include despite not being needed by anything below.
72 
73 // User service macros, Service must provide a constructor with the
74 // correct signature (see notes above).
75 
76 // Declare a service.
77 #define DECLARE_ART_SERVICE(svc, scope) ART_DETAIL_DECLARE_SERVICE(svc, scope)
78 
79 // Declare an interface.
80 #define DECLARE_ART_SERVICE_INTERFACE(svc, scope) \
81  static_assert( \
82  art::detail::handle_allowed_v<svc>, \
83  "\n\nart-error: You cannot create a service interface for type " \
84  "'" ART_DETAIL_STRINGIZED_TYPE(svc) "'.\n" \
85  " There is a base class of " \
86  "this type for which a ServiceHandle " \
87  "cannot\n" \
88  " be constructed. Please " \
89  "contact artists@fnal.gov for " \
90  "guidance.\n"); \
91  ART_DETAIL_DECLARE_SERVICE_INTERFACE(svc, scope)
92 
93 // Declare a service implementing an interface.
94 #define DECLARE_ART_SERVICE_INTERFACE_IMPL(svc, iface, scope) \
95  static_assert( \
96  art::detail::handle_allowed_v<svc>, \
97  "\n\nart-error: You cannot create a service implementation for type " \
98  "'" ART_DETAIL_STRINGIZED_TYPE(svc) "'.\n" \
99  " There is a base class of " \
100  "this type for which a ServiceHandle " \
101  "cannot\n" \
102  " be constructed. Please " \
103  "contact artists@fnal.gov for " \
104  "guidance.\n"); \
105  ART_DETAIL_DECLARE_SERVICE_INTERFACE_IMPL(svc, iface, scope)
106 
107 #endif /* art_Framework_Services_Registry_ServiceDeclarationMacros_h */
108 
109 // Local Variables:
110 // mode: c++
111 // End: