Skip to content

Commit

Permalink
get rid of argp dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
john30 committed Oct 1, 2023
1 parent 1b9723c commit 22b6f02
Show file tree
Hide file tree
Showing 20 changed files with 740 additions and 304 deletions.
12 changes: 0 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,6 @@ check_function_exists(ppoll HAVE_PPOLL)
check_include_file(linux/serial.h HAVE_LINUX_SERIAL -DHAVE_LINUX_SERIAL=1)
check_include_file(dev/usb/uftdiio.h HAVE_FREEBSD_UFTDI -DHAVE_FREEBSD_UFTDI=1)

check_function_exists(argp_parse HAVE_ARGP_H)
if(NOT HAVE_ARGP_H)
if(NOT ARGP_HINTS)
set(ARGP_HINTS ~/argp-standalone/src)
endif(NOT ARGP_HINTS)
find_library(LIB_ARGP NAMES argp argp-standalone HINTS ARGP_HINTS)
if (NOT LIB_ARGP)
message(FATAL_ERROR "argp library not available")
endif(NOT LIB_ARGP)
set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES} ${LIB_ARGP}")
endif(NOT HAVE_ARGP_H)

option(coverage "enable code coverage tracking." OFF)
if(NOT coverage STREQUAL OFF)
add_definitions(-g -O0 --coverage -Wall)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Building ebusd from the source requires the following packages and/or features:
* g++ with C++11 support (>=4.8.1)
* make
* kernel with pselect or ppoll support
* glibc with argp support or argp-standalone
* glibc with getopt_long support
* libmosquitto-dev for MQTT support
* libssl-dev for SSL support

Expand Down
3 changes: 0 additions & 3 deletions config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
/* Defined if syslog.h is available. */
#cmakedefine HAVE_SYSLOG_H

/* Defined if argp.h is available. */
#cmakedefine HAVE_ARGP_H

/* The name of package. */
#cmakedefine PACKAGE "${PACKAGE_NAME}"

