*** lookup.m   the lookup service ******8
*** used by SSPTK, CSPTK


fmod LOOKUP-CLASS is
  inc LOOKUP-IFACE .
  inc SERVICE-TABLE .
  op LOOKUP : -> Cid .
  op svctable : ServiceTable -> Attribute .
endfm


mod LOOKUP is
  inc LOOKUP-CLASS .
 
  rl[lookup.register]:
    < O:Oid : LOOKUP | svctable(st:ServiceTable) >
    msg(O:Oid, C:Oid, registerReq(sname:String, sp:Data))
    =>
    < O:Oid : LOOKUP | 
                svctable(st:ServiceTable, (sname:String := sp:Data)) >
    msg(C:Oid, O:Oid, registerReply) .

  rl[lookup.lookup]:
    < O:Oid : LOOKUP | svctable(st:ServiceTable) >
    msg(O:Oid, C:Oid, lookupReq(sname:String))
    =>
    < O:Oid : LOOKUP | svctable(st:ServiceTable) >
     msg(C:Oid, O:Oid, 
         if (lookup(st:ServiceTable, sname:String) == noEntry)
         then lookupFail(sname:String)
         else lookupOk(sname:String, 
                       svcProxy(lookup(st:ServiceTable, sname:String)))
         fi) .
endm

