objc2_metric_kit/generated/MXMetricManager.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10/// Describes the general purpose of a specific launch task.
11///
12/// See also [Apple's documentation](https://developer.apple.com/documentation/metrickit/mxlaunchtaskid?language=objc)
13// NS_TYPED_EXTENSIBLE_ENUM
14pub type MXLaunchTaskID = NSString;
15
16extern_class!(
17 /// An instance of this class can be used to retrieve periodic, aggregated power and performance metrics.
18 ///
19 /// To receive metrics, clients must acquire a reference to the shared instance of the metric manager and add an eligible MXMetricManagerSubscriber.
20 ///
21 /// Metrics are not guaranteed to be delivered, but can be expected atleast once per day when conditions permit.
22 ///
23 /// Subscribers to the metric manager can remove themselves using removeSubscriber:subscriber if they no longer wish to receive metrics.
24 ///
25 /// See also [Apple's documentation](https://developer.apple.com/documentation/metrickit/mxmetricmanager?language=objc)
26 #[unsafe(super(NSObject))]
27 #[derive(Debug, PartialEq, Eq, Hash)]
28 pub struct MXMetricManager;
29);
30
31extern_conformance!(
32 unsafe impl NSObjectProtocol for MXMetricManager {}
33);
34
35impl MXMetricManager {
36 extern_methods!(
37 #[cfg(feature = "MXMetricPayload")]
38 /// A list of past metric payloads received.
39 #[unsafe(method(pastPayloads))]
40 #[unsafe(method_family = none)]
41 pub unsafe fn pastPayloads(&self) -> Retained<NSArray<MXMetricPayload>>;
42
43 #[cfg(feature = "MXDiagnosticPayload")]
44 /// A list of past diagnostic payloads received.
45 #[unsafe(method(pastDiagnosticPayloads))]
46 #[unsafe(method_family = none)]
47 pub unsafe fn pastDiagnosticPayloads(&self) -> Retained<NSArray<MXDiagnosticPayload>>;
48
49 /// Singleton instance of MXMetricManager.
50 #[unsafe(method(sharedManager))]
51 #[unsafe(method_family = none)]
52 pub unsafe fn sharedManager() -> Retained<MXMetricManager>;
53
54 /// Adds a subscriber to the metric manager.
55 ///
56 /// Parameter `subscriber`: An object that conforms to the MXMetricManagerSubscriber protocol.
57 ///
58 /// Subscribers can receive metric payloads by conforming to the MXMetricManagerSubscriber protocol.
59 #[unsafe(method(addSubscriber:))]
60 #[unsafe(method_family = none)]
61 pub unsafe fn addSubscriber(
62 &self,
63 subscriber: &ProtocolObject<dyn MXMetricManagerSubscriber>,
64 );
65
66 /// Removes a subscriber from the metric manager.
67 ///
68 /// Parameter `subscriber`: An object that conforms to the MXMetricManagerSubscriber protocol.
69 ///
70 /// The subscriber indicated, if previously registered, will no longer receive metric payloads.
71 #[unsafe(method(removeSubscriber:))]
72 #[unsafe(method_family = none)]
73 pub unsafe fn removeSubscriber(
74 &self,
75 subscriber: &ProtocolObject<dyn MXMetricManagerSubscriber>,
76 );
77
78 /// Start measuring an extended launch task with the given task id.
79 ///
80 /// This method tracks extra setup tasks required to make the application perceived as fully launched, such as loading up content from the disk or refreshing data from the network, rendering images, etc.
81 ///
82 /// The first task needs to start before or during
83 /// `UISceneDelegate.scene(_:restoreInteractionStateWith:)`or before
84 /// `UISceneDelegate.sceneDidBecomeActive(_:)`is called on the first scene to connect. For example, at the time
85 /// `UIApplicationDelegate.application(_:didFinishLaunchingWithOptions:)`is called. Other tasks need to start before the last current task is finished, otherwise the extended launch measurement will end.
86 ///
87 /// The maximum number of tasks is 16.
88 ///
89 /// This method needs to be called on the main thread.
90 ///
91 /// Parameter `taskID`: The task identifier. Must be an unique nonnull custom string.
92 ///
93 /// Parameter `error`: If an error occurs, this will contain a valid
94 /// `NSError`object on exit.
95 ///
96 /// Returns: Returns
97 /// `YES`if the measurement started successfully and
98 /// `NO`otherwise.
99 #[unsafe(method(extendLaunchMeasurementForTaskID:error:_))]
100 #[unsafe(method_family = none)]
101 pub unsafe fn extendLaunchMeasurementForTaskID_error(
102 task_id: &MXLaunchTaskID,
103 ) -> Result<(), Retained<NSError>>;
104
105 /// Signal the end of an extended launch task previously started with
106 /// `extendLaunchMeasurementForTaskID:error:`.
107 ///
108 /// This method needs to be called on the main thread.
109 ///
110 /// Parameter `taskID`: The task identifier. Must match the task identifier passed to
111 /// `extendLaunchMeasurementForTaskID:error:`.
112 ///
113 /// Parameter `error`: If an error occurs, this will contain a valid
114 /// `NSError`object on exit.
115 ///
116 /// Returns: Returns
117 /// `YES`if the measurement for the task finished successfully and
118 /// `NO`otherwise.
119 #[unsafe(method(finishExtendedLaunchMeasurementForTaskID:error:_))]
120 #[unsafe(method_family = none)]
121 pub unsafe fn finishExtendedLaunchMeasurementForTaskID_error(
122 task_id: &MXLaunchTaskID,
123 ) -> Result<(), Retained<NSError>>;
124 );
125}
126
127/// Methods declared on superclass `NSObject`.
128impl MXMetricManager {
129 extern_methods!(
130 #[unsafe(method(init))]
131 #[unsafe(method_family = init)]
132 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
133
134 #[unsafe(method(new))]
135 #[unsafe(method_family = new)]
136 pub unsafe fn new() -> Retained<Self>;
137 );
138}
139
140extern_protocol!(
141 /// A protocol that allows the conforming object to receive metric payloads from the metric manager.
142 ///
143 /// In order to receive metric payloads, atleast one object must conform to this protocol and be subscribed to the metric manager.
144 ///
145 /// Objects which conform to this protocol can be passed to addSubscriber:subscriber and removeSubscriber:subscriber to manage their subscription state.
146 ///
147 /// See also [Apple's documentation](https://developer.apple.com/documentation/metrickit/mxmetricmanagersubscriber?language=objc)
148 pub unsafe trait MXMetricManagerSubscriber: NSObjectProtocol {
149 #[cfg(feature = "MXMetricPayload")]
150 /// This method is invoked when a new MXMetricPayload has been received.
151 ///
152 /// Parameter `payloads`: An NSArray of MXMetricPayload objects. This array of payloads contains data from previous usage sessions.
153 ///
154 /// You can expect for this method to be invoked atleast once per day when the app is running and subscribers are available.
155 ///
156 /// If no subscribers are available, this method will not be invoked.
157 ///
158 /// Atleast one subscriber must be available to receive metrics.
159 ///
160 /// This method is invoked on a background queue.
161 #[optional]
162 #[unsafe(method(didReceiveMetricPayloads:))]
163 #[unsafe(method_family = none)]
164 unsafe fn didReceiveMetricPayloads(&self, payloads: &NSArray<MXMetricPayload>);
165
166 #[cfg(feature = "MXDiagnosticPayload")]
167 /// This method is invoked when a new MXDiagnosticPayload has been received.
168 ///
169 /// Parameter `payloads`: An NSArray of MXDiagnosticPayload objects. This array of payloads contains diagnostics from previous usage sessions.
170 ///
171 /// You can expect for this method to be invoked atleast once per day when the app is running and subscribers are available.
172 ///
173 /// If no subscribers are available, this method will not be invoked.
174 ///
175 /// Atleast one subscriber must be available to receive diagnostics.
176 ///
177 /// This method is invoked on a background queue.
178 #[optional]
179 #[unsafe(method(didReceiveDiagnosticPayloads:))]
180 #[unsafe(method_family = none)]
181 unsafe fn didReceiveDiagnosticPayloads(&self, payloads: &NSArray<MXDiagnosticPayload>);
182 }
183);