本文整理汇总了C++中enif_make_resource函数的典型用法代码示例。如果您正苦于以下问题:C++ enif_make_resource函数的具体用法?C++ enif_make_resource怎么用?C++ enif_make_resource使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了enif_make_resource函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ex_slp_open
static ERL_NIF_TERM
ex_slp_open(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) {
char *lang;
char *ret_code;
int isasync;
unsigned int term_len;
SLPHandle *hslp;
SLPEXP SLPError SLPAPI error;
if (enif_get_atom_length(env, argv[0], &term_len, ERL_NIF_LATIN1) < 0) {
return enif_make_badarg(env);
}
if (enif_get_atom(env, argv[0], lang, term_len, ERL_NIF_LATIN1) < 0) {
return enif_make_badarg(env);
}
if ( ! enif_get_int(env, argv[1], &isasync)) return enif_make_badarg(env);
hslp = enif_alloc_resource(NIF_SLP_HANDLE, sizeof(SLPHandle));
if (hslp == NULL) return enif_make_badarg(env);
//error = SLPOpen(lang, isasync > 0 ? SLP_TRUE : SLP_FALSE, hslp);
error = SLPOpen(lang, isasync > 0 ? SLP_TRUE : SLP_FALSE, hslp);
ERL_NIF_TERM term = enif_make_resource(env, hslp);
enif_release_resource(hslp);
return enif_make_tuple2(env, enif_make_int(env, error), term);
}
示例2: create
static ERL_NIF_TERM
create(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
Example* res;
ERL_NIF_TERM ret;
unsigned int id;
Tracker* tracker;
if(argc != 1)
{
return enif_make_badarg(env);
}
if(!enif_get_uint(env, argv[0], &id))
{
return enif_make_badarg(env);
}
res = enif_alloc_resource(RES_TYPE, sizeof(Example));
if(res == NULL) return enif_make_badarg(env);
ret = enif_make_resource(env, res);
enif_release_resource(res);
res->id = id;
tracker = (Tracker*) enif_priv_data(env);
tracker->count += 1;
return enif_make_tuple2(env, atom_ok, ret);
}
示例3: nif_open
static ERL_NIF_TERM
nif_open(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
ErlNifBinary dev;
SRLY_STATE *sp = NULL;
if (!enif_inspect_iolist_as_binary(env, argv[0], (ErlNifBinary *)&dev))
return enif_make_badarg(env);
sp = enif_alloc_resource(SRLY_STATE_RESOURCE, sizeof(SRLY_STATE));
if (sp == NULL)
return error_tuple(env, ENOMEM);
if (!enif_realloc_binary(&dev, dev.size+1))
return enif_make_badarg(env);
dev.data[dev.size-1] = '\0';
sp->fd = open((char *)dev.data, O_RDWR|O_NOCTTY|O_NONBLOCK);
if (sp->fd < 0 || isatty(sp->fd) != 1) {
int err = errno;
enif_release_resource(sp);
return error_tuple(env, err);
}
return enif_make_tuple2(env,
atom_ok,
enif_make_resource(env, sp));
}
示例4: enif_make_handle
ERL_NIF_TERM enif_make_handle(ErlNifEnv* env, void* obj)
{
ERL_NIF_TERM handle;
handle = enif_make_resource(env, obj);
enif_release_resource(obj);
return handle;
}
示例5: _open
static ERL_NIF_TERM
_open(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
CAN_handle* handle;
ERL_NIF_TERM result;
char dev_path[512];
if (!enif_get_string(env, argv[0], dev_path, 512, ERL_NIF_LATIN1))
return enif_make_int(env, -2000);
handle = enif_alloc_resource(CAN_handle_type, sizeof(CAN_handle));
memset(handle, 0, sizeof(CAN_handle));
handle->device = open((const char*)dev_path, O_RDWR | O_SYNC);
if (!enif_get_int(env, argv[1], &handle->raw))
return enif_make_int(env, -2001);
handle->threaded = 0;
if (handle->device >= 0)
{
int len = strlen(dev_path);
result = enif_make_resource(env, handle);
handle->devpath = enif_alloc(len);
memcpy(handle->devpath, dev_path, len);
handle->devpath_bin = enif_make_resource_binary(env, handle, handle->devpath, len);
}
else
{
result = enif_make_int(env, errno);
}
enif_release_resource(handle);
return result;
}
示例6: open_nif
static ERL_NIF_TERM open_nif(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
posix_errno_t posix_errno;
efile_data_t *d;
ErlNifPid controlling_process;
enum efile_modes_t modes;
ERL_NIF_TERM result;
efile_path_t path;
ASSERT(argc == 2);
if(!enif_is_list(env, argv[1])) {
return enif_make_badarg(env);
}
modes = efile_translate_modelist(env, argv[1]);
if((posix_errno = efile_marshal_path(env, argv[0], &path))) {
return posix_error_to_tuple(env, posix_errno);
} else if((posix_errno = efile_open(&path, modes, efile_resource_type, &d))) {
return posix_error_to_tuple(env, posix_errno);
}
result = enif_make_resource(env, d);
enif_release_resource(d);
enif_self(env, &controlling_process);
if(enif_monitor_process(env, d, &controlling_process, &d->monitor)) {
return posix_error_to_tuple(env, EINVAL);
}
return enif_make_tuple2(env, am_ok, result);
}
示例7: _hi_open
ERL_NIF_TERM _hi_open(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
uint32_t iterator_type = 0;
if (argc != 1 ||
!enif_get_uint(env, argv[0], &iterator_type))
{
return enif_make_badarg(env);
}
if (iterator_type != HDR_ITER_REC &&
iterator_type != HDR_ITER_LIN &&
iterator_type != HDR_ITER_LOG &&
iterator_type != HDR_ITER_PCT)
{
return make_error(env, "bad_iterator_type");
}
ErlNifResourceType* ctx_type = get_hi_ctx_type(env);
hi_ctx_t* ctx = (hi_ctx_t*)enif_alloc_resource(ctx_type, sizeof(hi_ctx_t));
ctx->type = iterator_type;
ctx->opts = NULL;
ctx->iter = NULL;
ERL_NIF_TERM result = enif_make_resource(env, ctx);
enif_release_resource(ctx);
return enif_make_tuple2(env, ATOM_OK, result);
}
示例8: get_driver
/* OGRSFDriverH CPL_DLL OGRGetDriver( int );
{ok, Driver} = lgeo_ogr:get_driver(0),
*/
static ERL_NIF_TERM
get_driver(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
int driver_idx;
ERL_NIF_TERM eterm;
if (argc != 1) {
return enif_make_badarg(env);
}
if (!enif_get_int(env, argv[0], &driver_idx)) {
return enif_make_badarg(env);
}
OGRSFDriverH drv = OGRGetDriver(driver_idx);
if (!drv) {
return enif_make_tuple2(env,
enif_make_atom(env, "error"),
enif_make_string(env, "Driver not found", ERL_NIF_LATIN1));
}
OGRSFDriverH **driver = \
enif_alloc_resource(OGR_D_RESOURCE, sizeof(OGRSFDriverH*));
*driver = drv;
eterm = enif_make_resource(env, driver);
enif_release_resource(driver);
return enif_make_tuple2(env, enif_make_atom(env, "ok"), eterm);
}
示例9: l_get_layer_defn
/* OGRFeatureDefnH OGR_L_GetLayerDefn(OGRLayerH hLayer)
{ok, DataSource} = lgeo_ogr:open("test/polygon.shp"),
{ok, Layer} = lgeo_ogr:ds_get_layer(DataSource, 0),
{ok, FeatureDefn} = lgeo_ogr:l_get_layer_defn(Layer).
*/
static ERL_NIF_TERM
l_get_layer_defn(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
EnvLayer_t **layer;
ERL_NIF_TERM eterm;
if (argc != 1) {
return enif_make_badarg(env);
}
if(!enif_get_resource(env, argv[0], OGR_L_RESOURCE, (void**)&layer)) {
return enif_make_badarg(env);
}
OGRFeatureDefnH feat_defn = OGR_L_GetLayerDefn((**layer).obj);
EnvFeatureDefn_t **feature_defn = \
enif_alloc_resource(OGR_FD_RESOURCE, sizeof(EnvFeatureDefn_t*));
ErlNifEnv *feature_defn_env = enif_alloc_env();
*feature_defn = (EnvFeatureDefn_t*) enif_alloc(sizeof(EnvFeatureDefn_t));
(**feature_defn).env = feature_defn_env;
(**feature_defn).obj = feat_defn;
// Save copy of layer so is not garbage collected
enif_make_copy(feature_defn_env, argv[0]);
eterm = enif_make_resource(env, feature_defn);
enif_release_resource(feature_defn);
return enif_make_tuple2(env, enif_make_atom(env, "ok"), eterm);
}
示例10: zdoor_cb
static struct zdoor_result *
zdoor_cb(struct zdoor_cookie *cookie, char *argp, size_t argp_sz)
{
struct door *d;
struct req *r;
ErlNifEnv *env = enif_alloc_env();
/* we kept the struct door in the biscuit */
d = (struct door *)cookie->zdc_biscuit;
/* this request */
r = req_alloc();
/* take the rlist lock first, then the req lock */
enif_rwlock_rwlock(d->rlock);
enif_mutex_lock(r->lock);
req_insert(d, r);
enif_rwlock_rwunlock(d->rlock);
/* make the request into a binary term to put it into enif_send() */
ErlNifBinary bin;
enif_alloc_binary(argp_sz, &bin);
memcpy(bin.data, argp, argp_sz);
ERL_NIF_TERM binTerm = enif_make_binary(env, &bin);
/* send a message back to the session owner */
enif_send(NULL, &d->owner, env,
enif_make_tuple3(env,
enif_make_atom(env, "zdoor"),
enif_make_resource(env, r),
binTerm));
/* now wait until the request has been replied to */
enif_cond_wait(r->cond, r->lock);
/* convert the reply into a zdoor_result */
/* we have to use naked malloc() since libzdoor will use free() */
struct zdoor_result *res = malloc(sizeof(struct zdoor_result));
res->zdr_size = r->replen;
res->zdr_data = r->rep;
r->rep = NULL;
r->replen = 0;
/* yes, we have to unlock and re-lock to avoid lock inversion here */
enif_mutex_unlock(r->lock);
/* remove and free the struct req */
enif_rwlock_rwlock(d->rlock);
enif_mutex_lock(r->lock);
req_remove(d, r);
enif_rwlock_rwunlock(d->rlock);
req_free(r);
enif_free_env(env);
return res;
}
示例11: f_get_geometry
/*
{ok, DataSource} = lgeo_ogr:open("test/polygon.shp"),
{ok, Layer} = lgeo_ogr:ds_get_layer(DataSource, 0),
{ok, Feature} = lgeo_ogr:l_get_feature(Layer, 0),
{ok, Geometry} = lgeo_ogr:f_get_geometry(Feature).
*/
static ERL_NIF_TERM
f_get_geometry(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
EnvFeature_t **feature;
ERL_NIF_TERM eterm;
if (argc != 1) {
return enif_make_badarg(env);
}
if(!enif_get_resource(env, argv[0], OGR_F_RESOURCE, (void**)&feature)) {
return enif_make_badarg(env);
}
OGRGeometryH geom = OGR_F_GetGeometryRef((**feature).obj);
if(geom == NULL) {
return enif_make_atom(env, "undefined");
}
OGRGeometryH geom_clone = OGR_G_Clone(geom);
EnvGeometry_t **geometry = \
enif_alloc_resource(OGR_G_RESOURCE, sizeof(EnvGeometry_t*));
*geometry = (EnvGeometry_t*) enif_alloc(sizeof(EnvGeometry_t));
(**geometry).env = NULL;
(**geometry).obj = geom_clone;
eterm = enif_make_resource(env, geometry);
enif_release_resource(geometry);
return enif_make_tuple2(env, enif_make_atom(env, "ok"), eterm);
}
示例12: exmagick_init_handle
static
ERL_NIF_TERM exmagick_init_handle (ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
ERL_NIF_TERM result;
EXM_INIT;
ErlNifResourceType *type = (ErlNifResourceType *) enif_priv_data(env);
exm_resource_t *resource = enif_alloc_resource(type, sizeof(exm_resource_t));
if (resource == NULL)
{ EXM_FAIL(ehandler, "enif_alloc_resource"); }
/* initializes exception to default values (badly named function) */
GetExceptionInfo(&resource->e_info);
resource->image = NULL;
resource->i_info = CloneImageInfo(0);
if (resource->i_info == NULL)
{ EXM_FAIL(ehandler, "CloneImageInfo"); }
result = enif_make_resource(env, (void *) resource);
enif_release_resource(resource);
return(enif_make_tuple2(env, enif_make_atom(env, "ok"), result));
ehandler:
if (resource != NULL)
{
if (resource->i_info != NULL)
{ DestroyImageInfo(resource->i_info); }
enif_release_resource(resource);
}
return(enif_make_tuple2(env, enif_make_atom(env, "error"), exmagick_make_utf8str(env, errmsg)));
}
示例13: compile
static ERL_NIF_TERM compile(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
ErlNifBinary patternbin;
if (enif_inspect_iolist_as_binary(env, argv[0], &patternbin)) {
ERL_NIF_TERM ret;
xmlRegexpPtr xre;
char *patternstr = enif_alloc(patternbin.size + 1);
patternstr[patternbin.size] = 0;
memcpy(patternstr, patternbin.data, patternbin.size);
if ((xre = xmlRegexpCompile((xmlChar *)patternstr)) != NULL) {
struct regexp *r;
r = enif_alloc_resource(regexp_type, sizeof(struct regexp));
memset(r, 0, sizeof(*r));
r->xre = xre;
r->string = patternstr;
/* transfer ownership to calling process */
ret = enif_make_tuple2(env, am_ok(env),
enif_make_resource(env, r));
enif_release_resource(r);
} else {
enif_free(patternstr);
ret = last_error(env, "Bad Pattern");
}
return ret;
}
return enif_make_badarg(env);
}
示例14: _hh_from_binary
ERL_NIF_TERM _hh_from_binary(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
ErlNifBinary source;
if (!enif_inspect_binary(env, argv[0], &source))
{
return enif_make_badarg(env);
}
hdr_histogram_t* target = NULL;
int success = hdr_decode(source.data, source.size, &target);
if (success != 0)
{
return make_error(env, "bad_hdr_binary");
}
ErlNifResourceType* ctx_type = get_hh_ctx_type(env);
hh_ctx_t* ctx = (hh_ctx_t*)enif_alloc_resource(ctx_type, sizeof(hh_ctx_t));
ctx->data = (hdr_histogram_t*)target;
ctx->highest_trackable_value = target->highest_trackable_value;
ctx->significant_figures = target->significant_figures;
ERL_NIF_TERM result = enif_make_resource(env, ctx);
enif_release_resource(ctx);
return enif_make_tuple2(env, ATOM_OK, result);
}
示例15: add
static ERL_NIF_TERM add(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
/* add(Matrix_A, Matrix_B) -> Matrix_Sum */
unsigned i, j;
ERL_NIF_TERM ret;
mx_t mxA, mxB, mxS;
mxA.p = NULL;
mxB.p = NULL;
mxS.p = NULL;
if (!enif_get_resource(env, argv[0], resource_type, &mxA.vp) ||
!enif_get_resource(env, argv[1], resource_type, &mxB.vp) ||
mxA.p->nrows != mxB.p->nrows ||
mxB.p->ncols != mxB.p->ncols) {
return enif_make_badarg(env);
}
mxS.p = alloc_matrix(env, mxA.p->nrows, mxA.p->ncols);
for (i = 0; i < mxA.p->nrows; i++) {
for (j = 0; j < mxA.p->ncols; j++) {
POS(mxS.p, i, j) = POS(mxA.p, i, j) + POS(mxB.p, i, j);
}
}
ret = enif_make_resource(env, mxS.p);
enif_release_resource(mxS.p);
return ret;
}