From 22f907bf633839309dcfe5bfd50ebaff494dc11e Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Mon, 21 Jul 2014 10:04:30 +0200 Subject: [PATCH] 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. --- Makefile | 3 +- codec/SMPPDeliverSM.st | 76 ++++++++++++++++++++++++++++++++++++ connection/SMPPCommand.st | 64 ++++++++++++++++++++++++++++++ connection/SMPPConnection.st | 44 ++++++++++++--------- package.xml | 1 + 5 files changed, 169 insertions(+), 19 deletions(-) create mode 100644 connection/SMPPCommand.st diff --git a/Makefile b/Makefile index 5420c49..9d632e7 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,8 @@ TEST = \ CONNECTION = \ ./connection/Extensions.st \ - ./connection/SMPPConnection.st + ./connection/SMPPConnection.st \ + ./connection/SMPPCommand.st CODEC = \ ./codec/attributes/SMPPOctetString.st \ diff --git a/codec/SMPPDeliverSM.st b/codec/SMPPDeliverSM.st index 51edf25..ed115ff 100644 --- a/codec/SMPPDeliverSM.st +++ b/codec/SMPPDeliverSM.st @@ -95,4 +95,80 @@ SMPPBodyBase subclass: SMPPDeliverSM [ ^short_message ] + + destinationAddress: aString [ + destination_addr := aString + ] + + scheduleDeliveryTime: aString [ + schedule_delivery_time := aString + ] + + registeredDelivery: anInteger [ + registered_delivery := anInteger + ] + + dontReplaceIfPresent [ + replace_if_present_flag := 0 + ] + + destinationNumberingPlanIndicator: anInteger [ + dest_addr_npi := anInteger + ] + + destinationTypeOfNumber: anInteger [ + dest_addr_ton := anInteger + ] + + dataCoding: anInteger [ + data_coding := 0 + ] + + sourceAddress: aString [ + source_addr := aString + ] + + protocolId: anInteger [ + protocol_id := anInteger + ] + + esmClass: anInteger [ + esm_class := anInteger + ] + + priorityLevel: anInteger [ + priority_flag := 0 + ] + + shortMessage: aCollection [ + short_message := aCollection + ] + + messagePayload: aCollection [ + message_payload := aCollection + ] + + sourceNumberingPlanIndicator: anInteger [ + source_addr_npi := anInteger + ] + + defaultMessageID: anInteger [ + sm_default_msg_id := 0 + ] + + serviceType: anInteger [ + service_type := anInteger + ] + + sourceTypeOfNumber: anInteger [ + source_addr_ton := anInteger + ] + + registeredValidity: anInteger [ + self shouldBeImplemented + ] + + validityPeriod: aString [ + validity_period := aString + ] ] 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 | + + + + + SMPPCommand class >> initWith: aBody [ + ^self new + body: aBody; + yourself + ] + + messageType [ + ^body class messageType + ] + + body [ + ^body + ] + + body: aBody [ + + body := aBody + ] + + onResult: aBlock [ + + onResult := aBlock + ] + + onError: aBlock [ + + onError := aBlock + ] + + onTimeout: aBlock [ + + onTimeout := aBlock + ] + + scheduledOn: aConnection [ + connection := aConnection. + timeoutTimer := Osmo.TimerScheduler instance + scheduleInSeconds: 10 block: [self timeout]. + ] + + timeout [ + + onTimeout ifNotNil: [:block | block value]. + ] + + error: anError [ + + timeoutTimer cancel. + onError ifNotNil: [:block | block value: anError]. + ] + + result: aResult [ + + 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. - - self send: (SMPPMessage new - header: header; - body: body) onResponse: [:resp | ]. + command := SMPPCommand initWith: body. + self scheduleCommand: command. ] - send: aMessage onResponse: aBlock [ - | seq key | + scheduleCommand: aCommand [ + aCommand scheduledOn: self. + self send: aCommand. + ] + + 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. + + message := SMPPMessage new + header: header; + body: aCommand body; + yourself. "Remember that we want a response. TODO add timeout handling" - pendingCommands at: seq put: aBlock. - - writeQueue nextPut: aMessage toMessage asByteArray + 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. ] ] diff --git a/package.xml b/package.xml index e4107f7..f2e083f 100644 --- a/package.xml +++ b/package.xml @@ -42,6 +42,7 @@ codec/SMPPMessage.st connection/SMPPConnection.st + connection/SMPPCommand.st connection/Extensions.st