diff --git a/Dockerfile b/Dockerfile index 010cdef..d6c2afb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ ARG ARCH=armv7hf ARG REPO=axisecp -ARG VERSION=1.7 +ARG VERSION=1.14 ARG UBUNTU_VERSION=22.04 FROM arm64v8/ubuntu:${UBUNTU_VERSION} AS containerized_aarch64 diff --git a/Makefile b/Makefile index 34cd81c..4d3fa6e 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,7 @@ PKG_CONFIG_CFLAGS_OTHER := $(shell PKG_CONFIG_SYSROOT_DIR="" PKG_CONFIG_PATH=$(P PKG_CONFIG_LDFLAGS := $(shell PKG_CONFIG_SYSROOT_DIR="" PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --libs-only-L $(PKGS)) PKG_CONFIG_LDLIBS := $(shell PKG_CONFIG_SYSROOT_DIR="" PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --libs-only-l $(PKGS)) -PKGS = gio-2.0 glib-2.0 vdostream +PKGS = gio-2.0 glib-2.0 vdostream axparameter PKG_CONFIG_CFLAGS_I += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --cflags-only-I $(PKGS)) PKG_CONFIG_CFLAGS_OTHER += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --cflags-only-other $(PKGS)) PKG_CONFIG_LDFLAGS += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --libs-only-L $(PKGS)) diff --git a/src/parameter.cpp b/src/parameter.cpp index 1a5fb89..bbd40c6 100644 --- a/src/parameter.cpp +++ b/src/parameter.cpp @@ -31,49 +31,44 @@ namespace acap_runtime { bool Parameter::Init(const bool verbose) { _verbose = verbose; TRACELOG << "Init" << endl; + _error = NULL; + if (ax_parameter == NULL) + ax_parameter = ax_parameter_new(APP_NAME, &_error); + if (ax_parameter == NULL) { + ERRORLOG << "Error when creating axparameter: " << _error->message << endl; + g_clear_error(&_error); + return false; + } + return true; } -// Logic and data behind the server's behavior. Status Parameter::GetValues(ServerContext* context, ServerReaderWriter* stream) { - char parhand_result[BUFSIZ]; - Request request; + Response response; while (stream->Read(&request)) { - size_t pos = 0; - const char* parameter_value = NULL; - string parhand_cmd = "parhandclient get "; - string parameter_key = request.key().c_str(); - const regex pattern("[a-zA-Z0-9.]+"); - if (regex_match(parameter_key, pattern)) { - string parhandclient_cmd = parhand_cmd + parameter_key; - - FILE* fp = popen(parhandclient_cmd.c_str(), "r"); - if (!fp) { - throw std::runtime_error("popen() failed!"); - } - std::string value; - if (fgets(parhand_result, BUFSIZ, fp) != NULL) { - value = parhand_result; - while ((pos = value.find('"', pos)) != std::string::npos) - value = value.erase(pos, 1); - parameter_value = value.c_str(); - } - if (parameter_value != nullptr) { - TRACELOG << request.key().c_str() << ": " << parameter_value << endl; - } else { - parameter_value = ""; - TRACELOG << request.key().c_str() << ": " << parameter_value << endl; - } + if (ax_parameter == NULL) { + ERRORLOG << "axparameter not initalized" << endl; + return Status::CANCELLED; + } - Response response; - response.set_value(parameter_value); - stream->Write(response); - pclose(fp); - } else { + const gchar* parameter_key = request.key().c_str(); + const regex pattern("[a-zA-Z0-9.]+"); + if (!regex_match(parameter_key, pattern)) { TRACELOG << "No valid input request" << endl; return Status(StatusCode::INVALID_ARGUMENT, "No valid input request"); } + char* parameter_value = NULL; + if (!ax_parameter_get(ax_parameter, parameter_key, ¶meter_value, &_error)) { + ERRORLOG << "Error when getting axparameter: " << _error->message << endl; + parameter_value = g_strdup(""); + g_clear_error(&_error); + } + TRACELOG << parameter_key << ": " << parameter_value << endl; + + response.set_value(parameter_value); + stream->Write(response); + free(parameter_value); } return Status::OK; diff --git a/src/parameter.h b/src/parameter.h index f84d616..23adfdb 100644 --- a/src/parameter.h +++ b/src/parameter.h @@ -15,6 +15,7 @@ */ #include "keyvaluestore.grpc.pb.h" +#include #ifdef TEST #define APP_NAME "acapruntimetest" @@ -35,6 +36,8 @@ class Parameter final : public KeyValueStore::Service { private: Status GetValues(ServerContext* context, ServerReaderWriter* stream); + AXParameter* ax_parameter; + GError* _error; bool _verbose; }; } // namespace acap_runtime