当前位置: 首页>>代码示例>>C++>>正文


C++ enif_get_resource函数代码示例

本文整理汇总了C++中enif_get_resource函数的典型用法代码示例。如果您正苦于以下问题:C++ enif_get_resource函数的具体用法?C++ enif_get_resource怎么用?C++ enif_get_resource使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了enif_get_resource函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: query_frame

// query_frame/1 :: (device, frame) -> ok | error
static ERL_NIF_TERM
query_frame(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
  device_t* dev;
  frame_t* frame;
  if (!enif_get_resource(env, argv[0], device_res, (void**) &dev) ||
      !enif_get_resource(env, argv[1], frame_res, (void**) &frame)) {
    return enif_make_badarg(env);
  }
  cvReleaseImage(&frame->_frame);
  IplImage* raw_image = (IplImage*) cvQueryFrame(dev->_device);
  IplImage* gray_image = cvCreateImage(cvGetSize(raw_image), IPL_DEPTH_8U, 1);
  cvCvtColor(raw_image, gray_image, CV_RGB2GRAY);
  frame->_frame = gray_image;
  return enif_make_atom(env, "ok");
}
开发者ID:ccprek,项目名称:parcv,代码行数:17,代码来源:ocv_nif.c

示例2: leo_mcerl_nif_delete

/**
 * Remove an object from LRU-Storage
 */
static ERL_NIF_TERM leo_mcerl_nif_delete(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) {
  lcu_cache* cache;
  String key;
  ErlNifResourceType* pert;
  ErlNifBinary keybin;

  if (argc < 2) {
    return enif_make_badarg(env);
  }

  pert = (ErlNifResourceType*)enif_priv_data(env);

  if (!enif_get_resource(env, argv[0], pert, (void**)&cache)) {
    return enif_make_badarg(env);
  }

  if (!enif_inspect_binary(env, argv[1], &keybin)) {
    return enif_make_badarg(env);
  }
  if (keybin.size <= 0) {
    return enif_make_badarg(env);
  }
  key.str = keybin.data;
  key.len = keybin.size;
  lcu_cache_delete(cache, key);
  return atom_ok;
}
开发者ID:DavidAlphaFox,项目名称:leofs,代码行数:30,代码来源:leo_mcerl_nif.c

示例3: esqlite_prepare

/*
 * Prepare the sql statement
 */
static ERL_NIF_TERM
esqlite_prepare(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
    esqlite_connection *conn;
    esqlite_command *cmd = NULL;
    ErlNifPid pid;

    if(argc != 4)
	    return enif_make_badarg(env);
    if(!enif_get_resource(env, argv[0], esqlite_connection_type, (void **) &conn))
	    return enif_make_badarg(env);
    if(!enif_is_ref(env, argv[1]))
	    return make_error_tuple(env, "invalid_ref");
    if(!enif_get_local_pid(env, argv[2], &pid))
	    return make_error_tuple(env, "invalid_pid");

    cmd = command_create();
    if(!cmd)
	    return make_error_tuple(env, "command_create_failed");

    cmd->type = cmd_prepare;
    cmd->ref = enif_make_copy(cmd->env, argv[1]);
    cmd->pid = pid;
    cmd->arg = enif_make_copy(cmd->env, argv[3]);

    return push_command(env, conn, cmd);
}
开发者ID:mmzeeman,项目名称:esqlite,代码行数:30,代码来源:esqlite3_nif.c

示例4: exmagick_num_pages

static
ERL_NIF_TERM exmagick_num_pages (ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
  exm_resource_t *resource;
  Image* image;
  int num_pages;

  EXM_INIT;
  ErlNifResourceType *type = (ErlNifResourceType *) enif_priv_data(env);

  if (0 == enif_get_resource(env, argv[0], type, (void **) &resource))
  { EXM_FAIL(ehandler, "invalid handle"); }

  if (resource->image == NULL)
  { EXM_FAIL(ehandler, "image not loaded"); }

  image = resource->image;
  num_pages = 1;

  while((image = image->next))
  { ++num_pages; }

  return(enif_make_tuple2(env, enif_make_atom(env, "ok"), enif_make_int(env, num_pages)));

ehandler:
  return(enif_make_tuple2(env, enif_make_atom(env, "error"), exmagick_make_utf8str(env, errmsg)));
}
开发者ID:Xerpa,项目名称:exmagick,代码行数:27,代码来源:exmagick.c

