Reputation: 11047
I have the following (simplified) architecture:
client(s) --> bouncer --> server
The clients send commands to the server. The 'bouncer' performs sanity and other checks on the commands issued by the client, and prevents faulty commands from reaching the server. For example, the bouncer may have the following code:
bool Bouncer::someCommand(const someCommandArg& arg) {
if (arg.x < 100) {
return false;
}
if (arg.y > 10) {
return false;
}
// more checks ...
return server->someCommand(arg);
}
The problem with this approach is that the bouncer conditions have to be hard-coded one by one, and is not flexible enough. I'm looking for a way to define these conditions in some configuration file, which the bouncer will load when created, and will loop through all the
conditions when someCommand
is called. Moreover, the test loop itself has to be fast.
Were it C#, I guess I would have used its compile-on-the-fly capabilities, and have my if
clauses written in plain code in the configuration file. What do you suggest for C++?
Upvotes: 1
Views: 108
Reputation: 106196
Choices include:
What's best depends a lot on the complexity of useful predicates, performance requirements, deployment practices etc..
Upvotes: 2
Reputation: 1234
You can use a plugin approach. Make the bouncer a plugin and then use a pipeline/chain-of-responsibility pattern to pass a command through multiple bouncers? Different bouncer plugins can check for different conditions and by chaining them, you define the final rule applied to the command. You can use a config file to specify what plugins should be loaded and how to setup the chain.
This still implies that the plugins have to be compiled before you can load them, but you can dynamically load them while your program is running if this is really a requirement. At least adding new plugins doesn't require your application to be recompiled.
Upvotes: 0