Various cleanup/fleshout
This commit is contained in:
parent
ceb66315e7
commit
f1c52ba1c9
13
Rakefile
13
Rakefile
|
@ -9,20 +9,23 @@ CLOBBER.include %w( c_src/system )
|
||||||
directory 'c_src'
|
directory 'c_src'
|
||||||
|
|
||||||
DB_LIB = "c_src/system/lib/libdb.a"
|
DB_LIB = "c_src/system/lib/libdb.a"
|
||||||
|
DRIVER = "priv/bdberl_drv.so"
|
||||||
|
|
||||||
file DB_LIB do
|
file DB_LIB do
|
||||||
sh "cd c_src && ./buildlib.sh 2>&1"
|
sh "cd c_src && ./buildlib.sh 2>&1"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
file DRIVER do
|
||||||
|
puts "linking priv/#{DRIVER}..."
|
||||||
|
sh "gcc #{erts_link_cflags()} c_src/*.o c_src/system/lib/libdb-*.a -o #{DRIVER}", :verbose => false
|
||||||
|
end
|
||||||
|
|
||||||
rule ".o" => ["%X.c"] do |t|
|
rule ".o" => ["%X.c"] do |t|
|
||||||
puts "compiling #{t.source}..."
|
puts "compiling #{t.source}..."
|
||||||
sh "gcc -c -Wall -Werror -Ic_src/system/include -I#{erts_dir()}/include #{t.source} -o #{t.name}", :verbose => false
|
sh "gcc -c -Wall -Werror -Ic_src/system/include -I#{erts_dir()}/include #{t.source} -o #{t.name}", :verbose => false
|
||||||
end
|
end
|
||||||
|
|
||||||
task :compile_c => ['c_src'] + C_OBJS do
|
task :compile_c => ['c_src'] + C_OBJS
|
||||||
puts "linking c_src/bdberl_drv.so..."
|
|
||||||
sh "gcc #{erts_link_cflags()} c_src/*.o c_src/system/lib/libdb-*.a -o priv/bdberl_drv.so", :verbose => false
|
|
||||||
end
|
|
||||||
|
|
||||||
task :compile => [DB_LIB, :compile_c]
|
task :compile => [DB_LIB, :compile_c, DRIVER]
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,6 @@ def erl_app_modules(app)
|
||||||
ERL
|
ERL
|
||||||
|
|
||||||
output = erl_run(script, "-pa ebin")
|
output = erl_run(script, "-pa ebin")
|
||||||
puts output
|
|
||||||
if output[/badmatch/]
|
if output[/badmatch/]
|
||||||
fail "Error processing .app file: ", output
|
fail "Error processing .app file: ", output
|
||||||
""
|
""
|
||||||
|
|
|
@ -24,10 +24,15 @@ static int bdberl_drv_control(ErlDrvData handle, unsigned int cmd,
|
||||||
char* inbuf, int inbuf_sz,
|
char* inbuf, int inbuf_sz,
|
||||||
char** outbuf, int outbuf_sz);
|
char** outbuf, int outbuf_sz);
|
||||||
|
|
||||||
|
static void bdberl_ready_async(ErlDrvData handle, ErlDrvThreadData thread_data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command codes
|
* Command codes
|
||||||
*/
|
*/
|
||||||
#define CMD_PARSE 0
|
#define CMD_OPEN_DB 0
|
||||||
|
#define CMD_CLOSE_DB 1
|
||||||
|
#define CMD_GET 2
|
||||||
|
#define CMD_PUT 3
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Driver Entry
|
* Driver Entry
|
||||||
|
@ -46,7 +51,7 @@ ErlDrvEntry bdberl_drv_entry =
|
||||||
bdberl_drv_control, /* F_PTR control, port_command callback */
|
bdberl_drv_control, /* F_PTR control, port_command callback */
|
||||||
NULL, /* F_PTR timeout, reserved */
|
NULL, /* F_PTR timeout, reserved */
|
||||||
NULL, /* F_PTR outputv, reserved */
|
NULL, /* F_PTR outputv, reserved */
|
||||||
NULL, /* F_PTR ready_async */
|
bdberl_ready_async, /* F_PTR ready_async */
|
||||||
NULL, /* F_PTR flush */
|
NULL, /* F_PTR flush */
|
||||||
NULL, /* F_PTR call */
|
NULL, /* F_PTR call */
|
||||||
NULL, /* F_PTR event */
|
NULL, /* F_PTR event */
|
||||||
|
@ -105,3 +110,7 @@ static int bdberl_drv_control(ErlDrvData handle, unsigned int cmd,
|
||||||
*outbuf = 0;
|
*outbuf = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void bdberl_ready_async(ErlDrvData handle, ErlDrvThreadData thread_data)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
10
ebin/bdberl.app
Normal file
10
ebin/bdberl.app
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{application, bdberl,
|
||||||
|
[{description, "Berkeley DB Erlang Driver"},
|
||||||
|
{vsn, "1"},
|
||||||
|
{modules, [ bdberl_port ]},
|
||||||
|
{registered, []},
|
||||||
|
{applications, [kernel,
|
||||||
|
stdlib]},
|
||||||
|
% {mod, {sparker, []}},
|
||||||
|
{env, []}
|
||||||
|
]}.
|
14
src/bdberl_port.erl
Normal file
14
src/bdberl_port.erl
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
%% -------------------------------------------------------------------
|
||||||
|
%%
|
||||||
|
%% bdberl: Port Interface
|
||||||
|
%% Copyright (c) 2008 The Hive. All rights reserved.
|
||||||
|
%%
|
||||||
|
%% -------------------------------------------------------------------
|
||||||
|
-module(bdberl_port).
|
||||||
|
|
||||||
|
-export([open/0]).
|
||||||
|
|
||||||
|
open() ->
|
||||||
|
ok = erl_ddll:load_driver(code:priv_dir(bdberl), bdberl_drv),
|
||||||
|
Port = open_port({spawn, bdberl_drv}, [binary]),
|
||||||
|
{ok, Port}.
|
Loading…
Reference in a new issue