# 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 "SFBFrame.h"
    00033 #include "SFBHeap.h"
    00034 #include "SFBReactor.h"  /* For PacketHandler, ::reflex */
    00035
    00036 #define MAX_PACKETS_IN_MEMORY 20
    00037
    00041 class SFBMemory {
    00042
    00043 public:
    00044
    00045   SFBMemory() ;
    00046
    00047   void reflex(const char type, PacketHandler ph) {
    00048     ::reflex(type, ph, SFBReactor::TRIGGER_MEMORY);
    00049   }
    00050
    00051   bool dispatch(int maxPackets, u32 deadline) ;
    00052
    00053   int remember(const u8 * packet) ;
    00054
    00055   int rememberUnread(const u8 * packet,u8 sourceOverride = MAX_FACE_INDEX) ;
    00056
    00057   u8 * makeNewMemory(u32 packetLength) ;
    00058
    00059   void forget() {
    00060     if (inTrigger)
    00061       killIt = true;
    00062   }
    00063
    00064   void remember() {
    00065     if (inTrigger)
    00066       killIt = false;
    00067   }
    00068
    00069   bool forget(u32 index) ;
    00070
    00071   u8 * get(const u32 index) {
    00072     API_ASSERT_MAX(index,MAX_PACKETS_IN_MEMORY);
    00073     return packets[index];
    00074   }
    00075   bool fire(const u32 index) ;
    00076   int find(const u8 type) {
    00077     return find((const char *) &type, 1);
    00078   }
    00079   int find(const char * prefix, const int len = -1) ;
    00080
    00081 private:
    00082   SFBHeap heap;
    00083   u8 * packets[MAX_PACKETS_IN_MEMORY];
    00084   u8 spinner;
    00085   u8 inUse;
    00086   bool inTrigger;
    00087   bool killIt;
    00088 };
    00089
    00090 extern SFBMemory Memory;
    00091
    00092 #endif  /* SFBMEMORY_H */
    00093