QTSS_ObjectType添加静态属性

(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);


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sunxiaopengsun

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值