View Javadoc

1   package org.ximtec.igesture.tool.view.devicemanager;
2   
3   import java.io.DataInputStream;
4   import java.io.IOException;
5   import java.util.List;
6   
7   import javax.bluetooth.RemoteDevice;
8   import javax.microedition.io.Connector;
9   import javax.microedition.io.StreamConnection;
10  import javax.microedition.io.StreamConnectionNotifier;
11  
12  import org.sigtec.ink.Note;
13  import org.sigtec.ink.Point;
14  import org.ximtec.igesture.core.Gesture;
15  import org.ximtec.igesture.io.AbstractGestureDevice;
16  import org.ximtec.igesture.util.Constant;
17  
18  /**
19   * Dummy BlueTooth Device
20   * @author Bjorn Puype, bpuype@gmail.com
21   *
22   */
23  public class BlueToothReader extends AbstractGestureDevice<Note,Point>{
24  	
25  	private RemoteDevice device;
26  	
27  	public BlueToothReader(String address, String name, RemoteDevice device)
28  	{
29  		setName(name);
30  		setDeviceID(address);
31  		setConnectionType(Constant.CONNECTION_BLUETOOTH);
32  		setDeviceType(Constant.TYPE_2D);
33  		
34  		this.device = device;
35  	}
36  	
37  	@Override
38  	public void connect() {
39  		
40  //		String url = "btspp://"+device.getBluetoothAddress()+":1101;master=false";
41  //		String url = "btspp://localhost:1101;name=ANOTOSTREAMING";
42  //		
43  //		System.out.println("Connecting to " + url);
44  //		
45  //		StreamConnectionNotifier server;
46  //		try{
47  //			server = (StreamConnectionNotifier) Connector.open(url,Connector.READ);
48  //			System.out.println("Waiting for incoming connection...");
49  //	        StreamConnection conn = server.acceptAndOpen();
50  //	        System.out.println("Client Connected...");
51  //	        DataInputStream din   = new DataInputStream(conn.openInputStream());
52  //	        while(true){
53  //	            String cmd = "";
54  //	            char c;
55  //	            while (((c = din.readChar()) > 0) && (c!='\n') ){
56  //	                cmd = cmd + c;
57  //	            }
58  //	            System.out.println("Received " + cmd);
59  //	        }
60  //		} catch (IOException e) {
61  //			// TODO Auto-generated catch block
62  //			e.printStackTrace();
63  //		}
64          
65  
66  		
67  		
68  		
69  //		final Object lock = new Object();
70  //		
71  //		UUID[] uuidSet = new UUID[1];
72  //		uuidSet[0]=new UUID(0x0011); //OBEX Object Push service 0x1105
73  //
74  //		int[] attrIDs =  new int[] {
75  //		        0x0100 // Service name
76  //		};
77  //
78  //		try {
79  //			LocalDevice localDevice = LocalDevice.getLocalDevice();
80  //			DiscoveryAgent agent = localDevice.getDiscoveryAgent();
81  //			 agent.searchServices(null,uuidSet,device, new DiscoveryListener(){
82  //
83  //				@Override
84  //				public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {}
85  //
86  //				@Override
87  //				public void inquiryCompleted(int discType) {}
88  //
89  //				@Override
90  //				public void serviceSearchCompleted(int transID, int respCode) {
91  //					synchronized(lock){
92  //			            lock.notify();
93  //			        }
94  //				}
95  //
96  //				@Override
97  //				public void servicesDiscovered(int transID, ServiceRecord[] servRecord) {
98  //
99  //			       for (int i = 0; i < servRecord.length; i++) {
100 //			           String url = servRecord[i].getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
101 //			           if (url == null) {
102 //			               continue;
103 //			           }
104 //
105 //			           DataElement serviceName = servRecord[i].getAttributeValue(0x0100);
106 //			           if (serviceName != null) {
107 //			               System.out.println("service " + serviceName.getValue() + " found " + url);
108 //			           } else {
109 //			               System.out.println("service found " + url);
110 //			           }
111 //
112 //			             // if(serviceName.getValue().equals("OBEX Object Push")){
113 ////			                       sendMessageToDevice(url);
114 //			              //}
115 //			       }
116 //
117 //			   }
118 //
119 //
120 //				private void sendMessageToDevice(String serverURL){
121 //			        try{
122 //			            System.out.println("Connecting to " + serverURL);
123 //
124 //			            ClientSession clientSession = (ClientSession) Connector.open(serverURL);
125 //			            HeaderSet hsConnectReply = clientSession.connect(null);
126 //			            if (hsConnectReply.getResponseCode() != ResponseCodes.OBEX_HTTP_OK) {
127 //			                System.out.println("Failed to connect");
128 //			                return;
129 //			            }
130 //
131 //			            HeaderSet hsOperation = clientSession.createHeaderSet();
132 //			            hsOperation.setHeader(HeaderSet.NAME, "Hello.txt");
133 //			            hsOperation.setHeader(HeaderSet.TYPE, "text");
134 //
135 //			            //Create PUT Operation
136 //			            Operation putOperation = clientSession.put(hsOperation);
137 //
138 //			            // Sending the message
139 //			            byte data[] = "Hello World !!!".getBytes("iso-8859-1");
140 //			            OutputStream os = putOperation.openOutputStream();
141 //			            os.write(data);
142 //			            os.close();
143 //
144 //			            putOperation.close();
145 //			            clientSession.disconnect(null);
146 //			            clientSession.close();
147 //			        }
148 //			        catch (Exception e) {
149 //			            e.printStackTrace();
150 //			        }
151 //			    }
152 //
153 //			 });
154 //
155 //			    try {
156 //			        synchronized(lock){
157 //			            lock.wait();
158 //			        }
159 //			    }
160 //			    catch (InterruptedException e) {
161 //			        e.printStackTrace();
162 //			        return;
163 //			    }
164 //			
165 //		} catch (BluetoothStateException e) {
166 //			e.printStackTrace();
167 //		}
168 		
169 
170 	}
171 
172 	@Override
173 	public void disconnect() {	
174 	}
175 
176 	@Override
177 	public void clear() {
178 	}
179 
180 	@Override
181 	public void dispose() {	
182 	}
183 
184 	@Override
185 	public List<Point> getChunks() {
186 		return null;
187 	}
188 
189 	@Override
190 	public Gesture<Note> getGesture() {
191 		return null;
192 	}
193 
194 	@Override
195 	public void init() {		
196 	}
197 
198 }