(void)QTSS_AddStaticAttribute(qtssClientSessionObjectType, sOutputName, NULL, qtssAttrDataTypeVoidPointer);
(void)QTSS_IDForAttr(qtssClientSessionObjectType, sOutputName, &sOutputAttr);
1.为QTSS_ObjectType添加静态属性:最终将调用QTSSDictionaryMap的SetAttribute增加一个属性,同时 fNextAvailableID++
(void)QTSS_AddStaticAttribute(qtssClientSessionObjectType, sOutputName, NULL, qtssAttrDataTypeVoidPointer);
QTSS_Error QTSSCallbacks::QTSS_AddStaticAttribute(QTSS_ObjectType inObjectType, const char* inAttrName, void* inUnused, QTSS_AttrDataType inAttrDataType)
{
Assert(inUnused == NULL);
QTSS_ModuleState* theState = (QTSS_ModuleState*)OSThread::GetMainThreadData();
if (OSThread::GetCurrent() != NULL)
theState = (QTSS_ModuleState*)OSThread::GetCurrent()->GetThreadData();
// Static attributes can only be added before modules have had their Initialize role invoked.
if ((theState == NULL) || (theState->curRole != QTSS_Register_Role))
return QTSS_OutOfState;
UInt32 theDictionaryIndex = QTSSDictionaryMap::GetMapIndex(inObjectType);
if (theDictionaryIndex == QTSSDictionaryMap::kIllegalDictionary)
return QTSS_BadArgument;
QTSSDictionaryMap* theMap = QTSSDictionaryMap::GetMap(theDictionaryIndex);
return theMap->AddAttribute(inAttrName, NULL, inAttrDataType, qtssAttrModeRead | qtssAttrModeWrite | qtssAttrModePreempSafe);
}
QTSS_Error QTSSDictionaryMap::AddAttribute( const char* inAttrName,
QTSS_AttrFunctionPtr inFuncPtr,
QTSS_AttrDataType inDataType,
QTSS_AttrPermission inPermission)
{
if (inAttrName == NULL || ::strlen(inAttrName) > QTSS_MAX_ATTRIBUTE_NAME_SIZE)
return QTSS_BadArgument;
for (UInt32 count = 0; count < fNextAvailableID; count++)
{
if (::strcmp(&fAttrArray[count]->fAttrInfo.fAttrName[0], inAttrName) == 0)
{ // found the name in the dictionary
if (fAttrArray[count]->fAttrInfo.fAttrPermission & qtssPrivateAttrModeRemoved )
{ // it is a previously removed attribute
if (fAttrArray[count]->fAttrInfo.fAttrDataType == inDataType)
{ //same type so reuse the attribute
QTSS_AttributeID attrID = fAttrArray[count]->fID;
this->UnRemoveAttribute(attrID);
fAttrArray[count]->fAttrInfo.fFuncPtr = inFuncPtr; // reset
fAttrArray[count]->fAttrInfo.fAttrPermission = inPermission;// reset
return QTSS_NoErr; // nothing left to do. It is re-added.
}
// a removed attribute with the same name but different type--so keep checking
continue;
}
// an error, an active attribute with this name exists
return QTSS_AttrNameExists;
}
}
if (fAttrArraySize == fNextAvailableID)
{
// If there currently isn't an attribute array, or if the current array
// is full, allocate a new array and copy all the old stuff over to the new array.
UInt32 theNewArraySize = fAttrArraySize * 2;
if (theNewArraySize == 0)
theNewArraySize = kMinArraySize;
QTSSAttrInfoDict** theNewArray = NEW QTSSAttrInfoDict*[theNewArraySize];
::memset(theNewArray, 0, sizeof(QTSSAttrInfoDict*) * theNewArraySize);
if (fAttrArray != NULL)
{
::memcpy(theNewArray, fAttrArray, sizeof(QTSSAttrInfoDict*) * fAttrArraySize);
delete [] fAttrArray;
}
fAttrArray = theNewArray;
fAttrArraySize = theNewArraySize;
}
QTSS_AttributeID theID = fNextAvailableID;
fNextAvailableID++;
fNumValidAttrs++;
if (fFlags & kIsInstanceMap)
theID |= 0x80000000; // Set the high order bit to indicate this is an instance attr
// Copy the information into the first available element
// Currently, all attributes added in this fashion are always writeable
this->SetAttribute(theID, inAttrName, inFuncPtr, inDataType, inPermission);
return QTSS_NoErr;
}
2.找到新增加的属性对应的属性id,为后续设置属性值作准备
(void)QTSS_IDForAttr(qtssClientSessionObjectType, sOutputName, &sOutputAttr);