• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ enif_make_int函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: nif_api_version

static ERL_NIF_TERM nif_api_version(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    /*ADD_CALL("nif_api_version");*/
    return enif_make_tuple2(env,
			    enif_make_int(env, ERL_NIF_MAJOR_VERSION),
			    enif_make_int(env, ERL_NIF_MINOR_VERSION));
}
开发者ID:hawk,项目名称:otp,代码行数:7,代码来源:nif_mod.c


示例2: send_list_seq

static ERL_NIF_TERM send_list_seq(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    ErlNifPid to;
    ERL_NIF_TERM msg;
    ErlNifEnv* msg_env;
    int i, res;
    
    if (!enif_get_int(env, argv[0], &i)) {
	return enif_make_badarg(env);
    }
    if (argv[1] == atom_self) {
	enif_self(env, &to);
    }
    else if (!enif_get_local_pid(env, argv[1], &to)) {
	return enif_make_badarg(env);
    }
    msg_env = enif_alloc_env();
    msg = enif_make_list(msg_env,0);
    for ( ; i>0 ; i--) {
	msg = enif_make_list_cell(msg_env, enif_make_int(msg_env, i), msg);
    }
    res = enif_send(env, &to, msg_env, msg);
    enif_free_env(msg_env);
    return enif_make_tuple2(env, atom_ok, enif_make_int(env,res));
}
开发者ID:cristiangreco,项目名称:otp,代码行数:25,代码来源:nif_SUITE.c


示例3: update

//key, incr, ttl, timestamp
static ERL_NIF_TERM update(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) {

    int ttl=0, timestamp=0, incr=0, next=0;
    CHECK(enif_get_string(env, argv[0], keybuff, KEY_MAX_LEN, ERL_NIF_LATIN1));
    CHECK(enif_get_int(env, argv[1], &incr));
    CHECK(enif_get_int(env, argv[2], &ttl));
    CHECK(enif_get_int(env, argv[3], &timestamp));

    metronome_item * item = find_in_hash(keybuff, timestamp);
    item->ttl = ttl;

    if(item->timestamp + ttl > timestamp) {
        item->value += incr;
        next = item->timestamp + ttl - timestamp;
    } else {
        item->value = incr;
        item->timestamp = timestamp;
        next = ttl;
    }

    //
    return enif_make_tuple3(env,
                            enif_make_atom(env, "ok"),
                            enif_make_int(env, item->value),
                            enif_make_int(env, next)
                           );
}
开发者ID:flaboy,项目名称:metronome,代码行数:28,代码来源:metronome.c


示例4: _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;
}
开发者ID:qoocku,项目名称:erleos,代码行数:29,代码来源:CAN_nif.c


示例5: _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


示例6: mres

//
// build result for re2:match
//
static ERL_NIF_TERM mres(ErlNifEnv* env,
                         const re2::StringPiece& str,
                         const re2::StringPiece& match,
                         const matchoptions::capture_type ct)
{
    switch (ct) {
    case matchoptions::CT_BINARY:
        ErlNifBinary bmatch;
        if(!enif_alloc_binary(match.size(), &bmatch))
            return a_err_alloc_binary;
        memcpy(bmatch.data, match.data(), match.size());
        return enif_make_binary(env, &bmatch);
    default:
    case matchoptions::CT_INDEX:
        int l, r;
        if (match.empty()) {
            l = -1;
            r = 0;
        } else {
            l = match.data() - str.data();
            r = match.size();
        }
        return enif_make_tuple2(env,
                                enif_make_int(env, l),
                                enif_make_int(env, r));
    }
}
开发者ID:cooldaemon,项目名称:re2,代码行数:30,代码来源:re2_nif.cpp


示例7: _load

static ERL_NIF_TERM _load(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]){
	UNUSED(argc);

	ErlNifBinary in,out;
	struct jpeg_decompress_struct cinfo;
	struct error_mgr jerr;
	unsigned int width, height;

	enif_inspect_binary(env,argv[0],&in);

	cinfo.err = jpeg_std_error(&jerr.pub);
	jerr.pub.error_exit = error_exit;
	if (setjmp(jerr.setjmp_buffer)) {
		jpeg_destroy_decompress(&cinfo);
		return -1;
	}

	jpeg_create_decompress(&cinfo);

	jpeg_mem_src(&cinfo, in.data, in.size);
	jpeg_read_header (&cinfo, TRUE);

	width = cinfo.image_width;
	height = cinfo.image_height;

	enif_alloc_binary(width*height*3,&out);

	cinfo.do_block_smoothing = TRUE;
	cinfo.do_fancy_upsampling = TRUE;
	cinfo.out_color_space = JCS_RGB;

	jpeg_start_decompress(&cinfo);

	JSAMPROW rowp[1];
	unsigned long location = 0;

	rowp[0] = (unsigned char*) malloc(cinfo.output_width*cinfo.num_components);

	unsigned int i = 0;
	while (cinfo.output_scanline < cinfo.output_height){
		jpeg_read_scanlines(&cinfo, rowp, 1);
		for( i=0; i<cinfo.image_width*cinfo.num_components;i++)
			out.data[location++] = rowp[0][i];
	}

	free(rowp[0]);

	jpeg_finish_decompress (&cinfo);
	jpeg_destroy_decompress (&cinfo);

	return	enif_make_tuple2(env,
				enif_make_atom(env,"ok"),
				enif_make_tuple3(env,
					enif_make_int(env,width),
					enif_make_int(env,height),
					enif_make_binary(env, &out)
				)
			);
}
开发者ID:DAOCUONG,项目名称:evercam-media,代码行数:59,代码来源:lib_elixir_motiondetection.c


