You can become friends with the ConfD examples, the confd_cmd and confd_load tools source code, man pages, and UG to find answers on how to use the API.
$ find $CONFD_DIR/examples.confd/ -name "*.c" |xargs grep -n cdb_subscribe2
confd-7.5.1/examples.confd//cdb_subscription/twophase/twophase.c:256: ret = cdb_subscribe2(ss, subtype, 0, prio, &sid, 0, argv[0]);
$ find $CONFD_DIR/src/confd/tools -name "*.c" |xargs grep -n cdb_subscribe2
confd-7.5.1/src/confd/tools/confd_cmd.c:1018: OK(cdb_subscribe2(cs, CDB_SUB_RUNNING_TWOPHASE, 0, prio, &id, 0, argv[0]));
confd-7.5.1/src/confd/tools/confd_cmd.c:1102: OK(cdb_subscribe2(cs, type, 0, prio, &id, 0, argv[0]));
confd-7.5.1/src/confd/tools/confd_cmd.c:1149: OK(cdb_subscribe2(cs, subtype, 0, prio, &id, 0, argv[1]));
confd-7.5.1/src/confd/tools/src/confd_cmd.c:1018: OK(cdb_subscribe2(cs, CDB_SUB_RUNNING_TWOPHASE, 0, prio, &id, 0, argv[0]));
confd-7.5.1/src/confd/tools/src/confd_cmd.c:1102: OK(cdb_subscribe2(cs, type, 0, prio, &id, 0, argv[0]));
confd-7.5.1/src/confd/tools/src/confd_cmd.c:1149: OK(cdb_subscribe2(cs, subtype, 0, prio, &id, 0, argv[1]));
$ man $CONFD_DIR/man/man3/confd_lib_cdb.3 | col -b | sed -n -e '/int cdb_subscribe2/,/int cdb_/ p'
int cdb_subscribe2(int sock, enum cdb_sub_type type, int flags,
int priority, int *spoint, int nspace,
const char *fmt, ...);
int cdb_subscribe(int sock, int priority, int nspace, int *spoint,
int cdb_subscribe2(int sock, enum cdb_sub_type type, int flags,
int priority, int *spoint, int nspace,
const char *fmt, ...);
This function supersedes the current cdb_subscribe() and
cdb_oper_subscribe() as well as makes it possible to use the new two
phase subscription method. The cdb_sub_type is defined as:
enum cdb_sub_type {
CDB_SUB_RUNNING = 1,
CDB_SUB_RUNNING_TWOPHASE = 2,
CDB_SUB_OPERATIONAL = 3
};
The CDB subscription type CDB_SUB_RUNNING is the same as
cdb_subscribe(), CDB_SUB_OPERATIONAL is the same as
cdb_oper_subscribe(), and CDB_SUB_RUNNING_TWOPHASE does a two phase
subscription.
The flags argument should be set to 0, or a combination of:
CDB_SUB_WANT_ABORT_ON_ABORT
Normally if a subscriber is the one to abort a transaction it will
not receive an abort notification. This flags means that this
subscriber wants an abort notification even if it was the one that
called cdb_sub_abort_trans(). This flag is only valid when the
subscription type is CDB_SUB_RUNNING_TWOPHASE.
The two phase subscriptions work like this: A subscriber uses
cdb_subscribe2() with the type set to CDB_SUB_RUNNING_TWOPHASE to
register as many subscription points as required. The
cdb_subscribe_done() function is used to indicate that no more
subscription points will be registered on that particular socket. Only
after cdb_subscribe_done() is called will subscription notifications be
delivered.
Once a transaction enters prepare state all CDB two phase subscribers
will be notified in priority order (lowest priority first, subscribers
with the same priority is delivered in parallel). The
cdb_read_subscription_socket2() function will set type to
CDB_SUB_PREPARE. Once all subscribers have acknowledged the
notification by using the function
cdb_sync_subscription_socket(CDB_DONE_PRIORITY) they will subsequently
be notified when the transaction is committed. The CDB_SUB_COMMIT
notification is the same as the current subscription mechanism, so when
a transaction is committed all subscribers will be notified (again in
priority order).
When a transaction is aborted, delivery of any remaining
CDB_SUB_PREPARE notifications is cancelled. The subscribers that had
already been notified with CDB_SUB_PREPARE will be notified with
CDB_SUB_ABORT (This notification will be done in reverse order of the
CDB_SUB_PREPARE notification). The transaction could be aborted because
one of the subscribers that received CDB_SUB_PREPARE called
cdb_sub_abort_trans(), but it could also be caused for other reasons,
for example another data provider (than CDB) can abort the transaction.
Note
Two phase subscriptions are not supported for NCS.
Note
Operational and configuration subscriptions can be done on the same
socket, but in that case the notifications may be arbitrarily
interleaved, including operational notifications arriving between
different configuration notifications for the same transaction. If
this is a problem, use separate sockets for operational and
configuration subscriptions.
Errors: CONFD_ERR_MALLOC, CONFD_ERR_OS, CONFD_ERR_BADPATH,
CONFD_ERR_NOEXISTS
int cdb_subscribe_done(int sock);