Thanks for the suggestion. But I have to say sorry that I haven’t described my question clearly.
What I wanna know is that when I do the no operations is the iter able to store the old value in oldv like it does when do the operation of setting new value?
enum cdb_iter_ret (*iter) (confd_hkeypath_t *kp, enum cdb_iter_op op, confd_value_t *oldv,
confd_value_t *newv, void *state)
the following is the code flow:
epoll_handler()
{
cdb_read_subscription_socket(fd, sub_points, &reslen);
if (reslen > 0)
{
for (i = 0; i < reslen; i++)
{
cdb_diff_iterate(subsock, sub_points[i], cdb_iter, ITER_WANT_PREV, NULL);
}
}
}
static enum cdb_iter_ret cdb_iter(confd_hkeypath_t *kp,
enum cdb_iter_op op,
confd_value_t *oldv,
confd_value_t *newv,
void *state)
{
char xpath[BUFSIZ] = "Empty";
char nval[BUFSIZ] = "Empty";
char oval[BUFSIZ] = "Empty";
if (kp)
confd_pp_kpath(xpath, BUFSIZ, kp);
if (newv)
confd_pp_value(nval, BUFSIZ, newv);
if (oldv)
confd_pp_value(oval, BUFSIZ, oldv);
switch (op)
{
case MOP_CREATED:
_DBG("CREATED on %s with (oldv) %s -> (newv) %s\n", xpath, oval, nval);
break;
case MOP_DELETED:
_DBG("DELETED on %s with (oldv) %s -> (newv) %s\n", xpath, oval, nval);
break;
case MOP_MODIFIED:
_DBG("MODIFIED on %s with (oldv) %s -> (newv) %s\n", xpath, oval, nval);
break;
case MOP_VALUE_SET:
_DBG("VALUE_SET on %s with (oldv) %s -> (newv) %s\n", xpath, oval, nval);
break;
default:
printf("should never run here!\n");
break;
}
return ITER_RECURSE;
}
You see, I didn’t start the any session myself, and just called cdb_diff_iterate() with the flag ITER_WANT_PREV, It works well as expected, when I set different value to the leaf,
-- VALUE_SET on /demo/pass with (oldv) 2 -> (newv) b
-- VALUE_SET on /demo/user with (oldv) 1 -> (newv) a
but It seems failed when no operations given, the oldv is Empty
-- DELETED on /demo/pass with (oldv) Empty -> (newv) Empty
-- DELETED on /demo/user with (oldv) Empty -> (newv) Empty
Do I have the call cdb_start_session(readsock, CDB_PRE_COMMIT_RUNNING) on readsock,with db type CDB_PRE_COMMIT_RUNNING, and get the old value myself?