Changeset 59:a3e0b8455dc8 for src/mlx/pyuipc_sim.py
- Timestamp:
- 04/07/12 08:48:34 (12 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/pyuipc_sim.py
r57 r59 637 637 #------------------------------------------------------------------------------ 638 638 639 failOpen = False 640 641 opened = False 642 643 #------------------------------------------------------------------------------ 644 639 645 def open(request): 640 646 """Open the connection.""" 641 return True 647 global opened 648 if failOpen: 649 raise FSUIPCException(ERR_NOFS) 650 elif opened: 651 raise FSUIPCException(ERR_OPEN) 652 else: 653 time.sleep(0.5) 654 opened = True 655 return True 642 656 643 657 #------------------------------------------------------------------------------ … … 645 659 def prepare_data(pattern, forRead = True): 646 660 """Prepare the given pattern for reading and/or writing.""" 647 return pattern 648 661 if opened: 662 return pattern 663 else: 664 raise FSUIPCException(ERR_OPEN) 665 649 666 #------------------------------------------------------------------------------ 650 667 651 668 def read(data): 652 669 """Read the given data.""" 653 return [values.read(offset) for (offset, type) in data] 670 print "opened", opened 671 if opened: 672 return [values.read(offset) for (offset, type) in data] 673 else: 674 raise FSUIPCException(ERR_OPEN) 654 675 655 676 #------------------------------------------------------------------------------ … … 657 678 def write(data): 658 679 """Write the given data.""" 659 for (offset, type, value) in data: 660 values.write(offset, value) 680 if opened: 681 for (offset, type, value) in data: 682 values.write(offset, value) 683 else: 684 raise FSUIPCException(ERR_OPEN) 661 685 662 686 #------------------------------------------------------------------------------ … … 664 688 def close(): 665 689 """Close the connection.""" 666 pass 690 global opened 691 opened = False 667 692 668 693 #------------------------------------------------------------------------------ … … 673 698 CALL_WRITE=2 674 699 CALL_CLOSE=3 700 CALL_FAILOPEN=4 701 CALL_QUIT = 99 675 702 676 703 RESULT_RETURNED=1 … … 715 742 elif call==CALL_WRITE: 716 743 result = write(args[0]) 744 elif call==CALL_CLOSE: 745 global opened 746 opened = False 747 result = None 748 elif call==CALL_FAILOPEN: 749 global failOpen 750 failOpen = args[0] 751 result = None 717 752 else: 718 753 break … … 753 788 """Write the given data.""" 754 789 return self._call(CALL_WRITE, data) 790 791 def close(self): 792 """Close the connection currently opened in the simulator.""" 793 return self._call(CALL_CLOSE, None) 794 795 def failOpen(self, really): 796 """Enable/disable open failure in the simulator.""" 797 return self._call(CALL_FAILOPEN, really) 798 799 def quit(self): 800 """Quit from the simulator.""" 801 data = cPickle.dumps((CALL_QUIT, None)) 802 self._socket.send(struct.pack("I", len(data)) + data) 755 803 756 804 def _call(self, command, data): … … 1024 1072 if line=="EOF": 1025 1073 print 1026 return True1074 return self.do_quit("") 1027 1075 else: 1028 1076 return super(CLI, self).default(line) … … 1102 1150 return [key + "=" for key in self._valueHandlers if key.startswith(text)] 1103 1151 1152 def do_close(self, args): 1153 """Close an existing connection so that FS will fail.""" 1154 try: 1155 self._client.close() 1156 print "Connection closed" 1157 except Exception, e: 1158 print >> sys.stderr, "Failed to close the connection: " + str(e) 1159 1160 def do_failopen(self, args): 1161 """Enable/disable the failing of opens.""" 1162 try: 1163 value = self.str2bool(args) 1164 self._client.failOpen(value) 1165 print "Opening will%s fail" % ("" if value else " not",) 1166 except Exception, e: 1167 print >> sys.stderr, "Failed to set open failure: " + str(e) 1168 1169 def help_failopen(self, usage = False): 1170 """Help for the failopen close""" 1171 if usage: print "Usage:", 1172 print "failopen yes|no" 1173 1174 def complete_failopen(self, text, line, begidx, endidx): 1175 if text: 1176 if "yes".startswith(text): return ["yes"] 1177 elif "no".startswith(text): return ["no"] 1178 else: return [] 1179 else: 1180 return ["yes", "no"] 1181 1104 1182 def do_quit(self, args): 1105 1183 """Handle the quit command.""" 1184 self._client.quit() 1106 1185 return True 1107 1186
Note:
See TracChangeset
for help on using the changeset viewer.