MAYBE_UNUSED const static char* PLUGIN_DEPENDENCY = "dependency";
MAYBE_UNUSED const static char* PLUGIN_USES = "uses";
MAYBE_UNUSED const static char* PLUGIN_DOCSECTION = "docsection";
+MAYBE_UNUSED const static char* PLUGIN_LICENSE = "license";
/*
* Hardcoded xml entities of dataModel.xml
return myFeaturesInFiles;
}
+const std::map<std::string, std::string>& Config_ModuleReader::proprietaryFeatures() const
+{
+ return myProprietaryFeatures;
+}
+
+const std::set<std::string>& Config_ModuleReader::proprietaryPlugins() const
+{
+ return myProprietaryPlugins;
+}
+
const std::set<std::string>& Config_ModuleReader::modulePluginFiles() const
{
return myPluginFiles;
void Config_ModuleReader::addFeature(const std::string& theFeatureName,
const std::string& thePluginConfig)
{
+ if (myProprietaryFeatures.count(theFeatureName)) {
+ myProprietaryFeatures.erase(theFeatureName);
+ }
+
if (myFeaturesInFiles.count(theFeatureName)) {
std::string anErrorMsg = "Can not register feature '%1' in plugin '%2'."
" There is a feature with the same ID.";
myFeaturesInFiles[theFeatureName] = thePluginConfig;
}
+void Config_ModuleReader::addFeatureRequireLicense(const std::string& theFeatureName,
+ const std::string& thePluginConfig)
+{
+ if (myFeaturesInFiles.count(theFeatureName) ||
+ myProprietaryFeatures.count(theFeatureName)) {
+ std::string anErrorMsg = "Can not register feature '%1' in plugin '%2'."
+ " There is a feature with the same ID.";
+ Events_InfoMessage("Config_ModuleReader", anErrorMsg)
+ .arg(theFeatureName).arg(thePluginConfig).send();
+ return;
+ }
+
+ myProprietaryFeatures[theFeatureName] = thePluginConfig;
+}
+
void Config_ModuleReader::processNode(xmlNodePtr theNode)
{
if (isNode(theNode, NODE_PLUGIN, NULL)) {
Events_Loop::loop()->send(aMess);
}
+ std::string aLicense = getProperty(theNode, PLUGIN_LICENSE);
+ std::transform(aLicense.begin(), aLicense.end(), aLicense.begin(), ::tolower);
+ bool isLicensed = aLicense == "true";
+ if (isLicensed)
+ myProprietaryPlugins.insert(aPluginName);
+
std::list<std::string> aFeatures = importPlugin(aPluginName, aPluginConf, aPluginDocSection);
std::list<std::string>::iterator it = aFeatures.begin();
for (; it != aFeatures.end(); it++) {
- addFeature(*it, aPluginConf);
+ if (isLicensed)
+ addFeatureRequireLicense(*it, aPluginConf);
+ else
+ addFeature(*it, aPluginConf);
}
}
}
/// Returns map that describes which file contains a feature
/// (the feature is key, the file is value)
CONFIG_EXPORT const std::map<std::string, std::string>& featuresInFiles() const;
+ /// Returns map containing features, which have licensed.
+ /// The valid license should be confirmed first
+ /// (the feature is key, the file is value)
+ CONFIG_EXPORT const std::map<std::string, std::string>& proprietaryFeatures() const;
+ /// Returns proprietary plugins
+ CONFIG_EXPORT const std::set<std::string>& proprietaryPlugins() const;
/// Returns list of module's xml files
CONFIG_EXPORT const std::set<std::string>& modulePluginFiles() const;
/// Returns module name: an xml attribute from the root of the plugins.xml:
/// Save feature in myFeaturesInFiles.
/// Generates an error if the feature name is already registered.
void addFeature(const std::string& theFeatureName, const std::string& thePluginConfig);
+ /// Save feature in myFeaturesRequireLicense.
+ /// Generates an error if the feature name is already registered.
+ void addFeatureRequireLicense(const std::string& theFeatureName,
+ const std::string& thePluginConfig);
private:
std::map<std::string, std::string> myFeaturesInFiles; ///< a feature name is key, a file is value
+ /// list of features, which need a license, and their config files
+ std::map<std::string, std::string> myProprietaryFeatures;
std::set<std::string> myPluginFiles; ///< a feature name is key, a file is value
/// a plugin name is key, a plugin type is value
static std::map<std::string, PluginType> myPluginTypes;
static std::set<std::string> myDependencyModules; ///< set of loaded modules
const char* myEventGenerated; ///< gives ability to send Feature_Messages to various listeners
+
+ std::set<std::string> myProprietaryPlugins; ///< list of plugins protected by license
};
#endif /* CONFIG_XMLMODULEREADER_H_ */
return ROOT_DOC->redoList();
}
+bool Model_Session::checkLicense(const std::string& thePluginName)
+{
+ return getPlugin(thePluginName);
+}
+
ModelAPI_Plugin* Model_Session::getPlugin(const std::string& thePluginName)
{
if (myPluginObjs.find(thePluginName) == myPluginObjs.end()) {
/// the plugin manager on call of the feature)
MODEL_EXPORT virtual void registerPlugin(ModelAPI_Plugin* thePlugin);
+ /// Verifies the license for the plugin is valid
+ MODEL_EXPORT virtual bool checkLicense(const std::string& thePluginName);
+
/// Processes the configuration file reading
MODEL_EXPORT virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
{
return myShapes;
}
+
+
+// ===== ModelAPI_FeaturesLicenseValidMessage =====
+ModelAPI_FeaturesLicenseValidMessage::ModelAPI_FeaturesLicenseValidMessage(
+ const Events_ID theID, const void* theSender)
+ : Events_Message(theID, theSender)
+{}
+
+ModelAPI_FeaturesLicenseValidMessage::~ModelAPI_FeaturesLicenseValidMessage()
+{}
+
+void ModelAPI_FeaturesLicenseValidMessage::setFeatures(const std::set<std::string>& theFeatures)
+{
+ myFeatures = theFeatures;
+}
+
+const std::set<std::string>& ModelAPI_FeaturesLicenseValidMessage::features() const
+{
+ return myFeatures;
+}
/// Event ID that requests updates visual attributes for presentations
MAYBE_UNUSED static const char * EVENT_VISUAL_ATTRIBUTES = "UpdateVisualAttributes";
-
/// Event ID that 1D-fillet failed (comes with ModelAPI_ShapesFailedMessage)
MAYBE_UNUSED static const char * EVENT_OPERATION_SHAPES_FAILED = "OperationShapesFailed";
+/// Event ID that license of specified features is checked and valid
+MAYBE_UNUSED static const char * EVENT_FEATURE_LICENSE_VALID = "FeaturesLicenseValid";
+
/// Message that feature was changed (used for Object Browser update): moved, updated and deleted
class MODELAPI_EXPORT ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup
{
std::list< std::shared_ptr<GeomAPI_Shape> > myShapes;
};
+/// Message that sends the features which license is checked and valid
+class ModelAPI_FeaturesLicenseValidMessage : public Events_Message
+{
+public:
+ /// Creates an message
+ MODELAPI_EXPORT
+ ModelAPI_FeaturesLicenseValidMessage(const Events_ID theID, const void* theSender = 0);
+ /// Default destructor
+ MODELAPI_EXPORT virtual ~ModelAPI_FeaturesLicenseValidMessage();
+ /// Static. Returns EventID of the message.
+ MODELAPI_EXPORT static Events_ID eventId()
+ {
+ return Events_Loop::eventByName(EVENT_FEATURE_LICENSE_VALID);
+ }
+
+ /// Sets list of features with valid license
+ MODELAPI_EXPORT void setFeatures(const std::set<std::string>& theFeatures);
+ /// Returns list of features with valid license
+ MODELAPI_EXPORT const std::set<std::string>& features() const;
+
+private:
+ std::set<std::string> myFeatures;
+};
+
#endif
/// the plugin manager on call of the feature)
virtual void registerPlugin(ModelAPI_Plugin* thePlugin) = 0;
+ /// Verifies the license for the plugin is valid
+ virtual bool checkLicense(const std::string& thePluginName) = 0;
+
/// Returns the root document of the application (that may contains sub-documents)
virtual std::shared_ptr<ModelAPI_Document> moduleDocument() = 0;
#include "ModuleBase_Dialog.h"
#include "ModuleBase_IErrorMgr.h"
+#include <Events_InfoMessage.h>
#include <Events_Loop.h>
#include <Events_Message.h>
Config_ModuleReader aXMLReader = Config_ModuleReader();
aXMLReader.readAll();
myFeaturesInFiles = aXMLReader.featuresInFiles();
+ myProprietaryFeatures = aXMLReader.proprietaryFeatures();
+ myProprietaryPlugins = aXMLReader.proprietaryPlugins();
+}
+
+void ModuleBase_IModule::processProprietaryFeatures()
+{
+ std::set<std::string>::iterator it = myFeaturesValidLicense.begin();
+ while (it != myFeaturesValidLicense.end()) {
+ std::map<std::string, std::string>::iterator aFound = myProprietaryFeatures.find(*it);
+ if (aFound == myProprietaryFeatures.end())
+ ++it;
+ else {
+ myFeaturesInFiles[aFound->first] = aFound->second;
+ myProprietaryFeatures.erase(aFound);
+ std::set<std::string>::iterator aRemoveIt = it++;
+ myFeaturesValidLicense.erase(aRemoveIt);
+ }
+ }
+}
+
+void ModuleBase_IModule::loadProprietaryPlugins()
+{
+ for (std::set<std::string>::const_iterator itP = myProprietaryPlugins.begin();
+ itP != myProprietaryPlugins.end(); ++itP) {
+ if (!ModelAPI_Session::get()->checkLicense(*itP))
+ Events_InfoMessage(*itP, "License of %1 plugin is not valid or not exist!").arg(*itP).send();
+ }
}
/// Returns new instance of operation object (used in createOperation for customization)
virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);
+ /// Load plugins required license
+ void loadProprietaryPlugins();
+
+ /// Collect features, which have valid license
+ void processProprietaryFeatures();
+
protected:
/// Reference to workshop
ModuleBase_IWorkshop* myWorkshop;
/// Map of features in XML
std::map<std::string, std::string> myFeaturesInFiles;
+ /// Map of features in XML, which require license but not confirmed yet
+ std::map<std::string, std::string> myProprietaryFeatures;
+ /// Proprietary plugins
+ std::set<std::string> myProprietaryPlugins;
+ /// Features, which have valid license
+ std::set<std::string> myFeaturesValidLicense;
std::map<ModuleBase_SelectionFilterType, Handle(SelectMgr_Filter)> mySelectionFilters;
Events_Loop* aLoop = Events_Loop::loop();
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_LICENSE_VALID));
registerSelectionFilter(SF_GlobalFilter, new PartSet_GlobalFilter(myWorkshop));
registerSelectionFilter(SF_FilterInfinite, new PartSet_FilterInfinite(myWorkshop));
ModuleBase_IModule::createFeatures();
myRoot = new PartSet_RootNode();
myRoot->setWorkshop(workshop());
+ ModuleBase_IModule::loadProprietaryPlugins();
}
mySketchMgr->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop);
}
}
+ else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_LICENSE_VALID)) {
+ std::shared_ptr<ModelAPI_FeaturesLicenseValidMessage> aMsg =
+ std::dynamic_pointer_cast<ModelAPI_FeaturesLicenseValidMessage>(theMessage);
+ myFeaturesValidLicense.insert(aMsg->features().begin(), aMsg->features().end());
+ processProprietaryFeatures();
+ }
}
//******************************************************