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


C++ ei_decode_atom函数代码示例

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


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

示例1: trace_file_output

/*
** Data sent from erlang to port.
*/
static void trace_file_output(ErlDrvData handle, char *buf,
			      ErlDrvSizeT len)
{
  int index = 1;
  ei_print_term(stdout, buf, &index);
  erts_printf("\n");
  /* erts_printf("output: %d: %u\n", rc, (unsigned char)buff[0]); */
  int arity;
  char atom[MAXATOMLEN];
  char type[MAXATOMLEN];
  char pidstr[100];
  index = 1;
  erlang_pid pid;
  if(!ei_decode_tuple_header(buf, &index, &arity)) {
    if(!ei_decode_atom(buf, &index, atom)) {
      if(strcmp("trace", atom) == 0) {
        if(!ei_decode_pid(buf, &index, &pid)) {
          if(!ei_decode_atom(buf, &index, type)) {
            snprintf(pidstr, 100, "<0.%d.%d>", pid.num, pid.serial);
            erts_printf("%s: %s\n", pidstr, type);
            dispatch(pidstr, type, index, buf);
          }
        }
      }
    }
  }
}
开发者ID:jtuple,项目名称:dt_trace,代码行数:30,代码来源:dt_trace.c

示例2: handle_flush

static void handle_flush(const char *req, int *req_index)
{
    char dirstr[MAXATOMLEN];
    if (ei_decode_atom(req, req_index, dirstr) < 0) {
        send_error_response("einval");
        return;
    }

    enum uart_direction direction;
    if (strcmp(dirstr, "receive") == 0)
        direction = UART_DIRECTION_RECEIVE;
    else if (strcmp(dirstr, "transmit") == 0)
        direction = UART_DIRECTION_TRANSMIT;
    else if (strcmp(dirstr, "both") == 0)
        direction = UART_DIRECTION_BOTH;
    else {
        send_error_response("einval");
        return;
    }

    if (!uart_is_open(uart)) {
        send_error_response("ebadf");
        return;
    }

    if (uart_flush(uart, direction) >= 0)
        send_ok_response();
    else
        send_error_response(uart_last_error());
}
开发者ID:nerves-project,项目名称:nerves_uart,代码行数:30,代码来源:circuits_uart.c

示例3: update_list

static int
update_list(struct exmpp_hashtable *kl, const char *buf, int *index)
{
	int nb_items, i, type, item_len;
	char item[MAXATOMLEN];

	/* We check that we have a real list. */
	if (ei_decode_list_header(buf, index, &nb_items) != 0)
		return (-1);

	if (nb_items < 0)
		return (0);

	for (i = 0; i < nb_items; ++i) {
		/* Decode the item. */
		if (ei_get_type(buf, index, &type, &item_len) != 0)
			return (-1);
		if (ei_decode_atom(buf, index, item) != 0)
			return (-1);

		/* Add it to the list. */
		if (!exmpp_ht_exists(kl, item, item_len))
			exmpp_ht_store(kl, item, item_len, &DUMMY);
	}

	return (0);
}
开发者ID:ASalimov,项目名称:exmpp,代码行数:27,代码来源:exmpp_xml.c

示例4: ei_rpc

  /*
  * A true RPC. It return a NULL pointer
  * in case of failure, otherwise a valid
  * (ETERM *) pointer containing the reply
  */
int ei_rpc(ei_cnode* ec, int fd, char *mod, char *fun,
	   const char* inbuf, int inbuflen, ei_x_buff* x)
{
    int i, index;
    ei_term t;
    erlang_msg msg;
    char rex[MAXATOMLEN];

    if (ei_rpc_to(ec, fd, mod, fun, inbuf, inbuflen) < 0) {
	return -1;
    }
    /* FIXME are we not to reply to the tick? */
    while ((i = ei_rpc_from(ec, fd, ERL_NO_TIMEOUT, &msg, x)) == ERL_TICK)
	;

    if (i == ERL_ERROR)  return -1;
    /*ep = 'erl'_element(2,emsg.msg);*/ /* {RPC_Tag, RPC_Reply} */
    index = 0;
    if (ei_decode_version(x->buff, &index, &i) < 0
	|| ei_decode_ei_term(x->buff, &index, &t) < 0)
	return -1;		/* FIXME ei_decode_version don't set erl_errno as before */
    /* FIXME this is strange, we don't check correct "rex" atom
       and we let it pass if not ERL_SMALL_TUPLE_EXT and arity == 2 */
    if (t.ei_type == ERL_SMALL_TUPLE_EXT && t.arity == 2)
	if (ei_decode_atom(x->buff, &index, rex) < 0)
	    return -1;
    /* remove header */
    x->index -= index;
    memmove(x->buff, &x->buff[index], x->index);
    return 0;
}
开发者ID:616050468,项目名称:otp,代码行数:36,代码来源:ei_connect.c

