Permalink
Browse files

initial commit

  • Loading branch information...
ayakamercan@chitika.com
ayakamercan@chitika.com committed Jul 27, 2012
0 parents commit 3df803950977f6cc9c8b561bbf9c7aa741fdc88b
Showing with 1,584 additions and 0 deletions.
  1. +6 −0 .gitignore
  2. +1 −0 AUTHORS
  3. +13 −0 LICENSE
  4. +38 −0 README.md
  5. BIN c_src/.cberl_nif.c.swp
  6. +17 −0 c_src/GNUmakefile
  7. +10 −0 c_src/Makefile
  8. +111 −0 c_src/callbacks.h
  9. +695 −0 c_src/cberl_nif.c
  10. +186 −0 c_src/config.h
  11. +107 −0 c_src/config_static.h
  12. +14 −0 include/cberl.hrl
  13. BIN rebar
  14. +7 −0 rebar.config
  15. +11 −0 src/cberl.app.src
  16. +252 −0 src/cberl.erl
  17. +60 −0 src/cberl_nif.erl
  18. +56 −0 test/cberl_tests.erl
@@ -0,0 +1,6 @@
+.eunit
+deps
+priv
+*.o
+*.beam
+*.plt
@@ -0,0 +1 @@
+Ali Yakamercan <ayakamercan@chitika.com>
13 LICENSE
@@ -0,0 +1,13 @@
+ Copyright 2012 Chitika Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
@@ -0,0 +1,38 @@
+CBERL
+====
+
+NIF based Erlang bindings for couchbase based on libcouchbase.
+CBERL is at very early stage of development, it only supports very basic functionality. Please submit bugs and patches if you find any.
+
+Quick Start
+---------
+if you don't have libcouchbase already installed run ./rebar get-deps then:
+
+ ./rebar compile
+ erl -pa ebin
+
+Example
+-------
+
+Make sure you have couchbase running on localhost or use cberl:new(Host) instead.
+
+ 1> {ok, Instance} = cberl:new().
+ {ok,<<>>}
+ 2> cberl:set(Instance, "fkey", "cberl").
+ ok
+ 3> cberl:mget(Instance, "fkey").
+ {ok,"cberl"}
+
+
+For more information on all the functions -> ./rebar doc
+
+TODO
+----
+
+1) Write more tests
+
+2) Support batch operations, right now all operations are performed on single key
+
+3) Add informational methods
+
+4) Make function signatures more compatible with other couchbase clients
Binary file not shown.
@@ -0,0 +1,17 @@
+DEPS=../deps
+
+all: deps
+
+clean:
+ @rm -rf $(DEPS)
+
+deps:
+ @if [ ! -d "$(DEPS)/libvbucket" ]; then \
+ mkdir -p $(DEPS);\
+ git clone https://github.com/couchbase/libvbucket.git $(DEPS)/libvbucket;\
+ git clone https://github.com/couchbase/libcouchbase.git $(DEPS)/libcouchbase;\
+ git clone https://github.com/nmathewson/Libevent.git $(DEPS)/libevent;\
+ cd $(DEPS)/libevent && ./autogen.sh && ./configure && make && make install;\
+ cd ../libvbucket && ./config/autorun.sh && ./configure && make && make install;\
+ cd ../libcouchbase && ./config/autorun.sh && ./configure --disable-couchbasemock && make && make install;\
+ fi
@@ -0,0 +1,10 @@
+# Author: YAMAMOTO Takashi
+# a stub makefile for BSD make.
+# just redirect to GNU make, which is commonly available as "gmake".
+
+TARGETS=all clean distclean
+
+.for T in ${TARGETS}
+${T}:
+ @gmake ${T}
+.endfor
@@ -0,0 +1,111 @@
+#ifndef CALLBACKS_H
+#define CALLBACKS_H
+
+#include "config.h"
+#include <string.h>
+#include <libcouchbase/couchbase.h>
+
+struct libcouchbase_callback {
+ libcouchbase_error_t error;
+ size_t size;
+ void *data;
+ int flag;
+};
+
+//libcouchbase callbacks
+static void error_callback(libcouchbase_t instance,
+ libcouchbase_error_t error,
+ const char *errinfo)
+{
+ (void)instance;
+ exit(EXIT_FAILURE);
+}
+
+static void get_callback(libcouchbase_t instance,
+ const void *cookie,
+ libcouchbase_error_t error,
+ const void *key,
+ libcouchbase_size_t nkey,
+ const void *bytes,
+ libcouchbase_size_t nbytes,
+ libcouchbase_uint32_t flags,
+ libcouchbase_cas_t cas)
+{
+ (void)key; (void)nkey; (void)flags; (void)cas;
+ struct libcouchbase_callback *cb;
+ cb = (struct libcouchbase_callback *)cookie;
+ cb->error = error;
+ cb->flag = flags;
+ if (error == LIBCOUCHBASE_SUCCESS) {
+ cb->data = malloc(nbytes);
+ memcpy(cb->data, bytes, nbytes);
+ cb->size = nbytes;
+ }
+}
+
+static void arithmetic_callback(libcouchbase_t instance,
+ const void *cookie,
+ libcouchbase_error_t error,
+ const void *key,
+ libcouchbase_size_t nkey,
+ libcouchbase_uint64_t value,
+ libcouchbase_cas_t cas)
+{
+ (void)key; (void)nkey; (void)cas;
+ struct libcouchbase_callback *cb;
+ cb = (struct libcouchbase_callback *)cookie;
+ cb->error = error;
+ cb->flag = 1;
+ if (error == LIBCOUCHBASE_SUCCESS) {
+ cb->data = &value;
+ }
+}
+static void unlock_callback(libcouchbase_t instance,
+ const void *cookie,
+ libcouchbase_error_t error,
+ const void *key, size_t nkey)
+{
+ (void)instance; (void)key; (void)nkey;
+ struct libcouchbase_callback *cb;
+ cb = (struct libcouchbase_callback *)cookie;
+ cb->error = error;
+}
+
+static void touch_callback(libcouchbase_t instance,
+ const void *cookie,
+ libcouchbase_error_t error,
+ const void *key,
+ libcouchbase_size_t nkey)
+{
+ (void)instance; (void)key; (void)nkey;
+ struct libcouchbase_callback *cb;
+ cb = (struct libcouchbase_callback *)cookie;
+ cb->error = error;
+}
+
+static void storage_callback(libcouchbase_t instance,
+ const void *cookie,
+ libcouchbase_storage_t operation,
+ libcouchbase_error_t error,
+ const void *key, size_t nkey,
+ uint64_t cas)
+{
+ (void)instance; (void)operation; (void)key;
+ (void)nkey; (void)cas;
+ struct libcouchbase_callback *cb;
+ cb = (struct libcouchbase_callback *)cookie;
+ cb->error = error;
+}
+
+static void remove_callback(libcouchbase_t instance,
+ const void *cookie,
+ libcouchbase_error_t error,
+ const void *key,
+ libcouchbase_size_t nkey)
+{
+ (void)instance; (void)key; (void)nkey;
+ struct libcouchbase_callback *cb;
+ cb = (struct libcouchbase_callback *)cookie;
+ cb->error = error;
+}
+#endif
Oops, something went wrong.

0 comments on commit 3df8039

Please sign in to comment.