示例8: geef_library_version

ERL_NIF_TERM geef_library_version(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
	int major, minor, rev;

	git_libgit2_version(&major, &minor, &rev);

	return enif_make_tuple3(env, enif_make_int(env, major), enif_make_int(env, minor), enif_make_int(env, rev));
}
开发者ID:CODECOMMUNITY,项目名称:geef,代码行数:8,代码来源:library.c


示例9: _receive_can_messages

static ERL_NIF_TERM
_receive_can_messages (ErlNifEnv* env,
                        CAN_handle* handle,
                        unsigned int chunk_size,
                        long timeout)
{
  int length         = 0,
      i              = 0,
      chunks         = 0;
  ERL_NIF_TERM *list, result;
  canmsg_t     buffer[sizeof(canmsg_t) * BUFFER_LIMIT];
  do {
    int status = _wait_for_input(handle, timeout);
    if (status == 0) break;
    if (status == -1)
      {
        result = enif_make_int(env, errno);
        goto end;
      }
    length = read(handle->device, &buffer[chunks], sizeof(canmsg_t) * chunk_size);
    if (length < 0) break;
    chunks += length / sizeof(canmsg_t) ;
  } while (length > 0 && chunks <= BUFFER_LIMIT && chunks < chunk_size);
  if (chunks > 0)
    {
    if (handle->raw)
      {
        void* data = enif_make_new_binary(env, chunks * sizeof(canmsg_t), &result);
        memcpy(data, buffer, chunks * sizeof(canmsg_t));
      }
    else
      {
      list = enif_alloc(sizeof(ERL_NIF_TERM) * chunks);
      // rewrite canmsgs to list of tuples
      for (i = 0; i < chunks; i++)
        {
        canmsg_t* can_msg = buffer + i;
        ERL_NIF_TERM bin;
        void* data = enif_make_new_binary(env, can_msg->length, &bin);
        memcpy(data, can_msg->data, can_msg->length);
        list[i] = enif_make_tuple3(env,
                                   enif_make_int(env, can_msg->id),
                                   enif_make_tuple2(env,
                                                    enif_make_long(env, can_msg->timestamp.tv_sec),
                                                    enif_make_long(env, can_msg->timestamp.tv_usec)),
                                   bin);
        }
      result = enif_make_list_from_array(env, list, chunks);
      enif_free(list);
      }
    }
  else if (length == 0)
    result = enif_make_int(env, 0);
  else
    result = enif_make_int(env, errno);
end:
  return result;
}
开发者ID:qoocku,项目名称:erleos,代码行数:58,代码来源:CAN_nif.c


示例10: setup_2

static ERL_NIF_TERM setup_2(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
	unsigned int channel;
	unsigned long speed;
	int error;

	if (argc != 2 || !enif_is_number(env, argv[0]) || !enif_is_number(env, argv[1])) {
		return enif_make_badarg(env);
	}
	if (!enif_get_uint(env, argv[0], &channel)) {
		return enif_make_badarg(env);
	}
	if (!enif_get_ulong(env, argv[1], &speed)) {
		return enif_make_badarg(env);
	}
	if (speed < 500000 || speed > 32000000) {
		return enif_make_badarg(env);
	}
	switch (channel) {
		case 0:
			if (state0.fd != 0) {
				return enif_make_tuple2(env, enif_make_atom(env, "error"), enif_make_string(env, "channel already opened", ERL_NIF_LATIN1));
			}
			else {
				state0.env = env;
				state0.fd = wiringPiSPISetup(channel, speed);
				if (state0.fd == 0) {
					error = errno;
					return enif_make_tuple2(env, enif_make_atom(env, "error"), enif_make_int(env, error));
				}
				else {
					return enif_make_tuple2(env, enif_make_atom(env, "ok"), enif_make_int(env, channel));
				}
			}
			break;
		case 1:
			if (state1.fd != 0) {
				return enif_make_tuple2(env, enif_make_atom(env, "error"), enif_make_string(env, "channel already opened", ERL_NIF_LATIN1));
			}
			else {
				state1.env = env;
				state1.fd = wiringPiSPISetup(channel, speed);
				if (state1.fd == 0) {
					error = errno;
					return enif_make_tuple2(env, enif_make_atom(env, "error"), enif_make_int(env, error));
				}
				else {
					return enif_make_tuple2(env, enif_make_atom(env, "ok"), enif_make_int(env, channel));
				}
			}
			break;
		default:
			return enif_make_badarg(env);
	}
}
开发者ID:sivieri,项目名称:spidev2,代码行数:54,代码来源:spidev.c


