[Sofaswitch-svn] [commit] r210 - in sofaswitch/trunk/callflow: docs/current src tests
Author: derek Date: Sun Nov 19 19:37:21 2006 New Revision: 210 Added: sofaswitch/trunk/callflow/tests/child.src sofaswitch/trunk/callflow/tests/parent.src Modified: sofaswitch/trunk/callflow/docs/current/eachicon.dxy sofaswitch/trunk/callflow/src/loadnewgraph.cpp sofaswitch/trunk/callflow/src/shapelist.cpp Log: Add a child and parent file, which illustrate the load new graph item. Add code to the loadnewgraph functions to do the things described in the documentation. Add to the documentation so that it describes correctly how loadnewgraph works. Add to the generated python code the notion of self.parentId, and the ability to pass variable data from the parent to the child. Modified: sofaswitch/trunk/callflow/docs/current/eachicon.dxy ============================================================================== --- sofaswitch/trunk/callflow/docs/current/eachicon.dxy (original) +++ sofaswitch/trunk/callflow/docs/current/eachicon.dxy Sun Nov 19 19:37:21 2006 @@ -363,8 +363,15 @@ As a convenience, the child process always has a Python variable, "self.parentId" defined, which contains the id of the child process. The child -may send a message (via the server) to the parent Id indicating status. +may send a message (via the server) to the parent Id indicating status. The +variable "self.parentId" is None, if there is no parent. +The data (or Python variable) specified in the bottom rectangle of the +properties window is contained in Python variable, "self.userData" of the +child graph. This variable is None, if no data was specified. If there is an +error in processing the specified variable, None will be assigned to +"self.userData" + The graph in the figure \image html exloadnewgraph.png illustrates the operation of this item. There are two event handlers setup, @@ -380,7 +387,11 @@ \li if the parent graph is itself a child graph, only the processing of the parent graph is terminated. - +As a convenience, when the child dies, the server will automatically send an +"Advise on termination message" to the parent. Thus, the parent has a way of +knowing when a child graph terminates. There is no error if the parent has +died before the child. In this case, the "advice on termination" mesasge is +never sent - the server has nowhere to send it. Modified: sofaswitch/trunk/callflow/src/loadnewgraph.cpp ============================================================================== --- sofaswitch/trunk/callflow/src/loadnewgraph.cpp (original) +++ sofaswitch/trunk/callflow/src/loadnewgraph.cpp Sun Nov 19 19:37:21 2006 @@ -29,6 +29,9 @@ displayData[displayData.size()] = InformationSection(wxT("new graph file (Python code)"), wxT("\"file_graph\"")); + displayData[displayData.size()] = + InformationSection(wxT("Python variable to pass to child"), wxT("self.data[a]")); + AdjustIoPoints(); } @@ -69,14 +72,20 @@ file.AddLine(" def Load_New_Graph(self, sTuple): "); file.AddLine(" a,b,c = sTuple "); file.AddLine(" try: "); - file.AddLine(" self.fname = eval(self.data[a][\"new graph file\"]) "); + file.AddLine(" self.udata = (self.myId, eval(self.data[a][\"user variable\"]) )"); file.AddLine(" except: "); + file.AddLine(" self.udata = (self.myId, None) "); + file.AddLine(" "); + file.AddLine(" try: "); + file.AddLine(" self.fname = eval(self.data[a][\"new graph file\"]) "); + file.AddLine(" except: "); file.AddLine(" print \"The new graph file \", self.data[a][\"new graph file\"], \" is not a valid Python string\" "); file.AddLine(" self.fname = None "); file.AddLine(" f = MyFactory() "); file.AddLine(" f.isMaster = False "); file.AddLine(" f.setGraph(self.fname) "); file.AddLine(" f.setMaster(False) "); + file.AddLine(" f.setUserData(self.udata) "); file.AddLine(" reactor.connectTCP(sofaServer, 5000, f) "); file.AddLine(" return self.data[a][\"Output\"] "); file.AddLine(""); @@ -100,6 +109,10 @@ file.AddLine(wxString::Format(" \"new graph file\" : ")); wxString dest = ProtectString(displayData[1].data); + file.AddLine(wxString::Format(" \"%s\", ", dest.c_str())); + + file.AddLine(wxString::Format(" \"user variable\" : ")); + dest = ProtectString(displayData[2].data); file.AddLine(wxString::Format(" \"%s\", ", dest.c_str())); file.AddLine(wxString::Format(" },")); Modified: sofaswitch/trunk/callflow/src/shapelist.cpp ============================================================================== --- sofaswitch/trunk/callflow/src/shapelist.cpp (original) +++ sofaswitch/trunk/callflow/src/shapelist.cpp Sun Nov 19 19:37:21 2006 @@ -310,6 +310,7 @@ file.AddLine(" self.knownNetworkMessages= [] "); file.AddLine(" self.knownNetworkMessages.append(\"REQUESTNEWID\") "); file.AddLine(" self.knownNetworkMessages.append(\"RECEIVEDDTMF\") "); + file.AddLine(" self.knownNetworkMessages.append(\"Terminating\") "); // file.AddLine(" self.knownNetworkMessages.append(\"\") "); char c= 34; wxString tString = wxString::Format(" self.quote = \"\\%c\"", c); @@ -322,6 +323,16 @@ file.AddLine(" process that was invoked from the command line. "); file.AddLine(" \"\"\" "); file.AddLine(" self.isMaster = newIsMaster "); + file.AddLine(" "); + file.AddLine(" def setUserData(self, newData): "); + file.AddLine(" \"\"\"transfer data process, which is required when we "); + file.AddLine(" create a child graph of a parent graph, when we have "); + file.AddLine(" spawned a new process. The variable self.parentId is "); + file.AddLine(" the id of the parent, or None, if there is no parent "); + file.AddLine(" The variable self.userData contains the data transferred, "); + file.AddLine(" or None, if there is no data data transferred. "); + file.AddLine(" \"\"\" "); + file.AddLine(" self.parentId, self.userData = newData "); file.AddLine(" "); file.AddLine(" def setGraphData(self, graphFile): "); file.AddLine(" \"\"\"Read in the file which describes where the flow "); @@ -493,6 +504,11 @@ file.AddLine(" if self.countReceived == 1: "); file.AddLine(" self.myId = oneMessage; "); file.AddLine(" self.timeout2 = reactor.callLater(0, self.startTimerExpired, \"connected\")"); + file.AddLine(" try: "); + file.AddLine(" self.tmsg= \"AdviseOnTermination \" + self.parentId + \"\\0\" "); + file.AddLine(" self.transport.write(self.tmsg) "); + file.AddLine(" except: "); + file.AddLine(" self.tmsg = None "); file.AddLine(" else: "); file.AddLine(" self.processReceivedMessage(oneMessage)"); file.AddLine(" "); @@ -555,6 +571,7 @@ file.AddLine(" self.myController = p "); file.AddLine(" self.myController.setGraphData(self.myGraphName) "); file.AddLine(" self.myController.setMaster(self.isMaster) "); + file.AddLine(" self.myController.setUserData(self.userData) "); file.AddLine(" return p "); file.AddLine(" "); file.AddLine(" def setGraph(self, newName): "); @@ -563,10 +580,14 @@ file.AddLine(" def setMaster(self, newMaster): "); file.AddLine(" self.isMaster = newMaster "); file.AddLine(" "); + file.AddLine(" def setUserData(self, newData): "); + file.AddLine(" self.userData = newData "); file.AddLine(" "); + file.AddLine(" "); file.AddLine("f = MyFactory() "); file.AddLine(wxString::Format("f.setGraph(\"%s\") ", graphFileName.c_str())); file.AddLine("f.setMaster(True) "); + file.AddLine("f.setUserData((None, None)) "); file.AddLine("reactor.connectTCP(sofaServer, 5000, f) "); file.AddLine("reactor.run() "); file.AddLine(" "); Added: sofaswitch/trunk/callflow/tests/child.src ============================================================================== --- (empty file) +++ sofaswitch/trunk/callflow/tests/child.src Sun Nov 19 19:37:21 2006 @@ -0,0 +1 @@ +20<B>531<B>142<B> extra <special>Tool Tip<ms>Death<ms><special> <B><Shape>1<B>518<B>50<B> extra <special>Tool Tip<ms>Start Processing<ms><special> <B><Shape>10<B>528<B>93<B> extra <special>Tool Tip<ms>Python<ms><special>Python Code<ms>print "CHILD says::: parent id is ", self.parentId, " user data is ", self.userData<ms><special> <B><Shape> Added: sofaswitch/trunk/callflow/tests/parent.src ============================================================================== --- (empty file) +++ sofaswitch/trunk/callflow/tests/parent.src Sun Nov 19 19:37:21 2006 @@ -0,0 +1 @@ +14<B>574<B>226<B> extra <special>Tool Tip<ms>Eventer<ms><special>Event sought (Python code)<ms><ms><special>Event sought (Regular Exp)<ms>Terminating<ms><special>Python variable to hold event data<ms>self.termTime<ms><special> <B><Shape>14<B>533<B>200<B> extra <special>Tool Tip<ms>Eventer<ms><special>Event sought (Python code)<ms><ms><special>Event sought (Regular Exp)<ms>timer<ms><special>Python variable to hold event data<ms>self.eventData<ms><special> <B><Shape>18<B>518<B>99<B> extra <special>Tool Tip<ms>Load New Graph<ms><special>new graph file (Python code)<ms>"child.graph"<ms><special>Python variable to pass to child<ms>self.data[a]<ms><special> <B><Shape>2<B>564<B>314<B> extra <special>Tool Tip<ms>End Processing<ms><special> <B><Shape>1<B>518<B>50<B> extra <special>Tool Tip<ms>Start Processing<ms><special> <B><Shape>2<B>599<B>249<B> extra <special>Tool Tip<ms>End Processing<ms><special> <B><Shape>20<B>534<B>247<B> extra <special>Tool Tip<ms>Death<ms><special> <B><Shape>10<B>572<B>265<B> extra <special>Tool Tip<ms>Python<ms><special>Python Code<ms>print "child has terminated", self.termTime<ms><special> <B><Shape>12<B>519<B>146<B> extra <special>Tool Tip<ms>Timer<ms><special>Timer period (seconds, Python code)<ms>10<ms><special>Timer label (Python code)<ms>self.myId + "thistimer"<ms><special> <B><Shape>
participants (1)
-
SofaSWITCH SVN