Beispiel #1
0
Datei: pty.c Projekt: myra/kmscon
int kmscon_pty_new(struct kmscon_pty **out, struct ev_eloop *loop,
				kmscon_pty_input_cb input_cb, void *data)
{
	struct kmscon_pty *pty;
	int ret;

	if (!out || !loop || !input_cb)
		return -EINVAL;

	pty = malloc(sizeof(*pty));
	if (!pty)
		return -ENOMEM;

	memset(pty, 0, sizeof(*pty));
	pty->fd = -1;
	pty->ref = 1;
	pty->eloop = loop;
	pty->input_cb = input_cb;
	pty->data = data;

	ret = kmscon_ring_new(&pty->msgbuf);
	if (ret)
		goto err_free;

	log_debug("new pty object");
	ev_eloop_ref(pty->eloop);
	*out = pty;
	return 0;

err_free:
	free(pty);
	return ret;
}
Beispiel #2
0
Datei: vt.c Projekt: myra/kmscon
static int connect_eloop(struct kmscon_vt *vt, struct ev_eloop *eloop)
{
	int ret;

	if (!vt || !eloop || vt->fd < 0)
		return -EINVAL;

	ret = ev_eloop_register_signal_cb(eloop, SIGUSR1, vt_leave, vt);
	if (ret)
		return ret;

	ret = ev_eloop_register_signal_cb(eloop, SIGUSR2, vt_enter, vt);
	if (ret)
		goto err_sig1;

	ret = ev_eloop_new_fd(eloop, &vt->efd, vt->fd, EV_READABLE,
				vt_input, vt);
	if (ret)
		goto err_sig2;

	vt->eloop = eloop;
	ev_eloop_ref(vt->eloop);
	return 0;

err_sig2:
	ev_eloop_unregister_signal_cb(vt->eloop, SIGUSR2, vt_enter, vt);
err_sig1:
	ev_eloop_unregister_signal_cb(vt->eloop, SIGUSR1, vt_leave, vt);
	return ret;
}
Beispiel #3
0
SHL_EXPORT
int uterm_video_new(struct uterm_video **out, struct ev_eloop *eloop,
		    const char *node, const struct uterm_video_module *mod)
{
	struct uterm_video *video;
	int ret;

	if (!out || !eloop)
		return -EINVAL;
	if (!mod || !mod->ops)
		return -EOPNOTSUPP;

	video = malloc(sizeof(*video));
	if (!video)
		return -ENOMEM;
	memset(video, 0, sizeof(*video));
	video->ref = 1;
	video->mod = mod;
	video->ops = mod->ops;
	video->eloop = eloop;
	shl_dlist_init(&video->displays);

	ret = shl_hook_new(&video->hook);
	if (ret)
		goto err_free;

	ret = VIDEO_CALL(video->ops->init, 0, video, node);
	if (ret)
		goto err_hook;

	ev_eloop_ref(video->eloop);
	log_info("new device %p", video);
	*out = video;
	return 0;

err_hook:
	shl_hook_free(video->hook);
err_free:
	free(video);
	return ret;
}
Beispiel #4
0
int uterm_vt_master_new(struct uterm_vt_master **out,
			struct ev_eloop *eloop)
{
	struct uterm_vt_master *vtm;

	if (!out || !eloop)
		return -EINVAL;

	vtm = malloc(sizeof(*vtm));
	if (!vtm)
		return -ENOMEM;
	memset(vtm, 0, sizeof(*vtm));
	vtm->ref = 1;
	vtm->eloop = eloop;
	kmscon_dlist_init(&vtm->vts);
	vtm->vt_support = check_vt_support();

	ev_eloop_ref(vtm->eloop);
	*out = vtm;
	return 0;
}
Beispiel #5
0
int uterm_video_new(struct uterm_video **out,
			struct ev_eloop *eloop,
			unsigned int type,
			const char *node)
{
	struct uterm_video *video;
	int ret;
	const struct video_ops *ops;

	if (!out || !eloop)
		return -EINVAL;

	switch (type) {
	case UTERM_VIDEO_DRM:
		if (!drm_available) {
			log_err("DRM backend is not available");
			return -EOPNOTSUPP;
		}
		ops = &drm_video_ops;
		break;
	case UTERM_VIDEO_DUMB:
		if (!dumb_available) {
			log_err("Dumb DRM backend is not available");
			return -EOPNOTSUPP;
		}
		ops = &dumb_video_ops;
		break;
	case UTERM_VIDEO_FBDEV:
		if (!fbdev_available) {
			log_err("FBDEV backend is not available");
			return -EOPNOTSUPP;
		}
		ops = &fbdev_video_ops;
		break;
	default:
		log_err("invalid video backend %d", type);
		return -EINVAL;
	}

	video = malloc(sizeof(*video));
	if (!video)
		return -ENOMEM;
	memset(video, 0, sizeof(*video));
	video->ref = 1;
	video->ops = ops;
	video->eloop = eloop;

	ret = shl_hook_new(&video->hook);
	if (ret)
		goto err_free;

	ret = VIDEO_CALL(video->ops->init, 0, video, node);
	if (ret)
		goto err_hook;

	ev_eloop_ref(video->eloop);
	log_info("new device %p", video);
	*out = video;
	return 0;

err_hook:
	shl_hook_free(video->hook);
err_free:
	free(video);
	return ret;
}