~vomun-developers/anonplus/vomun-trunk

« back to all changes in this revision

Viewing changes to src/api/server.py

  • Committer: AJ00200
  • Date: 2011-11-25 21:24:46 UTC
  • mfrom: (158.1.2)
  • Revision ID: git-v1:49f3402d2806f0bf05cba20d985a005227e14638
Fixed merge conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
'''Run a server on 127.0.0.1:3451 for the localhost API. Parse the packets
2
 
with api.packets when we get them.
3
 
'''
4
 
 
5
 
import libs.threadmanager
6
 
import libs.globals
7
 
import xmlrpclib
8
 
import api.functions
9
 
from SimpleXMLRPCServer import SimpleXMLRPCServer
10
 
 
11
 
class APIServer(libs.threadmanager.Thread):
12
 
    '''Contains the APIServer within a stopable and registered thread'''
13
 
    calls = []
14
 
    def __init__(self):
15
 
        libs.threadmanager.Thread.__init__(self)
16
 
        self.server = SimpleXMLRPCServer(("localhost", 3451),allow_none = True)
17
 
 
18
 
    def add_call(self,call):
19
 
        self.server.register_function(call,call.__name__)
20
 
        self.calls.append(call)
21
 
 
22
 
    def run(self):
23
 
        print('API-server running on port 3451 : Started')
24
 
        while not self._stop.isSet():
25
 
            try:
26
 
                self.server.handle_request()
27
 
            except KeyboardInterrupt:
28
 
                print('^C received, shutting down web server')
29
 
                self.server.socket.close()
30
 
                self._stop.set()
31
 
            
32
 
## Start the server and handler            
33
 
def start():
34
 
    '''Start the user interface. Create the Server object and the listener
35
 
    we use to listen for events from this interface.
36
 
    '''
37
 
    libs.globals.global_vars["apiserver"] = APIServer()
38
 
    libs.threadmanager.register(libs.globals.global_vars["apiserver"])
39
 
    libs.globals.global_vars["apiserver"].start()
40
 
    api.functions.register()
 
 
b'\\ No newline at end of file'