summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Bostic <keith@wiredtiger.com>2013-06-10 09:33:26 -0400
committerKeith Bostic <keith@wiredtiger.com>2013-06-10 09:33:48 -0400
commitbe6742a425158d1d695be2aa25f819313f9f4878 (patch)
treefe3fa400b6f3e32730ec94c9f56874ee51861a20
parent05993c03275b1a5fc36e24808567b38451c07086 (diff)
downloadmongo-be6742a425158d1d695be2aa25f819313f9f4878.tar.gz
Add some more structure to the data-source cursor-create example.
-rw-r--r--examples/c/ex_data_source.c61
1 files changed, 56 insertions, 5 deletions
diff --git a/examples/c/ex_data_source.c b/examples/c/ex_data_source.c
index 3372d1825f4..34bbeb12c30 100644
--- a/examples/c/ex_data_source.c
+++ b/examples/c/ex_data_source.c
@@ -139,19 +139,69 @@ data_source_error(int v)
return (v == 0 ? "one" : "two");
}
+static int my_cursor_next(WT_CURSOR *wtcursor)
+ { (void)wtcursor; return (0); }
+static int my_cursor_prev(WT_CURSOR *wtcursor)
+ { (void)wtcursor; return (0); }
+static int my_cursor_reset(WT_CURSOR *wtcursor)
+ { (void)wtcursor; return (0); }
+static int my_cursor_search(WT_CURSOR *wtcursor)
+ { (void)wtcursor; return (0); }
+static int my_cursor_search_near(WT_CURSOR *wtcursor, int *exactp)
+ { (void)wtcursor; (void)exactp; return (0); }
+static int my_cursor_insert(WT_CURSOR *wtcursor)
+ { (void)wtcursor; return (0); }
+static int my_cursor_update(WT_CURSOR *wtcursor)
+ { (void)wtcursor; return (0); }
+static int my_cursor_remove(WT_CURSOR *wtcursor)
+ { (void)wtcursor; return (0); }
+static int my_cursor_close(WT_CURSOR *wtcursor)
+ { (void)wtcursor; return (0); }
+
/*! [WT_DATA_SOURCE open_cursor] */
+typedef struct __my_cursor {
+ WT_CURSOR wtcursor; /* WiredTiger cursor, must come first */
+
+ /*
+ * Local cursor information: for example, we might want to have a
+ * reference to the extension functions.
+ */
+ WT_EXTENSION_API *wtext; /* Extension functions */
+} MY_CURSOR;
+
static int
my_open_cursor(WT_DATA_SOURCE *dsrc, WT_SESSION *session,
const char *uri, WT_CONFIG_ARG *config, WT_CURSOR **new_cursor)
-/*! [WT_DATA_SOURCE open_cursor] */
{
- int ret;
+ MY_CURSOR *cursor;
+
+ /* Allocate and initialize a WiredTiger cursor. */
+ if ((cursor = calloc(1, sizeof(*cursor))) == NULL)
+ return (errno);
+
+ cursor->wtcursor.next = my_cursor_next;
+ cursor->wtcursor.prev = my_cursor_prev;
+ cursor->wtcursor.reset = my_cursor_reset;
+ cursor->wtcursor.search = my_cursor_search;
+ cursor->wtcursor.search_near = my_cursor_search_near;
+ cursor->wtcursor.insert = my_cursor_insert;
+ cursor->wtcursor.update = my_cursor_update;
+ cursor->wtcursor.remove = my_cursor_remove;
+ cursor->wtcursor.close = my_cursor_close;
- /* Unused parameters */
- (void)dsrc;
+ /*
+ * Configure local cursor information.
+ */
+
+ /* Return combined cursor to WiredTiger. */
+ *new_cursor = (WT_CURSOR *)cursor;
+
+/*! [WT_DATA_SOURCE open_cursor] */
+ {
+ int ret = 0;
+ (void)dsrc; /* Unused parameters */
(void)session;
(void)uri;
- (void)config;
(void)new_cursor;
{
@@ -352,6 +402,7 @@ my_open_cursor(WT_DATA_SOURCE *dsrc, WT_SESSION *session,
/*! [WT_EXTENSION metadata update] */
}
+ }
return (0);
}