示例5: exmagick_image_dump_file

static
ERL_NIF_TERM exmagick_image_dump_file (ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
  char filename[MaxTextExtent];
  ErlNifBinary utf8;
  exm_resource_t *resource;

  EXM_INIT;
  ErlNifResourceType *type = (ErlNifResourceType *) enif_priv_data(env);

  if (0 == enif_get_resource(env, argv[0], type, (void **) &resource))
  { EXM_FAIL(ehandler, "invalid handle"); }

  if (0 == exmagick_get_utf8str(env, argv[1], &utf8))
  { EXM_FAIL(ehandler, "argv[1]: bad argument"); }

  exmagick_utf8strcpy (filename, &utf8, MaxTextExtent);
  if (0 == WriteImages(resource->i_info, resource->image, filename, &resource->e_info))
  {
    CatchException(&resource->e_info);
    EXM_FAIL(ehandler, resource->e_info.reason);
  }

  return(enif_make_tuple2(env, enif_make_atom(env, "ok"), argv[0]));

ehandler:
  return(enif_make_tuple2(env, enif_make_atom(env, "error"), exmagick_make_utf8str(env, errmsg)));
}
开发者ID:Xerpa,项目名称:exmagick,代码行数:28,代码来源:exmagick.c

示例6: nif_write

    static ERL_NIF_TERM
nif_write(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
    SRLY_STATE *sp = NULL;
    ErlNifBinary buf = {0};
    ssize_t n = -1;

    ERL_NIF_TERM rv = atom_ok;


    if (!enif_get_resource(env, argv[0], SRLY_STATE_RESOURCE, (void **)&sp))
        return enif_make_badarg(env);

    if (!enif_inspect_iolist_as_binary(env, argv[1], (ErlNifBinary *)&buf))
        return enif_make_badarg(env);

    n = write(sp->fd, buf.data, buf.size);

    if (n < 0)
        rv = error_tuple(env, errno);
    else if (n != buf.size)
        rv = enif_make_tuple2(env,
            atom_ok,
            enif_make_long(env, n));

    return rv;
}
开发者ID:kovyl2404,项目名称:srly,代码行数:27,代码来源:serctl.c

示例7: nif_tcgetattr

    static ERL_NIF_TERM
nif_tcgetattr(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
    SRLY_STATE *sp = NULL;
    ErlNifBinary buf = {0};

    int err = 0;


    if (!enif_get_resource(env, argv[0], SRLY_STATE_RESOURCE, (void **)&sp))
        return enif_make_badarg(env);

    if (!enif_alloc_binary(sizeof(struct termios), &buf))
        return error_tuple(env, ENOMEM);

    if (tcgetattr(sp->fd, (struct termios *)buf.data) < 0) {
        err = errno;
        enif_release_binary(&buf);
        return error_tuple(env, err);
    }

    return enif_make_tuple2(env,
        atom_ok,
        enif_make_binary(env, &buf));
}
开发者ID:jj1bdx,项目名称:srly,代码行数:25,代码来源:serctl.c

示例8: engine_remove_nif

ERL_NIF_TERM engine_remove_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{/* (Engine) */
#ifdef HAS_ENGINE_SUPPORT
    struct engine_ctx *ctx;

    // Get Engine
    ASSERT(argc == 1);

    if (!enif_get_resource(env, argv[0], engine_ctx_rtype, (void**)&ctx))
        goto bad_arg;

    if (!ENGINE_remove(ctx->engine))
        goto failed;

    return atom_ok;

 bad_arg:
    return enif_make_badarg(env);

 failed:
    return ERROR_Atom(env, "remove_engine_failed");
#else
    return atom_notsup;
#endif
}
开发者ID:bjorng,项目名称:otp,代码行数:25,代码来源:engine.c

示例9: fd_get_fields_type

