Commits

Anonymous committed f0b7518

first API set.

  • Participants
  • Parent commits f2d05db
  • Branches dev

Comments (0)

Files changed (4)

 TARGET=libyatce.so
 OBJECTS=dispatcher.o tc_wrapper.o endecode.o easy_test.o \
 tc_table_operation.o \
-linked_list.o lock.o hash_map.o
+linked_list.o lock.o hash_map.o ytcadb.o
 
 CFLAGS += -fPIC -Wall -O2 #-O0 -DDEBUG_MSG #-DDEBUG_DONE
 
+#include "ytcadb.h"
+#include <stdio.h>
+#include <string.h>
+
+static ERL_NIF_TERM ytcadb_open(ErlNifEnv * env, ERL_NIF_TERM atom_tablename, ERL_NIF_TERM list_options){}
+static ERL_NIF_TERM ytcadb_close(ErlNifEnv * env, ERL_NIF_TERM atom_tablename){}
+static ERL_NIF_TERM ytcadb_put(ErlNifEnv * env, ERL_NIF_TERM atom_tablename, ERL_NIF_TERM key, ERL_NIF_TERM value){}
+static ERL_NIF_TERM ytcadb_putkeep(ErlNifEnv * env, ERL_NIF_TERM atom_tablename, ERL_NIF_TERM key, ERL_NIF_TERM value){}
+static ERL_NIF_TERM ytcadb_out(ErlNifEnv * env, ERL_NIF_TERM atom_tablename, ERL_NIF_TERM key){}
+static ERL_NIF_TERM ytcadb_get(ErlNifEnv * env, ERL_NIF_TERM atom_tablename, ERL_NIF_TERM key){}
+static ERL_NIF_TERM ytcadb_iterinit(ErlNifEnv * env, ERL_NIF_TERM atom_tablename){}
+static ERL_NIF_TERM ytcadb_iternext(ErlNifEnv * env, ERL_NIF_TERM atom_tablename){}
+static ERL_NIF_TERM ytcadb_sync(ErlNifEnv * env, ERL_NIF_TERM atom_tablename){}
+static ERL_NIF_TERM ytcadb_vanish(ErlNifEnv * env, ERL_NIF_TERM atom_tablename){}
+static ERL_NIF_TERM ytcadb_copy(ErlNifEnv * env, ERL_NIF_TERM atom_tablename, ERL_NIF_TERM string_filename){}
+static ERL_NIF_TERM ytcadb_path(ErlNifEnv * env, ERL_NIF_TERM atom_tablename){}
+static ERL_NIF_TERM ytcadb_rnum(ErlNifEnv * env, ERL_NIF_TERM atom_tablename){}
+static ERL_NIF_TERM ytcadb_size(ErlNifEnv * env, ERL_NIF_TERM atom_tablename){}
+
+p
+int load_(ErlNifEnv *env, void ** priv_data, ERL_NIF_TERM load_info){
+  return 0;
+}
+int reload_(ErlNifEnv *env, void ** priv_data, ERL_NIF_TERM load_info){
+  return 0; 
+}
+int upgrade_(ErlNifEnv *env, void ** priv_data, void ** old_priv_data, ERL_NIF_TERM load_info){
+  return 0;
+}
+void unload_(ErlNifEnv *env, void* priv_data){
+  return;
+}
+#ifndef YTCADB_H
+#define YTCADB_H
+
+#include "erl_nif.h"
+
+static ERL_NIF_TERM ytcadb_open(ErlNifEnv * env, ERL_NIF_TERM, ERL_NIF_TERM);
+static ERL_NIF_TERM ytcadb_close(ErlNifEnv * env, ERL_NIF_TERM);
+static ERL_NIF_TERM ytcadb_put(ErlNifEnv * env, ERL_NIF_TERM, ERL_NIF_TERM, ERL_NIF_TERM);
+static ERL_NIF_TERM ytcadb_putkeep(ErlNifEnv * env, ERL_NIF_TERM, ERL_NIF_TERM, ERL_NIF_TERM);
+static ERL_NIF_TERM ytcadb_out(ErlNifEnv * env, ERL_NIF_TERM, ERL_NIF_TERM);
+static ERL_NIF_TERM ytcadb_get(ErlNifEnv * env, ERL_NIF_TERM, ERL_NIF_TERM);
+static ERL_NIF_TERM ytcadb_iterinit(ErlNifEnv * env, ERL_NIF_TERM);
+static ERL_NIF_TERM ytcadb_iternext(ErlNifEnv * env, ERL_NIF_TERM);
+static ERL_NIF_TERM ytcadb_sync(ErlNifEnv * env, ERL_NIF_TERM);
+static ERL_NIF_TERM ytcadb_vanish(ErlNifEnv * env, ERL_NIF_TERM);
+static ERL_NIF_TERM ytcadb_copy(ErlNifEnv * env, ERL_NIF_TERM, ERL_NIF_TERM);
+static ERL_NIF_TERM ytcadb_path(ErlNifEnv * env, ERL_NIF_TERM);
+static ERL_NIF_TERM ytcadb_rnum(ErlNifEnv * env, ERL_NIF_TERM);
+static ERL_NIF_TERM ytcadb_size(ErlNifEnv * env, ERL_NIF_TERM);
+
+static ErlNifFunc ytcadb_funcs[] =
+{
+  {"open", 2, ytcadb_open},
+  {"close", 1, ytcadb_close},
+  {"put", 3, ytcadb_put},
+  {"putkeep", 3, ytcadb_putkeep},
+  {"out", 2, ytcadb_out},
+  {"get", 2, ytcadb_get},
+  {"iterinit", 1, ytcadb_iterinit},
+  {"iternext", 1, ytcadb_iternext},
+  {"sync", 1, ytcadb_sync},
+  {"vanish", 1, ytcadb_vanish},
+  {"copy", 2, ytcadb_copy},
+  {"path", 1, ytcadb_path},
+  {"rnum", 1, ytcadb_rnum},
+  {"size", 1, ytcadb_size}
+};
+
+int load_(ErlNifEnv *env, void ** priv_data, ERL_NIF_TERM load_info);
+int reload_(ErlNifEnv *env, void ** priv_data, ERL_NIF_TERM load_info);
+int upgrade_(ErlNifEnv *env, void ** priv_data, void ** old_priv_data, ERL_NIF_TERM load_info);
+void unload_(ErlNifEnv *env, void* priv_data);
+
+
+//ERL_NIF_INIT(test_nif,nif_funcs,NULL,NULL,NULL,NULL)
+ERL_NIF_INIT(tcadb,ytcadb_funcs,load_,reload_,upgrade_,unload_);
+
+#endif
+
 %% OO type interface, going to be compliant with tokyocabinet.idl
 %% see http://d.hatena.ne.jp/cooldaemon/20080502/1209716211
 