示例5: handle_elixir_request

/**
 * @brief Decode and forward requests from Elixir to the appropriate handlers
 * @param req the undecoded request
 * @param cookie
 */
static void handle_elixir_request(const char *req, void *cookie)
{
    (void) cookie;

    // Commands are of the form {Command, Arguments}:
    // { atom(), term() }
    int req_index = sizeof(uint16_t);
    if (ei_decode_version(req, &req_index, NULL) < 0)
        errx(EXIT_FAILURE, "Message version issue?");

    int arity;
    if (ei_decode_tuple_header(req, &req_index, &arity) < 0 ||
            arity != 2)
        errx(EXIT_FAILURE, "expecting {cmd, args} tuple");

    char cmd[MAXATOMLEN];
    if (ei_decode_atom(req, &req_index, cmd) < 0)
        errx(EXIT_FAILURE, "expecting command atom");

    for (struct request_handler *rh = request_handlers; rh->name != NULL; rh++) {
        if (strcmp(cmd, rh->name) == 0) {
            rh->handler(req, &req_index);
            return;
        }
    }
    errx(EXIT_FAILURE, "unknown command: %s", cmd);
}
开发者ID:johnhamelink,项目名称:nerves_uart,代码行数:32,代码来源:nerves_uart.c

示例6: next_pointer

int next_pointer(GEOSCommand *command, int argc, char *name, void** data) {
	int arity;
	char atom[MAXATOMLEN];
	unsigned long pointer;


	//decode tuple
	if(ei_decode_tuple_header(command->param_bytes, &command->index, &arity)) {
		return -1;
	}

	//verify if it's the right label
	if(arity!=argc) {
		return -1;
	}


	//decode pointer label
	if(ei_decode_atom(command->param_bytes,&command->index, atom)) {
		return -1;
	}

	if(strcmp(atom,name)) {
		return -1;
	}
	//decode the pointer
	if(ei_decode_ulong(command->param_bytes, &command->index, &pointer)) {
		return -1;
	}

	*data = (void *) pointer;
	return 0;
}
开发者ID:alepharchives,项目名称:erlgeo,代码行数:33,代码来源:erl_geos_util.c

示例7: select_known_elems

static int
select_known_elems(struct exmpp_xml_ctx *ctx, const char *buf, int index)
{
	int type, list_name_len;
	char list_name[MAXATOMLEN];
	struct exmpp_hashtable *kl;

	if (ei_get_type(buf, &index, &type, &list_name_len) != 0)
		return (-1);
	if (ei_decode_atom(buf, &index, list_name) != 0)
		return (-1);

	if (strcmp(list_name, "false") == 0) {
		ctx->check_elems = 0;
		return (0);
	}
	
	if (strcmp(list_name, "true") == 0) {
		if (ctx->known_elems == NULL)
			return (-1);

		ctx->check_elems = 1;
		return (0);
	}

	kl = exmpp_ht_fetch(known_elems_index, list_name, list_name_len);
	if (kl == NULL)
		return (-1);

	ctx->known_elems = kl;
	ctx->check_elems = 1;

	return (0);
}
开发者ID:ASalimov,项目名称:exmpp,代码行数:34,代码来源:exmpp_xml.c

示例8: erl_self

