···11-#ifndef __XPC_ACTIVITY_H__
22-#define __XPC_ACTIVITY_H__
33-44-#ifndef __XPC_INDIRECT__
55-#error "Please #include <xpc/xpc.h> instead of this file directly."
66-// For HeaderDoc.
77-#include <xpc/base.h>
88-#endif // __XPC_INDIRECT__
99-1010-#ifdef __BLOCKS__
1111-1212-__BEGIN_DECLS
1313-1414-/*
1515- * The following are a collection of keys and values used to set an activity's
1616- * execution criteria.
1717- */
1818-1919-/*!
2020- * @constant XPC_ACTIVITY_INTERVAL
2121- * An integer property indicating the desired time interval (in seconds) of the
2222- * activity. The activity will not be run more than once per time interval.
2323- * Due to the nature of XPC Activity finding an opportune time to run
2424- * the activity, any two occurrences may be more or less than 'interval'
2525- * seconds apart, but on average will be 'interval' seconds apart.
2626- * The presence of this key implies the following, unless overridden:
2727- * - XPC_ACTIVITY_REPEATING with a value of true
2828- * - XPC_ACTIVITY_DELAY with a value of half the 'interval'
2929- * The delay enforces a minimum distance between any two occurrences.
3030- * - XPC_ACTIVITY_GRACE_PERIOD with a value of half the 'interval'.
3131- * The grace period is the amount of time allowed to pass after the end of
3232- * the interval before more aggressive scheduling occurs. The grace period
3333- * does not increase the size of the interval.
3434- */
3535-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
3636-XPC_EXPORT
3737-const char *XPC_ACTIVITY_INTERVAL;
3838-3939-/*!
4040- * @constant XPC_ACTIVITY_REPEATING
4141- * A boolean property indicating whether this is a repeating activity.
4242- */
4343-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
4444-XPC_EXPORT
4545-const char *XPC_ACTIVITY_REPEATING;
4646-4747-/*!
4848- * @constant XPC_ACTIVITY_DELAY
4949- * An integer property indicating the number of seconds to delay before
5050- * beginning the activity.
5151- */
5252-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
5353-XPC_EXPORT
5454-const char *XPC_ACTIVITY_DELAY;
5555-5656-/*!
5757- * @constant XPC_ACTIVITY_GRACE_PERIOD
5858- * An integer property indicating the number of seconds to allow as a grace
5959- * period before the scheduling of the activity becomes more aggressive.
6060- */
6161-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
6262-XPC_EXPORT
6363-const char *XPC_ACTIVITY_GRACE_PERIOD;
6464-6565-6666-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
6767-XPC_EXPORT
6868-const int64_t XPC_ACTIVITY_INTERVAL_1_MIN;
6969-7070-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
7171-XPC_EXPORT
7272-const int64_t XPC_ACTIVITY_INTERVAL_5_MIN;
7373-7474-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
7575-XPC_EXPORT
7676-const int64_t XPC_ACTIVITY_INTERVAL_15_MIN;
7777-7878-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
7979-XPC_EXPORT
8080-const int64_t XPC_ACTIVITY_INTERVAL_30_MIN;
8181-8282-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
8383-XPC_EXPORT
8484-const int64_t XPC_ACTIVITY_INTERVAL_1_HOUR;
8585-8686-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
8787-XPC_EXPORT
8888-const int64_t XPC_ACTIVITY_INTERVAL_4_HOURS;
8989-9090-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
9191-XPC_EXPORT
9292-const int64_t XPC_ACTIVITY_INTERVAL_8_HOURS;
9393-9494-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
9595-XPC_EXPORT
9696-const int64_t XPC_ACTIVITY_INTERVAL_1_DAY;
9797-9898-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
9999-XPC_EXPORT
100100-const int64_t XPC_ACTIVITY_INTERVAL_7_DAYS;
101101-102102-/*!
103103- * @constant XPC_ACTIVITY_PRIORITY
104104- * A string property indicating the priority of the activity.
105105- */
106106-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
107107-XPC_EXPORT
108108-const char *XPC_ACTIVITY_PRIORITY;
109109-110110-/*!
111111- * @constant XPC_ACTIVITY_PRIORITY_MAINTENANCE
112112- * A string indicating activity is maintenance priority.
113113- * Maintenance priority is intended for user-invisible maintenance tasks
114114- * such as garbage collection or optimization.
115115- */
116116-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
117117-XPC_EXPORT
118118-const char *XPC_ACTIVITY_PRIORITY_MAINTENANCE;
119119-120120-/*!
121121- * @constant XPC_ACTIVITY_PRIORITY_UTILITY
122122- * A string indicating activity is utility priority.
123123- * Utility priority is intended for user-visible tasks such as fetching data
124124- * from the network, copying files, or importing data.
125125- */
126126-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
127127-XPC_EXPORT
128128-const char *XPC_ACTIVITY_PRIORITY_UTILITY;
129129-130130-/*!
131131- * @constant XPC_ACTIVITY_ALLOW_BATTERY
132132- * A Boolean value indicating whether the activity should be allowed to run
133133- * while the computer is on battery power. The default value is false for
134134- * maintenance priority activity and true for utility priority activity.
135135- */
136136-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
137137-XPC_EXPORT
138138-const char *XPC_ACTIVITY_ALLOW_BATTERY;
139139-140140-/*!
141141- * @constant XPC_ACTIVITY_REQUIRE_SCREEN_SLEEP
142142- * A Boolean value indicating whether the activity should only be performed
143143- * while the primary screen is in sleep mode. Defaults to false.
144144- */
145145-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
146146-XPC_EXPORT
147147-const char *XPC_ACTIVITY_REQUIRE_SCREEN_SLEEP; // bool
148148-149149-/*!
150150- * @constant XPC_ACTIVITY_REQUIRE_BATTERY_LEVEL
151151- * An integer percentage of minimum battery charge required to allow the
152152- * activity to run. A default minimum battery level is determined by the
153153- * system.
154154- */
155155-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
156156-XPC_EXPORT
157157-const char *XPC_ACTIVITY_REQUIRE_BATTERY_LEVEL; // int (%)
158158-159159-/*!
160160- * @constant XPC_ACTIVITY_REQUIRE_HDD_SPINNING
161161- * A Boolean value indicating whether the activity should only be performed
162162- * while the hard disk drive (HDD) is spinning. Computers with flash storage
163163- * are considered to be equivalent to HDD spinning. Defaults to false.
164164- */
165165-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
166166-XPC_EXPORT
167167-const char *XPC_ACTIVITY_REQUIRE_HDD_SPINNING; // bool
168168-169169-/*!
170170- * @define XPC_TYPE_ACTIVITY
171171- * A type representing a connection to a named service. This connection is
172172- * bidirectional and can be used to both send and receive messages. A
173173- * connection carries the credentials of the remote service provider.
174174- */
175175-#define XPC_TYPE_ACTIVITY (&_xpc_type_activity)
176176-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
177177-XPC_EXPORT
178178-XPC_TYPE(_xpc_type_activity);
179179-180180-/*!
181181- * @typedef xpc_activity_t
182182- *
183183- * @abstract
184184- * An XPC activity object.
185185- *
186186- * @discussion
187187- * This object represents a set of execution criteria and a current execution
188188- * state for background activity on the system. Once an activity is registered,
189189- * the system will evaluate its criteria to determine whether the activity is
190190- * eligible to run under current system conditions. When an activity becomes
191191- * eligible to run, its execution state will be updated and an invocation of
192192- * its handler block will be made.
193193- */
194194-XPC_DECL(xpc_activity);
195195-196196-/*!
197197- * @typedef xpc_activity_handler_t
198198- *
199199- * @abstract
200200- * A block that is called when an XPC activity becomes eligible to run.
201201- */
202202-typedef void (^xpc_activity_handler_t)(xpc_activity_t activity);
203203-204204-/*!
205205- * @constant XPC_ACTIVITY_CHECK_IN
206206- * This constant may be passed to xpc_activity_register() as the criteria
207207- * dictionary in order to check in with the system for previously registered
208208- * activity using the same identifier (for example, an activity taken from a
209209- * launchd property list).
210210- */
211211-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
212212-XPC_EXPORT
213213-const xpc_object_t XPC_ACTIVITY_CHECK_IN;
214214-215215-/*!
216216- * @function xpc_activity_register
217217- *
218218- * @abstract
219219- * Registers an activity with the system.
220220- *
221221- * @discussion
222222- * Registers a new activity with the system. The criteria of the activity are
223223- * described by the dictionary passed to this function. If an activity with the
224224- * same identifier already exists, the criteria provided override the existing
225225- * criteria unless the special dictionary XPC_ACTIVITY_CHECK_IN is used. The
226226- * XPC_ACTIVITY_CHECK_IN dictionary instructs the system to first look up an
227227- * existing activity without modifying its criteria. Once the existing activity
228228- * is found (or a new one is created with an empty set of criteria) the handler
229229- * will be called with an activity object in the XPC_ACTIVITY_STATE_CHECK_IN
230230- * state.
231231- *
232232- * @param identifier
233233- * A unique identifier for the activity. Each application has its own namespace.
234234- * The identifier should remain constant across registrations, relaunches of
235235- * the application, and reboots. It should identify the kind of work being done,
236236- * not a particular invocation of the work.
237237- *
238238- * @param criteria
239239- * A dictionary of criteria for the activity.
240240- *
241241- * @param handler
242242- * The handler block to be called when the activity changes state to one of the
243243- * following states:
244244- * - XPC_ACTIVITY_STATE_CHECK_IN (optional)
245245- * - XPC_ACTIVITY_STATE_RUN
246246- *
247247- * The handler block is never invoked reentrantly. It will be invoked on a
248248- * dispatch queue with an appropriate priority to perform the activity.
249249- */
250250-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
251251-XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2 XPC_NONNULL3
252252-void
253253-xpc_activity_register(const char *identifier, xpc_object_t criteria,
254254- xpc_activity_handler_t handler);
255255-256256-/*!
257257- * @function xpc_activity_copy_criteria
258258- *
259259- * @abstract
260260- * Returns an XPC dictionary describing the execution criteria of an activity.
261261- * This will return NULL in cases where the activity has already completed, e.g.
262262- * when checking in to an event that finished and was not rescheduled.
263263- */
264264-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
265265-XPC_EXPORT XPC_WARN_RESULT XPC_RETURNS_RETAINED
266266-xpc_object_t
267267-xpc_activity_copy_criteria(xpc_activity_t activity);
268268-269269-/*!
270270- * @function xpc_activity_set_criteria
271271- *
272272- * @abstract
273273- * Modifies the execution criteria of an activity.
274274- */
275275-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
276276-XPC_EXPORT XPC_NONNULL1 XPC_NONNULL2
277277-void
278278-xpc_activity_set_criteria(xpc_activity_t activity, xpc_object_t criteria);
279279-280280-/*!
281281- * @enum xpc_activity_state_t
282282- * An activity is defined to be in one of the following states. Applications
283283- * may check the current state of the activity using xpc_activity_get_state()
284284- * in the handler block provided to xpc_activity_register().
285285- *
286286- * The application can modify the state of the activity by calling
287287- * xpc_activity_set_state() with one of the following:
288288- * - XPC_ACTIVITY_STATE_DEFER
289289- * - XPC_ACTIVITY_STATE_CONTINUE
290290- * - XPC_ACTIVITY_STATE_DONE
291291- *
292292- * @constant XPC_ACTIVITY_STATE_CHECK_IN
293293- * An activity in this state has just completed a checkin with the system after
294294- * XPC_ACTIVITY_CHECK_IN was provided as the criteria dictionary to
295295- * xpc_activity_register. The state gives the application an opportunity to
296296- * inspect and modify the activity's criteria.
297297- *
298298- * @constant XPC_ACTIVITY_STATE_WAIT
299299- * An activity in this state is waiting for an opportunity to run. This value
300300- * is never returned within the activity's handler block, as the block is
301301- * invoked in response to XPC_ACTIVITY_STATE_CHECK_IN or XPC_ACTIVITY_STATE_RUN.
302302- *
303303- * Note:
304304- * A launchd job may idle exit while an activity is in the wait state and be
305305- * relaunched in response to the activity becoming runnable. The launchd job
306306- * simply needs to re-register for the activity on its next launch by passing
307307- * XPC_ACTIVITY_STATE_CHECK_IN to xpc_activity_register().
308308- *
309309- * @constant XPC_ACTIVITY_STATE_RUN
310310- * An activity in this state is eligible to run based on its criteria.
311311- *
312312- * @constant XPC_ACTIVITY_STATE_DEFER
313313- * An application may pass this value to xpc_activity_set_state() to indicate
314314- * that the activity should be deferred (placed back into the WAIT state) until
315315- * a time when its criteria are met again. Deferring an activity does not reset
316316- * any of its time-based criteria (in other words, it will remain past due).
317317- *
318318- * IMPORTANT:
319319- * This should be done in response to observing xpc_activity_should_defer().
320320- * It should not be done unilaterally. If you determine that conditions are bad
321321- * to do your activity's work for reasons you can't express in a criteria
322322- * dictionary, you should set the activity's state to XPC_ACTIVITY_STATE_DONE.
323323- *
324324- *
325325- * @constant XPC_ACTIVITY_STATE_CONTINUE
326326- * An application may pass this value to xpc_activity_set_state() to indicate
327327- * that the activity will continue its operation beyond the return of its
328328- * handler block. This can be used to extend an activity to include asynchronous
329329- * operations. The activity's handler block will not be invoked again until the
330330- * state has been updated to either XPC_ACTIVITY_STATE_DEFER or, in the case
331331- * of repeating activity, XPC_ACTIVITY_STATE_DONE.
332332- *
333333- * @constant XPC_ACTIVITY_STATE_DONE
334334- * An application may pass this value to xpc_activity_set_state() to indicate
335335- * that the activity has completed. For non-repeating activity, the resources
336336- * associated with the activity will be automatically released upon return from
337337- * the handler block. For repeating activity, timers present in the activity's
338338- * criteria will be reset.
339339- */
340340-enum {
341341- XPC_ACTIVITY_STATE_CHECK_IN,
342342- XPC_ACTIVITY_STATE_WAIT,
343343- XPC_ACTIVITY_STATE_RUN,
344344- XPC_ACTIVITY_STATE_DEFER,
345345- XPC_ACTIVITY_STATE_CONTINUE,
346346- XPC_ACTIVITY_STATE_DONE,
347347-};
348348-typedef long xpc_activity_state_t;
349349-350350-/*!
351351- * @function xpc_activity_get_state
352352- *
353353- * @abstract
354354- * Returns the current state of an activity.
355355- */
356356-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
357357-XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1
358358-xpc_activity_state_t
359359-xpc_activity_get_state(xpc_activity_t activity);
360360-361361-/*!
362362- * @function xpc_activity_set_state
363363- *
364364- * @abstract
365365- * Updates the current state of an activity.
366366- *
367367- * @return
368368- * Returns true if the state was successfully updated; otherwise, returns
369369- * false if the requested state transition is not valid.
370370- */
371371-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
372372-XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL1
373373-bool
374374-xpc_activity_set_state(xpc_activity_t activity, xpc_activity_state_t state);
375375-376376-/*!
377377- * @function xpc_activity_should_defer
378378- *
379379- * @abstract
380380- * Test whether an activity should be deferred.
381381- *
382382- * @discussion
383383- * This function may be used to test whether the criteria of a long-running
384384- * activity are still satisfied. If not, the system indicates that the
385385- * application should defer the activity. The application may acknowledge the
386386- * deferral by calling xpc_activity_set_state() with XPC_ACTIVITY_STATE_DEFER.
387387- * Once deferred, the system will place the activity back into the WAIT state
388388- * and re-invoke the handler block at the earliest opportunity when the criteria
389389- * are once again satisfied.
390390- *
391391- * @return
392392- * Returns true if the activity should be deferred.
393393- */
394394-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
395395-XPC_EXPORT
396396-bool
397397-xpc_activity_should_defer(xpc_activity_t activity);
398398-399399-/*!
400400- * @function xpc_activity_unregister
401401- *
402402- * @abstract
403403- * Unregisters an activity found by its identifier.
404404- *
405405- * @discussion
406406- * A dynamically registered activity will be deleted in response to this call.
407407- * Statically registered activity (from a launchd property list) will be
408408- * reverted to its original criteria if any modifications were made.
409409- *
410410- * Unregistering an activity has no effect on any outstanding xpc_activity_t
411411- * objects or any currently executing xpc_activity_handler_t blocks; however,
412412- * no new handler block invocations will be made after it is unregistered.
413413- *
414414- * @param identifier
415415- * The identifier of the activity to unregister.
416416- */
417417-__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0)
418418-XPC_EXPORT XPC_NONNULL1
419419-void
420420-xpc_activity_unregister(const char *identifier);
421421-422422-__END_DECLS
423423-424424-#endif // __BLOCKS__
425425-426426-#endif // __XPC_ACTIVITY_H__
427427-11+../../src/external/libxpc/xpc/activity.h