/* Sequence Cooperative Server - DMS - February 2003 - by Bob Le Gob */ /******************************************************************************* Variables *******************************************************************************/ typeof lUsers = [User r1];; /* Users list */ var iNb = 0;; /* Sequence size */ var iCurrent = 0;; /* Sequence index */ /******************************************************************************* Functions *******************************************************************************/ /******************************************************************************* Registers a client from -> DMI : Not used user -> User : The user who triggers the action action -> S : Not used param -> S : Not used others -> [User r1] : Not used tag -> Tag : Not used <- I : Not used *******************************************************************************/ fun cbRegister(from, user, action, param, others, tag) = set lUsers = user::lUsers; _DMSeventTag this user "registered" param others nil; 0;; /******************************************************************************* Unregisters a client from -> DMI : Not used user -> User : The user who triggers the action action -> S : Not used param -> S : Not used others -> [User r1] : Not used tag -> Tag : Not used <- I : Not used *******************************************************************************/ fun cbUnregister(from, user, action, param, others, tag) = set lUsers = remove_from_list lUsers user; _DMSeventTag this user "unregistered" param others nil; 0;; /******************************************************************************* Sends out'n' event to single client user -> User : Destination client p -> [S S [User r1]] : Event and transmitted parameters <- I : Not used *******************************************************************************/ fun cbSendEvent(user, p) = let p -> [event param others] in _DMSeventTag this user event param others nil;; /******************************************************************************* Triggers single current out'n' event by registered clients from -> DMI : Not used user -> User : Not used action -> S : Not used param -> S : Not used others -> [User r1] : Not used tag -> Tag : Not used <- I : Not used *******************************************************************************/ fun cbInputOneByOne(from, user, action, param, others, tag) = set iCurrent = (mod iCurrent iNb) + 1; apply_on_list lUsers @cbSendEvent [(strcat "out" itoa iCurrent) param others]; 0;; /******************************************************************************* Triggers all out'n' events by registered clients from -> DMI : Not used user -> User : Not used action -> S : Not used param -> S : Not used others -> [User r1] : Not used tag -> Tag : Not used <- I : Not used *******************************************************************************/ fun cbInputAllAtOnce(from, user, action, param, others, tag) = let 1 -> i in while (i <= iNb) do ( apply_on_list lUsers @cbSendEvent [(strcat "out" itoa i) param others]; set i = i + 1; );; /******************************************************************************* Module instanciation *******************************************************************************/ /******************************************************************************* Standard IniDMI param -> S : Not used <- I : Not used *******************************************************************************/ fun IniDMI (param)= let _DMSgetDef this "dmi" -> l in let getInfo l "sequence" -> s in { set iNb = atoi s; set iCurrent = iNb; }; _DMSdefineActions this ["register" @cbRegister]:: ["unregister" @cbUnregister]:: ["inputOneByOne" @cbInputOneByOne]:: ["inputAllAtOnce" @cbInputAllAtOnce]:: nil; 0;;