1 /*-
2  * Copyright (c) 2015 Tycho Nightingale <tycho.nightingale@pluribusnetworks.com>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26 
27 
28 #include <stdio.h>
29 #include "gc.h"
30 #include "console.h"
31 
32 static struct {
33 	struct gfx_ctx		*gc;
34 
35 	fb_render_func_t	fb_render_cb;
36 	void			*fb_arg;
37 
38 	kbd_event_func_t	kbd_event_cb;
39 	void			*kbd_arg;
40 	int			kbd_priority;
41 
42 	ptr_event_func_t	ptr_event_cb;
43 	void			*ptr_arg;
44 	int			ptr_priority;
45 } console;
46 
47 struct gfx_ctx_image *
console_get_image(void)48 console_get_image(void)
49 {
50 	struct gfx_ctx_image *image;
51 
52 	image = gc_get_image(console.gc);
53 
54 	return image;
55 }
56 
57 void
console_kbd_register(kbd_event_func_t event_cb,void * arg,int pri)58 console_kbd_register(kbd_event_func_t event_cb, void *arg, int pri)
59 {
60 	if (pri > console.kbd_priority) {
61 		console.kbd_event_cb = event_cb;
62 		console.kbd_arg = arg;
63 		console.kbd_priority = pri;
64 	}
65 }
66 
67 void
console_kbd_unregister(void)68 console_kbd_unregister(void)
69 {
70 	console.kbd_event_cb = NULL;
71 	console.kbd_arg = NULL;
72 	console.kbd_priority = 0;
73 }
74 
75 void
console_ptr_register(ptr_event_func_t event_cb,void * arg,int pri)76 console_ptr_register(ptr_event_func_t event_cb, void *arg, int pri)
77 {
78 	if (pri > console.ptr_priority) {
79 		console.ptr_event_cb = event_cb;
80 		console.ptr_arg = arg;
81 		console.ptr_priority = pri;
82 	}
83 }
84 
85 void
console_ptr_unregister()86 console_ptr_unregister()
87 {
88 	console.ptr_event_cb = NULL;
89 	console.ptr_arg = NULL;
90 	console.ptr_priority = 0;
91 }
92