/* eventinstance.c I don't understand how the GETROUTINE declarations after the last closing '}' get executed ??? - RJL 94/6/28 Revised by RJL 94/12/1 - I merely added comment paragraphs. Rev. RJL 95/2/13 - ditto */ #include #include # if !defined OLC3COMMON_H # include "olc3common.h" # endif #include "f93olc.h" # if !defined EVENTINSTANCE_H # include "eventinstance.h" # endif /* # if !defined OLC93SU523_H # include "olc93su523.h" # endif */ /* ** EventInstanceFirst ** EventInstanceNext ** EventInstanceDelete */ STANDARDROUTINES(EventInstance, EI) /* EventInstanceCreate finds ETid and ETcurr from Label or fails with no event, and supplies a default non-null string argument to pr_add(). [But what if Text is a non-null pointer to the null character? - RJL] */ FUNCTION8( void EventInstanceCreate, hcg_key, FromThisActiveInstance, /* event originator id */ hcg_key, ToThisActiveInstance, /* event destination id */ hcg_key, ThisTypeOfEvent, /* EventType id */ int, FirstIntData, int, SecondIntData, double, FirstFloatData, double, SecondFloatData, const char *, Text ) { const char *EventText; #ifdef GENV7 char databuffer[BUFSIZE]; KEYBUFFER(EIkey); KEYBUFFER(AI1key); KEYBUFFER(AI2key); KEYBUFFER(ETkey); #else struct EI *EI_elt; #endif /* ** If Text is the null pointer, use "" as the event text */ EventText = (Text == 0) ? "nothing" : Text; #ifdef GENV7 /* ** Get the keys we need */ decode(AI1key, &FromThisActiveInstance); /* pAI_source->AIid? */ decode(AI2key, &ToThisActiveInstance); /* pAI_dest->AIid? */ decode(ETkey, &ThisTypeOfEvent); pr_gen_pkey("JuicePlant", EI, EIkey); /* ** Form the new table line */ sprintf(databuffer, " %s %s %s %s %d %d %e %e %.*s", EIkey, AI1key, AI2key, ETkey, FirstIntData, SecondIntData, FirstFloatData, SecondFloatData, EventInstanceMaxStringLen, EventText); /* ** And add it */ pr_add("JuicePlant", databuffer); #else EI_elt = pr_create(EI); pr_set_key(EI_elt, AIid1, FromThisActiveInstance); pr_set_key(EI_elt, AIid2, ToThisActiveInstance); pr_set_key(EI_elt, ETid, ThisTypeOfEvent); pr_set_int(EI_elt, Int1, FirstIntData); pr_set_int(EI_elt, Int2, SecondIntData); pr_set_flt(EI_elt, Flt1, FirstFloatData); pr_set_flt(EI_elt, Flt2, SecondFloatData); pr_set_str(EI_elt, Text, EventText); pr_add("JuicePlant", EI, EI_elt); #endif } /* EventInstanceCreate */ FUNCTION8( void GenerateEvent, const char *, FromThisNamedActiveInstance, const char *, ToThisNamedActiveInstance, const char *, EventLabel, int, FirstIntData, int, SecondIntData, double, FirstFloatData, double, SecondFloatData, const char *, Text ) { hcg_key AIid1; hcg_key AIid2; hcg_key ETid; int bad; /* ** Convert the names of the Active Instances and the Label of the ** event into keys */ bad = 0; find_str_loop("JuicePlant", AI, Name, FromThisNamedActiveInstance) { break; } if (AIcurr == 0) { printf("Could not find an Active Instance named %s.\n", FromThisNamedActiveInstance); bad = 1; } else { AIid1 = AIcurr->AIid; /* and/or pAIid_source = AIcurr ? */ } find_str_loop("JuicePlant", AI, Name, ToThisNamedActiveInstance) { break; } if (AIcurr == 0) { printf("Could not find an Active Instance named %s\n", ToThisNamedActiveInstance); bad = 1; } else { AIid2 = AIcurr->AIid; /* and/or pAIid_dest = AIcurr ? */ } find_str_loop("JuicePlant", ET, Label, EventLabel) { break; } if (ETcurr == 0) { printf("Could not find an Event labeled %s.\n", EventLabel); bad = 1; } else { ETid = ETcurr->ETid; /* ETcurr is also uptodate */ } if (bad) { printf("Event not generated\n"); return; } /* ** And have Event Instance Create do the work */ EventInstanceCreate(AIid1, /* or pAIid_source? */ AIid2, /* of pAIid_dest? */ ETid, /* or EIcurr? */ FirstIntData, SecondIntData, FirstFloatData, SecondFloatData, Text); } /* GenerateEvent: calls EventInstanceCreate */ /* From RJL 94/12/1: EICreate pre-empts an abbreviated name which I would have reserved for a more direct implementation called by EventInstanceCreate - one which uses currency pointer arguments like EIcurr, ETcurr, pAIself, pAIdest for direct access since XXcurr is usually known when XXid is known or after pr_find_key. find_str_loop finds ETid (and ETcurr) from Label (or fails with no action) and supplies a default non-null string argument to EventInstanceCreate(). NOTE: The TImer can store ETid of the reply event, which is more efficient, but must pass ETid as a different argument type to create the reply event. Requiring an active instance to pass ETid or ETcurr instead of Label would be more efficient (find_pkey instead of find_str_loop); then the source would have to search for Label (but could locally cache ETcurr). EICreate should also find AIid1, AIid2 from the subclass pkeys of the event source and destination - because subclass keys are application-specific - RJL */ FUNCTION8( void EICreate, hcg_key, AIid1, hcg_key, AIid2, const char *, EventLabel, int, FirstIntData, int, SecondIntData, double, FirstFloatData, double, SecondFloatData, const char *, Text ) { hcg_key ETid; int bad; bad = 0; find_str_loop("JuicePlant", ET, Label, EventLabel) { break; } if (ETcurr == 0) { printf("Could not find an Event labeled %s.\n", EventLabel); bad = 1; } else { ETid = ETcurr->ETid; } if (bad) { printf("Event not generated\n"); return; } /* ** And have Event Instance Create do the work */ EventInstanceCreate(AIid1, AIid2, ETid, FirstIntData, SecondIntData, FirstFloatData, SecondFloatData, Text); } /* EICreate: calls EventInstanceCreate */ GETROUTINE(hcg_key, EventInstance,EI,ETid) GETROUTINE(hcg_key, EventInstance,EI,AIid1) GETROUTINE(hcg_key, EventInstance,EI,AIid2) GETROUTINE(int, EventInstance,EI,Int1) GETROUTINE(int, EventInstance,EI,Int2) GETROUTINE(double, EventInstance,EI,Flt1) GETROUTINE(double, EventInstance,EI,Flt2) GETROUTINE(const char *,EventInstance,EI,Text) COPYROUTINE(EventInstance,EI,Text)