Skip to content

Commit 9461646

Browse files
author
Alejandro Infante
committed
Add handlers to Application.
1 parent ef16c45 commit 9461646

7 files changed

+61
-27
lines changed
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Extension { #name : #Collection }
2+
3+
{ #category : #'*PythonBridge' }
4+
Collection >> ensureDo: aBlock [
5+
self do: [ :el | aBlock valueUninterruptably ]
6+
]

src/PythonBridge/PBApplication.class.st

+29-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Class {
33
#superclass : #Object,
44
#instVars : [
55
'promiseHandler',
6+
'sendMessageHandler',
67
'processHandler'
78
],
89
#classInstVars : [
@@ -228,6 +229,15 @@ if __name__ == "__main__":
228229
pharo_hooks_globals.logger.log("PYTHON: Finished command execution")'
229230
]
230231

232+
{ #category : #instructions }
233+
PBApplication class >> resetUniqueInstance [
234+
uniqueInstance ifNotNil: [
235+
[ uniqueInstance stop ]
236+
on: Error
237+
do: [ UIManager inform: 'Error on reseting unique instance.' ]. ].
238+
uniqueInstance := nil
239+
]
240+
231241
{ #category : #instructions }
232242
PBApplication class >> retrieveExpression: obj [
233243
self assert: self isRunning.
@@ -279,6 +289,21 @@ PBApplication class >> stop [
279289
uniqueInstance := nil
280290
]
281291

292+
{ #category : #handlers }
293+
PBApplication >> handlers [
294+
^ Array
295+
with: promiseHandler
296+
with: sendMessageHandler
297+
with: processHandler
298+
]
299+
300+
{ #category : #accessing }
301+
PBApplication >> initializeHandlers [
302+
processHandler := PBProcessHandler new.
303+
promiseHandler := PBPromiseHandler new.
304+
sendMessageHandler := PBSendMessageHandler new
305+
]
306+
282307
{ #category : #testing }
283308
PBApplication >> isPythonReady [
284309
"Ensures python webserver is ready for receiving commands"
@@ -287,21 +312,19 @@ PBApplication >> isPythonReady [
287312

288313
{ #category : #testing }
289314
PBApplication >> isRunning [
290-
^ processHandler isRunning and: [ promiseHandler isRunning ]
315+
^ self handlers allSatisfy: #isRunning
291316
]
292317

293318
{ #category : #accessing }
294319
PBApplication >> start [
295-
processHandler := PBProcessHandler new.
296-
processHandler start.
297-
promiseHandler := PBPromiseHandler new.
298-
promiseHandler start.
299-
320+
self initializeHandlers.
321+
self handlers do: #start.
300322
self waitInitialization.
301323
]
302324

303325
{ #category : #accessing }
304326
PBApplication >> stop [
327+
self handlers do: #stop
305328
]
306329

307330
{ #category : #'as yet unclassified' }

src/PythonBridge/PBApplicationTest.class.st

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Class {
66

77
{ #category : #running }
88
PBApplicationTest >> tearDown [
9-
PBApplication isRunning ifTrue: [ PBApplication stop ]
9+
PBApplication resetUniqueInstance
1010
]
1111

1212
{ #category : #tests }

src/PythonBridge/PBHandler.class.st

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Class {
2+
#name : #PBHandler,
3+
#superclass : #Object,
4+
#category : #PythonBridge
5+
}
6+
7+
{ #category : #testing }
8+
PBHandler >> isRunning [
9+
^ true
10+
]
11+
12+
{ #category : #accessing }
13+
PBHandler >> start [
14+
]
15+
16+
{ #category : #accessing }
17+
PBHandler >> stop [
18+
]
+1-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
Class {
22
#name : #PBProcessHandler,
3-
#superclass : #Object,
3+
#superclass : #PBHandler,
44
#category : #PythonBridge
55
}
6-
7-
{ #category : #testing }
8-
PBProcessHandler >> isRunning [
9-
^ true
10-
]
11-
12-
{ #category : #accessing }
13-
PBProcessHandler >> start [
14-
]
+1-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
Class {
22
#name : #PBPromiseHandler,
3-
#superclass : #Object,
3+
#superclass : #PBHandler,
44
#category : #PythonBridge
55
}
6-
7-
{ #category : #testing }
8-
PBPromiseHandler >> isRunning [
9-
^ true
10-
]
11-
12-
{ #category : #accessing }
13-
PBPromiseHandler >> start [
14-
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Class {
2+
#name : #PBSendMessageHandler,
3+
#superclass : #PBHandler,
4+
#category : #PythonBridge
5+
}

0 commit comments

Comments
 (0)