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.

dynamicskeleton.h 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. #ifndef ARTS_MCOP_DYNAMICSKELETON_H
  18. #define ARTS_MCOP_DYNAMICSKELETON_H
  19. #include "arts_export.h"
  20. #include "object.h"
  21. /*
  22. * BC - Status (2002-03-08): DynamicSkeletonBase, DynamicSkeleton
  23. *
  24. * Will be kept binary compatible (using d ptr).
  25. */
  26. namespace Arts {
  27. class DynamicSkeletonData;
  28. class ARTS_EXPORT DynamicSkeletonBase {
  29. private:
  30. DynamicSkeletonData *d;
  31. protected:
  32. DynamicSkeletonBase();
  33. /* <obsolete compatibility code> */
  34. DynamicSkeletonBase(Object_skel *skel,
  35. const std::string& interfacename,
  36. const std::string& interfacenameparent);
  37. /* </obsolete compatibility code> */
  38. virtual ~DynamicSkeletonBase();
  39. void _dsInit(Object_skel *skel, const std::string& interfacename,
  40. const std::string& interfacenameparent);
  41. std::string _dsInterfaceName();
  42. bool _dsIsCompatibleWith(const std::string& interfacename);
  43. void _dsBuildMethodTable();
  44. public:
  45. /**
  46. * process is called whenever you get a request that you need to implement
  47. * dynamically
  48. *
  49. * @param methodID contains the ID of the method that you need to
  50. * implement - you can get the full signature by calling
  51. * getMethodDef
  52. *
  53. * @param request contains the marshalled parameters
  54. *
  55. * @param result is for the return code - if your method returns a
  56. * value, you need to write the it in the result Buffer
  57. */
  58. virtual void process(long methodID, Buffer *request, Buffer *result) = 0;
  59. };
  60. /**
  61. * DynamicSkeleton is used to dynamically implement an interface (i.e. without
  62. * static type bindings as generated by the MCOP idl compiler.
  63. *
  64. * You will always implement a mixed version: mcopidl generated skeletons up
  65. * to a certain point, and above this, dynamically implemented interfaces.
  66. * So you'll inherit DynamicSkeleton<Static_skel> and give the interface you
  67. * want to implement dynamically as argument. Suppose your idl file looks
  68. * like
  69. *
  70. * <pre>
  71. * interface A { void a(); };
  72. * interface B : A { void b(); };
  73. * </pre>
  74. *
  75. * And you want to implement interface A "classic" (i.e. with mcopidl generated
  76. * virtual void a()) and interface B "dynamic", you would do
  77. *
  78. * <pre>
  79. * typedef Arts::DynamicSkeleton<A_skel> A_dskel; // convenient with typedef
  80. *
  81. * class B_impl : public A_dskel {
  82. * public:
  83. * B_impl() : A_dskel("B") { // we dynamically implement the B interface
  84. * }
  85. * void a() { // through A_skel
  86. * arts_info("a called");
  87. * }
  88. * void process(long methodID, Arts::Buffer *request, Arts::Buffer *result)
  89. * {
  90. * const Arts::MethodDef& methodDef = getMethodDef(methodID);
  91. *
  92. * if(methodDef.name == "b")
  93. * arts_info("b called!");
  94. * else
  95. * arts_fatal("Unknown method '%s' called");
  96. * }
  97. * };
  98. * </pre>
  99. */
  100. template<class Parent_skel>
  101. class DynamicSkeleton : virtual public Parent_skel, public DynamicSkeletonBase
  102. {
  103. public:
  104. /**
  105. * constructor
  106. */
  107. DynamicSkeleton(const std::string& interface)
  108. {
  109. _dsInit(this, interface, Parent_skel::_interfaceNameSkel());
  110. }
  111. /**
  112. * getMethodDef returns a MethodDef structure for a given methodID - it
  113. * is quite useful if you implement process
  114. *
  115. * <pre>
  116. * void process(long methodID, Arts::Buffer *request, Arts::Buffer *result)
  117. * {
  118. * const Arts::MethodDef& methodDef = getMethodDef(methodID);
  119. *
  120. * if(methodDef.name == "hello") // the method named hello was called
  121. * printf("Hello!\n");
  122. * else // method with other name was called
  123. * arts_fatal("Method '%s' not implemented",methodDef.name.c_str());
  124. * }
  125. * </pre>
  126. */
  127. const MethodDef& getMethodDef(long methodID) {
  128. return this->_dsGetMethodDef(methodID);
  129. }
  130. /*-- reimplemented from Arts::Object_skel: --*/
  131. std::string _interfaceName() {
  132. return _dsInterfaceName();
  133. }
  134. bool _isCompatibleWith(const std::string& interfacename) {
  135. if(_dsIsCompatibleWith(interfacename)) return true;
  136. return Parent_skel::_isCompatibleWith(interfacename);
  137. }
  138. void _buildMethodTable() {
  139. Parent_skel::_buildMethodTable();
  140. _dsBuildMethodTable();
  141. }
  142. };
  143. }
  144. #endif /* ARTS_MCOP_DYNAMICSKELETON_H */