Skip to content
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

add callbacks for device (un)loading #163

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions MMCore/MMCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,11 @@ void CMMCore::loadDevice(const char* label, const char* moduleName, const char*

LOG_INFO(coreLogger_) << "Did load device " << deviceName <<
" from " << moduleName << "; label = " << label;

if (externalCallback_ != 0)
{
externalCallback_->onDeviceLoaded(label);
}
}

void CMMCore::assignDefaultRole(boost::shared_ptr<DeviceInstance> pDevice)
Expand Down Expand Up @@ -783,6 +788,11 @@ void CMMCore::unloadDevice(const char* label///< the name of the device to unloa
{
boost::shared_ptr<DeviceInstance> pDevice = deviceManager_->GetDevice(label);

if (externalCallback_ != 0)
{
externalCallback_->onDeviceWillBeUnloaded(label);
}

try {
mm::DeviceModuleLockGuard guard(pDevice);
LOG_DEBUG(coreLogger_) << "Will unload device " << label;
Expand Down Expand Up @@ -819,6 +829,10 @@ void CMMCore::unloadAllDevices() throw (CMMError)
}

LOG_DEBUG(coreLogger_) << "Will unload all devices";
if (externalCallback_ != 0)
{
externalCallback_->onAllDevicesWillBeUnloaded();
}
deviceManager_->UnloadAllDevices();
LOG_INFO(coreLogger_) << "Did unload all devices";

Expand Down
14 changes: 14 additions & 0 deletions MMCore/MMEventCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,18 @@ class MMEventCallback
std::cout << "onSLMExposureChanged()" << name << " " << newExposure << "\n";
}

virtual void onDeviceLoaded(const char* name)
{
std::cout << "onDeviceLoaded " << name;
}

virtual void onDeviceWillBeUnloaded(const char* name)
{
std::cout << "onDeviceWillBeUnloaded " << name;
}

virtual void onAllDevicesWillBeUnloaded()
{
std::cout << "onAllDevicesWillBeUnloaded ";
}
Comment on lines +102 to +105
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally I think this would be made irrelevant by the single device unloading signal. But that doesn't look like it's possible without pushing the external callback into the deviceManager which currently doesn't happen. Happy to do that, but figured Id start with the less invasive option.

};