22 |
22 |
23 class JsonServer(QTcpServer): |
23 class JsonServer(QTcpServer): |
24 """ |
24 """ |
25 Class implementing the JSON based server base class. |
25 Class implementing the JSON based server base class. |
26 """ |
26 """ |
27 def __init__(self, multiplex=False, parent=None): |
27 def __init__(self, name="", multiplex=False, parent=None): |
28 """ |
28 """ |
29 Constructor |
29 Constructor |
30 |
30 |
|
31 @param name name of the server (used for output only) |
|
32 @type str |
31 @param multiplex flag indicating a multiplexing server |
33 @param multiplex flag indicating a multiplexing server |
32 @type bool |
34 @type bool |
33 @param parent parent object |
35 @param parent parent object |
34 @type QObject |
36 @type QObject |
35 """ |
37 """ |
55 |
57 |
56 self.newConnection.connect(self.handleNewConnection) |
58 self.newConnection.connect(self.handleNewConnection) |
57 |
59 |
58 port = self.serverPort() |
60 port = self.serverPort() |
59 ## Note: Need the port if started external in debugger: |
61 ## Note: Need the port if started external in debugger: |
60 print('Refactoring server listening on: {0:d}'.format(port)) |
62 print('JSON server ({1}) listening on: {0:d}'.format(port, name)) |
61 # __IGNORE_WARNING__ |
63 # __IGNORE_WARNING__ |
62 |
64 |
63 @pyqtSlot() |
65 @pyqtSlot() |
64 def handleNewConnection(self): |
66 def handleNewConnection(self): |
65 """ |
67 """ |
98 @type str |
100 @type str |
99 """ |
101 """ |
100 if idString: |
102 if idString: |
101 if idString in self.__connections: |
103 if idString in self.__connections: |
102 self.__connections[idString].close() |
104 self.__connections[idString].close() |
103 del self.__connections[id] |
105 del self.__connections[idString] |
104 else: |
106 else: |
105 if self.__connection is not None: |
107 if self.__connection is not None: |
106 self.__connection.close() |
108 self.__connection.close() |
107 |
109 |
108 self.__connection = None |
110 self.__connection = None |
245 else: |
247 else: |
246 if self.__clientProcess is not None: |
248 if self.__clientProcess is not None: |
247 self.__clientProcess.close() |
249 self.__clientProcess.close() |
248 self.__clientProcess = None |
250 self.__clientProcess = None |
249 |
251 |
|
252 def stopAllClients(self): |
|
253 """ |
|
254 Public method to stop all clients. |
|
255 """ |
|
256 clientNames = self.connectionNames()[:] |
|
257 for clientName in clientNames: |
|
258 self.stopClient(clientName) |
|
259 |
250 ####################################################################### |
260 ####################################################################### |
251 ## The following methods should be overridden by derived classes |
261 ## The following methods should be overridden by derived classes |
252 ####################################################################### |
262 ####################################################################### |
253 |
263 |
254 def handleCall(self, method, params): |
264 def handleCall(self, method, params): |