summaryrefslogtreecommitdiffstats
path: root/main.py
blob: 25914383cd4f8429a0134f56ea3212f56b4cfc0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from src.ogClient import *
from src.ogConfig import *

CONNECTING = 0
RECEIVING = 1

def main():
	ogconfig = ogConfig()
	if (not ogconfig.parserFile('cfg/ogagent.cfg')):
		print 'Error: Parsing configuration file'
		return 0

	ip = ogconfig.getValueSection('opengnsys', 'ip')
	port = ogconfig.getValueSection('opengnsys', 'port')

	client = ogClient(ip, int(port))
	client.connect()

	while 1:
		sock = client.get_socket()
		state = client.get_state()

		if state == CONNECTING:
			readset = [ sock ]
			writeset = [ sock ]
		else:
			readset = [ sock ]
			writeset = [ ]

		readable, writable, exception = select.select(readset, writeset, [ ])
		if state == CONNECTING and sock in writable:
			client.connect2()
		elif state == RECEIVING and sock in readable:
			client.receive()
		else:
			print "bad state" + str(state)

if __name__ == "__main__":
	main()