package org.hwo.pulscounter; import java.io.File; import java.io.IOException; import java.lang.reflect.Field; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Arrays; import java.util.Iterator; import java.util.prefs.Preferences; import org.hwo.beacon.Beacon; import org.hwo.os.OsDetect; import org.hwo.os.OsDetect.OsType; import org.hwo.rpc.json.RPCAdapter; import org.hwo.rpc.simple.SimpleRPCServer; public class PulsCounter { static private Preferences prefs; public static Preferences getPrefs() { return prefs; } static private IPulsCounter deviceConnection; public static IPulsCounter getDeviceConnection() { return deviceConnection; } public static void setDeviceConnection(IPulsCounter deviceConnection) { PulsCounter.deviceConnection = deviceConnection; } private static Beacon beacon; public static Beacon getBeacon() { return beacon; } static boolean serverMode; public static void main(String args[]) { File cwd = new File("."); System.err.println("Starting on OS: " + System.getProperty("os.name")); System.err.println("Current Directory: " + cwd.getAbsolutePath()); System.err.println("Library Path: " + System.getProperty("java.library.path")); prefs = Preferences.userRoot(); if (OsDetect.getOperatingSystem() == OsType.LINUX) { System.err.println("Linux erkannt. Patche java.library.path"); System.setProperty("java.library.path",String.format(".:%s",System.getProperty("java.library.path"))); Field fieldSysPath; try { fieldSysPath = ClassLoader.class.getDeclaredField( "sys_paths" ); fieldSysPath.setAccessible( true ); fieldSysPath.set( null, null ); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchFieldException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.err.println("Library Path: " + System.getProperty("java.library.path")); } Iterator options = Arrays.asList(args).iterator(); while (options.hasNext()) { String no = options.next(); if (no.equals("-s")) { serverMode = true; } } deviceConnection = null; beacon = new Beacon(44556); beacon.getProperties().setProperty("rpc.simple.interfaces", "org.hwo.pulsecounter"); beacon.getProperties().setProperty("rpc.simple.port", "44352"); beacon.setServerOnly(serverMode); beacon.start(); try { NewPulsCounterDevice device = new NewPulsCounterDevice(); SimpleRPCServer rpcserver = new SimpleRPCServer(InetAddress.getByName("0.0.0.0"), 44352); rpcserver.registerObject(IPulsCounter.class, device); rpcserver.start(); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } if (!serverMode) { PulsCounterWindow window = new PulsCounterWindow(); window.setVisible(true); } } }