MyDaemonInterface.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package uraxis;
  2. import java.net.MalformedURLException;
  3. import java.net.URL;
  4. import java.util.ArrayList;
  5. import org.apache.xmlrpc.XmlRpcException;
  6. import org.apache.xmlrpc.client.XmlRpcClient;
  7. import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
  8. public class MyDaemonInterface {
  9. XmlRpcClient client;
  10. public MyDaemonInterface(String host, int port) {
  11. XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
  12. config.setEnabledForExtensions(true);
  13. try {
  14. config.setServerURL(new URL("http://" + host + ":" + port + "/RPC2"));
  15. } catch (MalformedURLException e) {
  16. e.printStackTrace();
  17. }
  18. config.setConnectionTimeout(1000); //1s
  19. client = new XmlRpcClient();
  20. client.setConfig(config);
  21. }
  22. public boolean isReachable() {
  23. try {
  24. client.execute("get_title", new ArrayList<String>());
  25. return true;
  26. } catch (XmlRpcException e) {
  27. return false;
  28. }
  29. }
  30. public void setTitle(String title) {
  31. }
  32. public String getTitle() {
  33. return "";
  34. }
  35. public String getMessage(String name) {
  36. return "";
  37. }
  38. public boolean rel(int val) {
  39. try {
  40. ArrayList l = new ArrayList();
  41. l.add(val);
  42. client.execute("rel", l);
  43. return true;
  44. } catch (XmlRpcException e) {
  45. return false;
  46. }
  47. }
  48. public boolean abs(int val) {
  49. try {
  50. ArrayList l = new ArrayList();
  51. l.add(val);
  52. client.execute("abs", l);
  53. return true;
  54. } catch (XmlRpcException e) {
  55. return false;
  56. }
  57. }
  58. // public String getTitle() throws XmlRpcException, UnknownResponseException {
  59. // Object result = client.execute("get_title", new ArrayList<String>());
  60. // return processString(result);
  61. // }
  62. //
  63. // public String setTitle(String title) throws XmlRpcException, UnknownResponseException {
  64. // ArrayList<String> args = new ArrayList<String>();
  65. // args.add(title);
  66. // Object result = client.execute("set_title", args);
  67. // return processString(result);
  68. // }
  69. //
  70. // public String getMessage(String name) throws XmlRpcException, UnknownResponseException {
  71. // ArrayList<String> args = new ArrayList<String>();
  72. // args.add(name);
  73. // Object result = client.execute("get_message", args);
  74. // return processString(result);
  75. // }
  76. }