本文整理汇总了C++中DataItem::getConstrainedValues方法的典型用法代码示例。如果您正苦于以下问题:C++ DataItem::getConstrainedValues方法的具体用法?C++ DataItem::getConstrainedValues怎么用?C++ DataItem::getConstrainedValues使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataItem
的用法示例。
在下文中一共展示了DataItem::getConstrainedValues方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: disconnected
/* Add values for related data items UNAVAILABLE */
void Agent::disconnected (Adapter *anAdapter, vector<Device *> aDevices)
{
string time = getCurrentTime(GMT_UV_SEC);
sLogger << LDEBUG << "Disconnected from adapter, setting all values to UNAVAILABLE";
std::vector<Device *>::iterator iter;
for ( iter = aDevices.begin( ); iter != aDevices.end( ); ++iter )
{
std::map<std::string, DataItem *> dataItems = ( *iter )->getDeviceDataItems( );
std::map<std::string, DataItem *>::iterator dataItemAssoc;
for ( dataItemAssoc = dataItems.begin( ); dataItemAssoc != dataItems.end( ); ++dataItemAssoc )
{
DataItem *dataItem = ( *dataItemAssoc ).second;
if ( ( dataItem != NULL ) && ( ( dataItem->getDataSource( ) == anAdapter ) ||
( anAdapter->isAutoAvailable( ) &&
( dataItem->getDataSource( ) == NULL ) &&
( dataItem->getType( ) == "AVAILABILITY" ) ) ) )
{
const string *value = NULL;
if ( dataItem->isCondition( ) )
{
value = &sConditionUnavailable;
}
else if ( dataItem->hasConstraints( ) )
{
std::vector<std::string> & values = dataItem->getConstrainedValues( );
if ( values.size( ) > 1 )
{
value = &sUnavailable;
}
}
else
{
value = &sUnavailable;
}
if ( value != NULL )
{
addToBuffer(dataItem, *value, time);
}
}
else if ( dataItem == NULL )
{
sLogger << LWARN << "No data Item for " << ( *dataItemAssoc ).first;
}
}
}
}
示例2: runtime_error
//.........这里部分代码省略.........
string time = getCurrentTime(GMT_UV_SEC);
// Unique id number for agent instance
mInstanceId = getCurrentTimeInSec();
// Sequence number and sliding buffer for data
mSequence = 1;
mSlidingBufferSize = 1 << aBufferSize;
mSlidingBuffer = new sliding_buffer_kernel_1<ComponentEventPtr>();
mSlidingBuffer->set_size(aBufferSize);
mCheckpointFreq = aCheckpointFreq;
mCheckpointCount = (mSlidingBufferSize / aCheckpointFreq) + 1;
// Asset sliding buffer
mMaxAssets = aMaxAssets;
// Create the checkpoints at a regular frequency
mCheckpoints = new Checkpoint[mCheckpointCount];
// Mutex used for synchronized access to sliding buffer and sequence number
mSequenceLock = new dlib::mutex;
mAssetLock = new dlib::mutex;
// Add the devices to the device map and create availability and
// asset changed events if they don't exist
vector<Device *>::iterator device;
for (device = mDevices.begin(); device != mDevices.end(); ++device)
{
mDeviceMap[(*device)->getName()] = *device;
// Make sure we have two device level data items:
// 1. Availability
// 2. AssetChanged
if ((*device)->getAvailability() == NULL)
{
// Create availability data item and add it to the device.
std::map<string,string> attrs;
attrs["type"] = "AVAILABILITY";
attrs["id"] = (*device)->getId() + "_avail";
attrs["category"] = "EVENT";
DataItem *di = new DataItem(attrs);
di->setComponent(*(*device));
(*device)->addDataItem(*di);
(*device)->addDeviceDataItem(*di);
(*device)->mAvailabilityAdded = true;
}
if ((*device)->getAssetChanged() == NULL)
{
// Create availability data item and add it to the device.
std::map<string,string> attrs;
attrs["type"] = "ASSET_CHANGED";
attrs["id"] = (*device)->getId() + "_asset_chg";
attrs["category"] = "EVENT";
DataItem *di = new DataItem(attrs);
di->setComponent(*(*device));
(*device)->addDataItem(*di);
(*device)->addDeviceDataItem(*di);
}
}
// Reload the document for path resolution
mXmlParser->loadDocument(XmlPrinter::printProbe(mInstanceId, mSlidingBufferSize,
mMaxAssets,
mAssets.size(),
mSequence, mDevices));
/* Initialize the id mapping for the devices and set all data items to UNAVAILABLE */
for (device = mDevices.begin(); device != mDevices.end(); ++device)
{
const std::map<string, DataItem*> &items = (*device)->getDeviceDataItems();
std::map<string, DataItem *>::const_iterator item;
for (item = items.begin(); item != items.end(); ++item)
{
// Check for single valued constrained data items.
DataItem *d = item->second;
const string *value = &sUnavailable;
if (d->isCondition()) {
value = &sConditionUnavailable;
} else if (d->hasConstraints()) {
std::vector<std::string> &values = d->getConstrainedValues();
if (values.size() == 1)
value = &values[0];
}
addToBuffer(d, *value, time);
if (mDataItemMap.count(d->getId()) == 0)
mDataItemMap[d->getId()] = d;
else {
sLogger << LFATAL << "Duplicate DataItem id " << d->getId() <<
" for device: " << (*device)->getName() << " and data item name: " <<
d->getName();
exit(1);
}
}
}
}