Skip to content

Commit

Permalink
Added functions to the Core that can read properties and presets from…
Browse files Browse the repository at this point in the history
… cache

git-svn-id: https://valelab.ucsf.edu/svn/micromanager2/trunk@9688 d0ab736e-dc22-4aeb-8dc9-08def0aa14fd
  • Loading branch information
nico committed Jul 29, 2012
1 parent 87b907a commit 7fb41b2
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 7 deletions.
7 changes: 4 additions & 3 deletions MMCore/ErrorCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
#define MMERR_CircularBufferIncompatibleImage 45
#define MMERR_NotAllowedDuringSequenceAcquisition 46
#define MMERR_OutOfMemory 47
#define MMERR_InvalidImageSequence 48
#define MMERR_NullPointerException 49
#define MMERR_CreatePeripheralFailed 50
#define MMERR_InvalidImageSequence 48
#define MMERR_NullPointerException 49
#define MMERR_CreatePeripheralFailed 50
#define MMERR_PropertyNotInCache 51
#endif //_ERRORCODES_H_
100 changes: 96 additions & 4 deletions MMCore/MMCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,28 @@ Configuration CMMCore::getConfigState(const char* group, const char* config) con


/**
* Returns the parital state of the system, only for the devices included in the
* Returns the partial state of the system, only for the devices included in the
* specified group. It will create a union of all devices referenced in a group.
*/
Configuration CMMCore::getConfigGroupState(const char* group) const throw (CMMError)
{
return getConfigGroupState(group, false);
}

/**
* Returns the partial state of the system cache, only for the devices included in the
* specified group. It will create a union of all devices referenced in a group.
*/
Configuration CMMCore::getConfigGroupStateFromCache(const char* group) const throw (CMMError)
{
return getConfigGroupState(group, true);
}

