iorequest.c

Go to the documentation of this file.
00001 /***************************************************************************
00002  $RCSfile$
00003                              -------------------
00004     cvs         : $Id: crypttoken.h 1113 2007-01-10 09:14:16Z martin $
00005     begin       : Wed Mar 16 2005
00006     copyright   : (C) 2005 by Martin Preuss
00007     email       : martin@libchipcard.de
00008 
00009  ***************************************************************************
00010  *          Please see toplevel file COPYING for license details           *
00011  ***************************************************************************/
00012 
00013 #ifdef HAVE_CONFIG_H
00014 # include <config.h>
00015 #endif
00016 
00017 
00018 #include "iorequest_p.h"
00019 
00020 #include "i18n_l.h"
00021 #include <gwenhywfar/misc.h>
00022 #include <gwenhywfar/debug.h>
00023 #include <gwenhywfar/gui.h>
00024 
00025 #include <assert.h>
00026 
00027 
00028 
00029 GWEN_LIST_FUNCTIONS(GWEN_IO_REQUEST, GWEN_Io_Request)
00030 GWEN_LIST2_FUNCTIONS(GWEN_IO_REQUEST, GWEN_Io_Request)
00031 
00032 
00033 
00034 const char *GWEN_Io_RequestType_toString(GWEN_IO_REQUEST_TYPE t) {
00035   switch(t) {
00036   case GWEN_Io_Request_TypeConnect:     return "connect";
00037   case GWEN_Io_Request_TypeDisconnect:  return "disconnect";
00038   case GWEN_Io_Request_TypeRead:        return "read";
00039   case GWEN_Io_Request_TypeWrite:       return "write";
00040   default:                              return "unknown";
00041   }
00042 }
00043 
00044 
00045 
00046 const char *GWEN_Io_RequestStatus_toString(GWEN_IO_REQUEST_STATUS st) {
00047   switch(st) {
00048   case GWEN_Io_Request_StatusFree:     return "free";
00049   case GWEN_Io_Request_StatusEnqueued: return "enqueued";
00050   case GWEN_Io_Request_StatusFinished: return "finished";
00051   default:                             return "unknown";
00052   }
00053 }
00054 
00055 
00056 
00057 
00058 GWEN_IO_REQUEST *GWEN_Io_Request_new(GWEN_IO_REQUEST_TYPE t,
00059                                      uint8_t *pBuffer,
00060                                      uint32_t lBuffer,
00061                                      GWEN_IO_REQUEST_FINISH_FN finishFn,
00062                                      void *user_data,
00063                                      uint32_t guiid) {
00064   GWEN_IO_REQUEST *r;
00065 
00066   GWEN_NEW_OBJECT(GWEN_IO_REQUEST, r);
00067   r->refCount=1;
00068   GWEN_LIST_INIT(GWEN_IO_REQUEST, r);
00069 
00070   r->type=t;
00071   r->bufferPtr=pBuffer;
00072   r->bufferSize=lBuffer;
00073   r->finishFn=finishFn;
00074   r->user_data=user_data;
00075   r->guiid=guiid;
00076 
00077   DBG_DEBUG(GWEN_LOGDOMAIN,
00078             "Request %p created (%s, %d)",
00079             r,
00080             GWEN_Io_RequestType_toString(r->type),
00081             lBuffer);
00082 
00083   return r;
00084 }
00085 
00086 
00087 
00088 void GWEN_Io_Request_Attach(GWEN_IO_REQUEST *r) {
00089   assert(r);
00090   assert(r->refCount);
00091   r->refCount++;
00092 }
00093 
00094 
00095 
00096 void GWEN_Io_Request_free(GWEN_IO_REQUEST *r) {
00097   if (r) {
00098     assert(r->refCount);
00099     if (r->refCount==1) {
00100       GWEN_LIST_FINI(GWEN_IO_REQUEST, r);
00101       if (r->incomingLayer)
00102         GWEN_Io_Layer_free(r->incomingLayer);
00103       if (r->flags & GWEN_IO_REQUEST_FLAGS_TAKEOVER)
00104         free(r->bufferPtr);
00105       r->refCount=0;
00106       GWEN_FREE_OBJECT(r);
00107     }
00108     else
00109       r->refCount--;
00110   }
00111 }
00112 
00113 
00114 
00115 GWEN_IO_REQUEST_TYPE GWEN_Io_Request_GetType(const GWEN_IO_REQUEST *r) {
00116   assert(r);
00117   assert(r->refCount);
00118 
00119   return r->type;
00120 }
00121 
00122 
00123 
00124 uint32_t GWEN_Io_Request_GetFlags(const GWEN_IO_REQUEST *r) {
00125   assert(r);
00126   assert(r->refCount);
00127 
00128   return r->flags;
00129 }
00130 
00131 
00132 
00133 void GWEN_Io_Request_SetFlags(GWEN_IO_REQUEST *r, uint32_t f) {
00134   assert(r);
00135   assert(r->refCount);
00136 
00137   r->flags=f;
00138 }
00139 
00140 
00141 
00142 void GWEN_Io_Request_AddFlags(GWEN_IO_REQUEST *r, uint32_t f) {
00143   assert(r);
00144   assert(r->refCount);
00145 
00146   r->flags|=f;
00147 }
00148 
00149 
00150 
00151 void GWEN_Io_Request_SubFlags(GWEN_IO_REQUEST *r, uint32_t f) {
00152   assert(r);
00153   assert(r->refCount);
00154 
00155   r->flags&=~f;
00156 }
00157 
00158 
00159 
00160 uint8_t *GWEN_Io_Request_GetBufferPtr(const GWEN_IO_REQUEST *r) {
00161   assert(r);
00162   assert(r->refCount);
00163 
00164   return r->bufferPtr;
00165 }
00166 
00167 
00168 
00169 uint32_t GWEN_Io_Request_GetBufferSize(const GWEN_IO_REQUEST *r) {
00170   assert(r);
00171   assert(r->refCount);
00172 
00173   return r->bufferSize;
00174 }
00175 
00176 
00177 
00178 uint32_t GWEN_Io_Request_GetBufferPos(const GWEN_IO_REQUEST *r) {
00179   assert(r);
00180   assert(r->refCount);
00181 
00182   return r->bufferPos;
00183 }
00184 
00185 
00186 
00187 void GWEN_Io_Request_SetBufferPos(GWEN_IO_REQUEST *r, uint32_t i) {
00188   assert(r);
00189   assert(r->refCount);
00190 
00191   r->bufferPos=i;
00192 }
00193 
00194 
00195 
00196 uint32_t GWEN_Io_Request_GetGuiId(const GWEN_IO_REQUEST *r) {
00197   assert(r);
00198   assert(r->refCount);
00199 
00200   return r->guiid;
00201 }
00202 
00203 
00204 
00205 void GWEN_Io_Request_SetGuiId(GWEN_IO_REQUEST *r, uint32_t i) {
00206   assert(r);
00207   assert(r->refCount);
00208 
00209   r->guiid=i;
00210 }
00211 
00212 
00213 
00214 GWEN_IO_LAYER *GWEN_Io_Request_GetIoLayer(const GWEN_IO_REQUEST *r) {
00215   assert(r);
00216   assert(r->refCount);
00217 
00218   return r->ioLayer;
00219 }
00220 
00221 
00222 
00223 GWEN_IO_REQUEST_STATUS GWEN_Io_Request_GetStatus(const GWEN_IO_REQUEST *r) {
00224   assert(r);
00225   assert(r->refCount);
00226 
00227   return r->status;
00228 }
00229 
00230 
00231 
00232 void GWEN_Io_Request_SetStatus(GWEN_IO_REQUEST *r, GWEN_IO_REQUEST_STATUS st) {
00233   assert(r);
00234   assert(r->refCount);
00235 
00236   r->status=st;
00237 }
00238 
00239 
00240 
00241 int GWEN_Io_Request_GetResultCode(const GWEN_IO_REQUEST *r) {
00242   assert(r);
00243   assert(r->refCount);
00244 
00245   return r->resultCode;
00246 }
00247 
00248 
00249 
00250 void GWEN_Io_Request_SetResultCode(GWEN_IO_REQUEST *r, int result) {
00251   assert(r);
00252   assert(r->refCount);
00253 
00254   r->resultCode=result;
00255 }
00256 
00257 
00258 
00259 GWEN_IO_LAYER *GWEN_Io_Request_GetIncomingLayer(const GWEN_IO_REQUEST *r) {
00260   assert(r);
00261   assert(r->refCount);
00262 
00263   return r->incomingLayer;
00264 }
00265 
00266 
00267 
00268 GWEN_IO_LAYER *GWEN_Io_Request_TakeIncomingLayer(GWEN_IO_REQUEST *r) {
00269   GWEN_IO_LAYER *newIo;
00270 
00271   assert(r);
00272   assert(r->refCount);
00273 
00274   newIo=r->incomingLayer;
00275   r->incomingLayer=NULL;
00276   return newIo;
00277 }
00278 
00279 
00280 
00281 void GWEN_Io_Request_SetIncomingLayer(GWEN_IO_REQUEST *r, GWEN_IO_LAYER *iol) {
00282   assert(r);
00283   assert(r->refCount);
00284 
00285   r->incomingLayer=iol;
00286 }
00287 
00288 
00289 
00290 void GWEN_Io_Request_SetIoLayer(GWEN_IO_REQUEST *r, GWEN_IO_LAYER *io) {
00291   assert(r);
00292   assert(r->refCount);
00293 
00294   r->ioLayer=io;
00295 }
00296 
00297 
00298 
00299 void GWEN_Io_Request_Finished(GWEN_IO_REQUEST *r, GWEN_IO_REQUEST_STATUS st, int result) {
00300   assert(r);
00301   assert(r->refCount);
00302 
00303   DBG_DEBUG(GWEN_LOGDOMAIN,
00304             "Request %p finished (%s, %d/%d, result=%d)",
00305             r,
00306             GWEN_Io_RequestType_toString(r->type),
00307             r->bufferPos,
00308             r->bufferSize,
00309             result);
00310   GWEN_Io_Request_SetStatus(r, st);
00311   GWEN_Io_Request_SetResultCode(r, result);
00312   if (r->finishFn)
00313     r->finishFn(r, r->user_data);
00314 }
00315 
00316 
00317 
00318 
00319 
00320 
00321 
00322 
00323 
00324 
00325 

Generated on Wed Sep 3 15:21:58 2008 for gwenhywfar by  doxygen 1.5.6