Expand Down
8 changes: 0 additions & 8 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ if test "x$with_contrib" != "xno"; then
fi
AC_ARG_WITH(ebusfeed, AS_HELP_STRING([--with-ebusfeed], [enable inclusion of ebusfeed tool]), [with_ebusfeed=yes], [])
AM_CONDITIONAL([WITH_EBUSFEED], [test "x$with_ebusfeed" == "xyes"])
AC_ARG_WITH(argp-lib, AS_HELP_STRING([--with-argp-lib=PATH], [path to argp libraries]), [LDFLAGS+="-L$with_argp_lib"])
AC_ARG_WITH(argp-include, AS_HELP_STRING([--with-argp-include=PATH], [path to argp includes]), [CXXFLAGS+="-I$with_argp_include"])
AC_CHECK_FUNC([argp_parse], [have_argp=yes], AC_CHECK_LIB([argp], [argp_parse], [have_argp=yes; LIBS="-largp $LIBS"], [have_argp=no]))
if test "x$have_argp" = "xyes"; then
AC_CHECK_HEADER([argp.h], AC_DEFINE([HAVE_ARGP_H], [1], [Defined if argp.h is available.]), AC_MSG_ERROR([argp.h not found]))
else
AC_MSG_ERROR([argp library not found, specify argp-standalone location in --with-argp-lib= and --with-argp-include= options.])
fi
AC_ARG_WITH(mqtt, AS_HELP_STRING([--without-mqtt], [disable support for MQTT handling]), [], [with_mqtt=yes])
if test "x$with_mqtt" != "xno"; then
AC_CHECK_LIB([mosquitto], [mosquitto_lib_init],
Expand Down
2 changes: 1 addition & 1 deletion contrib/alpine/APKBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ url="https://github.com/john30/ebusd"
# Upstream only supports these archs.
arch="x86 x86_64 aarch64 armhf armv7"
license="GPL-3.0-only"
makedepends="argp-standalone cmake mosquitto-dev openssl-dev"
makedepends="cmake mosquitto-dev openssl-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/john30/${pkgname}/archive/refs/tags/${pkgver}.tar.gz"

build() {
Expand Down
2 changes: 1 addition & 1 deletion src/ebusd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ include_directories(../lib/ebus)
include_directories(../lib/utils)

add_executable(ebusd ${ebusd_SOURCES})
target_link_libraries(ebusd utils ebus pthread rt ${LIB_ARGP} ${ebusd_LIBS})
target_link_libraries(ebusd utils ebus pthread rt ${ebusd_LIBS})

install(TARGETS ebusd EXPORT ebusd DESTINATION usr/bin)

18 changes: 9 additions & 9 deletions src/ebusd/datahandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@

namespace ebusd {

/** the final @a argp_child structure. */
static const struct argp_child g_last_argp_child = {nullptr, 0, nullptr, 0};
/** the final @a argParseChildOpt structure. */
static const argParseChildOpt g_last_arg_child = {nullptr, nullptr};

/** the list of @a argp_child structures. */
static struct argp_child g_argp_children[
/** the list of @a argParseChildOpt structures. */
static argParseChildOpt g_arg_children[
1
#ifdef HAVE_MQTT
+1
Expand All @@ -44,17 +44,17 @@ static struct argp_child g_argp_children[
#endif
];

const struct argp_child* datahandler_getargs() {
const argParseChildOpt* datahandler_getargs() {
size_t count = 0;
#ifdef HAVE_MQTT
g_argp_children[count++] = *mqtthandler_getargs();
g_arg_children[count++] = *mqtthandler_getargs();
#endif
#ifdef HAVE_KNX
g_argp_children[count++] = *knxhandler_getargs();
g_arg_children[count++] = *knxhandler_getargs();
#endif
if (count > 0) {
g_argp_children[count] = g_last_argp_child;
return g_argp_children;
g_arg_children[count] = g_last_arg_child;
return g_arg_children;
}
return nullptr;
}
Expand Down
8 changes: 4 additions & 4 deletions src/ebusd/datahandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
#ifndef EBUSD_DATAHANDLER_H_
#define EBUSD_DATAHANDLER_H_

#include <argp.h>
#include <map>
#include <list>
#include <string>
#include "ebusd/bushandler.h"
#include "lib/ebus/message.h"
#include "lib/utils/arg.h"

namespace ebusd {

Expand All @@ -49,10 +49,10 @@ enum scanStatus_t {


/**
* Helper function for getting the argp definition for all known @a DataHandler instances.
* @return a pointer to the argp_child structure, or nullptr.
* Helper function for getting the arg definition for all known @a DataHandler instances.
* @return a pointer to the child argument options, or nullptr.
*/
const struct argp_child* datahandler_getargs();
const argParseChildOpt* datahandler_getargs();

/**
* Registration function that is called once during initialization.
Expand Down
31 changes: 14 additions & 17 deletions src/ebusd/knxhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ using std::dec;
#define O_VAR (O_INT-1)

/** the definition of the KNX arguments. */
static const struct argp_option g_knx_argp_options[] = {
static const argDef g_knx_argDefs[] = {
{nullptr, 0, nullptr, 0, "KNX options:", 1 },
{"knxurl", O_URL, "URL", OPTION_ARG_OPTIONAL, "URL to open (i.e. \"[multicast][@interface]\" for KNXnet/IP"
{"knxurl", O_URL, "URL", af_optional, "URL to open (i.e. \"[multicast][@interface]\" for KNXnet/IP"
#ifdef HAVE_KNXD
" or \"ip:host[:port]\" / \"local:/socketpath\" for knxd"
#endif
Expand All @@ -79,11 +79,11 @@ static vector<string>* g_integrationVars = nullptr; //!< the integration settin

/**
* The KNX argument parsing function.
* @param key the key from @a g_knx_argp_options.
* @param key the key from @a g_knx_arg_options.
* @param arg the option argument, or nullptr.
* @param state the parsing state.
*/
static error_t knx_parse_opt(int key, char *arg, struct argp_state *state) {
static int knx_parse_opt(int key, char *arg, const argParseOpt *parseOpt) {
result_t result;
unsigned int value;
switch (key) {
Expand All @@ -94,33 +94,33 @@ static error_t knx_parse_opt(int key, char *arg, struct argp_state *state) {

case O_AGR: // --knxrage=5
if (arg == nullptr || arg[0] == 0) {
argp_error(state, "invalid knxrage value");
argParseError(parseOpt, "invalid knxrage value");
return EINVAL;
}
value = parseInt(arg, 10, 0, 99999999, &result);
if (result != RESULT_OK) {
argp_error(state, "invalid knxrage");
argParseError(parseOpt, "invalid knxrage");
return EINVAL;
}
g_maxReadAge = value;
break;

case O_AGW: // --knxwage=5
if (arg == nullptr || arg[0] == 0) {
argp_error(state, "invalid knxwage value");
argParseError(parseOpt, "invalid knxwage value");
return EINVAL;
}
value = parseInt(arg, 10, 0, 99999999, &result);
if (result != RESULT_OK) {
argp_error(state, "invalid knxwage");
argParseError(parseOpt, "invalid knxwage");
return EINVAL;
}
g_maxWriteAge = value;
break;

case O_INT: // --knxint=/etc/ebusd/knx.cfg
if (arg == nullptr || arg[0] == 0 || strcmp("/", arg) == 0) {
argp_error(state, "invalid knxint file");
argParseError(parseOpt, "invalid knxint file");
return EINVAL;
}
g_integrationFile = arg;
Expand All @@ -129,7 +129,7 @@ static error_t knx_parse_opt(int key, char *arg, struct argp_state *state) {
case O_VAR: // --knxvar=NAME=VALUE[,NAME=VALUE]*
{
if (arg == nullptr || arg[0] == 0 || !strchr(arg, '=')) {
argp_error(state, "invalid knxvar");
argParseError(parseOpt, "invalid knxvar");
return EINVAL;
}
if (!g_integrationVars) {
Expand All @@ -143,18 +143,15 @@ static error_t knx_parse_opt(int key, char *arg, struct argp_state *state) {
}

default:
return ARGP_ERR_UNKNOWN;
return ESRCH;
}
return 0;
}

static const struct argp g_knx_argp = { g_knx_argp_options, knx_parse_opt, nullptr, nullptr, nullptr, nullptr,
nullptr };
static const struct argp_child g_knx_argp_child = {&g_knx_argp, 0, "", 1};
static const argParseChildOpt g_knx_arg_child = { g_knx_argDefs, knx_parse_opt };


const struct argp_child* knxhandler_getargs() {
return &g_knx_argp_child;
const argParseChildOpt* knxhandler_getargs() {
return &g_knx_arg_child;
}

bool knxhandler_register(UserInfo* userInfo, BusHandler* busHandler, MessageMap* messages,
Expand Down
7 changes: 4 additions & 3 deletions src/ebusd/knxhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "lib/ebus/message.h"
#include "lib/ebus/stringhelper.h"
#include "lib/knx/knx.h"
#include "lib/utils/arg.h"

namespace ebusd {

Expand All @@ -41,10 +42,10 @@ using std::string;
using std::vector;

/**
* Helper function for getting the argp definition for KNX.
* @return a pointer to the argp_child structure.
* Helper function for getting the arg definition for KNX.
* @return a pointer to the child argument options, or nullptr.
*/
const struct argp_child* knxhandler_getargs();
const argParseChildOpt* knxhandler_getargs();

/**
* Registration function that is called once during initialization.
Expand Down
Loading

0 comments on commit 22b6f02

Please sign in to comment.