2 * Copyright (C) 2018, 2019 "IoT.bzh"
3 * Author José Bollo <jose.bollo@iot.bzh>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 #include <systemd/sd-event.h>
24 #include "fdev-systemd.h"
26 static int handler(sd_event_source *s, int fd, uint32_t revents, void *userdata)
28 struct fdev *fdev = userdata;
29 fdev_dispatch(fdev, revents);
33 static void unref(void *closure)
35 sd_event_source *source = closure;
36 sd_event_source_unref(source);
39 static void disable(void *closure, const struct fdev *fdev)
41 sd_event_source *source = closure;
42 sd_event_source_set_enabled(source, SD_EVENT_OFF);
45 static void enable(void *closure, const struct fdev *fdev)
47 sd_event_source *source = closure;
48 sd_event_source_set_io_events(source, fdev_events(fdev));
49 sd_event_source_set_enabled(source, SD_EVENT_ON);
52 static struct fdev_itf itf =
60 struct fdev *fdev_systemd_create(struct sd_event *eloop, int fd)
63 sd_event_source *source;
66 fdev = fdev_create(fd);
68 rc = sd_event_add_io(eloop, &source, fd, 0, handler, fdev);
74 sd_event_source_set_enabled(source, SD_EVENT_OFF);
75 fdev_set_itf(fdev, &itf, source);