home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / arts / dynamicskeleton.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-10  |  4.8 KB  |  164 lines

  1.     /*
  2.  
  3.     Copyright (C) 2001 Stefan Westerfeld
  4.                        stefan@space.twc.de
  5.  
  6.     This library is free software; you can redistribute it and/or
  7.     modify it under the terms of the GNU Library General Public
  8.     License as published by the Free Software Foundation; either
  9.     version 2 of the License, or (at your option) any later version.
  10.   
  11.     This library is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.     Library General Public License for more details.
  15.    
  16.     You should have received a copy of the GNU Library General Public License
  17.     along with this library; see the file COPYING.LIB.  If not, write to
  18.     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19.     Boston, MA 02111-1307, USA.
  20.  
  21.     */
  22.  
  23. #ifndef ARTS_MCOP_DYNAMICSKELETON_H
  24. #define ARTS_MCOP_DYNAMICSKELETON_H
  25.  
  26. #include "arts_export.h"
  27.  
  28. #include "object.h"
  29.  
  30. /*
  31.  * BC - Status (2002-03-08): DynamicSkeletonBase, DynamicSkeleton
  32.  *
  33.  * Will be kept binary compatible (using d ptr).
  34.  */
  35. namespace Arts {
  36.  
  37. class DynamicSkeletonData;
  38.  
  39. class ARTS_EXPORT DynamicSkeletonBase {
  40. private:
  41.     DynamicSkeletonData *d;
  42.  
  43. protected:
  44.     DynamicSkeletonBase();
  45.     /* <obsolete compatibility code> */
  46.     DynamicSkeletonBase(Object_skel *skel,
  47.                 const std::string& interfacename,
  48.                 const std::string& interfacenameparent);
  49.     /* </obsolete compatibility code> */
  50.     virtual ~DynamicSkeletonBase();
  51.  
  52.     void _dsInit(Object_skel *skel, const std::string& interfacename,
  53.                                        const std::string& interfacenameparent);
  54.     std::string _dsInterfaceName();
  55.     bool _dsIsCompatibleWith(const std::string& interfacename);
  56.     void _dsBuildMethodTable();
  57.  
  58. public:
  59.     /**
  60.      * process is called whenever you get a request that you need to implement
  61.      * dynamically
  62.      *
  63.      * @param methodID contains the ID of the method that you need to
  64.      *                 implement - you can get the full signature by calling
  65.      *                 getMethodDef
  66.      *
  67.      * @param request  contains the marshalled parameters
  68.      *
  69.      * @param result   is for the return code - if your method returns a
  70.      *                 value, you need to write the it in the result Buffer
  71.      */
  72.     virtual void process(long methodID, Buffer *request, Buffer *result) = 0;
  73. };
  74.  
  75. /**
  76.  * DynamicSkeleton is used to dynamically implement an interface (i.e. without
  77.  * static type bindings as generated by the MCOP idl compiler.
  78.  *
  79.  * You will always implement a mixed version: mcopidl generated skeletons up
  80.  * to a certain point, and above this, dynamically implemented interfaces.
  81.  * So you'll inherit DynamicSkeleton<Static_skel> and give the interface you
  82.  * want to implement dynamically as argument. Suppose your idl file looks
  83.  * like
  84.  *
  85.  * <pre>
  86.  * interface A { void a(); };
  87.  * interface B : A { void b(); };
  88.  * </pre>
  89.  *
  90.  * And you want to implement interface A "classic" (i.e. with mcopidl generated
  91.  * virtual void a()) and interface B "dynamic", you would do
  92.  *
  93.  * <pre>
  94.  * typedef Arts::DynamicSkeleton<A_skel> A_dskel;   // convenient with typedef
  95.  *
  96.  * class B_impl : public A_dskel {
  97.  * public:
  98.  *   B_impl() : A_dskel("B") {  // we dynamically implement the B interface
  99.  *   }
  100.  *   void a() { // through A_skel
  101.  *     arts_info("a called");
  102.  *   }
  103.  *   void process(long methodID, Arts::Buffer *request, Arts::Buffer *result)
  104.  *   {
  105.  *       const Arts::MethodDef& methodDef = getMethodDef(methodID);
  106.  *     
  107.  *       if(methodDef.name == "b")
  108.  *         arts_info("b called!");
  109.  *       else
  110.  *         arts_fatal("Unknown method '%s' called");
  111.  *     }
  112.  * };
  113.  * </pre>
  114.  */
  115. template<class Parent_skel>
  116. class DynamicSkeleton : virtual public Parent_skel, public DynamicSkeletonBase
  117. {
  118. public:
  119.     /**
  120.      * constructor
  121.      */
  122.     DynamicSkeleton(const std::string& interface)
  123.     {
  124.         _dsInit(this, interface, Parent_skel::_interfaceNameSkel());
  125.     }
  126.  
  127.     /**
  128.      * getMethodDef returns a MethodDef structure for a given methodID - it
  129.      * is quite useful if you implement process
  130.      *
  131.      * <pre>
  132.      * void process(long methodID, Arts::Buffer *request, Arts::Buffer *result)
  133.      * {
  134.      *   const Arts::MethodDef& methodDef = getMethodDef(methodID);
  135.      * 
  136.      *     if(methodDef.name == "hello") // the method named hello was called
  137.      *       printf("Hello!\n");
  138.      *     else                          // method with other name was called
  139.      *       arts_fatal("Method '%s' not implemented",methodDef.name.c_str());
  140.      * }
  141.      * </pre>
  142.      */
  143.     const MethodDef& getMethodDef(long methodID) {
  144.         return this->_dsGetMethodDef(methodID);
  145.     }
  146.  
  147. /*-- reimplemented from Arts::Object_skel: --*/
  148.     std::string _interfaceName() {
  149.         return _dsInterfaceName();
  150.     }
  151.  
  152.     bool _isCompatibleWith(const std::string& interfacename) {
  153.         if(_dsIsCompatibleWith(interfacename)) return true;
  154.         return Parent_skel::_isCompatibleWith(interfacename);
  155.     }
  156.     void _buildMethodTable() {
  157.         Parent_skel::_buildMethodTable();
  158.         _dsBuildMethodTable();
  159.     }
  160. };
  161.  
  162. }
  163. #endif /* ARTS_MCOP_DYNAMICSKELETON_H */
  164.