00001
00002
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
00050
00051
00052
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
00072
00073
00074
00075
00076
00077
00078 exotkPlugin_Plugin::exotkPlugin_Plugin(const TCollection_AsciiString& aFilename)
00079 {
00080 myFilename = aFilename;
00081 myLibraryIsOpened = Standard_False;
00082 }
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 exotkPlugin_Plugin::~exotkPlugin_Plugin()
00093 {
00094
00095 }
00096
00097
00098
00099
00100
00101
00102
00103
00104
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
00118
00119
00120
00121
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
00150
00151
00152
00153
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