gmlTcl_Wrapper.h

00001 /*
00002  * gml/tcl/wrapper/wrapper/gmlTcl_Wrapper.h --
00003  *
00004  *    See "gmlTclWrapper.cc".
00005  *
00006  *  Copyright (c) 1996-2003 CLIPS-IMAG
00007  *
00008  *  See the file "gml_LicenseTerms.txt" for information on usage and redistribution
00009  *  of this file, and for a DISCLAIMER OF ALL WARRANTIES.
00010  *
00011  *  May 16, 2003 (FB)
00012  *    hide wrapper structures, internals.
00013  *
00014  *  September 8, 2002 (FB)
00015  *    re-written for gml.
00016  *
00017  *  Created on April 10, 1996 (FB).
00018  */
00019 #ifndef __GMLTCLWRAPPER__
00020 #define __GMLTCLWRAPPER__
00021   #if defined(__cplusplus)
00022     extern "C" {
00023   #endif
00024 
00025 #include "tcl.h"
00026 
00027 #include "gml/base/gml_Types.h"
00028 #include "gml/base/gml_Callback.h"
00029 
00030 #include "gml/tcl/wrapper/wrapper/gmlTcl_WrapperParser.h"
00031 
00032 
00033 
00034 /*
00035  * gmlTclWrapper constant and globals --
00036  */
00037 #define gmlTcl_kMaxCommandNameLength      1024
00038 
00039 #define gmlTcl_kClassMethodPrefix         "--"
00040 
00041 
00042 
00043 /*
00044  * gmlTcl_TWrapClass --
00045  * gmlTcl_TWrapObject --
00046  * gmlTcl_TWrapEvent --
00047  *
00048  *  Opaque types representing, repectively, a wrapper of a class, a wrapper of an object,
00049  *    and a wrapper of an event.
00050  */
00051 typedef void* gmlTcl_TWrapClass;
00052 typedef void* gmlTcl_TWrapObject;
00053 typedef void* gmlTcl_TWrapEvent;
00054 
00055 
00056 
00057 /*
00058  * gmlTcl_WrapObject_GetNative --
00059  * gmlTcl_WrapObject_SetNative --
00060  *
00061  *  Returns or set the native object of an object wrapper.
00062  */
00063 void* gmlTcl_WrapObject_GetNative (gmlTcl_TWrapObject wrapObj);
00064 void  gmlTcl_WrapObject_SetNative (gmlTcl_TWrapObject wrapObj, void* object);
00065 
00066 
00067 
00068 /*
00069  * gmlTcl_TWrapMethodProc --
00070  *
00071  *  Prototype of a function that wraps a "native" method call on an object.
00072  *    <interp>        is the interpreter in which the object exists.
00073  *    <obj>           is the object on which to call the method.
00074  *    <objc>, <objv>  contains the parameters of the call.
00075  *    <parsedParams>  points to the result of the parsing of the above parameters.
00076  */
00077 typedef int (gmlTcl_TWrapMethodProc) (Tcl_Interp*           interp,
00078                                       gmlTcl_TWrapObject    wrapObj,
00079                                       int                   objc,
00080                                       Tcl_Obj*CONST         objv[],
00081                                       void*                 parsedParams);
00082 
00083 
00084 
00085 /*
00086  * gmlTcl_TMethodDescr --
00087  *
00088  *  Informations for wrapping a method.
00089  *    <fName>           is the string name of the method (used in a Tcl command to call the method),
00090  *                        length must not be greater than <gmlTcl_kMaxCommandNameLength>.
00091  *    <fMethodProc>     is the method wrapper function.
00092  *    <fParamDescrs>    is an array, possibily empty (NULL), that tells which parameters are accepted
00093  *                        by this method and how to parse them (see "gml/tcl/wrapper/wrapper/gmlTcl_WrapperParser.h").
00094  *                        If <NULL>, no processing is done on the parameters, it is the responsability
00095  *                        of <fMethodProc> to parse them.
00096  *    <fResultSize>     is the size, in byte, of the structure that stores the values resulting from
00097  *                        the parsing of the parameters. Used only if <fParamDescrs> is not NULL.
00098  */
00099 typedef struct {
00100 
00101   char                      fName[gmlTcl_kMaxCommandNameLength+1];
00102   gmlTcl_TWrapMethodProc*   fMethodProc;
00103   gmlTcl_TParamDescr*       fParamDescrs;
00104   gml_TBlockSize            fResultSize;
00105   
00106 } gmlTcl_TMethodDescr;
00107 
00108 
00109 // Optional macro-constructors for gmlTcl_TMethodDescr's
00110 
00111 #define GMLTCL_DECLARE_METHOD(CLASS,METHOD)              
00112   {                                                      
00113     #METHOD, &gmlTcl_ ## CLASS ## _ ## METHOD,           
00114     gmlTcl_g ## CLASS ## _ ## METHOD ## _descr,          
00115     sizeof (gmlTcl_ ## CLASS ## _ ## METHOD ## _params)  
00116   }
00117 
00118 #define GMLTCL_END_METHOD_LIST 
00119   {"", (gmlTcl_TWrapMethodProc *) NULL, (gmlTcl_TParamDescr *) NULL, 0}
00120 
00121 
00122 /*
00123  * gmlTcl_WrapClass_New --
00124  *
00125  *  Create the wrapping for a class of object into a Tcl interpreter.
00126  *    <interp>          is the interpreter in which the class wrapper is created.
00127  *    <className>       is the string for the Tcl command that creates objects of this class,
00128  *                        length must not be greater than <gmlTcl_kMaxCommandNameLength>.
00129  *    <methodDescrs>    is the array of method-wrappers of this class.
00130  *                        The array must contain a "constructor" method to allow instanciation
00131  *                        of objects of this class. The "constructor" function wrapper must
00132  *                        allocate a native (C++) object and associate it with the object
00133  *                        wrapper with "gmlTcl_WrapObject_SetNative".
00134  *                        If there is no "constructor" method in the array, this is a
00135  *                        pure virtual class: no instance can be created, the class is only
00136  *                        used by inheritance.
00137  *                        If the array contains a "destructor" method, it is invoked when an
00138  *                        instance is deleted. The destructor has the responsability to delete
00139  *                        the native (C++) object.
00140  *
00141  *    <classWrap>       on return, is set to the class wrapper token.
00142  */
00143 int gmlTcl_WrapClass_New (Tcl_Interp*             interp,
00144                           char*                   className,
00145                           gmlTcl_TMethodDescr*    methodDescrs,
00146                           gmlTcl_TWrapClass*      classWrap);
00147 
00148 
00149 
00150 /*
00151  * gmlTcl_WrapClass_Delete --
00152  *
00153  *  Deletes a class wrapper from an interpreter.
00154  *    <classWrap>       class wrapper token, returned by <gmlTcl_WrapClass_New>.
00155  */
00156 void gmlTcl_WrapClass_Delete (gmlTcl_TWrapClass  classWrap);
00157 
00158 
00159 
00160 /*
00161  * gmlTcl_WrapClass_StrName --
00162  *
00163  *  Returns the string name of the wrapped class <wrapClass>.
00164  */
00165 char* gmlTcl_WrapClass_StrName (gmlTcl_TWrapObject wrapClass);
00166 
00167 
00168 
00169 /*
00170  * gmlTcl_WrapClass_Inherit --
00171  *
00172  *  Arrange for <specialized> to inherit from <super> methods.
00173  */
00174 int gmlTcl_WrapClass_Inherit (Tcl_Interp* interp, gmlTcl_TWrapClass specialized, gmlTcl_TWrapClass super);
00175 
00176 
00177 
00178 /*
00179  * gmlTcl_WrapClass_DeInherit --
00180  *
00181  *  Arrange for <specialized> to loose inheritance from <super>.
00182  */
00183 void gmlTcl_WrapClass_DeInherit (gmlTcl_TWrapClass specialized, gmlTcl_TWrapClass super);
00184 
00185 
00186 
00187 /*
00188  * gmlTcl_WrapClass_ObjectFromName --
00189  *
00190  *  Returns in <object> the object wrapper for the object named <objName> which class
00191  *    is <wrapClass> or one of its specializations.
00192  *  If there is no such object, TCL_ERROR is returned and an error message is left in
00193  *    <interp>.
00194  */
00195 int gmlTcl_WrapClass_ObjectFromName  (Tcl_Interp*           interp,
00196                                       gmlTcl_TWrapClass     wrapClass,
00197                                       char*                 objName,
00198                                       gmlTcl_TWrapObject*   object);
00199 
00200 
00201 
00202 /*
00203  * gmlTcl_WrapObject_NewWrapper --
00204  *
00205  *  Create an object wrapper for the low-level object <object> from the class <wrapClass>.
00206  *  The low-level object must be already constructed. Thus, the constructor is not called,
00207  *    and the destructor will not be called when the wrapper will be deleted (for example,
00208  *    when its associated tcl command is deleted). It is the responsability of the called
00209  *    to delete the low-level object.
00210  *
00211  *  If <ownerRef> is not NULL, it is a pointer to the owner's reference to the new object
00212  *    wrapper. It is stored so that, when the wrapper will be deleted, the reference will
00213  *    be set to NULL (so that the owner knows that the wrapper has been deleted).
00214  *
00215  *  If <owner> is not NULL, it is the wrapper of the object that owns the new object. When
00216  *    <owner> will be deleted, this new wrapper will be deleted also. When <owner> is not
00217  *    NULL, <ownerRef> is ignored.
00218  */
00219 int gmlTcl_WrapObject_NewWrapper (Tcl_Interp*           interp,
00220                                   gmlTcl_TWrapClass     wrapClass,
00221                                   char*                 objName,
00222                                   void*                 object,
00223                                   gmlTcl_TWrapObject*   ownerRef,
00224                                   gmlTcl_TWrapObject    owner);
00225 
00226 
00227 
00228 /*
00229  * gmlTcl_WrapObject_DeleteWrapper --
00230  */
00231 void gmlTcl_WrapObject_DeleteWrapper (gmlTcl_TWrapObject wrapObj);
00232 
00233 
00234 
00235 /*
00236  * gmlTcl_WrapObject_StrName --
00237  *
00238  *  Returns the string name of the wrapped object <wrapObj>.
00239  */
00240 char* gmlTcl_WrapObject_StrName (gmlTcl_TWrapObject wrapObj);
00241 
00242 
00243 
00244 /*
00245  * gmlTcl_WrapBinding_AddEvent --
00246  *
00247  *  Add a new event named <eventName> to the list of event that can be bound to
00248  *    the class <wrapClass> or to objects of the class <wrapClass> depending on
00249  *    <isAClassEvent>: if <isAClassEvent> is true this is a class event than can
00250  *    be bound to by calling the "--bind" class method, otherwise it is an object
00251  *    event that is bound to by calling the "bind" method on the object.
00252  *
00253  *  A handle to the event is returned in <wrapEvent>, it will be used to invoke
00254  *    the event with "gmlTcl_WrapperBinding_Invoke" or to remove the event.
00255  */
00256 int gmlTcl_WrapBinding_AddEvent  (Tcl_Interp*         interp,
00257                                   gmlTcl_TWrapClass   wrapClass,
00258                                   gml_TBoolean        isAClassEvent,
00259                                   char*               eventName,
00260                                   gmlTcl_TWrapEvent*  wrapEvent);
00261 
00262 
00263 
00264 /*
00265  * gmlTcl_WrapBinding_RemoveEvent --
00266  *
00267  *  Remove the event from the list.
00268  */
00269 void gmlTcl_WrapBinding_RemoveEvent (gmlTcl_TWrapEvent wrapEvent);
00270 
00271 
00272 
00273 /*
00274  * gmlTcl_WrapBinding_Invoke --
00275  *
00276  *  Evaluate every script bound to the event <wrapEvent>. If this event is an
00277  *    object event, then the object must be provided in <wrapObj>, otherwise
00278  *    <wrapObj> is ignored.
00279  *  If <async> is true, the callbacks will not be called immediately, they will be
00280  *    called when it is safe to do so (at the end of the evaluation of a Tcl command)
00281  *    using Tcl asynchronous mechanism (cf. "Tcl_AsyncCreate").
00282  *  The <objc> parameters stored in <objv> are added at the end of the scripts
00283  *    before evaluation.
00284  *
00285  *  If a callback script generate an error, it is removed from this list of bound scripts.
00286  *  Returns TCL_OK, or TCL_ERROR only in the case of a failed async invoke because their was
00287  *    no more memory to schedule the invoke.
00288  */
00289 int gmlTcl_WrapBinding_Invoke  (gmlTcl_TWrapEvent   wrapEvent,
00290                                 gmlTcl_TWrapObject  wrapObj,
00291                                 gml_TBoolean        async,
00292                                 int                 objc,
00293                                 Tcl_Obj*            objv[]);
00294 
00295 
00296 
00297 
00298   #if defined(__cplusplus)
00299     }
00300   #endif
00301 #endif
00302 
00303 
Generated on Tue Jun 12 14:03:27 2007 for gml by Doxygen 1.5.2.