void CdipPublicationManager::extractStringsFromCompoundString(CharString &compoundString, std::vector<std::string> & strings){
	unsigned int startOfStringInd = 0;
	unsigned int endOfStringInd = 0;
	std::string localCopy = (const char *)compoundString;
	
	char delimiter;

	//Check which delimiter is used, well at least present in the strin provided, then run the string processing.
	if (-1 != compoundString.indexOf(CdipClientManager::pubNameDelimiter[0])) {
		//Use delimiter 0
		delimiter = CdipClientManager::pubNameDelimiter[0][0];
	} else if (-1 != compoundString.indexOf(CdipClientManager::pubNameDelimiter[1])){
		//Use delimiter 1
		delimiter = CdipClientManager::pubNameDelimiter[1][0];
	} else if (-1 != compoundString.indexOf(CdipClientManager::pubNameDelimiter[0])
		 && -1 != compoundString.indexOf(CdipClientManager::pubNameDelimiter[1])
		){
		//Both delimiters present, this is a problem to report.
		PVSSERROR("Configuration string delimiters "<<CdipClientManager::pubNameDelimiter[0]<<" and "<<CdipClientManager::pubNameDelimiter[1]<<" are both present for Publications, take first one.");
		delimiter = CdipClientManager::pubNameDelimiter[0][0];
	} else {
		//No delimiter found, this is a problem to report.
		PVSSERROR("None of the configuration string delimiters "<<CdipClientManager::pubNameDelimiter[0]<<" and "<<CdipClientManager::pubNameDelimiter[1]<<" were found for Publications.");
		return;
	}

	while(endOfStringInd < localCopy.size()){
		if ((localCopy[endOfStringInd] == delimiter) || (endOfStringInd == (localCopy.size()-1))){
			int lenOfString = (endOfStringInd - startOfStringInd) + 1;
			if (localCopy[endOfStringInd] == delimiter){
				lenOfString--;
			}
			std::string str = localCopy.substr(startOfStringInd, lenOfString);
			strings.push_back(str);
			startOfStringInd = endOfStringInd+1;
		}
		endOfStringInd++;
	}
}
Beispiel #2
0
bool CdpeWrapper::retriveDIPAddress(CharString & dipAddress) const{
	dipAddress = "";
	// first make sure address config exists.
	{
		CharString addConfigExistDPE[1] = {getName()+":_address.._type"};
		DpIdentList dpList;
		if (makeListOfDPEs(dpList, addConfigExistDPE, 1) != 1){
			return false;
		}
		PVSSINFO("");
		CdpGetCallBackHandler handler; // handler will be destroyed at end of this code block
		
		getValuesOfDPEs(handler, dpList);

		// look at the responses
		const DpIdValueList & answerList = handler.getListOfResponses();
		const DpVCItem* responsePair = answerList.getFirstItem();
		IntegerVar * addConfigType = (IntegerVar *)responsePair->getValuePtr();
		if (addConfigType->getValue() == 0){
			// address config does not exist!
			PVSSERROR("Address config does not exist for " << (const char *)getName());
			return false;
		}
	}


	// Address config exists - read it
	const int numProperties = 2; 
	CharString addConfigNames[numProperties] = {getName()+":_address.._drv_ident",
												getName()+":_address.._reference"};
	DpIdentList dpList;
	if (makeListOfDPEs(dpList, addConfigNames, numProperties) != numProperties){
		PVSSERROR("Failed to build dpList to get address info for " << (const char *)getName());
		return false;
	}
	
	// now get the values of the elements stored in the list
	// values are held in the handler
	CdpGetCallBackHandler handler;
	getValuesOfDPEs(handler, dpList);

	// look at the responses
	const DpIdValueList & answerList = handler.getListOfResponses();
	const DpVCItem* responsePair = answerList.getFirstItem();
	bool found = false;
	while(responsePair != NULL){
		CharString dpName;
		Manager::getLIName (responsePair->getDpIdentifier(), dpName);
		//cout << "Looking at response " << dpName << endl;

		if (dpName.indexOf(addConfigNames[0],0) != -1){
			// got response to _drv_ident
			const TextVar * value = (TextVar *)responsePair->getValuePtr();
			if ((value == NULL) || (strcmp(value->getValue(),"DIP") != 0)){
				CharString driverName = (value == NULL) ? "missing" : value->getString();
				PVSSERROR("DPE " << (const char *)getName() << " has bad driver id " << (const char *)driverName);
				return false;
			}
		}
		else if (dpName.indexOf(addConfigNames[1],0) != -1){
			// got response to _reference
			const TextVar * value = (TextVar *)responsePair->getValuePtr();
			if (value == NULL){
				found = false;
				PVSSERROR("DPE " << (const char *)getName() <<" has empty reference"); 
			} else {
				found = true;
				dipAddress = value->getString();
			}
		}

		responsePair = answerList.getNextItem();
	}

	return found;
}