// // printAttribute // void wb_print_wbl::printAttribute(wb_volume& v, wb_attribute& attr, wb_attribute& tattr, ///< template wb_adef& adef, int force) { if ( !force && (adef.flags() & PWR_MASK_POINTER || adef.flags() & PWR_MASK_NOWBL)) return; if (attr.isClass() && adef.cid() == pwr_eClass_Buffer) printBuffer(v, attr, tattr, adef); else if (attr.isClass()) printClass(v, attr, tattr, adef); else { switch (adef.cid()) { case pwr_eClass_Param: case pwr_eClass_Input: case pwr_eClass_Intern: case pwr_eClass_Output: case pwr_eClass_ObjXRef: printParameter(v, attr, tattr, adef); break; default: m_os << "! %%WBDUMP-E-Error Unknown attribute class: " << adef.name() << ", cid: " << adef.cid() << endl; m_errCnt++; break; } } }
bool wb_session::writeAttribute(wb_attribute& a, void* p, size_t size) { if (isReadonly()) throw wb_error_str("ReadOnlySession"); bool sts = m_vrep->writeAttribute( &m_sts, (wb_orep*)a, a.bix(), a.offset(), a.size(), p); m_srep->update(); ldh_sEvent* ep = m_srep->eventStart(a.aoid(), ldh_eEvent_AttributeModified); m_srep->eventSend(ep); return sts; }
static pwr_tStatus replaceClass( wb_session *sp, wb_attribute& oa, pwr_sAttrRef *target) { for ( int i = 0; i < oa.nElement(); i++) { for ( wb_attribute a = oa.first(i); a; a = a.after()) { if ( a.isClass()) replaceClass( sp, a, target); else replaceAttr( sp, a, target); } } return LDH__SUCCESS; }
pwr_tStatus wb_volume::syntaxCheckAttr(wb_attribute& a, int *errorcount, int *warningcount) { pwr_tStatus sts = LDH__SUCCESS; pwr_tStatus asts; if ( !a.isSuperClass()) sts = triggSyntaxCheck(a, errorcount, warningcount); // Get any attribute objects wb_cdef cd = cdef(a.tid()); if ( !cd) return cd.sts(); wb_bdef bdef = cd.bdef(pwr_eBix_rt); wb_adef adef; if ( bdef) { for (adef = bdef.adef(); adef; adef = adef.next()) { if ( adef.flags() & PWR_MASK_SUPERCLASS) continue; if ( !(adef.flags() & PWR_MASK_CLASS)) continue; if ( adef.flags() & PWR_MASK_ARRAY) { for ( int i = 0; i < adef.nElement(); i++) { wb_attribute attr( a, -1, adef.name(), i); asts = syntaxCheckAttr( attr, errorcount, warningcount); if ( EVEN(asts)) sts = asts; } } else { wb_attribute attr( a, 0, adef.name()); if ( adef.flags() & PWR_MASK_DISABLEATTR && attr.disabled()) continue; asts = syntaxCheckAttr( attr, errorcount, warningcount); if ( EVEN(asts)) sts = asts; } } } return sts; }
pwr_tStatus wb_volume::triggSyntaxCheck(wb_attribute& a, int *errorcount, int *warningcount) { pwr_tStatus sts; char methodName[80]; wb_tMethod method; if ( !cdh_tidIsCid( a.tid())) return 0; // Call object method, or inherited method for ( wb_cdef cd = cdef( a.tid()); cd; cd = cd.super()) { sprintf( methodName, "%s-SyntaxCheck", cd.name()); m_vrep->erep()->method(&sts, methodName, &method); if ( ODD(sts)) { sts = ((wb_tMethodSyntaxCheck) (method))((ldh_tSesContext)this, a.aref(), errorcount, warningcount); if ( EVEN(sts)) return sts; break; } } return LDH__SUCCESS; }
static pwr_tStatus replaceAttr( wb_session *sp, wb_attribute& a, pwr_sAttrRef *target) { printf( "%s\n", a.attrName()); switch( a.type()) { case pwr_eType_AttrRef: { pwr_sAttrRef *value = (pwr_sAttrRef *)a.value(); pwr_sAttrRef aref = *value; if ( aref.Objid.vid == ldh_cIoConnectVolume) { aref.Objid = target->Objid; wb_attribute va = sp->attribute( &aref); printf( "Replacing %s\n", va.attrName()); sp->writeAttribute( a, &aref, sizeof(aref)); } break; } default: ; } return LDH__SUCCESS; }
// // printParameter // void wb_print_wbl::printParameter(wb_volume& v, wb_attribute& attr, wb_attribute& tattr, ///< template wb_adef& adef) { int nElement = adef.nElement(); int varSize = adef.size() / nElement; char* valueb = (char *)attr.value(); char* val; char* tvalueb; char* tval; char* svalp; int varOffset; bool parValOk; bool print_all = false; const char* name = adef.subName(); if (valueb == NULL) { m_os << "! %WBDUMP-E-Error Failed to get attribute address for " << adef.name() << endl; m_errCnt++; return; } if (adef.type() == pwr_eType_Text) { printText(v, adef, valueb, adef.size()); return; } if ( tattr.evenSts()) { // Template attribute not found, should not happen tvalueb = (char *)calloc( 1, attr.size()); print_all = true; } else if ( attr == tattr || m_isTemplateObject) // This is the template object itself, print all nonzero tvalueb = (char *)calloc( 1, tattr.size()); else tvalueb = (char *)tattr.value(); for (int i = 0; i < nElement; i++) { switch (adef.type()) { case pwr_eType_Boolean: case pwr_eType_Float32: case pwr_eType_Float64: case pwr_eType_Char: case pwr_eType_String: case pwr_eType_ProString: case pwr_eType_Int8: case pwr_eType_Int16: case pwr_eType_Int32: case pwr_eType_Int64: case pwr_eType_UInt8: case pwr_eType_UInt16: case pwr_eType_UInt32: case pwr_eType_UInt64: case pwr_eType_Objid: case pwr_eType_TypeId: case pwr_eType_CastId: case pwr_eType_DisableAttr: case pwr_eType_ClassId: case pwr_eType_AttrRef: case pwr_eType_Time: case pwr_eType_VolumeId: case pwr_eType_ObjectIx: case pwr_eType_RefId: case pwr_eType_DeltaTime: case pwr_eType_Mask: case pwr_eType_Enum: case pwr_eType_Status: case pwr_eType_NetStatus: case pwr_eType_DataRef: varOffset = varSize * i; val = valueb + varOffset; tval = tvalueb + varOffset; if (memcmp(val, tval, varSize) == 0 && !(adef.flags() & PWR_MASK_ALWAYSWBL) && !print_all) continue; parValOk = printValue(v, adef, val, varSize, &svalp); if (parValOk) indent(); else m_os << "! %WBDUMP-E-Error "; if (adef.flags() & PWR_MASK_ARRAY) { m_os << "Attr " << name << "[" << i << "] = " << svalp << endl; } else { m_os << "Attr " << name << " = " << svalp << endl; } break; case pwr_eType_Array: m_os << "! %WBDUMP-E-Error Type pwr_eType_Array is not yet implemented" << endl; m_errCnt++; break; case pwr_eType_Buffer: m_os << "! %WBDUMP-E-Error Type pwr_eType_Buffer is not yet implemented" << endl; m_errCnt++; break; case pwr_eType_Struct: m_os << "! %WBDUMP-E-Error Type pwr_eType_Struct is not yet implemented" << endl; m_errCnt++; break; default: m_os << "! %WBDUMP-E-Error Attribute " << adef.name() << " is of unknown type: " << adef.type() << endl; m_errCnt++; break; } } if ( tattr.evenSts() || attr == tattr) free( tvalueb); }
// // printClass // void wb_print_wbl::printClass(wb_volume& v, wb_attribute& attr, wb_attribute& tattr, wb_adef& adef) { pwr_tCid subClass = attr.subClass(); wb_object templ; wb_object sysbo; wb_attribute tattr2; wb_attribute attr2; wb_adef adef2; // if ( strcmp( attr.name(), "Template") == 0 && v.cid() == pwr_eClass_ClassVolume) // The parser can't handle subclasses in template objects yet... // return; wb_cdef cdef = v.cdef(attr.cid()); if (!cdef) { m_os << "! %WBDUMP-E-Error Unknown sub class: " << subClass << endl; m_errCnt++; return; } wb_bdef bdef = cdef.bdef(pwr_eBix_sys); if (!bdef) { m_os << "! %WBDUMP-E-Error sub class: " << subClass << " not defined" << endl; m_errCnt++; return; } for (int i = 0; i < adef.nElement(); i++) { attr2 = attr.first(i); tattr2 = tattr.first(i); while ( attr2.oddSts()) { adef2 = bdef.adef( attr2.attrName()); printAttribute(v, attr2, tattr2, adef2, 0); attr2 = attr2.after(); if ( tattr2.oddSts()) tattr2 = tattr2.after(); } } #if 0 wb_object co = v.object(cdh_ClassIdToObjid(subClass)); if (!co) { m_os << "! %WBDUMP-E-Error Unknown sub class: " << subClass << endl; m_errCnt++; return; } wb_cdef cdef = v.cdef(subClass); if (!cdef) { m_os << "! %WBDUMP-E-Error Unknown sub class: " << subClass << endl; m_errCnt++; return; } wb_name t("Template"); templ = co.child(t); if (!templ) { m_errCnt++; m_os << "! %WBDUMP-E-Error Template not found for class " << cdef.longName() << endl; return; } wb_bdef bdef = cdef.bdef(pwr_eBix_sys); if (!bdef) { m_os << "! %WBDUMP-E-Error sub class: " << subClass << " not defined" << endl; m_errCnt++; return; } bname = bdef.name(); for (int i = 0; i < adef.nElement(); i++) { if (adef.flags() & PWR_MASK_ARRAY) indent(1) << "Buffer " << adef.name() << "[" << i << "]" << endl; else indent(1) << "Buffer " << adef.name() << endl; adef2 = bdef.adef(); attr2 = attr.first(i); while (1) { tattr2 = templ.attribute(bname, adef2.name()); printAttribute(v, attr2, tattr2, adef2, 0); if (!(adef2 = adef2.next())) break; if (!(attr2 = attr2.after())) break; } indent(-1) << "EndBuffer" << endl; if (adef.flags() & PWR_MASK_ARRAY) indent(1) << "Buffer " << adef.name() << "[" << i << "]" << endl; else indent(1) << "Buffer " << adef.name() << endl; adef2 = bdef.adef(); attr2 = attr.first(i); while (1) { strcpy( aname, adef.subName()); strcat( aname, "."); strcat( aname, attr2.name()); attr2 tattr2 = templ.attribute(bname, adef2.name()); printAttribute(v, attr2, tattr2, adef2, 0); if (!(adef2 = adef2.next())) break; if (!(attr2 = attr2.after())) break; } } #endif }
wb_attribute::wb_attribute(const wb_attribute& pa, int pidx, const char *aname, int aidx) : wb_status(LDH__NOSUCHATTR), m_orep(0), m_adrep(0), m_size(0), m_offset(0), m_tid(0), m_elements(1), m_is_elem(0), m_type(pwr_eType_), m_flags(0), m_bix(pwr_eBix__), m_body(0), m_shadowed(false) { pwr_tCid cid; wb_attrname n; pwr_tAName attrname; if ( !cdh_tidIsCid( pa.tid()) || pa.m_orep == 0) return; if ( pidx == -1) pidx = pa.m_idx; if ( pa.m_flags & PWR_MASK_ARRAY && !pa.m_is_elem && (pidx < 0 || pidx >= pa.m_elements)) throw wb_error_str("Invalid subscript"); strcpy( attrname, pa.attrName()); if ( pa.m_flags & PWR_MASK_ARRAY) { if ( attrname[strlen(attrname)-1] == ']') { // Replace the index char *s = strrchr( attrname, '['); if ( s) sprintf( s, "[%d]", pidx); } else // Add index sprintf( &attrname[strlen(attrname)], "[%d]", pidx); } strcat( attrname, "."); if ( aname != 0) strcat( attrname, aname); else { // First attribute if ( pa.isClass()) cid = pa.subClass(); else cid = pa.tid(); wb_cdrep *cd = pa.m_orep->vrep()->merep()->cdrep(&m_sts, cid); if ( evenSts()) return; wb_bdrep* bd = cd->bdrep(&m_sts, pwr_eBix_sys); if ( evenSts()) { delete cd; return;} wb_adrep *adrep = bd->adrep(&m_sts); if ( evenSts()) { delete cd; delete bd; return;} strcat( attrname, adrep->name()); delete adrep; delete bd; delete cd; } n = attrname; cid = pa.cid(); wb_cdrep *cd = pa.m_orep->vrep()->merep()->cdrep(&m_sts, cid); if (evenSts()) return; wb_bdrep* bd = cd->bdrep(&m_sts, pwr_eBix_sys); if (evenSts()) { // Try devbody bd = cd->bdrep(&m_sts, pwr_eBix_dev); if (evenSts()) { delete cd; return;} } m_adrep = bd->adrep(&m_sts, n.attributesAllTrue()); if (evenSts()) { // Try devbody bd = cd->bdrep(&m_sts, pwr_eBix_dev); if (evenSts()) { delete cd; return;} m_adrep = bd->adrep(&m_sts, n.attributesAllTrue()); if (evenSts()) { delete cd; delete bd; return;} } m_adrep->ref(); m_size = m_adrep->size(); m_offset = m_adrep->offset(); m_tid = m_original_tid = m_adrep->tid(); m_elements = m_adrep->nElement(); m_flags = m_adrep->flags(); m_type = m_adrep->type(); m_idx = aidx; m_orep = pa.m_orep; m_orep->ref(); m_bix = bd->bix(); if ( m_flags & PWR_MASK_CASTATTR) { pwr_tCastId castid; castId( &castid); if ( castid != pwr_cNCastId) m_tid = castid; } #if 0 if ( pa.isClass()) { m_flags |= PWR_MASK_SUBCLASS; if (pa.m_flags & PWR_MASK_SUBCLASS) m_bix = pa.m_bix; else m_bix = pa.m_adrep->bix(); } else m_bix = pa.m_bix; #endif delete bd; delete cd; }