?? windows.java
字號:
boolean done = false; this.finishedScan = false; while(!this.finishedScan){ if(!done){ if(Windows.debugWatcher) System.out.println(Windows.createUSB + " Watcher.Constructor() >>> scan started"); scan(); done = true; } } if(Windows.debugWatcher) System.out.println(Windows.createUSB + " Watcher.Constructor() >>> after scan! \n"); if (busses.isEmpty()) throw new IOException( "There is no Host Controller on the Windows operating system." + " You don't have a USB at all!"); } public void run() { while(true){ try{ if(Windows.debugWatcher) System.out.println("\n>>>> Watcher.run() >>> Thread goes now to sleeps for " + POLL_PERIOD +"s \n"); Thread.sleep (POLL_PERIOD * 1000); boolean done = false; this.finishedScan = false; while(!this.finishedScan){ if(!done){ if(Windows.debugWatcher) System.out.println("\n>> Watcher.run() >>> G O I N I G T O S C A N A L L ! Starttime[" + System.currentTimeMillis() + "] \n"); scan(); done = true; } } } catch (InterruptedException e) { // set dir to null to cause a clean exit } catch(IOException e){ e.printStackTrace(); } } } private native String getHostControllerName(int number); /** * scan all the busses and all the devices on each bus */ private void scan() throws IOException{ synchronized(busses){ // what busses exists now? // look for all existing Host Controller on the Windows OS int i = 0; String hostControllerDevicePath; Vector kids = null; // Kids contains all current Host Controllers // as long we find a hostcontroller create a new bus while((hostControllerDevicePath = Windows.getHostControllerDevicePath(i)) != null){ if(kids == null) //create a Vector for kids as soon we kids = new Vector(); // find at least one host controller kids.add(hostControllerDevicePath); //add the hc to the kids // for debugging if(Windows.debugWatcher) System.out.println(Windows.createUSB + " Watcher.scan() >>> kids[" + i + "].add("+ hostControllerDevicePath + " )"); i++; } // so far our kids contains all host controller which are currently // available on the windows system // now check if something changed since the last scan has being applied if(Windows.debugWatcher) System.out.println(Windows.createUSB + " Watcher.scan() >>> check if something changed since the last scan has being applied"); Vector seen = new Vector(kids.size()); for(i = 0; i < kids.size() ; i++) { // Windows has not really a bus number for each USB bus // therefore we give each bus an abstract number, so that // it corresponds to linux impl and the jusb core API int busnum = i + 1; //mark the kid we look at as seen seen.add((String)kids.get(i)); //try to get the bus object from the current busses USB bus = (USB) busses.get((String)kids.get(i)); //if we didn't get a bus object, it is a new bus if(bus == null){ if(Windows.debugWatcher) System.out.println(Windows.createUSB + " Watcher.scan() >>> NEW <<< found a new bus. Create a new BUS with busnum="+busnum); mkBus((String)kids.get(i),busnum); }else{ // check wheter the existing bus has some changes // with its attached devices if(Windows.debugWatcher) System.out.println(Windows.createUSB + " Watcher.scan() >>> SAME <<< BUS["+busnum+"] already exists. Check if something changed on the BUS[" + busnum + "]"); bus.setFinishScanBusFalse(); boolean done = false; while(!bus.getFinishScanBus()){ if(!done){ if(Windows.debugWatcher) System.out.println(Windows.createUSB + " Watcher.scan() >>> start scanBus BUS["+busnum+"]!"); bus.scanBus(); done = true; } } } } // end of for // what are the busses that previously existed? // if we find some busses that doesn't exist // anymore, we have to remove them for(Enumeration e = busses.keys(); e.hasMoreElements(); ){ Object busname = e.nextElement(); if(!seen.contains(busname)){ //this bus is not attached anymore, remove it if(Windows.debugWatcher) System.out.println(Windows.createUSB + " Watcher.scan() >>> OLD <<< remove a bus, because it does not exists anymore!"); rmBus(busname); } } } // end of synchronized(busses) this.finishedScan = true; } private void rmBus(Object busname){ USB bus = (USB) busses.get(busname); if(Windows.debugWatcher) System.out.println(Windows.createUSB + " Watcher:rmBus() >>> REMOVE <<< BUS[" + bus.getBusNum() + "] REMOVED! inform the USBListener that a bus is removed "); for(int i = 0; i < listeners.size(); i++){ USBListener listener; listener = (USBListener) listeners.get(i); try{ listener.busRemoved(bus); } catch(Exception e){ e.printStackTrace(); } } busses.remove(busname); bus.kill(); } private void mkBus(String hostControllerDevicePath, int busnum) throws IOException{ USB bus; String hostControllerName = Windows.getHostControllerName(hostControllerDevicePath); boolean done = false; Windows.createUSB = false; bus = null; while(!Windows.createUSB){ if(!done){ if(Windows.debugWatcher) System.out.println(Windows.createUSB + " Watcher:mkBus() >>> ADD <<< BUS[" + busnum + "]"); bus = new USB( hostControllerName, hostControllerDevicePath, busnum, listeners, self); done = true; } } if(bus == null) if(Windows.debugWatcher) System.out.println(Windows.createUSB + " Watcher:mkBus() >>> ADD <<< BUS[" + busnum + "] not created!!! >>> FAILURE <<<"); else if(Windows.debugWatcher) System.out.println(Windows.createUSB + " Watcher:mkBus() >>> ADD <<< BUS[" + busnum + "] created! BUS Object: " + bus); busses.put(hostControllerDevicePath,bus); if(Windows.debugWatcher) System.out.println(Windows.createUSB + " Watcher:mkBus() >>> ADD <<< BUS[" + busnum + "] inform the USBListener that a bus is added"); for(int i=0; i < listeners.size(); i++){ USBListener listener; listener = (USBListener) listeners.get(i); try{ listener.busAdded(bus); } catch(Exception e){ e.printStackTrace(); } } // end for } } // end of class Watcher }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -