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

exotkPlugin_Plugin.cxx

Go to the documentation of this file.
00001 
00002 //   exotkPlugin_Plugin.cxx
00004 //    Copyright (C) 2001  Stephane Routelous
00005 //
00006 //    This file is part of exoTK.
00007 //
00008 //    exoTK is free software; you can redistribute it and/or modify
00009 //    it under the terms of the GNU General Public License as published by
00010 //    the Free Software Foundation; either version 2 of the License, or
00011 //    (at your option) any later version.
00012 //
00013 //    exoTK is distributed in the hope that it will be useful,
00014 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 //    GNU General Public License for more details.
00017 //
00018 //    You should have received a copy of the GNU General Public License
00019 //    along with exoTK; if not, write to the Free Software
00020 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 
00029 #include <exotkPlugin_Plugin.hxx>
00030 #ifndef  _OSD_Function_HeaderFile
00031 #include <OSD_Function.hxx>
00032 #endif
00033 #ifndef  _OSD_Path_HeaderFile
00034 #include <OSD_Path.hxx>
00035 #endif
00036 #ifndef  _OSD_File_HeaderFile
00037 #include <OSD_File.hxx>
00038 #endif
00039 
00040 
00041 #ifndef _Standard_DefineHandle_HeaderFile
00042 #include <Standard_DefineHandle.hxx>
00043 #endif
00044 
00045 //
00046 IMPLEMENT_STANDARD_HANDLE(exotkPlugin_Plugin, MMgt_TShared)
00047 IMPLEMENT_STANDARD_RTTI(exotkPlugin_Plugin, MMgt_TShared)
00048 //
00049 // Foreach ancestors, we add a IMPLEMENT_STANDARD_SUPERTYPE and 
00050 // a IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY macro.
00051 // We must respect the order: from the direct ancestor class
00052 // to the base class.
00053 //
00054 
00055 IMPLEMENT_STANDARD_TYPE(exotkPlugin_Plugin)
00056 IMPLEMENT_STANDARD_SUPERTYPE(MMgt_TShared) 
00057 IMPLEMENT_STANDARD_SUPERTYPE(Standard_Transient)
00058 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY()
00059 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY(MMgt_TShared)
00060 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY(Standard_Transient)
00061 IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_END()
00062 IMPLEMENT_STANDARD_TYPE_END(exotkPlugin_Plugin)
00063 
00067 typedef void (*EXOTKID_FCT)(TCollection_AsciiString& anExotkID);
00068 
00069 
00070 //==================================================================================
00071 // Function name        : exotkPlugin_Plugin::exotkPlugin_Plugin
00072 //==================================================================================
00073 // Written by       : Stephane Routelous - 2001-12-29 00:46:44
00074 // Description      : 
00075 // Return type          : 
00076 //==================================================================================
00077 // Argument         : const TCollection_AsciiString& aFilename
00078 exotkPlugin_Plugin::exotkPlugin_Plugin(const TCollection_AsciiString& aFilename)
00079 {
00080         myFilename = aFilename;
00081         myLibraryIsOpened = Standard_False;
00082 }
00083 
00084 
00085 //==================================================================================
00086 // Function name        : exotkPlugin_Plugin::~exotkPlugin_Plugin
00087 //==================================================================================
00088 // Written by       : Stephane Routelous - 2001-12-29 00:46:46
00089 // Description      : 
00090 // Return type          : 
00091 //==================================================================================
00092 exotkPlugin_Plugin::~exotkPlugin_Plugin()
00093 {
00094 
00095 }
00096 
00097 //==================================================================================
00098 // Function name        : exotkPlugin_Plugin::Function
00099 //==================================================================================
00100 // Written by       : Stephane Routelous - 2001-12-29 00:46:49
00101 // Description      : 
00102 // Return type          : OSD_Function 
00103 //==================================================================================
00104 // Argument         : const TCollection_AsciiString& aFunctionName
00105 OSD_Function exotkPlugin_Plugin::Function(const TCollection_AsciiString& aFunctionName)
00106 {
00107         OSD_Function theFunction = NULL;
00108         if ( !aFunctionName.IsEmpty() && OpenLibrary())
00109         {
00110                 theFunction = myLibrary.DlSymb(aFunctionName.ToCString());
00111         }
00112         return theFunction;
00113 }
00114 
00115 
00116 //==================================================================================
00117 // Function name        : exotkPlugin_Plugin::IsValid
00118 //==================================================================================
00119 // Written by       : Stephane Routelous - 2001-12-29 00:46:50
00120 // Description      : 
00121 // Return type          : Standard_Boolean 
00122 //==================================================================================
00123 Standard_Boolean exotkPlugin_Plugin::IsValid()
00124 {
00125         Standard_Boolean theIsValid = Standard_False;
00126         if ( OpenLibrary() )
00127         {
00128                 OSD_Function thePluginIDFunction = Function("PluginID");
00129                 if ( thePluginIDFunction!=NULL )
00130                 {
00131                         OSD_Function theFunction = Function("exotkID");
00132                         if ( theFunction!=NULL )
00133                         {
00134                                 EXOTKID_FCT theExotkIDFunction = (EXOTKID_FCT)theFunction;
00135                                 if ( theExotkIDFunction != NULL )
00136                                 {
00137                                         TCollection_AsciiString theGoodID("174205A5-1BD6-4d16-AE6D-B7EAE5D5C8B5");
00138                                         TCollection_AsciiString theReadID;
00139                                         (theExotkIDFunction)(theReadID);
00140                                         theIsValid = ( theReadID==theGoodID);
00141                                 }
00142                         }
00143                 }
00144         }
00145         return theIsValid;
00146 }
00147 
00148 //==================================================================================
00149 // Function name        : exotkPlugin_Plugin::OpenLibrary
00150 //==================================================================================
00151 // Written by       : Stephane Routelous - 2001-12-29 00:46:55
00152 // Description      : 
00153 // Return type          : Standard_Boolean 
00154 //==================================================================================
00155 Standard_Boolean exotkPlugin_Plugin::OpenLibrary()
00156 {
00157         Standard_Boolean theOpenIsOK = Standard_False;
00158         if ( !myLibraryIsOpened )
00159         {
00160                 if ( !myFilename.IsEmpty() )
00161                 {
00162                         OSD_Path thePath(myFilename);
00163                         OSD_File theFile(thePath);
00164                         if ( theFile.Exists() )
00165                         {
00166                                 myLibrary.SetName(myFilename.ToCString());
00167                                 if( myLibrary.DlOpen(OSD_RTLD_NOW) )
00168                                 {
00169                                         myLibraryIsOpened = Standard_True;
00170                                         theOpenIsOK = Standard_True;
00171                                 }
00172                         }
00173                 }
00174         }
00175         else
00176         {
00177                 theOpenIsOK = Standard_True;
00178         }
00179 
00180         return theOpenIsOK;
00181 }
00182 

Generated on Wed Jan 23 12:16:43 2002 for exotk by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001