ETERM *erl_global_whereis(int fd, const char *name, char *node)
{
  char buf[EISMALLBUF];
  char *bufp=buf;
  char tmpbuf[64];
  int index = 0;
  erlang_pid *self = erl_self();
  erlang_pid epid;
  ETERM *opid;
  erlang_msg msg;
  int i;
  int version,arity,msglen;

  self->num = fd;		/* FIXME looks strange to change something?! */

  ei_encode_version(buf,&index);
  ei_encode_tuple_header(buf,&index,2);
  ei_encode_pid(buf,&index,self);               /* PidFrom */
  ei_encode_tuple_header(buf,&index,5);
  ei_encode_atom(buf,&index,"call");            /* call */
  ei_encode_atom(buf,&index,"global");          /* Mod */
  ei_encode_atom(buf,&index,"whereis_name");    /* Fun */
  ei_encode_list_header(buf,&index,1);          /* Args: [ name ] */
  ei_encode_atom(buf,&index,name);
  ei_encode_empty_list(buf,&index);
  ei_encode_atom(buf,&index,"user");            /* user */

  /* make the rpc call */
  if (ei_send_reg_encoded(fd,self,"rex",buf,index)) return NULL;

  while (1) {
    index = EISMALLBUF;
    if (!(i = ei_recv_internal(fd,&bufp,&index,&msg,&msglen,1,0))) continue;
    else break;
  }

  if (i != ERL_SEND) return NULL;
    
  /* expecting { rex, pid } */
  index = 0;
  if (ei_decode_version(buf,&index,&version) 
      || ei_decode_tuple_header(buf,&index,&arity) 
      || (arity != 2) 
      || ei_decode_atom(buf,&index,tmpbuf) 
      || strcmp(tmpbuf,"rex")
      || ei_decode_pid(buf,&index,&epid))
    return NULL; /* bad response from other side */

  /* put the pid into a format for the caller */
  index = 0;
  ei_encode_pid(buf,&index,&epid);
  opid = erl_decode((unsigned char*)buf);

  /* extract the nodename for the caller */
  if (node) strcpy(node,epid.node);

  return opid;
}
开发者ID:system,项目名称:erlang-otp,代码行数:58,代码来源:global_whereis.c

示例9: main

/*-----------------------------------------------------------------
 * MAIN
 *----------------------------------------------------------------*/
int main(int argc, char *argv[])
{
    byte*     buf;
    int       size = BUF_SIZE;

    if (argc > 1) {
	test(argc, argv);
	return 0;
    }

    fprintf(stderr, "gssapi started\r\n");

    if ((buf = malloc(size)) == NULL)
	return -1;
    
    while ( (buf = read_cmd(buf, &size)) ) {
	int res = 0;
	int index = 0;
	int version, arity;
	char command[MAXATOMLEN];
	ei_x_buff result;
	port_func func;

	/* Ensure that we are receiving the binary term by reading and 
	 * stripping the version byte */
	EI(ei_decode_version(buf, &index, &version));
    
	/* Our marshalling spec is that we are expecting a tuple {Command, Arg1} */
	EI(ei_decode_tuple_header(buf, &index, &arity));
    
	EI(arity != 2);
    
	EI(ei_decode_atom(buf, &index, command));

	/* Prepare the output buffer that will hold {ok, Result} or {error, Reason} */
	EI(ei_x_new_with_version(&result) || ei_x_encode_tuple_header(&result, 2));
    
/* 	fprintf(stderr, "command: %s\r\n", command); */
	func = lookup_func(command);

	if (func) {
	    res = func(buf, index, &result);
	} else {
	    EI(ei_x_encode_atom(&result, "error") || ei_x_encode_atom(&result, "unsupported_command"));
	}

	write_cmd(&result);

	ei_x_free(&result);
    }

/* error: */
    fprintf(stderr, "No more command, exiting\r\n");

    return 0;
}
开发者ID:GlenWalker,项目名称:egssapi,代码行数:59,代码来源:gssapi_drv.c

示例10: toArray

	QByteArray toArray() const
	{
		int idx = _index; QByteArray a(_size, 0);
		if (isAtom())
			ei_decode_atom(_buf, &idx, a.data());
		else
			ei_decode_string(_buf, &idx, a.data());

		return a;
	}
开发者ID:krant,项目名称:eqml,代码行数:10,代码来源:eqml.cpp

示例11: erlcmd_decode_atom

/**
 * @brief Helper for decoding atoms that checks the length of the atom
 * @param buf the request
 * @param index the index into the request
 * @param dest where to store the response
 * @param maxlength the length of the destination
 * @return -1 on error; 0 on success
 */
