Changeset 152:f0701a18628a for src/mlx


Ignore:
Timestamp:
05/05/12 11:40:28 (13 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Made the sending of the closing message more reliable

Location:
src/mlx
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/acft.py

    r150 r152  
    202202                                    "Block time: " +
    203203                                    util.getTimeIntervalString(blockLength))
    204                 bookedFlight = self._flight.bookedFlight
    205                 # FIXME: translate the ICAO into an airport name
    206                 fs.sendMessage(const.MESSAGETYPE_ENVIRONMENT,
    207                                "Flight plan closed. Welcome to %s" % \
    208                                (bookedFlight.arrivalICAO,),
    209                                5)
    210204
    211205    def prepareFlare(self):
  • src/mlx/fs.py

    r134 r152  
    6464        self.daemon = True
    6565
    66     def add(self, messageType, text, duration):
     66    def add(self, messageType, text, duration, disconnect):
    6767        """Add the given message to the requested messages."""
    6868        with self._requestCondition:
    69             self._messages.append((messageType, text, duration))
     69            self._messages.append((messageType, text, duration,
     70                                   disconnect))
    7071            self._requestCondition.notify()
    7172
     
    8081        """Perform the thread's operation."""
    8182        while True:
    82             (messageType, text, duration) = (None, None, None)
     83            (messageType, text, duration, disconnect) = (None, None, None, None)
    8384            with self._requestCondition:
    8485                now = time.time()
     
    9697
    9798                    if self._messages:
    98                         (messageType, text, duration) = self._messages[0]
     99                        (messageType, text,
     100                         duration, disconnect) = self._messages[0]
    99101                        del self._messages[0]
    100102
    101103            if text is not None:       
    102                 self._sendMessage(messageType, text, duration)
    103 
    104     def _sendMessage(self, messageType, text, duration):
     104                self._sendMessage(messageType, text, duration, disconnect)
     105
     106    def _sendMessage(self, messageType, text, duration, disconnect):
    105107        """Send the message and setup the next message time."""
    106108        messageLevel = self._config.getMessageTypeLevel(messageType)
     
    110112        if (messageLevel==const.MESSAGELEVEL_FS or \
    111113            messageLevel==const.MESSAGELEVEL_BOTH):
    112             self._simulator.sendMessage("[MLX] " + text, duration = duration)
     114            if disconnect:
     115                self._simulator.disconnect("[MLX] " + text,
     116                                           duration = duration)
     117            else:
     118                self._simulator.sendMessage("[MLX] " + text,
     119                                            duration = duration)
     120        elif disconnecte:
     121            self._simulator.disconnect()
    113122        self._nextMessageTime = time.time() + duration
    114123
     
    129138#-------------------------------------------------------------------------------
    130139
    131 def sendMessage(messageType, text, duration = 3):
     140def sendMessage(messageType, text, duration = 3, disconnect = False):
    132141    """Send the given message of the given type into the simulator and/or play
    133142    a corresponding sound."""
    134143    global _messageThread
    135144    if _messageThread is not None:
    136         _messageThread.add(messageType, text, duration)
     145        _messageThread.add(messageType, text, duration, disconnect)
    137146
    138147#-------------------------------------------------------------------------------
  • src/mlx/fsuipc.py

    r148 r152  
    245245        """
    246246        with self._requestCondition:
    247             self._requests.append(Handler.Request(True, data, callback, extra))
     247            request = Handler.Request(True, data, callback, extra)
     248            #print "fsuipc.Handler.requestWrite", request
     249            self._requests.append(request)
    248250            self._requestCondition.notify()
    249251
     
    371373                timeout = self._periodicRequests[0].nextFire - time.time()
    372374
    373             if timeout is not None and timeout <= 0.0:
     375            if self._requests or \
     376               (timeout is not None and timeout <= 0.0):
    374377                return
    375378           
     
    378381    def _disconnect(self):
    379382        """Disconnect from the flight simulator."""
     383        print "fsuipc.Handler._disconnect"
    380384        if self._connected:
    381385            pyuipc.close()
     
    394398        whole processing the request and reconnecting."""
    395399        self._requestCondition.release()
     400
     401        #print "fsuipc.Handler._processRequest", request
    396402
    397403        needReconnect = False
     
    531537        self._flareStart = None
    532538        self._flareStartFS = None
    533    
     539
    534540        self._latin1decoder = codecs.getdecoder("iso-8859-1")
    535541
     
    600606            self._flareRequestID = None
    601607
    602     def sendMessage(self, message, duration = 3):
     608    def sendMessage(self, message, duration = 3,
     609                    _disconnect = False):
    603610        """Send a message to the pilot via the simulator.
    604611
     
    613620                (0x32fa, 'h', duration)]
    614621
    615         self._handler.requestWrite(data, self._handleMessageSent)
     622        #if _disconnect:
     623        #    print "fsuipc.Simulator.sendMessage(disconnect)", message
     624
     625        self._handler.requestWrite(data, self._handleMessageSent,
     626                                   extra = _disconnect)
    616627
    617628    def getFuel(self, tanks, callback):
     
    655666        self._nextSyncTime = -1
    656667           
    657     def disconnect(self):
     668    def disconnect(self, closingMessage = None, duration = 3):
    658669        """Disconnect from the simulator."""
    659670        assert not self._monitoringRequested
     671
     672        print "fsuipc.Simulator.disconnect", closingMessage, duration
    660673       
    661674        self._stopNormal()
    662         self._handler.disconnect()
     675        if closingMessage is None:
     676            self._handler.disconnect()
     677        else:
     678            self.sendMessage(closingMessage, duration = duration,
     679                             _disconnect = True)
    663680
    664681    def _startDefaultNormal(self):
     
    874891        callback(dow, payload, zfw, grossWeight)
    875892
    876     def _handleMessageSent(self, success, extra):
     893    def _handleMessageSent(self, success, disconnect):
    877894        """Callback for a message sending request."""
    878         pass
     895        #print "fsuipc.Simulator._handleMessageSent", disconnect
     896        if disconnect:
     897            self._handler.disconnect()
    879898
    880899    def _handleFuelRetrieved(self, data, callback):
  • src/mlx/gui/gui.py

    r151 r152  
    399399        self._logView.get_buffer().set_text("")
    400400
    401     def _disconnect(self):
     401    def _disconnect(self, closingMessage = None, duration = 3):
    402402        """Disconnect from the simulator if connected."""
    403403        self.stopMonitoring()
    404404
    405405        if self._connected:
    406             self._flight.simulator.disconnect()
     406            if closingMessage is None:
     407                self._flight.simulator.disconnect()
     408            else:
     409                fs.sendMessage(const.MESSAGETYPE_ENVIRONMENT,
     410                               closingMessage, duration,
     411                               disconnect = True)
    407412            self._connected = False
    408413
     
    455460        self._wizard.setStage(stage)
    456461        if stage==const.STAGE_END:
    457             # FIXME: perhaps a more elegant method, e.g.
    458             # the simulator should provide a function disconnect
    459             # with a final message
    460             gobject.timeout_add(1000, self._disconnect)
     462            self._disconnect(closingMessage =
     463                             "Flight plan closed. Welcome to %s" % \
     464                             (self.bookedFlight.arrivalICAO,),
     465                             duration = 5)
    461466
    462467    def setRating(self, rating):
Note: See TracChangeset for help on using the changeset viewer.