--export([             %%   interface ADB { //from tokyocabinet.idl
+-export([          
+	 init/0,
+   %%   interface ADB { //from tokyocabinet.idl
 	 open/2,      %%     boolean open(in string name);
 	 close/1,     %%     boolean close();
 	 put/3,       %%     boolean put(in string key, in string value);
 	 sync/1,      %%     boolean sync();
 %	 optimize/1,  %%     boolean optimize(in string params);
 	 vanish/1,    %%     boolean vanish();
-	 copy/1,      %%     boolean copy(in string path);
+	 copy/2,      %%     boolean copy(in string path);
 %	 tx/1,	      %%     boolean tranbegin();
 		      %%     boolean trancommit();
 		      %%     boolean tranabort();
 
 -spec init() -> 'ok'.
 init()->
-    erlang:load_nif(DYLIB_NAME, 0).
+    erlang:load_nif(?DYLIB_NAME, 0).
 
 -spec open( atom(), list() ) -> {ok, opened} | {error, tcadbopen_failure}.
 open(_,_)-> not_loaded.
 -spec get(atom(), key() )-> {ok, value()} | {error, record_doesnt_exist}.
 get(_,Key)-> not_loaded.
 
--spec iterinit() -> {ok, init} | {error, failed}.
+-spec iterinit(atom()) -> {ok, init} | {error, failed}.
 iterinit(_)-> not_loaded.
 
--spec iternext() -> {ok, value()} | {error, end_of_data}.
+-spec iternext(atom()) -> {ok, value()} | {error, end_of_data}.
 iternext(_)-> not_loaded.
 
--spec sync() -> {ok, sync} | {error, not_synced}.
+-spec sync(atom()) -> {ok, sync} | {error, not_synced}.
 sync(_)-> not_loaded.
 
 optimize(_)->
     {error, not_yet_supported}.
 
--spec vanish() -> {ok, vanished} | {error, not_vanished}.
+-spec vanish(atom()) -> {ok, vanished} | {error, not_vanished}.
 vanish(_)-> not_loaded.
 
 copy(_,_)-> not_loaded.
 
--spec path() -> tablename().
+-spec path(atom()) -> tablename().
 path(_)-> not_loaded.
      
--spec rnum() -> non_neg_integer().
+-spec rnum(atom()) -> non_neg_integer().
 rnum(_)-> not_loaded.
 
--spec size() -> non_neg_integer().
+-spec size(atom()) -> non_neg_integer().
 size(_)-> not_loaded.