erlang
/
osmo-map-masq
Archived
4
0
Fork 0

sccp_node: Remove complex.c, pick two atom names for functions we support

This commit is contained in:
Holger Hans Peter Freyther 2010-08-02 19:55:26 +08:00
parent 3852e7e7c3
commit 922747ca79
3 changed files with 32 additions and 23 deletions

View File

@ -1,7 +1,7 @@
INCLUDES = $(all_includes)
AM_CFLAGS = $(ERLANG_CFLAGS) -Wall
AM_CFLAGS = $(ERLANG_CFLAGS) $(LIBOSMOSCCP_CFLAGS) -Wall
bin_PROGRAMS = sccp_node
sccp_node_SOURCES = sccp_node.c complex.c
sccp_node_LDADD = $(ERLANG_LIBS) -lpthread
sccp_node_SOURCES = sccp_node.c
sccp_node_LDADD = $(ERLANG_LIBS) -lpthread $(LIBOSMOSCCP_LIBS)

View File

@ -1,9 +0,0 @@
/* complex.c */
int foo(int x) {
return x+1;
}
int bar(int y) {
return y*2;
}

View File

@ -10,7 +10,28 @@
#include "erl_interface.h"
#include "ei.h"
#define BUFSIZE 1000
/*
* Split the SCCP UDT message into header and data...
*/
static int split_udt(int fd, ETERM *fromp, ETERM *argp)
{
ETERM *resp;
resp = erl_format("{split_udt, {~i, ~i}}", 10, 20);
erl_send(fd, fromp, resp);
erl_free_term(resp);
return 0;
}
static int wrap_udt(int fd, ETERM *fromp, ETERM *argp)
{
ETERM *resp;
resp = erl_format("{wrap_udt, ~i}", 10);
erl_send(fd, fromp, resp);
erl_free_term(resp);
return 0;
}
static int create_listen_socket(int port)
{
@ -60,7 +81,7 @@ static int handle_command(int fd) {
unsigned char buf[4096]; /* Buffer for incoming message */
ErlMessage emsg; /* Incoming message */
ETERM *fromp, *tuplep, *fnp, *argp, *resp;
ETERM *fromp, *tuplep, *fnp, *argp;
int got; /* Result of receive */
int exit = 0;
@ -70,22 +91,19 @@ static int handle_command(int fd) {
} else if (got == ERL_ERROR) {
exit = 1;
} else if (emsg.type == ERL_REG_SEND) {
int res = -1;
fromp = erl_element(2, emsg.msg);
tuplep = erl_element(3, emsg.msg);
fnp = erl_element(1, tuplep);
argp = erl_element(2, tuplep);
if (ERL_IS_ATOM(fnp)) {
if (strncmp(ERL_ATOM_PTR(fnp), "foo", 3) == 0) {
res = foo(ERL_INT_VALUE(argp));
} else if (strncmp(ERL_ATOM_PTR(fnp), "bar", 3) == 0) {
res = bar(ERL_INT_VALUE(argp));
if (strcmp(ERL_ATOM_PTR(fnp), "split_udt") == 0) {
split_udt(fd, fromp, argp);
} else if (strcmp(ERL_ATOM_PTR(fnp), "wrap_udt") == 0) {
wrap_udt(fd, fromp, argp);
} else {
printf("unknown command '%s'\n", ERL_ATOM_PTR(fnp));
}
resp = erl_format("{cnode, ~i}", res);
erl_send(fd, fromp, resp);
erl_free_term(resp);
}
erl_free_term(emsg.from); erl_free_term(emsg.msg);