forked from ObjectProfile/PythonBridge
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPBCommandQueue.class.st
More file actions
126 lines (108 loc) · 2.77 KB
/
PBCommandQueue.class.st
File metadata and controls
126 lines (108 loc) · 2.77 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
Class {
#name : #PBCommandQueue,
#superclass : #Object,
#instVars : [
'currentIndex',
'innerCollection',
'executionHandler'
],
#category : #'PythonBridge-Execution'
}
{ #category : #accessing }
PBCommandQueue class >> executionHandler: aHandler [
^ self new
executionHandler: aHandler;
yourself
]
{ #category : #accessing }
PBCommandQueue >> cleanIndex: anIndex [
self debugMode ifTrue: [ ^ self ].
currentIndex := currentIndex - 1.
innerCollection removeAt: anIndex
]
{ #category : #accessing }
PBCommandQueue >> completedCommands [
^ innerCollection first: currentIndex
]
{ #category : #accessing }
PBCommandQueue >> currentCommand [
self isFinished ifTrue: [ ^ nil ].
^ innerCollection at: currentIndex
]
{ #category : #accessing }
PBCommandQueue >> debugMode [
^ PBApplication debugMode
]
{ #category : #accessing }
PBCommandQueue >> enqueueCommand: aCommand [
innerCollection add: aCommand
]
{ #category : #accessing }
PBCommandQueue >> excecutionHandler [
^ executionHandler
]
{ #category : #accessing }
PBCommandQueue >> executionHandler [
^ executionHandler
]
{ #category : #accessing }
PBCommandQueue >> executionHandler: anObject [
executionHandler := anObject
]
{ #category : #accessing }
PBCommandQueue >> finishCommand: aCommand [
^ self finishCommandId: aCommand id
]
{ #category : #accessing }
PBCommandQueue >> finishCommandId: id [
| commandIndex |
self currentCommand
ifNotNil: [ :command |
command id = id
ifTrue: [ self cleanIndex: currentIndex.
currentIndex := currentIndex + 1.
^ true ] ].
commandIndex := innerCollection
detectIndex: [ :command | command id = id ].
commandIndex > currentIndex
ifTrue: [ currentIndex := commandIndex + 1.
self
trace: (PBErrorLog message: 'Out of sync command queue. Pharo is delayed.') ]
ifFalse: [ self
trace: (PBErrorLog message: 'Out of sync command queue. Python is delayed.') ].
self cleanIndex: commandIndex.
^ false
]
{ #category : #accessing }
PBCommandQueue >> getCommand: aCommandId [
^ innerCollection detect: [ :command | command id = aCommandId ]
]
{ #category : #initialization }
PBCommandQueue >> initialize [
super initialize.
innerCollection := OrderedCollection new.
currentIndex := 1
]
{ #category : #accessing }
PBCommandQueue >> isFinished [
^ innerCollection size < currentIndex
]
{ #category : #accessing }
PBCommandQueue >> list [
^ innerCollection
]
{ #category : #accessing }
PBCommandQueue >> nextCommand [
| nextCommandIndex |
nextCommandIndex := currentIndex + 1.
innerCollection size < nextCommandIndex ifTrue: [ ^ nil ].
^ innerCollection at: nextCommandIndex
]
{ #category : #accessing }
PBCommandQueue >> queue [
^ self waitingCommands
]
{ #category : #accessing }
PBCommandQueue >> waitingCommands [
^ innerCollection allButFirst: currentIndex
]