示例11: parse_error

/**
 * Convert an UErrorCode to an atom. 
 */
ERL_NIF_TERM parse_error(ErlNifEnv* env, UErrorCode status, 
        UParseError* e) {
    return build_error(env, 
        enif_make_tuple3(env,
            enif_make_atom(env, u_errorName(status)),
            enif_make_tuple2(env,
                enif_make_atom(env, "line"),
                enif_make_int(env, (int) e->line)),
            enif_make_tuple2(env,
                enif_make_atom(env, "offset"),
                enif_make_int(env, (int) e->offset))
            ));
}
开发者ID:djui,项目名称:i18n,代码行数:16,代码来源:i18n_nif.cpp


示例12: version_directive_to_term

static ERL_NIF_TERM version_directive_to_term(ErlNifEnv *env, yaml_version_directive_t *ver)
{
    if(ver)
    {
        return enif_make_tuple2(env,
                                enif_make_int(env, ver->major),
                                enif_make_int(env, ver->minor));
    }
    else
    {
        return enif_make_atom(env, "null");
    }
}
开发者ID:chinnurtb,项目名称:yamler,代码行数:13,代码来源:yaml_libyaml.c


示例13: window_event_to_map

static ERL_NIF_TERM window_event_to_map(ErlNifEnv* env, SDL_Event* event, ERL_NIF_TERM map)
{
	enif_make_map_put(env, map, atom_window_id,
		enif_make_uint(env, event->window.windowID), &map);
	enif_make_map_put(env, map, atom_event,
		window_event_to_atom(event->window.event), &map);
	enif_make_map_put(env, map, atom_data1,
		enif_make_int(env, event->window.data1), &map);
	enif_make_map_put(env, map, atom_data2,
		enif_make_int(env, event->window.data2), &map);

	return map;
}
开发者ID:ninenines,项目名称:esdl2,代码行数:13,代码来源:sdl_events.c


示例14: return_value

ERL_NIF_TERM return_value(ErlNifEnv* env, void * cookie) {
    struct libcouchbase_callback *cb;
    cb = (struct libcouchbase_callback *)cookie;
    ErlNifBinary value_binary;
    ERL_NIF_TERM term;
    enif_alloc_binary(cb->size, &value_binary);
    memcpy(value_binary.data, cb->data, cb->size);
    term  =   enif_make_tuple3(env, enif_make_int(env, cb->cas),
                                           enif_make_int(env, cb->flag),
                                           enif_make_binary(env, &value_binary));
    free(cb->data);
    return term;
}
开发者ID:muut,项目名称:cberl,代码行数:13,代码来源:cb.c


示例15: pteracuda_nifs_buffer_minmax

ERL_NIF_TERM pteracuda_nifs_buffer_minmax(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
    PCudaContextRef *ctxRef;
    PCudaBufferRef *bufRef;
    if (argc !=2 || !enif_get_resource(env, argv[0], pteracuda_context_resource, (void **) &ctxRef) ||
        !enif_get_resource(env, argv[1], pteracuda_buffer_resource, (void **) &bufRef)) {
        return enif_make_badarg(env);
    }
    if (bufRef->buffer->size() == 0) {
        return enif_make_tuple2(env, ATOM_OK, enif_make_tuple2(env, enif_make_int(env, 0),
                                                               enif_make_int(env, 0)));
    }
    cuCtxSetCurrent(ctxRef->ctx);
    return enif_make_tuple2(env, ATOM_OK, bufRef->buffer->minmax(env));
}
开发者ID:jacktang,项目名称:pteracuda,代码行数:14,代码来源:pteracuda_nifs.cpp


示例16: get_imginfo

static ERL_NIF_TERM get_imginfo(ErlNifEnv* env, GDALDatasetH out_ds) {
    double padfTransform[6];
    GDALGetGeoTransform(out_ds, padfTransform);
    if (padfTransform[2] != 0.0 && padfTransform[4] != 0.0) {
        return ATOM_ERROR;
    }

    return enif_make_tuple6(env, 
                enif_make_double(env, padfTransform[0]),        // OriginX 
                enif_make_double(env, padfTransform[3]),        // OriginY
                enif_make_double(env, padfTransform[1]),        // PixelXSize
                enif_make_double(env, padfTransform[5]),        // PixelYSize
                enif_make_int(env, GDALGetRasterXSize(out_ds)), // RasterXSize
                enif_make_int(env, GDALGetRasterYSize(out_ds)));// RasterYSize
}
开发者ID:refactor,项目名称:geo_utils,代码行数:15,代码来源:gdal_nif.c


