I’m making a new application which is full and full powered by plugins. After discussing with a few friends and developers, they suggested me to make the application in such a way that the plugins have restrictive access, so that users privacy and security can be ensured.
The application and plugins will be in Python. I decided to make the application using an API-kinda thing. That is, my application will be a separate object (Python object, based on Gtk.Application), there will be a bridge object and plugins.
Plugins --- Bridge --- Core
So whenever a plugin wants to do something, like say it wants to show a notification to user, it will make a request to Bridge. The Bridge will forward the request to Core. If the request is legible, then Core will reply that it has accepted and do the required action (like showing a notification), otherwise it will give a reject message and Bridge will tell this to the plugin.
As I said already, everything will be plugin based, so Core itself behaves like a plugin. If a plugin wants to communicate with other plugin, it will use the same mechanism. The request mechanism.
At programming level, this is how I have planned to implement, (rough sketch):
import gi, blah, blah # All import statements class MyPlugin(GObject.Object): def __init__(self, name, bridge): self.name = name self.bridge = bridge def send_notification_request(self): reply = self.bridge.request(id=123, from=self.name, from_obj=self, to="Core", message="notify-users", args=["Hello users this is from your MyPlugin...",]) if reply: print("Request Accepted") else: print("Request Rejected")
Now Bridge will take the request. First it will verify if the
from_obj is the same as the one mentioned in
from string. (This is done to prevent other plugins from cheating). Bridge has an internal dictionary, that maps the name of strings to the plugins with that name. Now, Bridge will hash
from_obj using Python’s hash function. Similarly it will obtain the hash of plugin pointed by the
from string from the dictionary, and check if the hashes are equal. Using this validation is done.
After validation, it will access the
to plugin and send the message by calling its
request method with all the arguments.
So this is how the application works. Whenever a plugin wants to communicate, it will use the bridge to send the request to another plugin. The request calls and communications will be pure Python function calls. Every plugin will have reference only to the bridge and no other plugin. This prevents any mishandling or misuse of plugins. The entire application life-cycle based on this working. How is it? What improvements do you want suggest? Please share your feedback.
Now comes the second part. As I said, the requests will be pure Python function calls, like
obj.call(msg), this Pythonic way could be slow, inefficient or even not so attractive. I had heard some fancy names like DBus, Sockets, Process, Threads etc. Should I use something like that instead? What is the proper and best way to handle the mechanism I described above? Please tell your comments on this too
Thank You for reading till here. I welcome all kinda feedback, and whenever you are suggesting a new “mechanism”, please explain it as much as you can, or point to a nice tutorial, it will really be helpful for me.