The unified diff between revisions [8697eea5..] and [efcca794..] is displayed below. It can also be downloaded as a raw diff.

#
#
# patch "System.py"
#  from [3e2a9d2a57fd7a35306c1a1fb7adbae3b09af3ae]
#    to [2f53e410c158b7abd945b28f0abbe2bfe01c617b]
#
# patch "fourstar.py"
#  from [b42150cc088a8140b77f0814d837e2495c5c617c]
#    to [225282fd45bd2b68ac3cdd920bf918f965766fe5]
#
============================================================
--- System.py	3e2a9d2a57fd7a35306c1a1fb7adbae3b09af3ae
+++ System.py	2f53e410c158b7abd945b28f0abbe2bfe01c617b
@@ -12,8 +12,18 @@
 #
 # Store as a shelf

+from time import time, sleep
+
+#FOO#DOOR = 1
+#FOO#SWITCH = 2
+#FOO#KEY = 3
+TICK = 4
+
 class System:
-	def __init__(self):
+	def __init__(self, rfh, wfh):
+		#VS
+		self.events = []
+		#
 		self.connected = False
 		self.file = None
 		self.db = None
@@ -23,3 +33,20 @@ class System:

 	def status(self):
 		pass
+
+	def next_event(self, timeout = None):
+		if timeout < 0: timeout = 0
+		if len(self.events) > 0: timeout = 0
+#		while True:
+#			(r, _, _) = select([self.rfh], [], [], timeout)
+#			if r:
+#				self.get_response(async = True)
+#				timeout = 0
+#			else:
+#				break
+		if len(self.events) == 0: return (TICK, time())
+		ret = self.events[0]
+		del self.events[0]
+		return ret
+
+
============================================================
--- fourstar.py	b42150cc088a8140b77f0814d837e2495c5c617c
+++ fourstar.py	225282fd45bd2b68ac3cdd920bf918f965766fe5
@@ -36,16 +36,9 @@ print "Hello Cruel World!"

 print "Hello Cruel World!"

-fs = System()

-print fs
-
-
-
-
 # real code below here

-
 #!/usr/bin/python
 # vim:ts=4

@@ -56,22 +49,11 @@ from time import time, sleep, mktime, lo
 import logging, logging.handlers
 from traceback import format_tb
 from time import time, sleep, mktime, localtime
-CREDITS="""
-This vending machine software brought to you by:
-Bernard Blackham
-Mark Tearle
-Nick Bannon
-Cameron Patrick
-and a collective of hungry alpacas.

+#DOOR = 1
+#KEY = 3
+TICK = 4

-
-For a good time call +61 8 6488 3901
-
-
-
-"""
-DOOR = 1
 (
 STATE_IDLE,
 STATE_DOOR_OPENING,
@@ -81,13 +63,14 @@ STATE_GRANDFATHER_CLOCK,
 STATE_GET_SELECTION,
 STATE_GRANDFATHER_CLOCK,
 ) = range(1,8)
-class VendState:
+
+class FS_State:
 	def __init__(self,v):
 		self.state_table = {}
 		self.state = STATE_IDLE
-		self.counter = 0
+		self.counter = 1

-		self.mk = MessageKeeper(v)
+		#self.mk = MessageKeeper(v)
 		self.cur_user = ''
 		self.cur_pin = ''
 		self.username = ''
@@ -110,13 +93,15 @@ class VendState:
 			#print " to ",
 			#print newcounter
 			self.counter = newcounter
+
 def do_nothing(state, event, params, v, vstatus):
 	print "doing nothing (s,e,p)", state, " ", event, " ", params
 	pass
+
 def create_state_table(vstatus):
-#	vstatus.state_table[(STATE_IDLE,TICK,1)] = handle_idle_tick
-#	vstatus.state_table[(STATE_IDLE,KEY,1)] = handle_idle_key
-#	vstatus.state_table[(STATE_IDLE,DOOR,1)] = handle_door_event
+	vstatus.state_table[(STATE_IDLE,TICK,1)] = do_nothing
+#	vstatus.state_table[(STATE_IDLE,KEY,1)] = do_nothing
+#	vstatus.state_table[(STATE_IDLE,DOOR,1)] = do_nothing
 #
 #	vstatus.state_table[(STATE_DOOR_OPENING,TICK,1)] = handle_door_idle
 #	vstatus.state_table[(STATE_DOOR_OPENING,DOOR,1)] = handle_door_event
@@ -140,17 +125,21 @@ def create_state_table(vstatus):
 #
 #	vstatus.state_table[(STATE_GRANDFATHER_CLOCK,TICK,1)] = handle_idle_grandfather_tick
 #	vstatus.state_table[(STATE_GRANDFATHER_CLOCK,TICK,2)] = handle_grandfather_tick
