Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - split platform-dependent code into per-platform subtrees #6

Open
wants to merge 24 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# .gitignore for libcoap

cscope.out

# ignoring autogenerated files and directories by autoreconf
INSTALL
Makefile
Expand Down Expand Up @@ -32,6 +34,11 @@ src/.dirstamp
src/.libs/
src/*.o
src/*.lo
platform/**/.deps/
platform/**/.dirstamp
platform/**/.libs/
platform/**/*.o
platform/**/*.lo

# the doc/ folder
doc/Doxyfile
Expand All @@ -42,7 +49,9 @@ doc/html/

# the examples/ folder
examples/.deps/
examples/*.o
examples/**/*.o
examples/**/*.a
examples/**/obj_native/
examples/coap-client
examples/coap-rd
examples/coap-server
Expand All @@ -53,6 +62,9 @@ examples/coap-rd.txt
examples/coap-server.5
examples/coap-server.txt

# contiki OS folder
examples/contiki/contiki

# the include/ folder
include/coap/coap.h

Expand Down
24 changes: 19 additions & 5 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ EXTRA_DIST = \
tests/test_uri.h \
tests/test_wellknown.h

AM_CFLAGS = -I @top_builddir@/include/coap/ $(WARNING_CFLAGS) -std=c99
# FIXME Only add for posix
AM_CFLAGS = -I @top_builddir@/include/coap/ \
-I @top_builddir@/platform/@PLATFORM@/
$(WARNING_CFLAGS) -std=c99

SUBDIRS = . $(DOC_DIR) tests examples
# FIXME Only add for posix
SUBDIRS = . platform/posix/libev $(DOC_DIR) tests examples

## Define a libtool archive target "libcoap-@LIBCOAP_API_VERSION@.la", with
## @LIBCOAP_API_VERSION@ substituted into the generated Makefile at configure
Expand All @@ -44,15 +48,17 @@ libcoap_@LIBCOAP_API_VERSION@_la_CFLAGS = \
-fPIE \
$(AM_CFLAGS)

# FIXME only add for POSIX
libcoap_@LIBCOAP_API_VERSION@_la_LIBADD = platform/posix/libev/libev.la

## Define the source file list for the "libcoap.la" target.
## Note that it is not necessary to list header files which are already listed
## elsewhere in a _HEADERS variable assignment.
libcoap_@LIBCOAP_API_VERSION@_la_SOURCES = \
src/address.c \
src/async.c \
src/block.c \
src/coap_io.c \
src/coap_time.c \
src/coap_context.c \
src/debug.c \
src/encode.c \
src/hashkey.c \
Expand All @@ -63,7 +69,13 @@ libcoap_@LIBCOAP_API_VERSION@_la_SOURCES = \
src/resource.c \
src/str.c \
src/subscribe.c \
src/uri.c
src/uri.c \
platform/@PLATFORM@/platform_address.c \
platform/@PLATFORM@/platform_io.c \
platform/@PLATFORM@/platform_net.c \
platform/@PLATFORM@/platform_prng.c \
platform/@PLATFORM@/platform_time.c \
platform/@PLATFORM@/platform_timer.c

## Define the list of public header files and their install location.
## The list defined here will be used within the include/Makefile.am
Expand All @@ -76,8 +88,10 @@ libcoap_include_HEADERS = \
include/coap/bits.h \
include/coap/block.h \
include/coap/coap.h \
include/coap/coap_context.h \
include/coap/coap_io.h \
include/coap/coap_time.h \
include/coap/coap_timer.h \
include/coap/debug.h \
include/coap/encode.h \
include/coap/hashkey.h \
Expand Down
2 changes: 1 addition & 1 deletion autogen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ test -n "$srcdir" || srcdir=.
mkdir -p $srcdir/m4

echo "Generating needed autotools files for $PROJECT by running autoreconf ..."
autoreconf --force --install --verbose "$srcdir"
autoreconf --make --force --install --verbose "$srcdir"

