c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#ifndef DICT_PRIVATE_H
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#define DICT_PRIVATE_H
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen
e28b4fc2b62be020156a857485b61842b3b5d791Timo Sirainen#include <time.h>
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen#include "dict.h"
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainenstruct dict_vfuncs {
10399559650f552a23949772be79eb6a80198c5aTimo Sirainen int (*init)(struct dict *dict_driver, const char *uri,
39ea5717264668e2c7f9f7986eb821d21785f47fTimo Sirainen const struct dict_settings *set,
eca38954bcf972618f6b85932a3690acbd2b673aTimo Sirainen struct dict **dict_r, const char **error_r);
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen void (*deinit)(struct dict *dict);
c4478af52de63804efef2055580adf1dfc8679c6Timo Sirainen void (*wait)(struct dict *dict);
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen
f8ead0942a9b7c8fcf91414ed1b534d5807ca555Timo Sirainen int (*lookup)(struct dict *dict, pool_t pool,
b5052fbfdbc2678cc8f12899afe55c998f43b740Timo Sirainen const char *key, const char **value_r,
b5052fbfdbc2678cc8f12899afe55c998f43b740Timo Sirainen const char **error_r);
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen struct dict_iterate_context *
9c7f6dbf65ca01026e5f9c8c8b67c7e629c0b5e7Timo Sirainen (*iterate_init)(struct dict *dict, const char *const *paths,
92d1458b00f4f236c4cec96a696253d3bbf8b05aTimo Sirainen enum dict_iterate_flags flags);
8d25b6ad05b99e75613cb045a121efd51e6afbb6Timo Sirainen bool (*iterate)(struct dict_iterate_context *ctx,
8d25b6ad05b99e75613cb045a121efd51e6afbb6Timo Sirainen const char **key_r, const char **value_r);
055389c58fa3915e12fb4e72ec86782ce77c5c72Timo Sirainen int (*iterate_deinit)(struct dict_iterate_context *ctx,
055389c58fa3915e12fb4e72ec86782ce77c5c72Timo Sirainen const char **error_r);
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen struct dict_transaction_context *(*transaction_init)(struct dict *dict);
c2a66e7950cb4d3fc4d68e4480ea8f39bdd7c871Timo Sirainen /* call the callback before returning if non-async commits */
c2a66e7950cb4d3fc4d68e4480ea8f39bdd7c871Timo Sirainen void (*transaction_commit)(struct dict_transaction_context *ctx,
c2a66e7950cb4d3fc4d68e4480ea8f39bdd7c871Timo Sirainen bool async,
c2a66e7950cb4d3fc4d68e4480ea8f39bdd7c871Timo Sirainen dict_transaction_commit_callback_t *callback,
c2a66e7950cb4d3fc4d68e4480ea8f39bdd7c871Timo Sirainen void *context);
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen void (*transaction_rollback)(struct dict_transaction_context *ctx);
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen void (*set)(struct dict_transaction_context *ctx,
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen const char *key, const char *value);
92d1458b00f4f236c4cec96a696253d3bbf8b05aTimo Sirainen void (*unset)(struct dict_transaction_context *ctx,
92d1458b00f4f236c4cec96a696253d3bbf8b05aTimo Sirainen const char *key);
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen void (*atomic_inc)(struct dict_transaction_context *ctx,
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen const char *key, long long diff);
d694b6009574ee6e3cfaee3834cbdbcd431affb0Timo Sirainen
d694b6009574ee6e3cfaee3834cbdbcd431affb0Timo Sirainen void (*lookup_async)(struct dict *dict, const char *key,
d694b6009574ee6e3cfaee3834cbdbcd431affb0Timo Sirainen dict_lookup_callback_t *callback, void *context);
a5ec9755556e3d97d7e6d78cb1b53046370e6598Timo Sirainen bool (*switch_ioloop)(struct dict *dict);
e28b4fc2b62be020156a857485b61842b3b5d791Timo Sirainen void (*set_timestamp)(struct dict_transaction_context *ctx,
e28b4fc2b62be020156a857485b61842b3b5d791Timo Sirainen const struct timespec *ts);
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen};
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainenstruct dict {
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen const char *name;
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen struct dict_vfuncs v;
b198cd6da331eb55d300b0e83f59695c58d5885cTimo Sirainen unsigned int iter_count;
f32da6b73c1edb6963eae0d4a5c1f995ad23151aAki Tuomi unsigned int transaction_count;
5012586ed3a75857ced48302bf0b8a8dc049796aTimo Sirainen struct dict_transaction_context *transactions;
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen};
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainenstruct dict_iterate_context {
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen struct dict *dict;
d694b6009574ee6e3cfaee3834cbdbcd431affb0Timo Sirainen
d694b6009574ee6e3cfaee3834cbdbcd431affb0Timo Sirainen dict_iterate_callback_t *async_callback;
d694b6009574ee6e3cfaee3834cbdbcd431affb0Timo Sirainen void *async_context;
d694b6009574ee6e3cfaee3834cbdbcd431affb0Timo Sirainen
6acd1a48e1377e74d3008288e5e95e006f41265cTimo Sirainen uint64_t row_count, max_rows;
6acd1a48e1377e74d3008288e5e95e006f41265cTimo Sirainen
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool has_more:1;
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen};
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainenstruct dict_transaction_context {
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen struct dict *dict;
5012586ed3a75857ced48302bf0b8a8dc049796aTimo Sirainen struct dict_transaction_context *prev, *next;
2be7df5df08ac4639ad83559ec5fcf552c84fb4aTimo Sirainen
e28b4fc2b62be020156a857485b61842b3b5d791Timo Sirainen struct timespec timestamp;
e28b4fc2b62be020156a857485b61842b3b5d791Timo Sirainen
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool changed:1;
aef407f147034a569591c0f59593342a8c7b39eaTimo Sirainen bool no_slowness_warning:1;
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen};
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen
701eb90460d6c57845dc4e0bf595a5d0b90b01c1Timo Sirainenvoid dict_transaction_commit_async_noop_callback(
701eb90460d6c57845dc4e0bf595a5d0b90b01c1Timo Sirainen const struct dict_commit_result *result, void *context);
701eb90460d6c57845dc4e0bf595a5d0b90b01c1Timo Sirainen
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainenextern struct dict dict_driver_client;
31257b47d47510ceb093a6b218810a1a5b830c55Timo Sirainenextern struct dict dict_driver_file;
9686ada8061745b4b8753572f6c04b7a27a8544eTimo Sirainenextern struct dict dict_driver_fs;
fefd62f9aaccecbc6011ecae359a3389668cbff5Timo Sirainenextern struct dict dict_driver_memcached;
75bb83681e30d6a86109bbafdfe6b513c11124bcTimo Sirainenextern struct dict dict_driver_memcached_ascii;
31257b47d47510ceb093a6b218810a1a5b830c55Timo Sirainenextern struct dict dict_driver_redis;
09b15d7b0619e8a1ad5a78b1f86b864a7f76b3c7Timo Sirainenextern struct dict dict_driver_cdb;
d70bf110f2f37ab5315a250c2367f164069755adAki Tuomiextern struct dict dict_driver_fail;
d70bf110f2f37ab5315a250c2367f164069755adAki Tuomi
d70bf110f2f37ab5315a250c2367f164069755adAki Tuomiextern struct dict_iterate_context dict_iter_unsupported;
d70bf110f2f37ab5315a250c2367f164069755adAki Tuomiextern struct dict_transaction_context dict_transaction_unsupported;
e3fabe8d0faa9aab7cae2d0eee9653f581a3061dTimo Sirainen
28c75d59f1d1a7caeb85635964f3881c0038eb23Timo Sirainen#endif