summaryrefslogtreecommitdiffstats
path: root/connection
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-07-21 10:04:30 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-07-21 10:13:20 +0200
commit22f907bf633839309dcfe5bfd50ebaff494dc11e (patch)
treeeed697a521b7e661ef58bb3422abaab640422f95 /connection
parentd22a3e248aa105a8a26d13266d8494be2f331778 (diff)
smpp: Add setter to SMPPDeliverySM and introduce SMPPCommand
The setters were developed under Pharo (what a breeze!) and the final SMPPConnection changes were done using GNU Smalltalk.
Diffstat (limited to 'connection')
-rw-r--r--connection/SMPPCommand.st64
-rw-r--r--connection/SMPPConnection.st42
2 files changed, 89 insertions, 17 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].
+ ]
+]
+
diff --git a/connection/SMPPConnection.st b/connection/SMPPConnection.st
index c244f0f..a2b521e 100644
--- a/connection/SMPPConnection.st
+++ b/connection/SMPPConnection.st
@@ -38,12 +38,8 @@ Osmo.OsmoStreamSocketBase subclass: SMPPConnection [
]
scheduleBindTrx [
- | header body |
+ | command body |
- header := SMPPPDUHeader new
- commandId: SMPPBindTransceiver messageType;
- commandStatus: 0;
- yourself.
body := SMPPBindTransceiver new
systemId: systemId;
password: password;
@@ -53,23 +49,35 @@ Osmo.OsmoStreamSocketBase subclass: SMPPConnection [
typeOfNumber: 0;
addressRange: #[];
yourself.
+ command := SMPPCommand initWith: body.
+ self scheduleCommand: command.
+ ]
- self send: (SMPPMessage new
- header: header;
- body: body) onResponse: [:resp | ].
+ scheduleCommand: aCommand [
+ aCommand scheduledOn: self.
+ self send: aCommand.
]
- send: aMessage onResponse: aBlock [
- | seq key |
+ send: aCommand [
+ | seq key header message |
+
seq := nextSeq.
nextSeq := nextSeq + 1.
- aMessage header sequenceNumber: seq.
+ header := SMPPPDUHeader new
+ sequenceNumber: seq;
+ commandId: aCommand messageType;
+ commandStatus: 0;
+ yourself.
- "Remember that we want a response. TODO add timeout handling"
- pendingCommands at: seq put: aBlock.
+ message := SMPPMessage new
+ header: header;
+ body: aCommand body;
+ yourself.
- writeQueue nextPut: aMessage toMessage asByteArray
+ "Remember that we want a response. TODO add timeout handling"
+ pendingCommands at: seq put: aCommand.
+ writeQueue nextPut: message toMessage asByteArray
]
connect [
@@ -113,13 +121,13 @@ Osmo.OsmoStreamSocketBase subclass: SMPPConnection [
]
receviedResponse: aMessage [
- | seq block |
+ | seq command |
"Search for a response"
seq := aMessage header sequenceNumber.
- block := pendingCommands removeKey: seq ifAbsent: [
+ command := pendingCommands removeKey: seq ifAbsent: [
"TODO: log it"
^false].
- block value: aMessage
+ command result: aMessage.
]
]