diff --git a/Makefile b/Makefile index 883483cc..b2452583 100644 --- a/Makefile +++ b/Makefile @@ -198,6 +198,7 @@ PUB:=pub PUB_C:=$(PUB)/c PMC_DIR:=ptp-tools JSON_SRC:=json +JCLKLIB_SRC:=jclklib OBJ_DIR:=objs CONF_FILES:=configure src/config.h.in @@ -225,11 +226,16 @@ HEADERS_INST:=$(HEADERS_PUB) $(HEADERS_GEN_PUB) HEADERS_INST_C:=$(HEADERS_PUB_C) $(HEADERS_GEN_PUB_C) SRCS:=$(wildcard $(SRC)/*.cpp) SRCS_JSON:=$(wildcard $(JSON_SRC)/*.cpp) +SRCS_JCLKLIB:=$(wildcard $(JCLKLIB_SRC)/*.cpp) COMP_DEPS:=$(OBJ_DIR) $(HEADERS_GEN_COMP) # json-c JSONC_LIB:=$(LIB_NAME)_jsonc.so JSONC_LIBA:=$(LIB_NAME)_jsonc.a JSONC_FLIB:=$(JSONC_LIB)$(SONAME) +# jclklib +JCLKLIB_LIB:=jclklib.so +#JSONC_LIBA:=$(LIB_NAME)_jsonc.a +JCLKLIB_FLIB:=$(JCLKLIB_LIB)$(SONAME) # fastjson FJSON_LIB:=$(LIB_NAME)_fastjson.so FJSON_LIBA:=$(LIB_NAME)_fastjson.a @@ -257,7 +263,9 @@ endif SRC_FILES_DIR:=$(wildcard scripts/* *.md t*/*.pl */*/*.m4 .reuse/* */gitlab*\ */github* */*.opt config.guess config.sub configure.ac install-sh */*.m4\ t*/*.sh */*/*.sh swig/*.md swig/*/* */*.i */*/msgCall.i */*/warn.i man/*\ - $(PMC_DIR)/phc_ctl $(PMC_DIR)/*.[ch]* $(JSON_SRC)/* */Makefile w*/*/Makefile\ + $(PMC_DIR)/phc_ctl $(PMC_DIR)/*.[ch]* $(JSON_SRC)/*\ + $(JCLKLIB_SRC)/common/* $(JCLKLIB_SRC)/proxy/* $(JCLKLIB_SRC)/client/*\ + */Makefile w*/*/Makefile\ */*/*test*/*.go LICENSES/* *.in tools/*.in) src/ver.h.in src/name.h.in\ $(SRCS) $(HEADERS_SRCS) LICENSE $(MAKEFILE_LIST) credits ifeq ($(INSIDE_GIT),true) @@ -392,6 +400,7 @@ endif # VALGRIND # JSON libraries include $(JSON_SRC)/Makefile +include $(JCLKLIB_SRC)/Makefile # Compile library source code $(LIB_OBJS): $(OBJ_DIR)/%.o: $(SRC)/%.cpp | $(COMP_DEPS) @@ -444,7 +453,7 @@ CPPCHECK_OPT+=--suppress=preprocessorErrorDirective EXTRA_C_SRCS:=$(wildcard uctest/*.c) EXTRA_SRCS:=$(wildcard $(foreach n,sample utest uctest,$n/*.cpp $n/*.h)) EXTRA_SRCS+=$(EXTRA_C_SRCS) -format: $(HEADERS_GEN) $(HEADERS_SRCS) $(SRCS) $(EXTRA_SRCS) $(SRCS_JSON) +format: $(HEADERS_GEN) $(HEADERS_SRCS) $(SRCS) $(EXTRA_SRCS) $(SRCS_JSON) $(SRCS_JCLKLIB) $(Q_FRMT) r=`$(ASTYLE) --project=none --options=tools/astyle.opt $^` test -z "$$r" || echo "$$r";./tools/format.pl $^ @@ -554,13 +563,13 @@ checkall: format doxygen ifneq ($(CTAGS),) tags: $(filter-out $(SRC)/ids.h,$(HEADERS_GEN_COMP)) $(HEADERS_SRCS) $(SRCS)\ - $(SRCS_JSON) + $(SRCS_JSON) $(SRCS_JCLKLIB) $(Q_TAGS)$(CTAGS) -R $^ ALL+=tags endif # CTAGS .DEFAULT_GOAL=all -all: $(COMP_DEPS) $(ALL) +all: $(COMP_DEPS) $(ALL) jclklib $(NOP) ####### installation ####### @@ -751,7 +760,7 @@ DISTCLEAN:=$(addprefix config.,log status) configure configure~ defs.mk\ $(wildcard src/config.h*) DISTCLEAN_DIRS:=autom4te.cache -clean: deb_clean +clean: deb_clean jclklib_clean $(Q_CLEAN)$(RM) $(CLEAN) $(RM) -R $(CLEAN_DIRS) distclean: deb_clean diff --git a/jclklib/Makefile b/jclklib/Makefile index 44d41bbf..f6019ab7 100644 --- a/jclklib/Makefile +++ b/jclklib/Makefile @@ -11,14 +11,20 @@ CWD := $(shell pwd) -.PHONY: all -all: - $(MAKE) -C $(CWD)/common default - $(MAKE) -C $(CWD)/proxy default - $(MAKE) -C $(CWD)/client default +.PHONY: jclklib +jclklib: + $(MAKE) -C $(CWD)/jclklib/common default + $(MAKE) -C $(CWD)/jclklib/proxy default + $(MAKE) -C $(CWD)/jclklib/client default +# $(MAKE) -C $(CWD)/jclklib/test default -.PHONY: clean -clean: - $(MAKE) -C $(CWD)/client clean - $(MAKE) -C $(CWD)/proxy clean - $(MAKE) -C $(CWD)/common clean +.PHONY: jclklib_test +jclklib_test: + $(MAKE) -C $(CWD)/jclklib/test default + +.PHONY: jclklib_clean +jclklib_clean: + $(MAKE) -C $(CWD)/jclklib/client clean + $(MAKE) -C $(CWD)/jclklib/proxy clean + $(MAKE) -C $(CWD)/jclklib/common clean +# $(MAKE) -C $(CWD)/jclklib/test clean diff --git a/jclklib/test/Makefile b/jclklib/test/Makefile new file mode 100644 index 00000000..7ec0fac6 --- /dev/null +++ b/jclklib/test/Makefile @@ -0,0 +1,28 @@ +# SPDX-License-Identifier: LGPL-3.0-or-later +# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. +# +# Makefile for jclklib client +# +# @author Christopher Hall +# @copyright © 2024 Intel Corporation. All rights reserved. +# @license LGPL-3.0-or-later +# +############################################################################### + + +JCLKLIB_CLIENT_DIR := $(shell pwd)/../client +JCLKLIB_TOPLEVEL_DIR = $(JCLKLIB_CLIENT_DIR)/.. +JCLKLIB_COMMON_DIR = $(JCLKLIB_TOPLEVEL_DIR)/common + +default: test + +#.PHONY: build-all +#build-all: test +# echo "Running" $@ +# $(MAKE) -C $(JCLKLIB_CLIENT_DIR) $(REAL_TARGETS) +test: test.o jclklib.so + g++ -o test test.o -L $(JCLKLIB_CLIENT_DIR) -I $(JCLKLIB_CLIENT_DIR)/.. -l:jclklib.so + +#%.o : %.cpp +# echo "[COMPILE]" $< +# g++ -c $< -I $(JCLKLIB_TOPLEVEL_DIR) -fPIC -fdiagnostics-color=always diff --git a/jclklib/test/test.cpp b/jclklib/test/test.cpp new file mode 100644 index 00000000..fe770cc6 --- /dev/null +++ b/jclklib/test/test.cpp @@ -0,0 +1,269 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file test.cpp + * @brief Test client code + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace JClkLibClient; +using namespace JClkLibCommon; + +volatile sig_atomic_t signal_flag = 0; + +void signal_handler(int sig) +{ + signal_flag = 1; +} + +int main(int argc, char *argv[]) +{ + int timeout = 10; + int upper_master_offset = 100000; + int lower_master_offset = -100000; + int ret = 0; + JClkLibCommon::jcl_subscription sub = {}; + JClkLibCommon::jcl_state jcl_state = {}; + JClkLibCommon::jcl_state_event_count eventCount = {}; + + std::uint32_t event2Sub1[1] = { + ((1<init(); + + ClientState &myState = cmAPI->getClientState(); + + if (cmAPI->jcl_connect() == false) { + std::cout << "[jclklib] Failure in connecting !!!\n"; + ret = EXIT_FAILURE; + goto do_exit; + } + else { + std::cout << "[jclklib] Connected. Session ID : " << + myState.get_sessionId() << "\n"; + } + + sleep(1); + + + sub.get_event().writeEvent(event2Sub1, (std::size_t)sizeof(event2Sub1)); + sub.get_value().setValue(gmOffsetValue, upper_master_offset, + lower_master_offset); + sub.get_composite_event().writeEvent(composite_event, + (std::size_t)sizeof(composite_event)); + std::cout << "[jclklib] set subscribe event : " + + sub.c_get_val_event().toString(); + std::cout << "[jclklib] set composite event : " + + sub.c_get_val_composite_event().toString() << "\n"; + std::cout << "Upper Master Offset: " << upper_master_offset << " ns\n"; + std::cout << "Lower Master Offset: " << lower_master_offset << " ns\n\n"; + + if (cmAPI->jcl_subscribe(sub, jcl_state) == false) { + std::cerr << "[jclklib] Failure in subscribing to jclklib Proxy !!!\n"; + cmAPI->jcl_disconnect(); + return EXIT_FAILURE; + } + + printf("[jclklib] Obtained data from Subscription Event:\n"); + printf("+-------------------+--------------------+\n"); + printf("| %-17s | %-18s |\n", "Event", "Event Status"); + if (event2Sub1[0]) { + printf("+-------------------+--------------------+\n"); + } + if (event2Sub1[0] & (1<jcl_status_wait(timeout, jcl_state , eventCount)) { + printf("No event status changes identified in %d seconds.\n\n", + timeout); + sleep(1); + continue; + } + printf("[jclklib] Obtained data from Notification Event:\n"); + printf("+-------------------+--------------+-------------+\n"); + printf("| %-17s | %-12s | %-11s |\n", "Event", "Event Status", + "Event Count"); + if (event2Sub1[0]) { + printf("+-------------------+--------------+-------------+\n"); + } + if (event2Sub1[0] & (1<jcl_disconnect(); + + return EXIT_SUCCESS; +}