This is one of the most user-visible areas for AWS2, and I have already
received some suggestions on it.  However, I want to have user consensus
before I commit to changing this.

How it currently works
----------------------

You create a script interface object through the iAws2 object.  You also
register a callback function.  The callback function is then called when
the notification object is called from the script, and a way to get
arguments and properties is provided.

Sample code for this looks like this:

/** Callback for particle fountain events like Start/Stop, etc. */
static void onParticleFountainEvent(iAws2ScriptObject *info)
{
        switch(info->GetIntArg(0))
        {
                default:
                        pe2App()->ReportError("Unknown particle fountain
command received!");    
        }
}


void initializeScriptEvents(csRef<iAws2> aws)
{
        iAws2ScriptObject *so;
                
        so = aws->CreateScriptObject("particleFountain",
onParticleFountainEvent);
        
}


An Alternative Method
---------------------

This would be very similar to the current method, except that you would
use a functor.

So the code above would be more like this:

class onParticleFountainEvent : public iAws2ScriptEvent
{
public:
        /** Callback for particle fountain events like Start/Stop, etc.
*/
        static void operator()(iAws2ScriptObject *info)
        {
                switch(info->GetIntArg(0))
                {
                        default:
                                pe2App()->ReportError("Unknown particle
fountain command received!");   
                }
        }
};


void initializeScriptEvents(csRef<iAws2> aws)
{
        iAws2ScriptObject *so;
                
        so = aws->CreateScriptObject("particleFountain", new
onParticleFountainEvent());
        
}

============================================================

Q&A
---

Q: Why did you implement the procedure-like version?
A: Because people hated (or seemed to hate) the AWS functor approach.  I
personally like it.  

Q: In what ways is the object-oriented method superior?
A: This is mostly a matter of taste, but you can wrap the event handlers
with the data that they might need, much like all OOP code.

Q: Why might the procedural-callback variation be superior?
A: Again, this is mostly a matter of taste, but it *is* simpler to
define a callback in that it doesn't require as much boiler-plate.  Of
course, the boiler-plate could be macro-ized.

Q: Do you really care which method is used?
A: Not really.  I'm not a purist, so I like to go with what works, and
what's easy for the majority.  That's why I'm posting this question.  If
I don't get much feedback I'll implement the functor approach and let
res field the hate mail. :-D

-={C}=-




-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642
_______________________________________________
Crystal-main mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/crystal-main
Unsubscribe: mailto:[EMAIL PROTECTED]

Reply via email to