Changeset 9:953cd606427c in xplra for misc


Ignore:
Timestamp:
01/04/13 16:12:21 (11 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
hg-Phase:
(<MercurialRepository 3 'hg:/home/ivaradi/xplane/hg/xplra' '/'>, 'public')
Message:

Registering multi-data update requests works

Location:
misc
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • misc/client.py

    r8 r9  
    100100        self._stream = stream
    101101        self._multiGets = {}
     102        self._multiSets = {}
    102103
    103104        self.use_rawinput = True
     
    230231
    231232    def do_exec_multiget(self, args):
    232         """Handle the 'unreg_multiget' command"""
     233        """Handle the 'exec_multiget' command"""
    233234        words = self._splitArgs(args)
    234235        if len(words)<1:
     
    254255            print >> sys.stderr, "Invalid dataref at #%d" % (index,)
    255256        else:
     257            print >> sys.stderr, "Error code:", result
     258
     259    def do_reg_multiset(self, args):
     260        """Handle the 'reg_multiset' command"""
     261        words = self._splitArgs(args)
     262        specs = []
     263        while words:
     264            result = self._parseGetSpec(words)
     265            if result is None:
     266                return False
     267            else:
     268                specs.append(result[0])
     269                words = result[1]
     270
     271        if not specs:
     272            return False
     273
     274        self._writeU8(0x21)
     275        self._writeU32(len(specs))
     276        for (name, type, length, offset) in specs:
     277            print name, type
     278            self._writeString(name)
     279            self._writeU8(self._types[type])
     280            if length is not None:
     281                self._writeS32(length)
     282                self._writeS32(offset)
     283        self._flush()
     284
     285        result = self._readU8()
     286        if result==0:
     287            id = self._readU32()
     288            self._multiSets[id] = \
     289                [(type, length) for (name, type, length, offset) in specs]
     290            print "ID:", id
     291        else:
     292            print >> sys.stderr, "Error code:", result
     293
     294    def do_unreg_multiset(self, args):
     295        """Handle the 'unreg_multiset' command"""
     296        words = self._splitArgs(args)
     297        if len(words)<1:
     298            print >> sys.stderr, "Missing parameter"
     299            return False
     300
     301        id = int(words[0])
     302
     303        self._writeU8(0x22)
     304        self._writeU32(id)
     305        self._flush()
     306
     307        result = self._readU8()
     308        if result!=0:
     309            print >> sys.stderr, "Error code:", result
     310
     311        if id in self._multiSets:
     312            del self._multiSets[id]
     313
     314    def do_exec_multiset(self, args):
     315        """Handle the 'exec_multiget' command"""
     316        words = self._splitArgs(args)
     317        if len(words)<1:
     318            print >> sys.stderr, "Missing parameter"
     319            return False
     320
     321        id = int(words[0])
     322        if id not in self._multiSets:
     323            print >> sys.stderr, "Invalid ID"
     324            return False
     325
     326        words = words[1:]
     327        types = self._multiSets[id]
     328        if len(words)<len(types):
     329            print >> sys.stderr, "Missing parameter"
     330            return False
     331
     332
     333        self._writeU8(0x23)
     334        self._writeU32(id)
     335        for ((type, length), word) in zip(types, words):
     336            self._writeValue(type, word, length)
     337        self._flush()
     338
     339        result = self._readU8()
     340        if result==0x02:
     341            index = self._readU32()
     342            print >> sys.stderr, "Invalid dataref at #%d" % (index,)
     343        elif result!=0:
    256344            print >> sys.stderr, "Error code:", result
    257345
Note: See TracChangeset for help on using the changeset viewer.