The API for the StrawLib is based on macros. For those who see macros as something evil this solution must be defended by the fact that the macros basically serves the purpose of hiding several global variables. They also do some token pasting to automate most of the execution logging.
CHUNK_BEGINMAP
This macro begins a event map, i.e. the first step to make the straw wait for one or more evens before continue executing. Below is an example of how the following macros are used to build a complete event map:
CHUNK_BEGINMAP
CHUNK_MAPEVENT(0, SIG_OP_SUCCESS, MatchHTTPOp, HandleResult)
CHUNK_MAPEVENT(0, SIG_OP_FAILURE, MatchHTTPOp, CleanUp)
CHUNK_ENDMAPANDWAIT
Fist we use CHUNK_BEGINMAP to mark the beginning of the map. Then we start mapping events to chunks using CHUNK_MAPEVENT. Each event has a corresponding matching function that will be used to verify that the event was really aimed at this straw. At last we exit the chunk and waits for the events using CHUNK_ENDMAPANDWAIT.
See also CHUNK_MAPEVENT and CHUNK_ENDMAPANDWAIT
#define CHUNK_BEGINMAP
CHUNK_MAPEVENT
This macro defines a event mapping and can hence only be used between the CHUNK_BEGINMAP and CHUNK_ENDMAPANDWAIT macros. What could seem a little tricky about this mapping is that you have to assign a event matching function. This function will be used, if the mapping gets a hit on a event, to make sure the event was aimed at the specific straw, e.g. if there are several instances of the same straw class all of them might be waiting for the same event.
Because there are situations when you might want to map a event no matter what, two predefined event mappers are defined:
CHUNK_MATCHALL
CHUNK_MATCHDROPPED
The CHUNK_MATCHALL matcher will match all events of the given type, and the CHUNK_MATCHDROPPED will have the same function except it will not match if there is another straw that also match the event. This is useful if a straw should only handle events dropped by all other straws, e.g. to be able to send back an error event.
int
ExampleEventMatcher(STRAW_ID StrawID,
void* StrawData_p,
void* EventData_p);
#define CHUNK_MAPEVENT(EventHigh, EventLow, Matcher, Chunk)