summaryrefslogtreecommitdiffstats
path: root/connection/SMPPCommand.st
blob: 7cc67e13e595b6b6f9ee6b6b4dbf80e698565358 (plain)
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
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].
    ]
]