1 package org.openhome.net.device.tests; 2 3 import java.io.File; 4 import java.net.Inet4Address; 5 import java.util.ArrayList; 6 import java.util.List; 7 import java.util.concurrent.Semaphore; 8 import java.util.concurrent.TimeUnit; 9 10 import org.openhome.net.controlpoint.CpDevice; 11 import org.openhome.net.controlpoint.CpDeviceListUpnpServiceType; 12 import org.openhome.net.controlpoint.ICpDeviceListListener; 13 import org.openhome.net.controlpoint.tests.TestBasicCp; 14 import org.openhome.net.core.InitParams; 15 import org.openhome.net.core.Library; 16 import org.openhome.net.core.NetworkAdapter; 17 import org.openhome.net.core.SubnetList; 18 19 20 public class TestDvDevice implements ICpDeviceListListener 21 { 22 private List<CpDevice> iDeviceList; 23 private DeviceBasic iDevice; 24 private Semaphore iSem; 25 26 public TestDvDevice() 27 { 28 File f = null; 29 try 30 { 31 f = new File("C:\\Keep\\git\\repository\\MediaPlayer\\com.upnp.mediaplayer\\build\\beta\\libs\\win32\\ohNet.dll"); 32 } 33 catch (Exception e) 34 { 35 36 } 37 System.loadLibrary(f.getAbsolutePath()); 38 System.out.println("TestDvDeviceJava - starting"); 39 iDevice = new DeviceBasic(); 40 iDeviceList = new ArrayList<CpDevice>(); 41 CpDeviceListUpnpServiceType list = new CpDeviceListUpnpServiceType("openhome.org", "TestBasic", 1, this); 42 iSem = new Semaphore(1); 43 iSem.acquireUninterruptibly(); 44 try { 45 iSem.tryAcquire(30*1000, TimeUnit.MILLISECONDS); 46 } 47 catch (InterruptedException ie) 48 { 49 ie.printStackTrace(); 50 } 51 assert(iDeviceList.size() == 1); 52 System.out.println("iDeviceList size: " + iDeviceList.size()); 53 TestBasicCp cp = new TestBasicCp(iDeviceList.get(0)); 54 cp.testActions(); 55 cp.testSubscriptions(); 56 list.destroy(); 57 synchronized (this) 58 { 59 for (CpDevice d : iDeviceList) 60 { 61 d.removeRef(); 62 } 63 } 64 iDevice.dispose(); 65 66 System.out.println("TestDvDeviceJava - completed"); 67 } 68 69 public void deviceAdded(CpDevice aDevice) 70 { 71 synchronized (this) 72 { 73 if (aDevice.getUdn().equals(iDevice.getUdn())) 74 { 75 aDevice.addRef(); 76 iDeviceList.add(aDevice); 77 iSem.release(); 78 } 79 } 80 81 } 82 83 public void deviceRemoved(CpDevice aDevice) 84 { 85 synchronized (this) 86 { 87 String udn = aDevice.getUdn(); 88 int i = 0; 89 for (CpDevice n : iDeviceList) 90 { 91 if (n.getUdn() == udn) 92 { 93 n.removeRef(); 94 iDeviceList.remove(i); 95 } 96 i++; 97 } 98 } 99 } 100 101 public static void main(String[] args) 102 { 103 InitParams initParams = new InitParams(); 104 initParams.setMsearchTimeSecs(1); 105 initParams.setUseLoopbackNetworkAdapter(); 106 initParams.setDvServerPort(0); 107 Library lib = new Library(); 108 lib.initialise(initParams); 109 SubnetList subnetList = new SubnetList(); 110 NetworkAdapter nif = subnetList.getSubnet(0); 111 Inet4Address subnet = nif.getSubnet(); 112 subnetList.destroy(); 113 lib.startCombined(subnet); 114 new TestDvDevice(); 115 lib.close(); 116 } 117 }