📄 commreg.cpp
字号:
delete k; HX_VECTOR_DELETE(curr_key_str); return 0; } } if (p && p->get_type() == PT_COMPOSITE) p->get_db_val(&ldb); k->append_sub_str(curr_key_str, len); if (ldb->find(curr_key_str)) { DPRINTF(D_REGISTRY, ("%s -- is ALREADY PRESENT!\n", k->get_key_str())); delete k; HX_VECTOR_DELETE(curr_key_str); return 0; } // everything is alright add the new property DB_node* new_d = _addBuf(k, curr_key_str, buf, ldb, PT_STRING); HX_VECTOR_DELETE(curr_key_str); AddDone(ldb, new_d, d, p); return new_d->get_id();}/* * Function Name: GetStr * Input Params: const char* prop_name, char*& value * Return Value: HX_RESULT * Description: * retrieves a STRING Property value from the registry given its * property name. */HX_RESULTCommonRegistry::GetStr(const char* prop_name, REF(IHXBuffer*) p_buf) const{ DB_node* d = 0; Property* p = 0; if (_find(&d, &p, prop_name) != HXR_OK) return HXR_FAIL; if (p) { switch(p->get_type()) { case PT_STRING: return p->get_buf_val(&p_buf, PT_STRING); break; default: DPRINTF(D_REGISTRY, ("%s -- Property<-->Type MISMATCH\n", prop_name)); return HXR_PROP_TYPE_MISMATCH; } } return HXR_FAIL;}/* * Function Name: GetStr * Input Params: const UINT32 hash_key, char*& value * Return Value: HX_RESULT * Description: * retrieves a STRING Property value from the registry given its * hash key. */HX_RESULTCommonRegistry::GetStr(const UINT32 hash_key, REF(IHXBuffer*) p_buf) const{ DB_node* d = 0; Property* p = 0; d = (DB_node *)_ids->get(hash_key); if (!d) { DPRINTF(D_REGISTRY, ("GetStr(%lu) failed\n", hash_key)); return HXR_FAIL; } p = d->get_data(); if (p) { switch(p->get_type()) { case PT_STRING: return p->get_buf_val(&p_buf, PT_STRING); break; default: DPRINTF(D_REGISTRY, ("%lu -- Property<-->Type MISMATCH\n", hash_key)); return HXR_PROP_TYPE_MISMATCH; } } return HXR_FAIL;}/* * Function Name: SetStr * Input Params: const char* prop_name, const IHXBuffer* value, * size_t val_len * Return Value: HX_RESULT * Description: * set the value of a STRING Property given a new value and its * CORRECT length. */HX_RESULTCommonRegistry::SetStr(const char* prop_name, IHXBuffer* p_buf){ DB_node* d = 0; Property* p = 0; if (_find(&d, &p, prop_name) != HXR_OK) return HXR_FAIL; if (!p) return HXR_FAIL; if (p->is_read_only()) { DPRINTF(D_REGISTRY, ("%s -- Property is READ ONLY\n", prop_name)); return HXR_FAIL; } switch(p->get_type()) { case PT_STRING: p->buf_val(p_buf, PT_STRING); break; default: DPRINTF(D_REGISTRY, ("%s -- Property<-->Type MISMATCH\n", prop_name)); return HXR_PROP_TYPE_MISMATCH; } // dispatch the callbacks and then return HXR_OK return SetDone(d, p);}/* * Function Name: SetStr * Input Params: const UINT32 hash_key, const IHXBuffer* value, * size_t val_len * Return Value: HX_RESULT * Description: * set the value of a STRING Property given a new value and its * CORRECT length. */HX_RESULTCommonRegistry::SetStr(const UINT32 hash_key, IHXBuffer* p_buf){ DB_node* d = 0; Property* p = 0; UINT32 h = hash_key; d = (DB_node *)_ids->get(hash_key); if (!d) { DPRINTF(D_REGISTRY, ("SetStr(%lu) failed\n", hash_key)); return HXR_FAIL; } p = d->get_data(); if (!p) return HXR_FAIL; if (p->is_read_only()) { DPRINTF(D_REGISTRY, ("%lu -- Property is READ ONLY\n", hash_key)); return HXR_FAIL; } switch(p->get_type()) { case PT_STRING: p->buf_val(p_buf, PT_STRING); break; default: DPRINTF(D_REGISTRY, ("%lu -- Property<-->Type MISMATCH\n", hash_key)); return HXR_PROP_TYPE_MISMATCH; } // dispatch the callbacks and then return HXR_OK return SetDone(d, p);}UINT32CommonRegistry::AddBuf(const char* prop_name, IHXBuffer* buf){ DPRINTF(D_REGISTRY, ("CommonRegistry::AddBuf(%s, buf(%p)\n", prop_name, buf)); DB_node* d = 0; Property* p = 0; Key* k = new Key(prop_name); if(!k) { return 0; } int len = k->size(); char* curr_key_str = new char[len]; if(!curr_key_str) { HX_DELETE(k); return 0; } DB_implem* ldb = _logdb_imp; BOOL read_only = FALSE; *curr_key_str = '\0'; while(!k->last_sub_str()) { k->append_sub_str(curr_key_str, len); if (p && p->get_type() == PT_COMPOSITE) p->get_db_val(&ldb); if (!ldb) { DPRINTF(D_REGISTRY, ("%s -- %s has NO Properties under it!\n", prop_name, curr_key_str)); HX_VECTOR_DELETE(curr_key_str); delete k; return 0; } d = ldb->find(curr_key_str); if (!d) { int ret = _buildSubstructure4Prop(curr_key_str, prop_name); if (!ret) { delete k; delete[] curr_key_str; return 0; } d = ldb->find(curr_key_str); if (!d) { delete k; delete[] curr_key_str; return 0; } } p = d->get_data(); if (!p) { DPRINTF(D_REGISTRY, ("%s -- %s has NO DATA\n", prop_name, curr_key_str)); HX_VECTOR_DELETE(curr_key_str); delete k; return 0; } read_only = p->is_read_only(); if (read_only) { DPRINTF(D_REGISTRY, ("%s -- %s is READ ONLY\n", prop_name, curr_key_str)); HX_VECTOR_DELETE(curr_key_str); delete k; return 0; } } if (p && p->get_type() == PT_COMPOSITE) p->get_db_val(&ldb); k->append_sub_str(curr_key_str, len); if (ldb->find(curr_key_str)) { DPRINTF(D_REGISTRY, ("%s -- is ALREADY PRESENT!\n", k->get_key_str())); HX_VECTOR_DELETE(curr_key_str); delete k; return 0; } // everything is alright add the new property DB_node* new_d = _addBuf(k, curr_key_str, buf, ldb); HX_VECTOR_DELETE(curr_key_str); AddDone(ldb, new_d, d, p); return new_d->get_id();}HX_RESULTCommonRegistry::GetBuf(const char* prop_name, IHXBuffer** pp_val) const{ DB_node* d = 0; Property* p = 0; if (_find(&d, &p, prop_name) != HXR_OK) return HXR_FAIL; if (p) { if (p->get_type() == PT_BUFFER) { return p->get_buf_val(pp_val); } else if (p->_alternate_string_access_ok) { return p->get_buf_val(pp_val, PT_STRING); } else { DPRINTF(D_REGISTRY, ("%s -- Property<-->Type MISMATCH\n", prop_name)); return HXR_PROP_TYPE_MISMATCH; } } return HXR_FAIL;}HX_RESULTCommonRegistry::GetBuf(const UINT32 hash_key, IHXBuffer** pp_buf) const{ DB_node* d = 0; Property* p = 0; d = (DB_node *)_ids->get(hash_key); if (!d) { DPRINTF(D_REGISTRY, ("GetBuf(%lu) failed\n", hash_key)); return HXR_FAIL; } p = d->get_data(); if (p) { if (p->get_type() == PT_BUFFER) { return p->get_buf_val(pp_buf); } else if (p->_alternate_string_access_ok) { return p->get_buf_val(pp_buf, PT_STRING); } else { DPRINTF(D_REGISTRY, ("%lu -- Property<-->Type MISMATCH\n", hash_key)); return HXR_PROP_TYPE_MISMATCH; } } return HXR_FAIL;}HX_RESULTCommonRegistry::SetBuf(const char* prop_name, IHXBuffer* p_buf){ DB_node* d = 0; Property* p = 0; if (_find(&d, &p, prop_name) != HXR_OK) return HXR_FAIL; if (!p) return HXR_FAIL; if (p->is_read_only()) { DPRINTF(D_REGISTRY, ("%s -- Property is READ ONLY\n", prop_name)); return HXR_FAIL; } if (p->get_type() == PT_BUFFER) { p->buf_val(p_buf); } else if (p->_alternate_string_access_ok) { p->buf_val(p_buf, PT_STRING); } else { DPRINTF(D_REGISTRY, ("%s -- Property<-->Type MISMATCH\n", prop_name)); return HXR_PROP_TYPE_MISMATCH; } // dispatch the callbacks and then return HXR_OK return SetDone(d, p);}HX_RESULTCommonRegistry::SetBuf(const UINT32 hash_key, IHXBuffer* p_buf){ DB_node* d = 0; Property* p = 0; UINT32 h = hash_key; d = (DB_node *)_ids->get(hash_key); if (!d) { DPRINTF(D_REGISTRY, ("GetBuf(%lu) failed\n", hash_key)); return HXR_FAIL; } p = d->get_data(); if (!p) return HXR_FAIL; if (p->is_read_only()) { DPRINTF(D_REGISTRY, ("%lu -- Property is READ ONLY\n", hash_key)); return HXR_FAIL; } switch(p->get_type()) { case PT_BUFFER: p_buf->AddRef(); p->buf_val(p_buf); p_buf->Release(); break; default: DPRINTF(D_REGISTRY, ("%lu -- Property<-->Type MISMATCH\n", hash_key)); return HXR_PROP_TYPE_MISMATCH; } // dispatch the callbacks and then return HXR_OK return SetDone(d, p);}HX_RESULTCommonRegistry::SetReadOnly(const char* pName, BOOL bValue){ DB_node* d = 0; Property* p = 0; if (_find(&d, &p, pName) != HXR_OK) return HXR_FAIL; if (!p) return HXR_FAIL; _setReadOnly(p, bValue); return HXR_OK;}HX_RESULTCommonRegistry::SetReadOnly(UINT32 ulRegId, BOOL bValue){ DB_node* d = 0; Property* p = 0; d = (DB_node *)_ids->get(ulRegId); if (!d) { DPRINTF(D_REGISTRY, ("SetReadOnly(%lu) failed\n", ulRegId)); return HXR_FAIL; } p = d->get_data(); if (!p) return HXR_FAIL; _setReadOnly(p, bValue); return HXR_OK;}UINT32CommonRegistry::AddIntRef(const char* prop_name, INT32* val){ DPRINTF(D_REGISTRY, ("CommonRegistry::AddIntRef(%s, %ld)\n", prop_name, *val)); DB_node* d = 0; Property* p = 0; Key* k = new Key(prop_name); if(!k) { return 0; } int len = k->size(); char* curr_key_str = new char[len]; if(!curr_key_str) { HX_DELETE(k); return 0; } DB_implem* ldb = _logdb_imp; BOOL read_only = FALSE; *curr_key_str = '\0'; while(!k->last_sub_str()) { k->append_sub_str(curr_key_str, len); if (p && p->get_type() == PT_COMPOSITE) p->get_db_val(&ldb); if (!ldb) { DPRINTF(D_REGISTRY, ("%s -- %s has NO Properties under it!\n", prop_name, curr_key_str)); HX_VECTOR_DELETE(curr_key_str); return 0; } d = ldb->find(curr_key_str); if (!d) { DPRINTF(D_REGISTRY, ("%s -- %s was NOT FOUND\n", prop_name, curr_key_str)); HX_VECTOR_DELETE(curr_key_str); return 0; } p = d->get_data(); if (!p) { DPRINTF(D_REGISTRY, ("%s -- %s has NO DATA\n", prop_name, curr_key_str)); HX_VECTOR_DELETE(curr_key_str); return 0; } read_only = p->is_read_only(); if (read_only) { DPRINTF(D_REGISTRY, ("%s -- %s is READ ONLY\n", prop_name, curr_key_str)); HX_VECTOR_DELETE(curr_key_str); return 0; } } if (p && p->get_type() == PT_COMPOSITE) p->get_db_val(&ldb); k->append_sub_str(curr_key_str, len); if (ldb->find(curr_key_str)) { DPRINTF(D_REGISTRY, ("%s -- is ALREADY PRESENT!\n", k->get_key_str())); HX_VECTOR_DELETE(curr_key_str); return 0; } // everything is alright add the new property DB_node* new_d = _addIntRef(k, curr_key_str, val, ldb); HX_VECTOR_DELETE(curr_key_str); AddDone(ldb, new_d, d, p); return new_d->get_id();}/* * Function Name: Del * Input Params: const char* prop_name * Return Value: UINT32 * Description: * delete a property (DB_node too) from the database given * the key string. */UINT32CommonRegistry::Del(const char* prop_name){ DB_node* d = 0; Property* p = 0; DB_implem* ldb = 0; if (_find(&d, &p, prop_name) != HXR_OK) return 0; if (!p) { DPRINTF(D_REGISTRY, ("%s -- has NO DATA\n", prop_name)); return 0; } // XXXDPS - Currently we do not check if any of the children are read- // only before deleting the key. Thus, a user could delete a read-only // node by deleting its parent, grandparent, etc. This would slow down // the Del() call significantly in the general case because we would // have to do a search first, and abort the entire operation if any child // is read-only. So it is currently safest to write-protect a key that // has no parents (a root key, like "license" or "config"). if (p->is_read_only()) { DPRINTF(D_REGISTRY, ("%s -- is READ ONLY\n", prop_name)); return 0; } // find the DB that contains this node ldb = d->get_db(); if (!ldb) { DPRINTF(D_REGISTRY, ("%s -- has NO IMPLEMENTATION\n", prop_name)); return 0; } // here the response method doesn't exactly end this method DeleteDone(ldb, d, p); UINT32 h = d->get_id(); if (p->m_lWatchCount) { /* * Wait for the clear watches to delete the node */ p->set_deleted(ldb, d, h); return h; } return _Del(ldb, d, p, h);}/* * Function Name: Del * Input Params: const UINT32 hash_key * Return Value: UINT32 * Description:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -