SFBMemory.h

Go to the documentation of this file.
00001 /*                                              -*- mode:C++; fill-column:100 -*-
00002   SFBMemory.h Support for 'Working Memory' - redispatching packets
00003   Copyright (C) 2009 The Regents of the University of New Mexico.  All rights reserved.
00004 
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Lesser General Public
00007   License as published by the Free Software Foundation; either
00008   version 2.1 of the License, or (at your option) any later version.
00009 
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Lesser General Public License for more details.
00014 
00015   You should have received a copy of the GNU General Public License
00016   along with this library; if not, write to the Free Software
00017   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
00018   USA
00019 
00020   $Id$
00021 */
00022 
00029 #ifndef SFBMEMORY_H
00030 #define SFBMEMORY_H
00031 
00032 #include <stdarg.h>
00033 #include "SFBFrame.h"
00034 #include "SFBHeap.h"
00035 #include "SFBReactor.h"  /* For PacketHandler, ::reflex */
00036 #include "SFBPrint.h"    /* For FacePrinter */ 
00037 
00038 
00039 #define MAX_PACKETS_IN_MEMORY 32
00040 
00044 class SFBMemory {
00045 
00046 public:
00047 
00048   SFBMemory() ;
00049 
00053   void reflex(const char type, PacketHandler ph) {
00054     ::reflex(type, ph, SFBReactor::TRIGGER_MEMORY);
00055   }
00056 
00062   bool dispatch(int maxPackets, u32 deadline) ;
00063 
00077   int remember(const u8 * packet) ;
00078 
00079   int rememberUnread(const u8 * packet,u8 sourceOverride = MAX_FACE_INDEX) ; 
00080 
00081   u8 * makeNewMemory(u32 packetLength) ;
00082 
00089   bool remembering() {
00090     return inTrigger;
00091   }
00092 
00101   void forget() {
00102     if (inTrigger)
00103       killIt = true;
00104   }
00105 
00115   void remember() {
00116     if (inTrigger)
00117       killIt = false;
00118   }
00119 
00120   
00140   bool forget(u32 index) ;
00141 
00150   u8 * get(const u32 index) {
00151     API_ASSERT_MAX(index,MAX_PACKETS_IN_MEMORY);
00152     return packets[index];
00153   }
00154 
00162   bool fire(const u32 index) ;
00163 
00164   int find(const u8 type) {
00165     return find((const char *) &type, 1);
00166   }
00167   int find(const char * prefix, const int len = -1) ;
00168 
00178   int printf(const char * format, ...) ;
00179 
00183   u8 getFace() { return WMEM; }
00184 
00185 private:
00186   SFBHeap heap;
00187   u8 * packets[MAX_PACKETS_IN_MEMORY];
00188   s8 lastIndexPrinted;          // -1 if none or 0..MAX_PACKETS_IN_MEMORY-1
00189   u8 spinner;
00190   u8 inUse;
00191   bool inTrigger;
00192   bool killIt;
00193 
00194   static const FacePrinter memoryFacePrinter ;
00195   static void MemoryFacePrint(u8 face, u8 ch) ;
00196   static void MemoryFacePrintln(u8 face) ;
00197 
00198   void facePrint(u8 face, u8 ch) ;
00199   void facePrintln(u8 face) ;
00200 
00201   u8 memoryPacketBuffer[PACKET_PRINTER_PACKET_BUFFER_SIZE];
00202 };
00203 
00207 extern SFBMemory Memory;
00208 
00209 #endif  /* SFBMEMORY_H */
00210 

Generated on Fri Apr 22 06:54:11 2011 for SFB by doxygen 1.5.9