forked from ObjectProfile/PythonBridge
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPBPlatform.class.st
More file actions
181 lines (152 loc) · 4.37 KB
/
PBPlatform.class.st
File metadata and controls
181 lines (152 loc) · 4.37 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
Class {
#name : #PBPlatform,
#superclass : #LanguageLinkPlatform,
#instVars : [
'processStrategy'
],
#classVars : [
'Current'
],
#category : #'PythonBridge-Platform'
}
{ #category : #accessing }
PBPlatform class >> current [
^ Current ifNil: [ Current := self getConcretePlatform new ]
]
{ #category : #accessing }
PBPlatform class >> current: aPlatform [
Current := aPlatform
]
{ #category : #utils }
PBPlatform class >> getConcretePlatform [
^ (self allSubclasses reject: #isAbstract)
inject: nil
into: [ :candidate :next |
candidate
ifNil: [ next ]
ifNotNil: [
candidate priority > next priority
ifTrue: [ candidate ]
ifFalse: [ next ] ] ]
]
{ #category : #hooks }
PBPlatform class >> globalPythonProcessClass [
self subclassResponsibility
]
{ #category : #hooks }
PBPlatform class >> httpMessageBrokerClass [
self subclassResponsibility
]
{ #category : #testing }
PBPlatform class >> isAbstract [
^ self name = 'PBPlatform' asSymbol
]
{ #category : #hooks }
PBPlatform class >> manualProcessClass [
self subclassResponsibility
]
{ #category : #hooks }
PBPlatform class >> pipenvProcessClass [
self subclassResponsibility
]
{ #category : #accessing }
PBPlatform class >> platform [
^ self current
]
{ #category : #private }
PBPlatform class >> priority [
^ -547835385
]
{ #category : #accessing }
PBPlatform class >> reset [
self current: nil
]
{ #category : #hooks }
PBPlatform class >> socketMessageBrokerClass [
self subclassResponsibility
]
{ #category : #'message broker strategy' }
PBPlatform >> defaultMessageBrokerClass [
^ self class httpMessageBrokerClass
]
{ #category : #utils }
PBPlatform >> defaultSettings [
| basePortNumber |
"Use 3 consecutive port numbers, makes it easier to listen using a port range in wireshark"
basePortNumber := 7000 + 99 atRandom.
^ PBSettings new
clientSocketAddress: (LanguageLinkSocketAddress ipOrName: 'localhost' port: basePortNumber);
serverSocketAddress: (LanguageLinkSocketAddress ipOrName: 'localhost' port: basePortNumber + 1);
debugSocketAddress: (LanguageLinkSocketAddress ipOrName: 'localhost' port: basePortNumber + 2);
messageBrokerStrategy: self messageBrokerStrategy;
platform: self;
serverProcessClass: self processStrategy;
commandFactoryClass: PBCommandFactory;
commandClass: PBCommand;
serializerClass: LanguageLinkSerializer;
deserializerClass: PBDeserializer;
parserClass: PythonParser;
connectionExceptionHandler: PharoLinkConnectionExceptionHandler new;
workingDirectory: self folderForApplication
]
{ #category : #accessing }
PBPlatform >> folderForApplication [
^ FileLocator imageDirectory / PBApplication runtimeDirectory
]
{ #category : #'gt-extensions' }
PBPlatform >> gtSettingsFor: aView [
<gtView>
^ aView forward
title: 'Settings';
priority: 60;
object: [ self defaultSettings ];
view: #gtSettingsFor:
]
{ #category : #'module creation' }
PBPlatform >> messageBroker: settings [
^ self messageBrokerStrategy settings: settings
]
{ #category : #'message broker strategy' }
PBPlatform >> messageBrokerStrategy [
^ msgBrokerStrategy ifNil: [ ^ msgBrokerStrategy := self defaultMessageBrokerClass ]
]
{ #category : #'message broker strategy' }
PBPlatform >> messageBrokerStrategy: msgBrokerCls [
msgBrokerStrategy := msgBrokerCls
]
{ #category : #accessing }
PBPlatform >> newRandomName [
^ 'pb' , UUID new asString36
]
{ #category : #'module creation' }
PBPlatform >> process: application [
^ self processStrategy application: application
]
{ #category : #'process strategy' }
PBPlatform >> processStrategy [
^ processStrategy ifNil: [ processStrategy := self class pipenvProcessClass ]
]
{ #category : #'process strategy' }
PBPlatform >> processStrategy: processCls [
processStrategy := processCls
]
{ #category : #'message broker strategy' }
PBPlatform >> setHttpMessageBroker [
self messageBrokerStrategy: self class httpMessageBrokerClass
]
{ #category : #'process strategy' }
PBPlatform >> setManualProcess [
self processStrategy: self class manualProcessClass
]
{ #category : #'process strategy' }
PBPlatform >> setPipenvProcess [
self processStrategy: self class pipenvProcessClass
]
{ #category : #'message broker strategy' }
PBPlatform >> setSocketMessageBroker [
self messageBrokerStrategy: self class socketMessageBrokerClass
]
{ #category : #accessing }
PBPlatform >> workingDirectory [
^ self folderForApplication
]