home *** CD-ROM | disk | FTP | other *** search
/ LineOne ISP Sign-Up 5 / LineOne.iso / assets / cxt / scripts / parentScripts.cst / 00076_glueService parent.ls < prev    next >
Encoding:
Text File  |  2001-01-27  |  4.7 KB  |  166 lines

  1. -- 2000.02.26
  2. -- Clive Green <clivegreen@atlas.co.uk>
  3.  
  4. ------------------------------------------------------------------------------------------------------
  5.  
  6. -- this is used to provide a means of driving the programme using messages received from
  7. -- outside the application (such as Flash 4 movies).
  8.  
  9. ------------------------------------------------------------------------------------------------------
  10.  
  11. -- declare properties:
  12. property main          -- main code directory object
  13. property glue          -- propList of recognised glue calls
  14. property bindings      -- propList identifying the methods (& arguments) invoked by known glue calls
  15. property glueBindings  -- active glue options
  16. property onlineService -- online-related functions
  17.  
  18. ------------------------------------------------------------------------------------------------------
  19.  
  20. on new me,L
  21.   
  22.   -- (1) extract and check arguments:
  23.   
  24.   -- check for a parameter list:
  25.   if ilk(L) <> #propList then return [#error:#noParamListSupplied, #msg:"glueService:new"]
  26.   
  27.   -- a reference to the parent codebase is REQUIRED:
  28.   main = L[#main]
  29.   if (ilk(main) <> #instance) then return [#error:#noMainObjectSupplied, #msg:"glueService:new"]
  30.   
  31.   --------------------
  32.   
  33.   -- (2) obtain binding instructions data:
  34.   dm = main.getDataManager()
  35.   glue = dm.getData([#set:#glueCalls])
  36.   bindings = dm.getData([#set:#callBindings])
  37.   
  38.   -- which glue calls are enabled, and what does each do? build a list:
  39.   glueBindings = [:]
  40.   repeat with i = 1 to count(glue)
  41.     
  42.     -- extract glue name and data:
  43.     g = getPropAt(glue,i)
  44.     L = getAt(glue,i)
  45.     
  46.     -- we want online options only ...
  47.     if L[#active] <> 1 then next repeat
  48.     
  49.     -- what is this glue call bound to?
  50.     b = L[#binding]
  51.     
  52.     -- obtain pukka bindings data:
  53.     if not symbolP(b) then next repeat
  54.     
  55.     bd = bindings[b]
  56.     if ilk(bd) <> #propList then next repeat
  57.     
  58.     -- add the bindingID as a member of the list bd obtained:
  59.     bd[#binding] = b
  60.     
  61.     -- add validated glue call:
  62.     glueBindings[g] = bd
  63.     
  64.   end repeat
  65.   
  66.   ------------------------
  67.   
  68.   -- pass my address back to the caller:
  69.   return me
  70.   
  71.   ----------------------------------------------------------------------------------------------------
  72.   
  73. on glue me,g
  74.   
  75.   -- check glue parameter:
  76.   if voidP(g) then return [#error:#e1013]
  77.   
  78.   -- is glue id a symbol?
  79.   if not symbolP(g) then return [#error:#e1014]
  80.   
  81.   --------------------
  82.   
  83.   -- obtain the bindings data for the glue id g:
  84.   L = glueBindings[g]
  85.   
  86.   -- L is a proplist containing a #methodID, an instance #reference, a bindingID symbol and
  87.   -- (optionally) a list of arguments. Its profile is:
  88.   --
  89.   --     [#method:<#symbol>, #objectReference:<#symbol>, #bindingID:<#symbol> {,#args[:]}]
  90.   
  91.   -- don't continue without a valid entry:
  92.   if ilk(L) <> #propList then return [#error:#e1015, #msg:"glueID =" && g]
  93.   
  94.   --------------------
  95.   
  96.   -- a method name is required: 
  97.   m = L[#method]
  98.   if voidP(m) then return [#error:#e1016]
  99.   
  100.   -- only allow symbol method refs:
  101.   if not symbolP(m) then return [#error:#e1017]
  102.   
  103.   --------------------
  104.   
  105.   -- a target object reference is also required:  
  106.   o = L[#objectReference]
  107.   if voidP(o) then return [#error:#e1018]
  108.   
  109.   -- only allow symbol refs:
  110.   if not symbolP(o) then return [#error:#e1019]
  111.   
  112.   -- we must resolve the object #name o supplied to a known service object:
  113.   x = main.getServiceManager().getService(o)
  114.   if (ilk(x) <> #instance) then return [#error:#e1020]
  115.   
  116.   -- store the object reference obtained:
  117.   o = x
  118.   
  119.   --------------------
  120.   
  121.   -- extract the bindingID!
  122.   b = L[#binding]
  123.   
  124.   --------------------
  125.   
  126.   -- extract (optional) arguments:
  127.   a = L[#args]
  128.   if not listP(a) then a = [:]
  129.   
  130.   --------------------
  131.   
  132.   -- this option may rely on the presence of dial-up networking:
  133.   
  134.   -- obtain online functions manager as needed:
  135.   if voidP(onlineService) then
  136.     
  137.     sm = main.getServiceManager()
  138.     onlineService = sm.getService(#onlineService)
  139.     
  140.   end if
  141.   
  142.   -- redirect the user to the DUN warning screen as needed:
  143.   if not onlineService.DUNbindingAvailable(b) then
  144.     
  145.     return me.glue(#noDUNmessage)
  146.     exit
  147.     
  148.   end if
  149.   
  150.   --------------------
  151.   
  152.   -- play soundFX (if amy) associated with the glue event g:
  153.   sm = main.getServiceManager()
  154.   fx = sm.getService(#soundFXservice)
  155.   
  156.   fx.playGlueFX(g)
  157.   
  158.   --------------------
  159.   
  160.   -- finally - combine the binding elements into a Lingo expression:
  161.   return call(m,[o],a)
  162.   
  163.   -- note the brackets around o in the above expression - these are used to suppress errors
  164.   -- incurred by calling a non-existent method m within the object o.
  165.   
  166.   ----------------------------------------------------------------------------------------------------