forked from megawubs/pyplex
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhttplistener.py
More file actions
52 lines (43 loc) · 1.49 KB
/
httplistener.py
File metadata and controls
52 lines (43 loc) · 1.49 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
import threading
import socket
import urllib2
import tornado.ioloop, tornado.web
class listenerClass(tornado.web.RequestHandler):
def initialize(self, queue):
self.queue = queue
def get(self):
string = self.get_argument("command")
print string
front = string.index("(")
end = string.rindex(")")
print "Front: %d, End: %d" %(front, end)
command = string[:front]
commandargs = string[front+1:end].split(';')
# print command
#print commandargs
print "Got HTTP command %s, args: %s" % (command, commandargs)
self.queue.put((command, commandargs))
self.write("received")
class hello(tornado.web.RequestHandler):
def get(self):
print("Got request, gave Hello")
self.write('Hello, World')
class httplistener(threading.Thread):
def __init__(self, queue):
super(httplistener, self).__init__()
self.queue = queue
self._stop = threading.Event()
self.app = tornado.web.Application([(r'/xbmcCmds/xbmcHttp', listenerClass, dict(queue=queue)), (r'/', hello)])
self.ioloop = tornado.ioloop.IOLoop.instance()
print "HTTP Init done"
def run(self):
self.app.listen(3000)
print "Started HTTP listener"
self.ioloop.start()
def ioloop_stop(self):
self.ioloop.stop()
def stop(self):
self.ioloop.add_callback(self.ioloop_stop)
self._stop.set()
def stopped(self):
return self._stop.isSet()