Commit 111ac995 authored by Claes Sjofors's avatar Claes Sjofors

wb script functions GetTemplateObject() and GetNextTemplateAttrRef() added

parent 3ddb55a3
...@@ -587,6 +587,18 @@ ldh_GetClassList(ldh_tSession session, pwr_tCid cid, pwr_tOid *oid) ...@@ -587,6 +587,18 @@ ldh_GetClassList(ldh_tSession session, pwr_tCid cid, pwr_tOid *oid)
return o.sts(); return o.sts();
} }
pwr_tStatus
ldh_GetTemplateObject(ldh_tSession session, pwr_tCid cid, pwr_tOid *oid)
{
wb_session *sp = (wb_session *)session;
wb_object o = sp->templateObject(cid);
if (!o) return o.sts();
*oid = o.oid();
return o.sts();
}
/* Returns the objid of the next object of the same class. */ /* Returns the objid of the next object of the same class. */
pwr_tStatus pwr_tStatus
...@@ -626,6 +638,18 @@ ldh_GetNextAttrRef(ldh_tSession session, pwr_tCid cid, pwr_sAttrRef *arp, ...@@ -626,6 +638,18 @@ ldh_GetNextAttrRef(ldh_tSession session, pwr_tCid cid, pwr_sAttrRef *arp,
return sp->sts(); return sp->sts();
} }
/* Returns the attrref of the next object of the same class. */
pwr_tStatus
ldh_GetNextTemplateAttrRef(ldh_tSession session, pwr_tCid cid, pwr_sAttrRef *arp,
pwr_sAttrRef *new_arp)
{
wb_session *sp = (wb_session *)session;
sp->nextTemplateAref( cid, arp, new_arp);
return sp->sts();
}
/* Returns the first attribute object of the specified class in /* Returns the first attribute object of the specified class in
the specified object. */ the specified object. */
......
...@@ -708,12 +708,25 @@ pwr_tStatus ldh_GetNextAttrRef( ...@@ -708,12 +708,25 @@ pwr_tStatus ldh_GetNextAttrRef(
pwr_sAttrRef *arp, pwr_sAttrRef *arp,
pwr_sAttrRef *new_arp pwr_sAttrRef *new_arp
); );
pwr_tStatus ldh_GetNextObjectAttrRef( pwr_tStatus ldh_GetNextObjectAttrRef(
ldh_tSession session, ldh_tSession session,
pwr_tCid cid, pwr_tCid cid,
pwr_sAttrRef *arp, pwr_sAttrRef *arp,
pwr_sAttrRef *new_arp pwr_sAttrRef *new_arp
); );
pwr_tStatus ldh_GetTemplateObject(
ldh_tSession session,
pwr_tCid cid,
pwr_tOid *oid
);
pwr_tStatus ldh_GetNextTemplateAttrRef(
ldh_tSession session,
pwr_tCid cid, pwr_sAttrRef *arp,
pwr_sAttrRef *new_arp
);
pwr_tStatus ldh_GetNextSibling ( pwr_tStatus ldh_GetNextSibling (
ldh_tSession Session, ldh_tSession Session,
pwr_tObjid object, pwr_tObjid object,
......
...@@ -733,6 +733,42 @@ tree_sTable *wb_merep::buildCatt( pwr_tStatus *sts) ...@@ -733,6 +733,42 @@ tree_sTable *wb_merep::buildCatt( pwr_tStatus *sts)
} }
} }
// If the current volume is a class volume, add objects from this also
if ( m_vrep->type() == ldh_eVolRep_Mem && m_vrep->cid() == pwr_eClass_ClassVolume) {
wb_vrep *vrep = m_vrep;
wb_orep *o, *onext;
wb_adrep *ad, *adnext;
pwr_tCid cid;
for ( o = vrep->object( sts, pwr_eClass_ClassDef);
ODD(*sts);
onext = o->next( sts), o->unref(), o = onext) {
o->ref();
cid = cdh_ClassObjidToId( o->oid());
wb_cdrep *cd = cdrep( sts, cid);
if ( EVEN(*sts)) throw wb_error(*sts);
wb_bdrep *bd = cd->bdrep( sts, pwr_eBix_rt);
if ( EVEN(*sts)) {
delete cd;
continue;
}
for ( ad = bd->adrep( sts);
ODD(*sts);
adnext = ad->next( sts), delete ad, ad = adnext) {
if ( ad->flags() & PWR_MASK_CLASS && cdh_tidIsCid( ad->tid())) {
insertCattObject( sts, cid, ad, 0);
if ( EVEN(*sts)) throw wb_error(*sts);
}
}
delete bd;
delete cd;
}
}
#if 0 #if 0
merep_sClassAttrKey key; merep_sClassAttrKey key;
key.subCid = 0; key.subCid = 0;
......
...@@ -192,6 +192,16 @@ wb_object wb_volume::object(const char *name) const ...@@ -192,6 +192,16 @@ wb_object wb_volume::object(const char *name) const
return o; return o;
} }
wb_object wb_volume::templateObject(pwr_tCid cid) const
{
pwr_tOid oid;
oid.oix = cdh_cixToOix( cdh_cidToCix(cid), pwr_eBix_template, 0);
oid.vid = cdh_CidToVid( cid);
return object(oid);
}
wb_adef wb_volume::adef(pwr_tCid cid, const char *bname, const char *aname) wb_adef wb_volume::adef(pwr_tCid cid, const char *bname, const char *aname)
{ {
pwr_tStatus sts; pwr_tStatus sts;
...@@ -206,7 +216,6 @@ wb_adef wb_volume::adef(pwr_tCid cid, const char *bname, const char *aname) ...@@ -206,7 +216,6 @@ wb_adef wb_volume::adef(pwr_tCid cid, const char *bname, const char *aname)
return bdef.adef(aname); return bdef.adef(aname);
} }
wb_cdef wb_volume::cdef(wb_object o) wb_cdef wb_volume::cdef(wb_object o)
{ {
pwr_tStatus sts; pwr_tStatus sts;
...@@ -1122,7 +1131,7 @@ void wb_volume::aref(pwr_tCid cid, pwr_sAttrRef *arp) ...@@ -1122,7 +1131,7 @@ void wb_volume::aref(pwr_tCid cid, pwr_sAttrRef *arp)
} }
void wb_volume::nextAref(pwr_tCid cid, pwr_sAttrRef *arp, void wb_volume::nextAref(pwr_tCid cid, pwr_sAttrRef *arp,
pwr_sAttrRef *oarp) pwr_sAttrRef *oarp)
{ {
tree_sTable *catt_tt = m_vrep->merep()->catt_tt(); tree_sTable *catt_tt = m_vrep->merep()->catt_tt();
int bd_size; int bd_size;
...@@ -1270,6 +1279,134 @@ void wb_volume::nextAref(pwr_tCid cid, pwr_sAttrRef *arp, ...@@ -1270,6 +1279,134 @@ void wb_volume::nextAref(pwr_tCid cid, pwr_sAttrRef *arp,
op->unref(); op->unref();
} }
void wb_volume::nextTemplateAref(pwr_tCid cid, pwr_sAttrRef *arp,
pwr_sAttrRef *oarp)
{
tree_sTable *catt_tt = m_vrep->merep()->buildCatt(&m_sts);
int bd_size;
wb_object o = object(arp->Objid);
if (!o) {
m_sts = o.sts();
return;
}
wb_orep *op = o;
// Get body size
wb_cdrep *cd = m_vrep->merep()->cdrep(&m_sts, cid);
if (evenSts()) return;
wb_bdrep *bd = cd->bdrep(&m_sts, pwr_eBix_rt);
if (oddSts()) {
bd_size = bd->size();
delete bd;
}
else
bd_size = 0;
delete cd;
if ( cid == op->cid()) {
// Find attribute object
pwr_tCid hostCid = 0;
merep_sClassAttrKey key;
merep_sClassAttr *item;
key.subCid = cid;
key.hostCid = 0;
key.idx = 0;
for (item = (merep_sClassAttr*) tree_FindSuccessor(&m_sts, catt_tt, &key);
item;
item = (merep_sClassAttr*) tree_FindSuccessor(&m_sts, catt_tt, &item->key)) {
if ( item->key.subCid != cid) {
m_sts = LDH__CLASSLIST;
break;
}
if (hostCid && item->key.hostCid == hostCid)
// Same class with other index
continue;
hostCid = item->key.hostCid;
wb_object to = templateObject( item->key.hostCid);
if ( to) {
wb_orep *o = to;
wb_cdrep *cd = m_vrep->merep()->cdrep(&m_sts, cid);
if (evenSts()) return;
int bd_size;
wb_bdrep *bd = cd->bdrep(&m_sts, pwr_eBix_rt);
if (oddSts()) {
bd_size = bd->size();
delete bd;
}
else
bd_size = 0;
delete cd;
*oarp = pwr_cNAttrRef;
oarp->Objid = o->oid();
oarp->Flags.b.ObjectAttr = 1;
oarp->Offset = item->offset[0];
oarp->Size = bd_size;
oarp->Body = cdh_cidToBid( cid, pwr_eBix_rt);
return;
}
}
}
// Find next attribute object in current object
merep_sClassAttrKey key;
merep_sClassAttr *item;
int first_offset = 0;
key.subCid = cid;
key.hostCid = op->cid();
key.idx = 0;
for (item = (merep_sClassAttr*)tree_Find(&m_sts, catt_tt, &key);
item && item->key.subCid == cid && item->key.hostCid == op->cid();
item = (merep_sClassAttr*)tree_FindSuccessor(&m_sts, catt_tt, &item->key)) {
// Find next offset
for (int i = 0; i < item->numOffset; i++) {
if (i == 0 && item->key.idx == 0)
first_offset = item->offset[0];
if (item->offset[i] > arp->Offset) {
*oarp = pwr_cNAttrRef;
oarp->Objid = op->oid();
oarp->Flags.b.ObjectAttr = 1;
oarp->Offset = item->offset[i];
oarp->Size = bd_size;
oarp->Body = cdh_cidToBid( cid, pwr_eBix_rt);
return;
}
}
}
// Find first offset in first object of next class
key.subCid = cid;
key.hostCid = op->cid();
key.idx = 0;
for (item = (merep_sClassAttr*) tree_Find(&m_sts, catt_tt, &key);
item && item->key.subCid == cid;
item = (merep_sClassAttr*) tree_FindSuccessor(&m_sts, catt_tt, &item->key)) {
if (item->key.hostCid == key.hostCid)
continue;
wb_object ol = templateObject( item->key.hostCid);
if (oddSts()) {
*oarp = pwr_cNAttrRef;
oarp->Objid = ol.oid();
oarp->Flags.b.ObjectAttr = 1;
oarp->Offset = item->offset[0];
oarp->Size = bd_size;
oarp->Body = cdh_cidToBid( cid, pwr_eBix_rt);
return;
}
}
m_sts = LDH__NONEXT;
}
void wb_volume::aref(pwr_tCid cid, wb_object o, pwr_sAttrRef *arp) void wb_volume::aref(pwr_tCid cid, wb_object o, pwr_sAttrRef *arp)
{ {
tree_sTable *catt_tt = m_vrep->merep()->buildCatt(&m_sts); tree_sTable *catt_tt = m_vrep->merep()->buildCatt(&m_sts);
......
...@@ -88,6 +88,7 @@ public: ...@@ -88,6 +88,7 @@ public:
wb_object object(pwr_tOid oid) const; wb_object object(pwr_tOid oid) const;
wb_object object(pwr_tCid cid) const; wb_object object(pwr_tCid cid) const;
wb_object object(const char *name) const; wb_object object(const char *name) const;
wb_object templateObject(pwr_tCid cid) const;
wb_attribute attribute(pwr_tOid oid, const char *bname, const char *aname) const; wb_attribute attribute(pwr_tOid oid, const char *bname, const char *aname) const;
wb_attribute attribute(pwr_tOid oid, const char *bname) const; wb_attribute attribute(pwr_tOid oid, const char *bname) const;
...@@ -139,6 +140,8 @@ public: ...@@ -139,6 +140,8 @@ public:
void nextAref( pwr_tCid cid, pwr_sAttrRef *arp, pwr_sAttrRef *new_arp); void nextAref( pwr_tCid cid, pwr_sAttrRef *arp, pwr_sAttrRef *new_arp);
void aref( pwr_tCid cid, wb_object o, pwr_sAttrRef *arp); void aref( pwr_tCid cid, wb_object o, pwr_sAttrRef *arp);
void nextObjectAref( pwr_tCid cid, pwr_sAttrRef *arp, pwr_sAttrRef *oarp); void nextObjectAref( pwr_tCid cid, pwr_sAttrRef *arp, pwr_sAttrRef *oarp);
void nextTemplateAref(pwr_tCid cid, pwr_sAttrRef *arp,
pwr_sAttrRef *oarp);
bool isAncestor( wb_object& ancestor, wb_object& o); bool isAncestor( wb_object& ancestor, wb_object& o);
void subClass( pwr_tCid cid, pwr_tCid subcid, pwr_tCid *nextsubcid); void subClass( pwr_tCid cid, pwr_tCid subcid, pwr_tCid *nextsubcid);
}; };
......
...@@ -604,6 +604,7 @@ wb_orep *wb_vrepmem::next(pwr_tStatus *sts, const wb_orep *o) ...@@ -604,6 +604,7 @@ wb_orep *wb_vrepmem::next(pwr_tStatus *sts, const wb_orep *o)
mem_object *next = root_object->next( mem->m_cid, &oix); mem_object *next = root_object->next( mem->m_cid, &oix);
if ( next) { if ( next) {
wb_orepmem *orep = new wb_orepmem( this, next); wb_orepmem *orep = new wb_orepmem( this, next);
*sts = LDH__SUCCESS;
return orep; return orep;
} }
} }
......
...@@ -375,6 +375,54 @@ static int wccm_getclasslist_func( ...@@ -375,6 +375,54 @@ static int wccm_getclasslist_func(
return 1; return 1;
} }
static int wccm_gettemplateobject_func(
void *filectx,
ccm_sArg *arg_list,
int arg_count,
int *return_decl,
ccm_tFloat *return_float,
ccm_tInt *return_int,
char *return_string)
{
int sts;
pwr_tOName name;
pwr_tCid cid;
pwr_tObjid oid;
int size;
ldh_tSesContext ldhses;
sts = wccm_get_ldhses( &ldhses);
if ( EVEN(sts))
{
strcpy( return_string, "");
*return_decl = CCM_DECL_STRING;
return CMD__NOVOLATTACHED;
}
if ( arg_count != 1)
return CCM__ARGMISM;
if ( arg_list->value_decl != CCM_DECL_STRING)
return CCM__ARGMISM;
sts = ldh_ClassNameToId( ldhses, &cid, arg_list->value_string);
if ( ODD(sts))
{
sts = ldh_GetTemplateObject( ldhses, cid, &oid);
if (ODD(sts))
sts = ldh_ObjidToName( ldhses, oid,
cdh_mName_volumeStrict, name, sizeof( name), &size);
}
if ( ODD(sts))
strcpy( return_string, name);
else
strcpy( return_string, "");
*return_decl = CCM_DECL_STRING;
return 1;
}
static int wccm_getnextobject_func( static int wccm_getnextobject_func(
void *filectx, void *filectx,
ccm_sArg *arg_list, ccm_sArg *arg_list,
...@@ -524,6 +572,61 @@ static int wccm_getnextattrref_func( ...@@ -524,6 +572,61 @@ static int wccm_getnextattrref_func(
return 1; return 1;
} }
static int wccm_getnexttemplateattrref_func(
void *filectx,
ccm_sArg *arg_list,
int arg_count,
int *return_decl,
ccm_tFloat *return_float,
ccm_tInt *return_int,
char *return_string)
{
int sts;
char *name;
pwr_tAttrRef aref;
pwr_tAttrRef next_aref;
int size;
ldh_tSesContext ldhses;
pwr_tCid cid;
ccm_sArg *arg_p2;
sts = wccm_get_ldhses( &ldhses);
if ( EVEN(sts))
{
strcpy( return_string, "");
*return_decl = CCM_DECL_STRING;
return CMD__NOVOLATTACHED;
}
if ( arg_count != 2)
return CCM__ARGMISM;
arg_p2 = arg_list->next;
if ( arg_list->value_decl != CCM_DECL_STRING)
return CCM__ARGMISM;
if ( arg_p2->value_decl != CCM_DECL_STRING)
return CCM__ARGMISM;
sts = ldh_ClassNameToId( ldhses, &cid, arg_list->value_string);
if ( ODD(sts)) {
sts = ldh_NameToAttrRef( ldhses, arg_p2->value_string, &aref);
if ( ODD(sts)) {
sts = ldh_GetNextTemplateAttrRef( ldhses, cid, &aref, &next_aref);
if (ODD(sts))
sts = ldh_AttrRefToName( ldhses, &next_aref,
cdh_mName_volumeStrict, &name, &size);
}
}
if ( ODD(sts))
strcpy( return_string, name);
else
strcpy( return_string, "");
*return_decl = CCM_DECL_STRING;
return 1;
}
static int wccm_getrootlist_func( static int wccm_getrootlist_func(
void *filectx, void *filectx,
ccm_sArg *arg_list, ccm_sArg *arg_list,
...@@ -1205,6 +1308,10 @@ int wccm_register( ...@@ -1205,6 +1308,10 @@ int wccm_register(
if ( EVEN(sts)) return sts; if ( EVEN(sts)) return sts;
sts = ccm_register_function( "GetObjectClass", wccm_getobjectclass_func); sts = ccm_register_function( "GetObjectClass", wccm_getobjectclass_func);
if ( EVEN(sts)) return sts; if ( EVEN(sts)) return sts;
sts = ccm_register_function( "GetTemplateObject", wccm_gettemplateobject_func);
if ( EVEN(sts)) return sts;
sts = ccm_register_function( "GetNextTemplateAttrRef", wccm_getnexttemplateattrref_func);
if ( EVEN(sts)) return sts;
sts = ccm_register_function( "GetVolumeList", wccm_getvolumelist_func); sts = ccm_register_function( "GetVolumeList", wccm_getvolumelist_func);
if ( EVEN(sts)) return sts; if ( EVEN(sts)) return sts;
sts = ccm_register_function( "GetNextVolume", wccm_getnextvolume_func); sts = ccm_register_function( "GetNextVolume", wccm_getnextvolume_func);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment