예제 #1
0
class YateApp:
	""" initialize the object """
	def __init__(self):
			# call the Yate object
			self.app = Yate()
			# declare the event intercetion method
			self.app.__Yatecall__ = self.retenv

	# this function will manage the imput from Yate.
	# param "d" is the Yate.type variable for incoming message 
	def retenv(self, d):
		if d == "":
			self.app.Output("PYTHON event: empty")
		elif d == "incoming":
			self.app.Output("PYTHON message: " +  self.app.name + " id: " + self.app.id)
			self.app.Acknowledge()
			self.count = self.count + 1
		elif d == "answer":
			self.app.Output("PYTHON Answered: " +  self.app.name + " id: " + self.app.id)
		elif d == "installed":
			self.app.Output("PYTHON Installed: " + self.app.name )
		elif d == "uninstalled":
			self.app.Output("PYTHON Uninstalled: " + self.app.name )
		else:
			self.app.Output("PYTHON event: " + self.app.type )
			

	# clean shutdown of our application... 
	def uninstall(self):
			self.app.Uninstall("engine.timer")

	def main(self):
		# create and dispatch an initial test message to Yate
		self.app.Yate("test")
		self.app.retval = "ret_value"
		self.app.params = [ ['param1', 'value1'], ['param2', 'value2'] ]
		self.app.Dispatch()

		# reset the counter
		self.count = 0

		# install engine.timer
		self.app.Install("engine.timer", 10)

		# start the main loop
		while True:
			# check for events
			self.app.flush()
			
			# uninstall engine.timer after 5 messages from Yate
			if self.count == 5:
				self.uninstall()
				break

		# ok, now a second example with a threaded asyncore loop!
		self.count = 0
		self.app.Install("engine.timer", 10)
		self.app.th_loop()
		
		# wow, amazing, the loop still running and we can continue in the execution!
		# dispatch a final test message after the main loop exit
		self.app.Yate("final_test")
		self.app.retval = "ret_value"
		self.app.params = [ ['param1', 'value1'] ]
		self.app.Dispatch()

		# now wait for 10 message from yate, and then uninstall the engine.timer and exit 
		while self.count != 10:
			pass
		self.uninstall()
		self.app.th_stop()
		# bye!
		self.app.Output("PYTHON: Bye!")

		# close file descriptors
		self.app.close()
예제 #2
0
파일: test.py 프로젝트: 5l1v3r1/evilbts-1
class YateApp:
	""" initialize the object """
	def __init__(self):
			# call the Yate object
			self.app = Yate()
			# declare the event intercetion method
			self.app.__Yatecall__ = self.retenv

	# this function will manage the imput from Yate.
	# param "d" is the Yate.type variable for incoming message
	def retenv(self, d):
		if d == "":
			self.app.Output("PYTHON event: empty")
		elif d == "incoming":
			self.app.Output("PYTHON message: " +  self.app.name + " id: " + self.app.id)
			self.app.Acknowledge()
			self.count = self.count + 1
		elif d == "answer":
			self.app.Output("PYTHON Answered: " +  self.app.name + " id: " + self.app.id)
		elif d == "installed":
			self.app.Output("PYTHON Installed: " + self.app.name )
		elif d == "uninstalled":
			self.app.Output("PYTHON Uninstalled: " + self.app.name )
		else:
			self.app.Output("PYTHON event: " + self.app.type )


	# clean shutdown of our application...
	def uninstall(self):
			self.app.Uninstall("engine.timer")

	def main(self):
		# create and dispatch an initial test message to Yate
		self.app.Yate("test")
		self.app.retval = "ret_value"
		self.app.params = [ ['param1', 'value1'], ['param2', 'value2'] ]
		self.app.Dispatch()

		# reset the counter
		self.count = 0

		# install engine.timer
		self.app.Install("engine.timer", 10)

		# start the main loop
		while True:
			# check for events
			self.app.flush()

			# uninstall engine.timer after 5 messages from Yate
			if self.count == 5:
				self.uninstall()
				break

		# ok, now a second example with a threaded asyncore loop!
		self.count = 0
		self.app.Install("engine.timer", 10)
		self.app.th_loop()

		# wow, amazing, the loop still running and we can continue in the execution!
		# dispatch a final test message after the main loop exit
		self.app.Yate("final_test")
		self.app.retval = "ret_value"
		self.app.params = [ ['param1', 'value1'] ]
		self.app.Dispatch()

		# now wait for 10 message from yate, and then uninstall the engine.timer and exit
		while self.count != 10:
			pass
		self.uninstall()
		self.app.th_stop()
		# bye!
		self.app.Output("PYTHON: Bye!")

		# close file descriptors
		self.app.close()