Skip to content

Commit

Permalink
DeviceInstance classes to manage loaded devices.
Browse files Browse the repository at this point in the history
git-svn-id: https://valelab.ucsf.edu/svn/micromanager2/trunk@13408 d0ab736e-dc22-4aeb-8dc9-08def0aa14fd
  • Loading branch information
mark committed May 15, 2014
1 parent b82274f commit 6c714ed
Show file tree
Hide file tree
Showing 43 changed files with 2,400 additions and 507 deletions.
20 changes: 10 additions & 10 deletions MMCore/CoreCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,10 @@ int CoreCallback::SetSerialProperties(const char* portName,
*/
int CoreCallback::WriteToSerial(const MM::Device* caller, const char* portName, const unsigned char* buf, unsigned long length)
{
boost::shared_ptr<MM::Serial> pSerial;
boost::shared_ptr<SerialInstance> pSerial;
try
{
pSerial = core_->GetDeviceWithCheckedLabelAndType<MM::Serial>(portName);
pSerial = core_->GetDeviceWithCheckedLabelAndType<SerialInstance>(portName);
}
catch (CMMError& err)
{
Expand All @@ -414,7 +414,7 @@ int CoreCallback::WriteToSerial(const MM::Device* caller, const char* portName,
}

// don't allow self reference
if (pSerial.get() == caller)
if (pSerial->GetRawPtr() == caller)
return DEVICE_SELF_REFERENCE;

return pSerial->Write(buf, length);
Expand All @@ -425,10 +425,10 @@ int CoreCallback::WriteToSerial(const MM::Device* caller, const char* portName,
*/
int CoreCallback::ReadFromSerial(const MM::Device* caller, const char* portName, unsigned char* buf, unsigned long bufLength, unsigned long &bytesRead)
{
boost::shared_ptr<MM::Serial> pSerial;
boost::shared_ptr<SerialInstance> pSerial;
try
{
pSerial = core_->GetDeviceWithCheckedLabelAndType<MM::Serial>(portName);
pSerial = core_->GetDeviceWithCheckedLabelAndType<SerialInstance>(portName);
}
catch (CMMError& err)
{
Expand All @@ -440,7 +440,7 @@ int CoreCallback::ReadFromSerial(const MM::Device* caller, const char* portName,
}

// don't allow self reference
if (pSerial.get() == caller)
if (pSerial->GetRawPtr() == caller)
return DEVICE_SELF_REFERENCE;

return pSerial->Read(buf, bufLength, bytesRead);
Expand All @@ -451,10 +451,10 @@ int CoreCallback::ReadFromSerial(const MM::Device* caller, const char* portName,
*/
int CoreCallback::PurgeSerial(const MM::Device* caller, const char* portName)
{
boost::shared_ptr<MM::Serial> pSerial;
boost::shared_ptr<SerialInstance> pSerial;
try
{
pSerial = core_->GetDeviceWithCheckedLabelAndType<MM::Serial>(portName);
pSerial = core_->GetDeviceWithCheckedLabelAndType<SerialInstance>(portName);
}
catch (CMMError& err)
{
Expand All @@ -466,7 +466,7 @@ int CoreCallback::PurgeSerial(const MM::Device* caller, const char* portName)
}

// don't allow self reference
if (pSerial.get() == caller)
if (pSerial->GetRawPtr() == caller)
return DEVICE_SELF_REFERENCE;

return pSerial->Purge();
Expand Down Expand Up @@ -791,7 +791,7 @@ MMThreadLock* CoreCallback::getModuleLock(const MM::Device* caller)
{
try
{
boost::shared_ptr<MM::Device> pCaller = core_->pluginManager_.GetDevice(caller);
boost::shared_ptr<DeviceInstance> pCaller = core_->pluginManager_.GetDevice(caller);
return core_->pluginManager_.getModuleLock(pCaller);
}
catch (const CMMError&)
Expand Down
47 changes: 37 additions & 10 deletions MMCore/CoreCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#ifndef _CORECALLBACK_H_
#define _CORECALLBACK_H_

#include "Devices/DeviceInstances.h"
#include "IMMLogger.h"
#include "CoreUtils.h"
#include "MMCore.h"
Expand Down Expand Up @@ -82,7 +83,7 @@ class CoreCallback : public MM::Core

try
{
MM::Device* pDevice = core_->GetDeviceWithCheckedLabel(label).get();
MM::Device* pDevice = core_->GetDeviceWithCheckedLabel(label)->GetRawPtr();
if (pDevice == caller)
return 0;
return pDevice;
Expand All @@ -95,10 +96,10 @@ class CoreCallback : public MM::Core

MM::PortType GetSerialPortType(const char* portName) const
{
boost::shared_ptr<MM::Serial> pSerial;
boost::shared_ptr<SerialInstance> pSerial;
try
{
pSerial = core_->GetDeviceWithCheckedLabelAndType<MM::Serial>(portName);
pSerial = core_->GetDeviceWithCheckedLabelAndType<SerialInstance>(portName);
}
catch (...)
{
Expand Down Expand Up @@ -186,52 +187,75 @@ class CoreCallback : public MM::Core
// device management
MM::ImageProcessor* GetImageProcessor(const MM::Device* /* caller */)
{
return core_->imageProcessor_.get();
if (core_->imageProcessor_)
return core_->imageProcessor_->GetRawPtr();
return 0;
}

MM::State* GetStateDevice(const MM::Device* /* caller */, const char* deviceName)
{
boost::shared_ptr<StateInstance> device;
try {
return core_->GetDeviceWithCheckedLabelAndType<MM::State>(deviceName).get();
device = core_->GetDeviceWithCheckedLabelAndType<StateInstance>(deviceName);
} catch(...) {
//trap all exceptions
return 0;
}
if (device)
return device->GetRawPtr();
return 0;
}

MM::SignalIO* GetSignalIODevice(const MM::Device* /* caller */, const char* deviceName)
{
boost::shared_ptr<SignalIOInstance> device;
try {
return core_->GetDeviceWithCheckedLabelAndType<MM::SignalIO>(deviceName).get();
device = core_->GetDeviceWithCheckedLabelAndType<SignalIOInstance>(deviceName);
} catch(...) {
//trap all exceptions
return 0;
}
if (device)
return device->GetRawPtr();
return 0;
}

MM::AutoFocus* GetAutoFocus(const MM::Device* /* caller */)
{
return core_->autoFocus_.get();
if (core_->autoFocus_)
return core_->autoFocus_->GetRawPtr();
return 0;
}

MM::Hub* GetParentHub(const MM::Device* caller) const
{
if (caller == 0)
return 0;

return core_->pluginManager_.GetParentDevice(*caller).get();
boost::shared_ptr<HubInstance> hubDevice;
try
{
hubDevice = core_->pluginManager_.GetParentDevice(core_->pluginManager_.GetDevice(caller));
}
catch (const CMMError&)
{
return 0;
}
if (hubDevice)
return hubDevice->GetRawPtr();
return 0;
}

MM::Device* GetPeripheral(const MM::Device* caller, unsigned idx) const
{
std::vector<MM::Device*> peripherals;
char hubLabel[MM::MaxStrLength];
caller->GetLabel(hubLabel);
std::vector<std::string> peripheralLabels = core_->pluginManager_.GetLoadedPeripherals(hubLabel);
boost::shared_ptr<DeviceInstance> peripheral;
try
{
if (idx < peripheralLabels.size())
return core_->pluginManager_.GetDevice(peripheralLabels[idx]).get();
peripheral = core_->pluginManager_.GetDevice(peripheralLabels[idx]);
else
return 0;
}
Expand All @@ -241,6 +265,9 @@ class CoreCallback : public MM::Core
assert(false);
return 0;
}
if (peripheral)
return peripheral->GetRawPtr();
return 0;
}

unsigned GetNumberOfPeripherals(const MM::Device* caller)
Expand Down
28 changes: 28 additions & 0 deletions MMCore/CoreUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,34 @@ inline std::string ToString<const char*>(char const* const& d)
return d;
}

template <>
inline std::string ToString<const MM::DeviceType>(const MM::DeviceType& d)
{
// TODO Any good way to ensure this doesn't get out of sync with the enum
// definition?
switch (d)
{
case MM::UnknownType: return "Unknown";
case MM::AnyType: return "Any";
case MM::CameraDevice: return "Camera";
case MM::ShutterDevice: return "Shutter";
case MM::StateDevice: return "State";
case MM::StageDevice: return "Stage";
case MM::XYStageDevice: return "XYStageDevice";
case MM::SerialDevice: return "Serial";
case MM::GenericDevice: return "Generic";
case MM::AutoFocusDevice: return "Autofocus";
case MM::CoreDevice: return "Core";
case MM::ImageProcessorDevice: return "ImageProcessor";
case MM::SignalIODevice: return "SignalIO";
case MM::MagnifierDevice: return "Magnifier";
case MM::SLMDevice: return "SLM";
case MM::HubDevice: return "Hub";
case MM::GalvoDevice: return "Galvo";
}
return "Invalid";
}

template <typename T>
inline std::string ToQuotedString(const T& d)
{ return "\"" + ToString(d) + "\""; }
Expand Down
34 changes: 34 additions & 0 deletions MMCore/Devices/AutoFocusInstance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// PROJECT: Micro-Manager
// SUBSYSTEM: MMCore
//
// DESCRIPTION: Autofocus device instance wrapper
//
// COPYRIGHT: University of California, San Francisco, 2014,
// All Rights reserved
//
// LICENSE: This file is distributed under the "Lesser GPL" (LGPL) license.
// License text is included with the source distribution.
//
// This file is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES.
//
// AUTHOR: Mark Tsuchida

#include "AutoFocusInstance.h"


int AutoFocusInstance::SetContinuousFocusing(bool state) { return GetImpl()->SetContinuousFocusing(state); }
int AutoFocusInstance::GetContinuousFocusing(bool& state) { return GetImpl()->GetContinuousFocusing(state); }
bool AutoFocusInstance::IsContinuousFocusLocked() { return GetImpl()->IsContinuousFocusLocked(); }
int AutoFocusInstance::FullFocus() { return GetImpl()->FullFocus(); }
int AutoFocusInstance::IncrementalFocus() { return GetImpl()->IncrementalFocus(); }
int AutoFocusInstance::GetLastFocusScore(double& score) { return GetImpl()->GetLastFocusScore(score); }
int AutoFocusInstance::GetCurrentFocusScore(double& score) { return GetImpl()->GetCurrentFocusScore(score); }
int AutoFocusInstance::AutoSetParameters() { return GetImpl()->AutoSetParameters(); }
int AutoFocusInstance::GetOffset(double &offset) { return GetImpl()->GetOffset(offset); }
int AutoFocusInstance::SetOffset(double offset) { return GetImpl()->SetOffset(offset); }
47 changes: 47 additions & 0 deletions MMCore/Devices/AutoFocusInstance.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// PROJECT: Micro-Manager
// SUBSYSTEM: MMCore
//
// COPYRIGHT: University of California, San Francisco, 2014,
// All Rights reserved
//
// LICENSE: This file is distributed under the "Lesser GPL" (LGPL) license.
// License text is included with the source distribution.
//
// This file is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES.
//
// AUTHOR: Mark Tsuchida

#pragma once

#include "DeviceInstanceBase.h"


class AutoFocusInstance : public DeviceInstanceBase<MM::AutoFocus>
{
public:
AutoFocusInstance(CMMCore* core,
boost::shared_ptr<LoadedDeviceAdapter> adapter,
const std::string& name,
MM::Device* pDevice,
DeleteDeviceFunction deleteFunction,
const std::string& label) :
DeviceInstanceBase(core, adapter, name, pDevice, deleteFunction, label)
{}

int SetContinuousFocusing(bool state);
int GetContinuousFocusing(bool& state);
bool IsContinuousFocusLocked();
int FullFocus();
int IncrementalFocus();
int GetLastFocusScore(double& score);
int GetCurrentFocusScore(double& score);
int AutoSetParameters();
int GetOffset(double &offset);
int SetOffset(double offset);
};
60 changes: 60 additions & 0 deletions MMCore/Devices/CameraInstance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// PROJECT: Micro-Manager
// SUBSYSTEM: MMCore
//
// DESCRIPTION: Camera device instance wrapper
//
// COPYRIGHT: University of California, San Francisco, 2014,
// All Rights reserved
//
// LICENSE: This file is distributed under the "Lesser GPL" (LGPL) license.
// License text is included with the source distribution.
//
// This file is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES.
//
// AUTHOR: Mark Tsuchida

#include "CameraInstance.h"


int CameraInstance::SnapImage() { return GetImpl()->SnapImage(); }
const unsigned char* CameraInstance::GetImageBuffer() { return GetImpl()->GetImageBuffer(); }
const unsigned char* CameraInstance::GetImageBuffer(unsigned channelNr) { return GetImpl()->GetImageBuffer(channelNr); }
const unsigned int* CameraInstance::GetImageBufferAsRGB32() { return GetImpl()->GetImageBufferAsRGB32(); }
unsigned CameraInstance::GetNumberOfComponents() const { return GetImpl()->GetNumberOfComponents(); }
int CameraInstance::GetComponentName(unsigned component, char* name) { return GetImpl()->GetComponentName(component, name); }
int unsigned CameraInstance::GetNumberOfChannels() const { return GetImpl()->GetNumberOfChannels(); }
int CameraInstance::GetChannelName(unsigned channel, char* name) { return GetImpl()->GetChannelName(channel, name); }
long CameraInstance::GetImageBufferSize()const { return GetImpl()->GetImageBufferSize(); }
unsigned CameraInstance::GetImageWidth() const { return GetImpl()->GetImageWidth(); }
unsigned CameraInstance::GetImageHeight() const { return GetImpl()->GetImageHeight(); }
unsigned CameraInstance::GetImageBytesPerPixel() const { return GetImpl()->GetImageBytesPerPixel(); }
unsigned CameraInstance::GetBitDepth() const { return GetImpl()->GetBitDepth(); }
double CameraInstance::GetPixelSizeUm() const { return GetImpl()->GetPixelSizeUm(); }
int CameraInstance::GetBinning() const { return GetImpl()->GetBinning(); }
int CameraInstance::SetBinning(int binSize) { return GetImpl()->SetBinning(binSize); }
void CameraInstance::SetExposure(double exp_ms) { return GetImpl()->SetExposure(exp_ms); }
double CameraInstance::GetExposure() const { return GetImpl()->GetExposure(); }
int CameraInstance::SetROI(unsigned x, unsigned y, unsigned xSize, unsigned ySize) { return GetImpl()->SetROI(x, y, xSize, ySize); }
int CameraInstance::GetROI(unsigned& x, unsigned& y, unsigned& xSize, unsigned& ySize) { return GetImpl()->GetROI(x, y, xSize, ySize); }
int CameraInstance::ClearROI() { return GetImpl()->ClearROI(); }
int CameraInstance::StartSequenceAcquisition(long numImages, double interval_ms, bool stopOnOverflow) { return GetImpl()->StartSequenceAcquisition(numImages, interval_ms, stopOnOverflow); }
int CameraInstance::StartSequenceAcquisition(double interval_ms) { return GetImpl()->StartSequenceAcquisition(interval_ms); }
int CameraInstance::StopSequenceAcquisition() { return GetImpl()->StopSequenceAcquisition(); }
int CameraInstance::PrepareSequenceAcqusition() { return GetImpl()->PrepareSequenceAcqusition(); }
bool CameraInstance::IsCapturing() { return GetImpl()->IsCapturing(); }
void CameraInstance::GetTags(char* serializedMetadata) { return GetImpl()->GetTags(serializedMetadata); }
void CameraInstance::AddTag(const char* key, const char* deviceLabel, const char* value) { return GetImpl()->AddTag(key, deviceLabel, value); }
void CameraInstance::RemoveTag(const char* key) { return GetImpl()->RemoveTag(key); }
int CameraInstance::IsExposureSequenceable(bool& isSequenceable) const { return GetImpl()->IsExposureSequenceable(isSequenceable); }
int CameraInstance::GetExposureSequenceMaxLength(long& nrEvents) const { return GetImpl()->GetExposureSequenceMaxLength(nrEvents); }
int CameraInstance::StartExposureSequence() { return GetImpl()->StartExposureSequence(); }
int CameraInstance::StopExposureSequence() { return GetImpl()->StopExposureSequence(); }
int CameraInstance::ClearExposureSequence() { return GetImpl()->ClearExposureSequence(); }
int CameraInstance::AddToExposureSequence(double exposureTime_ms) { return GetImpl()->AddToExposureSequence(exposureTime_ms); }
int CameraInstance::SendExposureSequence() const { return GetImpl()->SendExposureSequence(); }
Loading

0 comments on commit 6c714ed

Please sign in to comment.