51 else: |
51 else: |
52 # IPv6 |
52 # IPv6 |
53 self.__hostAddress = '::1' |
53 self.__hostAddress = '::1' |
54 self.listen(QHostAddress(self.__hostAddress)) |
54 self.listen(QHostAddress(self.__hostAddress)) |
55 |
55 |
56 self.newConnection.connect(self.__handleNewConnection) |
56 self.newConnection.connect(self.handleNewConnection) |
57 |
57 |
58 port = self.serverPort() |
58 port = self.serverPort() |
59 ## Note: Need the port if started external in debugger: |
59 ## Note: Need the port if started external in debugger: |
60 print('Refactoring server listening on: {0:d}'.format(port)) |
60 print('Refactoring server listening on: {0:d}'.format(port)) |
61 # __IGNORE_WARNING__ |
61 # __IGNORE_WARNING__ |
62 |
62 |
63 @pyqtSlot() |
63 @pyqtSlot() |
64 def __handleNewConnection(self): |
64 def handleNewConnection(self): |
65 """ |
65 """ |
66 Private slot for new incoming connections from a client. |
66 Public slot for new incoming connections from a client. |
67 """ |
67 """ |
68 connection = self.nextPendingConnection() |
68 connection = self.nextPendingConnection() |
69 if not connection.isValid(): |
69 if not connection.isValid(): |
70 return |
70 return |
71 |
71 |
86 |
86 |
87 connection.readyRead.connect( |
87 connection.readyRead.connect( |
88 lambda: self.__receiveJson(idString)) |
88 lambda: self.__receiveJson(idString)) |
89 connection.disconnected.connect( |
89 connection.disconnected.connect( |
90 lambda: self.__handleDisconnect(idString)) |
90 lambda: self.__handleDisconnect(idString)) |
91 |
|
92 self.sendJson("GetConfig", {}) |
|
93 |
91 |
94 @pyqtSlot() |
92 @pyqtSlot() |
95 def __handleDisconnect(self, idString): |
93 def __handleDisconnect(self, idString): |
96 """ |
94 """ |
97 Private slot handling a disconnect of the client. |
95 Private slot handling a disconnect of the client. |
148 method = clientDict["method"] |
146 method = clientDict["method"] |
149 params = clientDict["params"] |
147 params = clientDict["params"] |
150 |
148 |
151 self.handleCall(method, params) |
149 self.handleCall(method, params) |
152 |
150 |
153 def handleCall(self, method, params): |
|
154 """ |
|
155 Public method to handle a method call from the client. |
|
156 |
|
157 Note: This is an empty implementation that must be overridden in |
|
158 derived classes. |
|
159 |
|
160 @param method requested method name |
|
161 @type str |
|
162 @param params dictionary with method specific parameters |
|
163 @type dict |
|
164 """ |
|
165 pass |
|
166 |
|
167 def sendJson(self, command, params, flush=False, idString=""): |
151 def sendJson(self, command, params, flush=False, idString=""): |
168 """ |
152 """ |
169 Public method to send a single command to a client. |
153 Public method to send a single command to a client. |
170 |
154 |
171 @param command command name to be sent |
155 @param command command name to be sent |
247 del self.__clientProcesses[idString] |
231 del self.__clientProcesses[idString] |
248 else: |
232 else: |
249 if self.__clientProcess is not None: |
233 if self.__clientProcess is not None: |
250 self.__clientProcess.close() |
234 self.__clientProcess.close() |
251 self.__clientProcess = None |
235 self.__clientProcess = None |
|
236 |
|
237 ####################################################################### |
|
238 ## The following methods should be overridden by derived classes |
|
239 ####################################################################### |
|
240 |
|
241 def handleCall(self, method, params): |
|
242 """ |
|
243 Public method to handle a method call from the client. |
|
244 |
|
245 Note: This is an empty implementation that must be overridden in |
|
246 derived classes. |
|
247 |
|
248 @param method requested method name |
|
249 @type str |
|
250 @param params dictionary with method specific parameters |
|
251 @type dict |
|
252 """ |
|
253 pass |