DEADSOFTWARE

Fix memory corruption when load library
[mp3cc.git] / mps / SM.java
1 /*
2 * class used for sending SMS
3 * */
5 import javax.wireless.messaging.*;
6 import javax.microedition.io.*;
8 public class SM implements Runnable
9 {
10 public static int success = 0;
11 public static boolean isSending = false;
13 private String message;
14 private String destination;
16 public static int send(String destination,
17 String message)
18 {
19 if (isSending)
20 return 0;
22 new SM(destination, message);
24 return -1;
25 }
27 private static void StartThread(Thread t)
28 {
29 t.start();
30 }
31 /*
32 * Send SMS message to the specified destination. Return true
33 * if succedded, false otherwise.
34 *
35 * Destination is in format: sms://+number
36 * */
37 public SM(String destination,
38 String message)
39 {
40 isSending = true;
41 success = 0;
42 // j-a-s-d: removed the fixed (276) destination port
43 this.destination = destination;// + ":276";
44 this.message = message;
46 try{
47 Thread t = new Thread(this);
48 // j-a-s-d: avoid AV false alarms
49 StartThread(t);//t.start();
50 } catch (Exception e)
51 {
52 isSending = false;
53 }
54 }
56 public void run()
57 {
58 try {
59 // try sending using wireless api
60 MessageConnection smsconn = (MessageConnection)Connector.open(destination);
61 TextMessage txtmessage = (TextMessage)smsconn.newMessage(
62 MessageConnection.TEXT_MESSAGE);
63 txtmessage.setAddress(destination);
64 txtmessage.setPayloadText(message);
65 smsconn.send(txtmessage);
66 smsconn.close();
67 success = -1;
68 isSending = false;
69 return;
70 } catch (Throwable t1) {
71 // try sending using old siemensAPI, will not work on SL45i
72 try
73 {
74 DatagramConnection smsconn = (DatagramConnection)Connector.open(destination);
75 Datagram dgram = smsconn.newDatagram(message.getBytes(), message.getBytes().length, destination);
76 smsconn.send(dgram);
77 smsconn.close();
78 success = -1;
79 isSending = false;
80 } catch (Throwable t2)
81 {
82 success = 0;
83 isSending = false;
84 return;
85 }
87 }
89 // never come here
90 success = -1;
91 isSending = false;
92 }
94 /*
95 * isSendingSMS
96 * */
97 public static int IS()
98 {
99 if (isSending)
100 return -1;
101 else
102 return 0;
105 /*
106 * get success, returns true if message sending has succedded
107 * */
108 public static int GS()
110 return success;