cache_mngr: Provide nl_cache_mngr_info() to pring cache manager details

Useful for debugging and testing
This commit is contained in:
Thomas Graf 2012-04-21 15:48:37 +02:00
parent 743756f3b4
commit 516536625f
2 changed files with 44 additions and 0 deletions

View file

@ -127,6 +127,8 @@ extern int nl_cache_mngr_get_fd(struct nl_cache_mngr *);
extern int nl_cache_mngr_poll(struct nl_cache_mngr *,
int);
extern int nl_cache_mngr_data_ready(struct nl_cache_mngr *);
extern void nl_cache_mngr_info(struct nl_cache_mngr *,
struct nl_dump_params *);
extern void nl_cache_mngr_free(struct nl_cache_mngr *);
#ifdef __cplusplus

View file

@ -367,6 +367,48 @@ int nl_cache_mngr_data_ready(struct nl_cache_mngr *mngr)
return nread;
}
/**
* Print information about cache manager
* @arg mngr Cache manager
* @arg p Dumping parameters
*
* Prints information about the cache manager including all managed caches.
*
* @note This is a debugging function.
*/
void nl_cache_mngr_info(struct nl_cache_mngr *mngr, struct nl_dump_params *p)
{
char buf[128];
int i;
nl_dump_line(p, "cache-manager <%p>\n", mngr);
nl_dump_line(p, " .protocol = %s\n",
nl_nlfamily2str(mngr->cm_protocol, buf, sizeof(buf)));
nl_dump_line(p, " .flags = %#x\n", mngr->cm_flags);
nl_dump_line(p, " .nassocs = %u\n", mngr->cm_nassocs);
nl_dump_line(p, " .sock = <%p>\n", mngr->cm_sock);
for (i = 0; i < mngr->cm_nassocs; i++) {
struct nl_cache_assoc *assoc = &mngr->cm_assocs[i];
if (assoc->ca_cache) {
nl_dump_line(p, " .cache[%d] = <%p> {\n", i, assoc->ca_cache);
nl_dump_line(p, " .name = %s\n", assoc->ca_cache->c_ops->co_name);
nl_dump_line(p, " .change_func = <%p>\n", assoc->ca_change);
nl_dump_line(p, " .change_data = <%p>\n", assoc->ca_change_data);
nl_dump_line(p, " .nitems = %u\n", nl_cache_nitems(assoc->ca_cache));
nl_dump_line(p, " .objects = {\n");
p->dp_prefix += 6;
nl_cache_dump(assoc->ca_cache, p);
p->dp_prefix -= 6;
nl_dump_line(p, " }\n");
nl_dump_line(p, " }\n");
}
}
}
/**
* Free cache manager and all caches.
* @arg mngr Cache manager.