Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

naive.c

00001 /*
00002  *  naive.c - A very naive driver. It simply sends the contents of the canvas
00003  *            to the backend. It does not translate unicode characters outside
00004  *            the ASCII range. This works just fine for the ncurses backend,
00005  *            and for some displays as well (although you'll miss a lot of
00006  *            the display's functionality this way). This file is the right
00007  *            place to start for writing your own driver.
00008  *            This file is part of the FreeLCD package.
00009  *  
00010  *  $Id: naive_8c-source.html,v 1.1 2003/02/16 22:50:41 unicorn Exp $
00011  *
00012  *  This program is free software; you can redistribute it and/or modify it
00013  *  under the terms of the GNU General Public License as published by the
00014  *  Free Software Foundation; either version 2 of the License, or (at your
00015  *  option) any later version.
00016  * 
00017  *  This program is distributed in the hope that it will be useful,
00018  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  *  GNU General Public License for more details.
00021  *
00022  *  You should have received a copy of the GNU General Public License
00023  *  along with this program; if not, write to the Free Software
00024  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00025  *  MA  02111-1307  USA
00026  *
00027  *  Copyright (c) 2002, 2003, Jeroen van den Berg <unicorn@hippie.nu>
00028  */
00029 
00030 
00031 #include <stdlib.h>
00032 #include <string.h>
00033 
00034 #include "driver.h"
00035 #include "backend.h"
00036 
00037 typedef struct
00038 {
00039   void *backend;
00040 }
00041 naive_h;
00042 
00043 /*-------------------------------------------------------- drv_get_info --*/
00044 const char *
00045 drv_get_info (const char* field)
00046 {
00047   if (!strcmp(field, "name"))
00048     return "naive";
00049 
00050   if (!strcmp(field, "description"))
00051     return "This driver copies its character buffer directly to the backend.";
00052 
00053   if (!strcmp(field, "version"))
00054     return "1";
00055 
00056   return 0;
00057 }
00058 
00059 /*---------------------------------------------------- drv_create_handle --*/
00060 void *
00061 drv_create_handle (xml_node* config)
00062 {
00063   naive_h *h;
00064   h = malloc (sizeof (naive_h));
00065   if (h)
00066     h->backend = 0;
00067 
00068   return h;
00069 }
00070 
00071 /*--------------------------------------------------- drv_destroy_handle --*/
00072 void
00073 drv_destroy_handle (void *handle)
00074 {
00075   naive_h *h = (naive_h*)handle;
00076   if (h->backend)
00077     backend_free_handle (h->backend);
00078   
00079   free (h);
00080 }
00081 
00082 /*----------------------------------------------------- drv_bind_backend --*/
00083 void
00084 drv_bind_backend (void *handle, void* backend)
00085 {
00086   naive_h *h = (naive_h*)handle;
00087   h->backend = backend;
00088 
00089   /* FIXME */
00090   /* backend_send (backend, "This is a test.", 15); */
00091 }
00092 
00093 /*--------------------------------------------------- drv_process_layout --*/
00094 void
00095 drv_process_canvas (void *handle, cc_canvas *canvas)
00096 {
00097   naive_h *h = (naive_h*)handle;
00098   unsigned int size = canvas->width * canvas->height;
00099   unsigned int i;
00100 
00101   for (i = 0; i < size; ++i)
00102     backend_send (h->backend, (char*)&(canvas->elements[i].c),1);
00103 }
00104 
00105 /*------------------------------------------------------ drv_get_backend --*/
00106 void *
00107 drv_get_backend (void *handle)
00108 {
00109   naive_h *h = (naive_h*)handle;
00110 
00111   return h->backend;
00112 }

Generated on Sun Feb 16 23:39:49 2003 for FreeLCD by doxygen1.2.18