KCMS CMM Reference Manual

Examples

The following code sample shows you how to interface with the KcsProfile class and its derivatives using the KcsGetAttribute() KCMS framework API wrapper function.


Example 5-1 KcsProfile Class and KcsGetAttribute()

KcsStatusId
 KcsGetAttribute(KcsProfileId profile, KcsAttributeName name,
 			KcsAttributeValue *value)
 {
 	VirtualWorld vWorld(true, true);
 	KcsProfile * *profiles = 0;

 	if (gProfileArray == NULL)
 	// no profiles have been loaded or user has not handled a load
 	// error correctly
 	return(KCS_BAD_PROFILE_ID);
 	KcsStatusId stat;
 	profiles = (KcsProfile * *)KcsLockHandle(gProfileArray);
 	if (isValid(profile, profiles))
 		stat = profiles[profile]->getAttribute(name, value);
 	else
 		stat = KCS_BAD_PROFILE_ID;
 	KcsUnlockHandle(gProfileArray);
 	return(stat);
 }

The following code sample shows you how to interface with the KcsProfile class and its derivatives using the KcsConnectProfiles() KCMS framework API wrapper function.


Example 5-2 KcsProfile Class and KcsConnectProfiles()

KcsStatusId
 KcsConnectProfiles(KcsProfileId *resultProfileId,
 			unsigned long profileCount, KcsProfileId *profileSequence,
 			KcsOperationType operationLoadSet,
 			unsigned long *failedProfileIndex)
 {
 	VirtualWorld vWorld(true, true);
 	KcsProfile * *profiles = 0;
 	KcsStatus result;
 	long i;

 	if (gProfileArray == NULL)
 			// no profiles have been loaded or user hasn't handled a load
 			// error correctly
 			return(KCS_BAD_PROFILE_ID);

 	result = getNewValidIndex(resultProfileId);
 	if (result != KCS_SUCCESS)
 			return(result);
 	profiles = (KcsProfile * *)KcsLockHandle(gProfileArray);
 	KcsMemoryBlock * memblk = new KcsMemoryBlock(&result,
 			sizeof(KcsProfile * ), profileCount);
 	if (memblk == NULL)
 			return(KCS_MEM_ALLOC_ERROR);
 	KcsProfile * *moreProfiles = (KcsProfile * *)memblk->lock();
 	KcsProfile * madeProfile = NULL;
 	long failingNum = 0;
 	for (i = 0; i < profileCount; i++) (
 			if (!isValid(profileSequence[i], profiles)) {
 				*failedProfileIndex = i;
 				*resultProfileId = BAD_PROFILE_ID;
 				memblk->unlock();
 				memblk->dettach();
 				KcsUnlockHandle(gProfileArray);
 				// also have to do a dettach here !!
 				return(KCS_BAD_PROFILE_ID);
 				}
 			else
 				moreProfiles[i] =
 						(KcsProfile *)profiles[profileSequence[i]]->attach();
 			}
 	result = profiles[profileSequence[0]]->connect(profileCount,
 			moreProfiles, operationLoadSet, madeProfile, &failingNum);
 	*failedProfileIndex = failingNum;
 	if (result == KCS_SUCCESS)
 	profiles[*resultProfileId] = madeProfile;

 	for (i = 0; i < profileCount; i++) {
 			moreProfiles[i]->dettach();
 			}
 	memblk->unlock();
 	memblk->dettach();
 	KcsUnlockHandle(gProfileArray);

 gNumProfilesAllocated++;
 return(result);
 }