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.
7 SPDX-License-Identifier: LGPL-2.1+
10 Copyright 2015 Lennart Poettering
13 <refentry id="sd_event_source_set_enabled" xmlns:xi="http://www.w3.org/2001/XInclude">
16 <title>sd_event_source_set_enabled</title>
17 <productname>elogind</productname>
21 <contrib>Developer</contrib>
22 <firstname>Lennart</firstname>
23 <surname>Poettering</surname>
24 <email>lennart@poettering.net</email>
30 <refentrytitle>sd_event_source_set_enabled</refentrytitle>
31 <manvolnum>3</manvolnum>
35 <refname>sd_event_source_set_enabled</refname>
36 <refname>sd_event_source_get_enabled</refname>
37 <refname>SD_EVENT_ON</refname>
38 <refname>SD_EVENT_OFF</refname>
39 <refname>SD_EVENT_ONESHOT</refname>
41 <refpurpose>Enable or disable event sources</refpurpose>
46 <funcsynopsisinfo>#include <elogind/sd-event.h></funcsynopsisinfo>
48 <funcsynopsisinfo><token>enum</token> {
49 <constant>SD_EVENT_OFF</constant> = 0,
50 <constant>SD_EVENT_ON</constant> = 1,
51 <constant>SD_EVENT_ONESHOT</constant> = -1,
55 <funcdef>int <function>sd_event_source_set_enabled</function></funcdef>
56 <paramdef>sd_event_source *<parameter>source</parameter></paramdef>
57 <paramdef>int <parameter>enabled</parameter></paramdef>
61 <funcdef>int <function>sd_event_source_get_enabled</function></funcdef>
62 <paramdef>sd_event_source *<parameter>source</parameter></paramdef>
63 <paramdef>int *<parameter>enabled</parameter></paramdef>
70 <title>Description</title>
72 <para><function>sd_event_source_set_enabled()</function> may be
73 used to enable or disable the event source object specified as
74 <parameter>source</parameter>. The <parameter>enabled</parameter>
75 parameter takes one of <constant>SD_EVENT_ON</constant> (to
76 enable), <constant>SD_EVENT_OFF</constant> (to disable) or
77 <constant>SD_EVENT_ONESHOT</constant>. If invoked with
78 <constant>SD_EVENT_ONESHOT</constant> the event source will be
79 enabled but automatically reset to
80 <constant>SD_EVENT_OFF</constant> after the event source was
81 dispatched once.</para>
83 <para>Event sources that are disabled will not result in event
84 loop wakeups and will not be dispatched, until they are enabled
87 <para><function>sd_event_source_get_enabled()</function> may be
88 used to query whether the event source object
89 <parameter>source</parameter> is currently enabled or not. It
90 returns the enablement state in
91 <parameter>enabled</parameter>.</para>
93 <para>Event source objects are enabled when they are first created
95 <citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
96 <citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry>. However,
97 depending on the event source type they are enabled continuously
98 (<constant>SD_EVENT_ON</constant>) or only for a single invocation
99 of the event source handler
100 (<constant>SD_EVENT_ONESHOT</constant>). For details see the
101 respective manual pages.</para>
103 <para>As event source objects stay active and may be dispatched as
104 long as there is at least one reference to them, in many cases it
105 is a good idea to combine a call to
106 <citerefentry><refentrytitle>sd_event_source_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>
108 <function>sd_event_source_set_enabled()</function> with
109 <constant>SD_EVENT_OFF</constant>, to ensure the event source is
110 not dispatched again until all other remaining references are dropped.</para>
114 <title>Return Value</title>
116 <para>On success, <function>sd_event_source_set_enabled()</function> and
117 <function>sd_event_source_get_enabled()</function> return a
118 non-negative integer. On failure, they return a negative
119 errno-style error code.</para>
123 <title>Errors</title>
125 <para>Returned errors may indicate the following problems:</para>
129 <term><constant>-EINVAL</constant></term>
131 <listitem><para><parameter>source</parameter> is not a valid
132 pointer to an <structname>sd_event_source</structname>
133 object.</para></listitem>
137 <term><constant>-ENOMEM</constant></term>
139 <listitem><para>Not enough memory.</para></listitem>
143 <term><constant>-ECHILD</constant></term>
145 <listitem><para>The event loop has been created in a different process.</para></listitem>
152 <xi:include href="libelogind-pkgconfig.xml" />
155 <title>See Also</title>
158 <citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
159 <citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
160 <citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
161 <citerefentry><refentrytitle>sd_event_add_child</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
162 <citerefentry><refentrytitle>sd_event_add_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
163 <citerefentry><refentrytitle>sd_event_add_defer</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
164 <citerefentry><refentrytitle>sd_event_source_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>