/*

{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),
{ok, Types} = lgeo_ogr:fd_get_fields_type(FeatureDefn).
{"Integer","String"}
*/
static ERL_NIF_TERM
fd_get_fields_type(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    EnvFeatureDefn_t **feat_defn;
    ERL_NIF_TERM eterm;

    if (argc != 1) {
        return enif_make_badarg(env);
    }

    if(!enif_get_resource(env, argv[0], OGR_FD_RESOURCE, (void**)&feat_defn)) {
        return enif_make_badarg(env);
    }

    int count = OGR_FD_GetFieldCount((**feat_defn).obj);
    ERL_NIF_TERM *arr = (ERL_NIF_TERM *) malloc(sizeof(ERL_NIF_TERM)*count);
    int index;
    for(index=0; index<count; index++)
    {
        OGRFieldDefnH field_defn = OGR_FD_GetFieldDefn((**feat_defn).obj, index);
        arr[index] = enif_make_string(env,
            OGR_GetFieldTypeName(OGR_Fld_GetType(field_defn)),
            ERL_NIF_LATIN1);
    }

    eterm = enif_make_tuple_from_array(env, arr, index);
    free(arr);
    return enif_make_tuple2(env, enif_make_atom(env, "ok"), eterm);
}
开发者ID:namjae,项目名称:lgeo,代码行数:37,代码来源:lgeo_ogr.c

示例10: _listener

static ERL_NIF_TERM
_listener (ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
  CAN_handle* handle;
  ErlNifPid pid = { 0 }; // NOTE: breaking opaque type!
  enif_get_resource(env, argv[0], CAN_handle_type, (void**) &handle);
  if (handle->threaded) // there is a thread already and some pid!
  {
    pid = handle->receiver;
  }
  if (!enif_get_local_pid(env, argv[1], &handle->receiver)) // NOTE: use lock if pid type is structural!
    {
      handle->threaded = 0;
      return enif_make_badarg(env);
    }
  else
    {
      enif_get_uint(env, argv[2], &handle->chunk_size);
      enif_get_long(env, argv[3], &handle->timeout);
      if (!handle->threaded) // a thread was not created already
        {
          if (enif_thread_create("can_reading_thread",
              &handle->tid,
              _reading_thread,
              handle, 0))
            {
              handle->threaded = 0;
              return enif_make_int(env, -1004);
            }
        }
    }
  return pid.pid ? enif_make_pid(env, &pid) : enif_make_int(env, 0);
}
开发者ID:qoocku,项目名称:erleos,代码行数:33,代码来源:CAN_nif.c

示例11: _set_filter

static ERL_NIF_TERM
_set_filter (ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
  CAN_handle* handle;
  int flags, queueid, cob, id, mask;
  ERL_NIF_TERM result;
  if (!enif_get_resource(env, argv[0], CAN_handle_type, (void**) &handle) ||
      !enif_get_int(env, argv[1], &flags) ||
      !enif_get_int(env, argv[2], &queueid) ||
      !enif_get_int(env, argv[1], &cob) ||
      !enif_get_int(env, argv[1], &id) ||
      !enif_get_int(env, argv[1], &mask))
    return enif_make_badarg(env);
  else
    {
    canfilt_t filter = {
        /*.flags = */flags,
        /*.queid = */queueid,
        /*.cob = */cob,
        /*.id = */id,
        /*.mask = */mask
    };
    int status = ioctl(handle->device, CANQUE_FILTER, &filter);
    result = enif_make_int(env, status != 0 ? errno : status);
    }
  return result;
}
开发者ID:qoocku,项目名称:erleos,代码行数:27,代码来源:CAN_nif.c

示例12: date_get6

ERL_NIF_TERM date_get6(ErlNifEnv* env, int argc, 
    const ERL_NIF_TERM argv[])
{
    UErrorCode status = U_ZERO_ERROR;
    UCalendar* cal;
    cloner* ptr;
    int32_t year, month, day, hour, minute, second;    

    if(!((argc == 7)
      && enif_get_resource(env, argv[0], calendar_type, (void**) &ptr)  
      && enif_get_int(env, argv[1], &year)  
      && enif_get_int(env, argv[2], &month)  
      && enif_get_int(env, argv[3], &day)  
      && enif_get_int(env, argv[4], &hour)  
      && enif_get_int(env, argv[5], &minute)  
      && enif_get_int(env, argv[6], &second))) {
        return enif_make_badarg(env);
    }
    month--;

    cal = (UCalendar*) cloner_get(ptr);
    CHECK_RES(env, cal);

    ucal_setDateTime(cal,
        year,
        month,
        day,
        hour,
        minute,
        second,
        &status);
    CHECK(env, status);

    return calendar_to_double(env, (const UCalendar*) cal);
}
开发者ID:alepharchives,项目名称:i18n,代码行数:35,代码来源:i18n_date.cpp

