plug-in style code

Hi my fellow experts, may be you guys could help me and feed a food for thought. I am designing a complex application that requires some thing to be executed on-the-fly like a plug-in.
The problem is the application should be highly configurable and the rule-based application is all driven by config file determining what and when to run. The plug-in list that need to run would be supplied in the config file like,

plugins=Rule1, Rule2, Rule5, Rule6

Reading the above text, only the rules Rule1, Rule2, Rule5 and Rule6 objects are picked up for the application process.
Keeping the rule in mind, "no change in the code" and highly configurable though a rule-based simple text (config) file, the rule classes/objects are to be picked up dynamically based on the list provided like above.

My design is to have a Register class which maintains a list of rules (objects) registered and executes for a particular model/process dynamically. Although my initial thought to define a Base class for the Rules class so that all the plug-in style rules would derive from and execute through the base class type pointer dynamically, am not having enough thought of how to read the constants from config file and invoke respective rule objects.

I also had a thought to design the Rule class to register with its object's address or a pointer to its function, and a function to invoke it as needed on-the-fly but the object requires to be instantiated dynamically someway, HOW???

The scenario of my initial thought of design is some thing like;

Config file (a plain text file):
rules=Rule2, Rule4, Rule7

The class Register would look like
class Register
   bool register(RuleBase *plugin_rule); // would be a list or vector of registered plug-ins
   bool registered(id); // checks if the rule is in registered list/vector
   invoke(string id); // invokes the rule.process() one after another all registered

The Register's invoke() would be called from main application during run-time to process only the registered (ie, listed in config file) rule (objects).

The rule of thumb is to not to change the code when the application is run for different models/departments. A simple change in the config file should fulfil the model's requirements.

Thought to implement the design pattern, Command (with Functor), but not sure how to read the text file and invoke the relevant on-the fly.

Any ideas or food for thought would be really appreciated.

PS: It is NOT in windows env.

Thanks a lot.
Last edited on
At a glance, your rules might go in shared libraries/DLLs. You may have multiple rules in a library, so they'd all need a unique ID. All the rules should be derived from a common Rule base class, that has virtual functions that define the protocol, with each rule implementing it's own version. You'd need some means of mapping text rule names (that you use in a config file) to object names (that exist as code somewhere).

All this sounds very much like COM/CORBA/... But it's easy enough to code yourself.
I forgot to mention that the library (or Rulex class) would be supplied as a file that to be linked as a plug-n-play kind. The plugged-in (dynamically read) file would have a class definition whose name is not known to the Application.
Sounds too much dynamics involved, but that is what the current direction is.

As I initially that the plugged-in library (ie. class definition) would register its identity and invoker function's address, which in turn would be stored in a vector-like registrations list. And the application would instantiate the Register class and inovoke the registered plug-ins one after another. Some thing like that.

Although I am trying to change the direction and propose alternatives, what would be the best solution for this if this turned to be the final design/requirement.
Topic archived. No new replies allowed.