示例17: nif_socket

/*  0: procotol, 1: type, 2: family */
    static ERL_NIF_TERM
nif_socket(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
    int s = -1;
    int family = 0;
    int type = 0;
    int protocol = 0;
    int flags = 0;


    if (!enif_get_int(env, argv[0], &family))
        return enif_make_badarg(env);

    if (!enif_get_int(env, argv[1], &type))
        return enif_make_badarg(env);

    if (!enif_get_int(env, argv[2], &protocol))
        return enif_make_badarg(env);

    s = socket(family, type, protocol);
    if (s < 0)
        return error_tuple(env, errno);

    flags = fcntl(s, F_GETFL, 0);

    if (flags < 0)
        return error_tuple(env, errno);

    if (fcntl(s, F_SETFL, flags|O_NONBLOCK) < 0)
        return error_tuple(env, errno);

    return enif_make_tuple2(env,
           atom_ok,
           enif_make_int(env, s));
}
开发者ID:alepharchives,项目名称:procket,代码行数:36,代码来源:procket.c


示例18: mruby2erl

static ERL_NIF_TERM mruby2erl(ErlNifEnv* env, mrb_state* mrb, mrb_value value) {
  if (mrb_nil_p(value)) {
    return enif_make_atom(env, "nil");
  } else {
    switch(value.tt) {
      case MRB_TT_TRUE:
        return enif_make_atom(env, "true");

      case MRB_TT_FALSE:
        return enif_make_atom(env, "false");

      case MRB_TT_SYMBOL:
        return enif_make_atom(env, _mrb_symbol(mrb, value));

      case MRB_TT_FIXNUM:
        return enif_make_int(env, _mrb_fixnum(value));

      case MRB_TT_FLOAT:
        return enif_make_double(env, _mrb_float(value));

      case MRB_TT_STRING:
        return make_binary(env, _mrb_string(mrb, value));

      case MRB_TT_ARRAY:
        return make_array(env, mrb, value);

      case MRB_TT_HASH:
        return make_hash(env, mrb, value);

      default :
        return enif_make_atom(env, "nil");
    }
  }
}
开发者ID:mururu,项目名称:erlang-mruby,代码行数:34,代码来源:mruby.c


示例19: do_date_get_field

static ERL_NIF_TERM do_date_get_field(ErlNifEnv* env, UCalendar* cal,
    const ERL_NIF_TERM field_atom, UErrorCode& status)
{
    char value[ATOM_LEN];
    int parsed_value, amount;
    UCalendarDateFields field;

    if (!enif_get_atom(env, field_atom, (char*) value, ATOM_LEN,
            ERL_NIF_LATIN1)) {
        status = U_ILLEGAL_ARGUMENT_ERROR;
        return 0;
    }

    parsed_value = parseCalendarDateField(value);
    if (parsed_value == -1) {
        status = U_ILLEGAL_ARGUMENT_ERROR;
        return 0;
    }

    field = (UCalendarDateFields) parsed_value;

    amount = (int) ucal_get(cal, field, &status);
    if (U_FAILURE(status))
        return 0;

    if (field == UCAL_MONTH)
        amount++; /* month from 0 */

    return enif_make_int(env, amount);
}
开发者ID:djui,项目名称:i18n,代码行数:30,代码来源:i18n_date.cpp


示例20: spi_data_rw_nif

static ERL_NIF_TERM
spi_data_rw_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    int channel, len;
    ErlNifBinary buf;
    ERL_NIF_TERM atom_fail, err_code;

    if (!enif_get_int(env, argv[0], &channel) ||
        !enif_inspect_binary(env, argv[1], &buf) ||
        !enif_get_int(env, argv[2], &len))
    {
        return enif_make_badarg(env);
    }

    enif_realloc_binary(&buf, len);

    int result = wiringPiSPIDataRW(channel, buf.data, len);
    if (result >= 0) {
        return enif_make_tuple2(env,
                                atom_ok,
                                enif_make_binary(env, &buf));
    } else {
        atom_fail = enif_make_atom(env, "failed_to_read_write_data");
        err_code = enif_make_int(env, result);
        enif_release_binary(&buf);
        return enif_make_tuple2(env,
                                atom_error,
                                enif_make_tuple2(env, atom_fail, err_code));
    }
}
开发者ID:alepharchives,项目名称:wpi,代码行数:30,代码来源:wpi.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ enif_make_list函数代码示例发布时间:2022-05-30
下一篇:
C++ enif_make_copy函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap