bdberl/c_src/bdberl_drv.c

117 lines
3.1 KiB
C
Raw Normal View History

2008-12-06 06:20:26 +00:00
/* -------------------------------------------------------------------
*
* bdberl: Berkeley DB Driver for Erlang
* Copyright (c) 2008 The Hive. All rights reserved.
*
* ------------------------------------------------------------------- */
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include "erl_driver.h"
#include "db.h"
/**
* Driver functions
*/
static ErlDrvData bdberl_drv_start(ErlDrvPort port, char* buffer);
static void bdberl_drv_stop(ErlDrvData handle);
static int bdberl_drv_control(ErlDrvData handle, unsigned int cmd,
char* inbuf, int inbuf_sz,
char** outbuf, int outbuf_sz);
2008-12-06 06:52:51 +00:00
static void bdberl_ready_async(ErlDrvData handle, ErlDrvThreadData thread_data);
2008-12-06 06:20:26 +00:00
/**
* Command codes
*/
2008-12-06 06:52:51 +00:00
#define CMD_OPEN_DB 0
#define CMD_CLOSE_DB 1
#define CMD_GET 2
#define CMD_PUT 3
2008-12-06 06:20:26 +00:00
/**
* Driver Entry
*/
ErlDrvEntry bdberl_drv_entry =
{
NULL, /* F_PTR init, N/A */
bdberl_drv_start, /* L_PTR start, called when port is opened */
bdberl_drv_stop, /* F_PTR stop, called when port is closed */
NULL, /* F_PTR output, called when erlang has sent */
NULL, /* F_PTR ready_input, called when input descriptor ready */
NULL, /* F_PTR ready_output, called when output descriptor ready */
"bdberl_drv", /* driver_name */
NULL, /* F_PTR finish, called when unloaded */
NULL, /* handle */
bdberl_drv_control, /* F_PTR control, port_command callback */
NULL, /* F_PTR timeout, reserved */
NULL, /* F_PTR outputv, reserved */
2008-12-06 06:52:51 +00:00
bdberl_ready_async, /* F_PTR ready_async */
2008-12-06 06:20:26 +00:00
NULL, /* F_PTR flush */
NULL, /* F_PTR call */
NULL, /* F_PTR event */
ERL_DRV_EXTENDED_MARKER,
ERL_DRV_EXTENDED_MAJOR_VERSION,
ERL_DRV_EXTENDED_MINOR_VERSION,
ERL_DRV_FLAG_USE_PORT_LOCKING,
NULL, /* Reserved */
NULL /* F_PTR process_exit */
};
/**
* Structure for holding port instance data
*/
typedef struct
{
ErlDrvPort port;
} PortData;
DRIVER_INIT(bdberl_drv)
{
return &bdberl_drv_entry;
}
static ErlDrvData bdberl_drv_start(ErlDrvPort port, char* buffer)
{
PortData* d = (PortData*)driver_alloc(sizeof(PortData));
memset(d, '\0', sizeof(PortData));
// Save handle to the port
d->port = port;
// Make sure port is running in binary mode
set_port_control_flags(port, PORT_CONTROL_FLAG_BINARY);
return (ErlDrvData)d;
}
static void bdberl_drv_stop(ErlDrvData handle)
{
// Release the port instance data
driver_free(handle);
}
static int bdberl_drv_control(ErlDrvData handle, unsigned int cmd,
char* inbuf, int inbuf_sz,
char** outbuf, int outbuf_sz)
{
//PortData* d = (PortData*)handle;
DB* dbp;
db_create(&dbp, NULL, 0);
switch(cmd)
{
}
*outbuf = 0;
return 0;
}
2008-12-06 06:52:51 +00:00
static void bdberl_ready_async(ErlDrvData handle, ErlDrvThreadData thread_data)
{
}