W3C home > Mailing lists > Public > www-voice@w3.org > January to March 2007

RE: [SCXML] Reusing code through functions/templates

From: Barnett, James <James.Barnett@aspect.com>
Date: Wed, 10 Jan 2007 08:38:03 -0500
Message-ID: <57686697B4E28949A90094A6469165C70155AF24@ASP1EXCH1.aspect.com>
To: "Nestor Urquiza" <nestoru@yahoo.com>, <www-voice@w3.org>

Nestor,
 Do these examples help?  They are intended for the next version of the
spec.

- Jim

<?xml version="1.0"?>
<?access-control allow="*"?>
<scxml initialstate="Intro">
  <state id="Intro">
    <invoke src="dialog.vxml#Intro"/>
    <transition event="success" cond="g_DataModel.sessionChrome.playAds"
target="PlayAds"/>
    <transition event="success" cond="!g_DataModel.sessionChrome.playAds
&amp;&amp; g_DataModel.ANIQuality" target="ShouldGoBack"/>
    <transition event="success" cond="!g_DataModel.sessionChrome.playAds
&amp;&amp; !g_DataModel.ANIQuality" target="StartOver"/>
  </state>

  <state id="PlayAds">
    <invoke src="dialog.vxml#PlayAds"/>
    <transition event="success" cond="g_DataModel.ANIQuality"
target="ShouldGoBack"/>
    <transition event="success" cond="!g_DataModel.ANIQuality"
target="StartOver"/>
  </state>

  <state id="StartOver">
    <onenter>
      <script>enterStartOver();</script>   
    </onenter>
    <invoke src="dialog.vxml#StartOver">
      <param name="gotItFromANI" expr="g_DataModel.gotItFromANI"/>
      <finalize> 
        <script>finalizeStartOver();</script>   
      </finalize>
    </invoke>
    <transition event="success" target="ShouldGoBack"/>
    <transition event="doOver" target="StartOver"/>
    <transition event="restart" target="Intro"/> <!-- bail out to caller
-->
  </state>

  <state id="ShouldGoBack">
    <invoke src="dialog.vxml#ShouldGoBack">
      <param name="cityState" expr="g_DataModel.cityState"/>
      <param name="gotItFromANI" expr="g_DataModel.gotItFromANI"/>
      <finalize> 
        <script>finalizeShouldGoBack();</script>   
      </finalize>
    </invoke>
    <transition event="highWay" target="HighwayReport"/>
    <transition event="go_back" target="StartOver"/>
    <transition event="doOver" target="ShouldGoBack"/>
    <transition event="restart" target="Intro"/>
  </state>

  <state id="HighwayReport">
    <invoke src="dialog.vxml#HighwayReport">
      <param name="cityState" expr="g_DataModel.cityState"/>
      <param name="gotItFromANI" expr="g_DataModel.gotItFromANI"/>
      <param name="playHRPrompt" expr="g_DataModel.playHRPrompt"/>
      <param name="metroArea" expr="g_DataModel.metroArea"/>
      <finalize> 
        <script>finalizeHighwayReport();</script>   
      </finalize>
    </invoke>
    <transition event="highway" target="PlayHighway"/>
    <transition event="go_back" target="StartOver"/>
    <transition event="doOver" target="HighwayReport"/>
    <transition event="fullreport" target="FullReport"/>
    <transition event="restart" target="Intro"/>
  </state>

  <state id="FullReport">
    <invoke src="dialog.vxml#FullReport">
      <param name="cityState" expr="g_DataModel.cityState"/>
      <param name="metroArea" expr="g_DataModel.metroArea"/>
      <finalize> 
        <script>finalizeFullReport();</script>   
      </finalize>
    </invoke>
    <transition event="go_back" target="HighwayReport"/>
    <transition event="new_city" target="StartOver"/>
  </state>

  <state id="PlayHighway">
    <invoke src="dialog.vxml#PlayHighway">
      <param name="cityState" expr="g_DataModel.cityState"/>
      <param name="curHighway" expr="g_DataModel.curHighway"/>
      <finalize> 
        <script>finalizePlayHighway();</script>   
      </finalize>
    </invoke>
    <transition event="go_back" target="HighwayReport"/>
  </state>
</scxml>

and:

