-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose interface callbacks as C# events in idiomatic wrappers (Managed-OSVR) #7
Comments
This is in progress. I will be implementing this issue at the same time, as they are related: |
Status update - I have an implementation for this here (work in progress - feedback welcome): I need to add samples for the state APIs and the interface adapter. Question/Discussion: However, I got the impression from the C++ state API wrapper issue that separate classes per report/state type was more desirable. If going in that direction, I would have removed the methods from Interface and made it the base class for the other interface types instead of a new InterfaceBase class (an earlier version of my code above went in this direction, until I noticed the TrackerCallback sample). |
This issue has been implemented. Closing. |
Moved from here:
OSVR/OSVR-Unity#17
This issue is specifically for Managed-OSVR interface wrappers:
Events in .net are the idiomatic way to implement the pattern we are using over the raw registerSubscriber* functions from the native code. The editor (at least in visual studio) has explicit support for creating callbacks of the right type for an event. For example, if you typed interface.PoseReported += then visual studio's intellisense would have an auto-complete option to create a callback that has the correct arguments for the type of event delegate that PoseReported is using. Very easy and convenient. It's also easy to unsubscribe - you just call interface.PoseReported -= game.PoseReportHandler.
We could go two ways in terms of defining the events. One way, we use custom event add/remove accessors, and call into the native callback registration code the first time someone subscribes to the event, i.e. on demand. Also, clean up any subscriptions when the last subscriber is removed. This requires a lot of bookkeeping and boilerplate code.
The second way is to use plain events (compiler generates accessors), and then have functions that 'activate' the callbacks. For example, you could subscribe to the PoseReported event, but the event wouldn't be fired until you called Start(), or maybe StartPoseReports(), along with a Stop()/StopPoseReports() method. The Start and Stop methods would handle calling into the native api to register a callback, or clean up the callback when Stop is called. Only one callback would be needed for each event (the event has its own invocation list, which also handles unsubscribe).
Custom event add/remove function reference:
https://msdn.microsoft.com/en-us/library/bb882534.aspx
The text was updated successfully, but these errors were encountered: