Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

vos/metaobjects/hello/hello.hh

Go to the documentation of this file.
00001 /* <![CDATA[ 
00002     Copyright (C) 2002 Peter Amstutz <tetron@interreality.org>
00003 
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or
00007     (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  */ 
00018 
00019 #ifndef _HELLO_HH_
00020 #define _HELLO_HH_
00021 
00022 // this stuff makes DLL's work on windows
00023 #if defined(_WIN32) && defined(_MSC_VER)
00024 # ifdef HELLO_EXPORTS
00025 #  define HELLO_API __declspec(dllexport)
00026 # else
00027 #  define HELLO_API __declspec(dllimport)
00028 # endif
00029 #else
00030 # define HELLO_API
00031 #endif
00032 
00033 
00034 // First of all, bring in all the VOS class definitions.
00035 #include <vos/corelibs/vos/vos.hh>
00036 
00037 /** Example MetaObject class.  This is a metaobject extension, which means
00038     that it can be used to extend (on the fly) the API and
00039     capabilities of a Vobject.
00040 
00041     This class is abstract.  It provides a abstract interface for the
00042     methods we want to virtualize, the implementation is left to the
00043     subclasses.
00044 
00045     For starters, all extensions must inherit
00046     from "MetaObject".  Also note that they must inherit as "virtual"
00047     (a virtual base class) because of the way VOS uses multiple
00048     inheritance internally.
00049 
00050     The HELLO_API tag makes DLL's work on Windoze.
00051  */
00052 class HELLO_API Hello : public virtual MetaObject
00053 {
00054 protected:
00055     /** Construtor.  Never called directly (this is an abstract class
00056         anyhow.) */
00057     Hello(MetaObject* superobject);
00058 public:
00059     /** The method we are virtualizing.  Here we simply supply the
00060         interface.  This allows the application to simply interact
00061         with objects of type "Hello" and not care at all whether the
00062         object is local or remote.
00063     */
00064     virtual string hello(const string& s) = 0;
00065 
00066     /* This returns the VOS type string for this specific extension, in
00067        this case "example:hello".  This is the object type at the VOS
00068        level (in the Vobject::getTypes() set) NOT the C++ class name.
00069        Note: this is prepended with "example:" because the hello is part
00070        of the "example" group of object types.  Other object
00071        types may be prepended with other group names, for example
00072        types part of Abstract 3D Layer are prepended with "a3dl:"
00073        instead.  This avoids name conflicts and make may make it
00074        easier to determine what unfamiliar object types do.  (Note that
00075        in the local and remote subclasses, the hello method's name (at 
00076        the VOS protocol level) is also prepended with "example:".)
00077      */
00078     virtual const string getType();
00079 
00080     /** Standard method to be called by an application to request
00081        that this type extension be registered with VOS.
00082      */
00083     static void registerExtenders();
00084 };
00085 
00086 /** This class implements the local Hello object.  It also
00087     contains the code to respond to requests from its remote peer.
00088 */
00089 class HELLO_API LocalHello : public virtual Hello
00090 {
00091 protected:
00092     /** Constructor.  You don't call this directly; the Site::createMetaObject
00093         methods are used instead.   */
00094     LocalHello(MetaObject* superobject);
00095 public:
00096 
00097     /** The hello method declared pure virtual above. This method is called
00098         directly from the local application, or by handleHello() in response to a
00099         message from this object's remote peer. */
00100     virtual string hello(const string& s);
00101 
00102     /** Callback for a "hello" message from the remote peer: extracts fields
00103         from the Message and then calls hello. */
00104     void handleHello(Message* m);
00105 
00106     /** Since constructors are not quite normal functions, we have a wrapper
00107         around the constructor which can be stored by VOS, and called when
00108         you ask for an object with this type extension by calling 
00109         Site::createMetaObject().
00110     */
00111     static MetaObject* new_LocalHello(MetaObject* superobject, const string& type);
00112 };
00113 
00114 
00115 
00116 /** This class defines the remote proxy for the local Hello object.  */
00117 class HELLO_API RemoteHello : public virtual Hello
00118 {
00119 protected:
00120     /** Constructor.  You don't call this directly. Usually you won't be
00121         creating Vobjects remotely, but finding them with Vobject::findObject(),
00122         Vobject::findObjectFromRoot(), etc.  */
00123     RemoteHello(MetaObject* superobject);
00124 
00125 public:
00126     /** This will dispatch a request message to this remote object's local 
00127         peer object, and wait for a response. */
00128     virtual string hello(const string& s);
00129 
00130     /** Since constructors are not quite normal functions, we have a wrapper
00131         around the constructor which VOS can store and call to create an
00132         object with this type extension.
00133     */
00134     static MetaObject* new_RemoteHello(MetaObject* superobject, const string& type);
00135 };
00136 
00137 #endif
00138 
00139 // end of hello.hh ]]>

Generated on Tue Aug 12 03:55:43 2003 for Interreality Project - VOS by doxygen 1.3.2