-	vstatus.state_table[(STATE_GRANDFATHER_CLOCK,DOOR,1)] = do_nothing
-	vstatus.state_table[(STATE_GRANDFATHER_CLOCK,DOOR,2)] = do_nothing
-	vstatus.state_table[(STATE_GRANDFATHER_CLOCK,KEY,1)] = do_nothing
-	vstatus.state_table[(STATE_GRANDFATHER_CLOCK,KEY,2)] = do_nothing
+#	vstatus.state_table[(STATE_GRANDFATHER_CLOCK,DOOR,1)] = do_nothing
+#	vstatus.state_table[(STATE_GRANDFATHER_CLOCK,DOOR,2)] = do_nothing
+#	vstatus.state_table[(STATE_GRANDFATHER_CLOCK,KEY,1)] = do_nothing
+#	vstatus.state_table[(STATE_GRANDFATHER_CLOCK,KEY,2)] = do_nothing

 def get_state_table_handler(vstatus, state, event, counter):
 	return vstatus.state_table[(state,event,counter)]
+
 def run_forever(rfh, wfh, options, cf):
-	v = VendingMachine(rfh, wfh)
-	vstatus = VendState(v)
+	# get system, status object
+	v = System(rfh, wfh)
+	vstatus = FS_State(v)
+
 	create_state_table(vstatus)
+
 	# This main loop was hideous and the work of the devil.
 	# This has now been fixed (mostly) - mtearle
 	#
@@ -162,9 +151,11 @@ def run_forever(rfh, wfh, options, cf):
 	#
 	# ( return state - not currently implemented )
 	while True:
+		timeout = 0
 		e = v.next_event(timeout)
 		(event, params) = e
 		run_handler(event, params, v, vstatus)
+
 def run_handler(event, params, v, vstatus):
 	handler = get_state_table_handler(vstatus,vstatus.state,event,vstatus.counter)
 	if handler:
@@ -199,7 +190,7 @@ config_options = {
 }


-class VendConfigFile:
+class FS_ConfigFile:
 	def __init__(self, config_file, options):
 		try:
 			cp = ConfigParser.ConfigParser()
@@ -225,7 +216,7 @@ def set_stuff_up():
 	signal.signal(signal.SIGINT, stop_server)

 	options = parse_args()
-	config_opts = VendConfigFile(options.config_file, config_options)
+	config_opts = FS_ConfigFile(options.config_file, config_options)
 #	if options.daemon: become_daemon()
 	set_up_logging(options)
 	if options.pid_file != '': create_pid_file(options.pid_file)
@@ -259,7 +250,7 @@ def set_up_logging(options):

 	if options.syslog != None:
 		sys_logger = logging.handlers.SysLogHandler('/dev/log', options.syslog)
-		sys_logger.setFormatter(logging.Formatter('vendserver[%d]'%(os.getpid()) + ' %(levelname)s: %(message)s'))
+		sys_logger.setFormatter(logging.Formatter('fourstar[%d]'%(os.getpid()) + ' %(levelname)s: %(message)s'))
 		logger.addHandler(sys_logger)

 	if options.quiet:
@@ -284,7 +275,7 @@ def set_up_logging(options):
 #		raise SystemExit('failed to fork: '+str(e))


-def do_vend_server(options, config_opts):
+def do_FS_server(options, config_opts):
 	while True:

 		wfh = sys.stdout
@@ -302,13 +293,13 @@ if __name__ == '__main__':
 	options, config_opts = set_stuff_up()
 	while True:
 		try:
-			logging.warning('Starting Vend Server')
-			do_vend_server(options, config_opts)
-			logging.error('Vend Server finished unexpectedly, restarting')
+			logging.warning('Starting FS Server')
+			do_FS_server(options, config_opts)
+			logging.error('FS Server finished unexpectedly, restarting')
 		except KeyboardInterrupt:
 			logging.info("Killed by signal, cleaning up")
 			clean_up_nicely(options, config_opts)
-			logging.warning("Vend Server stopped")
+			logging.warning("FS Server stopped")
 			break
 		except SystemExit:
 			break
@@ -323,7 +314,7 @@ if __name__ == '__main__':
 			for event in tb:
 				for line in event.split('\n'):
 					logging.critical('    '+line)
-			logging.critical("This message should be considered a bug in the Vend Server.")
+			logging.critical("This message should be considered a bug in the FS Server.")
 			logging.critical("Please report this to someone who can fix it.")
 			sleep(10)
 			logging.warning("Trying again anyway (might not help, but hey...)")