@@ -79,6 +79,7 @@ import StackOverflow;
7979import System;
8080import TplMain;
8181import Util;
82+ import ZeroMQ;
8283
8384protected function serverLoop
8485"This function is the main loop of the server listening
@@ -115,6 +116,40 @@ algorithm
115116 end match;
116117end serverLoop;
117118
119+ protected function serverLoopZMQ
120+ "This function is the main loop of the ZeroMQ server listening
121+ to a port which recieves modelica expressions."
122+ input Boolean cont;
123+ input Option< Integer > inZMQSocket;
124+ input GlobalScript.SymbolTable inInteractiveSymbolTable;
125+ output GlobalScript.SymbolTable outInteractiveSymbolTable;
126+ algorithm
127+ outInteractiveSymbolTable := match (cont,inZMQSocket,inInteractiveSymbolTable)
128+ local
129+ Boolean b;
130+ String str,replystr;
131+ GlobalScript.SymbolTable newsymb,ressymb,isymb;
132+ Option< Integer > zmqSocket;
133+ case (false ,_,isymb) then isymb;
134+ case (_,SOME(0 ),_) then fail();
135+ case (_,zmqSocket,isymb)
136+ equation
137+ str = ZeroMQ.handleRequest(zmqSocket);
138+ if Flags.isSet(Flags.INTERACTIVE_DUMP) then
139+ Debug.trace("------- Recieved Data from client -----\n " );
140+ Debug.trace(str);
141+ Debug.trace("------- End recieved Data-----\n " );
142+ end if ;
143+ (b,replystr,newsymb) = handleCommand(str, isymb) "Print.clearErrorBuf &" ;
144+ replystr = if b then replystr else "quit requested, shutting server down\n " ;
145+ ZeroMQ.sendReply(zmqSocket, replystr);
146+ if not b then
147+ ZeroMQ.close(zmqSocket);
148+ end if ;
149+ then serverLoopZMQ(b, zmqSocket, newsymb);
150+ end match;
151+ end serverLoopZMQ;
152+
118153protected function makeDebugResult
119154 input Flags.DebugFlag inFlag;
120155 input String res;
@@ -655,6 +690,14 @@ algorithm
655690 end try;
656691end interactivemodeCorba;
657692
693+ protected function interactivemodeZMQ
694+ "Initiate the interactive mode using ZMQ communication."
695+ input GlobalScript.SymbolTable symbolTable;
696+ algorithm
697+ print("Starting a ZeroMQ server on port " + intString(29500 ) + "\n " );
698+ serverLoopZMQ(true , ZeroMQ.initialize(29500 ), symbolTable);
699+ end interactivemodeZMQ;
700+
658701protected function serverLoopCorba
659702"This function is the main loop of the server for a CORBA impl."
660703 input GlobalScript.SymbolTable inSettings;
@@ -866,6 +909,8 @@ algorithm
866909 interactivemode(readSettings(args));
867910 elseif Flags.isSet(Flags.INTERACTIVE_CORBA) then
868911 interactivemodeCorba(readSettings(args));
912+ elseif Flags.isSet(Flags.INTERACTIVE_ZMQ) then
913+ interactivemodeZMQ(readSettings(args));
869914 else // No interactive flag given, try to flatten the file.
870915 readSettings(args);
871916 FGraphStream.start();
0 commit comments