Closed bernardoaraujor closed 4 years ago
@vlad-ns FYI
@djordjeglbvc you said:
Instead, we are passing callbacks around, which is very bad practice.
but then you go on to propose:
int pip_plugin_init(pip_plugin_t *plugin, pip_plugin_initializer_t initializer);
which is still receiving a callback.
I admit I don't know what's the best way to design this solution. My approach on https://github.com/iotaledger/access/commit/b27ec7cb020e78c12cba61fb7087a969163d4ae5 for sure was not the best.
But I want us to be very careful in regards to the place where the developer choice of which plugin implementations are used is made.
This choice must not be hardcoded into access.c
, because that kills the modular approach. We have been repeating this mistake many times. Access Actor must know nothing about hardware protocols or IOTA wallet.
Meanwhile, pep_register_callback()
and pip_register_callback()
must be called inside access.c
, because doing it anywhere else would characterize Access Core API leak.
For reference, check https://github.com/iotaledger/access/commit/f0340546f86440c71571d26b6b82c8b388784bf4, where I move pep_register_callback()
into the scope of access_init()
.
@djordjeglbvc you said:
Instead, we are passing callbacks around, which is very bad practice.
but then you go on to propose:
int pip_plugin_init(pip_plugin_t *plugin, pip_plugin_initializer_t initializer);
which is still receiving a callback.
It's not a callback as such, it gets called once during a run-time, and it doesn't get passed around, no api leaking here.
pip_plugin_init
should probably be named something like pip_plugin_register
, as it is it's purpose.
Different approach (not so different really) would be to call initializer function on its own, it fills plugin structure with callbacks, and then we pass it to pip_plugin_register
. That adds additional step in plugin usage, but doesn't make things cleaner (doesn't make things less clean, either).
I admit I don't know what's the best way to design this solution. My approach on b27ec7c for sure was not the best.
But I want us to be very careful in regards to the place where the developer choice of which plugin implementations are used is made. This choice must not be hardcoded into
access.c
, because that kills the modular approach. We have been repeating this mistake many times. Access Actor must know nothing about hardware protocols or IOTA wallet.Meanwhile,
pep_register_callback()
andpip_register_callback()
must be called insideaccess.c
, because doing it anywhere else would characterize Access Core API leak. For reference, check f034054, where I movepep_register_callback()
into the scope ofaccess_init()
.
We could make pep_plugin_t
structure here similarly to what I've proposed for pip plugins, then user creates initializer for plugin and passes it through access api without revealing pep api. We would add new function to access api (edit: to register pep plugin), as we would anyway because user needs to at least choose which plugins to use through access api.
Callbacks shouldn't use pep calls, or any other api (access or modules within it) calls in general - this is what we solve with callbacks. We can define which data (and how) gets passed between plugin and module by extending pep_plugin_t
structure.
@bernardoaraujor I'm going through b27ec7cb020e78c12cba61fb7087a969163d4ae5 and there is a comment
// ToDo: how to properly determine the value of actuator index????
Why don't we leave it to the resolver plugin to determine the value of actuator index based on action? We would have one callback which handles one or more actuator actions. We can also add more callbacks, which would then process different groups of actuators. (Having callback per actuator might not be such a good idea in the long run, but multiple callbacks definitely - for different groups of actuators.)
Resolver plugin, sensors and actuators definitions are implemented like a group, or a package, and as I understand only they should be aware of sensors and actuators semantics.
I most likely didn't go through everything thoroughly, so I've probably missed something.
Sorry for jumping from one thing from another, just to share my thoughts on this. There are two good options if using static arrays, really:
I'm in favor of passing array length as a parameter, as we need to keep it anyway while adding callbacks to arrays, but it's just a preference. If we plan to use dynamic registration of callbacks in future (which is not a bad idea), we could move to using linked lists, or just mimic lists logic with arrays (I like to stay away from using dynamic lists on small bare metal embedded systems, as I do with any dynamic allocation). But some callback management would need to be done either way.
Continuing from previous comment, maybe turn this:
access_init(&access_context, device_wallet, plugin_initializers);
into this
access_init(&access_context, device_wallet);
access_register_resolver_plugin(demorelayplugin_initializer);
access_register_resolver_plugin(demowalletplugin_initializer);
access_register_pep_plugin(pep_initializer);
or
access_init(&access_context, device_wallet);
access_register_resolver_plugins(plugin_initializers, plugin_initializers_len);
access_register_pep_plugins(pep_initializers, pep_len);
something like that... I've added pep_initializer
just for illustration.
@djordjeglbvc I haven't read all your comments in detail yet, but first thing I notice is that you didn't understand one point.
resolver
has been renamed to pep_plugin
, so it doesn't make sense to have access_register_resolver_plugin
and access_register_pep_plugin
as separate things.
check https://github.com/iotaledger/access/pull/107/commits/92335c2e00bc34cf72e7f4e0684a61369e8d045c
@bernardoaraujor you are right, I was quick browsing through code, sorry. I wanted to illustrate use case if we would have more than one plugin system to register plugins to from access API. Also I think it is better to have separate api for plugin registering, instead of passing them to access init function.
another remark is that access_init(&access_context, device_wallet);
is not ideal. we do not want wallet references inside Access Actor.
that was the purpose of https://github.com/iotaledger/access/pull/107/commits/011c581624c5aa28d8e301fb83d51c64b3f4a4fc.
please, let's keep wallet representation only inside pep_plugin_wallet.{c,h}
and pip_plugin_wallet.{c,h}
@strahinjagolic + @vlad-ns I'm marking as solved the subtasks that are being handled on #113, as well as the one solved by #114
@bernardoaraujor
rename resolver to pep_plugin: follow 92335c2 rename storage to pap_plugin: follow c35a1f4
These two are not covered by #113 I will handle them.
@bernardoaraujor
rename resolver to pep_plugin: follow 92335c2 rename storage to pap_plugin: follow c35a1f4
These two are not covered by #113 I will handle them.
Maybe better to create new issue just for renaming. I think it is better to have more small tasks when possible, makes progress tracking easier.
done, check #115
@bernardoaraujor Regarding bullet point 2 (register PEP callback on access_init), I've added access apis for registering pap, pep and pip plugins, and they are all registered in app supervisor (check 8f71fcb5ffd24b2f828f2225b5dde97ee4263c44). This made more sense to me, as it is left to SDK user's decision to choose and/or implement plugins for each access subsystem. If this is ok with you, point 2 can be marked as finished.
that's ok @djordjeglbvc
Summary Follow https://github.com/iotaledger/access/pull/107 and finish the work
Details
[x] rename resolver demos: follow https://github.com/iotaledger/access/pull/107/commits/65b075e2d1c454d67f5c434f3bd00168746f826d
[x] register PEP callback on access_init: follow https://github.com/iotaledger/access/pull/107/commits/f0340546f86440c71571d26b6b82c8b388784bf4 (will be handled as part of #113)
[x] multiple resolver callbacks: follow https://github.com/iotaledger/access/pull/107/commits/b27ec7cb020e78c12cba61fb7087a969163d4ae5 (note 1: this is likely where some nasty bugs are being introduced with that ugly for loop on
access.c
and unchecked empty callback slots) (note 2: don't dopep_actuators_e
onpep.h
,pep_plugin.h
is more appropriate for thisenum
, and use it instead of my uglyint actuator
aspep_register_callback()
arg). (Will be handled in #113)[x] discuss the guidelines proposed by @djordjeglbvc on the quote below regardinig plugin architecture.
[x] init wallet on wallet plugin: follow https://github.com/iotaledger/access/pull/107/commits/011c581624c5aa28d8e301fb83d51c64b3f4a4fc + https://github.com/iotaledger/access/pull/107/commits/10440c342a785e9a1a78258538e89f2dd29dde71 (note:
device_wallet
is created and destroyed in the context where it's used, and wallet define statements are moved into wallet.h (avoiding spaghetti))[ ] add pip_plugins: follow https://github.com/iotaledger/access/pull/107/commits/e940710158d7fd85e7769f580b75c8b4b6ad161c + https://github.com/iotaledger/access/pull/107/commits/68ee4f9e70eb09f93adf11e71c01f989090751e6 (note: please move
pip_authorities_e
topip_plugin.h
)[ ] relay plugin: follow https://github.com/iotaledger/access/pull/107/commits/babd9975a922bf61e95dfbe574a4d6fdedffcacd + https://github.com/iotaledger/access/pull/107/commits/789fe3bc7faefcb47d50a8d1a1d16149f04933bf
Requirements
access
directory). This API must be agnostic and modular, containing only PxP core functionality. All protocol and wallet references must reside in the plugin context. That was the main purpose of https://github.com/iotaledger/access/pull/107plugins
directory must follow this organization for the PxP plugins: https://rentry.co/ehetqpep_register_callback()
andpip_register_callback()
insideaccess.c
and not insidemain.c
. Otherwise the Access Core API is leaking out of the scope of Access Actor.main.c
,pep_plugin.h
orpip_plugin.h
, but not onaccess.{c,h}
,pep.{c,h}
orpip.{c,h}
.Links / references