📄 commreg.cpp
字号:
}/* * Function Name: CommonRegistry::GetPropList const * Input Params: const char* prop_name, IHXValues*& pValues * Return Value: HX_RESULT * Description: * given a PT_COMPOSITE property, it returns back a list of triples * one for each property under the PT_COMPOSITE. each of which consists * of property name, type and the hash key * * XXXAAK -- return a list of hash keys if the list element is PT_COMPOSITE. */HX_RESULTCommonRegistry::GetPropList(const char* prop_name, IHXValues*& pValues) const{ DB_node* d = 0; Property* p = 0; if (_find(&d, &p, prop_name) == HXR_OK) { if (p) { switch(p->get_type()) { case PT_COMPOSITE: { DB_implem* ldb = 0; p->get_db_val(&ldb); return _getPropList(ldb, pValues); } default: DPRINTF(D_REGISTRY, ("%s -- is NOT a COMPOSITE property\n", prop_name)); break; } } } return HXR_FAIL;}HX_RESULTCommonRegistry::Copy(const char* pFrom, const char* pTo){ HXPropType type; type = GetType(pFrom); char buf[256]; /* Flawfinder: ignore */ INT32 Int; UINT32 ul; IHXBuffer* pBuffer = 0; HX_RESULT res; IHXValues* pValues = 0; const char* pName; switch (type) { case PT_COMPOSITE: /* * Get all props and recurse copy all of them. */ if (HXR_OK != (res = GetPropList(pFrom, pValues))) { break; } if (HXR_OK == pValues->GetFirstPropertyULONG32(pName, ul)) { SafeStrCpy(buf, pTo, 256); SafeStrCat(buf, pName + strlen(pFrom), 256); res = Copy(pName, buf); while (HXR_OK == pValues->GetNextPropertyULONG32(pName, ul)) { SafeStrCpy(buf, pTo, 256); SafeStrCat(buf, pName + strlen(pFrom), 256); res = Copy(pName, buf); } } HX_RELEASE(pValues); break; case PT_INTEGER: if (HXR_OK != (res = GetInt(pFrom, &Int))) { break; } if (AddInt(pTo, Int)) { res = HXR_OK; } else { res = HXR_FAIL; } break; case PT_STRING: if (HXR_OK != (res = GetStr(pFrom, pBuffer))) { break; } if (AddStr(pTo, pBuffer)) { res = HXR_OK; } else { res = HXR_FAIL; } if (pBuffer) { pBuffer->Release(); } pBuffer = 0; break; case PT_BUFFER: if (HXR_OK != (res = GetBuf(pFrom, &pBuffer))) { break; } if (AddBuf(pTo, pBuffer)) { res = HXR_OK; } else { res = HXR_FAIL; } if (pBuffer) { pBuffer->Release(); } pBuffer = 0; break; default: res = HXR_FAIL; } return res;}HX_RESULTCommonRegistry::SetStringAccessAsBufferById(UINT32 hash_key){ DB_node* d = 0; Property* p = 0; d = (DB_node *)_ids->get(hash_key); if (!d) { DPRINTF(D_REGISTRY, ("SetStringAccessAsBufferById(%lu) failed\n", hash_key)); return HXR_FAIL; } p = d->get_data(); if (p) { switch(p->get_type()) { case PT_STRING: p->SetStringAccessAsBufferById(); return HXR_OK; default: DPRINTF(D_REGISTRY, ("%lu -- Property<-->Type MISMATCH\n", hash_key)); return HXR_PROP_TYPE_MISMATCH; } } return HXR_FAIL;}/* * Function Name: CommonRegistry::GetPropList const * Input Params: const UINT32 hash_key, IHXValues*& pValues * Return Value: HX_RESULT * Description: * given a PT_COMPOSITE property, it returns back a list of triples * one for each property under the PT_COMPOSITE. each of which consists * of property name, type and the hash key * * XXXAAK -- return a list of hash keys if the list element is PT_COMPOSITE. */HX_RESULTCommonRegistry::GetPropList(const UINT32 hash_key, IHXValues*& pValues) const{ if (!hash_key) return _getPropList(_logdb_imp, pValues); DB_node* d = 0; Property* p = 0; d = (DB_node *)_ids->get(hash_key); if (!d) { DPRINTF(D_REGISTRY, ("could not get PropList for %lu -- no data\n", hash_key)); return HXR_FAIL; } p = d->get_data(); if (p) { switch(p->get_type()) { case PT_COMPOSITE: { DB_implem* ldb = 0; p->get_db_val(&ldb); return _getPropList(ldb, pValues); } default: DPRINTF(D_REGISTRY, ("%s(%lu) -- is NOT a COMPOSITE property\n", p->get_key_str(), hash_key)); break; } } return HXR_FAIL;}/* * Function Name: CommonRegistry::GetPropName const * Input Params: const UINT32 id, IHXBuffer*& prop_name * Return Value: HX_RESULT * Description: * return a pointer to the key string of the Property whose * id is given. */HX_RESULTCommonRegistry::GetPropName(const UINT32 id, IHXBuffer*& prop_name) const{ DB_node* d = (DB_node *)_ids->get(id); if (d) { Property* p = d->get_data(); if (p) { prop_name = new CHXBuffer; prop_name->Set((const unsigned char *)p->get_key_str(), p->get_key_str_len()); prop_name->AddRef(); return HXR_OK; } } return HXR_FAIL;}/* * Function Name: GetId * Input Params: const char* prop_name * Return Value: UINT32 * Description: * returns the ID value for the Property name (prop_name) passed * as a parameter. the main CONDITION is that the Property MUST EXIST, * otherwise it returns a ZERO (0). */UINT32CommonRegistry::GetId(const char* prop_name) const{ DPRINTF(D_REGISTRY&D_ENTRY, ("CommonRegistry::GetId(%s)\n", prop_name)); DB_node* d = 0; Property* p = 0; if (_find(&d, &p, prop_name) == HXR_OK) if (d) return d->get_id(); return 0;}UINT32CommonRegistry::FindParentKey(const char* prop_name){ DB_node* d = 0; Property* p = 0; if (_find(&d, &p, prop_name) == HXR_OK) { if (d) { // find the DB that contains this node DB_implem* ldb = d->get_db(); if (ldb) { // find the node that owns this DB d = ldb->owner_node(); if (d) return d->get_id(); } } } return 0;}UINT32CommonRegistry::FindParentKey(const UINT32 hash_key){ DB_node* d = (DB_node *)_ids->get(hash_key); // find the node with the hash key if (d) { // find the DB that contains this node DB_implem* ldb = d->get_db(); if (ldb) { // find the node that owns this DB d = ldb->owner_node(); if (d) return d->get_id(); } } return 0;}/* * Function Name: CommonRegistry::Count const * Input Params: * Return Value: INT32 * Description: * returns the total number of Properties (including COMPOSITE types) * in the registry. */INT32CommonRegistry::Count() const{ return _count;}/* * Function Name: CommonRegistry::Count * Input Params: const char* prop_name * Return Value: UINT32 * Description: * returns the number of Properties below the COMPOSITE whose * name has been specified. if the Property is not a COMPOSITE then * ZERO is returned. */INT32CommonRegistry::Count(const char* prop_name) const{ DB_node* d = 0; Property* p = 0; DB_implem* ldb = 0; UINT32 h = 0; if (_find(&d, &p, prop_name) != HXR_OK) return 0; if (p) { if (p->get_type() == PT_COMPOSITE) { p->get_db_val(&ldb); if (ldb) return ldb->count(); } } return 0;}/* * Function Name: CommonRegistry::Count * Input Params: const UINT32 hash_key * Return Value: UINT32 * Description: * returns the number of Properties below the COMPOSITE whose * hash key has been specified. if the Property is not a COMPOSITE * then ZERO is returned. */INT32CommonRegistry::Count(const UINT32 hash_key) const{ DB_node* d = 0; Property* p = 0; DB_implem* ldb = 0; d = (DB_node *)_ids->get(hash_key); if (!d) { DPRINTF(D_REGISTRY, ("%lu -- does not exist\n", hash_key)); return HXR_FAIL; } p = d->get_data(); if (p) { if (p->get_type() == PT_COMPOSITE) { p->get_db_val(&ldb); if (ldb) return ldb->count(); } } return 0;}/* * Function Name: CommonRegistry::_del * Input Params: DB_implem* db * Return Value: HX_RESULT * Description: * recursive delete down the database, which simultaneously * deletes nodes from the hash tree. this method gets called from * Del() when the user wants to delete a COMPOSITE Property. the * default action is to delete all Properties under that COMPOSITE. */HX_RESULTCommonRegistry::_del(DB_implem* db){ DPRINTF(D_REGISTRY, ("_del(db(%p)\n", db)); DB_node* d = db->first(); while (d) { Property* pnode = d->get_data(); DPRINTF(D_REGISTRY, ("_del(db(%p)) -- %s(%lu)\n", db, pnode->get_key_str(), d->get_id())); if (pnode) { if (pnode->get_type() == PT_COMPOSITE) { DB_implem* ldb; pnode->get_db_val(&ldb); if (!ldb) { DPRINTF(D_REGISTRY, ("invalid Property(%lu) not deleted\n", d->get_id())); return HXR_FAIL; } _del(ldb); } // fire off the callbacks if someone is watching this prop DeleteDone(db, d, pnode); _ids->destroy(d->get_id()); db->del(d); _count--; } else { DPRINTF(D_REGISTRY, ("data corrputed for Property(%lu)\n", d->get_id())); return HXR_FAIL; } d = db->first(); } return HXR_OK;}/* * Function Name: CommonRegistry::_getPropList const * Input Params: DB_implem* ldb, IHXValues*& pValues * Return Value: HX_RESULT * Description: * return back a list of triples (name, type, hash) consisting of * all the properties in the database level specified by "ldb". this * method is generally called from GetPropList() when a user requests * for a list of Properties under some COMPOSITE Property. */HX_RESULTCommonRegistry::_getPropList(DB_implem* ldb, IHXValues*& pValues) const{ DPRINTF(D_REGISTRY, ("_getPropList(ldb(%p))\n", ldb)); DB_node* node = 0; pValues = new CHXHeader; pValues->AddRef(); node = ldb->first(); while (node) { Property* p = node->get_data(); if (!p) { DPRINTF(D_REGISTRY, ("%ld is an empty Registry node, skipping it\n", node->get_id())); } pValues->SetPropertyULONG32(p->get_key_str(), node->get_id()); DB_node* n = ldb->next(node); node = n; } return HXR_OK;}/* * Copyright (c) 1996, 1997, 1998 RealNetworks * * Function Name: CommonRegistry::_setReadOnly * Input Params: Property* pProp, BOOL bValue * Return Value: HX_RESULT * Description: * set the read_only flag of this node, and all nodes beneath * this node (if this node is a composite) to bValue. */HX_RESULTCommonRegistry::_setReadOnly(Property* pProp, BOOL bValue){ DB_implem* ldb = 0; DB_node* node = 0; // Set read_only flag on pProp pProp->set_read_only(bValue); if (pProp->get_type() == PT_COMPOSITE) { // Get ldb of pProp pProp->get_db_val(&ldb); if (ldb) { // Set read_only flag on each child node = ldb->first(); while (node) { Property* p = node->get_data(); if (!p) { DPRINTF(D_REGISTRY, ("%ld is an empty Registry node, " "skipping it\n", node->get_id())); } // Recurse... _setReadOnly(p, bValue); DB_node* n = ldb->next(node); node = n; } } } return HXR_OK;}/* * Function Name: _find * Input Params: DB_node** d, Property** p, * UINT32& hash_key, const char* prop_name * Return Value: HX_RESULT * Description: * find a DB_node and its corresponding Property based on the name * or the hash key, whichever is given. */HX_RESULTCommonRegistry::_find(DB_node** d, Property** p, const char* prop_name) const{ DPRINTF(D_REGISTRY, ("CommonRegistry::_find(prop_name(%s))\n", prop_name)); Key* k = new Key(prop_name); if(!k) { return 0; } int len = k->size(); char* curr_key_str = new char[len]; if(NULL==curr_key_str) { HX_DELETE(k); return 0; } DB_implem* ldb = _logdb_imp; HX_RESULT ret = HXR_OK; // find the node that contains the "prop_name" *curr_key_str = '\0'; while(k->append_sub_str(curr_key_str, len)) { if (!ldb) { DPRINTF(D_REGISTRY, ("%s -- %s has NO Properties under it!\n", prop_name, curr_key_str)); ret = HXR_FAIL; goto cleanup; } *d = ldb->find(curr_key_str); if (!(*d)) { DPRINTF(D_REGISTRY, ("%s -- %s was NOT FOUND\n", prop_name, curr_key_str)); ret = HXR_PROP_NOT_FOUND; goto cleanup; } *p = (*d)->get_data(); if (!(*p)) { DPRINTF(D_REGISTRY, ("%s -- %s has NO DATA\n", prop_name, curr_key_str)); ret = HXR_FAIL; goto cleanup; } if ((*p)->get_type() == PT_COMPOSITE) (*p)->get_db_val(&ldb); } if (*d && *p) ret = HXR_OK; else ret = HXR_FAIL;cleanup: HX_VECTOR_DELETE(curr_key_str); delete k; return ret;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -