Пример #1
0
	def test_pySubscriber_withInvalidTopic(self):
		apiObj = ezmq.pyEZMQAPI()
		apiObj.initialize()
		subscriber_cb = callback()
		subscriber = ezmq.pyEZMQSubscriber("localhost", int(5562), subscriber_cb)
		self.assertNotEqual(subscriber, None)
		subscriber.start()
		self.assertRaises(ValueError, subscriber.subscribe, topic=4452)	
		self.assertRaises(ValueError, subscriber.subscribe, topic=0)	
		self.assertRaises(ValueError, subscriber.subscribe, topic=1.55)		
		
		topicString = "sample/string"
		ret = subscriber.subscribe(topic=topicString)
		self.assertEqual("EZMQ_OK", ezmq.errorString(ret))

		self.assertRaises(ValueError, subscriber.unSubscribe, topic=4452)
		self.assertRaises(ValueError, subscriber.unSubscribe, topic=22)
		self.assertRaises(ValueError, subscriber.unSubscribe, topic=1.2589)

		ret = subscriber.unSubscribe(topic=topicString)
		self.assertEqual("EZMQ_OK", ezmq.errorString(ret))
		ret = subscriber.stop()
		self.assertEqual("EZMQ_OK", ezmq.errorString(ret))

		ret = apiObj.terminate()
		self.assertEqual("EZMQ_OK", ezmq.errorString(ret))	

		del subscriber, subscriber_cb, apiObj
Пример #2
0
def subscribe(**kwargs):
	ip = "localhost"
	port = 5562
	if "port" in kwargs:
		port = kwargs["port"]

	topicName = ""
	if "topic" in kwargs:
		topicName = kwargs["topic"]

	secure = 0
	if "secure" in kwargs:
		secure = kwargs["secure"]

	apiObj = ezmq.pyEZMQAPI()
	apiObj.initialize()
	cb = callback()
	subscriber = ezmq.pyEZMQSubscriber(ip, int(port), cb)
	if secure == 1:
		subscriber.setServerPublicKey("")
		subscriber.setClientKeys("", 
			"")
	subscriber.start()
	if topicName == "":
		subscriber.subscribe()
	else:
		subscriber.subscribe(topic=topicName)
	return apiObj, subscriber
Пример #3
0
	def test_pyEZMQPublisher_EventData(self):
                port = 5563
                apiObj = ezmq.pyEZMQAPI()
                apiObj.initialize()
                obj = ezmq.pyEZMQPublisher(port)
                ret = obj.start()

		data = ezmq.pyEvent()
		data.init()
		data.set_device("device")
		data.set_created(10)
		data.set_modified(20)
		data.set_id("id")
		data.set_pushed(10)
		data.set_origin(20)
		read1 = data.add_reading()
		read1.set_name("reading1")
		read1.set_value("10")
		read1.set_created(25)
		read1.set_device("device")
		read1.set_modified(20)
		read1.set_id("id1")
		read1.set_origin(25)
		read1.set_pushed(1)

		topic = "arya"
                for i in range(0, 5):
                        ret = obj.publish(data)
                        self.assertEqual("EZMQ_OK", ezmq.errorString(ret))
                ret = obj.stop()
                self.assertEqual("EZMQ_OK", ezmq.errorString(ret))
                ret = apiObj.terminate()
                self.assertEqual("EZMQ_OK", ezmq.errorString(ret))
Пример #4
0
	def test_pySubscriber_withTopicList(self):
		apiObj = ezmq.pyEZMQAPI()
		apiObj.initialize()

		subscriber_cb = callback()
		ip = "localhost"
		port = 5562
		subscriber = ezmq.pyEZMQSubscriber(ip, int(port), subscriber_cb)
		self.assertNotEqual(subscriber, None)

		self.assertEqual(subscriber.getIp(), ip)
		self.assertEqual(subscriber.getPort(), port)

		ret = subscriber.start()
		self.assertEqual("EZMQ_OK", ezmq.errorString(ret))
		topicList = ["sample/topic1", "sample/topic2", "/topic3"]
		ret = subscriber.subscribe(topic=topicList)
		self.assertEqual("EZMQ_OK", ezmq.errorString(ret))

		ret = subscriber.unSubscribe(topic=topicList)
		self.assertEqual("EZMQ_OK", ezmq.errorString(ret))

		ret = subscriber.stop()
		self.assertEqual("EZMQ_OK", ezmq.errorString(ret))

		ret = apiObj.terminate()
		self.assertEqual("EZMQ_OK", ezmq.errorString(ret))

		del subscriber, subscriber_cb, apiObj
Пример #5
0
	def test_pyEZMQAPI_N(self):
		obj = ezmq.pyEZMQAPI()
		self.assertNotEqual(obj, None)
		status = obj.getStatus()
		self.assertEqual(ezmq.statusString(status), "EZMQ_Constructed")
		self.assertNotEqual(ezmq.statusString(status), "EZMQ_Unknown")
		self.assertNotEqual(ezmq.statusString(status), "EZMQ_Terminated")
		self.assertNotEqual(ezmq.statusString(status), "EZMQ_Initialized")
		
		ret = obj.initialize()
		status = obj.getStatus()
		self.assertNotEqual(ezmq.errorString(ret), "EZMQ_ERROR")
		self.assertNotEqual(ezmq.errorString(ret), "EZMQ_INVALID_TOPIC")
		self.assertNotEqual(ezmq.errorString(ret), "EZMQ_INVALID_CONTENT_TYPE")
		self.assertNotEqual(ezmq.statusString(status), "EZMQ_Unknown")
		self.assertNotEqual(ezmq.statusString(status), "EZMQ_Terminated")
		self.assertNotEqual(ezmq.statusString(status), "EZMQ_Constructed")
		
		ret = obj.terminate()
		status = obj.getStatus()
		self.assertNotEqual(ezmq.errorString(ret), "EZMQ_ERROR")
		self.assertNotEqual(ezmq.errorString(ret), "EZMQ_INVALID_TOPIC")
		self.assertNotEqual(ezmq.errorString(ret), "EZMQ_INVALID_CONTENT_TYPE")
		self.assertNotEqual(ezmq.statusString(status), "EZMQ_Unknown")
		self.assertNotEqual(ezmq.statusString(status), "EZMQ_Constructed")
		self.assertNotEqual(ezmq.statusString(status), "EZMQ_Initialized")
Пример #6
0
	def test_pyEZMQAPI_P(self):
		obj = ezmq.pyEZMQAPI()
		self.assertNotEqual(obj, None)
		status = obj.getStatus()
		self.assertEqual(ezmq.statusString(status), "EZMQ_Terminated")

		ret = obj.initialize()
		status = obj.getStatus()
		self.assertEqual(ezmq.errorString(ret), "EZMQ_OK")
		self.assertEqual(ezmq.statusString(status), "EZMQ_Initialized")

		ret = obj.terminate()
		status = obj.getStatus()
		self.assertEqual(ezmq.errorString(ret), "EZMQ_OK")
		self.assertEqual(ezmq.statusString(status), "EZMQ_Terminated")
Пример #7
0
def publish(**kwargs):

	print "PUBLISH CALLED"
	port = 5562
	if "port" in kwargs:
		port = kwargs["port"]

	topicName = ""
	if "topic" in kwargs:
		topicName = kwargs["topic"]

	counter = 0
	if "counter" in kwargs:
		counter = kwargs["counter"]

	secure = 1
	if "secure" in kwargs:
		secure = kwargs["secure"]
	apiObj = ezmq.pyEZMQAPI()
	apiObj.initialize()
	publisher = ezmq.pyEZMQPublisher(int(port))
	if secure == 1:
		publisher.setServerPrivateKey("")
	publisher.start()

	while counter != 0 :
		event = getByteArray()
		length = len(event)
		data = ezmq.pyEZMQByteData()
		data.init(event, len(event))
		d = bytearray(data.getByteData())
		dl = data.getLength()
		print " DATA : ", list(d[0:dl])
		print " DATA LENGTH : ", dl
		if topicName == "":
			ret = publisher.publish(data)
		else:
			print " TOPIC ", topicName
			ret = publisher.publish(data, topic=topicName)

		print ' EVENT PUBLISH RESULT :: ', ezmq.errorString(ret)
		counter -= 1
		time.sleep(1)

	publisher.stop()
	apiObj.terminate()
Пример #8
0
	def test_pyEZMQPublisher(self):
		port = 5560
		obj = ezmq.pyEZMQPublisher(port)
		self.assertNotEqual(obj, None)

		ret = obj.start()
		self.assertEqual("EZMQ_ERROR", ezmq.errorString(ret))

		apiObj = ezmq.pyEZMQAPI()
		apiObj.initialize()
		obj = ezmq.pyEZMQPublisher(port)
		ret = obj.start()
		self.assertEqual("EZMQ_OK", ezmq.errorString(ret))	
		ret = obj.stop()
		self.assertEqual("EZMQ_OK", ezmq.errorString(ret))
		ret = apiObj.terminate()
		self.assertEqual("EZMQ_OK", ezmq.errorString(ret))
Пример #9
0
	def test_pyEZMQPublisher_ByteData(self):
                port = 5562
                apiObj = ezmq.pyEZMQAPI()
                apiObj.initialize()
                obj = ezmq.pyEZMQPublisher(port)
                ret = obj.start()
                
		event = bytearray([12, 24, 36, 48, 60])
		length = len(event)
		data = ezmq.pyEZMQByteData()
		data.init(event, len(event))

		for i in range(0, 5):
			ret = obj.publish(data)
			self.assertEqual("EZMQ_OK", ezmq.errorString(ret))

		ret = obj.stop()
		self.assertEqual("EZMQ_OK", ezmq.errorString(ret))
		ret = apiObj.terminate()
		self.assertEqual("EZMQ_OK", ezmq.errorString(ret))
Пример #10
0
topicSub = ""
if (topicStr is ""):
    print "========>SUBSCRIBING WITH NO TOPIC"
    print "========>TO USE TOPIC run subscriber topic=topicName"
else:
    if ',' in topicStr:
        topicSub = [str(elem) for elem in topicStr.split(",")]
    else:
        topicSub = topicStr
    print "USING TOPIC :: ", topicStr
if secured == 1:
    print "SECURITY ENABLED FOR SAMPLE."
print "-----------------------------------------------------------"

print "\nCreating ezmq API object"
apiObj = ezmq.pyEZMQAPI()
print "Python ezmqApi object created successfully"
print "EZMQAPI Status : ", ezmq.statusString(apiObj.getStatus())
print "Initializing ezmqApi object"
ret = apiObj.initialize()
print "Initializing API RESULT", ezmq.errorString(ret)
print "EZMQAPI Status : ", ezmq.statusString(apiObj.getStatus())
print "Creating ezmq Subscriber object"
cb = callback()
subscriber = ezmq.pyEZMQSubscriber(ip, int(port), cb)
if subscriber is None:
    print "FAILED TO GET Subscription object for ", ip, port
    print "RERUN Subscriber as :: \"$python subscriber.py ip=\'Publisher IP\' port=5562\""
    exit()

print "Python ezmqSubscriber object created successfully"