package uraxis; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import org.apache.xmlrpc.XmlRpcException; import org.apache.xmlrpc.client.XmlRpcClient; import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; public class MyDaemonInterface { XmlRpcClient client; public MyDaemonInterface(String host, int port) { XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); config.setEnabledForExtensions(true); try { config.setServerURL(new URL("http://" + host + ":" + port + "/RPC2")); } catch (MalformedURLException e) { e.printStackTrace(); } config.setConnectionTimeout(1000); //1s client = new XmlRpcClient(); client.setConfig(config); } public boolean isReachable() { try { client.execute("get_title", new ArrayList()); return true; } catch (XmlRpcException e) { return false; } } public void setTitle(String title) { } public String getTitle() { return ""; } public String getMessage(String name) { return ""; } public int getpos() { try { Object res= client.execute("getpos", new Object[]{}); return (int) res; } catch (XmlRpcException e) { e.printStackTrace(); return -1; } } public String getstatus() { try { String res= (String) client.execute("status", new Object[]{}); return res; } catch (XmlRpcException e) { e.printStackTrace(); return ""; } } public boolean rel(int pos, int speed) { try { boolean success= (boolean) client.execute("rel", new Object[]{String.valueOf(pos), String.valueOf(speed)}); return success; } catch (XmlRpcException e) { e.printStackTrace(); return false; } } public boolean abs(int pos, int speed) { try { boolean success= (boolean) client.execute("abs", new Object[]{String.valueOf(pos), String.valueOf(speed)}); return success; } catch (XmlRpcException e) { e.printStackTrace(); return false; } } }