int erlcmd_decode_atom(const char *buf, int *index, char *dest, int maxlength)
{
    int type;
    int size;
    if (ei_get_type(buf, index, &type, &size) < 0 ||
            type != ERL_ATOM_EXT ||
            size + 1 > maxlength)
        return -1;

    return ei_decode_atom(buf, index, dest);
}
开发者ID:nerves-project,项目名称:nerves_network_interface,代码行数:19,代码来源:erlcmd.c

示例12: do_call

void do_call(char *pid, int index, char *buf) {
  char m[MAXATOMLEN];
  char f[MAXATOMLEN];
  long a;
  int arity;

  if(ei_decode_tuple_header(buf, &index, &arity) || (arity != 3))
    return;
  if(ei_decode_atom(buf, &index, m))
    return;
  if(ei_decode_atom(buf, &index, f))
    return;
  
  if(ei_decode_long(buf, &index, &a)) {
    if(ei_decode_list_header(buf, &index, &arity))
      return;
    a = arity;
  }

  erts_printf("%s call %s/%s/%d\n", pid, m, f, a);
}
开发者ID:jtuple,项目名称:dt_trace,代码行数:21,代码来源:dt_trace.c

示例13: cmd_ei_rpc

static void cmd_ei_rpc(char* buf, int len)
{
    int index = 0, n;
    long fd;
    erlang_pid pid;
    ei_x_buff x, rpc_x;
    int r;
    char mod[MAXATOMLEN], func[MAXATOMLEN];

#if 0 && defined(__WIN32__) 
    DebugBreak();
#endif

    if (ei_decode_long(buf, &index, &fd) < 0)
	fail("expected long");
    if (ei_decode_pid(buf, &index, &pid) < 0)
	fail("expected pid (node)");
    if (ei_decode_tuple_header(buf, &index, &n) < 0 && n < 2)
	fail("expected tuple {module, function}");
    if (ei_decode_atom(buf, &index, mod) < 0)
	fail("expected atom (module)");
    if (ei_decode_atom(buf, &index, func) < 0)
	fail("expected atom (function)");
    message("pid %s %d %d %d\n", pid.node, pid.num, pid.serial, pid.creation);
    message("{%s, %s}\n", mod, func);
    if (ei_x_new(&rpc_x) < 0)
	fail("ei_x_new");
    if (ei_rpc(&ec, fd, mod, func, &buf[index], len - index, &rpc_x) < 0)
	fail("ei_rpc");
    if (ei_x_new_with_version(&x) < 0)
 	fail("ei_x_new_with_version");
    if (ei_x_append(&x, &rpc_x) < 0)
	fail("append");
    send_bin_term(&x);
    /*send_errno_result(ei_send(&ec, fd, &pid, x.buff, x.index));*/
    ei_x_free(&x);
    ei_x_free(&rpc_x);
}
开发者ID:3112517927,项目名称:otp,代码行数:38,代码来源:ei_connect_test.c

示例14: cmd_ei_connect

static void cmd_ei_connect(char* buf, int len)
{
    int index = 0;
    char node[256];
    int i;
    if (ei_decode_atom(buf, &index, node) < 0)
	fail("expected atom");
    i=ei_connect(&ec, node);
#ifdef VXWORKS
    if(i >= 0) {
	save_fd(i);
    }
#endif
    send_errno_result(i);
}
开发者ID:3112517927,项目名称:otp,代码行数:15,代码来源:ei_connect_test.c

示例15: ei_decode_atom_safe

int ei_decode_atom_safe(char *buf, int *index, char *dst) {
    int type, size;

    ei_get_type(buf, index, &type, &size);

	if (type != ERL_ATOM_EXT) {
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unexpected erlang term type %d (size %d), needed atom\n", type, size);
        return -1;
	} else if (size > MAXATOMLEN) {
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Requested decoding of atom with size %d into a buffer of size %d\n", size, MAXATOMLEN);
        return -1;
	} else {
		return ei_decode_atom(buf, index, dst);
	}
}
开发者ID:jasonmsoft,项目名称:freeswitch_mod_xpass,代码行数:15,代码来源:xpass_utils.c


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