1 /*------------------------------------------------------------------------ 2 * Copyright 2007-2009 (c) Jeff Brown <spadix@users.sourceforge.net> 3 * 4 * This file is part of the ZBar Bar Code Reader. 5 * 6 * The ZBar Bar Code Reader is free software; you can redistribute it 7 * and/or modify it under the terms of the GNU Lesser Public License as 8 * published by the Free Software Foundation; either version 2.1 of 9 * the License, or (at your option) any later version. 10 * 11 * The ZBar Bar Code Reader is distributed in the hope that it will be 12 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Lesser Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser Public License 17 * along with the ZBar Bar Code Reader; if not, write to the Free 18 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, 19 * Boston, MA 02110-1301 USA 20 * 21 * http://sourceforge.net/projects/zbar 22 *------------------------------------------------------------------------*/ 23 #ifndef _PROCESSOR_H_ 24 #define _PROCESSOR_H_ 25 26 #include <config.h> 27 #ifdef HAVE_INTTYPES_H 28 # include <inttypes.h> 29 #endif 30 #include <unistd.h> 31 #include <stdlib.h> 32 #include <string.h> 33 34 #include <zbar.h> 35 #include "error.h" 36 #include "thread.h" 37 #include "event.h" 38 39 /* max time to wait for input before looking for the next frame. 40 * only used in unthreaded mode with blocking (non-pollable) video. 41 * NB subject to precision of whatever timer is in use 42 */ 43 #define MAX_INPUT_BLOCK 15/*ms*/ 44 45 /* platform specific state wrapper */ 46 typedef struct processor_state_s processor_state_t; 47 48 /* specific notification tracking */ 49 typedef struct proc_waiter_s { 50 struct proc_waiter_s *next; 51 zbar_event_t notify; 52 zbar_thread_id_t requester; 53 unsigned events; 54 } proc_waiter_t; 55 56 /* high-level API events */ 57 #define EVENT_INPUT 0x01 /* user input */ 58 #define EVENT_OUTPUT 0x02 /* decoded output data available */ 59 #define EVENT_CANCELED 0x80 /* cancellation flag */ 60 #define EVENTS_PENDING (EVENT_INPUT | EVENT_OUTPUT) 61 62 struct zbar_processor_s { 63 errinfo_t err; /* error reporting */ 64 const void *userdata; /* application data */ 65 66 zbar_video_t *video; /* input video device abstraction */ 67 zbar_window_t *window; /* output window abstraction */ 68 zbar_image_scanner_t *scanner; /* barcode scanner */ 69 70 zbar_image_data_handler_t *handler; /* application data handler */ 71 72 unsigned req_width, req_height; /* application requested video size */ 73 int req_intf, req_iomode; /* application requested interface */ 74 uint32_t force_input; /* force input format (debug) */ 75 uint32_t force_output; /* force format conversion (debug) */ 76 77 int input; /* user input status */ 78 79 /* state flags */ 80 int threaded; 81 int visible; /* output window mapped to display */ 82 int streaming; /* video enabled */ 83 int dumping; /* debug image dump */ 84 85 void *display; /* X display connection */ 86 unsigned long xwin; /* toplevel window */ 87 88 zbar_thread_t input_thread; /* video input handler */ 89 zbar_thread_t video_thread; /* window event handler */ 90 91 const zbar_symbol_set_t *syms; /* previous decode results */ 92 93 zbar_mutex_t mutex; /* shared data mutex */ 94 95 /* API serialization lock */ 96 int lock_level; 97 zbar_thread_id_t lock_owner; 98 proc_waiter_t *wait_head, *wait_tail, *wait_next; 99 proc_waiter_t *free_waiter; 100 101 processor_state_t *state; 102 103 int is_dbus_enabled; /* dbus enabled flag */ 104 }; 105 106 /* processor lock API */ 107 extern int _zbar_processor_lock(zbar_processor_t*); 108 extern int _zbar_processor_unlock(zbar_processor_t*, int); 109 extern void _zbar_processor_notify(zbar_processor_t*, unsigned); 110 extern int _zbar_processor_wait(zbar_processor_t*, unsigned, zbar_timer_t*); 111 112 /* platform API */ 113 extern int _zbar_processor_init(zbar_processor_t*); 114 extern int _zbar_processor_cleanup(zbar_processor_t*); 115 extern int _zbar_processor_input_wait(zbar_processor_t*, zbar_event_t*, int); 116 extern int _zbar_processor_enable(zbar_processor_t*); 117 118 extern int _zbar_process_image(zbar_processor_t*, zbar_image_t*); 119 extern int _zbar_processor_handle_input(zbar_processor_t*, int); 120 121 /* windowing platform API */ 122 extern int _zbar_processor_open(zbar_processor_t*, char*, unsigned, unsigned); 123 extern int _zbar_processor_close(zbar_processor_t*); 124 extern int _zbar_processor_set_visible(zbar_processor_t*, int); 125 extern int _zbar_processor_set_size(zbar_processor_t*, unsigned, unsigned); 126 extern int _zbar_processor_invalidate(zbar_processor_t*); 127 128 #endif 129