<?xml version="1.0"?>
<?access-control allow="*"?>
<smxml initialstate="master">
<state id="master">
    <initial id="init1">
      <transition target="_home"/>
    </initial>
    <transition event="new_dealer" target="NewDealer"/>
    <transition event="mumble" target="_home"/> <!-- bail out to caller
-->
    <transition event="silence" target="_home"/> <!-- bail out to caller
-->
    <state id="_home">
      <onenter>
        <script>
        g_DataModel = {};
        </script>
      </onenter>    
      <invoke src="datamodel.v3#InitDataModel"/>
      <finalize>
        <script>
        var n;
        for (n in g_InvokeResults) {
            g_DataModel[n] = g_InvokeResults[n];
        }
        </script>
      </finalize>
      <transition event="success" target="Welcome"/>
    </state>

    <state id="Welcome">
      <invoke src="dialog.vxml#Welcome">
        <param name="skinpath" expr="g_DataModel.skinpath"/>
      </invoke>
      <transition event="success" target="Intro2"/>
    </state>

    <state id="Intro2">
      <invoke src="dialog.vxml#Intro2">
        <param name="skinpath" expr="g_DataModel.skinpath"/>
      </invoke>
      <transition event="success" target="EvalDeal"/>
    </state>

    <state id="EvalDeal">
      <onenter>
        <script>enterEvalDeal();</script>
      </onenter>    
      <invoke src="dialog.vxml#EvalDeal">
        <param name="skinpath" expr="g_DataModel.skinpath"/>
        <param name="playercard1" expr="g_DataModel.playercard1"/>
        <param name="playercard2" expr="g_DataModel.playercard2"/>
        <param name="playertotal"
expr="g_DataModel.blackjack.GetTotalOf('caller').toString()"/>
        <param name="dealercardshowing"
expr="g_DataModel.dealercardshowing"/>
      </invoke>
      <transition event="success" target="AskHit"/>
    </state>

    <state id="AskHit">
      <invoke src="dialog.vxml#AskHit">
        <param name="skinpath" expr="g_DataModel.skinpath"/>
      </invoke>
      <finalize> 
         <script>finalizeAskHit();</script>   
      </finalize>
      <transition event="hit" target="PlayNewCard"/>
      <transition event="stand" target="PlayDone"/>
    </state>

    <state id="PlayNewCard">
      <invoke src="dialog.vxml#PlayNewCard">
        <param name="skinpath" expr="g_DataModel.skinpath"/>
        <param name="playernewcard" expr="g_DataModel.playernewcard"/>
        <param name="playertotal"
expr="g_DataModel.blackjack.GetTotalOf('caller').toString()"/>
      </invoke>
      <transition event="success"
cond="g_DataModel.blackjack.GetTotalOf('caller') &gt;= 21"
target="PlayDone"/>      
      <transition event="success" target="AskHit"/> <!-- less than 21
--> 
    </state>

    <state id="PlayDone">
      <onenter>
        <script>enterPlayDone();</script>
      </onenter>    
      <invoke src="dialog.vxml#PlayDone">
        <param name="skinpath" expr="g_DataModel.skinpath"/>
        <param name="gameresult"
expr="g_DataModel.blackjack.GetGameResult()"/>
        <param name="dealertotal"
expr="g_DataModel.blackjack.GetTotalOf('dealer').toString()"/>
      </invoke>
      <transition event="playagain" target="Intro2"/>
      <transition event="quit" target="_home"/>      
    </state>

    <state id="NewDealer">
      <onenter>
       <script>enterNewDealer();</script>
      </onenter>
      <invoke src="dialog.vxml#Dummy"/>
      <transition event="success" target="Welcome"/>    
    </state>
  </state>
</smxml>

to:

<?xml version="1.0"?>
<?access-control allow="*"?>
<scxml initialstate="master">
<state id="master">
    <initial id="init1">
      <transition target="_home"/>
    </initial>
    <transition event="new_dealer" target="NewDealer"/>
    <transition event="mumble" target="_home"/> <!-- bail out to caller
-->
    <transition event="silence" target="_home"/> <!-- bail out to caller
