diff options
author | Vincent Sanders <vince@netsurf-browser.org> | 2009-04-09 15:26:51 +0000 |
---|---|---|
committer | Vincent Sanders <vince@netsurf-browser.org> | 2009-04-09 15:26:51 +0000 |
commit | 6e4ab5b91771e516b3fb80f5692f31a23001d72c (patch) | |
tree | d36c59986fa08d01e0efbec0d4cb66c5f7ffc904 | |
parent | e136ab597105dcbe211ce0a1f49113b4cb14b1ca (diff) | |
download | libnsfb-6e4ab5b91771e516b3fb80f5692f31a23001d72c.tar.gz libnsfb-6e4ab5b91771e516b3fb80f5692f31a23001d72c.tar.bz2 |
add frontend selection and fix finalisation support
svn path=/trunk/libnsfb/; revision=7072
-rw-r--r-- | include/frontend.h | 9 | ||||
-rw-r--r-- | include/libnsfb.h | 24 | ||||
-rw-r--r-- | src/frontend.c | 11 | ||||
-rw-r--r-- | src/libnsfb.c | 5 | ||||
-rw-r--r-- | test/Makefile | 2 | ||||
-rw-r--r-- | test/frontend.c | 38 | ||||
-rw-r--r-- | test/plottest.c | 2 |
7 files changed, 83 insertions, 8 deletions
diff --git a/include/frontend.h b/include/frontend.h index ee76632..5590543 100644 --- a/include/frontend.h +++ b/include/frontend.h @@ -1,4 +1,6 @@ -#include "libnsfb.h" /* exported interface */ +/* libnsfb framebuffer frontend support */ + +#include "libnsfb.h" #include "nsfb.h" /* frontend default options */ @@ -25,7 +27,6 @@ typedef struct nsfb_frontend_rtns_s { void _nsfb_register_frontend(const enum nsfb_frontend_e type, const nsfb_frontend_rtns_t *rtns, const char *name); -nsfb_frontend_rtns_t *nsfb_frontend_get_rtns(enum nsfb_frontend_e type); /* macro which adds a builtin command with no argument limits */ #define NSFB_FRONTEND_DEF(__name, __type, __rtns) \ @@ -33,3 +34,7 @@ nsfb_frontend_rtns_t *nsfb_frontend_get_rtns(enum nsfb_frontend_e type); void __name##_register_frontend(void) { \ _nsfb_register_frontend(__type, __rtns, #__name); \ } + +/* Obtain routines for a frontend */ +nsfb_frontend_rtns_t *nsfb_frontend_get_rtns(enum nsfb_frontend_e type); + diff --git a/include/libnsfb.h b/include/libnsfb.h index 0af8ab3..0869614 100644 --- a/include/libnsfb.h +++ b/include/libnsfb.h @@ -7,7 +7,7 @@ typedef struct nsfb_cursor_s nsfb_cursor_t; typedef struct nsfb_s nsfb_t; typedef uint32_t nsfb_colour_t; -/* bounding box */ +/** bounding box for plotting operations */ typedef struct nsfb_bbox_s { int x0; int y0; @@ -17,8 +17,8 @@ typedef struct nsfb_bbox_s { /** The type of frontend for a framebuffer context. */ enum nsfb_frontend_e { - NSFB_FRONTEND_NONE = 0, /* Empty frontend. */ - NSFB_FRONTEND_SDL, + NSFB_FRONTEND_NONE = 0, /**< Empty frontend. */ + NSFB_FRONTEND_SDL, /**< SDL frontend */ NSFB_FRONTEND_LINUX, NSFB_FRONTEND_VNC, NSFB_FRONTEND_ABLE, @@ -33,12 +33,28 @@ enum nsfb_frontend_e { */ nsfb_t *nsfb_init(enum nsfb_frontend_e frontend); +/** Finalise nsfb. + * + * This shuts down and releases all resources associated with an nsfb context. + * + * @param nsfb The context returned from ::nsfb_init tofinalise + */ +int nsfb_finalise(nsfb_t *nsfb); + /** Initialise selected frontend. * - * @param nsfb The context frturned from ::nsfb_init + * @param nsfb The context returned from ::nsfb_init */ int nsfb_init_frontend(nsfb_t *nsfb); +/** Select frontend type from a name. + * + * @param name The name to select a frontend. + * @return The frontend type or NSFB_FRONTEND_NONE if frontend with specified + * name was not available + */ +enum nsfb_frontend_e nsfb_frontend_from_name(const char *name); + /** Process input from a frontend. */ int nsfb_input(nsfb_t *nsfb); diff --git a/src/frontend.c b/src/frontend.c index c6f266e..efc1d58 100644 --- a/src/frontend.c +++ b/src/frontend.c @@ -96,3 +96,14 @@ nsfb_frontend_rtns_t *nsfb_frontend_get_rtns(enum nsfb_frontend_e type) } return rtns; } + +enum nsfb_frontend_e nsfb_frontend_from_name(const char *name) +{ + int fend_loop; + + for (fend_loop = 0; fend_loop < frontend_count; fend_loop++) { + if (strcmp(frontends[fend_loop].name, name) == 0) + return frontends[fend_loop].type; + } + return NSFB_FRONTEND_NONE; +} diff --git a/src/libnsfb.c b/src/libnsfb.c index ec6ba86..f5c4ca5 100644 --- a/src/libnsfb.c +++ b/src/libnsfb.c @@ -27,6 +27,11 @@ nsfb_init(const enum nsfb_frontend_e frontend_type) return newfb; } +int nsfb_finalise(nsfb_t *nsfb) +{ + return nsfb->frontend_rtns->finalise(nsfb); +} + int nsfb_init_frontend(nsfb_t *nsfb) diff --git a/test/Makefile b/test/Makefile index e027ba0..6d4f4fa 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,3 +1,3 @@ -DIR_TEST_ITEMS := plottest:plottest.c;nsglobe.c +DIR_TEST_ITEMS := plottest:plottest.c;nsglobe.c frontend:frontend.c include build/makefiles/Makefile.subdir diff --git a/test/frontend.c b/test/frontend.c new file mode 100644 index 0000000..bdc8d67 --- /dev/null +++ b/test/frontend.c @@ -0,0 +1,38 @@ +#include <stdio.h> +#include <stdbool.h> +#include <stdlib.h> + +#include "libnsfb.h" +int main(int argc, char **argv) +{ + nsfb_t *nsfb; + const char *fename; + enum nsfb_frontend_e fetype; + + if (argc < 2) { + fename="sdl"; + } else { + fename = argv[1]; + } + + fetype = nsfb_frontend_from_name(fename); + if (fetype == NSFB_FRONTEND_NONE) { + fprintf(stderr, "Unable to initialise nsfb with %s frontend\n", fename); + return 1; + } + + nsfb = nsfb_init(fetype); + if (nsfb == NULL) { + fprintf(stderr, "Unable to initialise nsfb with %s frontend\n", fename); + return 2; + } + + if (nsfb_init_frontend(nsfb) == -1) { + fprintf(stderr, "Unable to initialise nsfb frontend\n"); + nsfb_finalise(nsfb); + return 3; + } + + nsfb_finalise(nsfb); + return 0; +} diff --git a/test/plottest.c b/test/plottest.c index f2008fa..dc469f6 100644 --- a/test/plottest.c +++ b/test/plottest.c @@ -86,7 +86,7 @@ int main(int argc, char **argv) if (nsfb_init_frontend(nsfb) == -1) { fprintf(stderr, "Unable to initialise nsfb frontend\n"); - + return 2; } /* get the geometry of the whole screen */ |