File: gsm_event.cc

package info (click to toggle)
gsmlib 1.10+20120414.gita5e5ae9a-0.3
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 3,468 kB
  • ctags: 1,907
  • sloc: cpp: 12,315; sh: 11,376; ansic: 2,366; makefile: 263; sed: 93
file content (173 lines) | stat: -rw-r--r-- 4,193 bytes parent folder | download | duplicates (2)
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
// *************************************************************************
// * GSM TA/ME library
// *
// * File:    gsm_event.cc
// *
// * Purpose: Event handler interface
// *
// * Author:  Peter Hofmann (software@pxh.de)
// *
// * Created: 7.6.1999
// *************************************************************************

#ifdef HAVE_CONFIG_H
#include <gsm_config.h>
#endif
#include <gsmlib/gsm_nls.h>
#include <gsmlib/gsm_event.h>
#include <gsmlib/gsm_parser.h>
#include <gsmlib/gsm_at.h>
#include <gsmlib/gsm_me_ta.h>

using namespace gsmlib;

// GsmEvent members

void GsmEvent::dispatch(std::string s, GsmAt &at) throw(GsmException)
{
  SMSMessageType messageType;
  bool indication = false;
  if (s.substr(0, 5) == "+CMT:")
    messageType = NormalSMS;
  else if (s.substr(0, 5) == "+CBM:")
    messageType = CellBroadcastSMS;
  else if (s.substr(0, 5) == "+CDS:")
  {
    // workaround for phones that report CDS when they actually mean CDSI
    indication = at.getMeTa().getCapabilities()._CDSmeansCDSI;
    messageType = StatusReportSMS;
  }
  else if (s.substr(0, 6) == "+CMTI:")
  {
    indication = true;
    messageType = NormalSMS;
  }
  else if (s.substr(0, 6) == "+CBMI:")
  {
    indication = true;
    messageType = CellBroadcastSMS;
  }
  else if (s.substr(0, 6) == "+CDSI:")
  {
    indication = true;
    messageType = StatusReportSMS;
  }
  else if (s.substr(0, 4) == "RING")
  {
    ringIndication();
    return;
  }
  // handling  NO CARRIER
  else if (s.substr(0, 10) == "NO CARRIER")
  {
    noAnswer();
    return;
  }
  
  else if (s.substr(0, 6) == "+CLIP:")
  {
    //    <number>,<type>[,<subaddr>,<satype>[,<alpha>]]
    s = s.substr(6);
    Parser p(s);
    std::string num = p.parseString();
    if (p.parseComma(true))
    {
      unsigned int numberFormat;
      if ((numberFormat = p.parseInt()) == InternationalNumberFormat)
        num = "+" + num;
      else if (numberFormat != UnknownNumberFormat)
        throw GsmException(stringPrintf(_("unexpected number format %d"),
                                        numberFormat), OtherError);
    }
    std::string subAddr;
    std::string alpha;
    if (p.parseComma(true))
    {
      subAddr = p.parseString(true);
      p.parseComma();
      p.parseInt(true);         // FIXME subaddr type ignored

      if (p.parseComma(true))
        alpha = p.parseString(true);
    }
    
    // call the event handler
    callerLineID(num, subAddr, alpha);
    return;
  }
  else
    throw GsmException(stringPrintf(_("unexpected unsolicited event '%s'"),
                                    s.c_str()), OtherError);

  if (indication)
  {
    // handle SMS storage indication
    s = s.substr(6);
    Parser p(s);
    std::string storeName = p.parseString();
    p.parseComma();
    unsigned int index = p.parseInt();
    SMSReceptionIndication(storeName, index - 1, messageType);
  }
  else
    if (messageType == CellBroadcastSMS)
    {
      // handle CB message
      std::string pdu = at.getLine();

      CBMessageRef cb = new CBMessage(pdu);

      // call the event handler
      CBReception(cb);
    }
    else
    {
      // handle SMS
      std::string pdu = at.getLine();
      
      // add missing service centre address if required by ME
      if (! at.getMeTa().getCapabilities()._hasSMSSCAprefix)
      pdu = "00" + pdu;
      
      SMSMessageRef sms = SMSMessage::decode(pdu);
      
      // send acknowledgement if necessary
      if (at.getMeTa().getCapabilities()._sendAck)
        at.chat("+CNMA");
      
      // call the event handler
      SMSReception(sms, messageType);
    }
}

void GsmEvent::callerLineID(std::string number, std::string subAddr, std::string alpha)
{
  // ignore event
}

void GsmEvent::SMSReception(SMSMessageRef newMessage,
                            SMSMessageType messageType)
{
  // ignore event
}

void GsmEvent::CBReception(CBMessageRef newMessage)
{
  // ignore event
}

void GsmEvent::SMSReceptionIndication(std::string storeName, unsigned int index,
                                      SMSMessageType messageType)
{
  // ignore event
}

void GsmEvent::ringIndication()
{
  // ignore event
}

void GsmEvent::noAnswer()
{
  // ignore event
}