echo
echo "You can now run 'configure --help' to see possible configuration options."
Expand Down
15 changes: 14 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ AC_SUBST(LIBCOAP_API_VERSION)
# see https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
# and http://www.gnu.org/software/automake/manual/html_node/Flag-Variables-Ordering.html
WARNING_CFLAGS="\
-pedantic \
-Wall \
-Wextra \
-Werror \
-Wformat-security \
-Winline \
-Wmissing-declarations \
Expand All @@ -109,6 +109,7 @@ WARNING_CFLAGS="\
-Wswitch-default \
-Wswitch-enum \
-Wunused \
-Wno-error=unused-parameter \
-Wunused-result \
"

Expand Down Expand Up @@ -192,6 +193,18 @@ AM_CONDITIONAL([HAVE_DOXYGEN],
[test -n "$DOXYGEN"])AM_COND_IF([HAVE_DOXYGEN],
[AC_CONFIG_FILES([doc/Doxyfile])])

# configure options
# __platform__
AC_ARG_VAR([PLATFORM],
[Select a platform to build for. E.g. posix, contiki, lwip])

if test -z "$PLATFORM"; then
PLATFORM="posix"
fi
if test "$PLATFORM" = "posix"; then
AC_CONFIG_SUBDIRS([platform/posix/libev])
fi

