1 <?xml version='1.0'?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
6 This file is part of elogind.
8 Copyright 2015 Lennart Poettering
10 elogind is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
15 elogind is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public License
21 along with elogind; If not, see <http://www.gnu.org/licenses/>.
24 <refentry id="sd_event_source_set_prepare" xmlns:xi="http://www.w3.org/2001/XInclude">
27 <title>sd_event_source_set_prepare</title>
28 <productname>elogind</productname>
32 <contrib>Developer</contrib>
33 <firstname>Lennart</firstname>
34 <surname>Poettering</surname>
35 <email>lennart@poettering.net</email>
41 <refentrytitle>sd_event_source_set_prepare</refentrytitle>
42 <manvolnum>3</manvolnum>
46 <refname>sd_event_source_set_prepare</refname>
48 <refpurpose>Set a preparation callback for event sources</refpurpose>
53 <funcsynopsisinfo>#include <elogind/sd-event.h></funcsynopsisinfo>
56 <funcdef>int <function>sd_event_source_set_prepare</function></funcdef>
57 <paramdef>sd_event_source *<parameter>source</parameter></paramdef>
58 <paramdef>sd_event_handler_t <parameter>callback</parameter></paramdef>
62 <funcdef>typedef int (*<function>sd_event_handler_t</function>)</funcdef>
63 <paramdef>sd_event_source *<parameter>s</parameter></paramdef>
64 <paramdef>void *<parameter>userdata</parameter></paramdef>
71 <title>Description</title>
73 <para><function>sd_event_source_set_prepare()</function> may be
74 used to set a preparation callback for the event source object
75 specified as <parameter>source</parameter>. The callback function
76 specified as <parameter>callback</parameter> will be invoked
77 immediately before the event loop goes to sleep to wait for
78 incoming events. It is invoked with the user data pointer passed
79 when the event source was created. The event source will be disabled
80 if the callback function returns a negative error code. The callback
81 function may be used to reconfigure the precise events to wait for.
82 If the <parameter>callback</parameter> parameter is passed as NULL
83 the callback function is reset. </para>
85 <para>Event source objects have no preparation callback associated
86 when they are first created with calls such as
87 <citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
88 <citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry>. Preparation
89 callback functions are supported for all event source types with
90 the exception of those created with
91 <citerefentry><refentrytitle>sd_event_add_exit</refentrytitle><manvolnum>3</manvolnum></citerefentry>. Preparation
92 callback functions are dispatched in the order indicated by the
93 event source's priority field, as set with
94 <citerefentry><refentrytitle>sd_event_source_set_priority</refentrytitle><manvolnum>3</manvolnum></citerefentry>. Preparation
95 callbacks of disabled event sources (see
96 <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>)
97 are not invoked.</para>
101 <title>Return Value</title>
104 <function>sd_event_source_set_prepare()</function> returns a
105 non-negative integer. On failure, it returns a negative
106 errno-style error code.</para>
110 <title>Errors</title>
112 <para>Returned errors may indicate the following problems:</para>
116 <term><constant>-EINVAL</constant></term>
118 <listitem><para><parameter>source</parameter> is not a valid
119 pointer to an <structname>sd_event_source</structname>
120 object.</para></listitem>
124 <term><constant>-ESTALE</constant></term>
126 <listitem><para>The event loop is already terminated.</para></listitem>
130 <term><constant>-ENOMEM</constant></term>
132 <listitem><para>Not enough memory.</para></listitem>
136 <term><constant>-ECHILD</constant></term>
138 <listitem><para>The event loop has been created in a different process.</para></listitem>
143 <term><constant>-EDOM</constant></term>
145 <listitem><para>The specified event source has been created
147 <citerefentry><refentrytitle>sd_event_add_exit</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para></listitem>
154 <xi:include href="libelogind-pkgconfig.xml" />
157 <title>See Also</title>
160 <citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
161 <citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
162 <citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
163 <citerefentry><refentrytitle>sd_event_add_child</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
164 <citerefentry><refentrytitle>sd_event_add_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
165 <citerefentry><refentrytitle>sd_event_add_defer</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
166 <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
167 <citerefentry><refentrytitle>sd_event_source_set_priority</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
168 <citerefentry><refentrytitle>sd_event_source_set_userdata</refentrytitle><manvolnum>3</manvolnum></citerefentry>