示例13: date_get_field

ERL_NIF_TERM date_get_field(ErlNifEnv* env, int argc, 
    const ERL_NIF_TERM argv[])
{
    UErrorCode status = U_ZERO_ERROR;
    UCalendar* cal;
    cloner* ptr;
    double date;
    ERL_NIF_TERM res;


    if(!((argc == 3)
      && enif_get_resource(env, argv[0], calendar_type, (void**) &ptr)  
      && enif_get_double(env, argv[1], &date))) {
        return enif_make_badarg(env);
    }

    cal = (UCalendar*) cloner_get(ptr);
    CHECK_RES(env, cal);

    ucal_setMillis(cal, (UDate) date, &status);
    CHECK(env, status);

    res = do_date_get_field(env, cal, argv[2], status);
    CHECK(env, status);

    return res;
}
开发者ID:alepharchives,项目名称:i18n,代码行数:27,代码来源:i18n_date.cpp

示例14: histogram_stats

ERL_NIF_TERM histogram_stats(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    histogram_handle* handle;
    if (enif_get_resource(env,argv[0],histogram_RESOURCE,(void**)&handle))
    {
        pthread_mutex_lock(&(handle->m));

        std::vector<double> percentiles;
        percentiles.push_back(0.500);
        percentiles.push_back(0.950);
        percentiles.push_back(0.990);
        std::vector<double> scores(handle->p->percentiles(percentiles));

        ERL_NIF_TERM result =
                          enif_make_list8(env, 
                               STAT_TUPLE(ATOM_MIN, handle->p->min()),
                               STAT_TUPLE(ATOM_MAX, handle->p->max()),
                               STAT_TUPLE(ATOM_MEAN, handle->p->mean()),
                               STAT_TUPLE(ATOM_COUNT, handle->p->count()),
                               STAT_TUPLE(ATOM_STDDEV, handle->p->stddev()),
                               STAT_TUPLE(ATOM_P50, scores[0]),
                               STAT_TUPLE(ATOM_P95, scores[1]),
                               STAT_TUPLE(ATOM_P99, scores[2]));

        pthread_mutex_unlock(&(handle->m));
        return result;
    }
    else 
        return enif_make_badarg(env);
}
开发者ID:basho,项目名称:basho_metrics,代码行数:30,代码来源:basho_metrics_nifs.cpp

示例15: send_blob_thread

static ERL_NIF_TERM send_blob_thread(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    union { void* vp; struct make_term_info* p; }mti;
    ERL_NIF_TERM copy;
    if (!enif_get_resource(env, argv[0], msgenv_resource_type, &mti.vp)
	|| !enif_get_local_pid(env,argv[1], &mti.p->to_pid)) {
	return enif_make_badarg(env);
    }
    copy = enif_make_copy(env, mti.p->blob);

    mti.p->send_it = enif_is_identical(argv[2],atom_join);
    if (enif_thread_create("nif_SUITE:send_from_thread", &mti.p->tid,
			   threaded_sender, mti.p, NULL) != 0) {
	return enif_make_badarg(env);
    }
    if (enif_is_identical(argv[2],atom_join)) {
	int err = enif_thread_join(mti.p->tid, NULL);
	assert(err == 0);
	return enif_make_tuple3(env, atom_ok, enif_make_int(env, mti.p->send_res), copy);
    }
    else {
	enif_keep_resource(mti.vp);
	return enif_make_tuple2(env, atom_ok, copy);
    }
}
开发者ID:cristiangreco,项目名称:otp,代码行数:25,代码来源:nif_SUITE.c


注:本文中的enif_get_resource函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。