Generate unique id

This commit is contained in:
Iwan Timmer
2014-08-16 17:28:54 +02:00
parent 23ad1e426a
commit 47a3057827

View File

@@ -1,7 +1,5 @@
package com.limelight; package com.limelight;
import java.io.IOException;
import com.limelight.binding.PlatformBinding; import com.limelight.binding.PlatformBinding;
import com.limelight.binding.audio.FakeAudioRenderer; import com.limelight.binding.audio.FakeAudioRenderer;
import com.limelight.binding.video.FakeVideoRenderer; import com.limelight.binding.video.FakeVideoRenderer;
@@ -13,19 +11,22 @@ import com.limelight.nvstream.StreamConfiguration;
import com.limelight.nvstream.av.video.VideoDecoderRenderer; import com.limelight.nvstream.av.video.VideoDecoderRenderer;
import com.limelight.nvstream.http.NvApp; import com.limelight.nvstream.http.NvApp;
import com.limelight.nvstream.http.NvHTTP; import com.limelight.nvstream.http.NvHTTP;
import java.io.File;
import java.io.FileNotFoundException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.limelight.nvstream.http.PairingManager; import com.limelight.nvstream.http.PairingManager;
import com.limelight.nvstream.mdns.MdnsComputer; import com.limelight.nvstream.mdns.MdnsComputer;
import com.limelight.nvstream.mdns.MdnsDiscoveryAgent; import com.limelight.nvstream.mdns.MdnsDiscoveryAgent;
import com.limelight.nvstream.mdns.MdnsDiscoveryListener; import com.limelight.nvstream.mdns.MdnsDiscoveryListener;
import org.xmlpull.v1.XmlPullParserException; import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* Main class for Limelight Pi * Main class for Limelight Pi
@@ -76,7 +77,7 @@ public class Limelight implements NvConnectionListener {
} }
} }
conn = new NvConnection(host.getHostAddress(), "Pi", this, streamConfig, PlatformBinding.getCryptoProvider()); conn = new NvConnection(host.getHostAddress(), getUniqueId(), this, streamConfig, PlatformBinding.getCryptoProvider());
GamepadMapping mapping = null; GamepadMapping mapping = null;
if (mappingFile!=null) { if (mappingFile!=null) {
@@ -110,7 +111,7 @@ public class Limelight implements NvConnectionListener {
* Creates a connection to the host and starts up the stream. * Creates a connection to the host and starts up the stream.
*/ */
private void startUpFake(StreamConfiguration streamConfig, String videoFile) { private void startUpFake(StreamConfiguration streamConfig, String videoFile) {
conn = new NvConnection(host.getHostAddress(), "Pi", this, streamConfig, PlatformBinding.getCryptoProvider()); conn = new NvConnection(host.getHostAddress(), getUniqueId(), this, streamConfig, PlatformBinding.getCryptoProvider());
conn.start(PlatformBinding.getDeviceName(), null, conn.start(PlatformBinding.getDeviceName(), null,
VideoDecoderRenderer.FLAG_PREFER_QUALITY, VideoDecoderRenderer.FLAG_PREFER_QUALITY,
new FakeAudioRenderer(), new FakeAudioRenderer(),
@@ -124,7 +125,7 @@ public class Limelight implements NvConnectionListener {
NvHTTP httpConn; NvHTTP httpConn;
httpConn = new NvHTTP(host, httpConn = new NvHTTP(host,
"Pi", PlatformBinding.getDeviceName(), PlatformBinding.getCryptoProvider()); getUniqueId(), PlatformBinding.getDeviceName(), PlatformBinding.getCryptoProvider());
try { try {
if (httpConn.getPairState() == PairingManager.PairState.PAIRED) { if (httpConn.getPairState() == PairingManager.PairState.PAIRED) {
displayError("pair", "Already paired"); displayError("pair", "Already paired");
@@ -150,7 +151,7 @@ public class Limelight implements NvConnectionListener {
} }
private void listApps() { private void listApps() {
NvHTTP conn = new NvHTTP(host, "Pi", PlatformBinding.getDeviceName(), PlatformBinding.getCryptoProvider()); NvHTTP conn = new NvHTTP(host, getUniqueId(), PlatformBinding.getDeviceName(), PlatformBinding.getCryptoProvider());
displayMessage("Search apps"); displayMessage("Search apps");
try { try {
List<NvApp> apps = conn.getAppList(); List<NvApp> apps = conn.getAppList();
@@ -393,6 +394,29 @@ public class Limelight implements NvConnectionListener {
} }
} }
public String getUniqueId() {
try {
File file = new File("uniqueid.dat");
if (file.exists()) {
FileInputStream in = new FileInputStream(file);
byte[] id = new byte[16];
in.read(id);
in.close();
return new String(id);
} else {
String id = String.format("%016x", new Random().nextLong());
FileOutputStream out = new FileOutputStream(file);
out.write(id.getBytes());
out.close();
return id;
}
} catch (IOException ex) {
LimeLog.severe(ex.getMessage());
}
return "limelight";
}
public void setLevel(Level level) { public void setLevel(Level level) {
if (logger==null) if (logger==null)
logger = Logger.getLogger(LimeLog.class.getName()); logger = Logger.getLogger(LimeLog.class.getName());