-->
    <state id="_home">
      <onenter>
        <script>
        g_DataModel = {};
        </script>
      </onenter>    
      <invoke src="datamodel.v3#InitDataModel">
        <finalize>
          <script>
          var n;
          for (n in g_InvokeResults) {
              g_DataModel[n] = g_InvokeResults[n];
          }
          </script>
        </finalize>
      </invoke>
      <transition event="success" target="Welcome"/>
    </state>

    <state id="Welcome">
      <invoke src="dialog.vxml#Welcome">
        <param name="skinpath" expr="g_DataModel.skinpath"/>
      </invoke>
      <transition event="success" target="Intro2"/>
    </state>

    <state id="Intro2">
      <invoke src="dialog.vxml#Intro2">
        <param name="skinpath" expr="g_DataModel.skinpath"/>
      </invoke>
      <transition event="success" target="EvalDeal"/>
    </state>

    <state id="EvalDeal">
      <onenter>
        <script>enterEvalDeal();</script>
      </onenter>    
      <invoke src="dialog.vxml#EvalDeal">
        <param name="skinpath" expr="g_DataModel.skinpath"/>
        <param name="playercard1" expr="g_DataModel.playercard1"/>
        <param name="playercard2" expr="g_DataModel.playercard2"/>
        <param name="playertotal"
expr="g_DataModel.blackjack.GetTotalOf('caller').toString()"/>
        <param name="dealercardshowing"
expr="g_DataModel.dealercardshowing"/>
      </invoke>
      <transition event="success" target="AskHit"/>
    </state>

    <state id="AskHit">
      <invoke src="dialog.vxml#AskHit">
        <param name="skinpath" expr="g_DataModel.skinpath"/>
        <finalize> 
          <script>finalizeAskHit();</script>   
        </finalize>
      </invoke>
      <transition event="hit" target="PlayNewCard"/>
      <transition event="stand" target="PlayDone"/>
    </state>

    <state id="PlayNewCard">
      <invoke src="dialog.vxml#PlayNewCard">
        <param name="skinpath" expr="g_DataModel.skinpath"/>
        <param name="playernewcard" expr="g_DataModel.playernewcard"/>
        <param name="playertotal"
expr="g_DataModel.blackjack.GetTotalOf('caller').toString()"/>
      </invoke>
      <transition event="success"
cond="g_DataModel.blackjack.GetTotalOf('caller') &gt;= 21"
target="PlayDone"/>      
      <transition event="success" target="AskHit"/> <!-- less than 21
--> 
    </state>

    <state id="PlayDone">
      <onenter>
        <script>enterPlayDone();</script>
      </onenter>    
      <invoke src="dialog.vxml#PlayDone">
        <param name="skinpath" expr="g_DataModel.skinpath"/>
        <param name="gameresult"
expr="g_DataModel.blackjack.GetGameResult()"/>
        <param name="dealertotal"
expr="g_DataModel.blackjack.GetTotalOf('dealer').toString()"/>
      </invoke>
      <transition event="playagain" target="Intro2"/>
      <transition event="quit" target="_home"/>      
    </state>

    <state id="NewDealer">
      <onenter>
       <script>enterNewDealer();</script>
      </onenter>
      <invoke src="dialog.vxml#Dummy"/>
      <transition event="success" target="Welcome"/>    
    </state>
  </state>
</scxml>

-----Original Message-----
From: www-voice-request@w3.org [mailto:www-voice-request@w3.org] On
Behalf Of Nestor Urquiza
Sent: Wednesday, January 10, 2007 3:27 AM
To: Barnett, James; www-voice@w3.org
Subject: RE: [SCXML] Reusing code through functions/templates


Thanks for the example. I still think I might be
missing something. That example claims to be an
<invoke> and <finalize> one but I do not see the use
of <finalize> there. 

Furthermore the <invoke> statements refer to the file
dialog.vxml which I do not see there ... maybe because
the file is just the whole example by itself in which
case I would expect to find the bits to be reused like
dialog.vxml#PlayAds but I see no other "PlayAds"
reference than the name of the state where <invoke> is
used.

What I am asking for is an example in which I can see
how params al passed from the invoker bits, how the
invoked ones process those params and return back to
the invoker context the result. The parametrized
invoked bits are supposed to be reusable as we have
been discussing of course.

Thanks again for your help. It is greatly appreciated.

-Nestor
--- "Barnett, James" <James.Barnett@aspect.com> wrote:

