Using the template driver as example we need to do a couple of changes
In the main everything is fine, but for the driver I face the problem that I need to combine:
- CTrack::Subscriber : unmanaged baseclass that keeps subscriptions
- LMF::Tracker::Tracker : managed driver class from Leica's LMF SDK
.. and that seems to be a problem because:
- managed classes don't know multiple inheritance
- you cannot add an unmanaged class as member to a managed, all members of a managed class must be managed as well
- you cannot add a managed class as a member to an unmanaged.
Great!
But then, we don't need to inherit from CTrack::Subscriber, this is just a way to track and release subscriptions. We can track these subscriptions also by an external array.
Another question mark is if we can feed a managed class instance with one of its functions to Subscribe.
Answer is yes,...through lambda's.
Here is an example for Hardware detection
CLeicaLMFDriver ^ driver = gcnew CLeicaLMFDriver();
msclr::gcroot<CLeicaLMFDriver ^> driverHandle = driver;
std::vector<CTrack::Subscription> subscriptions;
...
subscriptions.emplace_back(std::move(TCPServer.GetMessageResponder()->Subscribe(
TAG_COMMAND_HARDWAREDETECT,
[&driverHandle](const CTrack::Message &message) -> CTrack::Reply
{
return driverHandle->HardwareDetect(message);
})));
Explanation:
- Creation of managed driver class
- Can't pass driver as capture, so we need a handle that we can pass
- Keep our subscription in a separate vector
- Subsribe with TCPServer.GetMessageResponder, we pass the handle to the driver (remember, we can't pass a managed class) which is used to call the HardwareDetect from the driver.