summaryrefslogtreecommitdiffstats
path: root/connection/SMPPCommand.st
diff options
context:
space:
mode:
Diffstat (limited to 'connection/SMPPCommand.st')
-rw-r--r--connection/SMPPCommand.st64
1 files changed, 64 insertions, 0 deletions
diff --git a/connection/SMPPCommand.st b/connection/SMPPCommand.st
new file mode 100644
index 0000000..7cc67e1
--- /dev/null
+++ b/connection/SMPPCommand.st
@@ -0,0 +1,64 @@
+Object subclass: SMPPCommand [
+ | body onTimeout onResult onError timeoutTimer connection |
+
+ <category: 'SMPP-Connection'>
+ <comment: ''>
+
+ SMPPCommand class >> initWith: aBody [
+ ^self new
+ body: aBody;
+ yourself
+ ]
+
+ messageType [
+ ^body class messageType
+ ]
+
+ body [
+ ^body
+ ]
+
+ body: aBody [
+ <category: 'creation'>
+ body := aBody
+ ]
+
+ onResult: aBlock [
+ <category: 'creation'>
+ onResult := aBlock
+ ]
+
+ onError: aBlock [
+ <category: 'creation'>
+ onError := aBlock
+ ]
+
+ onTimeout: aBlock [
+ <category: 'creation'>
+ onTimeout := aBlock
+ ]
+
+ scheduledOn: aConnection [
+ connection := aConnection.
+ timeoutTimer := Osmo.TimerScheduler instance
+ scheduleInSeconds: 10 block: [self timeout].
+ ]
+
+ timeout [
+ <category: 'result dispatch'>
+ onTimeout ifNotNil: [:block | block value].
+ ]
+
+ error: anError [
+ <category: 'result dispatch'>
+ timeoutTimer cancel.
+ onError ifNotNil: [:block | block value: anError].
+ ]
+
+ result: aResult [
+ <category: 'result dispatch'>
+ timeoutTimer cancel.
+ onResult ifNotNil: [:block | block value: aResult].
+ ]
+]
+