00001 /* 00002 * Copyright (C) 2006 SRI International 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2.1 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this library; if not, write to the Free Software 00016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00017 * 00018 * SRI International: 333 Ravenswood Ave, Menlo Park, CA 94025 00019 */ 00020 00021 #include "termreader.h" 00022 #include <stdlib.h> 00023 #ifndef _WINDOWS 00024 #include <unistd.h> 00025 #endif 00026 #include "libicl.h" 00027 00028 struct TermReaderStruct 00029 { 00030 TermReaderGetNext getNext; 00031 TermReaderType type; 00032 gint listenSocket; 00033 gint error; 00034 TermReaderCleanup cleanup; 00035 gpointer readerSpecificData; 00036 } 00037 ; 00038 00039 TermReader* termReader_create() 00040 { 00041 TermReader* t = (TermReader*)malloc(sizeof(TermReader)); 00042 t->getNext = NULL; 00043 t->type = UNKNOWNTERMREADERTYPE; 00044 t->listenSocket = -1; 00045 t->error = TERMREADER_OKAY; 00046 t->cleanup = NULL; 00047 t->readerSpecificData = NULL; 00048 return t; 00049 } 00050 00051 void termReader_free(TermReader* t) 00052 { 00053 if(t->cleanup != NULL) { 00054 t->cleanup(t); 00055 } 00056 free(t); 00057 } 00058 00059 ICLTerm* termReader_getNextTerm(TermReader* t, double timeout) 00060 { 00061 if(t->getNext != NULL) { 00062 return t->getNext(t, timeout); 00063 } 00064 else { 00065 t->error = TERMREADER_NOTINITIALIZED; 00066 return NULL; 00067 } 00068 } 00069 00070 void termReader_setError(TermReader* t, gint errnum) 00071 { 00072 t->error = errnum; 00073 } 00074 00075 gint termReader_getError(TermReader* t) 00076 { 00077 return t->error; 00078 } 00079 00080 void termReader_setSocket(TermReader* t, gint newsocket) 00081 { 00082 t->listenSocket = newsocket; 00083 } 00084 00085 gint termReader_getSocket(TermReader* t) 00086 { 00087 return t->listenSocket; 00088 } 00089 00090 void termReader_setType(TermReader* t, TermReaderType type) 00091 { 00092 t->type = type; 00093 } 00094 00095 TermReaderType termReader_getType(TermReader* t) 00096 { 00097 return t->type; 00098 } 00099 00100 void termReader_setReaderSpecificData(TermReader* t, gpointer g) 00101 { 00102 t->readerSpecificData = g; 00103 } 00104 00105 gpointer termReader_getReaderSpecificData(TermReader* t) 00106 { 00107 return t->readerSpecificData; 00108 } 00109 00110 void termReader_setGetNextCallback(TermReader* t, TermReaderGetNext g) 00111 { 00112 t->getNext = g; 00113 } 00114 00115 void termReader_setCleanupCallback(TermReader* t, TermReaderCleanup c) 00116 { 00117 t->cleanup = c; 00118 } 00119