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.

125 lines
3.2KB

  1. /*
  2. Copyright (C) 2001 Stefan Westerfeld
  3. stefan@space.twc.de
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library 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 GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public License
  13. along with this library; see the file COPYING.LIB. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. #include "hello.h"
  18. #include "dynamicskeleton.h"
  19. #include "debug.h"
  20. #include "stdio.h"
  21. using namespace Arts;
  22. using namespace std;
  23. namespace Arts { typedef DynamicSkeleton<Arts::Object_skel> Object_dskel; }
  24. class HelloDynamic : public Arts::Object_dskel {
  25. protected:
  26. long myValue;
  27. public:
  28. HelloDynamic() : Arts::Object_dskel("Hello") {
  29. }
  30. void process(long methodID, Arts::Buffer *request, Arts::Buffer *result)
  31. {
  32. const Arts::MethodDef& methodDef = getMethodDef(methodID);
  33. if(methodDef.name == "hello") // void hello(string);
  34. {
  35. string s; request->readString(s);
  36. printf("Hello '%s'!\n",s.c_str());
  37. }
  38. else if(methodDef.name == "_set_myValue") // attribute long myValue;
  39. {
  40. myValue = request->readLong();
  41. }
  42. else if(methodDef.name == "_get_myValue")
  43. {
  44. result->writeLong(myValue);
  45. }
  46. else if(methodDef.name == "concat")
  47. {
  48. string s1; request->readString(s1);
  49. string s2; request->readString(s2);
  50. result->writeString(s1+s2);
  51. }
  52. else if(methodDef.name == "sum")
  53. {
  54. long a = request->readLong();
  55. long b = request->readLong();
  56. result->writeLong(a+b);
  57. }
  58. else
  59. {
  60. arts_fatal("method %s unimplemented", methodDef.name.c_str());
  61. }
  62. }
  63. };
  64. /*
  65. * this program illustrates that you /can/ implement an interface without
  66. * using the IDL compiler skeleton do to so - this is useful if you want
  67. * to create a language or object system binding, where you don't know
  68. * all interfaces that are present at compile time
  69. *
  70. * however, it's definitely advanced stuff, and not for daily use ;)
  71. */
  72. int main()
  73. {
  74. Dispatcher dispatcher;
  75. Object obj = Object::_from_base(new HelloDynamic());
  76. if(obj.isNull())
  77. arts_fatal("dimpl is no object?");
  78. HelloBase b = DynamicCast(obj);
  79. if(b.isNull())
  80. arts_fatal("can't cast the object to HelloBase");
  81. Hello h = DynamicCast(obj);
  82. /*arts_info("%d",obj.isCompatibleWith("Hello"));*/
  83. if(h.isNull())
  84. arts_fatal("can't destringify to the object");
  85. const char *who = getenv("LOGNAME");
  86. if(!who) who = "stefan";
  87. arts_info("calling h.hello(\"%s\")", who);
  88. h.hello(who);
  89. h.myValue(6);
  90. arts_info("h.myValue(6), h.myValue() is %ld",
  91. h.myValue());
  92. arts_info("h.concat(\"MCOP \",\"is great!\") is \"%s\"",
  93. h.concat("MCOP ","is great!").c_str());
  94. /*
  95. int i,j = 0;
  96. for(i=0;i<100000;i++)
  97. j += h.sum(2,4);
  98. printf("%d\n",j);
  99. */
  100. return 0;
  101. }