- Cap'n Hook - A Hook Manager for the CE
- 19 Feb 2020 11:39:49 am
- Last edited by commandblockguy on 05 Oct 2020 10:25:41 pm; edited 3 times in total
Hooks are a feature of TI-OS that allow apps and programs to run their own code whenever an event occurs in the OS - for example, using a token hook, you can change how tokens are displayed in TI-OS.
A major limitation of hooks is that only one program can install a hook of a particular type. If another program wants to use the same type of hook, it must either prevent the first hook from using it or implement chaining logic.
Cap'n Hook seeks to prevent this problem by providing a common interface for programs to register their hooks with. This has a number of advantages over the OS's interface:
Multiple programs can use the same type of hook.
Individual programs do not have to implement chaining logic.
If a hook is changed by a program that does not use Cap'n Hook, the next time a program that does use Cap'n Hook is run, the old hooks are restored.
In case two hooks conflict with each other (for example, two programs both want to open a menu when a certain key is pressed), the user can assign them a priority to change which one will run.
Cap'n Hook does not currently provide a mechanism for storing hooks persistently. Hooks should be stored somewhere that is unlikely to be overwritten - for example, in a deleted appvar, which will persist until the next garbage collect.
Here's the download for both the library and the dev headers, and here's the assembly source and test program.
===================================================================
Original Post: "Creating a Standardized Hook Manager for the CE"
Currently, very few projects on the CE use hooks, and I believe this is likely to avoid causing issues with other programs that use them. I think that it would be a good idea to create a library that would provide an interface for managing hooks, rather than having all programs handle installing hooks themselves.
Right now I have a decent idea of how this would work in my head, but that doesn't really count for anything, so I created a GitHub gist explaining the basic idea. I'm posting this to get feedback, at this point mostly for any glaring issues with the concept. If there aren't any, I can start working on more polished design documentation and then start actually implementing it.
I'm currently not addressing memory management issues, only chaining issues, though that might change in the future.
Anyways, here's the GitHub gist:
https://gist.github.com/commandblockguy/8eb7fcfca46df2967903c3eb2adeb9db
A major limitation of hooks is that only one program can install a hook of a particular type. If another program wants to use the same type of hook, it must either prevent the first hook from using it or implement chaining logic.
Cap'n Hook seeks to prevent this problem by providing a common interface for programs to register their hooks with. This has a number of advantages over the OS's interface:
Multiple programs can use the same type of hook.
Individual programs do not have to implement chaining logic.
If a hook is changed by a program that does not use Cap'n Hook, the next time a program that does use Cap'n Hook is run, the old hooks are restored.
In case two hooks conflict with each other (for example, two programs both want to open a menu when a certain key is pressed), the user can assign them a priority to change which one will run.
Cap'n Hook does not currently provide a mechanism for storing hooks persistently. Hooks should be stored somewhere that is unlikely to be overwritten - for example, in a deleted appvar, which will persist until the next garbage collect.
Here's the download for both the library and the dev headers, and here's the assembly source and test program.
===================================================================
Original Post: "Creating a Standardized Hook Manager for the CE"
Currently, very few projects on the CE use hooks, and I believe this is likely to avoid causing issues with other programs that use them. I think that it would be a good idea to create a library that would provide an interface for managing hooks, rather than having all programs handle installing hooks themselves.
Right now I have a decent idea of how this would work in my head, but that doesn't really count for anything, so I created a GitHub gist explaining the basic idea. I'm posting this to get feedback, at this point mostly for any glaring issues with the concept. If there aren't any, I can start working on more polished design documentation and then start actually implementing it.
I'm currently not addressing memory management issues, only chaining issues, though that might change in the future.
Anyways, here's the GitHub gist:
https://gist.github.com/commandblockguy/8eb7fcfca46df2967903c3eb2adeb9db