Config_WidgetAPI.cpp
Config_WidgetReader.cpp
Config_PointerMessage.cpp
+ Config_Common.cpp
)
SET(XML_RESOURCES
--- /dev/null
+/*
+ * Config_Common.cpp
+ *
+ * Created on: Apr 17, 2014
+ * Author: sbh
+ */
+
+#include "Config_Common.h"
+
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
+bool isElementNode(xmlNodePtr theNode)
+{
+ return theNode->type == XML_ELEMENT_NODE;
+}
+
+bool isNode(xmlNodePtr theNode, const char* theNodeName, ...)
+{
+ bool result = false;
+ const xmlChar* aName = theNode->name;
+ if (!aName || !isElementNode(theNode)) {
+ return false;
+ }
+ if (!xmlStrcmp(aName, (const xmlChar *) theNodeName)) {
+ return true;
+ }
+ va_list args; // define argument list variable
+ va_start(args, theNodeName); // init list; point to last defined argument
+ while(true) {
+ char *anArg = va_arg (args, char*); // get next argument
+ if (anArg == NULL)
+ break;
+ if (!xmlStrcmp(aName, (const xmlChar *) anArg)) {
+ va_end(args); // cleanup the system stack
+ return true;
+ }
+ }
+ va_end(args); // cleanup the system stack
+ return false;
+}
+
+bool hasChild(xmlNodePtr theNode)
+{
+ xmlNodePtr aNode = theNode->children;
+ for( ; aNode; aNode = aNode->next) {
+ if (isElementNode(theNode)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+std::string library(const std::string& theLibName)
+{
+ std::string aLibName = theLibName;
+#ifndef WIN32
+ static std::string aLibExt( ".so" );
+ if (aLibName.size() < 3 || aLibName.substr(0, 3) !="lib") {
+ aLibName = "lib" + aLibName;
+ }
+#else
+ static std::string aLibExt(".dll");
+#endif
+ std::string anExt = aLibName.substr(aLibName.size() - 4);
+ if (anExt != aLibExt)
+ aLibName += aLibExt;
+
+ return aLibName;
+}
* Author: sbh
*/
-#include <libxml/parser.h>
-#include <libxml/tree.h>
+#ifndef Config_Common_H_
+#define Config_Common_H_
+
+#include "Config.h"
+
+#include <string>
+#include <stdarg.h>
//>> Forward declaration of xmlNodePtr.
typedef struct _xmlNode xmlNode;
/*
* Returns true if theNode is XML ELEMENT node (not a "text" node ie).
*/
-static bool isElementNode(xmlNodePtr theNode)
-{
- return theNode->type == XML_ELEMENT_NODE;
-}
+CONFIG_EXPORT bool isElementNode(xmlNodePtr theNode);
/*
* Returns true if theNode is XML node with a given name.
* ", NULL" is required to use unlimited number of arguments.
* TODO(sbh): find a way to simplify calling this method.
*/
-static bool isNode(xmlNodePtr theNode, const char* theNodeName, ...)
-{
- bool result = false;
- const xmlChar* aName = theNode->name;
- if (!aName || !isElementNode(theNode)) {
- return false;
- }
- if (!xmlStrcmp(aName, (const xmlChar *) theNodeName)) {
- return true;
- }
- va_list args; // define argument list variable
- va_start(args, theNodeName); // init list; point to last defined argument
- while(true) {
- char *anArg = va_arg (args, char*); // get next argument
- if (anArg == NULL)
- break;
- if (!xmlStrcmp(aName, (const xmlChar *) anArg)) {
- va_end(args); // cleanup the system stack
- return true;
- }
- }
- va_end(args); // cleanup the system stack
- return false;
-}
-
+CONFIG_EXPORT bool isNode(xmlNodePtr theNode, const char* theNodeName, ...);
/*
* Every xml node has child. Even if there is no explicit
* This method checks if real child nodes exist in the
* given node.
*/
-static bool hasChild(xmlNodePtr theNode)
-{
- xmlNodePtr aNode = theNode->children;
- for(; aNode; aNode = aNode->next) {
- if (isElementNode(theNode)) {
- return true;
- }
- }
- return false;
-}
+CONFIG_EXPORT bool hasChild(xmlNodePtr theNode);
+
+/*!
+ \brief Convert the given parameter to the platform-specific library name.
+
+ The function appends platform-specific prefix (lib) and suffix (.dll/.so)
+ to the library file name.
+ For example, if \a str = "mylib", "libmylib.so" is returned for Linux and
+ mylib.dll for Windows.
+
+ \param str short library name
+ \return full library name
+ */
+CONFIG_EXPORT std::string library(const std::string& theLibName);
+
+#endif
#include <Config_Common.h>
#include <Config_ModuleReader.h>
#include <Config_FeatureReader.h>
+#include <Events_Error.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
-#ifdef _DEBUG
+//Necessary for cerr
#include <iostream>
-#endif
-
+#ifdef WIN32
+#include <windows.h>
+#else
+#include <dlfcn.h>
+#endif
Config_ModuleReader::Config_ModuleReader(const char* theEventGenerated)
- : Config_XMLReader("plugins.xml"),
- myEventGenerated(theEventGenerated)
+ : Config_XMLReader("plugins.xml"), myEventGenerated(theEventGenerated)
{
}
if (isNode(theNode, NODE_PLUGIN, NULL)) {
std::string aPluginConf = getProperty(theNode, PLUGIN_CONFIG);
std::string aPluginLibrary = getProperty(theNode, PLUGIN_LIBRARY);
- std::list<std::string> aFeatures = importPlugin(aPluginConf, aPluginLibrary);
+ std::list<std::string> aFeatures = importPlugin(aPluginLibrary, aPluginConf);
std::list<std::string>::iterator it = aFeatures.begin();
- for( ; it != aFeatures.end(); it++ ) {
+ for(; it != aFeatures.end(); it++) {
myFeaturesInFiles[*it] = aPluginConf;
}
}
return isNode(theNode, NODE_PLUGINS, NULL);
}
-std::list<std::string>
-Config_ModuleReader::importPlugin(const std::string& thePluginFile,
- const std::string& thePluginLibrary)
+std::list<std::string> Config_ModuleReader::importPlugin(const std::string& thePluginLibrary,
+ const std::string& thePluginFile)
{
- Config_FeatureReader aReader = Config_FeatureReader(thePluginFile,
- thePluginLibrary,
+ if (thePluginFile.empty()) { //probably a third party library
+ loadLibrary(thePluginLibrary);
+ return std::list<std::string>();
+ }
+
+ Config_FeatureReader aReader = Config_FeatureReader(thePluginFile, thePluginLibrary,
myEventGenerated);
aReader.readAll();
return aReader.features();
}
+void Config_ModuleReader::loadLibrary(const std::string theLibName)
+{
+#ifdef _DEBUG
+ std::cout << "Config_ModuleReader::loading library... " << theLibName.c_str() << std::endl;
+#endif
+ std::string aFileName = library(theLibName);
+ if (aFileName.empty())
+ return;
+
+#ifdef WIN32
+ HINSTANCE aModLib = ::LoadLibrary(aFileName.c_str());
+ if (!aModLib) {
+ std::string errorMsg = "Failed to load " + aFileName;
+ std::cerr << errorMsg << std::endl;
+ Events_Error::send(errorMsg);
+ }
+#else
+ void* aModLib = dlopen( aFileName.c_str(), RTLD_LAZY );
+ if ( !aModLib ) {
+ std::cerr << "Failed to load " << aFileName.c_str() << std::endl;
+ }
+#endif
+}
+
CONFIG_EXPORT std::string getModuleName();
+ /// loads the library with specific name, appends "lib*.dll" or "*.so" depending on the platform
+ CONFIG_EXPORT static void loadLibrary(const std::string theLibName);
+
protected:
void processNode(xmlNodePtr aNode);
bool processChildren(xmlNodePtr aNode);
- std::list<std::string> importPlugin(const std::string& thePluginFile,
- const std::string& thePluginLibrary);
+ std::list<std::string> importPlugin(const std::string& thePluginLibrary,
+ const std::string& thePluginFile);
+
private:
std::map<std::string, std::string> myFeaturesInFiles;
Model_AttributeRefList.cpp
Model_Events.cpp
)
+SET(PROJECT_LIBRARIES
+ ModelAPI
+ Events
+ Config
+ GeomData
+ ${CAS_OCAF}
+)
+
+
ADD_DEFINITIONS(-DMODEL_EXPORTS ${CAS_DEFINITIONS} ${BOOST_DEFINITIONS})
ADD_LIBRARY(Model SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
-TARGET_LINK_LIBRARIES(Model ${PROJECT_LIBRARIES} ${CAS_OCAF} ModelAPI Events Config GeomData)
+TARGET_LINK_LIBRARIES(Model ${PROJECT_LIBRARIES})
INCLUDE_DIRECTORIES(
../ModelAPI
myCurrentPluginName = myPlugins[theFeatureID];
if (myPluginObjs.find(myCurrentPluginName) == myPluginObjs.end()) {
// load plugin library if not yet done
- loadLibrary(myCurrentPluginName);
+ Config_ModuleReader::loadLibrary(myCurrentPluginName);
}
if (myPluginObjs.find(myCurrentPluginName) != myPluginObjs.end()) {
boost::shared_ptr<ModelAPI_Feature> aCreated =
ModelAPI_PluginManager.cpp
)
+SET(PROJECT_LIBRARIES
+ Config
+)
+
ADD_DEFINITIONS(-DMODELAPI_EXPORTS)
ADD_LIBRARY(ModelAPI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
SET_TARGET_PROPERTIES(ModelAPI PROPERTIES LINKER_LANGUAGE CXX)
-#TARGET_LINK_LIBRARIES(ModelAPI ${PROJECT_LIBRARIES})
+TARGET_LINK_LIBRARIES(ModelAPI ${PROJECT_LIBRARIES})
+
+INCLUDE_DIRECTORIES(
+ ../Config
+)
SET(CMAKE_SWIG_FLAGS "")
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeRefList.h>
+#include <Config_ModuleReader.h>
+
#ifdef WIN32
#include <windows.h>
#else
using namespace std;
-/// Converts library name to the operation system file name
-string library(const string& theLibName);
+#ifdef _DEBUG
+#include <iostream>
+#endif
/// Manager that will be initialized from Model package, one per application
boost::shared_ptr<ModelAPI_PluginManager> MY_MANAGER;
boost::shared_ptr<ModelAPI_PluginManager> ModelAPI_PluginManager::get()
{
if (!MY_MANAGER) { // import Model library that implements this interface of ModelAPI
- loadLibrary("Model");
+ #ifdef _DEBUG
+ std::cout << "ModelAPI_PluginManager::get: " << "Model library has not been loaded from xml." << std::endl;
+ #endif
+ Config_ModuleReader::loadLibrary("Model");
}
return MY_MANAGER;
}
-
-string library(const string& theLibName)
-{
- string aLibName = theLibName;
-
-#ifndef WIN32
- static string aLibExt( ".so" );
- if (aLibName.size() < 3 || aLibName.substr(0, 3) !="lib")
- aLibName = "lib" + aLibName;
-#else
- static string aLibExt( ".dll" );
-#endif
-
- string anExt = aLibName.substr(aLibName.size() - 4);
-
- if ( anExt != aLibExt)
- aLibName += aLibExt;
-
- return aLibName;
-}
-
-// for debug purpose only (cerr), before the error management system is implemented
-#include <iostream>
-void ModelAPI_PluginManager::loadLibrary(const string theLibName)
-{
- string aFileName = library(theLibName);
- if ( aFileName.empty() )
- {
- cerr<<"Library "<<theLibName.c_str()<<" can not be imported"<<endl;
- return;
- }
-
-#ifdef WIN32
- HINSTANCE aModLib = ::LoadLibrary( aFileName.c_str() );
- if (!aModLib)
- cerr<<"Failed to load "<<aFileName.c_str()<<endl;
-#else
- void* aModLib = dlopen( aFileName.c_str(), RTLD_LAZY );
- if ( !aModLib )
- cerr<<"Failed to load "<<aFileName.c_str()<<endl;
-#endif
-}
/// Defines the current document that used for current work in the application
virtual void setCurrentDocument(boost::shared_ptr<ModelAPI_Document> theDoc) = 0;
- /// loads the library with specific name, appends "lib*.dll" or "*.so" depending on the platform
- static void loadLibrary(const std::string theLibName);
-
/// Is needed for python wrapping by swig, call Get to get an instance
ModelAPI_PluginManager();
#include <QDir>
-//******************************************************************
-QString library(const QString& str)
-{
- QString path = dir(str, false);
- QString name = file(str, false);
- QString ext = extension(str);
-
-#ifndef WIN32
- if ( !name.startsWith( "lib" ) )
- name = QString( "lib" ) + name;
-#endif
-
-#ifdef WIN32
- QString libExt("dll");
-#else
- QString libExt( "so" );
-#endif
-
- if (ext.toLower() != QString("so") && ext.toLower() != QString("dll")) {
- if (!name.isEmpty() && !ext.isEmpty())
- name += QString(".");
- name += ext;
- }
-
- ext = libExt;
-
- QString fileName = addSlash(path) + name + QString(".") + ext;
-
- return fileName;
-}
-
//******************************************************************
QString dir(const QString& path, bool isAbs)
{
#include <QString>
#include <QRect>
-/*!
- \brief Convert the given parameter to the platform-specific library name.
-
- The function appends platform-specific prefix (lib) and suffix (.dll/.so)
- to the library file name.
- For example, if \a str = "mylib", "libmylib.so" is returned for Linux and
- mylib.dll for Windows.
-
- \param str short library name
- \return full library name
- */
-QString XGUI_EXPORT library(const QString& str);
-
/*!
\brief Return directory part of the file path.
#include <ModuleBase_Operation.h>
#include <ModuleBase_Operation.h>
#include <ModuleBase_OperationDescription.h>
+#include <Config_Common.h>
#include <Config_FeatureMessage.h>
#include <Config_PointerMessage.h>
//******************************************************
XGUI_Module* XGUI_Workshop::loadModule(const QString& theModule)
{
- QString libName = library(theModule);
+ QString libName =
+ QString::fromStdString(library(theModule.toStdString()));
if (libName.isEmpty()) {
qWarning(
qPrintable( tr( "Information about module \"%1\" doesn't exist." ).arg( theModule ) ));