/**
* Returns the partial state of the system, only for the devices included in the
* specified group. It will create a union of all devices referenced in a group.
*/
Configuration CMMCore::getConfigGroupState(const char* group, bool fromCache) const throw (CMMError)
{

vector<string> configs = configGroups_->GetAvailableConfigs(group);
Expand All @@ -537,7 +555,11 @@ Configuration CMMCore::getConfigGroupState(const char* group) const throw (CMMEr
PropertySetting cs = cfgData.getSetting(i); // config setting
if (!state.isPropertyIncluded(cs.getDeviceLabel().c_str(), cs.getPropertyName().c_str()))
{
string value = getProperty(cs.getDeviceLabel().c_str(), cs.getPropertyName().c_str());
string value = "";
if (fromCache)
value = getPropertyFromCache(cs.getDeviceLabel().c_str(), cs.getPropertyName().c_str());
else
value = getProperty(cs.getDeviceLabel().c_str(), cs.getPropertyName().c_str());
PropertySetting ss(cs.getDeviceLabel().c_str(), cs.getPropertyName().c_str(), value.c_str()); // state setting
state.addSetting(ss);
}
Expand Down Expand Up @@ -2991,6 +3013,43 @@ string CMMCore::getProperty(const char* label, const char* propName) const throw

return string(value);
}

/**
* Returns the cached property value for the specified device.
* @return string property value
* @param const char* label device label
* @param const char* propName property name
*/
string CMMCore::getPropertyFromCache(const char* label, const char* propName) const throw (CMMError)
{

if (label == NULL || propName == NULL)
throw CMMError(MMERR_NullPointerException);

// in case we requested Core device
if (strcmp(label, MM::g_Keyword_CoreDevice) == 0)
{
return properties_->Get(propName);
}


if (!stateCache_.isPropertyIncluded(label, propName))
throw CMMError(label, "Property not found in the cache", MMERR_PropertyNotInCache);

PropertySetting s = stateCache_.getSetting(label, propName);

return s.getPropertyValue();
}

/**
* Changes the value of the device property.
*
* @return void
* @param const char* label device label
* @param const char* propName property name
* @param const char* propValue the new property value
*/
/**
* Changes the value of the device property.
*
Expand Down Expand Up @@ -4292,7 +4351,7 @@ vector<string> CMMCore::getAvailablePixelSizeConfigs() const

/**
* Returns the current configuration for a given group.
* An empty string as a valid return value, since the system state will not
* An empty string is a valid return value, since the system state will not
* always correspond to any of the defined configurations.
* Also, in general it is possible that the system state fits multiple configurations.
* This method will return only the first matching configuration, if any.
Expand All @@ -4311,7 +4370,40 @@ string CMMCore::getCurrentConfig(const char* groupName) const throw (CMMError)
if (cfgs.empty())
return empty;

Configuration curState = getConfigGroupState(groupName);
Configuration curState = getConfigGroupState(groupName, false);

for (size_t i=0; i<cfgs.size(); i++)
{
Configuration* pCfg = configGroups_->Find(groupName, cfgs[i].c_str());
if (pCfg && curState.isConfigurationIncluded(*pCfg))
return cfgs[i];
}

// no match
return empty;
}

/**
* Returns the configuration for a given group based on the data in the cache.
* An empty string is a valid return value, since the system state will not
* always correspond to any of the defined configurations.
* Also, in general it is possible that the system state fits multiple configurations.
* This method will return only the first matching configuration, if any.
*
* @return string configuration name
*/
string CMMCore::getCurrentConfigFromCache(const char* groupName) const throw (CMMError)
{

string empty("");
if (groupName == NULL)
throw CMMError(MMERR_NullPointerException);

vector<string> cfgs = configGroups_->GetAvailableConfigs(groupName);
if (cfgs.empty())
return empty;

Configuration curState = getConfigGroupState(groupName, true);

for (size_t i=0; i<cfgs.size(); i++)
{
Expand Down
4 changes: 4 additions & 0 deletions MMCore/MMCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class CMMCore
void setSystemState(const Configuration& conf);
Configuration getConfigState(const char* group, const char* config) const throw (CMMError);
Configuration getConfigGroupState(const char* group) const throw (CMMError);
Configuration getConfigGroupStateFromCache(const char* group) const throw (CMMError);
void saveSystemState(const char* fileName) throw (CMMError);
void loadSystemState(const char* fileName) throw (CMMError);
void saveSystemConfiguration(const char* fileName) throw (CMMError);
Expand All @@ -158,6 +159,7 @@ class CMMCore
std::vector<std::string> getLoadedDevicesOfType(MM::DeviceType devType) const;
std::vector<std::string> getDevicePropertyNames(const char* label) const throw (CMMError);
std::string getProperty(const char* label, const char* propName) const throw (CMMError);
std::string getPropertyFromCache(const char* label, const char* propName) const throw (CMMError);
void setProperty(const char* label, const char* propName, const char* propValue) throw (CMMError);

void setProperty(const char* label, const char* propName, const bool propValue) throw (CMMError);
Expand Down Expand Up @@ -246,6 +248,7 @@ class CMMCore
std::vector<std::string> getAvailableConfigGroups() const;
std::vector<std::string> getAvailableConfigs(const char* configGroup) const;
std::string getCurrentConfig(const char* groupName) const throw (CMMError);
std::string getCurrentConfigFromCache(const char* groupName) const throw (CMMError);
Configuration getConfigData(const char* configGroup, const char* configName) const throw (CMMError);
std::string getCurrentPixelSizeConfig() const throw (CMMError);
std::string getCurrentPixelSizeConfig(bool cached) const throw (CMMError);
Expand Down Expand Up @@ -561,6 +564,7 @@ class CMMCore
int applyProperties(std::vector<PropertySetting>& props, std::string& lastError);
MM::Device* getDevice(const char* label) const throw (CMMError);
void waitForDevice(MM::Device* pDev) throw (CMMError);
Configuration getConfigGroupState(const char* group, bool fromCache = false) const throw (CMMError);
std::string getDeviceErrorText(int deviceCode, MM::Device* pDevice) const;
std::string getDeviceName(MM::Device* pDev);
void logError(const char* device, const char* msg, const char* file=0, int line=0) const;
Expand Down

0 comments on commit 7fb41b2

Please sign in to comment.