swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: compiled and registered swarm XPCOM - could i have a crash course ?


From: Marcus G. Daniels
Subject: Re: compiled and registered swarm XPCOM - could i have a crash course ?
Date: 18 Dec 2001 09:36:40 -0700
User-agent: Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.7

>>>>> "DK" == daniel kottow <address@hidden> writes:

DK> here actually comes my first question, what are the suffixes C and
DK> S for swarm interfaces about ?  for many objects i see:
DK> swarmISwarmObject, swarmISwarmObjectC, swarmISwarmObjectS.

It's the same convention as in Java, explained here:

  http://www.santafe.edu/projects/swarm/archive/list-archive.0112/0036.html

Unfortunately, I need to work on something else right now [about ready
to take the phone off the hook!], and so I can't make a Python test
case, but the steps for instantiating an object are:

1) look up the contract ID by its URN.  That has the form
   urn:swarm:MODULE:CLASSImpl, e.g. urn:swarm:space:Grid2dImpl

2) Call createInstance with the interface you want, e.g. swarmIGrid2d

3) Call the Swarm create method, passing the Zone (globalZone can be
   aquired via urn:swarm:SwarmEnvironmentImpl (which also needs to
   be instantiated)

4) Call QueryInterface to get the specific interface you want from your
   object in #2.

   [I haven't checked to confirm, but my understanding is that XPCOM now has
   a `interface flattening' feature that means that it isn't necessary
   to do QueryInterface to get specific interfaces.]

There is a more complex form of this that involves phase switching 
(the "C" interfaces), along the lines of the URL above.

In JavaScript, I found it was pretty easy to hide object creation
complexity by adding a few functions, like these:

function createComponentUsing (typeName, iid, constructorName, retiid)
{
  var moduleName = env.typeModule (typeName);
  var modulePrefix = moduleName.length == 0 ? "" : moduleName + ".";

  var contractid = "urn:swarm:" + modulePrefix + typeName + "Impl";
  var obj = Components.classes[contractid].createInstance (iid);
  var arglist = new Array ();

  if (constructorName == null)
    constructorName = "create";
  for (var i = 4; i < arguments.length; i++)
    arglist[i - 4 + 1] = arguments[i];
  arglist[0] = env.globalZone;
  obj[constructorName].apply (obj, arglist);
  obj = obj.QueryInterface (retiid != null
                             ? retiid
                             : Components.interfaces["swarmI" + typeName]);
  return obj;
}

function createComponent (typeName)
{
  return createComponentUsing (typeName,
                               Components.interfaces.swarmICreate,
                               "create", null);
}

Then, building on them to make convenience functions like this:

function createRepeatingSchedule (interval)
{
  return createComponentUsing ("Schedule", 
                               Components.interfaces.swarmISchedule,
                               "create_setRepeatInterval",
                               Components.interfaces.swarmISchedule,
                               interval);
}


                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]