Couchbase C Client  2.4.4
api3.h
Go to the documentation of this file.
1 /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  * Copyright 2014 Couchbase, Inc.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef LCB_API3_H
19 #define LCB_API3_H
20 #include <libcouchbase/kvbuf.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
60 #define LCB_CMD_BASE \
61  \
64  lcb_U32 cmdflags; \
65  \
66  \
74  lcb_U32 exptime; \
75  \
76  \
81  lcb_U64 cas; \
82  \
83  \
89  lcb_KEYBUF key; \
90  \
91  \
95  lcb_KEYBUF _hashkey
96 
99 typedef struct lcb_CMDBASE {
100  LCB_CMD_BASE;
101 } lcb_CMDBASE;
102 
112 #define LCB_CMD_SET_KEY(cmd, keybuf, keylen) \
113  LCB_KREQ_SIMPLE(&(cmd)->key, keybuf, keylen)
114 
150 #define LCB_RESP_BASE \
151  void *cookie; \
152  const void *key; \
153  lcb_SIZE nkey; \
154  lcb_cas_t cas; \
155  lcb_error_t rc; \
156  lcb_U16 version; \
157  lcb_U16 rflags;
162 typedef struct {
164 } lcb_RESPBASE;
165 
166 #define LCB_RESP_SERVER_FIELDS \
167  \
168  const char *server;
169 
174 typedef struct {
176  LCB_RESP_SERVER_FIELDS
178 
181 typedef enum {
184 
191 
194 } lcb_RESPFLAGS;
195 
209 typedef enum {
225  LCB_CALLBACK__MAX /* Number of callbacks */
227 
236 typedef void (*lcb_RESPCALLBACK)
237  (lcb_t instance, int cbtype, const lcb_RESPBASE* resp);
238 
260 LIBCOUCHBASE_API
262 lcb_install_callback3(lcb_t instance, int cbtype, lcb_RESPCALLBACK cb);
263 
275 LIBCOUCHBASE_API
277 lcb_get_callback3(lcb_t instance, int cbtype);
278 
332 LIBCOUCHBASE_API
333 void lcb_sched_enter(lcb_t instance);
334 
343 LIBCOUCHBASE_API
344 void lcb_sched_leave(lcb_t instance);
345 
346 
355 LIBCOUCHBASE_API
356 void lcb_sched_fail(lcb_t instance);
357 
372 LIBCOUCHBASE_API
373 void lcb_sched_flush(lcb_t instance);
374 
388 typedef struct {
389  LCB_CMD_BASE;
396  int lock;
397 } lcb_CMDGET;
398 
400 typedef struct {
402  const void *value;
403  lcb_SIZE nvalue;
404  void* bufh;
405  lcb_datatype_t datatype;
406  lcb_U32 itmflags;
407 } lcb_RESPGET;
408 
429 LIBCOUCHBASE_API
431 lcb_get3(lcb_t instance, const void *cookie, const lcb_CMDGET *cmd);
432 
437 
441 
463 LIBCOUCHBASE_API
465 lcb_unlock3(lcb_t instance, const void *cookie, const lcb_CMDUNLOCK *cmd);
483 typedef struct {
484  LCB_CMD_BASE;
488  lcb_int64_t delta;
491  lcb_U64 initial;
494  int create;
496 
500 typedef struct {
503  lcb_U64 value;
505 
526 LIBCOUCHBASE_API
528 lcb_counter3(lcb_t instance, const void *cookie, const lcb_CMDCOUNTER *cmd);
546 typedef struct {
547  LCB_CMD_BASE;
549  int index;
551 
559 LIBCOUCHBASE_API
561 lcb_rget3(lcb_t instance, const void *cookie, const lcb_CMDGETREPLICA *cmd);
577 typedef struct {
578  LCB_CMD_BASE;
579 
584  lcb_U32 flags;
586  lcb_datatype_t datatype;
589 } lcb_CMDSTORE;
590 
591 typedef struct {
593  lcb_storage_t op;
594 } lcb_RESPSTORE;
595 
604 #define LCB_CMD_SET_VALUE(scmd, valbuf, vallen) do { \
605  (scmd)->value.vtype = LCB_KV_COPY; \
606  (scmd)->value.u_buf.contig.bytes = valbuf; \
607  (scmd)->value.u_buf.contig.nbytes = vallen; \
608 } while (0);
609 
630 LIBCOUCHBASE_API
632 lcb_store3(lcb_t instance, const void *cookie, const lcb_CMDSTORE *cmd);
648 
659 
675 LIBCOUCHBASE_API
677 lcb_remove3(lcb_t instance, const void *cookie, const lcb_CMDREMOVE * cmd);
695 
699 
716 LIBCOUCHBASE_API
718 lcb_touch3(lcb_t instance, const void *cookie, const lcb_CMDTOUCH *cmd);
730 
734 #define LCB_CMDSTATS_F_KV (1 << 16)
735 
740 typedef struct {
742  LCB_RESP_SERVER_FIELDS
743  const char *value;
744  lcb_SIZE nvalue;
745 } lcb_RESPSTATS;
746 
747 
789 LIBCOUCHBASE_API
791 lcb_stats3(lcb_t instance, const void *cookie, const lcb_CMDSTATS * cmd);
826 typedef struct lcb_MULTICMD_CTX_st {
833  lcb_error_t (*addcmd)(struct lcb_MULTICMD_CTX_st *ctx, const lcb_CMDBASE *cmd);
834 
844  lcb_error_t (*done)(struct lcb_MULTICMD_CTX_st *ctx, const void *cookie);
845 
853  void (*fail)(struct lcb_MULTICMD_CTX_st *ctx);
855 
862 #define LCB_CMDOBSERVE_F_MASTER_ONLY 1<<16
863 
869 
875 typedef struct {
877  lcb_U8 status;
878  lcb_U8 ismaster;
879  lcb_U32 ttp;
880  lcb_U32 ttr;
882 
916 LIBCOUCHBASE_API
918 lcb_observe3_ctxnew(lcb_t instance);
933 
935 typedef struct {
937  lcb_U16 nresponses;
938  lcb_U8 exists_master;
940  lcb_U8 npersisted;
941  lcb_U8 nreplicated;
943 
957 LIBCOUCHBASE_API
959 lcb_endure3_ctxnew(lcb_t instance,
960  const lcb_durability_opts_t *options, lcb_error_t *err);
971 typedef struct {
973  LCB_RESP_SERVER_FIELDS
974  const char *mcversion;
975  lcb_SIZE nversion;
977 
979 LIBCOUCHBASE_API
981 lcb_server_versions3(lcb_t instance, const void *cookie, const lcb_CMDBASE * cmd);
987 typedef struct {
988  /* unused */
989  LCB_CMD_BASE;
990  const char *server;
991  lcb_verbosity_level_t level;
992 } lcb_CMDVERBOSITY;
995 LIBCOUCHBASE_API
997 lcb_server_verbosity3(lcb_t instance, const void *cookie, const lcb_CMDVERBOSITY *cmd);
1005 typedef lcb_CMDBASE lcb_CMDFLUSH;
1008 LIBCOUCHBASE_API
1010 lcb_flush3(lcb_t instance, const void *cookie, const lcb_CMDFLUSH *cmd);
1024 #define LCB_CMDHTTP_F_STREAM 1<<16
1025 
1030 typedef struct {
1031  LCB_CMD_BASE;
1041  const char *body;
1042 
1044  lcb_SIZE nbody;
1045 
1048  lcb_http_request_t *reqhandle;
1049 
1051  const char *content_type;
1052 
1055  const char *username;
1056 
1059  const char *password;
1060 
1063  const char *host;
1064 } lcb_CMDHTTP;
1065 
1066 typedef struct {
1068  short htstatus;
1069  const char * const * headers;
1070  const void *body;
1071  lcb_SIZE nbody;
1072  lcb_http_request_t _htreq; /* Private */
1073 } lcb_RESPHTTP;
1074 
1075 LIBCOUCHBASE_API
1077 lcb_http3(lcb_t instance, const void *cookie, const lcb_CMDHTTP *cmd);
1081 #ifdef __cplusplus
1082 }
1083 #endif
1084 
1085 #endif /* LCB_API3_H */
const void * value
Value buffer for the item.
Definition: api3.h:402
lcb_error_t lcb_server_verbosity3(lcb_t instance, const void *cookie, const lcb_CMDVERBOSITY *cmd)
lcb_RESPBASE lcb_RESPTOUCH
Response structure for a touch request.
Definition: api3.h:698
lcb_MULTICMD_CTX * lcb_observe3_ctxnew(lcb_t instance)
Create a new multi context for an observe operation.
The response was a result of a not-my-vbucket error.
Definition: api3.h:193
lcb_http_type_t type
Type of request to issue.
Definition: api3.h:1036
lcb_touch3()
Definition: api3.h:214
No more responses are to be received for this request.
Definition: api3.h:183
Command for retrieving a single item.
Definition: api3.h:388
lcb_observe3_ctxnew()
Definition: api3.h:221
lcb_U64 initial
If the item does not exist on the server (and create is true) then this will be the initial value for...
Definition: api3.h:491
Options for lcb_durability_poll() (wrapper)
Definition: couchbase.h:1897
lcb_replica_t strategy
Strategy to use for selecting a replica.
Definition: api3.h:548
lcb_get3()
Definition: api3.h:211
Response structure for the version command.
Definition: api3.h:971
const char * password
Password to authenticate with, if left empty, will use the credentials passed to lcb_create() ...
Definition: api3.h:1059
lcb_storage_t operation
Must be assigned.
Definition: api3.h:588
Command for counter operations.
Definition: api3.h:483
lcb_verbosity_level_t
level field for lcb_set_verbosity()
Definition: couchbase.h:2266
lcb_SIZE nversion
Length of the version string.
Definition: api3.h:975
lcb_error_t lcb_touch3(lcb_t instance, const void *cookie, const lcb_CMDTOUCH *cmd)
Spool a touch request.
Command for requesting an item from a replica.
Definition: api3.h:546
lcb_remove3()
Definition: api3.h:215
void lcb_sched_leave(lcb_t instance)
Leave the current scheduling context, scheduling the commands within the context to be flushed to the...
lcb_CMDBASE lcb_CMDSTATS
Command structure for stats request The lcb_CMDSTATS::key field should contain the statistics key...
Definition: api3.h:729
void(* lcb_RESPCALLBACK)(lcb_t instance, int cbtype, const lcb_RESPBASE *resp)
Callback invoked for responses.
Definition: api3.h:237
The response was artificially generated inside the client.
Definition: api3.h:190
lcb_CMDBASE lcb_CMDREMOVE
Command for removing an item from the server.
Definition: api3.h:647
lcb_http_method_t
HTTP Request method enumeration These just enumerate the various types of HTTP request methods suppor...
Definition: couchbase.h:2455
lcb_CMDBASE lcb_CMDENDURE
Command structure for endure.
Definition: api3.h:932
lcb_int64_t delta
Delta value.
Definition: api3.h:488
lcb_RESPCALLBACK lcb_get_callback3(lcb_t instance, int cbtype)
lcb_flush3()
Definition: api3.h:220
Response structure for counter operations.
Definition: api3.h:500
const char * host
If set, this must be a string in the form of http://host:port.
Definition: api3.h:1063
const char * value
The value, if any, for the given statistic.
Definition: api3.h:743
lcb_U8 exists_master
True if the item exists in master's cache.
Definition: api3.h:938
lcb_error_t lcb_counter3(lcb_t instance, const void *cookie, const lcb_CMDCOUNTER *cmd)
Spool a single counter operation.
lcb_error_t lcb_get3(lcb_t instance, const void *cookie, const lcb_CMDGET *cmd)
Spool a single get operation.
lcb_error_t lcb_flush3(lcb_t instance, const void *cookie, const lcb_CMDFLUSH *cmd)
lcb_storage_t
operation parameter for lcb_store()
Definition: couchbase.h:1203
lcb_stats3()
Definition: api3.h:217
const char * mcversion
The version string.
Definition: api3.h:974
lcb_error_t lcb_stats3(lcb_t instance, const void *cookie, const lcb_CMDSTATS *cmd)
Spool a request for statistics from the cluster.
void lcb_sched_fail(lcb_t instance)
Fail all commands in the current scheduling context.
lcb_U8 status
Bit set of flags.
Definition: api3.h:877
lcb_http3()
Definition: api3.h:224
Multi Command Context API Some commands (notably, OBSERVE and its higher level equivalent, endue) are handled more efficiently at the cluster side by stuffing multiple items into a single packet.
Definition: api3.h:826
Default callback invoked as a fallback.
Definition: api3.h:210
lcb_error_t lcb_unlock3(lcb_t instance, const void *cookie, const lcb_CMDUNLOCK *cmd)
Unlock a previously locked item using lcb_CMDGET::lock.
lcb_RESPFLAGS
Response flags.
Definition: api3.h:181
lcb_RESPCALLBACK lcb_install_callback3(lcb_t instance, int cbtype, lcb_RESPCALLBACK cb)
lcb_U8 ismaster
Set to true if this response came from the master node.
Definition: api3.h:878
lcb_SIZE nvalue
Length of value.
Definition: api3.h:403
lcb_CMDBASE lcb_CMDTOUCH
Command structure for a touch request.
Definition: api3.h:694
lcb_endure3_ctxnew()
Definition: api3.h:223
lcb_replica_t
Select get-replica mode.
Definition: couchbase.h:1014
lcb_error_t lcb_server_versions3(lcb_t instance, const void *cookie, const lcb_CMDBASE *cmd)
lcb_datatype_t datatype
Ignored for now.
Definition: api3.h:586
Low level structures used by commands for buffers.
int lock
If set to true, the exptime field inside options will take to mean the time the lock should be held...
Definition: api3.h:396
int create
Boolean value.
Definition: api3.h:494
lcb_U8 npersisted
How many nodes was this item persisted to.
Definition: api3.h:940
Response structure when retrieving a single item.
Definition: api3.h:400
lcb_U32 flags
These flags are stored alongside the item on the server.
Definition: api3.h:584
Base response structure for callbacks.
Definition: api3.h:162
const char * content_type
For views, set this to application/json
Definition: api3.h:1051
Structure for performing an HTTP request.
Definition: api3.h:1030
lcb_RESPBASE lcb_RESPREMOVE
Response structure for removal operation.
Definition: api3.h:658
const char * body
If the request requires a body (e.g.
Definition: api3.h:1041
lcb_error_t lcb_rget3(lcb_t instance, const void *cookie, const lcb_CMDGETREPLICA *cmd)
Spool a single get-with-replica request.
Base structure for informational commands from servers This contains an additional lcb_RESPSERVERBASE...
Definition: api3.h:174
Response structure for cluster statistics.
Definition: api3.h:740
lcb_error_t
Error codes returned by the library.
Definition: error.h:425
Response structure for an observe command.
Definition: api3.h:875
lcb_U8 nreplicated
How many nodes was this item replicated to.
Definition: api3.h:941
lcb_U32 ttr
Unused.
Definition: api3.h:880
lcb_VALBUF value
Value to store on the server.
Definition: api3.h:581
Response structure for endure.
Definition: api3.h:935
const char * username
Username to authenticate with, if left empty, will use the credentials passed to lcb_create() ...
Definition: api3.h:1055
lcb_U16 nresponses
Total number of polls needed for this item.
Definition: api3.h:937
lcb_unlock3()
Definition: api3.h:216
lcb_U32 itmflags
User-defined flags for the item.
Definition: api3.h:406
lcb_SIZE nbody
Length of the body for the request.
Definition: api3.h:1044
lcb_server_verbosity3()
Definition: api3.h:219
lcb_server_versions3()
Definition: api3.h:218
Common ABI header for all commands.
Definition: api3.h:99
Command for storing an item to the server.
Definition: api3.h:577
#define LCB_RESP_BASE
Response specific flags.
Definition: api3.h:150
lcb_http_request_t * reqhandle
If non-NULL, will be assigned a handle which may be used to subsequently cancel the request...
Definition: api3.h:1048
lcb_CMDBASE lcb_CMDUNLOCK
Command for lcb_unlock3()
Definition: api3.h:436
lcb_error_t lcb_remove3(lcb_t instance, const void *cookie, const lcb_CMDREMOVE *cmd)
Spool a removal of an item.
lcb_U64 value
Contains the current value after the operation was performed.
Definition: api3.h:503
lcb_counter3()
Definition: api3.h:213
lcb_http_type_t
The type of HTTP request to execute.
Definition: couchbase.h:2427
lcb_error_t lcb_store3(lcb_t instance, const void *cookie, const lcb_CMDSTORE *cmd)
Spool a single storage request.
lcb_store3()
Definition: api3.h:212
lcb_CALLBACKTYPE
The type of response passed to the callback.
Definition: api3.h:209
Structure representing a value to be stored.
Definition: kvbuf.h:100
lcb_MULTICMD_CTX * lcb_endure3_ctxnew(lcb_t instance, const lcb_durability_opts_t *options, lcb_error_t *err)
Return a new command context for scheduling endure operations.
lcb_http_method_t method
HTTP Method to use.
Definition: api3.h:1037
lcb_rget3()
Definition: api3.h:222
void lcb_sched_flush(lcb_t instance)
Request commands to be flushed to the network.
lcb_U8 persisted_master
True if item exists in master's disk.
Definition: api3.h:939
void lcb_sched_enter(lcb_t instance)
Enter a scheduling context.
lcb_RESPBASE lcb_RESPUNLOCK
Response structure for an unlock command.
Definition: api3.h:440
lcb_CMDBASE lcb_CMDOBSERVE
Structure for an observe request.
Definition: api3.h:868
lcb_U32 ttp
Unused.
Definition: api3.h:879