> Nestor,
>  We don't believe that <invoke> will change much in
> future drafts.
> There is an example of how to use it in appendix F.3
> of the current
> draft:
>
http://www.w3.org/TR/2006/WD-scxml-20060124/#invokeex
> 
> 
> - Jim
> 
> -----Original Message-----
> From: www-voice-request@w3.org
> [mailto:www-voice-request@w3.org] On
> Behalf Of Nestor Urquiza
> Sent: Monday, January 08, 2007 9:11 AM
> To: www-voice@w3.org
> Subject: RE: [SCXML] Reusing code through
> functions/templates
> 
> 
> Sounds great,
> Do you think the proposed <invoke> mechanism could
> change in future drafts? I am asking because 
> current
> implementations like commons-scxml could potentially
> implement the full invoke mechanism including
> <finalize>.
> 
> In regards to the returning data from <invoke> seems
> like the only way to get the result would be through
> <finalize> right? 
> I am wondering how a sample use case like the below
> should look when using <invoke>:
> 
> Build an external to invoke SCXML piece that returns
> the name of the pet knowing that:
> if animal type="dog" then name="Fido"
> if animal type="cat" then name="Kitty"
> if animal type="bird" then name="Tweety"
> 
> How the above SCXML piece of code should look like
> if
> it must done using SCXML?
> 
> >From the main SCXML we should be able to <invoke>
> several time within even different states the above
> bits passing param animal-type and getting back
> animal-name.
> 
> How the <invoke> node should look like to pass the
> param when invoking?
> 
> How the finalize node should look like to get the
> name
> back in the context variable animalName?
> <var name="animalName" expr="''"/>
> <finalize>
> <!-- what comes here? -->
> <assign name="animalName" expr="what.comes.here.?"/>
> </finalize>
> 
> Many thanks,
> 
> -Nestor
> > 
> > 
> > 
> > --- "Barnett, James" <James.Barnett@aspect.com>
> > wrote:
> > 
> > > Nestor,
> > >   We have two reuse mechanisms in mind.  First
> > off,
> > > <invoke> is
> > > definitely intended to be used so that one SCXML
> > > script can invoke
> > > another.  Note that in this case, the two
> scripts
> > do
> > > not share any
> > > context (but parameters can be passed in and
> out).
> > 
> > > Secondly, there is
> > > an include mechanism that will be expanded in
> the
> > > next draft that allows
> > > one state to include part or all of another
> script
> > > as if by copy, so
> > > that the copied material does share context with
> > the
> > > copying context.  
> > > 
> > > We hope that these two mechanisms will cover
> most
> > of
> > > the common reuse
> > > cases.
> > > 
> > > - Jim
> > > 
> > > -----Original Message-----
> > > From: www-voice-request@w3.org
> > > [mailto:www-voice-request@w3.org] On
> > > Behalf Of Nestor Urquiza
> > > Sent: Friday, January 05, 2007 4:05 PM
> > > To: www-voice@w3.org
> > > Subject: [SCXML] Reusing code through
> > > functions/templates
> > > 
> > > 
> > > Hello guys,
> > > 
> > > I have been discussing about possibilities to
> > reuse
> > > code within SCXML and I wanted to know about the
> > > plans
> > > to offer those possibilities within the SCXML
> > > Specification [1].
> > > 
> > > Basically wherever executable content exists
> there
> > > is
> > > a clear need to reuse code and to apply DRY some
> > way
> > > of grouping code in functions/routines/templates
> > is
> > > needed.
> > > 
> > > Currently I see the following possibilities and
> I
> > > would like to know about any others and of
> course
> > if
> > > there is already a preference among them.
> > > 
> > > 1. <invoke>
> > > 2. <script>
> > > 3. Just as a proposal, I think an XSLT
> templating
> > > alike mechanism (just in terms of the syntax)
> > could
> > > be
> > > used to be able to call passing parameters a
> given
> > > template that in turns could return some result.
> > > 
> > > Thanks,
> > > 
> > > -Nestor
> > > 
> > > [1]
> > >
> >
>
http://marc.theaimsgroup.com/?t=116241382900003&r=1&w=2
> > > 
> > >
> __________________________________________________
> > > Do You Yahoo!?
> > > Tired of spam?  Yahoo! Mail has the best spam
> > > protection around 
> > > http://mail.yahoo.com 
> > > 
> > > 
> > 
> > 
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam
> > protection around 
> > http://mail.yahoo.com 
> > 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam
> protection around 
> http://mail.yahoo.com 
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
Received on Wednesday, 10 January 2007 16:47:34 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 10 January 2007 16:47:39 GMT