*** empty log message ***
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/htdocs/summerofcode/mel/RoutingSMS/server/AboutForm.java Wed Aug 31 20:53:40 2005 -0400
@@ -0,0 +1,56 @@
+Copyright (c) <2005>, <Mel Dooki> +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +* Neither the name of the <ORGANIZATION> nor the names of its contributors +may be used to endorse or promote products derived from this software without +specific prior written permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +import javax.microedition.lcdui.*; +public class AboutForm extends Form implements CommandListener + private CellPhoneMIDlet midlet; + private Command backCommand = new Command("Back", Command.BACK, 1); + public AboutForm(String title, CellPhoneMIDlet midlet) + addCommand(backCommand); + setCommandListener(this); + this.append("Series 80 "); + this.append("SMS Routing over Bluetooth link"); + this.append("from the PC to the mobile "); + this.append("to be sent to the desired phone numbers"); + public void commandAction(Command c, Displayable d) --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/htdocs/summerofcode/mel/RoutingSMS/server/CellPhoneMidlet.java Wed Aug 31 20:53:40 2005 -0400
@@ -0,0 +1,169 @@
+Copyright (c) <2005>, <Mel Dooki> +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +* Neither the name of the <ORGANIZATION> nor the names of its contributors +may be used to endorse or promote products derived from this software without +specific prior written permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +import javax.microedition.lcdui.*; +import javax.microedition.midlet.*; +public class CellPhoneMIDlet extends MIDlet implements CommandListener + * menulist, main menu List object. + * elements, String elements of the menu. + private String[] elements; + * server, Server object is created if this MIDlet is launced as Server. + * UUIDString, Service record UUID that is used in this example application. + * Both Client and Server retrives this UUID string from this MIDlet class. + public static final String UUIDString = "11223344556677889900aabbccddeeff"; + * Constructor. Initialize main menu; + public CellPhoneMIDlet() + elements = new String[3]; + elements[0] = "Start Application"; + menulist = new List(title, List.IMPLICIT, elements, null); + menulist.setCommandListener(this); + * startApp Shows main menu + * @throws MIDletStateChangeException + protected void startApp() + throws MIDletStateChangeException + protected void pauseApp() + * destroyApp. Ensures that connections have been closed. + protected void destroyApp(boolean p1) + server.applicationClosed = true; + server.closeConnection(); + * commandAction. Handles main menu command events. + public void commandAction(Command c, Displayable d) + int index = menulist.getSelectedIndex(); + * quitApp. Called when application is closed. + * showMenu. Shows main menu list. + Display.getDisplay(this).setCurrent(menulist); + * showAbout. Shows About dialog. + public void showAbout() + AboutForm aboutForm = new AboutForm("About SMS Routing over BT Link", this); + Display.getDisplay(this).setCurrent(aboutForm); + * startServer. Starts bluetooth server thread. + private void startServer() + server = new Server(this); --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/htdocs/summerofcode/mel/RoutingSMS/server/Server.java Wed Aug 31 20:53:40 2005 -0400
@@ -0,0 +1,547 @@
+Copyright (c) <2005>, <Mel Dooki> +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +* Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. +* Neither the name of the <ORGANIZATION> nor the names of its contributors +may be used to endorse or promote products derived from this software without +specific prior written permission. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +import java.util.Vector; +import javax.bluetooth.*; +import javax.microedition.io.*; +import javax.microedition.lcdui.*; +import javax.wireless.messaging.TextMessage.*; +import javax.wireless.messaging.*; +//for importing phonebook +import javax.microedition.lcdui.Display; +import javax.microedition.lcdui.Displayable; +import javax.microedition.midlet.MIDlet; +import javax.microedition.pim.*; +import java.util.Enumeration; +public class Server implements Runnable, CommandListener + // major service class as TELEPHONY + private final static int TELEPHONY = 0x400000; + private CellPhoneMIDlet midlet; + private StreamConnectionNotifier notifier = null; + private StreamConnection streamConnection = null; + private DataOutputStream out; + private DataInputStream in; + private LocalDevice localDevice; + private RemoteDevice remoteDevice; + private Command QuitCommand; + * serviceURL, Service URL that is opened when this server starts to + private String serviceURL = "btspp://localhost:"+CellPhoneMIDlet.UUIDString+";name=RoutingSMS"; + private boolean connectionOpen; + private boolean clientExit = false; + boolean applicationClosed; + private Vector unsuccessfulNumbers; + * Server, Constructor that creates UI and sets discoverable mode to LIAC to + * speed up device inquiry by the clients. + * @param midlet CellPhoneMIDlet + public Server (CellPhoneMIDlet midlet) + connectionOpen = false; + applicationClosed = false; + unsuccessfulNumbers = new Vector (); + localDevice = LocalDevice.getLocalDevice(); + localDevice.setDiscoverable(DiscoveryAgent.GIAC); + notifier = (StreamConnectionNotifier) Connector.open(serviceURL); + * Creates this thread and starts it. + * start a thread to serve the server connection. + * only one server thread is started + * see run() for the task of this thread + thread = new Thread(this); + * Run method that is called when this thread starts. opens connectin and + * starts to wait for clients to conatct. After succesful connection by a + * client starts to read data from the client and then sends response to the + f = new Form("Waiting..."); + f2 = new Form("Connected to client"); + QuitCommand = new Command("Quit", Command.EXIT, 1); + f.addCommand(QuitCommand); + f.setCommandListener(this); + f2.addCommand(QuitCommand); + f2.setCommandListener(this); + Gauge gauge = new Gauge("Waiting for clients to contact", false, + Gauge.INDEFINITE, Gauge.CONTINUOUS_RUNNING); + while (! applicationClosed) + Display.getDisplay(midlet).setCurrent(f); + waitAndOpenConnection (); + if (connectionOpen == true) + // Jout ("Exception in connection to client\n"); + continue; //waits for another client + // Jout ("exception in retrieve contacts\n"); + //Jout ("Unable to retrieve names and numbers "+"\n"); + Jout ("sending EXCEPTION"+"\n"); + out.writeUTF("EXCEPTION"); //notifies the client that an error occured while retrieving the contacts + if (connectionOpen == true) + if (applicationClosed==true) + // Jout ("Exception in sending SMS" + "\n"); + //try{Thread.sleep (1000);}catch (Exception eee){} + // Jout ("connection with PC failed failed"+"\n"); + public void waitAndOpenConnection () + //this will block the current thread until a client connects + streamConnection = notifier.acceptAndOpen(); + // Retrieve the service record template + ServiceRecord rec = localDevice.getRecord( notifier ); + // Setting the Major Service Classes flag in Bluetooth stack. + // which I choose to be Telephony Service + rec.setDeviceServiceClasses( TELEPHONY ); + remoteDevice = RemoteDevice.getRemoteDevice( streamConnection ); + //Jout ("remoteDevice.getBluetoothAddress (): " + remoteDevice.getBluetoothAddress ()+ "\n"); + Jout ("Connected to " + remoteDevice.getFriendlyName (false)+"\n"); + // obtain an input stream to the remote service + in = streamConnection.openDataInputStream(); + out = streamConnection.openDataOutputStream(); + connectionOpen = false; + * Handles Server Command events. + * param disp Displayable + public void commandAction(Command cmd, Displayable d) + if (cmd == QuitCommand) + applicationClosed = true; + else if ((d==f) && (cmd == QuitCommand)) + * Closes connection and streams. + public void closeConnection() + if (connectionOpen == true) + connectionOpen = false; + streamConnection.close(); + *Method responsible for getting the databases containing the contacts + public void retrieveContacts () + String[] allContactLists = PIM.getInstance().listPIMLists (PIM.CONTACT_LIST); + if (allContactLists.length > 0) + for (int i = 0; i < allContactLists.length;i++) + retrieveNamesAndNumbers (allContactLists[i]); + out.writeUTF ("EOF"); //indicates to the clients end of contacts + * Retrieves the names and the numbers of the contacts and passes them to the client + public void retrieveNamesAndNumbers (String theContactList) + ContactList clist = null; + //get items in contacts and then get the list in these items nd then get the items in each list + clist = (ContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY, theContactList); + Jout ("Openning Contacts" +"\n"); + // failed opening the default contact list! + Jout ("Error accessing database - aborting action" +"\n"); + catch (SecurityException e) + // user rejected application's request for + // read access to contact list + // This is not an error condition and can be normal + Jout("Okay, this application won't get contacts"+"\n"); + // Retrieve contact values + Enumeration contacts = clist.items();//This operation takes most of the time of importing + //Jout ("before hasMoreElements \n" ); + while(contacts.hasMoreElements() ) + Contact contact = (Contact) contacts.nextElement(); + String contactNumber = ""; + String contactName = ""; + contactName = contact.getString(Contact.FORMATTED_NAME, 0); + * The countValues() method returns the number of data values currently + * set in a particular field. + int numValues = contact.countValues(Contact.TEL); + for (int i = 0; i < numValues; i++) + if (contact.getAttributes(Contact.TEL, i) == Contact.ATTR_WORK) + //work = contact.getString(Contact.TEL, i); + else if (contact.getAttributes(Contact.TEL, i) == Contact.ATTR_HOME) + //home = contact.getString(Contact.TEL, i); + // I only need the mobile number and the name + else if (contact.getAttributes(Contact.TEL, i) == Contact.ATTR_MOBILE) + contactNumber = contact.getString( Contact.TEL, i ); + out.writeUTF( contactNumber+" "+contactName ); + else if (contact.getAttributes(Contact.TEL, i) == Contact.ATTR_PAGER) + // pager = contact.getString(Contact.TEL, i); + //Jout ("After hasMoreElement\n"); + catch( PIMException e ) + // an error occurred and raised a PIM access exception + catch( SecurityException e ) + // can't read this list (security Exception) + * Method responsible for sending the SMS to the desired numbers entered by the user on the pC + Jout ("Waiting for user message"+"\n"); + //checks whether the buffer empty + //waits for the same client to see if he likes to send another message + while (in.available()==0) + if (applicationClosed==true) //the application on the phone was closed by the user + message = in.readUTF(); //reading the message from the user on PC + if (message.equals ("CLIENT_EXIT")) //the client on PC quit the application and so no messages to be sent + catch (EOFException eof) + //Jout ("EOF Exception" + "\n"); + //Jout ("IO Exception"+"\n"); + //reading number of recipients + int countDesiredNumbers = in.read (); + String cellPhoneNumber; + MessageConnection smsConnection = null; + unsuccessfulNumbers.removeAllElements(); //clears the vector bec of batch sending + for(int i=0; i<countDesiredNumbers; i++) + cellPhoneNumber = in.readUTF(); //reading phone number to send sms to + String address = "sms://" + cellPhoneNumber; + /** Open the message connection. */ + smsConnection = (MessageConnection)Connector.open(address); + TextMessage txtmessage = (TextMessage) smsConnection.newMessage( + MessageConnection.TEXT_MESSAGE); + txtmessage.setAddress(address); + txtmessage.setPayloadText(message); + smsConnection.send(txtmessage); //sending the message + Jout ("Your message to "+ cellPhoneNumber + " has been sent successfully"+ "\n"); + unsuccessfulNumbers.addElement (cellPhoneNumber); + Jout("Your message to "+cellPhoneNumber+" has failed"+"\n"); + if (smsConnection != null) + catch (IOException ioe) + success (); //reports to the client whether the server was able to send the sms to the desired number (s) or not + * sends to the server a message indicating the number of the unsuccessful sms 's if any as well as the numbers + out.write(unsuccessfulNumbers.size()); + for (int i = 0 ; i < unsuccessfulNumbers.size() ; i++) + out.writeUTF( (String)unsuccessfulNumbers.elementAt(i)); + * utility for Displaying output + public void Jout( String s ) //displays messages on the screen + Display.getDisplay(midlet).setCurrent(f2);