Author: derek Date: Tue Sep 12 01:17:27 2006 New Revision: 87 Modified: sofaswitch/trunk/callflow/src/dnd.cpp sofaswitch/trunk/callflow/src/eventer.cpp sofaswitch/trunk/callflow/src/shapelist.cpp sofaswitch/trunk/callflow/src/stoptimer.cpp sofaswitch/trunk/callflow/src/timer.cpp Log: Add more system code to handle start and stop of timers, and collect events. Fix some existing code. Modified: sofaswitch/trunk/callflow/src/dnd.cpp ============================================================================== --- sofaswitch/trunk/callflow/src/dnd.cpp (original) +++ sofaswitch/trunk/callflow/src/dnd.cpp Tue Sep 12 01:17:27 2006 @@ -136,15 +136,18 @@ wxString LabelledPoint::GetFullLabel() const { - wxString kindLabel = DndShape::GetKindName((DndShape::Kind)otherNodeKind); - kindLabel.Replace(" ", "_", true); //Replace all spaces with underscores. + if (otherNodeKind == DndShape::None) + return "None"; - wxString answer = wxString::Format("(\"%s\", %d, \"%s\" )", - otherNodeLabel.c_str(), - otherNodeIndex, - kindLabel.c_str()); + wxString kindLabel = DndShape::GetKindName((DndShape::Kind)otherNodeKind); + kindLabel.Replace(" ", "_", true); //Replace all spaces with underscores. + + wxString answer = wxString::Format("(\"%s\", %d, \"%s\" )", + otherNodeLabel.c_str(), + otherNodeIndex, + kindLabel.c_str()); - return answer; + return answer; } bool LabelledPoint::SetKindValue(MyListShapesExtended & activeShapes) Modified: sofaswitch/trunk/callflow/src/eventer.cpp ============================================================================== --- sofaswitch/trunk/callflow/src/eventer.cpp (original) +++ sofaswitch/trunk/callflow/src/eventer.cpp Tue Sep 12 01:17:27 2006 @@ -84,8 +84,8 @@ { file.AddLine(" def Eventer(self, sTuple): "); file.AddLine(" a,b,c = sTuple"); - file.AddLine(" print \"Eventer \", a "); - file.AddLine(" return (1,2,3)"); + file.AddLine(" self.currentHandlers[self.data[a][\"Event\"] = self.data[a][\"Event Handler\"] "); + file.AddLine(" return self.data[a][\"OutputKeepGoing\"] "); file.AddLine(""); return true; @@ -104,7 +104,7 @@ wxNode *outputNode = (wxNode *)GetOutputPoints().GetFirst(); const wxString & outputLabel = ((LabelledPoint *)outputNode->GetData())->GetFullLabel(); - file.AddLine(wxString::Format(" \"OutputFromEvent\" : ")); + file.AddLine(wxString::Format(" \"Event Handler\" : ")); file.AddLine(wxString::Format(" %s, ", outputLabel.c_str())); outputNode = outputNode->GetNext(); Modified: sofaswitch/trunk/callflow/src/shapelist.cpp ============================================================================== --- sofaswitch/trunk/callflow/src/shapelist.cpp (original) +++ sofaswitch/trunk/callflow/src/shapelist.cpp Tue Sep 12 01:17:27 2006 @@ -278,19 +278,23 @@ file.AddLine(" "); file.AddLine("import sys "); file.AddLine("import os "); - file.AddLine("import time "); file.AddLine("import socket "); - file.AddLine("import Queue "); file.AddLine("import distutils "); - file.AddLine("import thread "); + file.AddLine("import random "); file.AddLine("from twisted.internet import reactor, protocol "); file.AddLine(" "); - + file.AddLine("class MyEvent(): "); + file.AddLine(" self.name = None "); + file.AddLine(" self.onEvent = None "); /*Go here on receiving event*/ + file.AddLine(" "); file.AddLine("class Controller(protocol.Protocol): "); file.AddLine(" def __init__(self): "); file.AddLine(" self.graphSet = False "); file.AddLine(" self.connectionIsMade = False "); file.AddLine(" self.endProgramNow = False "); + file.AddLine(" self.generatedEvents = [] "); + file.AddLine(" self.pendingEvents = [] "); + file.AddLine(" self.currentHandlers= {} "); char c= 34; wxString tString = wxString::Format(" self.quote = \"\\%c\"", c); file.AddLine(tString.c_str()); @@ -306,6 +310,7 @@ file.AddLine(" for k,v in self.data.iteritems(): "); file.AddLine(" if k[:16] == \"Start_Processing\": "); file.AddLine(" self.firstNode = k "); + file.AddLine(" self.nextNode = k "); file.AddLine(" print \"first node is \", k "); file.AddLine(" break "); file.AddLine(" self.timeout = reactor.callLater(0, self.startTimerExpired, \"graph\")"); @@ -317,6 +322,27 @@ file.AddLine(" self.connectionIsMade = True "); file.AddLine(" if self.graphSet and self.connectionIsMade:"); file.AddLine(" print \"start processing now \" "); + file.AddLine(" "); + file.AddLine(" def DeleteThisEvent(self, killEvent): "); + file.AddLine(" for i in range(len(self.pendingEvents)): "); + file.AddLine(" if self.pendingEvents[i].name == killEvent: "); + file.AddLine(" self.pendingEvents.pop(i) "); + file.AddLine(" break "); + file.AddLine(" for i in range(len(self.generatedEvents)): "); + file.AddLine(" if self.generatedEvents[i].name == killEvent:"); + file.AddLine(" self.generatedEvents.pop(i) "); + file.AddLine(" break "); + file.AddLine(" "); + + file.AddLine(" def transferEventToGenerated(self, data) "); + file.AddLine(" for i in range(len(self.pendingEvents)) "); + file.AddLine(" if self.pendingEvents[i].name == data:"); + file.AddLine(" self.generatedEvents.append(self.pendingEvents.pop(i)) "); + file.AddLine(" break; "); + file.AddLine(" "); + file.AddLine(" def timerObjectExpired(self, data): "); + file.AddLine(" eName= data[0 : (len(data)-8)] "); + file.AddLine(" self.transferEventToGenerated(eName) "); file.AddLine(" "); file.AddLine(" def startWorkNow(): "); file.AddLine(" sTuple = \"(\" + self.quote + self.firstNode + self.quote + \", 0, \" +self.quote + \"Start_Processing\" + self.quote + \")\""); Modified: sofaswitch/trunk/callflow/src/stoptimer.cpp ============================================================================== --- sofaswitch/trunk/callflow/src/stoptimer.cpp (original) +++ sofaswitch/trunk/callflow/src/stoptimer.cpp Tue Sep 12 01:17:27 2006 @@ -33,7 +33,7 @@ displayData[displayData.size()] = InformationSection(wxT("Tool Tip"), GetName()); displayData[displayData.size()] = - InformationSection(wxT("Timer to stop"), wxT("self.label=\"first\"")); + InformationSection(wxT("Timer to stop"), wxT("thistimer")); } @@ -54,8 +54,10 @@ bool DndShapeStopTimer::WriteSystemCode(wxTextFile & file) { file.AddLine(" def Timer(self, sTuple): "); + file.AddLine(" killTimer = \"Timer\" + self.data[a][\"Timer label\"]"); + file.AddLine(" self.DeleteThisEvent(killTimer) "); file.AddLine(" a,b,c = sTuple"); - file.AddLine(" return data[a][\"Output\"]"); + file.AddLine(" return self.data[a][\"Output\"]"); file.AddLine(""); return true; Modified: sofaswitch/trunk/callflow/src/timer.cpp ============================================================================== --- sofaswitch/trunk/callflow/src/timer.cpp (original) +++ sofaswitch/trunk/callflow/src/timer.cpp Tue Sep 12 01:17:27 2006 @@ -27,10 +27,10 @@ relOutputPoints.Add(25, 50); displayData[displayData.size()] = - InformationSection(wxT("Timer period"), wxT("self.period = 2000")); + InformationSection(wxT("Timer period (seconds)"), wxT("2")); displayData[displayData.size()] = - InformationSection(wxT("Timer label"), wxT("self.label=\"first\"")); + InformationSection(wxT("Timer label"), wxT("thistimer")); AdjustIoPoints(); } @@ -76,8 +76,13 @@ bool DndShapeTimer::WriteSystemCode(wxTextFile & file) { file.AddLine(" def Timer(self, sTuple): "); + file.AddLine(" event = MyEvent "); + file.AddLine(" self.r = repr(random.random())[2:10] "); //Last 8 chars of name are "random" + file.AddLine(" event.name = \"Timer\" + self.data[a][\"Timer label\"] + self.r"); + file.AddLine(" self.pendingEvents.append(event) "); + file.AddLine(" reactor.callLater(self.data[a][\"Timer period\"], self.timerEventExpired, event.name)"); file.AddLine(" a,b,c = sTuple"); - file.AddLine(" return data[a][\"Output\"]"); + file.AddLine(" return self.data[a][\"Output\"]"); file.AddLine(""); return true; @@ -85,25 +90,25 @@ bool DndShapeTimer::WriteThisShapeInfo(wxTextFile & file) { - file.AddLine(wxString::Format("\"%s\" : { ", GetKey().c_str())); + file.AddLine(wxString::Format(" \"%s\" : { ", GetKey().c_str())); wxNode *inputNode = (wxNode *)GetInputPoints().GetFirst(); const wxString & inputLabel = ((LabelledPoint *)inputNode->GetData())->GetFullLabel(); - file.AddLine(wxString::Format(" \"Input\" : ")); - file.AddLine(wxString::Format(" %s, ", inputLabel.c_str())); + file.AddLine(wxString::Format(" \"Input\" : ")); + file.AddLine(wxString::Format(" %s, ", inputLabel.c_str())); wxNode *outputNode = (wxNode *)GetOutputPoints().GetFirst(); const wxString & outputLabel = ((LabelledPoint *)outputNode->GetData())->GetFullLabel(); - file.AddLine(wxString::Format(" \"Output\" : ")); - file.AddLine(wxString::Format(" %s, ", outputLabel.c_str())); + file.AddLine(wxString::Format(" \"Output\" : ")); + file.AddLine(wxString::Format(" %s, ", outputLabel.c_str())); - file.AddLine(wxString::Format(" \"Timer period\" : ")); - file.AddLine(wxString::Format(" \"%s\", ", displayData[1].data.c_str())); + file.AddLine(wxString::Format(" \"Timer period\" : ")); + file.AddLine(wxString::Format(" %s, ", displayData[1].data.c_str())); - file.AddLine(wxString::Format(" \"Timer label\" : ")); - file.AddLine(wxString::Format(" \"%s\", ", displayData[2].data.c_str())); + file.AddLine(wxString::Format(" \"Timer label\" : ")); + file.AddLine(wxString::Format(" \"%s\", ", displayData[2].data.c_str())); - file.AddLine(wxString::Format(" },")); + file.AddLine(wxString::Format(" },")); return true; }
participants (1)
-
SofaSWITCH SVN