aRts audio server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.7KB

  1. /*
  2. Copyright (C) 1999 Stefan Westerfeld
  3. stefan@space.twc.de
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  15. Permission is also granted to link this program with the Qt
  16. library, treating Qt like a library that normally accompanies the
  17. operating system kernel, whether or not that is in fact the case.
  18. */
  19. #include "hello.h"
  20. #include "dynamicrequest.h"
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <iostream>
  24. using namespace std;
  25. using namespace Arts;
  26. /*
  27. * Hellodynamic illustrates the usage of the DynamicRequest class to perform
  28. * dynamic requests. There are two things you can try
  29. *
  30. * hellodynamic
  31. *
  32. * which will use a local implementation of a hello object, and
  33. *
  34. * hellodynamic <mcop reference>
  35. *
  36. * which will use a remote implementation of a hello object.
  37. */
  38. int main(int argc, char **argv)
  39. {
  40. Dispatcher dispatcher;
  41. Hello h;
  42. // Check if we should connect to a remote server:
  43. if(argc == 2)
  44. {
  45. h = Reference(argv[1]);
  46. if(h.isNull())
  47. {
  48. fprintf(stderr,"can't connect to the object\n");
  49. exit(1);
  50. }
  51. }
  52. // find out logname
  53. const char *who = getenv("LOGNAME");
  54. if(!who) who = "stefan";
  55. printf("calling h.hello(\"%s\")\n", who);
  56. // the dynamic equivalent to h.hello(who)
  57. DynamicRequest hellorequest(h);
  58. if(!hellorequest.method("hello").param(who).invoke())
  59. cout << "dynamic invocation to h.hello(...) failed" << endl;
  60. /*
  61. Note: you could reuse hellorequest here, and indeed, if you
  62. call the _same_ method over and over again, you'll get quite
  63. some speed gain as the signature is only looked up once.
  64. */
  65. // set a value (no error checking here, I am lazy ;)
  66. DynamicRequest(h).method("_set_myValue").param(42).invoke();
  67. // get a value via "normal" interface
  68. printf("h.myValue() is %ld (after setting it to 42)\n", h.myValue());
  69. // call h.concat("MCOP ","rules.") dynamically
  70. string s;
  71. DynamicRequest(h).method("concat").param("MCOP ").param("rules.").invoke(s);
  72. cout << "Conclusion of this test: " << s << endl;
  73. return 0;
  74. }