/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2012 I-maginer This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/lesser.txt ----------------------------------------------------------------------------- */ struct SeqPlugin=[ SEQ_inst : PInstance, SEQ_bStopOnError : I, SEQ_trmTimer : Timer, SEQ_iPeriod : I, SEQ_sCurrentSeq : S, SEQ_lSeq : [[S [S I]] r1], SEQ_iPos : I, SEQ_iNbError : I, SEQ_iState : I ] mkSeqPlugin;; fun deleteOb(inst, obstr)= if (obstr.SEQ_trmTimer == nil) then nil else ( _deltimer obstr.SEQ_trmTimer; set obstr.SEQ_trmTimer = nil; ); 0;; fun cbFailedTime(trm, obstr)= _deltimer trm; set obstr.SEQ_trmTimer = nil; set obstr.SEQ_iNbError = 0; set obstr.SEQ_iState = 0; set obstr.SEQ_iPos = 0; set obstr.SEQ_sCurrentSeq = nil; SendPluginEvent obstr.SEQ_inst "Failed" nil nil; 0;; fun cbInput(inst, from, action, param, rep, obstr) = if (obstr.SEQ_trmTimer == nil) then nil else ( _deltimer obstr.SEQ_trmTimer; set obstr.SEQ_trmTimer = nil; ); let (sizelist obstr.SEQ_lSeq) -> nbacts in let substr action ((strlen (getPluginInstanceName inst)) + 1) (strlen action) -> action in let switchstri obstr.SEQ_lSeq action -> [act period] in if ((act == nil) || (obstr.SEQ_iState != 1)) then nil else ( set obstr.SEQ_iNbError = obstr.SEQ_iNbError + 1; let nth_list obstr.SEQ_lSeq obstr.SEQ_iPos -> [seqname _] in if (!strcmp seqname action) then ( set obstr.SEQ_iPos = obstr.SEQ_iPos + 1; SendPluginEvent inst strcat act " valided" param rep; let nth_list obstr.SEQ_lSeq obstr.SEQ_iPos -> [nxtname [_ period]] in ( set obstr.SEQ_sCurrentSeq = nxtname; SendPluginEvent inst strcat "Waiting for " obstr.SEQ_sCurrentSeq nil nil; if (period <= 0) then nil else set obstr.SEQ_trmTimer = _rfltimer _starttimer _channel period @cbFailedTime obstr; ); if (obstr.SEQ_iPos == nbacts) then ( set obstr.SEQ_iState = 0; set obstr.SEQ_iNbError = 0; set obstr.SEQ_iPos = 0; set obstr.SEQ_sCurrentSeq = nil; SendPluginEvent inst "Success" nil nil; 0; ) else if (!obstr.SEQ_bStopOnError || (obstr.SEQ_iNbError < nbacts)) then nil else ( set obstr.SEQ_iState = 0; set obstr.SEQ_iNbError = 0; set obstr.SEQ_iPos = 0; set obstr.SEQ_sCurrentSeq = nil; SendPluginEvent inst "Failed" nil nil; ); ) else ( if (!obstr.SEQ_bStopOnError || (obstr.SEQ_iNbError < nbacts)) then nil else ( set obstr.SEQ_iState = 0; set obstr.SEQ_iNbError = 0; set obstr.SEQ_iPos = 0; set obstr.SEQ_sCurrentSeq = nil; SendPluginEvent inst "Failed" nil nil; ); 0; ); ); 0;; fun cbReset(inst, from, action, param, rep, obstr) = if (obstr.SEQ_trmTimer == nil) then nil else ( _deltimer obstr.SEQ_trmTimer; set obstr.SEQ_trmTimer = nil; ); set obstr.SEQ_iPos = 0; let nth_list obstr.SEQ_lSeq obstr.SEQ_iPos -> [nxtname [_ period]] in ( set obstr.SEQ_sCurrentSeq = nxtname; SendPluginEvent inst strcat "Waiting for " obstr.SEQ_sCurrentSeq nil nil; if (period <= 0) then nil else set obstr.SEQ_trmTimer = _rfltimer _starttimer _channel period @cbFailedTime obstr; ); 0;; fun cbStart(inst, from, action, param, rep, obstr) = if (obstr.SEQ_trmTimer == nil) then nil else ( _deltimer obstr.SEQ_trmTimer; set obstr.SEQ_trmTimer = nil; ); set obstr.SEQ_iState = 1; let nth_list obstr.SEQ_lSeq obstr.SEQ_iPos -> [nxtname [_ period]] in ( set obstr.SEQ_sCurrentSeq = nxtname; SendPluginEvent inst strcat "Waiting for " obstr.SEQ_sCurrentSeq nil nil; if (period <= 0) then nil else set obstr.SEQ_trmTimer = _rfltimer _starttimer _channel period @cbFailedTime obstr; ); 0;; fun cbStop(inst, from, action, param, rep, obstr) = if (obstr.SEQ_trmTimer == nil) then nil else ( _deltimer obstr.SEQ_trmTimer; set obstr.SEQ_trmTimer = nil; ); set obstr.SEQ_iNbError = 0; set obstr.SEQ_sCurrentSeq = nil; set obstr.SEQ_iPos = 0; set obstr.SEQ_iState = 0; 0;; fun cbPause(inst, from, action, param, rep, obstr) = if (obstr.SEQ_trmTimer == nil) then nil else ( _deltimer obstr.SEQ_trmTimer; set obstr.SEQ_trmTimer = nil; ); set obstr.SEQ_iState = 2; 0;; fun loadSeq(obstr)= let 0 -> i in let getPluginInstanceParam obstr.SEQ_inst (strcat "seq_" (itoa i)) -> seqname in let atoi (getPluginInstanceParam obstr.SEQ_inst (strcat "timeout_" (itoa i))) -> timeout in while (seqname != nil) do ( set obstr.SEQ_lSeq = lcat obstr.SEQ_lSeq [seqname [seqname timeout]]::nil; set i = i + 1; set seqname = getPluginInstanceParam obstr.SEQ_inst (strcat "seq_" (itoa i)); set timeout = atoi (getPluginInstanceParam obstr.SEQ_inst (strcat "timeout_" (itoa i))); ); 0;; fun newOb(inst)= let atoi (getPluginInstanceParam inst "errorfail") -> errorfail in let if errorfail == nil then 0 else errorfail -> errorfail in let atoi (getPluginInstanceParam inst "init") -> init in let if init == nil then 1 else init -> init in let mkSeqPlugin [inst errorfail nil 0 nil nil 0 0 0] -> obstr in ( loadSeq obstr; let getPluginInstanceUserActions inst -> laction in while (laction != nil) do ( let hd laction -> act in PluginRegisterAction inst act mkfun6 @cbInput obstr; set laction = tl laction; ); PluginRegisterAction inst "Start" mkfun6 @cbStart obstr; PluginRegisterAction inst "Stop" mkfun6 @cbStop obstr; PluginRegisterAction inst "Pause" mkfun6 @cbPause obstr; PluginRegisterAction inst "Reset" mkfun6 @cbReset obstr; setPluginInstanceCbDel inst mkfun2 @deleteOb obstr; if (!init) then nil else cbStart inst nil nil nil nil obstr; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;