/* */ /* Copyright (c) 2003, organization : Scol Technologies Association, owner : Sylvain Huet */ /* For conditions of distribution and use, see copyright notice in dms/l/license.txt */ /* or on 'www.scol-technologies.org' */ /* sDHDMS - mar 00 - by Sylvain HUET */ /* graph part */ typedef Pending= actionPending [DMI User S S S [User r1] Tag];; struct GRAPH= /* GRAPH structure */ [idGRAPH:I,defGRAPH:DEF, masterGRAPH:GRAPH, subGRAPH:[GRAPH r1], modGRAPH:DMI, eventGRAPH:[[S I] r1], actionGRAPH:[[S I] r1], relayGRAPH:[[S I] r1], brutlinkGRAPH:[[S S S S S [[S r1] r1]] r1], zonesrvGRAPH:[[S r1] r1], zonecliGRAPH:[[S r1] r1], linkGRAPH:[[S [[GRAPH S S S [[S r1] r1] I] r1]] r1], linkcliGRAPH:[[S [[I S S S] r1]] r1], hookcliGRAPH:[S r1], fifoGRAPH:[[[Pending I]r1] [[Pending I]r1]] ] mkGRAPH;; typeof siteGRAPH=GRAPH;; /* site graph */ typeof hookInactiveList=[[S r1] r1];; /* list of inactive hooks */ var relayIN=0;; var relayOUT=1;; fun graphbyname(a,b)=!strcmp a.defGRAPH.nameDEF b;; /* graph creation */ fun GRAPHgetThings(dmi,w0,w1)= if dmi==nil then nil else let dmi->[[a [b _]] nxt] in let GRAPHgetThings nxt w0 w1 -> res in if !strcmp a w0 then [b 0]::res else if !strcmp a w1 then [b 1]::res else res;; fun GRAPHgetLinks(dmi)= if dmi==nil then nil else let dmi->[[a [b [c [d [e [f _]]]]]] nxt] in [a b c Tunder d Tunder e strextr Tunder f]::GRAPHgetLinks nxt;; /* initial creation */ fun GRAPHcreate(l,master)= if l==nil then nil else let l->[d nxt] in let _DEFgetDef d "dmi" -> dmi in let _DEFgetDef d "link" -> link in let _DEFgetDef d "zone" -> zone in let mkGRAPH [ set DMSnbDmi=DMSnbDmi+1 d master nil nil GRAPHgetThings dmi "event" "eventC" GRAPHgetThings dmi "action" "actionC" GRAPHgetThings dmi "in" "out" GRAPHgetLinks link getTabInfos zone "zoneS" getTabInfos zone "zoneC" nil nil nil nil] -> node in (set node.subGRAPH=GRAPHcreate _DEFgetSub d node; node::GRAPHcreate nxt master);; fun niltest(a,b)=if a==nil then b else a;; /* solve static links */ fun GRAPHsolveLinks(g,event,links,param,reply,cond,res)= if links==nil then res else let links->[[ev module action param2 reply2 cond2] nxt] in GRAPHsolveLinks g event nxt param reply cond if strcmp ev event then res else if !strcmp module ".." then let g.masterGRAPH-> m in if (switchstr m.relayGRAPH action)==relayOUT then GRAPHsolveLinks m action m.brutlinkGRAPH niltest param param2 niltest reply reply2 conc cond2 cond res else res else let if (nth_char module 0)=='. then search_in_list g.subGRAPH @graphbyname substr module 1 strlen module else search_in_list g.masterGRAPH.subGRAPH @graphbyname module -> d in if d==nil then res else if (switchstr d.relayGRAPH action)==relayIN then GRAPHsolveLinks d action d.brutlinkGRAPH niltest param param2 niltest reply reply2 conc cond2 cond res else let switchstr d.actionGRAPH action -> loc in [d action niltest param param2 niltest reply reply2 conc cond2 cond loc]::res;; /* extract the list of links that can be managed locally by the client */ fun GRAPHdefLocalEvent(l,rs,rc)= if l==nil then [rs rc] else let l->[x nxt] in let x->[d action param reply cond loc] in if loc && cond==nil then GRAPHdefLocalEvent nxt rs [d.idGRAPH action param reply]::rc else GRAPHdefLocalEvent nxt x::rs rc;; /* test wether there is a link to a server of with a condition (then it should go always through the server) */ fun GRAPHisHookEvent(l)= if l==nil then 0 else let l->[[_ _ _ _ cond loc] nxt] in if loc && cond==nil then GRAPHisHookEvent nxt else 1;; /* compute links for one node */ fun GRAPHaddLinks(g,l)= if l==nil then g else let l->[link nxt] in let link->[event _ _ _ _ _] in let switchstr g.eventGRAPH event-> locev in let GRAPHsolveLinks g event link::nil nil nil nil nil -> links in (if links==nil then nil else let if locev==1 then GRAPHdefLocalEvent links nil nil else [links nil] -> [slinks clinks] in (if slinks==nil then nil else let getSwitchStr g.linkGRAPH event -> x in if x==nil then (set g.linkGRAPH=[event slinks]::g.linkGRAPH;nil) else let x->[_ ll] in mutate x<-[_ conc slinks ll]; if clinks==nil then nil else let getSwitchStr g.linkcliGRAPH event -> x in if x==nil then (set g.linkcliGRAPH=[event clinks]::g.linkcliGRAPH;nil) else let x->[_ ll] in mutate x<-[_ conc clinks ll]; if locev==1 then if (strFindList g.hookcliGRAPH event)||(!GRAPHisHookEvent links) then nil else set g.hookcliGRAPH=event::g.hookcliGRAPH else nil ); GRAPHaddLinks g nxt );; /* compute links for a list of nodes and their sons */ fun GRAPHcalcLinks(lg)= if lg==nil then 0 else let lg->[g nxt] in (GRAPHaddLinks g g.brutlinkGRAPH; GRAPHcalcLinks g.subGRAPH; GRAPHcalcLinks nxt);; /* start a list of nodes and their sons */ fun GRAPHstart(lg)= if lg==nil then 0 else let lg->[g nxt] in (_DMIstartModule g; /* while d.fifoDMI!=nil do let getFifo d.fifoDMI ->[x newf] in (set d.fifoDMI=newf; fireEvent d x 1);*/ GRAPHstart g.subGRAPH; GRAPHstart nxt);; /* desactiv a list of nodes */ fun GRAPHdelete(l)= if l==nil then 0 else let l->[g n] in let g.modGRAPH->d in (GRAPHdelete g.subGRAPH; /* UdeleteDMI d;*/ execch d.chnDMI d.beforecloseDMI []; set g.masterGRAPH.subGRAPH=remove_from_list g.masterGRAPH.subGRAPH g; set DMSdmi.(g.idGRAPH)=nil; /* _DOCremoveDmiDoc d; _killchannel d.chnDMI; _setenv d.chnDMI nil; set d.chnDMI=nil;*/ GRAPHdelete n);; /* compute list of local link definitions */ fun GRAPHclientLocal2(id,ev,l,res)= if l==nil then res else let l->[[num action param rep] nxt] in GRAPHclientLocal2 id ev nxt (Cloclink [id ev num action param rep])::res;; fun GRAPHclientLocal(id,l,res)= if l==nil then res else let l->[[ev ll] nxt] in GRAPHclientLocal id nxt GRAPHclientLocal2 id ev ll res;; fun GRAPHclientHook(id,l,res)= if l==nil then res else (Chookevent [id strbuild l::nil])::res;; /* misc */ fun GRAPHfullName(g)= if g.masterGRAPH==nil then "" else strcat strcat GRAPHfullName g.masterGRAPH "." g.defGRAPH.nameDEF;; /* _foo */ /* fun GRAPHfooBrutLinks(l)= if l==nil then 0 else let l->[[ev module action param rep cond] nxt] in (_fooS strcatn " -"::ev::" "::module::" "::action::" "::param::" "::rep::" "::(strbuild cond)::nil; GRAPHfooBrutLinks nxt);; fun GRAPHfooLinks2(l)= if l==nil then 0 else let l->[[g action param rep cond loc] nxt] in (_fooS strcatn " ->mod "::g.defGRAPH.nameDEF::" "::(itoa g.idGRAPH)::" ":: action::" "::param::" "::rep::" "::(strbuild cond)::" "::(itoa loc)::nil; GRAPHfooLinks2 nxt);; fun GRAPHfooLinks(l)= if l==nil then 0 else let l->[[ev ll] nxt] in (_fooS strcat "#" ev; GRAPHfooLinks2 ll; GRAPHfooLinks nxt);; fun GRAPHfooThing(l)= if l==nil then 0 else let l->[[name loc] nxt] in (_fooS strcatn "["::name::"]"::(itoa loc)::nil; GRAPHfooThing nxt);; fun GRAPHfooLocLinks2(l)= if l==nil then 0 else let l->[[id action param rep] nxt] in (_fooS strcatn " // "::(itoa id)::" "::action::" "::param::" "::rep::" "::nil; GRAPHfooLocLinks2 nxt);; fun GRAPHfooLocLinks(l)= if l==nil then 0 else let l->[[ev ll] nxt] in (_fooS strcat ">" ev; GRAPHfooLocLinks2 ll; GRAPHfooLocLinks nxt);; fun GRAPHfooHook(l)= _fooS strbuild ("HOOK"::l)::nil;; fun GRAPHfoo(l)= if l==nil then 0 else let l->[g nxt] in (_fooS strcatn ">mod "::g.defGRAPH.nameDEF::" "::(itoa g.idGRAPH)::nil; _fooS "events:"; GRAPHfooThing g.eventGRAPH; _fooS "actions:"; GRAPHfooThing g.actionGRAPH; GRAPHfooBrutLinks g.brutlinkGRAPH; GRAPHfooLinks g.linkGRAPH; GRAPHfooLocLinks g.linkcliGRAPH; GRAPHfooHook g.hookcliGRAPH; GRAPHfoo g.subGRAPH; _fooS "<"; GRAPHfoo nxt);; */ fun GRAPHstartRoot()= let _DEFgetDef siteDef "def" -> def in (set DMSname=getInfo def "name"; set DMSport=atoi getInfo def "port"; let getInfo def "capacity"-> capa in if capa==nil then nil else _reduceCapacity atoi capa; let getInfos def "download" ->[b[f[t _]]] in (set BARfore=htoi f;set BARback=htoi b; set BARtext=htoi t); set DMStimeout=atoi getInfo def "timeout"; let getInfo def "logfile" -> x in if x==nil then nil else set SRVlogfile=x; let getInfo def "blacklist_timeout" -> x in if x==nil then nil else set SRVblacktime=atoi x; let getInfo def "pending_timeout" -> x in if x==nil then nil else set SRVtimeout=atoi x; let getInfo def "pending_simultaneous" -> x in if x==nil then nil else set SRVsimult=atoi x; 0 ) ;; /* API */ fun _GRAPHinit()= set DMSnbDmi=-1; set siteGRAPH=hd GRAPHcreate _DEFgetRoot::nil nil; set DMSnbDmi=DMSnbDmi+1; GRAPHcalcLinks siteGRAPH::nil; set DMSdmi=mktab DMSnbDmi nil; GRAPHstart siteGRAPH::nil;; fun _GRAPHclientLinks(g)= GRAPHclientLocal g.idGRAPH g.linkcliGRAPH GRAPHclientHook g.idGRAPH g.hookcliGRAPH (Cendgraph [g.idGRAPH])::nil;; fun _GRAPHgetLinks(g,ev)= switchstr g.linkGRAPH ev;; fun _GRAPHid(g)=g.idGRAPH;; fun _GRAPHsetHookInactive(i,l)= if l==nil then 0 else let l->[[a _] nxt] in (set hookInactiveList=((itoa i)::a::nil)::hookInactiveList; _GRAPHsetHookInactive i nxt);; fun _GRAPHgetHookInactive()= if hookInactiveList==nil then nil else ChookInactive [strbuild hookInactiveList];; fun findLinkCli2(l,i,act)= if l==nil then 0 else let l->[[i0 act0 _ _] nxt] in if i==i0 && !strcmp act act0 then 1 else findLinkCli2 nxt i act;; fun findLinkCli(l,i,act)= if l==nil then 0 else let l->[[_ ll] nxt] in if findLinkCli2 ll i act then 1 else findLinkCli nxt i act;; fun GRAPHfindLinkCli(g,i,act)=findLinkCli g.linkcliGRAPH i act;; /* fun _GRAPHfoo()= GRAPHfoo siteGRAPH::nil;; */