12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- 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<String>());
- 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[]{pos, 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[]{pos, speed});
- return success;
- } catch (XmlRpcException e) {
- e.printStackTrace();
- return false;
- }
- }
- }
|