# configure options
# __tests__
AC_ARG_ENABLE([tests],
Expand Down
2 changes: 1 addition & 1 deletion examples/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
if BUILD_EXAMPLES

# picking up the default warning CFLAGS into AM_CFLAGS
AM_CFLAGS = -isystem@top_builddir@/include/coap/ $(WARNING_CFLAGS) -std=c99
AM_CFLAGS = -isystem@top_builddir@/include/coap/ -isystem@top_builddir@/platform/@PLATFORM@/ $(WARNING_CFLAGS) -std=c99

# etsi_iot_01 and tiny are missing
bin_PROGRAMS = coap-client coap-server coap-rd
Expand Down
31 changes: 4 additions & 27 deletions examples/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,6 @@ main(int argc, char **argv) {
struct timeval tv;
int result;
coap_tick_t now;
coap_queue_t *nextpdu;
coap_pdu_t *pdu;
static str server;
unsigned short port = COAP_DEFAULT_PORT;
Expand Down Expand Up @@ -1208,37 +1207,15 @@ main(int argc, char **argv) {

while ( !(ready && coap_can_exit(ctx)) ) {
FD_ZERO(&readfds);
FD_SET( ctx->sockfd, &readfds );
FD_SET( ctx->endpoint->handle.fd, &readfds );

nextpdu = coap_peek_next( ctx );

coap_ticks(&now);
while (nextpdu && nextpdu->t <= now - ctx->sendqueue_basetime) {
coap_retransmit( ctx, coap_pop_next( ctx ));
nextpdu = coap_peek_next( ctx );
}

if (nextpdu && nextpdu->t < min(obs_wait ? obs_wait : max_wait, max_wait) - now) {
/* set timeout if there is a pdu to send */
tv.tv_usec = ((nextpdu->t) % COAP_TICKS_PER_SECOND) * 1000000 / COAP_TICKS_PER_SECOND;
tv.tv_sec = (nextpdu->t) / COAP_TICKS_PER_SECOND;
} else {
/* check if obs_wait fires before max_wait */
if (obs_wait && obs_wait < max_wait) {
tv.tv_usec = ((obs_wait - now) % COAP_TICKS_PER_SECOND) * 1000000 / COAP_TICKS_PER_SECOND;
tv.tv_sec = (obs_wait - now) / COAP_TICKS_PER_SECOND;
} else {
tv.tv_usec = ((max_wait - now) % COAP_TICKS_PER_SECOND) * 1000000 / COAP_TICKS_PER_SECOND;
tv.tv_sec = (max_wait - now) / COAP_TICKS_PER_SECOND;
}
}

result = select(ctx->sockfd + 1, &readfds, 0, 0, &tv);
tv.tv_sec = wait_seconds;
result = select(ctx->endpoint->handle.fd + 1, &readfds, 0, 0, &tv);

if ( result < 0 ) { /* error */
perror("select");
} else if ( result > 0 ) { /* read from socket */
if ( FD_ISSET( ctx->sockfd, &readfds ) ) {
if ( FD_ISSET( ctx->endpoint->handle.fd, &readfds ) ) {
coap_read( ctx ); /* read received data */
/* coap_dispatch( ctx ); /\* and dispatch PDUs from receivequeue *\/ */
}
Expand Down
27 changes: 6 additions & 21 deletions examples/coap-rd.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ join(coap_context_t *ctx, char *group_name) {
}
}

result = setsockopt(ctx->sockfd,
result = setsockopt(ctx->endpoint->handle.fd,
IPPROTO_IPV6, IPV6_JOIN_GROUP,
(char *)&mreq, sizeof(mreq) );
if ( result < 0 )
Expand All @@ -677,7 +677,6 @@ main(int argc, char **argv) {
struct timeval tv, *timeout;
int result;
coap_tick_t now;
coap_queue_t *nextpdu;
char addr_str[NI_MAXHOST] = "::";
char port_str[NI_MAXSERV] = "5683";
char *group = NULL;
Expand Down Expand Up @@ -721,34 +720,20 @@ main(int argc, char **argv) {

while ( !quit ) {
FD_ZERO(&readfds);
FD_SET( ctx->sockfd, &readfds );

nextpdu = coap_peek_next( ctx );
FD_SET( ctx->endpoint->handle.fd, &readfds );

coap_ticks(&now);
while ( nextpdu && nextpdu->t <= now ) {
coap_retransmit( ctx, coap_pop_next( ctx ) );
nextpdu = coap_peek_next( ctx );
}

if ( nextpdu && nextpdu->t <= now + COAP_RESOURCE_CHECK_TIME ) {
/* set timeout if there is a pdu to send before our automatic
timeout occurs */
tv.tv_usec = ((nextpdu->t - now) % COAP_TICKS_PER_SECOND) * 1000000 / COAP_TICKS_PER_SECOND;
tv.tv_sec = (nextpdu->t - now) / COAP_TICKS_PER_SECOND;
timeout = &tv;
} else {
tv.tv_usec = 0;
tv.tv_sec = COAP_RESOURCE_CHECK_TIME;
timeout = &tv;
}
tv.tv_usec = 0;
tv.tv_sec = COAP_RESOURCE_CHECK_TIME;
timeout = &tv;
result = select( FD_SETSIZE, &readfds, 0, 0, timeout );

if ( result < 0 ) { /* error */
if (errno != EINTR)
perror("select");
} else if ( result > 0 ) { /* read from socket */
if ( FD_ISSET( ctx->sockfd, &readfds ) ) {
if ( FD_ISSET( ctx->endpoint->handle.fd, &readfds ) ) {
coap_read( ctx ); /* read received data */
/* coap_dispatch( ctx ); /\* and dispatch PDUs from receivequeue *\/ */
}
Expand Down
26 changes: 6 additions & 20 deletions examples/coap-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ join(coap_context_t *ctx, char *group_name){
}
}

result = setsockopt(ctx->sockfd, IPPROTO_IPV6, IPV6_JOIN_GROUP,
result = setsockopt(ctx->endpoint->handle.fd, IPPROTO_IPV6, IPV6_JOIN_GROUP,
(char *)&mreq, sizeof(mreq));
if (result < 0)
perror("join: setsockopt");
Expand All @@ -450,7 +450,6 @@ main(int argc, char **argv) {
struct timeval tv, *timeout;
int result;
coap_tick_t now;
coap_queue_t *nextpdu;
char addr_str[NI_MAXHOST] = "::";
char port_str[NI_MAXSERV] = "5683";
int opt;
Expand Down Expand Up @@ -496,33 +495,20 @@ main(int argc, char **argv) {

while ( !quit ) {
FD_ZERO(&readfds);
FD_SET( ctx->sockfd, &readfds );

nextpdu = coap_peek_next( ctx );
FD_SET( ctx->endpoint->handle.fd, &readfds );

coap_ticks(&now);
while (nextpdu && nextpdu->t <= now - ctx->sendqueue_basetime) {
coap_retransmit( ctx, coap_pop_next( ctx ) );
nextpdu = coap_peek_next( ctx );
}

if ( nextpdu && nextpdu->t <= COAP_RESOURCE_CHECK_TIME ) {
/* set timeout if there is a pdu to send before our automatic timeout occurs */
tv.tv_usec = ((nextpdu->t) % COAP_TICKS_PER_SECOND) * 1000000 / COAP_TICKS_PER_SECOND;
tv.tv_sec = (nextpdu->t) / COAP_TICKS_PER_SECOND;
timeout = &tv;
} else {
tv.tv_usec = 0;
tv.tv_sec = COAP_RESOURCE_CHECK_TIME;
timeout = &tv;
}
tv.tv_usec = 0;
tv.tv_sec = COAP_RESOURCE_CHECK_TIME;
timeout = &tv;
result = select( FD_SETSIZE, &readfds, 0, 0, timeout );

if ( result < 0 ) { /* error */
if (errno != EINTR)
perror("select");
} else if ( result > 0 ) { /* read from socket */
if ( FD_ISSET( ctx->sockfd, &readfds ) ) {
if ( FD_ISSET( ctx->endpoint->handle.fd, &readfds ) ) {
coap_read( ctx ); /* read received data */
/* coap_dispatch( ctx ); /\* and dispatch PDUs from receivequeue *\/ */
}
Expand Down
28 changes: 14 additions & 14 deletions examples/contiki/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ all: server
contiki:
git clone https://github.com/contiki-os/contiki.git

# contiki and coap opts
CONTIKI=contiki

CFLAGS += -g3 -Wall -pedantic -O0

CFLAGS += -I.

# contiki library

PLATFORM_VPATH = $(CONTIKI)/cpu/native $(CONTIKI)/cpu/native/net $(CONTIKI)/platform/minimal-net
#PLATFORM_CPPFLAGS =
PLATFORM_CFLAGS = -I$(CONTIKI)/cpu/native/ -I$(CONTIKI)/platform/minimal-net
PLATFORM_OBJS = contiki-main.o tapdev6.o tapdev-drv.o clock.o serial-line.o

CONTIKIOBJS = $(PLATFORM_OBJS) ringbuf.o autostart.o list.o memb.o uiplib.o uip-nd6.o uip-neighbor.o uip-ds6.o uip-ds6-nbr.o linkaddr.o uip.o uip-udp-packet.o random.o ctimer.o timer.o etimer.o stimer.o procinit.o process.o udp-socket.o uip-icmp6.o tcpip.o uip-packetqueue.o uip-ds6-route.o nbr-table.o uip6.o uip.o uip-debug.o packetbuf.o
vpath %.c $(CONTIKI)/core $(CONTIKI)/core/lib $(CONTIKI)/core/sys $(CONTIKI)/core/dev $(CONTIKI)/core/net $(CONTIKI)/core/net/ip $(CONTIKI)/core/net/ipv4 $(CONTIKI)/core/net/ipv6 $(CONTIKI)/core/loader $(CONTIKI)/core/cfs $(PLATFORM_VPATH)

CFLAGS += -DCONTIKI_TARGET_MINIMAL_NET=1 -DWITH_UIP6=1 -DUIP6_CONF_IPV6=1 -DNETSTACK_CONF_WITH_IPV6=1 -DUIP_CONF_IPV6_RPL=0 -URPL_BORDER_ROUTER -DAUTOSTART_ENABLE -DNODE_ADDR=$(NODE_ADDR)

CFLAGS += -g3 -Wall -pedantic -O0
CONTIKI = contiki

CFLAGS += -DCONTIKI_TARGET_MINIMAL_NET=1 \
-DWITH_UIP6=1 \
-DUIP6_CONF_IPV6=1 \
-DNETSTACK_CONF_WITH_IPV6=1 \
-URPL_BORDER_ROUTER \
-DAUTOSTART_ENABLE \
-DNODE_ADDR=$(NODE_ADDR) \
-DCONTIKI_WITH_RPL=0

include $(CONTIKI)/Makefile.include

include Makefile.common
Loading