librpc
query.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2017 Two Pore Guys, Inc.
3  * All rights reserved
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted providing that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
18  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
22  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
23  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24  * POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 
28 #ifndef LIBRPC_QUERY_H
29 #define LIBRPC_QUERY_H
30 
31 #include <rpc/object.h>
32 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
48 struct rpc_query_iter;
49 
53 typedef struct rpc_query_iter *rpc_query_iter_t;
54 
68 typedef _Nullable rpc_object_t (^rpc_query_cb_t)(_Nonnull rpc_object_t object);
69 
73 #define RPC_QUERY_CB(_fn, _arg) \
74  ^(rpc_object_t _object) { \
75  return ((rpc_object_t)_fn(_arg, _object)); \
76  }
77 
102  bool single;
103  bool count;
104  uint64_t offset;
105  uint64_t limit;
106  bool reverse;
107  _Nullable rpc_array_cmp_t sort;
108  _Nullable rpc_query_cb_t callback;
109 };
110 
115 
131 _Nullable rpc_object_t rpc_query_get(_Nonnull rpc_object_t object,
132  const char *_Nonnull path, _Nullable rpc_object_t default_val);
133 
149 void rpc_query_set(_Nonnull rpc_object_t object, const char *_Nonnull path,
150  _Nullable rpc_object_t value,
151  bool steal);
152 
173 void rpc_query_delete(_Nonnull rpc_object_t object, const char *_Nonnull path);
174 
186 bool rpc_query_contains(_Nonnull rpc_object_t object, const char *_Nonnull path);
187 
243 _Nullable rpc_query_iter_t rpc_query(_Nonnull rpc_object_t object,
244  _Nullable rpc_query_params_t params, _Nullable rpc_object_t rules);
245 
260 _Nullable rpc_query_iter_t rpc_query_fmt(_Nonnull rpc_object_t object,
261  _Nonnull rpc_query_params_t params, const char *_Nonnull rules_fmt, ...);
262 
274 _Nullable rpc_object_t rpc_query_apply(_Nonnull rpc_object_t object,
275  _Nonnull rpc_object_t rules);
276 
294 bool rpc_query_next(_Nonnull rpc_query_iter_t iter,
295  _Nonnull rpc_object_t *_Nullable chunk);
296 
303 void rpc_query_iter_free(_Nonnull rpc_query_iter_t iter);
304 
305 #ifdef __cplusplus
306 }
307 #endif
308 
309 #endif /* LIBRPC_QUERY_H */
_Nullable rpc_query_iter_t rpc_query(_Nonnull rpc_object_t object, _Nullable rpc_query_params_t params, _Nullable rpc_object_t rules)
struct rpc_object * rpc_object_t
Definition: object.h:73
void rpc_query_delete(_Nonnull rpc_object_t object, const char *_Nonnull path)
_Nullable rpc_object_t(^ rpc_query_cb_t)(_Nonnull rpc_object_t object)
Definition: query.h:68
_Nullable rpc_query_iter_t rpc_query_fmt(_Nonnull rpc_object_t object, _Nonnull rpc_query_params_t params, const char *_Nonnull rules_fmt,...)
struct rpc_query_params * rpc_query_params_t
Definition: query.h:114
void rpc_query_iter_free(_Nonnull rpc_query_iter_t iter)
struct rpc_query_iter * rpc_query_iter_t
Definition: query.h:53
int(^ rpc_array_cmp_t)(_Nonnull rpc_object_t o1, _Nonnull rpc_object_t o2)
Definition: object.h:127
void rpc_query_set(_Nonnull rpc_object_t object, const char *_Nonnull path, _Nullable rpc_object_t value, bool steal)
bool rpc_query_next(_Nonnull rpc_query_iter_t iter, _Nonnull rpc_object_t *_Nullable chunk)
_Nullable rpc_object_t rpc_query_apply(_Nonnull rpc_object_t object, _Nonnull rpc_object_t rules)
_Nullable rpc_object_t rpc_query_get(_Nonnull rpc_object_t object, const char *_Nonnull path, _Nullable rpc_object_t default_val)
bool rpc_query_contains(_Nonnull rpc_object_t object, const char *_Nonnull path)