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 / dynamicrequest.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-10  |  3.3 KB  |  134 lines

  1.     /*
  2.  
  3.     Copyright (C) 2000 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 MCOP_DYNAMICREQUEST_H
  24. #define MCOP_DYNAMICREQUEST_H
  25.  
  26. #include "buffer.h"
  27. #include "anyref.h"
  28. #include <vector>
  29. #include <string>
  30.  
  31. #include "arts_export.h"
  32.  
  33. /*
  34.  * BC - Status (2002-03-08): DynamicRequest
  35.  *
  36.  * Has to be kept binary compatible (use d ptr).
  37.  */
  38.  
  39. namespace Arts {
  40.  
  41. class Object;
  42. class Type;
  43. class DynamicRequestPrivate;
  44.  
  45. /**
  46.  * The DynamicRequest class can be used to invoke requests on objects, without
  47.  * using IDL generated code to do so (i.e. you can talk to objects without
  48.  * having to know their interfaces at compile time)
  49.  *
  50.  * Suppose you have the interface
  51.  *
  52.  * interface SimpleSoundServer {
  53.  *   [...]
  54.  *   long play(string file);    // plays a file and returns an id
  55.  *   [...]
  56.  * };
  57.  *
  58.  * And server is of type SimpleSoundServer, you can write in your C++ code:
  59.  *
  60.  *   long id;
  61.  *   if(DynamicRequest(server).method("play").param("/tmp/bong.wav").invoke(id))
  62.  *   {
  63.  *     cout << "playing file now, id is " << id << endl;
  64.  *   }
  65.  *   else
  66.  *   {
  67.  *     cout << "something went wrong with the dynamic request" << endl;
  68.  *   }
  69.  *
  70.  * You can of course also add parameters and other information one-by-one:
  71.  *
  72.  *   DynamicRequest request(server);
  73.  *   request.method("play");
  74.  *   request.param("/tmp/bong.wav");
  75.  *
  76.  *   long id;
  77.  *   if(request.invoke(id)) cout << "success" << endl;
  78.  */
  79.  
  80. class ARTS_EXPORT DynamicRequest {
  81. public:
  82.     /**
  83.      * creates a dynamic request which will be sent to a specific object
  84.      */
  85.     DynamicRequest(const Object& object);
  86.  
  87.     /**
  88.      * deletes the dynamic request
  89.      */
  90.     ~DynamicRequest();
  91.  
  92.     /**
  93.      * says that the following method will be a oneway method, for example
  94.      *
  95.      * DynamicRequest(someobject).oneway().method("stop").invoke();
  96.      */
  97.     DynamicRequest& oneway();
  98.  
  99.     /**
  100.      * sets the method to invoke
  101.      */
  102.     DynamicRequest& method(const std::string& method);
  103.  
  104.     /**
  105.      * adds a parameter to the call
  106.      */
  107.     DynamicRequest& param(const AnyConstRef& value);
  108.  
  109.     /**
  110.      * executes the request, call this if you don't expect a return type
  111.      * 
  112.      * @returns true if the request could be performed
  113.      */
  114.     bool invoke();
  115.  
  116.     /**
  117.      * executes the request: this version accepts an AnyRef& as result type
  118.      *
  119.      * @returns true if the request could be performed
  120.      */
  121.     bool invoke(const AnyRef& result);
  122.  
  123.     /*
  124.      * TODO: Some types can't yet be used in dynamic requests, these are
  125.      * enum, sequence<enum>, type, sequence<type>, object, sequence<object>
  126.      */
  127. private:
  128.     DynamicRequestPrivate *d;
  129. };
  130.  
  131. }
  132.  
  133. #endif /* MCOP_DYNAMICREQUEST_H */
  134.