For quite a while, I've been thinking about creating an Abiathar extension that functions as a client for a server-client level editing collaboration system. The whole system would be called AbiathRPC, a play on words involving "Abiathar" and "RPC" (Remote Procedure Call). I had some extra time today, and I had an idea I wanted to test.
A lot of Abiathar's functionality is accessed programmatically through the IAbiatharState interface. For AbiathRPC to intercept the various calls, it would need to replace some functions on that interface. I don't want to manually rewrite the full implementation, which might change from version to version. I decided to try the Emit features of the Reflection system, which allows for runtime code generation.
I threw together a class that takes an IAbiatharState and uses it to create an AbiathRPC state wrapper. It generates a new class implementing that interface and (using the list of "hooked" methods) figures out where to redirect calls. The body of each generated method is very short, just a load of a field that stores the real state wrapper, a push of each argument, and a call. It took a lot of fiddling, but eventually I got something that works for the methods I tried (one pass-through and one hooked) and doesn't blow up with InvalidProgramException.
Tomorrow I'll see about swapping out the real Abiathar state manager for this one to make sure that the pass-through doesn't break anything.
No comments:
Post a Comment