SFBMemory Class Reference

A class for temporarily storing packets, and then retriggering on them at a later time. More...

#include <SFBMemory.h>

Collaboration diagram for SFBMemory:

Collaboration graph
[legend]

Public Member Functions

void reflex (const char type, PacketHandler ph)
 Define a reflex that is operational only when a packet is triggered from memory.
bool dispatch (int maxPackets, u32 deadline)
 Reflex-trigger up to maxPackets currently remembered packets, so long as millis() has not yet exceeded deadline.
int remember (const u8 *packet)
 Save a copy of packet for later redispatch (if memory is available to do so).
int rememberUnread (const u8 *packet, u8 sourceOverride=MAX_FACE_INDEX)
u8makeNewMemory (u32 packetLength)
bool remembering ()
 Determine if we are reacting to a memorized packet, rather than a 'real' packet (that has just arrived on a face).
void forget ()
 Specify that the current memory packet should be forgotten after the current packet handler finishes.
void remember ()
 Specify that the current memory packet should be remembered after the current packet handler finishes.
bool forget (u32 index)
 Specify that the packet in slot index should be forgotten.
u8get (const u32 index)
 Access the packet associated with slot index.
bool fire (const u32 index)
 Reflex-trigger the packet stored in slot index, if any.
int find (const u8 type)
int find (const char *prefix, const int len=-1)
int printf (const char *format,...)
 Formatting printing to a temporary local packet.
u8 getFace ()
 Returns WMEM.

Detailed Description

A class for temporarily storing packets, and then retriggering on them at a later time.

Member Function Documentation

bool SFBMemory::dispatch ( int  maxPackets,
u32  deadline 
)

Reflex-trigger up to maxPackets currently remembered packets, so long as millis() has not yet exceeded deadline.

Normally called automatically during delay()s and between loop() calls, but may be explicitly invoked in the loop() method to force faster memory processing.

bool SFBMemory::fire ( const u32  index  ) 

Reflex-trigger the packet stored in slot index, if any.

Returns:
true iff a packet was triggered, false if slot index was empty
Blinks:
E_API_MAX_RANGE if index is greater than or equal to MAX_PACKETS_IN_MEMORY.

bool SFBMemory::forget ( u32  index  ) 

Specify that the packet in slot index should be forgotten.

Returns true if a packet was successfully forgotten from slot index; returns false if slot index did not currently contain a packet.

This method must be used with caution. In particular, it is up to the caller to ensure that the index forgotten still contains whatever packet the caller actually intends to forget. This will be true so long as no packet dispatching has occurred since the time the index was returned from remember(const u8 *), but will not be true in general: Once dispatching has occurred, the packet in slot index may be been dispatched and forgotten, and another packet may have been stored in that same index slot.

Returns:
if some packet was forgotten from slot index, and false if slot index was already empty.
Blinks:
E_API_MAX_RANGE if index is outside the range 0..MAX_PACKETS_IN_MEMORY-1.
See also:
remember(const u8 *)

void SFBMemory::forget (  )  [inline]

Specify that the current memory packet should be forgotten after the current packet handler finishes.

Only effective inside a packet handler that is handling a memorized packet. Note that forgetting memory packets after triggering reflexes is the default behavior, so this method usually doesn't need to be called explicitly.

See also:
remember()

u8* SFBMemory::get ( const u32  index  )  [inline]

Access the packet associated with slot index.

Returns:
0 if there is no packet stored in slot index, or a pointer to the packet stored there.
Blinks:
E_API_MAX_RANGE if index is greater than or equal to MAX_PACKETS_IN_MEMORY.

int SFBMemory::printf ( const char *  format,
  ... 
)

Formatting printing to a temporary local packet.

Equivalent to facePrint(WMEM,format,...).

Returns:
slot index where the last-just-printed packet was placed. Or returns -1 if more or less than a complete packet was printed, or there were no free slots to store the last-just-printed packet.
Since:
0.9.18
Examples:
fifthdirection.cpp.

void SFBMemory::remember (  )  [inline]

Specify that the current memory packet should be remembered after the current packet handler finishes.

Only effective inside a packet handler that is handling a memorized packet. Normally, a memorized packet ia forgotten after it triggers a reflex once; if it is desired to cause an additional trigger sometime after the current packet handler is finished, this method must be called during packet handling.

See also:
forget()

int SFBMemory::remember ( const u8 packet  ) 

Save a copy of packet for later redispatch (if memory is available to do so).

Returns -1 if no room was available, else returns a 'slot number' in the range of 0..MAX_PACKETS_IN_MEMORY-1. This slot number can be used to forget the copied packet if desired (though this must be used with caution; see forget(u32) for details.)

Returns:
-1 if no room was available to copy packet, else returns index of slot containing copied packet.
Blinks:
E_API_NULL_PACKET if packet is null.
See also:
forget(u32)
Examples:
reorder.cpp.

bool SFBMemory::remembering (  )  [inline]

Determine if we are reacting to a memorized packet, rather than a 'real' packet (that has just arrived on a face).

Only valid inside packet handlers.

Returns:
true if the current packet handler was triggered by a memory packet; false if not.


The documentation for this class was generated from the following files:

Generated on Fri Apr 22 06:57:21 2011 for SFB by doxygen 1.5.9