aboutsummaryrefslogtreecommitdiff
path: root/src/supplemental/util
diff options
context:
space:
mode:
authorGregor Burger <gregor.burger@bhs-technologies.com>2018-11-20 11:48:03 +0100
committerGarrett D'Amore <garrett@damore.org>2018-11-22 12:28:27 -0800
commitd6bb25e1e0a25cb5aa781ac4f90b513fd5624f50 (patch)
treef081a6868a6c3d88b4df64ef20a38fb3e83925d1 /src/supplemental/util
parent8a9fd805d96201c780610b765f9e6dd9f2eda642 (diff)
downloadnng-d6bb25e1e0a25cb5aa781ac4f90b513fd5624f50.tar.gz
nng-d6bb25e1e0a25cb5aa781ac4f90b513fd5624f50.tar.bz2
nng-d6bb25e1e0a25cb5aa781ac4f90b513fd5624f50.zip
move all public headers to include/nng/ folder
This change makes embedding nng + nggpp (or other projects depending on nng) in cmake easier. The header files are moved to a separate include directory. This also makes installation of the headers easier, and allows clearer identification of private vs public heade files. Some additional cleanups were performed by @gedamore, but the main credit for this change belongs with @gregorburger.
Diffstat (limited to 'src/supplemental/util')
-rw-r--r--src/supplemental/util/CMakeLists.txt7
-rw-r--r--src/supplemental/util/options.c2
-rw-r--r--src/supplemental/util/options.h48
-rw-r--r--src/supplemental/util/platform.c2
-rw-r--r--src/supplemental/util/platform.h106
5 files changed, 6 insertions, 159 deletions
diff --git a/src/supplemental/util/CMakeLists.txt b/src/supplemental/util/CMakeLists.txt
index c61d8a09..64374d69 100644
--- a/src/supplemental/util/CMakeLists.txt
+++ b/src/supplemental/util/CMakeLists.txt
@@ -8,8 +8,9 @@
# found online at https://opensource.org/licenses/MIT.
#
-set(_SRCS supplemental/util/options.c supplemental/util/platform.c)
-set(_HDRS supplemental/util/options.h supplemental/util/platform.h)
+set(_SRCS supplemental/util/options.c
+ ${PROJECT_SOURCE_DIR}/include/nng/supplemental/util/options.h
+ supplemental/util/platform.c
+ ${PROJECT_SOURCE_DIR}/include/nng/supplemental/util/platform.h)
set(NNG_SRCS ${NNG_SRCS} ${_SRCS} PARENT_SCOPE)
-set(NNG_HDRS ${NNG_HDRS} ${_HDRS} PARENT_SCOPE)
diff --git a/src/supplemental/util/options.c b/src/supplemental/util/options.c
index 711635e2..c8dafed8 100644
--- a/src/supplemental/util/options.c
+++ b/src/supplemental/util/options.c
@@ -12,7 +12,7 @@
#include <string.h>
#include "core/nng_impl.h"
-#include "supplemental/util/options.h"
+#include "nng/supplemental/util/options.h"
// Call with optidx set to 1 to start parsing.
int
diff --git a/src/supplemental/util/options.h b/src/supplemental/util/options.h
deleted file mode 100644
index 83969a90..00000000
--- a/src/supplemental/util/options.h
+++ /dev/null
@@ -1,48 +0,0 @@
-//
-// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
-// Copyright 2018 Capitar IT Group BV <info@capitar.com>
-//
-// This software is supplied under the terms of the MIT License, a
-// copy of which should be located in the distribution where this
-// file was obtained (LICENSE.txt). A copy of the license may also be
-// found online at https://opensource.org/licenses/MIT.
-//
-
-#ifndef NNG_SUPPLEMENTAL_UTIL_OPTIONS_H
-#define NNG_SUPPLEMENTAL_UTIL_OPTIONS_H
-
-#include <stdbool.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-// This is a relatively simple "options parsing" library, used to
-// parse command line options. We would use getopt(3), but there are
-// two problems with getopt(3). First, it isn't available on all
-// platforms (especially Win32), and second, it doesn't support long
-// options. We *exclusively* support long options. POSIX style
-// short option clustering is *NOT* supported.
-
-struct nng_optspec {
- const char *o_name; // Long style name (may be NULL for short only)
- int o_short; // Short option (no clustering!)
- int o_val; // Value stored on a good parse (>0)
- bool o_arg; // Option takes an argument if true
-};
-
-typedef struct nng_optspec nng_optspec;
-
-// Call with *optidx set to 1 to start parsing for a standard program.
-// The val will store the value of the matched "o_val", optarg will be
-// set to match the option string, and optidx will be increment appropriately.
-// Returns -1 when the end of options is reached, 0 on success, or
-// NNG_EINVAL if the option parse is invalid for any reason.
-NNG_DECL int nng_opts_parse(int argc, char *const *argv,
- const nng_optspec *opts, int *val, char **optarg, int *optidx);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // NNG_SUPPLEMENTAL_UTIL_OPTIONS_H
diff --git a/src/supplemental/util/platform.c b/src/supplemental/util/platform.c
index 691ce867..138e8b0b 100644
--- a/src/supplemental/util/platform.c
+++ b/src/supplemental/util/platform.c
@@ -12,7 +12,7 @@
#include <string.h>
#include "core/nng_impl.h"
-#include "supplemental/util/platform.h"
+#include "nng/supplemental/util/platform.h"
nng_time
nng_clock(void)
diff --git a/src/supplemental/util/platform.h b/src/supplemental/util/platform.h
deleted file mode 100644
index 0fcc7d16..00000000
--- a/src/supplemental/util/platform.h
+++ /dev/null
@@ -1,106 +0,0 @@
-//
-// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
-// Copyright 2018 Capitar IT Group BV <info@capitar.com>
-//
-// This software is supplied under the terms of the MIT License, a
-// copy of which should be located in the distribution where this
-// file was obtained (LICENSE.txt). A copy of the license may also be
-// found online at https://opensource.org/licenses/MIT.
-//
-
-#ifndef NNG_SUPPLEMENTAL_UTIL_PLATFORM_H
-#define NNG_SUPPLEMENTAL_UTIL_PLATFORM_H
-
-// The declarations in this file are provided to assist with application
-// portability. Conceptually these APIs are based on work we have already
-// done for NNG internals, and we find that they are useful in building
-// portable applications.
-
-// If it is more natural to use native system APIs like pthreads or C11
-// APIs or Windows APIs, then by all means please feel free to simply
-// ignore this.
-
-#include <stddef.h>
-#include <stdint.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-// nng_time represents an absolute time since some arbitrary point in the
-// past, measured in milliseconds. The values are always positive.
-typedef uint64_t nng_time;
-
-// Return an absolute time from some arbitrary point. The value is
-// provided in milliseconds, and is of limited resolution based on the
-// system clock. (Do not use it for fine grained performance measurements.)
-NNG_DECL nng_time nng_clock(void);
-
-// Sleep for specified msecs.
-NNG_DECL void nng_msleep(nng_duration);
-
-// nng_thread is a handle to a "thread", which may be a real system
-// thread, or a coroutine on some platforms.
-typedef struct nng_thread nng_thread;
-
-// Create and start a thread. Note that on some platforms, this might
-// actually be a coroutine, with limitations about what system APIs
-// you can call. Therefore, these threads should only be used with the
-// I/O APIs provided by nng. The thread runs until completion.
-NNG_DECL int nng_thread_create(nng_thread **, void (*)(void *), void *);
-
-// Destroy a thread (waiting for it to complete.) When this function
-// returns all resources for the thread are cleaned up.
-NNG_DECL void nng_thread_destroy(nng_thread *);
-
-// nng_mtx represents a mutex, which is a simple, non-retrant, boolean lock.
-typedef struct nng_mtx nng_mtx;
-
-// nng_mtx_alloc allocates a mutex structure.
-NNG_DECL int nng_mtx_alloc(nng_mtx **);
-
-// nng_mtx_free frees the mutex. It most not be locked.
-NNG_DECL void nng_mtx_free(nng_mtx *);
-
-// nng_mtx_lock locks the mutex; if it is already locked it will block
-// until it can be locked. If the caller already holds the lock, the
-// results are undefined (a panic may occur).
-NNG_DECL void nng_mtx_lock(nng_mtx *);
-
-// nng_mtx_unlock unlocks a previously locked mutex. It is an error to
-// call this on a mutex which is not owned by caller.
-NNG_DECL void nng_mtx_unlock(nng_mtx *);
-
-// nng_cv is a condition variable. It is always allocated with an
-// associated mutex, which must be held when waiting for it, or
-// when signaling it.
-typedef struct nng_cv nng_cv;
-
-NNG_DECL int nng_cv_alloc(nng_cv **, nng_mtx *);
-
-// nng_cv_free frees the condition variable.
-NNG_DECL void nng_cv_free(nng_cv *);
-
-// nng_cv_wait waits until the condition variable is "signaled".
-NNG_DECL void nng_cv_wait(nng_cv *);
-
-// nng_cv_until waits until either the condition is signaled, or
-// the timeout expires. It returns NNG_ETIMEDOUT in that case.
-NNG_DECL int nng_cv_until(nng_cv *, nng_time);
-
-// nng_cv_wake wakes all threads waiting on the condition.
-NNG_DECL void nng_cv_wake(nng_cv *);
-
-// nng_cv_wake1 wakes only one thread waiting on the condition. This may
-// reduce the thundering herd problem, but care must be taken to ensure
-// that no waiter starves forvever.
-NNG_DECL void nng_cv_wake1(nng_cv *);
-
-// nng_random returns a "strong" (cryptographic sense) random number.
-NNG_DECL uint32_t nng_random(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // NNG_SUPPLEMENTAL_UTIL_PLATFORM_H