From 935c4a63deed582e3860225ade8e6f11283f4b4c Mon Sep 17 00:00:00 2001 From: Noor Azura Ahmad Tarmizi Date: Thu, 1 Feb 2024 13:47:13 +0800 Subject: [PATCH 001/151] Add Intel files --- CODE_OF_CONDUCT.md | 131 +++++++++++++++++++++++++++++++++++++++++++++ CONTRIBUTING.md | 57 ++++++++++++++++++++ README.md | 3 ++ SECURITY.md | 5 ++ 4 files changed, 196 insertions(+) create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md create mode 100644 SECURITY.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..58dba18d --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,131 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, caste, color, religion, or sexual +identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall + community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or advances of + any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email address, + without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +CommunityCodeOfConduct AT intel DOT com. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of +actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or permanent +ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the +community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.1, available at +[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][Mozilla CoC]. + +For answers to common questions about this code of conduct, see the FAQ at +[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at +[https://www.contributor-covenant.org/translations][translations]. + +[homepage]: https://www.contributor-covenant.org +[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html +[Mozilla CoC]: https://github.com/mozilla/diversity +[FAQ]: https://www.contributor-covenant.org/faq diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..f682f4e4 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,57 @@ +# Contributing + +### License + + is licensed under the terms in [LICENSE]. By contributing to the project, you agree to the license and copyright terms therein and release your contribution under these terms. + +### Sign your work + +Please use the sign-off line at the end of the patch. Your signature certifies that you wrote the patch or otherwise have the right to pass it on as an open-source patch. The rules are pretty simple: if you can certify +the below (from [developercertificate.org](http://developercertificate.org/)): + +``` +Developer Certificate of Origin +Version 1.1 + +Copyright (C) 2004, 2006 The Linux Foundation and its contributors. +660 York Street, Suite 102, +San Francisco, CA 94110 USA + +Everyone is permitted to copy and distribute verbatim copies of this +license document, but changing it is not allowed. + +Developer's Certificate of Origin 1.1 + +By making a contribution to this project, I certify that: + +(a) The contribution was created in whole or in part by me and I + have the right to submit it under the open source license + indicated in the file; or + +(b) The contribution is based upon previous work that, to the best + of my knowledge, is covered under an appropriate open source + license and I have the right under that license to submit that + work with modifications, whether created in whole or in part + by me, under the same open source license (unless I am + permitted to submit under a different license), as indicated + in the file; or + +(c) The contribution was provided directly to me by some other + person who certified (a), (b) or (c) and I have not modified + it. + +(d) I understand and agree that this project and the contribution + are public and that a record of the contribution (including all + personal information I submit with it, including my sign-off) is + maintained indefinitely and may be redistributed consistent with + this project or the open source license(s) involved. +``` + +Then you just add a line to every git commit message: + + Signed-off-by: Joe Smith + +Use your real name (sorry, no pseudonyms or anonymous contributions.) + +If you set your `user.name` and `user.email` git configs, you can sign your +commit automatically with `git commit -s`. diff --git a/README.md b/README.md index 4f024e12..fcbe9b44 100644 --- a/README.md +++ b/README.md @@ -156,3 +156,6 @@ The Licence of this project is * The library is under LGPL v3 or later. * The pmc and phc_ctl tools and the testing scripts are under GPL v3 or later. * Documentation is under under GFDL v1.3 or later without invariants sections. + +# Disclaimer +This project is under development. All source code and features on the main branch are for the purpose of testing or evaluation and not production ready. diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 00000000..cb59eb89 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,5 @@ +# Security Policy +Intel is committed to rapidly addressing security vulnerabilities affecting our customers and providing clear guidance on the solution, impact, severity and mitigation. + +## Reporting a Vulnerability +Please report any security vulnerabilities in this project utilizing the guidelines [here](https://www.intel.com/content/www/us/en/security-center/vulnerability-handling-guidelines.html). From 0244c1cfdef33dfe5ca374ecbc84cf04fcaf56af Mon Sep 17 00:00:00 2001 From: Christopher S M Hall Date: Mon, 5 Feb 2024 08:30:41 -0500 Subject: [PATCH 002/151] Add additional field in TIME_STATUS_NP message --- ptp-tools/pmc_dump.cpp | 6 ++++-- pub/msg.h | 6 ++++++ sample/checksync.cpp | 2 ++ src/comp.h | 2 ++ src/ids_base.m4 | 2 +- src/json.cpp | 4 +++- src/msg.cpp | 10 ++++++++++ src/proc.cpp | 2 +- src/proc.m4 | 1 + src/types.m4 | 21 +++++++++++++++++++++ 10 files changed, 51 insertions(+), 5 deletions(-) diff --git a/ptp-tools/pmc_dump.cpp b/ptp-tools/pmc_dump.cpp index 7dacda96..2236987e 100644 --- a/ptp-tools/pmc_dump.cpp +++ b/ptp-tools/pmc_dump.cpp @@ -358,7 +358,8 @@ class MsgDump : public MessageDispatcher IDENT "gmTimeBaseIndicator %u" IDENT "lastGmPhaseChange 0x%04hx'%016jd.%04hx" IDENT "gmPresent %s" - IDENT "gmIdentity %s", + IDENT "gmIdentity %s" + IDENT "servo_state %s", d.master_offset, d.ingress_time, (float_nanoseconds)d.cumulativeScaledRateOffset / P41, @@ -369,7 +370,8 @@ class MsgDump : public MessageDispatcher d.nanoseconds_lsb, d.fractional_nanoseconds, d.gmPresent ? "true" : "false", - d.gmIdentity.string().c_str()); + d.gmIdentity.string().c_str(), + m.servo2str_c(d.servo_state)); } dump(GRANDMASTER_SETTINGS_NP) { DUMPS( diff --git a/pub/msg.h b/pub/msg.h index e47b775d..ab8d0987 100644 --- a/pub/msg.h +++ b/pub/msg.h @@ -182,6 +182,12 @@ class Message * @return string with the TLV type */ static const char *type2str_c(msgType_e type); + /** + * Convert servo state to string + * @param[in] state + * @return string with the servo state + */ + static const char *servo2str_c(servoState_e state); /** * Convert TLV type to string * @param[in] type diff --git a/sample/checksync.cpp b/sample/checksync.cpp index 2c0042dc..effd6291 100644 --- a/sample/checksync.cpp +++ b/sample/checksync.cpp @@ -21,6 +21,8 @@ #include #include #include +//#include +#include using namespace ptpmgmt; diff --git a/src/comp.h b/src/comp.h index aae9726a..54787c73 100644 --- a/src/comp.h +++ b/src/comp.h @@ -338,6 +338,7 @@ struct MsgProc { bool proc(SMPTEmasterLockingStatus_e &val) { return procE8(val); } bool proc(linuxptpTimeStamp_e &val) { return procE8(val); } bool proc(linuxptpUnicastState_e &val) { return procE8(val); } + bool proc(servoState_e &val) { return procE8(val); } /* For Enumerators using 16 bits */ template bool procE16(T &val); bool proc(networkProtocol_e &val) { return procE16(val); } @@ -535,6 +536,7 @@ struct JsonProc { _ptpmProcType(FaultRecord_t) _ptpmProcType(AcceptableMaster_t) _ptpmProcType(LinuxptpUnicastMaster_t) + _ptpmProcType(servoState_e) virtual bool procBinary(const char *name, Binary &val, uint16_t &len) = 0; virtual bool procBinary(const char *name, uint8_t *val, size_t len) = 0; virtual bool procFlag(const char *name, uint8_t &flags, int mask) = 0; diff --git a/src/ids_base.m4 b/src/ids_base.m4 index b245d25c..a5f85faa 100644 --- a/src/ids_base.m4 +++ b/src/ids_base.m4 @@ -79,7 +79,7 @@ dnl linuxptp TLVs (in Implementation-specific C000-DFFF) dnl Shortcuts defined in msg.cpp dnl use_GL => A_GET | A_USE_LINUXPTP dnl use_GSL => A_GET | A_SET | A_USE_LINUXPTP -A(TIME_STATUS_NP, c000, clock, use_GL, 50, UF) +A(TIME_STATUS_NP, c000, clock, use_GL, 51, UF) A(GRANDMASTER_SETTINGS_NP, c001, clock, use_GSL, 8, UFB) A(PORT_DATA_SET_NP, c002, port, use_GSL, 8, UFB) A(SUBSCRIBE_EVENTS_NP, c003, clock, use_GSL, 66, UFB) diff --git a/src/json.cpp b/src/json.cpp index 5028198c..b113c116 100644 --- a/src/json.cpp +++ b/src/json.cpp @@ -357,7 +357,8 @@ JS(TIME_STATUS_NP) PROC_VAL(nanoseconds_lsb) && PROC_VAL(fractional_nanoseconds) && PROC_VAL(gmPresent) && - PROC_VAL(gmIdentity); + PROC_VAL(gmIdentity) && + PROC_VAL(servo_state); } JS(GRANDMASTER_SETTINGS_NP) { @@ -707,6 +708,7 @@ struct JsonProcToJson : public JsonProc { procTypeEnum(managementErrorId_e, errId2str_c) procTypeEnum(SMPTEmasterLockingStatus_e, smpteLck2str_c) procTypeEnumR(networkProtocol_e, netProt2str_c) + procTypeEnumR(servoState_e, servo2str_c) bool procValue(const char *name, mng_vals_e val) { if(val != SMPTE_MNG_ID) procString(name, Message::mng2str_c(val)); diff --git a/src/msg.cpp b/src/msg.cpp index 2592fcb6..80207184 100644 --- a/src/msg.cpp +++ b/src/msg.cpp @@ -722,6 +722,16 @@ const char *Message::type2str_c(msgType_e type) } return "unknown message type"; } +const char *Message::servo2str_c(servoState_e state) +{ + switch(state) { + case caseItem(SERVO_UNLOCKED); + case caseItem(SERVO_JUMP); + case caseItem(SERVO_LOCKED); + case caseItem(SERVO_LOCKED_STABLE); + } + return "unknown servo state"; +} const char *Message::tlv2str_c(tlvType_e type) { switch(type) { diff --git a/src/proc.cpp b/src/proc.cpp index f73a94b9..c729f4a4 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -812,7 +812,7 @@ A(TIME_STATUS_NP) proc(d.scaledLastGmPhaseChange) || proc(d.gmTimeBaseIndicator) || proc(d.nanoseconds_msb) || proc(d.nanoseconds_lsb) || proc(d.fractional_nanoseconds) || proc(d.gmPresent) || - proc(d.gmIdentity); + proc(d.gmIdentity) || proc(d.servo_state); } A(GRANDMASTER_SETTINGS_NP) { diff --git a/src/proc.m4 b/src/proc.m4 index 3791723d..d3ef1d3e 100644 --- a/src/proc.m4 +++ b/src/proc.m4 @@ -441,6 +441,7 @@ strc(TIME_STATUS_NP_t) sz(: public BaseMngTlv) { uint16_t fractional_nanoseconds; Integer32_t gmPresent; /**< Flag for grandmaster presence */ strcc(ClockIdentity_t) gmIdentity; /**< Grandmaster clock ID */ + enmc(servoState_e) servo_state; /** Servo state */ }; /** Grandmaster settings TLV * @note linuxptp implementation specific diff --git a/src/types.m4 b/src/types.m4 index 6c513015..488c77a8 100644 --- a/src/types.m4 +++ b/src/types.m4 @@ -328,6 +328,27 @@ enm(delayMechanism_e) sz(: uint8_t) { /** Special Ports do not use either delay mechanism. */ NM(SPECIAL) = 4, }; +/** Servo State */ +enm(servoState_e) sz(: uint8_t) { + /** + * The servo is not yet ready to track the master clock. + */ + NM(SERVO_UNLOCKED) = 0, + /** + * The servo is ready to track and requests a clock jump to + * immediately correct the estimated offset. + */ + NM(SERVO_JUMP) = 1, + /** + * The servo is tracking the master clock. + */ + NM(SERVO_LOCKED) = 2, + /** + * The Servo has stabilized. The last 'servo_num_offset_values' values + * of the estimated threshold are less than servo_offset_threshold. + */ + NM(SERVO_LOCKED_STABLE) = 3, +}; /** Specify Management TLV implementation-specific to use * @note: Ruby's wrapping, capitalize first letter of enumerators values */ From 755491b2ce60f71d38e37a38c5b3052b9346cc2e Mon Sep 17 00:00:00 2001 From: Christopher Hall Date: Fri, 18 Aug 2023 16:15:45 -0700 Subject: [PATCH 003/151] Initial add of JClkLib proxy code Add upper and lower limits for threshold Fix name (SPC->'.') of client side message queue and add unlinking in finalize to cleanup queue --- jclklib/Makefile | 20 ++++ jclklib/client/Makefile | 68 +++++++++++++ jclklib/client/client_state.cpp | 10 ++ jclklib/client/client_state.hpp | 21 ++++ jclklib/client/connect_msg.cpp | 41 ++++++++ jclklib/client/connect_msg.hpp | 27 +++++ jclklib/client/init.cpp | 60 +++++++++++ jclklib/client/init.hpp | 17 ++++ jclklib/client/message.cpp | 19 ++++ jclklib/client/message.hpp | 33 ++++++ jclklib/client/msgq_tport.cpp | 122 ++++++++++++++++++++++ jclklib/client/msgq_tport.hpp | 56 ++++++++++ jclklib/client/null_msg.hpp | 26 +++++ jclklib/client/null_tport.cpp | 21 ++++ jclklib/client/null_tport.hpp | 25 +++++ jclklib/client/run_test.sh | 5 + jclklib/client/test.cpp | 21 ++++ jclklib/client/transport.cpp | 44 ++++++++ jclklib/client/transport.hpp | 45 ++++++++ jclklib/common/Makefile | 61 +++++++++++ jclklib/common/connect_msg.cpp | 54 ++++++++++ jclklib/common/connect_msg.hpp | 35 +++++++ jclklib/common/jclklib_import.cpp | 153 ++++++++++++++++++++++++++++ jclklib/common/jclklib_import.hpp | 95 +++++++++++++++++ jclklib/common/jcltypes.hpp | 18 ++++ jclklib/common/message.cpp | 120 ++++++++++++++++++++++ jclklib/common/message.hpp | 90 ++++++++++++++++ jclklib/common/msgq_tport.cpp | 94 +++++++++++++++++ jclklib/common/msgq_tport.hpp | 66 ++++++++++++ jclklib/common/notification_msg.cpp | 19 ++++ jclklib/common/notification_msg.hpp | 37 +++++++ jclklib/common/null_msg.cpp | 21 ++++ jclklib/common/null_msg.hpp | 27 +++++ jclklib/common/null_tport.hpp | 26 +++++ jclklib/common/print.cpp | 64 ++++++++++++ jclklib/common/print.hpp | 36 +++++++ jclklib/common/serialize.hpp | 78 ++++++++++++++ jclklib/common/sighandler.cpp | 124 ++++++++++++++++++++++ jclklib/common/sighandler.hpp | 21 ++++ jclklib/common/subscribe_msg.cpp | 18 ++++ jclklib/common/subscribe_msg.hpp | 31 ++++++ jclklib/common/transport.cpp | 149 +++++++++++++++++++++++++++ jclklib/common/transport.hpp | 119 ++++++++++++++++++++++ jclklib/common/util.hpp | 55 ++++++++++ jclklib/proxy/Makefile | 66 ++++++++++++ jclklib/proxy/client.cpp | 28 +++++ jclklib/proxy/client.hpp | 31 ++++++ jclklib/proxy/clock_config.cpp | 64 ++++++++++++ jclklib/proxy/clock_config.hpp | 47 +++++++++ jclklib/proxy/clock_status.cpp | 60 +++++++++++ jclklib/proxy/clock_status.hpp | 42 ++++++++ jclklib/proxy/connect_msg.cpp | 49 +++++++++ jclklib/proxy/connect_msg.hpp | 30 ++++++ jclklib/proxy/main.cpp | 42 ++++++++ jclklib/proxy/message.cpp | 20 ++++ jclklib/proxy/message.hpp | 39 +++++++ jclklib/proxy/msgq_tport.cpp | 105 +++++++++++++++++++ jclklib/proxy/msgq_tport.hpp | 58 +++++++++++ jclklib/proxy/notification_msg.cpp | 26 +++++ jclklib/proxy/notification_msg.hpp | 32 ++++++ jclklib/proxy/null_msg.hpp | 29 ++++++ jclklib/proxy/null_tport.cpp | 21 ++++ jclklib/proxy/null_tport.hpp | 25 +++++ jclklib/proxy/subscribe_msg.cpp | 26 +++++ jclklib/proxy/subscribe_msg.hpp | 28 +++++ jclklib/proxy/transport.cpp | 47 +++++++++ jclklib/proxy/transport.hpp | 51 ++++++++++ 67 files changed, 3258 insertions(+) create mode 100644 jclklib/Makefile create mode 100644 jclklib/client/Makefile create mode 100644 jclklib/client/client_state.cpp create mode 100644 jclklib/client/client_state.hpp create mode 100644 jclklib/client/connect_msg.cpp create mode 100644 jclklib/client/connect_msg.hpp create mode 100644 jclklib/client/init.cpp create mode 100644 jclklib/client/init.hpp create mode 100644 jclklib/client/message.cpp create mode 100644 jclklib/client/message.hpp create mode 100644 jclklib/client/msgq_tport.cpp create mode 100644 jclklib/client/msgq_tport.hpp create mode 100644 jclklib/client/null_msg.hpp create mode 100644 jclklib/client/null_tport.cpp create mode 100644 jclklib/client/null_tport.hpp create mode 100755 jclklib/client/run_test.sh create mode 100644 jclklib/client/test.cpp create mode 100644 jclklib/client/transport.cpp create mode 100644 jclklib/client/transport.hpp create mode 100644 jclklib/common/Makefile create mode 100644 jclklib/common/connect_msg.cpp create mode 100644 jclklib/common/connect_msg.hpp create mode 100644 jclklib/common/jclklib_import.cpp create mode 100644 jclklib/common/jclklib_import.hpp create mode 100644 jclklib/common/jcltypes.hpp create mode 100644 jclklib/common/message.cpp create mode 100644 jclklib/common/message.hpp create mode 100644 jclklib/common/msgq_tport.cpp create mode 100644 jclklib/common/msgq_tport.hpp create mode 100644 jclklib/common/notification_msg.cpp create mode 100644 jclklib/common/notification_msg.hpp create mode 100644 jclklib/common/null_msg.cpp create mode 100644 jclklib/common/null_msg.hpp create mode 100644 jclklib/common/null_tport.hpp create mode 100644 jclklib/common/print.cpp create mode 100644 jclklib/common/print.hpp create mode 100644 jclklib/common/serialize.hpp create mode 100644 jclklib/common/sighandler.cpp create mode 100644 jclklib/common/sighandler.hpp create mode 100644 jclklib/common/subscribe_msg.cpp create mode 100644 jclklib/common/subscribe_msg.hpp create mode 100644 jclklib/common/transport.cpp create mode 100644 jclklib/common/transport.hpp create mode 100644 jclklib/common/util.hpp create mode 100644 jclklib/proxy/Makefile create mode 100644 jclklib/proxy/client.cpp create mode 100644 jclklib/proxy/client.hpp create mode 100644 jclklib/proxy/clock_config.cpp create mode 100644 jclklib/proxy/clock_config.hpp create mode 100644 jclklib/proxy/clock_status.cpp create mode 100644 jclklib/proxy/clock_status.hpp create mode 100644 jclklib/proxy/connect_msg.cpp create mode 100644 jclklib/proxy/connect_msg.hpp create mode 100644 jclklib/proxy/main.cpp create mode 100644 jclklib/proxy/message.cpp create mode 100644 jclklib/proxy/message.hpp create mode 100644 jclklib/proxy/msgq_tport.cpp create mode 100644 jclklib/proxy/msgq_tport.hpp create mode 100644 jclklib/proxy/notification_msg.cpp create mode 100644 jclklib/proxy/notification_msg.hpp create mode 100644 jclklib/proxy/null_msg.hpp create mode 100644 jclklib/proxy/null_tport.cpp create mode 100644 jclklib/proxy/null_tport.hpp create mode 100644 jclklib/proxy/subscribe_msg.cpp create mode 100644 jclklib/proxy/subscribe_msg.hpp create mode 100644 jclklib/proxy/transport.cpp create mode 100644 jclklib/proxy/transport.hpp diff --git a/jclklib/Makefile b/jclklib/Makefile new file mode 100644 index 00000000..aa4b0b5d --- /dev/null +++ b/jclklib/Makefile @@ -0,0 +1,20 @@ +##! \file Makefile +# \brief top level makefile +# +# (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. +# Author: Christopher Hall +# + +CWD := $(shell pwd) + +.PHONY: all +all: + $(MAKE) -C $(CWD)/common default + $(MAKE) -C $(CWD)/proxy default + $(MAKE) -C $(CWD)/client default + +.PHONY: clean +clean: + $(MAKE) -C $(CWD)/client clean + $(MAKE) -C $(CWD)/proxy clean + $(MAKE) -C $(CWD)/common clean diff --git a/jclklib/client/Makefile b/jclklib/client/Makefile new file mode 100644 index 00000000..4ed4016a --- /dev/null +++ b/jclklib/client/Makefile @@ -0,0 +1,68 @@ +##! \file Makefile +# \brief Client makefile +# +# (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. +# Author: Christopher Hall +# + +JCLKLIB_CLIENT_DIR := $(shell pwd) +JCLKLIB_TOPLEVEL_DIR = $(JCLKLIB_CLIENT_DIR)/.. +JCLKLIB_COMMON_DIR = $(JCLKLIB_TOPLEVEL_DIR)/common +LIBS = pthread rt +LIBS_FLAGS = $(foreach lib,$(LIBS),-l$(lib)) +OBJ = init msgq_tport message null_tport transport msgq_tport connect_msg client_state +COMMON_OBJ = print sighandler transport msgq_tport message connect_msg +OBJ_FILES = $(foreach f,$(OBJ),$(f).o) +DEPENDS = $(foreach f,$(OBJ),$(f).d) +COMMON_OBJ_DIR = $(JCLKLIB_COMMON_DIR)/obj +COMMON_OBJ_FILES = $(foreach obj,$(COMMON_OBJ),$(COMMON_OBJ_DIR)/$(obj).o) +REAL_TARGETS = jclklib.so test + +.PHONY: default +default: + $(MAKE) -s -C $(JCLKLIB_CLIENT_DIR) build-all 2>&1 | less -R + +.PHONY: build-prep +build-prep: + echo "Running" $@ + $(MAKE) -C $(JCLKLIB_CLIENT_DIR) $(DEPENDS) 2>&1 + + +%.d : %.cpp + echo "[MAKEDEP]" $@ + g++ -I $(JCLKLIB_TOPLEVEL_DIR) -MM -MF $@ $< + +.PHONY: clean +clean: + $(RM) -rf *.o *.d $(REAL_TARGETS) + +ifneq ($(MAKECMDGOALS),) +ifeq ($(findstring build-prep,$(MAKECMDGOALS)),) +ifeq ($(findstring build-all,$(MAKECMDGOALS)),) +ifeq ($(findstring clean,$(MAKECMDGOALS)),) +ifneq ($(suffix $(MAKECMDGOALS)),.d) +-include $(DEPENDS) +endif +endif +endif +endif +endif + +pathof_relative_to = $(foreach abpth,$(foreach dep,$1,$(shell realpath $(dep))), \ +$(shell realpath --relative-to="$2" $(abpth))) + +.PHONY: build-all +build-all: build-prep + echo "Running" $@ + $(MAKE) -C $(JCLKLIB_CLIENT_DIR) $(REAL_TARGETS) + +jclklib.so: $(OBJ_FILES) $(COMMON_OBJ_FILES) + echo "[LINK]" $@ "{" $(call pathof_relative_to,$^,$(JCLKLIB_TOPLEVEL_DIR)) "}" | fold -s + g++ -shared -o $@ $^ $(LIBS_FLAGS) -fdiagnostics-color=always + +test: test.o jclklib.so + g++ -o test test.o -L $(JCLKLIB_CLIENT_DIR) -l:jclklib.so + +%.o : %.cpp + echo "[COMPILE]" $< + g++ -c $< -g -I $(JCLKLIB_TOPLEVEL_DIR) -fPIC -fdiagnostics-color=always diff --git a/jclklib/client/client_state.cpp b/jclklib/client/client_state.cpp new file mode 100644 index 00000000..ddd195cf --- /dev/null +++ b/jclklib/client/client_state.cpp @@ -0,0 +1,10 @@ +#include + +using namespace JClkLibClient; + +ClientState::ClientState() +{ + connected = false; +} + +ClientState JClkLibClient::state{}; diff --git a/jclklib/client/client_state.hpp b/jclklib/client/client_state.hpp new file mode 100644 index 00000000..121bcad9 --- /dev/null +++ b/jclklib/client/client_state.hpp @@ -0,0 +1,21 @@ +#ifndef PROXY_CLIENT_STATE +#define PROXY_CLIENT_STATE + +#include +#include + +namespace JClkLibClient { + class ClientState { + private: + bool connected; + JClkLibCommon::sessionId_t sessionId; + public: + ClientState(); + DECLARE_ACCESSOR(connected); + DECLARE_ACCESSOR(sessionId); + }; + + extern JClkLibClient::ClientState state; +} + +#endif/*PROXY_CLIENT_STATE*/ diff --git a/jclklib/client/connect_msg.cpp b/jclklib/client/connect_msg.cpp new file mode 100644 index 00000000..ee752573 --- /dev/null +++ b/jclklib/client/connect_msg.cpp @@ -0,0 +1,41 @@ +/*! \file connect_msg.cpp + \brief Client connect message class. Implements client specific functionality. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include + +using namespace JClkLibClient; +using namespace JClkLibCommon; +using namespace std; + +MAKE_RXBUFFER_TYPE(ClientConnectMessage::buildMessage) +{ + msg = new ClientConnectMessage(); + + return true; +} + +bool ClientConnectMessage::initMessage() +{ + addMessageType(parseMsgMapElement_t(CONNECT_MSG, buildMessage)); + return true; +} + +PROCESS_MESSAGE_TYPE(ClientConnectMessage::processMessage) +{ + sessionId_t newSessionId; + + PrintDebug("Processing client connect message (reply)"); + + state.set_connected(true); + state.set_sessionId(this->get_sessionId()); + + PrintDebug("Connected with session ID: " + to_string(this->get_sessionId())); + + this->set_msgAck(ACK_NONE); + return true; +} diff --git a/jclklib/client/connect_msg.hpp b/jclklib/client/connect_msg.hpp new file mode 100644 index 00000000..b84fbcbe --- /dev/null +++ b/jclklib/client/connect_msg.hpp @@ -0,0 +1,27 @@ +/*! \file connect_msg.hpp + \brief Client connect message class. Implements client specific functionality. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#ifndef CLIENT_CONNECT_MSG_HPP +#define CLIENT_CONNECT_MSG_HPP + +#include +#include + +namespace JClkLibClient +{ + class ClientConnectMessage : virtual public JClkLibCommon::CommonConnectMessage, + virtual public ClientMessage + { + public: + ClientConnectMessage() : MESSAGE_CONNECT() {}; + virtual PROCESS_MESSAGE_TYPE(processMessage); + static MAKE_RXBUFFER_TYPE(buildMessage); + static bool initMessage(); + }; +} + +#endif/*CLIENT_CONNECT_MSG_HPP*/ diff --git a/jclklib/client/init.cpp b/jclklib/client/init.cpp new file mode 100644 index 00000000..55014d73 --- /dev/null +++ b/jclklib/client/init.cpp @@ -0,0 +1,60 @@ +/*! \file init.cpp + \brief Client utilities to setup and cleanup the library. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include +#include +#include +#include + +using namespace JClkLibClient; +using namespace JClkLibCommon; +using namespace std; + +bool JClkLibClient::connect() +{ + Message0 connectMsg(new ClientConnectMessage()); + + BlockStopSignal(); + if(!ClientMessage::init()) { + PrintError("Client Message Init Failed"); + return false; + } + if(!ClientTransport::init()) { + PrintError("Client Transport Init Failed"); + return false; + } + + ClientMessageQueue::writeTransportClientId(connectMsg.get()); + ClientMessageQueue::sendMessage(connectMsg.get()); + + // Wait for connection result + + + return true; +} + +bool JClkLibClient::disconnect() +{ + bool retVal = false; + + // Send a disconnect message + if(!ClientTransport::stop()) { + PrintDebug("Client Stop Failed"); + goto done; + } + if(!ClientTransport::finalize()) { + PrintDebug("Client Finalize Failed"); + goto done; + } + retVal = true; + + done: + if (!retVal) + PrintError("Client Error Occured"); + return retVal; +} diff --git a/jclklib/client/init.hpp b/jclklib/client/init.hpp new file mode 100644 index 00000000..a9666341 --- /dev/null +++ b/jclklib/client/init.hpp @@ -0,0 +1,17 @@ +/*! \file init.hpp + \brief Client utilities to setup and cleanup the library. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#ifndef CLIENT_INIT_HPP +#define CLIENT_INIT_HPP + +namespace JClkLibClient { + bool connect(); + bool disconnect(); + //bool subscribe(); +}; + +#endif/*CLIENT_INIT_HPP*/ diff --git a/jclklib/client/message.cpp b/jclklib/client/message.cpp new file mode 100644 index 00000000..0bd5ecea --- /dev/null +++ b/jclklib/client/message.cpp @@ -0,0 +1,19 @@ +/*! \file message.cpp + \brief Client message base class. Extended for specific messages such as connect and subscribe. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include +#include +#include + +using namespace JClkLibClient; + +bool ClientMessage::init() +{ + PrintDebug("Initializing Client Message"); + return JClkLibCommon::_initMessage(); +} diff --git a/jclklib/client/message.hpp b/jclklib/client/message.hpp new file mode 100644 index 00000000..60d5f7e7 --- /dev/null +++ b/jclklib/client/message.hpp @@ -0,0 +1,33 @@ +/*! \file message.hpp + \brief Client message base class. Extended for specific messages such as connect and subscribe. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include +#include + +#ifndef CLIENT_MESSAGE_HPP +#define CLIENT_MESSAGE_HPP + +#include +#include + +namespace JClkLibClient +{ + class ClientMessage; + typedef std::shared_ptr MessageX; + typedef std::unique_ptr Message0; + + class ClientMessage : virtual public JClkLibCommon::Message + { + protected: + ClientMessage() : JClkLibCommon::Message() {} + public: + static bool init(); + }; +} + +#endif/*CLIENT_MESSAGE_HPP*/ diff --git a/jclklib/client/msgq_tport.cpp b/jclklib/client/msgq_tport.cpp new file mode 100644 index 00000000..4ee7916b --- /dev/null +++ b/jclklib/client/msgq_tport.cpp @@ -0,0 +1,122 @@ +/*! \file msgq_tport.cpp + \brief Client POSIX message queue transport class. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include + +using namespace JClkLibClient; +using namespace JClkLibCommon; +using namespace std; + +DECLARE_STATIC(ClientMessageQueue::mqListenerName,""); +DECLARE_STATIC(ClientMessageQueue::mqNativeClientTransmitterDesc,-1); +DECLARE_STATIC(ClientMessageQueue::txContext); + +LISTENER_CONTEXT_PROCESS_MESSAGE_TYPE(ClientMessageQueueListenerContext::processMessage) +{ + ClientMessage *msg = dynamic_cast(bmsg); + + PrintDebug("Processing received client message"); + if (msg == NULL) { + PrintError("Wrong message type"); + return false; + } + + return msg->processMessage(*this,txcontext); +} + +bool ClientMessageQueue::initTransport() +{ + struct mq_attr mq_attr; + + mq_attr.mq_flags = 0; + mq_attr.mq_maxmsg = 2; // Two outstanding messages per client + mq_attr.mq_msgsize = (decltype(mq_attr.mq_msgsize)) std::tuple_size::value; + + PrintInfo("Initializing Message Queue Client Transport..."); + mqListenerName += mqProxyName + "."; + mqListenerName += to_string(getpid()); + mqNativeListenerDesc = mq_open(mqListenerName.c_str(), RX_QUEUE_FLAGS, RX_QUEUE_MODE, &mq_attr); + if (mqNativeListenerDesc == -1) { + PrintError("Failed to open listener queue"); + return false; + } + + if (InvalidTransportWorkDesc == + (mqListenerDesc = registerWork + (move((TransportWork){MqListenerWork, + TransportWorkArg(new ClientMessageQueueListenerContext(mqNativeListenerDesc))})) )) { + PrintError("Listener Thread Unexpectedly Exited"); + return false; + } + + mqNativeClientTransmitterDesc = mq_open(mqProxyName.c_str(), TX_QUEUE_FLAGS); + if (mqNativeClientTransmitterDesc == -1) { + PrintErrorCode("Failed to open transmitter queue: " + mqProxyName); + return false; + } + txContext.reset(new ClientMessageQueueTransmitterContext(mqNativeClientTransmitterDesc)); + + PrintDebug("Client Message queue opened"); + + return true; +} + +bool ClientMessageQueue::stopTransport() +{ + PrintInfo("Stopping Message Queue Client Transport"); + PrintDebug("mqListenerName = " + mqListenerName); + if (mq_unlink(mqListenerName.c_str()) == -1) + PrintErrorCode("unlink failed"); + if (mqListenerDesc != InvalidTransportWorkDesc && !InterruptWorker(mqListenerDesc)) + PrintError("Interrupt worker failed"); + + return true; +} + +bool ClientMessageQueue::finalizeTransport() +{ + PrintDebug("mqNativeListenerDesc = " + to_string(mqNativeListenerDesc)); + PrintDebug("mqNativeClientTransmitterDesc = " + to_string(mqNativeClientTransmitterDesc)); + return mq_close(mqNativeListenerDesc) != -1 && mq_close(mqNativeClientTransmitterDesc) != -1; +} + +bool ClientMessageQueue::writeTransportClientId(Message *msg) +{ + ClientConnectMessage *cmsg = dynamic_cast(msg); + if (cmsg == NULL) + return false; + strcpy((char *)cmsg->getClientId().data(), mqListenerName.c_str()); + return true; +} + +SEND_CLIENT_MESSAGE(ClientMessageQueue::sendMessage) +{ + auto context = txContext.get(); + + msg->presendMessage(context); + if (mq_send(mqNativeClientTransmitterDesc, (char *)context->getc_buffer().data(), context->getc_offset(), 0) == -1) { + PrintErrorCode("Failed to transmit client message"); + return false; + } + + return true; +} diff --git a/jclklib/client/msgq_tport.hpp b/jclklib/client/msgq_tport.hpp new file mode 100644 index 00000000..e3fc17f8 --- /dev/null +++ b/jclklib/client/msgq_tport.hpp @@ -0,0 +1,56 @@ +/*! \file msgq_tport.hpp + \brief Client POSIX message queue transport class. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include +#include +#include + +#include + +#ifndef CLIENT_MSGQ_TPORT_HPP +#define CLIENT_MSGQ_TPORT_HPP + +#include +#include +#include +#include + +namespace JClkLibClient +{ + class ClientMessageQueueListenerContext : public JClkLibCommon::MessageQueueListenerContext + { + friend class ClientMessageQueue; + protected: + virtual LISTENER_CONTEXT_PROCESS_MESSAGE_TYPE(processMessage); + ClientMessageQueueListenerContext(mqd_t mqListenerDesc) : MessageQueueListenerContext(mqListenerDesc) {} + }; + + class ClientMessageQueueTransmitterContext : public JClkLibCommon::MessageQueueTransmitterContext + { + friend class ClientMessageQueue; + protected: + //virtual bool processMessage(JClkLibCommon::Message *msg); + ClientMessageQueueTransmitterContext(mqd_t mqListenerDesc) : MessageQueueTransmitterContext(mqListenerDesc) {} + }; + + class ClientMessageQueue : public JClkLibCommon::MessageQueue, public ClientTransport + { + private: + static mqd_t mqNativeClientTransmitterDesc; + static std::string mqListenerName; + static std::unique_ptr txContext; + public: + static bool initTransport(); + static bool stopTransport(); + static bool finalizeTransport(); + static bool writeTransportClientId(JClkLibCommon::Message *msg); + static SEND_CLIENT_MESSAGE(sendMessage); + }; +} + +#endif/*CLIENT_MSGQ_TPORT_HPP*/ diff --git a/jclklib/client/null_msg.hpp b/jclklib/client/null_msg.hpp new file mode 100644 index 00000000..942db27f --- /dev/null +++ b/jclklib/client/null_msg.hpp @@ -0,0 +1,26 @@ +/*! \file null_msg.hpp + \brief Non-functional message class for debug + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include + +#ifndef CLIENT_NULL_MSG_HPP +#define CLIENT_NULL_MSG_HPP + +namespace JClkLibClient +{ + class ClientNullMessage : public JClkLibClient::ClientMessage, + public JClkLibCommon::CommonNullMessage + { + protected: + public: + static bool initMessage() { return true; } + ClientNullMessage() {} + }; +} + +#endif/*CLIENT_NULL_MSG_HPP*/ diff --git a/jclklib/client/null_tport.cpp b/jclklib/client/null_tport.cpp new file mode 100644 index 00000000..f4fc2582 --- /dev/null +++ b/jclklib/client/null_tport.cpp @@ -0,0 +1,21 @@ +/*! \file null_tport.cpp + \brief Null transport implementation. Non-functional for testing only. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include + +#include + +using namespace JClkLibClient; +using namespace std; + +bool NullClientTransport::sendMessage(uint8_t *buffer, size_t length) +{ + PrintError("NullTransport should not be used"); + return false; +} + diff --git a/jclklib/client/null_tport.hpp b/jclklib/client/null_tport.hpp new file mode 100644 index 00000000..f1648a1e --- /dev/null +++ b/jclklib/client/null_tport.hpp @@ -0,0 +1,25 @@ +/*! \file null_tport.hpp + \brief Null transport class. Non-functional for testing only. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#ifndef CLIENT_NULL_TPORT_HPP +#define CLIENT_NULL_TPORT_HPP + +#include +#include + +#include + +namespace JClkLibClient +{ + class NullClientTransport : public JClkLibCommon::NullTransport + { + public: + static bool sendMessage(std::uint8_t *buffer, std::size_t length); + }; +} + +#endif/*CLIENT_NULL_TPORT_HPP*/ diff --git a/jclklib/client/run_test.sh b/jclklib/client/run_test.sh new file mode 100755 index 00000000..e18f2356 --- /dev/null +++ b/jclklib/client/run_test.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +TEST_PATH=/home/chall/siemens_dev/libptpmgmt/jclklib/client/ + +LD_LIBRARY_PATH=$TEST_PATH $TEST_PATH/test diff --git a/jclklib/client/test.cpp b/jclklib/client/test.cpp new file mode 100644 index 00000000..78b997bc --- /dev/null +++ b/jclklib/client/test.cpp @@ -0,0 +1,21 @@ +/*! \file test.cpp + \brief Test client code + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include "init.hpp" + +#include + +using namespace JClkLibClient; +using namespace std; + +int main() +{ + connect(); + sleep(1); + do_exit: + disconnect(); +} diff --git a/jclklib/client/transport.cpp b/jclklib/client/transport.cpp new file mode 100644 index 00000000..782a5251 --- /dev/null +++ b/jclklib/client/transport.cpp @@ -0,0 +1,44 @@ +/*! \file transport.cpp + \brief Client transport base implementation for JClkLib. It is extended for specific transports such as POSIX message queue. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include +#include +#include +#include +#include + +using namespace JClkLibClient; +using namespace JClkLibCommon; +using namespace std; + +bool ClientTransport::init() +{ + if (!Transport::init()) + return false; + PrintDebug("Finished common init"); + + return JClkLibCommon::_initTransport(); +} + +bool ClientTransport::stop() +{ + if (!Transport::stop()) + return false; + + /* Do any transport specific stop */ + return JClkLibCommon::_stopTransport(); +} + +bool ClientTransport::finalize() +{ + if (!Transport::finalize()) + return false; + + return JClkLibCommon::_finalizeTransport(); +} + diff --git a/jclklib/client/transport.hpp b/jclklib/client/transport.hpp new file mode 100644 index 00000000..5c9f749f --- /dev/null +++ b/jclklib/client/transport.hpp @@ -0,0 +1,45 @@ +/*! \file transport.hpp + \brief Client transport base class for JClkLib. It is extended for specific transports such as POSIX message queue. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include +#include +#include +#include +#include + +#ifndef CLIENT_TRANSPORT_HPP +#define CLIENT_TRANSPORT_HPP + +#include +#include +#include + +namespace JClkLibClient +{ + class ClientTransportContext : virtual public JClkLibCommon::TransportContext { + public: + virtual ~ClientTransportContext() = default; + }; + +#define SEND_CLIENT_MESSAGE(name) \ + bool name (::JClkLibCommon::Message *msg) + + class ClientTransport : public JClkLibCommon::Transport + { + protected: + static bool processMessage(JClkLibCommon::Message *msg) { return false; } + public: + static bool init(); + static bool stop(); + static bool finalize(); + static void writeTransportClientId(Message0 &msg) {} + static SEND_CLIENT_MESSAGE(sendMessage) { return false; } + }; +} + +#endif/*CLIENT_TRANSPORT_HPP*/ diff --git a/jclklib/common/Makefile b/jclklib/common/Makefile new file mode 100644 index 00000000..3fcf5aa6 --- /dev/null +++ b/jclklib/common/Makefile @@ -0,0 +1,61 @@ +##! \file Makefile +# \brief Common makefile +# +# (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. +# Author: Christopher Hall +# + +JCLKLIB_COMMON_DIR := $(shell pwd) +JCLKLIB_TOPLEVEL_DIR := $(JCLKLIB_COMMON_DIR)/.. +LIBS = pthread rt +LIBS_FLAGS = $(foreach lib,$(LIBS),-l$(lib)) +OBJ = jclklib_import message msgq_tport notification_msg null_msg connect_msg print sighandler subscribe_msg transport util +OBJ_FILES = $(foreach f,$(OBJ),$(f).o) +DEPENDS = $(foreach f,$(OBJ),$(f).d) +OBJ_DIR = $(JCLKLIB_COMMON_DIR)/obj + +.PHONY: default +default: + $(MAKE) -s -C $(JCLKLIB_COMMON_DIR) build-all 2>&1 | less -R + +.PHONY: build-prep +build-prep: + echo "Running" $@ + $(MAKE) -C $(JCLKLIB_COMMON_DIR) $(DEPENDS) 2>&1 + + +%.d : %.cpp + echo "[MAKEDEP]" $@ + g++ -I $(JCLKLIB_TOPLEVEL_DIR) -MM -MF $@ $< + +.PHONY: clean +clean: + $(RM) -rf *.o *.d $(OBJ_DIR) + +ifneq ($(MAKECMDGOALS),) +ifeq ($(findstring build-prep,$(MAKECMDGOALS)),) +ifeq ($(findstring build-all,$(MAKECMDGOALS)),) +ifeq ($(findstring clean,$(MAKECMDGOALS)),) +ifneq ($(suffix $(MAKECMDGOALS)),.d) +-include $(DEPENDS) +endif +endif +endif +endif +endif + +.PHONY: build-all +build-all: build-prep + echo "Running" $@ + $(MAKE) -C $(JCLKLIB_COMMON_DIR) common-obj + +.PHONY: common-obj +common-obj: $(OBJ_FILES) + echo "[LINK]" $@ + install -d $(OBJ_DIR) + install -t $(OBJ_DIR) $? + +%.o : %.cpp + echo "[COMPILE]" $< + g++ -c $< -g -I $(JCLKLIB_TOPLEVEL_DIR) -fPIC -Werror -Wall -fdiagnostics-color=always + diff --git a/jclklib/common/connect_msg.cpp b/jclklib/common/connect_msg.cpp new file mode 100644 index 00000000..a9cdc4be --- /dev/null +++ b/jclklib/common/connect_msg.cpp @@ -0,0 +1,54 @@ +/*! \file connect_msg.cpp + \brief Common connect message implementation. Implements common functions and (de-)serialization + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include +#include + +using namespace JClkLibCommon; +using namespace std; + +string CommonConnectMessage::toString() +{ + string name = ExtractClassName(string(__PRETTY_FUNCTION__),string(__FUNCTION__)); + name += "\n"; + name += Message::toString(); + name += "Client ID: " + string((char *)clientId.data()) + "\n"; + + return name; +} + +PARSE_RXBUFFER_TYPE(CommonConnectMessage::parseBuffer) { + if(!Message::parseBuffer(LxContext)) + return false; + + if (!PARSE_RX(ARRAY,clientId, LxContext)) + return false; + + return true; +} + + +BUILD_TXBUFFER_TYPE(CommonConnectMessage::makeBuffer) const +{ + auto ret = Message::makeBuffer(TxContext); + if (!ret) + return ret; + + if (!WRITE_TX(ARRAY,clientId,TxContext)) + return false; + + return true; +} + +TRANSMIT_MESSAGE_TYPE(CommonConnectMessage::transmitMessage) +{ + if (!presendMessage(&TxContext)) + return false; + + return TxContext.sendBuffer(); +} diff --git a/jclklib/common/connect_msg.hpp b/jclklib/common/connect_msg.hpp new file mode 100644 index 00000000..f14fbf62 --- /dev/null +++ b/jclklib/common/connect_msg.hpp @@ -0,0 +1,35 @@ +/*! \file connect_msg.hpp + \brief Common connect message class. Implements common functions and (de-)serialization + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include + +#ifndef COMMON_CONNECT_MSG_HPP +#define COMMON_CONNECT_MSG_HPP + +#include +#include + +namespace JClkLibCommon +{ + class CommonConnectMessage : virtual public Message + { + private: + TransportClientId clientId; + protected: +#define MESSAGE_CONNECT() JClkLibCommon::Message(JClkLibCommon::CONNECT_MSG) + CommonConnectMessage() : MESSAGE_CONNECT() {} + public: + TransportClientId &getClientId() { return clientId; } + virtual PARSE_RXBUFFER_TYPE(parseBuffer); + static bool registerBuild(); + virtual TRANSMIT_MESSAGE_TYPE(transmitMessage); + virtual BUILD_TXBUFFER_TYPE(makeBuffer) const; + virtual std::string toString(); + }; +} + +#endif/*COMMON_CONNECT_MSG_HPP*/ diff --git a/jclklib/common/jclklib_import.cpp b/jclklib/common/jclklib_import.cpp new file mode 100644 index 00000000..0520d107 --- /dev/null +++ b/jclklib/common/jclklib_import.cpp @@ -0,0 +1,153 @@ +/*! \file jclklib_import.cpp + \brief C API import. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include + +#include + +using namespace JClkLibCommon; + +jcl_value::value_t::value_t() +{ + upper = 0; + lower = 0; +} + +jcl_value::value_t::value_t(uint32_t limit) +{ + upper = limit; + lower = limit; +} + +bool jcl_value::value_t::equal(const value_t &v) +{ + if (this->upper == v.upper && this->lower == v.lower) + return true; + return false; +} + +uint8_t *jcl_value::parse(uint8_t *buf, std::size_t &length) +{ + for(size_t i = 0; i < sizeof(value)/sizeof(value[0]) && buf != NULL; ++i) + //buf = PARSE(value[i],buf,length); + for(size_t i = 0; i < sizeof(reserved)/sizeof(reserved[0]) && buf != NULL; ++i) { + //buf = PARSE(reserved[i],buf,length); + if (!CHECK_RSV(reserved[i])) + return (uint8_t *)-1; + } + + return buf; +} + +uint8_t *jcl_value::write(uint8_t *buf, std::size_t &length) +{ + for(size_t i = 0; i < sizeof(value)/sizeof(value[0]) && buf != NULL; ++i) + buf += WRITE_FIELD(value[i],buf,length); + for(size_t i = 0; i < sizeof(reserved)/sizeof(reserved[0]) && buf != NULL; ++i) + reserved[i].zero(); + + return buf; +} + +bool jcl_value::equal( const jcl_value &c) +{ + if (memcmp(this->value, c.value, sizeof(this->value)) == 0) + return true; + return false; +} + + +uint8_t *jcl_subscription::parse(uint8_t *buf, std::size_t &length) +{ + buf = event.parse(buf, length); + if (buf != NULL) + buf = value.parse(buf, length); + + return buf; +} + +uint8_t *jcl_subscription::write(uint8_t *buf, std::size_t &length) +{ + buf = event.write(buf, length); + if (buf != NULL) + buf = value.write(buf, length); + + return buf; +} + +uint8_t *jcl_event::parse(uint8_t *buf, std::size_t &length) +{ + for(size_t i = 0; i < sizeof(event_mask)/sizeof(event_mask[0]) && buf != NULL; ++i) + //buf = PARSE(event_mask[i],buf,length); + for(size_t i = 0; i < sizeof(reserved)/sizeof(reserved[0]) && buf != NULL; ++i) { + //buf = PARSE(reserved[i],buf,length); + if (!CHECK_RSV(reserved[i])) + return (uint8_t *)-1; + } + + return buf; +} + +uint8_t *jcl_event::write(uint8_t *buf, std::size_t &length) +{ + for(size_t i = 0; i < sizeof(event_mask)/sizeof(event_mask[0]) && buf != NULL; ++i) + buf += WRITE_FIELD(event_mask[i],buf,length); + memset(reserved, 0, sizeof(reserved)); + + return buf; +} + +void jcl_event::zero() +{ + for(size_t i = 0; i < sizeof(event_mask)/sizeof(event_mask[0]); ++i) + event_mask[i] = 0; + memset(reserved, 0, sizeof(reserved)); +} + +bool jcl_event::equal(const jcl_event &c) +{ + if (memcmp(this->event_mask, c.event_mask, sizeof(event_mask)) == 0) + return true; + return false; +} + +uint8_t *jcl_eventcount::parse(uint8_t *buf, std::size_t &length) +{ + for(size_t i = 0; i < sizeof(count)/sizeof(count[0]) && buf != NULL; ++i) + //buf = PARSE(count[i],buf,length); + for(size_t i = 0; i < sizeof(reserved)/sizeof(reserved[0]) && buf != NULL; ++i) { + //buf = PARSE(reserved[i],buf,length); + if (!CHECK_RSV(reserved[i])) + return (uint8_t *)-1; + } + + return buf; +} + +uint8_t *jcl_eventcount::write(uint8_t *buf, std::size_t &length) +{ + for(size_t i = 0; i < sizeof(count)/sizeof(count[0]) && buf != NULL; ++i) + buf += WRITE_FIELD(count[i],buf,length); + memset(reserved, 0, sizeof(reserved)); + + return buf; +} + +void jcl_eventcount::zero() +{ + for(size_t i = 0; i < sizeof(count)/sizeof(count[0]); ++i) + count[i] = 0; + memset(reserved, 0, sizeof(reserved)); +} + +bool jcl_eventcount::equal( const jcl_eventcount &ec) +{ + if (memcmp(this->count, ec.count, sizeof(this->count)) == 0) + return true; + return false; +} diff --git a/jclklib/common/jclklib_import.hpp b/jclklib/common/jclklib_import.hpp new file mode 100644 index 00000000..45b02939 --- /dev/null +++ b/jclklib/common/jclklib_import.hpp @@ -0,0 +1,95 @@ +/*! \file jclklib_import.hpp + \brief C API import. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include + +#ifndef JCLKLIB_IMPORT_HPP +#define JCLKLIB_IMPORT_HPP + +#include + +namespace JClkLibCommon +{ + typedef enum : std::uint8_t + { gmOffsetValue, + valueLast } valueType; +#define MAX_VALUE_COUNT 12 + + class jcl_value + { + private: + struct value_t { + std::uint32_t upper; + std::uint32_t lower; + value_t(); + value_t(uint32_t limit); + bool equal(const value_t &v); + bool operator== (const value_t &value) { return this->equal(value); } + bool operator!= (const value_t &value) { return !this->equal(value); } + void zero() { upper = 0; lower = 0; } + }; + value_t value[valueLast]; + value_t reserved[MAX_VALUE_COUNT-sizeof(value)/sizeof(value[0])]; + public: + std::uint8_t *parse(std::uint8_t *buf, std::size_t &length); + std::uint8_t *write(std::uint8_t *buf, std::size_t &length); + bool equal( const jcl_value &c); + bool operator== (const jcl_value &value) { return this->equal(value); } + bool operator!= (const jcl_value &value) { return !this->equal(value); } + }; + + typedef enum : std::uint8_t + { peerPresentEvent, gmPresentEvent, gmOffsetEvent, servoLockedEvent, + eventLast } eventType; +#define BITS_PER_BYTE (8) +#define MAX_EVENT_COUNT (128) + + class jcl_event + { + private: + std::uint32_t event_mask[eventLast/(sizeof(std::uint32_t)*BITS_PER_BYTE)+1]; + std::uint32_t reserved[MAX_EVENT_COUNT/ + sizeof(event_mask[0]*BITS_PER_BYTE) + -sizeof(event_mask)/sizeof(std::uint32_t)]; + public: + std::uint8_t *parse(std::uint8_t *buf, std::size_t &length); + std::uint8_t *write(std::uint8_t *buf, std::size_t &length); + void zero(); + bool equal( const jcl_event &c); + bool operator== (const jcl_event &event) { return this->equal(event); } + bool operator!= (const jcl_event &event) { return !this->equal(event); } + }; + + + class jcl_eventcount + { + std::uint32_t count[eventLast]; + std::uint32_t reserved[MAX_EVENT_COUNT-eventLast]; + public: + std::uint8_t *parse(std::uint8_t *buf, std::size_t &length); + std::uint8_t *write(std::uint8_t *buf, std::size_t &length); + void zero(); + bool equal(const jcl_eventcount &ec); + bool operator== (const jcl_eventcount &ec) { return this->equal(ec); } + bool operator!= (const jcl_eventcount &ec) { return !this->equal(ec); } + }; + + class jcl_subscription + { + private: + jcl_event event; + jcl_value value; + public: + std::uint8_t *parse(std::uint8_t *buf, std::size_t &length); + std::uint8_t *write(std::uint8_t *buf, std::size_t &length); + + DECLARE_ACCESSOR(event); + DECLARE_ACCESSOR(value); + }; +} + +#endif/*JCLKLIB_IMPORT_HPP*/ diff --git a/jclklib/common/jcltypes.hpp b/jclklib/common/jcltypes.hpp new file mode 100644 index 00000000..86f3c3e3 --- /dev/null +++ b/jclklib/common/jcltypes.hpp @@ -0,0 +1,18 @@ +#include + +#ifndef COMMON_JCLTYPES_HPP +#define COMMON_JCLTYPES_HPP + +namespace JClkLibCommon { + typedef std::uint16_t sessionId_t; + static const sessionId_t InvalidSessionId = (sessionId_t)(-1); + + typedef std::uint8_t msgAck_t; + enum : msgAck_t {ACK_FAIL = (msgAck_t)-1, ACK_NONE = 0, ACK_SUCCESS = 1, }; + + typedef std::uint8_t msgId_t; + enum msgId : msgId_t {INVALID_MSG = (msgId_t)-1, NULL_MSG = 1, CONNECT_MSG, SUBSCRIBE_MSG, NOTIFY_MESSAGE, + DISCONNECT_MSG}; +} + +#endif/*COMMON_JCLTYPES_HPP*/ diff --git a/jclklib/common/message.cpp b/jclklib/common/message.cpp new file mode 100644 index 00000000..544a8b71 --- /dev/null +++ b/jclklib/common/message.cpp @@ -0,0 +1,120 @@ +/*! \file message.cpp + \brief Common message base implementation. Extended for specific messages such as connect and subscribe. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include +#include +#include +#include + +using namespace JClkLibCommon; +using namespace std; + +DECLARE_STATIC(Message::parseMsgMap); + +Message::Message(decltype(msgId) msgId) + { + this->msgId = msgId; + this->msgAck = ACK_NONE; + this->sessionId = InvalidSessionId; + } + +string Message::ExtractClassName(string prettyFunction, string function) +{ + auto fpos = prettyFunction.find(function); + auto spos = fpos; + if (fpos == string::npos) + return prettyFunction; + spos = prettyFunction.rfind(" ",fpos); + ++spos; + if (spos == string::npos || spos >= fpos) + return prettyFunction; + auto ret = prettyFunction.substr(spos,fpos-spos); + while(ret.length() > 0 && ret.back() == ':') + ret.pop_back(); + return ret.length() != 0 ? ret : prettyFunction; +} + +string Message::toString() +{ + string ret; + + ret += PRIMITIVE_TOSTRING(msgId); + ret += PRIMITIVE_TOSTRING(msgAck); + + return ret; +} + +BUILD_TXBUFFER_TYPE(Message::makeBuffer) const +{ + if (!WRITE_TX(FIELD,msgId,TxContext)) + return false; + if (!WRITE_TX(FIELD,msgAck,TxContext)) + return false; + + return true; +} + +COMMON_PRESEND_MESSAGE_TYPE(Message::presendMessage) +{ + ctx->resetOffset(); + if (!makeBuffer(*ctx)) { + PrintError("Failed to make buffer from message object"); + return false; + } + DumpOctetArray("Sending message (length = " + to_string(ctx->getc_offset()) + "): ", ctx->getc_buffer().data(), + ctx->getc_offset()); + + return true; +} + + +bool Message::addMessageType(parseMsgMapElement_t mapping) +{ + decltype(parseMsgMap)::size_type size = parseMsgMap.size(); + parseMsgMap.insert(mapping); + if (parseMsgMap.size() == size) + return false; + + PrintDebug("Added message type: " + to_string(mapping.first)); + + return true; +} + +PARSE_RXBUFFER_TYPE(Message::parseBuffer) +{ + if (!PARSE_RX(FIELD,msgId, LxContext)) + return false; + if (!PARSE_RX(FIELD,msgAck, LxContext)) + return false; + + return true; +} + +MAKE_RXBUFFER_TYPE(Message::buildMessage) +{ + msgId_t msgId; + decltype(parseMsgMap)::iterator it; + + if (!PARSE_RX(FIELD,msgId,LxContext)) + return false; + + it = parseMsgMap.find(msgId); + if (it == parseMsgMap.cend()) { + PrintError("Unknown message type " + to_string(msgId)); + return false; + } + if (!it->second(msg, LxContext)) { + PrintError("Error parsing message"); + return false; + } + LxContext.resetOffset(); + if (!msg->parseBuffer(LxContext)) + return false; + + return true; +} diff --git a/jclklib/common/message.hpp b/jclklib/common/message.hpp new file mode 100644 index 00000000..3ff0949d --- /dev/null +++ b/jclklib/common/message.hpp @@ -0,0 +1,90 @@ +/*! \file message.hpp + \brief Common message base class. Extended for specific messages such as connect and subscribe. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include +#include + +#ifndef COMMON_MESSAGE_HPP +#define COMMON_MESSAGE_HPP + +#include +#include + +namespace JClkLibCommon +{ + class Message; + + class TransportListenerContext; + class TransportTransmitterContext; + +#define MAKE_RXBUFFER_TYPE(name) bool name (Message *&msg, ::JClkLibCommon::TransportListenerContext &LxContext) + typedef std::function BuildMessage_t; + + typedef std::pair parseMsgMapElement_t; + + class Message + { + private: + static std::map parseMsgMap; + msgId_t msgId; + msgAck_t msgAck; + sessionId_t sessionId; + + protected: + Message(decltype(msgId) msgId); + static bool addMessageType(parseMsgMapElement_t); + static std::string ExtractClassName(std::string prettyFunction, std::string function); + public: +#define COMMON_PRESEND_MESSAGE_TYPE(name) bool name (JClkLibCommon::TransportTransmitterContext *ctx) + COMMON_PRESEND_MESSAGE_TYPE(presendMessage); + +#define BUILD_TXBUFFER_TYPE(name) bool name (::JClkLibCommon::TransportTransmitterContext &TxContext) + static bool registerBuild(BUILD_TXBUFFER_TYPE(buildMessage)); + +#define PROCESS_MESSAGE_TYPE(name) bool name(JClkLibCommon::TransportListenerContext &LxContext, \ + JClkLibCommon::TransportTransmitterContext *&TxContext) + virtual PROCESS_MESSAGE_TYPE(processMessage) = 0; + +#define TRANSMIT_MESSAGE_TYPE(name) bool name(JClkLibCommon::TransportTransmitterContext &TxContext) + virtual TRANSMIT_MESSAGE_TYPE(transmitMessage) = 0; + + static MAKE_RXBUFFER_TYPE(buildMessage); + +#define PARSE_RXBUFFER_TYPE(name) \ + bool name (::JClkLibCommon::TransportListenerContext &LxContext) + virtual PARSE_RXBUFFER_TYPE(parseBuffer); + virtual BUILD_TXBUFFER_TYPE(makeBuffer) const; + +#define PRIMITIVE_TOSTRING(p) std::string(#p) + ": " + std::to_string(p) + "\n" + virtual std::string toString(); + + virtual ~Message() = default; + DECLARE_ACCESSOR(msgId); + DECLARE_ACCESSOR(msgAck); + DECLARE_ACCESSOR(sessionId); + + static bool initMessage() { return false; }; + static bool init() { return false; } + }; + + template + inline bool _initMessage() + { + return T::initMessage(); + } + + template + inline typename std::enable_if::type + _initMessage() + { + return _initMessage() && _initMessage(); + } +} + +#endif/*COMMON_MESSAGE_HPP*/ diff --git a/jclklib/common/msgq_tport.cpp b/jclklib/common/msgq_tport.cpp new file mode 100644 index 00000000..3dc988a1 --- /dev/null +++ b/jclklib/common/msgq_tport.cpp @@ -0,0 +1,94 @@ +/*! \file msgq_tport.cpp + \brief Common POSIX message queue transport implementation. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include + +using namespace JClkLibCommon; +using namespace std; + +#define QUEUE_FLAGS (O_RDONLY | O_CREAT) +#define QUEUE_MODE (S_IRUSR | S_IWGRP) + +#define NSEC_PER_MSEC (1000000 /*ns*/) +#define NSEC_PER_SEC (1000000000 /*ns*/) + +DECLARE_STATIC(MessageQueue::mqProxyName,MESSAGE_QUEUE_PREFIX); +DECLARE_STATIC(MessageQueue::mqListenerDesc,Transport::InvalidTransportWorkDesc); +DECLARE_STATIC(MessageQueue::mqNativeListenerDesc,-1); + +MessageQueueListenerContext::MessageQueueListenerContext(mqd_t mqListenerDesc) +{ + this->mqListenerDesc = mqListenerDesc; +} + +MessageQueueTransmitterContext::MessageQueueTransmitterContext(mqd_t mqTransmitterDesc) +{ + this->mqTransmitterDesc = mqTransmitterDesc; +} + +int mqRecvWrapper(mqd_t mqDesc, uint8_t *data, size_t length) +{ + int ret; + + ret = mq_receive(mqDesc, (char *)data, length, NULL); + if (ret == -1) + return -errno; + + return ret; +} + +bool MessageQueue::MqListenerWork(TransportContext *mqListenerContext) +{ + MessageQueueListenerContext *context = dynamic_cast(mqListenerContext); + + if(!context) { + PrintError("Internal Error: Received inappropriate context"); + } + if (context->init() && !EnableSyscallInterruptSignal()) { + PrintError("Unable to enable interrupts in work process context"); + return false; + } + + int ret = mqRecvWrapper(context->mqListenerDesc, context->get_buffer().data(), context->getc_buffer().max_size()); + if (ret < 0) { + if (ret != -EINTR) + PrintError("MQ Receive Failed",-ret); + return ret != -EINTR ? false : true; + } + PrintDebug("Receive complete"); + + DumpOctetArray("Received Message", context->getc_buffer().data(), context->getc_buffer().max_size()); + + Transport::processMessage(*context); + + return true; +} + +SEND_BUFFER_TYPE(MessageQueueTransmitterContext::sendBuffer) +{ + if (mq_send(mqTransmitterDesc, (char *)get_buffer().data(), get_offset(), 0) == -1) { + PrintErrorCode("Failed to send buffer"); + return false; + } + + return true; +} diff --git a/jclklib/common/msgq_tport.hpp b/jclklib/common/msgq_tport.hpp new file mode 100644 index 00000000..c5f1a699 --- /dev/null +++ b/jclklib/common/msgq_tport.hpp @@ -0,0 +1,66 @@ +/*! \file msgq_tport.hpp + \brief Common POSIX message queue transport class. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include +#include +#include + +#include + +#ifndef COMMON_MSGQ_TPORT_HPP +#define COMMON_MSGQ_TPORT_HPP + +//#include +#include +#include + +#define MESSAGE_QUEUE_PREFIX "/jclklib" + +#define TX_QUEUE_FLAGS (O_WRONLY) +#define RX_QUEUE_FLAGS (O_RDONLY | O_CREAT) +#define RX_QUEUE_MODE (S_IRUSR | S_IWUSR | S_IWGRP) + +namespace JClkLibCommon +{ + class MessageQueueListenerContext : virtual public TransportListenerContext { + friend class MessageQueue; + private: + mqd_t mqListenerDesc; + protected: + MessageQueueListenerContext(mqd_t mqListenerDesc); + public: + virtual ~MessageQueueListenerContext() = default; + }; + + class MessageQueueTransmitterContext : virtual public TransportTransmitterContext { + friend class MessageQueue; + private: + mqd_t mqTransmitterDesc; + protected: + MessageQueueTransmitterContext(mqd_t mqTransmitterDesc); + public: + virtual ~MessageQueueTransmitterContext() = default; + virtual SEND_BUFFER_TYPE(sendBuffer); + }; + + class MessageQueue : public Transport + { + protected: + static std::string const mqProxyName; + static TransportWorkDesc mqListenerDesc; + static mqd_t mqNativeListenerDesc; + static bool MqListenerWork(TransportContext *mqListenerContext); + static bool MqTransmit(TransportContext *mqTransmitterContext, Message *msg); + public: + static bool initTransport() { return true; }; + static bool stopTransport() { return true; }; + static bool finalizeTransport() { return true; }; + }; +} + +#endif/*COMMON_MSGQ_TPORT_HPP*/ diff --git a/jclklib/common/notification_msg.cpp b/jclklib/common/notification_msg.cpp new file mode 100644 index 00000000..4822d6ee --- /dev/null +++ b/jclklib/common/notification_msg.cpp @@ -0,0 +1,19 @@ +/*! \file notification_msg.cpp + \brief Common notification message implementation. Implements common functions and (de-)serialization + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include + +using namespace JClkLibCommon; +using namespace std; + +MAKE_RXBUFFER_TYPE(NotificationMessage::buildMessage) +{ + // Fill in the fields + + return true; +} diff --git a/jclklib/common/notification_msg.hpp b/jclklib/common/notification_msg.hpp new file mode 100644 index 00000000..1df6ab46 --- /dev/null +++ b/jclklib/common/notification_msg.hpp @@ -0,0 +1,37 @@ +/*! \file notification_msg.hpp + \brief Common notification message class. Implements common functions and (de-)serialization + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include + +#ifndef COMMON_NOTIFICATION_MSG_HPP +#define COMMON_NOTIFICATION_MSG_HPP + +#include +#include + +namespace JClkLibCommon +{ + class NotificationMessage : public Message + { + public: + static msgId_t getMsgId() { return SUBSCRIBE_MSG; } + static MAKE_RXBUFFER_TYPE(buildMessage); + + const jcl_eventcount &getEventCount(); + const jcl_event &getEvent(); + bool isEnable() { return waitEnable == 0x1; } + protected: +#define MESSAGE_NOTIFY() JClkLibCommon::Message(JClkLibCommon::NOTIFY_MESSAGE) + NotificationMessage() : MESSAGE_NOTIFY() {} + private: + std::uint32_t waitEnable :1; + jcl_event event; + jcl_eventcount eventCount; + }; +} + +#endif/*COMMON_NOTIFICATION_MSG_HPP*/ diff --git a/jclklib/common/null_msg.cpp b/jclklib/common/null_msg.cpp new file mode 100644 index 00000000..a6cc3d71 --- /dev/null +++ b/jclklib/common/null_msg.cpp @@ -0,0 +1,21 @@ +/*! \file null_msg.cpp + \brief Non-functional message implementation for debug + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include + +using namespace JClkLibCommon; +using namespace std; + +MAKE_RXBUFFER_TYPE(CommonNullMessage::buildMessage) +{ + return true; +} + +bool CommonNullMessage::initMessage() +{ + return true; +} diff --git a/jclklib/common/null_msg.hpp b/jclklib/common/null_msg.hpp new file mode 100644 index 00000000..3c616b21 --- /dev/null +++ b/jclklib/common/null_msg.hpp @@ -0,0 +1,27 @@ +/*! \file null_msg.hpp + \brief Non-functional message class for debug + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#ifndef COMMON_NULL_MSG_HPP +#define COMMON_NULL_MSG_HPP + +#include + +namespace JClkLibCommon +{ + class CommonNullMessage : virtual public Message + { + protected: + public: + static msgId_t getMsgId() { return NULL_MSG; } + static MAKE_RXBUFFER_TYPE(buildMessage); +#define MESSAGE_NULL() JClkLibCommon::Message(JClkLibCommon::NULL_MSG) + CommonNullMessage() : MESSAGE_NULL() {}; + static bool initMessage(); + }; +} + +#endif/*COMMON_NULL_MSG_HPP*/ diff --git a/jclklib/common/null_tport.hpp b/jclklib/common/null_tport.hpp new file mode 100644 index 00000000..9ff2b990 --- /dev/null +++ b/jclklib/common/null_tport.hpp @@ -0,0 +1,26 @@ +/*! \file null_tport.hpp + \brief Null transport class. Non-functional for testing only. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#ifndef NULL_TPORT_HPP +#define NULL_TPORT_HPP + +#include + +#include + +namespace JClkLibCommon +{ + class NullTransport : public Transport + { + public: + static bool initTransport() { return true; } + static bool stopTransport() { return true; } + static bool finalizeTransport() { return true; } + }; +} + +#endif/*NULL_TPORT_HPP*/ diff --git a/jclklib/common/print.cpp b/jclklib/common/print.cpp new file mode 100644 index 00000000..9569a4b4 --- /dev/null +++ b/jclklib/common/print.cpp @@ -0,0 +1,64 @@ +/*! \file print.cpp + \brief Utility functions for printing + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include + +#include +#include +#include + +using namespace std; +using namespace JClkLibCommon; + +void JClkLibCommon::_PrintError(std::string msg, uint16_t line, std::string file, std::string func, + errno_type errnum) +{ + cerr << "*** Error: " + msg + " " + (errnum != (errno_type)-1 ? strerror(errnum) : "") + " at line " + to_string(line) + + " in " + file + ":" + func + "\n"; + cerr.flush(); +} + +void JClkLibCommon::_PrintDebug(std::string msg, uint16_t line, std::string file, std::string func) +{ + cerr << "** Debug: " + msg + " at line " + to_string(line) + " in " + file + ":" + func + "\n"; + cerr.flush(); +} + +void JClkLibCommon::_PrintInfo(std::string msg, uint16_t line, std::string file, std::string func) +{ + cerr << "* Info: " + msg + " at line " + to_string(line) + " in " + file + ":" + func + "\n"; + cerr.flush(); +} + +#define HEX_DIGITS_PER_LINE 16 +void JClkLibCommon::_DumpOctetArray(string msg, const uint8_t *arr, size_t length, uint16_t line, string file, string func) +{ + const uint8_t *index = arr; + size_t offset; + stringstream output; + bool addspc = false, addcr; + + output << "* Info: " << msg << " at line " << to_string(line) << " in " << file << ":" << func << "\n"; + + while ((offset = (index - arr)) < length) { + if (addspc) + output << " "; + output << "0x" << setfill('0') << setw(2) << std::hex << int(*index++); + if (offset % HEX_DIGITS_PER_LINE != HEX_DIGITS_PER_LINE-1) { + addspc = true; + addcr = true; + } else { + addspc = false; + addcr = false; + output << "\n"; + } + } + if (addcr) + output << "\n"; + cerr << output.str(); + cerr.flush(); +} diff --git a/jclklib/common/print.hpp b/jclklib/common/print.hpp new file mode 100644 index 00000000..e7a6890e --- /dev/null +++ b/jclklib/common/print.hpp @@ -0,0 +1,36 @@ +/*! \file print.hpp + \brief Utility functions for printing + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include + +#ifndef PRINT_HPP +#define PRINT_HPP + +namespace JClkLibCommon +{ + + typedef std::remove_reference::type errno_type; +#define PrintErrorCode(msg) PrintError(msg, errno) +#define PrintError(msg,...) ::JClkLibCommon::_PrintError(msg, __LINE__, __FILE__, __func__ __VA_OPT__(,) \ + __VA_ARGS__) + void _PrintError(std::string msg, uint16_t line, std::string file, std::string func, + errno_type errnum = (errno_type)-1); + +#define PrintDebug(msg) ::JClkLibCommon::_PrintDebug(msg, __LINE__, __FILE__, __func__) +#define PrintInfo(msg) ::JClkLibCommon::_PrintInfo(msg, __LINE__, __FILE__, __func__) + + void _PrintDebug(std::string msg, uint16_t line, std::string file, std::string func); + void _PrintInfo(std::string msg, uint16_t line, std::string file, std::string func); + +#define DumpOctetArray(msg,arr,size) JClkLibCommon::_DumpOctetArray(msg, arr, size, __LINE__, __FILE__, __func__) + + void _DumpOctetArray(std::string msg, const std::uint8_t *arr, std::size_t length, std::uint16_t line, std::string file, + std::string func); +} + +#endif/*PRINT_HPP*/ diff --git a/jclklib/common/serialize.hpp b/jclklib/common/serialize.hpp new file mode 100644 index 00000000..9b5d16db --- /dev/null +++ b/jclklib/common/serialize.hpp @@ -0,0 +1,78 @@ +/*! \file serialize.hpp + \brief Utility macros for (de-)serializing data + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include +#include +#include + +#ifndef SERIALIZE_HPP +#define SERIALIZE_HPP + +#include + +#define PARSE_RX(type,var,lc) \ + ({ \ + decltype(lc.getc_offset()) offset = PARSE_##type(var,lc.getc_buffer().data() + lc.getc_offset(), \ + lc.getc_buffer().max_size() - lc.getc_offset()); \ + if (offset != (decltype(offset))-1) { \ + lc.addOffset(offset); \ + } \ + (offset != (decltype(offset))-1 ? true : false); \ + }) + +#define PARSE_FIELD(var,ptr,len) _PARSE(std::remove_reference::type,var,ptr,len) +#define _PARSE(var_type,var,ptr,len) \ + ({ \ + std::size_t var_len = sizeof(var); \ + bool can_parse = len >= var_len; \ + if (can_parse) var = *(var_type *)(ptr); \ + (can_parse ? var_len : (std::remove_reference::type)(-1)); \ + }) + +#define PARSE_ARRAY(arr,ptr,len) \ + ({ \ + std::size_t var_len = arr.max_size()*sizeof(decltype(arr)::value_type); \ + bool can_parse = len >= var_len; \ + if (can_parse) memcpy(arr.data(), ptr, var_len); \ + (can_parse ? var_len : (std::remove_reference::type)(-1)); \ + }) + +#define CHECK_RSV(field) \ + (field == (std::remove_reference::type)0) + +#define WRITE_TX(type,var,tc) \ +({ \ + decltype(tc.getc_offset()) offset = WRITE_##type(var,tc.get_buffer().data() + tc.get_offset(), \ + tc.get_buffer().max_size() - tc.get_offset()); \ + if (offset != (decltype(offset))-1) { \ + tc.addOffset(offset); \ + } \ + (offset != (decltype(offset))-1 ? true : false); \ + }) + +#define WRITE_FIELD(var,ptr,len) _WRITE(std::remove_reference::type,var,ptr,len) +#define _WRITE(var_type,var,ptr,len) \ + ({ \ + std::size_t var_len = sizeof(var); \ + bool can_parse = (len) >= var_len; \ + if (can_parse) *(var_type *)(ptr) = var; \ + (can_parse ? var_len : (std::remove_reference::type)(-1)); \ + }) + +// For writing std::array +// +#define WRITE_ARRAY(arr,ptr,len) \ + ({ \ + std::size_t var_len = arr.max_size()*sizeof(decltype(arr)::value_type); \ + bool can_parse = len >= var_len; \ + if (can_parse) memcpy(ptr, arr.data(), var_len); \ + (can_parse ? var_len : (std::remove_reference::type)(-1)); \ + }) + + +#endif/*SERIALIZE_HPP*/ diff --git a/jclklib/common/sighandler.cpp b/jclklib/common/sighandler.cpp new file mode 100644 index 00000000..813b2f5a --- /dev/null +++ b/jclklib/common/sighandler.cpp @@ -0,0 +1,124 @@ +/*! \file sighandler.cpp + \brief Signal handling utilities + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include + +#include + +#include + +#define INTR_SIGNAL (SIGUSR1) + +using namespace JClkLibCommon; +using namespace std; + +#define SIGADDSET(set,sig,ret) \ + if(sigaddset(set, sig) == -1) \ + return ret; + +bool AddStopSignal(sigset_t *sigset) +{ + SIGADDSET(sigset, SIGINT, false); + SIGADDSET(sigset, SIGHUP, false); + SIGADDSET(sigset, SIGTERM, false); + SIGADDSET(sigset, SIGQUIT, false); + SIGADDSET(sigset, SIGALRM, false); + SIGADDSET(sigset, SIGABRT, false); + + return true; +} + +bool AddInterruptSignal(sigset_t *sigset) +{ + SIGADDSET(sigset, SIGUSR1, false); + SIGADDSET(sigset, SIGUSR2, false); + + return true; +} + +bool GenerateBlockSigset(sigset_t *block) { + sigemptyset(block); + + if (!AddStopSignal(block)) + return false; + if (!AddInterruptSignal(block)) + return false; + + return true; +} + +bool GenerateWaitSigset(sigset_t *wait) { + sigemptyset(wait); + + if (!AddStopSignal(wait)) + return false; + + return true; +} + +bool JClkLibCommon::BlockStopSignal() +{ + sigset_t blockSigset; + + if (!GenerateBlockSigset(&blockSigset)) + return false; + if (pthread_sigmask(SIG_BLOCK,&blockSigset,NULL) != 0) + return false; + + return true; +} + +bool JClkLibCommon::WaitForStopSignal() +{ + sigset_t waitSigset; + int cause; + + if (!GenerateWaitSigset(&waitSigset)) + return false; + PrintDebug("Waiting for Interrupt Signal"); + if (sigwait(&waitSigset, &cause) == -1) { + PrintErrorCode("Waiting for Interrupt Signal"); + return false; + } + PrintDebug("Received Interrupt Signal"); + + return true; +} + +void NullSigaction(int sig, siginfo_t *siginfo, void *ctx) {} + +bool JClkLibCommon::EnableSyscallInterruptSignal() +{ + sigset_t unblockSigset; + struct sigaction intrSigaction; + + intrSigaction.sa_sigaction = NullSigaction; + sigemptyset(&intrSigaction.sa_mask); + intrSigaction.sa_flags = SA_SIGINFO; + if (sigaction(INTR_SIGNAL, &intrSigaction, NULL) == -1) + return false; + + sigemptyset(&unblockSigset); + SIGADDSET(&unblockSigset, INTR_SIGNAL, false); + if (pthread_sigmask(SIG_UNBLOCK,&unblockSigset,NULL) != 0) + return false; + + return true; +} + +bool JClkLibCommon::SendSyscallInterruptSignal(thread &t) +{ + int ret; + + if ((ret = pthread_kill(t.native_handle(), INTR_SIGNAL)) != 0) { + PrintError("pthread_kill()", ret); + return false; + } + + return true; +} diff --git a/jclklib/common/sighandler.hpp b/jclklib/common/sighandler.hpp new file mode 100644 index 00000000..f73b925c --- /dev/null +++ b/jclklib/common/sighandler.hpp @@ -0,0 +1,21 @@ +/*! \file sighandler.hpp + \brief Signal handling utilities + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#ifndef SIGHANDLER_HPP +#define SIGHANDLER_HPP + +#include + +namespace JClkLibCommon +{ + bool BlockStopSignal(); + bool WaitForStopSignal(); + bool EnableSyscallInterruptSignal(); + bool SendSyscallInterruptSignal(std::thread &t); +} +#endif/*SIGHANDLER_HPP*/ + diff --git a/jclklib/common/subscribe_msg.cpp b/jclklib/common/subscribe_msg.cpp new file mode 100644 index 00000000..d2f632e5 --- /dev/null +++ b/jclklib/common/subscribe_msg.cpp @@ -0,0 +1,18 @@ +/*! \file subscribe_msg.cpp + \brief Common subscribe message implementation. Implements common functions and (de-)serialization + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include + +using namespace JClkLibCommon; +using namespace std; + +MAKE_RXBUFFER_TYPE(SubscribeMessage::buildMessage) +{ + // Fill in fields + + return true; +} diff --git a/jclklib/common/subscribe_msg.hpp b/jclklib/common/subscribe_msg.hpp new file mode 100644 index 00000000..4ea6daf1 --- /dev/null +++ b/jclklib/common/subscribe_msg.hpp @@ -0,0 +1,31 @@ +/*! \file subscribe_msg.hpp + \brief Common subscribe message class. Implements common functions and (de-)serialization + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#ifndef COMMON_SUBSCRIBE_MSG_HPP +#define COMMON_SUBSCRIBE_MSG_HPP + +#include +#include + +namespace JClkLibCommon +{ + class SubscribeMessage : public Message + { + public: + static msgId_t getMsgId() { return SUBSCRIBE_MSG; } + static MAKE_RXBUFFER_TYPE(buildMessage); + + const jcl_subscription &getSubscription(); + protected: +#define MESSAGE_SUBSCRIBE() JClkLibCommon::Message(JClkLibCommon::SUBSCRIBE_MSG) + SubscribeMessage() : MESSAGE_SUBSCRIBE() {} + private: + jcl_subscription subscription; + }; +} + +#endif/*COMMON_SUBSCRIBE_MSG_HPP*/ diff --git a/jclklib/common/transport.cpp b/jclklib/common/transport.cpp new file mode 100644 index 00000000..64efad32 --- /dev/null +++ b/jclklib/common/transport.cpp @@ -0,0 +1,149 @@ +/*! \file transport.cpp + \brief Common transport base class implementation for JClkLib. It provides common functionality for derived transport classes. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include +#include +#include +#include +#include +#include + +#define EXIT_TIMEOUT (200 /*ms*/) +#define START_TIMEOUT (20 /*ms*/) + +using namespace std; + +using namespace JClkLibCommon; +DECLARE_STATIC(Transport::workerList); + + +void Transport::dispatchLoop(promise promise, + shared_ptr> exitVal, TransportWork work) +{ + FUTURE_TYPEOF(TransportWorkerState::retVal) promiseVal = false; + + PrintDebug("Transport Thread started"); + + for (; !exitVal->load();) { + if (!work.first(work.second.get())) { + goto done; + } + work.second.get()->_init = false; + } + promiseVal = true; + + done: + PrintDebug("Transport Thread exited"); + promise.set_value_at_thread_exit(promiseVal); + return; +} + +Transport::TransportWorkerState::TransportWorkerState(future retInit, bool exitInit) +{ + exitVal = make_shared>(exitInit); + retVal = move(retInit); + thread = NULL; +} + +Transport::TransportWorkDesc Transport::registerWork(TransportWork work) +{ + promise promise; + + workerList.push_back(TransportWorkerState(move(promise.get_future()),false)); + workerList.back().thread = make_unique + (MessageQueue::dispatchLoop, move(promise), + workerList.back().exitVal, TransportWork(work.first,move(work.second))); + PrintDebug("Thread started"); + if (isFutureSet(workerList.back().retVal)) { + workerList.back().thread.get()->join(); + workerList.pop_back(); + PrintError("Thread exited early"); + return InvalidTransportWorkDesc; + } + + /* Return the index of the element we just added */ + return (workerList.cend()-1)-workerList.cbegin(); +} + +bool Transport::processMessage(TransportListenerContext &context) +{ + Message *msg; + TransportTransmitterContext *txcontext; + + context.resetOffset(); + if (!Message::buildMessage(msg, context)) + return false; + PrintDebug("Received message " + msg->toString()); + + if (!context.processMessage(msg, txcontext)) + return false; + + /* Echo the message back with ACK disposition */ + if (msg->get_msgAck() != ACK_NONE) + return msg->transmitMessage(*txcontext); + + return true; +} + + +bool Transport::init() +{ + return _initTransport(); +} + +bool Transport::stop() +{ + /* Send stop signal to all of the threads */ + for (decltype(workerList)::iterator it = workerList.begin(); + it != workerList.end(); ++it) { + it->exitVal->store(true); + } + + /* Do any transport specific stop */ + if (!_stopTransport()) + return false; + + return true; +} + +bool Transport::finalize() +{ + bool retVal = false; + + for (auto it = workerList.begin(); + it != workerList.end(); ++it) { + if (it->retVal.wait_for(chrono::milliseconds(EXIT_TIMEOUT)) != + future_status::ready) { + PrintError("Thread Join Timeout"); + goto done; + } + + it->thread.get()->join(); + retVal &= it->retVal.get(); + } + + if (!_finalizeTransport()) + goto done; + + retVal = true; + done: + return retVal; +} + +bool Transport::InterruptWorker(TransportWorkDesc d) +{ + if (d == InvalidTransportWorkDesc) + return false; + + /* Thread has exited, no need to interrupt */ + if (isFutureSet(workerList.back().retVal)) + return true; + + PrintDebug("Sending interrupt to MessageQueue worker"); + return SendSyscallInterruptSignal(*workerList[d].thread.get()); +} diff --git a/jclklib/common/transport.hpp b/jclklib/common/transport.hpp new file mode 100644 index 00000000..3d16b45c --- /dev/null +++ b/jclklib/common/transport.hpp @@ -0,0 +1,119 @@ +/*! \file transport.hpp + \brief Common transport base class for JClkLib. It is extended for specific transports such as POSIX message queue. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include +#include +#include +#include +#include + +#ifndef COMMON_TRANSPORT_HPP +#define COMMON_TRANSPORT_HPP + +#include + +#define MAX_BUFFER_LENGTH (4096) + +namespace JClkLibCommon +{ + typedef std::array TransportBuffer; + class Message; + class Transport; + + class TransportContext { + protected: + bool _init; + std::size_t offset; + TransportBuffer buffer; + public: + bool init() { return _init; } + TransportContext() { _init = true; } + virtual ~TransportContext() = default; + DECLARE_ACCESSOR(offset); + DECLARE_ACCESSOR(buffer); + void resetOffset() { set_offset(0); } + void addOffset(std::size_t offset) { this->offset += offset; } + }; + + class TransportTransmitterContext : public TransportContext { + public: + virtual ~TransportTransmitterContext() = default; +#define SEND_BUFFER_TYPE(name) \ + bool name() + virtual SEND_BUFFER_TYPE(sendBuffer) = 0; + }; + +#define TRANSPORT_CLIENTID_LENGTH (512) + typedef std::array TransportClientId; + + class TransportListenerContext : public TransportContext { + friend class Transport; + protected: +#define LISTENER_CONTEXT_PROCESS_MESSAGE_TYPE(name) \ + bool name(JClkLibCommon::Message *bmsg, JClkLibCommon::TransportTransmitterContext *&txcontext) + virtual LISTENER_CONTEXT_PROCESS_MESSAGE_TYPE(processMessage) { return false; } + public: + virtual ~TransportListenerContext() = default; +#define CREATE_TRANSMIT_CONTEXT_TYPE(name) \ + JClkLibCommon::TransportTransmitterContext *name(JClkLibCommon::TransportClientId &clientId) + virtual CREATE_TRANSMIT_CONTEXT_TYPE(CreateTransmitterContext) { return NULL; } + }; + + class Transport + { + public: + typedef std::unique_ptr TransportWorkArg; + typedef std::function TransportWorkFunction; + typedef std::pair TransportWork; + typedef ptrdiff_t TransportWorkDesc; + static const TransportWorkDesc InvalidTransportWorkDesc = (TransportWorkDesc) -1; + private: + class TransportWorkerState { + public: + std::future retVal; + std::shared_ptr> exitVal; + std::unique_ptr thread; + TransportWorkerState(std::future retInit, bool exitInit); + }; + static std::vector workerList; + static void dispatchLoop(std::promise, + decltype(TransportWorkerState::exitVal) exitVal, + TransportWork arg + ); + public: + static bool processMessage(TransportListenerContext &context); + static bool initTransport() { return true; } + static bool stopTransport() { return true; } + static bool finalizeTransport() { return true; } + static TransportWorkDesc registerWork(TransportWork work); + static bool init(); + static bool stop(); + static bool finalize(); + static bool InterruptWorker(TransportWorkDesc d); + }; + +#define PER_TRANSPORT_VARIADIC_TEMPLATE(x) \ + template \ + inline bool _##x() \ + { \ + return T::x(); \ + } \ + template \ + inline typename std::enable_if::type \ + _##x() \ + { \ + return _##x() && _##x(); \ + } + +PER_TRANSPORT_VARIADIC_TEMPLATE(initTransport) +PER_TRANSPORT_VARIADIC_TEMPLATE(stopTransport) +PER_TRANSPORT_VARIADIC_TEMPLATE(finalizeTransport) + +} + +#endif/*COMMON_TRANSPORT_HPP*/ diff --git a/jclklib/common/util.hpp b/jclklib/common/util.hpp new file mode 100644 index 00000000..2187f6d1 --- /dev/null +++ b/jclklib/common/util.hpp @@ -0,0 +1,55 @@ +/*! \file util.hpp + \brief Helper functions, templates, and macros + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include + +#ifndef UTIL_HPP +#define UTIL_HPP + +#define UNIQUE_TYPEOF(x) remove_reference::type +#define FUTURE_TYPEOF(x) decltype((x).get()) +#define DECLARE_STATIC(x,...) decltype(x) x __VA_OPT__({) __VA_ARGS__ __VA_OPT__(}) + +template +bool isFutureSet(std::future &f) +{ + return f.valid() && f.wait_for(std::chrono::milliseconds(0)) == std::future_status::ready; +} + +#define DECLARE_ACCESSOR(varname) \ + const decltype(varname) &getc_##varname() { return varname; } \ + decltype(varname) &get_##varname() { return varname; } \ + void set_##varname (const decltype(varname) &varname) { this->varname = varname; } + +#define PTHREAD_CALL(func,err_msg,retval) \ + { \ + int err; \ + if ((err = (func)) != 0) { \ + PrintError(err_msg, err); \ + return retval; \ + } \ + } + + +namespace JClkLibCommon { + class MutexSignal { + private: + pthread_mutex_t c_lock; + pthread_mutex_t p_lock; + public: + MutexSignal(); + bool init(); + bool PreProduce(bool &have); + bool PostProduce(); + bool PostConsume(); + bool PreConsume(); + }; +} + +#endif/*UTIL_HPP*/ + diff --git a/jclklib/proxy/Makefile b/jclklib/proxy/Makefile new file mode 100644 index 00000000..64cb3e4f --- /dev/null +++ b/jclklib/proxy/Makefile @@ -0,0 +1,66 @@ +##! \file Makefile +# \brief Proxy makefile +# +# (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. +# Author: Christopher Hall +# + +JCLKLIB_PROXY_DIR := $(shell pwd) +JCLKLIB_TOPLEVEL_DIR = $(JCLKLIB_PROXY_DIR)/.. +JCLKLIB_COMMON_DIR = $(JCLKLIB_TOPLEVEL_DIR)/common +LIBS = pthread rt +LIBS_FLAGS = $(foreach lib,$(LIBS),-l$(lib)) +OBJ = client main message msgq_tport notification_msg null_tport connect_msg subscribe_msg transport +COMMON_OBJ = print sighandler transport msgq_tport jclklib_import message connect_msg +OBJ_FILES = $(foreach f,$(OBJ),$(f).o) +DEPENDS = $(foreach f,$(OBJ),$(f).d) +COMMON_OBJ_DIR = $(JCLKLIB_COMMON_DIR)/obj +COMMON_OBJ_FILES = $(foreach obj,$(COMMON_OBJ),$(COMMON_OBJ_DIR)/$(obj).o) +REAL_TARGETS = jclklib_proxy + +.PHONY: default +default: + $(MAKE) -s -C $(JCLKLIB_PROXY_DIR) build-all 2>&1 | less -R + +.PHONY: build-prep +build-prep: + echo "Running" $@ + $(MAKE) -C $(JCLKLIB_PROXY_DIR) $(DEPENDS) 2>&1 + + +%.d : %.cpp + echo "[MAKEDEP]" $@ + g++ -I $(JCLKLIB_TOPLEVEL_DIR) -MM -MF $@ $< + +.PHONY: clean +clean: + $(RM) -rf *.o *.d jclklib_proxy + +ifneq ($(MAKECMDGOALS),) +ifeq ($(findstring build-prep,$(MAKECMDGOALS)),) +ifeq ($(findstring build-all,$(MAKECMDGOALS)),) +ifeq ($(findstring clean,$(MAKECMDGOALS)),) +ifneq ($(suffix $(MAKECMDGOALS)),.d) +-include $(DEPENDS) +endif +endif +endif +endif +endif + +pathof_relative_to = $(foreach abpth,$(foreach dep,$1,$(shell realpath $(dep))),\ +$(shell realpath --relative-to="$2" $(abpth))) + +.PHONY: build-all +build-all: build-prep + echo "Running" $@ + $(MAKE) -C $(JCLKLIB_PROXY_DIR) $(REAL_TARGETS) + +jclklib_proxy: $(OBJ_FILES) $(COMMON_OBJ_FILES) + echo "[LINK]" $@ "{" $(call pathof_relative_to,$^,$(JCLKLIB_TOPLEVEL_DIR)) "}" | fold -s + g++ -o $@ $^ $(LIBS_FLAGS) -fdiagnostics-color=always + +%.o : %.cpp + echo "[COMPILE]" $< + g++ -c $< -g -I $(JCLKLIB_TOPLEVEL_DIR) -fdiagnostics-color=always + diff --git a/jclklib/proxy/client.cpp b/jclklib/proxy/client.cpp new file mode 100644 index 00000000..63c465d7 --- /dev/null +++ b/jclklib/proxy/client.cpp @@ -0,0 +1,28 @@ +#include +#include + +using namespace JClkLibProxy; +using namespace JClkLibCommon; +using namespace std; + +DECLARE_STATIC(Client::nextSession,sessionId_t(InvalidSessionId+1)); +DECLARE_STATIC(Client::SessionMap); + +sessionId_t Client::CreateClientSession() +{ + for (auto iter = SessionMap.find(nextSession); nextSession != InvalidSessionId && iter != SessionMap.cend(); + iter = SessionMap.find(++nextSession)); + SessionMap.emplace(SessionMapping_t(nextSession,new Client())); + return nextSession; +} + +ClientX Client::GetClientSession(sessionId_t sessionId) +{ + auto iter = SessionMap.find(sessionId); + if (iter == SessionMap.cend()) { + PrintError("Session ID " + to_string(sessionId) + " not found"); + return ClientX(NULL); + } + + return iter->second; +} diff --git a/jclklib/proxy/client.hpp b/jclklib/proxy/client.hpp new file mode 100644 index 00000000..904a78a6 --- /dev/null +++ b/jclklib/proxy/client.hpp @@ -0,0 +1,31 @@ +#include + +#ifndef PROXY_CLIENT +#define PROXY_CLIENT + +#include + +namespace JClkLibProxy { + class Client; + typedef std::shared_ptr ClientX; + + class Client + { + public: + typedef std::pair SessionMapping_t; + private: + static JClkLibCommon::sessionId_t nextSession; + static std::map SessionMap; + public: + static JClkLibCommon::sessionId_t CreateClientSession(); + static ClientX GetClientSession(JClkLibCommon::sessionId_t sessionId); + private: + std::unique_ptr transmitContext; + public: + void set_transmitContext(decltype(transmitContext)::pointer context) + { this->transmitContext.reset(context); } + auto get_transmitContext() { return transmitContext.get(); } + }; +} + +#endif/*PROXY_CLIENT*/ diff --git a/jclklib/proxy/clock_config.cpp b/jclklib/proxy/clock_config.cpp new file mode 100644 index 00000000..3a615da1 --- /dev/null +++ b/jclklib/proxy/clock_config.cpp @@ -0,0 +1,64 @@ +/*! \file clock_config.cpp + \brief Proxy configuration implementation. One configuration object per session is instatiated + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include + +using namespace JClkLibProxy; +using namespace JClkLibCommon; +using namespace std; + +bool ClockConfiguration::readConsume() +{ + lock_guard update_guard(update_lock); + if (update) + readShadow = config; + update = false; + + return update; +} + +ClockConfiguration::ClockConfiguration() +{ + // Initialize configuration +} + +void ClockConfiguration::speculateWrite() +{ + lock_guard update_guard(update_lock); + writeShadow = config; +} + +void ClockConfiguration::setEvent( const jcl_event &sEvent ) +{ + if (writeShadow.event != sEvent) { + writeShadow.event = sEvent; + writeUpdate = true; + } +} + +void ClockConfiguration::setValue( const jcl_value &sValue ) +{ + if (writeShadow.value != sValue) { + writeShadow.value = sValue; + writeUpdate = true; + } +} + +void ClockConfiguration::commitWrite() +{ + lock_guard update_guard(update_lock); + if (writeUpdate) { + config = writeShadow; + update = writeUpdate; + } + writeUpdate = false; +} + +sessionId_t ClockConfiguration::getSessionId() +{ + return InvalidSessionId; +} diff --git a/jclklib/proxy/clock_config.hpp b/jclklib/proxy/clock_config.hpp new file mode 100644 index 00000000..3a01947c --- /dev/null +++ b/jclklib/proxy/clock_config.hpp @@ -0,0 +1,47 @@ +/*! \file clock_config.hpp + \brief Proxy configuration class. One configuration object per session is instatiated + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include + +#ifndef CLOCK_CONFIG_HPP +#define CLOCK_CONFIG_HPP + +#include +#include + +namespace JClkLibProxy +{ + + class ClockConfiguration + { + private: + enum { event = 0, value }; + bool update, writeUpdate; + std::mutex update_lock; + struct Config { + JClkLibCommon::jcl_event event; + JClkLibCommon::jcl_value value; + }; + Config writeShadow, readShadow; + Config config; + public: + ClockConfiguration(); + void speculateWrite(); + void setEvent( const JClkLibCommon::jcl_event &event ); + void setValue( const JClkLibCommon::jcl_value &value ); + void commitWrite(); + + bool readConsume(); + const JClkLibCommon::jcl_event &getEvent() { return readShadow.event; } + const JClkLibCommon::jcl_value &getValue() { return readShadow.value; } + + static JClkLibCommon::sessionId_t getSessionId(); + }; +} + +#endif/*CLOCK_CONFIG_HPP*/ diff --git a/jclklib/proxy/clock_status.cpp b/jclklib/proxy/clock_status.cpp new file mode 100644 index 00000000..2ad8f5dc --- /dev/null +++ b/jclklib/proxy/clock_status.cpp @@ -0,0 +1,60 @@ +/*! \file clock_status.cpp + \brief Proxy status implementation. One status object per session. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include + +using namespace JClkLibProxy; +using namespace JClkLibCommon; +using namespace std; + +bool ClockStatus::readConsume() +{ + lock_guard update_guard(update_lock); + if (update) + readShadow = status; + update = false; + + return update; +} + +ClockStatus::ClockStatus() +{ + // Initialize status +} + +void ClockStatus::speculateWrite() +{ + lock_guard update_guard(update_lock); + writeShadow = status; +} + +void ClockStatus::setEvent( const jcl_event &sEvent ) +{ + if (writeShadow.event != sEvent) { + writeShadow.event = sEvent; + writeUpdate = true; + } +} + +void ClockStatus::setCount( const jcl_eventcount &sCount ) +{ + if (writeShadow.count != sCount) { + writeShadow.count = sCount; + writeUpdate = true; + } +} + +void ClockStatus::commitWrite() +{ + lock_guard update_guard(update_lock); + if (writeUpdate) { + status = writeShadow; + update = writeUpdate; + } + writeUpdate = false; +} + diff --git a/jclklib/proxy/clock_status.hpp b/jclklib/proxy/clock_status.hpp new file mode 100644 index 00000000..6b1274db --- /dev/null +++ b/jclklib/proxy/clock_status.hpp @@ -0,0 +1,42 @@ +/*! \file clock_status.hpp + \brief Proxy status class. One status object per session. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include + +#ifndef CLOCK_STATUS_HPP +#define CLOCK_STATUS_HPP + +#include + +namespace JClkLibProxy +{ + class ClockStatus + { + private: + class Status { + public: + JClkLibCommon::jcl_event event; + JClkLibCommon::jcl_eventcount count; + }; + bool update, writeUpdate; + std::mutex update_lock; + Status status; + Status writeShadow, readShadow; + public: + ClockStatus(); + void speculateWrite(); + void setEvent( const JClkLibCommon::jcl_event &event ); + void setCount( const JClkLibCommon::jcl_eventcount &count ); + void commitWrite(); + + bool readConsume(); + const JClkLibCommon::jcl_event &getEvent() { return readShadow.event; } + const JClkLibCommon::jcl_eventcount &getCount() { return readShadow.count; } + }; +} + +#endif/*CLOCK_STATUS_HPP*/ diff --git a/jclklib/proxy/connect_msg.cpp b/jclklib/proxy/connect_msg.cpp new file mode 100644 index 00000000..51702e5b --- /dev/null +++ b/jclklib/proxy/connect_msg.cpp @@ -0,0 +1,49 @@ +/*! \file connect_msg.cpp + \brief Proxy connect message implementation. Implements proxy specific connect message function. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include +#include + +using namespace std; +using namespace JClkLibProxy; +using namespace JClkLibCommon; + +MAKE_RXBUFFER_TYPE(ProxyConnectMessage::buildMessage) +{ + msg = new ProxyConnectMessage(); + + return true; +} + +bool ProxyConnectMessage::initMessage() +{ + addMessageType(parseMsgMapElement_t(CONNECT_MSG, buildMessage)); + return true; +} + +PROCESS_MESSAGE_TYPE(ProxyConnectMessage::processMessage) +{ + sessionId_t newSessionId; + + PrintDebug("Processing proxy connect message"); + + if (this->getc_sessionId() != InvalidSessionId) { + PrintError("Session ID *should be* invalid for received proxy connect message"); + return false; + } + + newSessionId = Client::CreateClientSession(); + PrintDebug("Created new client session ID: " + to_string(newSessionId)); + this->set_sessionId(newSessionId); + TxContext = LxContext.CreateTransmitterContext(getClientId()); + Client::GetClientSession(newSessionId).get()->set_transmitContext(TxContext); + set_msgAck(ACK_SUCCESS); + + return true; +} + diff --git a/jclklib/proxy/connect_msg.hpp b/jclklib/proxy/connect_msg.hpp new file mode 100644 index 00000000..43b41b2c --- /dev/null +++ b/jclklib/proxy/connect_msg.hpp @@ -0,0 +1,30 @@ +/*! \file connect_msg.hpp + \brief Proxy connect message class. Implements proxy specific connect message function. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#ifndef PROXY_CONNECT_MSG_HPP +#define PROXY_CONNECT_MSG_HPP + +#include +#include + +namespace JClkLibProxy +{ + class ProxyConnectMessage : virtual public ProxyMessage, virtual public JClkLibCommon::CommonConnectMessage + { + protected: + ProxyConnectMessage() : MESSAGE_CONNECT() {}; + public: + virtual PROCESS_MESSAGE_TYPE(processMessage); + bool generateResponse(uint8_t *msgBuffer, std::size_t &length, + const ClockStatus &status) + { return false; } + static MAKE_RXBUFFER_TYPE(buildMessage); + static bool initMessage(); + }; +} + +#endif/*PROXY_CONNECT_MSG_HPP*/ diff --git a/jclklib/proxy/main.cpp b/jclklib/proxy/main.cpp new file mode 100644 index 00000000..93b72db2 --- /dev/null +++ b/jclklib/proxy/main.cpp @@ -0,0 +1,42 @@ +/*! \file main.cpp + \brief Proxy application implementation + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include +#include +#include + +#include + +using namespace JClkLibProxy; +using namespace JClkLibCommon; +using namespace std; + +int main() +{ + BlockStopSignal(); + if(!ProxyTransport::init()) { + cout << "Transport init failed" << endl; + return -1; + } + if(!ProxyMessage::init()) { + cout << "Message init failed" << endl; + return -1; + } + WaitForStopSignal(); + PrintDebug("Got stop signal"); + if(!ProxyTransport::stop()) { + cout << "stop failed" << endl; + return -1; + } + if(!ProxyTransport::finalize()) { + cout << "finalize failed" << endl; + return -1; + } + + return 0; +} diff --git a/jclklib/proxy/message.cpp b/jclklib/proxy/message.cpp new file mode 100644 index 00000000..e430b616 --- /dev/null +++ b/jclklib/proxy/message.cpp @@ -0,0 +1,20 @@ +/*! \file message.cpp + \brief Proxy message base implementation. Extended for specific messages such as connect and subscribe. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include + +using namespace JClkLibProxy; +using namespace JClkLibCommon; + +bool ProxyMessage::init() +{ + return _initMessage(); +} + + + diff --git a/jclklib/proxy/message.hpp b/jclklib/proxy/message.hpp new file mode 100644 index 00000000..4698856e --- /dev/null +++ b/jclklib/proxy/message.hpp @@ -0,0 +1,39 @@ +/*! \file message.hpp + \brief Proxy message base class. Extended for specific messages such as connect and subscribe. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include +#include + +#ifndef PROXY_MESSAGE_HPP +#define PROXY_MESSAGE_HPP + +#include +#include +#include + +namespace JClkLibProxy +{ + class ProxyMessage : virtual public JClkLibCommon::Message + { + public: + /** + * Generate a response, if necessary, to the received message + * @brief generate response to received message + * + * @param msgBuffer (out) transport buffer to fill response + * @param length (in/out) length of transport buffer to fill (in) and send (out) + * + * @return true if a response is required, false otherwise + */ + virtual bool generateResponse(uint8_t *msgBuffer, std::size_t &length, + const ClockStatus &status) = 0; + static bool init(); + }; +} + +#endif/*PROXY_MESSAGE_HPP*/ diff --git a/jclklib/proxy/msgq_tport.cpp b/jclklib/proxy/msgq_tport.cpp new file mode 100644 index 00000000..c99661d0 --- /dev/null +++ b/jclklib/proxy/msgq_tport.cpp @@ -0,0 +1,105 @@ +/*! \file msgq_tport.cpp + \brief Proxy POSIX message queue transport implementation. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include + +using namespace JClkLibProxy; +using namespace JClkLibCommon; +using namespace std; + +#define NSEC_PER_MSEC (1000000 /*ns*/) +#define NSEC_PER_SEC (1000000000 /*ns*/) + +LISTENER_CONTEXT_PROCESS_MESSAGE_TYPE(ProxyMessageQueueListenerContext::processMessage) +{ + ProxyMessage *msg = dynamic_cast(bmsg); + + PrintDebug("Processing received proxy message"); + if (msg == NULL) { + PrintError("Wrong message type"); + return false; + } + + return msg->processMessage(*this,txcontext); +} + +CREATE_TRANSMIT_CONTEXT_TYPE(ProxyMessageQueueListenerContext::CreateTransmitterContext) +{ + mqd_t txd = mq_open((char *)clientId.data(), TX_QUEUE_FLAGS); + if (txd == -1) { + PrintErrorCode("Failed to open message queue " + string((const char*)clientId.data())); + return NULL; + } + PrintDebug("Successfully connected to client " + string((const char*)clientId.data())); + return new ProxyMessageQueueTransmitterContext(txd); +} + +ProxyMessageQueueListenerContext::ProxyMessageQueueListenerContext(mqd_t mqListenerDesc) + : MessageQueueListenerContext(mqListenerDesc) +{ +} + +ProxyMessageQueueTransmitterContext::ProxyMessageQueueTransmitterContext(mqd_t mqTransmitterDesc) + : MessageQueueTransmitterContext(mqTransmitterDesc) +{ +} + +bool ProxyMessageQueue::initTransport() +{ + struct mq_attr mq_attr; + + mq_attr.mq_flags = 0; + mq_attr.mq_maxmsg = MAX_CLIENT_COUNT; + mq_attr.mq_msgsize = (decltype(mq_attr.mq_msgsize)) std::tuple_size::value; + + PrintInfo("Initializing Message Queue Proxy Transport..."); + mqNativeListenerDesc = mq_open(mqProxyName.c_str(), RX_QUEUE_FLAGS, RX_QUEUE_MODE, &mq_attr); + if (mqNativeListenerDesc == -1) { + cout << "mq_open failed " << strerror(errno) << endl; + return false; + } + + if (InvalidTransportWorkDesc == + (mqListenerDesc = + registerWork(move((TransportWork){MqListenerWork, + TransportWorkArg(new ProxyMessageQueueListenerContext(mqNativeListenerDesc))})))) + return false; + + PrintDebug("Proxy Message queue opened"); + + return true; +} + +bool ProxyMessageQueue::stopTransport() +{ + PrintInfo("Stopping Message Queue Proxy Transport"); + mq_unlink(mqProxyName.c_str()); + if (mqListenerDesc != InvalidTransportWorkDesc && !InterruptWorker(mqListenerDesc)) + PrintError("Interrupt worker failed"); + + return true; +} + +bool ProxyMessageQueue::finalizeTransport() +{ + return mq_close(mqNativeListenerDesc) != -1; +} diff --git a/jclklib/proxy/msgq_tport.hpp b/jclklib/proxy/msgq_tport.hpp new file mode 100644 index 00000000..fa939d5a --- /dev/null +++ b/jclklib/proxy/msgq_tport.hpp @@ -0,0 +1,58 @@ +/*! \file msgq_tport.hpp + \brief Proxy POSIX message queue transport class. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include +#include +#include + +#include + +#ifndef PROXY_MSGQ_TPORT_HPP +#define PROXY_MSGQ_TPORT_HPP + +#include +#include +#include + +#define MAX_CLIENT_COUNT (8) + +namespace JClkLibProxy +{ + class ProxyMessageQueueListenerContext : virtual public JClkLibCommon::MessageQueueListenerContext, + virtual public ProxyTransportListenerContext + { + friend class ProxyMessageQueue; + protected: + virtual LISTENER_CONTEXT_PROCESS_MESSAGE_TYPE(processMessage); + ProxyMessageQueueListenerContext(mqd_t mqListenerDesc); + public: + virtual ~ProxyMessageQueueListenerContext() = default; + virtual CREATE_TRANSMIT_CONTEXT_TYPE(CreateTransmitterContext); + }; + + class ProxyMessageQueueTransmitterContext : virtual public JClkLibCommon::MessageQueueTransmitterContext, + virtual public ProxyTransportTransmitterContext + { + friend class ProxyMessageQueue; + friend class ProxyMessageQueueListenerContext; + protected: + ProxyMessageQueueTransmitterContext(mqd_t mqTransmitterDesc); + public: + virtual ~ProxyMessageQueueTransmitterContext() = default; +}; + + class ProxyMessageQueue : public JClkLibCommon::MessageQueue, public ProxyTransport + { + public: + static bool initTransport(); + static bool stopTransport(); + static bool finalizeTransport(); + }; +} + +#endif/*PROXY_MSGQ_TPORT_HPP*/ diff --git a/jclklib/proxy/notification_msg.cpp b/jclklib/proxy/notification_msg.cpp new file mode 100644 index 00000000..d1b8e108 --- /dev/null +++ b/jclklib/proxy/notification_msg.cpp @@ -0,0 +1,26 @@ +/*! \file notification_msg.cpp + \brief Proxy connect message implementation. Implements proxy specific connect message function. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include +#include + +using namespace JClkLibProxy; + +bool ProxyNotificationMessage::processMessage(ClockConfiguration &config) +{ + //config.setWait( waitEnable ); + + return true; +} +bool ProxyNotificationMessage::generateResponse(uint8_t *msgBuffer, size_t &length, + const ClockStatus &status) +{ + return false; +} + + diff --git a/jclklib/proxy/notification_msg.hpp b/jclklib/proxy/notification_msg.hpp new file mode 100644 index 00000000..48b436d5 --- /dev/null +++ b/jclklib/proxy/notification_msg.hpp @@ -0,0 +1,32 @@ +/*! \file notification_msg.hpp + \brief Proxy connect message class. Implements proxy specific connect message function. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include + +#ifndef PROXY_NOTIFICATION_MSG_HPP +#define PROXY_NOTIFICATION_MSG_HPP + +#include +#include +#include + +namespace JClkLibProxy +{ + class ProxyNotificationMessage : virtual public ProxyMessage, + virtual public JClkLibCommon::NotificationMessage + { + public: + bool processMessage(ClockConfiguration &config); + bool generateResponse(std::uint8_t *msgBuffer, std::size_t &length, + const ClockStatus &status); + + protected: + ProxyNotificationMessage() : MESSAGE_NOTIFY() {} + }; +} + +#endif/*PROXY_NOTIFICATION_MSG_HPP*/ diff --git a/jclklib/proxy/null_msg.hpp b/jclklib/proxy/null_msg.hpp new file mode 100644 index 00000000..6a3bb5b4 --- /dev/null +++ b/jclklib/proxy/null_msg.hpp @@ -0,0 +1,29 @@ +/*! \file null_msg.hpp + \brief Proxy null message class. Used for debug only. Should not be used. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#ifndef PROXY_NULL_MSG_HPP +#define PROXY_NULL_MSG_HPP + +#include +#include + +namespace JClkLibProxy +{ + class ProxyNullMessage : virtual public ProxyMessage, virtual public JClkLibCommon::CommonNullMessage + { + protected: + ProxyNullMessage() : MESSAGE_NULL() {}; + public: + bool processMessage(ClockConfiguration &config) { return true; } + bool generateResponse(uint8_t *msgBuffer, std::size_t &length, + const ClockStatus &status) + { return false; } + static bool initMessage() { return true; } + }; +} + +#endif/*PROXY_NULL_MSG_HPP*/ diff --git a/jclklib/proxy/null_tport.cpp b/jclklib/proxy/null_tport.cpp new file mode 100644 index 00000000..00b37450 --- /dev/null +++ b/jclklib/proxy/null_tport.cpp @@ -0,0 +1,21 @@ +/*! \file null_tport.cpp + \brief Null transport implementation. Non-functional for testing only. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include + +#include + +using namespace JClkLibProxy; +using namespace std; + +SEND_PROXY_MESSAGE(NullProxyTransport::sendMessage) +{ + PrintError("NullTransport should not be used"); + return false; +} + diff --git a/jclklib/proxy/null_tport.hpp b/jclklib/proxy/null_tport.hpp new file mode 100644 index 00000000..33aabb9d --- /dev/null +++ b/jclklib/proxy/null_tport.hpp @@ -0,0 +1,25 @@ +/*! \file null_tport.hpp + \brief Null transport class. Non-functional for testing only. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#ifndef PROXY_NULL_TPORT_HPP +#define PROXY_NULL_TPORT_HPP + +#include +#include + +#include + +namespace JClkLibProxy +{ + class NullProxyTransport : public JClkLibCommon::NullTransport + { + public: + static SEND_PROXY_MESSAGE(sendMessage); + }; +} + +#endif/*PROXY_NULL_TPORT_HPP*/ diff --git a/jclklib/proxy/subscribe_msg.cpp b/jclklib/proxy/subscribe_msg.cpp new file mode 100644 index 00000000..c49ed0c1 --- /dev/null +++ b/jclklib/proxy/subscribe_msg.cpp @@ -0,0 +1,26 @@ +/*! \file subscribe_msg.cpp + \brief Proxy subscribe message implementation. Implements proxy specific subscribe message function. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include + +using namespace JClkLibProxy; + +bool ProxySubscribeMessage::processMessage(ClockConfiguration &config) +{ + //config.setEvent(subscription.getEvent()); + //config.setValue(subscription.getValue()); + + return true; +} +bool ProxySubscribeMessage::generateResponse(uint8_t *msgBuffer, size_t &length, + const ClockStatus &status) +{ + return false; +} + + diff --git a/jclklib/proxy/subscribe_msg.hpp b/jclklib/proxy/subscribe_msg.hpp new file mode 100644 index 00000000..2009d201 --- /dev/null +++ b/jclklib/proxy/subscribe_msg.hpp @@ -0,0 +1,28 @@ +/*! \file subscribe_msg.hpp + \brief Proxy subscribe message class. Implements proxy specific subscribe message function. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#ifndef PROXY_SUBSCRIBE_MSG_HPP +#define PROXY_SUBSCRIBE_MSG_HPP + +#include +#include + +namespace JClkLibProxy +{ + class ProxySubscribeMessage : virtual public ProxyMessage, virtual public JClkLibCommon::SubscribeMessage + { + public: + bool processMessage(ClockConfiguration &config); + bool generateResponse(uint8_t *msgBuffer, std::size_t &length, + const ClockStatus &status); + + protected: + ProxySubscribeMessage() : MESSAGE_SUBSCRIBE() {}; + }; +} + +#endif/*SUBSCRIBE_MSG_HPP*/ diff --git a/jclklib/proxy/transport.cpp b/jclklib/proxy/transport.cpp new file mode 100644 index 00000000..b2b02d3b --- /dev/null +++ b/jclklib/proxy/transport.cpp @@ -0,0 +1,47 @@ +/*! \file transport.cpp + \brief Proxy transport base class implementation for JClkLib. It provides common functionality for derived transport classes. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include +#include +#include +#include +#include + +#define EXIT_TIMEOUT (200 /*ms*/) +#define START_TIMEOUT (20 /*ms*/) + +using namespace JClkLibProxy; +using namespace JClkLibCommon; +using namespace std; + +bool ProxyTransport::init() +{ + if (!Transport::init()) + return false; + PrintDebug("Finished common init"); + + return JClkLibCommon::_initTransport(); +} + +bool ProxyTransport::stop() +{ + if (!Transport::stop()) + return false; + + /* Do any transport specific stop */ + return JClkLibCommon::_stopTransport(); +} + +bool ProxyTransport::finalize() +{ + if (!Transport::finalize()) + return false; + + return JClkLibCommon::_finalizeTransport(); +} + diff --git a/jclklib/proxy/transport.hpp b/jclklib/proxy/transport.hpp new file mode 100644 index 00000000..91d835b0 --- /dev/null +++ b/jclklib/proxy/transport.hpp @@ -0,0 +1,51 @@ +/*! \file transport.hpp + \brief Transport base class for JClkLib Proxy. It is extended for specific transports such as POSIX message queue. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include +#include +#include +#include +#include + +#ifndef PROXY_TRANSPORT_HPP +#define PROXY_TRANSPORT_HPP + +#include +#include +#include +#include +#include + +namespace JClkLibProxy +{ + class ProxyTransportTransmitterContext : virtual public JClkLibCommon::TransportTransmitterContext { + protected: + ProxyTransportTransmitterContext() {} + public: + virtual ~ProxyTransportTransmitterContext() = default; + }; + + class ProxyTransportListenerContext : virtual public JClkLibCommon::TransportListenerContext { + public: + virtual ~ProxyTransportListenerContext() = default; + }; + + + class ProxyTransport : public JClkLibCommon::Transport + { + public: + static bool init(); + static bool stop(); + static bool finalize(); +#define SEND_PROXY_MESSAGE(name) \ + bool name (const JClkLibProxy::ProxyMessage *msg) + static SEND_PROXY_MESSAGE(sendMessage) { return false; } + }; +} + +#endif/*PROXY_TRANSPORT_HPP*/ From 0fc99a9439ad5a59f1882af36aa73ef2cd489194 Mon Sep 17 00:00:00 2001 From: Christopher S M Hall Date: Thu, 19 Oct 2023 18:30:31 -0700 Subject: [PATCH 004/151] Add priority inheritance signaling --- jclklib/common/Makefile | 5 +- jclklib/common/mutex_signal.cpp | 201 ++++++++++++++++++++++++++++++++ jclklib/common/mutex_signal.hpp | 49 ++++++++ jclklib/common/util.hpp | 17 +-- 4 files changed, 255 insertions(+), 17 deletions(-) create mode 100644 jclklib/common/mutex_signal.cpp create mode 100644 jclklib/common/mutex_signal.hpp diff --git a/jclklib/common/Makefile b/jclklib/common/Makefile index 3fcf5aa6..e8229ad8 100644 --- a/jclklib/common/Makefile +++ b/jclklib/common/Makefile @@ -9,7 +9,8 @@ JCLKLIB_COMMON_DIR := $(shell pwd) JCLKLIB_TOPLEVEL_DIR := $(JCLKLIB_COMMON_DIR)/.. LIBS = pthread rt LIBS_FLAGS = $(foreach lib,$(LIBS),-l$(lib)) -OBJ = jclklib_import message msgq_tport notification_msg null_msg connect_msg print sighandler subscribe_msg transport util +OBJ = jclklib_import message msgq_tport notification_msg null_msg connect_msg print sighandler subscribe_msg transport\ + mutex_signal OBJ_FILES = $(foreach f,$(OBJ),$(f).o) DEPENDS = $(foreach f,$(OBJ),$(f).d) OBJ_DIR = $(JCLKLIB_COMMON_DIR)/obj @@ -57,5 +58,5 @@ common-obj: $(OBJ_FILES) %.o : %.cpp echo "[COMPILE]" $< - g++ -c $< -g -I $(JCLKLIB_TOPLEVEL_DIR) -fPIC -Werror -Wall -fdiagnostics-color=always + g++ -c $< -g -I $(JCLKLIB_TOPLEVEL_DIR) -fPIC -Werror -Wall -Wextra -Wno-unused-parameter -fdiagnostics-color=always diff --git a/jclklib/common/mutex_signal.cpp b/jclklib/common/mutex_signal.cpp new file mode 100644 index 00000000..cadd6973 --- /dev/null +++ b/jclklib/common/mutex_signal.cpp @@ -0,0 +1,201 @@ +#include + +#include +#include + +using namespace std; +using namespace mutex_signal_test; + +#define NSEC_PER_SEC (1000000000) + +#define PTHREAD_CALL(func,err_msg,retval,...) \ + ({ \ + int err; \ + if ((err = (func)) != 0 __VA_OPT__(&& err !=) __VA_ARGS__) { \ + cerr << string(err_msg) + " " + strerror(err) + "\n"; \ + return retval; \ + } \ + (err == 0); \ + }) + +mutex_signal::mutex_signal() +{ + update_available = false; + consumer_locked = false; + producer_locked = false; +} + +bool mutex_signal::init() +{ + pthread_mutexattr_t attr; + + PTHREAD_CALL(pthread_mutexattr_init(&attr), "Failed to initialize mutex attribute", false); + PTHREAD_CALL(pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT), "Failed to set priority inheritance", false); + PTHREAD_CALL(pthread_mutex_init(&p_lock, &attr), "Failed to initialize producer mutex", false); + PTHREAD_CALL(pthread_mutex_init(&c_lock, &attr), "Failed to initialize consumer mutex", false); + PTHREAD_CALL(pthread_mutex_init(&d_lock, NULL), "Failed to initialize data mutex", false); + PTHREAD_CALL(pthread_mutexattr_destroy(&attr), "Failed to cleanup mutex attribute", false); + + return true; +} + +mutex_signal::~mutex_signal() +{ + PTHREAD_CALL(pthread_mutex_destroy(&d_lock), "Failed to cleanup data mutex",); +} + +bool mutex_signal::consumerTryLock(bool &success) +{ + success = PTHREAD_CALL(pthread_mutex_trylock(&c_lock), "Failed to lock consumer lock", false, EBUSY); + return true; +} +bool mutex_signal::consumerLock() +{ + PTHREAD_CALL(pthread_mutex_lock(&c_lock), "Failed to lock consumer lock", false); + return true; +} +bool mutex_signal::consumerUnlock() +{ + PTHREAD_CALL(pthread_mutex_unlock(&c_lock), "Failed to unlock consumer lock", false); + return true; +} + +bool mutex_signal::producerTryLock(bool &success) +{ + success = PTHREAD_CALL(pthread_mutex_trylock(&p_lock), "Failed to lock producer lock", false, EBUSY); + return true; +} +bool mutex_signal::producerTimedLock(bool &success, chrono::time_point wait_until) +{ + struct timespec wait_until_ts; + wait_until_ts.tv_sec = chrono::duration_cast(wait_until.time_since_epoch()).count() / NSEC_PER_SEC; + wait_until_ts.tv_nsec = chrono::duration_cast(wait_until.time_since_epoch()).count() % NSEC_PER_SEC; + + success = PTHREAD_CALL(pthread_mutex_timedlock(&p_lock, &wait_until_ts),"Failed to lock producer lock", false, ETIMEDOUT); + + return true; +} +bool mutex_signal::producerLock() +{ + PTHREAD_CALL(pthread_mutex_lock(&p_lock), "Failed to lock producer lock", false); + return true; +} +bool mutex_signal::producerUnlock() +{ + PTHREAD_CALL(pthread_mutex_unlock(&p_lock), "Failed to unlock producer lock", false); + return true; +} + +bool mutex_signal::dataTryLock(bool &success) +{ + success = PTHREAD_CALL(pthread_mutex_trylock(&d_lock), "Failed to lock data lock", false, EBUSY); + return true; +} +bool mutex_signal::dataTimedLock(bool &success, chrono::time_point wait_until) +{ + struct timespec wait_until_ts; + wait_until_ts.tv_sec = chrono::duration_cast(wait_until.time_since_epoch()).count() / NSEC_PER_SEC; + wait_until_ts.tv_nsec = chrono::duration_cast(wait_until.time_since_epoch()).count() % NSEC_PER_SEC; + success = PTHREAD_CALL(pthread_mutex_timedlock(&d_lock, &wait_until_ts),"Failed to lock data lock", false, ETIMEDOUT); + + return true; +} +bool mutex_signal::dataLock() +{ + PTHREAD_CALL(pthread_mutex_lock(&d_lock), "Failed to lock data lock", false); + return true; +} +bool mutex_signal::dataUnlock() +{ + PTHREAD_CALL(pthread_mutex_unlock(&d_lock), "Failed to unlock data lock", false); + return true; +} + +bool mutex_signal::preProduce() +{ + if (!dataLock()) + return false; + + producer_locked = true; + return true; +} +bool mutex_signal::postProduce() +{ + bool producer_c_lock; + if (!producer_locked) + return false; + update_available = true; + if (!dataUnlock() || !consumerTryLock(producer_c_lock)) + return false; + if (producer_c_lock && (!producerUnlock() || !consumerUnlock() || !producerLock())) + return false; + + producer_locked = false; + return true; +} + +bool mutex_signal::preConsume(bool &success, chrono::duration wait_for) +{ + auto wait_until = chrono::system_clock::now() + wait_for; + bool consumer_p_lock; + + if (!dataTimedLock(success, wait_until)) + return false; + consumer_locked = success && update_available; + if (!success || consumer_locked) + return true; + + success = false; + if (!consumerUnlock() || !dataUnlock() || !producerTimedLock(consumer_p_lock, wait_until) || !consumerLock()) + return false; + if (!consumer_p_lock) + return true; + if (!dataTimedLock(success, wait_until)) + return false; + if (consumer_p_lock && !producerUnlock()) + return false; + + if (success && !update_available && !dataUnlock()) + return false; + success = consumer_locked = success && update_available; + + return true; +} + +bool mutex_signal::postConsume() +{ + if (!consumer_locked) + return false; + update_available = false; + if(!dataUnlock()) + return false; + + consumer_locked = false; + return true; +} + +bool mutex_signal::producerInit() +{ + return producerLock(); +} + +bool mutex_signal::producerCleanup() +{ + if (producer_locked && !postProduce()) + return false; + + return producerUnlock(); +} + +bool mutex_signal::consumerInit() +{ + return consumerLock(); +} + +bool mutex_signal::consumerCleanup() +{ + if (consumer_locked && !postConsume()) + return false; + + return consumerUnlock(); +} diff --git a/jclklib/common/mutex_signal.hpp b/jclklib/common/mutex_signal.hpp new file mode 100644 index 00000000..7e767fa9 --- /dev/null +++ b/jclklib/common/mutex_signal.hpp @@ -0,0 +1,49 @@ +#include +#include + +#ifndef MUTEX_SIGNAL_HPP +#define MUTEX_SIGNAL_HPP + +namespace mutex_signal_test { + class mutex_signal + { + private: + pthread_mutex_t p_lock; + pthread_mutex_t c_lock; + pthread_mutex_t d_lock; + bool update_available; + + bool consumer_locked; + bool producer_locked; + + bool consumerTryLock(bool &success); + bool consumerLock(); + bool consumerUnlock(); + + bool producerTryLock(bool &success); + bool producerTimedLock(bool &success, std::chrono::time_point wait_until); + bool producerLock(); + bool producerUnlock(); + + bool dataTryLock(bool &success); + bool dataTimedLock(bool &success, std::chrono::time_point wait_until); + bool dataLock(); + bool dataUnlock(); + public: + mutex_signal(); + ~mutex_signal(); + bool init(); + + bool producerInit(); + bool producerCleanup(); + bool preProduce(); + bool postProduce(); + + bool consumerInit(); + bool consumerCleanup(); + bool preConsume(bool &success, std::chrono::duration wait_until); + bool postConsume(); + }; +} + +#endif/*MUTEX_SIGNAL_HPP*/ diff --git a/jclklib/common/util.hpp b/jclklib/common/util.hpp index 2187f6d1..14663a6c 100644 --- a/jclklib/common/util.hpp +++ b/jclklib/common/util.hpp @@ -11,6 +11,8 @@ #ifndef UTIL_HPP #define UTIL_HPP +#include + #define UNIQUE_TYPEOF(x) remove_reference::type #define FUTURE_TYPEOF(x) decltype((x).get()) #define DECLARE_STATIC(x,...) decltype(x) x __VA_OPT__({) __VA_ARGS__ __VA_OPT__(}) @@ -36,20 +38,5 @@ bool isFutureSet(std::future &f) } -namespace JClkLibCommon { - class MutexSignal { - private: - pthread_mutex_t c_lock; - pthread_mutex_t p_lock; - public: - MutexSignal(); - bool init(); - bool PreProduce(bool &have); - bool PostProduce(); - bool PostConsume(); - bool PreConsume(); - }; -} - #endif/*UTIL_HPP*/ From fbee4da3ff37eef12f0a007a141b5639a44eeab7 Mon Sep 17 00:00:00 2001 From: Noor Azura Ahmad Tarmizi Date: Tue, 19 Mar 2024 03:39:49 -0400 Subject: [PATCH 005/151] Doc: add README_jclklib.md This document will provide basic architecture and simplified code flow for connect/subscribe/notification messages. This is a live document. Signed-off-by: Noor Azura Ahmad Tarmizi --- jclklib/README_jclklib.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 jclklib/README_jclklib.md diff --git a/jclklib/README_jclklib.md b/jclklib/README_jclklib.md new file mode 100644 index 00000000..c44ff576 --- /dev/null +++ b/jclklib/README_jclklib.md @@ -0,0 +1,23 @@ +# JCLKLIB codeflow + +Jclklib is a 2-part implementation for C/C++ application to obtain +ptp4l events via pub/sub method using a library api call. + +It provides a library jcklib.so (aka client-runtime library) and a daemon +jclklib_proxy. + +In short we have : + FRONT-END MIDDLE-PIPE BACK-END +c/c++ app <---------> jclklib.so <----------> jclklib_proxy<--------> ptp4l + (library call) (using msq) | (via UDS) + | + libptpmgmt.so + +* **c++ app** - Customer application that will be linking to jclklib.so library. Header file and sample test cpp file will be provided. + +* **jcklib.so** - A dynamic library that provides a set of APIs to customer application : connect/disconnect, subscribe to ptp4l daemon. This library is written in C++. It will have a permissive licence. It communicates with jclkib_proxy using message queues. + +* **jclklib_proxy** - A daemon that is using libptpmgmt api to establish connection and subscribe towards ptp4l events. The communication is establish using ptp4l UDS (/var/run/ptp4l as we now assumed it is always installed in the same local machine as the ptp4l) + +## Connect message flow (simplified code walkthrough) + From 640460f7c5d0ee535b52ea833ae49cc64d3b1a9c Mon Sep 17 00:00:00 2001 From: Noor Azura Ahmad Tarmizi Date: Tue, 19 Mar 2024 04:26:49 -0400 Subject: [PATCH 006/151] Doc: Add doxy comments for connect message related files. Signed-off-by: Noor Azura Ahmad Tarmizi --- jclklib/client/connect_msg.cpp | 31 +++++++++++++++++++++++++++++++ jclklib/client/connect_msg.hpp | 18 ++++++++++++++++++ jclklib/proxy/connect_msg.cpp | 32 +++++++++++++++++++++++++++++--- jclklib/proxy/connect_msg.hpp | 20 +++++++++++++++++++- 4 files changed, 97 insertions(+), 4 deletions(-) diff --git a/jclklib/client/connect_msg.cpp b/jclklib/client/connect_msg.cpp index ee752573..23db1bf1 100644 --- a/jclklib/client/connect_msg.cpp +++ b/jclklib/client/connect_msg.cpp @@ -12,6 +12,12 @@ using namespace JClkLibClient; using namespace JClkLibCommon; using namespace std; +/** @brief Create the ClientConnectMessage object + * + * @param msg msg structure to be fill up + * @param LxContext client run-time transport listener context + * @return true + */ MAKE_RXBUFFER_TYPE(ClientConnectMessage::buildMessage) { msg = new ClientConnectMessage(); @@ -19,12 +25,35 @@ MAKE_RXBUFFER_TYPE(ClientConnectMessage::buildMessage) return true; } +/** @brief Add client's CONNECT_MSG type and its builder to transport layer. + * + * This function will be called during init to add a map of CONNECT_MSG + * type and its corresponding buildMessage function. + * + * @return true + */ bool ClientConnectMessage::initMessage() { addMessageType(parseMsgMapElement_t(CONNECT_MSG, buildMessage)); return true; } +/** @brief process the reply for connect msg from proxy. + * + * This function will be called when the transport layer + * in client runtime received a CONNECT_MSG type (an echo reply from + * proxy) + * In this case, transport layer will rx a buffer in the client associated + * listening message queue (listening to proxy) and call this function when + * the enum ID corresponding to the CONNECT_MSG is received. + * For client-runtime, this will always be the reply, since connect msg + * is always send first from the client runtime first. The proxy will + * echo-reply with a different ACK msg. + * + * @param LxContext client run-time transport listener context + * @param TxContext client run-time transport transmitter context + * @return true + */ PROCESS_MESSAGE_TYPE(ClientConnectMessage::processMessage) { sessionId_t newSessionId; @@ -36,6 +65,8 @@ PROCESS_MESSAGE_TYPE(ClientConnectMessage::processMessage) PrintDebug("Connected with session ID: " + to_string(this->get_sessionId())); + /*[TODO] client runtime shd return client ID to application - return client ID at least */ + /*[Question] ACK_NONE is necessary ?*/ this->set_msgAck(ACK_NONE); return true; } diff --git a/jclklib/client/connect_msg.hpp b/jclklib/client/connect_msg.hpp index b84fbcbe..3c1eeab0 100644 --- a/jclklib/client/connect_msg.hpp +++ b/jclklib/client/connect_msg.hpp @@ -18,8 +18,26 @@ namespace JClkLibClient { public: ClientConnectMessage() : MESSAGE_CONNECT() {}; + /** + * @brief process the reply for connect msg from proxy. + * @param LxContext client run-time transport listener context + * @param TxContext client run-time transport transmitter context + * @return true + */ virtual PROCESS_MESSAGE_TYPE(processMessage); + + /** + * @brief Create the ClientConnectMessage object + * @param msg msg structure to be fill up + * @param LxContext client run-time transport listener context + * @return true + */ static MAKE_RXBUFFER_TYPE(buildMessage); + + /** + * @brief Add client's CONNECT_MSG type and its builder to transport layer. + * @return true + */ static bool initMessage(); }; } diff --git a/jclklib/proxy/connect_msg.cpp b/jclklib/proxy/connect_msg.cpp index 51702e5b..b23b4b4e 100644 --- a/jclklib/proxy/connect_msg.cpp +++ b/jclklib/proxy/connect_msg.cpp @@ -13,19 +13,45 @@ using namespace std; using namespace JClkLibProxy; using namespace JClkLibCommon; +/** @brief Create the ProxyConnectMessage object + * + * @param msg msg structure to be fill up + * @param LxContext proxy transport listener context + * @return true + */ MAKE_RXBUFFER_TYPE(ProxyConnectMessage::buildMessage) { msg = new ProxyConnectMessage(); - return true; } +/** @brief Add proxy's CONNECT_MSG type and its builder to transport layer. + * + * This function will be called during init to add a map of CONNECT_MSG + * type and its corresponding buildMessage function. + * + * @return true + */ bool ProxyConnectMessage::initMessage() { - addMessageType(parseMsgMapElement_t(CONNECT_MSG, buildMessage)); - return true; + addMessageType(parseMsgMapElement_t(CONNECT_MSG, buildMessage)); + return true; } +/** @brief process the connect msg from client-runtime + * + * This function will be called when the transport layer + * in proxy receive a CONNECT_MSG type from client-runtime. + * In this case, proxy transport layer will rx a buffer in the + * message queue and call this function when + * the enum ID corresponding to the CONNECT_MSG is received. + * A new ClientSession object and a corresponding TxContext + * (with the transmit msq) is created in the proxy. + * + * @param LxContext proxy transport listener context + * @param TxContext proxy transport transmitter context + * @return true + */ PROCESS_MESSAGE_TYPE(ProxyConnectMessage::processMessage) { sessionId_t newSessionId; diff --git a/jclklib/proxy/connect_msg.hpp b/jclklib/proxy/connect_msg.hpp index 43b41b2c..86745316 100644 --- a/jclklib/proxy/connect_msg.hpp +++ b/jclklib/proxy/connect_msg.hpp @@ -18,11 +18,29 @@ namespace JClkLibProxy protected: ProxyConnectMessage() : MESSAGE_CONNECT() {}; public: + /** + * @brief process the connect msg from client-runtime + * @param LxContext proxy transport listener context + * @param TxContext proxy transport transmitter context + * @return true + */ virtual PROCESS_MESSAGE_TYPE(processMessage); + bool generateResponse(uint8_t *msgBuffer, std::size_t &length, const ClockStatus &status) { return false; } - static MAKE_RXBUFFER_TYPE(buildMessage); + + /** + * @brief Create the ProxyConnectMessage object + * @param msg msg structure to be fill up + * @param LxContext proxy transport listener context + * @return true + */ + static MAKE_RXBUFFER_TYPE(buildMessage); + + /** @brief Add proxy's CONNECT_MSG type and its builder to transport layer. + * @return true + */ static bool initMessage(); }; } From dfa3dfd60f6aa910d4bec32b82400e2e5cdf15e7 Mon Sep 17 00:00:00 2001 From: Noor Azura Ahmad Tarmizi Date: Wed, 20 Mar 2024 00:36:26 -0400 Subject: [PATCH 007/151] Doc: Added details on connect message code flow. Signed-off-by: Noor Azura Ahmad Tarmizi --- jclklib/README_jclklib.md | 111 +++++++++++++++++++++++++++++++++++--- 1 file changed, 103 insertions(+), 8 deletions(-) diff --git a/jclklib/README_jclklib.md b/jclklib/README_jclklib.md index c44ff576..0f56bde1 100644 --- a/jclklib/README_jclklib.md +++ b/jclklib/README_jclklib.md @@ -7,17 +7,112 @@ It provides a library jcklib.so (aka client-runtime library) and a daemon jclklib_proxy. In short we have : - FRONT-END MIDDLE-PIPE BACK-END -c/c++ app <---------> jclklib.so <----------> jclklib_proxy<--------> ptp4l - (library call) (using msq) | (via UDS) - | - libptpmgmt.so + FRONT-END MIDDLE-PIPE BACK-END +c/c++ app<-------->jclklib.so<---------->jclklib_proxy<-------->ptp4l + (library call) (using msq) | (via UDS) + | + libptpmgmt.so + +**if the diagram is not lisible, please change to text mode.** * **c++ app** - Customer application that will be linking to jclklib.so library. Header file and sample test cpp file will be provided. -* **jcklib.so** - A dynamic library that provides a set of APIs to customer application : connect/disconnect, subscribe to ptp4l daemon. This library is written in C++. It will have a permissive licence. It communicates with jclkib_proxy using message queues. +* **jclklib.so** - A dynamic library that provides a set of APIs to customer application : connect/disconnect, subscribe to proxy which in turn connect to ptp4l service. +This library is written in C++. It will have a permissive licence. It communicates with jclkib_proxy using message queues. +This library is also referred to as client-runtime library. + +* **jclklib_proxy** - A daemon that is using libptpmgmt api to establish connection and subscribe towards ptp4l events. The communication is established using ptp4l UDS (/var/run/ptp4l as we now assumed it is always installed in the same local machine as the ptp4l) + +## Compilation +Currently, we need to run 'make' in client, proxy folder. +It will definitely change in the future. Stay tuned. + +## Connect message info + +### Code Example : client/test.cpp , client/run_test.sh +Please adjust the LD_LIBRARY_PATH accordingly to include the correct jclklib.so +The placement will be changed in the future. + +### Connect message flow (simplified code walkthrough) + +Scenario : client application uses the jcklkib.so API to call `connect()`. +This will establish connection to the proxy. + +** Client point of view ** + +1. **client/init.cpp/JClkLibClient::connect()** + - Creation of new ClientConnectMessage object for CONNECT_MSG + +1.1. **client/message.cpp/ClientMessage::init()** + - We have this recursive template. + `"template JClkLibCommon::_initMessage()` + This will execute the `ClientConnectMessage::initMessage()` + + 1.1.1 **client/connect_msg.cpp/ClientConnectMessage::initMessage()** + - This will add the pair of + - When an object of the type of ClientConnectMessage is received + by the client transporter layer, it will know how to translate the object + to messagequeue buffer. + +1.2. **client/init.cpp/ClientTransport::init()** + - Same concept as above but using initTransport recursive template. + This will execute the `ClientMessageQueue::initTransport()` + + 1.2.1 **client/msgq_tport.cpp/initTransport()** + - Creation of listening and transmitting message queue. + - Creation of **ClientMessageQueueListenerContext** and + **ClientMessageQueueTransmitterContext** + + For each Listener and Transmitter context a specific message queue is defined. + + - Start *MqListenerWork* listener thread to listen to proxy reply. + +1.3. **client/msgq_tport.cpp/ClientMessageQueue::writeTransportClientId(connectMsg.get());** +- Write the Client Listener msgq as the Transport Client ID. +This will allow the proxy to later connect to the client listener msgq to send ack msg. + +1.4. **ClientMessageQueue::sendMessage(connectMsg.get());** +- Send the connect message to proxy. The object will be passed to transport layer. +Transport will then transform the client connect message object to buffer that +will then be sent thru the client transmitter msgq. + +NOTE: Acknowledgement from proxy is the echo of the same message with ACK field added. +1.5 **client/connect_msg.cpp/ClientConnectMessage::processMessage** +- Client Transport layer will call this function to process from ClientConnectMessage reply received. +It is identified based on the unique msgID for CONNECT_MSG. +Currently we only printout the sessionID given by the proxy. + +**[TODO]**: Return the sessionID to user calling the api connect. + +** Proxy point of view ** +Jclklib_proxy runs like a service daemon waiting for messages from potential client app. +The main loop function is in main.cpp. + +How to run : LD_CONFIG_PATH= jcklib_proxy -lptpmgmt & + +1. **proxy/transport.cpp/ProxyTransport::init()** +- Same as for Client, the ProxyTransport layer is initialized. +- Set up listening message queue : `proxy/msg_tport.cpp/ProxyMessageQueue::initTransport()` + +1. **proxy/message.cpp/ProxyMessage::init()** +- Same as for Client, the ProxyMessage layer is initialized. +This will call the `ProxyConnectMessage::initMessage()` + +1.1 **proxy/connect_message.cpp/ProxyConnectMessage::initMessage()** +- Initialize the map with the first pair being CONNECT_MSG and its proxy buildMessage function. + +Upon receiving the CONNECT_MSG in the proxy listener message queue (msgq) buffer, it will be received by `common/Transport::processMessage()` +which then trigger the `ProxyConnectMessage::buildMessage`. +And it will the message to `ProxyConnectMessage:processMessage`. -* **jclklib_proxy** - A daemon that is using libptpmgmt api to establish connection and subscribe towards ptp4l events. The communication is establish using ptp4l UDS (/var/run/ptp4l as we now assumed it is always installed in the same local machine as the ptp4l) +2. **proxy/connect_message.cpp/ProxyConnectMessage:processMessage** +- A new client session is created. A transmitter context is created for the client. +A transmitter context will have a dedicated tx msgq buffer for the client. +- The msg_ack is put to ACK_SUCCESS. This will then be taken back in +common/Transport::processMessage() and the echo reply be sent back to client. -## Connect message flow (simplified code walkthrough) +## Subscription message info +To be added soon. +## Notification message info +To be added soon. From 76e15b82d69d0df49396033bdebcdf203b43dff0 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Fri, 29 Mar 2024 10:53:17 +0800 Subject: [PATCH 008/151] Add coverity scan workflow Add workflow to build the code using coverity tool and upload the result to https://scan.coverity.com/builds?project=libptpmgmt_iaclocklib. The workflow will run automatically when new changes are pushed to main branch. Signed-off-by: Song Yoong Siang --- .github/workflows/coverity.yml | 25 +++++++++++++++++++++++++ README.md | 6 ++++++ 2 files changed, 31 insertions(+) create mode 100644 .github/workflows/coverity.yml diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml new file mode 100644 index 00000000..4d097516 --- /dev/null +++ b/.github/workflows/coverity.yml @@ -0,0 +1,25 @@ +# Visit https://scan.coverity.com/projects/libptpmgmt_iaclocklib for coverity result + +name: Coverity Scan + +on: + push: + branches: [main] + workflow_dispatch: + +jobs: + coverity: + runs-on: ubuntu-latest + steps: + - name: Install dependencies + run: sudo apt-get install -y swig libtool-bin + - uses: actions/checkout@v4 + - name: autoconf + run: autoconf + - name: configure + run: ./configure + - uses: vapier/coverity-scan-action@v1 + with: + email: ${{ secrets.COVERITY_SCAN_EMAIL }} + token: ${{ secrets.COVERITY_SCAN_TOKEN }} + project: libptpmgmt_iaclocklib diff --git a/README.md b/README.md index fcbe9b44..05521f9c 100644 --- a/README.md +++ b/README.md @@ -159,3 +159,9 @@ The Licence of this project is # Disclaimer This project is under development. All source code and features on the main branch are for the purpose of testing or evaluation and not production ready. + +# Coverity Scan + + Coverity Scan Build Status + From e0d1b77ce87b5a5e132bf58cb2fa7ca65139e91f Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Fri, 29 Mar 2024 11:00:15 +0800 Subject: [PATCH 009/151] Add OSSF Scorecard workflow Add workflow for security vulnerabilities scan and upload the result to https://securityscorecards.dev/viewer/?uri=github.com/intel-staging/libptpmgmt_iaclocklib The workflow will run automatically when new changes are pushed to main branch. Signed-off-by: Song Yoong Siang --- .github/workflows/scorecard.yml | 73 +++++++++++++++++++++++++++++++++ README.md | 3 ++ 2 files changed, 76 insertions(+) create mode 100644 .github/workflows/scorecard.yml diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml new file mode 100644 index 00000000..d0437b90 --- /dev/null +++ b/.github/workflows/scorecard.yml @@ -0,0 +1,73 @@ +# This workflow uses actions that are not certified by GitHub. They are provided +# by a third-party and are governed by separate terms of service, privacy +# policy, and support documentation. + +name: Scorecard supply-chain security +on: + # For Branch-Protection check. Only the default branch is supported. See + # https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection + branch_protection_rule: + # To guarantee Maintained check is occasionally updated. See + # https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained + schedule: + - cron: '34 21 * * 2' + push: + branches: [ "main" ] + +# Declare default permissions as read only. +permissions: read-all + +jobs: + analysis: + name: Scorecard analysis + runs-on: ubuntu-latest + permissions: + # Needed to upload the results to code-scanning dashboard. + security-events: write + # Needed to publish results and get a badge (see publish_results below). + id-token: write + # Uncomment the permissions below if installing in a private repository. + # contents: read + # actions: read + + steps: + - name: "Checkout code" + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + persist-credentials: false + + - name: "Run analysis" + uses: ossf/scorecard-action@0864cf19026789058feabb7e87baa5f140aac736 # v2.3.1 + with: + results_file: results.sarif + results_format: sarif + # (Optional) "write" PAT token. Uncomment the `repo_token` line below if: + # - you want to enable the Branch-Protection check on a *public* repository, or + # - you are installing Scorecard on a *private* repository + # To create the PAT, follow the steps in https://github.com/ossf/scorecard-action?tab=readme-ov-file#authentication-with-fine-grained-pat-optional. + # repo_token: ${{ secrets.SCORECARD_TOKEN }} + + # Public repositories: + # - Publish results to OpenSSF REST API for easy access by consumers + # - Allows the repository to include the Scorecard badge. + # - See https://github.com/ossf/scorecard-action#publishing-results. + # For private repositories: + # - `publish_results` will always be set to `false`, regardless + # of the value entered here. + publish_results: true + + # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF + # format to the repository Actions tab. + - name: "Upload artifact" + uses: actions/upload-artifact@97a0fba1372883ab732affbe8f94b823f91727db # v3.pre.node20 + with: + name: SARIF file + path: results.sarif + retention-days: 5 + + # Upload the results to GitHub's code scanning dashboard (optional). + # Commenting out will disable upload of results to your repo's Code Scanning dashboard + - name: "Upload to code-scanning" + uses: github/codeql-action/upload-sarif@1b1aada464948af03b950897e5eb522f92603cc2 # v3.24.9 + with: + sarif_file: results.sarif diff --git a/README.md b/README.md index 05521f9c..a6c640cd 100644 --- a/README.md +++ b/README.md @@ -165,3 +165,6 @@ This project is under development. All source code and features on the main bran Coverity Scan Build Status + +# OpenSSF Scorecard +[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/intel-staging/libptpmgmt_iaclocklib/badge)](https://securityscorecards.dev/viewer/?uri=github.com/intel-staging/libptpmgmt_iaclocklib) From 1ccea76ffbb3a25875c435bba24ec30e55aef99e Mon Sep 17 00:00:00 2001 From: StepSecurity Bot Date: Fri, 29 Mar 2024 04:07:27 +0000 Subject: [PATCH 010/151] Apply security best practices 1. In GitHub action: - set permissions as read - add Harden Runner - use SHA commit id instead of version 2. Add codeql scanning Signed-off-by: StepSecurity Bot --- .github/workflows/build_gentoo.yml | 3 ++ .github/workflows/ci.yml | 3 ++ .github/workflows/codeql.yml | 78 ++++++++++++++++++++++++++++++ .github/workflows/coverity.yml | 9 +++- .github/workflows/doc.yml | 7 ++- .github/workflows/scorecard.yml | 5 ++ 6 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/codeql.yml diff --git a/.github/workflows/build_gentoo.yml b/.github/workflows/build_gentoo.yml index 53488895..0ab0a493 100644 --- a/.github/workflows/build_gentoo.yml +++ b/.github/workflows/build_gentoo.yml @@ -15,6 +15,9 @@ on: workflow_dispatch env: REGISTRY: ghcr.io +permissions: + contents: read + jobs: gentoo: runs-on: ubuntu-latest diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a5ad552f..c1496970 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,9 @@ on: [push, pull_request] env: USER: builder +permissions: + contents: read + jobs: ci: runs-on: ubuntu-latest diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 00000000..5f13ed90 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,78 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: ["main"] + pull_request: + # The branches below must be a subset of the branches above + branches: ["main"] + schedule: + - cron: "0 0 * * 1" + +permissions: + contents: read + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: ["cpp", "go", "python", "ruby"] + # CodeQL supports [ $supported-codeql-languages ] + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Harden Runner + uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0 + with: + egress-policy: audit + + - name: Checkout repository + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@a82bad71823183e5b120ab52d521460ecb0585fe # v2.24.9 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@a82bad71823183e5b120ab52d521460ecb0585fe # v2.24.9 + + # ℹ️ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@a82bad71823183e5b120ab52d521460ecb0585fe # v2.24.9 + with: + category: "/language:${{matrix.language}}" diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml index 4d097516..4eff9c9a 100644 --- a/.github/workflows/coverity.yml +++ b/.github/workflows/coverity.yml @@ -11,14 +11,19 @@ jobs: coverity: runs-on: ubuntu-latest steps: + - name: Harden Runner + uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0 + with: + egress-policy: audit + - name: Install dependencies run: sudo apt-get install -y swig libtool-bin - - uses: actions/checkout@v4 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: autoconf run: autoconf - name: configure run: ./configure - - uses: vapier/coverity-scan-action@v1 + - uses: vapier/coverity-scan-action@2068473c7bdf8c2fb984a6a40ae76ee7facd7a85 # v1.8.0 with: email: ${{ secrets.COVERITY_SCAN_EMAIL }} token: ${{ secrets.COVERITY_SCAN_TOKEN }} diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml index 668721d1..927ecfb1 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/doc.yml @@ -51,6 +51,11 @@ jobs: runs-on: ubuntu-latest steps: + - name: Harden Runner + uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0 + with: + egress-policy: audit + - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@v2 + uses: actions/deploy-pages@de14547edc9944350dc0481aa5b7afb08e75f254 # v2.0.5 diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml index d0437b90..e43eaa2b 100644 --- a/.github/workflows/scorecard.yml +++ b/.github/workflows/scorecard.yml @@ -31,6 +31,11 @@ jobs: # actions: read steps: + - name: Harden Runner + uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0 + with: + egress-policy: audit + - name: "Checkout code" uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: From 6517c19ac0035a628675ddb4def760f103647ed7 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Fri, 29 Mar 2024 13:37:07 +0800 Subject: [PATCH 011/151] Fix CodeQL build issue Replace autobuild command with proper build steps Signed-off-by: Song Yoong Siang --- .github/workflows/codeql.yml | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 5f13ed90..3c7a6a78 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -57,20 +57,14 @@ jobs: # By default, queries listed here will override any specified in a config file. # Prefix the list here with "+" to use these queries and those in the config file. - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@a82bad71823183e5b120ab52d521460ecb0585fe # v2.24.9 - - # ℹ️ Command-line programs to run using the OS shell. - # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun - - # If the Autobuild fails above, remove it and uncomment the following three lines. - # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. - - # - run: | - # echo "Run, Build Application using script" - # ./location_of_script_within_repo/buildscript.sh + - name: Install dependencies + run: sudo apt-get install -y swig libtool-bin + - name: autoconf + run: autoconf + - name: configure + run: ./configure + - name: build + run: make - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@a82bad71823183e5b120ab52d521460ecb0585fe # v2.24.9 From f6c8a1f90141e5903a9d0b994de3413ab9da1c6e Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Fri, 29 Mar 2024 14:09:55 +0800 Subject: [PATCH 012/151] temporary fix CI running issue Try to point to erezgeva container as we dint plan to create our own image. Signed-off-by: Song Yoong Siang --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c1496970..56459439 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,7 @@ jobs: names: [deb.trixie, deb.bookworm, rpmbuild, pacmanbuild, portage] fail-fast: false container: - image: ghcr.io/${{ github.repository_owner }}/${{ matrix.names }}:latest + image: ghcr.io/erezgeva/${{ matrix.names }}:latest env: GITHUB_CONTAINER: ${{ matrix.names }} @@ -60,7 +60,7 @@ jobs: names: [deb.trixie, deb.bookworm] fail-fast: false container: - image: ghcr.io/${{ github.repository_owner }}/${{ matrix.names }}:latest + image: ghcr.io/erezgeva/${{ matrix.names }}:latest steps: @@ -79,7 +79,7 @@ jobs: names: [deb.trixie, deb.bookworm, rpmbuild, pacmanbuild, portage] fail-fast: false container: - image: ghcr.io/${{ github.repository_owner }}/${{ matrix.names }}:latest + image: ghcr.io/erezgeva/${{ matrix.names }}:latest env: GITHUB_CONTAINER: ${{ matrix.names }} From f001d7c1bd812869ce840e72fce9ac81ff635fb9 Mon Sep 17 00:00:00 2001 From: Noor Azura Ahmad Tarmizi Date: Mon, 1 Apr 2024 11:33:59 -0400 Subject: [PATCH 013/151] Feature: Complete the connect msg path with timeout The connect message now will return the client session ID to the client. It will also have the timeout of 5 sec by default to receive the proxy reply. This could be change in the future. Signed-off-by: Noor Azura Ahmad Tarmizi --- jclklib/client/client_state.cpp | 6 ++++++ jclklib/client/client_state.hpp | 6 ++++-- jclklib/client/connect_msg.cpp | 3 +++ jclklib/client/connect_msg.hpp | 7 +++++++ jclklib/client/init.cpp | 25 ++++++++++++++++++++++++- jclklib/client/test.cpp | 28 ++++++++++++++++++++++++++-- jclklib/common/connect_msg.cpp | 6 ++++++ jclklib/common/util.hpp | 3 ++- 8 files changed, 78 insertions(+), 6 deletions(-) diff --git a/jclklib/client/client_state.cpp b/jclklib/client/client_state.cpp index ddd195cf..e3257919 100644 --- a/jclklib/client/client_state.cpp +++ b/jclklib/client/client_state.cpp @@ -1,10 +1,16 @@ #include +#include using namespace JClkLibClient; ClientState::ClientState() { connected = false; + sessionId = JClkLibCommon::InvalidSessionId; } +bool ClientState::get_connected() {return connected;} + +void ClientState::set_connected(bool new_state) {connected = new_state;} + ClientState JClkLibClient::state{}; diff --git a/jclklib/client/client_state.hpp b/jclklib/client/client_state.hpp index 121bcad9..c825afad 100644 --- a/jclklib/client/client_state.hpp +++ b/jclklib/client/client_state.hpp @@ -3,15 +3,17 @@ #include #include +#include namespace JClkLibClient { class ClientState { private: - bool connected; + std::atomic_bool connected; JClkLibCommon::sessionId_t sessionId; public: ClientState(); - DECLARE_ACCESSOR(connected); + bool get_connected(); + void set_connected(bool state); DECLARE_ACCESSOR(sessionId); }; diff --git a/jclklib/client/connect_msg.cpp b/jclklib/client/connect_msg.cpp index 23db1bf1..d777317e 100644 --- a/jclklib/client/connect_msg.cpp +++ b/jclklib/client/connect_msg.cpp @@ -68,5 +68,8 @@ PROCESS_MESSAGE_TYPE(ClientConnectMessage::processMessage) /*[TODO] client runtime shd return client ID to application - return client ID at least */ /*[Question] ACK_NONE is necessary ?*/ this->set_msgAck(ACK_NONE); + + cv.notify_one(); + return true; } diff --git a/jclklib/client/connect_msg.hpp b/jclklib/client/connect_msg.hpp index 3c1eeab0..7ca323d9 100644 --- a/jclklib/client/connect_msg.hpp +++ b/jclklib/client/connect_msg.hpp @@ -10,6 +10,8 @@ #include #include +#include +#include namespace JClkLibClient { @@ -17,7 +19,12 @@ namespace JClkLibClient virtual public ClientMessage { public: + ClientConnectMessage() : MESSAGE_CONNECT() {}; + + static std::mutex cv_mtx; + static std::condition_variable cv; + /** * @brief process the reply for connect msg from proxy. * @param LxContext client run-time transport listener context diff --git a/jclklib/client/init.cpp b/jclklib/client/init.cpp index 55014d73..b4cb78d3 100644 --- a/jclklib/client/init.cpp +++ b/jclklib/client/init.cpp @@ -10,13 +10,22 @@ #include #include #include +#include +#include +#include + +#define DEFAULT_CONNECT_TIME_OUT 5 //5 sec using namespace JClkLibClient; using namespace JClkLibCommon; using namespace std; +std::mutex ClientConnectMessage::cv_mtx; +std::condition_variable ClientConnectMessage::cv; + bool JClkLibClient::connect() { + unsigned int timeout_sec = (unsigned int) DEFAULT_CONNECT_TIME_OUT; Message0 connectMsg(new ClientConnectMessage()); BlockStopSignal(); @@ -33,7 +42,21 @@ bool JClkLibClient::connect() ClientMessageQueue::sendMessage(connectMsg.get()); // Wait for connection result - + auto endTime = std::chrono::system_clock::now() + std::chrono::seconds(timeout_sec); + std::unique_lock lck(ClientConnectMessage::cv_mtx); + while (state.get_connected() == false ) + { + auto res = ClientConnectMessage::cv.wait_until(lck, endTime); + if (res == std::cv_status::timeout) { + if (state.get_connected() == false) { + PrintDebug("[CONNECT] Connect reply from proxy - timeout failure!!"); + return false; + } + } + else { + PrintDebug("[CONNECT] Connect reply received."); + } + } return true; } diff --git a/jclklib/client/test.cpp b/jclklib/client/test.cpp index 78b997bc..bcc43304 100644 --- a/jclklib/client/test.cpp +++ b/jclklib/client/test.cpp @@ -8,14 +8,38 @@ #include "init.hpp" #include +#include +#include +#include +#include +#include using namespace JClkLibClient; +using namespace JClkLibCommon; using namespace std; int main() { - connect(); - sleep(1); + int ret = EXIT_SUCCESS; + // TODO + // JClkLibCommon::jcl_subscription sub; + + std::cout << "[CLIENT] Before connect : Session ID : " << state.get_sessionId() << "\n"; + + if (connect() == false) { + std::cout << "[CLIENT] Failure in connecting !!!\n"; + ret = EXIT_FAILURE; + goto do_exit; + } + else { + std::cout << "[CLIENT] Connected. Session ID : " << state.get_sessionId() << "\n"; + } + sleep(5); + // TODO + // subscribe(sub); + sleep(5); do_exit: disconnect(); + + return ret; } diff --git a/jclklib/common/connect_msg.cpp b/jclklib/common/connect_msg.cpp index a9cdc4be..589247af 100644 --- a/jclklib/common/connect_msg.cpp +++ b/jclklib/common/connect_msg.cpp @@ -26,6 +26,9 @@ PARSE_RXBUFFER_TYPE(CommonConnectMessage::parseBuffer) { if(!Message::parseBuffer(LxContext)) return false; + if (!PARSE_RX(FIELD, get_sessionId(), LxContext)) + return false; + if (!PARSE_RX(ARRAY,clientId, LxContext)) return false; @@ -39,6 +42,9 @@ BUILD_TXBUFFER_TYPE(CommonConnectMessage::makeBuffer) const if (!ret) return ret; + if (!WRITE_TX(FIELD, c_get_val_sessionId(), TxContext)) + return false; + if (!WRITE_TX(ARRAY,clientId,TxContext)) return false; diff --git a/jclklib/common/util.hpp b/jclklib/common/util.hpp index 14663a6c..9ff0b65c 100644 --- a/jclklib/common/util.hpp +++ b/jclklib/common/util.hpp @@ -26,7 +26,8 @@ bool isFutureSet(std::future &f) #define DECLARE_ACCESSOR(varname) \ const decltype(varname) &getc_##varname() { return varname; } \ decltype(varname) &get_##varname() { return varname; } \ - void set_##varname (const decltype(varname) &varname) { this->varname = varname; } + void set_##varname (const decltype(varname) &varname) { this->varname = varname; } \ + decltype(varname) c_get_val_##varname () const { return varname; } #define PTHREAD_CALL(func,err_msg,retval) \ { \ From 633a03df8b7262354aa46e3041fe64cc80be69e0 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Mon, 15 Apr 2024 14:05:03 +0800 Subject: [PATCH 014/151] Add new Github action for Virus Scan The virus scan will be run for every PR agaist master branch and whenever master branch got changes. Signed-off-by: Song Yoong Siang --- .github/workflows/virus_scan.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/virus_scan.yml diff --git a/.github/workflows/virus_scan.yml b/.github/workflows/virus_scan.yml new file mode 100644 index 00000000..35d4b330 --- /dev/null +++ b/.github/workflows/virus_scan.yml @@ -0,0 +1,25 @@ +# scan virus +name: "Virus Scan" + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + +permissions: + contents: read + +jobs: + job_id: + name: Scan Virus + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4.0.0 + with: + fetch-depth: 0 + - name: Scan Repository + uses: hugoalh/scan-virus-ghaction@v0.20.0 + with: + statistics_summary: True From b9bb4f26820247af4b8267d4f5d49d507e04091d Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Mon, 8 Apr 2024 15:04:08 +0800 Subject: [PATCH 015/151] Add new subscribe event Add two new subscribe events: 1. NOTIFY_PORT_STATE_NP 2. NOTIFY_ALL Signed-off-by: Song Yoong Siang --- src/proc.m4 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/proc.m4 b/src/proc.m4 index d3ef1d3e..312a6447 100644 --- a/src/proc.m4 +++ b/src/proc.m4 @@ -480,6 +480,10 @@ cnst_st() int NM(NOTIFY_TIME_SYNC) = 1; cnst_st() int NM(NOTIFY_PARENT_DATA_SET) = 2; /** Notify Common Mean Link Delay Information in SUBSCRIBE_EVENTS_NP.bitmask */ cnst_st() int NM(NOTIFY_CMLDS) = 3; +/** Notify NP parent state offset in SUBSCRIBE_EVENTS_NP.bitmask */ +cnst_st() int NM(NOTIFY_PORT_STATE_NP) = 4; +/** Notify all event in SUBSCRIBE_EVENTS_NP.bitmask */ +cnst_st() int NM(NOTIFY_ALL) = 5; /** Subscribe events TLV * @note linuxptp implementation specific */ From bdf06fb84d61d724a75bb3331c40781365e8385a Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Wed, 3 Apr 2024 14:40:03 +0800 Subject: [PATCH 016/151] Add connection between jclklib proxy and ptp4l Signed-off-by: Lai Peter Jun Ann --- jclklib/proxy/Makefile | 4 +- jclklib/proxy/connect.cpp | 296 ++++++++++++++++++++++++++++++++++++++ jclklib/proxy/connect.hpp | 12 ++ jclklib/proxy/main.cpp | 2 + 4 files changed, 312 insertions(+), 2 deletions(-) create mode 100644 jclklib/proxy/connect.cpp create mode 100644 jclklib/proxy/connect.hpp diff --git a/jclklib/proxy/Makefile b/jclklib/proxy/Makefile index 64cb3e4f..8f7dc5ee 100644 --- a/jclklib/proxy/Makefile +++ b/jclklib/proxy/Makefile @@ -8,9 +8,9 @@ JCLKLIB_PROXY_DIR := $(shell pwd) JCLKLIB_TOPLEVEL_DIR = $(JCLKLIB_PROXY_DIR)/.. JCLKLIB_COMMON_DIR = $(JCLKLIB_TOPLEVEL_DIR)/common -LIBS = pthread rt +LIBS = pthread rt ptpmgmt LIBS_FLAGS = $(foreach lib,$(LIBS),-l$(lib)) -OBJ = client main message msgq_tport notification_msg null_tport connect_msg subscribe_msg transport +OBJ = client main message msgq_tport notification_msg null_tport connect_msg subscribe_msg transport connect COMMON_OBJ = print sighandler transport msgq_tport jclklib_import message connect_msg OBJ_FILES = $(foreach f,$(OBJ),$(f).o) DEPENDS = $(foreach f,$(OBJ),$(f).d) diff --git a/jclklib/proxy/connect.cpp b/jclklib/proxy/connect.cpp new file mode 100644 index 00000000..59b9d87b --- /dev/null +++ b/jclklib/proxy/connect.cpp @@ -0,0 +1,296 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//TODO: subsription part +//#include "thread.hpp" +//#include "ptp4l_connect.hpp" + +using namespace std; +using namespace JClkLibProxy; +using namespace ptpmgmt; + +const int SUBSCRIBE_DURATION = 180; /* 3 minutes */ + +static const size_t bufSize = 2000; +static char buf[bufSize]; +static Init obj; +static Message &msg = obj.msg(); +static Message msgu; // TODO: to be removed +static SockBase *sk; +static unsigned int threshold; + +static std::string designated_iface; +static std::unique_ptr m_sk; + +struct port_info { + PortIdentity_t portid; + portState_e portState; + std::string interface; + int64_t master_offset; + bool local; +}; + +std::map ports; + +int epd; +struct epoll_event epd_event; +SUBSCRIBE_EVENTS_NP_t d; + +static inline portState_e normalize_state(portState_e state) +{ + switch(state) { + case PRE_TIME_TRANSMITTER: + case TIME_TRANSMITTER: + case UNCALIBRATED: + case TIME_RECEIVER: + return state; + default: + return DISABLED; + } +}; + +const port_info *designated_port_get() +{ + if(designated_iface.empty()) + return nullptr; + for(const auto &p : ports) { + const auto &port = p.second; + if(port.local && port.interface == designated_iface && + port.portState == TIME_RECEIVER) + return &p.second; + } + for(const auto &p : ports) { + const auto &port = p.second; + if(port.local && port.portState == TIME_RECEIVER) + return &p.second; + } + return nullptr; +} + +void handle(bool local) +{ + const BaseMngTlv *data = msg.getData(); + PORT_PROPERTIES_NP_t *pp; + PORT_DATA_SET_t *pd; + portState_e portState; + switch(msg.getTlvId()) { + case PORT_PROPERTIES_NP: + pp = (PORT_PROPERTIES_NP_t *)data; + if(local || TS_SOFTWARE != pp->timestamping) { + // create or update + port_info &pi = ports[pp->portIdentity]; + pi.portid = pp->portIdentity; + pi.portState = normalize_state(pp->portState); + pi.interface = pp->interface.textField; + pi.local = local; + } + return; + case PORT_DATA_SET: + pd = (PORT_DATA_SET_t *)data; + portState = normalize_state(pd->portState); + if(ports.count(pd->portIdentity) > 0) { + port_info &pi = ports[pd->portIdentity]; + if(pi.portState == portState) + return; + pi.portState = portState; + printf("port %s (%s) changed state\n", + pd->portIdentity.string().c_str(), pi.interface.c_str()); + } else + return; + break; + case TIME_STATUS_NP: + if(ports.count(msg.getPeer()) > 0) { + port_info &pi = ports[msg.getPeer()]; + if(pi.portState != TIME_RECEIVER) + return; + pi.master_offset = ((TIME_STATUS_NP_t *)data)->master_offset; + } else { + printf("received time sync data for unknown port %s\n", + msg.getPeer().string().c_str()); + return; + } + break; + default: + return; + } + const port_info *port = designated_port_get(); + if(port != nullptr) { + if(llabs(port->master_offset) > threshold) { + printf("port %s (%s) offset %10jd under threshold %d", + port->portid.string().c_str(), port->interface.c_str(), + port->master_offset, threshold); + return; + } + return; + } + for(const auto &p : ports) { + const auto &port = p.second; + if(port.portState == TIME_RECEIVER) { + if(llabs(port.master_offset) > threshold) { + printf("port %s (%s) offset %10jd under threshold %d", + port.portid.string().c_str(), port.interface.c_str(), + port.master_offset, threshold); + return; + } + } + } +} + +static inline bool sendAction(bool local) +{ + static int seq = 0; + Message *m; + if(local) + m = &msgu; + else + m = &msg; + MNG_PARSE_ERROR_e err = m->build(buf, bufSize, seq); + if(err != MNG_PARSE_ERROR_OK) { + fprintf(stderr, "build error %s\n", msgu.err2str_c(err)); + return false; + } + bool ret; + if(!local) + ret = sk->send(buf, m->getMsgLen()); + + if(!ret) { + fprintf(stderr, "send failed\n"); + return false; + } + seq++; + return true; +} +static inline bool sendGet(bool local, mng_vals_e id) +{ + bool ret; + if(local) + ret = msgu.setAction(GET, id); + else + ret = msg.setAction(GET, id); + if(!ret) { + fprintf(stderr, "Fail get %s\n", msg.mng2str_c(id)); + return false; + } + return sendAction(local); +} + +//TODO: subscription part +//bool send_subscription(struct jcl_handle *handle) +bool send_subscription() +{ + memset(d.bitmask, 0, sizeof d.bitmask); + d.duration = SUBSCRIBE_DURATION; + d.setEvent(NOTIFY_PORT_STATE); + d.setEvent(NOTIFY_TIME_SYNC); + + //TODO: subscription part +/* struct jcl_subscription subscription; + subscription.event = jcl_offset_threshold_flag | jcl_peer_present_flag; + subscription.threshold.offset = 100; + handle->subscription = subscription; +*/ + if(!msg.setAction(SET, SUBSCRIBE_EVENTS_NP, &d)) { + fprintf(stderr, "Fail set SUBSCRIBE_EVENTS_NP\n"); + return false; + } + bool ret = sendAction(false); + msg.clearData(); // Remove referance to local SUBSCRIBE_EVENTS_NP_t + return ret; +} + +void *loop( void *arg) +//static void loop(void) +{ + const uint64_t timeout_ms = 1000; // 1 second + for(;;) { + if(!sendGet(true, PORT_PROPERTIES_NP)) + break; + ssize_t cnt; + + sk->poll(timeout_ms); + cnt = sk->rcv(buf, bufSize); + + if(cnt > 0) { + MNG_PARSE_ERROR_e err = msg.parse(buf, cnt); + if(err == MNG_PARSE_ERROR_OK) { + handle(true); + break; + } + } + } + // Send to all + sendGet(false, PORT_PROPERTIES_NP); + send_subscription(); + + while (1) { + if (epoll_wait( epd, &epd_event, 1, 100) != -1) { + //if ( sk->poll(timeout_ms)) { + const auto cnt = sk->rcv(buf, bufSize); + MNG_PARSE_ERROR_e err = msg.parse(buf, cnt); + if(err == MNG_PARSE_ERROR_OK) + handle(false); + } + } +} + +int Connect::connect() +{ + // Ensure we recieve reply from local ptp daemon + MsgParams prms = msg.getParams(); + prms.boundaryHops = 0; + + std::string interface; + std::unique_ptr m_sk; + std::string uds_address; + + //TODO: hard-coded the interface + interface = "enp1s0"; + SockUnix *sku = new SockUnix; + if(sku == nullptr) { + return -1; + } + m_sk.reset(sku); + + //TODO: hard-coded uds_socket + uds_address = "/var/run/ptp4l"; + if(!sku->setDefSelfAddress() || !sku->init() || + !sku->setPeerAddress(uds_address)) + return -1; + pid_t pid = getpid(); + prms.self_id.clockIdentity.v[6] = (pid >> 24) && 0xff; + prms.self_id.clockIdentity.v[7] = (pid >> 16) && 0xff; + prms.self_id.portNumber = pid & 0xffff; + + sk = m_sk.get(); + + msgu.updateParams(prms); + + int ret; + epd = epoll_create1( 0); + if( epd == -1) { + ret = -errno; + printf("epoll create failed"); + } + + epd_event.data.fd = sk->fileno(); + epd_event.events = ( EPOLLIN | EPOLLERR); + if( epoll_ctl( epd, EPOLL_CTL_ADD, sk->fileno(), &epd_event) == 1) { + ret = -errno; + printf("epoll ctl failed"); + } + + //TODO: subscription part + //jcl_handle_connect( NULL, epd_event); + + //TODO: to be removed, for testing purpose + loop(NULL); + return 0; +} diff --git a/jclklib/proxy/connect.hpp b/jclklib/proxy/connect.hpp new file mode 100644 index 00000000..d75ac9b2 --- /dev/null +++ b/jclklib/proxy/connect.hpp @@ -0,0 +1,12 @@ +#include +#include + +namespace JClkLibProxy +{ + class Connect + { + private: + public: + static int connect(); + }; +} \ No newline at end of file diff --git a/jclklib/proxy/main.cpp b/jclklib/proxy/main.cpp index 93b72db2..056e0fbf 100644 --- a/jclklib/proxy/main.cpp +++ b/jclklib/proxy/main.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -19,6 +20,7 @@ using namespace std; int main() { BlockStopSignal(); + Connect::connect(); if(!ProxyTransport::init()) { cout << "Transport init failed" << endl; return -1; From 7365c8a900e850e283db66180edd56095e837e02 Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Wed, 3 Apr 2024 15:25:57 +0800 Subject: [PATCH 017/151] Add thread for ptp4l event subscription and notification Signed-off-by: Lai Peter Jun Ann --- jclklib/proxy/Makefile | 2 +- jclklib/proxy/connect.cpp | 259 +++++++++++-------------- jclklib/proxy/connect.hpp | 13 +- jclklib/proxy/main.cpp | 4 +- jclklib/proxy/thread.cpp | 384 ++++++++++++++++++++++++++++++++++++++ jclklib/proxy/thread.hpp | 122 ++++++++++++ 6 files changed, 633 insertions(+), 151 deletions(-) create mode 100644 jclklib/proxy/thread.cpp create mode 100644 jclklib/proxy/thread.hpp diff --git a/jclklib/proxy/Makefile b/jclklib/proxy/Makefile index 8f7dc5ee..21d67da9 100644 --- a/jclklib/proxy/Makefile +++ b/jclklib/proxy/Makefile @@ -10,7 +10,7 @@ JCLKLIB_TOPLEVEL_DIR = $(JCLKLIB_PROXY_DIR)/.. JCLKLIB_COMMON_DIR = $(JCLKLIB_TOPLEVEL_DIR)/common LIBS = pthread rt ptpmgmt LIBS_FLAGS = $(foreach lib,$(LIBS),-l$(lib)) -OBJ = client main message msgq_tport notification_msg null_tport connect_msg subscribe_msg transport connect +OBJ = client main message msgq_tport notification_msg null_tport connect_msg subscribe_msg transport connect thread COMMON_OBJ = print sighandler transport msgq_tport jclklib_import message connect_msg OBJ_FILES = $(foreach f,$(OBJ),$(f).o) DEPENDS = $(foreach f,$(OBJ),$(f).d) diff --git a/jclklib/proxy/connect.cpp b/jclklib/proxy/connect.cpp index 59b9d87b..af6445f2 100644 --- a/jclklib/proxy/connect.cpp +++ b/jclklib/proxy/connect.cpp @@ -1,3 +1,10 @@ +/*! \file connect.cpp + \brief Proxy connect message class. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Lai Peter Jun Ann +*/ + #include #include #include @@ -10,8 +17,7 @@ #include //TODO: subsription part -//#include "thread.hpp" -//#include "ptp4l_connect.hpp" +#include "thread.hpp" using namespace std; using namespace JClkLibProxy; @@ -25,128 +31,59 @@ static Init obj; static Message &msg = obj.msg(); static Message msgu; // TODO: to be removed static SockBase *sk; -static unsigned int threshold; -static std::string designated_iface; static std::unique_ptr m_sk; struct port_info { PortIdentity_t portid; - portState_e portState; std::string interface; int64_t master_offset; bool local; }; -std::map ports; +struct ptp_event { + int64_t master_offset; + ClockIdentity_t gmIdentity; /**< Grandmaster clock ID */ + Integer32_t asCapable; /**< Flag for 802@.1AS Capable */ + int64_t servo_state; +}; int epd; struct epoll_event epd_event; SUBSCRIBE_EVENTS_NP_t d; +ptp_event pe; -static inline portState_e normalize_state(portState_e state) +void event_handle() { - switch(state) { - case PRE_TIME_TRANSMITTER: - case TIME_TRANSMITTER: - case UNCALIBRATED: - case TIME_RECEIVER: - return state; - default: - return DISABLED; - } -}; + const BaseMngTlv *data = msg.getData(); + int64_t offset; + ClockIdentity_t gm_uuid; + int64_t servo; + switch(msg.getTlvId()) { + case TIME_STATUS_NP: + offset = ((TIME_STATUS_NP_t *)data)->master_offset; + servo = ((TIME_STATUS_NP_t *)data)->servo_state; + gm_uuid = ((TIME_STATUS_NP_t *)data)->gmIdentity; -const port_info *designated_port_get() -{ - if(designated_iface.empty()) - return nullptr; - for(const auto &p : ports) { - const auto &port = p.second; - if(port.local && port.interface == designated_iface && - port.portState == TIME_RECEIVER) - return &p.second; - } - for(const auto &p : ports) { - const auto &port = p.second; - if(port.local && port.portState == TIME_RECEIVER) - return &p.second; - } - return nullptr; -} + pe.master_offset = offset; + pe.servo_state = servo; + pe.gmIdentity = gm_uuid; -void handle(bool local) -{ - const BaseMngTlv *data = msg.getData(); - PORT_PROPERTIES_NP_t *pp; - PORT_DATA_SET_t *pd; - portState_e portState; - switch(msg.getTlvId()) { - case PORT_PROPERTIES_NP: - pp = (PORT_PROPERTIES_NP_t *)data; - if(local || TS_SOFTWARE != pp->timestamping) { - // create or update - port_info &pi = ports[pp->portIdentity]; - pi.portid = pp->portIdentity; - pi.portState = normalize_state(pp->portState); - pi.interface = pp->interface.textField; - pi.local = local; - } + //TODO: Add debug flag checking, only print if the flag is set + printf("master_offset = %ld, servo_state = %ld, gmIdentity = %lx\n\n", pe.master_offset, pe.servo_state, pe.gmIdentity); + return; + case PORT_DATA_SET_NP: + pe.asCapable = ((PORT_DATA_SET_NP_t *)data)->asCapable; + printf("asCapable = %d\n\n", pe.asCapable); return; - case PORT_DATA_SET: - pd = (PORT_DATA_SET_t *)data; - portState = normalize_state(pd->portState); - if(ports.count(pd->portIdentity) > 0) { - port_info &pi = ports[pd->portIdentity]; - if(pi.portState == portState) - return; - pi.portState = portState; - printf("port %s (%s) changed state\n", - pd->portIdentity.string().c_str(), pi.interface.c_str()); - } else - return; - break; - case TIME_STATUS_NP: - if(ports.count(msg.getPeer()) > 0) { - port_info &pi = ports[msg.getPeer()]; - if(pi.portState != TIME_RECEIVER) - return; - pi.master_offset = ((TIME_STATUS_NP_t *)data)->master_offset; - } else { - printf("received time sync data for unknown port %s\n", - msg.getPeer().string().c_str()); - return; - } - break; default: - return; - } - const port_info *port = designated_port_get(); - if(port != nullptr) { - if(llabs(port->master_offset) > threshold) { - printf("port %s (%s) offset %10jd under threshold %d", - port->portid.string().c_str(), port->interface.c_str(), - port->master_offset, threshold); return; - } - return; - } - for(const auto &p : ports) { - const auto &port = p.second; - if(port.portState == TIME_RECEIVER) { - if(llabs(port.master_offset) > threshold) { - printf("port %s (%s) offset %10jd under threshold %d", - port.portid.string().c_str(), port.interface.c_str(), - port.master_offset, threshold); - return; - } - } } } -static inline bool sendAction(bool local) +static inline bool msg_send(bool local) { - static int seq = 0; + static int seq = 0; Message *m; if(local) m = &msgu; @@ -158,19 +95,18 @@ static inline bool sendAction(bool local) return false; } bool ret; - if(!local) - ret = sk->send(buf, m->getMsgLen()); - + ret = sk->send(buf, m->getMsgLen()); + if(!ret) { - fprintf(stderr, "send failed\n"); + //fprintf(stderr, "send failed\n"); return false; } seq++; return true; } -static inline bool sendGet(bool local, mng_vals_e id) +static inline bool msg_set_action(bool local, mng_vals_e id) { - bool ret; + bool ret; if(local) ret = msgu.setAction(GET, id); else @@ -179,40 +115,64 @@ static inline bool sendGet(bool local, mng_vals_e id) fprintf(stderr, "Fail get %s\n", msg.mng2str_c(id)); return false; } - return sendAction(local); + return msg_send(local); } -//TODO: subscription part -//bool send_subscription(struct jcl_handle *handle) -bool send_subscription() +/** + * @brief Subscribes to a set of PTP (Precision Time Protocol) events. + * + * This function configures a subscription to various PTP events by setting the appropriate + * bitmask in a subscription data structure. It then sends an action to subscribe to these + * events using a message handling system. The function clears the message data after sending + * the action to avoid referencing local data that may go out of scope. + * + * @param handle A double pointer to a jcl_handle structure representing the handle to be used + * for the subscription. The actual usage of this parameter is not shown in the + * provided code snippet, so it may need to be implemented or removed. + * @return A boolean value indicating the success of the subscription action. + * Returns true if the subscription action is successfully sent, false otherwise. + * + */ +bool event_subscription(struct jcl_handle **handle) { memset(d.bitmask, 0, sizeof d.bitmask); d.duration = SUBSCRIBE_DURATION; - d.setEvent(NOTIFY_PORT_STATE); - d.setEvent(NOTIFY_TIME_SYNC); + d.setEvent(NOTIFY_TIME_SYNC); + d.setEvent(NOTIFY_PORT_STATE_NP); - //TODO: subscription part -/* struct jcl_subscription subscription; - subscription.event = jcl_offset_threshold_flag | jcl_peer_present_flag; - subscription.threshold.offset = 100; - handle->subscription = subscription; -*/ if(!msg.setAction(SET, SUBSCRIBE_EVENTS_NP, &d)) { fprintf(stderr, "Fail set SUBSCRIBE_EVENTS_NP\n"); return false; } - bool ret = sendAction(false); + bool ret = msg_send(false); msg.clearData(); // Remove referance to local SUBSCRIBE_EVENTS_NP_t return ret; } -void *loop( void *arg) -//static void loop(void) +/** + * @brief Runs the main event loop for handling PTP (Precision Time Protocol) events. + * + * This function enters an infinite loop, where it sends a GET request with the intention + * of receiving a reply from the local PTP daemon. If the GET request is successful, it + * waits for incoming messages with a timeout and processes them if received. The loop + * terminates if a message is successfully handled. After breaking out of the first loop, + * the function sends a GET request to all destinations and enters a second infinite loop + * to handle asynchronous events using epoll. + * + * @param arg A void pointer to an argument that can be passed to the function. The actual + * type and content of this argument should be defined by the user and cast + * appropriately within the function. + * @return This function does not return a value. If a return value is needed, the function + * signature and implementation should be modified accordingly. + * + */ +void *ptp4l_event_loop( void *arg) { const uint64_t timeout_ms = 1000; // 1 second - for(;;) { - if(!sendGet(true, PORT_PROPERTIES_NP)) - break; + + for(;;) { + if(!msg_set_action(true, PORT_PROPERTIES_NP)) + break; ssize_t cnt; sk->poll(timeout_ms); @@ -221,14 +181,15 @@ void *loop( void *arg) if(cnt > 0) { MNG_PARSE_ERROR_e err = msg.parse(buf, cnt); if(err == MNG_PARSE_ERROR_OK) { - handle(true); + event_handle(); break; } } } + // Send to all - sendGet(false, PORT_PROPERTIES_NP); - send_subscription(); + msg_set_action(false, PORT_PROPERTIES_NP); + event_subscription(NULL); while (1) { if (epoll_wait( epd, &epd_event, 1, 100) != -1) { @@ -236,29 +197,40 @@ void *loop( void *arg) const auto cnt = sk->rcv(buf, bufSize); MNG_PARSE_ERROR_e err = msg.parse(buf, cnt); if(err == MNG_PARSE_ERROR_OK) - handle(false); + event_handle(); } } } +/** @brief Establishes a connection to the local PTP (Precision Time Protocol) daemon. + * + * This method initializes a Unix socket connection to the local PTP daemon. It sets up + * the message parameters, including the boundary hops and the process ID as part of the + * clock identity. It also configures the epoll instance to monitor the socket for incoming + * data or errors. + * + * @return An integer indicating the status of the connection attempt. + * Returns 0 on success, or -1 if an error occurs during socket initialization, + * address setting, or epoll configuration. + */ int Connect::connect() { // Ensure we recieve reply from local ptp daemon MsgParams prms = msg.getParams(); prms.boundaryHops = 0; - + std::string interface; std::unique_ptr m_sk; std::string uds_address; //TODO: hard-coded the interface - interface = "enp1s0"; + interface = "enp1s0"; SockUnix *sku = new SockUnix; if(sku == nullptr) { return -1; } m_sk.reset(sku); - + //TODO: hard-coded uds_socket uds_address = "/var/run/ptp4l"; if(!sku->setDefSelfAddress() || !sku->init() || @@ -275,22 +247,19 @@ int Connect::connect() int ret; epd = epoll_create1( 0); - if( epd == -1) { - ret = -errno; - printf("epoll create failed"); - } - - epd_event.data.fd = sk->fileno(); - epd_event.events = ( EPOLLIN | EPOLLERR); - if( epoll_ctl( epd, EPOLL_CTL_ADD, sk->fileno(), &epd_event) == 1) { - ret = -errno; - printf("epoll ctl failed"); - } - + if( epd == -1) + ret = -errno; + + epd_event.data.fd = sk->fileno(); + epd_event.events = ( EPOLLIN | EPOLLERR); + if( epoll_ctl( epd, EPOLL_CTL_ADD, sk->fileno(), &epd_event) == 1) + ret = -errno; + //TODO: subscription part - //jcl_handle_connect( NULL, epd_event); + handle_connect( NULL, epd_event); + while (1) { + sleep(1); + } - //TODO: to be removed, for testing purpose - loop(NULL); return 0; } diff --git a/jclklib/proxy/connect.hpp b/jclklib/proxy/connect.hpp index d75ac9b2..ed206a28 100644 --- a/jclklib/proxy/connect.hpp +++ b/jclklib/proxy/connect.hpp @@ -1,11 +1,18 @@ +/*! \file connect.hpp + \brief Proxy connect message class. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Lai Peter Jun Ann +*/ + #include #include namespace JClkLibProxy { - class Connect - { - private: + class Connect + { + private: public: static int connect(); }; diff --git a/jclklib/proxy/main.cpp b/jclklib/proxy/main.cpp index 056e0fbf..9699831e 100644 --- a/jclklib/proxy/main.cpp +++ b/jclklib/proxy/main.cpp @@ -19,8 +19,7 @@ using namespace std; int main() { - BlockStopSignal(); - Connect::connect(); + //BlockStopSignal(); if(!ProxyTransport::init()) { cout << "Transport init failed" << endl; return -1; @@ -29,6 +28,7 @@ int main() cout << "Message init failed" << endl; return -1; } + Connect::connect(); WaitForStopSignal(); PrintDebug("Got stop signal"); if(!ProxyTransport::stop()) { diff --git a/jclklib/proxy/thread.cpp b/jclklib/proxy/thread.cpp new file mode 100644 index 00000000..2c99bdc7 --- /dev/null +++ b/jclklib/proxy/thread.cpp @@ -0,0 +1,384 @@ +/*! \file thread.cpp + \brief Proxy message thread class. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Lai Peter Jun Ann +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "thread.hpp" +//#include "ptp4l_connect.hpp" + +using namespace ptpmgmt; + +#define MSEC_PER_SEC (1000) +#define USEC_PER_SEC (1000000) +#define NSEC_PER_SEC (1000000000) +#define NSEC_PER_USEC (NSEC_PER_SEC/USEC_PER_SEC) +#define USEC_PER_MSEC (USEC_PER_SEC/MSEC_PER_SEC) + +int initialize_thread_signal( struct thread_signal **psignal) +{ + struct thread_signal *signal; + pthread_condattr_t signal_attr; + pthread_mutexattr_t siglock_attr; + int err, ret; + + signal = ( typeof( signal)) malloc(( size_t) sizeof( *signal)); + if( signal == NULL) { + ret = errno; + goto allocate_fail; + } + + if(( ret = pthread_mutexattr_init( &siglock_attr)) != 0) + goto mutexattr_fail; + if(( ret = pthread_condattr_init( &signal_attr)) != 0) + goto condattr_fail; + + if(( ret = pthread_mutex_init + ( &signal->siglock, &siglock_attr)) != 0 ) { + goto fail; + } + if(( ret = pthread_cond_init + ( &signal->signal, &signal_attr)) != 0 ) { + goto fail; + } + + fail: + if(( err = pthread_condattr_destroy( &signal_attr)) != 0) + ret = ret == 0 ? err : ret; // Report first error only + condattr_fail: + if(( err = pthread_mutexattr_destroy( &siglock_attr)) != 0) + ret = ret == 0 ? err : ret; // Report first error only + mutexattr_fail: + allocate_fail: + + if( ret == 0) { + signal->signaled = false; + *psignal = signal; + } else { + free(signal); + } + + return -ret; +} + +int wait_thread_signal( struct thread_signal *signal, unsigned timeout ) +{ + struct timespec abs_timeout; + int err, ret; + + clock_gettime( CLOCK_REALTIME, &abs_timeout); + abs_timeout.tv_nsec += (timeout % USEC_PER_SEC) * NSEC_PER_USEC; + abs_timeout.tv_sec += abs_timeout.tv_nsec / NSEC_PER_SEC; + abs_timeout.tv_nsec %= NSEC_PER_SEC; + abs_timeout.tv_sec += timeout / USEC_PER_SEC; + + if(( ret = pthread_mutex_lock( &signal->siglock)) != 0) + goto lock_fail; + while( !signal->signaled) { + if(( ret = pthread_cond_timedwait + ( &signal->signal, &signal->siglock, &abs_timeout )) != 0) { + break; + } + } + if( ret == 0) + signal->signaled = false; + + if(( err = pthread_mutex_unlock( &signal->siglock)) != 0) + ret = ret == 0 ? err : ret; // Report first error only + + lock_fail: + return -ret; +} + +static bool check_for_events( struct jcl_handle *handle) +{ + int i; + + for( i = 0; i < jcl_event_count; ++i) { + if( handle->event_count[i] != 0) + return true; + } + + return false; +} + +static int check_status( struct jcl_handle *handle, + unsigned *event_count, struct jcl_state *state, bool *done) +{ + int ret; + + *done = false; + if(( ret = -pthread_mutex_lock( &handle->state_lock)) < 0) + goto lock_failed; + if( check_for_events( handle)) { + *state = handle->state; + memcpy( event_count, handle->event_count, sizeof( handle->event_count)); + *done = true; + } + ret = -pthread_mutex_unlock( &handle->state_lock); + + lock_failed: + return ret; +} + +int handle_status_wait( struct jcl_handle *handle, unsigned timeout, + unsigned *event_count, struct jcl_state *state ) +{ + bool done; + int ret; + + if(( ret = check_status( handle, event_count, state, &done)) < 0 || done || timeout == 0) + goto do_exit; + + if(( ret = wait_thread_signal( handle->status_signal, timeout)) < 0) + goto do_exit; + + ret = check_status( handle, event_count, state, &done); + + do_exit: + return ret; +} + +static int start_work_thread( struct ptp4l_handle *handle ) +{ + int ret; + + if(( ret = initialize_thread_signal( &handle->init_signal)) < 0) + goto init_signal_failed; + if(( ret = initialize_thread_signal( &handle->exit_signal)) < 0) + goto exit_signal_failed; + + if(( ret = -pthread_create( &handle->work_thread, NULL, ptp4l_event_loop, (void *) handle)) < 0) + return ret; + +// if(( ret = wait_thread_signal( handle->init_signal, 30000)) < 0) { +// PTP4L_CONNECT_TIMEOUT*USEC_PER_MSEC)) < 0) +// goto start_wait_failed; +// } + return 0; + +// start_wait_failed: +// stop_work_thread( handle); +// free_thread_signal( handle->exit_signal); + exit_signal_failed: +// free_thread_signal( handle->init_signal); + init_signal_failed: + return ret; +} + +int connect_ptp4l( struct ptp4l_handle **phandle, struct epoll_event epd_event, state_update_t update_cb, void *ctx) +{ + struct ptp4l_handle *handle; + int ret; + char *path; + + handle = (typeof( handle)) malloc(( size_t) sizeof(*handle)); + if( handle == NULL) { + ret = -errno; + goto alloc_handle_fail; + } + + memset( &handle->server_addr, 0, sizeof( handle->server_addr)); + handle->server_addr.sun_family = AF_LOCAL; + + //TODO: hard-coded for now + path = "/var/run/ptp4l"; + strncpy( handle->server_addr.sun_path, path, + sizeof( handle->server_addr.sun_path ) - 1); + + //subscribe event + handle->epd_event = epd_event; + handle->ptp4l_sock = epd_event.data.fd; + + handle->update_cb = update_cb; + handle->ctx = ctx; + handle->pid = getpid(); + + if(( ret = start_work_thread( handle)) < 0) + goto thread_failed; + + *phandle = handle; + return 0; + + thread_failed: + alloc_handle_fail: + return ret; +} + +int set_thread_signal( struct thread_signal *signal) +{ + int err, ret; + + if(( ret = pthread_mutex_lock( &signal->siglock)) != 0) + goto lock_fail; + signal->signaled = true; + if(( ret = pthread_cond_signal( &signal->signal )) != 0) + goto signal_fail; + + signal_fail: + if(( err = pthread_mutex_unlock( &signal->siglock)) != 0) + ret = ret == 0 ? err : ret; // Report first error only + + lock_fail: + return -ret; +} + +static bool state_update_callback( struct ptp4l_state *state, void * ctx) +{ + struct jcl_handle *handle = (typeof(handle)) ctx; + bool generate_signal = false; + int ret; + + if(( ret = -pthread_mutex_lock( &handle->state_lock)) < 0) + goto lock_failed; + + // TODO: update the state based on the event notification + //generate_signal = update_offset( handle, state) || generate_signal ? true : false; + //generate_signal = update_peer_present( handle, state) || generate_signal ? true : false; + //generate_signal = update_gm_present( handle, state) || generate_signal ? true : false; + //generate_signal = update_servo_locked( handle, state) || generate_signal ? true : false; + + generate_signal = handle->ptp4l_state_initialized ? generate_signal : false; + handle->ptp4l_state_initialized = state->initialized; + + if(( ret = -pthread_mutex_unlock( &handle->state_lock)) < 0) + goto unlock_failed; + + if( generate_signal) + set_thread_signal( handle->status_signal); + + unlock_failed: + lock_failed: + return ret >= 0 ? true : false; +} + +int init_thread_signal( struct thread_signal **psignal) +{ + struct thread_signal *signal; + pthread_condattr_t signal_attr; + pthread_mutexattr_t siglock_attr; + int err, ret; + + signal = ( typeof( signal)) malloc(( size_t) sizeof( *signal)); + if( signal == NULL) { + ret = errno; + goto allocate_fail; + } + + if(( ret = pthread_mutexattr_init( &siglock_attr)) != 0) + goto mutexattr_fail; + if(( ret = pthread_condattr_init( &signal_attr)) != 0) + goto condattr_fail; + + if(( ret = pthread_mutex_init + ( &signal->siglock, &siglock_attr)) != 0 ) { + goto fail; + } + if(( ret = pthread_cond_init + ( &signal->signal, &signal_attr)) != 0 ) { + goto fail; + } + + fail: + if(( err = pthread_condattr_destroy( &signal_attr)) != 0) + ret = ret == 0 ? err : ret; // Report first error only + condattr_fail: + if(( err = pthread_mutexattr_destroy( &siglock_attr)) != 0) + ret = ret == 0 ? err : ret; // Report first error only + mutexattr_fail: + allocate_fail: + if( ret == 0) { + signal->signaled = false; + *psignal = signal; + } else { + free(signal); + } + + return -ret; +} + +int free_thread_signal( struct thread_signal *signal) +{ + int err, ret; + + ret = pthread_mutex_destroy( &signal->siglock); + if(( err = pthread_cond_destroy( &signal->signal)) != 0 ) + ret = ret == 0 ? err : ret; // Report first error only + + free(signal); + + return -ret; +} + +/** + * @brief Initializes and connects a handle for PTP (Precision Time Protocol) event handling. + * + * This function allocates and initializes a jcl_handle structure, sets up thread signaling, + * mutexes, and subscribes to PTP events. It also initiates a connection to ptp4l and enters + * a loop to wait for and handle status updates. + * + * @param phandle A double pointer to a jcl_handle structure where the initialized handle will + * be stored. + * @param epd_event An epoll_event structure containing the event data used for the connection. + * @return An integer indicating the status of the connection attempt. + * Returns 0 on success, or a negative error code on failure. + * + */ +int handle_connect( struct jcl_handle **phandle, struct epoll_event epd_event ) +{ + struct jcl_handle *handle; + int ret; + + handle = ( typeof( handle)) malloc(( size_t) sizeof( *handle)); + if( handle == NULL) { + ret = -errno; + goto alloc_fail; + } + + if(( ret = init_thread_signal( &handle->status_signal)) < 0) + goto status_signal_fail; + + if(( ret = -pthread_mutex_init( &handle->state_lock, NULL)) < 0) + goto state_lock_fail; + + //handle_init start + handle->state.peer_present = false; + handle->state.offset = UINT_MAX; + handle->subscription.event = 0; + memset( handle->event_count, 0, sizeof( handle->event_count)); + + event_subscription( &handle ); + + connect_ptp4l( &handle->ptp4l_handle, + epd_event, state_update_callback, handle); + + //TODO: wait operation + unsigned event_count[1000]; + int iter; + iter = 100; + while (iter > 0) { + handle_status_wait( handle, 1000, handle->event_count, &handle->state ); + --iter; + } + + return 0; + + state_lock_fail: + free_thread_signal( handle->status_signal); + status_signal_fail: + alloc_fail: + return ret; +} + diff --git a/jclklib/proxy/thread.hpp b/jclklib/proxy/thread.hpp new file mode 100644 index 00000000..313df156 --- /dev/null +++ b/jclklib/proxy/thread.hpp @@ -0,0 +1,122 @@ +/*! \file thread.hpp + \brief Proxy message thread class. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + Author: Lai Peter Jun Ann +*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +typedef struct thread_signal *thread_signal_t; +typedef struct ptp4l_handle *ptp4l_handle_t; +typedef struct jcl_handle *jcl_handle_t; + +struct thread_signal { + pthread_mutex_t siglock; + pthread_cond_t signal; + bool signaled; +}; + +struct jcl_state +{ + bool peer_present; + bool gm_present; + unsigned offset; + bool servo_locked; +}; + +struct jcl_threshold +{ + unsigned offset; /* ns */ +}; + +struct jcl_subscription +{ + unsigned event; + struct jcl_threshold threshold; +}; + +struct jcl_handle +{ + clockid_t clk_id; + + ptp4l_handle_t ptp4l_handle; + bool ptp4l_state_initialized; + + thread_signal_t status_signal; + pthread_mutex_t state_lock; + unsigned event_count[4]; //jcl_event_count + struct jcl_subscription subscription; + struct jcl_state state; +}; + +typedef enum { jcl_peer_present, jcl_gm_present, jcl_offset_threshold, jcl_servo_locked, + jcl_event_count,} + jcl_event_t; + +#define jcl_servo_locked_flag ( 0x1 << jcl_gm_present) +#define jcl_gm_present_flag ( 0x1 << jcl_gm_present) +#define jcl_peer_present_flag ( 0x1 << jcl_peer_present) +#define jcl_offset_threshold_flag ( 0x1 << jcl_offset_threshold) + +typedef bool ( *state_update_t)( struct ptp4l_state *, void *); +typedef struct thread_signal *thread_signal_t; + +int handle_connect( jcl_handle_t *handle, struct epoll_event epd_event ); +int connect_ptp4l( ptp4l_handle_t *phandle, struct epoll_event epd_event, state_update_t update, void *ctx); +int disconnect_ptp4l( ptp4l_handle_t handle); + +void *ptp4l_event_loop(void *arg); +bool event_subscription(struct jcl_handle **handle); + +struct ptp4l_handle { + int ptp4l_sock; + int epd; + struct epoll_event epd_event; + int error; + + pid_t pid; + struct sockaddr_un server_addr; + struct sockaddr_un client_addr; + + state_update_t update_cb; + void *ctx; + + bool do_exit; + thread_signal_t exit_signal; + thread_signal_t init_signal; + + pthread_t work_thread; +}; + +enum ptp4l_status_update_type +{ + ptp4l_peer_present, + ptp4l_offset, + ptp4l_gmpresent, + ptp4l_servolocked, +}; + +#define ptp4l_peer_present_valid (0x1 << ptp4l_peer_present) +#define ptp4l_offset_valid (0x1 << ptp4l_offset) +#define ptp4l_gmpresent_valid (0x1 << ptp4l_gmpresent) +#define ptp4l_servolocked_valid (0x1 << ptp4l_servolocked) + +struct ptp4l_state { + bool initialized; + unsigned valid_mask; + bool peer_present; + unsigned offset; + bool gm_present; + bool servo_locked; +}; From 65ab75bf97870f97c24b44764b1c5fc54c536d78 Mon Sep 17 00:00:00 2001 From: Noor Azura Ahmad Tarmizi Date: Wed, 24 Apr 2024 06:44:33 -0400 Subject: [PATCH 018/151] doc: Creation TEST_jclkib.md This document is created for clock manager installation and test guidance reference. Can be used by user and validation alike. This is a work in progress. Signed-off-by: Noor Azura Ahmad Tarmizi --- jclklib/TEST_jclklib.md | 88 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 jclklib/TEST_jclklib.md diff --git a/jclklib/TEST_jclklib.md b/jclklib/TEST_jclklib.md new file mode 100644 index 00000000..cde714fa --- /dev/null +++ b/jclklib/TEST_jclklib.md @@ -0,0 +1,88 @@ +# The diagram of clockmanager(CM) usage in system : + +Test app <------> CM runtime lib (jclklib.so) <----------> jclklib_proxy <-----> libptpmgmt.so <-----> ptp4l + +# How to install linux-ptp (with Intel suggested changes) : + + - Ptp4l version based on 4.2 . + - ptp4l patches -> (servo_state subscription changes, etc) + + Repo : https://github.com/intel-staging/linux-ptp_iaclocklib + + Need to clone and install this version with our patches to extend ptp4l subscription options to be used later by libptpmgmt. + + **How to install linuxptp:** + make & make install + + +# How to compile clock manager: + +Clock manager is basically divided to 2 parts: jclklib.so + jclklib_proxy . + +Test application is using CM runtime library : jclklib.so provided API to connect, subscribe and receive ptp4l events. Jclkib.so is communicating with jclklib_proxy using messagequeue. jclklib_proxy uses libptpmgmt.so API (dynamically linked) to subscribe to ptp4l events. + +First, we need to compile the libptpmgmt, giving us the libptpmgmt.so . +Then we compile the clock manager inside the jclklib folder. This will give us : jclklib.so, jclklib_proxy binary and test binary. + + 1. Clone the github : https://github.com/intel-staging/libptpmgmt_iaclocklib + 2. Package dependencies to be installed before compiling libptpmgmt : + + Swig + Cppcheck + Doxygen + Ctags + astyle + Dot + Epstopdf + Valgrind + Libtool-bin + + 3. Run this at the github root directory to compile libptpmgmt : + autoconf + ./configure + make + + 4. Change directory to jclklib and run make clean && make + +NOTE : make will traverse the client, common and proxy folder one by one. You need to type "q" to continue from one folder to another. This is a temporary situation. + + 5. Outcome : you must have 3 binaries created - + client/test + client/jclklib.so + proxy/jclklib_proxy + +# How to test : + +We are currently using a "test.cpp" file to act as an application. This test.cpp is using the API provided in the init.hpp. + +We are dividing the test plan according to message type : + A. Connect message + B. Subscription message + C. Notification message + + +## A. CONNECT message + +** Prerequisite ** +Jclklib_proxy needs to be running before running the test. +Ptp4l shd be running before as well : proxy/run_ptp4l.sh + +### Test setup : + + 1. On a terminal, we run : ./proxy/jclklib_proxy + 2. In the same machine, on a second terminal , e run the test app, using client/run_test.sh on one terminal. -> this will execute the test with LD_CONFIG_PATH set using the current libptpmgmt.so + Please change the LD_CONFIG_PATH accordingly. + +### Test scenario for connect : + + 1. Proxy is not responding (i.e proxy is hang, message queue not working properly) -> in this case, by default timeout for connect is 5 sec . + + 2. Session ID is unique and incremental for a lifetime of proxy. When the proxy is restarted, the sessionID restarts at 0. + + sessionID : std::uint16_t + +## B. Subscription message + + + + From 674fd7e92871d79279c7bd2c77c977cc3bdd7272 Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Wed, 24 Apr 2024 20:38:08 +0800 Subject: [PATCH 019/151] Script: Start ptp4l program at proxy Execute the script with "sh ./run_ptp4l.sh" and start ptp4l program. Signed-off-by: Lai Peter Jun Ann --- jclklib/proxy/run_ptp4l.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 jclklib/proxy/run_ptp4l.sh diff --git a/jclklib/proxy/run_ptp4l.sh b/jclklib/proxy/run_ptp4l.sh new file mode 100644 index 00000000..97f9fed3 --- /dev/null +++ b/jclklib/proxy/run_ptp4l.sh @@ -0,0 +1,10 @@ +#clone the linux-ptp repo and make +git clone https://github.com/intel-staging/linux-ptp_iaclocklib.git +cd linux-ptp_iaclocklib/ +make + +#start ptp4l on board A (where jclklib_proxy running) as slave +./ptp4l -i enp1s0 -m -S -A -P -s -f configs/default.cfg + +#start ptp4l on board B as master +#./ptp4l -i enp1s0 -m -S -A -P -f configs/default.cfg From 49c89da114172906ba93fc69c66801b4388bf7ee Mon Sep 17 00:00:00 2001 From: Noor Azura Ahmad Tarmizi Date: Thu, 4 Apr 2024 23:26:10 -0400 Subject: [PATCH 020/151] Feature: Subscription message rx and tx Added subscription message tx and rx pathway between the proxy and client. Signed-off-by: Noor Azura Ahmad Tarmizi --- jclklib/client/Makefile | 4 +- jclklib/client/init.cpp | 13 +++++++ jclklib/client/init.hpp | 4 +- jclklib/client/message.cpp | 3 +- jclklib/client/msgq_tport.cpp | 7 +++- jclklib/client/test.cpp | 6 +-- jclklib/common/message.cpp | 8 +++- jclklib/common/subscribe_msg.cpp | 59 +++++++++++++++++++++++++++++- jclklib/common/subscribe_msg.hpp | 22 +++++++---- jclklib/proxy/Makefile | 2 +- jclklib/proxy/message.cpp | 3 +- jclklib/proxy/notification_msg.cpp | 11 ++++++ jclklib/proxy/subscribe_msg.cpp | 52 +++++++++++++++++++++++++- jclklib/proxy/subscribe_msg.hpp | 23 +++++++++--- 14 files changed, 189 insertions(+), 28 deletions(-) diff --git a/jclklib/client/Makefile b/jclklib/client/Makefile index 4ed4016a..8991e0a5 100644 --- a/jclklib/client/Makefile +++ b/jclklib/client/Makefile @@ -10,8 +10,8 @@ JCLKLIB_TOPLEVEL_DIR = $(JCLKLIB_CLIENT_DIR)/.. JCLKLIB_COMMON_DIR = $(JCLKLIB_TOPLEVEL_DIR)/common LIBS = pthread rt LIBS_FLAGS = $(foreach lib,$(LIBS),-l$(lib)) -OBJ = init msgq_tport message null_tport transport msgq_tport connect_msg client_state -COMMON_OBJ = print sighandler transport msgq_tport message connect_msg +OBJ = init msgq_tport message null_tport transport msgq_tport connect_msg client_state subscribe_msg +COMMON_OBJ = print sighandler transport msgq_tport message connect_msg subscribe_msg jclklib_import OBJ_FILES = $(foreach f,$(OBJ),$(f).o) DEPENDS = $(foreach f,$(OBJ),$(f).d) COMMON_OBJ_DIR = $(JCLKLIB_COMMON_DIR)/obj diff --git a/jclklib/client/init.cpp b/jclklib/client/init.cpp index b4cb78d3..c48adc24 100644 --- a/jclklib/client/init.cpp +++ b/jclklib/client/init.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -61,6 +62,18 @@ bool JClkLibClient::connect() return true; } + +bool JClkLibClient::subscribe(JClkLibCommon::jcl_subscription &subscription) +{ + PrintDebug("[AZU] JClkLibClient::subscribe"); + Message0 subscribeMsg(new ClientSubscribeMessage()); + + ClientMessageQueue::writeTransportClientId(subscribeMsg.get()); + ClientMessageQueue::sendMessage(subscribeMsg.get()); + /* overwrite | merge the current event to this event */ + return true; +} + bool JClkLibClient::disconnect() { bool retVal = false; diff --git a/jclklib/client/init.hpp b/jclklib/client/init.hpp index a9666341..3573802e 100644 --- a/jclklib/client/init.hpp +++ b/jclklib/client/init.hpp @@ -8,10 +8,12 @@ #ifndef CLIENT_INIT_HPP #define CLIENT_INIT_HPP +#include + namespace JClkLibClient { bool connect(); bool disconnect(); - //bool subscribe(); + bool subscribe(JClkLibCommon::jcl_subscription &subscription); }; #endif/*CLIENT_INIT_HPP*/ diff --git a/jclklib/client/message.cpp b/jclklib/client/message.cpp index 0bd5ecea..e1372fc0 100644 --- a/jclklib/client/message.cpp +++ b/jclklib/client/message.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include using namespace JClkLibClient; @@ -15,5 +16,5 @@ using namespace JClkLibClient; bool ClientMessage::init() { PrintDebug("Initializing Client Message"); - return JClkLibCommon::_initMessage(); + return JClkLibCommon::_initMessage(); } diff --git a/jclklib/client/msgq_tport.cpp b/jclklib/client/msgq_tport.cpp index 4ee7916b..91c4ec90 100644 --- a/jclklib/client/msgq_tport.cpp +++ b/jclklib/client/msgq_tport.cpp @@ -102,9 +102,12 @@ bool ClientMessageQueue::finalizeTransport() bool ClientMessageQueue::writeTransportClientId(Message *msg) { ClientConnectMessage *cmsg = dynamic_cast(msg); - if (cmsg == NULL) + if (cmsg == NULL) { + PrintErrorCode("[ClientMessageQueue] cmsg is NULL !!\n"); return false; + } strcpy((char *)cmsg->getClientId().data(), mqListenerName.c_str()); + printf ("[ClientMessageQueue] cmsg->getClientId().data(): %s", (char *)cmsg->getClientId().data()); return true; } @@ -117,6 +120,6 @@ SEND_CLIENT_MESSAGE(ClientMessageQueue::sendMessage) PrintErrorCode("Failed to transmit client message"); return false; } - + PrintDebug("[Azu] ClientMessageQueue::sendMessage successful "); return true; } diff --git a/jclklib/client/test.cpp b/jclklib/client/test.cpp index bcc43304..f09dd98f 100644 --- a/jclklib/client/test.cpp +++ b/jclklib/client/test.cpp @@ -21,8 +21,7 @@ using namespace std; int main() { int ret = EXIT_SUCCESS; - // TODO - // JClkLibCommon::jcl_subscription sub; + JClkLibCommon::jcl_subscription sub; std::cout << "[CLIENT] Before connect : Session ID : " << state.get_sessionId() << "\n"; @@ -35,8 +34,7 @@ int main() std::cout << "[CLIENT] Connected. Session ID : " << state.get_sessionId() << "\n"; } sleep(5); - // TODO - // subscribe(sub); + subscribe(sub); sleep(5); do_exit: disconnect(); diff --git a/jclklib/common/message.cpp b/jclklib/common/message.cpp index 544a8b71..564c9dd9 100644 --- a/jclklib/common/message.cpp +++ b/jclklib/common/message.cpp @@ -10,6 +10,7 @@ #include #include #include +#include using namespace JClkLibCommon; using namespace std; @@ -51,6 +52,7 @@ string Message::toString() BUILD_TXBUFFER_TYPE(Message::makeBuffer) const { + PrintDebug("[AZU] Message::makeBuffer "); if (!WRITE_TX(FIELD,msgId,TxContext)) return false; if (!WRITE_TX(FIELD,msgAck,TxContext)) @@ -66,8 +68,9 @@ COMMON_PRESEND_MESSAGE_TYPE(Message::presendMessage) PrintError("Failed to make buffer from message object"); return false; } - DumpOctetArray("Sending message (length = " + to_string(ctx->getc_offset()) + "): ", ctx->getc_buffer().data(), - ctx->getc_offset()); + //DumpOctetArray("Sending message (length = " + to_string(ctx->getc_offset()) + "): ", ctx->getc_buffer().data(), + // ctx->getc_offset()); //AZU + PrintDebug("[AZU] Message::presendMessage successful "); return true; } @@ -87,6 +90,7 @@ bool Message::addMessageType(parseMsgMapElement_t mapping) PARSE_RXBUFFER_TYPE(Message::parseBuffer) { + PrintDebug("[AZU] Message::parseBuffer "); if (!PARSE_RX(FIELD,msgId, LxContext)) return false; if (!PARSE_RX(FIELD,msgAck, LxContext)) diff --git a/jclklib/common/subscribe_msg.cpp b/jclklib/common/subscribe_msg.cpp index d2f632e5..2e4ff2e0 100644 --- a/jclklib/common/subscribe_msg.cpp +++ b/jclklib/common/subscribe_msg.cpp @@ -6,13 +6,70 @@ */ #include +#include +#include using namespace JClkLibCommon; using namespace std; -MAKE_RXBUFFER_TYPE(SubscribeMessage::buildMessage) +/*MAKE_RXBUFFER_TYPE(SubscribeMessage::buildMessage) { // Fill in fields + return true; +}*/ + + +string CommonSubscribeMessage::toString() +{ + string name = ExtractClassName(string(__PRETTY_FUNCTION__),string(__FUNCTION__)); + name += "\n"; + name += Message::toString(); + name += "Client ID: " + string((char *)clientId.data()) + "\n"; + + return name; +} + +PARSE_RXBUFFER_TYPE(CommonSubscribeMessage::parseBuffer) { + PrintDebug("[AZU] CommonSubscribeMessage::parseBuffer "); + if(!Message::parseBuffer(LxContext)) + return false; + + if (!PARSE_RX(FIELD, get_sessionId(), LxContext)) + return false; + + if (!PARSE_RX(FIELD,subscription, LxContext)) + return false; + return true; } + + +BUILD_TXBUFFER_TYPE(CommonSubscribeMessage::makeBuffer) const +{ + auto ret = Message::makeBuffer(TxContext); + PrintDebug("[AZU] CommonSubscribeMessage::makeBuffer"); + if (!ret) + return ret; + + PrintDebug("[AZU] CommonSubscribeMessage::makeBuffer - sessionId : " + to_string(c_get_val_sessionId())); + if (!WRITE_TX(FIELD, c_get_val_sessionId(), TxContext)) + return false; + + PrintDebug("[AZU] CommonSubscribeMessage::makeBuffer - sessionId : " + to_string(c_get_val_sessionId())); + if (!WRITE_TX(FIELD,subscription,TxContext)) + return false; + + return true; +} + +TRANSMIT_MESSAGE_TYPE(CommonSubscribeMessage::transmitMessage) +{ + PrintDebug("[AZU] CommonSubscribeMessage::transmitMessage "); + if (!presendMessage(&TxContext)) + return false; + + return TxContext.sendBuffer(); +} + + diff --git a/jclklib/common/subscribe_msg.hpp b/jclklib/common/subscribe_msg.hpp index 4ea6daf1..4c8946d3 100644 --- a/jclklib/common/subscribe_msg.hpp +++ b/jclklib/common/subscribe_msg.hpp @@ -13,18 +13,26 @@ namespace JClkLibCommon { - class SubscribeMessage : public Message + class CommonSubscribeMessage : virtual public Message { + private: + jcl_subscription subscription; + TransportClientId clientId; public: static msgId_t getMsgId() { return SUBSCRIBE_MSG; } - static MAKE_RXBUFFER_TYPE(buildMessage); - - const jcl_subscription &getSubscription(); + //static MAKE_RXBUFFER_TYPE(buildMessage); + //const jcl_subscription &getSubscription(); + virtual PARSE_RXBUFFER_TYPE(parseBuffer); + virtual TRANSMIT_MESSAGE_TYPE(transmitMessage); + virtual BUILD_TXBUFFER_TYPE(makeBuffer) const; + jcl_subscription &getSubscription() + { return subscription; } + TransportClientId &getClientId() + { return clientId; } + virtual std::string toString(); protected: #define MESSAGE_SUBSCRIBE() JClkLibCommon::Message(JClkLibCommon::SUBSCRIBE_MSG) - SubscribeMessage() : MESSAGE_SUBSCRIBE() {} - private: - jcl_subscription subscription; + CommonSubscribeMessage() : MESSAGE_SUBSCRIBE() {} }; } diff --git a/jclklib/proxy/Makefile b/jclklib/proxy/Makefile index 21d67da9..735f22f1 100644 --- a/jclklib/proxy/Makefile +++ b/jclklib/proxy/Makefile @@ -11,7 +11,7 @@ JCLKLIB_COMMON_DIR = $(JCLKLIB_TOPLEVEL_DIR)/common LIBS = pthread rt ptpmgmt LIBS_FLAGS = $(foreach lib,$(LIBS),-l$(lib)) OBJ = client main message msgq_tport notification_msg null_tport connect_msg subscribe_msg transport connect thread -COMMON_OBJ = print sighandler transport msgq_tport jclklib_import message connect_msg +COMMON_OBJ = print sighandler transport msgq_tport jclklib_import message connect_msg subscribe_msg OBJ_FILES = $(foreach f,$(OBJ),$(f).o) DEPENDS = $(foreach f,$(OBJ),$(f).d) COMMON_OBJ_DIR = $(JCLKLIB_COMMON_DIR)/obj diff --git a/jclklib/proxy/message.cpp b/jclklib/proxy/message.cpp index e430b616..e8f7b0de 100644 --- a/jclklib/proxy/message.cpp +++ b/jclklib/proxy/message.cpp @@ -7,13 +7,14 @@ #include #include +#include using namespace JClkLibProxy; using namespace JClkLibCommon; bool ProxyMessage::init() { - return _initMessage(); + return _initMessage(); } diff --git a/jclklib/proxy/notification_msg.cpp b/jclklib/proxy/notification_msg.cpp index d1b8e108..fdda3c99 100644 --- a/jclklib/proxy/notification_msg.cpp +++ b/jclklib/proxy/notification_msg.cpp @@ -11,12 +11,23 @@ using namespace JClkLibProxy; + +/* +* [Azu] This is to send notification from Proxy to subscribed client upon state change +* This shd be in the RX buffer - so this shd be inside the client to process +* notification from proxy. +*/ +/* REMOVE */ bool ProxyNotificationMessage::processMessage(ClockConfiguration &config) { //config.setWait( waitEnable ); return true; } + +/* +TO BE REMOVED +*/ bool ProxyNotificationMessage::generateResponse(uint8_t *msgBuffer, size_t &length, const ClockStatus &status) { diff --git a/jclklib/proxy/subscribe_msg.cpp b/jclklib/proxy/subscribe_msg.cpp index c49ed0c1..5d1661ac 100644 --- a/jclklib/proxy/subscribe_msg.cpp +++ b/jclklib/proxy/subscribe_msg.cpp @@ -7,16 +7,66 @@ #include #include +#include +#include +using namespace std; using namespace JClkLibProxy; +using namespace JClkLibCommon; -bool ProxySubscribeMessage::processMessage(ClockConfiguration &config) +/** @brief Create the ProxySubscribeMessage object + * + * @param msg msg structure to be fill up + * @param LxContext proxy transport listener context + * @return true + */ +MAKE_RXBUFFER_TYPE(ProxySubscribeMessage::buildMessage) +{ + msg = new ProxySubscribeMessage(); + return true; +} + +/** @brief Add proxy's SUBSCRIBE_MSG type and its builder to transport layer. + * + * This function will be called during init to add a map of SUBSCRIBE_MSG + * type and its corresponding buildMessage function. + * + * @return true + */ +bool ProxySubscribeMessage::initMessage() +{ + addMessageType(parseMsgMapElement_t(SUBSCRIBE_MSG, buildMessage)); + return true; +} + +/* +This is to process the subscription from the jclklib client runtime via POSIX msg queue +[Question] The client list of real-time subscription is hold inside jcklib_proxy? +*/ +//bool ProxySubscribeMessage::processMessage(ClockConfiguration &config) +PROCESS_MESSAGE_TYPE(ProxySubscribeMessage::processMessage) { //config.setEvent(subscription.getEvent()); //config.setValue(subscription.getValue()); + sessionId_t sID; + sID = this->getc_sessionId(); + PrintDebug("[AZU] ProxySubscribeMessage::processMessage - Use current client session ID: " + to_string(sID)); + + if(sID == InvalidSessionId) { + PrintError("Session ID *should be* invalid for received proxy connect message"); + PrintDebug("[AZU] overwrite the sID to 0"); + sID = 0; + //return false; //azu hack + } + TxContext = Client::GetClientSession(sID).get()->get_transmitContext(); + set_msgAck(ACK_SUCCESS); return true; } + +/* +[NOTE] This is to response towards ProxySubscribeMessage - wont be using this for the time being. +*/ bool ProxySubscribeMessage::generateResponse(uint8_t *msgBuffer, size_t &length, const ClockStatus &status) { diff --git a/jclklib/proxy/subscribe_msg.hpp b/jclklib/proxy/subscribe_msg.hpp index 2009d201..57a737ae 100644 --- a/jclklib/proxy/subscribe_msg.hpp +++ b/jclklib/proxy/subscribe_msg.hpp @@ -13,16 +13,29 @@ namespace JClkLibProxy { - class ProxySubscribeMessage : virtual public ProxyMessage, virtual public JClkLibCommon::SubscribeMessage + class ProxySubscribeMessage : virtual public ProxyMessage, virtual public JClkLibCommon::CommonSubscribeMessage { + protected: + ProxySubscribeMessage() : MESSAGE_SUBSCRIBE() {}; public: - bool processMessage(ClockConfiguration &config); + //bool processMessage(ClockConfiguration &config); + virtual PROCESS_MESSAGE_TYPE(processMessage); bool generateResponse(uint8_t *msgBuffer, std::size_t &length, const ClockStatus &status); + /** + * @brief Create the ProxyConnectMessage object + * @param msg msg structure to be fill up + * @param LxContext proxy transport listener context + * @return true + */ + static MAKE_RXBUFFER_TYPE(buildMessage); - protected: - ProxySubscribeMessage() : MESSAGE_SUBSCRIBE() {}; + /** + * @brief Add proxy's CONNECT_MSG type and its builder to transport layer. + * @return true + */ + static bool initMessage(); }; } -#endif/*SUBSCRIBE_MSG_HPP*/ +#endif/*PROXY_SUBSCRIBE_MSG_HPP*/ From 2a52be73cfa4fe2e0fe228dbea28a0ad2cc63cdd Mon Sep 17 00:00:00 2001 From: Noor Azura Ahmad Tarmizi Date: Tue, 9 Apr 2024 03:18:16 -0400 Subject: [PATCH 021/151] feature: Add subscription files in client Signed-off-by: Noor Azura Ahmad Tarmizi --- jclklib/.gitignore | 2 + jclklib/client/client_state.cpp | 15 +++++++ jclklib/client/client_state.hpp | 6 +++ jclklib/client/connect_msg.cpp | 3 +- jclklib/client/init.cpp | 27 +++++++++++-- jclklib/client/init.hpp | 2 +- jclklib/client/msgq_tport.cpp | 45 +++++++++++++++++---- jclklib/client/run_test.sh | 4 +- jclklib/client/subscribe_msg.cpp | 63 ++++++++++++++++++++++++++++++ jclklib/client/subscribe_msg.hpp | 45 +++++++++++++++++++++ jclklib/client/test.cpp | 4 ++ jclklib/common/connect_msg.cpp | 1 + jclklib/common/jclklib_import.cpp | 49 +++++++++++++++++++++++ jclklib/common/jclklib_import.hpp | 9 ++++- jclklib/common/message.cpp | 11 +++--- jclklib/common/subscribe_msg.cpp | 30 ++++++-------- jclklib/common/subscribe_msg.hpp | 2 + jclklib/proxy/notification_msg.cpp | 2 +- jclklib/proxy/subscribe_msg.cpp | 7 +--- 19 files changed, 282 insertions(+), 45 deletions(-) create mode 100644 jclklib/.gitignore create mode 100644 jclklib/client/subscribe_msg.cpp create mode 100644 jclklib/client/subscribe_msg.hpp diff --git a/jclklib/.gitignore b/jclklib/.gitignore new file mode 100644 index 00000000..eb24d0ba --- /dev/null +++ b/jclklib/.gitignore @@ -0,0 +1,2 @@ +client/test +proxy/jclklib_proxy diff --git a/jclklib/client/client_state.cpp b/jclklib/client/client_state.cpp index e3257919..216fe6e2 100644 --- a/jclklib/client/client_state.cpp +++ b/jclklib/client/client_state.cpp @@ -1,16 +1,31 @@ +#include #include #include +#include +#include +#include +using namespace std; using namespace JClkLibClient; +using namespace JClkLibCommon; ClientState::ClientState() { connected = false; sessionId = JClkLibCommon::InvalidSessionId; + fill(begin(clientID ), end( clientID ), 0 ); } bool ClientState::get_connected() {return connected;} void ClientState::set_connected(bool new_state) {connected = new_state;} +TransportClientId ClientState::get_clientID() { + return clientID; +} + +void ClientState::set_clientID(TransportClientId new_cID) { + strcpy((char *)clientID.data(), (char *)new_cID.data()); +} + ClientState JClkLibClient::state{}; diff --git a/jclklib/client/client_state.hpp b/jclklib/client/client_state.hpp index c825afad..0ee42f0e 100644 --- a/jclklib/client/client_state.hpp +++ b/jclklib/client/client_state.hpp @@ -3,6 +3,7 @@ #include #include +#include #include namespace JClkLibClient { @@ -10,10 +11,15 @@ namespace JClkLibClient { private: std::atomic_bool connected; JClkLibCommon::sessionId_t sessionId; + JClkLibCommon::TransportClientId clientID; public: ClientState(); bool get_connected(); void set_connected(bool state); + JClkLibCommon::TransportClientId get_clientID(); + void set_clientID(JClkLibCommon::TransportClientId cID); + void get_clientID_memcpy(JClkLibCommon::TransportClientId cID); + void set_clientID_memcpy(JClkLibCommon::TransportClientId cID); DECLARE_ACCESSOR(sessionId); }; diff --git a/jclklib/client/connect_msg.cpp b/jclklib/client/connect_msg.cpp index d777317e..ef67267e 100644 --- a/jclklib/client/connect_msg.cpp +++ b/jclklib/client/connect_msg.cpp @@ -64,9 +64,8 @@ PROCESS_MESSAGE_TYPE(ClientConnectMessage::processMessage) state.set_sessionId(this->get_sessionId()); PrintDebug("Connected with session ID: " + to_string(this->get_sessionId())); + PrintDebug("Current state.sessionId: " + to_string(state.get_sessionId())); - /*[TODO] client runtime shd return client ID to application - return client ID at least */ - /*[Question] ACK_NONE is necessary ?*/ this->set_msgAck(ACK_NONE); cv.notify_one(); diff --git a/jclklib/client/init.cpp b/jclklib/client/init.cpp index c48adc24..e838af7d 100644 --- a/jclklib/client/init.cpp +++ b/jclklib/client/init.cpp @@ -14,6 +14,8 @@ #include #include #include +#include +#include #define DEFAULT_CONNECT_TIME_OUT 5 //5 sec @@ -23,6 +25,7 @@ using namespace std; std::mutex ClientConnectMessage::cv_mtx; std::condition_variable ClientConnectMessage::cv; +TransportClientId globalClientID; bool JClkLibClient::connect() { @@ -59,18 +62,34 @@ bool JClkLibClient::connect() } } + ClientConnectMessage *cmsg = dynamic_cast(connectMsg.get()); + strcpy((char *)globalClientID.data(), (char *)cmsg->getClientId().data()); + state.set_clientID(globalClientID); + return true; } -bool JClkLibClient::subscribe(JClkLibCommon::jcl_subscription &subscription) +bool JClkLibClient::subscribe(JClkLibCommon::jcl_subscription &newSub) { - PrintDebug("[AZU] JClkLibClient::subscribe"); - Message0 subscribeMsg(new ClientSubscribeMessage()); + + PrintDebug("[JClkLibClient]::subscribe"); + MessageX subscribeMsg(new ClientSubscribeMessage()); + + ClientSubscribeMessage *cmsg = dynamic_cast(subscribeMsg.get()); + if (cmsg == NULL) { + PrintErrorCode("[JClkLibClient::subscribe] subscribeMsg is NULL !!\n"); + return false; + } + else + PrintDebug("[JClkLibClient::subscribe] subscribeMsgcreation is OK !!\n"); + + /* Write the current event subscription */ + cmsg->getSubscription().get_event().copyEventMask(newSub.get_event()); ClientMessageQueue::writeTransportClientId(subscribeMsg.get()); ClientMessageQueue::sendMessage(subscribeMsg.get()); - /* overwrite | merge the current event to this event */ + return true; } diff --git a/jclklib/client/init.hpp b/jclklib/client/init.hpp index 3573802e..5c3630ec 100644 --- a/jclklib/client/init.hpp +++ b/jclklib/client/init.hpp @@ -13,7 +13,7 @@ namespace JClkLibClient { bool connect(); bool disconnect(); - bool subscribe(JClkLibCommon::jcl_subscription &subscription); + bool subscribe(JClkLibCommon::jcl_subscription &newSub); }; #endif/*CLIENT_INIT_HPP*/ diff --git a/jclklib/client/msgq_tport.cpp b/jclklib/client/msgq_tport.cpp index 91c4ec90..47b9f12a 100644 --- a/jclklib/client/msgq_tport.cpp +++ b/jclklib/client/msgq_tport.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -101,13 +102,42 @@ bool ClientMessageQueue::finalizeTransport() bool ClientMessageQueue::writeTransportClientId(Message *msg) { - ClientConnectMessage *cmsg = dynamic_cast(msg); - if (cmsg == NULL) { - PrintErrorCode("[ClientMessageQueue] cmsg is NULL !!\n"); - return false; + msgId_t msgId = msg->get_msgId(); + + switch (msgId) { + + case CONNECT_MSG : + { + ClientConnectMessage *cmsg = dynamic_cast(msg); + if (cmsg == NULL) { + PrintErrorCode("[ClientMessageQueue] ClientConnectMessage cmsg is NULL !!\n"); + return false; + } + strcpy((char *)cmsg->getClientId().data(), mqListenerName.c_str()); + printf ("[ClientMessageQueue][CONNECT] cmsg->getClientId().data(): %s\n", (char *)cmsg->getClientId().data()); + break; + } + case SUBSCRIBE_MSG : + { + ClientSubscribeMessage *cmsg = dynamic_cast(msg); + if (cmsg == NULL) { + PrintErrorCode("[ClientMessageQueue] ClientSubscribeMessage cmsg is NULL !!\n"); + return false; + } + + strcpy((char *)cmsg->getClientId().data(), (char *)state.get_clientID().data()); + + cmsg->set_sessionId(state.get_sessionId()); // this is where it turns to 0 + printf ("[ClientMessageQueue] [SUBSCRIBE] cmsg->set_sessionId() : %d\n", cmsg->get_sessionId()); + PrintDebug("[ClientMessageQueue] [SUBSCRIBE] : subscription->event Mask : " + cmsg->getSubscription().get_event().toString()); + break; + } + default: + { + PrintErrorCode("Unknown msgID type"); + return false; + } } - strcpy((char *)cmsg->getClientId().data(), mqListenerName.c_str()); - printf ("[ClientMessageQueue] cmsg->getClientId().data(): %s", (char *)cmsg->getClientId().data()); return true; } @@ -116,10 +146,11 @@ SEND_CLIENT_MESSAGE(ClientMessageQueue::sendMessage) auto context = txContext.get(); msg->presendMessage(context); + if (mq_send(mqNativeClientTransmitterDesc, (char *)context->getc_buffer().data(), context->getc_offset(), 0) == -1) { PrintErrorCode("Failed to transmit client message"); return false; } - PrintDebug("[Azu] ClientMessageQueue::sendMessage successful "); + PrintDebug("[ClientMessageQueue]::sendMessage successful "); return true; } diff --git a/jclklib/client/run_test.sh b/jclklib/client/run_test.sh index e18f2356..0c8ac890 100755 --- a/jclklib/client/run_test.sh +++ b/jclklib/client/run_test.sh @@ -1,5 +1,7 @@ #!/bin/bash -TEST_PATH=/home/chall/siemens_dev/libptpmgmt/jclklib/client/ +TEST_PATH=/home/ubuntu20/siemens/libptpmgmt_iaclocklib_org/jclklib/client/ LD_LIBRARY_PATH=$TEST_PATH $TEST_PATH/test + + diff --git a/jclklib/client/subscribe_msg.cpp b/jclklib/client/subscribe_msg.cpp new file mode 100644 index 00000000..fa3f9e3a --- /dev/null +++ b/jclklib/client/subscribe_msg.cpp @@ -0,0 +1,63 @@ +/*! \file subscribe_msg.cpp + \brief Client subscribe message class. Implements client specific functionality. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + @author: Noor Azura Ahmad Tarmizi +*/ + +#include +#include + +using namespace JClkLibClient; +using namespace JClkLibCommon; +using namespace std; + +/** @brief Create the ClientSubscribeMessage object + * + * @param msg msg structure to be fill up + * @param LxContext client run-time transport listener context + * @return true + */ +MAKE_RXBUFFER_TYPE(ClientSubscribeMessage::buildMessage) +{ + PrintDebug("[ClientSubscribeMessage]::buildMessage()"); + msg = new ClientSubscribeMessage(); + + return true; +} + +/** @brief Add client's SUBSCRIBE_MSG type and its builder to transport layer. + * + * This function will be called during init to add a map of SUBSCRIBE_MSG + * type and its corresponding buildMessage function. + * + * @return true + */ +bool ClientSubscribeMessage::initMessage() +{ + PrintDebug("[ClientSubscribeMessage]::initMessage()"); + addMessageType(parseMsgMapElement_t(SUBSCRIBE_MSG, buildMessage)); + return true; +} + +/** @brief process the reply for notification msg from proxy. + * + * This function will be called when the transport layer + * in client runtime received a SUBSCRIBE_MSG type (an echo reply from + * proxy) + * In this case, transport layer will rx a buffer in the client associated + * listening message queue (listening to proxy) and call this function when + * the enum ID corresponding to the SUBSCRIBE_MSG is received. + * + * @param LxContext client run-time transport listener context + * @param TxContext client run-time transport transmitter context + * @return true + */ +PROCESS_MESSAGE_TYPE(ClientSubscribeMessage::processMessage) +{ + + PrintDebug("[ClientSubscribeMessage]::processMessage (reply)"); + + this->set_msgAck(ACK_NONE); + return true; +} diff --git a/jclklib/client/subscribe_msg.hpp b/jclklib/client/subscribe_msg.hpp new file mode 100644 index 00000000..a79ee528 --- /dev/null +++ b/jclklib/client/subscribe_msg.hpp @@ -0,0 +1,45 @@ +/*! \file subscribe_msg.hpp + \brief Client subscribe message class. Implements client specific functionality. + + (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + @author: Noor Azura Ahmad Tarmizi +*/ + +#ifndef CLIENT_SUBSCRIBE_MSG_HPP +#define CLIENT_SUBSCRIBE_MSG_HPP + +#include +#include + +namespace JClkLibClient +{ + class ClientSubscribeMessage : virtual public JClkLibCommon::CommonSubscribeMessage, + virtual public ClientMessage + { + public: + ClientSubscribeMessage() : MESSAGE_SUBSCRIBE() {}; + /** + * @brief process the reply for subscribe msg from proxy. + * @param LxContext client run-time transport listener context + * @param TxContext client run-time transport transmitter context + * @return true + */ + virtual PROCESS_MESSAGE_TYPE(processMessage); + + /** + * @brief Create the ClientSubscribeMessage object + * @param msg msg structure to be fill up + * @param LxContext client run-time transport listener context + * @return true + */ + static MAKE_RXBUFFER_TYPE(buildMessage); + + /** + * @brief Add client's SUBSCRIBE_MSG type and its builder to transport layer. + * @return true + */ + static bool initMessage(); + }; +} + +#endif/*CLIENT_SUBSCRIBE_MSG_HPP*/ diff --git a/jclklib/client/test.cpp b/jclklib/client/test.cpp index f09dd98f..850ae6ac 100644 --- a/jclklib/client/test.cpp +++ b/jclklib/client/test.cpp @@ -22,6 +22,7 @@ int main() { int ret = EXIT_SUCCESS; JClkLibCommon::jcl_subscription sub; + std::uint32_t event2Sub1[1] = {((1< #include +#include #include using namespace JClkLibCommon; +using namespace std; + jcl_value::value_t::value_t() { @@ -80,6 +83,40 @@ uint8_t *jcl_subscription::write(uint8_t *buf, std::size_t &length) return buf; } +int8_t jcl_event::writeEvent(uint32_t *newEvent, std::size_t newEventlength) +{ + if (newEvent == NULL || sizeof(event_mask) < newEventlength) { + PrintDebug("jcl_event::writeEvent failure"); + return -1; + } + + memcpy(this->event_mask, newEvent , newEventlength); + + return 0; +} + +int8_t jcl_event::readEvent(uint32_t *readEvnt, std::size_t eventLength) +{ + if (readEvnt == NULL || sizeof(event_mask) > eventLength) { + PrintDebug("jcl_event::readEvent failure"); + return -1; + } + + memcpy(readEvnt, this->event_mask, eventLength); + + return 0; +} + +int8_t jcl_event::copyEventMask(jcl_event &newEvent) +{ + std::size_t newEventLength = sizeof(newEvent.getEventMask()); + + memcpy(event_mask, newEvent.event_mask , newEventLength); + printf ("[jcl_event]::copyEventMask - newEventLength = %ld , incoming event mask = 0x%x\n", newEventLength, newEvent.getEventMask()[0]); + + return 0; +} + uint8_t *jcl_event::parse(uint8_t *buf, std::size_t &length) { for(size_t i = 0; i < sizeof(event_mask)/sizeof(event_mask[0]) && buf != NULL; ++i) @@ -151,3 +188,15 @@ bool jcl_eventcount::equal( const jcl_eventcount &ec) return true; return false; } + +std::string jcl_value::toString() +{ + std::string name = "jcl_value : upper " + to_string (this->value->upper) + " lower : " + to_string (this->value->lower) + "\n"; + return name; +} + +std::string jcl_event::toString() +{ + std::string name = "jcl_event : event[0] = " + to_string (this->event_mask[0]) + "\n"; + return name; +} diff --git a/jclklib/common/jclklib_import.hpp b/jclklib/common/jclklib_import.hpp index 45b02939..4e764b53 100644 --- a/jclklib/common/jclklib_import.hpp +++ b/jclklib/common/jclklib_import.hpp @@ -40,11 +40,13 @@ namespace JClkLibCommon bool equal( const jcl_value &c); bool operator== (const jcl_value &value) { return this->equal(value); } bool operator!= (const jcl_value &value) { return !this->equal(value); } + std::string toString(); }; typedef enum : std::uint8_t - { peerPresentEvent, gmPresentEvent, gmOffsetEvent, servoLockedEvent, + { peerPresentEvent, gmPresentUUIDEvent, gmOffsetEvent, servoLockedEvent, asCapableEvent, eventLast } eventType; + #define BITS_PER_BYTE (8) #define MAX_EVENT_COUNT (128) @@ -62,6 +64,11 @@ namespace JClkLibCommon bool equal( const jcl_event &c); bool operator== (const jcl_event &event) { return this->equal(event); } bool operator!= (const jcl_event &event) { return !this->equal(event); } + std::string toString(); + int8_t writeEvent(uint32_t *newEvent, std::size_t length); + int8_t readEvent(uint32_t *readEvnt, std::size_t length); + int8_t copyEventMask(jcl_event &newEvent); + std::uint32_t *getEventMask() { return event_mask; } }; diff --git a/jclklib/common/message.cpp b/jclklib/common/message.cpp index 564c9dd9..d0e0fe9c 100644 --- a/jclklib/common/message.cpp +++ b/jclklib/common/message.cpp @@ -52,7 +52,7 @@ string Message::toString() BUILD_TXBUFFER_TYPE(Message::makeBuffer) const { - PrintDebug("[AZU] Message::makeBuffer "); + PrintDebug("[Message]::makeBuffer"); if (!WRITE_TX(FIELD,msgId,TxContext)) return false; if (!WRITE_TX(FIELD,msgAck,TxContext)) @@ -63,14 +63,15 @@ BUILD_TXBUFFER_TYPE(Message::makeBuffer) const COMMON_PRESEND_MESSAGE_TYPE(Message::presendMessage) { + PrintDebug("[Message]::presendMessage starts"); ctx->resetOffset(); if (!makeBuffer(*ctx)) { PrintError("Failed to make buffer from message object"); return false; } - //DumpOctetArray("Sending message (length = " + to_string(ctx->getc_offset()) + "): ", ctx->getc_buffer().data(), - // ctx->getc_offset()); //AZU - PrintDebug("[AZU] Message::presendMessage successful "); + DumpOctetArray("Sending message (length = " + to_string(ctx->getc_offset()) + "): ", ctx->getc_buffer().data(), + ctx->getc_offset()); + PrintDebug("[Message]::presendMessage successful"); return true; } @@ -90,7 +91,7 @@ bool Message::addMessageType(parseMsgMapElement_t mapping) PARSE_RXBUFFER_TYPE(Message::parseBuffer) { - PrintDebug("[AZU] Message::parseBuffer "); + PrintDebug("[Message]::parseBuffer "); if (!PARSE_RX(FIELD,msgId, LxContext)) return false; if (!PARSE_RX(FIELD,msgAck, LxContext)) diff --git a/jclklib/common/subscribe_msg.cpp b/jclklib/common/subscribe_msg.cpp index 2e4ff2e0..e33b2ecd 100644 --- a/jclklib/common/subscribe_msg.cpp +++ b/jclklib/common/subscribe_msg.cpp @@ -12,52 +12,44 @@ using namespace JClkLibCommon; using namespace std; -/*MAKE_RXBUFFER_TYPE(SubscribeMessage::buildMessage) -{ - // Fill in fields - - return true; -}*/ - - string CommonSubscribeMessage::toString() { string name = ExtractClassName(string(__PRETTY_FUNCTION__),string(__FUNCTION__)); name += "\n"; name += Message::toString(); - name += "Client ID: " + string((char *)clientId.data()) + "\n"; + //name += "Client ID: " + string((char *)clientId.data()) + "\n"; return name; } PARSE_RXBUFFER_TYPE(CommonSubscribeMessage::parseBuffer) { - PrintDebug("[AZU] CommonSubscribeMessage::parseBuffer "); + PrintDebug("[CommonSubscribeMessage]::parseBuffer "); if(!Message::parseBuffer(LxContext)) return false; if (!PARSE_RX(FIELD, get_sessionId(), LxContext)) return false; - if (!PARSE_RX(FIELD,subscription, LxContext)) + if (!PARSE_RX(FIELD, subscription, LxContext)) return false; return true; } - BUILD_TXBUFFER_TYPE(CommonSubscribeMessage::makeBuffer) const { auto ret = Message::makeBuffer(TxContext); - PrintDebug("[AZU] CommonSubscribeMessage::makeBuffer"); + if (!ret) return ret; - PrintDebug("[AZU] CommonSubscribeMessage::makeBuffer - sessionId : " + to_string(c_get_val_sessionId())); + PrintDebug("[CommonSubscribeMessage]::makeBuffer - sessionId : " + to_string(c_get_val_sessionId())); if (!WRITE_TX(FIELD, c_get_val_sessionId(), TxContext)) return false; - PrintDebug("[AZU] CommonSubscribeMessage::makeBuffer - sessionId : " + to_string(c_get_val_sessionId())); - if (!WRITE_TX(FIELD,subscription,TxContext)) + PrintDebug("[CommonSubscribeMessage]::makeBuffer - subscription event : " + subscription.c_get_val_event().toString() + \ + ", subscription val : " + subscription.c_get_val_value().toString()); + if (!WRITE_TX(FIELD,subscription, TxContext)) return false; return true; @@ -65,11 +57,13 @@ BUILD_TXBUFFER_TYPE(CommonSubscribeMessage::makeBuffer) const TRANSMIT_MESSAGE_TYPE(CommonSubscribeMessage::transmitMessage) { - PrintDebug("[AZU] CommonSubscribeMessage::transmitMessage "); + PrintDebug("[CommonSubscribeMessage]::transmitMessage "); if (!presendMessage(&TxContext)) return false; return TxContext.sendBuffer(); } - +void setSubscription(jcl_subscription newsub) { + PrintDebug("[CommonSubscribeMessage]::setSubscription "); +} diff --git a/jclklib/common/subscribe_msg.hpp b/jclklib/common/subscribe_msg.hpp index 4c8946d3..49aecd36 100644 --- a/jclklib/common/subscribe_msg.hpp +++ b/jclklib/common/subscribe_msg.hpp @@ -29,6 +29,8 @@ namespace JClkLibCommon { return subscription; } TransportClientId &getClientId() { return clientId; } + void setSubscription(jcl_subscription newsub); + virtual std::string toString(); protected: #define MESSAGE_SUBSCRIBE() JClkLibCommon::Message(JClkLibCommon::SUBSCRIBE_MSG) diff --git a/jclklib/proxy/notification_msg.cpp b/jclklib/proxy/notification_msg.cpp index fdda3c99..0e8c22ae 100644 --- a/jclklib/proxy/notification_msg.cpp +++ b/jclklib/proxy/notification_msg.cpp @@ -17,7 +17,7 @@ using namespace JClkLibProxy; * This shd be in the RX buffer - so this shd be inside the client to process * notification from proxy. */ -/* REMOVE */ +/* TO BE REMOVED */ bool ProxyNotificationMessage::processMessage(ClockConfiguration &config) { //config.setWait( waitEnable ); diff --git a/jclklib/proxy/subscribe_msg.cpp b/jclklib/proxy/subscribe_msg.cpp index 5d1661ac..e0fc013f 100644 --- a/jclklib/proxy/subscribe_msg.cpp +++ b/jclklib/proxy/subscribe_msg.cpp @@ -43,7 +43,6 @@ bool ProxySubscribeMessage::initMessage() This is to process the subscription from the jclklib client runtime via POSIX msg queue [Question] The client list of real-time subscription is hold inside jcklib_proxy? */ -//bool ProxySubscribeMessage::processMessage(ClockConfiguration &config) PROCESS_MESSAGE_TYPE(ProxySubscribeMessage::processMessage) { //config.setEvent(subscription.getEvent()); @@ -51,13 +50,11 @@ PROCESS_MESSAGE_TYPE(ProxySubscribeMessage::processMessage) sessionId_t sID; sID = this->getc_sessionId(); - PrintDebug("[AZU] ProxySubscribeMessage::processMessage - Use current client session ID: " + to_string(sID)); + PrintDebug("[ProxySubscribeMessage]::processMessage - Use current client session ID: " + to_string(sID)); if(sID == InvalidSessionId) { PrintError("Session ID *should be* invalid for received proxy connect message"); - PrintDebug("[AZU] overwrite the sID to 0"); - sID = 0; - //return false; //azu hack + return false; } TxContext = Client::GetClientSession(sID).get()->get_transmitContext(); set_msgAck(ACK_SUCCESS); From a6bf8bd05b540f0edcf92e4ca32fb7d4929d0a55 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Tue, 23 Apr 2024 22:31:12 +0800 Subject: [PATCH 022/151] Subscription: Send back data from Proxy to Client When Proxy receive subscription message, send the initial state of PTP back to Client. Client will parse the data and print it out. Signed-off-by: Song Yoong Siang --- jclklib/client/subscribe_msg.cpp | 21 +++++++++++++++++++++ jclklib/client/subscribe_msg.hpp | 2 ++ jclklib/common/jclklib_import.hpp | 7 +++++++ jclklib/proxy/connect.cpp | 19 ++++++++----------- jclklib/proxy/subscribe_msg.cpp | 17 +++++++++++++++++ jclklib/proxy/subscribe_msg.hpp | 1 + 6 files changed, 56 insertions(+), 11 deletions(-) diff --git a/jclklib/client/subscribe_msg.cpp b/jclklib/client/subscribe_msg.cpp index fa3f9e3a..7dd70589 100644 --- a/jclklib/client/subscribe_msg.cpp +++ b/jclklib/client/subscribe_msg.cpp @@ -6,6 +6,7 @@ */ #include +#include #include using namespace JClkLibClient; @@ -40,6 +41,26 @@ bool ClientSubscribeMessage::initMessage() return true; } +PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { + JClkLibCommon::ptp_event data; + + PrintDebug("[ClientSubscribeMessage]::parseBuffer "); + if(!Message::parseBuffer(LxContext)) + return false; + + if (!PARSE_RX(FIELD, data, LxContext)) + return false; + + printf("master_offset = %ld, servo_state = %d ", data.master_offset, data.servo_state); + printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x ", + data.gmIdentity[0], data.gmIdentity[1],data.gmIdentity[2], + data.gmIdentity[3], data.gmIdentity[4], + data.gmIdentity[5], data.gmIdentity[6],data.gmIdentity[7]); + printf("asCapable = %d\n\n", data.asCapable); + + return true; +} + /** @brief process the reply for notification msg from proxy. * * This function will be called when the transport layer diff --git a/jclklib/client/subscribe_msg.hpp b/jclklib/client/subscribe_msg.hpp index a79ee528..2990ddff 100644 --- a/jclklib/client/subscribe_msg.hpp +++ b/jclklib/client/subscribe_msg.hpp @@ -39,6 +39,8 @@ namespace JClkLibClient * @return true */ static bool initMessage(); + + virtual PARSE_RXBUFFER_TYPE(parseBuffer); }; } diff --git a/jclklib/common/jclklib_import.hpp b/jclklib/common/jclklib_import.hpp index 4e764b53..f8f88084 100644 --- a/jclklib/common/jclklib_import.hpp +++ b/jclklib/common/jclklib_import.hpp @@ -97,6 +97,13 @@ namespace JClkLibCommon DECLARE_ACCESSOR(event); DECLARE_ACCESSOR(value); }; + + struct ptp_event { + int64_t master_offset; + uint8_t gmIdentity[8]; /* Grandmaster clock ID */ + int32_t asCapable; /* 802@.1AS Capable */ + uint8_t servo_state; + }; } #endif/*JCLKLIB_IMPORT_HPP*/ diff --git a/jclklib/proxy/connect.cpp b/jclklib/proxy/connect.cpp index af6445f2..02404305 100644 --- a/jclklib/proxy/connect.cpp +++ b/jclklib/proxy/connect.cpp @@ -41,24 +41,17 @@ struct port_info { bool local; }; -struct ptp_event { - int64_t master_offset; - ClockIdentity_t gmIdentity; /**< Grandmaster clock ID */ - Integer32_t asCapable; /**< Flag for 802@.1AS Capable */ - int64_t servo_state; -}; - int epd; struct epoll_event epd_event; SUBSCRIBE_EVENTS_NP_t d; -ptp_event pe; +JClkLibCommon::ptp_event pe; void event_handle() { const BaseMngTlv *data = msg.getData(); int64_t offset; ClockIdentity_t gm_uuid; - int64_t servo; + uint8_t servo; switch(msg.getTlvId()) { case TIME_STATUS_NP: offset = ((TIME_STATUS_NP_t *)data)->master_offset; @@ -67,10 +60,14 @@ void event_handle() pe.master_offset = offset; pe.servo_state = servo; - pe.gmIdentity = gm_uuid; + memcpy(pe.gmIdentity, gm_uuid.v, sizeof(pe.gmIdentity)); //TODO: Add debug flag checking, only print if the flag is set - printf("master_offset = %ld, servo_state = %ld, gmIdentity = %lx\n\n", pe.master_offset, pe.servo_state, pe.gmIdentity); + printf("master_offset = %ld, servo_state = %d ", pe.master_offset, pe.servo_state); + printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x\n\n", + pe.gmIdentity[0], pe.gmIdentity[1],pe.gmIdentity[2], + pe.gmIdentity[3], pe.gmIdentity[4], + pe.gmIdentity[5], pe.gmIdentity[6],pe.gmIdentity[7]); return; case PORT_DATA_SET_NP: pe.asCapable = ((PORT_DATA_SET_NP_t *)data)->asCapable; diff --git a/jclklib/proxy/subscribe_msg.cpp b/jclklib/proxy/subscribe_msg.cpp index e0fc013f..63dd31dc 100644 --- a/jclklib/proxy/subscribe_msg.cpp +++ b/jclklib/proxy/subscribe_msg.cpp @@ -9,11 +9,15 @@ #include #include #include +#include +#include using namespace std; using namespace JClkLibProxy; using namespace JClkLibCommon; +extern JClkLibCommon::ptp_event pe; + /** @brief Create the ProxySubscribeMessage object * * @param msg msg structure to be fill up @@ -39,6 +43,19 @@ bool ProxySubscribeMessage::initMessage() return true; } +BUILD_TXBUFFER_TYPE(ProxySubscribeMessage::makeBuffer) const +{ + PrintDebug("[ProxySubscribeMessage]::makeBuffer"); + if(!Message::makeBuffer(TxContext)) + return false; + + /* Add ptp data here */ + if (!WRITE_TX(FIELD, pe, TxContext)) + return false; + + return true; +} + /* This is to process the subscription from the jclklib client runtime via POSIX msg queue [Question] The client list of real-time subscription is hold inside jcklib_proxy? diff --git a/jclklib/proxy/subscribe_msg.hpp b/jclklib/proxy/subscribe_msg.hpp index 57a737ae..52d05621 100644 --- a/jclklib/proxy/subscribe_msg.hpp +++ b/jclklib/proxy/subscribe_msg.hpp @@ -20,6 +20,7 @@ namespace JClkLibProxy public: //bool processMessage(ClockConfiguration &config); virtual PROCESS_MESSAGE_TYPE(processMessage); + virtual BUILD_TXBUFFER_TYPE(makeBuffer) const; bool generateResponse(uint8_t *msgBuffer, std::size_t &length, const ClockStatus &status); /** From 34ef4c2ed24b2f73b684893b61cb60989541a449 Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Thu, 25 Apr 2024 15:59:17 +0800 Subject: [PATCH 023/151] Connect: Send ptp4l_id from Proxy to Client once ptp4l is connected Signed-off-by: Lai Peter Jun Ann --- jclklib/client/connect_msg.cpp | 17 +++++++++++++++++ jclklib/client/connect_msg.hpp | 1 + jclklib/client/subscribe_msg.cpp | 2 +- jclklib/common/jclklib_import.hpp | 1 + jclklib/proxy/connect.cpp | 12 +++++++----- jclklib/proxy/connect_msg.cpp | 22 ++++++++++++++++++++++ jclklib/proxy/connect_msg.hpp | 1 + jclklib/proxy/thread.cpp | 5 ++--- 8 files changed, 52 insertions(+), 9 deletions(-) diff --git a/jclklib/client/connect_msg.cpp b/jclklib/client/connect_msg.cpp index ef67267e..9c6719b8 100644 --- a/jclklib/client/connect_msg.cpp +++ b/jclklib/client/connect_msg.cpp @@ -7,6 +7,8 @@ #include #include +#include +#include using namespace JClkLibClient; using namespace JClkLibCommon; @@ -38,6 +40,21 @@ bool ClientConnectMessage::initMessage() return true; } +PARSE_RXBUFFER_TYPE(ClientConnectMessage::parseBuffer) { + JClkLibCommon::ptp_event data; + + PrintDebug("[ClientConnectMessage]::parseBuffer "); + if(!CommonConnectMessage::parseBuffer(LxContext)) + return false; + + if (!PARSE_RX(FIELD, data.ptp4l_id, LxContext)) + return false; + + printf("ptp4l_id = %d\n\n", data.ptp4l_id); + + return true; +} + /** @brief process the reply for connect msg from proxy. * * This function will be called when the transport layer diff --git a/jclklib/client/connect_msg.hpp b/jclklib/client/connect_msg.hpp index 7ca323d9..2deb14ad 100644 --- a/jclklib/client/connect_msg.hpp +++ b/jclklib/client/connect_msg.hpp @@ -32,6 +32,7 @@ namespace JClkLibClient * @return true */ virtual PROCESS_MESSAGE_TYPE(processMessage); + virtual PARSE_RXBUFFER_TYPE(parseBuffer); /** * @brief Create the ClientConnectMessage object diff --git a/jclklib/client/subscribe_msg.cpp b/jclklib/client/subscribe_msg.cpp index 7dd70589..9be7394b 100644 --- a/jclklib/client/subscribe_msg.cpp +++ b/jclklib/client/subscribe_msg.cpp @@ -56,7 +56,7 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { data.gmIdentity[0], data.gmIdentity[1],data.gmIdentity[2], data.gmIdentity[3], data.gmIdentity[4], data.gmIdentity[5], data.gmIdentity[6],data.gmIdentity[7]); - printf("asCapable = %d\n\n", data.asCapable); + printf("asCapable = %d, ptp4l_id = %d\n\n", data.asCapable, data.ptp4l_id); return true; } diff --git a/jclklib/common/jclklib_import.hpp b/jclklib/common/jclklib_import.hpp index f8f88084..cd675c06 100644 --- a/jclklib/common/jclklib_import.hpp +++ b/jclklib/common/jclklib_import.hpp @@ -103,6 +103,7 @@ namespace JClkLibCommon uint8_t gmIdentity[8]; /* Grandmaster clock ID */ int32_t asCapable; /* 802@.1AS Capable */ uint8_t servo_state; + uint8_t ptp4l_id; }; } diff --git a/jclklib/proxy/connect.cpp b/jclklib/proxy/connect.cpp index 02404305..a4fb2a93 100644 --- a/jclklib/proxy/connect.cpp +++ b/jclklib/proxy/connect.cpp @@ -36,7 +36,6 @@ static std::unique_ptr m_sk; struct port_info { PortIdentity_t portid; - std::string interface; int64_t master_offset; bool local; }; @@ -44,7 +43,7 @@ struct port_info { int epd; struct epoll_event epd_event; SUBSCRIBE_EVENTS_NP_t d; -JClkLibCommon::ptp_event pe; +JClkLibCommon::ptp_event pe = { 0, {0, 0, 0, 0, 0, 0, 0, 0}, 0 , 0 , 0}; void event_handle() { @@ -216,18 +215,21 @@ int Connect::connect() MsgParams prms = msg.getParams(); prms.boundaryHops = 0; - std::string interface; std::unique_ptr m_sk; std::string uds_address; - //TODO: hard-coded the interface - interface = "enp1s0"; SockUnix *sku = new SockUnix; if(sku == nullptr) { return -1; } m_sk.reset(sku); + while (system("ls /var/run/ptp4l*") != 0) { + //sleep for 2 seconds and keep looping until there is ptp4l available + sleep(2); + } + pe.ptp4l_id = 1; + //TODO: hard-coded uds_socket uds_address = "/var/run/ptp4l"; if(!sku->setDefSelfAddress() || !sku->init() || diff --git a/jclklib/proxy/connect_msg.cpp b/jclklib/proxy/connect_msg.cpp index b23b4b4e..f4154873 100644 --- a/jclklib/proxy/connect_msg.cpp +++ b/jclklib/proxy/connect_msg.cpp @@ -8,11 +8,16 @@ #include #include #include +#include +#include +#include using namespace std; using namespace JClkLibProxy; using namespace JClkLibCommon; +extern JClkLibCommon::ptp_event pe; + /** @brief Create the ProxyConnectMessage object * * @param msg msg structure to be fill up @@ -63,6 +68,11 @@ PROCESS_MESSAGE_TYPE(ProxyConnectMessage::processMessage) return false; } + /* check whether there is ptp4l available */ + if (!pe.ptp4l_id) { + return false; + } + newSessionId = Client::CreateClientSession(); PrintDebug("Created new client session ID: " + to_string(newSessionId)); this->set_sessionId(newSessionId); @@ -73,3 +83,15 @@ PROCESS_MESSAGE_TYPE(ProxyConnectMessage::processMessage) return true; } +BUILD_TXBUFFER_TYPE(ProxyConnectMessage::makeBuffer) const +{ + PrintDebug("[ProxyConnectMessage]::makeBuffer"); + if(!CommonConnectMessage::makeBuffer(TxContext)) + return false; + + /* Add ptp4l_id here */ + if (!WRITE_TX(FIELD, pe.ptp4l_id, TxContext)) + return false; + + return true; +} \ No newline at end of file diff --git a/jclklib/proxy/connect_msg.hpp b/jclklib/proxy/connect_msg.hpp index 86745316..41470350 100644 --- a/jclklib/proxy/connect_msg.hpp +++ b/jclklib/proxy/connect_msg.hpp @@ -25,6 +25,7 @@ namespace JClkLibProxy * @return true */ virtual PROCESS_MESSAGE_TYPE(processMessage); + virtual BUILD_TXBUFFER_TYPE(makeBuffer) const; bool generateResponse(uint8_t *msgBuffer, std::size_t &length, const ClockStatus &status) diff --git a/jclklib/proxy/thread.cpp b/jclklib/proxy/thread.cpp index 2c99bdc7..36200cfc 100644 --- a/jclklib/proxy/thread.cpp +++ b/jclklib/proxy/thread.cpp @@ -182,7 +182,8 @@ int connect_ptp4l( struct ptp4l_handle **phandle, struct epoll_event epd_event, { struct ptp4l_handle *handle; int ret; - char *path; + //TODO: hard-coded for now + char path[] = "/var/run/ptp4l"; handle = (typeof( handle)) malloc(( size_t) sizeof(*handle)); if( handle == NULL) { @@ -193,8 +194,6 @@ int connect_ptp4l( struct ptp4l_handle **phandle, struct epoll_event epd_event, memset( &handle->server_addr, 0, sizeof( handle->server_addr)); handle->server_addr.sun_family = AF_LOCAL; - //TODO: hard-coded for now - path = "/var/run/ptp4l"; strncpy( handle->server_addr.sun_path, path, sizeof( handle->server_addr.sun_path ) - 1); From ab3faa8f4073deade05c2f189573d56b84614299 Mon Sep 17 00:00:00 2001 From: Noor Azura Ahmad Tarmizi Date: Thu, 2 May 2024 02:11:55 -0400 Subject: [PATCH 024/151] feature: Using CommonSubscribe make and parse message for Client and proxy sub msg This is to ensure the whole message with the data : Msgid, msgack, jcl_subscription, ptp_event struct are sent by the proxy and received correctly by the Client. Signed-off-by: Noor Azura Ahmad Tarmizi --- jclklib/client/subscribe_msg.cpp | 2 +- jclklib/proxy/subscribe_msg.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jclklib/client/subscribe_msg.cpp b/jclklib/client/subscribe_msg.cpp index 9be7394b..76cb8e91 100644 --- a/jclklib/client/subscribe_msg.cpp +++ b/jclklib/client/subscribe_msg.cpp @@ -45,7 +45,7 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { JClkLibCommon::ptp_event data; PrintDebug("[ClientSubscribeMessage]::parseBuffer "); - if(!Message::parseBuffer(LxContext)) + if(!CommonSubscribeMessage::parseBuffer(LxContext)) return false; if (!PARSE_RX(FIELD, data, LxContext)) diff --git a/jclklib/proxy/subscribe_msg.cpp b/jclklib/proxy/subscribe_msg.cpp index 63dd31dc..cace2576 100644 --- a/jclklib/proxy/subscribe_msg.cpp +++ b/jclklib/proxy/subscribe_msg.cpp @@ -46,7 +46,7 @@ bool ProxySubscribeMessage::initMessage() BUILD_TXBUFFER_TYPE(ProxySubscribeMessage::makeBuffer) const { PrintDebug("[ProxySubscribeMessage]::makeBuffer"); - if(!Message::makeBuffer(TxContext)) + if(!CommonSubscribeMessage::makeBuffer(TxContext)) return false; /* Add ptp data here */ From 9f97c700cfd0974973f8fe0cdce1ab7d04801e6d Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Mon, 29 Apr 2024 18:11:31 +0800 Subject: [PATCH 025/151] Subscribe: Write the ptp4l event into client's struct Signed-off-by: Lai Peter Jun Ann --- jclklib/client/subscribe_msg.cpp | 32 +++++++++++++++++++++++++++++++ jclklib/common/jclklib_import.hpp | 15 +++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/jclklib/client/subscribe_msg.cpp b/jclklib/client/subscribe_msg.cpp index 76cb8e91..900bd433 100644 --- a/jclklib/client/subscribe_msg.cpp +++ b/jclklib/client/subscribe_msg.cpp @@ -13,6 +13,8 @@ using namespace JClkLibClient; using namespace JClkLibCommon; using namespace std; +JClkLibCommon::client_ptp_event client_data; + /** @brief Create the ClientSubscribeMessage object * * @param msg msg structure to be fill up @@ -58,6 +60,36 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { data.gmIdentity[5], data.gmIdentity[6],data.gmIdentity[7]); printf("asCapable = %d, ptp4l_id = %d\n\n", data.asCapable, data.ptp4l_id); + if (data.master_offset != client_data.master_offset) { + client_data.master_offset = data.master_offset; + if ((client_data.master_offset > client_data.master_offset_low) && (client_data.master_offset < client_data.master_offset_high)) { + client_data.master_offset_within_boundary = true; + client_data.offset_event_count.fetch_add(1, std::memory_order_relaxed) + 1; // Atomic increment + } + } + + if (data.servo_state != client_data.servo_state) { + client_data.servo_state = data.servo_state; + client_data.servo_state_event_count.fetch_add(1, std::memory_order_relaxed); // Atomic increment + } + + if (memcmp(client_data.gmIdentity, data.gmIdentity, sizeof(data.gmIdentity)) != 0) { + memcpy(client_data.gmIdentity, data.gmIdentity, sizeof(data.gmIdentity)); + client_data.gmIdentity_event_count.fetch_add(1, std::memory_order_relaxed); // Atomic increment + } + + if (data.asCapable != client_data.asCapable) { + client_data.asCapable = data.asCapable; + client_data.asCapable_event_count.fetch_add(1, std::memory_order_relaxed); // Atomic increment + } + + printf("CLIENT master_offset = %ld, servo_state = %d ", data.master_offset, data.servo_state); + printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x ", + client_data.gmIdentity[0], client_data.gmIdentity[1],client_data.gmIdentity[2], + client_data.gmIdentity[3], client_data.gmIdentity[4], + client_data.gmIdentity[5], client_data.gmIdentity[6],client_data.gmIdentity[7]); + printf("asCapable = %d\n\n", data.asCapable); + return true; } diff --git a/jclklib/common/jclklib_import.hpp b/jclklib/common/jclklib_import.hpp index cd675c06..d447e5a9 100644 --- a/jclklib/common/jclklib_import.hpp +++ b/jclklib/common/jclklib_import.hpp @@ -105,6 +105,21 @@ namespace JClkLibCommon uint8_t servo_state; uint8_t ptp4l_id; }; + + struct client_ptp_event { + int64_t master_offset; + int64_t master_offset_low; + int64_t master_offset_high; + bool master_offset_within_boundary; + uint8_t gmIdentity[8]; /* Grandmaster clock ID */ + int32_t asCapable; /* 802@.1AS Capable */ + uint8_t servo_state; + uint8_t ptp4l_id; + std::atomic offset_event_count{}; + std::atomic gmIdentity_event_count{}; + std::atomic asCapable_event_count{}; + std::atomic servo_state_event_count{}; + }; } #endif/*JCLKLIB_IMPORT_HPP*/ From f096580e9faf25cf9a6cc458a449912ba20aa615 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Tue, 30 Apr 2024 17:34:51 +0800 Subject: [PATCH 026/151] Add notification message Proxy will send notification message to client to report the latest data it received from ptp4l. Signed-off-by: Song Yoong Siang --- jclklib/client/Makefile | 4 +- jclklib/client/message.cpp | 4 +- jclklib/client/notification_msg.cpp | 72 +++++++++++++++++++++++++++++ jclklib/client/notification_msg.hpp | 47 +++++++++++++++++++ jclklib/client/test.cpp | 19 +++++++- jclklib/common/notification_msg.cpp | 11 +++-- jclklib/common/notification_msg.hpp | 5 +- jclklib/proxy/Makefile | 2 +- jclklib/proxy/client.cpp | 10 ++++ jclklib/proxy/client.hpp | 1 + jclklib/proxy/connect.cpp | 37 +++++++++++++-- jclklib/proxy/message.cpp | 3 +- jclklib/proxy/notification_msg.cpp | 57 ++++++++++++++++++----- jclklib/proxy/notification_msg.hpp | 23 +++++++-- 14 files changed, 263 insertions(+), 32 deletions(-) create mode 100644 jclklib/client/notification_msg.cpp create mode 100644 jclklib/client/notification_msg.hpp diff --git a/jclklib/client/Makefile b/jclklib/client/Makefile index 8991e0a5..f29d8d85 100644 --- a/jclklib/client/Makefile +++ b/jclklib/client/Makefile @@ -10,8 +10,8 @@ JCLKLIB_TOPLEVEL_DIR = $(JCLKLIB_CLIENT_DIR)/.. JCLKLIB_COMMON_DIR = $(JCLKLIB_TOPLEVEL_DIR)/common LIBS = pthread rt LIBS_FLAGS = $(foreach lib,$(LIBS),-l$(lib)) -OBJ = init msgq_tport message null_tport transport msgq_tport connect_msg client_state subscribe_msg -COMMON_OBJ = print sighandler transport msgq_tport message connect_msg subscribe_msg jclklib_import +OBJ = init msgq_tport message null_tport transport msgq_tport notification_msg connect_msg client_state subscribe_msg +COMMON_OBJ = print sighandler transport msgq_tport message connect_msg subscribe_msg notification_msg jclklib_import OBJ_FILES = $(foreach f,$(OBJ),$(f).o) DEPENDS = $(foreach f,$(OBJ),$(f).d) COMMON_OBJ_DIR = $(JCLKLIB_COMMON_DIR)/obj diff --git a/jclklib/client/message.cpp b/jclklib/client/message.cpp index e1372fc0..9ca8d0a9 100644 --- a/jclklib/client/message.cpp +++ b/jclklib/client/message.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include using namespace JClkLibClient; @@ -16,5 +17,6 @@ using namespace JClkLibClient; bool ClientMessage::init() { PrintDebug("Initializing Client Message"); - return JClkLibCommon::_initMessage(); + return JClkLibCommon::_initMessage(); } diff --git a/jclklib/client/notification_msg.cpp b/jclklib/client/notification_msg.cpp new file mode 100644 index 00000000..3c35b469 --- /dev/null +++ b/jclklib/client/notification_msg.cpp @@ -0,0 +1,72 @@ +/*! \file notification_msg.cpp + \brief Client notification message implementation. Implements client specific notification message function. + + (C) Copyright Intel Corporation 2024. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include +#include +#include +#include + +using namespace std; +using namespace JClkLibCommon; +using namespace JClkLibClient; + +/** @brief Create the ClientNotificationMessage object + * + * @param msg msg structure to be fill up + * @param LxContext proxy transport listener context + * @return true + */ +MAKE_RXBUFFER_TYPE(ClientNotificationMessage::buildMessage) +{ + msg = new ClientNotificationMessage(); + return true; +} + +/** @brief Add proxy's NOTIFY_MESSAGE type and its builder to transport layer. + * + * This function will be called during init to add a map of NOTIFY_MESSAGE + * type and its corresponding buildMessage function. + * + * @return true + */ +bool ClientNotificationMessage::initMessage() +{ + addMessageType(parseMsgMapElement_t(NOTIFY_MESSAGE, buildMessage)); + return true; +} + +BUILD_TXBUFFER_TYPE(ClientNotificationMessage::makeBuffer) const +{ + PrintDebug("[ClientNotificationMessage]::makeBuffer"); + + return true; +} + +PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) +{ + return true; +} + +PARSE_RXBUFFER_TYPE(ClientNotificationMessage::parseBuffer) +{ + ptp_event data; + + PrintDebug("[ClientNotificationMessage]::parseBuffer "); + if(!Message::parseBuffer(LxContext)) + return false; + + if (!PARSE_RX(FIELD, data, LxContext)) + return false; + + printf("master_offset = %ld, servo_state = %d ", data.master_offset, data.servo_state); + printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x ", + data.gmIdentity[0], data.gmIdentity[1],data.gmIdentity[2], + data.gmIdentity[3], data.gmIdentity[4], + data.gmIdentity[5], data.gmIdentity[6],data.gmIdentity[7]); + printf("asCapable = %d\n\n", data.asCapable); + return true; +} diff --git a/jclklib/client/notification_msg.hpp b/jclklib/client/notification_msg.hpp new file mode 100644 index 00000000..d01d22d7 --- /dev/null +++ b/jclklib/client/notification_msg.hpp @@ -0,0 +1,47 @@ +/*! \file notification_msg.hpp + \brief Client notification message class. Implements client specific notification message function. + + (C) Copyright Intel Corporation 2024. All rights reserved. Intel Confidential. + Author: Christopher Hall +*/ + +#include + +#ifndef CLIENT_NOTIFICATION_MSG_HPP +#define CLIENT_NOTIFICATION_MSG_HPP + +#include +#include +#include + +namespace JClkLibClient +{ + class ClientNotificationMessage : virtual public ClientMessage, + virtual public JClkLibCommon::NotificationMessage + { + public: + virtual PROCESS_MESSAGE_TYPE(processMessage); + virtual BUILD_TXBUFFER_TYPE(makeBuffer) const; + + /** + * @brief Create the ClientNotificationMessage object + * @param msg msg structure to be fill up + * @param LxContext client transport listener context + * @return true + */ + static MAKE_RXBUFFER_TYPE(buildMessage); + + /** + * @brief Add client's NOTIFY_MESSAGE type and its builder to transport layer. + * @return true + */ + static bool initMessage(); + + virtual PARSE_RXBUFFER_TYPE(parseBuffer); + + protected: + ClientNotificationMessage() : MESSAGE_NOTIFY() {} + }; +} + +#endif/*CLIENT_NOTIFICATION_MSG_HPP*/ diff --git a/jclklib/client/test.cpp b/jclklib/client/test.cpp index 850ae6ac..8c21b812 100644 --- a/jclklib/client/test.cpp +++ b/jclklib/client/test.cpp @@ -13,17 +13,29 @@ #include #include #include +#include using namespace JClkLibClient; using namespace JClkLibCommon; using namespace std; +volatile sig_atomic_t signal_flag = 0; + +void signal_handler(int sig) +{ + signal_flag = 1; +} + int main() { int ret = EXIT_SUCCESS; JClkLibCommon::jcl_subscription sub; std::uint32_t event2Sub1[1] = {((1< #include +#include using namespace JClkLibCommon; using namespace std; -MAKE_RXBUFFER_TYPE(NotificationMessage::buildMessage) +TRANSMIT_MESSAGE_TYPE(NotificationMessage::transmitMessage) { - // Fill in the fields - - return true; + PrintDebug("[NotificationMessage]::transmitMessage "); + if (!presendMessage(&TxContext)) + return false; + + return TxContext.sendBuffer(); } diff --git a/jclklib/common/notification_msg.hpp b/jclklib/common/notification_msg.hpp index 1df6ab46..1c24730d 100644 --- a/jclklib/common/notification_msg.hpp +++ b/jclklib/common/notification_msg.hpp @@ -12,14 +12,15 @@ #include #include +#include namespace JClkLibCommon { - class NotificationMessage : public Message + class NotificationMessage : virtual public Message { public: + virtual TRANSMIT_MESSAGE_TYPE(transmitMessage); static msgId_t getMsgId() { return SUBSCRIBE_MSG; } - static MAKE_RXBUFFER_TYPE(buildMessage); const jcl_eventcount &getEventCount(); const jcl_event &getEvent(); diff --git a/jclklib/proxy/Makefile b/jclklib/proxy/Makefile index 735f22f1..95926ce0 100644 --- a/jclklib/proxy/Makefile +++ b/jclklib/proxy/Makefile @@ -11,7 +11,7 @@ JCLKLIB_COMMON_DIR = $(JCLKLIB_TOPLEVEL_DIR)/common LIBS = pthread rt ptpmgmt LIBS_FLAGS = $(foreach lib,$(LIBS),-l$(lib)) OBJ = client main message msgq_tport notification_msg null_tport connect_msg subscribe_msg transport connect thread -COMMON_OBJ = print sighandler transport msgq_tport jclklib_import message connect_msg subscribe_msg +COMMON_OBJ = print sighandler transport msgq_tport jclklib_import message connect_msg subscribe_msg notification_msg OBJ_FILES = $(foreach f,$(OBJ),$(f).o) DEPENDS = $(foreach f,$(OBJ),$(f).d) COMMON_OBJ_DIR = $(JCLKLIB_COMMON_DIR)/obj diff --git a/jclklib/proxy/client.cpp b/jclklib/proxy/client.cpp index 63c465d7..444979f0 100644 --- a/jclklib/proxy/client.cpp +++ b/jclklib/proxy/client.cpp @@ -16,6 +16,16 @@ sessionId_t Client::CreateClientSession() return nextSession; } +sessionId_t Client::GetSessionIdAt(size_t index) +{ + if (index < SessionMap.size()) { + auto iter = SessionMap.begin(); + std::advance(iter, index); + return iter->first; + } + return InvalidSessionId; +} + ClientX Client::GetClientSession(sessionId_t sessionId) { auto iter = SessionMap.find(sessionId); diff --git a/jclklib/proxy/client.hpp b/jclklib/proxy/client.hpp index 904a78a6..b0b2b62a 100644 --- a/jclklib/proxy/client.hpp +++ b/jclklib/proxy/client.hpp @@ -18,6 +18,7 @@ namespace JClkLibProxy { static std::map SessionMap; public: static JClkLibCommon::sessionId_t CreateClientSession(); + static JClkLibCommon::sessionId_t GetSessionIdAt(size_t index); static ClientX GetClientSession(JClkLibCommon::sessionId_t sessionId); private: std::unique_ptr transmitContext; diff --git a/jclklib/proxy/connect.cpp b/jclklib/proxy/connect.cpp index a4fb2a93..0b78b959 100644 --- a/jclklib/proxy/connect.cpp +++ b/jclklib/proxy/connect.cpp @@ -15,6 +15,9 @@ #include #include #include +#include +#include +#include //TODO: subsription part #include "thread.hpp" @@ -45,6 +48,32 @@ struct epoll_event epd_event; SUBSCRIBE_EVENTS_NP_t d; JClkLibCommon::ptp_event pe = { 0, {0, 0, 0, 0, 0, 0, 0, 0}, 0 , 0 , 0}; +void notify_client() +{ + PrintDebug("[JClkLibProxy]::notify_client"); + JClkLibCommon::sessionId_t SessionId; + std::unique_ptr notifyMsg(new ProxyNotificationMessage()); + + ProxyNotificationMessage *pmsg = dynamic_cast(notifyMsg.get()); + if (pmsg == NULL) { + PrintErrorCode("[JClkLibProxy::notify_client] notifyMsg is NULL !!\n"); + return; + } + + PrintDebug("[JClkLibProxy::notify_client] notifyMsg creation is OK !!\n"); + + /* ToDo: loop for multiple sessions */ + SessionId = Client::GetSessionIdAt(0); + if (SessionId != JClkLibCommon::InvalidSessionId) { + PrintDebug("Get client session ID: " + to_string(SessionId)); + + auto TxContext = Client::GetClientSession(SessionId).get()->get_transmitContext(); + pmsg->transmitMessage(*TxContext); + } else { + PrintDebug("Unable to get Session ID"); + } +} + void event_handle() { const BaseMngTlv *data = msg.getData(); @@ -67,14 +96,16 @@ void event_handle() pe.gmIdentity[0], pe.gmIdentity[1],pe.gmIdentity[2], pe.gmIdentity[3], pe.gmIdentity[4], pe.gmIdentity[5], pe.gmIdentity[6],pe.gmIdentity[7]); - return; + break; case PORT_DATA_SET_NP: pe.asCapable = ((PORT_DATA_SET_NP_t *)data)->asCapable; printf("asCapable = %d\n\n", pe.asCapable); - return; + break; default: - return; + break; } + + notify_client(); } static inline bool msg_send(bool local) diff --git a/jclklib/proxy/message.cpp b/jclklib/proxy/message.cpp index e8f7b0de..0bf80fdd 100644 --- a/jclklib/proxy/message.cpp +++ b/jclklib/proxy/message.cpp @@ -8,13 +8,14 @@ #include #include #include +#include using namespace JClkLibProxy; using namespace JClkLibCommon; bool ProxyMessage::init() { - return _initMessage(); + return _initMessage(); } diff --git a/jclklib/proxy/notification_msg.cpp b/jclklib/proxy/notification_msg.cpp index 0e8c22ae..b2812853 100644 --- a/jclklib/proxy/notification_msg.cpp +++ b/jclklib/proxy/notification_msg.cpp @@ -1,27 +1,62 @@ /*! \file notification_msg.cpp - \brief Proxy connect message implementation. Implements proxy specific connect message function. + \brief Proxy notification message implementation. Implements proxy specific notification message function. - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + (C) Copyright Intel Corporation 2024. All rights reserved. Intel Confidential. Author: Christopher Hall */ #include #include #include +#include +#include +using namespace std; +using namespace JClkLibCommon; using namespace JClkLibProxy; +extern JClkLibCommon::ptp_event pe; -/* -* [Azu] This is to send notification from Proxy to subscribed client upon state change -* This shd be in the RX buffer - so this shd be inside the client to process -* notification from proxy. -*/ -/* TO BE REMOVED */ -bool ProxyNotificationMessage::processMessage(ClockConfiguration &config) +/** @brief Create the ProxyNotificationMessage object + * + * @param msg msg structure to be fill up + * @param LxContext proxy transport listener context + * @return true + */ +MAKE_RXBUFFER_TYPE(ProxyNotificationMessage::buildMessage) { - //config.setWait( waitEnable ); + msg = new ProxyNotificationMessage(); + return true; +} +/** @brief Add proxy's NOTIFY_MESSAGE type and its builder to transport layer. + * + * This function will be called during init to add a map of NOTIFY_MESSAGE + * type and its corresponding buildMessage function. + * + * @return true + */ +bool ProxyNotificationMessage::initMessage() +{ + addMessageType(parseMsgMapElement_t(NOTIFY_MESSAGE, buildMessage)); + return true; +} + +BUILD_TXBUFFER_TYPE(ProxyNotificationMessage::makeBuffer) const +{ + PrintDebug("[ProxyNotificationMessage]::makeBuffer"); + if(!Message::makeBuffer(TxContext)) + return false; + + /* Add ptp data here */ + if (!WRITE_TX(FIELD, pe, TxContext)) + return false; + + return true; +} + +PROCESS_MESSAGE_TYPE(ProxyNotificationMessage::processMessage) +{ return true; } @@ -33,5 +68,3 @@ bool ProxyNotificationMessage::generateResponse(uint8_t *msgBuffer, size_t &leng { return false; } - - diff --git a/jclklib/proxy/notification_msg.hpp b/jclklib/proxy/notification_msg.hpp index 48b436d5..23ce2e83 100644 --- a/jclklib/proxy/notification_msg.hpp +++ b/jclklib/proxy/notification_msg.hpp @@ -1,7 +1,7 @@ /*! \file notification_msg.hpp - \brief Proxy connect message class. Implements proxy specific connect message function. + \brief Proxy notification message class. Implements proxy specific notification message function. - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. + (C) Copyright Intel Corporation 2024. All rights reserved. Intel Confidential. Author: Christopher Hall */ @@ -20,12 +20,25 @@ namespace JClkLibProxy virtual public JClkLibCommon::NotificationMessage { public: - bool processMessage(ClockConfiguration &config); + ProxyNotificationMessage() : MESSAGE_NOTIFY() {} + virtual PROCESS_MESSAGE_TYPE(processMessage); bool generateResponse(std::uint8_t *msgBuffer, std::size_t &length, const ClockStatus &status); + virtual BUILD_TXBUFFER_TYPE(makeBuffer) const; - protected: - ProxyNotificationMessage() : MESSAGE_NOTIFY() {} + /** + * @brief Create the ProxyNotificationMessage object + * @param msg msg structure to be fill up + * @param LxContext proxy transport listener context + * @return true + */ + static MAKE_RXBUFFER_TYPE(buildMessage); + + /** + * @brief Add proxy's NOTIFY_MESSAGE type and its builder to transport layer. + * @return true + */ + static bool initMessage(); }; } From 8d893fa1bae18bf70da21166be7ee186ce6ddee9 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 2 May 2024 11:56:07 +0800 Subject: [PATCH 027/151] jclklib: Remove less -R from Makefile This commit removes the less -R command from the default target in the Makefile of client, common and proxy. The less -R command was originally used to paginate the output of the make command. However, this caused an issue where the build process would pause until the user manually quit less by pressing "q". This is not a typical or recommended use of less, especially in a Makefile. less is designed for interactive use in a shell to view the contents of a file or the output of a command page by page. In a Makefile, it can cause problems if the Makefile is run in a non-interactive environment where there's no user to scroll through the pages. Signed-off-by: Song Yoong Siang --- jclklib/client/Makefile | 2 +- jclklib/common/Makefile | 2 +- jclklib/proxy/Makefile | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jclklib/client/Makefile b/jclklib/client/Makefile index f29d8d85..50622dc8 100644 --- a/jclklib/client/Makefile +++ b/jclklib/client/Makefile @@ -20,7 +20,7 @@ REAL_TARGETS = jclklib.so test .PHONY: default default: - $(MAKE) -s -C $(JCLKLIB_CLIENT_DIR) build-all 2>&1 | less -R + $(MAKE) -s -C $(JCLKLIB_CLIENT_DIR) build-all 2>&1 .PHONY: build-prep build-prep: diff --git a/jclklib/common/Makefile b/jclklib/common/Makefile index e8229ad8..14acaf2a 100644 --- a/jclklib/common/Makefile +++ b/jclklib/common/Makefile @@ -17,7 +17,7 @@ OBJ_DIR = $(JCLKLIB_COMMON_DIR)/obj .PHONY: default default: - $(MAKE) -s -C $(JCLKLIB_COMMON_DIR) build-all 2>&1 | less -R + $(MAKE) -s -C $(JCLKLIB_COMMON_DIR) build-all 2>&1 .PHONY: build-prep build-prep: diff --git a/jclklib/proxy/Makefile b/jclklib/proxy/Makefile index 95926ce0..14a3153b 100644 --- a/jclklib/proxy/Makefile +++ b/jclklib/proxy/Makefile @@ -20,7 +20,7 @@ REAL_TARGETS = jclklib_proxy .PHONY: default default: - $(MAKE) -s -C $(JCLKLIB_PROXY_DIR) build-all 2>&1 | less -R + $(MAKE) -s -C $(JCLKLIB_PROXY_DIR) build-all 2>&1 .PHONY: build-prep build-prep: From c5fd76d65219460c50ca0a8c48ed202da2807314 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 2 May 2024 13:17:39 +0800 Subject: [PATCH 028/151] jclklib: client: temporary disable BlockStopSignal() Will add back when we figure out why we need it. Signed-off-by: Song Yoong Siang --- jclklib/client/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jclklib/client/init.cpp b/jclklib/client/init.cpp index e838af7d..f6512569 100644 --- a/jclklib/client/init.cpp +++ b/jclklib/client/init.cpp @@ -32,7 +32,7 @@ bool JClkLibClient::connect() unsigned int timeout_sec = (unsigned int) DEFAULT_CONNECT_TIME_OUT; Message0 connectMsg(new ClientConnectMessage()); - BlockStopSignal(); + //BlockStopSignal(); if(!ClientMessage::init()) { PrintError("Client Message Init Failed"); return false; From 6102431e766b52ee52c2a75e081fa98eed3c9706 Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Thu, 2 May 2024 14:07:59 +0800 Subject: [PATCH 029/151] Process notification message and add event count Signed-off-by: Lai Peter Jun Ann --- jclklib/client/notification_msg.cpp | 57 +++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/jclklib/client/notification_msg.cpp b/jclklib/client/notification_msg.cpp index 3c35b469..0f1f9621 100644 --- a/jclklib/client/notification_msg.cpp +++ b/jclklib/client/notification_msg.cpp @@ -14,6 +14,9 @@ using namespace std; using namespace JClkLibCommon; using namespace JClkLibClient; +JClkLibCommon::client_ptp_event client_ptp_data; +JClkLibCommon::ptp_event proxy_data; + /** @brief Create the ClientNotificationMessage object * * @param msg msg structure to be fill up @@ -48,25 +51,63 @@ BUILD_TXBUFFER_TYPE(ClientNotificationMessage::makeBuffer) const PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) { + PrintDebug("[ClientNotificationMessage]::processMessage "); + if (proxy_data.master_offset != client_ptp_data.master_offset) { + client_ptp_data.master_offset = proxy_data.master_offset; + if ((client_ptp_data.master_offset > client_ptp_data.master_offset_low) && (client_ptp_data.master_offset < client_ptp_data.master_offset_high)) { + client_ptp_data.master_offset_within_boundary = true; + client_ptp_data.offset_event_count.fetch_add(1, std::memory_order_relaxed); + } + } + + if (proxy_data.servo_state != client_ptp_data.servo_state) { + client_ptp_data.servo_state = proxy_data.servo_state; + client_ptp_data.servo_state_event_count.fetch_add(1, std::memory_order_relaxed); + } + + if (memcmp(client_ptp_data.gmIdentity, proxy_data.gmIdentity, sizeof(proxy_data.gmIdentity)) != 0) { + memcpy(client_ptp_data.gmIdentity, proxy_data.gmIdentity, sizeof(proxy_data.gmIdentity)); + client_ptp_data.gmIdentity_event_count.fetch_add(1, std::memory_order_relaxed); + } + + if (proxy_data.asCapable != client_ptp_data.asCapable) { + client_ptp_data.asCapable = proxy_data.asCapable; + client_ptp_data.asCapable_event_count.fetch_add(1, std::memory_order_relaxed); + } + + // Load the value of event_count atomically for TESTING only, will be remove later + int offset_event_count = client_ptp_data.offset_event_count; + int gmIdentity_event_count = client_ptp_data.gmIdentity_event_count; + int asCapable_event_count = client_ptp_data.asCapable_event_count; + int servo_state_event_count = client_ptp_data.servo_state_event_count; + + printf("CLIENT master_offset = %ld, servo_state = %d ", client_ptp_data.master_offset, client_ptp_data.servo_state); + printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x ", + client_ptp_data.gmIdentity[0], client_ptp_data.gmIdentity[1],client_ptp_data.gmIdentity[2], + client_ptp_data.gmIdentity[3], client_ptp_data.gmIdentity[4], + client_ptp_data.gmIdentity[5], client_ptp_data.gmIdentity[6],client_ptp_data.gmIdentity[7]); + printf("asCapable = %d\n\n", client_ptp_data.asCapable); + printf("CLIENT offset_event_count = %d, gmIdentity_event_count = %d, asCapable_event_count = %d, servo_state_event_count = %d\n\n", offset_event_count, gmIdentity_event_count, asCapable_event_count, servo_state_event_count); + return true; } PARSE_RXBUFFER_TYPE(ClientNotificationMessage::parseBuffer) { - ptp_event data; - PrintDebug("[ClientNotificationMessage]::parseBuffer "); if(!Message::parseBuffer(LxContext)) return false; - if (!PARSE_RX(FIELD, data, LxContext)) + if (!PARSE_RX(FIELD, proxy_data, LxContext)) return false; - printf("master_offset = %ld, servo_state = %d ", data.master_offset, data.servo_state); + printf("master_offset = %ld, servo_state = %d ", proxy_data.master_offset, proxy_data.servo_state); printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x ", - data.gmIdentity[0], data.gmIdentity[1],data.gmIdentity[2], - data.gmIdentity[3], data.gmIdentity[4], - data.gmIdentity[5], data.gmIdentity[6],data.gmIdentity[7]); - printf("asCapable = %d\n\n", data.asCapable); + proxy_data.gmIdentity[0], proxy_data.gmIdentity[1],proxy_data.gmIdentity[2], + proxy_data.gmIdentity[3], proxy_data.gmIdentity[4], + proxy_data.gmIdentity[5], proxy_data.gmIdentity[6],proxy_data.gmIdentity[7]); + printf("asCapable = %d\n\n", proxy_data.asCapable); + + return true; } From a55dcdcf0b86f1bc11ed4d6b7261cb0a56c2361a Mon Sep 17 00:00:00 2001 From: Noor Azura Ahmad Tarmizi Date: Thu, 2 May 2024 12:18:07 -0400 Subject: [PATCH 030/151] ptp4l_event: Adding gmpresent in the ptp event structure Signed-off-by: Noor Azura Ahmad Tarmizi --- jclklib/client/subscribe_msg.cpp | 11 ++++++++--- jclklib/common/jclklib_import.hpp | 12 ++++++++++++ jclklib/proxy/connect.cpp | 4 ++-- jclklib/proxy/thread.cpp | 1 + jclklib/proxy/thread.hpp | 11 ++--------- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/jclklib/client/subscribe_msg.cpp b/jclklib/client/subscribe_msg.cpp index 900bd433..e2f724a5 100644 --- a/jclklib/client/subscribe_msg.cpp +++ b/jclklib/client/subscribe_msg.cpp @@ -13,7 +13,7 @@ using namespace JClkLibClient; using namespace JClkLibCommon; using namespace std; -JClkLibCommon::client_ptp_event client_data; +JClkLibCommon::client_ptp_event client_data = {}; /** @brief Create the ClientSubscribeMessage object * @@ -53,7 +53,7 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { if (!PARSE_RX(FIELD, data, LxContext)) return false; - printf("master_offset = %ld, servo_state = %d ", data.master_offset, data.servo_state); + printf("master_offset = %ld, servo_state = %d gmPresent = %d\n", data.master_offset, data.servo_state, data.gmPresent); printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x ", data.gmIdentity[0], data.gmIdentity[1],data.gmIdentity[2], data.gmIdentity[3], data.gmIdentity[4], @@ -83,7 +83,12 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { client_data.asCapable_event_count.fetch_add(1, std::memory_order_relaxed); // Atomic increment } - printf("CLIENT master_offset = %ld, servo_state = %d ", data.master_offset, data.servo_state); + if (data.gmPresent != client_data.gmPresent) { + client_data.gmPresent = data.gmPresent; + client_data.gmPresent_event_count.fetch_add(1, std::memory_order_relaxed); // Atomic increment + } + + printf("CLIENT master_offset = %ld, servo_state = %d gmPresent = %d\n", client_data.master_offset, client_data.servo_state, client_data.gmPresent); printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x ", client_data.gmIdentity[0], client_data.gmIdentity[1],client_data.gmIdentity[2], client_data.gmIdentity[3], client_data.gmIdentity[4], diff --git a/jclklib/common/jclklib_import.hpp b/jclklib/common/jclklib_import.hpp index d447e5a9..a5d45480 100644 --- a/jclklib/common/jclklib_import.hpp +++ b/jclklib/common/jclklib_import.hpp @@ -103,6 +103,7 @@ namespace JClkLibCommon uint8_t gmIdentity[8]; /* Grandmaster clock ID */ int32_t asCapable; /* 802@.1AS Capable */ uint8_t servo_state; + int32_t gmPresent; uint8_t ptp4l_id; }; @@ -113,13 +114,24 @@ namespace JClkLibCommon bool master_offset_within_boundary; uint8_t gmIdentity[8]; /* Grandmaster clock ID */ int32_t asCapable; /* 802@.1AS Capable */ + int32_t gmPresent; uint8_t servo_state; uint8_t ptp4l_id; std::atomic offset_event_count{}; std::atomic gmIdentity_event_count{}; std::atomic asCapable_event_count{}; std::atomic servo_state_event_count{}; + std::atomic gmPresent_event_count{}; }; + + struct jcl_state + { + bool peer_present; + bool gm_present; + unsigned offset; + bool servo_locked; + }; + } #endif/*JCLKLIB_IMPORT_HPP*/ diff --git a/jclklib/proxy/connect.cpp b/jclklib/proxy/connect.cpp index 0b78b959..4b32f987 100644 --- a/jclklib/proxy/connect.cpp +++ b/jclklib/proxy/connect.cpp @@ -85,13 +85,13 @@ void event_handle() offset = ((TIME_STATUS_NP_t *)data)->master_offset; servo = ((TIME_STATUS_NP_t *)data)->servo_state; gm_uuid = ((TIME_STATUS_NP_t *)data)->gmIdentity; - + pe.gmPresent = ((TIME_STATUS_NP_t *)data)->gmPresent; pe.master_offset = offset; pe.servo_state = servo; memcpy(pe.gmIdentity, gm_uuid.v, sizeof(pe.gmIdentity)); //TODO: Add debug flag checking, only print if the flag is set - printf("master_offset = %ld, servo_state = %d ", pe.master_offset, pe.servo_state); + printf("master_offset = %ld, servo_state = %d gmPresent = %d\n", pe.master_offset, pe.servo_state, pe.gmPresent); printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x\n\n", pe.gmIdentity[0], pe.gmIdentity[1],pe.gmIdentity[2], pe.gmIdentity[3], pe.gmIdentity[4], diff --git a/jclklib/proxy/thread.cpp b/jclklib/proxy/thread.cpp index 36200cfc..88c0966e 100644 --- a/jclklib/proxy/thread.cpp +++ b/jclklib/proxy/thread.cpp @@ -20,6 +20,7 @@ //#include "ptp4l_connect.hpp" using namespace ptpmgmt; +using namespace JClkLibCommon; #define MSEC_PER_SEC (1000) #define USEC_PER_SEC (1000000) diff --git a/jclklib/proxy/thread.hpp b/jclklib/proxy/thread.hpp index 313df156..4bab8482 100644 --- a/jclklib/proxy/thread.hpp +++ b/jclklib/proxy/thread.hpp @@ -16,6 +16,7 @@ #include #include #include +#include typedef struct thread_signal *thread_signal_t; typedef struct ptp4l_handle *ptp4l_handle_t; @@ -27,14 +28,6 @@ struct thread_signal { bool signaled; }; -struct jcl_state -{ - bool peer_present; - bool gm_present; - unsigned offset; - bool servo_locked; -}; - struct jcl_threshold { unsigned offset; /* ns */ @@ -57,7 +50,7 @@ struct jcl_handle pthread_mutex_t state_lock; unsigned event_count[4]; //jcl_event_count struct jcl_subscription subscription; - struct jcl_state state; + struct JClkLibCommon::jcl_state state; }; typedef enum { jcl_peer_present, jcl_gm_present, jcl_offset_threshold, jcl_servo_locked, From fe1fe80b12e9f09c32d52683b0dc27ec560db97e Mon Sep 17 00:00:00 2001 From: Noor Azura Ahmad Tarmizi Date: Sun, 5 May 2024 21:42:30 -0400 Subject: [PATCH 031/151] feature: subscribe api with current state given Complete subscription flow with current state given. The timeout is 5 sec. Signed-off-by: Noor Azura Ahmad Tarmizi --- jclklib/client/client_state.cpp | 33 +++++++++++++++++++++++ jclklib/client/client_state.hpp | 17 ++++++++++-- jclklib/client/init.cpp | 30 ++++++++++++++++++++- jclklib/client/init.hpp | 4 ++- jclklib/client/subscribe_msg.cpp | 25 +++++++++++++++--- jclklib/client/subscribe_msg.hpp | 12 +++++++++ jclklib/client/test.cpp | 10 ++++--- jclklib/common/jclklib_import.hpp | 44 ++++++++++++++++++++++++++++--- jclklib/common/subscribe_msg.hpp | 1 + jclklib/proxy/connect_msg.cpp | 3 ++- jclklib/proxy/thread.cpp | 3 +-- 11 files changed, 164 insertions(+), 18 deletions(-) diff --git a/jclklib/client/client_state.cpp b/jclklib/client/client_state.cpp index 216fe6e2..93eefa1c 100644 --- a/jclklib/client/client_state.cpp +++ b/jclklib/client/client_state.cpp @@ -2,8 +2,10 @@ #include #include #include +#include #include #include +#include using namespace std; using namespace JClkLibClient; @@ -12,6 +14,7 @@ using namespace JClkLibCommon; ClientState::ClientState() { connected = false; + subscribed = false; sessionId = JClkLibCommon::InvalidSessionId; fill(begin(clientID ), end( clientID ), 0 ); } @@ -20,6 +23,10 @@ bool ClientState::get_connected() {return connected;} void ClientState::set_connected(bool new_state) {connected = new_state;} +bool ClientState::get_subscribed() {return subscribed;} + +void ClientState::set_subscribed(bool subscriptionState) {subscribed = subscriptionState;} + TransportClientId ClientState::get_clientID() { return clientID; } @@ -28,4 +35,30 @@ void ClientState::set_clientID(TransportClientId new_cID) { strcpy((char *)clientID.data(), (char *)new_cID.data()); } +JClkLibCommon::jcl_state_event_count &ClientState::get_eventStateCount() { + return eventStateCount; +} +JClkLibCommon::jcl_state &ClientState::get_eventState() { + return eventState; +} + +void ClientState::set_eventStateCount(JClkLibCommon::jcl_state_event_count newCount) { + eventStateCount = newCount; +} + +void ClientState::set_eventState(JClkLibCommon::jcl_state newState) { + eventState = newState; +} + +string ClientState::toString() { + string name = "[ClientState::eventState]"; + name += " as_Capable = " + to_string(this->get_eventState().as_Capable); + name += " gm_changed = " + to_string(this->get_eventState().gm_changed); + name += " gm_present = " + to_string(this->get_eventState().gm_present); + name += " offset_in_range = " + to_string(this->get_eventState().offset_in_range); + name += " servo_locked = " + to_string(this->get_eventState().servo_locked); + name += "\n"; + return name; +} + ClientState JClkLibClient::state{}; diff --git a/jclklib/client/client_state.hpp b/jclklib/client/client_state.hpp index 0ee42f0e..67833454 100644 --- a/jclklib/client/client_state.hpp +++ b/jclklib/client/client_state.hpp @@ -4,22 +4,35 @@ #include #include #include +#include #include +#include namespace JClkLibClient { class ClientState { private: std::atomic_bool connected; + std::atomic_bool subscribed; JClkLibCommon::sessionId_t sessionId; JClkLibCommon::TransportClientId clientID; + JClkLibCommon::jcl_state eventState; + JClkLibCommon::jcl_state_event_count eventStateCount; + public: ClientState(); bool get_connected(); void set_connected(bool state); + bool get_subscribed(); + void set_subscribed(bool subscriptionState); JClkLibCommon::TransportClientId get_clientID(); void set_clientID(JClkLibCommon::TransportClientId cID); - void get_clientID_memcpy(JClkLibCommon::TransportClientId cID); - void set_clientID_memcpy(JClkLibCommon::TransportClientId cID); + JClkLibCommon::jcl_state_event_count &get_eventStateCount(); + JClkLibCommon::jcl_state &get_eventState(); + void set_eventStateCount(JClkLibCommon::jcl_state_event_count eCount); + void set_eventState(JClkLibCommon::jcl_state eState); + std::string toString(); + //void get_clientID_memcpy(JClkLibCommon::TransportClientId cID); + //void set_clientID_memcpy(JClkLibCommon::TransportClientId cID); DECLARE_ACCESSOR(sessionId); }; diff --git a/jclklib/client/init.cpp b/jclklib/client/init.cpp index f6512569..03f958d9 100644 --- a/jclklib/client/init.cpp +++ b/jclklib/client/init.cpp @@ -18,6 +18,7 @@ #include #define DEFAULT_CONNECT_TIME_OUT 5 //5 sec +#define DEFAULT_SUBSCRIBE_TIME_OUT 5 //5 sec using namespace JClkLibClient; using namespace JClkLibCommon; @@ -25,6 +26,9 @@ using namespace std; std::mutex ClientConnectMessage::cv_mtx; std::condition_variable ClientConnectMessage::cv; +std::mutex ClientSubscribeMessage::cv_mtx; +std::condition_variable ClientSubscribeMessage::cv; + TransportClientId globalClientID; bool JClkLibClient::connect() @@ -70,8 +74,9 @@ bool JClkLibClient::connect() } -bool JClkLibClient::subscribe(JClkLibCommon::jcl_subscription &newSub) +bool JClkLibClient::subscribe(JClkLibCommon::jcl_subscription &newSub, JClkLibCommon::jcl_state ¤tState) { + unsigned int timeout_sec = (unsigned int) DEFAULT_SUBSCRIBE_TIME_OUT; PrintDebug("[JClkLibClient]::subscribe"); MessageX subscribeMsg(new ClientSubscribeMessage()); @@ -90,6 +95,29 @@ bool JClkLibClient::subscribe(JClkLibCommon::jcl_subscription &newSub) ClientMessageQueue::writeTransportClientId(subscribeMsg.get()); ClientMessageQueue::sendMessage(subscribeMsg.get()); + // Wait for subscription result + auto endTime = std::chrono::system_clock::now() + std::chrono::seconds(timeout_sec); + std::unique_lock lck(ClientSubscribeMessage::cv_mtx); + while (state.get_subscribed() == false ) + { + auto res = ClientSubscribeMessage::cv.wait_until(lck, endTime); + if (res == std::cv_status::timeout) { + if (state.get_subscribed() == false) { + PrintDebug("[SUBSCRIBE] No reply from proxy - timeout failure!!"); + return false; + } + } + else { + PrintDebug("[SUBSCRIBE] SUBSCRIBE reply received."); + } + } + + JClkLibCommon::jcl_state jclCurrentState = state.get_eventState(); + printf("[JClkLibClient]::subscribe : state - \n"); + printf ("offset_in_range = %d, servo_locked = %d gmPresent = %d as_Capable = %d gm_Changed = %d\n", \ + jclCurrentState.offset_in_range, jclCurrentState.servo_locked,\ + jclCurrentState.gm_present, jclCurrentState.as_Capable, jclCurrentState.gm_changed); + return true; } diff --git a/jclklib/client/init.hpp b/jclklib/client/init.hpp index 5c3630ec..85c871b4 100644 --- a/jclklib/client/init.hpp +++ b/jclklib/client/init.hpp @@ -13,7 +13,9 @@ namespace JClkLibClient { bool connect(); bool disconnect(); - bool subscribe(JClkLibCommon::jcl_subscription &newSub); + bool subscribe(JClkLibCommon::jcl_subscription &newSub, JClkLibCommon::jcl_state ¤tState); + int status_wait( unsigned timeout, JClkLibCommon::jcl_state &jcl_state , JClkLibCommon::jcl_state_event_count &eventCount); + }; #endif/*CLIENT_INIT_HPP*/ diff --git a/jclklib/client/subscribe_msg.cpp b/jclklib/client/subscribe_msg.cpp index e2f724a5..e8c9d520 100644 --- a/jclklib/client/subscribe_msg.cpp +++ b/jclklib/client/subscribe_msg.cpp @@ -44,7 +44,8 @@ bool ClientSubscribeMessage::initMessage() } PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { - JClkLibCommon::ptp_event data; + JClkLibCommon::ptp_event data = {}; + JClkLibCommon::jcl_state jclCurrentState = {}; PrintDebug("[ClientSubscribeMessage]::parseBuffer "); if(!CommonSubscribeMessage::parseBuffer(LxContext)) @@ -60,6 +61,7 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { data.gmIdentity[5], data.gmIdentity[6],data.gmIdentity[7]); printf("asCapable = %d, ptp4l_id = %d\n\n", data.asCapable, data.ptp4l_id); + /* TODO : set the client_data per client instead of global */ if (data.master_offset != client_data.master_offset) { client_data.master_offset = data.master_offset; if ((client_data.master_offset > client_data.master_offset_low) && (client_data.master_offset < client_data.master_offset_high)) { @@ -93,8 +95,16 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { client_data.gmIdentity[0], client_data.gmIdentity[1],client_data.gmIdentity[2], client_data.gmIdentity[3], client_data.gmIdentity[4], client_data.gmIdentity[5], client_data.gmIdentity[6],client_data.gmIdentity[7]); - printf("asCapable = %d\n\n", data.asCapable); + printf("asCapable = %d\n\n", client_data.asCapable); + jclCurrentState.gm_present = client_data.gmPresent > 0 ? true:false; + jclCurrentState.as_Capable = client_data.asCapable > 0 ? true:false; + jclCurrentState.offset_in_range = client_data.master_offset_within_boundary; + jclCurrentState.servo_locked = client_data.servo_state >= SERVO_LOCKED ? true:false; + /* TODO : checked for jclCurrentState.gm_changed based on GM_identity previously stored */ + + this->setClientState (jclCurrentState); + return true; } @@ -116,6 +126,15 @@ PROCESS_MESSAGE_TYPE(ClientSubscribeMessage::processMessage) PrintDebug("[ClientSubscribeMessage]::processMessage (reply)"); - this->set_msgAck(ACK_NONE); + state.set_eventState(this->getClientState()); + state.set_subscribed(true); + + this->set_msgAck(ACK_NONE); + + JClkLibCommon::jcl_state jclCurrentState = state.get_eventState(); + printf("[ClientSubscribeMessage]::processMessage : state - offset in range = %d, servo_locked = %d gmPresent = %d as_Capable = %d\n", \ + jclCurrentState.offset_in_range, jclCurrentState.servo_locked, jclCurrentState.gm_present, jclCurrentState.as_Capable); + + cv.notify_one(); return true; } diff --git a/jclklib/client/subscribe_msg.hpp b/jclklib/client/subscribe_msg.hpp index 2990ddff..e982c3a6 100644 --- a/jclklib/client/subscribe_msg.hpp +++ b/jclklib/client/subscribe_msg.hpp @@ -16,8 +16,13 @@ namespace JClkLibClient class ClientSubscribeMessage : virtual public JClkLibCommon::CommonSubscribeMessage, virtual public ClientMessage { + private: + JClkLibCommon::jcl_state clientState = {}; public: ClientSubscribeMessage() : MESSAGE_SUBSCRIBE() {}; + + static std::mutex cv_mtx; + static std::condition_variable cv; /** * @brief process the reply for subscribe msg from proxy. * @param LxContext client run-time transport listener context @@ -41,6 +46,13 @@ namespace JClkLibClient static bool initMessage(); virtual PARSE_RXBUFFER_TYPE(parseBuffer); + + void setClientState(JClkLibCommon::jcl_state newState) { + clientState = newState; + } + + JClkLibCommon::jcl_state &getClientState() + { return clientState; } }; } diff --git a/jclklib/client/test.cpp b/jclklib/client/test.cpp index 8c21b812..e27be345 100644 --- a/jclklib/client/test.cpp +++ b/jclklib/client/test.cpp @@ -29,8 +29,10 @@ void signal_handler(int sig) int main() { int ret = EXIT_SUCCESS; - JClkLibCommon::jcl_subscription sub; - std::uint32_t event2Sub1[1] = {((1< asCapable_event_count{}; std::atomic servo_state_event_count{}; std::atomic gmPresent_event_count{}; + std::atomic gmChanged_event_count{}; }; struct jcl_state { - bool peer_present; + bool as_Capable; bool gm_present; - unsigned offset; + bool offset_in_range; bool servo_locked; + bool gm_changed; + }; + + struct jcl_state_event_count + { + uint64_t gmPresent_event_count; + uint64_t offset_in_range_event_count; + uint64_t gm_changed_event_count; + uint64_t asCapable_event_count; + uint64_t servo_locked_event_count; }; + + } #endif/*JCLKLIB_IMPORT_HPP*/ diff --git a/jclklib/common/subscribe_msg.hpp b/jclklib/common/subscribe_msg.hpp index 49aecd36..a6108475 100644 --- a/jclklib/common/subscribe_msg.hpp +++ b/jclklib/common/subscribe_msg.hpp @@ -18,6 +18,7 @@ namespace JClkLibCommon private: jcl_subscription subscription; TransportClientId clientId; + public: static msgId_t getMsgId() { return SUBSCRIBE_MSG; } //static MAKE_RXBUFFER_TYPE(buildMessage); diff --git a/jclklib/proxy/connect_msg.cpp b/jclklib/proxy/connect_msg.cpp index f4154873..32b37ecf 100644 --- a/jclklib/proxy/connect_msg.cpp +++ b/jclklib/proxy/connect_msg.cpp @@ -70,7 +70,8 @@ PROCESS_MESSAGE_TYPE(ProxyConnectMessage::processMessage) /* check whether there is ptp4l available */ if (!pe.ptp4l_id) { - return false; + //return false; + PrintDebug("[AZU_HACK] ptp4l is not available !!! , we continue anyway"); } newSessionId = Client::CreateClientSession(); diff --git a/jclklib/proxy/thread.cpp b/jclklib/proxy/thread.cpp index 88c0966e..cae828f5 100644 --- a/jclklib/proxy/thread.cpp +++ b/jclklib/proxy/thread.cpp @@ -354,8 +354,7 @@ int handle_connect( struct jcl_handle **phandle, struct epoll_event epd_event ) goto state_lock_fail; //handle_init start - handle->state.peer_present = false; - handle->state.offset = UINT_MAX; + handle->state = {}; handle->subscription.event = 0; memset( handle->event_count, 0, sizeof( handle->event_count)); From 8657d0f514dcb895731b41f21c0f1f1d741c8d51 Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Mon, 6 May 2024 17:10:55 +0800 Subject: [PATCH 032/151] Add status_wait API function Signed-off-by: Lai Peter Jun Ann --- jclklib/client/init.cpp | 20 ++++++++++++++++++++ jclklib/client/notification_msg.cpp | 18 +++++++++++++++++- jclklib/client/test.cpp | 10 ++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/jclklib/client/init.cpp b/jclklib/client/init.cpp index 03f958d9..677d6394 100644 --- a/jclklib/client/init.cpp +++ b/jclklib/client/init.cpp @@ -141,3 +141,23 @@ bool JClkLibClient::disconnect() PrintError("Client Error Occured"); return retVal; } + +int JClkLibClient::status_wait( unsigned timeout, JClkLibCommon::jcl_state &jcl_state , JClkLibCommon::jcl_state_event_count &eventCount) +{ + + PrintDebug("[JClkLibClient]::status_wait"); + + /* Get the event state and event count*/ + eventCount = state.get_eventStateCount(); + jcl_state = state.get_eventState(); + + printf("[JClkLibClient]::status_wait : event_count - \n"); + printf ("offset_in_range = %ld, servo_locked = %ld gmPresent = %ld as_Capable = %ld gm_Changed = %ld\n", \ + eventCount.offset_in_range_event_count, eventCount.servo_locked_event_count,\ + eventCount.gmPresent_event_count, eventCount.asCapable_event_count, eventCount.gm_changed_event_count); + + /* Reset the atomic */ + //client_data.event_count.fetch_sub(eventCount, std::memory_order_relaxed); + + return true; +} diff --git a/jclklib/client/notification_msg.cpp b/jclklib/client/notification_msg.cpp index 0f1f9621..cdc1d05d 100644 --- a/jclklib/client/notification_msg.cpp +++ b/jclklib/client/notification_msg.cpp @@ -15,7 +15,9 @@ using namespace JClkLibCommon; using namespace JClkLibClient; JClkLibCommon::client_ptp_event client_ptp_data; -JClkLibCommon::ptp_event proxy_data; +JClkLibCommon::ptp_event proxy_data = {}; +JClkLibCommon::jcl_state jclCurrentState = {}; +JClkLibCommon::jcl_state_event_count jclCurrentEventCount = {}; /** @brief Create the ClientNotificationMessage object * @@ -89,6 +91,20 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) printf("asCapable = %d\n\n", client_ptp_data.asCapable); printf("CLIENT offset_event_count = %d, gmIdentity_event_count = %d, asCapable_event_count = %d, servo_state_event_count = %d\n\n", offset_event_count, gmIdentity_event_count, asCapable_event_count, servo_state_event_count); + jclCurrentState.gm_present = client_ptp_data.gmPresent > 0 ? true:false; + jclCurrentState.as_Capable = client_ptp_data.asCapable > 0 ? true:false; + jclCurrentState.offset_in_range = client_ptp_data.master_offset_within_boundary; + jclCurrentState.servo_locked = client_ptp_data.servo_state >= SERVO_LOCKED ? true:false; + /* TODO : checked for jclCurrentState.gm_changed based on GM_identity previously stored */ + + jclCurrentEventCount.gmPresent_event_count = client_ptp_data.gmIdentity_event_count; + jclCurrentEventCount.offset_in_range_event_count = client_ptp_data.offset_event_count; + jclCurrentEventCount.asCapable_event_count = client_ptp_data.asCapable_event_count; + jclCurrentEventCount.servo_locked_event_count = client_ptp_data.servo_state_event_count; + + state.set_eventState (jclCurrentState); + state.set_eventStateCount (jclCurrentEventCount); + return true; } diff --git a/jclklib/client/test.cpp b/jclklib/client/test.cpp index e27be345..ff26351e 100644 --- a/jclklib/client/test.cpp +++ b/jclklib/client/test.cpp @@ -31,6 +31,9 @@ int main() int ret = EXIT_SUCCESS; JClkLibCommon::jcl_subscription sub = {}; JClkLibCommon::jcl_state currentState = {}; + JClkLibCommon::jcl_state jcl_state = {}; + JClkLibCommon::jcl_state_event_count eventCount = {}; + unsigned timeout = 1; std::uint32_t event2Sub1[1] = {((1< Date: Mon, 6 May 2024 17:16:37 +0800 Subject: [PATCH 033/151] jclklib: set default logging level to ERROR Set default logging level to ERROR so that it does not print out debug and info related log. Signed-off-by: Song Yoong Siang --- jclklib/common/print.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/jclklib/common/print.cpp b/jclklib/common/print.cpp index 9569a4b4..253f80ad 100644 --- a/jclklib/common/print.cpp +++ b/jclklib/common/print.cpp @@ -14,6 +14,9 @@ using namespace std; using namespace JClkLibCommon; +enum LogLevel { DEBUG, INFO, ERROR }; +static LogLevel currentLogLevel = ERROR; + void JClkLibCommon::_PrintError(std::string msg, uint16_t line, std::string file, std::string func, errno_type errnum) { @@ -24,14 +27,18 @@ void JClkLibCommon::_PrintError(std::string msg, uint16_t line, std::string file void JClkLibCommon::_PrintDebug(std::string msg, uint16_t line, std::string file, std::string func) { - cerr << "** Debug: " + msg + " at line " + to_string(line) + " in " + file + ":" + func + "\n"; - cerr.flush(); + if (currentLogLevel <= DEBUG) { + cerr << "** Debug: " + msg + " at line " + to_string(line) + " in " + file + ":" + func + "\n"; + cerr.flush(); + } } void JClkLibCommon::_PrintInfo(std::string msg, uint16_t line, std::string file, std::string func) { - cerr << "* Info: " + msg + " at line " + to_string(line) + " in " + file + ":" + func + "\n"; - cerr.flush(); + if (currentLogLevel <= INFO) { + cerr << "* Info: " + msg + " at line " + to_string(line) + " in " + file + ":" + func + "\n"; + cerr.flush(); + } } #define HEX_DIGITS_PER_LINE 16 @@ -42,6 +49,10 @@ void JClkLibCommon::_DumpOctetArray(string msg, const uint8_t *arr, size_t lengt stringstream output; bool addspc = false, addcr; + if (currentLogLevel > DEBUG) { + return; + } + output << "* Info: " << msg << " at line " << to_string(line) << " in " << file << ":" << func << "\n"; while ((offset = (index - arr)) < length) { From 5f5c0a1d1cbf9edcfba353890f590856e55402cc Mon Sep 17 00:00:00 2001 From: JunAnnLaiIntel Date: Mon, 6 May 2024 21:35:25 +0800 Subject: [PATCH 034/151] Add status wait v2 (#26) jclklib: Improve status wait API Improve status wait API. Signed-off-by: Lai Peter Jun Ann --- jclklib/client/client_state.cpp | 4 ++++ jclklib/client/client_state.hpp | 2 ++ jclklib/client/init.cpp | 3 +++ jclklib/client/notification_msg.cpp | 18 +++++++++++++++--- jclklib/client/subscribe_msg.cpp | 7 +------ jclklib/client/test.cpp | 12 ++++++++---- jclklib/common/jclklib_import.hpp | 24 ++++++++++++++++++++++-- 7 files changed, 55 insertions(+), 15 deletions(-) diff --git a/jclklib/client/client_state.cpp b/jclklib/client/client_state.cpp index 93eefa1c..b41b50ce 100644 --- a/jclklib/client/client_state.cpp +++ b/jclklib/client/client_state.cpp @@ -61,4 +61,8 @@ string ClientState::toString() { return name; } +JClkLibCommon::jcl_subscription &ClientState::get_eventSub() { + return eventSub; +} + ClientState JClkLibClient::state{}; diff --git a/jclklib/client/client_state.hpp b/jclklib/client/client_state.hpp index 67833454..9f57d64f 100644 --- a/jclklib/client/client_state.hpp +++ b/jclklib/client/client_state.hpp @@ -17,6 +17,7 @@ namespace JClkLibClient { JClkLibCommon::TransportClientId clientID; JClkLibCommon::jcl_state eventState; JClkLibCommon::jcl_state_event_count eventStateCount; + JClkLibCommon::jcl_subscription eventSub; public: ClientState(); @@ -31,6 +32,7 @@ namespace JClkLibClient { void set_eventStateCount(JClkLibCommon::jcl_state_event_count eCount); void set_eventState(JClkLibCommon::jcl_state eState); std::string toString(); + JClkLibCommon::jcl_subscription &get_eventSub(); //void get_clientID_memcpy(JClkLibCommon::TransportClientId cID); //void set_clientID_memcpy(JClkLibCommon::TransportClientId cID); DECLARE_ACCESSOR(sessionId); diff --git a/jclklib/client/init.cpp b/jclklib/client/init.cpp index 677d6394..6c354a82 100644 --- a/jclklib/client/init.cpp +++ b/jclklib/client/init.cpp @@ -90,6 +90,9 @@ bool JClkLibClient::subscribe(JClkLibCommon::jcl_subscription &newSub, JClkLibCo PrintDebug("[JClkLibClient::subscribe] subscribeMsgcreation is OK !!\n"); /* Write the current event subscription */ + state.get_eventSub().set_event(newSub.getc_event()); + state.get_eventSub().set_value(newSub.getc_value()); + cmsg->getSubscription().get_event().copyEventMask(newSub.get_event()); ClientMessageQueue::writeTransportClientId(subscribeMsg.get()); diff --git a/jclklib/client/notification_msg.cpp b/jclklib/client/notification_msg.cpp index cdc1d05d..6c7e1fa0 100644 --- a/jclklib/client/notification_msg.cpp +++ b/jclklib/client/notification_msg.cpp @@ -54,11 +54,23 @@ BUILD_TXBUFFER_TYPE(ClientNotificationMessage::makeBuffer) const PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) { PrintDebug("[ClientNotificationMessage]::processMessage "); + if (proxy_data.master_offset != client_ptp_data.master_offset) { client_ptp_data.master_offset = proxy_data.master_offset; - if ((client_ptp_data.master_offset > client_ptp_data.master_offset_low) && (client_ptp_data.master_offset < client_ptp_data.master_offset_high)) { - client_ptp_data.master_offset_within_boundary = true; - client_ptp_data.offset_event_count.fetch_add(1, std::memory_order_relaxed); + if ((client_ptp_data.master_offset > state.get_eventSub().get_value().getLower(0)) && (client_ptp_data.master_offset < state.get_eventSub().get_value().getUpper(0))) { + if (!(client_ptp_data.master_offset_within_boundary)) + { + client_ptp_data.master_offset_within_boundary = true; + client_ptp_data.offset_event_count.fetch_add(1, std::memory_order_relaxed); + } + } + else + { + if ((client_ptp_data.master_offset_within_boundary)) + { + client_ptp_data.master_offset_within_boundary = false; + client_ptp_data.offset_event_count.fetch_add(1, std::memory_order_relaxed); + } } } diff --git a/jclklib/client/subscribe_msg.cpp b/jclklib/client/subscribe_msg.cpp index e8c9d520..73e8cd25 100644 --- a/jclklib/client/subscribe_msg.cpp +++ b/jclklib/client/subscribe_msg.cpp @@ -64,30 +64,25 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { /* TODO : set the client_data per client instead of global */ if (data.master_offset != client_data.master_offset) { client_data.master_offset = data.master_offset; - if ((client_data.master_offset > client_data.master_offset_low) && (client_data.master_offset < client_data.master_offset_high)) { + if ((client_data.master_offset > state.get_eventSub().get_value().getLower(0)) && (client_data.master_offset < state.get_eventSub().get_value().getUpper(0))) { client_data.master_offset_within_boundary = true; - client_data.offset_event_count.fetch_add(1, std::memory_order_relaxed) + 1; // Atomic increment } } if (data.servo_state != client_data.servo_state) { client_data.servo_state = data.servo_state; - client_data.servo_state_event_count.fetch_add(1, std::memory_order_relaxed); // Atomic increment } if (memcmp(client_data.gmIdentity, data.gmIdentity, sizeof(data.gmIdentity)) != 0) { memcpy(client_data.gmIdentity, data.gmIdentity, sizeof(data.gmIdentity)); - client_data.gmIdentity_event_count.fetch_add(1, std::memory_order_relaxed); // Atomic increment } if (data.asCapable != client_data.asCapable) { client_data.asCapable = data.asCapable; - client_data.asCapable_event_count.fetch_add(1, std::memory_order_relaxed); // Atomic increment } if (data.gmPresent != client_data.gmPresent) { client_data.gmPresent = data.gmPresent; - client_data.gmPresent_event_count.fetch_add(1, std::memory_order_relaxed); // Atomic increment } printf("CLIENT master_offset = %ld, servo_state = %d gmPresent = %d\n", client_data.master_offset, client_data.servo_state, client_data.gmPresent); diff --git a/jclklib/client/test.cpp b/jclklib/client/test.cpp index ff26351e..42ea2505 100644 --- a/jclklib/client/test.cpp +++ b/jclklib/client/test.cpp @@ -54,6 +54,7 @@ int main() sleep(5); sub.get_event().writeEvent(event2Sub1, (std::size_t)sizeof(event2Sub1)); + sub.get_value().setValue(0, 8888, -8888); std::cout << "[CLIENT] set subscribe event : " + sub.c_get_val_event().toString() << "\n"; subscribe(sub, currentState); std::cout << "[CLIENT] " + state.toString(); @@ -61,14 +62,17 @@ int main() while (!signal_flag) { /* ToDo: call wait API here */ status_wait(timeout, jcl_state , eventCount); + printf ("\n\nAPP PRINT jcl_state: offset_in_range = %d, servo_locked = %d gmPresent = %d as_Capable = %d gm_Changed = %d\n", \ + jcl_state.offset_in_range, jcl_state.servo_locked,\ + jcl_state.gm_present, jcl_state.as_Capable, jcl_state.gm_changed); + printf ("APP PRINT eventCount: offset_in_range = %ld, servo_locked = %ld gmPresent = %ld as_Capable = %ld gm_Changed = %ld\n\n", \ + eventCount.offset_in_range_event_count, eventCount.servo_locked_event_count,\ + eventCount.gmPresent_event_count, eventCount.asCapable_event_count, eventCount.gm_changed_event_count); + std::cout << "[CLIENT status_wait] " + state.toString(); sleep(1); } - printf ("offset_in_range = %ld, servo_locked = %ld gmPresent = %ld as_Capable = %ld gm_Changed = %ld\n", \ - eventCount.offset_in_range_event_count, eventCount.servo_locked_event_count,\ - eventCount.gmPresent_event_count, eventCount.asCapable_event_count, eventCount.gm_changed_event_count); - do_exit: disconnect(); diff --git a/jclklib/common/jclklib_import.hpp b/jclklib/common/jclklib_import.hpp index e0ff9a18..29184dcb 100644 --- a/jclklib/common/jclklib_import.hpp +++ b/jclklib/common/jclklib_import.hpp @@ -45,8 +45,8 @@ enum servoState_e { { private: struct value_t { - std::uint32_t upper; - std::uint32_t lower; + std::int32_t upper; + std::int32_t lower; value_t(); value_t(uint32_t limit); bool equal(const value_t &v); @@ -62,6 +62,26 @@ enum servoState_e { bool equal( const jcl_value &c); bool operator== (const jcl_value &value) { return this->equal(value); } bool operator!= (const jcl_value &value) { return !this->equal(value); } + // Add a method to set the upper and lower values of a specific value_t in the value array + void setValue(int index, std::int32_t upper, std::int32_t lower) { + if (index >= 0 && index < valueLast) { + value[index].upper = upper; + value[index].lower = lower; + } + } + std::int32_t getUpper(int index) { + if (index >= 0 && index < valueLast) { + return value[index].upper; + } + return 0; + } + + std::int32_t getLower(int index) { + if (index >= 0 && index < valueLast) { + return value[index].lower; + } + return 0; + } std::string toString(); }; From 7b23a9dd64158916182676b94756aa24065e9358 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Mon, 6 May 2024 21:55:34 +0800 Subject: [PATCH 035/151] jclklib: remove debug printing remove additional debug print for better view on the result. Signed-off-by: Song Yoong Siang --- jclklib/client/init.cpp | 5 ----- jclklib/client/notification_msg.cpp | 22 ---------------------- jclklib/client/test.cpp | 4 +--- 3 files changed, 1 insertion(+), 30 deletions(-) diff --git a/jclklib/client/init.cpp b/jclklib/client/init.cpp index 6c354a82..d5a019cf 100644 --- a/jclklib/client/init.cpp +++ b/jclklib/client/init.cpp @@ -154,11 +154,6 @@ int JClkLibClient::status_wait( unsigned timeout, JClkLibCommon::jcl_state &jcl_ eventCount = state.get_eventStateCount(); jcl_state = state.get_eventState(); - printf("[JClkLibClient]::status_wait : event_count - \n"); - printf ("offset_in_range = %ld, servo_locked = %ld gmPresent = %ld as_Capable = %ld gm_Changed = %ld\n", \ - eventCount.offset_in_range_event_count, eventCount.servo_locked_event_count,\ - eventCount.gmPresent_event_count, eventCount.asCapable_event_count, eventCount.gm_changed_event_count); - /* Reset the atomic */ //client_data.event_count.fetch_sub(eventCount, std::memory_order_relaxed); diff --git a/jclklib/client/notification_msg.cpp b/jclklib/client/notification_msg.cpp index 6c7e1fa0..fd741e3e 100644 --- a/jclklib/client/notification_msg.cpp +++ b/jclklib/client/notification_msg.cpp @@ -89,20 +89,6 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) client_ptp_data.asCapable_event_count.fetch_add(1, std::memory_order_relaxed); } - // Load the value of event_count atomically for TESTING only, will be remove later - int offset_event_count = client_ptp_data.offset_event_count; - int gmIdentity_event_count = client_ptp_data.gmIdentity_event_count; - int asCapable_event_count = client_ptp_data.asCapable_event_count; - int servo_state_event_count = client_ptp_data.servo_state_event_count; - - printf("CLIENT master_offset = %ld, servo_state = %d ", client_ptp_data.master_offset, client_ptp_data.servo_state); - printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x ", - client_ptp_data.gmIdentity[0], client_ptp_data.gmIdentity[1],client_ptp_data.gmIdentity[2], - client_ptp_data.gmIdentity[3], client_ptp_data.gmIdentity[4], - client_ptp_data.gmIdentity[5], client_ptp_data.gmIdentity[6],client_ptp_data.gmIdentity[7]); - printf("asCapable = %d\n\n", client_ptp_data.asCapable); - printf("CLIENT offset_event_count = %d, gmIdentity_event_count = %d, asCapable_event_count = %d, servo_state_event_count = %d\n\n", offset_event_count, gmIdentity_event_count, asCapable_event_count, servo_state_event_count); - jclCurrentState.gm_present = client_ptp_data.gmPresent > 0 ? true:false; jclCurrentState.as_Capable = client_ptp_data.asCapable > 0 ? true:false; jclCurrentState.offset_in_range = client_ptp_data.master_offset_within_boundary; @@ -129,13 +115,5 @@ PARSE_RXBUFFER_TYPE(ClientNotificationMessage::parseBuffer) if (!PARSE_RX(FIELD, proxy_data, LxContext)) return false; - printf("master_offset = %ld, servo_state = %d ", proxy_data.master_offset, proxy_data.servo_state); - printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x ", - proxy_data.gmIdentity[0], proxy_data.gmIdentity[1],proxy_data.gmIdentity[2], - proxy_data.gmIdentity[3], proxy_data.gmIdentity[4], - proxy_data.gmIdentity[5], proxy_data.gmIdentity[6],proxy_data.gmIdentity[7]); - printf("asCapable = %d\n\n", proxy_data.asCapable); - - return true; } diff --git a/jclklib/client/test.cpp b/jclklib/client/test.cpp index 42ea2505..5f550e08 100644 --- a/jclklib/client/test.cpp +++ b/jclklib/client/test.cpp @@ -62,14 +62,12 @@ int main() while (!signal_flag) { /* ToDo: call wait API here */ status_wait(timeout, jcl_state , eventCount); - printf ("\n\nAPP PRINT jcl_state: offset_in_range = %d, servo_locked = %d gmPresent = %d as_Capable = %d gm_Changed = %d\n", \ + printf ("APP PRINT jcl_state: offset_in_range = %d, servo_locked = %d gmPresent = %d as_Capable = %d gm_Changed = %d\n", \ jcl_state.offset_in_range, jcl_state.servo_locked,\ jcl_state.gm_present, jcl_state.as_Capable, jcl_state.gm_changed); printf ("APP PRINT eventCount: offset_in_range = %ld, servo_locked = %ld gmPresent = %ld as_Capable = %ld gm_Changed = %ld\n\n", \ eventCount.offset_in_range_event_count, eventCount.servo_locked_event_count,\ eventCount.gmPresent_event_count, eventCount.asCapable_event_count, eventCount.gm_changed_event_count); - - std::cout << "[CLIENT status_wait] " + state.toString(); sleep(1); } From 50cbd4db791c625505db624dfe8da3a9871fe337 Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Mon, 6 May 2024 22:25:53 +0800 Subject: [PATCH 036/151] fix event_count after status_wait Reset the event_count after status_wait. Signed-off-by: Lai Peter Jun Ann --- jclklib/client/init.cpp | 8 +++++++- jclklib/client/notification_msg.cpp | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/jclklib/client/init.cpp b/jclklib/client/init.cpp index d5a019cf..3ee3500d 100644 --- a/jclklib/client/init.cpp +++ b/jclklib/client/init.cpp @@ -29,6 +29,8 @@ std::condition_variable ClientConnectMessage::cv; std::mutex ClientSubscribeMessage::cv_mtx; std::condition_variable ClientSubscribeMessage::cv; +extern JClkLibCommon::client_ptp_event client_ptp_data; + TransportClientId globalClientID; bool JClkLibClient::connect() @@ -155,7 +157,11 @@ int JClkLibClient::status_wait( unsigned timeout, JClkLibCommon::jcl_state &jcl_ jcl_state = state.get_eventState(); /* Reset the atomic */ - //client_data.event_count.fetch_sub(eventCount, std::memory_order_relaxed); + client_ptp_data.offset_event_count.fetch_sub(eventCount.offset_in_range_event_count, std::memory_order_relaxed); + client_ptp_data.asCapable_event_count.fetch_sub(eventCount.asCapable_event_count, std::memory_order_relaxed); + client_ptp_data.servo_state_event_count.fetch_sub(eventCount.servo_locked_event_count, std::memory_order_relaxed); + client_ptp_data.gmPresent_event_count.fetch_sub(eventCount.gmPresent_event_count, std::memory_order_relaxed); + client_ptp_data.gmChanged_event_count.fetch_sub(eventCount.gm_changed_event_count, std::memory_order_relaxed); return true; } diff --git a/jclklib/client/notification_msg.cpp b/jclklib/client/notification_msg.cpp index fd741e3e..c08026ce 100644 --- a/jclklib/client/notification_msg.cpp +++ b/jclklib/client/notification_msg.cpp @@ -89,13 +89,18 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) client_ptp_data.asCapable_event_count.fetch_add(1, std::memory_order_relaxed); } + if (proxy_data.gmPresent != client_ptp_data.gmPresent) { + client_ptp_data.gmPresent = proxy_data.gmPresent; + client_ptp_data.gmPresent_event_count.fetch_add(1, std::memory_order_relaxed); + } + jclCurrentState.gm_present = client_ptp_data.gmPresent > 0 ? true:false; jclCurrentState.as_Capable = client_ptp_data.asCapable > 0 ? true:false; jclCurrentState.offset_in_range = client_ptp_data.master_offset_within_boundary; jclCurrentState.servo_locked = client_ptp_data.servo_state >= SERVO_LOCKED ? true:false; /* TODO : checked for jclCurrentState.gm_changed based on GM_identity previously stored */ - jclCurrentEventCount.gmPresent_event_count = client_ptp_data.gmIdentity_event_count; + jclCurrentEventCount.gmPresent_event_count = client_ptp_data.gmPresent_event_count; jclCurrentEventCount.offset_in_range_event_count = client_ptp_data.offset_event_count; jclCurrentEventCount.asCapable_event_count = client_ptp_data.asCapable_event_count; jclCurrentEventCount.servo_locked_event_count = client_ptp_data.servo_state_event_count; From f60e18444283249636aac65530e47c3bff1438e0 Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Tue, 7 May 2024 11:07:35 +0800 Subject: [PATCH 037/151] Add gm UUID as data Signed-off-by: Lai Peter Jun Ann --- jclklib/client/init.cpp | 5 ++++- jclklib/client/notification_msg.cpp | 9 ++++++++- jclklib/client/subscribe_msg.cpp | 1 + jclklib/client/test.cpp | 4 ++++ jclklib/common/jclklib_import.hpp | 2 +- 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/jclklib/client/init.cpp b/jclklib/client/init.cpp index 3ee3500d..32336024 100644 --- a/jclklib/client/init.cpp +++ b/jclklib/client/init.cpp @@ -122,7 +122,10 @@ bool JClkLibClient::subscribe(JClkLibCommon::jcl_subscription &newSub, JClkLibCo printf ("offset_in_range = %d, servo_locked = %d gmPresent = %d as_Capable = %d gm_Changed = %d\n", \ jclCurrentState.offset_in_range, jclCurrentState.servo_locked,\ jclCurrentState.gm_present, jclCurrentState.as_Capable, jclCurrentState.gm_changed); - + printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x \n", + jclCurrentState.gmIdentity[0], jclCurrentState.gmIdentity[1],jclCurrentState.gmIdentity[2], + jclCurrentState.gmIdentity[3], jclCurrentState.gmIdentity[4], + jclCurrentState.gmIdentity[5], jclCurrentState.gmIdentity[6],jclCurrentState.gmIdentity[7]); return true; } diff --git a/jclklib/client/notification_msg.cpp b/jclklib/client/notification_msg.cpp index c08026ce..6a649548 100644 --- a/jclklib/client/notification_msg.cpp +++ b/jclklib/client/notification_msg.cpp @@ -81,7 +81,11 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) if (memcmp(client_ptp_data.gmIdentity, proxy_data.gmIdentity, sizeof(proxy_data.gmIdentity)) != 0) { memcpy(client_ptp_data.gmIdentity, proxy_data.gmIdentity, sizeof(proxy_data.gmIdentity)); - client_ptp_data.gmIdentity_event_count.fetch_add(1, std::memory_order_relaxed); + client_ptp_data.gmChanged_event_count.fetch_add(1, std::memory_order_relaxed); + jclCurrentState.gm_changed = true; + } + else { + jclCurrentState.gm_changed = false; } if (proxy_data.asCapable != client_ptp_data.asCapable) { @@ -98,12 +102,15 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) jclCurrentState.as_Capable = client_ptp_data.asCapable > 0 ? true:false; jclCurrentState.offset_in_range = client_ptp_data.master_offset_within_boundary; jclCurrentState.servo_locked = client_ptp_data.servo_state >= SERVO_LOCKED ? true:false; + memcpy(jclCurrentState.gmIdentity, client_ptp_data.gmIdentity, sizeof(client_ptp_data.gmIdentity)); + /* TODO : checked for jclCurrentState.gm_changed based on GM_identity previously stored */ jclCurrentEventCount.gmPresent_event_count = client_ptp_data.gmPresent_event_count; jclCurrentEventCount.offset_in_range_event_count = client_ptp_data.offset_event_count; jclCurrentEventCount.asCapable_event_count = client_ptp_data.asCapable_event_count; jclCurrentEventCount.servo_locked_event_count = client_ptp_data.servo_state_event_count; + jclCurrentEventCount.gm_changed_event_count = client_ptp_data.gmChanged_event_count; state.set_eventState (jclCurrentState); state.set_eventStateCount (jclCurrentEventCount); diff --git a/jclklib/client/subscribe_msg.cpp b/jclklib/client/subscribe_msg.cpp index 73e8cd25..a5ecf172 100644 --- a/jclklib/client/subscribe_msg.cpp +++ b/jclklib/client/subscribe_msg.cpp @@ -96,6 +96,7 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { jclCurrentState.as_Capable = client_data.asCapable > 0 ? true:false; jclCurrentState.offset_in_range = client_data.master_offset_within_boundary; jclCurrentState.servo_locked = client_data.servo_state >= SERVO_LOCKED ? true:false; + memcpy(jclCurrentState.gmIdentity, client_data.gmIdentity, sizeof(client_data.gmIdentity)); /* TODO : checked for jclCurrentState.gm_changed based on GM_identity previously stored */ this->setClientState (jclCurrentState); diff --git a/jclklib/client/test.cpp b/jclklib/client/test.cpp index 5f550e08..96863e71 100644 --- a/jclklib/client/test.cpp +++ b/jclklib/client/test.cpp @@ -65,6 +65,10 @@ int main() printf ("APP PRINT jcl_state: offset_in_range = %d, servo_locked = %d gmPresent = %d as_Capable = %d gm_Changed = %d\n", \ jcl_state.offset_in_range, jcl_state.servo_locked,\ jcl_state.gm_present, jcl_state.as_Capable, jcl_state.gm_changed); + printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x \n", + jcl_state.gmIdentity[0], jcl_state.gmIdentity[1],jcl_state.gmIdentity[2], + jcl_state.gmIdentity[3], jcl_state.gmIdentity[4], + jcl_state.gmIdentity[5], jcl_state.gmIdentity[6],jcl_state.gmIdentity[7]); printf ("APP PRINT eventCount: offset_in_range = %ld, servo_locked = %ld gmPresent = %ld as_Capable = %ld gm_Changed = %ld\n\n", \ eventCount.offset_in_range_event_count, eventCount.servo_locked_event_count,\ eventCount.gmPresent_event_count, eventCount.asCapable_event_count, eventCount.gm_changed_event_count); diff --git a/jclklib/common/jclklib_import.hpp b/jclklib/common/jclklib_import.hpp index 29184dcb..72ca344f 100644 --- a/jclklib/common/jclklib_import.hpp +++ b/jclklib/common/jclklib_import.hpp @@ -161,7 +161,6 @@ enum servoState_e { uint8_t servo_state; uint8_t ptp4l_id; std::atomic offset_event_count{}; - std::atomic gmIdentity_event_count{}; std::atomic asCapable_event_count{}; std::atomic servo_state_event_count{}; std::atomic gmPresent_event_count{}; @@ -175,6 +174,7 @@ enum servoState_e { bool offset_in_range; bool servo_locked; bool gm_changed; + uint8_t gmIdentity[8]; }; struct jcl_state_event_count From cb4e6eca4149cff33c91bdae468651eb58df419f Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Tue, 7 May 2024 10:47:03 +0800 Subject: [PATCH 038/151] jclklib: use gmOffsetValue instead of magic number use gmOffsetValue instead of 0 to represent upper and lower index for Grandmaster Offset. Signed-off-by: Song Yoong Siang --- jclklib/client/notification_msg.cpp | 3 ++- jclklib/client/subscribe_msg.cpp | 3 ++- jclklib/client/test.cpp | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/jclklib/client/notification_msg.cpp b/jclklib/client/notification_msg.cpp index 6a649548..cf4c3211 100644 --- a/jclklib/client/notification_msg.cpp +++ b/jclklib/client/notification_msg.cpp @@ -57,7 +57,8 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) if (proxy_data.master_offset != client_ptp_data.master_offset) { client_ptp_data.master_offset = proxy_data.master_offset; - if ((client_ptp_data.master_offset > state.get_eventSub().get_value().getLower(0)) && (client_ptp_data.master_offset < state.get_eventSub().get_value().getUpper(0))) { + if ((client_ptp_data.master_offset > state.get_eventSub().get_value().getLower(gmOffsetValue)) && + (client_ptp_data.master_offset < state.get_eventSub().get_value().getUpper(gmOffsetValue))) { if (!(client_ptp_data.master_offset_within_boundary)) { client_ptp_data.master_offset_within_boundary = true; diff --git a/jclklib/client/subscribe_msg.cpp b/jclklib/client/subscribe_msg.cpp index a5ecf172..1c6895fc 100644 --- a/jclklib/client/subscribe_msg.cpp +++ b/jclklib/client/subscribe_msg.cpp @@ -64,7 +64,8 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { /* TODO : set the client_data per client instead of global */ if (data.master_offset != client_data.master_offset) { client_data.master_offset = data.master_offset; - if ((client_data.master_offset > state.get_eventSub().get_value().getLower(0)) && (client_data.master_offset < state.get_eventSub().get_value().getUpper(0))) { + if ((client_data.master_offset > state.get_eventSub().get_value().getLower(gmOffsetValue)) && + (client_data.master_offset < state.get_eventSub().get_value().getUpper(gmOffsetValue))) { client_data.master_offset_within_boundary = true; } } diff --git a/jclklib/client/test.cpp b/jclklib/client/test.cpp index 96863e71..fec4343f 100644 --- a/jclklib/client/test.cpp +++ b/jclklib/client/test.cpp @@ -54,7 +54,7 @@ int main() sleep(5); sub.get_event().writeEvent(event2Sub1, (std::size_t)sizeof(event2Sub1)); - sub.get_value().setValue(0, 8888, -8888); + sub.get_value().setValue(gmOffsetValue, 8888, -8888); std::cout << "[CLIENT] set subscribe event : " + sub.c_get_val_event().toString() << "\n"; subscribe(sub, currentState); std::cout << "[CLIENT] " + state.toString(); From 08f9328a60d5fe019542a629cbd50aca68b2864e Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Tue, 7 May 2024 10:57:07 +0800 Subject: [PATCH 039/151] jclklib: update API name to include jcl_ as initial update API name: connect() -> jcl_connect() disconnect() -> jcl_disconnect() subscribe() -> jcl_subscribe() status_wait() -> jcl_status_wait() Signed-off-by: Song Yoong Siang --- jclklib/client/init.cpp | 10 ++++++---- jclklib/client/init.hpp | 10 ++++++---- jclklib/client/test.cpp | 8 ++++---- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/jclklib/client/init.cpp b/jclklib/client/init.cpp index 32336024..af4e42b7 100644 --- a/jclklib/client/init.cpp +++ b/jclklib/client/init.cpp @@ -33,7 +33,7 @@ extern JClkLibCommon::client_ptp_event client_ptp_data; TransportClientId globalClientID; -bool JClkLibClient::connect() +bool JClkLibClient::jcl_connect() { unsigned int timeout_sec = (unsigned int) DEFAULT_CONNECT_TIME_OUT; Message0 connectMsg(new ClientConnectMessage()); @@ -76,7 +76,8 @@ bool JClkLibClient::connect() } -bool JClkLibClient::subscribe(JClkLibCommon::jcl_subscription &newSub, JClkLibCommon::jcl_state ¤tState) +bool JClkLibClient::jcl_subscribe(JClkLibCommon::jcl_subscription &newSub, + JClkLibCommon::jcl_state ¤tState) { unsigned int timeout_sec = (unsigned int) DEFAULT_SUBSCRIBE_TIME_OUT; @@ -129,7 +130,7 @@ bool JClkLibClient::subscribe(JClkLibCommon::jcl_subscription &newSub, JClkLibCo return true; } -bool JClkLibClient::disconnect() +bool JClkLibClient::jcl_disconnect() { bool retVal = false; @@ -150,7 +151,8 @@ bool JClkLibClient::disconnect() return retVal; } -int JClkLibClient::status_wait( unsigned timeout, JClkLibCommon::jcl_state &jcl_state , JClkLibCommon::jcl_state_event_count &eventCount) +int JClkLibClient::jcl_status_wait(unsigned timeout, JClkLibCommon::jcl_state &jcl_state, + JClkLibCommon::jcl_state_event_count &eventCount) { PrintDebug("[JClkLibClient]::status_wait"); diff --git a/jclklib/client/init.hpp b/jclklib/client/init.hpp index 85c871b4..10738e78 100644 --- a/jclklib/client/init.hpp +++ b/jclklib/client/init.hpp @@ -11,10 +11,12 @@ #include namespace JClkLibClient { - bool connect(); - bool disconnect(); - bool subscribe(JClkLibCommon::jcl_subscription &newSub, JClkLibCommon::jcl_state ¤tState); - int status_wait( unsigned timeout, JClkLibCommon::jcl_state &jcl_state , JClkLibCommon::jcl_state_event_count &eventCount); + bool jcl_connect(); + bool jcl_disconnect(); + bool jcl_subscribe(JClkLibCommon::jcl_subscription &newSub, + JClkLibCommon::jcl_state ¤tState); + int jcl_status_wait(unsigned timeout, JClkLibCommon::jcl_state &jcl_state, + JClkLibCommon::jcl_state_event_count &eventCount); }; diff --git a/jclklib/client/test.cpp b/jclklib/client/test.cpp index fec4343f..c7662417 100644 --- a/jclklib/client/test.cpp +++ b/jclklib/client/test.cpp @@ -43,7 +43,7 @@ int main() std::cout << "[CLIENT] Before connect : Session ID : " << state.get_sessionId() << "\n"; - if (connect() == false) { + if (jcl_connect() == false) { std::cout << "[CLIENT] Failure in connecting !!!\n"; ret = EXIT_FAILURE; goto do_exit; @@ -56,12 +56,12 @@ int main() sub.get_event().writeEvent(event2Sub1, (std::size_t)sizeof(event2Sub1)); sub.get_value().setValue(gmOffsetValue, 8888, -8888); std::cout << "[CLIENT] set subscribe event : " + sub.c_get_val_event().toString() << "\n"; - subscribe(sub, currentState); + jcl_subscribe(sub, currentState); std::cout << "[CLIENT] " + state.toString(); while (!signal_flag) { /* ToDo: call wait API here */ - status_wait(timeout, jcl_state , eventCount); + jcl_status_wait(timeout, jcl_state , eventCount); printf ("APP PRINT jcl_state: offset_in_range = %d, servo_locked = %d gmPresent = %d as_Capable = %d gm_Changed = %d\n", \ jcl_state.offset_in_range, jcl_state.servo_locked,\ jcl_state.gm_present, jcl_state.as_Capable, jcl_state.gm_changed); @@ -76,7 +76,7 @@ int main() } do_exit: - disconnect(); + jcl_disconnect(); return ret; } From d9ce9f64e600140e829a464d185be4ce26ccb7bb Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Tue, 7 May 2024 12:53:14 +0800 Subject: [PATCH 040/151] jclklib: Add timeout support in jcl_status_wait() API Now, jcl_status_wait() will waits for a specified timeout period for any event changes. Signed-off-by: Song Yoong Siang --- jclklib/client/init.cpp | 60 ++++++++++++++++++++++++++++++++++------- jclklib/client/init.hpp | 2 +- jclklib/client/test.cpp | 33 +++++++++++++---------- 3 files changed, 70 insertions(+), 25 deletions(-) diff --git a/jclklib/client/init.cpp b/jclklib/client/init.cpp index af4e42b7..a645ea53 100644 --- a/jclklib/client/init.cpp +++ b/jclklib/client/init.cpp @@ -151,22 +151,62 @@ bool JClkLibClient::jcl_disconnect() return retVal; } -int JClkLibClient::jcl_status_wait(unsigned timeout, JClkLibCommon::jcl_state &jcl_state, +/** + * @brief This function waits for a specified timeout period for any event changes. + * + * @param timeout The timeout period in seconds. If timeout is 0, the function + * will check event changes once. If timeout is -1, the function + * wait until there is event changes occurs. + * @param jcl_state A reference to a jcl_state object where the current state + * will be stored. + * @param eventCount A reference to a jcl_state_event_count object where the + * event counts will be stored. + * + * @return Returns true if there is event changes within the timeout period, + * and false otherwise. + */ +int JClkLibClient::jcl_status_wait(int timeout, JClkLibCommon::jcl_state &jcl_state, JClkLibCommon::jcl_state_event_count &eventCount) { + auto start = std::chrono::high_resolution_clock::now(); + auto end = (timeout == -1) ? + std::chrono::time_point::max() : + start + std::chrono::seconds(timeout); + bool event_changes_detected = false; + + do { + /* Get the event state and event count*/ + eventCount = state.get_eventStateCount(); + jcl_state = state.get_eventState(); + + /* Check if any member of eventCount is non-zero */ + if (eventCount.offset_in_range_event_count || + eventCount.asCapable_event_count || + eventCount.servo_locked_event_count || + eventCount.gmPresent_event_count || + eventCount.gm_changed_event_count) { + event_changes_detected = true; + break; + } - PrintDebug("[JClkLibClient]::status_wait"); + /* Sleep for a short duration before the next iteration */ + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + } while (std::chrono::high_resolution_clock::now() < end); - /* Get the event state and event count*/ - eventCount = state.get_eventStateCount(); - jcl_state = state.get_eventState(); + if (!event_changes_detected) + return false; /* Reset the atomic */ - client_ptp_data.offset_event_count.fetch_sub(eventCount.offset_in_range_event_count, std::memory_order_relaxed); - client_ptp_data.asCapable_event_count.fetch_sub(eventCount.asCapable_event_count, std::memory_order_relaxed); - client_ptp_data.servo_state_event_count.fetch_sub(eventCount.servo_locked_event_count, std::memory_order_relaxed); - client_ptp_data.gmPresent_event_count.fetch_sub(eventCount.gmPresent_event_count, std::memory_order_relaxed); - client_ptp_data.gmChanged_event_count.fetch_sub(eventCount.gm_changed_event_count, std::memory_order_relaxed); + client_ptp_data.offset_event_count.fetch_sub(eventCount.offset_in_range_event_count, + std::memory_order_relaxed); + client_ptp_data.asCapable_event_count.fetch_sub(eventCount.asCapable_event_count, + std::memory_order_relaxed); + client_ptp_data.servo_state_event_count.fetch_sub(eventCount.servo_locked_event_count, + std::memory_order_relaxed); + client_ptp_data.gmPresent_event_count.fetch_sub(eventCount.gmPresent_event_count, + std::memory_order_relaxed); + client_ptp_data.gmChanged_event_count.fetch_sub(eventCount.gm_changed_event_count, + std::memory_order_relaxed); return true; } diff --git a/jclklib/client/init.hpp b/jclklib/client/init.hpp index 10738e78..def6e1e9 100644 --- a/jclklib/client/init.hpp +++ b/jclklib/client/init.hpp @@ -15,7 +15,7 @@ namespace JClkLibClient { bool jcl_disconnect(); bool jcl_subscribe(JClkLibCommon::jcl_subscription &newSub, JClkLibCommon::jcl_state ¤tState); - int jcl_status_wait(unsigned timeout, JClkLibCommon::jcl_state &jcl_state, + int jcl_status_wait(int timeout, JClkLibCommon::jcl_state &jcl_state, JClkLibCommon::jcl_state_event_count &eventCount); }; diff --git a/jclklib/client/test.cpp b/jclklib/client/test.cpp index c7662417..ed211b7d 100644 --- a/jclklib/client/test.cpp +++ b/jclklib/client/test.cpp @@ -33,7 +33,7 @@ int main() JClkLibCommon::jcl_state currentState = {}; JClkLibCommon::jcl_state jcl_state = {}; JClkLibCommon::jcl_state_event_count eventCount = {}; - unsigned timeout = 1; + int timeout = 10; std::uint32_t event2Sub1[1] = {((1< Date: Tue, 7 May 2024 13:15:34 +0800 Subject: [PATCH 041/151] jclklib: Add subscribed event checking Signed-off-by: Lai Peter Jun Ann --- jclklib/client/notification_msg.cpp | 13 ++++++++----- jclklib/client/subscribe_msg.cpp | 14 +++++++++----- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/jclklib/client/notification_msg.cpp b/jclklib/client/notification_msg.cpp index cf4c3211..69ff15f0 100644 --- a/jclklib/client/notification_msg.cpp +++ b/jclklib/client/notification_msg.cpp @@ -55,7 +55,10 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) { PrintDebug("[ClientNotificationMessage]::processMessage "); - if (proxy_data.master_offset != client_ptp_data.master_offset) { + std::uint32_t eventSub[1]; + state.get_eventSub().get_event().readEvent(eventSub, (std::size_t)sizeof(eventSub)); + + if ((eventSub[0] & 1< state.get_eventSub().get_value().getLower(gmOffsetValue)) && (client_ptp_data.master_offset < state.get_eventSub().get_value().getUpper(gmOffsetValue))) { @@ -75,12 +78,12 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) } } - if (proxy_data.servo_state != client_ptp_data.servo_state) { + if ((eventSub[0] & 1< state.get_eventSub().get_value().getLower(gmOffsetValue)) && (client_data.master_offset < state.get_eventSub().get_value().getUpper(gmOffsetValue))) { @@ -70,19 +73,20 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { } } - if (data.servo_state != client_data.servo_state) { + if ((eventSub[0] & 1< Date: Tue, 7 May 2024 13:29:58 +0800 Subject: [PATCH 042/151] jclklib: improve printing in test app improve printing of data receive by test app for better readability. Signed-off-by: Song Yoong Siang --- jclklib/client/test.cpp | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/jclklib/client/test.cpp b/jclklib/client/test.cpp index ed211b7d..24279d33 100644 --- a/jclklib/client/test.cpp +++ b/jclklib/client/test.cpp @@ -62,21 +62,29 @@ int main() while (!signal_flag) { if (!jcl_status_wait(timeout, jcl_state , eventCount)) { printf("No event status changes identified in %d seconds.\n\n", timeout); - } else { - printf("APP PRINT jcl_state: offset_in_range = %d, servo_locked = %d, " - "gmPresent = %d, as_Capable = %d, gm_Changed = %d\n", - jcl_state.offset_in_range, jcl_state.servo_locked, - jcl_state.gm_present, jcl_state.as_Capable, jcl_state.gm_changed); - printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x\n", - jcl_state.gmIdentity[0], jcl_state.gmIdentity[1], jcl_state.gmIdentity[2], - jcl_state.gmIdentity[3], jcl_state.gmIdentity[4], - jcl_state.gmIdentity[5], jcl_state.gmIdentity[6], jcl_state.gmIdentity[7]); - printf("APP PRINT eventCount: offset_in_range = %ld, servo_locked = %ld, " - "gmPresent = %ld, as_Capable = %ld, gm_Changed = %ld\n\n", - eventCount.offset_in_range_event_count, eventCount.servo_locked_event_count, - eventCount.gmPresent_event_count, eventCount.asCapable_event_count, - eventCount.gm_changed_event_count); + sleep(1); + continue; } + + printf("+------------------+--------------+-------------+\n"); + printf("| %-16s | %-12s | %-11s |\n", "Event", "Event Status", "Event Count"); + printf("+------------------+--------------+-------------+\n"); + printf("| %-16s | %-12d | %-11ld |\n", "offset_in_range", + jcl_state.offset_in_range, eventCount.offset_in_range_event_count); + printf("| %-16s | %-12d | %-11ld |\n", "servo_locked", + jcl_state.servo_locked, eventCount.servo_locked_event_count); + printf("| %-16s | %-12d | %-11ld |\n", "gmPresent", + jcl_state.gm_present, eventCount.gmPresent_event_count); + printf("| %-16s | %-12d | %-11ld |\n", "as_Capable", + jcl_state.as_Capable, eventCount.asCapable_event_count); + printf("| %-16s | %-12d | %-11ld |\n", "gm_Changed", + jcl_state.gm_changed, eventCount.gm_changed_event_count); + printf("+------------------+--------------+-------------+\n"); + printf("| %-16s | %02x%02x%02x.%02x%02x.%02x%02x%02x |\n", "UUID", + jcl_state.gmIdentity[0], jcl_state.gmIdentity[1], jcl_state.gmIdentity[2], + jcl_state.gmIdentity[3], jcl_state.gmIdentity[4], + jcl_state.gmIdentity[5], jcl_state.gmIdentity[6], jcl_state.gmIdentity[7]); + printf("+------------------+----------------------------+\n\n"); sleep(1); } From 6726c389db05ee33a273ef3a2763f0b229ca9603 Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Tue, 7 May 2024 15:07:21 +0800 Subject: [PATCH 043/151] jclklib: Remove the duration for ptp4l subscription Signed-off-by: Lai Peter Jun Ann --- jclklib/proxy/connect.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/jclklib/proxy/connect.cpp b/jclklib/proxy/connect.cpp index 4b32f987..d11b454c 100644 --- a/jclklib/proxy/connect.cpp +++ b/jclklib/proxy/connect.cpp @@ -26,8 +26,6 @@ using namespace std; using namespace JClkLibProxy; using namespace ptpmgmt; -const int SUBSCRIBE_DURATION = 180; /* 3 minutes */ - static const size_t bufSize = 2000; static char buf[bufSize]; static Init obj; @@ -163,7 +161,6 @@ static inline bool msg_set_action(bool local, mng_vals_e id) bool event_subscription(struct jcl_handle **handle) { memset(d.bitmask, 0, sizeof d.bitmask); - d.duration = SUBSCRIBE_DURATION; d.setEvent(NOTIFY_TIME_SYNC); d.setEvent(NOTIFY_PORT_STATE_NP); From 676aea46c25ccf34480bbceb2761c1d9d4ce4393 Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Wed, 8 May 2024 10:09:04 +0800 Subject: [PATCH 044/151] jclklib: client: Add copyright license header Signed-off-by: Lai Peter Jun Ann --- jclklib/client/Makefile | 13 +++++++++---- jclklib/client/client_state.cpp | 14 ++++++++++++++ jclklib/client/client_state.hpp | 14 ++++++++++++++ jclklib/client/connect_msg.cpp | 17 ++++++++++++----- jclklib/client/connect_msg.hpp | 19 +++++++++++++------ jclklib/client/init.cpp | 17 ++++++++++++----- jclklib/client/init.hpp | 17 ++++++++++++----- jclklib/client/message.cpp | 17 ++++++++++++----- jclklib/client/message.hpp | 17 ++++++++++++----- jclklib/client/msgq_tport.cpp | 19 +++++++++++++------ jclklib/client/msgq_tport.hpp | 19 +++++++++++++------ jclklib/client/notification_msg.cpp | 19 +++++++++++++------ jclklib/client/notification_msg.hpp | 19 +++++++++++++------ jclklib/client/null_msg.hpp | 17 ++++++++++++----- jclklib/client/null_tport.cpp | 17 ++++++++++++----- jclklib/client/null_tport.hpp | 17 ++++++++++++----- jclklib/client/run_test.sh | 8 ++++++++ jclklib/client/subscribe_msg.cpp | 17 ++++++++++++----- jclklib/client/subscribe_msg.hpp | 17 ++++++++++++----- jclklib/client/test.cpp | 19 +++++++++++++------ jclklib/client/transport.cpp | 19 +++++++++++++------ jclklib/client/transport.hpp | 19 +++++++++++++------ 22 files changed, 269 insertions(+), 102 deletions(-) diff --git a/jclklib/client/Makefile b/jclklib/client/Makefile index 50622dc8..b85534ae 100644 --- a/jclklib/client/Makefile +++ b/jclklib/client/Makefile @@ -1,9 +1,14 @@ -##! \file Makefile -# \brief Client makefile +# SPDX-License-Identifier: LGPL-3.0-or-later +# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. # -# (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. -# Author: Christopher Hall +# 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) JCLKLIB_TOPLEVEL_DIR = $(JCLKLIB_CLIENT_DIR)/.. diff --git a/jclklib/client/client_state.cpp b/jclklib/client/client_state.cpp index b41b50ce..c114dc9c 100644 --- a/jclklib/client/client_state.cpp +++ b/jclklib/client/client_state.cpp @@ -1,3 +1,17 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file client_state.cpp + * @brief Set and get the client subscribe event state + * + * @author Noor Azura Ahmad Tarmizi + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ + #include #include #include diff --git a/jclklib/client/client_state.hpp b/jclklib/client/client_state.hpp index 9f57d64f..32ecd301 100644 --- a/jclklib/client/client_state.hpp +++ b/jclklib/client/client_state.hpp @@ -1,3 +1,17 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file client_state.hpp + * @brief Set and get the client subscribe event state + * + * @author Noor Azura Ahmad Tarmizi + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ + #ifndef PROXY_CLIENT_STATE #define PROXY_CLIENT_STATE diff --git a/jclklib/client/connect_msg.cpp b/jclklib/client/connect_msg.cpp index 9c6719b8..b8c04a15 100644 --- a/jclklib/client/connect_msg.cpp +++ b/jclklib/client/connect_msg.cpp @@ -1,9 +1,16 @@ -/*! \file connect_msg.cpp - \brief Client connect message class. Implements client specific functionality. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file connect_msg.cpp + * @brief Client connect message class. Implements client specific functionality. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/client/connect_msg.hpp b/jclklib/client/connect_msg.hpp index 2deb14ad..4804a075 100644 --- a/jclklib/client/connect_msg.hpp +++ b/jclklib/client/connect_msg.hpp @@ -1,9 +1,16 @@ -/*! \file connect_msg.hpp - \brief Client connect message class. Implements client specific functionality. - - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file connect_msg.hpp + * @brief Client connect message class. Implements client specific functionality. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #ifndef CLIENT_CONNECT_MSG_HPP #define CLIENT_CONNECT_MSG_HPP diff --git a/jclklib/client/init.cpp b/jclklib/client/init.cpp index a645ea53..dfcd03ad 100644 --- a/jclklib/client/init.cpp +++ b/jclklib/client/init.cpp @@ -1,9 +1,16 @@ -/*! \file init.cpp - \brief Client utilities to setup and cleanup the library. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file init.cpp + * @brief Client utilities to setup and cleanup the library. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/client/init.hpp b/jclklib/client/init.hpp index def6e1e9..52793401 100644 --- a/jclklib/client/init.hpp +++ b/jclklib/client/init.hpp @@ -1,9 +1,16 @@ -/*! \file init.hpp - \brief Client utilities to setup and cleanup the library. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file init.hpp + * @brief Client utilities to setup and cleanup the library. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #ifndef CLIENT_INIT_HPP #define CLIENT_INIT_HPP diff --git a/jclklib/client/message.cpp b/jclklib/client/message.cpp index 9ca8d0a9..8fc0551a 100644 --- a/jclklib/client/message.cpp +++ b/jclklib/client/message.cpp @@ -1,9 +1,16 @@ -/*! \file message.cpp - \brief Client message base class. Extended for specific messages such as connect and subscribe. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file message.cpp + * @brief Client message base class. Extended for specific messages such as connect and subscribe. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/client/message.hpp b/jclklib/client/message.hpp index 60d5f7e7..ffd0955b 100644 --- a/jclklib/client/message.hpp +++ b/jclklib/client/message.hpp @@ -1,9 +1,16 @@ -/*! \file message.hpp - \brief Client message base class. Extended for specific messages such as connect and subscribe. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file message.hpp + * @brief Client message base class. Extended for specific messages such as connect and subscribe. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/client/msgq_tport.cpp b/jclklib/client/msgq_tport.cpp index 47b9f12a..ce064287 100644 --- a/jclklib/client/msgq_tport.cpp +++ b/jclklib/client/msgq_tport.cpp @@ -1,9 +1,16 @@ -/*! \file msgq_tport.cpp - \brief Client POSIX message queue transport class. - - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file msgq_tport.cpp + * @brief Client POSIX message queue transport class. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/client/msgq_tport.hpp b/jclklib/client/msgq_tport.hpp index e3fc17f8..474b2597 100644 --- a/jclklib/client/msgq_tport.hpp +++ b/jclklib/client/msgq_tport.hpp @@ -1,9 +1,16 @@ -/*! \file msgq_tport.hpp - \brief Client POSIX message queue transport class. - - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file msgq_tport.hpp + * @brief Client POSIX message queue transport class. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/client/notification_msg.cpp b/jclklib/client/notification_msg.cpp index 69ff15f0..ee484a7a 100644 --- a/jclklib/client/notification_msg.cpp +++ b/jclklib/client/notification_msg.cpp @@ -1,9 +1,16 @@ -/*! \file notification_msg.cpp - \brief Client notification message implementation. Implements client specific notification message function. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2024. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file notification_msg.hpp + * @brief Client notification message class. Implements client specific notification message function. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include @@ -132,4 +139,4 @@ PARSE_RXBUFFER_TYPE(ClientNotificationMessage::parseBuffer) return false; return true; -} +} \ No newline at end of file diff --git a/jclklib/client/notification_msg.hpp b/jclklib/client/notification_msg.hpp index d01d22d7..980ba672 100644 --- a/jclklib/client/notification_msg.hpp +++ b/jclklib/client/notification_msg.hpp @@ -1,9 +1,16 @@ -/*! \file notification_msg.hpp - \brief Client notification message class. Implements client specific notification message function. - - (C) Copyright Intel Corporation 2024. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file notification_msg.hpp + * @brief Client notification message class. Implements client specific notification message function. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include diff --git a/jclklib/client/null_msg.hpp b/jclklib/client/null_msg.hpp index 942db27f..e28c4a44 100644 --- a/jclklib/client/null_msg.hpp +++ b/jclklib/client/null_msg.hpp @@ -1,9 +1,16 @@ -/*! \file null_msg.hpp - \brief Non-functional message class for debug +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file null_msg.hpp + * @brief Non-functional message class for debug + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/client/null_tport.cpp b/jclklib/client/null_tport.cpp index f4fc2582..2ed82378 100644 --- a/jclklib/client/null_tport.cpp +++ b/jclklib/client/null_tport.cpp @@ -1,9 +1,16 @@ -/*! \file null_tport.cpp - \brief Null transport implementation. Non-functional for testing only. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file null_tport.cpp + * @brief Null transport implementation. Non-functional for testing only. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/client/null_tport.hpp b/jclklib/client/null_tport.hpp index f1648a1e..294f2b20 100644 --- a/jclklib/client/null_tport.hpp +++ b/jclklib/client/null_tport.hpp @@ -1,9 +1,16 @@ -/*! \file null_tport.hpp - \brief Null transport class. Non-functional for testing only. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file null_tport.cpp + * @brief Null transport implementation. Non-functional for testing only. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #ifndef CLIENT_NULL_TPORT_HPP #define CLIENT_NULL_TPORT_HPP diff --git a/jclklib/client/run_test.sh b/jclklib/client/run_test.sh index 0c8ac890..0bf77d6c 100755 --- a/jclklib/client/run_test.sh +++ b/jclklib/client/run_test.sh @@ -1,4 +1,12 @@ #!/bin/bash +# SPDX-License-Identifier: LGPL-3.0-or-later +# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. +# +# @author Christopher Hall +# @copyright © 2024 Intel Corporation. All rights reserved. +# @license LGPL-3.0-or-later +# +############################################################################### TEST_PATH=/home/ubuntu20/siemens/libptpmgmt_iaclocklib_org/jclklib/client/ diff --git a/jclklib/client/subscribe_msg.cpp b/jclklib/client/subscribe_msg.cpp index 10de6c35..13f58324 100644 --- a/jclklib/client/subscribe_msg.cpp +++ b/jclklib/client/subscribe_msg.cpp @@ -1,9 +1,16 @@ -/*! \file subscribe_msg.cpp - \brief Client subscribe message class. Implements client specific functionality. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - @author: Noor Azura Ahmad Tarmizi -*/ +/** @file subscribe_msg.cpp + * @brief Client subscribe message class. Implements client specific functionality. + * + * @author Noor Azura Ahmad Tarmizi + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/client/subscribe_msg.hpp b/jclklib/client/subscribe_msg.hpp index e982c3a6..dd8ce97d 100644 --- a/jclklib/client/subscribe_msg.hpp +++ b/jclklib/client/subscribe_msg.hpp @@ -1,9 +1,16 @@ -/*! \file subscribe_msg.hpp - \brief Client subscribe message class. Implements client specific functionality. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - @author: Noor Azura Ahmad Tarmizi -*/ +/** @file subscribe_msg.hpp + * @brief Client subscribe message class. Implements client specific functionality. + * + * @author Noor Azura Ahmad Tarmizi + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #ifndef CLIENT_SUBSCRIBE_MSG_HPP #define CLIENT_SUBSCRIBE_MSG_HPP diff --git a/jclklib/client/test.cpp b/jclklib/client/test.cpp index 24279d33..5f26e4f3 100644 --- a/jclklib/client/test.cpp +++ b/jclklib/client/test.cpp @@ -1,9 +1,16 @@ -/*! \file test.cpp - \brief Test client code - - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/* + * 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 "init.hpp" diff --git a/jclklib/client/transport.cpp b/jclklib/client/transport.cpp index 782a5251..d8be674f 100644 --- a/jclklib/client/transport.cpp +++ b/jclklib/client/transport.cpp @@ -1,9 +1,16 @@ -/*! \file transport.cpp - \brief Client transport base implementation for JClkLib. It is extended for specific transports such as POSIX message queue. - - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file transport.cpp + * @brief Client transport base implementation for JClkLib. It is extended for specific transports such as POSIX message queue. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/client/transport.hpp b/jclklib/client/transport.hpp index 5c9f749f..0ae9009e 100644 --- a/jclklib/client/transport.hpp +++ b/jclklib/client/transport.hpp @@ -1,9 +1,16 @@ -/*! \file transport.hpp - \brief Client transport base class for JClkLib. It is extended for specific transports such as POSIX message queue. - - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file transport.hpp + * @brief Client transport base class for JClkLib. It is extended for specific transports such as POSIX message queue. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include From 1e8feb4c4e207b218f21289a49d467596a1beac2 Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Wed, 8 May 2024 11:08:47 +0800 Subject: [PATCH 045/151] jclklib: common: Add copyright license header Signed-off-by: Lai Peter Jun Ann --- jclklib/common/Makefile | 12 ++++++++---- jclklib/common/connect_msg.cpp | 19 +++++++++++++------ jclklib/common/connect_msg.hpp | 17 ++++++++++++----- jclklib/common/jclklib_import.cpp | 19 +++++++++++++------ jclklib/common/jclklib_import.hpp | 19 +++++++++++++------ jclklib/common/jcltypes.hpp | 14 ++++++++++++++ jclklib/common/message.cpp | 19 +++++++++++++------ jclklib/common/message.hpp | 19 +++++++++++++------ jclklib/common/msgq_tport.cpp | 19 +++++++++++++------ jclklib/common/msgq_tport.hpp | 17 ++++++++++++----- jclklib/common/mutex_signal.cpp | 14 ++++++++++++++ jclklib/common/mutex_signal.hpp | 14 ++++++++++++++ jclklib/common/notification_msg.cpp | 17 ++++++++++++----- jclklib/common/notification_msg.hpp | 17 ++++++++++++----- jclklib/common/null_msg.cpp | 17 ++++++++++++----- jclklib/common/null_msg.hpp | 17 ++++++++++++----- jclklib/common/null_tport.hpp | 17 ++++++++++++----- jclklib/common/print.cpp | 17 ++++++++++++----- jclklib/common/print.hpp | 19 +++++++++++++------ jclklib/common/serialize.hpp | 17 ++++++++++++----- jclklib/common/sighandler.cpp | 19 +++++++++++++------ jclklib/common/sighandler.hpp | 17 ++++++++++++----- jclklib/common/subscribe_msg.cpp | 19 +++++++++++++------ jclklib/common/subscribe_msg.hpp | 17 ++++++++++++----- jclklib/common/transport.cpp | 19 +++++++++++++------ jclklib/common/transport.hpp | 17 ++++++++++++----- jclklib/common/util.hpp | 19 +++++++++++++------ 27 files changed, 337 insertions(+), 130 deletions(-) diff --git a/jclklib/common/Makefile b/jclklib/common/Makefile index 14acaf2a..942416ad 100644 --- a/jclklib/common/Makefile +++ b/jclklib/common/Makefile @@ -1,9 +1,13 @@ -##! \file Makefile -# \brief Common makefile +# SPDX-License-Identifier: LGPL-3.0-or-later +# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. # -# (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. -# Author: Christopher Hall +# Makefile for jclklib common # +# @author Christopher Hall +# @copyright © 2024 Intel Corporation. All rights reserved. +# @license LGPL-3.0-or-later +# +############################################################################### JCLKLIB_COMMON_DIR := $(shell pwd) JCLKLIB_TOPLEVEL_DIR := $(JCLKLIB_COMMON_DIR)/.. diff --git a/jclklib/common/connect_msg.cpp b/jclklib/common/connect_msg.cpp index 535ca681..3475b75f 100644 --- a/jclklib/common/connect_msg.cpp +++ b/jclklib/common/connect_msg.cpp @@ -1,9 +1,16 @@ -/*! \file connect_msg.cpp - \brief Common connect message implementation. Implements common functions and (de-)serialization - - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file connect_msg.cpp + * @brief Common connect message implementation. Implements common functions and (de-)serialization + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/common/connect_msg.hpp b/jclklib/common/connect_msg.hpp index f14fbf62..a0105baf 100644 --- a/jclklib/common/connect_msg.hpp +++ b/jclklib/common/connect_msg.hpp @@ -1,9 +1,16 @@ -/*! \file connect_msg.hpp - \brief Common connect message class. Implements common functions and (de-)serialization +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file connect_msg.hpp + * @brief Common connect message class. Implements common functions and (de-)serialization + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include diff --git a/jclklib/common/jclklib_import.cpp b/jclklib/common/jclklib_import.cpp index 04decfda..296817bf 100644 --- a/jclklib/common/jclklib_import.cpp +++ b/jclklib/common/jclklib_import.cpp @@ -1,9 +1,16 @@ -/*! \file jclklib_import.cpp - \brief C API import. - - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file jclklib_import.cpp + * @brief C API import. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/common/jclklib_import.hpp b/jclklib/common/jclklib_import.hpp index 72ca344f..71c22a17 100644 --- a/jclklib/common/jclklib_import.hpp +++ b/jclklib/common/jclklib_import.hpp @@ -1,9 +1,16 @@ -/*! \file jclklib_import.hpp - \brief C API import. - - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file jclklib_import.hpp + * @brief C API import. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include diff --git a/jclklib/common/jcltypes.hpp b/jclklib/common/jcltypes.hpp index 86f3c3e3..2235818e 100644 --- a/jclklib/common/jcltypes.hpp +++ b/jclklib/common/jcltypes.hpp @@ -1,3 +1,17 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file jcltypes.hpp + * @brief Common message type + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ + #include #ifndef COMMON_JCLTYPES_HPP diff --git a/jclklib/common/message.cpp b/jclklib/common/message.cpp index d0e0fe9c..8ae0f6a9 100644 --- a/jclklib/common/message.cpp +++ b/jclklib/common/message.cpp @@ -1,9 +1,16 @@ -/*! \file message.cpp - \brief Common message base implementation. Extended for specific messages such as connect and subscribe. - - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file message.cpp + * @brief Common message base implementation. Extended for specific messages such as connect and subscribe. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/common/message.hpp b/jclklib/common/message.hpp index 3ff0949d..c75d577f 100644 --- a/jclklib/common/message.hpp +++ b/jclklib/common/message.hpp @@ -1,9 +1,16 @@ -/*! \file message.hpp - \brief Common message base class. Extended for specific messages such as connect and subscribe. - - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file message.hpp + * @brief Common message base class. Extended for specific messages such as connect and subscribe. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/common/msgq_tport.cpp b/jclklib/common/msgq_tport.cpp index 3dc988a1..a844596f 100644 --- a/jclklib/common/msgq_tport.cpp +++ b/jclklib/common/msgq_tport.cpp @@ -1,9 +1,16 @@ -/*! \file msgq_tport.cpp - \brief Common POSIX message queue transport implementation. - - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file msgq_tport.cpp + * @brief Common POSIX message queue transport implementation. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/common/msgq_tport.hpp b/jclklib/common/msgq_tport.hpp index c5f1a699..b4fd2b0f 100644 --- a/jclklib/common/msgq_tport.hpp +++ b/jclklib/common/msgq_tport.hpp @@ -1,9 +1,16 @@ -/*! \file msgq_tport.hpp - \brief Common POSIX message queue transport class. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file msgq_tport.hpp + * @brief Common POSIX message queue transport class. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/common/mutex_signal.cpp b/jclklib/common/mutex_signal.cpp index cadd6973..561053af 100644 --- a/jclklib/common/mutex_signal.cpp +++ b/jclklib/common/mutex_signal.cpp @@ -1,3 +1,17 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file mutex_signal.cpp + * @brief Common pthread mutex implementation. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ + #include #include diff --git a/jclklib/common/mutex_signal.hpp b/jclklib/common/mutex_signal.hpp index 7e767fa9..3000488e 100644 --- a/jclklib/common/mutex_signal.hpp +++ b/jclklib/common/mutex_signal.hpp @@ -1,3 +1,17 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file mutex_signal.hpp + * @brief Common pthread mutex implementation. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ + #include #include diff --git a/jclklib/common/notification_msg.cpp b/jclklib/common/notification_msg.cpp index 3180a1d6..c2a085c1 100644 --- a/jclklib/common/notification_msg.cpp +++ b/jclklib/common/notification_msg.cpp @@ -1,9 +1,16 @@ -/*! \file notification_msg.cpp - \brief Common notification message implementation. Implements common functions and (de-)serialization +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file notification_msg.cpp + * @brief Common notification message implementation. Implements common functions and (de-)serialization + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/common/notification_msg.hpp b/jclklib/common/notification_msg.hpp index 1c24730d..10c722e9 100644 --- a/jclklib/common/notification_msg.hpp +++ b/jclklib/common/notification_msg.hpp @@ -1,9 +1,16 @@ -/*! \file notification_msg.hpp - \brief Common notification message class. Implements common functions and (de-)serialization +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file notification_msg.hpp + * @brief Common notification message class. Implements common functions and (de-)serialization + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include diff --git a/jclklib/common/null_msg.cpp b/jclklib/common/null_msg.cpp index a6cc3d71..f13e36e8 100644 --- a/jclklib/common/null_msg.cpp +++ b/jclklib/common/null_msg.cpp @@ -1,9 +1,16 @@ -/*! \file null_msg.cpp - \brief Non-functional message implementation for debug +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file null_msg.cpp + * @brief Non-functional message implementation for debug + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include diff --git a/jclklib/common/null_msg.hpp b/jclklib/common/null_msg.hpp index 3c616b21..990aad9f 100644 --- a/jclklib/common/null_msg.hpp +++ b/jclklib/common/null_msg.hpp @@ -1,9 +1,16 @@ -/*! \file null_msg.hpp - \brief Non-functional message class for debug +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file null_msg.hpp + * @brief Non-functional message class for debug + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #ifndef COMMON_NULL_MSG_HPP #define COMMON_NULL_MSG_HPP diff --git a/jclklib/common/null_tport.hpp b/jclklib/common/null_tport.hpp index 9ff2b990..8ca25e6b 100644 --- a/jclklib/common/null_tport.hpp +++ b/jclklib/common/null_tport.hpp @@ -1,9 +1,16 @@ -/*! \file null_tport.hpp - \brief Null transport class. Non-functional for testing only. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file null_tport.hpp + * @brief Null transport class. Non-functional for testing only. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #ifndef NULL_TPORT_HPP #define NULL_TPORT_HPP diff --git a/jclklib/common/print.cpp b/jclklib/common/print.cpp index 253f80ad..6dff402f 100644 --- a/jclklib/common/print.cpp +++ b/jclklib/common/print.cpp @@ -1,9 +1,16 @@ -/*! \file print.cpp - \brief Utility functions for printing +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file print.cpp + * @brief Utility functions for printing + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include diff --git a/jclklib/common/print.hpp b/jclklib/common/print.hpp index e7a6890e..7de8b206 100644 --- a/jclklib/common/print.hpp +++ b/jclklib/common/print.hpp @@ -1,9 +1,16 @@ -/*! \file print.hpp - \brief Utility functions for printing - - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file print.hpp + * @brief Utility functions for printing + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/common/serialize.hpp b/jclklib/common/serialize.hpp index 9b5d16db..743b1ed4 100644 --- a/jclklib/common/serialize.hpp +++ b/jclklib/common/serialize.hpp @@ -1,9 +1,16 @@ -/*! \file serialize.hpp - \brief Utility macros for (de-)serializing data +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file serialize.hpp + * @brief Utility macros for (de-)serializing data + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/common/sighandler.cpp b/jclklib/common/sighandler.cpp index 813b2f5a..f44ed74f 100644 --- a/jclklib/common/sighandler.cpp +++ b/jclklib/common/sighandler.cpp @@ -1,9 +1,16 @@ -/*! \file sighandler.cpp - \brief Signal handling utilities - - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file sighandler.cpp + * @brief Signal handling utilities + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/common/sighandler.hpp b/jclklib/common/sighandler.hpp index f73b925c..ed61892f 100644 --- a/jclklib/common/sighandler.hpp +++ b/jclklib/common/sighandler.hpp @@ -1,9 +1,16 @@ -/*! \file sighandler.hpp - \brief Signal handling utilities +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file sighandler.hpp + * @brief Signal handling utilities + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #ifndef SIGHANDLER_HPP #define SIGHANDLER_HPP diff --git a/jclklib/common/subscribe_msg.cpp b/jclklib/common/subscribe_msg.cpp index e33b2ecd..b59d33d3 100644 --- a/jclklib/common/subscribe_msg.cpp +++ b/jclklib/common/subscribe_msg.cpp @@ -1,9 +1,16 @@ -/*! \file subscribe_msg.cpp - \brief Common subscribe message implementation. Implements common functions and (de-)serialization - - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file subscribe_msg.cpp + * @brief Common subscribe message implementation. Implements common functions and (de-)serialization + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/common/subscribe_msg.hpp b/jclklib/common/subscribe_msg.hpp index a6108475..fabee0d4 100644 --- a/jclklib/common/subscribe_msg.hpp +++ b/jclklib/common/subscribe_msg.hpp @@ -1,9 +1,16 @@ -/*! \file subscribe_msg.hpp - \brief Common subscribe message class. Implements common functions and (de-)serialization +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file subscribe_msg.hpp + * @brief Common subscribe message class. Implements common functions and (de-)serialization + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #ifndef COMMON_SUBSCRIBE_MSG_HPP #define COMMON_SUBSCRIBE_MSG_HPP diff --git a/jclklib/common/transport.cpp b/jclklib/common/transport.cpp index 64efad32..ab323f60 100644 --- a/jclklib/common/transport.cpp +++ b/jclklib/common/transport.cpp @@ -1,9 +1,16 @@ -/*! \file transport.cpp - \brief Common transport base class implementation for JClkLib. It provides common functionality for derived transport classes. - - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file transport.cpp + * @brief Common transport base class implementation for JClkLib. It provides common functionality for derived transport classes. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/common/transport.hpp b/jclklib/common/transport.hpp index 3d16b45c..5d645d48 100644 --- a/jclklib/common/transport.hpp +++ b/jclklib/common/transport.hpp @@ -1,9 +1,16 @@ -/*! \file transport.hpp - \brief Common transport base class for JClkLib. It is extended for specific transports such as POSIX message queue. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file transport.hpp + * @brief Common transport base class for JClkLib. It is extended for specific transports such as POSIX message queue. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/common/util.hpp b/jclklib/common/util.hpp index 9ff0b65c..9a4b0988 100644 --- a/jclklib/common/util.hpp +++ b/jclklib/common/util.hpp @@ -1,9 +1,16 @@ -/*! \file util.hpp - \brief Helper functions, templates, and macros - - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file util.hpp + * @brief Helper functions, templates, and macros + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include From deccad668b8bbd6809a048f233c8000702910c7d Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Wed, 8 May 2024 11:26:55 +0800 Subject: [PATCH 046/151] jclklib: proxy: Add copyright license header Signed-off-by: Lai Peter Jun Ann --- jclklib/.gitignore | 9 +++++++++ jclklib/Makefile | 12 ++++++++---- jclklib/proxy/Makefile | 12 ++++++++---- jclklib/proxy/client.cpp | 14 ++++++++++++++ jclklib/proxy/client.hpp | 14 ++++++++++++++ jclklib/proxy/clock_config.cpp | 17 ++++++++++++----- jclklib/proxy/clock_config.hpp | 19 +++++++++++++------ jclklib/proxy/clock_status.cpp | 17 ++++++++++++----- jclklib/proxy/clock_status.hpp | 17 ++++++++++++----- jclklib/proxy/connect.cpp | 17 ++++++++++++----- jclklib/proxy/connect.hpp | 17 ++++++++++++----- jclklib/proxy/connect_msg.cpp | 17 ++++++++++++----- jclklib/proxy/connect_msg.hpp | 19 +++++++++++++------ jclklib/proxy/main.cpp | 17 ++++++++++++----- jclklib/proxy/message.cpp | 17 ++++++++++++----- jclklib/proxy/message.hpp | 17 ++++++++++++----- jclklib/proxy/msgq_tport.cpp | 19 +++++++++++++------ jclklib/proxy/msgq_tport.hpp | 17 ++++++++++++----- jclklib/proxy/notification_msg.cpp | 17 ++++++++++++----- jclklib/proxy/notification_msg.hpp | 19 +++++++++++++------ jclklib/proxy/null_msg.hpp | 17 ++++++++++++----- jclklib/proxy/null_tport.cpp | 17 ++++++++++++----- jclklib/proxy/null_tport.hpp | 17 ++++++++++++----- jclklib/proxy/run_ptp4l.sh | 10 ++++++++++ jclklib/proxy/subscribe_msg.cpp | 17 ++++++++++++----- jclklib/proxy/subscribe_msg.hpp | 17 ++++++++++++----- jclklib/proxy/thread.cpp | 17 ++++++++++++----- jclklib/proxy/thread.hpp | 18 +++++++++++++----- jclklib/proxy/transport.cpp | 19 +++++++++++++------ jclklib/proxy/transport.hpp | 19 +++++++++++++------ 30 files changed, 358 insertions(+), 134 deletions(-) diff --git a/jclklib/.gitignore b/jclklib/.gitignore index eb24d0ba..2c567b24 100644 --- a/jclklib/.gitignore +++ b/jclklib/.gitignore @@ -1,2 +1,11 @@ +# SPDX-License-Identifier: LGPL-3.0-or-later +# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. +# +# @author Christopher Hall +# @copyright © 2024 Intel Corporation. All rights reserved. +# @license LGPL-3.0-or-later +# +############################################################################### + client/test proxy/jclklib_proxy diff --git a/jclklib/Makefile b/jclklib/Makefile index aa4b0b5d..44d41bbf 100644 --- a/jclklib/Makefile +++ b/jclklib/Makefile @@ -1,9 +1,13 @@ -##! \file Makefile -# \brief top level makefile +# SPDX-License-Identifier: LGPL-3.0-or-later +# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. # -# (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. -# Author: Christopher Hall +# Makefile for jclklib # +# @author Christopher Hall +# @copyright © 2024 Intel Corporation. All rights reserved. +# @license LGPL-3.0-or-later +# +############################################################################### CWD := $(shell pwd) diff --git a/jclklib/proxy/Makefile b/jclklib/proxy/Makefile index 14a3153b..7a6ddc7d 100644 --- a/jclklib/proxy/Makefile +++ b/jclklib/proxy/Makefile @@ -1,9 +1,13 @@ -##! \file Makefile -# \brief Proxy makefile +# SPDX-License-Identifier: LGPL-3.0-or-later +# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. # -# (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. -# Author: Christopher Hall +# Makefile for jclklib proxy # +# @author Christopher Hall +# @copyright © 2024 Intel Corporation. All rights reserved. +# @license LGPL-3.0-or-later +# +############################################################################### JCLKLIB_PROXY_DIR := $(shell pwd) JCLKLIB_TOPLEVEL_DIR = $(JCLKLIB_PROXY_DIR)/.. diff --git a/jclklib/proxy/client.cpp b/jclklib/proxy/client.cpp index 444979f0..22e3ed26 100644 --- a/jclklib/proxy/client.cpp +++ b/jclklib/proxy/client.cpp @@ -1,3 +1,17 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file client.cpp + * @brief Common client infomation implementation + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ + #include #include diff --git a/jclklib/proxy/client.hpp b/jclklib/proxy/client.hpp index b0b2b62a..0d51d89d 100644 --- a/jclklib/proxy/client.hpp +++ b/jclklib/proxy/client.hpp @@ -1,3 +1,17 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file client.hpp + * @brief Common client infomation implementation + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ + #include #ifndef PROXY_CLIENT diff --git a/jclklib/proxy/clock_config.cpp b/jclklib/proxy/clock_config.cpp index 3a615da1..e0439c4a 100644 --- a/jclklib/proxy/clock_config.cpp +++ b/jclklib/proxy/clock_config.cpp @@ -1,9 +1,16 @@ -/*! \file clock_config.cpp - \brief Proxy configuration implementation. One configuration object per session is instatiated +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file clock_config.cpp + * @brief Proxy configuration implementation. One configuration object per session is instatiated + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include diff --git a/jclklib/proxy/clock_config.hpp b/jclklib/proxy/clock_config.hpp index 3a01947c..85b71390 100644 --- a/jclklib/proxy/clock_config.hpp +++ b/jclklib/proxy/clock_config.hpp @@ -1,9 +1,16 @@ -/*! \file clock_config.hpp - \brief Proxy configuration class. One configuration object per session is instatiated - - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file clock_config.hpp + * @brief Proxy configuration class. One configuration object per session is instatiated + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/proxy/clock_status.cpp b/jclklib/proxy/clock_status.cpp index 2ad8f5dc..03943a6c 100644 --- a/jclklib/proxy/clock_status.cpp +++ b/jclklib/proxy/clock_status.cpp @@ -1,9 +1,16 @@ -/*! \file clock_status.cpp - \brief Proxy status implementation. One status object per session. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file clock_status.cpp + * @brief Proxy status implementation. One status object per session. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include diff --git a/jclklib/proxy/clock_status.hpp b/jclklib/proxy/clock_status.hpp index 6b1274db..5bbcba33 100644 --- a/jclklib/proxy/clock_status.hpp +++ b/jclklib/proxy/clock_status.hpp @@ -1,9 +1,16 @@ -/*! \file clock_status.hpp - \brief Proxy status class. One status object per session. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file clock_status.hpp + * @brief Proxy status class. One status object per session. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include diff --git a/jclklib/proxy/connect.cpp b/jclklib/proxy/connect.cpp index d11b454c..578d8b89 100644 --- a/jclklib/proxy/connect.cpp +++ b/jclklib/proxy/connect.cpp @@ -1,9 +1,16 @@ -/*! \file connect.cpp - \brief Proxy connect message class. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Lai Peter Jun Ann -*/ +/** @file connect.cpp + * @brief Proxy connect ptp4l message class. + * + * @author Lai Peter Jun Ann + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/proxy/connect.hpp b/jclklib/proxy/connect.hpp index ed206a28..c6854dd5 100644 --- a/jclklib/proxy/connect.hpp +++ b/jclklib/proxy/connect.hpp @@ -1,9 +1,16 @@ -/*! \file connect.hpp - \brief Proxy connect message class. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Lai Peter Jun Ann -*/ +/** @file connect.hpp + * @brief Proxy connect ptp4l message class. + * + * @author Lai Peter Jun Ann + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/proxy/connect_msg.cpp b/jclklib/proxy/connect_msg.cpp index 32b37ecf..fe60386a 100644 --- a/jclklib/proxy/connect_msg.cpp +++ b/jclklib/proxy/connect_msg.cpp @@ -1,9 +1,16 @@ -/*! \file connect_msg.cpp - \brief Proxy connect message implementation. Implements proxy specific connect message function. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file connect_msg.cpp + * @brief Proxy connect message implementation. Implements proxy specific connect message function. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/proxy/connect_msg.hpp b/jclklib/proxy/connect_msg.hpp index 41470350..a8b3e7dd 100644 --- a/jclklib/proxy/connect_msg.hpp +++ b/jclklib/proxy/connect_msg.hpp @@ -1,9 +1,16 @@ -/*! \file connect_msg.hpp - \brief Proxy connect message class. Implements proxy specific connect message function. - - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file connect_msg.hpp + * @brief Proxy connect message class. Implements proxy specific connect message function. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #ifndef PROXY_CONNECT_MSG_HPP #define PROXY_CONNECT_MSG_HPP diff --git a/jclklib/proxy/main.cpp b/jclklib/proxy/main.cpp index 9699831e..757641dd 100644 --- a/jclklib/proxy/main.cpp +++ b/jclklib/proxy/main.cpp @@ -1,9 +1,16 @@ -/*! \file main.cpp - \brief Proxy application implementation +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file main.cpp + * @brief Proxy application implementation + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/proxy/message.cpp b/jclklib/proxy/message.cpp index 0bf80fdd..13655532 100644 --- a/jclklib/proxy/message.cpp +++ b/jclklib/proxy/message.cpp @@ -1,9 +1,16 @@ -/*! \file message.cpp - \brief Proxy message base implementation. Extended for specific messages such as connect and subscribe. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file message.cpp + * @brief Proxy message base implementation. Extended for specific messages such as connect and subscribe. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/proxy/message.hpp b/jclklib/proxy/message.hpp index 4698856e..553d798e 100644 --- a/jclklib/proxy/message.hpp +++ b/jclklib/proxy/message.hpp @@ -1,9 +1,16 @@ -/*! \file message.hpp - \brief Proxy message base class. Extended for specific messages such as connect and subscribe. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file message.hpp + * @brief Proxy message base class. Extended for specific messages such as connect and subscribe. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/proxy/msgq_tport.cpp b/jclklib/proxy/msgq_tport.cpp index c99661d0..d8123c97 100644 --- a/jclklib/proxy/msgq_tport.cpp +++ b/jclklib/proxy/msgq_tport.cpp @@ -1,9 +1,16 @@ -/*! \file msgq_tport.cpp - \brief Proxy POSIX message queue transport implementation. - - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file msgq_tport.cpp + * @brief Proxy POSIX message queue transport implementation. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/proxy/msgq_tport.hpp b/jclklib/proxy/msgq_tport.hpp index fa939d5a..baf5b22a 100644 --- a/jclklib/proxy/msgq_tport.hpp +++ b/jclklib/proxy/msgq_tport.hpp @@ -1,9 +1,16 @@ -/*! \file msgq_tport.hpp - \brief Proxy POSIX message queue transport class. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file msgq_tport.hpp + * @brief Proxy POSIX message queue transport class. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/proxy/notification_msg.cpp b/jclklib/proxy/notification_msg.cpp index b2812853..2ce6b7ce 100644 --- a/jclklib/proxy/notification_msg.cpp +++ b/jclklib/proxy/notification_msg.cpp @@ -1,9 +1,16 @@ -/*! \file notification_msg.cpp - \brief Proxy notification message implementation. Implements proxy specific notification message function. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2024. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file notification_msg.cpp + * @brief Proxy notification message implementation. Implements proxy specific notification message function. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/proxy/notification_msg.hpp b/jclklib/proxy/notification_msg.hpp index 23ce2e83..237eb15f 100644 --- a/jclklib/proxy/notification_msg.hpp +++ b/jclklib/proxy/notification_msg.hpp @@ -1,9 +1,16 @@ -/*! \file notification_msg.hpp - \brief Proxy notification message class. Implements proxy specific notification message function. - - (C) Copyright Intel Corporation 2024. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file notification_msg.hpp + * @brief Proxy notification message class. Implements proxy specific notification message function. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include diff --git a/jclklib/proxy/null_msg.hpp b/jclklib/proxy/null_msg.hpp index 6a3bb5b4..6fed2f52 100644 --- a/jclklib/proxy/null_msg.hpp +++ b/jclklib/proxy/null_msg.hpp @@ -1,9 +1,16 @@ -/*! \file null_msg.hpp - \brief Proxy null message class. Used for debug only. Should not be used. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file null_msg.hpp + * @brief Proxy null message class. Used for debug only. Should not be used. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #ifndef PROXY_NULL_MSG_HPP #define PROXY_NULL_MSG_HPP diff --git a/jclklib/proxy/null_tport.cpp b/jclklib/proxy/null_tport.cpp index 00b37450..2421610c 100644 --- a/jclklib/proxy/null_tport.cpp +++ b/jclklib/proxy/null_tport.cpp @@ -1,9 +1,16 @@ -/*! \file null_tport.cpp - \brief Null transport implementation. Non-functional for testing only. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file null_tport.cpp + * @brief Null transport implementation. Non-functional for testing only. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/proxy/null_tport.hpp b/jclklib/proxy/null_tport.hpp index 33aabb9d..44cad8a4 100644 --- a/jclklib/proxy/null_tport.hpp +++ b/jclklib/proxy/null_tport.hpp @@ -1,9 +1,16 @@ -/*! \file null_tport.hpp - \brief Null transport class. Non-functional for testing only. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file null_tport.hpp + * @brief Null transport class. Non-functional for testing only. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #ifndef PROXY_NULL_TPORT_HPP #define PROXY_NULL_TPORT_HPP diff --git a/jclklib/proxy/run_ptp4l.sh b/jclklib/proxy/run_ptp4l.sh index 97f9fed3..65da1b47 100644 --- a/jclklib/proxy/run_ptp4l.sh +++ b/jclklib/proxy/run_ptp4l.sh @@ -1,3 +1,13 @@ +#!/bin/bash +# SPDX-License-Identifier: LGPL-3.0-or-later +# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. +# +# @author Christopher Hall +# @copyright © 2024 Intel Corporation. All rights reserved. +# @license LGPL-3.0-or-later +# +############################################################################### + #clone the linux-ptp repo and make git clone https://github.com/intel-staging/linux-ptp_iaclocklib.git cd linux-ptp_iaclocklib/ diff --git a/jclklib/proxy/subscribe_msg.cpp b/jclklib/proxy/subscribe_msg.cpp index cace2576..67abb52b 100644 --- a/jclklib/proxy/subscribe_msg.cpp +++ b/jclklib/proxy/subscribe_msg.cpp @@ -1,9 +1,16 @@ -/*! \file subscribe_msg.cpp - \brief Proxy subscribe message implementation. Implements proxy specific subscribe message function. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file subscribe_msg.cpp + * @brief Proxy subscribe message implementation. Implements proxy specific subscribe message function. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/proxy/subscribe_msg.hpp b/jclklib/proxy/subscribe_msg.hpp index 52d05621..d03cd588 100644 --- a/jclklib/proxy/subscribe_msg.hpp +++ b/jclklib/proxy/subscribe_msg.hpp @@ -1,9 +1,16 @@ -/*! \file subscribe_msg.hpp - \brief Proxy subscribe message class. Implements proxy specific subscribe message function. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/** @file subscribe_msg.hpp + * @brief Proxy subscribe message class. Implements proxy specific subscribe message function. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #ifndef PROXY_SUBSCRIBE_MSG_HPP #define PROXY_SUBSCRIBE_MSG_HPP diff --git a/jclklib/proxy/thread.cpp b/jclklib/proxy/thread.cpp index cae828f5..47de6281 100644 --- a/jclklib/proxy/thread.cpp +++ b/jclklib/proxy/thread.cpp @@ -1,9 +1,16 @@ -/*! \file thread.cpp - \brief Proxy message thread class. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Lai Peter Jun Ann -*/ +/** @file thread.cpp + * @brief Proxy message thread class. + * + * @author Lai Peter Jun Ann + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/proxy/thread.hpp b/jclklib/proxy/thread.hpp index 4bab8482..d29e7c12 100644 --- a/jclklib/proxy/thread.hpp +++ b/jclklib/proxy/thread.hpp @@ -1,9 +1,17 @@ -/*! \file thread.hpp - \brief Proxy message thread class. +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file thread.hpp + * @brief Proxy message thread class. + * + * @author Lai Peter Jun Ann + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Lai Peter Jun Ann -*/ #include #include #include diff --git a/jclklib/proxy/transport.cpp b/jclklib/proxy/transport.cpp index b2b02d3b..911e7646 100644 --- a/jclklib/proxy/transport.cpp +++ b/jclklib/proxy/transport.cpp @@ -1,9 +1,16 @@ -/*! \file transport.cpp - \brief Proxy transport base class implementation for JClkLib. It provides common functionality for derived transport classes. - - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file transport.cpp + * @brief Proxy transport base class implementation for JClkLib. It provides common functionality for derived transport classes. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include diff --git a/jclklib/proxy/transport.hpp b/jclklib/proxy/transport.hpp index 91d835b0..bc861281 100644 --- a/jclklib/proxy/transport.hpp +++ b/jclklib/proxy/transport.hpp @@ -1,9 +1,16 @@ -/*! \file transport.hpp - \brief Transport base class for JClkLib Proxy. It is extended for specific transports such as POSIX message queue. - - (C) Copyright Intel Corporation 2023. All rights reserved. Intel Confidential. - Author: Christopher Hall -*/ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file transport.hpp + * @brief Proxy transport base class for JClkLib. It provides common functionality for derived transport classes. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ #include #include From 9540357541ff3fc2ee619b1b83af55e2048115c8 Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Wed, 8 May 2024 20:43:42 +0800 Subject: [PATCH 047/151] Add copyright license header for yml file Signed-off-by: Lai Peter Jun Ann --- .github/workflows/codeql.yml | 10 +++++++++- .github/workflows/coverity.yml | 8 ++++++++ .github/workflows/scorecard.yml | 8 ++++++++ .github/workflows/virus_scan.yml | 9 +++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 3c7a6a78..bcc9af13 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -1,3 +1,10 @@ +# SPDX-License-Identifier: LGPL-3.0-or-later +# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. +# +# @author Song Yoong Siang +# @copyright © 2024 Intel Corporation. All rights reserved. +# @license LGPL-3.0-or-later +# # For most projects, this workflow file will not need changing; you simply need # to commit it to your repository. # @@ -8,7 +15,8 @@ # We have attempted to detect the languages in your repository. Please check # the `language` matrix defined below to confirm you have the correct set of # supported CodeQL languages. -# +############################################################################### + name: "CodeQL" on: diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml index 4eff9c9a..ce2c372c 100644 --- a/.github/workflows/coverity.yml +++ b/.github/workflows/coverity.yml @@ -1,4 +1,12 @@ +# SPDX-License-Identifier: LGPL-3.0-or-later +# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. +# +# @author Song Yoong Siang +# @copyright © 2024 Intel Corporation. All rights reserved. +# @license LGPL-3.0-or-later +# # Visit https://scan.coverity.com/projects/libptpmgmt_iaclocklib for coverity result +############################################################################### name: Coverity Scan diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml index e43eaa2b..a97480d6 100644 --- a/.github/workflows/scorecard.yml +++ b/.github/workflows/scorecard.yml @@ -1,6 +1,14 @@ +# SPDX-License-Identifier: LGPL-3.0-or-later +# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. +# +# @author Song Yoong Siang +# @copyright © 2024 Intel Corporation. All rights reserved. +# @license LGPL-3.0-or-later +# # This workflow uses actions that are not certified by GitHub. They are provided # by a third-party and are governed by separate terms of service, privacy # policy, and support documentation. +############################################################################### name: Scorecard supply-chain security on: diff --git a/.github/workflows/virus_scan.yml b/.github/workflows/virus_scan.yml index 35d4b330..6a22c90a 100644 --- a/.github/workflows/virus_scan.yml +++ b/.github/workflows/virus_scan.yml @@ -1,4 +1,13 @@ +# SPDX-License-Identifier: LGPL-3.0-or-later +# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. +# +# @author Song Yoong Siang +# @copyright © 2024 Intel Corporation. All rights reserved. +# @license LGPL-3.0-or-later +# # scan virus +############################################################################### + name: "Virus Scan" on: From 67f6208c5c44501746bc3d04c1f08bf4f34caf41 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Wed, 8 May 2024 11:08:45 +0800 Subject: [PATCH 048/151] jclklib: Add composite event support Allow user to set composite event where they will only be notified whether all events are meet or at least one of the event is not meet. Signed-off-by: Song Yoong Siang --- jclklib/client/init.cpp | 4 +++ jclklib/client/notification_msg.cpp | 34 ++++++++++++++++++++++++ jclklib/client/subscribe_msg.cpp | 27 +++++++++++++++++++ jclklib/client/test.cpp | 40 +++++++++++++++++++---------- jclklib/common/jclklib_import.hpp | 6 +++++ 5 files changed, 98 insertions(+), 13 deletions(-) diff --git a/jclklib/client/init.cpp b/jclklib/client/init.cpp index dfcd03ad..c658935d 100644 --- a/jclklib/client/init.cpp +++ b/jclklib/client/init.cpp @@ -102,6 +102,7 @@ bool JClkLibClient::jcl_subscribe(JClkLibCommon::jcl_subscription &newSub, /* Write the current event subscription */ state.get_eventSub().set_event(newSub.getc_event()); state.get_eventSub().set_value(newSub.getc_value()); + state.get_eventSub().set_composite_event(newSub.getc_composite_event()); cmsg->getSubscription().get_event().copyEventMask(newSub.get_event()); @@ -191,6 +192,7 @@ int JClkLibClient::jcl_status_wait(int timeout, JClkLibCommon::jcl_state &jcl_st eventCount.asCapable_event_count || eventCount.servo_locked_event_count || eventCount.gmPresent_event_count || + eventCount.composite_event_count || eventCount.gm_changed_event_count) { event_changes_detected = true; break; @@ -214,6 +216,8 @@ int JClkLibClient::jcl_status_wait(int timeout, JClkLibCommon::jcl_state &jcl_st std::memory_order_relaxed); client_ptp_data.gmChanged_event_count.fetch_sub(eventCount.gm_changed_event_count, std::memory_order_relaxed); + client_ptp_data.composite_event_count.fetch_sub(eventCount.composite_event_count, + std::memory_order_relaxed); return true; } diff --git a/jclklib/client/notification_msg.cpp b/jclklib/client/notification_msg.cpp index ee484a7a..14762d2d 100644 --- a/jclklib/client/notification_msg.cpp +++ b/jclklib/client/notification_msg.cpp @@ -22,6 +22,7 @@ using namespace JClkLibCommon; using namespace JClkLibClient; JClkLibCommon::client_ptp_event client_ptp_data; +JClkLibCommon::client_ptp_event composite_client_ptp_data; JClkLibCommon::ptp_event proxy_data = {}; JClkLibCommon::jcl_state jclCurrentState = {}; JClkLibCommon::jcl_state_event_count jclCurrentEventCount = {}; @@ -64,6 +65,9 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) std::uint32_t eventSub[1]; state.get_eventSub().get_event().readEvent(eventSub, (std::size_t)sizeof(eventSub)); + std::uint32_t composite_eventSub[1]; + state.get_eventSub().get_composite_event().readEvent(composite_eventSub, (std::size_t)sizeof(composite_eventSub)); + bool old_composite_event; if ((eventSub[0] & 1< state.get_eventSub().get_value().getLower(gmOffsetValue)) && + (composite_client_ptp_data.master_offset < state.get_eventSub().get_value().getUpper(gmOffsetValue))) { + composite_client_ptp_data.composite_event = true; + } + else { + composite_client_ptp_data.composite_event = false; + } + } + + if ((composite_eventSub[0] & 1<= SERVO_LOCKED ? true:false; + } + + if ((composite_eventSub[0] & 1< 0 ? true:false; + } + + if (composite_eventSub[0] && (old_composite_event != composite_client_ptp_data.composite_event)) { + client_ptp_data.composite_event_count.fetch_add(1, std::memory_order_relaxed); + } + jclCurrentState.gm_present = client_ptp_data.gmPresent > 0 ? true:false; jclCurrentState.as_Capable = client_ptp_data.asCapable > 0 ? true:false; jclCurrentState.offset_in_range = client_ptp_data.master_offset_within_boundary; jclCurrentState.servo_locked = client_ptp_data.servo_state >= SERVO_LOCKED ? true:false; + jclCurrentState.composite_event = composite_client_ptp_data.composite_event; memcpy(jclCurrentState.gmIdentity, client_ptp_data.gmIdentity, sizeof(client_ptp_data.gmIdentity)); /* TODO : checked for jclCurrentState.gm_changed based on GM_identity previously stored */ @@ -122,6 +155,7 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) jclCurrentEventCount.asCapable_event_count = client_ptp_data.asCapable_event_count; jclCurrentEventCount.servo_locked_event_count = client_ptp_data.servo_state_event_count; jclCurrentEventCount.gm_changed_event_count = client_ptp_data.gmChanged_event_count; + jclCurrentEventCount.composite_event_count = client_ptp_data.composite_event_count; state.set_eventState (jclCurrentState); state.set_eventStateCount (jclCurrentEventCount); diff --git a/jclklib/client/subscribe_msg.cpp b/jclklib/client/subscribe_msg.cpp index 13f58324..7b9d4088 100644 --- a/jclklib/client/subscribe_msg.cpp +++ b/jclklib/client/subscribe_msg.cpp @@ -21,6 +21,7 @@ using namespace JClkLibCommon; using namespace std; JClkLibCommon::client_ptp_event client_data = {}; +JClkLibCommon::client_ptp_event composite_client_data = {}; /** @brief Create the ClientSubscribeMessage object * @@ -57,6 +58,9 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { std::uint32_t eventSub[1]; state.get_eventSub().get_event().readEvent(eventSub, (std::size_t)sizeof(eventSub)); + std::uint32_t composite_eventSub[1]; + state.get_eventSub().get_composite_event().readEvent(composite_eventSub, (std::size_t)sizeof(composite_eventSub)); + PrintDebug("[ClientSubscribeMessage]::parseBuffer "); if(!CommonSubscribeMessage::parseBuffer(LxContext)) return false; @@ -97,6 +101,28 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { client_data.gmPresent = data.gmPresent; } + if (composite_eventSub[0]) { + composite_client_data.composite_event = true; + } + + if ((composite_eventSub[0] & 1< state.get_eventSub().get_value().getLower(gmOffsetValue)) && + (composite_client_data.master_offset < state.get_eventSub().get_value().getUpper(gmOffsetValue))) { + composite_client_data.composite_event = true; + } else { + composite_client_data.composite_event = false; + } + } + + if ((composite_eventSub[0] & 1<= SERVO_LOCKED ? true:false; + } + + if ((composite_eventSub[0] & 1< 0 ? true:false; + } + printf("CLIENT master_offset = %ld, servo_state = %d gmPresent = %d\n", client_data.master_offset, client_data.servo_state, client_data.gmPresent); printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x ", client_data.gmIdentity[0], client_data.gmIdentity[1],client_data.gmIdentity[2], @@ -108,6 +134,7 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { jclCurrentState.as_Capable = client_data.asCapable > 0 ? true:false; jclCurrentState.offset_in_range = client_data.master_offset_within_boundary; jclCurrentState.servo_locked = client_data.servo_state >= SERVO_LOCKED ? true:false; + jclCurrentState.composite_event = composite_client_data.composite_event; memcpy(jclCurrentState.gmIdentity, client_data.gmIdentity, sizeof(client_data.gmIdentity)); /* TODO : checked for jclCurrentState.gm_changed based on GM_identity previously stored */ diff --git a/jclklib/client/test.cpp b/jclklib/client/test.cpp index 5f26e4f3..07b18069 100644 --- a/jclklib/client/test.cpp +++ b/jclklib/client/test.cpp @@ -42,7 +42,8 @@ int main() JClkLibCommon::jcl_state_event_count eventCount = {}; int timeout = 10; - std::uint32_t event2Sub1[1] = {((1< offset_event_count{}; std::atomic asCapable_event_count{}; std::atomic servo_state_event_count{}; std::atomic gmPresent_event_count{}; std::atomic gmChanged_event_count{}; + std::atomic composite_event_count{}; }; struct jcl_state @@ -181,6 +185,7 @@ enum servoState_e { bool offset_in_range; bool servo_locked; bool gm_changed; + bool composite_event; uint8_t gmIdentity[8]; }; @@ -191,6 +196,7 @@ enum servoState_e { uint64_t gm_changed_event_count; uint64_t asCapable_event_count; uint64_t servo_locked_event_count; + uint64_t composite_event_count; }; From c8baf735a51a4f9b411d119c3ca1a83e7cdbb686 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 9 May 2024 11:30:35 +0800 Subject: [PATCH 049/151] jclklib: Fix incorrect composite status Fix incorrect composite status check in subscribe and notify msg. Signed-off-by: Song Yoong Siang --- jclklib/client/notification_msg.cpp | 4 ++-- jclklib/client/subscribe_msg.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/jclklib/client/notification_msg.cpp b/jclklib/client/notification_msg.cpp index 14762d2d..f1485fd7 100644 --- a/jclklib/client/notification_msg.cpp +++ b/jclklib/client/notification_msg.cpp @@ -129,11 +129,11 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) } } - if ((composite_eventSub[0] & 1<= SERVO_LOCKED ? true:false; } - if ((composite_eventSub[0] & 1< 0 ? true:false; } diff --git a/jclklib/client/subscribe_msg.cpp b/jclklib/client/subscribe_msg.cpp index 7b9d4088..c5d1eaf6 100644 --- a/jclklib/client/subscribe_msg.cpp +++ b/jclklib/client/subscribe_msg.cpp @@ -115,11 +115,11 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { } } - if ((composite_eventSub[0] & 1<= SERVO_LOCKED ? true:false; } - if ((composite_eventSub[0] & 1< 0 ? true:false; } From 3b7b3a8f297e9983c41a080bf97694f3cd6bf347 Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Thu, 9 May 2024 12:09:28 +0800 Subject: [PATCH 050/151] jclklib: Code cleanup for proxy Code cleanup and remove those unused function. Signed-off-by: Lai Peter Jun Ann --- jclklib/proxy/thread.cpp | 265 --------------------------------------- jclklib/proxy/thread.hpp | 70 ++--------- 2 files changed, 9 insertions(+), 326 deletions(-) diff --git a/jclklib/proxy/thread.cpp b/jclklib/proxy/thread.cpp index 47de6281..cbf92143 100644 --- a/jclklib/proxy/thread.cpp +++ b/jclklib/proxy/thread.cpp @@ -12,186 +12,22 @@ * */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include "thread.hpp" -//#include "ptp4l_connect.hpp" - -using namespace ptpmgmt; -using namespace JClkLibCommon; - -#define MSEC_PER_SEC (1000) -#define USEC_PER_SEC (1000000) -#define NSEC_PER_SEC (1000000000) -#define NSEC_PER_USEC (NSEC_PER_SEC/USEC_PER_SEC) -#define USEC_PER_MSEC (USEC_PER_SEC/MSEC_PER_SEC) - -int initialize_thread_signal( struct thread_signal **psignal) -{ - struct thread_signal *signal; - pthread_condattr_t signal_attr; - pthread_mutexattr_t siglock_attr; - int err, ret; - - signal = ( typeof( signal)) malloc(( size_t) sizeof( *signal)); - if( signal == NULL) { - ret = errno; - goto allocate_fail; - } - - if(( ret = pthread_mutexattr_init( &siglock_attr)) != 0) - goto mutexattr_fail; - if(( ret = pthread_condattr_init( &signal_attr)) != 0) - goto condattr_fail; - - if(( ret = pthread_mutex_init - ( &signal->siglock, &siglock_attr)) != 0 ) { - goto fail; - } - if(( ret = pthread_cond_init - ( &signal->signal, &signal_attr)) != 0 ) { - goto fail; - } - - fail: - if(( err = pthread_condattr_destroy( &signal_attr)) != 0) - ret = ret == 0 ? err : ret; // Report first error only - condattr_fail: - if(( err = pthread_mutexattr_destroy( &siglock_attr)) != 0) - ret = ret == 0 ? err : ret; // Report first error only - mutexattr_fail: - allocate_fail: - - if( ret == 0) { - signal->signaled = false; - *psignal = signal; - } else { - free(signal); - } - - return -ret; -} - -int wait_thread_signal( struct thread_signal *signal, unsigned timeout ) -{ - struct timespec abs_timeout; - int err, ret; - - clock_gettime( CLOCK_REALTIME, &abs_timeout); - abs_timeout.tv_nsec += (timeout % USEC_PER_SEC) * NSEC_PER_USEC; - abs_timeout.tv_sec += abs_timeout.tv_nsec / NSEC_PER_SEC; - abs_timeout.tv_nsec %= NSEC_PER_SEC; - abs_timeout.tv_sec += timeout / USEC_PER_SEC; - - if(( ret = pthread_mutex_lock( &signal->siglock)) != 0) - goto lock_fail; - while( !signal->signaled) { - if(( ret = pthread_cond_timedwait - ( &signal->signal, &signal->siglock, &abs_timeout )) != 0) { - break; - } - } - if( ret == 0) - signal->signaled = false; - - if(( err = pthread_mutex_unlock( &signal->siglock)) != 0) - ret = ret == 0 ? err : ret; // Report first error only - - lock_fail: - return -ret; -} - -static bool check_for_events( struct jcl_handle *handle) -{ - int i; - - for( i = 0; i < jcl_event_count; ++i) { - if( handle->event_count[i] != 0) - return true; - } - - return false; -} - -static int check_status( struct jcl_handle *handle, - unsigned *event_count, struct jcl_state *state, bool *done) -{ - int ret; - - *done = false; - if(( ret = -pthread_mutex_lock( &handle->state_lock)) < 0) - goto lock_failed; - if( check_for_events( handle)) { - *state = handle->state; - memcpy( event_count, handle->event_count, sizeof( handle->event_count)); - *done = true; - } - ret = -pthread_mutex_unlock( &handle->state_lock); - - lock_failed: - return ret; -} - -int handle_status_wait( struct jcl_handle *handle, unsigned timeout, - unsigned *event_count, struct jcl_state *state ) -{ - bool done; - int ret; - - if(( ret = check_status( handle, event_count, state, &done)) < 0 || done || timeout == 0) - goto do_exit; - - if(( ret = wait_thread_signal( handle->status_signal, timeout)) < 0) - goto do_exit; - - ret = check_status( handle, event_count, state, &done); - - do_exit: - return ret; -} static int start_work_thread( struct ptp4l_handle *handle ) { int ret; - if(( ret = initialize_thread_signal( &handle->init_signal)) < 0) - goto init_signal_failed; - if(( ret = initialize_thread_signal( &handle->exit_signal)) < 0) - goto exit_signal_failed; - if(( ret = -pthread_create( &handle->work_thread, NULL, ptp4l_event_loop, (void *) handle)) < 0) return ret; -// if(( ret = wait_thread_signal( handle->init_signal, 30000)) < 0) { -// PTP4L_CONNECT_TIMEOUT*USEC_PER_MSEC)) < 0) -// goto start_wait_failed; -// } return 0; - -// start_wait_failed: -// stop_work_thread( handle); -// free_thread_signal( handle->exit_signal); - exit_signal_failed: -// free_thread_signal( handle->init_signal); - init_signal_failed: - return ret; } int connect_ptp4l( struct ptp4l_handle **phandle, struct epoll_event epd_event, state_update_t update_cb, void *ctx) { struct ptp4l_handle *handle; int ret; - //TODO: hard-coded for now - char path[] = "/var/run/ptp4l"; handle = (typeof( handle)) malloc(( size_t) sizeof(*handle)); if( handle == NULL) { @@ -199,20 +35,6 @@ int connect_ptp4l( struct ptp4l_handle **phandle, struct epoll_event epd_event, goto alloc_handle_fail; } - memset( &handle->server_addr, 0, sizeof( handle->server_addr)); - handle->server_addr.sun_family = AF_LOCAL; - - strncpy( handle->server_addr.sun_path, path, - sizeof( handle->server_addr.sun_path ) - 1); - - //subscribe event - handle->epd_event = epd_event; - handle->ptp4l_sock = epd_event.data.fd; - - handle->update_cb = update_cb; - handle->ctx = ctx; - handle->pid = getpid(); - if(( ret = start_work_thread( handle)) < 0) goto thread_failed; @@ -251,12 +73,6 @@ static bool state_update_callback( struct ptp4l_state *state, void * ctx) if(( ret = -pthread_mutex_lock( &handle->state_lock)) < 0) goto lock_failed; - // TODO: update the state based on the event notification - //generate_signal = update_offset( handle, state) || generate_signal ? true : false; - //generate_signal = update_peer_present( handle, state) || generate_signal ? true : false; - //generate_signal = update_gm_present( handle, state) || generate_signal ? true : false; - //generate_signal = update_servo_locked( handle, state) || generate_signal ? true : false; - generate_signal = handle->ptp4l_state_initialized ? generate_signal : false; handle->ptp4l_state_initialized = state->initialized; @@ -271,64 +87,6 @@ static bool state_update_callback( struct ptp4l_state *state, void * ctx) return ret >= 0 ? true : false; } -int init_thread_signal( struct thread_signal **psignal) -{ - struct thread_signal *signal; - pthread_condattr_t signal_attr; - pthread_mutexattr_t siglock_attr; - int err, ret; - - signal = ( typeof( signal)) malloc(( size_t) sizeof( *signal)); - if( signal == NULL) { - ret = errno; - goto allocate_fail; - } - - if(( ret = pthread_mutexattr_init( &siglock_attr)) != 0) - goto mutexattr_fail; - if(( ret = pthread_condattr_init( &signal_attr)) != 0) - goto condattr_fail; - - if(( ret = pthread_mutex_init - ( &signal->siglock, &siglock_attr)) != 0 ) { - goto fail; - } - if(( ret = pthread_cond_init - ( &signal->signal, &signal_attr)) != 0 ) { - goto fail; - } - - fail: - if(( err = pthread_condattr_destroy( &signal_attr)) != 0) - ret = ret == 0 ? err : ret; // Report first error only - condattr_fail: - if(( err = pthread_mutexattr_destroy( &siglock_attr)) != 0) - ret = ret == 0 ? err : ret; // Report first error only - mutexattr_fail: - allocate_fail: - if( ret == 0) { - signal->signaled = false; - *psignal = signal; - } else { - free(signal); - } - - return -ret; -} - -int free_thread_signal( struct thread_signal *signal) -{ - int err, ret; - - ret = pthread_mutex_destroy( &signal->siglock); - if(( err = pthread_cond_destroy( &signal->signal)) != 0 ) - ret = ret == 0 ? err : ret; // Report first error only - - free(signal); - - return -ret; -} - /** * @brief Initializes and connects a handle for PTP (Precision Time Protocol) event handling. * @@ -354,36 +112,13 @@ int handle_connect( struct jcl_handle **phandle, struct epoll_event epd_event ) goto alloc_fail; } - if(( ret = init_thread_signal( &handle->status_signal)) < 0) - goto status_signal_fail; - - if(( ret = -pthread_mutex_init( &handle->state_lock, NULL)) < 0) - goto state_lock_fail; - - //handle_init start - handle->state = {}; - handle->subscription.event = 0; - memset( handle->event_count, 0, sizeof( handle->event_count)); - event_subscription( &handle ); connect_ptp4l( &handle->ptp4l_handle, epd_event, state_update_callback, handle); - //TODO: wait operation - unsigned event_count[1000]; - int iter; - iter = 100; - while (iter > 0) { - handle_status_wait( handle, 1000, handle->event_count, &handle->state ); - --iter; - } - return 0; - state_lock_fail: - free_thread_signal( handle->status_signal); - status_signal_fail: alloc_fail: return ret; } diff --git a/jclklib/proxy/thread.hpp b/jclklib/proxy/thread.hpp index d29e7c12..14131acd 100644 --- a/jclklib/proxy/thread.hpp +++ b/jclklib/proxy/thread.hpp @@ -30,89 +30,31 @@ typedef struct thread_signal *thread_signal_t; typedef struct ptp4l_handle *ptp4l_handle_t; typedef struct jcl_handle *jcl_handle_t; +typedef bool ( *state_update_t)( struct ptp4l_state *, void *); +typedef struct thread_signal *thread_signal_t; + struct thread_signal { pthread_mutex_t siglock; pthread_cond_t signal; bool signaled; }; -struct jcl_threshold -{ - unsigned offset; /* ns */ -}; - -struct jcl_subscription -{ - unsigned event; - struct jcl_threshold threshold; -}; - struct jcl_handle { - clockid_t clk_id; - ptp4l_handle_t ptp4l_handle; bool ptp4l_state_initialized; - thread_signal_t status_signal; pthread_mutex_t state_lock; - unsigned event_count[4]; //jcl_event_count - struct jcl_subscription subscription; struct JClkLibCommon::jcl_state state; }; -typedef enum { jcl_peer_present, jcl_gm_present, jcl_offset_threshold, jcl_servo_locked, - jcl_event_count,} - jcl_event_t; - -#define jcl_servo_locked_flag ( 0x1 << jcl_gm_present) -#define jcl_gm_present_flag ( 0x1 << jcl_gm_present) -#define jcl_peer_present_flag ( 0x1 << jcl_peer_present) -#define jcl_offset_threshold_flag ( 0x1 << jcl_offset_threshold) - -typedef bool ( *state_update_t)( struct ptp4l_state *, void *); -typedef struct thread_signal *thread_signal_t; - -int handle_connect( jcl_handle_t *handle, struct epoll_event epd_event ); -int connect_ptp4l( ptp4l_handle_t *phandle, struct epoll_event epd_event, state_update_t update, void *ctx); -int disconnect_ptp4l( ptp4l_handle_t handle); - -void *ptp4l_event_loop(void *arg); -bool event_subscription(struct jcl_handle **handle); - struct ptp4l_handle { - int ptp4l_sock; - int epd; struct epoll_event epd_event; - int error; - - pid_t pid; - struct sockaddr_un server_addr; - struct sockaddr_un client_addr; - state_update_t update_cb; void *ctx; - - bool do_exit; - thread_signal_t exit_signal; - thread_signal_t init_signal; - pthread_t work_thread; }; -enum ptp4l_status_update_type -{ - ptp4l_peer_present, - ptp4l_offset, - ptp4l_gmpresent, - ptp4l_servolocked, -}; - -#define ptp4l_peer_present_valid (0x1 << ptp4l_peer_present) -#define ptp4l_offset_valid (0x1 << ptp4l_offset) -#define ptp4l_gmpresent_valid (0x1 << ptp4l_gmpresent) -#define ptp4l_servolocked_valid (0x1 << ptp4l_servolocked) - struct ptp4l_state { bool initialized; unsigned valid_mask; @@ -121,3 +63,9 @@ struct ptp4l_state { bool gm_present; bool servo_locked; }; + +int handle_connect( jcl_handle_t *handle, struct epoll_event epd_event ); +int connect_ptp4l( ptp4l_handle_t *phandle, struct epoll_event epd_event, state_update_t update, void *ctx); + +void *ptp4l_event_loop(void *arg); +bool event_subscription(struct jcl_handle **handle); From bbb07501feae8c5160c8cb86dc06c47c879c5707 Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Thu, 9 May 2024 15:36:02 +0800 Subject: [PATCH 051/151] jclklib: Add ptp4l port state event checking Check the port state before notifying client with the ptp4l event data. Reset the proxy ptp4l event date if gm is not present. Signed-off-by: Lai Peter Jun Ann --- jclklib/proxy/connect.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/jclklib/proxy/connect.cpp b/jclklib/proxy/connect.cpp index 578d8b89..15ef23b4 100644 --- a/jclklib/proxy/connect.cpp +++ b/jclklib/proxy/connect.cpp @@ -49,6 +49,7 @@ struct port_info { }; int epd; +portState_e portState; struct epoll_event epd_event; SUBSCRIBE_EVENTS_NP_t d; JClkLibCommon::ptp_event pe = { 0, {0, 0, 0, 0, 0, 0, 0, 0}, 0 , 0 , 0}; @@ -85,8 +86,15 @@ void event_handle() int64_t offset; ClockIdentity_t gm_uuid; uint8_t servo; + PORT_DATA_SET_t *pd; + switch(msg.getTlvId()) { case TIME_STATUS_NP: + //workaround for ptp4l continue to send even gm is not present + if(portState != TIME_RECEIVER) { + return; + } + offset = ((TIME_STATUS_NP_t *)data)->master_offset; servo = ((TIME_STATUS_NP_t *)data)->servo_state; gm_uuid = ((TIME_STATUS_NP_t *)data)->gmIdentity; @@ -106,8 +114,23 @@ void event_handle() pe.asCapable = ((PORT_DATA_SET_NP_t *)data)->asCapable; printf("asCapable = %d\n\n", pe.asCapable); break; - default: + case PORT_DATA_SET: + pd = (PORT_DATA_SET_t *)data; + portState = pd->portState; + + //Reset proxy ptp4l event data if port_state <= PASSIVE + if (portState <= PASSIVE) { + pe = { 0, {0, 0, 0, 0, 0, 0, 0, 0}, 0 , 0 , 0}; + } + break; + case PORT_PROPERTIES_NP: + //Retrieve current port state when proxy is started + pd = (PORT_DATA_SET_t *)data; + portState = pd->portState; + break; + default: + return; } notify_client(); @@ -170,6 +193,7 @@ bool event_subscription(struct jcl_handle **handle) memset(d.bitmask, 0, sizeof d.bitmask); d.setEvent(NOTIFY_TIME_SYNC); d.setEvent(NOTIFY_PORT_STATE_NP); + d.setEvent(NOTIFY_PORT_STATE); if(!msg.setAction(SET, SUBSCRIBE_EVENTS_NP, &d)) { fprintf(stderr, "Fail set SUBSCRIBE_EVENTS_NP\n"); From 7a3d1d3de1c149bf3101bc3181c1f93148e88d3d Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Thu, 9 May 2024 15:39:18 +0800 Subject: [PATCH 052/151] jclklib: Fix the event_count is not handle properly The event_count is not handle properly as the event_count is keep decreasing when there is no new notification from proxy. Signed-off-by: Lai Peter Jun Ann --- jclklib/client/init.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/jclklib/client/init.cpp b/jclklib/client/init.cpp index c658935d..1e5062a1 100644 --- a/jclklib/client/init.cpp +++ b/jclklib/client/init.cpp @@ -219,5 +219,16 @@ int JClkLibClient::jcl_status_wait(int timeout, JClkLibCommon::jcl_state &jcl_st client_ptp_data.composite_event_count.fetch_sub(eventCount.composite_event_count, std::memory_order_relaxed); + JClkLibCommon::jcl_state_event_count jclCurrentEventCount = {}; + + jclCurrentEventCount.gmPresent_event_count = client_ptp_data.gmPresent_event_count; + jclCurrentEventCount.offset_in_range_event_count = client_ptp_data.offset_event_count; + jclCurrentEventCount.asCapable_event_count = client_ptp_data.asCapable_event_count; + jclCurrentEventCount.servo_locked_event_count = client_ptp_data.servo_state_event_count; + jclCurrentEventCount.gm_changed_event_count = client_ptp_data.gmChanged_event_count; + jclCurrentEventCount.composite_event_count = client_ptp_data.composite_event_count; + + state.set_eventStateCount (jclCurrentEventCount); + return true; } From 891b82309e8b7114573265d5d61f023e5ae2d0d3 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 9 May 2024 15:51:40 +0800 Subject: [PATCH 053/151] jclklib: Improve test app Improve test app so that it can take in user argument for subscription and composition event mask. Signed-off-by: Song Yoong Siang --- jclklib/client/test.cpp | 200 +++++++++++++++++++++++++++++----------- 1 file changed, 148 insertions(+), 52 deletions(-) diff --git a/jclklib/client/test.cpp b/jclklib/client/test.cpp index 07b18069..f1cc0870 100644 --- a/jclklib/client/test.cpp +++ b/jclklib/client/test.cpp @@ -12,19 +12,19 @@ * */ -#include "init.hpp" - -#include +#include #include +#include #include -#include +#include #include #include -#include +#include + +#include "init.hpp" using namespace JClkLibClient; using namespace JClkLibCommon; -using namespace std; volatile sig_atomic_t signal_flag = 0; @@ -33,84 +33,180 @@ void signal_handler(int sig) signal_flag = 1; } -int main() +int main(int argc, char *argv[]) { - int ret = EXIT_SUCCESS; - JClkLibCommon::jcl_subscription sub = {}; - JClkLibCommon::jcl_state currentState = {}; - JClkLibCommon::jcl_state jcl_state = {}; - JClkLibCommon::jcl_state_event_count eventCount = {}; int timeout = 10; - std::uint32_t event2Sub1[1] = {((1< Date: Thu, 9 May 2024 15:53:01 +0800 Subject: [PATCH 054/151] jclklib: change order of subscription mask move mask that support composite event in front to ease validation of input mask. Signed-off-by: Song Yoong Siang --- jclklib/common/jclklib_import.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jclklib/common/jclklib_import.hpp b/jclklib/common/jclklib_import.hpp index 51512a00..da76e104 100644 --- a/jclklib/common/jclklib_import.hpp +++ b/jclklib/common/jclklib_import.hpp @@ -94,7 +94,7 @@ enum servoState_e { /* Events clients can subscribe to */ typedef enum : std::uint8_t - { gmPresentEvent, gmChangedEvent, gmOffsetEvent, servoLockedEvent, asCapableEvent, + { gmOffsetEvent, servoLockedEvent, asCapableEvent, gmPresentEvent, gmChangedEvent, eventLast } eventType; #define BITS_PER_BYTE (8) From 1e8ae73f77394af833af06136739f138850435ad Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 9 May 2024 16:03:00 +0800 Subject: [PATCH 055/151] jclklib: fix jcl_subscribe() API unable to retrieve data issue Retrieve the latest PTP data and pass back to user in jcl_subscribe() API. Signed-off-by: Song Yoong Siang --- jclklib/client/init.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/jclklib/client/init.cpp b/jclklib/client/init.cpp index 1e5062a1..e8ca1a98 100644 --- a/jclklib/client/init.cpp +++ b/jclklib/client/init.cpp @@ -126,15 +126,8 @@ bool JClkLibClient::jcl_subscribe(JClkLibCommon::jcl_subscription &newSub, } } - JClkLibCommon::jcl_state jclCurrentState = state.get_eventState(); - printf("[JClkLibClient]::subscribe : state - \n"); - printf ("offset_in_range = %d, servo_locked = %d gmPresent = %d as_Capable = %d gm_Changed = %d\n", \ - jclCurrentState.offset_in_range, jclCurrentState.servo_locked,\ - jclCurrentState.gm_present, jclCurrentState.as_Capable, jclCurrentState.gm_changed); - printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x \n", - jclCurrentState.gmIdentity[0], jclCurrentState.gmIdentity[1],jclCurrentState.gmIdentity[2], - jclCurrentState.gmIdentity[3], jclCurrentState.gmIdentity[4], - jclCurrentState.gmIdentity[5], jclCurrentState.gmIdentity[6],jclCurrentState.gmIdentity[7]); + currentState = state.get_eventState(); + return true; } From 614cdf63bdfc8e3af54f77394eef409956436250 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 9 May 2024 16:20:26 +0800 Subject: [PATCH 056/151] jclklib: remove unused debug print remove debug print as part of code clean up. Signed-off-by: Song Yoong Siang --- jclklib/client/msgq_tport.cpp | 2 -- jclklib/client/subscribe_msg.cpp | 18 ------------------ jclklib/common/jclklib_import.cpp | 1 - 3 files changed, 21 deletions(-) diff --git a/jclklib/client/msgq_tport.cpp b/jclklib/client/msgq_tport.cpp index ce064287..23a0f175 100644 --- a/jclklib/client/msgq_tport.cpp +++ b/jclklib/client/msgq_tport.cpp @@ -121,7 +121,6 @@ bool ClientMessageQueue::writeTransportClientId(Message *msg) return false; } strcpy((char *)cmsg->getClientId().data(), mqListenerName.c_str()); - printf ("[ClientMessageQueue][CONNECT] cmsg->getClientId().data(): %s\n", (char *)cmsg->getClientId().data()); break; } case SUBSCRIBE_MSG : @@ -135,7 +134,6 @@ bool ClientMessageQueue::writeTransportClientId(Message *msg) strcpy((char *)cmsg->getClientId().data(), (char *)state.get_clientID().data()); cmsg->set_sessionId(state.get_sessionId()); // this is where it turns to 0 - printf ("[ClientMessageQueue] [SUBSCRIBE] cmsg->set_sessionId() : %d\n", cmsg->get_sessionId()); PrintDebug("[ClientMessageQueue] [SUBSCRIBE] : subscription->event Mask : " + cmsg->getSubscription().get_event().toString()); break; } diff --git a/jclklib/client/subscribe_msg.cpp b/jclklib/client/subscribe_msg.cpp index c5d1eaf6..183f21e9 100644 --- a/jclklib/client/subscribe_msg.cpp +++ b/jclklib/client/subscribe_msg.cpp @@ -68,13 +68,6 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { if (!PARSE_RX(FIELD, data, LxContext)) return false; - printf("master_offset = %ld, servo_state = %d gmPresent = %d\n", data.master_offset, data.servo_state, data.gmPresent); - printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x ", - data.gmIdentity[0], data.gmIdentity[1],data.gmIdentity[2], - data.gmIdentity[3], data.gmIdentity[4], - data.gmIdentity[5], data.gmIdentity[6],data.gmIdentity[7]); - printf("asCapable = %d, ptp4l_id = %d\n\n", data.asCapable, data.ptp4l_id); - /* TODO : set the client_data per client instead of global */ if ((eventSub[0] & 1< 0 ? true:false; } - printf("CLIENT master_offset = %ld, servo_state = %d gmPresent = %d\n", client_data.master_offset, client_data.servo_state, client_data.gmPresent); - printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x ", - client_data.gmIdentity[0], client_data.gmIdentity[1],client_data.gmIdentity[2], - client_data.gmIdentity[3], client_data.gmIdentity[4], - client_data.gmIdentity[5], client_data.gmIdentity[6],client_data.gmIdentity[7]); - printf("asCapable = %d\n\n", client_data.asCapable); - jclCurrentState.gm_present = client_data.gmPresent > 0 ? true:false; jclCurrentState.as_Capable = client_data.asCapable > 0 ? true:false; jclCurrentState.offset_in_range = client_data.master_offset_within_boundary; @@ -165,10 +151,6 @@ PROCESS_MESSAGE_TYPE(ClientSubscribeMessage::processMessage) state.set_subscribed(true); this->set_msgAck(ACK_NONE); - - JClkLibCommon::jcl_state jclCurrentState = state.get_eventState(); - printf("[ClientSubscribeMessage]::processMessage : state - offset in range = %d, servo_locked = %d gmPresent = %d as_Capable = %d\n", \ - jclCurrentState.offset_in_range, jclCurrentState.servo_locked, jclCurrentState.gm_present, jclCurrentState.as_Capable); cv.notify_one(); return true; diff --git a/jclklib/common/jclklib_import.cpp b/jclklib/common/jclklib_import.cpp index 296817bf..9d6898da 100644 --- a/jclklib/common/jclklib_import.cpp +++ b/jclklib/common/jclklib_import.cpp @@ -119,7 +119,6 @@ int8_t jcl_event::copyEventMask(jcl_event &newEvent) std::size_t newEventLength = sizeof(newEvent.getEventMask()); memcpy(event_mask, newEvent.event_mask , newEventLength); - printf ("[jcl_event]::copyEventMask - newEventLength = %ld , incoming event mask = 0x%x\n", newEventLength, newEvent.getEventMask()[0]); return 0; } From 551bb9a69f4b0eb82bdc07db8b57bca44fa846c9 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 9 May 2024 16:23:57 +0800 Subject: [PATCH 057/151] jclklib: continue to process TIME_STATUS_NP msg for uncalibrated state Continue to process TIME_STATUS_NP message even when the port state is equal to uncalibrated. The servo state will equal to 0 in this state, which can be used to trace the actual situation. Signed-off-by: Song Yoong Siang --- jclklib/proxy/connect.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jclklib/proxy/connect.cpp b/jclklib/proxy/connect.cpp index 15ef23b4..abfc3eec 100644 --- a/jclklib/proxy/connect.cpp +++ b/jclklib/proxy/connect.cpp @@ -91,7 +91,7 @@ void event_handle() switch(msg.getTlvId()) { case TIME_STATUS_NP: //workaround for ptp4l continue to send even gm is not present - if(portState != TIME_RECEIVER) { + if(portState < UNCALIBRATED) { return; } From 438a69367ae1ca8436fdb57c9ca43d076d590afd Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 9 May 2024 16:45:46 +0800 Subject: [PATCH 058/151] jclklib: remove N/A printing Remove N/A printing to improve user experience. Signed-off-by: Song Yoong Siang --- jclklib/client/test.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/jclklib/client/test.cpp b/jclklib/client/test.cpp index f1cc0870..6cddc090 100644 --- a/jclklib/client/test.cpp +++ b/jclklib/client/test.cpp @@ -97,9 +97,8 @@ int main(int argc, char *argv[]) printf("[jclklib] Obtained data from Subscription Event:\n"); printf("+-------------------+--------------------+\n"); printf("| %-17s | %-18s |\n", "Event", "Event Status"); - printf("+-------------------+--------------------+\n"); - if (!event2Sub1[0]) { - printf("| %-17s | %-18s |\n", "N/A", "N/A"); + if (event2Sub1[0]) { + printf("+-------------------+--------------------+\n"); } if (event2Sub1[0] & (1< Date: Thu, 9 May 2024 17:43:58 +0800 Subject: [PATCH 059/151] jclklib: Fix formatting Fix following error check in CI: Check: jclklib/client/test.cpp:211: for wrong char: jcl_disconnect(); Signed-off-by: Song Yoong Siang --- jclklib/client/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jclklib/client/test.cpp b/jclklib/client/test.cpp index 6cddc090..ed201991 100644 --- a/jclklib/client/test.cpp +++ b/jclklib/client/test.cpp @@ -208,7 +208,7 @@ int main(int argc, char *argv[]) sleep(1); } - jcl_disconnect(); + jcl_disconnect(); return EXIT_SUCCESS; } From 899dbbe149ce8b47c190a3db7de8d6356b6d6b11 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 9 May 2024 23:05:10 +0800 Subject: [PATCH 060/151] Fix servo_state doxygen issue Fix following doxygen error in CI: 1. pub/c/proc.h:412: error: Member servo_state (variable) of struct ptpmgmt_TIME_STATUS_NP_t is not documented. 2. pub/proc.h:433: error: Member servo_state (variable) of struct TIME_STATUS_NP_t is not documented. Signed-off-by: Song Yoong Siang --- src/proc.m4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/proc.m4 b/src/proc.m4 index 312a6447..9b3c5ce7 100644 --- a/src/proc.m4 +++ b/src/proc.m4 @@ -441,7 +441,7 @@ strc(TIME_STATUS_NP_t) sz(: public BaseMngTlv) { uint16_t fractional_nanoseconds; Integer32_t gmPresent; /**< Flag for grandmaster presence */ strcc(ClockIdentity_t) gmIdentity; /**< Grandmaster clock ID */ - enmc(servoState_e) servo_state; /** Servo state */ + enmc(servoState_e) servo_state; /**< Servo state */ }; /** Grandmaster settings TLV * @note linuxptp implementation specific From 05d7e043f5f1ca2ea7016a3b4262ca11ecaf5059 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 9 May 2024 23:22:47 +0800 Subject: [PATCH 061/151] Fix error for Tlv2JsonTest.TIME_STATUS_NP unit test Fix following unit test error: utest/msg2json.cpp:1318: Failure Expected equality of these values: tlv2json(TIME_STATUS_NP, &t).c_str() Which is: "{\n \"master_offset\" : 0,\n \"ingress_time\" : 0,\n \"cu mulativeScaledRateOffset\" : 0,\n \"scaledLastGmPhaseChange\" : 0,\n \"gm TimeBaseIndicator\" : 0,\n \"nanoseconds_msb\" : 0,\n \"nanoseconds_lsb\" : 0,\n \"fractional_nanoseconds\" : 0,\n \"gmPresent\" : 0,\n \"gmIdent ity\" : \"c47d46.fffe.20acae\",\n \"servo_state\" : \"unknown servo state\ "\n}" "{\n" " \"master_offset\" : 0,\n" " \"ingress_time\" : 0,\n" " \"cumul ativeScaledRateOffset\" : 0,\n" " \"scaledLastGmPhaseChange\" : 0,\n" " \ "gmTimeBaseIndicator\" : 0,\n" " \"nanoseconds_msb\" : 0,\n" " \"nanoseco nds_lsb\" : 0,\n" " \"fractional_nanoseconds\" : 0,\n" " \"gmPresent\" : 0,\n" " \"gmIdentity\" : \"c47d46.fffe.20acae\"\n" "}" Which is: "{\n \"master_offset\" : 0,\n \"ingress_time\" : 0,\n \"cu mulativeScaledRateOffset\" : 0,\n \"scaledLastGmPhaseChange\" : 0,\n \"gm TimeBaseIndicator\" : 0,\n \"nanoseconds_msb\" : 0,\n \"nanoseconds_lsb\" : 0,\n \"fractional_nanoseconds\" : 0,\n \"gmPresent\" : 0,\n \"gmIdent ity\" : \"c47d46.fffe.20acae\"\n}" With diff: @@ -9,5 +9,4 @@ \"fractional_nanoseconds\" : 0, \"gmPresent\" : 0, - \"gmIdentity\" : \"c47d46.fffe.20acae\", - \"servo_state\" : \"unknown servo state\" + \"gmIdentity\" : \"c47d46.fffe.20acae\" } Signed-off-by: Song Yoong Siang --- uctest/msg2json.c | 4 +++- utest/msg2json.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/uctest/msg2json.c b/uctest/msg2json.c index 1c4f2e44..0a798650 100644 --- a/uctest/msg2json.c +++ b/uctest/msg2json.c @@ -1623,6 +1623,7 @@ Test(Tlv2JsonTest, TIME_STATUS_NP) t.gmIdentity.v[5] = 32; t.gmIdentity.v[6] = 172; t.gmIdentity.v[7] = 174; + t.servo_state = PTPMGMT_SERVO_UNLOCKED; char *ret = ptpmgmt_json_tlv2json(PTPMGMT_TIME_STATUS_NP, &t, 0); cr_assert(not(zero(ptr, ret))); cr_assert(eq(str, (char *)ret, @@ -1636,7 +1637,8 @@ Test(Tlv2JsonTest, TIME_STATUS_NP) " \"nanoseconds_lsb\" : 0,\n" " \"fractional_nanoseconds\" : 0,\n" " \"gmPresent\" : 0,\n" - " \"gmIdentity\" : \"c47d46.fffe.20acae\"\n" + " \"gmIdentity\" : \"c47d46.fffe.20acae\",\n" + " \"servo_state\" : \"SERVO_UNLOCKED\"\n" "}")); free(ret); } diff --git a/utest/msg2json.cpp b/utest/msg2json.cpp index c3e72bc5..f4c650e0 100644 --- a/utest/msg2json.cpp +++ b/utest/msg2json.cpp @@ -1319,6 +1319,7 @@ TEST(Tlv2JsonTest, TIME_STATUS_NP) t.gmPresent = 0; ClockIdentity_t clockId = { 196, 125, 70, 255, 254, 32, 172, 174 }; t.gmIdentity = clockId; + t.servo_state = SERVO_UNLOCKED; EXPECT_STREQ(tlv2json(TIME_STATUS_NP, &t).c_str(), "{\n" " \"master_offset\" : 0,\n" @@ -1330,7 +1331,8 @@ TEST(Tlv2JsonTest, TIME_STATUS_NP) " \"nanoseconds_lsb\" : 0,\n" " \"fractional_nanoseconds\" : 0,\n" " \"gmPresent\" : 0,\n" - " \"gmIdentity\" : \"c47d46.fffe.20acae\"\n" + " \"gmIdentity\" : \"c47d46.fffe.20acae\",\n" + " \"servo_state\" : \"SERVO_UNLOCKED\"\n" "}"); } From f5fe2f7a05be1f0e3dd7c2299adc63485739ba5a Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Fri, 10 May 2024 00:07:53 +0800 Subject: [PATCH 062/151] Fix invalid _ptpmProcType(servoState_e) macro Fis following error in CI: json/jsonFrom.cpp: In function 'ptpmgmt::JsonProcFrom* ptpm_json_alloc_proc()': json/jsonFrom.cpp:699:49: error: invalid new-expression of abstract class type 'JsonProcFromJson' 699 | JsonProcFrom *_n(alloc_proc)() { return new JsonProcFromJson; } | ^~~~~~~~~~~~~~~~ json/jsonFrom.cpp:213:8: note: because the following virtual functions are pure within 'JsonProcFromJson': 213 | struct JsonProcFromJson : public JsonProcFrom { | ^~~~~~~~~~~~~~~~ In file included from json/jsonFrom.cpp:19: src/comp.h:439:18: note: 'virtual bool ptpmgmt::JsonProc::procValue(const char*, ptpmgmt::servoState_e&)' 439 | virtual bool procValue(const char *name, type &val) = 0; | ^~~~~~~~~ src/comp.h:470:5: note: in expansion of macro '_ptpmProcType' 470 | _ptpmProcType(servoState_e) | ^~~~~~~~~~~~~ Signed-off-by: Song Yoong Siang --- json/jsonFrom.cpp | 5 +++++ pub/msg.h | 9 +++++++++ src/msg.cpp | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/json/jsonFrom.cpp b/json/jsonFrom.cpp index 3dee4d0b..2dde362b 100644 --- a/json/jsonFrom.cpp +++ b/json/jsonFrom.cpp @@ -580,6 +580,11 @@ struct JsonProcFromJson : public JsonProcFrom { return ret; } procObj(LinuxptpUnicastMaster_t) + bool procValue(const char *key, servoState_e &d) override { + if(!isType(key, JT_STR)) + return false; + return Message::findServoState(valsMap[key].strV, d); + } bool procBinary(const char *key, Binary &d, uint16_t &len) override { if(!isType(key, JT_STR) || !d.fromId(valsMap[key].strV) || d.size() == 0) diff --git a/pub/msg.h b/pub/msg.h index ab8d0987..57e6f1d1 100644 --- a/pub/msg.h +++ b/pub/msg.h @@ -188,6 +188,15 @@ class Message * @return string with the servo state */ static const char *servo2str_c(servoState_e state); + /** + * Convert string to servo state + * @param[in] str string to search + * @param[out] state servo state + * @param[in] caseSens perform case sensetive match + * @return true if found + */ + static const bool findServoState(const std::string &str, + servoState_e &state, bool caseSens = true); /** * Convert TLV type to string * @param[in] type diff --git a/src/msg.cpp b/src/msg.cpp index 80207184..cc41b5e0 100644 --- a/src/msg.cpp +++ b/src/msg.cpp @@ -732,6 +732,25 @@ const char *Message::servo2str_c(servoState_e state) } return "unknown servo state"; } +const bool Message::findServoState(const std::string &str, servoState_e &state, + bool caseSens) +{ + if(str.empty()) + return false; + int (*_strcmp)(const char *, const char *); + if(caseSens) + _strcmp = strcmp; // Excect match + else + _strcmp = strcasecmp; + for(int i = SERVO_UNLOCKED; i <= SERVO_LOCKED_STABLE; i++) { + servoState_e v = (servoState_e)i; + if(_strcmp(str.c_str(), servo2str_c(v)) == 0) { + state = v; + return true; + } + } + return false; +} const char *Message::tlv2str_c(tlvType_e type) { switch(type) { From 266a19376f29f34213865e726d6a2121ba782492 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Mon, 13 May 2024 11:55:45 +0800 Subject: [PATCH 063/151] Fix error for Json2msgTest.TIME_STATUS_NP unit test Fix following error in unit test: utest/json2msg.cpp:1832: Failure Value of: m.fromJson("{\"actionField\":\"SET\"," "\"managementId\":\"TIME_S TATUS_NP\",\"dataField\":{" "\"master_offset\":0," "\"ingress_time\":0," "\ "cumulativeScaledRateOffset\":0," "\"scaledLastGmPhaseChange\":0," "\"gmTim eBaseIndicator\":0," "\"nanoseconds_msb\":0," "\"nanoseconds_lsb\":0," "\"f ractional_nanoseconds\":0," "\"gmPresent\":0," "\"gmIdentity\":\"c47d46.fff e.20acae\"" "}}") Actual: false Expected: true Signed-off-by: Song Yoong Siang --- uctest/json2msg.c | 4 +++- utest/json2msg.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/uctest/json2msg.c b/uctest/json2msg.c index 746c84b1..ab1f0f39 100644 --- a/uctest/json2msg.c +++ b/uctest/json2msg.c @@ -1981,7 +1981,8 @@ Test(Json2msgTest, TIME_STATUS_NP) "\"nanoseconds_lsb\":0," "\"fractional_nanoseconds\":0," "\"gmPresent\":0," - "\"gmIdentity\":\"c47d46.fffe.20acae\"" + "\"gmIdentity\":\"c47d46.fffe.20acae\"," + "\"servo_state\":\"SERVO_UNLOCKED\"" "}}")); cr_expect(eq(int, m->actionField(m), PTPMGMT_SET)); cr_expect(eq(int, m->managementId(m), PTPMGMT_TIME_STATUS_NP)); @@ -1999,6 +2000,7 @@ Test(Json2msgTest, TIME_STATUS_NP) cr_expect(eq(int, t->fractional_nanoseconds, 0)); cr_expect(eq(int, t->gmPresent, 0)); cr_expect(zero(memcmp(t->gmIdentity.v, clockId, 8))); + cr_expect(eq(servoState_e, t->servo_state, PTPMGMT_SERVO_UNLOCKED)); m->free(m); } diff --git a/utest/json2msg.cpp b/utest/json2msg.cpp index a9f7aaea..e37136d7 100644 --- a/utest/json2msg.cpp +++ b/utest/json2msg.cpp @@ -1840,7 +1840,8 @@ TEST(Json2msgTest, TIME_STATUS_NP) "\"nanoseconds_lsb\":0," "\"fractional_nanoseconds\":0," "\"gmPresent\":0," - "\"gmIdentity\":\"c47d46.fffe.20acae\"" + "\"gmIdentity\":\"c47d46.fffe.20acae\"," + "\"servo_state\":\"SERVO_UNLOCKED\"" "}}")); EXPECT_EQ(m.actionField(), SET); EXPECT_EQ(m.managementId(), TIME_STATUS_NP); @@ -1859,6 +1860,7 @@ TEST(Json2msgTest, TIME_STATUS_NP) EXPECT_EQ(t->gmPresent, 0); ClockIdentity_t clockId = { 196, 125, 70, 255, 254, 32, 172, 174 }; EXPECT_EQ(t->gmIdentity, clockId); + EXPECT_EQ(t->servo_state, SERVO_UNLOCKED); } // Tests GRANDMASTER_SETTINGS_NP managment ID From d9ed515c522aa62baea76364ccc97db41eed6bd4 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Mon, 13 May 2024 12:39:02 +0800 Subject: [PATCH 064/151] Fix error for PmcDumpTest.TIME_STATUS_NP unit test Fix following unit test error: utest/pmc_dump.cpp:769: Failure Expected equality of these values: getPmcOut() Which is: " \n\t\tmaster_offset 0 \n\t\tingress_time 0 \n\t\tcumulativeScaledRateOffset +0.000000000 \n\t\tscaledLastGmPhaseChange 0 \n\t\tgmTimeBaseIndicator 0 \n\t\tlastGmPhaseChange 0x0000'0000000000000000.0000 \n\t\tgmPresent false \n\t\tgmIdentity c47d46.fffe.20acae \n\t\tservo_state SERVO_UNLOCKED" "\n\t\t" "master_offset 0" "\n\t\t" "ingress_time 0" "\n\t\t" "cumulativeScaledRateOffset +0.000000000" "\n\t\t" "scaledLastGmPhaseChange 0" "\n\t\t" "gmTimeBaseIndicator 0" "\n\t\t" "lastGmPhaseChange 0x0000'0000000000000000.0000" "\n\t\t" "gmPresent false" "\n\t\t" "gmIdentity c47d46.fffe.20acae" Which is: " \n\t\tmaster_offset 0 \n\t\tingress_time 0 \n\t\tcumulativeScaledRateOffset +0.000000000 \n\t\tscaledLastGmPhaseChange 0 \n\t\tgmTimeBaseIndicator 0 \n\t\tlastGmPhaseChange 0x0000'0000000000000000.0000 \n\t\tgmPresent false \n\t\tgmIdentity c47d46.fffe.20acae" With diff: @@ -8,3 @@ \t\tgmPresent false \t\tgmIdentity c47d46.fffe.20acae -\t\tservo_state SERVO_UNLOCKED Signed-off-by: Song Yoong Siang --- utest/pmc_dump.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utest/pmc_dump.cpp b/utest/pmc_dump.cpp index b735ffbc..eb49a35f 100644 --- a/utest/pmc_dump.cpp +++ b/utest/pmc_dump.cpp @@ -764,6 +764,7 @@ TEST(PmcDumpTest, TIME_STATUS_NP) t.gmPresent = 0; ClockIdentity_t clockId = { 196, 125, 70, 255, 254, 32, 172, 174 }; t.gmIdentity = clockId; + t.servo_state = SERVO_UNLOCKED; useTestMode(true); call_dump(m, TIME_STATUS_NP, &t); EXPECT_STREQ(getPmcOut(), @@ -774,7 +775,8 @@ TEST(PmcDumpTest, TIME_STATUS_NP) IDENT "gmTimeBaseIndicator 0" IDENT "lastGmPhaseChange 0x0000'0000000000000000.0000" IDENT "gmPresent false" - IDENT "gmIdentity c47d46.fffe.20acae"); + IDENT "gmIdentity c47d46.fffe.20acae" + IDENT "servo_state SERVO_UNLOCKED"); } // Tests dump GRANDMASTER_SETTINGS_NP tlv From 07660d15a0f8efc134ab034d07145a0f95e988da Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Mon, 13 May 2024 13:32:31 +0800 Subject: [PATCH 065/151] Fix c2cpp conversion for servo state enum Ensure proper convertion between ptpmgmt_servoState_e and ptpmgmt::servoState_e. Signed-off-by: Song Yoong Siang --- src/proc.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/proc.cpp b/src/proc.cpp index c729f4a4..12d903fa 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -1225,6 +1225,7 @@ C1(TIME_STATUS_NP) a.fractional_nanoseconds = d.fractional_nanoseconds; a.gmPresent = d.gmPresent; memcpy(a.gmIdentity.v, d.gmIdentity.v, ClockIdentity_t::size()); + a.servo_state = (ptpmgmt_servoState_e)d.servo_state; } C1(GRANDMASTER_SETTINGS_NP) { @@ -1713,6 +1714,7 @@ C2(TIME_STATUS_NP) a.fractional_nanoseconds = d.fractional_nanoseconds; a.gmPresent = d.gmPresent; memcpy(a.gmIdentity.v, d.gmIdentity.v, ClockIdentity_t::size()); + a.servo_state = (servoState_e)d.servo_state; } C2(GRANDMASTER_SETTINGS_NP) { From 4affffe2ed663d97a9e78c20f0704e75c030560b Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Mon, 13 May 2024 14:30:05 +0800 Subject: [PATCH 066/151] Add servo state into TIME_STATUS_NP structure test Add servo state into TIME_STATUS_NP structure c and cpp unit test. Signed-off-by: Song Yoong Siang --- uctest/json2msg.c | 2 +- uctest/proc.c | 3 ++- utest/proc.cpp | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/uctest/json2msg.c b/uctest/json2msg.c index ab1f0f39..f852f22c 100644 --- a/uctest/json2msg.c +++ b/uctest/json2msg.c @@ -2000,7 +2000,7 @@ Test(Json2msgTest, TIME_STATUS_NP) cr_expect(eq(int, t->fractional_nanoseconds, 0)); cr_expect(eq(int, t->gmPresent, 0)); cr_expect(zero(memcmp(t->gmIdentity.v, clockId, 8))); - cr_expect(eq(servoState_e, t->servo_state, PTPMGMT_SERVO_UNLOCKED)); + cr_expect(eq(u8, t->servo_state, PTPMGMT_SERVO_UNLOCKED)); m->free(m); } diff --git a/uctest/proc.c b/uctest/proc.c index c865e5f0..44dc9532 100644 --- a/uctest/proc.c +++ b/uctest/proc.c @@ -1156,7 +1156,7 @@ Test(ProcTest, TIME_STATUS_NP) cr_expect(eq(sz, m->getMsgLen(m), tlvLoc)); uint8_t mb[52] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 196, 125, 70, 255, 254, 32, 172, 174 + 0, 196, 125, 70, 255, 254, 32, 172, 174, 0 }; cr_assert(eq(int, m->parse(m, buf, rsp(buf, 0xc000, mb, sizeof mb)), PTPMGMT_MNG_PARSE_ERROR_OK)); @@ -1173,6 +1173,7 @@ Test(ProcTest, TIME_STATUS_NP) cr_expect(eq(int, r->fractional_nanoseconds, 0)); cr_expect(eq(int, r->gmPresent, 0)); cr_expect(zero(memcmp(r->gmIdentity.v, clockId, 8))); + cr_expect(eq(u8, r->servo_state, PTPMGMT_SERVO_UNLOCKED)); m->free(m); } diff --git a/utest/proc.cpp b/utest/proc.cpp index ac875164..7abc0126 100644 --- a/utest/proc.cpp +++ b/utest/proc.cpp @@ -892,7 +892,7 @@ TEST_F(ProcTest, TIME_STATUS_NP) EXPECT_EQ(getMsgLen(), tlvLoc); uint8_t m[52] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 196, 125, 70, 255, 254, 32, 172, 174 + 0, 196, 125, 70, 255, 254, 32, 172, 174, 0 }; ASSERT_EQ(parse(buf, rsp(0xc000, m, sizeof m)), MNG_PARSE_ERROR_OK); EXPECT_EQ(getTlvId(), TIME_STATUS_NP); @@ -907,6 +907,7 @@ TEST_F(ProcTest, TIME_STATUS_NP) EXPECT_EQ(r->fractional_nanoseconds, 0); EXPECT_EQ(r->gmPresent, 0); EXPECT_EQ(r->gmIdentity, clockId); + EXPECT_EQ(r->servo_state, SERVO_UNLOCKED); } // Tests GRANDMASTER_SETTINGS_NP structure From 1f88dda2c71460f9b93e2f00aa6c546c5d79d36e Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Tue, 14 May 2024 11:03:12 +0800 Subject: [PATCH 067/151] jclklib: Fix proxy hang issue after client is terminated Fix the issue that proxy is hang after client is terminated. Signed-off-by: Lai Peter Jun Ann --- jclklib/common/msgq_tport.cpp | 1 + jclklib/proxy/msgq_tport.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/jclklib/common/msgq_tport.cpp b/jclklib/common/msgq_tport.cpp index a844596f..e90a45aa 100644 --- a/jclklib/common/msgq_tport.cpp +++ b/jclklib/common/msgq_tport.cpp @@ -94,6 +94,7 @@ SEND_BUFFER_TYPE(MessageQueueTransmitterContext::sendBuffer) { if (mq_send(mqTransmitterDesc, (char *)get_buffer().data(), get_offset(), 0) == -1) { PrintErrorCode("Failed to send buffer"); + mq_close(mqTransmitterDesc); return false; } diff --git a/jclklib/proxy/msgq_tport.cpp b/jclklib/proxy/msgq_tport.cpp index d8123c97..5f4c6d68 100644 --- a/jclklib/proxy/msgq_tport.cpp +++ b/jclklib/proxy/msgq_tport.cpp @@ -51,7 +51,7 @@ LISTENER_CONTEXT_PROCESS_MESSAGE_TYPE(ProxyMessageQueueListenerContext::processM CREATE_TRANSMIT_CONTEXT_TYPE(ProxyMessageQueueListenerContext::CreateTransmitterContext) { - mqd_t txd = mq_open((char *)clientId.data(), TX_QUEUE_FLAGS); + mqd_t txd = mq_open((char *)clientId.data(), TX_QUEUE_FLAGS | O_NONBLOCK); if (txd == -1) { PrintErrorCode("Failed to open message queue " + string((const char*)clientId.data())); return NULL; From 0547369d5767654651979010b1b2ed62aa62c7f8 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Tue, 14 May 2024 12:34:54 +0800 Subject: [PATCH 068/151] jclklib: test: add upper and lower limit for master offset Allow user to input upper and lower limit for master offset. Signed-off-by: Song Yoong Siang --- jclklib/client/test.cpp | 60 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 5 deletions(-) diff --git a/jclklib/client/test.cpp b/jclklib/client/test.cpp index ed201991..32531497 100644 --- a/jclklib/client/test.cpp +++ b/jclklib/client/test.cpp @@ -36,6 +36,8 @@ void signal_handler(int sig) int main(int argc, char *argv[]) { int timeout = 10; + int upper_master_offset = 100000; + int lower_master_offset = -100000; std::uint32_t event2Sub1[1] = { ((1< Date: Tue, 14 May 2024 14:06:16 +0800 Subject: [PATCH 069/151] jclklib: test: Add hex support to mask input Allow user to input hex value to mask with 0x or 0X prefix. Besides, print out the unit for timeout and upper lower limit. Signed-off-by: Song Yoong Siang --- jclklib/client/test.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/jclklib/client/test.cpp b/jclklib/client/test.cpp index 32531497..1301c58d 100644 --- a/jclklib/client/test.cpp +++ b/jclklib/client/test.cpp @@ -52,10 +52,10 @@ int main(int argc, char *argv[]) while ((opt = getopt(argc, argv, "s:c:t:u:l:h")) != -1) { switch (opt) { case 's': - event2Sub1[0] = std::stoul(optarg); + event2Sub1[0] = std::stoul(optarg, nullptr, 0); break; case 'c': - composite_event[0] = std::stoul(optarg); + composite_event[0] = std::stoul(optarg, nullptr, 0); break; case 't': timeout = std::stoi(optarg); @@ -70,45 +70,45 @@ int main(int argc, char *argv[]) std::cout << "Usage of " << argv[0] << " :\n" "Options:\n" " -s subscribe_event_mask\n" - " Default: " << event2Sub1[0] << "\n" + " Default: 0x" << std::hex << event2Sub1[0] << "\n" " Bit 0: gmOffsetEvent\n" " Bit 1: servoLockedEvent\n" " Bit 2: asCapableEvent\n" " Bit 3: gmPresentEvent\n" " Bit 4: gmChangedEvent\n" " -c composite_event_mask\n" - " Default: " << composite_event[0] << "\n" + " Default: 0x" << composite_event[0] << "\n" " Bit 0: gmOffsetEvent\n" " Bit 1: servoLockedEvent\n" " Bit 2: asCapableEvent\n" - " -t timeout in waiting notification event\n" - " Default: " << timeout << "\n" - " -u upper master offset\n" - " Default: " << upper_master_offset << "\n" - " -l lower master offset\n" - " Default: " << lower_master_offset << "\n"; + " -u upper master offset (ns)\n" + " Default: " << std::dec << upper_master_offset << " ns\n" + " -l lower master offset (ns)\n" + " Default: " << lower_master_offset << " ns\n" + " -t timeout in waiting notification event (s)\n" + " Default: " << timeout << " s\n"; return EXIT_SUCCESS; default: std::cerr << "Usage of " << argv[0] << " :\n" "Options:\n" " -s subscribe_event_mask\n" - " Default: " << event2Sub1[0] << "\n" + " Default: 0x" << std::hex << event2Sub1[0] << "\n" " Bit 0: gmOffsetEvent\n" " Bit 1: servoLockedEvent\n" " Bit 2: asCapableEvent\n" " Bit 3: gmPresentEvent\n" " Bit 4: gmChangedEvent\n" " -c composite_event_mask\n" - " Default: " << composite_event[0] << "\n" + " Default: 0x" << composite_event[0] << "\n" " Bit 0: gmOffsetEvent\n" " Bit 1: servoLockedEvent\n" " Bit 2: asCapableEvent\n" - " -t timeout in waiting notification event\n" - " Default: " << timeout << "\n" - " -u upper master offset\n" - " Default: " << upper_master_offset << "\n" - " -l lower master offset\n" - " Default: " << lower_master_offset << "\n"; + " -u upper master offset (ns)\n" + " Default: " << std::dec << upper_master_offset << " ns\n" + " -l lower master offset (ns)\n" + " Default: " << lower_master_offset << " ns\n" + " -t timeout in waiting notification event (s)\n" + " Default: " << timeout << " s\n"; return EXIT_FAILURE; } } From 57b73df578872879167643ea7184b689cd696099 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 16 May 2024 13:44:15 +0800 Subject: [PATCH 070/151] Add license header to md Add GFDL-1.3-no-invariants-or-later license header to all md documentation files. Signed-off-by: Song Yoong Siang --- CODE_OF_CONDUCT.md | 2 ++ CONTRIBUTING.md | 2 ++ SECURITY.md | 2 ++ jclklib/README_jclklib.md | 2 ++ jclklib/TEST_jclklib.md | 2 ++ 5 files changed, 10 insertions(+) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 58dba18d..8e31d43d 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,3 +1,5 @@ + # Contributor Covenant Code of Conduct ## Our Pledge diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f682f4e4..5105bd99 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,3 +1,5 @@ + # Contributing ### License diff --git a/SECURITY.md b/SECURITY.md index cb59eb89..1f644380 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -1,3 +1,5 @@ + # Security Policy Intel is committed to rapidly addressing security vulnerabilities affecting our customers and providing clear guidance on the solution, impact, severity and mitigation. diff --git a/jclklib/README_jclklib.md b/jclklib/README_jclklib.md index 0f56bde1..4ce22f95 100644 --- a/jclklib/README_jclklib.md +++ b/jclklib/README_jclklib.md @@ -1,3 +1,5 @@ + # JCLKLIB codeflow Jclklib is a 2-part implementation for C/C++ application to obtain diff --git a/jclklib/TEST_jclklib.md b/jclklib/TEST_jclklib.md index cde714fa..9f392fde 100644 --- a/jclklib/TEST_jclklib.md +++ b/jclklib/TEST_jclklib.md @@ -1,3 +1,5 @@ + # The diagram of clockmanager(CM) usage in system : Test app <------> CM runtime lib (jclklib.so) <----------> jclklib_proxy <-----> libptpmgmt.so <-----> ptp4l From 8df6a18ed65ff0bc9bcbd6a7af08fa15e580d7fb Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 16 May 2024 14:10:23 +0800 Subject: [PATCH 071/151] jclklib: update new build steps in latest libptpmgmt code base In new code base, autoheader is needed. Signed-off-by: Song Yoong Siang --- jclklib/TEST_jclklib.md | 1 + 1 file changed, 1 insertion(+) diff --git a/jclklib/TEST_jclklib.md b/jclklib/TEST_jclklib.md index 9f392fde..06bb16ae 100644 --- a/jclklib/TEST_jclklib.md +++ b/jclklib/TEST_jclklib.md @@ -40,6 +40,7 @@ Then we compile the clock manager inside the jclklib folder. This will give us : Libtool-bin 3. Run this at the github root directory to compile libptpmgmt : + autoheader autoconf ./configure make From 26f5b8f96626435dd72c9fdfddcb737ef056e5d9 Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Thu, 16 May 2024 14:10:59 +0800 Subject: [PATCH 072/151] jclklib: Change to NOTIFY_CMLDS for as_capable ptp4l event Signed-off-by: Lai Peter Jun Ann --- jclklib/proxy/connect.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/jclklib/proxy/connect.cpp b/jclklib/proxy/connect.cpp index abfc3eec..816657e6 100644 --- a/jclklib/proxy/connect.cpp +++ b/jclklib/proxy/connect.cpp @@ -110,10 +110,6 @@ void event_handle() pe.gmIdentity[3], pe.gmIdentity[4], pe.gmIdentity[5], pe.gmIdentity[6],pe.gmIdentity[7]); break; - case PORT_DATA_SET_NP: - pe.asCapable = ((PORT_DATA_SET_NP_t *)data)->asCapable; - printf("asCapable = %d\n\n", pe.asCapable); - break; case PORT_DATA_SET: pd = (PORT_DATA_SET_t *)data; portState = pd->portState; @@ -129,6 +125,10 @@ void event_handle() pd = (PORT_DATA_SET_t *)data; portState = pd->portState; break; + case CMLDS_INFO_NP: + pe.asCapable = ((CMLDS_INFO_NP_t *)data)->as_capable; + printf("asCapable = %d\n\n", pe.asCapable); + break; default: return; } @@ -192,8 +192,8 @@ bool event_subscription(struct jcl_handle **handle) { memset(d.bitmask, 0, sizeof d.bitmask); d.setEvent(NOTIFY_TIME_SYNC); - d.setEvent(NOTIFY_PORT_STATE_NP); d.setEvent(NOTIFY_PORT_STATE); + d.setEvent(NOTIFY_CMLDS); if(!msg.setAction(SET, SUBSCRIBE_EVENTS_NP, &d)) { fprintf(stderr, "Fail set SUBSCRIBE_EVENTS_NP\n"); From 50013772b4ee9edd204a2c40f3e307bda8c7a7d2 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 16 May 2024 14:20:19 +0800 Subject: [PATCH 073/151] CI: update coverity based on new build steps new base need autoheader. Signed-off-by: Song Yoong Siang --- .github/workflows/coverity.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml index ce2c372c..37b3f613 100644 --- a/.github/workflows/coverity.yml +++ b/.github/workflows/coverity.yml @@ -27,6 +27,8 @@ jobs: - name: Install dependencies run: sudo apt-get install -y swig libtool-bin - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + - name: autoheader + run: autoheader - name: autoconf run: autoconf - name: configure From 15282f7e087f70f49b47855a02d473f3216988f4 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 16 May 2024 15:08:00 +0800 Subject: [PATCH 074/151] CI: move coverity to jclklib folder check coverity for jclklib since make is separated Signed-off-by: Song Yoong Siang --- .github/workflows/coverity.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml index 37b3f613..9221bcb9 100644 --- a/.github/workflows/coverity.yml +++ b/.github/workflows/coverity.yml @@ -33,8 +33,13 @@ jobs: run: autoconf - name: configure run: ./configure + - name: make + run: make + - name: install + run: sudo make install - uses: vapier/coverity-scan-action@2068473c7bdf8c2fb984a6a40ae76ee7facd7a85 # v1.8.0 with: + working-directory: jclklib email: ${{ secrets.COVERITY_SCAN_EMAIL }} token: ${{ secrets.COVERITY_SCAN_TOKEN }} project: libptpmgmt_iaclocklib From 65b1fc9ed9f29462a98ec145703d9a47048eccc3 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 16 May 2024 15:17:14 +0800 Subject: [PATCH 075/151] CI: fix Codeql build issue Update codeql build step to align with new build step Signed-off-by: Song Yoong Siang --- .github/workflows/codeql.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index bcc9af13..dc7ef3dc 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -67,6 +67,8 @@ jobs: - name: Install dependencies run: sudo apt-get install -y swig libtool-bin + - name: autoheader + run: autoheader - name: autoconf run: autoconf - name: configure From cfe2627502bd607ed34b2fe50e88ac4548bf50fe Mon Sep 17 00:00:00 2001 From: Noor Azura Ahmad Tarmizi Date: Thu, 9 May 2024 02:47:43 -0400 Subject: [PATCH 076/151] client data management: Regroup the client data accordingly. Split the data structures. Signed-off-by: Noor Azura Ahmad Tarmizi --- jclklib/client/client_state.cpp | 24 ++- jclklib/client/client_state.hpp | 22 +-- jclklib/client/connect_msg.cpp | 15 +- jclklib/client/connect_msg.hpp | 6 +- jclklib/client/init.cpp | 105 +++++++------ jclklib/client/init.hpp | 20 ++- jclklib/client/msgq_tport.cpp | 6 +- jclklib/client/notification_msg.cpp | 142 +++++++++++++----- jclklib/client/notification_msg.hpp | 10 ++ jclklib/client/subscribe_msg.cpp | 223 ++++++++++++++++++++++------ jclklib/client/subscribe_msg.hpp | 24 ++- jclklib/client/test.cpp | 39 +++-- jclklib/common/notification_msg.hpp | 8 +- 13 files changed, 469 insertions(+), 175 deletions(-) diff --git a/jclklib/client/client_state.cpp b/jclklib/client/client_state.cpp index c114dc9c..0465cdb3 100644 --- a/jclklib/client/client_state.cpp +++ b/jclklib/client/client_state.cpp @@ -33,6 +33,28 @@ ClientState::ClientState() fill(begin(clientID ), end( clientID ), 0 ); } +ClientState::ClientState(ClientState &newState) +{ + connected = newState.get_connected(); + subscribed = newState.get_subscribed(); + sessionId = newState.get_sessionId(); + strcpy((char *)clientID.data(), (char *)newState.get_clientID().data()); + eventState = newState.get_eventState(); + eventStateCount = newState.get_eventStateCount(); + eventSub = newState.get_eventSub(); +} + +void ClientState::set_clientState(ClientState &newState) +{ + connected = newState.get_connected(); + subscribed = newState.get_subscribed(); + sessionId = newState.get_sessionId(); + strcpy((char *)clientID.data(), (char *)newState.get_clientID().data()); + eventState = newState.get_eventState(); + eventStateCount = newState.get_eventStateCount(); + eventSub = newState.get_eventSub(); +} + bool ClientState::get_connected() {return connected;} void ClientState::set_connected(bool new_state) {connected = new_state;} @@ -79,4 +101,4 @@ JClkLibCommon::jcl_subscription &ClientState::get_eventSub() { return eventSub; } -ClientState JClkLibClient::state{}; +//ClientState JClkLibClient::state{}; diff --git a/jclklib/client/client_state.hpp b/jclklib/client/client_state.hpp index 32ecd301..63500a5d 100644 --- a/jclklib/client/client_state.hpp +++ b/jclklib/client/client_state.hpp @@ -25,16 +25,19 @@ namespace JClkLibClient { class ClientState { private: - std::atomic_bool connected; - std::atomic_bool subscribed; - JClkLibCommon::sessionId_t sessionId; - JClkLibCommon::TransportClientId clientID; - JClkLibCommon::jcl_state eventState; - JClkLibCommon::jcl_state_event_count eventStateCount; - JClkLibCommon::jcl_subscription eventSub; + std::atomic_bool connected = false; + std::atomic_bool subscribed = false; + JClkLibCommon::sessionId_t sessionId = JClkLibCommon::InvalidSessionId; + JClkLibCommon::TransportClientId clientID = {}; + uint8_t ptp4l_id = 0; + JClkLibCommon::jcl_state eventState = {}; + JClkLibCommon::jcl_state_event_count eventStateCount ={}; + JClkLibCommon::jcl_subscription eventSub ={}; public: ClientState(); + ClientState (ClientState &newState); + void set_clientState(ClientState &newState); bool get_connected(); void set_connected(bool state); bool get_subscribed(); @@ -47,12 +50,11 @@ namespace JClkLibClient { void set_eventState(JClkLibCommon::jcl_state eState); std::string toString(); JClkLibCommon::jcl_subscription &get_eventSub(); - //void get_clientID_memcpy(JClkLibCommon::TransportClientId cID); - //void set_clientID_memcpy(JClkLibCommon::TransportClientId cID); DECLARE_ACCESSOR(sessionId); + DECLARE_ACCESSOR(ptp4l_id); }; - extern JClkLibClient::ClientState state; + //extern JClkLibClient::ClientState state; } #endif/*PROXY_CLIENT_STATE*/ diff --git a/jclklib/client/connect_msg.cpp b/jclklib/client/connect_msg.cpp index b8c04a15..9711cb68 100644 --- a/jclklib/client/connect_msg.cpp +++ b/jclklib/client/connect_msg.cpp @@ -57,11 +57,18 @@ PARSE_RXBUFFER_TYPE(ClientConnectMessage::parseBuffer) { if (!PARSE_RX(FIELD, data.ptp4l_id, LxContext)) return false; - printf("ptp4l_id = %d\n\n", data.ptp4l_id); + currentClientState->set_ptp4l_id(data.ptp4l_id); + + printf("ptp4l_id = %d\n\n",currentClientState->get_ptp4l_id()); return true; } +void ClientConnectMessage::setClientState(ClientState *newClientState){ + //currentClientState.set_clientState(newClientState); + currentClientState = newClientState; +} + /** @brief process the reply for connect msg from proxy. * * This function will be called when the transport layer @@ -84,11 +91,11 @@ PROCESS_MESSAGE_TYPE(ClientConnectMessage::processMessage) PrintDebug("Processing client connect message (reply)"); - state.set_connected(true); - state.set_sessionId(this->get_sessionId()); + currentClientState->set_connected(true); + currentClientState->set_sessionId(this->get_sessionId()); PrintDebug("Connected with session ID: " + to_string(this->get_sessionId())); - PrintDebug("Current state.sessionId: " + to_string(state.get_sessionId())); + PrintDebug("Current state.sessionId: " + to_string(currentClientState->get_sessionId())); this->set_msgAck(ACK_NONE); diff --git a/jclklib/client/connect_msg.hpp b/jclklib/client/connect_msg.hpp index 4804a075..dd9a3fc4 100644 --- a/jclklib/client/connect_msg.hpp +++ b/jclklib/client/connect_msg.hpp @@ -25,10 +25,12 @@ namespace JClkLibClient class ClientConnectMessage : virtual public JClkLibCommon::CommonConnectMessage, virtual public ClientMessage { + private: + ClientState *currentClientState; public: ClientConnectMessage() : MESSAGE_CONNECT() {}; - + //ClientConnectMessage(ClientState &newState); static std::mutex cv_mtx; static std::condition_variable cv; @@ -54,6 +56,8 @@ namespace JClkLibClient * @return true */ static bool initMessage(); + + void setClientState(ClientState *newClientState); }; } diff --git a/jclklib/client/init.cpp b/jclklib/client/init.cpp index e8ca1a98..2fd05833 100644 --- a/jclklib/client/init.cpp +++ b/jclklib/client/init.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -36,14 +37,19 @@ std::condition_variable ClientConnectMessage::cv; std::mutex ClientSubscribeMessage::cv_mtx; std::condition_variable ClientSubscribeMessage::cv; -extern JClkLibCommon::client_ptp_event client_ptp_data; +//extern JClkLibCommon::client_ptp_event client_ptp_data; -TransportClientId globalClientID; +//TransportClientId globalClientID; -bool JClkLibClient::jcl_connect() +bool JClkLibClientApi::jcl_connect() { unsigned int timeout_sec = (unsigned int) DEFAULT_CONNECT_TIME_OUT; Message0 connectMsg(new ClientConnectMessage()); + TransportClientId newClientID; + + + ClientConnectMessage *cmsg = dynamic_cast(connectMsg.get()); + cmsg->setClientState(&appClientState); //BlockStopSignal(); if(!ClientMessage::init()) { @@ -61,11 +67,11 @@ bool JClkLibClient::jcl_connect() // Wait for connection result auto endTime = std::chrono::system_clock::now() + std::chrono::seconds(timeout_sec); std::unique_lock lck(ClientConnectMessage::cv_mtx); - while (state.get_connected() == false ) + while (appClientState.get_connected() == false ) { auto res = ClientConnectMessage::cv.wait_until(lck, endTime); if (res == std::cv_status::timeout) { - if (state.get_connected() == false) { + if (appClientState.get_connected() == false) { PrintDebug("[CONNECT] Connect reply from proxy - timeout failure!!"); return false; } @@ -75,15 +81,16 @@ bool JClkLibClient::jcl_connect() } } - ClientConnectMessage *cmsg = dynamic_cast(connectMsg.get()); - strcpy((char *)globalClientID.data(), (char *)cmsg->getClientId().data()); - state.set_clientID(globalClientID); + //ClientConnectMessage *cmsg = dynamic_cast(connectMsg.get()); + strcpy((char *)newClientID.data(), (char *)cmsg->getClientId().data()); + + appClientState.set_clientID(newClientID); return true; } -bool JClkLibClient::jcl_subscribe(JClkLibCommon::jcl_subscription &newSub, +bool JClkLibClientApi::jcl_subscribe(JClkLibCommon::jcl_subscription &newSub, JClkLibCommon::jcl_state ¤tState) { unsigned int timeout_sec = (unsigned int) DEFAULT_SUBSCRIBE_TIME_OUT; @@ -99,24 +106,32 @@ bool JClkLibClient::jcl_subscribe(JClkLibCommon::jcl_subscription &newSub, else PrintDebug("[JClkLibClient::subscribe] subscribeMsgcreation is OK !!\n"); + //cmsg->setClientState(JClkLibCommon::jcl_state *newState); + cmsg->setClientState(&appClientState); + /* Write the current event subscription */ - state.get_eventSub().set_event(newSub.getc_event()); - state.get_eventSub().set_value(newSub.getc_value()); - state.get_eventSub().set_composite_event(newSub.getc_composite_event()); + appClientState.get_eventSub().set_event(newSub.getc_event()); + appClientState.get_eventSub().set_value(newSub.getc_value()); + appClientState.get_eventSub().set_composite_event(newSub.getc_composite_event()); + // This is to copy the event Mask ( same as master_offset_low ?? ) cmsg->getSubscription().get_event().copyEventMask(newSub.get_event()); + // Wri + strcpy((char *)cmsg->getClientId().data(), (char *)appClientState.get_clientID().data()); + cmsg->set_sessionId(appClientState.get_sessionId()); // this is where it turns to 0 + ClientMessageQueue::writeTransportClientId(subscribeMsg.get()); ClientMessageQueue::sendMessage(subscribeMsg.get()); // Wait for subscription result auto endTime = std::chrono::system_clock::now() + std::chrono::seconds(timeout_sec); std::unique_lock lck(ClientSubscribeMessage::cv_mtx); - while (state.get_subscribed() == false ) + while (appClientState.get_subscribed() == false ) { auto res = ClientSubscribeMessage::cv.wait_until(lck, endTime); if (res == std::cv_status::timeout) { - if (state.get_subscribed() == false) { + if (appClientState.get_subscribed() == false) { PrintDebug("[SUBSCRIBE] No reply from proxy - timeout failure!!"); return false; } @@ -126,12 +141,22 @@ bool JClkLibClient::jcl_subscribe(JClkLibCommon::jcl_subscription &newSub, } } - currentState = state.get_eventState(); + JClkLibCommon::jcl_state jclCurrentState = appClientState.get_eventState(); + printf("[JClkLibClient]::subscribe : state - \n"); + printf ("offset_in_range = %d, servo_locked = %d gmPresent = %d as_Capable = %d gm_Changed = %d\n", \ + jclCurrentState.offset_in_range, jclCurrentState.servo_locked,\ + jclCurrentState.gm_present, jclCurrentState.as_Capable, jclCurrentState.gm_changed); + printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x \n", + jclCurrentState.gmIdentity[0], jclCurrentState.gmIdentity[1],jclCurrentState.gmIdentity[2], + jclCurrentState.gmIdentity[3], jclCurrentState.gmIdentity[4], + jclCurrentState.gmIdentity[5], jclCurrentState.gmIdentity[6],jclCurrentState.gmIdentity[7]); + + currentState = jclCurrentState; return true; } -bool JClkLibClient::jcl_disconnect() +bool JClkLibClientApi::jcl_disconnect() { bool retVal = false; @@ -144,6 +169,12 @@ bool JClkLibClient::jcl_disconnect() PrintDebug("Client Finalize Failed"); goto done; } + + /* delete the ClientPtpEvent inside Subscription */ + ClientSubscribeMessage::deleteClientPtpEventStruct(appClientState.get_sessionId()); + /* delete the ClientState reference inside ClientNotificationMessage class */ + ClientNotificationMessage::deleteClientState(&appClientState); + retVal = true; done: @@ -166,20 +197,20 @@ bool JClkLibClient::jcl_disconnect() * @return Returns true if there is event changes within the timeout period, * and false otherwise. */ -int JClkLibClient::jcl_status_wait(int timeout, JClkLibCommon::jcl_state &jcl_state, - JClkLibCommon::jcl_state_event_count &eventCount) +int JClkLibClientApi::jcl_status_wait(int timeout, JClkLibCommon::jcl_state &jcl_state_ref, + JClkLibCommon::jcl_state_event_count &eventCountRef) { auto start = std::chrono::high_resolution_clock::now(); auto end = (timeout == -1) ? std::chrono::time_point::max() : start + std::chrono::seconds(timeout); bool event_changes_detected = false; + + /* Get the event state and event count from the API*/ + JClkLibCommon::jcl_state_event_count eventCount = appClientState.get_eventStateCount(); + JClkLibCommon::jcl_state jcl_state = appClientState.get_eventState(); do { - /* Get the event state and event count*/ - eventCount = state.get_eventStateCount(); - jcl_state = state.get_eventState(); - /* Check if any member of eventCount is non-zero */ if (eventCount.offset_in_range_event_count || eventCount.asCapable_event_count || @@ -198,30 +229,12 @@ int JClkLibClient::jcl_status_wait(int timeout, JClkLibCommon::jcl_state &jcl_st if (!event_changes_detected) return false; - /* Reset the atomic */ - client_ptp_data.offset_event_count.fetch_sub(eventCount.offset_in_range_event_count, - std::memory_order_relaxed); - client_ptp_data.asCapable_event_count.fetch_sub(eventCount.asCapable_event_count, - std::memory_order_relaxed); - client_ptp_data.servo_state_event_count.fetch_sub(eventCount.servo_locked_event_count, - std::memory_order_relaxed); - client_ptp_data.gmPresent_event_count.fetch_sub(eventCount.gmPresent_event_count, - std::memory_order_relaxed); - client_ptp_data.gmChanged_event_count.fetch_sub(eventCount.gm_changed_event_count, - std::memory_order_relaxed); - client_ptp_data.composite_event_count.fetch_sub(eventCount.composite_event_count, - std::memory_order_relaxed); - - JClkLibCommon::jcl_state_event_count jclCurrentEventCount = {}; - - jclCurrentEventCount.gmPresent_event_count = client_ptp_data.gmPresent_event_count; - jclCurrentEventCount.offset_in_range_event_count = client_ptp_data.offset_event_count; - jclCurrentEventCount.asCapable_event_count = client_ptp_data.asCapable_event_count; - jclCurrentEventCount.servo_locked_event_count = client_ptp_data.servo_state_event_count; - jclCurrentEventCount.gm_changed_event_count = client_ptp_data.gmChanged_event_count; - jclCurrentEventCount.composite_event_count = client_ptp_data.composite_event_count; - - state.set_eventStateCount (jclCurrentEventCount); + /* copy out the current state */ + eventCountRef = eventCount; + jcl_state_ref = jcl_state; + + /* Reset the atomic count by reducing the corresponding eventCount */ + ClientSubscribeMessage::resetClientPtpEventStruct(appClientState.get_sessionId(), eventCount); return true; } diff --git a/jclklib/client/init.hpp b/jclklib/client/init.hpp index 52793401..bc94adbb 100644 --- a/jclklib/client/init.hpp +++ b/jclklib/client/init.hpp @@ -16,8 +16,25 @@ #define CLIENT_INIT_HPP #include +#include +#include + namespace JClkLibClient { + +class JClkLibClientApi { + private : + //std::map ports; + static std::map clientStateMap; + ClientState appClientState; + public : + JClkLibClientApi() { + } + static int init(){ + // In case we need to init something for API. + return 0; + }; + ClientState &getClientState() { return appClientState;}; bool jcl_connect(); bool jcl_disconnect(); bool jcl_subscribe(JClkLibCommon::jcl_subscription &newSub, @@ -25,6 +42,7 @@ namespace JClkLibClient { int jcl_status_wait(int timeout, JClkLibCommon::jcl_state &jcl_state, JClkLibCommon::jcl_state_event_count &eventCount); -}; + }; +} #endif/*CLIENT_INIT_HPP*/ diff --git a/jclklib/client/msgq_tport.cpp b/jclklib/client/msgq_tport.cpp index 23a0f175..f3f69c65 100644 --- a/jclklib/client/msgq_tport.cpp +++ b/jclklib/client/msgq_tport.cpp @@ -131,9 +131,9 @@ bool ClientMessageQueue::writeTransportClientId(Message *msg) return false; } - strcpy((char *)cmsg->getClientId().data(), (char *)state.get_clientID().data()); - - cmsg->set_sessionId(state.get_sessionId()); // this is where it turns to 0 + //strcpy((char *)cmsg->getClientId().data(), (char *)state.get_clientID().data()); + //cmsg->set_sessionId(state.get_sessionId()); // this is where it turns to 0 + printf ("[ClientMessageQueue] [SUBSCRIBE] cmsg->set_sessionId() : %d\n", cmsg->get_sessionId()); PrintDebug("[ClientMessageQueue] [SUBSCRIBE] : subscription->event Mask : " + cmsg->getSubscription().get_event().toString()); break; } diff --git a/jclklib/client/notification_msg.cpp b/jclklib/client/notification_msg.cpp index f1485fd7..f295a525 100644 --- a/jclklib/client/notification_msg.cpp +++ b/jclklib/client/notification_msg.cpp @@ -13,6 +13,8 @@ */ #include +#include + #include #include #include @@ -21,11 +23,13 @@ using namespace std; using namespace JClkLibCommon; using namespace JClkLibClient; +/* JClkLibCommon::client_ptp_event client_ptp_data; JClkLibCommon::client_ptp_event composite_client_ptp_data; JClkLibCommon::ptp_event proxy_data = {}; JClkLibCommon::jcl_state jclCurrentState = {}; JClkLibCommon::jcl_state_event_count jclCurrentEventCount = {}; +*/ /** @brief Create the ClientNotificationMessage object * @@ -59,107 +63,165 @@ BUILD_TXBUFFER_TYPE(ClientNotificationMessage::makeBuffer) const return true; } +void ClientNotificationMessage::addClientState(ClientState *newClientState){ + ClientStateArray.push_back(newClientState); +} + +void ClientNotificationMessage::deleteClientState(ClientState *newClientState) { + ClientStateArray.erase(std::remove(ClientStateArray.begin(), \ + ClientStateArray.end(), newClientState), ClientStateArray.end()); +} + PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) { PrintDebug("[ClientNotificationMessage]::processMessage "); + //std::uint32_t eventSub[1]; + //state.get_eventSub().get_event().readEvent(eventSub, (std::size_t)sizeof(eventSub)); + //std::uint32_t composite_eventSub[1]; + //state.get_eventSub().get_composite_event().readEvent(composite_eventSub, (std::size_t)sizeof(composite_eventSub)); + + bool old_composite_event; + /* Need to walk thru the whole vector*/ + std::vector ::iterator it ; + + for (it=ClientStateArray.begin(); it state.get_eventSub().get_value().getLower(gmOffsetValue)) && - (client_ptp_data.master_offset < state.get_eventSub().get_value().getUpper(gmOffsetValue))) { - if (!(client_ptp_data.master_offset_within_boundary)) + ClientState *currentClientState = *it; + + JClkLibCommon::jcl_state &jclCurrentState = currentClientState->get_eventState(); + JClkLibCommon::jcl_state_event_count &jclCurrentEventCount = currentClientState->get_eventStateCount(); + + currentClientState->get_eventSub().get_event().readEvent(eventSub, (std::size_t)sizeof(eventSub)); + currentClientState->get_eventSub().get_composite_event().readEvent(composite_eventSub, (std::size_t)sizeof(composite_eventSub)); + + /* get the correct client_ptp_data according to our current sessionID */ + JClkLibCommon::client_ptp_event* client_ptp_data = NULL; + client_ptp_data = ClientSubscribeMessage::getClientPtpEventStruct(currentClientState->get_sessionId()); + + JClkLibCommon::client_ptp_event* composite_client_ptp_data = NULL; + composite_client_ptp_data = ClientSubscribeMessage::getClientPtpEventCompositeStruct(currentClientState->get_sessionId()); + + if ( client_ptp_data == NULL ) { + printf ("ClientNotificationMessage::processMessage ERROR in obtaining client_ptp_data.\n"); + return false; + } + + if ((eventSub[0] & 1<master_offset)) { + client_ptp_data->master_offset = proxy_data.master_offset; + if ((client_ptp_data->master_offset > currentClientState->get_eventSub().get_value().getLower(gmOffsetValue)) && + (client_ptp_data->master_offset < currentClientState->get_eventSub().get_value().getUpper(gmOffsetValue))) { + if (!(client_ptp_data->master_offset_within_boundary)) { - client_ptp_data.master_offset_within_boundary = true; - client_ptp_data.offset_event_count.fetch_add(1, std::memory_order_relaxed); + client_ptp_data->master_offset_within_boundary = true; + client_ptp_data->offset_event_count.fetch_add(1, std::memory_order_relaxed); } } else { - if ((client_ptp_data.master_offset_within_boundary)) + if ((client_ptp_data->master_offset_within_boundary)) { - client_ptp_data.master_offset_within_boundary = false; - client_ptp_data.offset_event_count.fetch_add(1, std::memory_order_relaxed); + client_ptp_data->master_offset_within_boundary = false; + client_ptp_data->offset_event_count.fetch_add(1, std::memory_order_relaxed); } } } - if ((eventSub[0] & 1<servo_state)) { + client_ptp_data->servo_state = proxy_data.servo_state; + client_ptp_data->servo_state_event_count.fetch_add(1, std::memory_order_relaxed); } - if ((eventSub[0] & 1<gmIdentity, proxy_data.gmIdentity, sizeof(proxy_data.gmIdentity)) != 0)) { + memcpy(client_ptp_data->gmIdentity, proxy_data.gmIdentity, sizeof(proxy_data.gmIdentity)); + client_ptp_data->gmChanged_event_count.fetch_add(1, std::memory_order_relaxed); jclCurrentState.gm_changed = true; } else { jclCurrentState.gm_changed = false; } - if ((eventSub[0] & 1<asCapable)) { + client_ptp_data->asCapable = proxy_data.asCapable; + client_ptp_data->asCapable_event_count.fetch_add(1, std::memory_order_relaxed); } - if ((eventSub[0] & 1<gmPresent)) { + client_ptp_data->gmPresent = proxy_data.gmPresent; + client_ptp_data->gmPresent_event_count.fetch_add(1, std::memory_order_relaxed); } if (composite_eventSub[0]) { - old_composite_event = composite_client_ptp_data.composite_event; - composite_client_ptp_data.composite_event = true; + old_composite_event = composite_client_ptp_data->composite_event; + composite_client_ptp_data->composite_event = true; } - if ((composite_eventSub[0] & 1< state.get_eventSub().get_value().getLower(gmOffsetValue)) && - (composite_client_ptp_data.master_offset < state.get_eventSub().get_value().getUpper(gmOffsetValue))) { - composite_client_ptp_data.composite_event = true; + if ((composite_eventSub[0] & 1<master_offset)) { + composite_client_ptp_data->master_offset = proxy_data.master_offset; + if ((composite_client_ptp_data->master_offset > currentClientState->get_eventSub().get_value().getLower(gmOffsetValue)) && + (composite_client_ptp_data->master_offset < currentClientState->get_eventSub().get_value().getUpper(gmOffsetValue))) { + composite_client_ptp_data->composite_event = true; } else { - composite_client_ptp_data.composite_event = false; + composite_client_ptp_data->composite_event = false; } } if (composite_eventSub[0] & 1<= SERVO_LOCKED ? true:false; + composite_client_ptp_data->composite_event &= proxy_data.servo_state >= SERVO_LOCKED ? true:false; } if (composite_eventSub[0] & 1< 0 ? true:false; + composite_client_ptp_data->composite_event &= proxy_data.asCapable > 0 ? true:false; } - if (composite_eventSub[0] && (old_composite_event != composite_client_ptp_data.composite_event)) { - client_ptp_data.composite_event_count.fetch_add(1, std::memory_order_relaxed); + if (composite_eventSub[0] && (old_composite_event != composite_client_ptp_data->composite_event)) { + client_ptp_data->composite_event_count.fetch_add(1, std::memory_order_relaxed); } +/* jclCurrentState.gm_present = client_ptp_data.gmPresent > 0 ? true:false; jclCurrentState.as_Capable = client_ptp_data.asCapable > 0 ? true:false; jclCurrentState.offset_in_range = client_ptp_data.master_offset_within_boundary; jclCurrentState.servo_locked = client_ptp_data.servo_state >= SERVO_LOCKED ? true:false; jclCurrentState.composite_event = composite_client_ptp_data.composite_event; memcpy(jclCurrentState.gmIdentity, client_ptp_data.gmIdentity, sizeof(client_ptp_data.gmIdentity)); - +*/ /* TODO : checked for jclCurrentState.gm_changed based on GM_identity previously stored */ +/* jclCurrentEventCount.gmPresent_event_count = client_ptp_data.gmPresent_event_count; jclCurrentEventCount.offset_in_range_event_count = client_ptp_data.offset_event_count; jclCurrentEventCount.asCapable_event_count = client_ptp_data.asCapable_event_count; jclCurrentEventCount.servo_locked_event_count = client_ptp_data.servo_state_event_count; jclCurrentEventCount.gm_changed_event_count = client_ptp_data.gmChanged_event_count; jclCurrentEventCount.composite_event_count = client_ptp_data.composite_event_count; +*/ + + //state.set_eventState (jclCurrentState); + //state.set_eventStateCount (jclCurrentEventCount); + + jclCurrentState.gm_present = client_ptp_data->gmPresent > 0 ? true:false; + jclCurrentState.as_Capable = client_ptp_data->asCapable > 0 ? true:false; + jclCurrentState.offset_in_range = client_ptp_data->master_offset_within_boundary; + jclCurrentState.servo_locked = client_ptp_data->servo_state >= SERVO_LOCKED ? true:false; + jclCurrentState.composite_event = composite_client_ptp_data->composite_event; + memcpy(jclCurrentState.gmIdentity, client_ptp_data->gmIdentity, sizeof(client_ptp_data->gmIdentity)); - state.set_eventState (jclCurrentState); - state.set_eventStateCount (jclCurrentEventCount); + /* TODO : checked for jclCurrentState.gm_changed based on GM_identity previously stored */ + + jclCurrentEventCount.gmPresent_event_count = client_ptp_data->gmPresent_event_count; + jclCurrentEventCount.offset_in_range_event_count = client_ptp_data->offset_event_count; + jclCurrentEventCount.asCapable_event_count = client_ptp_data->asCapable_event_count; + jclCurrentEventCount.servo_locked_event_count = client_ptp_data->servo_state_event_count; + jclCurrentEventCount.gm_changed_event_count = client_ptp_data->gmChanged_event_count; + jclCurrentEventCount.composite_event_count = client_ptp_data->composite_event_count; + } + return true; } diff --git a/jclklib/client/notification_msg.hpp b/jclklib/client/notification_msg.hpp index 980ba672..d2034236 100644 --- a/jclklib/client/notification_msg.hpp +++ b/jclklib/client/notification_msg.hpp @@ -46,8 +46,18 @@ namespace JClkLibClient virtual PARSE_RXBUFFER_TYPE(parseBuffer); + static void addClientState(ClientState *newClientState); + static void deleteClientState(ClientState *newClientState); + protected: ClientNotificationMessage() : MESSAGE_NOTIFY() {} + + private: + inline static std::vector ClientStateArray; + + // proxy_data can be 1 only. it is ok. + JClkLibCommon::ptp_event proxy_data = {}; + }; } diff --git a/jclklib/client/subscribe_msg.cpp b/jclklib/client/subscribe_msg.cpp index 183f21e9..51fca0b5 100644 --- a/jclklib/client/subscribe_msg.cpp +++ b/jclklib/client/subscribe_msg.cpp @@ -13,6 +13,7 @@ */ #include +#include #include #include @@ -20,8 +21,9 @@ using namespace JClkLibClient; using namespace JClkLibCommon; using namespace std; -JClkLibCommon::client_ptp_event client_data = {}; -JClkLibCommon::client_ptp_event composite_client_data = {}; +//JClkLibCommon::client_ptp_event client_data = {}; +//JClkLibCommon::client_ptp_event composite_client_data = {}; +//JClkLibCommon::client_ptp_event client_data = {}; /** @brief Create the ClientSubscribeMessage object * @@ -51,15 +53,23 @@ bool ClientSubscribeMessage::initMessage() return true; } +void ClientSubscribeMessage::setClientState(ClientState *newClientState){ + //currentClientState.set_clientState(newClientState); + currentClientState = newClientState; + jclCurrentState = &(newClientState->get_eventState()); + +} + + PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { JClkLibCommon::ptp_event data = {}; - JClkLibCommon::jcl_state jclCurrentState = {}; + //JClkLibCommon::jcl_state jclCurrentStateLocal = *jclCurrentState; std::uint32_t eventSub[1]; - state.get_eventSub().get_event().readEvent(eventSub, (std::size_t)sizeof(eventSub)); + currentClientState->get_eventSub().get_event().readEvent(eventSub, (std::size_t)sizeof(eventSub)); std::uint32_t composite_eventSub[1]; - state.get_eventSub().get_composite_event().readEvent(composite_eventSub, (std::size_t)sizeof(composite_eventSub)); + currentClientState->get_eventSub().get_composite_event().readEvent(composite_eventSub, (std::size_t)sizeof(composite_eventSub)); PrintDebug("[ClientSubscribeMessage]::parseBuffer "); if(!CommonSubscribeMessage::parseBuffer(LxContext)) @@ -68,63 +78,98 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { if (!PARSE_RX(FIELD, data, LxContext)) return false; - /* TODO : set the client_data per client instead of global */ - if ((eventSub[0] & 1< state.get_eventSub().get_value().getLower(gmOffsetValue)) && - (client_data.master_offset < state.get_eventSub().get_value().getUpper(gmOffsetValue))) { - client_data.master_offset_within_boundary = true; - } - } + printf("master_offset = %ld, servo_state = %d gmPresent = %d\n", data.master_offset, data.servo_state, data.gmPresent); + printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x ", + data.gmIdentity[0], data.gmIdentity[1],data.gmIdentity[2], + data.gmIdentity[3], data.gmIdentity[4], + data.gmIdentity[5], data.gmIdentity[6],data.gmIdentity[7]); + printf("asCapable = %d, ptp4l_id = %d\n\n", data.asCapable, data.ptp4l_id); - if ((eventSub[0] & 1<get_sessionId(); + std::map >::iterator it ; + JClkLibCommon::client_ptp_event* client_data , *composite_client_data; - if ((eventSub[0] & 1<(it->second); + composite_client_data = std::get<1>(it->second); } - if ((eventSub[0] & 1<master_offset)) { + client_data->master_offset = data.master_offset; + if ((client_data->master_offset > currentClientState->get_eventSub().get_value().getLower(gmOffsetValue)) && + (client_data->master_offset < currentClientState->get_eventSub().get_value().getUpper(gmOffsetValue))) { + client_data->master_offset_within_boundary = true; + } } - if (composite_eventSub[0]) { - composite_client_data.composite_event = true; + if ((eventSub[0] & 1<servo_state)) { + client_data->servo_state = data.servo_state; } - if ((composite_eventSub[0] & 1< state.get_eventSub().get_value().getLower(gmOffsetValue)) && - (composite_client_data.master_offset < state.get_eventSub().get_value().getUpper(gmOffsetValue))) { - composite_client_data.composite_event = true; - } else { - composite_client_data.composite_event = false; - } + if ((eventSub[0] & 1<gmIdentity, data.gmIdentity, sizeof(data.gmIdentity))) != 0) { + memcpy(client_data->gmIdentity, data.gmIdentity, sizeof(data.gmIdentity)); + jclCurrentState->gm_changed = true; } - if (composite_eventSub[0] & 1<= SERVO_LOCKED ? true:false; + if ((eventSub[0] & 1<asCapable)) { + client_data->asCapable = data.asCapable; } - if (composite_eventSub[0] & 1< 0 ? true:false; + if ((eventSub[0] & 1<gmPresent)) { + client_data->gmPresent = data.gmPresent; } - jclCurrentState.gm_present = client_data.gmPresent > 0 ? true:false; - jclCurrentState.as_Capable = client_data.asCapable > 0 ? true:false; - jclCurrentState.offset_in_range = client_data.master_offset_within_boundary; - jclCurrentState.servo_locked = client_data.servo_state >= SERVO_LOCKED ? true:false; - jclCurrentState.composite_event = composite_client_data.composite_event; - memcpy(jclCurrentState.gmIdentity, client_data.gmIdentity, sizeof(client_data.gmIdentity)); - /* TODO : checked for jclCurrentState.gm_changed based on GM_identity previously stored */ + if (composite_eventSub[0]) { + composite_client_data->composite_event = true; + } - this->setClientState (jclCurrentState); + if ((composite_eventSub[0] & 1<master_offset)) { + composite_client_data->master_offset = data.master_offset; + if ((composite_client_data->master_offset > currentClientState->get_eventSub().get_value().getLower(gmOffsetValue)) && + (composite_client_data->master_offset < currentClientState->get_eventSub().get_value().getUpper(gmOffsetValue))) { + composite_client_data->composite_event = true; + } else { + composite_client_data->composite_event = false; + } + } + + if (composite_eventSub[0] & 1<composite_event &= data.servo_state >= SERVO_LOCKED ? true:false; + } + + if (composite_eventSub[0] & 1<composite_event &= data.asCapable > 0 ? true:false; + } + + printf("CLIENT master_offset = %ld, servo_state = %d gmPresent = %d\n", client_data->master_offset, \ + client_data->servo_state, client_data->gmPresent); + printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x ", + client_data->gmIdentity[0], client_data->gmIdentity[1],client_data->gmIdentity[2], + client_data->gmIdentity[3], client_data->gmIdentity[4], + client_data->gmIdentity[5], client_data->gmIdentity[6],client_data->gmIdentity[7]); + printf("asCapable = %d\n\n", client_data->asCapable); + + jclCurrentState->gm_present = client_data->gmPresent > 0 ? true:false; + jclCurrentState->as_Capable = client_data->asCapable > 0 ? true:false; + jclCurrentState->offset_in_range = client_data->master_offset_within_boundary; + jclCurrentState->servo_locked = client_data->servo_state >= SERVO_LOCKED ? true:false; + jclCurrentState->composite_event = composite_client_data->composite_event; + memcpy(jclCurrentState->gmIdentity, client_data->gmIdentity, sizeof(client_data->gmIdentity)); return true; } @@ -147,11 +192,93 @@ PROCESS_MESSAGE_TYPE(ClientSubscribeMessage::processMessage) PrintDebug("[ClientSubscribeMessage]::processMessage (reply)"); - state.set_eventState(this->getClientState()); - state.set_subscribed(true); + //currentClientState->set_eventState(this->getClientState()); // i cannot remember why i put this ? + currentClientState->set_subscribed(true); + /* Add the current ClientState to the notification class */ + ClientNotificationMessage::addClientState(currentClientState); this->set_msgAck(ACK_NONE); + + JClkLibCommon::jcl_state jclCurrentState = currentClientState->get_eventState(); + printf("[ClientSubscribeMessage]::processMessage : state - offset in range = %d, servo_locked = %d gmPresent = %d as_Capable = %d\n", \ + jclCurrentState.offset_in_range, jclCurrentState.servo_locked, jclCurrentState.gm_present, jclCurrentState.as_Capable); cv.notify_one(); return true; } + +/* delete the client ptp event based on session ID given */ +void ClientSubscribeMessage::deleteClientPtpEventStruct(JClkLibCommon::sessionId_t sID) { + + std::map >::iterator it; + JClkLibCommon::client_ptp_event* client_data, *composite_data; + + it = client_ptp_event_map.find(sID); + + if (it != client_ptp_event_map.end()) { + client_data = std::get<0>(it->second); + composite_data = std::get<1>(it->second); + delete client_data; + delete composite_data; + client_ptp_event_map.erase(it); + } + else { + PrintDebug("The item is not found in client_ptp_event_map"); + } +} + +/* get the corresponding ClientPtpEvent */ +JClkLibCommon::client_ptp_event* ClientSubscribeMessage::getClientPtpEventStruct(JClkLibCommon::sessionId_t sID) { + + std::map >::iterator it ; + JClkLibCommon::client_ptp_event* client_data = NULL; + + it = client_ptp_event_map.find(sID); + + if (it != client_ptp_event_map.end()) { + client_data = std::get<0>(it->second);; + } + + return client_data; +} + +/* get the corresponding ClientPtpEvent for composite */ +JClkLibCommon::client_ptp_event* ClientSubscribeMessage::getClientPtpEventCompositeStruct(JClkLibCommon::sessionId_t sID) { + + std::map >::iterator it ; + JClkLibCommon::client_ptp_event* client_data = NULL; + + it = client_ptp_event_map.find(sID); + + if (it != client_ptp_event_map.end()) { + client_data = std::get<1>(it->second); + } + + return client_data; +} + +/* reduce the corresponding eventCount */ +void ClientSubscribeMessage::resetClientPtpEventStruct(JClkLibCommon::sessionId_t sID, JClkLibCommon::jcl_state_event_count &eventCount) { + + std::map >::iterator it ; + JClkLibCommon::client_ptp_event* client_ptp_data = NULL; + + it = client_ptp_event_map.find(sID); + + if (it != client_ptp_event_map.end()) { + client_ptp_data = std::get<0>(it->second); + } + + client_ptp_data->offset_event_count.fetch_sub(eventCount.offset_in_range_event_count, + std::memory_order_relaxed); + client_ptp_data->asCapable_event_count.fetch_sub(eventCount.asCapable_event_count, + std::memory_order_relaxed); + client_ptp_data->servo_state_event_count.fetch_sub(eventCount.servo_locked_event_count, + std::memory_order_relaxed); + client_ptp_data->gmPresent_event_count.fetch_sub(eventCount.gmPresent_event_count, + std::memory_order_relaxed); + client_ptp_data->gmChanged_event_count.fetch_sub(eventCount.gm_changed_event_count, + std::memory_order_relaxed); + + /* TODO : reset the composite data count as well*/ +} \ No newline at end of file diff --git a/jclklib/client/subscribe_msg.hpp b/jclklib/client/subscribe_msg.hpp index dd8ce97d..fd802471 100644 --- a/jclklib/client/subscribe_msg.hpp +++ b/jclklib/client/subscribe_msg.hpp @@ -24,7 +24,13 @@ namespace JClkLibClient virtual public ClientMessage { private: - JClkLibCommon::jcl_state clientState = {}; + JClkLibCommon::jcl_state *jclCurrentState; + ClientState *currentClientState; + //JClkLibCommon::client_ptp_event composite_client_data = {}; + //inline static std::map client_ptp_event_map; + //std::map> map; + inline static std::map > client_ptp_event_map; + public: ClientSubscribeMessage() : MESSAGE_SUBSCRIBE() {}; @@ -54,12 +60,18 @@ namespace JClkLibClient virtual PARSE_RXBUFFER_TYPE(parseBuffer); - void setClientState(JClkLibCommon::jcl_state newState) { - clientState = newState; - } + void setClientState(ClientState *newClientState); + + /* delete the corresponding map pair item */ + static void deleteClientPtpEventStruct(JClkLibCommon::sessionId_t sID); + + /* get the corresponding map pair item */ + static JClkLibCommon::client_ptp_event* getClientPtpEventStruct(JClkLibCommon::sessionId_t sID); + + static JClkLibCommon::client_ptp_event* getClientPtpEventCompositeStruct(JClkLibCommon::sessionId_t sID); - JClkLibCommon::jcl_state &getClientState() - { return clientState; } + /* reduce the corresponding eventCount */ + static void resetClientPtpEventStruct(JClkLibCommon::sessionId_t sID, JClkLibCommon::jcl_state_event_count &eventCount); }; } diff --git a/jclklib/client/test.cpp b/jclklib/client/test.cpp index 1301c58d..bb8184ec 100644 --- a/jclklib/client/test.cpp +++ b/jclklib/client/test.cpp @@ -38,6 +38,10 @@ 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(); + + std::cout << "[CLIENT] Before connect : Session ID : " << + myState.get_sessionId() << "\n"; + + if (cmAPI->jcl_connect() == false) { + std::cout << "[CLIENT] Failure in connecting !!!\n"; + ret = EXIT_FAILURE; + goto do_exit; + } + else { + std::cout << "[CLIENT] Connected. Session ID : " << + myState.get_sessionId() << "\n"; } sleep(1); - JClkLibCommon::jcl_subscription sub = {}; + sub.get_event().writeEvent(event2Sub1, (std::size_t)sizeof(event2Sub1)); sub.get_value().setValue(gmOffsetValue, upper_master_offset, lower_master_offset); @@ -137,10 +155,9 @@ int main(int argc, char *argv[]) std::cout << "Upper Master Offset: " << upper_master_offset << "\n"; std::cout << "Lower Master Offset: " << lower_master_offset << "\n\n"; - JClkLibCommon::jcl_state jcl_state = {}; - if (jcl_subscribe(sub, jcl_state) == false) { + if (cmAPI->jcl_subscribe(sub, jcl_state) == false) { std::cerr << "[jclklib] Failure in subscribing to jclklib Proxy !!!\n"; - jcl_disconnect(); + cmAPI->jcl_disconnect(); return EXIT_FAILURE; } @@ -194,10 +211,9 @@ int main(int argc, char *argv[]) sleep(1); - JClkLibCommon::jcl_state_event_count eventCount = {}; while (!signal_flag) { - if (!jcl_status_wait(timeout, jcl_state , eventCount)) { - printf("[jclklib] No event changes identified in %d seconds.\n\n", + if (!cmAPI->jcl_status_wait(timeout, jcl_state , eventCount)) { + printf("No event status changes identified in %d seconds.\n\n", timeout); sleep(1); continue; @@ -258,7 +274,8 @@ int main(int argc, char *argv[]) sleep(1); } - jcl_disconnect(); +do_exit: + cmAPI->jcl_disconnect(); return EXIT_SUCCESS; } diff --git a/jclklib/common/notification_msg.hpp b/jclklib/common/notification_msg.hpp index 10c722e9..0b22883a 100644 --- a/jclklib/common/notification_msg.hpp +++ b/jclklib/common/notification_msg.hpp @@ -29,16 +29,16 @@ namespace JClkLibCommon virtual TRANSMIT_MESSAGE_TYPE(transmitMessage); static msgId_t getMsgId() { return SUBSCRIBE_MSG; } - const jcl_eventcount &getEventCount(); - const jcl_event &getEvent(); + //const jcl_eventcount &getEventCount(); + //const jcl_event &getEvent(); bool isEnable() { return waitEnable == 0x1; } protected: #define MESSAGE_NOTIFY() JClkLibCommon::Message(JClkLibCommon::NOTIFY_MESSAGE) NotificationMessage() : MESSAGE_NOTIFY() {} private: std::uint32_t waitEnable :1; - jcl_event event; - jcl_eventcount eventCount; + //jcl_event event; + //jcl_eventcount eventCount; }; } From 43ec112f619bea91a18e1a5563bed8c35e9a8053 Mon Sep 17 00:00:00 2001 From: Noor Azura Ahmad Tarmizi Date: Wed, 15 May 2024 12:04:07 -0400 Subject: [PATCH 077/151] client data management: Fix the tuple problem Signed-off-by: Noor Azura Ahmad Tarmizi --- jclklib/client/Makefile | 4 ++-- jclklib/client/connect_msg.cpp | 2 -- jclklib/client/connect_msg.hpp | 2 +- jclklib/client/init.cpp | 2 +- jclklib/client/subscribe_msg.cpp | 35 +++++++++++++++++--------------- jclklib/client/subscribe_msg.hpp | 8 +++----- jclklib/common/message.cpp | 2 +- jclklib/proxy/connect_msg.cpp | 3 +-- 8 files changed, 28 insertions(+), 30 deletions(-) diff --git a/jclklib/client/Makefile b/jclklib/client/Makefile index b85534ae..7cb28625 100644 --- a/jclklib/client/Makefile +++ b/jclklib/client/Makefile @@ -63,10 +63,10 @@ build-all: build-prep jclklib.so: $(OBJ_FILES) $(COMMON_OBJ_FILES) echo "[LINK]" $@ "{" $(call pathof_relative_to,$^,$(JCLKLIB_TOPLEVEL_DIR)) "}" | fold -s - g++ -shared -o $@ $^ $(LIBS_FLAGS) -fdiagnostics-color=always + g++ -g -shared -o $@ $^ $(LIBS_FLAGS) -fdiagnostics-color=always test: test.o jclklib.so - g++ -o test test.o -L $(JCLKLIB_CLIENT_DIR) -l:jclklib.so + g++ -g -o test test.o -L $(JCLKLIB_CLIENT_DIR) -l:jclklib.so %.o : %.cpp echo "[COMPILE]" $< diff --git a/jclklib/client/connect_msg.cpp b/jclklib/client/connect_msg.cpp index 9711cb68..b94da9a3 100644 --- a/jclklib/client/connect_msg.cpp +++ b/jclklib/client/connect_msg.cpp @@ -59,8 +59,6 @@ PARSE_RXBUFFER_TYPE(ClientConnectMessage::parseBuffer) { currentClientState->set_ptp4l_id(data.ptp4l_id); - printf("ptp4l_id = %d\n\n",currentClientState->get_ptp4l_id()); - return true; } diff --git a/jclklib/client/connect_msg.hpp b/jclklib/client/connect_msg.hpp index dd9a3fc4..3c23a847 100644 --- a/jclklib/client/connect_msg.hpp +++ b/jclklib/client/connect_msg.hpp @@ -26,7 +26,7 @@ namespace JClkLibClient virtual public ClientMessage { private: - ClientState *currentClientState; + inline static ClientState *currentClientState; public: ClientConnectMessage() : MESSAGE_CONNECT() {}; diff --git a/jclklib/client/init.cpp b/jclklib/client/init.cpp index 2fd05833..19c75d6a 100644 --- a/jclklib/client/init.cpp +++ b/jclklib/client/init.cpp @@ -47,8 +47,8 @@ bool JClkLibClientApi::jcl_connect() Message0 connectMsg(new ClientConnectMessage()); TransportClientId newClientID; - ClientConnectMessage *cmsg = dynamic_cast(connectMsg.get()); + cmsg->setClientState(&appClientState); //BlockStopSignal(); diff --git a/jclklib/client/subscribe_msg.cpp b/jclklib/client/subscribe_msg.cpp index 51fca0b5..a84d2a57 100644 --- a/jclklib/client/subscribe_msg.cpp +++ b/jclklib/client/subscribe_msg.cpp @@ -91,22 +91,24 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { */ JClkLibCommon::sessionId_t currentSessionID = currentClientState->get_sessionId(); - std::map >::iterator it ; + std::map >::iterator it ; JClkLibCommon::client_ptp_event* client_data , *composite_client_data; it = client_ptp_event_map.find(currentSessionID); if (it == client_ptp_event_map.end()) { /* Creation of a new map item for this new sessionID */ - //client_data = new JClkLibCommon::client_ptp_event(); - //client_composite_data = new JClkLibCommon::client_ptp_event(); - client_ptp_event_map.insert({currentSessionID, \ - std::make_tuple(new JClkLibCommon::client_ptp_event(), new JClkLibCommon::client_ptp_event())}); + client_data = new JClkLibCommon::client_ptp_event(); + composite_client_data = new JClkLibCommon::client_ptp_event(); + + client_ptp_event_map.insert( \ + std::pair>\ + (currentSessionID,{client_data, composite_client_data})); } else { /* Reuse the current client data */ - client_data = std::get<0>(it->second); - composite_client_data = std::get<1>(it->second); + client_data = it->second[0]; + composite_client_data = it->second[1]; } if ((eventSub[0] & 1<master_offset)) { @@ -210,14 +212,15 @@ PROCESS_MESSAGE_TYPE(ClientSubscribeMessage::processMessage) /* delete the client ptp event based on session ID given */ void ClientSubscribeMessage::deleteClientPtpEventStruct(JClkLibCommon::sessionId_t sID) { - std::map >::iterator it; + std::map >::iterator it; JClkLibCommon::client_ptp_event* client_data, *composite_data; it = client_ptp_event_map.find(sID); if (it != client_ptp_event_map.end()) { - client_data = std::get<0>(it->second); - composite_data = std::get<1>(it->second); + client_data = it->second[0]; + composite_data = it->second[1]; + delete client_data; delete composite_data; client_ptp_event_map.erase(it); @@ -230,13 +233,13 @@ void ClientSubscribeMessage::deleteClientPtpEventStruct(JClkLibCommon::sessionId /* get the corresponding ClientPtpEvent */ JClkLibCommon::client_ptp_event* ClientSubscribeMessage::getClientPtpEventStruct(JClkLibCommon::sessionId_t sID) { - std::map >::iterator it ; + std::map >::iterator it ; JClkLibCommon::client_ptp_event* client_data = NULL; it = client_ptp_event_map.find(sID); if (it != client_ptp_event_map.end()) { - client_data = std::get<0>(it->second);; + client_data = it->second[0]; } return client_data; @@ -245,13 +248,13 @@ JClkLibCommon::client_ptp_event* ClientSubscribeMessage::getClientPtpEventStruct /* get the corresponding ClientPtpEvent for composite */ JClkLibCommon::client_ptp_event* ClientSubscribeMessage::getClientPtpEventCompositeStruct(JClkLibCommon::sessionId_t sID) { - std::map >::iterator it ; + std::map >::iterator it ; JClkLibCommon::client_ptp_event* client_data = NULL; it = client_ptp_event_map.find(sID); if (it != client_ptp_event_map.end()) { - client_data = std::get<1>(it->second); + client_data = it->second[1]; } return client_data; @@ -260,13 +263,13 @@ JClkLibCommon::client_ptp_event* ClientSubscribeMessage::getClientPtpEventCompos /* reduce the corresponding eventCount */ void ClientSubscribeMessage::resetClientPtpEventStruct(JClkLibCommon::sessionId_t sID, JClkLibCommon::jcl_state_event_count &eventCount) { - std::map >::iterator it ; + std::map >::iterator it ; JClkLibCommon::client_ptp_event* client_ptp_data = NULL; it = client_ptp_event_map.find(sID); if (it != client_ptp_event_map.end()) { - client_ptp_data = std::get<0>(it->second); + client_ptp_data = it->second[0]; } client_ptp_data->offset_event_count.fetch_sub(eventCount.offset_in_range_event_count, diff --git a/jclklib/client/subscribe_msg.hpp b/jclklib/client/subscribe_msg.hpp index fd802471..d4c6d8d1 100644 --- a/jclklib/client/subscribe_msg.hpp +++ b/jclklib/client/subscribe_msg.hpp @@ -24,12 +24,10 @@ namespace JClkLibClient virtual public ClientMessage { private: - JClkLibCommon::jcl_state *jclCurrentState; - ClientState *currentClientState; + inline static JClkLibCommon::jcl_state *jclCurrentState; + inline static ClientState *currentClientState; //JClkLibCommon::client_ptp_event composite_client_data = {}; - //inline static std::map client_ptp_event_map; - //std::map> map; - inline static std::map > client_ptp_event_map; + inline static std::map > client_ptp_event_map; public: ClientSubscribeMessage() : MESSAGE_SUBSCRIBE() {}; diff --git a/jclklib/common/message.cpp b/jclklib/common/message.cpp index 8ae0f6a9..b084c27b 100644 --- a/jclklib/common/message.cpp +++ b/jclklib/common/message.cpp @@ -77,7 +77,7 @@ COMMON_PRESEND_MESSAGE_TYPE(Message::presendMessage) return false; } DumpOctetArray("Sending message (length = " + to_string(ctx->getc_offset()) + "): ", ctx->getc_buffer().data(), - ctx->getc_offset()); + ctx->getc_offset()); PrintDebug("[Message]::presendMessage successful"); return true; diff --git a/jclklib/proxy/connect_msg.cpp b/jclklib/proxy/connect_msg.cpp index fe60386a..1525f5c0 100644 --- a/jclklib/proxy/connect_msg.cpp +++ b/jclklib/proxy/connect_msg.cpp @@ -77,8 +77,7 @@ PROCESS_MESSAGE_TYPE(ProxyConnectMessage::processMessage) /* check whether there is ptp4l available */ if (!pe.ptp4l_id) { - //return false; - PrintDebug("[AZU_HACK] ptp4l is not available !!! , we continue anyway"); + return false; } newSessionId = Client::CreateClientSession(); From ac5b8298269d0f171464fe0d6cedb3f579716e92 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 16 May 2024 18:15:27 +0800 Subject: [PATCH 078/151] jclklib: reset composite event count after wait API Reset composite event count after user app retrieve it. Signed-off-by: Song Yoong Siang --- jclklib/client/subscribe_msg.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jclklib/client/subscribe_msg.cpp b/jclklib/client/subscribe_msg.cpp index a84d2a57..303e9c13 100644 --- a/jclklib/client/subscribe_msg.cpp +++ b/jclklib/client/subscribe_msg.cpp @@ -282,6 +282,6 @@ void ClientSubscribeMessage::resetClientPtpEventStruct(JClkLibCommon::sessionId_ std::memory_order_relaxed); client_ptp_data->gmChanged_event_count.fetch_sub(eventCount.gm_changed_event_count, std::memory_order_relaxed); - - /* TODO : reset the composite data count as well*/ + client_ptp_data->composite_event_count.fetch_sub(eventCount.composite_event_count, + std::memory_order_relaxed); } \ No newline at end of file From 6ae13790d440b05b631384c4dcb04288739aa8df Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 16 May 2024 22:22:19 +0800 Subject: [PATCH 079/151] jclklib: Add debug print in proxy connect msg Add debug print to indicate ptp4l_id is not ready Signed-off-by: Song Yoong Siang --- jclklib/proxy/connect_msg.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/jclklib/proxy/connect_msg.cpp b/jclklib/proxy/connect_msg.cpp index 1525f5c0..40353b8f 100644 --- a/jclklib/proxy/connect_msg.cpp +++ b/jclklib/proxy/connect_msg.cpp @@ -77,6 +77,7 @@ PROCESS_MESSAGE_TYPE(ProxyConnectMessage::processMessage) /* check whether there is ptp4l available */ if (!pe.ptp4l_id) { + PrintError("ptp4l_id is not available."); return false; } From a2ba8fa7e0a3f9595821d628cff6087ba1587ed7 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 16 May 2024 22:46:10 +0800 Subject: [PATCH 080/151] jclklib: fix ptp4l_id being clear accidentally Clear the member ptp_event one by one, to avoid clear unwanted members. Signed-off-by: Song Yoong Siang --- jclklib/proxy/connect.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/jclklib/proxy/connect.cpp b/jclklib/proxy/connect.cpp index 816657e6..2bf9088c 100644 --- a/jclklib/proxy/connect.cpp +++ b/jclklib/proxy/connect.cpp @@ -114,9 +114,12 @@ void event_handle() pd = (PORT_DATA_SET_t *)data; portState = pd->portState; - //Reset proxy ptp4l event data if port_state <= PASSIVE + //Reset TIME_STATUS_NP data if port_state <= PASSIVE if (portState <= PASSIVE) { - pe = { 0, {0, 0, 0, 0, 0, 0, 0, 0}, 0 , 0 , 0}; + pe.master_offset = 0; + memset(pe.gmIdentity, 0, sizeof(pe.gmIdentity)); + pe.servo_state = 0; + pe.gmPresent = 0; } break; From 31923133ad2c86b4928a106ce110f122210dc55f Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 16 May 2024 23:30:37 +0800 Subject: [PATCH 081/151] jclklib: fix event count dint update properly issue Put the getter of event count in while loop, so that its value reflect immediately. Signed-off-by: Song Yoong Siang --- jclklib/client/init.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/jclklib/client/init.cpp b/jclklib/client/init.cpp index 19c75d6a..14b60214 100644 --- a/jclklib/client/init.cpp +++ b/jclklib/client/init.cpp @@ -206,11 +206,13 @@ int JClkLibClientApi::jcl_status_wait(int timeout, JClkLibCommon::jcl_state &jcl start + std::chrono::seconds(timeout); bool event_changes_detected = false; - /* Get the event state and event count from the API*/ - JClkLibCommon::jcl_state_event_count eventCount = appClientState.get_eventStateCount(); - JClkLibCommon::jcl_state jcl_state = appClientState.get_eventState(); - + JClkLibCommon::jcl_state_event_count eventCount; + JClkLibCommon::jcl_state jcl_state; do { + /* Get the event state and event count from the API*/ + eventCount = appClientState.get_eventStateCount(); + jcl_state = appClientState.get_eventState(); + /* Check if any member of eventCount is non-zero */ if (eventCount.offset_in_range_event_count || eventCount.asCapable_event_count || From 611b14ec6953500d0851210ab9d4a6dfeb940de9 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Fri, 17 May 2024 16:14:22 +0800 Subject: [PATCH 082/151] jclklib: fix event count issue for composite event Fix unnnessary increment of event count Signed-off-by: Song Yoong Siang --- jclklib/client/notification_msg.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jclklib/client/notification_msg.cpp b/jclklib/client/notification_msg.cpp index f295a525..cc371214 100644 --- a/jclklib/client/notification_msg.cpp +++ b/jclklib/client/notification_msg.cpp @@ -159,7 +159,7 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) composite_client_ptp_data->composite_event = true; } - if ((composite_eventSub[0] & 1<master_offset)) { + if (composite_eventSub[0] & 1<master_offset = proxy_data.master_offset; if ((composite_client_ptp_data->master_offset > currentClientState->get_eventSub().get_value().getLower(gmOffsetValue)) && (composite_client_ptp_data->master_offset < currentClientState->get_eventSub().get_value().getUpper(gmOffsetValue))) { From 1984decc79924b99daeb488ea7f55afe325587b3 Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Mon, 20 May 2024 09:46:04 +0800 Subject: [PATCH 083/151] jclklib: Fix coverity scan issue Signed-off-by: Lai Peter Jun Ann --- jclklib/client/client_state.cpp | 5 +- jclklib/client/client_state.hpp | 2 +- jclklib/client/connect_msg.cpp | 2 +- jclklib/client/init.cpp | 8 +- jclklib/common/Makefile | 3 +- jclklib/common/jclklib_import.cpp | 5 + jclklib/common/msgq_tport.cpp | 1 + jclklib/common/mutex_signal.cpp | 215 ---------------------------- jclklib/common/mutex_signal.hpp | 63 -------- jclklib/common/notification_msg.hpp | 2 +- jclklib/common/subscribe_msg.cpp | 2 +- jclklib/common/subscribe_msg.hpp | 2 +- jclklib/common/transport.hpp | 2 +- jclklib/common/util.hpp | 2 - jclklib/proxy/connect.cpp | 14 +- jclklib/proxy/thread.cpp | 16 +-- jclklib/proxy/thread.hpp | 5 +- pub/init.h | 4 +- 18 files changed, 34 insertions(+), 319 deletions(-) delete mode 100644 jclklib/common/mutex_signal.cpp delete mode 100644 jclklib/common/mutex_signal.hpp diff --git a/jclklib/client/client_state.cpp b/jclklib/client/client_state.cpp index 0465cdb3..92ed1d44 100644 --- a/jclklib/client/client_state.cpp +++ b/jclklib/client/client_state.cpp @@ -31,6 +31,9 @@ ClientState::ClientState() subscribed = false; sessionId = JClkLibCommon::InvalidSessionId; fill(begin(clientID ), end( clientID ), 0 ); + eventState = {}; + eventStateCount = {}; + eventSub = {}; } ClientState::ClientState(ClientState &newState) @@ -67,7 +70,7 @@ TransportClientId ClientState::get_clientID() { return clientID; } -void ClientState::set_clientID(TransportClientId new_cID) { +void ClientState::set_clientID(TransportClientId &new_cID) { strcpy((char *)clientID.data(), (char *)new_cID.data()); } diff --git a/jclklib/client/client_state.hpp b/jclklib/client/client_state.hpp index 63500a5d..0bceb080 100644 --- a/jclklib/client/client_state.hpp +++ b/jclklib/client/client_state.hpp @@ -43,7 +43,7 @@ namespace JClkLibClient { bool get_subscribed(); void set_subscribed(bool subscriptionState); JClkLibCommon::TransportClientId get_clientID(); - void set_clientID(JClkLibCommon::TransportClientId cID); + void set_clientID(JClkLibCommon::TransportClientId &cID); JClkLibCommon::jcl_state_event_count &get_eventStateCount(); JClkLibCommon::jcl_state &get_eventState(); void set_eventStateCount(JClkLibCommon::jcl_state_event_count eCount); diff --git a/jclklib/client/connect_msg.cpp b/jclklib/client/connect_msg.cpp index b94da9a3..4ae4ce10 100644 --- a/jclklib/client/connect_msg.cpp +++ b/jclklib/client/connect_msg.cpp @@ -48,7 +48,7 @@ bool ClientConnectMessage::initMessage() } PARSE_RXBUFFER_TYPE(ClientConnectMessage::parseBuffer) { - JClkLibCommon::ptp_event data; + JClkLibCommon::ptp_event data = {}; PrintDebug("[ClientConnectMessage]::parseBuffer "); if(!CommonConnectMessage::parseBuffer(LxContext)) diff --git a/jclklib/client/init.cpp b/jclklib/client/init.cpp index 14b60214..85168105 100644 --- a/jclklib/client/init.cpp +++ b/jclklib/client/init.cpp @@ -81,10 +81,12 @@ bool JClkLibClientApi::jcl_connect() } } - //ClientConnectMessage *cmsg = dynamic_cast(connectMsg.get()); - strcpy((char *)newClientID.data(), (char *)cmsg->getClientId().data()); + if ((cmsg != nullptr) && !(cmsg->getClientId().empty())) { + //ClientConnectMessage *cmsg = dynamic_cast(connectMsg.get()); + strcpy((char *)newClientID.data(), (char *)cmsg->getClientId().data()); - appClientState.set_clientID(newClientID); + appClientState.set_clientID(newClientID); + } return true; } diff --git a/jclklib/common/Makefile b/jclklib/common/Makefile index 942416ad..7500cf2b 100644 --- a/jclklib/common/Makefile +++ b/jclklib/common/Makefile @@ -13,8 +13,7 @@ JCLKLIB_COMMON_DIR := $(shell pwd) JCLKLIB_TOPLEVEL_DIR := $(JCLKLIB_COMMON_DIR)/.. LIBS = pthread rt LIBS_FLAGS = $(foreach lib,$(LIBS),-l$(lib)) -OBJ = jclklib_import message msgq_tport notification_msg null_msg connect_msg print sighandler subscribe_msg transport\ - mutex_signal +OBJ = jclklib_import message msgq_tport notification_msg null_msg connect_msg print sighandler subscribe_msg transport OBJ_FILES = $(foreach f,$(OBJ),$(f).o) DEPENDS = $(foreach f,$(OBJ),$(f).d) OBJ_DIR = $(JCLKLIB_COMMON_DIR)/obj diff --git a/jclklib/common/jclklib_import.cpp b/jclklib/common/jclklib_import.cpp index 9d6898da..d670991f 100644 --- a/jclklib/common/jclklib_import.cpp +++ b/jclklib/common/jclklib_import.cpp @@ -118,6 +118,11 @@ int8_t jcl_event::copyEventMask(jcl_event &newEvent) { std::size_t newEventLength = sizeof(newEvent.getEventMask()); + if (sizeof(event_mask) < newEventLength) { + PrintDebug("jcl_event::copyEventMask failure"); + return -1; + } + memcpy(event_mask, newEvent.event_mask , newEventLength); return 0; diff --git a/jclklib/common/msgq_tport.cpp b/jclklib/common/msgq_tport.cpp index e90a45aa..00690e20 100644 --- a/jclklib/common/msgq_tport.cpp +++ b/jclklib/common/msgq_tport.cpp @@ -69,6 +69,7 @@ bool MessageQueue::MqListenerWork(TransportContext *mqListenerContext) if(!context) { PrintError("Internal Error: Received inappropriate context"); + return false; // Return early since context is null and cannot be used. } if (context->init() && !EnableSyscallInterruptSignal()) { PrintError("Unable to enable interrupts in work process context"); diff --git a/jclklib/common/mutex_signal.cpp b/jclklib/common/mutex_signal.cpp deleted file mode 100644 index 561053af..00000000 --- a/jclklib/common/mutex_signal.cpp +++ /dev/null @@ -1,215 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. - */ - -/** @file mutex_signal.cpp - * @brief Common pthread mutex implementation. - * - * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later - * - */ - -#include - -#include -#include - -using namespace std; -using namespace mutex_signal_test; - -#define NSEC_PER_SEC (1000000000) - -#define PTHREAD_CALL(func,err_msg,retval,...) \ - ({ \ - int err; \ - if ((err = (func)) != 0 __VA_OPT__(&& err !=) __VA_ARGS__) { \ - cerr << string(err_msg) + " " + strerror(err) + "\n"; \ - return retval; \ - } \ - (err == 0); \ - }) - -mutex_signal::mutex_signal() -{ - update_available = false; - consumer_locked = false; - producer_locked = false; -} - -bool mutex_signal::init() -{ - pthread_mutexattr_t attr; - - PTHREAD_CALL(pthread_mutexattr_init(&attr), "Failed to initialize mutex attribute", false); - PTHREAD_CALL(pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT), "Failed to set priority inheritance", false); - PTHREAD_CALL(pthread_mutex_init(&p_lock, &attr), "Failed to initialize producer mutex", false); - PTHREAD_CALL(pthread_mutex_init(&c_lock, &attr), "Failed to initialize consumer mutex", false); - PTHREAD_CALL(pthread_mutex_init(&d_lock, NULL), "Failed to initialize data mutex", false); - PTHREAD_CALL(pthread_mutexattr_destroy(&attr), "Failed to cleanup mutex attribute", false); - - return true; -} - -mutex_signal::~mutex_signal() -{ - PTHREAD_CALL(pthread_mutex_destroy(&d_lock), "Failed to cleanup data mutex",); -} - -bool mutex_signal::consumerTryLock(bool &success) -{ - success = PTHREAD_CALL(pthread_mutex_trylock(&c_lock), "Failed to lock consumer lock", false, EBUSY); - return true; -} -bool mutex_signal::consumerLock() -{ - PTHREAD_CALL(pthread_mutex_lock(&c_lock), "Failed to lock consumer lock", false); - return true; -} -bool mutex_signal::consumerUnlock() -{ - PTHREAD_CALL(pthread_mutex_unlock(&c_lock), "Failed to unlock consumer lock", false); - return true; -} - -bool mutex_signal::producerTryLock(bool &success) -{ - success = PTHREAD_CALL(pthread_mutex_trylock(&p_lock), "Failed to lock producer lock", false, EBUSY); - return true; -} -bool mutex_signal::producerTimedLock(bool &success, chrono::time_point wait_until) -{ - struct timespec wait_until_ts; - wait_until_ts.tv_sec = chrono::duration_cast(wait_until.time_since_epoch()).count() / NSEC_PER_SEC; - wait_until_ts.tv_nsec = chrono::duration_cast(wait_until.time_since_epoch()).count() % NSEC_PER_SEC; - - success = PTHREAD_CALL(pthread_mutex_timedlock(&p_lock, &wait_until_ts),"Failed to lock producer lock", false, ETIMEDOUT); - - return true; -} -bool mutex_signal::producerLock() -{ - PTHREAD_CALL(pthread_mutex_lock(&p_lock), "Failed to lock producer lock", false); - return true; -} -bool mutex_signal::producerUnlock() -{ - PTHREAD_CALL(pthread_mutex_unlock(&p_lock), "Failed to unlock producer lock", false); - return true; -} - -bool mutex_signal::dataTryLock(bool &success) -{ - success = PTHREAD_CALL(pthread_mutex_trylock(&d_lock), "Failed to lock data lock", false, EBUSY); - return true; -} -bool mutex_signal::dataTimedLock(bool &success, chrono::time_point wait_until) -{ - struct timespec wait_until_ts; - wait_until_ts.tv_sec = chrono::duration_cast(wait_until.time_since_epoch()).count() / NSEC_PER_SEC; - wait_until_ts.tv_nsec = chrono::duration_cast(wait_until.time_since_epoch()).count() % NSEC_PER_SEC; - success = PTHREAD_CALL(pthread_mutex_timedlock(&d_lock, &wait_until_ts),"Failed to lock data lock", false, ETIMEDOUT); - - return true; -} -bool mutex_signal::dataLock() -{ - PTHREAD_CALL(pthread_mutex_lock(&d_lock), "Failed to lock data lock", false); - return true; -} -bool mutex_signal::dataUnlock() -{ - PTHREAD_CALL(pthread_mutex_unlock(&d_lock), "Failed to unlock data lock", false); - return true; -} - -bool mutex_signal::preProduce() -{ - if (!dataLock()) - return false; - - producer_locked = true; - return true; -} -bool mutex_signal::postProduce() -{ - bool producer_c_lock; - if (!producer_locked) - return false; - update_available = true; - if (!dataUnlock() || !consumerTryLock(producer_c_lock)) - return false; - if (producer_c_lock && (!producerUnlock() || !consumerUnlock() || !producerLock())) - return false; - - producer_locked = false; - return true; -} - -bool mutex_signal::preConsume(bool &success, chrono::duration wait_for) -{ - auto wait_until = chrono::system_clock::now() + wait_for; - bool consumer_p_lock; - - if (!dataTimedLock(success, wait_until)) - return false; - consumer_locked = success && update_available; - if (!success || consumer_locked) - return true; - - success = false; - if (!consumerUnlock() || !dataUnlock() || !producerTimedLock(consumer_p_lock, wait_until) || !consumerLock()) - return false; - if (!consumer_p_lock) - return true; - if (!dataTimedLock(success, wait_until)) - return false; - if (consumer_p_lock && !producerUnlock()) - return false; - - if (success && !update_available && !dataUnlock()) - return false; - success = consumer_locked = success && update_available; - - return true; -} - -bool mutex_signal::postConsume() -{ - if (!consumer_locked) - return false; - update_available = false; - if(!dataUnlock()) - return false; - - consumer_locked = false; - return true; -} - -bool mutex_signal::producerInit() -{ - return producerLock(); -} - -bool mutex_signal::producerCleanup() -{ - if (producer_locked && !postProduce()) - return false; - - return producerUnlock(); -} - -bool mutex_signal::consumerInit() -{ - return consumerLock(); -} - -bool mutex_signal::consumerCleanup() -{ - if (consumer_locked && !postConsume()) - return false; - - return consumerUnlock(); -} diff --git a/jclklib/common/mutex_signal.hpp b/jclklib/common/mutex_signal.hpp deleted file mode 100644 index 3000488e..00000000 --- a/jclklib/common/mutex_signal.hpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. - */ - -/** @file mutex_signal.hpp - * @brief Common pthread mutex implementation. - * - * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later - * - */ - -#include -#include - -#ifndef MUTEX_SIGNAL_HPP -#define MUTEX_SIGNAL_HPP - -namespace mutex_signal_test { - class mutex_signal - { - private: - pthread_mutex_t p_lock; - pthread_mutex_t c_lock; - pthread_mutex_t d_lock; - bool update_available; - - bool consumer_locked; - bool producer_locked; - - bool consumerTryLock(bool &success); - bool consumerLock(); - bool consumerUnlock(); - - bool producerTryLock(bool &success); - bool producerTimedLock(bool &success, std::chrono::time_point wait_until); - bool producerLock(); - bool producerUnlock(); - - bool dataTryLock(bool &success); - bool dataTimedLock(bool &success, std::chrono::time_point wait_until); - bool dataLock(); - bool dataUnlock(); - public: - mutex_signal(); - ~mutex_signal(); - bool init(); - - bool producerInit(); - bool producerCleanup(); - bool preProduce(); - bool postProduce(); - - bool consumerInit(); - bool consumerCleanup(); - bool preConsume(bool &success, std::chrono::duration wait_until); - bool postConsume(); - }; -} - -#endif/*MUTEX_SIGNAL_HPP*/ diff --git a/jclklib/common/notification_msg.hpp b/jclklib/common/notification_msg.hpp index 0b22883a..a80ae432 100644 --- a/jclklib/common/notification_msg.hpp +++ b/jclklib/common/notification_msg.hpp @@ -34,7 +34,7 @@ namespace JClkLibCommon bool isEnable() { return waitEnable == 0x1; } protected: #define MESSAGE_NOTIFY() JClkLibCommon::Message(JClkLibCommon::NOTIFY_MESSAGE) - NotificationMessage() : MESSAGE_NOTIFY() {} + NotificationMessage() : MESSAGE_NOTIFY() , waitEnable(0) {} private: std::uint32_t waitEnable :1; //jcl_event event; diff --git a/jclklib/common/subscribe_msg.cpp b/jclklib/common/subscribe_msg.cpp index b59d33d3..158fab5d 100644 --- a/jclklib/common/subscribe_msg.cpp +++ b/jclklib/common/subscribe_msg.cpp @@ -71,6 +71,6 @@ TRANSMIT_MESSAGE_TYPE(CommonSubscribeMessage::transmitMessage) return TxContext.sendBuffer(); } -void setSubscription(jcl_subscription newsub) { +void setSubscription(jcl_subscription &newsub) { PrintDebug("[CommonSubscribeMessage]::setSubscription "); } diff --git a/jclklib/common/subscribe_msg.hpp b/jclklib/common/subscribe_msg.hpp index fabee0d4..b13215e5 100644 --- a/jclklib/common/subscribe_msg.hpp +++ b/jclklib/common/subscribe_msg.hpp @@ -37,7 +37,7 @@ namespace JClkLibCommon { return subscription; } TransportClientId &getClientId() { return clientId; } - void setSubscription(jcl_subscription newsub); + void setSubscription(jcl_subscription &newsub); virtual std::string toString(); protected: diff --git a/jclklib/common/transport.hpp b/jclklib/common/transport.hpp index 5d645d48..66f180e3 100644 --- a/jclklib/common/transport.hpp +++ b/jclklib/common/transport.hpp @@ -39,7 +39,7 @@ namespace JClkLibCommon TransportBuffer buffer; public: bool init() { return _init; } - TransportContext() { _init = true; } + TransportContext() : _init(true), offset(0) {} virtual ~TransportContext() = default; DECLARE_ACCESSOR(offset); DECLARE_ACCESSOR(buffer); diff --git a/jclklib/common/util.hpp b/jclklib/common/util.hpp index 9a4b0988..d1f86272 100644 --- a/jclklib/common/util.hpp +++ b/jclklib/common/util.hpp @@ -18,8 +18,6 @@ #ifndef UTIL_HPP #define UTIL_HPP -#include - #define UNIQUE_TYPEOF(x) remove_reference::type #define FUTURE_TYPEOF(x) decltype((x).get()) #define DECLARE_STATIC(x,...) decltype(x) x __VA_OPT__({) __VA_ARGS__ __VA_OPT__(}) diff --git a/jclklib/proxy/connect.cpp b/jclklib/proxy/connect.cpp index 2bf9088c..1c48b3ef 100644 --- a/jclklib/proxy/connect.cpp +++ b/jclklib/proxy/connect.cpp @@ -273,11 +273,6 @@ void *ptp4l_event_loop( void *arg) */ int Connect::connect() { - // Ensure we recieve reply from local ptp daemon - MsgParams prms = msg.getParams(); - prms.boundaryHops = 0; - - std::unique_ptr m_sk; std::string uds_address; SockUnix *sku = new SockUnix; @@ -297,15 +292,9 @@ int Connect::connect() if(!sku->setDefSelfAddress() || !sku->init() || !sku->setPeerAddress(uds_address)) return -1; - pid_t pid = getpid(); - prms.self_id.clockIdentity.v[6] = (pid >> 24) && 0xff; - prms.self_id.clockIdentity.v[7] = (pid >> 16) && 0xff; - prms.self_id.portNumber = pid & 0xffff; sk = m_sk.get(); - msgu.updateParams(prms); - int ret; epd = epoll_create1( 0); if( epd == -1) @@ -316,8 +305,7 @@ int Connect::connect() if( epoll_ctl( epd, EPOLL_CTL_ADD, sk->fileno(), &epd_event) == 1) ret = -errno; - //TODO: subscription part - handle_connect( NULL, epd_event); + handle_connect(epd_event); while (1) { sleep(1); } diff --git a/jclklib/proxy/thread.cpp b/jclklib/proxy/thread.cpp index cbf92143..bb284e04 100644 --- a/jclklib/proxy/thread.cpp +++ b/jclklib/proxy/thread.cpp @@ -67,21 +67,14 @@ int set_thread_signal( struct thread_signal *signal) static bool state_update_callback( struct ptp4l_state *state, void * ctx) { struct jcl_handle *handle = (typeof(handle)) ctx; - bool generate_signal = false; int ret; if(( ret = -pthread_mutex_lock( &handle->state_lock)) < 0) goto lock_failed; - generate_signal = handle->ptp4l_state_initialized ? generate_signal : false; - handle->ptp4l_state_initialized = state->initialized; - if(( ret = -pthread_mutex_unlock( &handle->state_lock)) < 0) goto unlock_failed; - if( generate_signal) - set_thread_signal( handle->status_signal); - unlock_failed: lock_failed: return ret >= 0 ? true : false; @@ -101,7 +94,7 @@ static bool state_update_callback( struct ptp4l_state *state, void * ctx) * Returns 0 on success, or a negative error code on failure. * */ -int handle_connect( struct jcl_handle **phandle, struct epoll_event epd_event ) +int handle_connect(struct epoll_event epd_event ) { struct jcl_handle *handle; int ret; @@ -114,9 +107,14 @@ int handle_connect( struct jcl_handle **phandle, struct epoll_event epd_event ) event_subscription( &handle ); - connect_ptp4l( &handle->ptp4l_handle, + ret = connect_ptp4l( &handle->ptp4l_handle, epd_event, state_update_callback, handle); + if (ret != 0) { + free(handle); // Free the memory if connect_ptp4l fails + goto alloc_fail; + } + free(handle); return 0; alloc_fail: diff --git a/jclklib/proxy/thread.hpp b/jclklib/proxy/thread.hpp index 14131acd..3c20af1e 100644 --- a/jclklib/proxy/thread.hpp +++ b/jclklib/proxy/thread.hpp @@ -42,7 +42,6 @@ struct thread_signal { struct jcl_handle { ptp4l_handle_t ptp4l_handle; - bool ptp4l_state_initialized; thread_signal_t status_signal; pthread_mutex_t state_lock; struct JClkLibCommon::jcl_state state; @@ -64,8 +63,8 @@ struct ptp4l_state { bool servo_locked; }; -int handle_connect( jcl_handle_t *handle, struct epoll_event epd_event ); -int connect_ptp4l( ptp4l_handle_t *phandle, struct epoll_event epd_event, state_update_t update, void *ctx); +int handle_connect(struct epoll_event epd_event ); +int connect_ptp4l(ptp4l_handle_t *phandle, struct epoll_event epd_event, state_update_t update, void *ctx); void *ptp4l_event_loop(void *arg); bool event_subscription(struct jcl_handle **handle); diff --git a/pub/init.h b/pub/init.h index 2392219f..09a8e300 100644 --- a/pub/init.h +++ b/pub/init.h @@ -29,8 +29,8 @@ class Init ConfigFile m_cfg; Message m_msg; std::unique_ptr m_sk; - char m_net_select; - bool m_use_uds; + char m_net_select = 0; + bool m_use_uds = false; public: /** From 0b6b5cca847733951bdb56b914587d02fb6f9d2b Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Mon, 20 May 2024 10:34:51 +0800 Subject: [PATCH 084/151] jclklib: Remove gm_present event Signed-off-by: Lai Peter Jun Ann --- jclklib/client/client_state.cpp | 1 - jclklib/client/init.cpp | 5 ++--- jclklib/client/notification_msg.cpp | 11 +---------- jclklib/client/subscribe_msg.cpp | 17 +++++------------ jclklib/client/test.cpp | 15 +++------------ jclklib/common/jclklib_import.hpp | 7 +------ jclklib/proxy/connect.cpp | 4 +--- jclklib/proxy/thread.hpp | 1 - 8 files changed, 13 insertions(+), 48 deletions(-) diff --git a/jclklib/client/client_state.cpp b/jclklib/client/client_state.cpp index 92ed1d44..119d77d6 100644 --- a/jclklib/client/client_state.cpp +++ b/jclklib/client/client_state.cpp @@ -93,7 +93,6 @@ string ClientState::toString() { string name = "[ClientState::eventState]"; name += " as_Capable = " + to_string(this->get_eventState().as_Capable); name += " gm_changed = " + to_string(this->get_eventState().gm_changed); - name += " gm_present = " + to_string(this->get_eventState().gm_present); name += " offset_in_range = " + to_string(this->get_eventState().offset_in_range); name += " servo_locked = " + to_string(this->get_eventState().servo_locked); name += "\n"; diff --git a/jclklib/client/init.cpp b/jclklib/client/init.cpp index 85168105..87a6d138 100644 --- a/jclklib/client/init.cpp +++ b/jclklib/client/init.cpp @@ -145,9 +145,9 @@ bool JClkLibClientApi::jcl_subscribe(JClkLibCommon::jcl_subscription &newSub, JClkLibCommon::jcl_state jclCurrentState = appClientState.get_eventState(); printf("[JClkLibClient]::subscribe : state - \n"); - printf ("offset_in_range = %d, servo_locked = %d gmPresent = %d as_Capable = %d gm_Changed = %d\n", \ + printf ("offset_in_range = %d, servo_locked = %d, as_Capable = %d gm_Changed = %d\n", \ jclCurrentState.offset_in_range, jclCurrentState.servo_locked,\ - jclCurrentState.gm_present, jclCurrentState.as_Capable, jclCurrentState.gm_changed); + jclCurrentState.as_Capable, jclCurrentState.gm_changed); printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x \n", jclCurrentState.gmIdentity[0], jclCurrentState.gmIdentity[1],jclCurrentState.gmIdentity[2], jclCurrentState.gmIdentity[3], jclCurrentState.gmIdentity[4], @@ -219,7 +219,6 @@ int JClkLibClientApi::jcl_status_wait(int timeout, JClkLibCommon::jcl_state &jcl if (eventCount.offset_in_range_event_count || eventCount.asCapable_event_count || eventCount.servo_locked_event_count || - eventCount.gmPresent_event_count || eventCount.composite_event_count || eventCount.gm_changed_event_count) { event_changes_detected = true; diff --git a/jclklib/client/notification_msg.cpp b/jclklib/client/notification_msg.cpp index cc371214..58032116 100644 --- a/jclklib/client/notification_msg.cpp +++ b/jclklib/client/notification_msg.cpp @@ -149,11 +149,6 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) client_ptp_data->asCapable_event_count.fetch_add(1, std::memory_order_relaxed); } - if ((eventSub[0] & 1<gmPresent)) { - client_ptp_data->gmPresent = proxy_data.gmPresent; - client_ptp_data->gmPresent_event_count.fetch_add(1, std::memory_order_relaxed); - } - if (composite_eventSub[0]) { old_composite_event = composite_client_ptp_data->composite_event; composite_client_ptp_data->composite_event = true; @@ -183,7 +178,6 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) } /* - jclCurrentState.gm_present = client_ptp_data.gmPresent > 0 ? true:false; jclCurrentState.as_Capable = client_ptp_data.asCapable > 0 ? true:false; jclCurrentState.offset_in_range = client_ptp_data.master_offset_within_boundary; jclCurrentState.servo_locked = client_ptp_data.servo_state >= SERVO_LOCKED ? true:false; @@ -193,7 +187,6 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) /* TODO : checked for jclCurrentState.gm_changed based on GM_identity previously stored */ /* - jclCurrentEventCount.gmPresent_event_count = client_ptp_data.gmPresent_event_count; jclCurrentEventCount.offset_in_range_event_count = client_ptp_data.offset_event_count; jclCurrentEventCount.asCapable_event_count = client_ptp_data.asCapable_event_count; jclCurrentEventCount.servo_locked_event_count = client_ptp_data.servo_state_event_count; @@ -204,7 +197,6 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) //state.set_eventState (jclCurrentState); //state.set_eventStateCount (jclCurrentEventCount); - jclCurrentState.gm_present = client_ptp_data->gmPresent > 0 ? true:false; jclCurrentState.as_Capable = client_ptp_data->asCapable > 0 ? true:false; jclCurrentState.offset_in_range = client_ptp_data->master_offset_within_boundary; jclCurrentState.servo_locked = client_ptp_data->servo_state >= SERVO_LOCKED ? true:false; @@ -213,7 +205,6 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) /* TODO : checked for jclCurrentState.gm_changed based on GM_identity previously stored */ - jclCurrentEventCount.gmPresent_event_count = client_ptp_data->gmPresent_event_count; jclCurrentEventCount.offset_in_range_event_count = client_ptp_data->offset_event_count; jclCurrentEventCount.asCapable_event_count = client_ptp_data->asCapable_event_count; jclCurrentEventCount.servo_locked_event_count = client_ptp_data->servo_state_event_count; @@ -235,4 +226,4 @@ PARSE_RXBUFFER_TYPE(ClientNotificationMessage::parseBuffer) return false; return true; -} \ No newline at end of file +} diff --git a/jclklib/client/subscribe_msg.cpp b/jclklib/client/subscribe_msg.cpp index 303e9c13..c4ca8425 100644 --- a/jclklib/client/subscribe_msg.cpp +++ b/jclklib/client/subscribe_msg.cpp @@ -78,7 +78,7 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { if (!PARSE_RX(FIELD, data, LxContext)) return false; - printf("master_offset = %ld, servo_state = %d gmPresent = %d\n", data.master_offset, data.servo_state, data.gmPresent); + printf("master_offset = %ld, servo_state = %d\n", data.master_offset, data.servo_state); printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x ", data.gmIdentity[0], data.gmIdentity[1],data.gmIdentity[2], data.gmIdentity[3], data.gmIdentity[4], @@ -132,10 +132,6 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { client_data->asCapable = data.asCapable; } - if ((eventSub[0] & 1<gmPresent)) { - client_data->gmPresent = data.gmPresent; - } - if (composite_eventSub[0]) { composite_client_data->composite_event = true; } @@ -158,15 +154,14 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { composite_client_data->composite_event &= data.asCapable > 0 ? true:false; } - printf("CLIENT master_offset = %ld, servo_state = %d gmPresent = %d\n", client_data->master_offset, \ - client_data->servo_state, client_data->gmPresent); + printf("CLIENT master_offset = %ld, servo_state = %d\n", client_data->master_offset, \ + client_data->servo_state); printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x ", client_data->gmIdentity[0], client_data->gmIdentity[1],client_data->gmIdentity[2], client_data->gmIdentity[3], client_data->gmIdentity[4], client_data->gmIdentity[5], client_data->gmIdentity[6],client_data->gmIdentity[7]); printf("asCapable = %d\n\n", client_data->asCapable); - jclCurrentState->gm_present = client_data->gmPresent > 0 ? true:false; jclCurrentState->as_Capable = client_data->asCapable > 0 ? true:false; jclCurrentState->offset_in_range = client_data->master_offset_within_boundary; jclCurrentState->servo_locked = client_data->servo_state >= SERVO_LOCKED ? true:false; @@ -202,8 +197,8 @@ PROCESS_MESSAGE_TYPE(ClientSubscribeMessage::processMessage) this->set_msgAck(ACK_NONE); JClkLibCommon::jcl_state jclCurrentState = currentClientState->get_eventState(); - printf("[ClientSubscribeMessage]::processMessage : state - offset in range = %d, servo_locked = %d gmPresent = %d as_Capable = %d\n", \ - jclCurrentState.offset_in_range, jclCurrentState.servo_locked, jclCurrentState.gm_present, jclCurrentState.as_Capable); + printf("[ClientSubscribeMessage]::processMessage : state - offset in range = %d, servo_locked = %d as_Capable = %d\n", \ + jclCurrentState.offset_in_range, jclCurrentState.servo_locked, jclCurrentState.as_Capable); cv.notify_one(); return true; @@ -278,8 +273,6 @@ void ClientSubscribeMessage::resetClientPtpEventStruct(JClkLibCommon::sessionId_ std::memory_order_relaxed); client_ptp_data->servo_state_event_count.fetch_sub(eventCount.servo_locked_event_count, std::memory_order_relaxed); - client_ptp_data->gmPresent_event_count.fetch_sub(eventCount.gmPresent_event_count, - std::memory_order_relaxed); client_ptp_data->gmChanged_event_count.fetch_sub(eventCount.gm_changed_event_count, std::memory_order_relaxed); client_ptp_data->composite_event_count.fetch_sub(eventCount.composite_event_count, diff --git a/jclklib/client/test.cpp b/jclklib/client/test.cpp index bb8184ec..2e7bc479 100644 --- a/jclklib/client/test.cpp +++ b/jclklib/client/test.cpp @@ -45,7 +45,7 @@ int main(int argc, char *argv[]) std::uint32_t event2Sub1[1] = { ((1< offset_event_count{}; std::atomic asCapable_event_count{}; std::atomic servo_state_event_count{}; - std::atomic gmPresent_event_count{}; std::atomic gmChanged_event_count{}; std::atomic composite_event_count{}; }; @@ -181,7 +178,6 @@ enum servoState_e { struct jcl_state { bool as_Capable; - bool gm_present; bool offset_in_range; bool servo_locked; bool gm_changed; @@ -191,7 +187,6 @@ enum servoState_e { struct jcl_state_event_count { - uint64_t gmPresent_event_count; uint64_t offset_in_range_event_count; uint64_t gm_changed_event_count; uint64_t asCapable_event_count; diff --git a/jclklib/proxy/connect.cpp b/jclklib/proxy/connect.cpp index 1c48b3ef..741112e9 100644 --- a/jclklib/proxy/connect.cpp +++ b/jclklib/proxy/connect.cpp @@ -98,13 +98,12 @@ void event_handle() offset = ((TIME_STATUS_NP_t *)data)->master_offset; servo = ((TIME_STATUS_NP_t *)data)->servo_state; gm_uuid = ((TIME_STATUS_NP_t *)data)->gmIdentity; - pe.gmPresent = ((TIME_STATUS_NP_t *)data)->gmPresent; pe.master_offset = offset; pe.servo_state = servo; memcpy(pe.gmIdentity, gm_uuid.v, sizeof(pe.gmIdentity)); //TODO: Add debug flag checking, only print if the flag is set - printf("master_offset = %ld, servo_state = %d gmPresent = %d\n", pe.master_offset, pe.servo_state, pe.gmPresent); + printf("master_offset = %ld, servo_state = %d\n", pe.master_offset, pe.servo_state); printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x\n\n", pe.gmIdentity[0], pe.gmIdentity[1],pe.gmIdentity[2], pe.gmIdentity[3], pe.gmIdentity[4], @@ -119,7 +118,6 @@ void event_handle() pe.master_offset = 0; memset(pe.gmIdentity, 0, sizeof(pe.gmIdentity)); pe.servo_state = 0; - pe.gmPresent = 0; } break; diff --git a/jclklib/proxy/thread.hpp b/jclklib/proxy/thread.hpp index 3c20af1e..ef116dd5 100644 --- a/jclklib/proxy/thread.hpp +++ b/jclklib/proxy/thread.hpp @@ -59,7 +59,6 @@ struct ptp4l_state { unsigned valid_mask; bool peer_present; unsigned offset; - bool gm_present; bool servo_locked; }; From 79c11fc6e8cd7bebe1d37660128b973d04deef0a Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Mon, 20 May 2024 10:59:11 +0800 Subject: [PATCH 085/151] jclklib: Fix unintialized scalar variable Signed-off-by: Lai Peter Jun Ann --- src/proc.m4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/proc.m4 b/src/proc.m4 index 9b3c5ce7..14b715cc 100644 --- a/src/proc.m4 +++ b/src/proc.m4 @@ -493,7 +493,7 @@ strc(SUBSCRIBE_EVENTS_NP_t) sz(: public BaseMngTlv) { c_cod(`};')dnl cpp_cod(` /**< Default constructor */')dnl cpp_cod(` /**< We need to zero the bitmask, as we do not set it explicity! */')dnl -cpp_cod(` SUBSCRIBE_EVENTS_NP_t() : bitmask{0} {}')dnl +cpp_cod(` SUBSCRIBE_EVENTS_NP_t() : duration(0), bitmask{0} {}')dnl idf()/** idf() * Set event bit in bitmask c_cod(idf()` * @param[in, out] tlv with the events storage')dnl From 773ea64807567201b3353008e7642ddd29ea8e60 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Mon, 20 May 2024 13:04:51 +0800 Subject: [PATCH 086/151] jclklib: proxy: Add multi client notification support Send notification to all clients. Signed-off-by: Song Yoong Siang --- jclklib/proxy/client.hpp | 1 + jclklib/proxy/connect.cpp | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/jclklib/proxy/client.hpp b/jclklib/proxy/client.hpp index 0d51d89d..0fba3ef3 100644 --- a/jclklib/proxy/client.hpp +++ b/jclklib/proxy/client.hpp @@ -32,6 +32,7 @@ namespace JClkLibProxy { static std::map SessionMap; public: static JClkLibCommon::sessionId_t CreateClientSession(); + static size_t GetSessionCount() { return SessionMap.size(); } static JClkLibCommon::sessionId_t GetSessionIdAt(size_t index); static ClientX GetClientSession(JClkLibCommon::sessionId_t sessionId); private: diff --git a/jclklib/proxy/connect.cpp b/jclklib/proxy/connect.cpp index 741112e9..29c3f762 100644 --- a/jclklib/proxy/connect.cpp +++ b/jclklib/proxy/connect.cpp @@ -68,15 +68,17 @@ void notify_client() PrintDebug("[JClkLibProxy::notify_client] notifyMsg creation is OK !!\n"); - /* ToDo: loop for multiple sessions */ - SessionId = Client::GetSessionIdAt(0); - if (SessionId != JClkLibCommon::InvalidSessionId) { - PrintDebug("Get client session ID: " + to_string(SessionId)); - - auto TxContext = Client::GetClientSession(SessionId).get()->get_transmitContext(); - pmsg->transmitMessage(*TxContext); - } else { - PrintDebug("Unable to get Session ID"); + /* Send data for multiple sessions */ + for(size_t i = 0; i < Client::GetSessionCount(); i++) { + SessionId = Client::GetSessionIdAt(i); + if (SessionId != JClkLibCommon::InvalidSessionId) { + PrintDebug("Get client session ID: " + to_string(SessionId)); + + auto TxContext = Client::GetClientSession(SessionId).get()->get_transmitContext(); + pmsg->transmitMessage(*TxContext); + } else { + PrintError("Unable to get Session ID\n"); + } } } From 72b22785aa1689742c4e24444a0bb46a807d1a26 Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Mon, 20 May 2024 14:26:21 +0800 Subject: [PATCH 087/151] jclklib: Remove debug printing Signed-off-by: Lai Peter Jun Ann --- jclklib/client/init.cpp | 8 -------- jclklib/client/msgq_tport.cpp | 2 +- jclklib/client/subscribe_msg.cpp | 17 ----------------- jclklib/client/test.cpp | 13 +++++-------- jclklib/proxy/connect.cpp | 14 +++++++------- 5 files changed, 13 insertions(+), 41 deletions(-) diff --git a/jclklib/client/init.cpp b/jclklib/client/init.cpp index 87a6d138..836c4698 100644 --- a/jclklib/client/init.cpp +++ b/jclklib/client/init.cpp @@ -144,14 +144,6 @@ bool JClkLibClientApi::jcl_subscribe(JClkLibCommon::jcl_subscription &newSub, } JClkLibCommon::jcl_state jclCurrentState = appClientState.get_eventState(); - printf("[JClkLibClient]::subscribe : state - \n"); - printf ("offset_in_range = %d, servo_locked = %d, as_Capable = %d gm_Changed = %d\n", \ - jclCurrentState.offset_in_range, jclCurrentState.servo_locked,\ - jclCurrentState.as_Capable, jclCurrentState.gm_changed); - printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x \n", - jclCurrentState.gmIdentity[0], jclCurrentState.gmIdentity[1],jclCurrentState.gmIdentity[2], - jclCurrentState.gmIdentity[3], jclCurrentState.gmIdentity[4], - jclCurrentState.gmIdentity[5], jclCurrentState.gmIdentity[6],jclCurrentState.gmIdentity[7]); currentState = jclCurrentState; diff --git a/jclklib/client/msgq_tport.cpp b/jclklib/client/msgq_tport.cpp index f3f69c65..e4187608 100644 --- a/jclklib/client/msgq_tport.cpp +++ b/jclklib/client/msgq_tport.cpp @@ -133,7 +133,7 @@ bool ClientMessageQueue::writeTransportClientId(Message *msg) //strcpy((char *)cmsg->getClientId().data(), (char *)state.get_clientID().data()); //cmsg->set_sessionId(state.get_sessionId()); // this is where it turns to 0 - printf ("[ClientMessageQueue] [SUBSCRIBE] cmsg->set_sessionId() : %d\n", cmsg->get_sessionId()); + //printf ("[ClientMessageQueue] [SUBSCRIBE] cmsg->set_sessionId() : %d\n", cmsg->get_sessionId()); PrintDebug("[ClientMessageQueue] [SUBSCRIBE] : subscription->event Mask : " + cmsg->getSubscription().get_event().toString()); break; } diff --git a/jclklib/client/subscribe_msg.cpp b/jclklib/client/subscribe_msg.cpp index c4ca8425..392d4eb9 100644 --- a/jclklib/client/subscribe_msg.cpp +++ b/jclklib/client/subscribe_msg.cpp @@ -78,13 +78,6 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { if (!PARSE_RX(FIELD, data, LxContext)) return false; - printf("master_offset = %ld, servo_state = %d\n", data.master_offset, data.servo_state); - printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x ", - data.gmIdentity[0], data.gmIdentity[1],data.gmIdentity[2], - data.gmIdentity[3], data.gmIdentity[4], - data.gmIdentity[5], data.gmIdentity[6],data.gmIdentity[7]); - printf("asCapable = %d, ptp4l_id = %d\n\n", data.asCapable, data.ptp4l_id); - /* TODO : 1. Remove the pair if the sessionID is terminated (disconnect) 2. to move some/all processing inside the processMessage instead of here. @@ -154,14 +147,6 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { composite_client_data->composite_event &= data.asCapable > 0 ? true:false; } - printf("CLIENT master_offset = %ld, servo_state = %d\n", client_data->master_offset, \ - client_data->servo_state); - printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x ", - client_data->gmIdentity[0], client_data->gmIdentity[1],client_data->gmIdentity[2], - client_data->gmIdentity[3], client_data->gmIdentity[4], - client_data->gmIdentity[5], client_data->gmIdentity[6],client_data->gmIdentity[7]); - printf("asCapable = %d\n\n", client_data->asCapable); - jclCurrentState->as_Capable = client_data->asCapable > 0 ? true:false; jclCurrentState->offset_in_range = client_data->master_offset_within_boundary; jclCurrentState->servo_locked = client_data->servo_state >= SERVO_LOCKED ? true:false; @@ -197,8 +182,6 @@ PROCESS_MESSAGE_TYPE(ClientSubscribeMessage::processMessage) this->set_msgAck(ACK_NONE); JClkLibCommon::jcl_state jclCurrentState = currentClientState->get_eventState(); - printf("[ClientSubscribeMessage]::processMessage : state - offset in range = %d, servo_locked = %d as_Capable = %d\n", \ - jclCurrentState.offset_in_range, jclCurrentState.servo_locked, jclCurrentState.as_Capable); cv.notify_one(); return true; diff --git a/jclklib/client/test.cpp b/jclklib/client/test.cpp index 2e7bc479..f6bd2d2b 100644 --- a/jclklib/client/test.cpp +++ b/jclklib/client/test.cpp @@ -125,16 +125,13 @@ int main(int argc, char *argv[]) ClientState &myState = cmAPI->getClientState(); - std::cout << "[CLIENT] Before connect : Session ID : " << - myState.get_sessionId() << "\n"; - if (cmAPI->jcl_connect() == false) { - std::cout << "[CLIENT] Failure in connecting !!!\n"; + std::cout << "[jclklib] Failure in connecting !!!\n"; ret = EXIT_FAILURE; goto do_exit; } else { - std::cout << "[CLIENT] Connected. Session ID : " << + std::cout << "[jclklib] Connected. Session ID : " << myState.get_sessionId() << "\n"; } @@ -147,11 +144,11 @@ int main(int argc, char *argv[]) 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() << "\n"; + 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 << "\n"; - std::cout << "Lower Master Offset: " << lower_master_offset << "\n\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"; diff --git a/jclklib/proxy/connect.cpp b/jclklib/proxy/connect.cpp index 29c3f762..81fd797c 100644 --- a/jclklib/proxy/connect.cpp +++ b/jclklib/proxy/connect.cpp @@ -104,12 +104,12 @@ void event_handle() pe.servo_state = servo; memcpy(pe.gmIdentity, gm_uuid.v, sizeof(pe.gmIdentity)); - //TODO: Add debug flag checking, only print if the flag is set - printf("master_offset = %ld, servo_state = %d\n", pe.master_offset, pe.servo_state); - printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x\n\n", - pe.gmIdentity[0], pe.gmIdentity[1],pe.gmIdentity[2], - pe.gmIdentity[3], pe.gmIdentity[4], - pe.gmIdentity[5], pe.gmIdentity[6],pe.gmIdentity[7]); + //Uncomment for debug data printing + //printf("master_offset = %ld, servo_state = %d\n", pe.master_offset, pe.servo_state); + //printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x\n\n", + // pe.gmIdentity[0], pe.gmIdentity[1],pe.gmIdentity[2], + // pe.gmIdentity[3], pe.gmIdentity[4], + // pe.gmIdentity[5], pe.gmIdentity[6],pe.gmIdentity[7]); break; case PORT_DATA_SET: pd = (PORT_DATA_SET_t *)data; @@ -130,7 +130,7 @@ void event_handle() break; case CMLDS_INFO_NP: pe.asCapable = ((CMLDS_INFO_NP_t *)data)->as_capable; - printf("asCapable = %d\n\n", pe.asCapable); + //printf("asCapable = %d\n\n", pe.asCapable); break; default: return; From faa5a96bc199b6c532418f65f69b22e1f6b8c0df Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Mon, 20 May 2024 14:29:16 +0800 Subject: [PATCH 088/151] jclklib: Remove -g flag from Makefile Remove flag to generate debugging information from Makefile Signed-off-by: Lai Peter Jun Ann --- jclklib/client/Makefile | 6 +++--- jclklib/common/Makefile | 2 +- jclklib/proxy/Makefile | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/jclklib/client/Makefile b/jclklib/client/Makefile index 7cb28625..43f42b43 100644 --- a/jclklib/client/Makefile +++ b/jclklib/client/Makefile @@ -63,11 +63,11 @@ build-all: build-prep jclklib.so: $(OBJ_FILES) $(COMMON_OBJ_FILES) echo "[LINK]" $@ "{" $(call pathof_relative_to,$^,$(JCLKLIB_TOPLEVEL_DIR)) "}" | fold -s - g++ -g -shared -o $@ $^ $(LIBS_FLAGS) -fdiagnostics-color=always + g++ -shared -o $@ $^ $(LIBS_FLAGS) -fdiagnostics-color=always test: test.o jclklib.so - g++ -g -o test test.o -L $(JCLKLIB_CLIENT_DIR) -l:jclklib.so + g++ -o test test.o -L $(JCLKLIB_CLIENT_DIR) -l:jclklib.so %.o : %.cpp echo "[COMPILE]" $< - g++ -c $< -g -I $(JCLKLIB_TOPLEVEL_DIR) -fPIC -fdiagnostics-color=always + g++ -c $< -I $(JCLKLIB_TOPLEVEL_DIR) -fPIC -fdiagnostics-color=always diff --git a/jclklib/common/Makefile b/jclklib/common/Makefile index 7500cf2b..866912d0 100644 --- a/jclklib/common/Makefile +++ b/jclklib/common/Makefile @@ -61,5 +61,5 @@ common-obj: $(OBJ_FILES) %.o : %.cpp echo "[COMPILE]" $< - g++ -c $< -g -I $(JCLKLIB_TOPLEVEL_DIR) -fPIC -Werror -Wall -Wextra -Wno-unused-parameter -fdiagnostics-color=always + g++ -c $< -I $(JCLKLIB_TOPLEVEL_DIR) -fPIC -Werror -Wall -Wextra -Wno-unused-parameter -fdiagnostics-color=always diff --git a/jclklib/proxy/Makefile b/jclklib/proxy/Makefile index 7a6ddc7d..a109396e 100644 --- a/jclklib/proxy/Makefile +++ b/jclklib/proxy/Makefile @@ -66,5 +66,5 @@ jclklib_proxy: $(OBJ_FILES) $(COMMON_OBJ_FILES) %.o : %.cpp echo "[COMPILE]" $< - g++ -c $< -g -I $(JCLKLIB_TOPLEVEL_DIR) -fdiagnostics-color=always + g++ -c $< -I $(JCLKLIB_TOPLEVEL_DIR) -fdiagnostics-color=always From e5a4b192b61a3c7e409af9e527342777da7ec51d Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Mon, 20 May 2024 20:21:10 +0800 Subject: [PATCH 089/151] jclklib: Fix event count not updated properly Signed-off-by: Lai Peter Jun Ann --- jclklib/client/init.cpp | 2 ++ jclklib/client/subscribe_msg.cpp | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/jclklib/client/init.cpp b/jclklib/client/init.cpp index 836c4698..c26fece3 100644 --- a/jclklib/client/init.cpp +++ b/jclklib/client/init.cpp @@ -231,5 +231,7 @@ int JClkLibClientApi::jcl_status_wait(int timeout, JClkLibCommon::jcl_state &jcl /* Reset the atomic count by reducing the corresponding eventCount */ ClientSubscribeMessage::resetClientPtpEventStruct(appClientState.get_sessionId(), eventCount); + appClientState.set_eventStateCount(eventCount); + return true; } diff --git a/jclklib/client/subscribe_msg.cpp b/jclklib/client/subscribe_msg.cpp index 392d4eb9..6266f27f 100644 --- a/jclklib/client/subscribe_msg.cpp +++ b/jclklib/client/subscribe_msg.cpp @@ -260,4 +260,10 @@ void ClientSubscribeMessage::resetClientPtpEventStruct(JClkLibCommon::sessionId_ std::memory_order_relaxed); client_ptp_data->composite_event_count.fetch_sub(eventCount.composite_event_count, std::memory_order_relaxed); -} \ No newline at end of file + + eventCount.offset_in_range_event_count = client_ptp_data->offset_event_count; + eventCount.asCapable_event_count = client_ptp_data->asCapable_event_count; + eventCount.servo_locked_event_count = client_ptp_data->servo_state_event_count; + eventCount.gm_changed_event_count = client_ptp_data->gmChanged_event_count; + eventCount.composite_event_count = client_ptp_data->composite_event_count; +} From e0bcb2eb54dec4d9b90b057e9b89819b49e70103 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Mon, 20 May 2024 17:11:54 +0800 Subject: [PATCH 090/151] jclklib: Move all API related definition to jclk_init.hpp Move all API related definition to jclk_init.hpp so that user application will just need to include one header file. In future, this file will be move to pub folder. Signed-off-by: Song Yoong Siang --- jclklib/TEST_jclklib.md | 2 +- jclklib/client/init.hpp | 48 ---------------------- jclklib/client/{init.cpp => jclk_init.cpp} | 2 +- jclklib/client/jclk_init.hpp | 40 ++++++++++++++++++ jclklib/client/test.cpp | 5 +-- 5 files changed, 43 insertions(+), 54 deletions(-) delete mode 100644 jclklib/client/init.hpp rename jclklib/client/{init.cpp => jclk_init.cpp} (99%) create mode 100644 jclklib/client/jclk_init.hpp diff --git a/jclklib/TEST_jclklib.md b/jclklib/TEST_jclklib.md index 06bb16ae..ebf6ea16 100644 --- a/jclklib/TEST_jclklib.md +++ b/jclklib/TEST_jclklib.md @@ -56,7 +56,7 @@ NOTE : make will traverse the client, common and proxy folder one by one. You n # How to test : -We are currently using a "test.cpp" file to act as an application. This test.cpp is using the API provided in the init.hpp. +We are currently using a "test.cpp" file to act as an application. This test.cpp is using the API provided in the jclk_init.hpp. We are dividing the test plan according to message type : A. Connect message diff --git a/jclklib/client/init.hpp b/jclklib/client/init.hpp deleted file mode 100644 index bc94adbb..00000000 --- a/jclklib/client/init.hpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. - */ - -/** @file init.hpp - * @brief Client utilities to setup and cleanup the library. - * - * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later - * - */ - -#ifndef CLIENT_INIT_HPP -#define CLIENT_INIT_HPP - -#include -#include -#include - - -namespace JClkLibClient { - -class JClkLibClientApi { - private : - //std::map ports; - static std::map clientStateMap; - ClientState appClientState; - public : - JClkLibClientApi() { - } - static int init(){ - // In case we need to init something for API. - return 0; - }; - ClientState &getClientState() { return appClientState;}; - bool jcl_connect(); - bool jcl_disconnect(); - bool jcl_subscribe(JClkLibCommon::jcl_subscription &newSub, - JClkLibCommon::jcl_state ¤tState); - int jcl_status_wait(int timeout, JClkLibCommon::jcl_state &jcl_state, - JClkLibCommon::jcl_state_event_count &eventCount); - - }; -} - -#endif/*CLIENT_INIT_HPP*/ diff --git a/jclklib/client/init.cpp b/jclklib/client/jclk_init.cpp similarity index 99% rename from jclklib/client/init.cpp rename to jclklib/client/jclk_init.cpp index c26fece3..0f1240b2 100644 --- a/jclklib/client/init.cpp +++ b/jclklib/client/jclk_init.cpp @@ -12,7 +12,7 @@ * */ -#include +#include #include #include #include diff --git a/jclklib/client/jclk_init.hpp b/jclklib/client/jclk_init.hpp new file mode 100644 index 00000000..b4847ace --- /dev/null +++ b/jclklib/client/jclk_init.hpp @@ -0,0 +1,40 @@ +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + */ + +/** @file jclk_init.hpp + * @brief Client utilities to setup and cleanup the library. + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. All rights reserved. + * @license LGPL-3.0-or-later + * + */ + +#ifndef JCLK_INIT_HPP +#define JCLK_INIT_HPP + +#include +#include +#include + +namespace JClkLibClient { + class JClkLibClientApi { + private: + static std::map clientStateMap; + ClientState appClientState; + public: + JClkLibClientApi() {} + /* In case we need to init something for API. */ + static int init() { return 0; } + ClientState &getClientState() { return appClientState; } + bool jcl_connect(); + bool jcl_disconnect(); + bool jcl_subscribe(JClkLibCommon::jcl_subscription &newSub, + JClkLibCommon::jcl_state ¤tState); + int jcl_status_wait(int timeout, JClkLibCommon::jcl_state &jcl_state, + JClkLibCommon::jcl_state_event_count &eventCount); + }; +} +#endif /* JCLK_INIT_HPP */ diff --git a/jclklib/client/test.cpp b/jclklib/client/test.cpp index f6bd2d2b..6c2a0abb 100644 --- a/jclklib/client/test.cpp +++ b/jclklib/client/test.cpp @@ -17,11 +17,8 @@ #include #include #include -#include -#include -#include -#include "init.hpp" +#include "jclk_init.hpp" using namespace JClkLibClient; using namespace JClkLibCommon; From d540df4579e903b0501d2494d011ac8c3c733da9 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Tue, 21 May 2024 12:54:15 +0800 Subject: [PATCH 091/151] jclklib: Fix No rule to make target 'init.d' error update Makefile since init.cpp is changed to jclk_init.cpp Signed-off-by: Song Yoong Siang --- jclklib/client/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jclklib/client/Makefile b/jclklib/client/Makefile index 43f42b43..10d4c92b 100644 --- a/jclklib/client/Makefile +++ b/jclklib/client/Makefile @@ -15,7 +15,7 @@ JCLKLIB_TOPLEVEL_DIR = $(JCLKLIB_CLIENT_DIR)/.. JCLKLIB_COMMON_DIR = $(JCLKLIB_TOPLEVEL_DIR)/common LIBS = pthread rt LIBS_FLAGS = $(foreach lib,$(LIBS),-l$(lib)) -OBJ = init msgq_tport message null_tport transport msgq_tport notification_msg connect_msg client_state subscribe_msg +OBJ = jclk_init msgq_tport message null_tport transport msgq_tport notification_msg connect_msg client_state subscribe_msg COMMON_OBJ = print sighandler transport msgq_tport message connect_msg subscribe_msg notification_msg jclklib_import OBJ_FILES = $(foreach f,$(OBJ),$(f).o) DEPENDS = $(foreach f,$(OBJ),$(f).d) From b500ac5e604f135f7826510c8281b326938885bd Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Tue, 21 May 2024 13:00:41 +0800 Subject: [PATCH 092/151] jclklib: Avoid notify client if ascapable is the same If the value of ascapable is same as previous, end the event handler. This is to avoid unneccesary messages in message queue. Signed-off-by: Song Yoong Siang --- jclklib/proxy/connect.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/jclklib/proxy/connect.cpp b/jclklib/proxy/connect.cpp index 81fd797c..68b8efe4 100644 --- a/jclklib/proxy/connect.cpp +++ b/jclklib/proxy/connect.cpp @@ -129,6 +129,10 @@ void event_handle() portState = pd->portState; break; case CMLDS_INFO_NP: + if (pe.asCapable == ((CMLDS_INFO_NP_t *)data)->as_capable) { + PrintDebug("Ignore unchanged asCapable"); + return; + } pe.asCapable = ((CMLDS_INFO_NP_t *)data)->as_capable; //printf("asCapable = %d\n\n", pe.asCapable); break; From 4fa5c17e93912b25b3239af2d04abfb1e405531b Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Wed, 22 May 2024 15:27:15 +0800 Subject: [PATCH 093/151] sample: remove unneccesary header Remove pub/init.h to prevent following build error: checksync.cpp:25:10: fatal error: pub/init.h: No such file or directory 25 | #include | ^~~~~~~~~~~~ Signed-off-by: Song Yoong Siang --- sample/checksync.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/sample/checksync.cpp b/sample/checksync.cpp index effd6291..2c0042dc 100644 --- a/sample/checksync.cpp +++ b/sample/checksync.cpp @@ -21,8 +21,6 @@ #include #include #include -//#include -#include using namespace ptpmgmt; From a6d006c5195613580d3a5f399a10304c429d7494 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Wed, 22 May 2024 16:13:28 +0800 Subject: [PATCH 094/151] jclklib: remove unused variable Remove ret to prevent following build warning: test.cpp:38:9: warning: variable 'ret' set but not used [-Wunused-but-set-variable] 38 | int ret = 0; | ^~~ Signed-off-by: Song Yoong Siang --- jclklib/client/test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jclklib/client/test.cpp b/jclklib/client/test.cpp index 6c2a0abb..be2d4e98 100644 --- a/jclklib/client/test.cpp +++ b/jclklib/client/test.cpp @@ -35,7 +35,7 @@ int main(int argc, char *argv[]) int timeout = 10; int upper_master_offset = 100000; int lower_master_offset = -100000; - int ret = 0; + int ret = EXIT_SUCCESS; JClkLibCommon::jcl_subscription sub = {}; JClkLibCommon::jcl_state jcl_state = {}; JClkLibCommon::jcl_state_event_count eventCount = {}; @@ -262,5 +262,5 @@ int main(int argc, char *argv[]) do_exit: cmAPI->jcl_disconnect(); - return EXIT_SUCCESS; + return ret; } From c6f3cec61d6542800bccb645ce77d67e7b6a190f Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Wed, 22 May 2024 16:22:11 +0800 Subject: [PATCH 095/151] Rename jclklib.so to libjclk.so in Makefile This commit updates the Makefile to change the target name from jclklib.so to libjclk.so. This change aligns with the convention of prefixing shared library names with 'lib'. This change ensures that the generated shared library follows the standard naming convention, which can help prevent confusion and potential issues with library linking in the future. Signed-off-by: Song Yoong Siang --- jclklib/client/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jclklib/client/Makefile b/jclklib/client/Makefile index 10d4c92b..b01ac406 100644 --- a/jclklib/client/Makefile +++ b/jclklib/client/Makefile @@ -21,7 +21,7 @@ OBJ_FILES = $(foreach f,$(OBJ),$(f).o) DEPENDS = $(foreach f,$(OBJ),$(f).d) COMMON_OBJ_DIR = $(JCLKLIB_COMMON_DIR)/obj COMMON_OBJ_FILES = $(foreach obj,$(COMMON_OBJ),$(COMMON_OBJ_DIR)/$(obj).o) -REAL_TARGETS = jclklib.so test +REAL_TARGETS = libjclk.so test .PHONY: default default: @@ -61,12 +61,12 @@ build-all: build-prep echo "Running" $@ $(MAKE) -C $(JCLKLIB_CLIENT_DIR) $(REAL_TARGETS) -jclklib.so: $(OBJ_FILES) $(COMMON_OBJ_FILES) +libjclk.so: $(OBJ_FILES) $(COMMON_OBJ_FILES) echo "[LINK]" $@ "{" $(call pathof_relative_to,$^,$(JCLKLIB_TOPLEVEL_DIR)) "}" | fold -s g++ -shared -o $@ $^ $(LIBS_FLAGS) -fdiagnostics-color=always -test: test.o jclklib.so - g++ -o test test.o -L $(JCLKLIB_CLIENT_DIR) -l:jclklib.so +test: test.o libjclk.so + g++ -o test test.o -L $(JCLKLIB_CLIENT_DIR) -l:libjclk.so %.o : %.cpp echo "[COMPILE]" $< From cb95930cfbd36e7eaaf0157543cb404d683e8f4e Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Wed, 22 May 2024 16:53:25 +0800 Subject: [PATCH 096/151] jclklib: separate sample test app from jclklib Makefile Sample test app should not build automatically with jclklib. Signed-off-by: Song Yoong Siang --- jclklib/.gitignore | 1 - jclklib/client/Makefile | 5 +---- jclklib/{client/test.cpp => sample/jclk_test.cpp} | 0 3 files changed, 1 insertion(+), 5 deletions(-) rename jclklib/{client/test.cpp => sample/jclk_test.cpp} (100%) diff --git a/jclklib/.gitignore b/jclklib/.gitignore index 2c567b24..54f42a6f 100644 --- a/jclklib/.gitignore +++ b/jclklib/.gitignore @@ -7,5 +7,4 @@ # ############################################################################### -client/test proxy/jclklib_proxy diff --git a/jclklib/client/Makefile b/jclklib/client/Makefile index b01ac406..88569ca5 100644 --- a/jclklib/client/Makefile +++ b/jclklib/client/Makefile @@ -21,7 +21,7 @@ OBJ_FILES = $(foreach f,$(OBJ),$(f).o) DEPENDS = $(foreach f,$(OBJ),$(f).d) COMMON_OBJ_DIR = $(JCLKLIB_COMMON_DIR)/obj COMMON_OBJ_FILES = $(foreach obj,$(COMMON_OBJ),$(COMMON_OBJ_DIR)/$(obj).o) -REAL_TARGETS = libjclk.so test +REAL_TARGETS = libjclk.so .PHONY: default default: @@ -65,9 +65,6 @@ libjclk.so: $(OBJ_FILES) $(COMMON_OBJ_FILES) echo "[LINK]" $@ "{" $(call pathof_relative_to,$^,$(JCLKLIB_TOPLEVEL_DIR)) "}" | fold -s g++ -shared -o $@ $^ $(LIBS_FLAGS) -fdiagnostics-color=always -test: test.o libjclk.so - g++ -o test test.o -L $(JCLKLIB_CLIENT_DIR) -l:libjclk.so - %.o : %.cpp echo "[COMPILE]" $< g++ -c $< -I $(JCLKLIB_TOPLEVEL_DIR) -fPIC -fdiagnostics-color=always diff --git a/jclklib/client/test.cpp b/jclklib/sample/jclk_test.cpp similarity index 100% rename from jclklib/client/test.cpp rename to jclklib/sample/jclk_test.cpp From c69bae364ad0b0eec85119ffde5fa180edd08cd3 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Wed, 22 May 2024 17:26:51 +0800 Subject: [PATCH 097/151] jclklib: sample: Create Makefile Introduces a new Makefile for building the jclk_test application. Signed-off-by: Song Yoong Siang --- jclklib/sample/Makefile | 35 +++++++++++++++++++++++++++++++++++ jclklib/sample/jclk_test.cpp | 10 +++++++--- 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 jclklib/sample/Makefile diff --git a/jclklib/sample/Makefile b/jclklib/sample/Makefile new file mode 100644 index 00000000..d4addb62 --- /dev/null +++ b/jclklib/sample/Makefile @@ -0,0 +1,35 @@ +# SPDX-License-Identifier: LGPL-3.0-or-later +# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. +# +# Makefile for jclklib test application +# +# @author Song Yoong Siang +# @copyright © 2024 Intel Corporation. All rights reserved. +# @license LGPL-3.0-or-later +# +############################################################################### + +# Variables +CXX = g++ +CXXFLAGS = -Wall +INCLUDES = -I$(shell pwd)/.. +LDFLAGS = -L$(shell pwd)/../client +LDLIBS = -ljclk +TARGET = jclk_test + +# Default target +all: $(TARGET) + +# Linking +$(TARGET): $(TARGET).o + $(CXX) $(LDFLAGS) $^ -o $@ $(LDLIBS) + +# Compiling +$(TARGET).o: $(TARGET).cpp + $(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@ + +# Cleaning +clean: + rm -f $(TARGET) $(TARGET).o + +.PHONY: all clean diff --git a/jclklib/sample/jclk_test.cpp b/jclklib/sample/jclk_test.cpp index be2d4e98..8e5bc8eb 100644 --- a/jclklib/sample/jclk_test.cpp +++ b/jclklib/sample/jclk_test.cpp @@ -3,13 +3,17 @@ * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. */ -/** @file test.cpp - * @brief Test client code +/** @file jclk_test.cpp + * @brief Test jclk client code * * @author Christopher Hall * @copyright © 2024 Intel Corporation. All rights reserved. * @license LGPL-3.0-or-later * + * @note This is a sample code, not a product! You should use it as a reference. + * You can compile it with: g++ -Wall jclk_test.cpp -o jclk_test -ljclk + * or use the CMakeLists.txt file. + * */ #include @@ -18,7 +22,7 @@ #include #include -#include "jclk_init.hpp" +#include using namespace JClkLibClient; using namespace JClkLibCommon; From b4ec358f8ba7809eb45fa0b306b575455d175070 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Wed, 22 May 2024 17:56:05 +0800 Subject: [PATCH 098/151] Add missing source files in SRC_FILES_DIR Add source files from jclklib folder into SRC_FILES_DIR Signed-off-by: Song Yoong Siang --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 883483cc..aeadabd3 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 @@ -258,6 +259,7 @@ 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\ + $(JCLKLIB_SRC)/*.md $(JCLKLIB_SRC)/*/Makefile $(JCLKLIB_SRC)/*/*.[ch]*\ */*/*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) From f9fe4eb16ee42292ce1c217c521f795ebf1ffa5f Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Wed, 22 May 2024 18:43:10 +0800 Subject: [PATCH 099/151] Makefile: Changes to make jclklib available from libptpmgmt make available to build jclklin from libptpmgmt or inside jclklib folder. Signed-off-by: Noor Azura Ahmad Tarmizi Signed-off-by: Song Yoong Siang --- Makefile | 15 +++++++++++---- jclklib/Makefile | 10 +++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index aeadabd3..80f504c2 100644 --- a/Makefile +++ b/Makefile @@ -226,11 +226,15 @@ 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:=libjclk.so +JCLKLIB_FLIB:=$(JCLKLIB_LIB)$(SONAME) # fastjson FJSON_LIB:=$(LIB_NAME)_fastjson.so FJSON_LIBA:=$(LIB_NAME)_fastjson.a @@ -395,6 +399,9 @@ endif # VALGRIND # JSON libraries include $(JSON_SRC)/Makefile +# JCLK libraries +include $(JCLKLIB_SRC)/Makefile + # Compile library source code $(LIB_OBJS): $(OBJ_DIR)/%.o: $(SRC)/%.cpp | $(COMP_DEPS) $(LIBTOOL_CC) $(CXX) -c $(CXXFLAGS) $< -o $@ @@ -447,7 +454,7 @@ 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) - $(Q_FRMT) + $(Q_FRMT) $(SRCS_JCLKLIB) r=`$(ASTYLE) --project=none --options=tools/astyle.opt $^` test -z "$$r" || echo "$$r";./tools/format.pl $^ if test $$? -ne 0 || test -n "$$r"; then echo '';exit 1;fi @@ -556,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 ####### @@ -753,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..22fbb2bf 100644 --- a/jclklib/Makefile +++ b/jclklib/Makefile @@ -9,16 +9,16 @@ # ############################################################################### -CWD := $(shell pwd) +CWD := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) -.PHONY: all -all: +.PHONY: jclklib +jclklib: $(MAKE) -C $(CWD)/common default $(MAKE) -C $(CWD)/proxy default $(MAKE) -C $(CWD)/client default -.PHONY: clean -clean: +.PHONY: jclklib_clean +jclklib_clean: $(MAKE) -C $(CWD)/client clean $(MAKE) -C $(CWD)/proxy clean $(MAKE) -C $(CWD)/common clean From f42ac997eb579689e45edda3cc8c39c596d85e32 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Wed, 22 May 2024 22:31:05 +0800 Subject: [PATCH 100/151] Fix clean issue in Makefile Fix following issue from CI: make: *** No rule to make target 'jclklib_clean', needed by 'clean'. Signed-off-by: Song Yoong Siang --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 80f504c2..cf8a699c 100644 --- a/Makefile +++ b/Makefile @@ -760,9 +760,11 @@ DISTCLEAN:=$(addprefix config.,log status) configure configure~ defs.mk\ $(wildcard src/config.h*) DISTCLEAN_DIRS:=autom4te.cache -clean: deb_clean jclklib_clean +clean: deb_clean jclk_clean $(Q_CLEAN)$(RM) $(CLEAN) $(RM) -R $(CLEAN_DIRS) +jclk_clean: + $(MAKE) -C $(JCLKLIB_SRC) jclklib_clean distclean: deb_clean $(Q_DISTCLEAN)$(RM) $(CLEAN) $(DISTCLEAN) $(RM) -R $(CLEAN_DIRS) $(DISTCLEAN_DIRS) From fdfbbfe074f74c836a5d0ee34eaa9d297636f0a3 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Wed, 22 May 2024 22:46:09 +0800 Subject: [PATCH 101/151] jclklib: Add header for unit8_t Fix following build error: print.cpp:54:15: error: 'uint8_t' does not name a type 54 | const uint8_t *index = arr; | ^~~~~~~ Signed-off-by: Song Yoong Siang --- jclklib/common/print.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/jclklib/common/print.hpp b/jclklib/common/print.hpp index 7de8b206..65048f2c 100644 --- a/jclklib/common/print.hpp +++ b/jclklib/common/print.hpp @@ -14,6 +14,7 @@ #include #include +#include #ifndef PRINT_HPP #define PRINT_HPP From 3859a83f88d55997d29e25d64752ad3462a68cc2 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Wed, 22 May 2024 22:58:09 +0800 Subject: [PATCH 102/151] jclklib: solve libptpmgmt dependancy issue Avoid pointing to ptpmgmt because user might not yet install it: connect.cpp:23:10: fatal error: ptpmgmt/init.h: No such file or directory 23 | #include | ^~~~~~~~~~~~~~~~ Signed-off-by: Song Yoong Siang --- jclklib/proxy/connect.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/jclklib/proxy/connect.cpp b/jclklib/proxy/connect.cpp index 68b8efe4..c8fbce13 100644 --- a/jclklib/proxy/connect.cpp +++ b/jclklib/proxy/connect.cpp @@ -20,14 +20,13 @@ #include #include #include -#include #include #include #include #include -//TODO: subsription part #include "thread.hpp" +#include "../../pub/init.h" using namespace std; using namespace JClkLibProxy; From 9f9eff3c8212bbc12386f5cca5b191724b539684 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Wed, 22 May 2024 23:20:58 +0800 Subject: [PATCH 103/151] jclklib: Remove unnecessary std::move from promise.get_future() This commit removes an unnecessary use of std::move from promise.get_future() in the registerWork function of the Transport class. The std::move was causing a compiler warning because it was applied to a temporary object, which can prevent certain compiler optimizations. Removing std::move in this case does not affect the functionality of the code, as promise.get_future() already returns a temporary object that can be efficiently moved. Signed-off-by: Song Yoong Siang --- jclklib/common/transport.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jclklib/common/transport.cpp b/jclklib/common/transport.cpp index ab323f60..c0100034 100644 --- a/jclklib/common/transport.cpp +++ b/jclklib/common/transport.cpp @@ -61,7 +61,7 @@ Transport::TransportWorkDesc Transport::registerWork(TransportWork work) { promise promise; - workerList.push_back(TransportWorkerState(move(promise.get_future()),false)); + workerList.push_back(TransportWorkerState(promise.get_future(),false)); workerList.back().thread = make_unique (MessageQueue::dispatchLoop, move(promise), workerList.back().exitVal, TransportWork(work.first,move(work.second))); From df66aacaf5f76b230172e2ff57f9ad6490680c98 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Wed, 22 May 2024 23:56:13 +0800 Subject: [PATCH 104/151] jclklib: update jclk_test shell script Update script to run jclk_test Signed-off-by: Song Yoong Siang --- jclklib/{client/run_test.sh => sample/run_jclk_test.sh} | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) rename jclklib/{client/run_test.sh => sample/run_jclk_test.sh} (75%) diff --git a/jclklib/client/run_test.sh b/jclklib/sample/run_jclk_test.sh similarity index 75% rename from jclklib/client/run_test.sh rename to jclklib/sample/run_jclk_test.sh index 0bf77d6c..79807d94 100755 --- a/jclklib/client/run_test.sh +++ b/jclklib/sample/run_jclk_test.sh @@ -8,8 +8,7 @@ # ############################################################################### -TEST_PATH=/home/ubuntu20/siemens/libptpmgmt_iaclocklib_org/jclklib/client/ - -LD_LIBRARY_PATH=$TEST_PATH $TEST_PATH/test - +SCRIPT_PATH="$(dirname "$0")" +TEST_PATH="${SCRIPT_PATH}/../client" +LD_LIBRARY_PATH=$TEST_PATH $SCRIPT_PATH/jclk_test "$@" From 899ad6714c60e9fe751838e5131fa2a35cae3755 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 23 May 2024 00:00:59 +0800 Subject: [PATCH 105/151] jclklib: Add shell script for running proxy Add sheel script to run proxy with correct library path Signed-off-by: Song Yoong Siang --- jclklib/proxy/run_proxy.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 jclklib/proxy/run_proxy.sh diff --git a/jclklib/proxy/run_proxy.sh b/jclklib/proxy/run_proxy.sh new file mode 100755 index 00000000..d41f0f87 --- /dev/null +++ b/jclklib/proxy/run_proxy.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# SPDX-License-Identifier: LGPL-3.0-or-later +# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. +# +# @author Christopher Hall +# @copyright © 2024 Intel Corporation. All rights reserved. +# @license LGPL-3.0-or-later +# +############################################################################### + +SCRIPT_PATH="$(dirname "$0")" +TEST_PATH="${SCRIPT_PATH}/../.." + +LD_LIBRARY_PATH=$TEST_PATH $SCRIPT_PATH/jclklib_proxy From 3508ba70c27d394a57510fb0b055cf9bdbc9076f Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 23 May 2024 09:08:24 +0800 Subject: [PATCH 106/151] jclklib: Add jclk_test into .gitignore Signed-off-by: Song Yoong Siang --- jclklib/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/jclklib/.gitignore b/jclklib/.gitignore index 54f42a6f..07f14a29 100644 --- a/jclklib/.gitignore +++ b/jclklib/.gitignore @@ -7,4 +7,5 @@ # ############################################################################### +sample/jclk_test proxy/jclklib_proxy From 55b59c8b50728a430fdb613b22e9080dbb24bcb0 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 23 May 2024 09:37:02 +0800 Subject: [PATCH 107/151] Update Makefile to include ptpmgmt library path in LIBS_FLAGS This commit updates the Makefile for building the jclklib_proxy. It modifies the LIBS_FLAGS variable to include the path to the ptpmgmt library using the -L option. This change ensures that the linker can find the ptpmgmt library when building jclklib_proxy, even if the library is not installed in the standard library paths. Signed-off-by: Song Yoong Siang --- jclklib/proxy/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jclklib/proxy/Makefile b/jclklib/proxy/Makefile index a109396e..452c9772 100644 --- a/jclklib/proxy/Makefile +++ b/jclklib/proxy/Makefile @@ -12,8 +12,9 @@ JCLKLIB_PROXY_DIR := $(shell pwd) JCLKLIB_TOPLEVEL_DIR = $(JCLKLIB_PROXY_DIR)/.. JCLKLIB_COMMON_DIR = $(JCLKLIB_TOPLEVEL_DIR)/common +PTPMGMT_DIR := $(JCLKLIB_TOPLEVEL_DIR)/.. LIBS = pthread rt ptpmgmt -LIBS_FLAGS = $(foreach lib,$(LIBS),-l$(lib)) +LIBS_FLAGS = $(foreach lib,$(LIBS),-l$(lib)) -L$(PTPMGMT_DIR) OBJ = client main message msgq_tport notification_msg null_tport connect_msg subscribe_msg transport connect thread COMMON_OBJ = print sighandler transport msgq_tport jclklib_import message connect_msg subscribe_msg notification_msg OBJ_FILES = $(foreach f,$(OBJ),$(f).o) From 8231d60cee6da033bbac25fc13e27fda05412038 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 23 May 2024 11:21:42 +0800 Subject: [PATCH 108/151] update coverity build step Signed-off-by: Song Yoong Siang --- .github/workflows/coverity.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml index 9221bcb9..37b3f613 100644 --- a/.github/workflows/coverity.yml +++ b/.github/workflows/coverity.yml @@ -33,13 +33,8 @@ jobs: run: autoconf - name: configure run: ./configure - - name: make - run: make - - name: install - run: sudo make install - uses: vapier/coverity-scan-action@2068473c7bdf8c2fb984a6a40ae76ee7facd7a85 # v1.8.0 with: - working-directory: jclklib email: ${{ secrets.COVERITY_SCAN_EMAIL }} token: ${{ secrets.COVERITY_SCAN_TOKEN }} project: libptpmgmt_iaclocklib From 27c176250fb396d62eef4db5612f8531767b3c50 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 23 May 2024 15:25:15 +0800 Subject: [PATCH 109/151] Add doc on how to clone, build, test Signed-off-by: Song Yoong Siang --- jclklib/TEST_jclklib.md | 210 ++++++++++++++++++++++++---------------- 1 file changed, 124 insertions(+), 86 deletions(-) diff --git a/jclklib/TEST_jclklib.md b/jclklib/TEST_jclklib.md index ebf6ea16..8e70c2d1 100644 --- a/jclklib/TEST_jclklib.md +++ b/jclklib/TEST_jclklib.md @@ -1,91 +1,129 @@ -# The diagram of clockmanager(CM) usage in system : - -Test app <------> CM runtime lib (jclklib.so) <----------> jclklib_proxy <-----> libptpmgmt.so <-----> ptp4l - -# How to install linux-ptp (with Intel suggested changes) : - - - Ptp4l version based on 4.2 . - - ptp4l patches -> (servo_state subscription changes, etc) - - Repo : https://github.com/intel-staging/linux-ptp_iaclocklib - - Need to clone and install this version with our patches to extend ptp4l subscription options to be used later by libptpmgmt. - - **How to install linuxptp:** - make & make install - - -# How to compile clock manager: - -Clock manager is basically divided to 2 parts: jclklib.so + jclklib_proxy . - -Test application is using CM runtime library : jclklib.so provided API to connect, subscribe and receive ptp4l events. Jclkib.so is communicating with jclklib_proxy using messagequeue. jclklib_proxy uses libptpmgmt.so API (dynamically linked) to subscribe to ptp4l events. - -First, we need to compile the libptpmgmt, giving us the libptpmgmt.so . -Then we compile the clock manager inside the jclklib folder. This will give us : jclklib.so, jclklib_proxy binary and test binary. - - 1. Clone the github : https://github.com/intel-staging/libptpmgmt_iaclocklib - 2. Package dependencies to be installed before compiling libptpmgmt : - - Swig - Cppcheck - Doxygen - Ctags - astyle - Dot - Epstopdf - Valgrind - Libtool-bin - - 3. Run this at the github root directory to compile libptpmgmt : - autoheader - autoconf - ./configure - make - - 4. Change directory to jclklib and run make clean && make - -NOTE : make will traverse the client, common and proxy folder one by one. You need to type "q" to continue from one folder to another. This is a temporary situation. - - 5. Outcome : you must have 3 binaries created - - client/test - client/jclklib.so - proxy/jclklib_proxy +# The diagram of Clock Manager usage in system : + +Test app <----> client runtime(libjclk.so) <----> jclklib_proxy <----> libptpmgmt.so <----> ptp4l + +# How to Clone and Build the Intel Customized Linux PTP: + +We have applied several patches to the latest version of Linux PTP project +(https://git.code.sf.net/p/linuxptp/code), including servo state notify event. +The repository with our custom changes can be found at +https://github.com/intel-staging/linux-ptp_iaclocklib. It should be used +together with this Clock Manager application. + +1. Clone the repository: + ```bash + git clone https://github.com/intel-staging/linux-ptp_iaclocklib.git + ``` + +2. Navigate to the cloned directory: + ```bash + cd linux-ptp_iaclocklib + ``` + +3. Build the application: + ```bash + make + ``` + +# How to Clone and Build the Clock Manager together with libptpmgmt: + +Clock manager is basically divided to 2 parts: libjclk.so + jclklib_proxy. +libjclk.so provided API for an user application to connect, subscribe and +receive ptp4l events, whereas jclklib_proxy uses libptpmgmt.so API +(dynamically linked) to subscribe and listen to notify event from ptp4l. +Jclkib.so is communicating with jclklib_proxy using message queue. + +1. Install package dependencies: + ```bash + sudo apt-get install -y swig libtool-bin cppcheck doxygen ctags astyle dot epstopdf valgrind + ``` + +2. Clone the repository: + ```bash + git clone https://github.com/intel-staging/libptpmgmt_iaclocklib + ``` + +3. Navigate to the cloned directory: + ```bash + cd libptpmgmt_iaclocklib + ``` + +4. Build the application: + ```bash + autoheader + autoconf + ./configure + make + ``` + +5. Outcome : you must have 3 binaries created: + ```bash + libptpmgmt.so + jclklib/client/libjclk.so + jclklib/proxy/jclklib_proxy + ``` + +# How to Build the Sample Application: + +We provided a sample code (not a product!) of test application which will uses +Clock Manager API to track latest status of ptp4l. You should use it as a +reference. + +1. Navigate to the sample directory: + ```bash + cd libptpmgmt_iaclocklib/jclklib/sample + ``` + +2. Build the application: + ```bash + make + ``` + +3. Outcome : you must have 1 binary created: + ```bash + jclk_test + ``` # How to test : -We are currently using a "test.cpp" file to act as an application. This test.cpp is using the API provided in the jclk_init.hpp. - -We are dividing the test plan according to message type : - A. Connect message - B. Subscription message - C. Notification message - - -## A. CONNECT message - -** Prerequisite ** -Jclklib_proxy needs to be running before running the test. -Ptp4l shd be running before as well : proxy/run_ptp4l.sh - -### Test setup : - - 1. On a terminal, we run : ./proxy/jclklib_proxy - 2. In the same machine, on a second terminal , e run the test app, using client/run_test.sh on one terminal. -> this will execute the test with LD_CONFIG_PATH set using the current libptpmgmt.so - Please change the LD_CONFIG_PATH accordingly. - -### Test scenario for connect : - - 1. Proxy is not responding (i.e proxy is hang, message queue not working properly) -> in this case, by default timeout for connect is 5 sec . - - 2. Session ID is unique and incremental for a lifetime of proxy. When the proxy is restarted, the sessionID restarts at 0. - - sessionID : std::uint16_t - -## B. Subscription message - - - - +1. Run the Intel customized ptp4l application: + ```bash + cd linux-ptp_iaclocklib + sudo ./ptp4l -i + ``` + +2. Run the jclk_proxy application: + ```bash + cd libptpmgmt_iaclocklib/jclklib/proxy + sudo ./run_proxy.sh + ``` + +3. Run the sample application + ```bash + cd libptpmgmt_iaclocklib/jclklib/client + sudo ./run_jclk_test.sh + ``` + +Usage of sample application (jclk_test) : + ```bash + Options: + -s subscribe_event_mask + Default: 0xf + Bit 0: gmOffsetEvent + Bit 1: servoLockedEvent + Bit 2: asCapableEvent + Bit 3: gmChangedEvent + -c composite_event_mask + Default: 0x7 + Bit 0: gmOffsetEvent + Bit 1: servoLockedEvent + Bit 2: asCapableEvent + -u upper master offset (ns) + Default: 100000 ns + -l lower master offset (ns) + Default: -100000 ns + -t timeout in waiting notification event (s) + Default: 10 s +``` From 57da78faaab133bdfc05a9acd7a1b84db50c7afc Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 23 May 2024 16:07:02 +0800 Subject: [PATCH 110/151] jclklib: fix display issue on md Signed-off-by: Song Yoong Siang --- jclklib/TEST_jclklib.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/jclklib/TEST_jclklib.md b/jclklib/TEST_jclklib.md index 8e70c2d1..5c04ea41 100644 --- a/jclklib/TEST_jclklib.md +++ b/jclklib/TEST_jclklib.md @@ -1,6 +1,6 @@ -# The diagram of Clock Manager usage in system : +# The diagram of Clock Manager usage in system : Test app <----> client runtime(libjclk.so) <----> jclklib_proxy <----> libptpmgmt.so <----> ptp4l @@ -25,7 +25,7 @@ together with this Clock Manager application. 3. Build the application: ```bash make - ``` + ``` # How to Clone and Build the Clock Manager together with libptpmgmt: @@ -126,4 +126,5 @@ Usage of sample application (jclk_test) : Default: -100000 ns -t timeout in waiting notification event (s) Default: 10 s -``` + ``` + From 977cd63c2bb820d48bb4bcb0f59b21fdb8e3bbc6 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 23 May 2024 16:17:43 +0800 Subject: [PATCH 111/151] Remove idention from md Signed-off-by: Song Yoong Siang --- jclklib/TEST_jclklib.md | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/jclklib/TEST_jclklib.md b/jclklib/TEST_jclklib.md index 5c04ea41..57d366c3 100644 --- a/jclklib/TEST_jclklib.md +++ b/jclklib/TEST_jclklib.md @@ -107,24 +107,23 @@ reference. ``` Usage of sample application (jclk_test) : - ```bash - Options: - -s subscribe_event_mask - Default: 0xf - Bit 0: gmOffsetEvent - Bit 1: servoLockedEvent - Bit 2: asCapableEvent - Bit 3: gmChangedEvent - -c composite_event_mask - Default: 0x7 - Bit 0: gmOffsetEvent - Bit 1: servoLockedEvent - Bit 2: asCapableEvent - -u upper master offset (ns) - Default: 100000 ns - -l lower master offset (ns) - Default: -100000 ns - -t timeout in waiting notification event (s) - Default: 10 s - ``` - +```bash +Options: +-s subscribe_event_mask + Default: 0xf + Bit 0: gmOffsetEvent + Bit 1: servoLockedEvent + Bit 2: asCapableEvent + Bit 3: gmChangedEvent +-c composite_event_mask + Default: 0x7 + Bit 0: gmOffsetEvent + Bit 1: servoLockedEvent + Bit 2: asCapableEvent +-u upper master offset (ns) + Default: 100000 ns +-l lower master offset (ns) + Default: -100000 ns +-t timeout in waiting notification event (s) + Default: 10 s +``` From 268de83c2e86e2ee09208e26457b78afc4e3895f Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Thu, 23 May 2024 18:30:51 +0800 Subject: [PATCH 112/151] jclklib: Fix proxy not able to reconnect to ptp4l Fix the issue that the proxy is not aware that ptp4l is terminated and not able to reconnect to ptp4l again. Signed-off-by: Lai Peter Jun Ann --- jclklib/proxy/connect.cpp | 58 ++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 7 deletions(-) diff --git a/jclklib/proxy/connect.cpp b/jclklib/proxy/connect.cpp index c8fbce13..771ae490 100644 --- a/jclklib/proxy/connect.cpp +++ b/jclklib/proxy/connect.cpp @@ -210,6 +210,16 @@ bool event_subscription(struct jcl_handle **handle) return ret; } +bool is_ptp4l_running() { + FILE *fp; + char result[8]; + fp = popen("pgrep ptp4l", "r"); + + bool resultExists = fgets(result, sizeof(result) - 1, fp) != NULL; + pclose(fp); + return resultExists; +} + /** * @brief Runs the main event loop for handling PTP (Precision Time Protocol) events. * @@ -253,12 +263,44 @@ void *ptp4l_event_loop( void *arg) event_subscription(NULL); while (1) { - if (epoll_wait( epd, &epd_event, 1, 100) != -1) { - //if ( sk->poll(timeout_ms)) { - const auto cnt = sk->rcv(buf, bufSize); - MNG_PARSE_ERROR_e err = msg.parse(buf, cnt); - if(err == MNG_PARSE_ERROR_OK) - event_handle(); + if(is_ptp4l_running()) { + if (epoll_wait( epd, &epd_event, 1, 100) != -1) { + const auto cnt = sk->rcv(buf, bufSize); + MNG_PARSE_ERROR_e err = msg.parse(buf, cnt); + if(err == MNG_PARSE_ERROR_OK) + event_handle(); + } + } + else { + PrintError("Failed to connect to ptp4l. Retrying..."); + SockUnix *sku = new SockUnix; + sk->close(); + sku->close(); + msg.clearData(); + + //Reset TIME_STATUS_NP data when ptp4l is disconnected + pe.master_offset = 0; + memset(pe.gmIdentity, 0, sizeof(pe.gmIdentity)); + pe.servo_state = 0; + pe.asCapable = 0; + notify_client(); + + while (1) { + if(is_ptp4l_running()) { + PrintInfo("Connected to ptp4l via /var/run/ptp4l."); + std::string uds_address; + m_sk.reset(sku); + uds_address = "/var/run/ptp4l"; + if(!sku->setDefSelfAddress() || !sku->init() || + !sku->setPeerAddress(uds_address)) + fprintf(stderr, "Fail to connect to ptp4l\n"); + + sk = m_sk.get(); + event_subscription(NULL); + break; + } + sleep(2); + } } } } @@ -284,10 +326,12 @@ int Connect::connect() } m_sk.reset(sku); - while (system("ls /var/run/ptp4l*") != 0) { + while (is_ptp4l_running() != 1) { //sleep for 2 seconds and keep looping until there is ptp4l available + PrintError("Failed to connect to ptp4l. Retrying..."); sleep(2); } + PrintInfo("Connected to ptp4l via /var/run/ptp4l."); pe.ptp4l_id = 1; //TODO: hard-coded uds_socket From 29e201655bd17a6d6ae78b9dc315efedb5c8e51c Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Thu, 23 May 2024 18:38:09 +0800 Subject: [PATCH 113/151] jclklib: Change log level to INFO Signed-off-by: Lai Peter Jun Ann --- jclklib/client/msgq_tport.cpp | 4 ++-- jclklib/common/print.cpp | 2 +- jclklib/proxy/msgq_tport.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/jclklib/client/msgq_tport.cpp b/jclklib/client/msgq_tport.cpp index e4187608..077bced4 100644 --- a/jclklib/client/msgq_tport.cpp +++ b/jclklib/client/msgq_tport.cpp @@ -59,7 +59,7 @@ bool ClientMessageQueue::initTransport() mq_attr.mq_maxmsg = 2; // Two outstanding messages per client mq_attr.mq_msgsize = (decltype(mq_attr.mq_msgsize)) std::tuple_size::value; - PrintInfo("Initializing Message Queue Client Transport..."); + PrintDebug("Initializing Message Queue Client Transport..."); mqListenerName += mqProxyName + "."; mqListenerName += to_string(getpid()); mqNativeListenerDesc = mq_open(mqListenerName.c_str(), RX_QUEUE_FLAGS, RX_QUEUE_MODE, &mq_attr); @@ -90,7 +90,7 @@ bool ClientMessageQueue::initTransport() bool ClientMessageQueue::stopTransport() { - PrintInfo("Stopping Message Queue Client Transport"); + PrintDebug("Stopping Message Queue Client Transport"); PrintDebug("mqListenerName = " + mqListenerName); if (mq_unlink(mqListenerName.c_str()) == -1) PrintErrorCode("unlink failed"); diff --git a/jclklib/common/print.cpp b/jclklib/common/print.cpp index 6dff402f..13518ff7 100644 --- a/jclklib/common/print.cpp +++ b/jclklib/common/print.cpp @@ -22,7 +22,7 @@ using namespace std; using namespace JClkLibCommon; enum LogLevel { DEBUG, INFO, ERROR }; -static LogLevel currentLogLevel = ERROR; +static LogLevel currentLogLevel = INFO; void JClkLibCommon::_PrintError(std::string msg, uint16_t line, std::string file, std::string func, errno_type errnum) diff --git a/jclklib/proxy/msgq_tport.cpp b/jclklib/proxy/msgq_tport.cpp index 5f4c6d68..7978b579 100644 --- a/jclklib/proxy/msgq_tport.cpp +++ b/jclklib/proxy/msgq_tport.cpp @@ -78,7 +78,7 @@ bool ProxyMessageQueue::initTransport() mq_attr.mq_maxmsg = MAX_CLIENT_COUNT; mq_attr.mq_msgsize = (decltype(mq_attr.mq_msgsize)) std::tuple_size::value; - PrintInfo("Initializing Message Queue Proxy Transport..."); + PrintDebug("Initializing Message Queue Proxy Transport..."); mqNativeListenerDesc = mq_open(mqProxyName.c_str(), RX_QUEUE_FLAGS, RX_QUEUE_MODE, &mq_attr); if (mqNativeListenerDesc == -1) { cout << "mq_open failed " << strerror(errno) << endl; @@ -98,7 +98,7 @@ bool ProxyMessageQueue::initTransport() bool ProxyMessageQueue::stopTransport() { - PrintInfo("Stopping Message Queue Proxy Transport"); + PrintDebug("Stopping Message Queue Proxy Transport"); mq_unlink(mqProxyName.c_str()); if (mqListenerDesc != InvalidTransportWorkDesc && !InterruptWorker(mqListenerDesc)) PrintError("Interrupt worker failed"); From 19b4a7eb917e3a117f3dfb92c74abfb25f9162cd Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 23 May 2024 20:37:36 +0800 Subject: [PATCH 114/151] jclklib: sample: Add idle time argument Add idle time to represent user app busying handle other task. Signed-off-by: Song Yoong Siang --- jclklib/TEST_jclklib.md | 2 ++ jclklib/sample/jclk_test.cpp | 44 ++++++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/jclklib/TEST_jclklib.md b/jclklib/TEST_jclklib.md index 57d366c3..b2b8931b 100644 --- a/jclklib/TEST_jclklib.md +++ b/jclklib/TEST_jclklib.md @@ -124,6 +124,8 @@ Options: Default: 100000 ns -l lower master offset (ns) Default: -100000 ns +-i idle time (s) + Default: 1 s -t timeout in waiting notification event (s) Default: 10 s ``` diff --git a/jclklib/sample/jclk_test.cpp b/jclklib/sample/jclk_test.cpp index 8e5bc8eb..7fd58c2d 100644 --- a/jclklib/sample/jclk_test.cpp +++ b/jclklib/sample/jclk_test.cpp @@ -36,25 +36,26 @@ void signal_handler(int sig) int main(int argc, char *argv[]) { - int timeout = 10; - int upper_master_offset = 100000; - int lower_master_offset = -100000; - int ret = EXIT_SUCCESS; + JClkLibCommon::jcl_state_event_count eventCount = {}; JClkLibCommon::jcl_subscription sub = {}; JClkLibCommon::jcl_state jcl_state = {}; - JClkLibCommon::jcl_state_event_count eventCount = {}; + int lower_master_offset = -100000; + int upper_master_offset = 100000; + int ret = EXIT_SUCCESS; + int idle_time = 1; + int timeout = 10; + int opt; std::uint32_t event2Sub1[1] = { - ((1<jcl_status_wait(timeout, jcl_state , eventCount)) { printf("No event status changes identified in %d seconds.\n\n", timeout); - sleep(1); + printf("[jclklib] sleep for %d seconds...\n\n", idle_time); + sleep(idle_time); continue; } printf("[jclklib] Obtained data from Notification Event:\n"); @@ -260,7 +268,9 @@ int main(int argc, char *argv[]) } else { printf("\n"); } - sleep(1); + + printf("[jclklib] sleep for %d seconds...\n\n", idle_time); + sleep(idle_time); } do_exit: From d636daa75f4fe340e588defb0b9d4469373048cc Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Fri, 24 May 2024 12:17:04 +0800 Subject: [PATCH 115/151] jclklib: client: code cleanup Signed-off-by: Lai Peter Jun Ann --- jclklib/client/client_state.cpp | 128 ++++++----- jclklib/client/client_state.hpp | 72 +++--- jclklib/client/connect_msg.cpp | 56 ++--- jclklib/client/connect_msg.hpp | 81 ++++--- jclklib/client/jclk_init.cpp | 335 ++++++++++++++-------------- jclklib/client/jclk_init.hpp | 8 +- jclklib/client/message.cpp | 6 +- jclklib/client/message.hpp | 28 +-- jclklib/client/msgq_tport.cpp | 207 +++++++++-------- jclklib/client/msgq_tport.hpp | 67 +++--- jclklib/client/notification_msg.cpp | 299 +++++++++++-------------- jclklib/client/notification_msg.hpp | 78 ++++--- jclklib/client/null_msg.hpp | 22 +- jclklib/client/null_tport.cpp | 9 +- jclklib/client/null_tport.hpp | 16 +- jclklib/client/subscribe_msg.cpp | 300 ++++++++++++------------- jclklib/client/subscribe_msg.hpp | 86 +++---- jclklib/client/transport.cpp | 26 +-- jclklib/client/transport.hpp | 51 +++-- 19 files changed, 916 insertions(+), 959 deletions(-) diff --git a/jclklib/client/client_state.cpp b/jclklib/client/client_state.cpp index 119d77d6..53f2a06a 100644 --- a/jclklib/client/client_state.cpp +++ b/jclklib/client/client_state.cpp @@ -12,95 +12,115 @@ * */ -#include +#include +#include +#include + #include +#include #include -#include #include -#include -#include -#include +#include -using namespace std; using namespace JClkLibClient; using namespace JClkLibCommon; +using namespace std; ClientState::ClientState() { - connected = false; - subscribed = false; - sessionId = JClkLibCommon::InvalidSessionId; - fill(begin(clientID ), end( clientID ), 0 ); - eventState = {}; - eventStateCount = {}; - eventSub = {}; + connected = false; + subscribed = false; + sessionId = JClkLibCommon::InvalidSessionId; + fill(begin(clientID ), end( clientID ), 0 ); + eventState = {}; + eventStateCount = {}; + eventSub = {}; } ClientState::ClientState(ClientState &newState) { - connected = newState.get_connected(); - subscribed = newState.get_subscribed(); - sessionId = newState.get_sessionId(); - strcpy((char *)clientID.data(), (char *)newState.get_clientID().data()); - eventState = newState.get_eventState(); - eventStateCount = newState.get_eventStateCount(); - eventSub = newState.get_eventSub(); + connected = newState.get_connected(); + subscribed = newState.get_subscribed(); + sessionId = newState.get_sessionId(); + strcpy((char *)clientID.data(), (char *)newState.get_clientID().data()); + eventState = newState.get_eventState(); + eventStateCount = newState.get_eventStateCount(); + eventSub = newState.get_eventSub(); } void ClientState::set_clientState(ClientState &newState) { - connected = newState.get_connected(); - subscribed = newState.get_subscribed(); - sessionId = newState.get_sessionId(); - strcpy((char *)clientID.data(), (char *)newState.get_clientID().data()); - eventState = newState.get_eventState(); - eventStateCount = newState.get_eventStateCount(); - eventSub = newState.get_eventSub(); + connected = newState.get_connected(); + subscribed = newState.get_subscribed(); + sessionId = newState.get_sessionId(); + strcpy((char *)clientID.data(), (char *)newState.get_clientID().data()); + eventState = newState.get_eventState(); + eventStateCount = newState.get_eventStateCount(); + eventSub = newState.get_eventSub(); } -bool ClientState::get_connected() {return connected;} +bool ClientState::get_connected() +{ + return connected; +} -void ClientState::set_connected(bool new_state) {connected = new_state;} +void ClientState::set_connected(bool new_state) +{ + connected = new_state; +} -bool ClientState::get_subscribed() {return subscribed;} +bool ClientState::get_subscribed() +{ + return subscribed; +} -void ClientState::set_subscribed(bool subscriptionState) {subscribed = subscriptionState;} +void ClientState::set_subscribed(bool subscriptionState) +{ + subscribed = subscriptionState; +} -TransportClientId ClientState::get_clientID() { - return clientID; +TransportClientId ClientState::get_clientID() +{ + return clientID; } -void ClientState::set_clientID(TransportClientId &new_cID) { - strcpy((char *)clientID.data(), (char *)new_cID.data()); +void ClientState::set_clientID(TransportClientId &new_cID) +{ + strcpy((char *)clientID.data(), (char *)new_cID.data()); } -JClkLibCommon::jcl_state_event_count &ClientState::get_eventStateCount() { - return eventStateCount; +JClkLibCommon::jcl_state_event_count &ClientState::get_eventStateCount() +{ + return eventStateCount; } -JClkLibCommon::jcl_state &ClientState::get_eventState() { - return eventState; + +JClkLibCommon::jcl_state &ClientState::get_eventState() +{ + return eventState; } -void ClientState::set_eventStateCount(JClkLibCommon::jcl_state_event_count newCount) { - eventStateCount = newCount; +void ClientState::set_eventStateCount(JClkLibCommon::jcl_state_event_count newCount) +{ + eventStateCount = newCount; } -void ClientState::set_eventState(JClkLibCommon::jcl_state newState) { - eventState = newState; +void ClientState::set_eventState(JClkLibCommon::jcl_state newState) +{ + eventState = newState; } -string ClientState::toString() { +string ClientState::toString() +{ string name = "[ClientState::eventState]"; - name += " as_Capable = " + to_string(this->get_eventState().as_Capable); - name += " gm_changed = " + to_string(this->get_eventState().gm_changed); - name += " offset_in_range = " + to_string(this->get_eventState().offset_in_range); - name += " servo_locked = " + to_string(this->get_eventState().servo_locked); - name += "\n"; - return name; + name += " as_Capable = " + to_string(this->get_eventState().as_Capable); + name += " gm_changed = " + to_string(this->get_eventState().gm_changed); + name += " offset_in_range = " + to_string(this->get_eventState().offset_in_range); + name += " servo_locked = " + to_string(this->get_eventState().servo_locked); + name += "\n"; + return name; } -JClkLibCommon::jcl_subscription &ClientState::get_eventSub() { - return eventSub; +JClkLibCommon::jcl_subscription &ClientState::get_eventSub() +{ + return eventSub; } - -//ClientState JClkLibClient::state{}; diff --git a/jclklib/client/client_state.hpp b/jclklib/client/client_state.hpp index 0bceb080..3870f051 100644 --- a/jclklib/client/client_state.hpp +++ b/jclklib/client/client_state.hpp @@ -15,46 +15,44 @@ #ifndef PROXY_CLIENT_STATE #define PROXY_CLIENT_STATE -#include -#include -#include -#include #include #include -namespace JClkLibClient { - class ClientState { - private: - std::atomic_bool connected = false; - std::atomic_bool subscribed = false; - JClkLibCommon::sessionId_t sessionId = JClkLibCommon::InvalidSessionId; - JClkLibCommon::TransportClientId clientID = {}; - uint8_t ptp4l_id = 0; - JClkLibCommon::jcl_state eventState = {}; - JClkLibCommon::jcl_state_event_count eventStateCount ={}; - JClkLibCommon::jcl_subscription eventSub ={}; +#include +#include +#include +#include - public: - ClientState(); - ClientState (ClientState &newState); - void set_clientState(ClientState &newState); - bool get_connected(); - void set_connected(bool state); - bool get_subscribed(); - void set_subscribed(bool subscriptionState); - JClkLibCommon::TransportClientId get_clientID(); - void set_clientID(JClkLibCommon::TransportClientId &cID); - JClkLibCommon::jcl_state_event_count &get_eventStateCount(); - JClkLibCommon::jcl_state &get_eventState(); - void set_eventStateCount(JClkLibCommon::jcl_state_event_count eCount); - void set_eventState(JClkLibCommon::jcl_state eState); - std::string toString(); - JClkLibCommon::jcl_subscription &get_eventSub(); - DECLARE_ACCESSOR(sessionId); - DECLARE_ACCESSOR(ptp4l_id); - }; +namespace JClkLibClient { + class ClientState { + private: + std::atomic_bool connected = false; + std::atomic_bool subscribed = false; + JClkLibCommon::sessionId_t sessionId = JClkLibCommon::InvalidSessionId; + JClkLibCommon::TransportClientId clientID = {}; + uint8_t ptp4l_id = 0; + JClkLibCommon::jcl_state eventState = {}; + JClkLibCommon::jcl_state_event_count eventStateCount ={}; + JClkLibCommon::jcl_subscription eventSub ={}; - //extern JClkLibClient::ClientState state; + public: + ClientState(); + ClientState (ClientState &newState); + void set_clientState(ClientState &newState); + bool get_connected(); + void set_connected(bool state); + bool get_subscribed(); + void set_subscribed(bool subscriptionState); + JClkLibCommon::TransportClientId get_clientID(); + void set_clientID(JClkLibCommon::TransportClientId &cID); + JClkLibCommon::jcl_state_event_count &get_eventStateCount(); + JClkLibCommon::jcl_state &get_eventState(); + void set_eventStateCount(JClkLibCommon::jcl_state_event_count eCount); + void set_eventState(JClkLibCommon::jcl_state eState); + std::string toString(); + JClkLibCommon::jcl_subscription &get_eventSub(); + DECLARE_ACCESSOR(sessionId); + DECLARE_ACCESSOR(ptp4l_id); + }; } - -#endif/*PROXY_CLIENT_STATE*/ +#endif /* PROXY_CLIENT_STATE */ diff --git a/jclklib/client/connect_msg.cpp b/jclklib/client/connect_msg.cpp index 4ae4ce10..f35fd47f 100644 --- a/jclklib/client/connect_msg.cpp +++ b/jclklib/client/connect_msg.cpp @@ -13,9 +13,9 @@ */ #include +#include #include #include -#include using namespace JClkLibClient; using namespace JClkLibCommon; @@ -29,9 +29,9 @@ using namespace std; */ MAKE_RXBUFFER_TYPE(ClientConnectMessage::buildMessage) { - msg = new ClientConnectMessage(); + msg = new ClientConnectMessage(); - return true; + return true; } /** @brief Add client's CONNECT_MSG type and its builder to transport layer. @@ -43,28 +43,30 @@ MAKE_RXBUFFER_TYPE(ClientConnectMessage::buildMessage) */ bool ClientConnectMessage::initMessage() { - addMessageType(parseMsgMapElement_t(CONNECT_MSG, buildMessage)); - return true; + addMessageType(parseMsgMapElement_t(CONNECT_MSG, buildMessage)); + + return true; } -PARSE_RXBUFFER_TYPE(ClientConnectMessage::parseBuffer) { - JClkLibCommon::ptp_event data = {}; +PARSE_RXBUFFER_TYPE(ClientConnectMessage::parseBuffer) +{ + JClkLibCommon::ptp_event data = {}; - PrintDebug("[ClientConnectMessage]::parseBuffer "); - if(!CommonConnectMessage::parseBuffer(LxContext)) - return false; + PrintDebug("[ClientConnectMessage]::parseBuffer "); + if(!CommonConnectMessage::parseBuffer(LxContext)) + return false; - if (!PARSE_RX(FIELD, data.ptp4l_id, LxContext)) - return false; + if (!PARSE_RX(FIELD, data.ptp4l_id, LxContext)) + return false; - currentClientState->set_ptp4l_id(data.ptp4l_id); + currentClientState->set_ptp4l_id(data.ptp4l_id); - return true; + return true; } -void ClientConnectMessage::setClientState(ClientState *newClientState){ - //currentClientState.set_clientState(newClientState); - currentClientState = newClientState; +void ClientConnectMessage::setClientState(ClientState *newClientState) +{ + currentClientState = newClientState; } /** @brief process the reply for connect msg from proxy. @@ -85,19 +87,21 @@ void ClientConnectMessage::setClientState(ClientState *newClientState){ */ PROCESS_MESSAGE_TYPE(ClientConnectMessage::processMessage) { - sessionId_t newSessionId; + sessionId_t newSessionId; - PrintDebug("Processing client connect message (reply)"); + PrintDebug("Processing client connect message (reply)"); - currentClientState->set_connected(true); - currentClientState->set_sessionId(this->get_sessionId()); + currentClientState->set_connected(true); + currentClientState->set_sessionId(this->get_sessionId()); - PrintDebug("Connected with session ID: " + to_string(this->get_sessionId())); - PrintDebug("Current state.sessionId: " + to_string(currentClientState->get_sessionId())); + PrintDebug("Connected with session ID: " + + to_string(this->get_sessionId())); + PrintDebug("Current state.sessionId: " + + to_string(currentClientState->get_sessionId())); - this->set_msgAck(ACK_NONE); + this->set_msgAck(ACK_NONE); - cv.notify_one(); + cv.notify_one(); - return true; + return true; } diff --git a/jclklib/client/connect_msg.hpp b/jclklib/client/connect_msg.hpp index 3c23a847..2ba05f5a 100644 --- a/jclklib/client/connect_msg.hpp +++ b/jclklib/client/connect_msg.hpp @@ -15,50 +15,49 @@ #ifndef CLIENT_CONNECT_MSG_HPP #define CLIENT_CONNECT_MSG_HPP -#include -#include -#include #include +#include + +#include +#include namespace JClkLibClient { - class ClientConnectMessage : virtual public JClkLibCommon::CommonConnectMessage, - virtual public ClientMessage - { - private: - inline static ClientState *currentClientState; - public: - - ClientConnectMessage() : MESSAGE_CONNECT() {}; - //ClientConnectMessage(ClientState &newState); - static std::mutex cv_mtx; - static std::condition_variable cv; - - /** - * @brief process the reply for connect msg from proxy. - * @param LxContext client run-time transport listener context - * @param TxContext client run-time transport transmitter context - * @return true - */ - virtual PROCESS_MESSAGE_TYPE(processMessage); - virtual PARSE_RXBUFFER_TYPE(parseBuffer); - - /** - * @brief Create the ClientConnectMessage object - * @param msg msg structure to be fill up - * @param LxContext client run-time transport listener context - * @return true - */ - static MAKE_RXBUFFER_TYPE(buildMessage); - - /** - * @brief Add client's CONNECT_MSG type and its builder to transport layer. - * @return true - */ - static bool initMessage(); - - void setClientState(ClientState *newClientState); - }; + class ClientConnectMessage : virtual public JClkLibCommon::CommonConnectMessage, + virtual public ClientMessage + { + private: + inline static ClientState *currentClientState; + public: + ClientConnectMessage() : MESSAGE_CONNECT() {}; + static std::mutex cv_mtx; + static std::condition_variable cv; + + /** + * @brief process the reply for connect msg from proxy. + * @param LxContext client run-time transport listener context + * @param TxContext client run-time transport transmitter context + * @return true + */ + virtual PROCESS_MESSAGE_TYPE(processMessage); + virtual PARSE_RXBUFFER_TYPE(parseBuffer); + + /** + * @brief Create the ClientConnectMessage object + * @param msg msg structure to be fill up + * @param LxContext client run-time transport listener context + * @return true + */ + static MAKE_RXBUFFER_TYPE(buildMessage); + + /** + * @brief Add client's CONNECT_MSG type and its builder to transport layer. + * @return true + */ + static bool initMessage(); + + void setClientState(ClientState *newClientState); + }; } -#endif/*CLIENT_CONNECT_MSG_HPP*/ +#endif /* CLIENT_CONNECT_MSG_HPP */ diff --git a/jclklib/client/jclk_init.cpp b/jclklib/client/jclk_init.cpp index 0f1240b2..9b6441cf 100644 --- a/jclklib/client/jclk_init.cpp +++ b/jclklib/client/jclk_init.cpp @@ -12,18 +12,19 @@ * */ +#include +#include +#include +#include +#include + +#include #include #include -#include -#include #include -#include +#include #include -#include -#include -#include -#include -#include +#include #define DEFAULT_CONNECT_TIME_OUT 5 //5 sec #define DEFAULT_SUBSCRIBE_TIME_OUT 5 //5 sec @@ -37,144 +38,134 @@ std::condition_variable ClientConnectMessage::cv; std::mutex ClientSubscribeMessage::cv_mtx; std::condition_variable ClientSubscribeMessage::cv; -//extern JClkLibCommon::client_ptp_event client_ptp_data; - -//TransportClientId globalClientID; - bool JClkLibClientApi::jcl_connect() { - unsigned int timeout_sec = (unsigned int) DEFAULT_CONNECT_TIME_OUT; - Message0 connectMsg(new ClientConnectMessage()); - TransportClientId newClientID; - - ClientConnectMessage *cmsg = dynamic_cast(connectMsg.get()); - - cmsg->setClientState(&appClientState); - - //BlockStopSignal(); - if(!ClientMessage::init()) { - PrintError("Client Message Init Failed"); - return false; - } - if(!ClientTransport::init()) { - PrintError("Client Transport Init Failed"); - return false; - } - - ClientMessageQueue::writeTransportClientId(connectMsg.get()); - ClientMessageQueue::sendMessage(connectMsg.get()); - - // Wait for connection result - auto endTime = std::chrono::system_clock::now() + std::chrono::seconds(timeout_sec); - std::unique_lock lck(ClientConnectMessage::cv_mtx); - while (appClientState.get_connected() == false ) - { - auto res = ClientConnectMessage::cv.wait_until(lck, endTime); - if (res == std::cv_status::timeout) { - if (appClientState.get_connected() == false) { - PrintDebug("[CONNECT] Connect reply from proxy - timeout failure!!"); - return false; - } - } - else { - PrintDebug("[CONNECT] Connect reply received."); - } - } - - if ((cmsg != nullptr) && !(cmsg->getClientId().empty())) { - //ClientConnectMessage *cmsg = dynamic_cast(connectMsg.get()); - strcpy((char *)newClientID.data(), (char *)cmsg->getClientId().data()); - - appClientState.set_clientID(newClientID); - } - - return true; + unsigned int timeout_sec = (unsigned int) DEFAULT_CONNECT_TIME_OUT; + Message0 connectMsg(new ClientConnectMessage()); + TransportClientId newClientID; + + ClientConnectMessage *cmsg = dynamic_cast(connectMsg.get()); + + cmsg->setClientState(&appClientState); + + if(!ClientMessage::init()) { + PrintError("Client Message Init Failed"); + return false; + } + if(!ClientTransport::init()) { + PrintError("Client Transport Init Failed"); + return false; + } + + ClientMessageQueue::writeTransportClientId(connectMsg.get()); + ClientMessageQueue::sendMessage(connectMsg.get()); + + /* Wait for connection result */ + auto endTime = std::chrono::system_clock::now() + + std::chrono::seconds(timeout_sec); + std::unique_lock lck(ClientConnectMessage::cv_mtx); + while (appClientState.get_connected() == false ) + { + auto res = ClientConnectMessage::cv.wait_until(lck, endTime); + if (res == std::cv_status::timeout) { + if (appClientState.get_connected() == false) { + PrintDebug("[CONNECT] Connect reply from proxy - timeout failure!!"); + return false; + } + } else { + PrintDebug("[CONNECT] Connect reply received."); + } + } + + if ((cmsg != nullptr) && !(cmsg->getClientId().empty())) { + strcpy((char *)newClientID.data(), (char *)cmsg->getClientId().data()); + appClientState.set_clientID(newClientID); + } + + return true; } bool JClkLibClientApi::jcl_subscribe(JClkLibCommon::jcl_subscription &newSub, - JClkLibCommon::jcl_state ¤tState) + JClkLibCommon::jcl_state ¤tState) { - unsigned int timeout_sec = (unsigned int) DEFAULT_SUBSCRIBE_TIME_OUT; - - PrintDebug("[JClkLibClient]::subscribe"); - MessageX subscribeMsg(new ClientSubscribeMessage()); - - ClientSubscribeMessage *cmsg = dynamic_cast(subscribeMsg.get()); - if (cmsg == NULL) { - PrintErrorCode("[JClkLibClient::subscribe] subscribeMsg is NULL !!\n"); - return false; - } - else - PrintDebug("[JClkLibClient::subscribe] subscribeMsgcreation is OK !!\n"); - - //cmsg->setClientState(JClkLibCommon::jcl_state *newState); - cmsg->setClientState(&appClientState); - - /* Write the current event subscription */ - appClientState.get_eventSub().set_event(newSub.getc_event()); - appClientState.get_eventSub().set_value(newSub.getc_value()); - appClientState.get_eventSub().set_composite_event(newSub.getc_composite_event()); - - // This is to copy the event Mask ( same as master_offset_low ?? ) - cmsg->getSubscription().get_event().copyEventMask(newSub.get_event()); - - // Wri - strcpy((char *)cmsg->getClientId().data(), (char *)appClientState.get_clientID().data()); - cmsg->set_sessionId(appClientState.get_sessionId()); // this is where it turns to 0 - - ClientMessageQueue::writeTransportClientId(subscribeMsg.get()); - ClientMessageQueue::sendMessage(subscribeMsg.get()); - - // Wait for subscription result - auto endTime = std::chrono::system_clock::now() + std::chrono::seconds(timeout_sec); - std::unique_lock lck(ClientSubscribeMessage::cv_mtx); - while (appClientState.get_subscribed() == false ) - { - auto res = ClientSubscribeMessage::cv.wait_until(lck, endTime); - if (res == std::cv_status::timeout) { - if (appClientState.get_subscribed() == false) { - PrintDebug("[SUBSCRIBE] No reply from proxy - timeout failure!!"); - return false; - } - } - else { - PrintDebug("[SUBSCRIBE] SUBSCRIBE reply received."); - } - } - - JClkLibCommon::jcl_state jclCurrentState = appClientState.get_eventState(); - - currentState = jclCurrentState; - - return true; + unsigned int timeout_sec = (unsigned int) DEFAULT_SUBSCRIBE_TIME_OUT; + + PrintDebug("[JClkLibClient]::subscribe"); + MessageX subscribeMsg(new ClientSubscribeMessage()); + + ClientSubscribeMessage *cmsg = dynamic_cast(subscribeMsg.get()); + if (cmsg == NULL) { + PrintErrorCode("[JClkLibClient::subscribe] subscribeMsg is NULL !!\n"); + return false; + } else { + PrintDebug("[JClkLibClient::subscribe] subscribeMsgcreation is OK !!\n"); + } + + cmsg->setClientState(&appClientState); + + /* Write the current event subscription */ + appClientState.get_eventSub().set_event(newSub.getc_event()); + appClientState.get_eventSub().set_value(newSub.getc_value()); + appClientState.get_eventSub().set_composite_event(newSub.getc_composite_event()); + + /* Copy the event Mask */ + cmsg->getSubscription().get_event().copyEventMask(newSub.get_event()); + + strcpy((char *)cmsg->getClientId().data(), (char *)appClientState.get_clientID().data()); + cmsg->set_sessionId(appClientState.get_sessionId()); + + ClientMessageQueue::writeTransportClientId(subscribeMsg.get()); + ClientMessageQueue::sendMessage(subscribeMsg.get()); + + /* Wait for subscription result */ + auto endTime = std::chrono::system_clock::now() + std::chrono::seconds(timeout_sec); + std::unique_lock lck(ClientSubscribeMessage::cv_mtx); + while (appClientState.get_subscribed() == false ) + { + auto res = ClientSubscribeMessage::cv.wait_until(lck, endTime); + if (res == std::cv_status::timeout) { + if (appClientState.get_subscribed() == false) { + PrintDebug("[SUBSCRIBE] No reply from proxy - timeout failure!!"); + return false; + } + } else { + PrintDebug("[SUBSCRIBE] SUBSCRIBE reply received."); + } + } + + JClkLibCommon::jcl_state jclCurrentState = appClientState.get_eventState(); + + currentState = jclCurrentState; + + return true; } bool JClkLibClientApi::jcl_disconnect() { - bool retVal = false; + bool retVal = false; - // Send a disconnect message - if(!ClientTransport::stop()) { - PrintDebug("Client Stop Failed"); - goto done; - } - if(!ClientTransport::finalize()) { - PrintDebug("Client Finalize Failed"); - goto done; - } + /* Send a disconnect message */ + if(!ClientTransport::stop()) { + PrintDebug("Client Stop Failed"); + goto done; + } + if(!ClientTransport::finalize()) { + PrintDebug("Client Finalize Failed"); + goto done; + } - /* delete the ClientPtpEvent inside Subscription */ - ClientSubscribeMessage::deleteClientPtpEventStruct(appClientState.get_sessionId()); - /* delete the ClientState reference inside ClientNotificationMessage class */ - ClientNotificationMessage::deleteClientState(&appClientState); + /* Delete the ClientPtpEvent inside Subscription */ + ClientSubscribeMessage::deleteClientPtpEventStruct(appClientState.get_sessionId()); + /* Delete the ClientState reference inside ClientNotificationMessage class */ + ClientNotificationMessage::deleteClientState(&appClientState); - retVal = true; + retVal = true; done: - if (!retVal) - PrintError("Client Error Occured"); - return retVal; + if (!retVal) + PrintError("Client Error Occured"); + return retVal; } /** @@ -191,47 +182,49 @@ bool JClkLibClientApi::jcl_disconnect() * @return Returns true if there is event changes within the timeout period, * and false otherwise. */ -int JClkLibClientApi::jcl_status_wait(int timeout, JClkLibCommon::jcl_state &jcl_state_ref, - JClkLibCommon::jcl_state_event_count &eventCountRef) +int JClkLibClientApi::jcl_status_wait(int timeout, + JClkLibCommon::jcl_state &jcl_state_ref, + JClkLibCommon::jcl_state_event_count &eventCountRef) { - auto start = std::chrono::high_resolution_clock::now(); - auto end = (timeout == -1) ? - std::chrono::time_point::max() : - start + std::chrono::seconds(timeout); - bool event_changes_detected = false; + auto start = std::chrono::high_resolution_clock::now(); + auto end = (timeout == -1) ? + std::chrono::time_point::max() : + start + std::chrono::seconds(timeout); + bool event_changes_detected = false; - JClkLibCommon::jcl_state_event_count eventCount; - JClkLibCommon::jcl_state jcl_state; - do { - /* Get the event state and event count from the API*/ - eventCount = appClientState.get_eventStateCount(); - jcl_state = appClientState.get_eventState(); - - /* Check if any member of eventCount is non-zero */ - if (eventCount.offset_in_range_event_count || - eventCount.asCapable_event_count || - eventCount.servo_locked_event_count || - eventCount.composite_event_count || - eventCount.gm_changed_event_count) { - event_changes_detected = true; - break; - } - - /* Sleep for a short duration before the next iteration */ - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - } while (std::chrono::high_resolution_clock::now() < end); - - if (!event_changes_detected) - return false; - - /* copy out the current state */ - eventCountRef = eventCount; - jcl_state_ref = jcl_state; - - /* Reset the atomic count by reducing the corresponding eventCount */ - ClientSubscribeMessage::resetClientPtpEventStruct(appClientState.get_sessionId(), eventCount); - - appClientState.set_eventStateCount(eventCount); - - return true; + JClkLibCommon::jcl_state_event_count eventCount; + JClkLibCommon::jcl_state jcl_state; + do { + /* Get the event state and event count from the API */ + eventCount = appClientState.get_eventStateCount(); + jcl_state = appClientState.get_eventState(); + + /* Check if any member of eventCount is non-zero */ + if (eventCount.offset_in_range_event_count || + eventCount.asCapable_event_count || + eventCount.servo_locked_event_count || + eventCount.composite_event_count || + eventCount.gm_changed_event_count) { + event_changes_detected = true; + break; + } + + /* Sleep for a short duration before the next iteration */ + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + } while (std::chrono::high_resolution_clock::now() < end); + + if (!event_changes_detected) + return false; + + /* Copy out the current state */ + eventCountRef = eventCount; + jcl_state_ref = jcl_state; + + /* Reset the atomic count by reducing the corresponding eventCount */ + ClientSubscribeMessage::resetClientPtpEventStruct(appClientState.get_sessionId(), + eventCount); + + appClientState.set_eventStateCount(eventCount); + + return true; } diff --git a/jclklib/client/jclk_init.hpp b/jclklib/client/jclk_init.hpp index b4847ace..9800c782 100644 --- a/jclklib/client/jclk_init.hpp +++ b/jclklib/client/jclk_init.hpp @@ -26,12 +26,12 @@ namespace JClkLibClient { ClientState appClientState; public: JClkLibClientApi() {} - /* In case we need to init something for API. */ + /* In case we need to init something for API */ static int init() { return 0; } ClientState &getClientState() { return appClientState; } - bool jcl_connect(); - bool jcl_disconnect(); - bool jcl_subscribe(JClkLibCommon::jcl_subscription &newSub, + bool jcl_connect(); + bool jcl_disconnect(); + bool jcl_subscribe(JClkLibCommon::jcl_subscription &newSub, JClkLibCommon::jcl_state ¤tState); int jcl_status_wait(int timeout, JClkLibCommon::jcl_state &jcl_state, JClkLibCommon::jcl_state_event_count &eventCount); diff --git a/jclklib/client/message.cpp b/jclklib/client/message.cpp index 8fc0551a..1523742d 100644 --- a/jclklib/client/message.cpp +++ b/jclklib/client/message.cpp @@ -12,18 +12,18 @@ * */ +#include #include +#include #include -#include #include -#include #include using namespace JClkLibClient; bool ClientMessage::init() { - PrintDebug("Initializing Client Message"); + PrintDebug("Initializing Client Message"); return JClkLibCommon::_initMessage(); } diff --git a/jclklib/client/message.hpp b/jclklib/client/message.hpp index ffd0955b..30ab04c0 100644 --- a/jclklib/client/message.hpp +++ b/jclklib/client/message.hpp @@ -12,29 +12,29 @@ * */ +#ifndef CLIENT_MESSAGE_HPP +#define CLIENT_MESSAGE_HPP + #include #include #include -#ifndef CLIENT_MESSAGE_HPP -#define CLIENT_MESSAGE_HPP - #include #include namespace JClkLibClient { - class ClientMessage; - typedef std::shared_ptr MessageX; - typedef std::unique_ptr Message0; + class ClientMessage; + typedef std::shared_ptr MessageX; + typedef std::unique_ptr Message0; - class ClientMessage : virtual public JClkLibCommon::Message - { - protected: - ClientMessage() : JClkLibCommon::Message() {} - public: - static bool init(); - }; + class ClientMessage : virtual public JClkLibCommon::Message + { + protected: + ClientMessage() : JClkLibCommon::Message() {} + public: + static bool init(); + }; } -#endif/*CLIENT_MESSAGE_HPP*/ +#endif /* CLIENT_MESSAGE_HPP */ diff --git a/jclklib/client/msgq_tport.cpp b/jclklib/client/msgq_tport.cpp index 077bced4..e6af0819 100644 --- a/jclklib/client/msgq_tport.cpp +++ b/jclklib/client/msgq_tport.cpp @@ -12,23 +12,20 @@ * */ -#include -#include -#include - -#include -#include -#include - -#include #include - +#include #include -#include #include +#include +#include #include -#include +#include +#include +#include +#include +#include +#include using namespace JClkLibClient; using namespace JClkLibCommon; @@ -40,122 +37,120 @@ DECLARE_STATIC(ClientMessageQueue::txContext); LISTENER_CONTEXT_PROCESS_MESSAGE_TYPE(ClientMessageQueueListenerContext::processMessage) { - ClientMessage *msg = dynamic_cast(bmsg); + ClientMessage *msg = dynamic_cast(bmsg); - PrintDebug("Processing received client message"); - if (msg == NULL) { - PrintError("Wrong message type"); - return false; - } + PrintDebug("Processing received client message"); + if (msg == NULL) { + PrintError("Wrong message type"); + return false; + } - return msg->processMessage(*this,txcontext); + return msg->processMessage(*this,txcontext); } bool ClientMessageQueue::initTransport() { - struct mq_attr mq_attr; - - mq_attr.mq_flags = 0; - mq_attr.mq_maxmsg = 2; // Two outstanding messages per client - mq_attr.mq_msgsize = (decltype(mq_attr.mq_msgsize)) std::tuple_size::value; - - PrintDebug("Initializing Message Queue Client Transport..."); - mqListenerName += mqProxyName + "."; - mqListenerName += to_string(getpid()); - mqNativeListenerDesc = mq_open(mqListenerName.c_str(), RX_QUEUE_FLAGS, RX_QUEUE_MODE, &mq_attr); - if (mqNativeListenerDesc == -1) { - PrintError("Failed to open listener queue"); - return false; - } - - if (InvalidTransportWorkDesc == - (mqListenerDesc = registerWork - (move((TransportWork){MqListenerWork, - TransportWorkArg(new ClientMessageQueueListenerContext(mqNativeListenerDesc))})) )) { - PrintError("Listener Thread Unexpectedly Exited"); - return false; - } - - mqNativeClientTransmitterDesc = mq_open(mqProxyName.c_str(), TX_QUEUE_FLAGS); - if (mqNativeClientTransmitterDesc == -1) { - PrintErrorCode("Failed to open transmitter queue: " + mqProxyName); - return false; - } - txContext.reset(new ClientMessageQueueTransmitterContext(mqNativeClientTransmitterDesc)); - - PrintDebug("Client Message queue opened"); - - return true; + struct mq_attr mq_attr; + + mq_attr.mq_flags = 0; + /* Two outstanding messages per client */ + mq_attr.mq_maxmsg = 2; + mq_attr.mq_msgsize = (decltype(mq_attr.mq_msgsize)) std::tuple_size::value; + + PrintDebug("Initializing Message Queue Client Transport..."); + mqListenerName += mqProxyName + "."; + mqListenerName += to_string(getpid()); + mqNativeListenerDesc = mq_open(mqListenerName.c_str(), RX_QUEUE_FLAGS, RX_QUEUE_MODE, &mq_attr); + if (mqNativeListenerDesc == -1) { + PrintError("Failed to open listener queue"); + return false; + } + + if (InvalidTransportWorkDesc == + (mqListenerDesc = registerWork + (move((TransportWork){MqListenerWork, + TransportWorkArg(new ClientMessageQueueListenerContext(mqNativeListenerDesc))})) )) { + PrintError("Listener Thread Unexpectedly Exited"); + return false; + } + + mqNativeClientTransmitterDesc = mq_open(mqProxyName.c_str(), TX_QUEUE_FLAGS); + if (mqNativeClientTransmitterDesc == -1) { + PrintErrorCode("Failed to open transmitter queue: " + mqProxyName); + return false; + } + txContext.reset(new ClientMessageQueueTransmitterContext(mqNativeClientTransmitterDesc)); + + PrintDebug("Client Message queue opened"); + + return true; } bool ClientMessageQueue::stopTransport() { - PrintDebug("Stopping Message Queue Client Transport"); - PrintDebug("mqListenerName = " + mqListenerName); - if (mq_unlink(mqListenerName.c_str()) == -1) - PrintErrorCode("unlink failed"); - if (mqListenerDesc != InvalidTransportWorkDesc && !InterruptWorker(mqListenerDesc)) - PrintError("Interrupt worker failed"); - - return true; + PrintDebug("Stopping Message Queue Client Transport"); + PrintDebug("mqListenerName = " + mqListenerName); + if (mq_unlink(mqListenerName.c_str()) == -1) + PrintErrorCode("unlink failed"); + if (mqListenerDesc != InvalidTransportWorkDesc && !InterruptWorker(mqListenerDesc)) + PrintError("Interrupt worker failed"); + + return true; } bool ClientMessageQueue::finalizeTransport() { - PrintDebug("mqNativeListenerDesc = " + to_string(mqNativeListenerDesc)); - PrintDebug("mqNativeClientTransmitterDesc = " + to_string(mqNativeClientTransmitterDesc)); - return mq_close(mqNativeListenerDesc) != -1 && mq_close(mqNativeClientTransmitterDesc) != -1; + PrintDebug("mqNativeListenerDesc = " + to_string(mqNativeListenerDesc)); + PrintDebug("mqNativeClientTransmitterDesc = " + to_string(mqNativeClientTransmitterDesc)); + return mq_close(mqNativeListenerDesc) != -1 && mq_close(mqNativeClientTransmitterDesc) != -1; } bool ClientMessageQueue::writeTransportClientId(Message *msg) { - msgId_t msgId = msg->get_msgId(); - - switch (msgId) { - - case CONNECT_MSG : - { - ClientConnectMessage *cmsg = dynamic_cast(msg); - if (cmsg == NULL) { - PrintErrorCode("[ClientMessageQueue] ClientConnectMessage cmsg is NULL !!\n"); - return false; - } - strcpy((char *)cmsg->getClientId().data(), mqListenerName.c_str()); - break; - } - case SUBSCRIBE_MSG : - { - ClientSubscribeMessage *cmsg = dynamic_cast(msg); - if (cmsg == NULL) { - PrintErrorCode("[ClientMessageQueue] ClientSubscribeMessage cmsg is NULL !!\n"); - return false; - } - - //strcpy((char *)cmsg->getClientId().data(), (char *)state.get_clientID().data()); - //cmsg->set_sessionId(state.get_sessionId()); // this is where it turns to 0 - //printf ("[ClientMessageQueue] [SUBSCRIBE] cmsg->set_sessionId() : %d\n", cmsg->get_sessionId()); - PrintDebug("[ClientMessageQueue] [SUBSCRIBE] : subscription->event Mask : " + cmsg->getSubscription().get_event().toString()); - break; - } - default: - { - PrintErrorCode("Unknown msgID type"); - return false; - } - } - return true; + msgId_t msgId = msg->get_msgId(); + + switch (msgId) { + case CONNECT_MSG : + { + ClientConnectMessage *cmsg = dynamic_cast(msg); + if (cmsg == NULL) { + PrintErrorCode("[ClientMessageQueue] ClientConnectMessage cmsg is NULL !!\n"); + return false; + } + strcpy((char *)cmsg->getClientId().data(), mqListenerName.c_str()); + break; + } + case SUBSCRIBE_MSG : + { + ClientSubscribeMessage *cmsg = dynamic_cast(msg); + if (cmsg == NULL) { + PrintErrorCode("[ClientMessageQueue] ClientSubscribeMessage cmsg is NULL !!\n"); + return false; + } + PrintDebug("[ClientMessageQueue] [SUBSCRIBE] : subscription->event Mask : " + + cmsg->getSubscription().get_event().toString()); + break; + } + default: + { + PrintErrorCode("Unknown msgID type"); + return false; + } + } + return true; } SEND_CLIENT_MESSAGE(ClientMessageQueue::sendMessage) { - auto context = txContext.get(); + auto context = txContext.get(); - msg->presendMessage(context); + msg->presendMessage(context); - if (mq_send(mqNativeClientTransmitterDesc, (char *)context->getc_buffer().data(), context->getc_offset(), 0) == -1) { - PrintErrorCode("Failed to transmit client message"); - return false; - } - PrintDebug("[ClientMessageQueue]::sendMessage successful "); - return true; + if (mq_send(mqNativeClientTransmitterDesc, (char *)context->getc_buffer().data(), + context->getc_offset(), 0) == -1) { + PrintErrorCode("Failed to transmit client message"); + return false; + } + PrintDebug("[ClientMessageQueue]::sendMessage successful "); + return true; } diff --git a/jclklib/client/msgq_tport.hpp b/jclklib/client/msgq_tport.hpp index 474b2597..303d78e8 100644 --- a/jclklib/client/msgq_tport.hpp +++ b/jclklib/client/msgq_tport.hpp @@ -12,15 +12,14 @@ * */ +#ifndef CLIENT_MSGQ_TPORT_HPP +#define CLIENT_MSGQ_TPORT_HPP + #include -#include #include #include - #include - -#ifndef CLIENT_MSGQ_TPORT_HPP -#define CLIENT_MSGQ_TPORT_HPP +#include #include #include @@ -29,35 +28,39 @@ namespace JClkLibClient { - class ClientMessageQueueListenerContext : public JClkLibCommon::MessageQueueListenerContext - { - friend class ClientMessageQueue; + class ClientMessageQueueListenerContext : + public JClkLibCommon::MessageQueueListenerContext + { + friend class ClientMessageQueue; protected: - virtual LISTENER_CONTEXT_PROCESS_MESSAGE_TYPE(processMessage); - ClientMessageQueueListenerContext(mqd_t mqListenerDesc) : MessageQueueListenerContext(mqListenerDesc) {} - }; + virtual LISTENER_CONTEXT_PROCESS_MESSAGE_TYPE(processMessage); + ClientMessageQueueListenerContext(mqd_t mqListenerDesc) : + MessageQueueListenerContext(mqListenerDesc) {} + }; - class ClientMessageQueueTransmitterContext : public JClkLibCommon::MessageQueueTransmitterContext - { - friend class ClientMessageQueue; + class ClientMessageQueueTransmitterContext : + public JClkLibCommon::MessageQueueTransmitterContext + { + friend class ClientMessageQueue; protected: - //virtual bool processMessage(JClkLibCommon::Message *msg); - ClientMessageQueueTransmitterContext(mqd_t mqListenerDesc) : MessageQueueTransmitterContext(mqListenerDesc) {} - }; - - class ClientMessageQueue : public JClkLibCommon::MessageQueue, public ClientTransport - { - private: - static mqd_t mqNativeClientTransmitterDesc; - static std::string mqListenerName; - static std::unique_ptr txContext; - public: - static bool initTransport(); - static bool stopTransport(); - static bool finalizeTransport(); - static bool writeTransportClientId(JClkLibCommon::Message *msg); - static SEND_CLIENT_MESSAGE(sendMessage); - }; + ClientMessageQueueTransmitterContext(mqd_t mqListenerDesc) : + MessageQueueTransmitterContext(mqListenerDesc) {} + }; + + class ClientMessageQueue : public JClkLibCommon::MessageQueue, + public ClientTransport + { + private: + static mqd_t mqNativeClientTransmitterDesc; + static std::string mqListenerName; + static std::unique_ptr txContext; + public: + static bool initTransport(); + static bool stopTransport(); + static bool finalizeTransport(); + static bool writeTransportClientId(JClkLibCommon::Message *msg); + static SEND_CLIENT_MESSAGE(sendMessage); + }; } -#endif/*CLIENT_MSGQ_TPORT_HPP*/ +#endif /* CLIENT_MSGQ_TPORT_HPP */ diff --git a/jclklib/client/notification_msg.cpp b/jclklib/client/notification_msg.cpp index 58032116..3bb55b82 100644 --- a/jclklib/client/notification_msg.cpp +++ b/jclklib/client/notification_msg.cpp @@ -14,22 +14,13 @@ #include #include - -#include -#include #include +#include +#include -using namespace std; using namespace JClkLibCommon; using namespace JClkLibClient; - -/* -JClkLibCommon::client_ptp_event client_ptp_data; -JClkLibCommon::client_ptp_event composite_client_ptp_data; -JClkLibCommon::ptp_event proxy_data = {}; -JClkLibCommon::jcl_state jclCurrentState = {}; -JClkLibCommon::jcl_state_event_count jclCurrentEventCount = {}; -*/ +using namespace std; /** @brief Create the ClientNotificationMessage object * @@ -39,8 +30,8 @@ JClkLibCommon::jcl_state_event_count jclCurrentEventCount = {}; */ MAKE_RXBUFFER_TYPE(ClientNotificationMessage::buildMessage) { - msg = new ClientNotificationMessage(); - return true; + msg = new ClientNotificationMessage(); + return true; } /** @brief Add proxy's NOTIFY_MESSAGE type and its builder to transport layer. @@ -52,178 +43,148 @@ MAKE_RXBUFFER_TYPE(ClientNotificationMessage::buildMessage) */ bool ClientNotificationMessage::initMessage() { - addMessageType(parseMsgMapElement_t(NOTIFY_MESSAGE, buildMessage)); - return true; + addMessageType(parseMsgMapElement_t(NOTIFY_MESSAGE, buildMessage)); + return true; } BUILD_TXBUFFER_TYPE(ClientNotificationMessage::makeBuffer) const { - PrintDebug("[ClientNotificationMessage]::makeBuffer"); + PrintDebug("[ClientNotificationMessage]::makeBuffer"); - return true; + return true; } -void ClientNotificationMessage::addClientState(ClientState *newClientState){ - ClientStateArray.push_back(newClientState); +void ClientNotificationMessage::addClientState(ClientState *newClientState) +{ + ClientStateArray.push_back(newClientState); } -void ClientNotificationMessage::deleteClientState(ClientState *newClientState) { - ClientStateArray.erase(std::remove(ClientStateArray.begin(), \ - ClientStateArray.end(), newClientState), ClientStateArray.end()); +void ClientNotificationMessage::deleteClientState(ClientState *newClientState) +{ + ClientStateArray.erase(std::remove(ClientStateArray.begin(), + ClientStateArray.end(), newClientState), ClientStateArray.end()); } PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) { - PrintDebug("[ClientNotificationMessage]::processMessage "); - - //std::uint32_t eventSub[1]; - //state.get_eventSub().get_event().readEvent(eventSub, (std::size_t)sizeof(eventSub)); - //std::uint32_t composite_eventSub[1]; - //state.get_eventSub().get_composite_event().readEvent(composite_eventSub, (std::size_t)sizeof(composite_eventSub)); - - bool old_composite_event; - /* Need to walk thru the whole vector*/ - std::vector ::iterator it ; - - for (it=ClientStateArray.begin(); itget_eventState(); - JClkLibCommon::jcl_state_event_count &jclCurrentEventCount = currentClientState->get_eventStateCount(); - - currentClientState->get_eventSub().get_event().readEvent(eventSub, (std::size_t)sizeof(eventSub)); - currentClientState->get_eventSub().get_composite_event().readEvent(composite_eventSub, (std::size_t)sizeof(composite_eventSub)); - - /* get the correct client_ptp_data according to our current sessionID */ - JClkLibCommon::client_ptp_event* client_ptp_data = NULL; - client_ptp_data = ClientSubscribeMessage::getClientPtpEventStruct(currentClientState->get_sessionId()); - - JClkLibCommon::client_ptp_event* composite_client_ptp_data = NULL; - composite_client_ptp_data = ClientSubscribeMessage::getClientPtpEventCompositeStruct(currentClientState->get_sessionId()); - - if ( client_ptp_data == NULL ) { - printf ("ClientNotificationMessage::processMessage ERROR in obtaining client_ptp_data.\n"); - return false; - } - - if ((eventSub[0] & 1<master_offset)) { - client_ptp_data->master_offset = proxy_data.master_offset; - if ((client_ptp_data->master_offset > currentClientState->get_eventSub().get_value().getLower(gmOffsetValue)) && - (client_ptp_data->master_offset < currentClientState->get_eventSub().get_value().getUpper(gmOffsetValue))) { - if (!(client_ptp_data->master_offset_within_boundary)) - { - client_ptp_data->master_offset_within_boundary = true; - client_ptp_data->offset_event_count.fetch_add(1, std::memory_order_relaxed); - } - } - else - { - if ((client_ptp_data->master_offset_within_boundary)) - { - client_ptp_data->master_offset_within_boundary = false; - client_ptp_data->offset_event_count.fetch_add(1, std::memory_order_relaxed); - } - } - } - - if ((eventSub[0] & 1<servo_state)) { - client_ptp_data->servo_state = proxy_data.servo_state; - client_ptp_data->servo_state_event_count.fetch_add(1, std::memory_order_relaxed); - } - - if ((eventSub[0] & 1<gmIdentity, proxy_data.gmIdentity, sizeof(proxy_data.gmIdentity)) != 0)) { - memcpy(client_ptp_data->gmIdentity, proxy_data.gmIdentity, sizeof(proxy_data.gmIdentity)); - client_ptp_data->gmChanged_event_count.fetch_add(1, std::memory_order_relaxed); - jclCurrentState.gm_changed = true; - } - else { - jclCurrentState.gm_changed = false; - } - - if ((eventSub[0] & 1<asCapable)) { - client_ptp_data->asCapable = proxy_data.asCapable; - client_ptp_data->asCapable_event_count.fetch_add(1, std::memory_order_relaxed); - } - - if (composite_eventSub[0]) { - old_composite_event = composite_client_ptp_data->composite_event; - composite_client_ptp_data->composite_event = true; - } - - if (composite_eventSub[0] & 1<master_offset = proxy_data.master_offset; - if ((composite_client_ptp_data->master_offset > currentClientState->get_eventSub().get_value().getLower(gmOffsetValue)) && - (composite_client_ptp_data->master_offset < currentClientState->get_eventSub().get_value().getUpper(gmOffsetValue))) { - composite_client_ptp_data->composite_event = true; - } - else { - composite_client_ptp_data->composite_event = false; - } - } - - if (composite_eventSub[0] & 1<composite_event &= proxy_data.servo_state >= SERVO_LOCKED ? true:false; - } - - if (composite_eventSub[0] & 1<composite_event &= proxy_data.asCapable > 0 ? true:false; - } - - if (composite_eventSub[0] && (old_composite_event != composite_client_ptp_data->composite_event)) { - client_ptp_data->composite_event_count.fetch_add(1, std::memory_order_relaxed); - } - -/* - jclCurrentState.as_Capable = client_ptp_data.asCapable > 0 ? true:false; - jclCurrentState.offset_in_range = client_ptp_data.master_offset_within_boundary; - jclCurrentState.servo_locked = client_ptp_data.servo_state >= SERVO_LOCKED ? true:false; - jclCurrentState.composite_event = composite_client_ptp_data.composite_event; - memcpy(jclCurrentState.gmIdentity, client_ptp_data.gmIdentity, sizeof(client_ptp_data.gmIdentity)); -*/ - /* TODO : checked for jclCurrentState.gm_changed based on GM_identity previously stored */ - -/* - jclCurrentEventCount.offset_in_range_event_count = client_ptp_data.offset_event_count; - jclCurrentEventCount.asCapable_event_count = client_ptp_data.asCapable_event_count; - jclCurrentEventCount.servo_locked_event_count = client_ptp_data.servo_state_event_count; - jclCurrentEventCount.gm_changed_event_count = client_ptp_data.gmChanged_event_count; - jclCurrentEventCount.composite_event_count = client_ptp_data.composite_event_count; -*/ - - //state.set_eventState (jclCurrentState); - //state.set_eventStateCount (jclCurrentEventCount); - - jclCurrentState.as_Capable = client_ptp_data->asCapable > 0 ? true:false; - jclCurrentState.offset_in_range = client_ptp_data->master_offset_within_boundary; - jclCurrentState.servo_locked = client_ptp_data->servo_state >= SERVO_LOCKED ? true:false; - jclCurrentState.composite_event = composite_client_ptp_data->composite_event; - memcpy(jclCurrentState.gmIdentity, client_ptp_data->gmIdentity, sizeof(client_ptp_data->gmIdentity)); - - /* TODO : checked for jclCurrentState.gm_changed based on GM_identity previously stored */ - - jclCurrentEventCount.offset_in_range_event_count = client_ptp_data->offset_event_count; - jclCurrentEventCount.asCapable_event_count = client_ptp_data->asCapable_event_count; - jclCurrentEventCount.servo_locked_event_count = client_ptp_data->servo_state_event_count; - jclCurrentEventCount.gm_changed_event_count = client_ptp_data->gmChanged_event_count; - jclCurrentEventCount.composite_event_count = client_ptp_data->composite_event_count; - - } - - return true; + PrintDebug("[ClientNotificationMessage]::processMessage "); + + bool old_composite_event; + /* Need to walk thru the whole vector */ + std::vector ::iterator it ; + + for (it=ClientStateArray.begin(); itget_eventState(); + JClkLibCommon::jcl_state_event_count &jclCurrentEventCount = + currentClientState->get_eventStateCount(); + + currentClientState->get_eventSub().get_event().readEvent(eventSub, + (std::size_t)sizeof(eventSub)); + currentClientState->get_eventSub().get_composite_event().readEvent(composite_eventSub, + (std::size_t)sizeof(composite_eventSub)); + + /* Get the correct client_ptp_data according to our current sessionID */ + JClkLibCommon::client_ptp_event* client_ptp_data = NULL; + client_ptp_data = ClientSubscribeMessage::getClientPtpEventStruct(currentClientState->get_sessionId()); + + JClkLibCommon::client_ptp_event* composite_client_ptp_data = NULL; + composite_client_ptp_data = ClientSubscribeMessage::getClientPtpEventCompositeStruct(currentClientState->get_sessionId()); + + if ( client_ptp_data == NULL ) { + PrintDebug("ClientNotificationMessage::processMessage ERROR in obtaining client_ptp_data.\n"); + return false; + } + + if ((eventSub[0] & 1<master_offset)) { + client_ptp_data->master_offset = proxy_data.master_offset; + if ((client_ptp_data->master_offset > currentClientState->get_eventSub().get_value().getLower(gmOffsetValue)) && + (client_ptp_data->master_offset < currentClientState->get_eventSub().get_value().getUpper(gmOffsetValue))) { + if (!(client_ptp_data->master_offset_within_boundary)) { + client_ptp_data->master_offset_within_boundary = true; + client_ptp_data->offset_event_count.fetch_add(1, std::memory_order_relaxed); + } + } else { + if ((client_ptp_data->master_offset_within_boundary)) { + client_ptp_data->master_offset_within_boundary = false; + client_ptp_data->offset_event_count.fetch_add(1, std::memory_order_relaxed); + } + } + } + + if ((eventSub[0] & 1<servo_state)) { + client_ptp_data->servo_state = proxy_data.servo_state; + client_ptp_data->servo_state_event_count.fetch_add(1, std::memory_order_relaxed); + } + + if ((eventSub[0] & 1<gmIdentity, proxy_data.gmIdentity, sizeof(proxy_data.gmIdentity)) != 0)) { + memcpy(client_ptp_data->gmIdentity, proxy_data.gmIdentity, sizeof(proxy_data.gmIdentity)); + client_ptp_data->gmChanged_event_count.fetch_add(1, std::memory_order_relaxed); + jclCurrentState.gm_changed = true; + } else { + jclCurrentState.gm_changed = false; + } + + if ((eventSub[0] & 1<asCapable)) { + client_ptp_data->asCapable = proxy_data.asCapable; + client_ptp_data->asCapable_event_count.fetch_add(1, std::memory_order_relaxed); + } + + if (composite_eventSub[0]) { + old_composite_event = composite_client_ptp_data->composite_event; + composite_client_ptp_data->composite_event = true; + } + + if (composite_eventSub[0] & 1<master_offset = proxy_data.master_offset; + if ((composite_client_ptp_data->master_offset > currentClientState->get_eventSub().get_value().getLower(gmOffsetValue)) && + (composite_client_ptp_data->master_offset < currentClientState->get_eventSub().get_value().getUpper(gmOffsetValue))) { + composite_client_ptp_data->composite_event = true; + } else { + composite_client_ptp_data->composite_event = false; + } + } + + if (composite_eventSub[0] & 1<composite_event &= proxy_data.servo_state >= SERVO_LOCKED ? true:false; + + if (composite_eventSub[0] & 1<composite_event &= proxy_data.asCapable > 0 ? true:false; + + if (composite_eventSub[0] && (old_composite_event != composite_client_ptp_data->composite_event)) + client_ptp_data->composite_event_count.fetch_add(1, std::memory_order_relaxed); + + jclCurrentState.as_Capable = client_ptp_data->asCapable > 0 ? true:false; + jclCurrentState.offset_in_range = client_ptp_data->master_offset_within_boundary; + jclCurrentState.servo_locked = client_ptp_data->servo_state >= SERVO_LOCKED ? true:false; + jclCurrentState.composite_event = composite_client_ptp_data->composite_event; + memcpy(jclCurrentState.gmIdentity, client_ptp_data->gmIdentity, sizeof(client_ptp_data->gmIdentity)); + + jclCurrentEventCount.offset_in_range_event_count = client_ptp_data->offset_event_count; + jclCurrentEventCount.asCapable_event_count = client_ptp_data->asCapable_event_count; + jclCurrentEventCount.servo_locked_event_count = client_ptp_data->servo_state_event_count; + jclCurrentEventCount.gm_changed_event_count = client_ptp_data->gmChanged_event_count; + jclCurrentEventCount.composite_event_count = client_ptp_data->composite_event_count; + } + + return true; } PARSE_RXBUFFER_TYPE(ClientNotificationMessage::parseBuffer) { - PrintDebug("[ClientNotificationMessage]::parseBuffer "); - if(!Message::parseBuffer(LxContext)) - return false; + PrintDebug("[ClientNotificationMessage]::parseBuffer "); + if(!Message::parseBuffer(LxContext)) + return false; - if (!PARSE_RX(FIELD, proxy_data, LxContext)) - return false; + if (!PARSE_RX(FIELD, proxy_data, LxContext)) + return false; - return true; + return true; } diff --git a/jclklib/client/notification_msg.hpp b/jclklib/client/notification_msg.hpp index d2034236..e6fb53d8 100644 --- a/jclklib/client/notification_msg.hpp +++ b/jclklib/client/notification_msg.hpp @@ -12,53 +12,51 @@ * */ -#include - #ifndef CLIENT_NOTIFICATION_MSG_HPP #define CLIENT_NOTIFICATION_MSG_HPP +#include + #include -#include #include +#include namespace JClkLibClient { - class ClientNotificationMessage : virtual public ClientMessage, - virtual public JClkLibCommon::NotificationMessage - { - public: - virtual PROCESS_MESSAGE_TYPE(processMessage); - virtual BUILD_TXBUFFER_TYPE(makeBuffer) const; - - /** - * @brief Create the ClientNotificationMessage object - * @param msg msg structure to be fill up - * @param LxContext client transport listener context - * @return true - */ - static MAKE_RXBUFFER_TYPE(buildMessage); - - /** - * @brief Add client's NOTIFY_MESSAGE type and its builder to transport layer. - * @return true - */ - static bool initMessage(); - - virtual PARSE_RXBUFFER_TYPE(parseBuffer); - - static void addClientState(ClientState *newClientState); - static void deleteClientState(ClientState *newClientState); - - protected: - ClientNotificationMessage() : MESSAGE_NOTIFY() {} - - private: - inline static std::vector ClientStateArray; - - // proxy_data can be 1 only. it is ok. - JClkLibCommon::ptp_event proxy_data = {}; - - }; + class ClientNotificationMessage : virtual public ClientMessage, + virtual public JClkLibCommon::NotificationMessage + { + public: + virtual PROCESS_MESSAGE_TYPE(processMessage); + virtual BUILD_TXBUFFER_TYPE(makeBuffer) const; + + /** + * @brief Create the ClientNotificationMessage object + * @param msg msg structure to be fill up + * @param LxContext client transport listener context + * @return true + */ + static MAKE_RXBUFFER_TYPE(buildMessage); + + /** + * @brief Add client's NOTIFY_MESSAGE type and its builder to transport layer. + * @return true + */ + static bool initMessage(); + + virtual PARSE_RXBUFFER_TYPE(parseBuffer); + + static void addClientState(ClientState *newClientState); + static void deleteClientState(ClientState *newClientState); + + protected: + ClientNotificationMessage() : MESSAGE_NOTIFY() {} + + private: + inline static std::vector ClientStateArray; + + JClkLibCommon::ptp_event proxy_data = {}; + }; } -#endif/*CLIENT_NOTIFICATION_MSG_HPP*/ +#endif /* CLIENT_NOTIFICATION_MSG_HPP */ diff --git a/jclklib/client/null_msg.hpp b/jclklib/client/null_msg.hpp index e28c4a44..6563c076 100644 --- a/jclklib/client/null_msg.hpp +++ b/jclklib/client/null_msg.hpp @@ -12,22 +12,22 @@ * */ -#include -#include - #ifndef CLIENT_NULL_MSG_HPP #define CLIENT_NULL_MSG_HPP +#include +#include + namespace JClkLibClient { - class ClientNullMessage : public JClkLibClient::ClientMessage, + class ClientNullMessage : public JClkLibClient::ClientMessage, public JClkLibCommon::CommonNullMessage - { - protected: - public: - static bool initMessage() { return true; } - ClientNullMessage() {} - }; + { + protected: + public: + static bool initMessage() { return true; } + ClientNullMessage() {} + }; } -#endif/*CLIENT_NULL_MSG_HPP*/ +#endif /* CLIENT_NULL_MSG_HPP */ diff --git a/jclklib/client/null_tport.cpp b/jclklib/client/null_tport.cpp index 2ed82378..9d83f3a6 100644 --- a/jclklib/client/null_tport.cpp +++ b/jclklib/client/null_tport.cpp @@ -12,17 +12,16 @@ * */ +#include + #include #include -#include - using namespace JClkLibClient; using namespace std; bool NullClientTransport::sendMessage(uint8_t *buffer, size_t length) { - PrintError("NullTransport should not be used"); - return false; + PrintError("NullTransport should not be used"); + return false; } - diff --git a/jclklib/client/null_tport.hpp b/jclklib/client/null_tport.hpp index 294f2b20..c56a1b53 100644 --- a/jclklib/client/null_tport.hpp +++ b/jclklib/client/null_tport.hpp @@ -15,18 +15,18 @@ #ifndef CLIENT_NULL_TPORT_HPP #define CLIENT_NULL_TPORT_HPP +#include + #include #include -#include - namespace JClkLibClient { - class NullClientTransport : public JClkLibCommon::NullTransport - { - public: - static bool sendMessage(std::uint8_t *buffer, std::size_t length); - }; + class NullClientTransport : public JClkLibCommon::NullTransport + { + public: + static bool sendMessage(std::uint8_t *buffer, std::size_t length); + }; } -#endif/*CLIENT_NULL_TPORT_HPP*/ +#endif /* CLIENT_NULL_TPORT_HPP */ diff --git a/jclklib/client/subscribe_msg.cpp b/jclklib/client/subscribe_msg.cpp index 6266f27f..2344d18a 100644 --- a/jclklib/client/subscribe_msg.cpp +++ b/jclklib/client/subscribe_msg.cpp @@ -12,19 +12,15 @@ * */ -#include #include -#include +#include #include +#include using namespace JClkLibClient; using namespace JClkLibCommon; using namespace std; -//JClkLibCommon::client_ptp_event client_data = {}; -//JClkLibCommon::client_ptp_event composite_client_data = {}; -//JClkLibCommon::client_ptp_event client_data = {}; - /** @brief Create the ClientSubscribeMessage object * * @param msg msg structure to be fill up @@ -33,10 +29,10 @@ using namespace std; */ MAKE_RXBUFFER_TYPE(ClientSubscribeMessage::buildMessage) { - PrintDebug("[ClientSubscribeMessage]::buildMessage()"); - msg = new ClientSubscribeMessage(); + PrintDebug("[ClientSubscribeMessage]::buildMessage()"); + msg = new ClientSubscribeMessage(); - return true; + return true; } /** @brief Add client's SUBSCRIBE_MSG type and its builder to transport layer. @@ -48,86 +44,81 @@ MAKE_RXBUFFER_TYPE(ClientSubscribeMessage::buildMessage) */ bool ClientSubscribeMessage::initMessage() { - PrintDebug("[ClientSubscribeMessage]::initMessage()"); - addMessageType(parseMsgMapElement_t(SUBSCRIBE_MSG, buildMessage)); - return true; + PrintDebug("[ClientSubscribeMessage]::initMessage()"); + addMessageType(parseMsgMapElement_t(SUBSCRIBE_MSG, buildMessage)); + return true; } -void ClientSubscribeMessage::setClientState(ClientState *newClientState){ - //currentClientState.set_clientState(newClientState); - currentClientState = newClientState; - jclCurrentState = &(newClientState->get_eventState()); - +void ClientSubscribeMessage::setClientState(ClientState *newClientState) +{ + currentClientState = newClientState; + jclCurrentState = &(newClientState->get_eventState()); } +PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) +{ + JClkLibCommon::ptp_event data = {}; + + std::uint32_t eventSub[1]; + currentClientState->get_eventSub().get_event().readEvent(eventSub, + (std::size_t)sizeof(eventSub)); + + std::uint32_t composite_eventSub[1]; + currentClientState->get_eventSub().get_composite_event().readEvent(composite_eventSub, + (std::size_t)sizeof(composite_eventSub)); + + PrintDebug("[ClientSubscribeMessage]::parseBuffer "); + if(!CommonSubscribeMessage::parseBuffer(LxContext)) + return false; + + if (!PARSE_RX(FIELD, data, LxContext)) + return false; + + /* TODO : + 1. Remove the pair if the sessionID is terminated (disconnect) + 2. to move some/all processing inside the processMessage instead of here. + */ + + JClkLibCommon::sessionId_t currentSessionID = currentClientState->get_sessionId(); + std::map >::iterator it ; + JClkLibCommon::client_ptp_event* client_data , *composite_client_data; + + it = client_ptp_event_map.find(currentSessionID); + + if (it == client_ptp_event_map.end()) { + /* Creation of a new map item for this new sessionID */ + client_data = new JClkLibCommon::client_ptp_event(); + composite_client_data = new JClkLibCommon::client_ptp_event(); + + client_ptp_event_map.insert( \ + std::pair>\ + (currentSessionID,{client_data, composite_client_data})); + } else { + /* Reuse the current client data */ + client_data = it->second[0]; + composite_client_data = it->second[1]; + } -PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { - JClkLibCommon::ptp_event data = {}; - //JClkLibCommon::jcl_state jclCurrentStateLocal = *jclCurrentState; - - std::uint32_t eventSub[1]; - currentClientState->get_eventSub().get_event().readEvent(eventSub, (std::size_t)sizeof(eventSub)); + if ((eventSub[0] & 1<master_offset)) { + client_data->master_offset = data.master_offset; + if ((client_data->master_offset > currentClientState->get_eventSub().get_value().getLower(gmOffsetValue)) && + (client_data->master_offset < currentClientState->get_eventSub().get_value().getUpper(gmOffsetValue))) + client_data->master_offset_within_boundary = true; + } - std::uint32_t composite_eventSub[1]; - currentClientState->get_eventSub().get_composite_event().readEvent(composite_eventSub, (std::size_t)sizeof(composite_eventSub)); + if ((eventSub[0] & 1<servo_state)) + client_data->servo_state = data.servo_state; - PrintDebug("[ClientSubscribeMessage]::parseBuffer "); - if(!CommonSubscribeMessage::parseBuffer(LxContext)) - return false; + if ((eventSub[0] & 1<gmIdentity, data.gmIdentity, sizeof(data.gmIdentity))) != 0) { + memcpy(client_data->gmIdentity, data.gmIdentity, sizeof(data.gmIdentity)); + jclCurrentState->gm_changed = true; + } - if (!PARSE_RX(FIELD, data, LxContext)) - return false; + if ((eventSub[0] & 1<asCapable)) + client_data->asCapable = data.asCapable; - /* TODO : - 1. Remove the pair if the sessionID is terminated (disconnect) - 2. to move some/all processing inside the processMessage instead of here. - */ - - JClkLibCommon::sessionId_t currentSessionID = currentClientState->get_sessionId(); - std::map >::iterator it ; - JClkLibCommon::client_ptp_event* client_data , *composite_client_data; - - it = client_ptp_event_map.find(currentSessionID); - - if (it == client_ptp_event_map.end()) { - /* Creation of a new map item for this new sessionID */ - client_data = new JClkLibCommon::client_ptp_event(); - composite_client_data = new JClkLibCommon::client_ptp_event(); - - client_ptp_event_map.insert( \ - std::pair>\ - (currentSessionID,{client_data, composite_client_data})); - } - else { - /* Reuse the current client data */ - client_data = it->second[0]; - composite_client_data = it->second[1]; - } - - if ((eventSub[0] & 1<master_offset)) { - client_data->master_offset = data.master_offset; - if ((client_data->master_offset > currentClientState->get_eventSub().get_value().getLower(gmOffsetValue)) && - (client_data->master_offset < currentClientState->get_eventSub().get_value().getUpper(gmOffsetValue))) { - client_data->master_offset_within_boundary = true; - } - } - - if ((eventSub[0] & 1<servo_state)) { - client_data->servo_state = data.servo_state; - } - - if ((eventSub[0] & 1<gmIdentity, data.gmIdentity, sizeof(data.gmIdentity))) != 0) { - memcpy(client_data->gmIdentity, data.gmIdentity, sizeof(data.gmIdentity)); - jclCurrentState->gm_changed = true; - } - - if ((eventSub[0] & 1<asCapable)) { - client_data->asCapable = data.asCapable; - } - - if (composite_eventSub[0]) { + if (composite_eventSub[0]) composite_client_data->composite_event = true; - } if ((composite_eventSub[0] & 1<master_offset)) { composite_client_data->master_offset = data.master_offset; @@ -139,21 +130,19 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { } } - if (composite_eventSub[0] & 1<composite_event &= data.servo_state >= SERVO_LOCKED ? true:false; - } - if (composite_eventSub[0] & 1<composite_event &= data.asCapable > 0 ? true:false; - } - jclCurrentState->as_Capable = client_data->asCapable > 0 ? true:false; - jclCurrentState->offset_in_range = client_data->master_offset_within_boundary; - jclCurrentState->servo_locked = client_data->servo_state >= SERVO_LOCKED ? true:false; - jclCurrentState->composite_event = composite_client_data->composite_event; - memcpy(jclCurrentState->gmIdentity, client_data->gmIdentity, sizeof(client_data->gmIdentity)); + jclCurrentState->as_Capable = client_data->asCapable > 0 ? true:false; + jclCurrentState->offset_in_range = client_data->master_offset_within_boundary; + jclCurrentState->servo_locked = client_data->servo_state >= SERVO_LOCKED ? true:false; + jclCurrentState->composite_event = composite_client_data->composite_event; + memcpy(jclCurrentState->gmIdentity, client_data->gmIdentity, sizeof(client_data->gmIdentity)); - return true; + return true; } /** @brief process the reply for notification msg from proxy. @@ -171,99 +160,98 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) { */ PROCESS_MESSAGE_TYPE(ClientSubscribeMessage::processMessage) { + PrintDebug("[ClientSubscribeMessage]::processMessage (reply)"); - PrintDebug("[ClientSubscribeMessage]::processMessage (reply)"); + currentClientState->set_subscribed(true); - //currentClientState->set_eventState(this->getClientState()); // i cannot remember why i put this ? - currentClientState->set_subscribed(true); + /* Add the current ClientState to the notification class */ + ClientNotificationMessage::addClientState(currentClientState); + this->set_msgAck(ACK_NONE); - /* Add the current ClientState to the notification class */ - ClientNotificationMessage::addClientState(currentClientState); - this->set_msgAck(ACK_NONE); + JClkLibCommon::jcl_state jclCurrentState = currentClientState->get_eventState(); - JClkLibCommon::jcl_state jclCurrentState = currentClientState->get_eventState(); - - cv.notify_one(); - return true; + cv.notify_one(); + return true; } /* delete the client ptp event based on session ID given */ -void ClientSubscribeMessage::deleteClientPtpEventStruct(JClkLibCommon::sessionId_t sID) { +void ClientSubscribeMessage::deleteClientPtpEventStruct(JClkLibCommon::sessionId_t sID) +{ - std::map >::iterator it; - JClkLibCommon::client_ptp_event* client_data, *composite_data; + std::map >::iterator it; + JClkLibCommon::client_ptp_event* client_data, *composite_data; - it = client_ptp_event_map.find(sID); + it = client_ptp_event_map.find(sID); - if (it != client_ptp_event_map.end()) { - client_data = it->second[0]; - composite_data = it->second[1]; + if (it != client_ptp_event_map.end()) { + client_data = it->second[0]; + composite_data = it->second[1]; - delete client_data; - delete composite_data; - client_ptp_event_map.erase(it); - } - else { - PrintDebug("The item is not found in client_ptp_event_map"); - } + delete client_data; + delete composite_data; + client_ptp_event_map.erase(it); + } else { + PrintDebug("The item is not found in client_ptp_event_map"); + } } /* get the corresponding ClientPtpEvent */ -JClkLibCommon::client_ptp_event* ClientSubscribeMessage::getClientPtpEventStruct(JClkLibCommon::sessionId_t sID) { +JClkLibCommon::client_ptp_event* ClientSubscribeMessage::getClientPtpEventStruct(JClkLibCommon::sessionId_t sID) +{ - std::map >::iterator it ; - JClkLibCommon::client_ptp_event* client_data = NULL; + std::map >::iterator it ; + JClkLibCommon::client_ptp_event* client_data = NULL; - it = client_ptp_event_map.find(sID); + it = client_ptp_event_map.find(sID); - if (it != client_ptp_event_map.end()) { - client_data = it->second[0]; - } + if (it != client_ptp_event_map.end()) + client_data = it->second[0]; - return client_data; + return client_data; } /* get the corresponding ClientPtpEvent for composite */ -JClkLibCommon::client_ptp_event* ClientSubscribeMessage::getClientPtpEventCompositeStruct(JClkLibCommon::sessionId_t sID) { +JClkLibCommon::client_ptp_event* ClientSubscribeMessage::getClientPtpEventCompositeStruct(JClkLibCommon::sessionId_t sID) +{ - std::map >::iterator it ; - JClkLibCommon::client_ptp_event* client_data = NULL; + std::map >::iterator it ; + JClkLibCommon::client_ptp_event* client_data = NULL; - it = client_ptp_event_map.find(sID); + it = client_ptp_event_map.find(sID); - if (it != client_ptp_event_map.end()) { - client_data = it->second[1]; - } + if (it != client_ptp_event_map.end()) + client_data = it->second[1]; - return client_data; + return client_data; } /* reduce the corresponding eventCount */ -void ClientSubscribeMessage::resetClientPtpEventStruct(JClkLibCommon::sessionId_t sID, JClkLibCommon::jcl_state_event_count &eventCount) { - - std::map >::iterator it ; - JClkLibCommon::client_ptp_event* client_ptp_data = NULL; - - it = client_ptp_event_map.find(sID); - - if (it != client_ptp_event_map.end()) { - client_ptp_data = it->second[0]; - } - - client_ptp_data->offset_event_count.fetch_sub(eventCount.offset_in_range_event_count, - std::memory_order_relaxed); - client_ptp_data->asCapable_event_count.fetch_sub(eventCount.asCapable_event_count, - std::memory_order_relaxed); - client_ptp_data->servo_state_event_count.fetch_sub(eventCount.servo_locked_event_count, - std::memory_order_relaxed); - client_ptp_data->gmChanged_event_count.fetch_sub(eventCount.gm_changed_event_count, - std::memory_order_relaxed); - client_ptp_data->composite_event_count.fetch_sub(eventCount.composite_event_count, - std::memory_order_relaxed); - - eventCount.offset_in_range_event_count = client_ptp_data->offset_event_count; - eventCount.asCapable_event_count = client_ptp_data->asCapable_event_count; - eventCount.servo_locked_event_count = client_ptp_data->servo_state_event_count; - eventCount.gm_changed_event_count = client_ptp_data->gmChanged_event_count; - eventCount.composite_event_count = client_ptp_data->composite_event_count; +void ClientSubscribeMessage::resetClientPtpEventStruct(JClkLibCommon::sessionId_t sID, + JClkLibCommon::jcl_state_event_count &eventCount) +{ + + std::map >::iterator it ; + JClkLibCommon::client_ptp_event* client_ptp_data = NULL; + + it = client_ptp_event_map.find(sID); + + if (it != client_ptp_event_map.end()) + client_ptp_data = it->second[0]; + + client_ptp_data->offset_event_count.fetch_sub(eventCount.offset_in_range_event_count, + std::memory_order_relaxed); + client_ptp_data->asCapable_event_count.fetch_sub(eventCount.asCapable_event_count, + std::memory_order_relaxed); + client_ptp_data->servo_state_event_count.fetch_sub(eventCount.servo_locked_event_count, + std::memory_order_relaxed); + client_ptp_data->gmChanged_event_count.fetch_sub(eventCount.gm_changed_event_count, + std::memory_order_relaxed); + client_ptp_data->composite_event_count.fetch_sub(eventCount.composite_event_count, + std::memory_order_relaxed); + + eventCount.offset_in_range_event_count = client_ptp_data->offset_event_count; + eventCount.asCapable_event_count = client_ptp_data->asCapable_event_count; + eventCount.servo_locked_event_count = client_ptp_data->servo_state_event_count; + eventCount.gm_changed_event_count = client_ptp_data->gmChanged_event_count; + eventCount.composite_event_count = client_ptp_data->composite_event_count; } diff --git a/jclklib/client/subscribe_msg.hpp b/jclklib/client/subscribe_msg.hpp index d4c6d8d1..47b85659 100644 --- a/jclklib/client/subscribe_msg.hpp +++ b/jclklib/client/subscribe_msg.hpp @@ -15,62 +15,62 @@ #ifndef CLIENT_SUBSCRIBE_MSG_HPP #define CLIENT_SUBSCRIBE_MSG_HPP -#include #include +#include namespace JClkLibClient { - class ClientSubscribeMessage : virtual public JClkLibCommon::CommonSubscribeMessage, - virtual public ClientMessage - { - private: - inline static JClkLibCommon::jcl_state *jclCurrentState; - inline static ClientState *currentClientState; - //JClkLibCommon::client_ptp_event composite_client_data = {}; - inline static std::map > client_ptp_event_map; + class ClientSubscribeMessage : virtual public JClkLibCommon::CommonSubscribeMessage, + virtual public ClientMessage + { + private: + inline static JClkLibCommon::jcl_state *jclCurrentState; + inline static ClientState *currentClientState; + inline static std::map > client_ptp_event_map; - public: - ClientSubscribeMessage() : MESSAGE_SUBSCRIBE() {}; + public: + ClientSubscribeMessage() : MESSAGE_SUBSCRIBE() {}; - static std::mutex cv_mtx; - static std::condition_variable cv; - /** - * @brief process the reply for subscribe msg from proxy. - * @param LxContext client run-time transport listener context - * @param TxContext client run-time transport transmitter context - * @return true - */ - virtual PROCESS_MESSAGE_TYPE(processMessage); + static std::mutex cv_mtx; + static std::condition_variable cv; + /** + * @brief process the reply for subscribe msg from proxy. + * @param LxContext client run-time transport listener context + * @param TxContext client run-time transport transmitter context + * @return true + */ + virtual PROCESS_MESSAGE_TYPE(processMessage); - /** - * @brief Create the ClientSubscribeMessage object - * @param msg msg structure to be fill up - * @param LxContext client run-time transport listener context - * @return true - */ - static MAKE_RXBUFFER_TYPE(buildMessage); + /** + * @brief Create the ClientSubscribeMessage object + * @param msg msg structure to be fill up + * @param LxContext client run-time transport listener context + * @return true + */ + static MAKE_RXBUFFER_TYPE(buildMessage); - /** - * @brief Add client's SUBSCRIBE_MSG type and its builder to transport layer. - * @return true - */ - static bool initMessage(); + /** + * @brief Add client's SUBSCRIBE_MSG type and its builder to transport layer. + * @return true + */ + static bool initMessage(); - virtual PARSE_RXBUFFER_TYPE(parseBuffer); + virtual PARSE_RXBUFFER_TYPE(parseBuffer); - void setClientState(ClientState *newClientState); + void setClientState(ClientState *newClientState); - /* delete the corresponding map pair item */ - static void deleteClientPtpEventStruct(JClkLibCommon::sessionId_t sID); + /* Delete the corresponding map pair item */ + static void deleteClientPtpEventStruct(JClkLibCommon::sessionId_t sID); - /* get the corresponding map pair item */ - static JClkLibCommon::client_ptp_event* getClientPtpEventStruct(JClkLibCommon::sessionId_t sID); + /* Get the corresponding map pair item */ + static JClkLibCommon::client_ptp_event* getClientPtpEventStruct(JClkLibCommon::sessionId_t sID); - static JClkLibCommon::client_ptp_event* getClientPtpEventCompositeStruct(JClkLibCommon::sessionId_t sID); + static JClkLibCommon::client_ptp_event* getClientPtpEventCompositeStruct(JClkLibCommon::sessionId_t sID); - /* reduce the corresponding eventCount */ - static void resetClientPtpEventStruct(JClkLibCommon::sessionId_t sID, JClkLibCommon::jcl_state_event_count &eventCount); - }; + /* Reduce the corresponding eventCount */ + static void resetClientPtpEventStruct(JClkLibCommon::sessionId_t sID, JClkLibCommon::jcl_state_event_count &eventCount); + }; } -#endif/*CLIENT_SUBSCRIBE_MSG_HPP*/ +#endif /* CLIENT_SUBSCRIBE_MSG_HPP */ diff --git a/jclklib/client/transport.cpp b/jclklib/client/transport.cpp index d8be674f..0e84f584 100644 --- a/jclklib/client/transport.cpp +++ b/jclklib/client/transport.cpp @@ -12,9 +12,9 @@ * */ -#include -#include #include +#include +#include #include #include #include @@ -25,27 +25,27 @@ using namespace std; bool ClientTransport::init() { - if (!Transport::init()) - return false; - PrintDebug("Finished common init"); + if (!Transport::init()) + return false; + PrintDebug("Finished common init"); - return JClkLibCommon::_initTransport(); + return JClkLibCommon::_initTransport(); } bool ClientTransport::stop() { - if (!Transport::stop()) - return false; + if (!Transport::stop()) + return false; - /* Do any transport specific stop */ - return JClkLibCommon::_stopTransport(); + /* Do any transport specific stop */ + return JClkLibCommon::_stopTransport(); } bool ClientTransport::finalize() { - if (!Transport::finalize()) - return false; + if (!Transport::finalize()) + return false; - return JClkLibCommon::_finalizeTransport(); + return JClkLibCommon::_finalizeTransport(); } diff --git a/jclklib/client/transport.hpp b/jclklib/client/transport.hpp index 0ae9009e..e63737f1 100644 --- a/jclklib/client/transport.hpp +++ b/jclklib/client/transport.hpp @@ -12,41 +12,40 @@ * */ +#ifndef CLIENT_TRANSPORT_HPP +#define CLIENT_TRANSPORT_HPP + #include #include -#include -#include #include +#include #include +#include -#ifndef CLIENT_TRANSPORT_HPP -#define CLIENT_TRANSPORT_HPP - +#include #include #include -#include namespace JClkLibClient { - class ClientTransportContext : virtual public JClkLibCommon::TransportContext { - public: - virtual ~ClientTransportContext() = default; - }; - -#define SEND_CLIENT_MESSAGE(name) \ - bool name (::JClkLibCommon::Message *msg) - - class ClientTransport : public JClkLibCommon::Transport - { - protected: - static bool processMessage(JClkLibCommon::Message *msg) { return false; } - public: - static bool init(); - static bool stop(); - static bool finalize(); - static void writeTransportClientId(Message0 &msg) {} - static SEND_CLIENT_MESSAGE(sendMessage) { return false; } - }; + class ClientTransportContext : virtual public JClkLibCommon::TransportContext { + public: + virtual ~ClientTransportContext() = default; + }; + +#define SEND_CLIENT_MESSAGE(name) bool name (::JClkLibCommon::Message *msg) + + class ClientTransport : public JClkLibCommon::Transport + { + protected: + static bool processMessage(JClkLibCommon::Message *msg) { return false; } + public: + static bool init(); + static bool stop(); + static bool finalize(); + static void writeTransportClientId(Message0 &msg) {} + static SEND_CLIENT_MESSAGE(sendMessage) { return false; } + }; } -#endif/*CLIENT_TRANSPORT_HPP*/ +#endif /* CLIENT_TRANSPORT_HPP */ From b0ec133b68767553200d28e5282f48076ab04ae1 Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Fri, 24 May 2024 13:33:27 +0800 Subject: [PATCH 116/151] jclklib: common: code cleanup Signed-off-by: Lai Peter Jun Ann --- jclklib/common/connect_msg.cpp | 53 ++--- jclklib/common/connect_msg.hpp | 34 +-- jclklib/common/jclklib_import.cpp | 172 ++++++-------- jclklib/common/jclklib_import.hpp | 338 ++++++++++++++-------------- jclklib/common/jcltypes.hpp | 20 +- jclklib/common/message.cpp | 141 ++++++------ jclklib/common/message.hpp | 114 +++++----- jclklib/common/msgq_tport.cpp | 95 ++++---- jclklib/common/msgq_tport.hpp | 76 +++---- jclklib/common/notification_msg.cpp | 10 +- jclklib/common/notification_msg.hpp | 35 ++- jclklib/common/null_msg.cpp | 4 +- jclklib/common/null_msg.hpp | 20 +- jclklib/common/null_tport.hpp | 16 +- jclklib/common/print.cpp | 77 ++++--- jclklib/common/print.hpp | 29 +-- jclklib/common/serialize.hpp | 98 ++++---- jclklib/common/sighandler.cpp | 127 ++++++----- jclklib/common/sighandler.hpp | 10 +- jclklib/common/subscribe_msg.cpp | 67 +++--- jclklib/common/subscribe_msg.hpp | 45 ++-- jclklib/common/transport.cpp | 169 +++++++------- jclklib/common/transport.hpp | 174 +++++++------- jclklib/common/util.hpp | 32 ++- 24 files changed, 958 insertions(+), 998 deletions(-) diff --git a/jclklib/common/connect_msg.cpp b/jclklib/common/connect_msg.cpp index 3475b75f..16479e00 100644 --- a/jclklib/common/connect_msg.cpp +++ b/jclklib/common/connect_msg.cpp @@ -13,56 +13,57 @@ */ #include -#include #include +#include using namespace JClkLibCommon; using namespace std; string CommonConnectMessage::toString() { - string name = ExtractClassName(string(__PRETTY_FUNCTION__),string(__FUNCTION__)); - name += "\n"; - name += Message::toString(); - name += "Client ID: " + string((char *)clientId.data()) + "\n"; + string name = ExtractClassName(string(__PRETTY_FUNCTION__),string(__FUNCTION__)); + name += "\n"; + name += Message::toString(); + name += "Client ID: " + string((char *)clientId.data()) + "\n"; - return name; + return name; } -PARSE_RXBUFFER_TYPE(CommonConnectMessage::parseBuffer) { - if(!Message::parseBuffer(LxContext)) - return false; +PARSE_RXBUFFER_TYPE(CommonConnectMessage::parseBuffer) +{ + if(!Message::parseBuffer(LxContext)) + return false; - if (!PARSE_RX(FIELD, get_sessionId(), LxContext)) - return false; + if (!PARSE_RX(FIELD, get_sessionId(), LxContext)) + return false; - if (!PARSE_RX(ARRAY,clientId, LxContext)) - return false; + if (!PARSE_RX(ARRAY,clientId, LxContext)) + return false; - return true; + return true; } BUILD_TXBUFFER_TYPE(CommonConnectMessage::makeBuffer) const { - auto ret = Message::makeBuffer(TxContext); - if (!ret) - return ret; + auto ret = Message::makeBuffer(TxContext); + if (!ret) + return ret; - if (!WRITE_TX(FIELD, c_get_val_sessionId(), TxContext)) - return false; + if (!WRITE_TX(FIELD, c_get_val_sessionId(), TxContext)) + return false; - if (!WRITE_TX(ARRAY,clientId,TxContext)) - return false; + if (!WRITE_TX(ARRAY,clientId,TxContext)) + return false; - return true; + return true; } TRANSMIT_MESSAGE_TYPE(CommonConnectMessage::transmitMessage) { - PrintDebug("[CommonConnectMessage]::transmitMessage "); - if (!presendMessage(&TxContext)) - return false; + PrintDebug("[CommonConnectMessage]::transmitMessage "); + if (!presendMessage(&TxContext)) + return false; - return TxContext.sendBuffer(); + return TxContext.sendBuffer(); } diff --git a/jclklib/common/connect_msg.hpp b/jclklib/common/connect_msg.hpp index a0105baf..1219e59f 100644 --- a/jclklib/common/connect_msg.hpp +++ b/jclklib/common/connect_msg.hpp @@ -12,31 +12,31 @@ * */ -#include - #ifndef COMMON_CONNECT_MSG_HPP #define COMMON_CONNECT_MSG_HPP +#include + #include #include namespace JClkLibCommon { - class CommonConnectMessage : virtual public Message - { - private: - TransportClientId clientId; - protected: + class CommonConnectMessage : virtual public Message + { + private: + TransportClientId clientId; + protected: #define MESSAGE_CONNECT() JClkLibCommon::Message(JClkLibCommon::CONNECT_MSG) - CommonConnectMessage() : MESSAGE_CONNECT() {} - public: - TransportClientId &getClientId() { return clientId; } - virtual PARSE_RXBUFFER_TYPE(parseBuffer); - static bool registerBuild(); - virtual TRANSMIT_MESSAGE_TYPE(transmitMessage); - virtual BUILD_TXBUFFER_TYPE(makeBuffer) const; - virtual std::string toString(); - }; + CommonConnectMessage() : MESSAGE_CONNECT() {} + public: + TransportClientId &getClientId() { return clientId; } + virtual PARSE_RXBUFFER_TYPE(parseBuffer); + static bool registerBuild(); + virtual TRANSMIT_MESSAGE_TYPE(transmitMessage); + virtual BUILD_TXBUFFER_TYPE(makeBuffer) const; + virtual std::string toString(); + }; } -#endif/*COMMON_CONNECT_MSG_HPP*/ +#endif /* COMMON_CONNECT_MSG_HPP */ diff --git a/jclklib/common/jclklib_import.cpp b/jclklib/common/jclklib_import.cpp index d670991f..532dea27 100644 --- a/jclklib/common/jclklib_import.cpp +++ b/jclklib/common/jclklib_import.cpp @@ -12,202 +12,180 @@ * */ +#include + #include -#include #include - -#include +#include using namespace JClkLibCommon; using namespace std; - jcl_value::value_t::value_t() { - upper = 0; - lower = 0; + upper = 0; + lower = 0; } jcl_value::value_t::value_t(uint32_t limit) { - upper = limit; - lower = limit; + upper = limit; + lower = limit; } bool jcl_value::value_t::equal(const value_t &v) { - if (this->upper == v.upper && this->lower == v.lower) - return true; - return false; + if (this->upper == v.upper && this->lower == v.lower) + return true; + return false; } uint8_t *jcl_value::parse(uint8_t *buf, std::size_t &length) { - for(size_t i = 0; i < sizeof(value)/sizeof(value[0]) && buf != NULL; ++i) - //buf = PARSE(value[i],buf,length); - for(size_t i = 0; i < sizeof(reserved)/sizeof(reserved[0]) && buf != NULL; ++i) { - //buf = PARSE(reserved[i],buf,length); - if (!CHECK_RSV(reserved[i])) - return (uint8_t *)-1; - } - - return buf; + return buf; } uint8_t *jcl_value::write(uint8_t *buf, std::size_t &length) { - for(size_t i = 0; i < sizeof(value)/sizeof(value[0]) && buf != NULL; ++i) - buf += WRITE_FIELD(value[i],buf,length); - for(size_t i = 0; i < sizeof(reserved)/sizeof(reserved[0]) && buf != NULL; ++i) - reserved[i].zero(); + for(size_t i = 0; i < sizeof(value)/sizeof(value[0]) && buf != NULL; ++i) + buf += WRITE_FIELD(value[i],buf,length); + for(size_t i = 0; i < sizeof(reserved)/sizeof(reserved[0]) && buf != NULL; ++i) + reserved[i].zero(); - return buf; + return buf; } bool jcl_value::equal( const jcl_value &c) { - if (memcmp(this->value, c.value, sizeof(this->value)) == 0) - return true; - return false; + if (memcmp(this->value, c.value, sizeof(this->value)) == 0) + return true; + return false; } uint8_t *jcl_subscription::parse(uint8_t *buf, std::size_t &length) { - buf = event.parse(buf, length); - if (buf != NULL) - buf = value.parse(buf, length); + buf = event.parse(buf, length); + if (buf != NULL) + buf = value.parse(buf, length); - return buf; + return buf; } uint8_t *jcl_subscription::write(uint8_t *buf, std::size_t &length) { - buf = event.write(buf, length); - if (buf != NULL) - buf = value.write(buf, length); + buf = event.write(buf, length); + if (buf != NULL) + buf = value.write(buf, length); - return buf; + return buf; } int8_t jcl_event::writeEvent(uint32_t *newEvent, std::size_t newEventlength) { - if (newEvent == NULL || sizeof(event_mask) < newEventlength) { - PrintDebug("jcl_event::writeEvent failure"); - return -1; - } + if (newEvent == NULL || sizeof(event_mask) < newEventlength) { + PrintDebug("jcl_event::writeEvent failure"); + return -1; + } - memcpy(this->event_mask, newEvent , newEventlength); + memcpy(this->event_mask, newEvent , newEventlength); - return 0; + return 0; } int8_t jcl_event::readEvent(uint32_t *readEvnt, std::size_t eventLength) { - if (readEvnt == NULL || sizeof(event_mask) > eventLength) { - PrintDebug("jcl_event::readEvent failure"); - return -1; - } + if (readEvnt == NULL || sizeof(event_mask) > eventLength) { + PrintDebug("jcl_event::readEvent failure"); + return -1; + } - memcpy(readEvnt, this->event_mask, eventLength); + memcpy(readEvnt, this->event_mask, eventLength); - return 0; + return 0; } int8_t jcl_event::copyEventMask(jcl_event &newEvent) { - std::size_t newEventLength = sizeof(newEvent.getEventMask()); + std::size_t newEventLength = sizeof(newEvent.getEventMask()); - if (sizeof(event_mask) < newEventLength) { - PrintDebug("jcl_event::copyEventMask failure"); - return -1; - } + if (sizeof(event_mask) < newEventLength) { + PrintDebug("jcl_event::copyEventMask failure"); + return -1; + } - memcpy(event_mask, newEvent.event_mask , newEventLength); + memcpy(event_mask, newEvent.event_mask , newEventLength); - return 0; + return 0; } uint8_t *jcl_event::parse(uint8_t *buf, std::size_t &length) { - for(size_t i = 0; i < sizeof(event_mask)/sizeof(event_mask[0]) && buf != NULL; ++i) - //buf = PARSE(event_mask[i],buf,length); - for(size_t i = 0; i < sizeof(reserved)/sizeof(reserved[0]) && buf != NULL; ++i) { - //buf = PARSE(reserved[i],buf,length); - if (!CHECK_RSV(reserved[i])) - return (uint8_t *)-1; - } - - return buf; + return buf; } uint8_t *jcl_event::write(uint8_t *buf, std::size_t &length) { - for(size_t i = 0; i < sizeof(event_mask)/sizeof(event_mask[0]) && buf != NULL; ++i) - buf += WRITE_FIELD(event_mask[i],buf,length); - memset(reserved, 0, sizeof(reserved)); + for(size_t i = 0; i < sizeof(event_mask)/sizeof(event_mask[0]) && + buf != NULL; ++i) + buf += WRITE_FIELD(event_mask[i],buf,length); + memset(reserved, 0, sizeof(reserved)); - return buf; + return buf; } void jcl_event::zero() { - for(size_t i = 0; i < sizeof(event_mask)/sizeof(event_mask[0]); ++i) - event_mask[i] = 0; - memset(reserved, 0, sizeof(reserved)); + for(size_t i = 0; i < sizeof(event_mask)/sizeof(event_mask[0]); ++i) + event_mask[i] = 0; + memset(reserved, 0, sizeof(reserved)); } bool jcl_event::equal(const jcl_event &c) { - if (memcmp(this->event_mask, c.event_mask, sizeof(event_mask)) == 0) - return true; - return false; + if (memcmp(this->event_mask, c.event_mask, sizeof(event_mask)) == 0) + return true; + return false; } uint8_t *jcl_eventcount::parse(uint8_t *buf, std::size_t &length) { - for(size_t i = 0; i < sizeof(count)/sizeof(count[0]) && buf != NULL; ++i) - //buf = PARSE(count[i],buf,length); - for(size_t i = 0; i < sizeof(reserved)/sizeof(reserved[0]) && buf != NULL; ++i) { - //buf = PARSE(reserved[i],buf,length); - if (!CHECK_RSV(reserved[i])) - return (uint8_t *)-1; - } - - return buf; + return buf; } uint8_t *jcl_eventcount::write(uint8_t *buf, std::size_t &length) { - for(size_t i = 0; i < sizeof(count)/sizeof(count[0]) && buf != NULL; ++i) - buf += WRITE_FIELD(count[i],buf,length); - memset(reserved, 0, sizeof(reserved)); + for(size_t i = 0; i < sizeof(count)/sizeof(count[0]) && buf != NULL; ++i) + buf += WRITE_FIELD(count[i],buf,length); + memset(reserved, 0, sizeof(reserved)); - return buf; + return buf; } void jcl_eventcount::zero() { - for(size_t i = 0; i < sizeof(count)/sizeof(count[0]); ++i) - count[i] = 0; - memset(reserved, 0, sizeof(reserved)); + for(size_t i = 0; i < sizeof(count)/sizeof(count[0]); ++i) + count[i] = 0; + memset(reserved, 0, sizeof(reserved)); } bool jcl_eventcount::equal( const jcl_eventcount &ec) { - if (memcmp(this->count, ec.count, sizeof(this->count)) == 0) - return true; - return false; + if (memcmp(this->count, ec.count, sizeof(this->count)) == 0) + return true; + return false; } std::string jcl_value::toString() { - std::string name = "jcl_value : upper " + to_string (this->value->upper) + " lower : " + to_string (this->value->lower) + "\n"; - return name; + std::string name = "jcl_value : upper " + to_string (this->value->upper) + + " lower : " + to_string (this->value->lower) + "\n"; + return name; } std::string jcl_event::toString() { - std::string name = "jcl_event : event[0] = " + to_string (this->event_mask[0]) + "\n"; - return name; + std::string name = "jcl_event : event[0] = " + + to_string (this->event_mask[0]) + "\n"; + return name; } diff --git a/jclklib/common/jclklib_import.hpp b/jclklib/common/jclklib_import.hpp index e9a6e748..0d0ca391 100644 --- a/jclklib/common/jclklib_import.hpp +++ b/jclklib/common/jclklib_import.hpp @@ -12,190 +12,184 @@ * */ -#include - #ifndef JCLKLIB_IMPORT_HPP #define JCLKLIB_IMPORT_HPP +#include + #include namespace JClkLibCommon { - typedef enum : std::uint8_t - { gmOffsetValue, - valueLast } valueType; + typedef enum : std::uint8_t + { gmOffsetValue, + valueLast } valueType; #define MAX_VALUE_COUNT 12 - - /** Servo State */ -enum servoState_e { - /** - * The servo is not yet ready to track the master clock. - */ - SERVO_UNLOCKED = 0, - /** - * The servo is ready to track and requests a clock jump to - * immediately correct the estimated offset. - */ - SERVO_JUMP = 1, - /** - * The servo is tracking the master clock. - */ - SERVO_LOCKED = 2, - /** - * The Servo has stabilized. The last 'servo_num_offset_values' values - * of the estimated threshold are less than servo_offset_threshold. - */ - SERVO_LOCKED_STABLE = 3, -}; - - class jcl_value - { - private: - struct value_t { - std::int32_t upper; - std::int32_t lower; - value_t(); - value_t(uint32_t limit); - bool equal(const value_t &v); - bool operator== (const value_t &value) { return this->equal(value); } - bool operator!= (const value_t &value) { return !this->equal(value); } - void zero() { upper = 0; lower = 0; } - }; - value_t value[valueLast]; - value_t reserved[MAX_VALUE_COUNT-sizeof(value)/sizeof(value[0])]; - public: - std::uint8_t *parse(std::uint8_t *buf, std::size_t &length); - std::uint8_t *write(std::uint8_t *buf, std::size_t &length); - bool equal( const jcl_value &c); - bool operator== (const jcl_value &value) { return this->equal(value); } - bool operator!= (const jcl_value &value) { return !this->equal(value); } - // Add a method to set the upper and lower values of a specific value_t in the value array - void setValue(int index, std::int32_t upper, std::int32_t lower) { - if (index >= 0 && index < valueLast) { - value[index].upper = upper; - value[index].lower = lower; - } - } - std::int32_t getUpper(int index) { - if (index >= 0 && index < valueLast) { - return value[index].upper; - } - return 0; - } + + /** Servo State */ + enum servoState_e { + /** + * The servo is not yet ready to track the master clock. + */ + SERVO_UNLOCKED = 0, + /** + * The servo is ready to track and requests a clock jump to + * immediately correct the estimated offset. + */ + SERVO_JUMP = 1, + /** + * The servo is tracking the master clock. + */ + SERVO_LOCKED = 2, + /** + * The Servo has stabilized. The last 'servo_num_offset_values' values + * of the estimated threshold are less than servo_offset_threshold. + */ + SERVO_LOCKED_STABLE = 3, + }; + + class jcl_value + { + private: + struct value_t { + std::int32_t upper; + std::int32_t lower; + value_t(); + value_t(uint32_t limit); + bool equal(const value_t &v); + bool operator== (const value_t &value) { return this->equal(value); } + bool operator!= (const value_t &value) { return !this->equal(value); } + void zero() { upper = 0; lower = 0; } + }; + value_t value[valueLast]; + value_t reserved[MAX_VALUE_COUNT-sizeof(value)/sizeof(value[0])]; + public: + std::uint8_t *parse(std::uint8_t *buf, std::size_t &length); + std::uint8_t *write(std::uint8_t *buf, std::size_t &length); + bool equal( const jcl_value &c); + bool operator== (const jcl_value &value) { return this->equal(value); } + bool operator!= (const jcl_value &value) { return !this->equal(value); } + /* Add a method to set the upper and lower values of a specific value_t in the value array */ + void setValue(int index, std::int32_t upper, std::int32_t lower) { + if (index >= 0 && index < valueLast) { + value[index].upper = upper; + value[index].lower = lower; + } + } + std::int32_t getUpper(int index) { + if (index >= 0 && index < valueLast) + return value[index].upper; + return 0; + } - std::int32_t getLower(int index) { - if (index >= 0 && index < valueLast) { - return value[index].lower; - } - return 0; - } - std::string toString(); - }; - - /* Events clients can subscribe to */ - typedef enum : std::uint8_t - { gmOffsetEvent, servoLockedEvent, asCapableEvent, gmChangedEvent, - eventLast } eventType; + std::int32_t getLower(int index) { + if (index >= 0 && index < valueLast) + return value[index].lower; + return 0; + } + std::string toString(); + }; + + /* Events clients can subscribe to */ + typedef enum : std::uint8_t + { gmOffsetEvent, servoLockedEvent, asCapableEvent, gmChangedEvent, + eventLast } eventType; #define BITS_PER_BYTE (8) #define MAX_EVENT_COUNT (128) - class jcl_event - { - private: - std::uint32_t event_mask[eventLast/(sizeof(std::uint32_t)*BITS_PER_BYTE)+1]; - std::uint32_t reserved[MAX_EVENT_COUNT/ - sizeof(event_mask[0]*BITS_PER_BYTE) - -sizeof(event_mask)/sizeof(std::uint32_t)]; - public: - std::uint8_t *parse(std::uint8_t *buf, std::size_t &length); - std::uint8_t *write(std::uint8_t *buf, std::size_t &length); - void zero(); - bool equal( const jcl_event &c); - bool operator== (const jcl_event &event) { return this->equal(event); } - bool operator!= (const jcl_event &event) { return !this->equal(event); } - std::string toString(); - int8_t writeEvent(uint32_t *newEvent, std::size_t length); - int8_t readEvent(uint32_t *readEvnt, std::size_t length); - int8_t copyEventMask(jcl_event &newEvent); - std::uint32_t *getEventMask() { return event_mask; } - }; - - - class jcl_eventcount - { - std::uint32_t count[eventLast]; - std::uint32_t reserved[MAX_EVENT_COUNT-eventLast]; - public: - std::uint8_t *parse(std::uint8_t *buf, std::size_t &length); - std::uint8_t *write(std::uint8_t *buf, std::size_t &length); - void zero(); - bool equal(const jcl_eventcount &ec); - bool operator== (const jcl_eventcount &ec) { return this->equal(ec); } - bool operator!= (const jcl_eventcount &ec) { return !this->equal(ec); } - }; - - class jcl_subscription - { - private: - jcl_event event; - jcl_value value; - jcl_event composite_event; - public: - std::uint8_t *parse(std::uint8_t *buf, std::size_t &length); - std::uint8_t *write(std::uint8_t *buf, std::size_t &length); - - DECLARE_ACCESSOR(event); - DECLARE_ACCESSOR(value); - DECLARE_ACCESSOR(composite_event); - }; - - struct ptp_event { - int64_t master_offset; - uint8_t gmIdentity[8]; /* Grandmaster clock ID */ - int32_t asCapable; /* 802@.1AS Capable */ - uint8_t servo_state; - uint8_t ptp4l_id; - }; - - struct client_ptp_event { - int64_t master_offset; - int64_t master_offset_low; - int64_t master_offset_high; - bool master_offset_within_boundary; - uint8_t gmIdentity[8]; /* Grandmaster clock ID */ - int32_t asCapable; /* 802@.1AS Capable */ - uint8_t servo_state; - uint8_t ptp4l_id; - bool composite_event; - std::atomic offset_event_count{}; - std::atomic asCapable_event_count{}; - std::atomic servo_state_event_count{}; - std::atomic gmChanged_event_count{}; - std::atomic composite_event_count{}; - }; - - struct jcl_state - { - bool as_Capable; - bool offset_in_range; - bool servo_locked; - bool gm_changed; - bool composite_event; - uint8_t gmIdentity[8]; - }; - - struct jcl_state_event_count - { - uint64_t offset_in_range_event_count; - uint64_t gm_changed_event_count; - uint64_t asCapable_event_count; - uint64_t servo_locked_event_count; - uint64_t composite_event_count; - }; - - - + class jcl_event + { + private: + std::uint32_t event_mask[eventLast/(sizeof(std::uint32_t)*BITS_PER_BYTE)+1]; + std::uint32_t reserved[MAX_EVENT_COUNT/ + sizeof(event_mask[0]*BITS_PER_BYTE) + -sizeof(event_mask)/sizeof(std::uint32_t)]; + public: + std::uint8_t *parse(std::uint8_t *buf, std::size_t &length); + std::uint8_t *write(std::uint8_t *buf, std::size_t &length); + void zero(); + bool equal( const jcl_event &c); + bool operator== (const jcl_event &event) { return this->equal(event); } + bool operator!= (const jcl_event &event) { return !this->equal(event); } + std::string toString(); + int8_t writeEvent(uint32_t *newEvent, std::size_t length); + int8_t readEvent(uint32_t *readEvnt, std::size_t length); + int8_t copyEventMask(jcl_event &newEvent); + std::uint32_t *getEventMask() { return event_mask; } + }; + + class jcl_eventcount + { + std::uint32_t count[eventLast]; + std::uint32_t reserved[MAX_EVENT_COUNT-eventLast]; + public: + std::uint8_t *parse(std::uint8_t *buf, std::size_t &length); + std::uint8_t *write(std::uint8_t *buf, std::size_t &length); + void zero(); + bool equal(const jcl_eventcount &ec); + bool operator== (const jcl_eventcount &ec) { return this->equal(ec); } + bool operator!= (const jcl_eventcount &ec) { return !this->equal(ec); } + }; + + class jcl_subscription + { + private: + jcl_event event; + jcl_value value; + jcl_event composite_event; + public: + std::uint8_t *parse(std::uint8_t *buf, std::size_t &length); + std::uint8_t *write(std::uint8_t *buf, std::size_t &length); + + DECLARE_ACCESSOR(event); + DECLARE_ACCESSOR(value); + DECLARE_ACCESSOR(composite_event); + }; + + struct ptp_event { + int64_t master_offset; + uint8_t gmIdentity[8]; /* Grandmaster clock ID */ + int32_t asCapable; /* 802@.1AS Capable */ + uint8_t servo_state; + uint8_t ptp4l_id; + }; + + struct client_ptp_event { + int64_t master_offset; + int64_t master_offset_low; + int64_t master_offset_high; + bool master_offset_within_boundary; + uint8_t gmIdentity[8]; /* Grandmaster clock ID */ + int32_t asCapable; /* 802@.1AS Capable */ + uint8_t servo_state; + uint8_t ptp4l_id; + bool composite_event; + std::atomic offset_event_count{}; + std::atomic asCapable_event_count{}; + std::atomic servo_state_event_count{}; + std::atomic gmChanged_event_count{}; + std::atomic composite_event_count{}; + }; + + struct jcl_state + { + bool as_Capable; + bool offset_in_range; + bool servo_locked; + bool gm_changed; + bool composite_event; + uint8_t gmIdentity[8]; + }; + + struct jcl_state_event_count + { + uint64_t offset_in_range_event_count; + uint64_t gm_changed_event_count; + uint64_t asCapable_event_count; + uint64_t servo_locked_event_count; + uint64_t composite_event_count; + }; } -#endif/*JCLKLIB_IMPORT_HPP*/ +#endif /* JCLKLIB_IMPORT_HPP */ diff --git a/jclklib/common/jcltypes.hpp b/jclklib/common/jcltypes.hpp index 2235818e..0bf372ad 100644 --- a/jclklib/common/jcltypes.hpp +++ b/jclklib/common/jcltypes.hpp @@ -12,21 +12,21 @@ * */ -#include - #ifndef COMMON_JCLTYPES_HPP #define COMMON_JCLTYPES_HPP +#include + namespace JClkLibCommon { - typedef std::uint16_t sessionId_t; - static const sessionId_t InvalidSessionId = (sessionId_t)(-1); + typedef std::uint16_t sessionId_t; + static const sessionId_t InvalidSessionId = (sessionId_t)(-1); - typedef std::uint8_t msgAck_t; - enum : msgAck_t {ACK_FAIL = (msgAck_t)-1, ACK_NONE = 0, ACK_SUCCESS = 1, }; + typedef std::uint8_t msgAck_t; + enum : msgAck_t {ACK_FAIL = (msgAck_t)-1, ACK_NONE = 0, ACK_SUCCESS = 1, }; - typedef std::uint8_t msgId_t; - enum msgId : msgId_t {INVALID_MSG = (msgId_t)-1, NULL_MSG = 1, CONNECT_MSG, SUBSCRIBE_MSG, NOTIFY_MESSAGE, - DISCONNECT_MSG}; + typedef std::uint8_t msgId_t; + enum msgId : msgId_t {INVALID_MSG = (msgId_t)-1, NULL_MSG = 1, CONNECT_MSG, + SUBSCRIBE_MSG, NOTIFY_MESSAGE, DISCONNECT_MSG}; } -#endif/*COMMON_JCLTYPES_HPP*/ +#endif /* COMMON_JCLTYPES_HPP */ diff --git a/jclklib/common/message.cpp b/jclklib/common/message.cpp index b084c27b..820ec81e 100644 --- a/jclklib/common/message.cpp +++ b/jclklib/common/message.cpp @@ -12,11 +12,10 @@ * */ -#include -#include #include -#include +#include #include +#include #include using namespace JClkLibCommon; @@ -25,108 +24,108 @@ using namespace std; DECLARE_STATIC(Message::parseMsgMap); Message::Message(decltype(msgId) msgId) - { - this->msgId = msgId; - this->msgAck = ACK_NONE; - this->sessionId = InvalidSessionId; - } +{ + this->msgId = msgId; + this->msgAck = ACK_NONE; + this->sessionId = InvalidSessionId; +} string Message::ExtractClassName(string prettyFunction, string function) { - auto fpos = prettyFunction.find(function); - auto spos = fpos; - if (fpos == string::npos) - return prettyFunction; - spos = prettyFunction.rfind(" ",fpos); - ++spos; - if (spos == string::npos || spos >= fpos) - return prettyFunction; - auto ret = prettyFunction.substr(spos,fpos-spos); - while(ret.length() > 0 && ret.back() == ':') - ret.pop_back(); - return ret.length() != 0 ? ret : prettyFunction; + auto fpos = prettyFunction.find(function); + auto spos = fpos; + if (fpos == string::npos) + return prettyFunction; + spos = prettyFunction.rfind(" ",fpos); + ++spos; + if (spos == string::npos || spos >= fpos) + return prettyFunction; + auto ret = prettyFunction.substr(spos,fpos-spos); + while(ret.length() > 0 && ret.back() == ':') + ret.pop_back(); + return ret.length() != 0 ? ret : prettyFunction; } string Message::toString() { - string ret; + string ret; - ret += PRIMITIVE_TOSTRING(msgId); - ret += PRIMITIVE_TOSTRING(msgAck); + ret += PRIMITIVE_TOSTRING(msgId); + ret += PRIMITIVE_TOSTRING(msgAck); - return ret; + return ret; } BUILD_TXBUFFER_TYPE(Message::makeBuffer) const { - PrintDebug("[Message]::makeBuffer"); - if (!WRITE_TX(FIELD,msgId,TxContext)) - return false; - if (!WRITE_TX(FIELD,msgAck,TxContext)) - return false; + PrintDebug("[Message]::makeBuffer"); + if (!WRITE_TX(FIELD,msgId,TxContext)) + return false; + if (!WRITE_TX(FIELD,msgAck,TxContext)) + return false; - return true; + return true; } COMMON_PRESEND_MESSAGE_TYPE(Message::presendMessage) { - PrintDebug("[Message]::presendMessage starts"); - ctx->resetOffset(); - if (!makeBuffer(*ctx)) { - PrintError("Failed to make buffer from message object"); - return false; - } - DumpOctetArray("Sending message (length = " + to_string(ctx->getc_offset()) + "): ", ctx->getc_buffer().data(), - ctx->getc_offset()); - PrintDebug("[Message]::presendMessage successful"); - - return true; + PrintDebug("[Message]::presendMessage starts"); + ctx->resetOffset(); + if (!makeBuffer(*ctx)) { + PrintError("Failed to make buffer from message object"); + return false; + } + DumpOctetArray("Sending message (length = " + to_string(ctx->getc_offset()) + + "): ", ctx->getc_buffer().data(), ctx->getc_offset()); + PrintDebug("[Message]::presendMessage successful"); + + return true; } bool Message::addMessageType(parseMsgMapElement_t mapping) { - decltype(parseMsgMap)::size_type size = parseMsgMap.size(); - parseMsgMap.insert(mapping); - if (parseMsgMap.size() == size) - return false; + decltype(parseMsgMap)::size_type size = parseMsgMap.size(); + parseMsgMap.insert(mapping); + if (parseMsgMap.size() == size) + return false; - PrintDebug("Added message type: " + to_string(mapping.first)); + PrintDebug("Added message type: " + to_string(mapping.first)); - return true; + return true; } PARSE_RXBUFFER_TYPE(Message::parseBuffer) { - PrintDebug("[Message]::parseBuffer "); - if (!PARSE_RX(FIELD,msgId, LxContext)) - return false; - if (!PARSE_RX(FIELD,msgAck, LxContext)) - return false; + PrintDebug("[Message]::parseBuffer "); + if (!PARSE_RX(FIELD,msgId, LxContext)) + return false; + if (!PARSE_RX(FIELD,msgAck, LxContext)) + return false; - return true; + return true; } MAKE_RXBUFFER_TYPE(Message::buildMessage) { - msgId_t msgId; - decltype(parseMsgMap)::iterator it; + msgId_t msgId; + decltype(parseMsgMap)::iterator it; - if (!PARSE_RX(FIELD,msgId,LxContext)) - return false; + if (!PARSE_RX(FIELD,msgId,LxContext)) + return false; - it = parseMsgMap.find(msgId); - if (it == parseMsgMap.cend()) { - PrintError("Unknown message type " + to_string(msgId)); - return false; - } - if (!it->second(msg, LxContext)) { - PrintError("Error parsing message"); - return false; - } - LxContext.resetOffset(); - if (!msg->parseBuffer(LxContext)) - return false; - - return true; + it = parseMsgMap.find(msgId); + if (it == parseMsgMap.cend()) { + PrintError("Unknown message type " + to_string(msgId)); + return false; + } + if (!it->second(msg, LxContext)) { + PrintError("Error parsing message"); + return false; + } + LxContext.resetOffset(); + if (!msg->parseBuffer(LxContext)) + return false; + + return true; } diff --git a/jclklib/common/message.hpp b/jclklib/common/message.hpp index c75d577f..c9ce765d 100644 --- a/jclklib/common/message.hpp +++ b/jclklib/common/message.hpp @@ -12,86 +12,86 @@ * */ -#include -#include -#include - #ifndef COMMON_MESSAGE_HPP #define COMMON_MESSAGE_HPP -#include +#include +#include +#include + #include +#include namespace JClkLibCommon { - class Message; + class Message; - class TransportListenerContext; - class TransportTransmitterContext; + class TransportListenerContext; + class TransportTransmitterContext; #define MAKE_RXBUFFER_TYPE(name) bool name (Message *&msg, ::JClkLibCommon::TransportListenerContext &LxContext) - typedef std::function BuildMessage_t; + typedef std::function BuildMessage_t; - typedef std::pair parseMsgMapElement_t; + typedef std::pair parseMsgMapElement_t; - class Message - { - private: - static std::map parseMsgMap; - msgId_t msgId; - msgAck_t msgAck; - sessionId_t sessionId; - - protected: - Message(decltype(msgId) msgId); - static bool addMessageType(parseMsgMapElement_t); - static std::string ExtractClassName(std::string prettyFunction, std::string function); - public: + class Message + { + private: + static std::map parseMsgMap; + msgId_t msgId; + msgAck_t msgAck; + sessionId_t sessionId; + + protected: + Message(decltype(msgId) msgId); + static bool addMessageType(parseMsgMapElement_t); + static std::string ExtractClassName(std::string prettyFunction, std::string function); + public: #define COMMON_PRESEND_MESSAGE_TYPE(name) bool name (JClkLibCommon::TransportTransmitterContext *ctx) - COMMON_PRESEND_MESSAGE_TYPE(presendMessage); + COMMON_PRESEND_MESSAGE_TYPE(presendMessage); #define BUILD_TXBUFFER_TYPE(name) bool name (::JClkLibCommon::TransportTransmitterContext &TxContext) - static bool registerBuild(BUILD_TXBUFFER_TYPE(buildMessage)); + static bool registerBuild(BUILD_TXBUFFER_TYPE(buildMessage)); #define PROCESS_MESSAGE_TYPE(name) bool name(JClkLibCommon::TransportListenerContext &LxContext, \ - JClkLibCommon::TransportTransmitterContext *&TxContext) - virtual PROCESS_MESSAGE_TYPE(processMessage) = 0; + JClkLibCommon::TransportTransmitterContext *&TxContext) + virtual PROCESS_MESSAGE_TYPE(processMessage) = 0; #define TRANSMIT_MESSAGE_TYPE(name) bool name(JClkLibCommon::TransportTransmitterContext &TxContext) - virtual TRANSMIT_MESSAGE_TYPE(transmitMessage) = 0; + virtual TRANSMIT_MESSAGE_TYPE(transmitMessage) = 0; - static MAKE_RXBUFFER_TYPE(buildMessage); + static MAKE_RXBUFFER_TYPE(buildMessage); #define PARSE_RXBUFFER_TYPE(name) \ - bool name (::JClkLibCommon::TransportListenerContext &LxContext) - virtual PARSE_RXBUFFER_TYPE(parseBuffer); - virtual BUILD_TXBUFFER_TYPE(makeBuffer) const; + bool name (::JClkLibCommon::TransportListenerContext &LxContext) + virtual PARSE_RXBUFFER_TYPE(parseBuffer); + virtual BUILD_TXBUFFER_TYPE(makeBuffer) const; #define PRIMITIVE_TOSTRING(p) std::string(#p) + ": " + std::to_string(p) + "\n" - virtual std::string toString(); - - virtual ~Message() = default; - DECLARE_ACCESSOR(msgId); - DECLARE_ACCESSOR(msgAck); - DECLARE_ACCESSOR(sessionId); - - static bool initMessage() { return false; }; - static bool init() { return false; } - }; - - template - inline bool _initMessage() - { - return T::initMessage(); - } - - template - inline typename std::enable_if::type - _initMessage() - { - return _initMessage() && _initMessage(); - } + virtual std::string toString(); + + virtual ~Message() = default; + DECLARE_ACCESSOR(msgId); + DECLARE_ACCESSOR(msgAck); + DECLARE_ACCESSOR(sessionId); + + static bool initMessage() { return false; }; + static bool init() { return false; } + }; + + template + inline bool _initMessage() + { + return T::initMessage(); + } + + template + inline typename std::enable_if::type + _initMessage() + { + return _initMessage() && _initMessage(); + } } -#endif/*COMMON_MESSAGE_HPP*/ +#endif /* COMMON_MESSAGE_HPP */ diff --git a/jclklib/common/msgq_tport.cpp b/jclklib/common/msgq_tport.cpp index 00690e20..2fb2d6ec 100644 --- a/jclklib/common/msgq_tport.cpp +++ b/jclklib/common/msgq_tport.cpp @@ -12,22 +12,19 @@ * */ +#include +#include +#include +#include +#include +#include +#include + #include #include - +#include #include #include -#include - -#include -#include - -#include -#include -#include - -#include -#include using namespace JClkLibCommon; using namespace std; @@ -44,60 +41,62 @@ DECLARE_STATIC(MessageQueue::mqNativeListenerDesc,-1); MessageQueueListenerContext::MessageQueueListenerContext(mqd_t mqListenerDesc) { - this->mqListenerDesc = mqListenerDesc; + this->mqListenerDesc = mqListenerDesc; } MessageQueueTransmitterContext::MessageQueueTransmitterContext(mqd_t mqTransmitterDesc) { - this->mqTransmitterDesc = mqTransmitterDesc; + this->mqTransmitterDesc = mqTransmitterDesc; } int mqRecvWrapper(mqd_t mqDesc, uint8_t *data, size_t length) { - int ret; + int ret; - ret = mq_receive(mqDesc, (char *)data, length, NULL); - if (ret == -1) - return -errno; + ret = mq_receive(mqDesc, (char *)data, length, NULL); + if (ret == -1) + return -errno; - return ret; + return ret; } bool MessageQueue::MqListenerWork(TransportContext *mqListenerContext) { - MessageQueueListenerContext *context = dynamic_cast(mqListenerContext); - - if(!context) { - PrintError("Internal Error: Received inappropriate context"); - return false; // Return early since context is null and cannot be used. - } - if (context->init() && !EnableSyscallInterruptSignal()) { - PrintError("Unable to enable interrupts in work process context"); - return false; - } - - int ret = mqRecvWrapper(context->mqListenerDesc, context->get_buffer().data(), context->getc_buffer().max_size()); - if (ret < 0) { - if (ret != -EINTR) - PrintError("MQ Receive Failed",-ret); - return ret != -EINTR ? false : true; - } - PrintDebug("Receive complete"); - - DumpOctetArray("Received Message", context->getc_buffer().data(), context->getc_buffer().max_size()); - - Transport::processMessage(*context); + MessageQueueListenerContext *context = dynamic_cast(mqListenerContext); + + if(!context) { + PrintError("Internal Error: Received inappropriate context"); + return false; // Return early since context is null and cannot be used. + } + if (context->init() && !EnableSyscallInterruptSignal()) { + PrintError("Unable to enable interrupts in work process context"); + return false; + } + + int ret = mqRecvWrapper(context->mqListenerDesc, context->get_buffer().data(), + context->getc_buffer().max_size()); + if (ret < 0) { + if (ret != -EINTR) + PrintError("MQ Receive Failed",-ret); + return ret != -EINTR ? false : true; + } + PrintDebug("Receive complete"); + + DumpOctetArray("Received Message", context->getc_buffer().data(), + context->getc_buffer().max_size()); + + Transport::processMessage(*context); - return true; + return true; } SEND_BUFFER_TYPE(MessageQueueTransmitterContext::sendBuffer) { - if (mq_send(mqTransmitterDesc, (char *)get_buffer().data(), get_offset(), 0) == -1) { - PrintErrorCode("Failed to send buffer"); - mq_close(mqTransmitterDesc); - return false; - } + if (mq_send(mqTransmitterDesc, (char *)get_buffer().data(), get_offset(), 0) == -1) { + PrintErrorCode("Failed to send buffer"); + mq_close(mqTransmitterDesc); + return false; + } - return true; + return true; } diff --git a/jclklib/common/msgq_tport.hpp b/jclklib/common/msgq_tport.hpp index b4fd2b0f..19789951 100644 --- a/jclklib/common/msgq_tport.hpp +++ b/jclklib/common/msgq_tport.hpp @@ -12,17 +12,15 @@ * */ +#ifndef COMMON_MSGQ_TPORT_HPP +#define COMMON_MSGQ_TPORT_HPP + #include -#include #include #include - #include +#include -#ifndef COMMON_MSGQ_TPORT_HPP -#define COMMON_MSGQ_TPORT_HPP - -//#include #include #include @@ -34,40 +32,40 @@ namespace JClkLibCommon { - class MessageQueueListenerContext : virtual public TransportListenerContext { - friend class MessageQueue; - private: - mqd_t mqListenerDesc; - protected: - MessageQueueListenerContext(mqd_t mqListenerDesc); - public: - virtual ~MessageQueueListenerContext() = default; - }; + class MessageQueueListenerContext : virtual public TransportListenerContext { + friend class MessageQueue; + private: + mqd_t mqListenerDesc; + protected: + MessageQueueListenerContext(mqd_t mqListenerDesc); + public: + virtual ~MessageQueueListenerContext() = default; + }; - class MessageQueueTransmitterContext : virtual public TransportTransmitterContext { - friend class MessageQueue; - private: - mqd_t mqTransmitterDesc; - protected: - MessageQueueTransmitterContext(mqd_t mqTransmitterDesc); - public: - virtual ~MessageQueueTransmitterContext() = default; - virtual SEND_BUFFER_TYPE(sendBuffer); - }; + class MessageQueueTransmitterContext : virtual public TransportTransmitterContext { + friend class MessageQueue; + private: + mqd_t mqTransmitterDesc; + protected: + MessageQueueTransmitterContext(mqd_t mqTransmitterDesc); + public: + virtual ~MessageQueueTransmitterContext() = default; + virtual SEND_BUFFER_TYPE(sendBuffer); + }; - class MessageQueue : public Transport - { - protected: - static std::string const mqProxyName; - static TransportWorkDesc mqListenerDesc; - static mqd_t mqNativeListenerDesc; - static bool MqListenerWork(TransportContext *mqListenerContext); - static bool MqTransmit(TransportContext *mqTransmitterContext, Message *msg); - public: - static bool initTransport() { return true; }; - static bool stopTransport() { return true; }; - static bool finalizeTransport() { return true; }; - }; + class MessageQueue : public Transport + { + protected: + static std::string const mqProxyName; + static TransportWorkDesc mqListenerDesc; + static mqd_t mqNativeListenerDesc; + static bool MqListenerWork(TransportContext *mqListenerContext); + static bool MqTransmit(TransportContext *mqTransmitterContext, Message *msg); + public: + static bool initTransport() { return true; }; + static bool stopTransport() { return true; }; + static bool finalizeTransport() { return true; }; + }; } -#endif/*COMMON_MSGQ_TPORT_HPP*/ +#endif /* COMMON_MSGQ_TPORT_HPP */ diff --git a/jclklib/common/notification_msg.cpp b/jclklib/common/notification_msg.cpp index c2a085c1..30c56841 100644 --- a/jclklib/common/notification_msg.cpp +++ b/jclklib/common/notification_msg.cpp @@ -12,18 +12,18 @@ * */ -#include #include #include +#include using namespace JClkLibCommon; using namespace std; TRANSMIT_MESSAGE_TYPE(NotificationMessage::transmitMessage) { - PrintDebug("[NotificationMessage]::transmitMessage "); - if (!presendMessage(&TxContext)) - return false; + PrintDebug("[NotificationMessage]::transmitMessage "); + if (!presendMessage(&TxContext)) + return false; - return TxContext.sendBuffer(); + return TxContext.sendBuffer(); } diff --git a/jclklib/common/notification_msg.hpp b/jclklib/common/notification_msg.hpp index a80ae432..0cfe7238 100644 --- a/jclklib/common/notification_msg.hpp +++ b/jclklib/common/notification_msg.hpp @@ -12,34 +12,29 @@ * */ -#include - #ifndef COMMON_NOTIFICATION_MSG_HPP #define COMMON_NOTIFICATION_MSG_HPP -#include +#include + #include +#include #include namespace JClkLibCommon { - class NotificationMessage : virtual public Message - { - public: - virtual TRANSMIT_MESSAGE_TYPE(transmitMessage); - static msgId_t getMsgId() { return SUBSCRIBE_MSG; } - - //const jcl_eventcount &getEventCount(); - //const jcl_event &getEvent(); - bool isEnable() { return waitEnable == 0x1; } - protected: + class NotificationMessage : virtual public Message + { + public: + virtual TRANSMIT_MESSAGE_TYPE(transmitMessage); + static msgId_t getMsgId() { return SUBSCRIBE_MSG; } + bool isEnable() { return waitEnable == 0x1; } + protected: #define MESSAGE_NOTIFY() JClkLibCommon::Message(JClkLibCommon::NOTIFY_MESSAGE) - NotificationMessage() : MESSAGE_NOTIFY() , waitEnable(0) {} - private: - std::uint32_t waitEnable :1; - //jcl_event event; - //jcl_eventcount eventCount; - }; + NotificationMessage() : MESSAGE_NOTIFY() , waitEnable(0) {} + private: + std::uint32_t waitEnable :1; + }; } -#endif/*COMMON_NOTIFICATION_MSG_HPP*/ +#endif /* COMMON_NOTIFICATION_MSG_HPP */ diff --git a/jclklib/common/null_msg.cpp b/jclklib/common/null_msg.cpp index f13e36e8..fdcffbd4 100644 --- a/jclklib/common/null_msg.cpp +++ b/jclklib/common/null_msg.cpp @@ -19,10 +19,10 @@ using namespace std; MAKE_RXBUFFER_TYPE(CommonNullMessage::buildMessage) { - return true; + return true; } bool CommonNullMessage::initMessage() { - return true; + return true; } diff --git a/jclklib/common/null_msg.hpp b/jclklib/common/null_msg.hpp index 990aad9f..8d469977 100644 --- a/jclklib/common/null_msg.hpp +++ b/jclklib/common/null_msg.hpp @@ -19,16 +19,16 @@ namespace JClkLibCommon { - class CommonNullMessage : virtual public Message - { - protected: - public: - static msgId_t getMsgId() { return NULL_MSG; } - static MAKE_RXBUFFER_TYPE(buildMessage); + class CommonNullMessage : virtual public Message + { + protected: + public: + static msgId_t getMsgId() { return NULL_MSG; } + static MAKE_RXBUFFER_TYPE(buildMessage); #define MESSAGE_NULL() JClkLibCommon::Message(JClkLibCommon::NULL_MSG) - CommonNullMessage() : MESSAGE_NULL() {}; - static bool initMessage(); - }; + CommonNullMessage() : MESSAGE_NULL() {}; + static bool initMessage(); + }; } -#endif/*COMMON_NULL_MSG_HPP*/ +#endif /* COMMON_NULL_MSG_HPP */ diff --git a/jclklib/common/null_tport.hpp b/jclklib/common/null_tport.hpp index 8ca25e6b..5093a510 100644 --- a/jclklib/common/null_tport.hpp +++ b/jclklib/common/null_tport.hpp @@ -21,13 +21,13 @@ namespace JClkLibCommon { - class NullTransport : public Transport - { - public: - static bool initTransport() { return true; } - static bool stopTransport() { return true; } - static bool finalizeTransport() { return true; } - }; + class NullTransport : public Transport + { + public: + static bool initTransport() { return true; } + static bool stopTransport() { return true; } + static bool finalizeTransport() { return true; } + }; } -#endif/*NULL_TPORT_HPP*/ +#endif /* NULL_TPORT_HPP */ diff --git a/jclklib/common/print.cpp b/jclklib/common/print.cpp index 13518ff7..df4fd31f 100644 --- a/jclklib/common/print.cpp +++ b/jclklib/common/print.cpp @@ -14,69 +14,68 @@ #include -#include #include #include +#include -using namespace std; using namespace JClkLibCommon; +using namespace std; enum LogLevel { DEBUG, INFO, ERROR }; static LogLevel currentLogLevel = INFO; void JClkLibCommon::_PrintError(std::string msg, uint16_t line, std::string file, std::string func, - errno_type errnum) + errno_type errnum) { - cerr << "*** Error: " + msg + " " + (errnum != (errno_type)-1 ? strerror(errnum) : "") + " at line " + to_string(line) + - " in " + file + ":" + func + "\n"; - cerr.flush(); + cerr << "*** Error: " + msg + " " + (errnum != (errno_type)-1 ? strerror(errnum) : "") + " at line " + to_string(line) + + " in " + file + ":" + func + "\n"; + cerr.flush(); } void JClkLibCommon::_PrintDebug(std::string msg, uint16_t line, std::string file, std::string func) { - if (currentLogLevel <= DEBUG) { - cerr << "** Debug: " + msg + " at line " + to_string(line) + " in " + file + ":" + func + "\n"; - cerr.flush(); - } + if (currentLogLevel <= DEBUG) { + cerr << "** Debug: " + msg + " at line " + to_string(line) + " in " + file + ":" + func + "\n"; + cerr.flush(); + } } void JClkLibCommon::_PrintInfo(std::string msg, uint16_t line, std::string file, std::string func) { - if (currentLogLevel <= INFO) { - cerr << "* Info: " + msg + " at line " + to_string(line) + " in " + file + ":" + func + "\n"; - cerr.flush(); - } + if (currentLogLevel <= INFO) { + cerr << "* Info: " + msg + " at line " + to_string(line) + " in " + file + ":" + func + "\n"; + cerr.flush(); + } } #define HEX_DIGITS_PER_LINE 16 void JClkLibCommon::_DumpOctetArray(string msg, const uint8_t *arr, size_t length, uint16_t line, string file, string func) { - const uint8_t *index = arr; - size_t offset; - stringstream output; - bool addspc = false, addcr; + const uint8_t *index = arr; + size_t offset; + stringstream output; + bool addspc = false, addcr; - if (currentLogLevel > DEBUG) { - return; - } + if (currentLogLevel > DEBUG) + return; - output << "* Info: " << msg << " at line " << to_string(line) << " in " << file << ":" << func << "\n"; + output << "* Info: " << msg << " at line " << to_string(line) << " in " << file << ":" << func << "\n"; - while ((offset = (index - arr)) < length) { - if (addspc) - output << " "; - output << "0x" << setfill('0') << setw(2) << std::hex << int(*index++); - if (offset % HEX_DIGITS_PER_LINE != HEX_DIGITS_PER_LINE-1) { - addspc = true; - addcr = true; - } else { - addspc = false; - addcr = false; - output << "\n"; - } - } - if (addcr) - output << "\n"; - cerr << output.str(); - cerr.flush(); + while ((offset = (index - arr)) < length) { + if (addspc) + output << " "; + output << "0x" << setfill('0') << setw(2) << std::hex << int(*index++); + if (offset % HEX_DIGITS_PER_LINE != HEX_DIGITS_PER_LINE-1) { + addspc = true; + addcr = true; + } else { + addspc = false; + addcr = false; + output << "\n"; + } + } + if (addcr) + output << "\n"; + cerr << output.str(); + cerr.flush(); } diff --git a/jclklib/common/print.hpp b/jclklib/common/print.hpp index 65048f2c..eada5bb0 100644 --- a/jclklib/common/print.hpp +++ b/jclklib/common/print.hpp @@ -12,33 +12,34 @@ * */ -#include -#include -#include - #ifndef PRINT_HPP #define PRINT_HPP +#include +#include +#include + namespace JClkLibCommon { - - typedef std::remove_reference::type errno_type; + typedef std::remove_reference::type errno_type; #define PrintErrorCode(msg) PrintError(msg, errno) #define PrintError(msg,...) ::JClkLibCommon::_PrintError(msg, __LINE__, __FILE__, __func__ __VA_OPT__(,) \ - __VA_ARGS__) - void _PrintError(std::string msg, uint16_t line, std::string file, std::string func, - errno_type errnum = (errno_type)-1); + __VA_ARGS__) + void _PrintError(std::string msg, uint16_t line, std::string file, + std::string func, errno_type errnum = (errno_type)-1); #define PrintDebug(msg) ::JClkLibCommon::_PrintDebug(msg, __LINE__, __FILE__, __func__) #define PrintInfo(msg) ::JClkLibCommon::_PrintInfo(msg, __LINE__, __FILE__, __func__) - void _PrintDebug(std::string msg, uint16_t line, std::string file, std::string func); - void _PrintInfo(std::string msg, uint16_t line, std::string file, std::string func); + void _PrintDebug(std::string msg, uint16_t line, std::string file, + std::string func); + void _PrintInfo(std::string msg, uint16_t line, std::string file, + std::string func); #define DumpOctetArray(msg,arr,size) JClkLibCommon::_DumpOctetArray(msg, arr, size, __LINE__, __FILE__, __func__) - void _DumpOctetArray(std::string msg, const std::uint8_t *arr, std::size_t length, std::uint16_t line, std::string file, - std::string func); + void _DumpOctetArray(std::string msg, const std::uint8_t *arr, std::size_t length, + std::uint16_t line, std::string file, std::string func); } -#endif/*PRINT_HPP*/ +#endif /* PRINT_HPP */ diff --git a/jclklib/common/serialize.hpp b/jclklib/common/serialize.hpp index 743b1ed4..cb2365e3 100644 --- a/jclklib/common/serialize.hpp +++ b/jclklib/common/serialize.hpp @@ -12,74 +12,72 @@ * */ -#include -#include -#include -#include - #ifndef SERIALIZE_HPP #define SERIALIZE_HPP +#include +#include +#include +#include + #include #define PARSE_RX(type,var,lc) \ - ({ \ - decltype(lc.getc_offset()) offset = PARSE_##type(var,lc.getc_buffer().data() + lc.getc_offset(), \ - lc.getc_buffer().max_size() - lc.getc_offset()); \ - if (offset != (decltype(offset))-1) { \ - lc.addOffset(offset); \ - } \ - (offset != (decltype(offset))-1 ? true : false); \ - }) + ({ \ + decltype(lc.getc_offset()) offset = PARSE_##type(var,lc.getc_buffer().data() + lc.getc_offset(), \ + lc.getc_buffer().max_size() - lc.getc_offset()); \ + if (offset != (decltype(offset))-1) { \ + lc.addOffset(offset); \ + } \ + (offset != (decltype(offset))-1 ? true : false); \ + }) #define PARSE_FIELD(var,ptr,len) _PARSE(std::remove_reference::type,var,ptr,len) #define _PARSE(var_type,var,ptr,len) \ - ({ \ - std::size_t var_len = sizeof(var); \ - bool can_parse = len >= var_len; \ - if (can_parse) var = *(var_type *)(ptr); \ - (can_parse ? var_len : (std::remove_reference::type)(-1)); \ - }) + ({ \ + std::size_t var_len = sizeof(var); \ + bool can_parse = len >= var_len; \ + if (can_parse) var = *(var_type *)(ptr); \ + (can_parse ? var_len : (std::remove_reference::type)(-1)); \ + }) #define PARSE_ARRAY(arr,ptr,len) \ - ({ \ - std::size_t var_len = arr.max_size()*sizeof(decltype(arr)::value_type); \ - bool can_parse = len >= var_len; \ - if (can_parse) memcpy(arr.data(), ptr, var_len); \ - (can_parse ? var_len : (std::remove_reference::type)(-1)); \ - }) + ({ \ + std::size_t var_len = arr.max_size()*sizeof(decltype(arr)::value_type); \ + bool can_parse = len >= var_len; \ + if (can_parse) memcpy(arr.data(), ptr, var_len); \ + (can_parse ? var_len : (std::remove_reference::type)(-1)); \ + }) #define CHECK_RSV(field) \ - (field == (std::remove_reference::type)0) + (field == (std::remove_reference::type)0) #define WRITE_TX(type,var,tc) \ -({ \ - decltype(tc.getc_offset()) offset = WRITE_##type(var,tc.get_buffer().data() + tc.get_offset(), \ - tc.get_buffer().max_size() - tc.get_offset()); \ - if (offset != (decltype(offset))-1) { \ - tc.addOffset(offset); \ - } \ - (offset != (decltype(offset))-1 ? true : false); \ - }) + ({ \ + decltype(tc.getc_offset()) offset = WRITE_##type(var,tc.get_buffer().data() + tc.get_offset(), \ + tc.get_buffer().max_size() - tc.get_offset()); \ + if (offset != (decltype(offset))-1) { \ + tc.addOffset(offset); \ + } \ + (offset != (decltype(offset))-1 ? true : false); \ + }) #define WRITE_FIELD(var,ptr,len) _WRITE(std::remove_reference::type,var,ptr,len) #define _WRITE(var_type,var,ptr,len) \ - ({ \ - std::size_t var_len = sizeof(var); \ - bool can_parse = (len) >= var_len; \ - if (can_parse) *(var_type *)(ptr) = var; \ - (can_parse ? var_len : (std::remove_reference::type)(-1)); \ - }) + ({ \ + std::size_t var_len = sizeof(var); \ + bool can_parse = (len) >= var_len; \ + if (can_parse) *(var_type *)(ptr) = var; \ + (can_parse ? var_len : (std::remove_reference::type)(-1)); \ + }) -// For writing std::array -// +/* For writing std::array */ #define WRITE_ARRAY(arr,ptr,len) \ - ({ \ - std::size_t var_len = arr.max_size()*sizeof(decltype(arr)::value_type); \ - bool can_parse = len >= var_len; \ - if (can_parse) memcpy(ptr, arr.data(), var_len); \ - (can_parse ? var_len : (std::remove_reference::type)(-1)); \ - }) - + ({ \ + std::size_t var_len = arr.max_size()*sizeof(decltype(arr)::value_type); \ + bool can_parse = len >= var_len; \ + if (can_parse) memcpy(ptr, arr.data(), var_len); \ + (can_parse ? var_len : (std::remove_reference::type)(-1)); \ + }) -#endif/*SERIALIZE_HPP*/ +#endif /* SERIALIZE_HPP */ diff --git a/jclklib/common/sighandler.cpp b/jclklib/common/sighandler.cpp index f44ed74f..e08144b3 100644 --- a/jclklib/common/sighandler.cpp +++ b/jclklib/common/sighandler.cpp @@ -12,120 +12,119 @@ * */ -#include -#include - #include - #include +#include +#include + #define INTR_SIGNAL (SIGUSR1) using namespace JClkLibCommon; using namespace std; -#define SIGADDSET(set,sig,ret) \ - if(sigaddset(set, sig) == -1) \ - return ret; +#define SIGADDSET(set,sig,ret) \ + if(sigaddset(set, sig) == -1) \ + return ret; bool AddStopSignal(sigset_t *sigset) { - SIGADDSET(sigset, SIGINT, false); - SIGADDSET(sigset, SIGHUP, false); - SIGADDSET(sigset, SIGTERM, false); - SIGADDSET(sigset, SIGQUIT, false); - SIGADDSET(sigset, SIGALRM, false); - SIGADDSET(sigset, SIGABRT, false); - - return true; + SIGADDSET(sigset, SIGINT, false); + SIGADDSET(sigset, SIGHUP, false); + SIGADDSET(sigset, SIGTERM, false); + SIGADDSET(sigset, SIGQUIT, false); + SIGADDSET(sigset, SIGALRM, false); + SIGADDSET(sigset, SIGABRT, false); + + return true; } bool AddInterruptSignal(sigset_t *sigset) { - SIGADDSET(sigset, SIGUSR1, false); - SIGADDSET(sigset, SIGUSR2, false); + SIGADDSET(sigset, SIGUSR1, false); + SIGADDSET(sigset, SIGUSR2, false); - return true; + return true; } bool GenerateBlockSigset(sigset_t *block) { - sigemptyset(block); + sigemptyset(block); - if (!AddStopSignal(block)) - return false; - if (!AddInterruptSignal(block)) - return false; + if (!AddStopSignal(block)) + return false; + if (!AddInterruptSignal(block)) + return false; - return true; + return true; } bool GenerateWaitSigset(sigset_t *wait) { - sigemptyset(wait); + sigemptyset(wait); - if (!AddStopSignal(wait)) - return false; + if (!AddStopSignal(wait)) + return false; - return true; + return true; } bool JClkLibCommon::BlockStopSignal() { - sigset_t blockSigset; + sigset_t blockSigset; - if (!GenerateBlockSigset(&blockSigset)) - return false; - if (pthread_sigmask(SIG_BLOCK,&blockSigset,NULL) != 0) - return false; + if (!GenerateBlockSigset(&blockSigset)) + return false; + if (pthread_sigmask(SIG_BLOCK,&blockSigset,NULL) != 0) + return false; - return true; + return true; } bool JClkLibCommon::WaitForStopSignal() { - sigset_t waitSigset; - int cause; - - if (!GenerateWaitSigset(&waitSigset)) - return false; - PrintDebug("Waiting for Interrupt Signal"); - if (sigwait(&waitSigset, &cause) == -1) { - PrintErrorCode("Waiting for Interrupt Signal"); - return false; - } - PrintDebug("Received Interrupt Signal"); + sigset_t waitSigset; + int cause; + + if (!GenerateWaitSigset(&waitSigset)) + return false; + PrintDebug("Waiting for Interrupt Signal"); + if (sigwait(&waitSigset, &cause) == -1) { + PrintErrorCode("Waiting for Interrupt Signal"); + return false; + } + PrintDebug("Received Interrupt Signal"); - return true; + return true; } void NullSigaction(int sig, siginfo_t *siginfo, void *ctx) {} bool JClkLibCommon::EnableSyscallInterruptSignal() { - sigset_t unblockSigset; - struct sigaction intrSigaction; + sigset_t unblockSigset; + struct sigaction intrSigaction; - intrSigaction.sa_sigaction = NullSigaction; - sigemptyset(&intrSigaction.sa_mask); - intrSigaction.sa_flags = SA_SIGINFO; - if (sigaction(INTR_SIGNAL, &intrSigaction, NULL) == -1) - return false; + intrSigaction.sa_sigaction = NullSigaction; + sigemptyset(&intrSigaction.sa_mask); + intrSigaction.sa_flags = SA_SIGINFO; + if (sigaction(INTR_SIGNAL, &intrSigaction, NULL) == -1) + return false; - sigemptyset(&unblockSigset); - SIGADDSET(&unblockSigset, INTR_SIGNAL, false); - if (pthread_sigmask(SIG_UNBLOCK,&unblockSigset,NULL) != 0) - return false; + sigemptyset(&unblockSigset); + SIGADDSET(&unblockSigset, INTR_SIGNAL, false); + if (pthread_sigmask(SIG_UNBLOCK,&unblockSigset,NULL) != 0) + return false; - return true; + return true; } bool JClkLibCommon::SendSyscallInterruptSignal(thread &t) { - int ret; + int ret; - if ((ret = pthread_kill(t.native_handle(), INTR_SIGNAL)) != 0) { - PrintError("pthread_kill()", ret); - return false; - } + if ((ret = pthread_kill(t.native_handle(), INTR_SIGNAL)) != 0) { + PrintError("pthread_kill()", ret); + return false; + } - return true; + return true; } diff --git a/jclklib/common/sighandler.hpp b/jclklib/common/sighandler.hpp index ed61892f..f678a887 100644 --- a/jclklib/common/sighandler.hpp +++ b/jclklib/common/sighandler.hpp @@ -19,10 +19,10 @@ namespace JClkLibCommon { - bool BlockStopSignal(); - bool WaitForStopSignal(); - bool EnableSyscallInterruptSignal(); - bool SendSyscallInterruptSignal(std::thread &t); + bool BlockStopSignal(); + bool WaitForStopSignal(); + bool EnableSyscallInterruptSignal(); + bool SendSyscallInterruptSignal(std::thread &t); } -#endif/*SIGHANDLER_HPP*/ +#endif /* SIGHANDLER_HPP */ diff --git a/jclklib/common/subscribe_msg.cpp b/jclklib/common/subscribe_msg.cpp index 158fab5d..f9204881 100644 --- a/jclklib/common/subscribe_msg.cpp +++ b/jclklib/common/subscribe_msg.cpp @@ -12,65 +12,68 @@ * */ -#include -#include #include +#include +#include using namespace JClkLibCommon; using namespace std; string CommonSubscribeMessage::toString() { - string name = ExtractClassName(string(__PRETTY_FUNCTION__),string(__FUNCTION__)); - name += "\n"; - name += Message::toString(); - //name += "Client ID: " + string((char *)clientId.data()) + "\n"; + string name = ExtractClassName(string(__PRETTY_FUNCTION__),string(__FUNCTION__)); + name += "\n"; + name += Message::toString(); + //name += "Client ID: " + string((char *)clientId.data()) + "\n"; - return name; + return name; } -PARSE_RXBUFFER_TYPE(CommonSubscribeMessage::parseBuffer) { - PrintDebug("[CommonSubscribeMessage]::parseBuffer "); - if(!Message::parseBuffer(LxContext)) - return false; +PARSE_RXBUFFER_TYPE(CommonSubscribeMessage::parseBuffer) +{ + PrintDebug("[CommonSubscribeMessage]::parseBuffer "); + if(!Message::parseBuffer(LxContext)) + return false; - if (!PARSE_RX(FIELD, get_sessionId(), LxContext)) - return false; + if (!PARSE_RX(FIELD, get_sessionId(), LxContext)) + return false; - if (!PARSE_RX(FIELD, subscription, LxContext)) - return false; + if (!PARSE_RX(FIELD, subscription, LxContext)) + return false; - return true; + return true; } BUILD_TXBUFFER_TYPE(CommonSubscribeMessage::makeBuffer) const { - auto ret = Message::makeBuffer(TxContext); + auto ret = Message::makeBuffer(TxContext); - if (!ret) - return ret; + if (!ret) + return ret; - PrintDebug("[CommonSubscribeMessage]::makeBuffer - sessionId : " + to_string(c_get_val_sessionId())); - if (!WRITE_TX(FIELD, c_get_val_sessionId(), TxContext)) - return false; + PrintDebug("[CommonSubscribeMessage]::makeBuffer - sessionId : " + \ + to_string(c_get_val_sessionId())); + if (!WRITE_TX(FIELD, c_get_val_sessionId(), TxContext)) + return false; - PrintDebug("[CommonSubscribeMessage]::makeBuffer - subscription event : " + subscription.c_get_val_event().toString() + \ - ", subscription val : " + subscription.c_get_val_value().toString()); - if (!WRITE_TX(FIELD,subscription, TxContext)) - return false; + PrintDebug("[CommonSubscribeMessage]::makeBuffer - subscription event : " + \ + subscription.c_get_val_event().toString() + \ + ", subscription val : " + subscription.c_get_val_value().toString()); + if (!WRITE_TX(FIELD,subscription, TxContext)) + return false; - return true; + return true; } TRANSMIT_MESSAGE_TYPE(CommonSubscribeMessage::transmitMessage) { - PrintDebug("[CommonSubscribeMessage]::transmitMessage "); - if (!presendMessage(&TxContext)) - return false; + PrintDebug("[CommonSubscribeMessage]::transmitMessage "); + if (!presendMessage(&TxContext)) + return false; - return TxContext.sendBuffer(); + return TxContext.sendBuffer(); } void setSubscription(jcl_subscription &newsub) { - PrintDebug("[CommonSubscribeMessage]::setSubscription "); + PrintDebug("[CommonSubscribeMessage]::setSubscription "); } diff --git a/jclklib/common/subscribe_msg.hpp b/jclklib/common/subscribe_msg.hpp index b13215e5..e03a4159 100644 --- a/jclklib/common/subscribe_msg.hpp +++ b/jclklib/common/subscribe_msg.hpp @@ -15,35 +15,34 @@ #ifndef COMMON_SUBSCRIBE_MSG_HPP #define COMMON_SUBSCRIBE_MSG_HPP -#include #include +#include namespace JClkLibCommon { - class CommonSubscribeMessage : virtual public Message - { - private: - jcl_subscription subscription; - TransportClientId clientId; + class CommonSubscribeMessage : virtual public Message + { + private: + jcl_subscription subscription; + TransportClientId clientId; - public: - static msgId_t getMsgId() { return SUBSCRIBE_MSG; } - //static MAKE_RXBUFFER_TYPE(buildMessage); - //const jcl_subscription &getSubscription(); - virtual PARSE_RXBUFFER_TYPE(parseBuffer); - virtual TRANSMIT_MESSAGE_TYPE(transmitMessage); - virtual BUILD_TXBUFFER_TYPE(makeBuffer) const; - jcl_subscription &getSubscription() - { return subscription; } - TransportClientId &getClientId() - { return clientId; } - void setSubscription(jcl_subscription &newsub); + public: + static msgId_t getMsgId() { return SUBSCRIBE_MSG; } + //static MAKE_RXBUFFER_TYPE(buildMessage); + virtual PARSE_RXBUFFER_TYPE(parseBuffer); + virtual TRANSMIT_MESSAGE_TYPE(transmitMessage); + virtual BUILD_TXBUFFER_TYPE(makeBuffer) const; + jcl_subscription &getSubscription() + { return subscription; } + TransportClientId &getClientId() + { return clientId; } + void setSubscription(jcl_subscription &newsub); - virtual std::string toString(); - protected: + virtual std::string toString(); + protected: #define MESSAGE_SUBSCRIBE() JClkLibCommon::Message(JClkLibCommon::SUBSCRIBE_MSG) - CommonSubscribeMessage() : MESSAGE_SUBSCRIBE() {} - }; + CommonSubscribeMessage() : MESSAGE_SUBSCRIBE() {} + }; } -#endif/*COMMON_SUBSCRIBE_MSG_HPP*/ +#endif /* COMMON_SUBSCRIBE_MSG_HPP */ diff --git a/jclklib/common/transport.cpp b/jclklib/common/transport.cpp index c0100034..1ed6db74 100644 --- a/jclklib/common/transport.cpp +++ b/jclklib/common/transport.cpp @@ -12,12 +12,12 @@ * */ -#include #include -#include #include +#include #include #include +#include #include #define EXIT_TIMEOUT (200 /*ms*/) @@ -28,129 +28,128 @@ using namespace std; using namespace JClkLibCommon; DECLARE_STATIC(Transport::workerList); - void Transport::dispatchLoop(promise promise, - shared_ptr> exitVal, TransportWork work) + shared_ptr> exitVal, TransportWork work) { - FUTURE_TYPEOF(TransportWorkerState::retVal) promiseVal = false; + FUTURE_TYPEOF(TransportWorkerState::retVal) promiseVal = false; - PrintDebug("Transport Thread started"); - - for (; !exitVal->load();) { - if (!work.first(work.second.get())) { - goto done; - } - work.second.get()->_init = false; - } - promiseVal = true; + PrintDebug("Transport Thread started"); + + for (; !exitVal->load();) { + if (!work.first(work.second.get())) { + goto done; + } + work.second.get()->_init = false; + } + promiseVal = true; done: - PrintDebug("Transport Thread exited"); - promise.set_value_at_thread_exit(promiseVal); - return; + PrintDebug("Transport Thread exited"); + promise.set_value_at_thread_exit(promiseVal); + return; } Transport::TransportWorkerState::TransportWorkerState(future retInit, bool exitInit) { - exitVal = make_shared>(exitInit); - retVal = move(retInit); - thread = NULL; + exitVal = make_shared>(exitInit); + retVal = move(retInit); + thread = NULL; } Transport::TransportWorkDesc Transport::registerWork(TransportWork work) { - promise promise; - - workerList.push_back(TransportWorkerState(promise.get_future(),false)); - workerList.back().thread = make_unique - (MessageQueue::dispatchLoop, move(promise), - workerList.back().exitVal, TransportWork(work.first,move(work.second))); - PrintDebug("Thread started"); - if (isFutureSet(workerList.back().retVal)) { - workerList.back().thread.get()->join(); - workerList.pop_back(); - PrintError("Thread exited early"); - return InvalidTransportWorkDesc; - } - - /* Return the index of the element we just added */ - return (workerList.cend()-1)-workerList.cbegin(); + promise promise; + + workerList.push_back(TransportWorkerState(promise.get_future(),false)); + workerList.back().thread = make_unique + (MessageQueue::dispatchLoop, move(promise), + workerList.back().exitVal, TransportWork(work.first,move(work.second))); + PrintDebug("Thread started"); + if (isFutureSet(workerList.back().retVal)) { + workerList.back().thread.get()->join(); + workerList.pop_back(); + PrintError("Thread exited early"); + return InvalidTransportWorkDesc; + } + + /* Return the index of the element we just added */ + return (workerList.cend()-1)-workerList.cbegin(); } bool Transport::processMessage(TransportListenerContext &context) { - Message *msg; - TransportTransmitterContext *txcontext; + Message *msg; + TransportTransmitterContext *txcontext; - context.resetOffset(); - if (!Message::buildMessage(msg, context)) - return false; - PrintDebug("Received message " + msg->toString()); + context.resetOffset(); + if (!Message::buildMessage(msg, context)) + return false; + PrintDebug("Received message " + msg->toString()); - if (!context.processMessage(msg, txcontext)) - return false; + if (!context.processMessage(msg, txcontext)) + return false; - /* Echo the message back with ACK disposition */ - if (msg->get_msgAck() != ACK_NONE) - return msg->transmitMessage(*txcontext); + /* Echo the message back with ACK disposition */ + if (msg->get_msgAck() != ACK_NONE) + return msg->transmitMessage(*txcontext); - return true; + return true; } bool Transport::init() { - return _initTransport(); + return _initTransport(); } bool Transport::stop() { - /* Send stop signal to all of the threads */ - for (decltype(workerList)::iterator it = workerList.begin(); - it != workerList.end(); ++it) { - it->exitVal->store(true); - } + /* Send stop signal to all of the threads */ + for (decltype(workerList)::iterator it = workerList.begin(); + it != workerList.end(); ++it) { + it->exitVal->store(true); + } - /* Do any transport specific stop */ - if (!_stopTransport()) - return false; + /* Do any transport specific stop */ + if (!_stopTransport()) + return false; - return true; + return true; } bool Transport::finalize() { - bool retVal = false; + bool retVal = false; - for (auto it = workerList.begin(); - it != workerList.end(); ++it) { - if (it->retVal.wait_for(chrono::milliseconds(EXIT_TIMEOUT)) != - future_status::ready) { - PrintError("Thread Join Timeout"); - goto done; - } - - it->thread.get()->join(); - retVal &= it->retVal.get(); - } - - if (!_finalizeTransport()) - goto done; - - retVal = true; + for (auto it = workerList.begin(); + it != workerList.end(); ++it) { + if (it->retVal.wait_for(chrono::milliseconds(EXIT_TIMEOUT)) != + future_status::ready) { + PrintError("Thread Join Timeout"); + goto done; + } + + it->thread.get()->join(); + retVal &= it->retVal.get(); + } + + if (!_finalizeTransport()) + goto done; + + retVal = true; done: - return retVal; + return retVal; } bool Transport::InterruptWorker(TransportWorkDesc d) { - if (d == InvalidTransportWorkDesc) - return false; - - /* Thread has exited, no need to interrupt */ - if (isFutureSet(workerList.back().retVal)) - return true; - - PrintDebug("Sending interrupt to MessageQueue worker"); - return SendSyscallInterruptSignal(*workerList[d].thread.get()); + if (d == InvalidTransportWorkDesc) + return false; + + /* Thread has exited, no need to interrupt */ + if (isFutureSet(workerList.back().retVal)) + return true; + + PrintDebug("Sending interrupt to MessageQueue worker"); + return SendSyscallInterruptSignal(*workerList[d].thread.get()); } diff --git a/jclklib/common/transport.hpp b/jclklib/common/transport.hpp index 66f180e3..0ab623da 100644 --- a/jclklib/common/transport.hpp +++ b/jclklib/common/transport.hpp @@ -12,15 +12,15 @@ * */ +#ifndef COMMON_TRANSPORT_HPP +#define COMMON_TRANSPORT_HPP + #include #include -#include -#include #include +#include #include - -#ifndef COMMON_TRANSPORT_HPP -#define COMMON_TRANSPORT_HPP +#include #include @@ -28,94 +28,94 @@ namespace JClkLibCommon { - typedef std::array TransportBuffer; - class Message; - class Transport; + typedef std::array TransportBuffer; + class Message; + class Transport; - class TransportContext { - protected: - bool _init; - std::size_t offset; - TransportBuffer buffer; - public: - bool init() { return _init; } - TransportContext() : _init(true), offset(0) {} - virtual ~TransportContext() = default; - DECLARE_ACCESSOR(offset); - DECLARE_ACCESSOR(buffer); - void resetOffset() { set_offset(0); } - void addOffset(std::size_t offset) { this->offset += offset; } - }; + class TransportContext { + protected: + bool _init; + std::size_t offset; + TransportBuffer buffer; + public: + bool init() { return _init; } + TransportContext() : _init(true), offset(0) {} + virtual ~TransportContext() = default; + DECLARE_ACCESSOR(offset); + DECLARE_ACCESSOR(buffer); + void resetOffset() { set_offset(0); } + void addOffset(std::size_t offset) { this->offset += offset; } + }; - class TransportTransmitterContext : public TransportContext { - public: - virtual ~TransportTransmitterContext() = default; -#define SEND_BUFFER_TYPE(name) \ - bool name() - virtual SEND_BUFFER_TYPE(sendBuffer) = 0; - }; + class TransportTransmitterContext : public TransportContext { + public: + virtual ~TransportTransmitterContext() = default; +#define SEND_BUFFER_TYPE(name) \ + bool name() + virtual SEND_BUFFER_TYPE(sendBuffer) = 0; + }; #define TRANSPORT_CLIENTID_LENGTH (512) - typedef std::array TransportClientId; + typedef std::array TransportClientId; - class TransportListenerContext : public TransportContext { - friend class Transport; - protected: -#define LISTENER_CONTEXT_PROCESS_MESSAGE_TYPE(name) \ - bool name(JClkLibCommon::Message *bmsg, JClkLibCommon::TransportTransmitterContext *&txcontext) - virtual LISTENER_CONTEXT_PROCESS_MESSAGE_TYPE(processMessage) { return false; } - public: - virtual ~TransportListenerContext() = default; -#define CREATE_TRANSMIT_CONTEXT_TYPE(name) \ - JClkLibCommon::TransportTransmitterContext *name(JClkLibCommon::TransportClientId &clientId) - virtual CREATE_TRANSMIT_CONTEXT_TYPE(CreateTransmitterContext) { return NULL; } - }; + class TransportListenerContext : public TransportContext { + friend class Transport; + protected: +#define LISTENER_CONTEXT_PROCESS_MESSAGE_TYPE(name) \ + bool name(JClkLibCommon::Message *bmsg, JClkLibCommon::TransportTransmitterContext *&txcontext) + virtual LISTENER_CONTEXT_PROCESS_MESSAGE_TYPE(processMessage) { return false; } + public: + virtual ~TransportListenerContext() = default; +#define CREATE_TRANSMIT_CONTEXT_TYPE(name) \ + JClkLibCommon::TransportTransmitterContext *name(JClkLibCommon::TransportClientId &clientId) + virtual CREATE_TRANSMIT_CONTEXT_TYPE(CreateTransmitterContext) { return NULL; } + }; - class Transport - { - public: - typedef std::unique_ptr TransportWorkArg; - typedef std::function TransportWorkFunction; - typedef std::pair TransportWork; - typedef ptrdiff_t TransportWorkDesc; - static const TransportWorkDesc InvalidTransportWorkDesc = (TransportWorkDesc) -1; - private: - class TransportWorkerState { - public: - std::future retVal; - std::shared_ptr> exitVal; - std::unique_ptr thread; - TransportWorkerState(std::future retInit, bool exitInit); - }; - static std::vector workerList; - static void dispatchLoop(std::promise, - decltype(TransportWorkerState::exitVal) exitVal, - TransportWork arg - ); - public: - static bool processMessage(TransportListenerContext &context); - static bool initTransport() { return true; } - static bool stopTransport() { return true; } - static bool finalizeTransport() { return true; } - static TransportWorkDesc registerWork(TransportWork work); - static bool init(); - static bool stop(); - static bool finalize(); - static bool InterruptWorker(TransportWorkDesc d); - }; + class Transport + { + public: + typedef std::unique_ptr TransportWorkArg; + typedef std::function TransportWorkFunction; + typedef std::pair TransportWork; + typedef ptrdiff_t TransportWorkDesc; + static const TransportWorkDesc InvalidTransportWorkDesc = (TransportWorkDesc) -1; + private: + class TransportWorkerState { + public: + std::future retVal; + std::shared_ptr> exitVal; + std::unique_ptr thread; + TransportWorkerState(std::future retInit, bool exitInit); + }; + static std::vector workerList; + static void dispatchLoop(std::promise, + decltype(TransportWorkerState::exitVal) exitVal, + TransportWork arg + ); + public: + static bool processMessage(TransportListenerContext &context); + static bool initTransport() { return true; } + static bool stopTransport() { return true; } + static bool finalizeTransport() { return true; } + static TransportWorkDesc registerWork(TransportWork work); + static bool init(); + static bool stop(); + static bool finalize(); + static bool InterruptWorker(TransportWorkDesc d); + }; -#define PER_TRANSPORT_VARIADIC_TEMPLATE(x) \ - template \ - inline bool _##x() \ - { \ - return T::x(); \ - } \ - template \ - inline typename std::enable_if::type \ - _##x() \ - { \ - return _##x() && _##x(); \ - } +#define PER_TRANSPORT_VARIADIC_TEMPLATE(x) \ + template \ + inline bool _##x() \ + { \ + return T::x(); \ + } \ + template \ + inline typename std::enable_if::type \ + _##x() \ + { \ + return _##x() && _##x(); \ + } PER_TRANSPORT_VARIADIC_TEMPLATE(initTransport) PER_TRANSPORT_VARIADIC_TEMPLATE(stopTransport) @@ -123,4 +123,4 @@ PER_TRANSPORT_VARIADIC_TEMPLATE(finalizeTransport) } -#endif/*COMMON_TRANSPORT_HPP*/ +#endif /* COMMON_TRANSPORT_HPP */ diff --git a/jclklib/common/util.hpp b/jclklib/common/util.hpp index d1f86272..9b675caa 100644 --- a/jclklib/common/util.hpp +++ b/jclklib/common/util.hpp @@ -12,8 +12,8 @@ * */ -#include #include +#include #ifndef UTIL_HPP #define UTIL_HPP @@ -25,24 +25,22 @@ template bool isFutureSet(std::future &f) { - return f.valid() && f.wait_for(std::chrono::milliseconds(0)) == std::future_status::ready; + return f.valid() && f.wait_for(std::chrono::milliseconds(0)) == std::future_status::ready; } #define DECLARE_ACCESSOR(varname) \ - const decltype(varname) &getc_##varname() { return varname; } \ - decltype(varname) &get_##varname() { return varname; } \ - void set_##varname (const decltype(varname) &varname) { this->varname = varname; } \ - decltype(varname) c_get_val_##varname () const { return varname; } + const decltype(varname) &getc_##varname() { return varname; } \ + decltype(varname) &get_##varname() { return varname; } \ + void set_##varname (const decltype(varname) &varname) { this->varname = varname; } \ + decltype(varname) c_get_val_##varname () const { return varname; } #define PTHREAD_CALL(func,err_msg,retval) \ - { \ - int err; \ - if ((err = (func)) != 0) { \ - PrintError(err_msg, err); \ - return retval; \ - } \ - } - - -#endif/*UTIL_HPP*/ - + { \ + int err; \ + if ((err = (func)) != 0) { \ + PrintError(err_msg, err); \ + return retval; \ + } \ + } + +#endif /* UTIL_HPP */ From abc05b6757e0f70dddd4cd5818931341346fe1f5 Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Fri, 24 May 2024 14:13:04 +0800 Subject: [PATCH 117/151] jclklib: proxy: code cleanup Signed-off-by: Lai Peter Jun Ann --- jclklib/proxy/client.cpp | 25 +++---- jclklib/proxy/client.hpp | 48 ++++++------- jclklib/proxy/clock_config.cpp | 48 ++++++------- jclklib/proxy/clock_config.hpp | 59 ++++++++-------- jclklib/proxy/clock_status.cpp | 47 ++++++------- jclklib/proxy/clock_status.hpp | 50 ++++++------- jclklib/proxy/connect.cpp | 39 ++++++----- jclklib/proxy/connect.hpp | 2 +- jclklib/proxy/connect_msg.cpp | 70 +++++++++---------- jclklib/proxy/connect_msg.hpp | 67 +++++++++--------- jclklib/proxy/main.cpp | 56 +++++++-------- jclklib/proxy/message.cpp | 12 ++-- jclklib/proxy/message.hpp | 40 +++++------ jclklib/proxy/msgq_tport.cpp | 108 ++++++++++++++--------------- jclklib/proxy/msgq_tport.hpp | 67 +++++++++--------- jclklib/proxy/notification_msg.cpp | 36 +++++----- jclklib/proxy/notification_msg.hpp | 58 ++++++++-------- jclklib/proxy/null_msg.hpp | 27 ++++---- jclklib/proxy/null_tport.cpp | 9 ++- jclklib/proxy/null_tport.hpp | 18 ++--- jclklib/proxy/subscribe_msg.cpp | 61 ++++++++-------- jclklib/proxy/subscribe_msg.hpp | 49 ++++++------- jclklib/proxy/thread.cpp | 102 ++++++++++++++------------- jclklib/proxy/thread.hpp | 50 ++++++------- jclklib/proxy/transport.cpp | 29 ++++---- jclklib/proxy/transport.hpp | 58 ++++++++-------- 26 files changed, 615 insertions(+), 620 deletions(-) diff --git a/jclklib/proxy/client.cpp b/jclklib/proxy/client.cpp index 22e3ed26..bcb29b96 100644 --- a/jclklib/proxy/client.cpp +++ b/jclklib/proxy/client.cpp @@ -12,11 +12,11 @@ * */ -#include #include +#include -using namespace JClkLibProxy; using namespace JClkLibCommon; +using namespace JClkLibProxy; using namespace std; DECLARE_STATIC(Client::nextSession,sessionId_t(InvalidSessionId+1)); @@ -24,10 +24,11 @@ DECLARE_STATIC(Client::SessionMap); sessionId_t Client::CreateClientSession() { - for (auto iter = SessionMap.find(nextSession); nextSession != InvalidSessionId && iter != SessionMap.cend(); - iter = SessionMap.find(++nextSession)); - SessionMap.emplace(SessionMapping_t(nextSession,new Client())); - return nextSession; + for (auto iter = SessionMap.find(nextSession); + nextSession != InvalidSessionId && iter != SessionMap.cend(); + iter = SessionMap.find(++nextSession)); + SessionMap.emplace(SessionMapping_t(nextSession,new Client())); + return nextSession; } sessionId_t Client::GetSessionIdAt(size_t index) @@ -42,11 +43,11 @@ sessionId_t Client::GetSessionIdAt(size_t index) ClientX Client::GetClientSession(sessionId_t sessionId) { - auto iter = SessionMap.find(sessionId); - if (iter == SessionMap.cend()) { - PrintError("Session ID " + to_string(sessionId) + " not found"); - return ClientX(NULL); - } + auto iter = SessionMap.find(sessionId); + if (iter == SessionMap.cend()) { + PrintError("Session ID " + to_string(sessionId) + " not found"); + return ClientX(NULL); + } - return iter->second; + return iter->second; } diff --git a/jclklib/proxy/client.hpp b/jclklib/proxy/client.hpp index 0fba3ef3..d09ac64f 100644 --- a/jclklib/proxy/client.hpp +++ b/jclklib/proxy/client.hpp @@ -12,36 +12,36 @@ * */ -#include - #ifndef PROXY_CLIENT #define PROXY_CLIENT +#include + #include namespace JClkLibProxy { - class Client; - typedef std::shared_ptr ClientX; + class Client; + typedef std::shared_ptr ClientX; - class Client - { - public: - typedef std::pair SessionMapping_t; - private: - static JClkLibCommon::sessionId_t nextSession; - static std::map SessionMap; - public: - static JClkLibCommon::sessionId_t CreateClientSession(); - static size_t GetSessionCount() { return SessionMap.size(); } - static JClkLibCommon::sessionId_t GetSessionIdAt(size_t index); - static ClientX GetClientSession(JClkLibCommon::sessionId_t sessionId); - private: - std::unique_ptr transmitContext; - public: - void set_transmitContext(decltype(transmitContext)::pointer context) - { this->transmitContext.reset(context); } - auto get_transmitContext() { return transmitContext.get(); } - }; + class Client + { + public: + typedef std::pair SessionMapping_t; + private: + static JClkLibCommon::sessionId_t nextSession; + static std::map SessionMap; + public: + static JClkLibCommon::sessionId_t CreateClientSession(); + static size_t GetSessionCount() { return SessionMap.size(); } + static JClkLibCommon::sessionId_t GetSessionIdAt(size_t index); + static ClientX GetClientSession(JClkLibCommon::sessionId_t sessionId); + private: + std::unique_ptr transmitContext; + public: + void set_transmitContext(decltype(transmitContext)::pointer context) + { this->transmitContext.reset(context); } + auto get_transmitContext() { return transmitContext.get(); } + }; } -#endif/*PROXY_CLIENT*/ +#endif /* PROXY_CLIENT */ diff --git a/jclklib/proxy/clock_config.cpp b/jclklib/proxy/clock_config.cpp index e0439c4a..9aee02f9 100644 --- a/jclklib/proxy/clock_config.cpp +++ b/jclklib/proxy/clock_config.cpp @@ -14,58 +14,58 @@ #include -using namespace JClkLibProxy; using namespace JClkLibCommon; +using namespace JClkLibProxy; using namespace std; bool ClockConfiguration::readConsume() { - lock_guard update_guard(update_lock); - if (update) - readShadow = config; - update = false; + lock_guard update_guard(update_lock); + if (update) + readShadow = config; + update = false; - return update; + return update; } ClockConfiguration::ClockConfiguration() { - // Initialize configuration + /* Initialize configuration */ } void ClockConfiguration::speculateWrite() { - lock_guard update_guard(update_lock); - writeShadow = config; + lock_guard update_guard(update_lock); + writeShadow = config; } void ClockConfiguration::setEvent( const jcl_event &sEvent ) { - if (writeShadow.event != sEvent) { - writeShadow.event = sEvent; - writeUpdate = true; - } + if (writeShadow.event != sEvent) { + writeShadow.event = sEvent; + writeUpdate = true; + } } void ClockConfiguration::setValue( const jcl_value &sValue ) { - if (writeShadow.value != sValue) { - writeShadow.value = sValue; - writeUpdate = true; - } + if (writeShadow.value != sValue) { + writeShadow.value = sValue; + writeUpdate = true; + } } void ClockConfiguration::commitWrite() { - lock_guard update_guard(update_lock); - if (writeUpdate) { - config = writeShadow; - update = writeUpdate; - } - writeUpdate = false; + lock_guard update_guard(update_lock); + if (writeUpdate) { + config = writeShadow; + update = writeUpdate; + } + writeUpdate = false; } sessionId_t ClockConfiguration::getSessionId() { - return InvalidSessionId; + return InvalidSessionId; } diff --git a/jclklib/proxy/clock_config.hpp b/jclklib/proxy/clock_config.hpp index 85b71390..e3ff9168 100644 --- a/jclklib/proxy/clock_config.hpp +++ b/jclklib/proxy/clock_config.hpp @@ -12,43 +12,42 @@ * */ -#include -#include - #ifndef CLOCK_CONFIG_HPP #define CLOCK_CONFIG_HPP +#include +#include + #include #include namespace JClkLibProxy { - - class ClockConfiguration - { - private: - enum { event = 0, value }; - bool update, writeUpdate; - std::mutex update_lock; - struct Config { - JClkLibCommon::jcl_event event; - JClkLibCommon::jcl_value value; - }; - Config writeShadow, readShadow; - Config config; - public: - ClockConfiguration(); - void speculateWrite(); - void setEvent( const JClkLibCommon::jcl_event &event ); - void setValue( const JClkLibCommon::jcl_value &value ); - void commitWrite(); - - bool readConsume(); - const JClkLibCommon::jcl_event &getEvent() { return readShadow.event; } - const JClkLibCommon::jcl_value &getValue() { return readShadow.value; } - - static JClkLibCommon::sessionId_t getSessionId(); - }; + class ClockConfiguration + { + private: + enum { event = 0, value }; + bool update, writeUpdate; + std::mutex update_lock; + struct Config { + JClkLibCommon::jcl_event event; + JClkLibCommon::jcl_value value; + }; + Config writeShadow, readShadow; + Config config; + public: + ClockConfiguration(); + void speculateWrite(); + void setEvent( const JClkLibCommon::jcl_event &event ); + void setValue( const JClkLibCommon::jcl_value &value ); + void commitWrite(); + + bool readConsume(); + const JClkLibCommon::jcl_event &getEvent() { return readShadow.event; } + const JClkLibCommon::jcl_value &getValue() { return readShadow.value; } + + static JClkLibCommon::sessionId_t getSessionId(); + }; } -#endif/*CLOCK_CONFIG_HPP*/ +#endif /* CLOCK_CONFIG_HPP */ diff --git a/jclklib/proxy/clock_status.cpp b/jclklib/proxy/clock_status.cpp index 03943a6c..882c65a6 100644 --- a/jclklib/proxy/clock_status.cpp +++ b/jclklib/proxy/clock_status.cpp @@ -14,54 +14,53 @@ #include -using namespace JClkLibProxy; using namespace JClkLibCommon; +using namespace JClkLibProxy; using namespace std; bool ClockStatus::readConsume() { - lock_guard update_guard(update_lock); - if (update) - readShadow = status; - update = false; + lock_guard update_guard(update_lock); + if (update) + readShadow = status; + update = false; - return update; + return update; } ClockStatus::ClockStatus() { - // Initialize status + /* Initialize status */ } void ClockStatus::speculateWrite() { - lock_guard update_guard(update_lock); - writeShadow = status; + lock_guard update_guard(update_lock); + writeShadow = status; } void ClockStatus::setEvent( const jcl_event &sEvent ) { - if (writeShadow.event != sEvent) { - writeShadow.event = sEvent; - writeUpdate = true; - } + if (writeShadow.event != sEvent) { + writeShadow.event = sEvent; + writeUpdate = true; + } } void ClockStatus::setCount( const jcl_eventcount &sCount ) { - if (writeShadow.count != sCount) { - writeShadow.count = sCount; - writeUpdate = true; - } + if (writeShadow.count != sCount) { + writeShadow.count = sCount; + writeUpdate = true; + } } void ClockStatus::commitWrite() { - lock_guard update_guard(update_lock); - if (writeUpdate) { - status = writeShadow; - update = writeUpdate; - } - writeUpdate = false; + lock_guard update_guard(update_lock); + if (writeUpdate) { + status = writeShadow; + update = writeUpdate; + } + writeUpdate = false; } - diff --git a/jclklib/proxy/clock_status.hpp b/jclklib/proxy/clock_status.hpp index 5bbcba33..204d77f5 100644 --- a/jclklib/proxy/clock_status.hpp +++ b/jclklib/proxy/clock_status.hpp @@ -12,38 +12,38 @@ * */ -#include - #ifndef CLOCK_STATUS_HPP #define CLOCK_STATUS_HPP +#include + #include namespace JClkLibProxy { - class ClockStatus - { - private: - class Status { - public: - JClkLibCommon::jcl_event event; - JClkLibCommon::jcl_eventcount count; - }; - bool update, writeUpdate; - std::mutex update_lock; - Status status; - Status writeShadow, readShadow; - public: - ClockStatus(); - void speculateWrite(); - void setEvent( const JClkLibCommon::jcl_event &event ); - void setCount( const JClkLibCommon::jcl_eventcount &count ); - void commitWrite(); + class ClockStatus + { + private: + class Status { + public: + JClkLibCommon::jcl_event event; + JClkLibCommon::jcl_eventcount count; + }; + bool update, writeUpdate; + std::mutex update_lock; + Status status; + Status writeShadow, readShadow; + public: + ClockStatus(); + void speculateWrite(); + void setEvent( const JClkLibCommon::jcl_event &event ); + void setCount( const JClkLibCommon::jcl_eventcount &count ); + void commitWrite(); - bool readConsume(); - const JClkLibCommon::jcl_event &getEvent() { return readShadow.event; } - const JClkLibCommon::jcl_eventcount &getCount() { return readShadow.count; } - }; + bool readConsume(); + const JClkLibCommon::jcl_event &getEvent() { return readShadow.event; } + const JClkLibCommon::jcl_eventcount &getCount() { return readShadow.count; } + }; } -#endif/*CLOCK_STATUS_HPP*/ +#endif /* CLOCK_STATUS_HPP */ diff --git a/jclklib/proxy/connect.cpp b/jclklib/proxy/connect.cpp index 771ae490..7a235093 100644 --- a/jclklib/proxy/connect.cpp +++ b/jclklib/proxy/connect.cpp @@ -12,19 +12,19 @@ * */ -#include -#include -#include -#include -#include #include -#include #include +#include +#include +#include +#include #include +#include + #include -#include #include - +#include +#include #include "thread.hpp" #include "../../pub/init.h" @@ -36,7 +36,7 @@ static const size_t bufSize = 2000; static char buf[bufSize]; static Init obj; static Message &msg = obj.msg(); -static Message msgu; // TODO: to be removed +static Message msgu; static SockBase *sk; static std::unique_ptr m_sk; @@ -91,7 +91,7 @@ void event_handle() switch(msg.getTlvId()) { case TIME_STATUS_NP: - //workaround for ptp4l continue to send even gm is not present + /* Workaround for ptp4l continue to send even gm is not present */ if(portState < UNCALIBRATED) { return; } @@ -103,7 +103,7 @@ void event_handle() pe.servo_state = servo; memcpy(pe.gmIdentity, gm_uuid.v, sizeof(pe.gmIdentity)); - //Uncomment for debug data printing + /* Uncomment for debug data printing */ //printf("master_offset = %ld, servo_state = %d\n", pe.master_offset, pe.servo_state); //printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x\n\n", // pe.gmIdentity[0], pe.gmIdentity[1],pe.gmIdentity[2], @@ -114,7 +114,7 @@ void event_handle() pd = (PORT_DATA_SET_t *)data; portState = pd->portState; - //Reset TIME_STATUS_NP data if port_state <= PASSIVE + /* Reset TIME_STATUS_NP data if port_state <= PASSIVE */ if (portState <= PASSIVE) { pe.master_offset = 0; memset(pe.gmIdentity, 0, sizeof(pe.gmIdentity)); @@ -123,7 +123,7 @@ void event_handle() break; case PORT_PROPERTIES_NP: - //Retrieve current port state when proxy is started + /* Retrieve current port state when proxy is started */ pd = (PORT_DATA_SET_t *)data; portState = pd->portState; break; @@ -165,6 +165,7 @@ static inline bool msg_send(bool local) seq++; return true; } + static inline bool msg_set_action(bool local, mng_vals_e id) { bool ret; @@ -206,7 +207,9 @@ bool event_subscription(struct jcl_handle **handle) return false; } bool ret = msg_send(false); - msg.clearData(); // Remove referance to local SUBSCRIBE_EVENTS_NP_t + + /* Remove referance to local SUBSCRIBE_EVENTS_NP_t */ + msg.clearData(); return ret; } @@ -239,7 +242,7 @@ bool is_ptp4l_running() { */ void *ptp4l_event_loop( void *arg) { - const uint64_t timeout_ms = 1000; // 1 second + const uint64_t timeout_ms = 1000; for(;;) { if(!msg_set_action(true, PORT_PROPERTIES_NP)) @@ -258,7 +261,6 @@ void *ptp4l_event_loop( void *arg) } } - // Send to all msg_set_action(false, PORT_PROPERTIES_NP); event_subscription(NULL); @@ -278,7 +280,7 @@ void *ptp4l_event_loop( void *arg) sku->close(); msg.clearData(); - //Reset TIME_STATUS_NP data when ptp4l is disconnected + /* Reset TIME_STATUS_NP data when ptp4l is disconnected */ pe.master_offset = 0; memset(pe.gmIdentity, 0, sizeof(pe.gmIdentity)); pe.servo_state = 0; @@ -327,14 +329,13 @@ int Connect::connect() m_sk.reset(sku); while (is_ptp4l_running() != 1) { - //sleep for 2 seconds and keep looping until there is ptp4l available + /* sleep for 2 seconds and keep looping until there is ptp4l available */ PrintError("Failed to connect to ptp4l. Retrying..."); sleep(2); } PrintInfo("Connected to ptp4l via /var/run/ptp4l."); pe.ptp4l_id = 1; - //TODO: hard-coded uds_socket uds_address = "/var/run/ptp4l"; if(!sku->setDefSelfAddress() || !sku->init() || !sku->setPeerAddress(uds_address)) diff --git a/jclklib/proxy/connect.hpp b/jclklib/proxy/connect.hpp index c6854dd5..2aeea608 100644 --- a/jclklib/proxy/connect.hpp +++ b/jclklib/proxy/connect.hpp @@ -12,8 +12,8 @@ * */ -#include #include +#include namespace JClkLibProxy { diff --git a/jclklib/proxy/connect_msg.cpp b/jclklib/proxy/connect_msg.cpp index 40353b8f..dfafbbca 100644 --- a/jclklib/proxy/connect_msg.cpp +++ b/jclklib/proxy/connect_msg.cpp @@ -12,16 +12,16 @@ * */ -#include -#include +#include #include #include -#include +#include +#include #include -using namespace std; -using namespace JClkLibProxy; using namespace JClkLibCommon; +using namespace JClkLibProxy; +using namespace std; extern JClkLibCommon::ptp_event pe; @@ -33,8 +33,8 @@ extern JClkLibCommon::ptp_event pe; */ MAKE_RXBUFFER_TYPE(ProxyConnectMessage::buildMessage) { - msg = new ProxyConnectMessage(); - return true; + msg = new ProxyConnectMessage(); + return true; } /** @brief Add proxy's CONNECT_MSG type and its builder to transport layer. @@ -46,8 +46,8 @@ MAKE_RXBUFFER_TYPE(ProxyConnectMessage::buildMessage) */ bool ProxyConnectMessage::initMessage() { - addMessageType(parseMsgMapElement_t(CONNECT_MSG, buildMessage)); - return true; + addMessageType(parseMsgMapElement_t(CONNECT_MSG, buildMessage)); + return true; } /** @brief process the connect msg from client-runtime @@ -66,40 +66,40 @@ bool ProxyConnectMessage::initMessage() */ PROCESS_MESSAGE_TYPE(ProxyConnectMessage::processMessage) { - sessionId_t newSessionId; + sessionId_t newSessionId; - PrintDebug("Processing proxy connect message"); + PrintDebug("Processing proxy connect message"); - if (this->getc_sessionId() != InvalidSessionId) { - PrintError("Session ID *should be* invalid for received proxy connect message"); - return false; - } + if (this->getc_sessionId() != InvalidSessionId) { + PrintError("Session ID *should be* invalid for received proxy connect message"); + return false; + } - /* check whether there is ptp4l available */ - if (!pe.ptp4l_id) { - PrintError("ptp4l_id is not available."); - return false; - } + /* Check whether there is ptp4l available */ + if (!pe.ptp4l_id) { + PrintError("ptp4l_id is not available."); + return false; + } - newSessionId = Client::CreateClientSession(); - PrintDebug("Created new client session ID: " + to_string(newSessionId)); - this->set_sessionId(newSessionId); - TxContext = LxContext.CreateTransmitterContext(getClientId()); - Client::GetClientSession(newSessionId).get()->set_transmitContext(TxContext); - set_msgAck(ACK_SUCCESS); + newSessionId = Client::CreateClientSession(); + PrintDebug("Created new client session ID: " + to_string(newSessionId)); + this->set_sessionId(newSessionId); + TxContext = LxContext.CreateTransmitterContext(getClientId()); + Client::GetClientSession(newSessionId).get()->set_transmitContext(TxContext); + set_msgAck(ACK_SUCCESS); - return true; + return true; } BUILD_TXBUFFER_TYPE(ProxyConnectMessage::makeBuffer) const { - PrintDebug("[ProxyConnectMessage]::makeBuffer"); - if(!CommonConnectMessage::makeBuffer(TxContext)) - return false; + PrintDebug("[ProxyConnectMessage]::makeBuffer"); + if(!CommonConnectMessage::makeBuffer(TxContext)) + return false; - /* Add ptp4l_id here */ - if (!WRITE_TX(FIELD, pe.ptp4l_id, TxContext)) - return false; + /* Add ptp4l_id here */ + if (!WRITE_TX(FIELD, pe.ptp4l_id, TxContext)) + return false; - return true; -} \ No newline at end of file + return true; +} diff --git a/jclklib/proxy/connect_msg.hpp b/jclklib/proxy/connect_msg.hpp index a8b3e7dd..85084cee 100644 --- a/jclklib/proxy/connect_msg.hpp +++ b/jclklib/proxy/connect_msg.hpp @@ -15,42 +15,43 @@ #ifndef PROXY_CONNECT_MSG_HPP #define PROXY_CONNECT_MSG_HPP -#include #include +#include namespace JClkLibProxy { - class ProxyConnectMessage : virtual public ProxyMessage, virtual public JClkLibCommon::CommonConnectMessage - { - protected: - ProxyConnectMessage() : MESSAGE_CONNECT() {}; - public: - /** - * @brief process the connect msg from client-runtime - * @param LxContext proxy transport listener context - * @param TxContext proxy transport transmitter context - * @return true - */ - virtual PROCESS_MESSAGE_TYPE(processMessage); - virtual BUILD_TXBUFFER_TYPE(makeBuffer) const; - - bool generateResponse(uint8_t *msgBuffer, std::size_t &length, - const ClockStatus &status) - { return false; } - - /** - * @brief Create the ProxyConnectMessage object - * @param msg msg structure to be fill up - * @param LxContext proxy transport listener context - * @return true - */ - static MAKE_RXBUFFER_TYPE(buildMessage); - - /** @brief Add proxy's CONNECT_MSG type and its builder to transport layer. - * @return true - */ - static bool initMessage(); - }; + class ProxyConnectMessage : virtual public ProxyMessage, + virtual public JClkLibCommon::CommonConnectMessage + { + protected: + ProxyConnectMessage() : MESSAGE_CONNECT() {}; + public: + /** + * @brief process the connect msg from client-runtime + * @param LxContext proxy transport listener context + * @param TxContext proxy transport transmitter context + * @return true + */ + virtual PROCESS_MESSAGE_TYPE(processMessage); + virtual BUILD_TXBUFFER_TYPE(makeBuffer) const; + + bool generateResponse(uint8_t *msgBuffer, std::size_t &length, + const ClockStatus &status) + { return false; } + + /** + * @brief Create the ProxyConnectMessage object + * @param msg msg structure to be fill up + * @param LxContext proxy transport listener context + * @return true + */ + static MAKE_RXBUFFER_TYPE(buildMessage); + + /** @brief Add proxy's CONNECT_MSG type and its builder to transport layer. + * @return true + */ + static bool initMessage(); + }; } -#endif/*PROXY_CONNECT_MSG_HPP*/ +#endif /* PROXY_CONNECT_MSG_HPP */ diff --git a/jclklib/proxy/main.cpp b/jclklib/proxy/main.cpp index 757641dd..433be078 100644 --- a/jclklib/proxy/main.cpp +++ b/jclklib/proxy/main.cpp @@ -12,40 +12,40 @@ * */ -#include -#include -#include -#include -#include - #include -using namespace JClkLibProxy; +#include +#include +#include +#include +#include + using namespace JClkLibCommon; +using namespace JClkLibProxy; using namespace std; int main() { - //BlockStopSignal(); - if(!ProxyTransport::init()) { - cout << "Transport init failed" << endl; - return -1; - } - if(!ProxyMessage::init()) { - cout << "Message init failed" << endl; - return -1; - } - Connect::connect(); - WaitForStopSignal(); - PrintDebug("Got stop signal"); - if(!ProxyTransport::stop()) { - cout << "stop failed" << endl; - return -1; - } - if(!ProxyTransport::finalize()) { - cout << "finalize failed" << endl; - return -1; - } + //BlockStopSignal(); + if(!ProxyTransport::init()) { + cout << "Transport init failed" << endl; + return -1; + } + if(!ProxyMessage::init()) { + cout << "Message init failed" << endl; + return -1; + } + Connect::connect(); + WaitForStopSignal(); + PrintDebug("Got stop signal"); + if(!ProxyTransport::stop()) { + cout << "stop failed" << endl; + return -1; + } + if(!ProxyTransport::finalize()) { + cout << "finalize failed" << endl; + return -1; + } - return 0; + return 0; } diff --git a/jclklib/proxy/message.cpp b/jclklib/proxy/message.cpp index 13655532..7913c141 100644 --- a/jclklib/proxy/message.cpp +++ b/jclklib/proxy/message.cpp @@ -12,18 +12,16 @@ * */ -#include #include -#include #include +#include +#include -using namespace JClkLibProxy; using namespace JClkLibCommon; +using namespace JClkLibProxy; bool ProxyMessage::init() { - return _initMessage(); + return _initMessage(); } - - - diff --git a/jclklib/proxy/message.hpp b/jclklib/proxy/message.hpp index 553d798e..573be472 100644 --- a/jclklib/proxy/message.hpp +++ b/jclklib/proxy/message.hpp @@ -12,35 +12,35 @@ * */ +#ifndef PROXY_MESSAGE_HPP +#define PROXY_MESSAGE_HPP + #include #include #include -#ifndef PROXY_MESSAGE_HPP -#define PROXY_MESSAGE_HPP - #include #include #include namespace JClkLibProxy { - class ProxyMessage : virtual public JClkLibCommon::Message - { - public: - /** - * Generate a response, if necessary, to the received message - * @brief generate response to received message - * - * @param msgBuffer (out) transport buffer to fill response - * @param length (in/out) length of transport buffer to fill (in) and send (out) - * - * @return true if a response is required, false otherwise - */ - virtual bool generateResponse(uint8_t *msgBuffer, std::size_t &length, - const ClockStatus &status) = 0; - static bool init(); - }; + class ProxyMessage : virtual public JClkLibCommon::Message + { + public: + /** + * Generate a response, if necessary, to the received message + * @brief generate response to received message + * + * @param msgBuffer (out) transport buffer to fill response + * @param length (in/out) length of transport buffer to fill (in) and send (out) + * + * @return true if a response is required, false otherwise + */ + virtual bool generateResponse(uint8_t *msgBuffer, std::size_t &length, + const ClockStatus &status) = 0; + static bool init(); + }; } -#endif/*PROXY_MESSAGE_HPP*/ +#endif /* PROXY_MESSAGE_HPP */ diff --git a/jclklib/proxy/msgq_tport.cpp b/jclklib/proxy/msgq_tport.cpp index 7978b579..fe1d92fe 100644 --- a/jclklib/proxy/msgq_tport.cpp +++ b/jclklib/proxy/msgq_tport.cpp @@ -12,25 +12,22 @@ * */ -#include -#include - -#include -#include -#include - -#include -#include - +#include #include -#include +#include #include - #include -#include +#include +#include + +#include +#include +#include +#include +#include -using namespace JClkLibProxy; using namespace JClkLibCommon; +using namespace JClkLibProxy; using namespace std; #define NSEC_PER_MSEC (1000000 /*ns*/) @@ -38,75 +35,74 @@ using namespace std; LISTENER_CONTEXT_PROCESS_MESSAGE_TYPE(ProxyMessageQueueListenerContext::processMessage) { - ProxyMessage *msg = dynamic_cast(bmsg); + ProxyMessage *msg = dynamic_cast(bmsg); - PrintDebug("Processing received proxy message"); - if (msg == NULL) { - PrintError("Wrong message type"); - return false; - } + PrintDebug("Processing received proxy message"); + if (msg == NULL) { + PrintError("Wrong message type"); + return false; + } - return msg->processMessage(*this,txcontext); + return msg->processMessage(*this,txcontext); } CREATE_TRANSMIT_CONTEXT_TYPE(ProxyMessageQueueListenerContext::CreateTransmitterContext) { - mqd_t txd = mq_open((char *)clientId.data(), TX_QUEUE_FLAGS | O_NONBLOCK); - if (txd == -1) { - PrintErrorCode("Failed to open message queue " + string((const char*)clientId.data())); - return NULL; - } - PrintDebug("Successfully connected to client " + string((const char*)clientId.data())); - return new ProxyMessageQueueTransmitterContext(txd); + mqd_t txd = mq_open((char *)clientId.data(), TX_QUEUE_FLAGS | O_NONBLOCK); + if (txd == -1) { + PrintErrorCode("Failed to open message queue " + string((const char*)clientId.data())); + return NULL; + } + PrintDebug("Successfully connected to client " + string((const char*)clientId.data())); + return new ProxyMessageQueueTransmitterContext(txd); } ProxyMessageQueueListenerContext::ProxyMessageQueueListenerContext(mqd_t mqListenerDesc) - : MessageQueueListenerContext(mqListenerDesc) + : MessageQueueListenerContext(mqListenerDesc) { } ProxyMessageQueueTransmitterContext::ProxyMessageQueueTransmitterContext(mqd_t mqTransmitterDesc) - : MessageQueueTransmitterContext(mqTransmitterDesc) + : MessageQueueTransmitterContext(mqTransmitterDesc) { } bool ProxyMessageQueue::initTransport() { - struct mq_attr mq_attr; - - mq_attr.mq_flags = 0; - mq_attr.mq_maxmsg = MAX_CLIENT_COUNT; - mq_attr.mq_msgsize = (decltype(mq_attr.mq_msgsize)) std::tuple_size::value; - - PrintDebug("Initializing Message Queue Proxy Transport..."); - mqNativeListenerDesc = mq_open(mqProxyName.c_str(), RX_QUEUE_FLAGS, RX_QUEUE_MODE, &mq_attr); - if (mqNativeListenerDesc == -1) { - cout << "mq_open failed " << strerror(errno) << endl; - return false; - } - - if (InvalidTransportWorkDesc == - (mqListenerDesc = - registerWork(move((TransportWork){MqListenerWork, - TransportWorkArg(new ProxyMessageQueueListenerContext(mqNativeListenerDesc))})))) - return false; + struct mq_attr mq_attr; + + mq_attr.mq_flags = 0; + mq_attr.mq_maxmsg = MAX_CLIENT_COUNT; + mq_attr.mq_msgsize = (decltype(mq_attr.mq_msgsize)) std::tuple_size::value; + + PrintDebug("Initializing Message Queue Proxy Transport..."); + mqNativeListenerDesc = mq_open(mqProxyName.c_str(), RX_QUEUE_FLAGS, RX_QUEUE_MODE, &mq_attr); + if (mqNativeListenerDesc == -1) { + cout << "mq_open failed " << strerror(errno) << endl; + return false; + } + + if (InvalidTransportWorkDesc == + (mqListenerDesc = registerWork(move((TransportWork){MqListenerWork, + TransportWorkArg(new ProxyMessageQueueListenerContext(mqNativeListenerDesc))})))) + return false; - PrintDebug("Proxy Message queue opened"); + PrintDebug("Proxy Message queue opened"); - return true; + return true; } bool ProxyMessageQueue::stopTransport() { - PrintDebug("Stopping Message Queue Proxy Transport"); - mq_unlink(mqProxyName.c_str()); - if (mqListenerDesc != InvalidTransportWorkDesc && !InterruptWorker(mqListenerDesc)) - PrintError("Interrupt worker failed"); + PrintDebug("Stopping Message Queue Proxy Transport"); + mq_unlink(mqProxyName.c_str()); + if (mqListenerDesc != InvalidTransportWorkDesc && !InterruptWorker(mqListenerDesc)) + PrintError("Interrupt worker failed"); - return true; + return true; } bool ProxyMessageQueue::finalizeTransport() { - return mq_close(mqNativeListenerDesc) != -1; + return mq_close(mqNativeListenerDesc) != -1; } diff --git a/jclklib/proxy/msgq_tport.hpp b/jclklib/proxy/msgq_tport.hpp index baf5b22a..ddae929a 100644 --- a/jclklib/proxy/msgq_tport.hpp +++ b/jclklib/proxy/msgq_tport.hpp @@ -12,54 +12,53 @@ * */ +#ifndef PROXY_MSGQ_TPORT_HPP +#define PROXY_MSGQ_TPORT_HPP + #include -#include #include #include - #include +#include -#ifndef PROXY_MSGQ_TPORT_HPP -#define PROXY_MSGQ_TPORT_HPP - -#include #include #include +#include #define MAX_CLIENT_COUNT (8) namespace JClkLibProxy { - class ProxyMessageQueueListenerContext : virtual public JClkLibCommon::MessageQueueListenerContext, - virtual public ProxyTransportListenerContext - { - friend class ProxyMessageQueue; - protected: - virtual LISTENER_CONTEXT_PROCESS_MESSAGE_TYPE(processMessage); - ProxyMessageQueueListenerContext(mqd_t mqListenerDesc); - public: - virtual ~ProxyMessageQueueListenerContext() = default; - virtual CREATE_TRANSMIT_CONTEXT_TYPE(CreateTransmitterContext); - }; + class ProxyMessageQueueListenerContext : virtual public JClkLibCommon::MessageQueueListenerContext, + virtual public ProxyTransportListenerContext + { + friend class ProxyMessageQueue; + protected: + virtual LISTENER_CONTEXT_PROCESS_MESSAGE_TYPE(processMessage); + ProxyMessageQueueListenerContext(mqd_t mqListenerDesc); + public: + virtual ~ProxyMessageQueueListenerContext() = default; + virtual CREATE_TRANSMIT_CONTEXT_TYPE(CreateTransmitterContext); + }; - class ProxyMessageQueueTransmitterContext : virtual public JClkLibCommon::MessageQueueTransmitterContext, - virtual public ProxyTransportTransmitterContext - { - friend class ProxyMessageQueue; - friend class ProxyMessageQueueListenerContext; - protected: - ProxyMessageQueueTransmitterContext(mqd_t mqTransmitterDesc); - public: - virtual ~ProxyMessageQueueTransmitterContext() = default; + class ProxyMessageQueueTransmitterContext : virtual public JClkLibCommon::MessageQueueTransmitterContext, + virtual public ProxyTransportTransmitterContext + { + friend class ProxyMessageQueue; + friend class ProxyMessageQueueListenerContext; + protected: + ProxyMessageQueueTransmitterContext(mqd_t mqTransmitterDesc); + public: + virtual ~ProxyMessageQueueTransmitterContext() = default; }; - class ProxyMessageQueue : public JClkLibCommon::MessageQueue, public ProxyTransport - { - public: - static bool initTransport(); - static bool stopTransport(); - static bool finalizeTransport(); - }; + class ProxyMessageQueue : public JClkLibCommon::MessageQueue, public ProxyTransport + { + public: + static bool initTransport(); + static bool stopTransport(); + static bool finalizeTransport(); + }; } -#endif/*PROXY_MSGQ_TPORT_HPP*/ +#endif /* PROXY_MSGQ_TPORT_HPP */ diff --git a/jclklib/proxy/notification_msg.cpp b/jclklib/proxy/notification_msg.cpp index 2ce6b7ce..27917606 100644 --- a/jclklib/proxy/notification_msg.cpp +++ b/jclklib/proxy/notification_msg.cpp @@ -12,15 +12,15 @@ * */ -#include +#include +#include #include #include -#include -#include +#include -using namespace std; using namespace JClkLibCommon; using namespace JClkLibProxy; +using namespace std; extern JClkLibCommon::ptp_event pe; @@ -32,8 +32,8 @@ extern JClkLibCommon::ptp_event pe; */ MAKE_RXBUFFER_TYPE(ProxyNotificationMessage::buildMessage) { - msg = new ProxyNotificationMessage(); - return true; + msg = new ProxyNotificationMessage(); + return true; } /** @brief Add proxy's NOTIFY_MESSAGE type and its builder to transport layer. @@ -45,33 +45,33 @@ MAKE_RXBUFFER_TYPE(ProxyNotificationMessage::buildMessage) */ bool ProxyNotificationMessage::initMessage() { - addMessageType(parseMsgMapElement_t(NOTIFY_MESSAGE, buildMessage)); - return true; + addMessageType(parseMsgMapElement_t(NOTIFY_MESSAGE, buildMessage)); + return true; } BUILD_TXBUFFER_TYPE(ProxyNotificationMessage::makeBuffer) const { - PrintDebug("[ProxyNotificationMessage]::makeBuffer"); - if(!Message::makeBuffer(TxContext)) - return false; + PrintDebug("[ProxyNotificationMessage]::makeBuffer"); + if(!Message::makeBuffer(TxContext)) + return false; - /* Add ptp data here */ - if (!WRITE_TX(FIELD, pe, TxContext)) - return false; + /* Add ptp data here */ + if (!WRITE_TX(FIELD, pe, TxContext)) + return false; - return true; + return true; } PROCESS_MESSAGE_TYPE(ProxyNotificationMessage::processMessage) { - return true; + return true; } /* TO BE REMOVED */ bool ProxyNotificationMessage::generateResponse(uint8_t *msgBuffer, size_t &length, - const ClockStatus &status) + const ClockStatus &status) { - return false; + return false; } diff --git a/jclklib/proxy/notification_msg.hpp b/jclklib/proxy/notification_msg.hpp index 237eb15f..9ea464d5 100644 --- a/jclklib/proxy/notification_msg.hpp +++ b/jclklib/proxy/notification_msg.hpp @@ -12,41 +12,41 @@ * */ -#include - #ifndef PROXY_NOTIFICATION_MSG_HPP #define PROXY_NOTIFICATION_MSG_HPP -#include -#include +#include + #include +#include +#include namespace JClkLibProxy { - class ProxyNotificationMessage : virtual public ProxyMessage, - virtual public JClkLibCommon::NotificationMessage - { - public: - ProxyNotificationMessage() : MESSAGE_NOTIFY() {} - virtual PROCESS_MESSAGE_TYPE(processMessage); - bool generateResponse(std::uint8_t *msgBuffer, std::size_t &length, - const ClockStatus &status); - virtual BUILD_TXBUFFER_TYPE(makeBuffer) const; - - /** - * @brief Create the ProxyNotificationMessage object - * @param msg msg structure to be fill up - * @param LxContext proxy transport listener context - * @return true - */ - static MAKE_RXBUFFER_TYPE(buildMessage); - - /** - * @brief Add proxy's NOTIFY_MESSAGE type and its builder to transport layer. - * @return true - */ - static bool initMessage(); - }; + class ProxyNotificationMessage : virtual public ProxyMessage, + virtual public JClkLibCommon::NotificationMessage + { + public: + ProxyNotificationMessage() : MESSAGE_NOTIFY() {} + virtual PROCESS_MESSAGE_TYPE(processMessage); + bool generateResponse(std::uint8_t *msgBuffer, std::size_t &length, + const ClockStatus &status); + virtual BUILD_TXBUFFER_TYPE(makeBuffer) const; + + /** + * @brief Create the ProxyNotificationMessage object + * @param msg msg structure to be fill up + * @param LxContext proxy transport listener context + * @return true + */ + static MAKE_RXBUFFER_TYPE(buildMessage); + + /** + * @brief Add proxy's NOTIFY_MESSAGE type and its builder to transport layer. + * @return true + */ + static bool initMessage(); + }; } -#endif/*PROXY_NOTIFICATION_MSG_HPP*/ +#endif /* PROXY_NOTIFICATION_MSG_HPP */ diff --git a/jclklib/proxy/null_msg.hpp b/jclklib/proxy/null_msg.hpp index 6fed2f52..bd8e60d8 100644 --- a/jclklib/proxy/null_msg.hpp +++ b/jclklib/proxy/null_msg.hpp @@ -15,22 +15,23 @@ #ifndef PROXY_NULL_MSG_HPP #define PROXY_NULL_MSG_HPP -#include #include +#include namespace JClkLibProxy { - class ProxyNullMessage : virtual public ProxyMessage, virtual public JClkLibCommon::CommonNullMessage - { - protected: - ProxyNullMessage() : MESSAGE_NULL() {}; - public: - bool processMessage(ClockConfiguration &config) { return true; } - bool generateResponse(uint8_t *msgBuffer, std::size_t &length, - const ClockStatus &status) - { return false; } - static bool initMessage() { return true; } - }; + class ProxyNullMessage : virtual public ProxyMessage, + virtual public JClkLibCommon::CommonNullMessage + { + protected: + ProxyNullMessage() : MESSAGE_NULL() {}; + public: + bool processMessage(ClockConfiguration &config) { return true; } + bool generateResponse(uint8_t *msgBuffer, std::size_t &length, + const ClockStatus &status) + { return false; } + static bool initMessage() { return true; } + }; } -#endif/*PROXY_NULL_MSG_HPP*/ +#endif /* PROXY_NULL_MSG_HPP */ diff --git a/jclklib/proxy/null_tport.cpp b/jclklib/proxy/null_tport.cpp index 2421610c..e7c80b09 100644 --- a/jclklib/proxy/null_tport.cpp +++ b/jclklib/proxy/null_tport.cpp @@ -12,17 +12,16 @@ * */ +#include + #include #include -#include - using namespace JClkLibProxy; using namespace std; SEND_PROXY_MESSAGE(NullProxyTransport::sendMessage) { - PrintError("NullTransport should not be used"); - return false; + PrintError("NullTransport should not be used"); + return false; } - diff --git a/jclklib/proxy/null_tport.hpp b/jclklib/proxy/null_tport.hpp index 44cad8a4..2e436a9b 100644 --- a/jclklib/proxy/null_tport.hpp +++ b/jclklib/proxy/null_tport.hpp @@ -15,18 +15,18 @@ #ifndef PROXY_NULL_TPORT_HPP #define PROXY_NULL_TPORT_HPP -#include -#include - #include +#include +#include + namespace JClkLibProxy { - class NullProxyTransport : public JClkLibCommon::NullTransport - { - public: - static SEND_PROXY_MESSAGE(sendMessage); - }; + class NullProxyTransport : public JClkLibCommon::NullTransport + { + public: + static SEND_PROXY_MESSAGE(sendMessage); + }; } -#endif/*PROXY_NULL_TPORT_HPP*/ +#endif /* PROXY_NULL_TPORT_HPP */ diff --git a/jclklib/proxy/subscribe_msg.cpp b/jclklib/proxy/subscribe_msg.cpp index 67abb52b..88c1218e 100644 --- a/jclklib/proxy/subscribe_msg.cpp +++ b/jclklib/proxy/subscribe_msg.cpp @@ -12,16 +12,16 @@ * */ -#include -#include -#include +#include #include #include -#include +#include +#include +#include -using namespace std; -using namespace JClkLibProxy; using namespace JClkLibCommon; +using namespace JClkLibProxy; +using namespace std; extern JClkLibCommon::ptp_event pe; @@ -33,8 +33,8 @@ extern JClkLibCommon::ptp_event pe; */ MAKE_RXBUFFER_TYPE(ProxySubscribeMessage::buildMessage) { - msg = new ProxySubscribeMessage(); - return true; + msg = new ProxySubscribeMessage(); + return true; } /** @brief Add proxy's SUBSCRIBE_MSG type and its builder to transport layer. @@ -46,21 +46,21 @@ MAKE_RXBUFFER_TYPE(ProxySubscribeMessage::buildMessage) */ bool ProxySubscribeMessage::initMessage() { - addMessageType(parseMsgMapElement_t(SUBSCRIBE_MSG, buildMessage)); - return true; + addMessageType(parseMsgMapElement_t(SUBSCRIBE_MSG, buildMessage)); + return true; } BUILD_TXBUFFER_TYPE(ProxySubscribeMessage::makeBuffer) const { - PrintDebug("[ProxySubscribeMessage]::makeBuffer"); - if(!CommonSubscribeMessage::makeBuffer(TxContext)) - return false; + PrintDebug("[ProxySubscribeMessage]::makeBuffer"); + if(!CommonSubscribeMessage::makeBuffer(TxContext)) + return false; - /* Add ptp data here */ - if (!WRITE_TX(FIELD, pe, TxContext)) - return false; + /* Add ptp data here */ + if (!WRITE_TX(FIELD, pe, TxContext)) + return false; - return true; + return true; } /* @@ -69,29 +69,26 @@ This is to process the subscription from the jclklib client runtime via POSIX ms */ PROCESS_MESSAGE_TYPE(ProxySubscribeMessage::processMessage) { - //config.setEvent(subscription.getEvent()); - //config.setValue(subscription.getValue()); - - sessionId_t sID; - sID = this->getc_sessionId(); - PrintDebug("[ProxySubscribeMessage]::processMessage - Use current client session ID: " + to_string(sID)); + sessionId_t sID; + sID = this->getc_sessionId(); + PrintDebug("[ProxySubscribeMessage]::processMessage - Use current client session ID: " + to_string(sID)); - if(sID == InvalidSessionId) { - PrintError("Session ID *should be* invalid for received proxy connect message"); - return false; - } - TxContext = Client::GetClientSession(sID).get()->get_transmitContext(); - set_msgAck(ACK_SUCCESS); - return true; + if(sID == InvalidSessionId) { + PrintError("Session ID *should be* invalid for received proxy connect message"); + return false; + } + TxContext = Client::GetClientSession(sID).get()->get_transmitContext(); + set_msgAck(ACK_SUCCESS); + return true; } /* [NOTE] This is to response towards ProxySubscribeMessage - wont be using this for the time being. */ bool ProxySubscribeMessage::generateResponse(uint8_t *msgBuffer, size_t &length, - const ClockStatus &status) + const ClockStatus &status) { - return false; + return false; } diff --git a/jclklib/proxy/subscribe_msg.hpp b/jclklib/proxy/subscribe_msg.hpp index d03cd588..bee25f8a 100644 --- a/jclklib/proxy/subscribe_msg.hpp +++ b/jclklib/proxy/subscribe_msg.hpp @@ -15,35 +15,36 @@ #ifndef PROXY_SUBSCRIBE_MSG_HPP #define PROXY_SUBSCRIBE_MSG_HPP -#include #include +#include namespace JClkLibProxy { - class ProxySubscribeMessage : virtual public ProxyMessage, virtual public JClkLibCommon::CommonSubscribeMessage - { - protected: - ProxySubscribeMessage() : MESSAGE_SUBSCRIBE() {}; - public: - //bool processMessage(ClockConfiguration &config); - virtual PROCESS_MESSAGE_TYPE(processMessage); - virtual BUILD_TXBUFFER_TYPE(makeBuffer) const; - bool generateResponse(uint8_t *msgBuffer, std::size_t &length, - const ClockStatus &status); - /** - * @brief Create the ProxyConnectMessage object - * @param msg msg structure to be fill up - * @param LxContext proxy transport listener context - * @return true - */ + class ProxySubscribeMessage : virtual public ProxyMessage, + virtual public JClkLibCommon::CommonSubscribeMessage + { + protected: + ProxySubscribeMessage() : MESSAGE_SUBSCRIBE() {}; + public: + //bool processMessage(ClockConfiguration &config); + virtual PROCESS_MESSAGE_TYPE(processMessage); + virtual BUILD_TXBUFFER_TYPE(makeBuffer) const; + bool generateResponse(uint8_t *msgBuffer, std::size_t &length, + const ClockStatus &status); + /** + * @brief Create the ProxyConnectMessage object + * @param msg msg structure to be fill up + * @param LxContext proxy transport listener context + * @return true + */ static MAKE_RXBUFFER_TYPE(buildMessage); - /** - * @brief Add proxy's CONNECT_MSG type and its builder to transport layer. - * @return true - */ - static bool initMessage(); - }; + /** + * @brief Add proxy's CONNECT_MSG type and its builder to transport layer. + * @return true + */ + static bool initMessage(); + }; } -#endif/*PROXY_SUBSCRIBE_MSG_HPP*/ +#endif /* PROXY_SUBSCRIBE_MSG_HPP */ diff --git a/jclklib/proxy/thread.cpp b/jclklib/proxy/thread.cpp index bb284e04..a9ab9ba9 100644 --- a/jclklib/proxy/thread.cpp +++ b/jclklib/proxy/thread.cpp @@ -16,68 +16,70 @@ static int start_work_thread( struct ptp4l_handle *handle ) { - int ret; + int ret; - if(( ret = -pthread_create( &handle->work_thread, NULL, ptp4l_event_loop, (void *) handle)) < 0) - return ret; + if(( ret = -pthread_create( &handle->work_thread, NULL, ptp4l_event_loop, + (void *) handle)) < 0) + return ret; - return 0; + return 0; } -int connect_ptp4l( struct ptp4l_handle **phandle, struct epoll_event epd_event, state_update_t update_cb, void *ctx) +int connect_ptp4l( struct ptp4l_handle **phandle, struct epoll_event epd_event, + state_update_t update_cb, void *ctx) { - struct ptp4l_handle *handle; - int ret; + struct ptp4l_handle *handle; + int ret; - handle = (typeof( handle)) malloc(( size_t) sizeof(*handle)); - if( handle == NULL) { - ret = -errno; - goto alloc_handle_fail; - } + handle = (typeof( handle)) malloc(( size_t) sizeof(*handle)); + if( handle == NULL) { + ret = -errno; + goto alloc_handle_fail; + } - if(( ret = start_work_thread( handle)) < 0) - goto thread_failed; + if(( ret = start_work_thread( handle)) < 0) + goto thread_failed; - *phandle = handle; - return 0; + *phandle = handle; + return 0; thread_failed: alloc_handle_fail: - return ret; + return ret; } int set_thread_signal( struct thread_signal *signal) { - int err, ret; + int err, ret; - if(( ret = pthread_mutex_lock( &signal->siglock)) != 0) - goto lock_fail; - signal->signaled = true; - if(( ret = pthread_cond_signal( &signal->signal )) != 0) - goto signal_fail; + if(( ret = pthread_mutex_lock( &signal->siglock)) != 0) + goto lock_fail; + signal->signaled = true; + if(( ret = pthread_cond_signal( &signal->signal )) != 0) + goto signal_fail; signal_fail: - if(( err = pthread_mutex_unlock( &signal->siglock)) != 0) - ret = ret == 0 ? err : ret; // Report first error only + if(( err = pthread_mutex_unlock( &signal->siglock)) != 0) + ret = ret == 0 ? err : ret; lock_fail: - return -ret; + return -ret; } static bool state_update_callback( struct ptp4l_state *state, void * ctx) { - struct jcl_handle *handle = (typeof(handle)) ctx; - int ret; + struct jcl_handle *handle = (typeof(handle)) ctx; + int ret; - if(( ret = -pthread_mutex_lock( &handle->state_lock)) < 0) - goto lock_failed; + if(( ret = -pthread_mutex_lock( &handle->state_lock)) < 0) + goto lock_failed; - if(( ret = -pthread_mutex_unlock( &handle->state_lock)) < 0) - goto unlock_failed; + if(( ret = -pthread_mutex_unlock( &handle->state_lock)) < 0) + goto unlock_failed; unlock_failed: lock_failed: - return ret >= 0 ? true : false; + return ret >= 0 ? true : false; } /** @@ -96,28 +98,28 @@ static bool state_update_callback( struct ptp4l_state *state, void * ctx) */ int handle_connect(struct epoll_event epd_event ) { - struct jcl_handle *handle; - int ret; + struct jcl_handle *handle; + int ret; - handle = ( typeof( handle)) malloc(( size_t) sizeof( *handle)); - if( handle == NULL) { - ret = -errno; - goto alloc_fail; - } + handle = ( typeof( handle)) malloc(( size_t) sizeof( *handle)); + if( handle == NULL) { + ret = -errno; + goto alloc_fail; + } - event_subscription( &handle ); + event_subscription( &handle ); - ret = connect_ptp4l( &handle->ptp4l_handle, - epd_event, state_update_callback, handle); - if (ret != 0) { - free(handle); // Free the memory if connect_ptp4l fails - goto alloc_fail; - } + ret = connect_ptp4l( &handle->ptp4l_handle, + epd_event, state_update_callback, handle); + if (ret != 0) { + free(handle); + goto alloc_fail; + } - free(handle); - return 0; + free(handle); + return 0; alloc_fail: - return ret; + return ret; } diff --git a/jclklib/proxy/thread.hpp b/jclklib/proxy/thread.hpp index ef116dd5..6592313e 100644 --- a/jclklib/proxy/thread.hpp +++ b/jclklib/proxy/thread.hpp @@ -12,18 +12,19 @@ * */ -#include -#include -#include #include -#include -#include +#include #include +#include +#include +#include +#include +#include #include #include -#include #include -#include +#include + #include typedef struct thread_signal *thread_signal_t; @@ -34,36 +35,37 @@ typedef bool ( *state_update_t)( struct ptp4l_state *, void *); typedef struct thread_signal *thread_signal_t; struct thread_signal { - pthread_mutex_t siglock; - pthread_cond_t signal; - bool signaled; + pthread_mutex_t siglock; + pthread_cond_t signal; + bool signaled; }; struct jcl_handle { - ptp4l_handle_t ptp4l_handle; - thread_signal_t status_signal; - pthread_mutex_t state_lock; - struct JClkLibCommon::jcl_state state; + ptp4l_handle_t ptp4l_handle; + thread_signal_t status_signal; + pthread_mutex_t state_lock; + struct JClkLibCommon::jcl_state state; }; struct ptp4l_handle { - struct epoll_event epd_event; - state_update_t update_cb; - void *ctx; - pthread_t work_thread; + struct epoll_event epd_event; + state_update_t update_cb; + void *ctx; + pthread_t work_thread; }; struct ptp4l_state { - bool initialized; - unsigned valid_mask; - bool peer_present; - unsigned offset; - bool servo_locked; + bool initialized; + unsigned valid_mask; + bool peer_present; + unsigned offset; + bool servo_locked; }; int handle_connect(struct epoll_event epd_event ); -int connect_ptp4l(ptp4l_handle_t *phandle, struct epoll_event epd_event, state_update_t update, void *ctx); +int connect_ptp4l(ptp4l_handle_t *phandle, struct epoll_event epd_event, + state_update_t update, void *ctx); void *ptp4l_event_loop(void *arg); bool event_subscription(struct jcl_handle **handle); diff --git a/jclklib/proxy/transport.cpp b/jclklib/proxy/transport.cpp index 911e7646..e98c868c 100644 --- a/jclklib/proxy/transport.cpp +++ b/jclklib/proxy/transport.cpp @@ -12,12 +12,12 @@ * */ -#include -#include -#include #include #include #include +#include +#include +#include #define EXIT_TIMEOUT (200 /*ms*/) #define START_TIMEOUT (20 /*ms*/) @@ -28,27 +28,26 @@ using namespace std; bool ProxyTransport::init() { - if (!Transport::init()) - return false; - PrintDebug("Finished common init"); + if (!Transport::init()) + return false; + PrintDebug("Finished common init"); - return JClkLibCommon::_initTransport(); + return JClkLibCommon::_initTransport(); } bool ProxyTransport::stop() { - if (!Transport::stop()) - return false; + if (!Transport::stop()) + return false; - /* Do any transport specific stop */ - return JClkLibCommon::_stopTransport(); + /* Do any transport specific stop */ + return JClkLibCommon::_stopTransport(); } bool ProxyTransport::finalize() { - if (!Transport::finalize()) - return false; + if (!Transport::finalize()) + return false; - return JClkLibCommon::_finalizeTransport(); + return JClkLibCommon::_finalizeTransport(); } - diff --git a/jclklib/proxy/transport.hpp b/jclklib/proxy/transport.hpp index bc861281..e6fee17c 100644 --- a/jclklib/proxy/transport.hpp +++ b/jclklib/proxy/transport.hpp @@ -12,47 +12,47 @@ * */ +#ifndef PROXY_TRANSPORT_HPP +#define PROXY_TRANSPORT_HPP + #include #include -#include -#include #include +#include #include +#include -#ifndef PROXY_TRANSPORT_HPP -#define PROXY_TRANSPORT_HPP - -#include #include -#include -#include #include +#include +#include +#include namespace JClkLibProxy { - class ProxyTransportTransmitterContext : virtual public JClkLibCommon::TransportTransmitterContext { - protected: - ProxyTransportTransmitterContext() {} - public: - virtual ~ProxyTransportTransmitterContext() = default; - }; - - class ProxyTransportListenerContext : virtual public JClkLibCommon::TransportListenerContext { - public: - virtual ~ProxyTransportListenerContext() = default; - }; + class ProxyTransportTransmitterContext : virtual public JClkLibCommon::TransportTransmitterContext { + protected: + ProxyTransportTransmitterContext() {} + public: + virtual ~ProxyTransportTransmitterContext() = default; + }; + + class ProxyTransportListenerContext : virtual public JClkLibCommon::TransportListenerContext { + public: + virtual ~ProxyTransportListenerContext() = default; + }; - class ProxyTransport : public JClkLibCommon::Transport - { - public: - static bool init(); - static bool stop(); - static bool finalize(); + class ProxyTransport : public JClkLibCommon::Transport + { + public: + static bool init(); + static bool stop(); + static bool finalize(); #define SEND_PROXY_MESSAGE(name) \ - bool name (const JClkLibProxy::ProxyMessage *msg) - static SEND_PROXY_MESSAGE(sendMessage) { return false; } - }; + bool name (const JClkLibProxy::ProxyMessage *msg) + static SEND_PROXY_MESSAGE(sendMessage) { return false; } + }; } -#endif/*PROXY_TRANSPORT_HPP*/ +#endif /* PROXY_TRANSPORT_HPP */ From 5dcaefc61ee68286c6695f0937613ed41e7dc90a Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Fri, 24 May 2024 14:46:24 +0800 Subject: [PATCH 118/151] jclklib: Add sample application example output Signed-off-by: Lai Peter Jun Ann --- jclklib/TEST_jclklib.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/jclklib/TEST_jclklib.md b/jclklib/TEST_jclklib.md index b2b8931b..43be2f68 100644 --- a/jclklib/TEST_jclklib.md +++ b/jclklib/TEST_jclklib.md @@ -129,3 +129,31 @@ Options: -t timeout in waiting notification event (s) Default: 10 s ``` + +Example output of sample application (jclk_test) : +```bash +[jclklib] Connected. Session ID : 1 +[jclklib] set subscribe event : jcl_event : event[0] = 15 +[jclklib] set composite event : jcl_event : event[0] = 7 + +Upper Master Offset: 100000 ns +Lower Master Offset: -100000 ns + +[jclklib] Obtained data from Subscription Event: ++-------------------+--------------------+ +| Event | Event Status | ++-------------------+--------------------+ +| offset_in_range | 1 | +| servo_locked | 1 | +| as_Capable | 1 | +| gm_Changed | 1 | ++-------------------+--------------------+ +| UUID | 00a1c1.fffe.000000 | ++-------------------+--------------------+ +| composite_event | 1 | +| - offset_in_range | | +| - servo_locked | | +| - as_Capable | | ++-------------------+--------------------+ + +``` From 5921f4e3009e6bfd3167d73af2186c70db1bf130 Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Fri, 24 May 2024 14:51:50 +0800 Subject: [PATCH 119/151] jclklib: Change file name to connect_ptp Signed-off-by: Lai Peter Jun Ann --- jclklib/proxy/Makefile | 2 +- jclklib/proxy/{connect.cpp => connect_ptp4l.cpp} | 2 +- jclklib/proxy/{connect.hpp => connect_ptp4l.hpp} | 0 jclklib/proxy/main.cpp | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename jclklib/proxy/{connect.cpp => connect_ptp4l.cpp} (99%) rename jclklib/proxy/{connect.hpp => connect_ptp4l.hpp} (100%) diff --git a/jclklib/proxy/Makefile b/jclklib/proxy/Makefile index 452c9772..fa19226b 100644 --- a/jclklib/proxy/Makefile +++ b/jclklib/proxy/Makefile @@ -15,7 +15,7 @@ JCLKLIB_COMMON_DIR = $(JCLKLIB_TOPLEVEL_DIR)/common PTPMGMT_DIR := $(JCLKLIB_TOPLEVEL_DIR)/.. LIBS = pthread rt ptpmgmt LIBS_FLAGS = $(foreach lib,$(LIBS),-l$(lib)) -L$(PTPMGMT_DIR) -OBJ = client main message msgq_tport notification_msg null_tport connect_msg subscribe_msg transport connect thread +OBJ = client main message msgq_tport notification_msg null_tport connect_msg subscribe_msg transport connect_ptp4l thread COMMON_OBJ = print sighandler transport msgq_tport jclklib_import message connect_msg subscribe_msg notification_msg OBJ_FILES = $(foreach f,$(OBJ),$(f).o) DEPENDS = $(foreach f,$(OBJ),$(f).d) diff --git a/jclklib/proxy/connect.cpp b/jclklib/proxy/connect_ptp4l.cpp similarity index 99% rename from jclklib/proxy/connect.cpp rename to jclklib/proxy/connect_ptp4l.cpp index 7a235093..35aca555 100644 --- a/jclklib/proxy/connect.cpp +++ b/jclklib/proxy/connect_ptp4l.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include "thread.hpp" #include "../../pub/init.h" diff --git a/jclklib/proxy/connect.hpp b/jclklib/proxy/connect_ptp4l.hpp similarity index 100% rename from jclklib/proxy/connect.hpp rename to jclklib/proxy/connect_ptp4l.hpp diff --git a/jclklib/proxy/main.cpp b/jclklib/proxy/main.cpp index 433be078..5e5a04b1 100644 --- a/jclklib/proxy/main.cpp +++ b/jclklib/proxy/main.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include From 5c2040a50d5046b22ff56c4918713da506810185 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Fri, 24 May 2024 15:51:14 +0800 Subject: [PATCH 120/151] jclklib: Add Proxy message queue liveness check Check whether Proxy still alive by sending connect msg and wait for response. Signed-off-by: Song Yoong Siang --- jclklib/client/jclk_init.cpp | 35 ++++++++++++++++++++++++++++++++++- jclklib/proxy/connect_msg.cpp | 22 ++++++++++++++++------ jclklib/sample/jclk_test.cpp | 8 +++++++- 3 files changed, 57 insertions(+), 8 deletions(-) diff --git a/jclklib/client/jclk_init.cpp b/jclklib/client/jclk_init.cpp index 9b6441cf..627b8d7a 100644 --- a/jclklib/client/jclk_init.cpp +++ b/jclklib/client/jclk_init.cpp @@ -168,6 +168,35 @@ bool JClkLibClientApi::jcl_disconnect() return retVal; } +bool check_proxy_liveness(ClientState &appClientState, int timeout) +{ + Message0 connectMsg(new ClientConnectMessage()); + ClientConnectMessage *cmsg = dynamic_cast(connectMsg.get()); + + appClientState.set_connected(false); + cmsg->setClientState(&appClientState); + cmsg->set_sessionId(appClientState.get_sessionId()); + ClientMessageQueue::writeTransportClientId(connectMsg.get()); + ClientMessageQueue::sendMessage(connectMsg.get()); + + /* Wait for connection result */ + auto endTime = std::chrono::system_clock::now() + std::chrono::seconds(timeout); + std::unique_lock lck(ClientConnectMessage::cv_mtx); + while (appClientState.get_connected() == false) { + auto res = ClientConnectMessage::cv.wait_until(lck, endTime); + if (res == std::cv_status::timeout) { + if (appClientState.get_connected() == false) { + PrintDebug("[CONNECT] Connect reply timeout!!"); + return false; + } + } else { + PrintDebug("[CONNECT] Connect reply received."); + } + } + + return true; +} + /** * @brief This function waits for a specified timeout period for any event changes. * @@ -191,7 +220,11 @@ int JClkLibClientApi::jcl_status_wait(int timeout, std::chrono::time_point::max() : start + std::chrono::seconds(timeout); bool event_changes_detected = false; - + + /* Check the liveness of the Proxy's message queue */ + if (!check_proxy_liveness(appClientState, timeout)) + return -1; + JClkLibCommon::jcl_state_event_count eventCount; JClkLibCommon::jcl_state jcl_state; do { diff --git a/jclklib/proxy/connect_msg.cpp b/jclklib/proxy/connect_msg.cpp index dfafbbca..01baaadc 100644 --- a/jclklib/proxy/connect_msg.cpp +++ b/jclklib/proxy/connect_msg.cpp @@ -66,21 +66,31 @@ bool ProxyConnectMessage::initMessage() */ PROCESS_MESSAGE_TYPE(ProxyConnectMessage::processMessage) { - sessionId_t newSessionId; + sessionId_t newSessionId = this->getc_sessionId(); PrintDebug("Processing proxy connect message"); - if (this->getc_sessionId() != InvalidSessionId) { - PrintError("Session ID *should be* invalid for received proxy connect message"); - return false; - } - /* Check whether there is ptp4l available */ if (!pe.ptp4l_id) { PrintError("ptp4l_id is not available."); return false; } + if (newSessionId != InvalidSessionId) { + auto clientSession = Client::GetClientSession(newSessionId); + if (clientSession) + TxContext = clientSession.get()->get_transmitContext(); + + if (TxContext) { + PrintDebug("Receive Connect msg as liveness check."); + set_msgAck(ACK_SUCCESS); + return true; + } + + PrintError("Session ID not exists: " + to_string(newSessionId)); + return false; + } + newSessionId = Client::CreateClientSession(); PrintDebug("Created new client session ID: " + to_string(newSessionId)); this->set_sessionId(newSessionId); diff --git a/jclklib/sample/jclk_test.cpp b/jclklib/sample/jclk_test.cpp index 7fd58c2d..ca7010c5 100644 --- a/jclklib/sample/jclk_test.cpp +++ b/jclklib/sample/jclk_test.cpp @@ -44,6 +44,7 @@ int main(int argc, char *argv[]) int ret = EXIT_SUCCESS; int idle_time = 1; int timeout = 10; + int retval; int opt; std::uint32_t event2Sub1[1] = { @@ -212,13 +213,18 @@ int main(int argc, char *argv[]) while (!signal_flag) { printf("[jclklib] Waiting for Notification Event...\n"); - if (!cmAPI->jcl_status_wait(timeout, jcl_state , eventCount)) { + retval = cmAPI->jcl_status_wait(timeout, jcl_state , eventCount); + if (!retval) { printf("No event status changes identified in %d seconds.\n\n", timeout); printf("[jclklib] sleep for %d seconds...\n\n", idle_time); sleep(idle_time); continue; + } else if (retval < 0) { + printf("[jclklib] Terminating: lost connection to jclklib Proxy\n"); + return EXIT_SUCCESS; } + printf("[jclklib] Obtained data from Notification Event:\n"); printf("+-------------------+--------------+-------------+\n"); printf("| %-17s | %-12s | %-11s |\n", "Event", "Event Status", From 99277d37531b368e3afa60aac919dd3f0d24ee4d Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Fri, 24 May 2024 16:58:24 +0800 Subject: [PATCH 121/151] Add null check for dynamic cast in check_proxy_liveness This commit adds a null check for the dynamic cast of `connectMsg.get()` to `ClientConnectMessage` in the `check_proxy_liveness` function. Previously, if the dynamic cast failed, the program would attempt to dereference a null pointer, leading to undefined behavior. With this change, if the dynamic cast fails, the function will print a debug message and return false, preventing the null pointer dereference. Signed-off-by: Song Yoong Siang --- jclklib/client/jclk_init.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/jclklib/client/jclk_init.cpp b/jclklib/client/jclk_init.cpp index 627b8d7a..4888e0ec 100644 --- a/jclklib/client/jclk_init.cpp +++ b/jclklib/client/jclk_init.cpp @@ -173,6 +173,11 @@ bool check_proxy_liveness(ClientState &appClientState, int timeout) Message0 connectMsg(new ClientConnectMessage()); ClientConnectMessage *cmsg = dynamic_cast(connectMsg.get()); + if (cmsg == nullptr) { + PrintDebug("[CONNECT] Failed to cast to ClientConnectMessage"); + return false; + } + appClientState.set_connected(false); cmsg->setClientState(&appClientState); cmsg->set_sessionId(appClientState.get_sessionId()); From 124029c9c9fbd83556ac402da6e50fca96c2cc55 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Fri, 24 May 2024 17:14:36 +0800 Subject: [PATCH 122/151] jclklib: Set default timeout for Proxy liveness check as 1s Set as default 1s instead of taking the value of timeout from wait API. Signed-off-by: Song Yoong Siang --- jclklib/client/jclk_init.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/jclklib/client/jclk_init.cpp b/jclklib/client/jclk_init.cpp index 4888e0ec..8f013794 100644 --- a/jclklib/client/jclk_init.cpp +++ b/jclklib/client/jclk_init.cpp @@ -26,6 +26,7 @@ #include #include +#define DEFAULT_LIVENESS_TIME_OUT 1 //1 sec #define DEFAULT_CONNECT_TIME_OUT 5 //5 sec #define DEFAULT_SUBSCRIBE_TIME_OUT 5 //5 sec @@ -168,8 +169,9 @@ bool JClkLibClientApi::jcl_disconnect() return retVal; } -bool check_proxy_liveness(ClientState &appClientState, int timeout) +bool check_proxy_liveness(ClientState &appClientState) { + unsigned int timeout_sec = (unsigned int) DEFAULT_LIVENESS_TIME_OUT; Message0 connectMsg(new ClientConnectMessage()); ClientConnectMessage *cmsg = dynamic_cast(connectMsg.get()); @@ -185,7 +187,7 @@ bool check_proxy_liveness(ClientState &appClientState, int timeout) ClientMessageQueue::sendMessage(connectMsg.get()); /* Wait for connection result */ - auto endTime = std::chrono::system_clock::now() + std::chrono::seconds(timeout); + auto endTime = std::chrono::system_clock::now() + std::chrono::seconds(timeout_sec); std::unique_lock lck(ClientConnectMessage::cv_mtx); while (appClientState.get_connected() == false) { auto res = ClientConnectMessage::cv.wait_until(lck, endTime); @@ -227,7 +229,7 @@ int JClkLibClientApi::jcl_status_wait(int timeout, bool event_changes_detected = false; /* Check the liveness of the Proxy's message queue */ - if (!check_proxy_liveness(appClientState, timeout)) + if (!check_proxy_liveness(appClientState)) return -1; JClkLibCommon::jcl_state_event_count eventCount; From ff317bf03b18b2e0b8fe052009157f224b2241df Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Thu, 30 May 2024 15:07:49 +0800 Subject: [PATCH 123/151] jclklib: Add time printing in user app Signed-off-by: Lai Peter Jun Ann --- jclklib/sample/jclk_test.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/jclklib/sample/jclk_test.cpp b/jclklib/sample/jclk_test.cpp index ca7010c5..e3b6503f 100644 --- a/jclklib/sample/jclk_test.cpp +++ b/jclklib/sample/jclk_test.cpp @@ -34,6 +34,20 @@ void signal_handler(int sig) signal_flag = 1; } +double getMonotonicTime() { + struct timespec timeSpec; + + if (clock_gettime(CLOCK_MONOTONIC, &timeSpec) == -1) { + perror("clock_gettime failed"); + return -1; + } + + double seconds = timeSpec.tv_sec; + double nanoseconds = timeSpec.tv_nsec / 1e9; + + return seconds + nanoseconds; +} + int main(int argc, char *argv[]) { JClkLibCommon::jcl_state_event_count eventCount = {}; @@ -164,7 +178,7 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - printf("[jclklib] Obtained data from Subscription Event:\n"); + printf("[jclklib][%.3f] Obtained data from Subscription Event:\n", getMonotonicTime()); printf("+-------------------+--------------------+\n"); printf("| %-17s | %-18s |\n", "Event", "Event Status"); if (event2Sub1[0]) { @@ -212,20 +226,20 @@ int main(int argc, char *argv[]) sleep(1); while (!signal_flag) { - printf("[jclklib] Waiting for Notification Event...\n"); + printf("[jclklib] Waiting for Notification Event...\n", getMonotonicTime()); retval = cmAPI->jcl_status_wait(timeout, jcl_state , eventCount); if (!retval) { - printf("No event status changes identified in %d seconds.\n\n", - timeout); - printf("[jclklib] sleep for %d seconds...\n\n", idle_time); + printf("[jclklib][%.3f] No event status changes identified in %d seconds.\n\n", + getMonotonicTime(), timeout); + printf("[jclklib][%.3f] sleep for %d seconds...\n\n", getMonotonicTime(), idle_time); sleep(idle_time); continue; } else if (retval < 0) { - printf("[jclklib] Terminating: lost connection to jclklib Proxy\n"); + printf("[jclklib][%.3f] Terminating: lost connection to jclklib Proxy\n",getMonotonicTime()); return EXIT_SUCCESS; } - printf("[jclklib] Obtained data from Notification Event:\n"); + printf("[jclklib][%.3f] Obtained data from Notification Event:\n",getMonotonicTime()); printf("+-------------------+--------------+-------------+\n"); printf("| %-17s | %-12s | %-11s |\n", "Event", "Event Status", "Event Count"); @@ -275,7 +289,7 @@ int main(int argc, char *argv[]) printf("\n"); } - printf("[jclklib] sleep for %d seconds...\n\n", idle_time); + printf("[jclklib][%.3f] sleep for %d seconds...\n\n", getMonotonicTime(), idle_time); sleep(idle_time); } From af5d63d445eac5ff58eaf6c94d4e0faee6de6753 Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Thu, 30 May 2024 15:08:45 +0800 Subject: [PATCH 124/151] jclklib: Add chrt -f 99 in run_jclk_test.sh Signed-off-by: Lai Peter Jun Ann --- jclklib/sample/run_jclk_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jclklib/sample/run_jclk_test.sh b/jclklib/sample/run_jclk_test.sh index 79807d94..67b11cce 100755 --- a/jclklib/sample/run_jclk_test.sh +++ b/jclklib/sample/run_jclk_test.sh @@ -11,4 +11,4 @@ SCRIPT_PATH="$(dirname "$0")" TEST_PATH="${SCRIPT_PATH}/../client" -LD_LIBRARY_PATH=$TEST_PATH $SCRIPT_PATH/jclk_test "$@" +LD_LIBRARY_PATH=$TEST_PATH chrt -f 99 $SCRIPT_PATH/jclk_test "$@" From b3f2c862b537b1dd0efb0c8c6fd5fcb6b62d8d38 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Mon, 3 Jun 2024 16:28:37 +0800 Subject: [PATCH 125/151] jclklib: sample: add missing timestamp Add missing time printing into printf and keep code wrap at 80 char Signed-off-by: Song Yoong Siang --- jclklib/sample/jclk_test.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/jclklib/sample/jclk_test.cpp b/jclklib/sample/jclk_test.cpp index e3b6503f..8dcd752c 100644 --- a/jclklib/sample/jclk_test.cpp +++ b/jclklib/sample/jclk_test.cpp @@ -178,7 +178,8 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - printf("[jclklib][%.3f] Obtained data from Subscription Event:\n", getMonotonicTime()); + printf("[jclklib][%.3f] Obtained data from Subscription Event:\n", + getMonotonicTime()); printf("+-------------------+--------------------+\n"); printf("| %-17s | %-18s |\n", "Event", "Event Status"); if (event2Sub1[0]) { @@ -226,20 +227,24 @@ int main(int argc, char *argv[]) sleep(1); while (!signal_flag) { - printf("[jclklib] Waiting for Notification Event...\n", getMonotonicTime()); + printf("[jclklib][%.3f] Waiting for Notification Event...\n", + getMonotonicTime()); retval = cmAPI->jcl_status_wait(timeout, jcl_state , eventCount); if (!retval) { printf("[jclklib][%.3f] No event status changes identified in %d seconds.\n\n", getMonotonicTime(), timeout); - printf("[jclklib][%.3f] sleep for %d seconds...\n\n", getMonotonicTime(), idle_time); + printf("[jclklib][%.3f] sleep for %d seconds...\n\n", + getMonotonicTime(), idle_time); sleep(idle_time); continue; } else if (retval < 0) { - printf("[jclklib][%.3f] Terminating: lost connection to jclklib Proxy\n",getMonotonicTime()); + printf("[jclklib][%.3f] Terminating: lost connection to jclklib Proxy\n", + getMonotonicTime()); return EXIT_SUCCESS; } - printf("[jclklib][%.3f] Obtained data from Notification Event:\n",getMonotonicTime()); + printf("[jclklib][%.3f] Obtained data from Notification Event:\n", + getMonotonicTime()); printf("+-------------------+--------------+-------------+\n"); printf("| %-17s | %-12s | %-11s |\n", "Event", "Event Status", "Event Count"); @@ -289,7 +294,8 @@ int main(int argc, char *argv[]) printf("\n"); } - printf("[jclklib][%.3f] sleep for %d seconds...\n\n", getMonotonicTime(), idle_time); + printf("[jclklib][%.3f] sleep for %d seconds...\n\n", + getMonotonicTime(), idle_time); sleep(idle_time); } From 91b106d2449e735103fcd31638d3780351a80d9e Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Fri, 31 May 2024 15:49:33 +0800 Subject: [PATCH 126/151] jclklib: Change datatype of servo_state and as_cap to boolean Signed-off-by: Lai Peter Jun Ann --- jclklib/client/notification_msg.cpp | 8 ++++---- jclklib/client/subscribe_msg.cpp | 8 ++++---- jclklib/common/jclklib_import.hpp | 8 ++++---- jclklib/proxy/connect_ptp4l.cpp | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/jclklib/client/notification_msg.cpp b/jclklib/client/notification_msg.cpp index 3bb55b82..fbbb24fd 100644 --- a/jclklib/client/notification_msg.cpp +++ b/jclklib/client/notification_msg.cpp @@ -153,17 +153,17 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) } if (composite_eventSub[0] & 1<composite_event &= proxy_data.servo_state >= SERVO_LOCKED ? true:false; + composite_client_ptp_data->composite_event &= proxy_data.servo_state; if (composite_eventSub[0] & 1<composite_event &= proxy_data.asCapable > 0 ? true:false; + composite_client_ptp_data->composite_event &= proxy_data.asCapable; if (composite_eventSub[0] && (old_composite_event != composite_client_ptp_data->composite_event)) client_ptp_data->composite_event_count.fetch_add(1, std::memory_order_relaxed); - jclCurrentState.as_Capable = client_ptp_data->asCapable > 0 ? true:false; + jclCurrentState.as_Capable = client_ptp_data->asCapable; jclCurrentState.offset_in_range = client_ptp_data->master_offset_within_boundary; - jclCurrentState.servo_locked = client_ptp_data->servo_state >= SERVO_LOCKED ? true:false; + jclCurrentState.servo_locked = client_ptp_data->servo_state; jclCurrentState.composite_event = composite_client_ptp_data->composite_event; memcpy(jclCurrentState.gmIdentity, client_ptp_data->gmIdentity, sizeof(client_ptp_data->gmIdentity)); diff --git a/jclklib/client/subscribe_msg.cpp b/jclklib/client/subscribe_msg.cpp index 2344d18a..40207962 100644 --- a/jclklib/client/subscribe_msg.cpp +++ b/jclklib/client/subscribe_msg.cpp @@ -131,14 +131,14 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) } if (composite_eventSub[0] & 1<composite_event &= data.servo_state >= SERVO_LOCKED ? true:false; + composite_client_data->composite_event &= data.servo_state; if (composite_eventSub[0] & 1<composite_event &= data.asCapable > 0 ? true:false; + composite_client_data->composite_event &= data.asCapable; - jclCurrentState->as_Capable = client_data->asCapable > 0 ? true:false; + jclCurrentState->as_Capable = client_data->asCapable; jclCurrentState->offset_in_range = client_data->master_offset_within_boundary; - jclCurrentState->servo_locked = client_data->servo_state >= SERVO_LOCKED ? true:false; + jclCurrentState->servo_locked = client_data->servo_state; jclCurrentState->composite_event = composite_client_data->composite_event; memcpy(jclCurrentState->gmIdentity, client_data->gmIdentity, sizeof(client_data->gmIdentity)); diff --git a/jclklib/common/jclklib_import.hpp b/jclklib/common/jclklib_import.hpp index 0d0ca391..6d26984a 100644 --- a/jclklib/common/jclklib_import.hpp +++ b/jclklib/common/jclklib_import.hpp @@ -150,8 +150,8 @@ namespace JClkLibCommon struct ptp_event { int64_t master_offset; uint8_t gmIdentity[8]; /* Grandmaster clock ID */ - int32_t asCapable; /* 802@.1AS Capable */ - uint8_t servo_state; + bool asCapable; /* 802@.1AS Capable */ + bool servo_state; uint8_t ptp4l_id; }; @@ -161,8 +161,8 @@ namespace JClkLibCommon int64_t master_offset_high; bool master_offset_within_boundary; uint8_t gmIdentity[8]; /* Grandmaster clock ID */ - int32_t asCapable; /* 802@.1AS Capable */ - uint8_t servo_state; + bool asCapable; /* 802@.1AS Capable */ + bool servo_state; uint8_t ptp4l_id; bool composite_event; std::atomic offset_event_count{}; diff --git a/jclklib/proxy/connect_ptp4l.cpp b/jclklib/proxy/connect_ptp4l.cpp index 35aca555..7a76a7d8 100644 --- a/jclklib/proxy/connect_ptp4l.cpp +++ b/jclklib/proxy/connect_ptp4l.cpp @@ -100,7 +100,7 @@ void event_handle() servo = ((TIME_STATUS_NP_t *)data)->servo_state; gm_uuid = ((TIME_STATUS_NP_t *)data)->gmIdentity; pe.master_offset = offset; - pe.servo_state = servo; + pe.servo_state = servo >= SERVO_LOCKED ? true:false; memcpy(pe.gmIdentity, gm_uuid.v, sizeof(pe.gmIdentity)); /* Uncomment for debug data printing */ @@ -132,7 +132,7 @@ void event_handle() PrintDebug("Ignore unchanged asCapable"); return; } - pe.asCapable = ((CMLDS_INFO_NP_t *)data)->as_capable; + pe.asCapable = ((CMLDS_INFO_NP_t *)data)->as_capable > 0 ? true:false; //printf("asCapable = %d\n\n", pe.asCapable); break; default: From e20ff410aafbab57224300d78ae7365246229215 Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Tue, 4 Jun 2024 10:54:05 +0800 Subject: [PATCH 127/151] jclklib: Refactor message parser Signed-off-by: Lai Peter Jun Ann --- jclklib/client/notification_msg.cpp | 74 +++++++++++++---------------- jclklib/client/notification_msg.hpp | 2 + jclklib/client/subscribe_msg.cpp | 25 +++++----- 3 files changed, 48 insertions(+), 53 deletions(-) diff --git a/jclklib/client/notification_msg.cpp b/jclklib/client/notification_msg.cpp index fbbb24fd..ea960eba 100644 --- a/jclklib/client/notification_msg.cpp +++ b/jclklib/client/notification_msg.cpp @@ -65,6 +65,29 @@ void ClientNotificationMessage::deleteClientState(ClientState *newClientState) ClientStateArray.end(), newClientState), ClientStateArray.end()); } +void ClientNotificationMessage::handleEventUpdate(uint32_t eventSub, uint32_t eventFlag, bool& currentState, const bool& newState, std::atomic& eventCount, bool& compositeEvent) { + if (eventSub & (1 << eventFlag)) { + if (currentState != newState) { + currentState = newState; + eventCount.fetch_add(1, std::memory_order_relaxed); + } + compositeEvent &= newState; + } +} + +void ClientNotificationMessage::handleGmOffsetEvent(uint32_t eventSub, uint32_t eventFlag, int64_t& masterOffset, const uint32_t& newMasterOffset, std::atomic& eventCount, bool& withinBoundary, uint32_t lowerBound, uint32_t upperBound) { + if (eventSub & (1 << eventFlag)) { + if (masterOffset != newMasterOffset) { + masterOffset = newMasterOffset; + bool isWithinBoundary = (masterOffset > lowerBound) && (masterOffset < upperBound); + if (withinBoundary != isWithinBoundary) { + withinBoundary = isWithinBoundary; + eventCount.fetch_add(1, std::memory_order_relaxed); + } + } + } +} + PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) { PrintDebug("[ClientNotificationMessage]::processMessage "); @@ -97,34 +120,16 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) JClkLibCommon::client_ptp_event* composite_client_ptp_data = NULL; composite_client_ptp_data = ClientSubscribeMessage::getClientPtpEventCompositeStruct(currentClientState->get_sessionId()); + int64_t lower_master_offset = currentClientState->get_eventSub().get_value().getLower(gmOffsetValue); + int64_t upper_master_offset = currentClientState->get_eventSub().get_value().getUpper(gmOffsetValue); + if ( client_ptp_data == NULL ) { PrintDebug("ClientNotificationMessage::processMessage ERROR in obtaining client_ptp_data.\n"); return false; } - if ((eventSub[0] & 1<master_offset)) { - client_ptp_data->master_offset = proxy_data.master_offset; - if ((client_ptp_data->master_offset > currentClientState->get_eventSub().get_value().getLower(gmOffsetValue)) && - (client_ptp_data->master_offset < currentClientState->get_eventSub().get_value().getUpper(gmOffsetValue))) { - if (!(client_ptp_data->master_offset_within_boundary)) { - client_ptp_data->master_offset_within_boundary = true; - client_ptp_data->offset_event_count.fetch_add(1, std::memory_order_relaxed); - } - } else { - if ((client_ptp_data->master_offset_within_boundary)) { - client_ptp_data->master_offset_within_boundary = false; - client_ptp_data->offset_event_count.fetch_add(1, std::memory_order_relaxed); - } - } - } - - if ((eventSub[0] & 1<servo_state)) { - client_ptp_data->servo_state = proxy_data.servo_state; - client_ptp_data->servo_state_event_count.fetch_add(1, std::memory_order_relaxed); - } - - if ((eventSub[0] & 1<gmIdentity, proxy_data.gmIdentity, sizeof(proxy_data.gmIdentity)) != 0)) { + if ((eventSub[0] & 1<gmIdentity, proxy_data.gmIdentity, sizeof(proxy_data.gmIdentity)) != 0)) { memcpy(client_ptp_data->gmIdentity, proxy_data.gmIdentity, sizeof(proxy_data.gmIdentity)); client_ptp_data->gmChanged_event_count.fetch_add(1, std::memory_order_relaxed); jclCurrentState.gm_changed = true; @@ -132,31 +137,16 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) jclCurrentState.gm_changed = false; } - if ((eventSub[0] & 1<asCapable)) { - client_ptp_data->asCapable = proxy_data.asCapable; - client_ptp_data->asCapable_event_count.fetch_add(1, std::memory_order_relaxed); - } - if (composite_eventSub[0]) { old_composite_event = composite_client_ptp_data->composite_event; composite_client_ptp_data->composite_event = true; } - if (composite_eventSub[0] & 1<master_offset = proxy_data.master_offset; - if ((composite_client_ptp_data->master_offset > currentClientState->get_eventSub().get_value().getLower(gmOffsetValue)) && - (composite_client_ptp_data->master_offset < currentClientState->get_eventSub().get_value().getUpper(gmOffsetValue))) { - composite_client_ptp_data->composite_event = true; - } else { - composite_client_ptp_data->composite_event = false; - } - } - - if (composite_eventSub[0] & 1<composite_event &= proxy_data.servo_state; + handleEventUpdate(eventSub[0], servoLockedEvent, client_ptp_data->servo_state, proxy_data.servo_state, client_ptp_data->servo_state_event_count, composite_client_ptp_data->composite_event); + handleEventUpdate(eventSub[0], asCapableEvent, client_ptp_data->asCapable, proxy_data.asCapable, client_ptp_data->asCapable_event_count, composite_client_ptp_data->composite_event); - if (composite_eventSub[0] & 1<composite_event &= proxy_data.asCapable; + handleGmOffsetEvent(eventSub[0], gmOffsetEvent, client_ptp_data->master_offset, proxy_data.master_offset, client_ptp_data->offset_event_count, client_ptp_data->master_offset_within_boundary, lower_master_offset, upper_master_offset); + handleGmOffsetEvent(composite_eventSub[0], gmOffsetEvent, composite_client_ptp_data->master_offset, proxy_data.master_offset, composite_client_ptp_data->offset_event_count, composite_client_ptp_data->composite_event, lower_master_offset, upper_master_offset); if (composite_eventSub[0] && (old_composite_event != composite_client_ptp_data->composite_event)) client_ptp_data->composite_event_count.fetch_add(1, std::memory_order_relaxed); diff --git a/jclklib/client/notification_msg.hpp b/jclklib/client/notification_msg.hpp index e6fb53d8..7900075d 100644 --- a/jclklib/client/notification_msg.hpp +++ b/jclklib/client/notification_msg.hpp @@ -48,6 +48,8 @@ namespace JClkLibClient static void addClientState(ClientState *newClientState); static void deleteClientState(ClientState *newClientState); + void handleEventUpdate(uint32_t eventSub, uint32_t eventFlag, bool& currentState, const bool& newState, std::atomic& eventCount, bool& compositeEvent); + void handleGmOffsetEvent(uint32_t eventSub, uint32_t eventFlag, int64_t& masterOffset, const uint32_t& newMasterOffset, std::atomic& eventCount, bool& withinBoundary, uint32_t lowerBound, uint32_t upperBound); protected: ClientNotificationMessage() : MESSAGE_NOTIFY() {} diff --git a/jclklib/client/subscribe_msg.cpp b/jclklib/client/subscribe_msg.cpp index 40207962..d23a482f 100644 --- a/jclklib/client/subscribe_msg.cpp +++ b/jclklib/client/subscribe_msg.cpp @@ -82,6 +82,8 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) JClkLibCommon::sessionId_t currentSessionID = currentClientState->get_sessionId(); std::map >::iterator it ; JClkLibCommon::client_ptp_event* client_data , *composite_client_data; + int64_t lower_master_offset = currentClientState->get_eventSub().get_value().getLower(gmOffsetValue); + int64_t upper_master_offset = currentClientState->get_eventSub().get_value().getUpper(gmOffsetValue); it = client_ptp_event_map.find(currentSessionID); @@ -101,15 +103,16 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) if ((eventSub[0] & 1<master_offset)) { client_data->master_offset = data.master_offset; - if ((client_data->master_offset > currentClientState->get_eventSub().get_value().getLower(gmOffsetValue)) && - (client_data->master_offset < currentClientState->get_eventSub().get_value().getUpper(gmOffsetValue))) + if ((client_data->master_offset > lower_master_offset) && + (client_data->master_offset < upper_master_offset)) client_data->master_offset_within_boundary = true; } if ((eventSub[0] & 1<servo_state)) client_data->servo_state = data.servo_state; - if ((eventSub[0] & 1<gmIdentity, data.gmIdentity, sizeof(data.gmIdentity))) != 0) { + if ((eventSub[0] & 1<gmIdentity, data.gmIdentity, sizeof(data.gmIdentity))) != 0) { memcpy(client_data->gmIdentity, data.gmIdentity, sizeof(data.gmIdentity)); jclCurrentState->gm_changed = true; } @@ -120,14 +123,14 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) if (composite_eventSub[0]) composite_client_data->composite_event = true; - if ((composite_eventSub[0] & 1<master_offset)) { - composite_client_data->master_offset = data.master_offset; - if ((composite_client_data->master_offset > currentClientState->get_eventSub().get_value().getLower(gmOffsetValue)) && - (composite_client_data->master_offset < currentClientState->get_eventSub().get_value().getUpper(gmOffsetValue))) { - composite_client_data->composite_event = true; - } else { - composite_client_data->composite_event = false; - } + if ((composite_eventSub[0] & 1<master_offset)) { + composite_client_data->master_offset = data.master_offset; + if ((composite_client_data->master_offset > lower_master_offset) && + (composite_client_data->master_offset < upper_master_offset)) + composite_client_data->composite_event = true; + else + composite_client_data->composite_event = false; } if (composite_eventSub[0] & 1< Date: Tue, 4 Jun 2024 17:05:31 +0800 Subject: [PATCH 128/151] jclklib: Standarize ptp4l event parameter Signed-off-by: Lai Peter Jun Ann --- jclklib/client/client_state.cpp | 2 +- jclklib/client/jclk_init.cpp | 2 +- jclklib/client/notification_msg.cpp | 38 +++++++++++++++----------- jclklib/client/subscribe_msg.cpp | 42 ++++++++++++++--------------- jclklib/common/jclklib_import.hpp | 28 +++++++++---------- jclklib/proxy/connect_ptp4l.cpp | 32 +++++++++++----------- jclklib/sample/jclk_test.cpp | 26 +++++++++--------- 7 files changed, 89 insertions(+), 81 deletions(-) diff --git a/jclklib/client/client_state.cpp b/jclklib/client/client_state.cpp index 53f2a06a..97915498 100644 --- a/jclklib/client/client_state.cpp +++ b/jclklib/client/client_state.cpp @@ -112,7 +112,7 @@ void ClientState::set_eventState(JClkLibCommon::jcl_state newState) string ClientState::toString() { string name = "[ClientState::eventState]"; - name += " as_Capable = " + to_string(this->get_eventState().as_Capable); + name += " as_capable = " + to_string(this->get_eventState().as_capable); name += " gm_changed = " + to_string(this->get_eventState().gm_changed); name += " offset_in_range = " + to_string(this->get_eventState().offset_in_range); name += " servo_locked = " + to_string(this->get_eventState().servo_locked); diff --git a/jclklib/client/jclk_init.cpp b/jclklib/client/jclk_init.cpp index 8f013794..06f73bce 100644 --- a/jclklib/client/jclk_init.cpp +++ b/jclklib/client/jclk_init.cpp @@ -241,7 +241,7 @@ int JClkLibClientApi::jcl_status_wait(int timeout, /* Check if any member of eventCount is non-zero */ if (eventCount.offset_in_range_event_count || - eventCount.asCapable_event_count || + eventCount.as_capable_event_count || eventCount.servo_locked_event_count || eventCount.composite_event_count || eventCount.gm_changed_event_count) { diff --git a/jclklib/client/notification_msg.cpp b/jclklib/client/notification_msg.cpp index ea960eba..eb56c91d 100644 --- a/jclklib/client/notification_msg.cpp +++ b/jclklib/client/notification_msg.cpp @@ -129,9 +129,9 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) } if ((eventSub[0] & 1<gmIdentity, proxy_data.gmIdentity, sizeof(proxy_data.gmIdentity)) != 0)) { - memcpy(client_ptp_data->gmIdentity, proxy_data.gmIdentity, sizeof(proxy_data.gmIdentity)); - client_ptp_data->gmChanged_event_count.fetch_add(1, std::memory_order_relaxed); + (memcmp(client_ptp_data->gm_identity, proxy_data.gm_identity, sizeof(proxy_data.gm_identity)) != 0)) { + memcpy(client_ptp_data->gm_identity, proxy_data.gm_identity, sizeof(proxy_data.gm_identity)); + client_ptp_data->gm_changed_event_count.fetch_add(1, std::memory_order_relaxed); jclCurrentState.gm_changed = true; } else { jclCurrentState.gm_changed = false; @@ -142,25 +142,33 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) composite_client_ptp_data->composite_event = true; } - handleEventUpdate(eventSub[0], servoLockedEvent, client_ptp_data->servo_state, proxy_data.servo_state, client_ptp_data->servo_state_event_count, composite_client_ptp_data->composite_event); - handleEventUpdate(eventSub[0], asCapableEvent, client_ptp_data->asCapable, proxy_data.asCapable, client_ptp_data->asCapable_event_count, composite_client_ptp_data->composite_event); + handleEventUpdate(eventSub[0], servoLockedEvent, client_ptp_data->servo_locked, + proxy_data.servo_locked, client_ptp_data->servo_locked_event_count, + composite_client_ptp_data->composite_event); + handleEventUpdate(eventSub[0], asCapableEvent, client_ptp_data->as_capable, + proxy_data.as_capable, client_ptp_data->as_capable_event_count, + composite_client_ptp_data->composite_event); - handleGmOffsetEvent(eventSub[0], gmOffsetEvent, client_ptp_data->master_offset, proxy_data.master_offset, client_ptp_data->offset_event_count, client_ptp_data->master_offset_within_boundary, lower_master_offset, upper_master_offset); - handleGmOffsetEvent(composite_eventSub[0], gmOffsetEvent, composite_client_ptp_data->master_offset, proxy_data.master_offset, composite_client_ptp_data->offset_event_count, composite_client_ptp_data->composite_event, lower_master_offset, upper_master_offset); + handleGmOffsetEvent(eventSub[0], gmOffsetEvent, client_ptp_data->master_offset, + proxy_data.master_offset, client_ptp_data->offset_in_range_event_count, + client_ptp_data->master_offset_in_range, lower_master_offset, upper_master_offset); + handleGmOffsetEvent(composite_eventSub[0], gmOffsetEvent, composite_client_ptp_data->master_offset, + proxy_data.master_offset, composite_client_ptp_data->offset_in_range_event_count, + composite_client_ptp_data->composite_event, lower_master_offset, upper_master_offset); if (composite_eventSub[0] && (old_composite_event != composite_client_ptp_data->composite_event)) client_ptp_data->composite_event_count.fetch_add(1, std::memory_order_relaxed); - jclCurrentState.as_Capable = client_ptp_data->asCapable; - jclCurrentState.offset_in_range = client_ptp_data->master_offset_within_boundary; - jclCurrentState.servo_locked = client_ptp_data->servo_state; + jclCurrentState.as_capable = client_ptp_data->as_capable; + jclCurrentState.offset_in_range = client_ptp_data->master_offset_in_range; + jclCurrentState.servo_locked = client_ptp_data->servo_locked; jclCurrentState.composite_event = composite_client_ptp_data->composite_event; - memcpy(jclCurrentState.gmIdentity, client_ptp_data->gmIdentity, sizeof(client_ptp_data->gmIdentity)); + memcpy(jclCurrentState.gm_identity, client_ptp_data->gm_identity, sizeof(client_ptp_data->gm_identity)); - jclCurrentEventCount.offset_in_range_event_count = client_ptp_data->offset_event_count; - jclCurrentEventCount.asCapable_event_count = client_ptp_data->asCapable_event_count; - jclCurrentEventCount.servo_locked_event_count = client_ptp_data->servo_state_event_count; - jclCurrentEventCount.gm_changed_event_count = client_ptp_data->gmChanged_event_count; + jclCurrentEventCount.offset_in_range_event_count = client_ptp_data->offset_in_range_event_count; + jclCurrentEventCount.as_capable_event_count = client_ptp_data->as_capable_event_count; + jclCurrentEventCount.servo_locked_event_count = client_ptp_data->servo_locked_event_count; + jclCurrentEventCount.gm_changed_event_count = client_ptp_data->gm_changed_event_count; jclCurrentEventCount.composite_event_count = client_ptp_data->composite_event_count; } diff --git a/jclklib/client/subscribe_msg.cpp b/jclklib/client/subscribe_msg.cpp index d23a482f..5a2d856b 100644 --- a/jclklib/client/subscribe_msg.cpp +++ b/jclklib/client/subscribe_msg.cpp @@ -105,20 +105,20 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) client_data->master_offset = data.master_offset; if ((client_data->master_offset > lower_master_offset) && (client_data->master_offset < upper_master_offset)) - client_data->master_offset_within_boundary = true; + client_data->master_offset_in_range = true; } - if ((eventSub[0] & 1<servo_state)) - client_data->servo_state = data.servo_state; + if ((eventSub[0] & 1<servo_locked)) + client_data->servo_locked = data.servo_locked; if ((eventSub[0] & 1<gmIdentity, data.gmIdentity, sizeof(data.gmIdentity))) != 0) { - memcpy(client_data->gmIdentity, data.gmIdentity, sizeof(data.gmIdentity)); + (memcmp(client_data->gm_identity, data.gm_identity, sizeof(data.gm_identity))) != 0) { + memcpy(client_data->gm_identity, data.gm_identity, sizeof(data.gm_identity)); jclCurrentState->gm_changed = true; } - if ((eventSub[0] & 1<asCapable)) - client_data->asCapable = data.asCapable; + if ((eventSub[0] & 1<as_capable)) + client_data->as_capable = data.as_capable; if (composite_eventSub[0]) composite_client_data->composite_event = true; @@ -134,16 +134,16 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) } if (composite_eventSub[0] & 1<composite_event &= data.servo_state; + composite_client_data->composite_event &= data.servo_locked; if (composite_eventSub[0] & 1<composite_event &= data.asCapable; + composite_client_data->composite_event &= data.as_capable; - jclCurrentState->as_Capable = client_data->asCapable; - jclCurrentState->offset_in_range = client_data->master_offset_within_boundary; - jclCurrentState->servo_locked = client_data->servo_state; + jclCurrentState->as_capable = client_data->as_capable; + jclCurrentState->offset_in_range = client_data->master_offset_in_range; + jclCurrentState->servo_locked = client_data->servo_locked; jclCurrentState->composite_event = composite_client_data->composite_event; - memcpy(jclCurrentState->gmIdentity, client_data->gmIdentity, sizeof(client_data->gmIdentity)); + memcpy(jclCurrentState->gm_identity, client_data->gm_identity, sizeof(client_data->gm_identity)); return true; } @@ -241,20 +241,20 @@ void ClientSubscribeMessage::resetClientPtpEventStruct(JClkLibCommon::sessionId_ if (it != client_ptp_event_map.end()) client_ptp_data = it->second[0]; - client_ptp_data->offset_event_count.fetch_sub(eventCount.offset_in_range_event_count, + client_ptp_data->offset_in_range_event_count.fetch_sub(eventCount.offset_in_range_event_count, std::memory_order_relaxed); - client_ptp_data->asCapable_event_count.fetch_sub(eventCount.asCapable_event_count, + client_ptp_data->as_capable_event_count.fetch_sub(eventCount.as_capable_event_count, std::memory_order_relaxed); - client_ptp_data->servo_state_event_count.fetch_sub(eventCount.servo_locked_event_count, + client_ptp_data->servo_locked_event_count.fetch_sub(eventCount.servo_locked_event_count, std::memory_order_relaxed); - client_ptp_data->gmChanged_event_count.fetch_sub(eventCount.gm_changed_event_count, + client_ptp_data->gm_changed_event_count.fetch_sub(eventCount.gm_changed_event_count, std::memory_order_relaxed); client_ptp_data->composite_event_count.fetch_sub(eventCount.composite_event_count, std::memory_order_relaxed); - eventCount.offset_in_range_event_count = client_ptp_data->offset_event_count; - eventCount.asCapable_event_count = client_ptp_data->asCapable_event_count; - eventCount.servo_locked_event_count = client_ptp_data->servo_state_event_count; - eventCount.gm_changed_event_count = client_ptp_data->gmChanged_event_count; + eventCount.offset_in_range_event_count = client_ptp_data->offset_in_range_event_count; + eventCount.as_capable_event_count = client_ptp_data->as_capable_event_count; + eventCount.servo_locked_event_count = client_ptp_data->servo_locked_event_count; + eventCount.gm_changed_event_count = client_ptp_data->gm_changed_event_count; eventCount.composite_event_count = client_ptp_data->composite_event_count; } diff --git a/jclklib/common/jclklib_import.hpp b/jclklib/common/jclklib_import.hpp index 6d26984a..58e48c65 100644 --- a/jclklib/common/jclklib_import.hpp +++ b/jclklib/common/jclklib_import.hpp @@ -149,9 +149,9 @@ namespace JClkLibCommon struct ptp_event { int64_t master_offset; - uint8_t gmIdentity[8]; /* Grandmaster clock ID */ - bool asCapable; /* 802@.1AS Capable */ - bool servo_state; + uint8_t gm_identity[8]; /* Grandmaster clock ID */ + bool as_capable; /* 802@.1AS Capable */ + bool servo_locked; uint8_t ptp4l_id; }; @@ -159,34 +159,34 @@ namespace JClkLibCommon int64_t master_offset; int64_t master_offset_low; int64_t master_offset_high; - bool master_offset_within_boundary; - uint8_t gmIdentity[8]; /* Grandmaster clock ID */ - bool asCapable; /* 802@.1AS Capable */ - bool servo_state; + uint8_t gm_identity[8]; /* Grandmaster clock ID */ uint8_t ptp4l_id; + bool as_capable; /* 802@.1AS Capable */ + bool servo_locked; + bool master_offset_in_range; bool composite_event; - std::atomic offset_event_count{}; - std::atomic asCapable_event_count{}; - std::atomic servo_state_event_count{}; - std::atomic gmChanged_event_count{}; + std::atomic offset_in_range_event_count{}; + std::atomic as_capable_event_count{}; + std::atomic servo_locked_event_count{}; + std::atomic gm_changed_event_count{}; std::atomic composite_event_count{}; }; struct jcl_state { - bool as_Capable; + uint8_t gm_identity[8]; + bool as_capable; bool offset_in_range; bool servo_locked; bool gm_changed; bool composite_event; - uint8_t gmIdentity[8]; }; struct jcl_state_event_count { uint64_t offset_in_range_event_count; uint64_t gm_changed_event_count; - uint64_t asCapable_event_count; + uint64_t as_capable_event_count; uint64_t servo_locked_event_count; uint64_t composite_event_count; }; diff --git a/jclklib/proxy/connect_ptp4l.cpp b/jclklib/proxy/connect_ptp4l.cpp index 7a76a7d8..0f61f769 100644 --- a/jclklib/proxy/connect_ptp4l.cpp +++ b/jclklib/proxy/connect_ptp4l.cpp @@ -100,15 +100,15 @@ void event_handle() servo = ((TIME_STATUS_NP_t *)data)->servo_state; gm_uuid = ((TIME_STATUS_NP_t *)data)->gmIdentity; pe.master_offset = offset; - pe.servo_state = servo >= SERVO_LOCKED ? true:false; - memcpy(pe.gmIdentity, gm_uuid.v, sizeof(pe.gmIdentity)); + pe.servo_locked = servo >= SERVO_LOCKED ? true:false; + memcpy(pe.gm_identity, gm_uuid.v, sizeof(pe.gm_identity)); /* Uncomment for debug data printing */ - //printf("master_offset = %ld, servo_state = %d\n", pe.master_offset, pe.servo_state); - //printf("gmIdentity = %02x%02x%02x.%02x%02x.%02x%02x%02x\n\n", - // pe.gmIdentity[0], pe.gmIdentity[1],pe.gmIdentity[2], - // pe.gmIdentity[3], pe.gmIdentity[4], - // pe.gmIdentity[5], pe.gmIdentity[6],pe.gmIdentity[7]); + //printf("master_offset = %ld, servo_locked = %d\n", pe.master_offset, pe.servo_locked); + //printf("gm_identity = %02x%02x%02x.%02x%02x.%02x%02x%02x\n\n", + // pe.gm_identity[0], pe.gm_identity[1],pe.gm_identity[2], + // pe.gm_identity[3], pe.gm_identity[4], + // pe.gm_identity[5], pe.gm_identity[6],pe.gm_identity[7]); break; case PORT_DATA_SET: pd = (PORT_DATA_SET_t *)data; @@ -117,8 +117,8 @@ void event_handle() /* Reset TIME_STATUS_NP data if port_state <= PASSIVE */ if (portState <= PASSIVE) { pe.master_offset = 0; - memset(pe.gmIdentity, 0, sizeof(pe.gmIdentity)); - pe.servo_state = 0; + memset(pe.gm_identity, 0, sizeof(pe.gm_identity)); + pe.servo_locked = 0; } break; @@ -128,12 +128,12 @@ void event_handle() portState = pd->portState; break; case CMLDS_INFO_NP: - if (pe.asCapable == ((CMLDS_INFO_NP_t *)data)->as_capable) { - PrintDebug("Ignore unchanged asCapable"); + if (pe.as_capable == ((CMLDS_INFO_NP_t *)data)->as_capable) { + PrintDebug("Ignore unchanged as_capable"); return; } - pe.asCapable = ((CMLDS_INFO_NP_t *)data)->as_capable > 0 ? true:false; - //printf("asCapable = %d\n\n", pe.asCapable); + pe.as_capable = ((CMLDS_INFO_NP_t *)data)->as_capable > 0 ? true:false; + //printf("as_capable = %d\n\n", pe.as_capable); break; default: return; @@ -282,9 +282,9 @@ void *ptp4l_event_loop( void *arg) /* Reset TIME_STATUS_NP data when ptp4l is disconnected */ pe.master_offset = 0; - memset(pe.gmIdentity, 0, sizeof(pe.gmIdentity)); - pe.servo_state = 0; - pe.asCapable = 0; + memset(pe.gm_identity, 0, sizeof(pe.gm_identity)); + pe.servo_locked = 0; + pe.as_capable = 0; notify_client(); while (1) { diff --git a/jclklib/sample/jclk_test.cpp b/jclklib/sample/jclk_test.cpp index 8dcd752c..bb996432 100644 --- a/jclklib/sample/jclk_test.cpp +++ b/jclklib/sample/jclk_test.cpp @@ -193,16 +193,16 @@ int main(int argc, char *argv[]) printf("| %-17s | %-18d |\n", "servo_locked", jcl_state.servo_locked); } if (event2Sub1[0] & (1< Date: Thu, 6 Jun 2024 22:19:50 +0800 Subject: [PATCH 129/151] jclklib: remove unused servoState_e enum Remove the definition of servoState_e enum because proxy side will directly tell client whether the servo is locked or not. Signed-off-by: Song Yoong Siang --- jclklib/common/jclklib_import.hpp | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/jclklib/common/jclklib_import.hpp b/jclklib/common/jclklib_import.hpp index 58e48c65..6811010e 100644 --- a/jclklib/common/jclklib_import.hpp +++ b/jclklib/common/jclklib_import.hpp @@ -26,28 +26,6 @@ namespace JClkLibCommon valueLast } valueType; #define MAX_VALUE_COUNT 12 - /** Servo State */ - enum servoState_e { - /** - * The servo is not yet ready to track the master clock. - */ - SERVO_UNLOCKED = 0, - /** - * The servo is ready to track and requests a clock jump to - * immediately correct the estimated offset. - */ - SERVO_JUMP = 1, - /** - * The servo is tracking the master clock. - */ - SERVO_LOCKED = 2, - /** - * The Servo has stabilized. The last 'servo_num_offset_values' values - * of the estimated threshold are less than servo_offset_threshold. - */ - SERVO_LOCKED_STABLE = 3, - }; - class jcl_value { private: From eb8c08e66256e1f2d39af7df55d6d76029eee845 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 6 Jun 2024 23:12:12 +0800 Subject: [PATCH 130/151] jclklib: remove unused variable Clean up variables which are not being used anywhere. Signed-off-by: Song Yoong Siang --- jclklib/common/jclklib_import.cpp | 19 ------------------- jclklib/common/jclklib_import.hpp | 3 --- jclklib/proxy/thread.hpp | 1 - 3 files changed, 23 deletions(-) diff --git a/jclklib/common/jclklib_import.cpp b/jclklib/common/jclklib_import.cpp index 532dea27..af1257e0 100644 --- a/jclklib/common/jclklib_import.cpp +++ b/jclklib/common/jclklib_import.cpp @@ -62,25 +62,6 @@ bool jcl_value::equal( const jcl_value &c) return false; } - -uint8_t *jcl_subscription::parse(uint8_t *buf, std::size_t &length) -{ - buf = event.parse(buf, length); - if (buf != NULL) - buf = value.parse(buf, length); - - return buf; -} - -uint8_t *jcl_subscription::write(uint8_t *buf, std::size_t &length) -{ - buf = event.write(buf, length); - if (buf != NULL) - buf = value.write(buf, length); - - return buf; -} - int8_t jcl_event::writeEvent(uint32_t *newEvent, std::size_t newEventlength) { if (newEvent == NULL || sizeof(event_mask) < newEventlength) { diff --git a/jclklib/common/jclklib_import.hpp b/jclklib/common/jclklib_import.hpp index 6811010e..62123f2b 100644 --- a/jclklib/common/jclklib_import.hpp +++ b/jclklib/common/jclklib_import.hpp @@ -117,9 +117,6 @@ namespace JClkLibCommon jcl_value value; jcl_event composite_event; public: - std::uint8_t *parse(std::uint8_t *buf, std::size_t &length); - std::uint8_t *write(std::uint8_t *buf, std::size_t &length); - DECLARE_ACCESSOR(event); DECLARE_ACCESSOR(value); DECLARE_ACCESSOR(composite_event); diff --git a/jclklib/proxy/thread.hpp b/jclklib/proxy/thread.hpp index 6592313e..d001bcd1 100644 --- a/jclklib/proxy/thread.hpp +++ b/jclklib/proxy/thread.hpp @@ -45,7 +45,6 @@ struct jcl_handle ptp4l_handle_t ptp4l_handle; thread_signal_t status_signal; pthread_mutex_t state_lock; - struct JClkLibCommon::jcl_state state; }; struct ptp4l_handle { From bebd63205fbf7f32aeafd04a2ddf2f677f69ff0e Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Thu, 6 Jun 2024 23:19:34 +0800 Subject: [PATCH 131/151] jclklib: rename client_state.cpp to jclk_client_state.cpp Add initial jclk to the file that contain struct which user need to use. Signed-off-by: Song Yoong Siang --- jclklib/client/Makefile | 2 +- jclklib/client/{client_state.cpp => jclk_client_state.cpp} | 4 ++-- jclklib/client/{client_state.hpp => jclk_client_state.hpp} | 2 +- jclklib/client/jclk_init.hpp | 2 +- jclklib/client/message.hpp | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) rename jclklib/client/{client_state.cpp => jclk_client_state.cpp} (97%) rename jclklib/client/{client_state.hpp => jclk_client_state.hpp} (98%) diff --git a/jclklib/client/Makefile b/jclklib/client/Makefile index 88569ca5..ead86a38 100644 --- a/jclklib/client/Makefile +++ b/jclklib/client/Makefile @@ -15,7 +15,7 @@ JCLKLIB_TOPLEVEL_DIR = $(JCLKLIB_CLIENT_DIR)/.. JCLKLIB_COMMON_DIR = $(JCLKLIB_TOPLEVEL_DIR)/common LIBS = pthread rt LIBS_FLAGS = $(foreach lib,$(LIBS),-l$(lib)) -OBJ = jclk_init msgq_tport message null_tport transport msgq_tport notification_msg connect_msg client_state subscribe_msg +OBJ = jclk_init msgq_tport message null_tport transport msgq_tport notification_msg connect_msg jclk_client_state subscribe_msg COMMON_OBJ = print sighandler transport msgq_tport message connect_msg subscribe_msg notification_msg jclklib_import OBJ_FILES = $(foreach f,$(OBJ),$(f).o) DEPENDS = $(foreach f,$(OBJ),$(f).d) diff --git a/jclklib/client/client_state.cpp b/jclklib/client/jclk_client_state.cpp similarity index 97% rename from jclklib/client/client_state.cpp rename to jclklib/client/jclk_client_state.cpp index 97915498..3388b634 100644 --- a/jclklib/client/client_state.cpp +++ b/jclklib/client/jclk_client_state.cpp @@ -3,7 +3,7 @@ * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. */ -/** @file client_state.cpp +/** @file jclk_client_state.cpp * @brief Set and get the client subscribe event state * * @author Noor Azura Ahmad Tarmizi @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include #include diff --git a/jclklib/client/client_state.hpp b/jclklib/client/jclk_client_state.hpp similarity index 98% rename from jclklib/client/client_state.hpp rename to jclklib/client/jclk_client_state.hpp index 3870f051..37d7d8f0 100644 --- a/jclklib/client/client_state.hpp +++ b/jclklib/client/jclk_client_state.hpp @@ -3,7 +3,7 @@ * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. */ -/** @file client_state.hpp +/** @file jclk_client_state.hpp * @brief Set and get the client subscribe event state * * @author Noor Azura Ahmad Tarmizi diff --git a/jclklib/client/jclk_init.hpp b/jclklib/client/jclk_init.hpp index 9800c782..a75e78d0 100644 --- a/jclklib/client/jclk_init.hpp +++ b/jclklib/client/jclk_init.hpp @@ -15,7 +15,7 @@ #ifndef JCLK_INIT_HPP #define JCLK_INIT_HPP -#include +#include #include #include diff --git a/jclklib/client/message.hpp b/jclklib/client/message.hpp index 30ab04c0..be3cfa53 100644 --- a/jclklib/client/message.hpp +++ b/jclklib/client/message.hpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include namespace JClkLibClient From 71256626b11b68a85a59b0561d40445e39ddef49 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Fri, 7 Jun 2024 08:29:03 +0800 Subject: [PATCH 132/151] jclklib: avoid calling client header file from proxy Proxy and Client should be separated and all shared structure need to be inside common file. Signed-off-by: Song Yoong Siang --- jclklib/proxy/client.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jclklib/proxy/client.hpp b/jclklib/proxy/client.hpp index d09ac64f..bcbc157c 100644 --- a/jclklib/proxy/client.hpp +++ b/jclklib/proxy/client.hpp @@ -17,7 +17,7 @@ #include -#include +#include namespace JClkLibProxy { class Client; From b49d5e53570e395ca859a1a1cdc61b4c7d45db29 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Fri, 7 Jun 2024 08:39:12 +0800 Subject: [PATCH 133/151] jclklib: move jcl_state and jcl_state_event_count from common to client since proxy is not using jcl_state and jcl_state_event_count, move them out from common, so that we keep the structure that needed by user application in one place. Signed-off-by: Song Yoong Siang --- jclklib/client/jclk_client_state.cpp | 8 ++--- jclklib/client/jclk_client_state.hpp | 29 ++++++++++++++---- jclklib/client/jclk_init.cpp | 13 ++++---- jclklib/client/jclk_init.hpp | 6 ++-- jclklib/client/notification_msg.cpp | 5 ++-- jclklib/client/subscribe_msg.cpp | 4 +-- jclklib/client/subscribe_msg.hpp | 5 ++-- jclklib/common/jclklib_import.hpp | 19 ------------ jclklib/sample/jclk_test.cpp | 44 ++++++++++++++-------------- 9 files changed, 66 insertions(+), 67 deletions(-) diff --git a/jclklib/client/jclk_client_state.cpp b/jclklib/client/jclk_client_state.cpp index 3388b634..8fe4f5cb 100644 --- a/jclklib/client/jclk_client_state.cpp +++ b/jclklib/client/jclk_client_state.cpp @@ -89,22 +89,22 @@ void ClientState::set_clientID(TransportClientId &new_cID) strcpy((char *)clientID.data(), (char *)new_cID.data()); } -JClkLibCommon::jcl_state_event_count &ClientState::get_eventStateCount() +jcl_state_event_count &ClientState::get_eventStateCount() { return eventStateCount; } -JClkLibCommon::jcl_state &ClientState::get_eventState() +jcl_state &ClientState::get_eventState() { return eventState; } -void ClientState::set_eventStateCount(JClkLibCommon::jcl_state_event_count newCount) +void ClientState::set_eventStateCount(jcl_state_event_count newCount) { eventStateCount = newCount; } -void ClientState::set_eventState(JClkLibCommon::jcl_state newState) +void ClientState::set_eventState(jcl_state newState) { eventState = newState; } diff --git a/jclklib/client/jclk_client_state.hpp b/jclklib/client/jclk_client_state.hpp index 37d7d8f0..4d1c92fe 100644 --- a/jclklib/client/jclk_client_state.hpp +++ b/jclklib/client/jclk_client_state.hpp @@ -24,6 +24,23 @@ #include namespace JClkLibClient { + struct jcl_state { + uint8_t gm_identity[8]; + bool as_capable; + bool offset_in_range; + bool servo_locked; + bool gm_changed; + bool composite_event; + }; + + struct jcl_state_event_count { + uint64_t offset_in_range_event_count; + uint64_t gm_changed_event_count; + uint64_t as_capable_event_count; + uint64_t servo_locked_event_count; + uint64_t composite_event_count; + }; + class ClientState { private: std::atomic_bool connected = false; @@ -31,8 +48,8 @@ namespace JClkLibClient { JClkLibCommon::sessionId_t sessionId = JClkLibCommon::InvalidSessionId; JClkLibCommon::TransportClientId clientID = {}; uint8_t ptp4l_id = 0; - JClkLibCommon::jcl_state eventState = {}; - JClkLibCommon::jcl_state_event_count eventStateCount ={}; + jcl_state eventState = {}; + jcl_state_event_count eventStateCount ={}; JClkLibCommon::jcl_subscription eventSub ={}; public: @@ -45,10 +62,10 @@ namespace JClkLibClient { void set_subscribed(bool subscriptionState); JClkLibCommon::TransportClientId get_clientID(); void set_clientID(JClkLibCommon::TransportClientId &cID); - JClkLibCommon::jcl_state_event_count &get_eventStateCount(); - JClkLibCommon::jcl_state &get_eventState(); - void set_eventStateCount(JClkLibCommon::jcl_state_event_count eCount); - void set_eventState(JClkLibCommon::jcl_state eState); + jcl_state_event_count &get_eventStateCount(); + jcl_state &get_eventState(); + void set_eventStateCount(jcl_state_event_count eCount); + void set_eventState(jcl_state eState); std::string toString(); JClkLibCommon::jcl_subscription &get_eventSub(); DECLARE_ACCESSOR(sessionId); diff --git a/jclklib/client/jclk_init.cpp b/jclklib/client/jclk_init.cpp index 06f73bce..1983b8ee 100644 --- a/jclklib/client/jclk_init.cpp +++ b/jclklib/client/jclk_init.cpp @@ -88,7 +88,7 @@ bool JClkLibClientApi::jcl_connect() bool JClkLibClientApi::jcl_subscribe(JClkLibCommon::jcl_subscription &newSub, - JClkLibCommon::jcl_state ¤tState) + jcl_state ¤tState) { unsigned int timeout_sec = (unsigned int) DEFAULT_SUBSCRIBE_TIME_OUT; @@ -135,7 +135,7 @@ bool JClkLibClientApi::jcl_subscribe(JClkLibCommon::jcl_subscription &newSub, } } - JClkLibCommon::jcl_state jclCurrentState = appClientState.get_eventState(); + jcl_state jclCurrentState = appClientState.get_eventState(); currentState = jclCurrentState; @@ -218,9 +218,8 @@ bool check_proxy_liveness(ClientState &appClientState) * @return Returns true if there is event changes within the timeout period, * and false otherwise. */ -int JClkLibClientApi::jcl_status_wait(int timeout, - JClkLibCommon::jcl_state &jcl_state_ref, - JClkLibCommon::jcl_state_event_count &eventCountRef) +int JClkLibClientApi::jcl_status_wait(int timeout, jcl_state &jcl_state_ref, + jcl_state_event_count &eventCountRef) { auto start = std::chrono::high_resolution_clock::now(); auto end = (timeout == -1) ? @@ -232,8 +231,8 @@ int JClkLibClientApi::jcl_status_wait(int timeout, if (!check_proxy_liveness(appClientState)) return -1; - JClkLibCommon::jcl_state_event_count eventCount; - JClkLibCommon::jcl_state jcl_state; + jcl_state_event_count eventCount; + jcl_state jcl_state; do { /* Get the event state and event count from the API */ eventCount = appClientState.get_eventStateCount(); diff --git a/jclklib/client/jclk_init.hpp b/jclklib/client/jclk_init.hpp index a75e78d0..8722f762 100644 --- a/jclklib/client/jclk_init.hpp +++ b/jclklib/client/jclk_init.hpp @@ -32,9 +32,9 @@ namespace JClkLibClient { bool jcl_connect(); bool jcl_disconnect(); bool jcl_subscribe(JClkLibCommon::jcl_subscription &newSub, - JClkLibCommon::jcl_state ¤tState); - int jcl_status_wait(int timeout, JClkLibCommon::jcl_state &jcl_state, - JClkLibCommon::jcl_state_event_count &eventCount); + jcl_state ¤tState); + int jcl_status_wait(int timeout, jcl_state &jcl_state, + jcl_state_event_count &eventCount); }; } #endif /* JCLK_INIT_HPP */ diff --git a/jclklib/client/notification_msg.cpp b/jclklib/client/notification_msg.cpp index eb56c91d..930e9ab1 100644 --- a/jclklib/client/notification_msg.cpp +++ b/jclklib/client/notification_msg.cpp @@ -12,6 +12,7 @@ * */ +#include #include #include #include @@ -103,9 +104,9 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) ClientState *currentClientState = *it; - JClkLibCommon::jcl_state &jclCurrentState = + jcl_state &jclCurrentState = currentClientState->get_eventState(); - JClkLibCommon::jcl_state_event_count &jclCurrentEventCount = + jcl_state_event_count &jclCurrentEventCount = currentClientState->get_eventStateCount(); currentClientState->get_eventSub().get_event().readEvent(eventSub, diff --git a/jclklib/client/subscribe_msg.cpp b/jclklib/client/subscribe_msg.cpp index 5a2d856b..e6402df3 100644 --- a/jclklib/client/subscribe_msg.cpp +++ b/jclklib/client/subscribe_msg.cpp @@ -171,7 +171,7 @@ PROCESS_MESSAGE_TYPE(ClientSubscribeMessage::processMessage) ClientNotificationMessage::addClientState(currentClientState); this->set_msgAck(ACK_NONE); - JClkLibCommon::jcl_state jclCurrentState = currentClientState->get_eventState(); + jcl_state jclCurrentState = currentClientState->get_eventState(); cv.notify_one(); return true; @@ -230,7 +230,7 @@ JClkLibCommon::client_ptp_event* ClientSubscribeMessage::getClientPtpEventCompos /* reduce the corresponding eventCount */ void ClientSubscribeMessage::resetClientPtpEventStruct(JClkLibCommon::sessionId_t sID, - JClkLibCommon::jcl_state_event_count &eventCount) + jcl_state_event_count &eventCount) { std::map >::iterator it ; diff --git a/jclklib/client/subscribe_msg.hpp b/jclklib/client/subscribe_msg.hpp index 47b85659..02eae415 100644 --- a/jclklib/client/subscribe_msg.hpp +++ b/jclklib/client/subscribe_msg.hpp @@ -15,6 +15,7 @@ #ifndef CLIENT_SUBSCRIBE_MSG_HPP #define CLIENT_SUBSCRIBE_MSG_HPP +#include #include #include @@ -24,7 +25,7 @@ namespace JClkLibClient virtual public ClientMessage { private: - inline static JClkLibCommon::jcl_state *jclCurrentState; + inline static jcl_state *jclCurrentState; inline static ClientState *currentClientState; inline static std::map > client_ptp_event_map; @@ -69,7 +70,7 @@ namespace JClkLibClient static JClkLibCommon::client_ptp_event* getClientPtpEventCompositeStruct(JClkLibCommon::sessionId_t sID); /* Reduce the corresponding eventCount */ - static void resetClientPtpEventStruct(JClkLibCommon::sessionId_t sID, JClkLibCommon::jcl_state_event_count &eventCount); + static void resetClientPtpEventStruct(JClkLibCommon::sessionId_t sID, jcl_state_event_count &eventCount); }; } diff --git a/jclklib/common/jclklib_import.hpp b/jclklib/common/jclklib_import.hpp index 62123f2b..9d83127e 100644 --- a/jclklib/common/jclklib_import.hpp +++ b/jclklib/common/jclklib_import.hpp @@ -146,25 +146,6 @@ namespace JClkLibCommon std::atomic gm_changed_event_count{}; std::atomic composite_event_count{}; }; - - struct jcl_state - { - uint8_t gm_identity[8]; - bool as_capable; - bool offset_in_range; - bool servo_locked; - bool gm_changed; - bool composite_event; - }; - - struct jcl_state_event_count - { - uint64_t offset_in_range_event_count; - uint64_t gm_changed_event_count; - uint64_t as_capable_event_count; - uint64_t servo_locked_event_count; - uint64_t composite_event_count; - }; } #endif /* JCLKLIB_IMPORT_HPP */ diff --git a/jclklib/sample/jclk_test.cpp b/jclklib/sample/jclk_test.cpp index bb996432..eb663e3c 100644 --- a/jclklib/sample/jclk_test.cpp +++ b/jclklib/sample/jclk_test.cpp @@ -50,9 +50,9 @@ double getMonotonicTime() { int main(int argc, char *argv[]) { - JClkLibCommon::jcl_state_event_count eventCount = {}; + jcl_state_event_count eventCount = {}; JClkLibCommon::jcl_subscription sub = {}; - JClkLibCommon::jcl_state jcl_state = {}; + jcl_state state = {}; int lower_master_offset = -100000; int upper_master_offset = 100000; int ret = EXIT_SUCCESS; @@ -172,7 +172,7 @@ int main(int argc, char *argv[]) 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) { + if (cmAPI->jcl_subscribe(sub, state) == false) { std::cerr << "[jclklib] Failure in subscribing to jclklib Proxy !!!\n"; cmAPI->jcl_disconnect(); return EXIT_FAILURE; @@ -187,27 +187,27 @@ int main(int argc, char *argv[]) } if (event2Sub1[0] & (1<jcl_status_wait(timeout, jcl_state , eventCount); + retval = cmAPI->jcl_status_wait(timeout, state , eventCount); if (!retval) { printf("[jclklib][%.3f] No event status changes identified in %d seconds.\n\n", getMonotonicTime(), timeout); @@ -253,31 +253,31 @@ int main(int argc, char *argv[]) } if (event2Sub1[0] & (1< Date: Fri, 7 Jun 2024 10:45:26 +0800 Subject: [PATCH 134/151] jclklib: Replace with librtpi wrapper Signed-off-by: Lai Peter Jun Ann --- jclklib/client/Makefile | 2 +- jclklib/client/connect_msg.cpp | 4 ++-- jclklib/client/connect_msg.hpp | 9 ++++---- jclklib/client/jclk_init.cpp | 18 +++++++-------- jclklib/client/subscribe_msg.cpp | 4 ++-- jclklib/client/subscribe_msg.hpp | 5 +++-- jclklib/common/Makefile | 2 +- jclklib/proxy/Makefile | 2 +- jclklib/proxy/clock_config.hpp | 4 ++-- jclklib/proxy/clock_status.hpp | 5 ++--- jclklib/proxy/thread.cpp | 38 ++------------------------------ jclklib/proxy/thread.hpp | 10 --------- 12 files changed, 29 insertions(+), 74 deletions(-) diff --git a/jclklib/client/Makefile b/jclklib/client/Makefile index ead86a38..83a2626b 100644 --- a/jclklib/client/Makefile +++ b/jclklib/client/Makefile @@ -13,7 +13,7 @@ JCLKLIB_CLIENT_DIR := $(shell pwd) JCLKLIB_TOPLEVEL_DIR = $(JCLKLIB_CLIENT_DIR)/.. JCLKLIB_COMMON_DIR = $(JCLKLIB_TOPLEVEL_DIR)/common -LIBS = pthread rt +LIBS = pthread rt rtpi LIBS_FLAGS = $(foreach lib,$(LIBS),-l$(lib)) OBJ = jclk_init msgq_tport message null_tport transport msgq_tport notification_msg connect_msg jclk_client_state subscribe_msg COMMON_OBJ = print sighandler transport msgq_tport message connect_msg subscribe_msg notification_msg jclklib_import diff --git a/jclklib/client/connect_msg.cpp b/jclklib/client/connect_msg.cpp index f35fd47f..d3451993 100644 --- a/jclklib/client/connect_msg.cpp +++ b/jclklib/client/connect_msg.cpp @@ -88,7 +88,7 @@ void ClientConnectMessage::setClientState(ClientState *newClientState) PROCESS_MESSAGE_TYPE(ClientConnectMessage::processMessage) { sessionId_t newSessionId; - + std::unique_lock lock(cv_mtx); PrintDebug("Processing client connect message (reply)"); currentClientState->set_connected(true); @@ -101,7 +101,7 @@ PROCESS_MESSAGE_TYPE(ClientConnectMessage::processMessage) this->set_msgAck(ACK_NONE); - cv.notify_one(); + cv.notify_one(lock); return true; } diff --git a/jclklib/client/connect_msg.hpp b/jclklib/client/connect_msg.hpp index 2ba05f5a..747d0e96 100644 --- a/jclklib/client/connect_msg.hpp +++ b/jclklib/client/connect_msg.hpp @@ -15,11 +15,10 @@ #ifndef CLIENT_CONNECT_MSG_HPP #define CLIENT_CONNECT_MSG_HPP -#include -#include - #include #include +#include +#include namespace JClkLibClient { @@ -30,8 +29,8 @@ namespace JClkLibClient inline static ClientState *currentClientState; public: ClientConnectMessage() : MESSAGE_CONNECT() {}; - static std::mutex cv_mtx; - static std::condition_variable cv; + static rtpi::mutex cv_mtx; + static rtpi::condition_variable cv; /** * @brief process the reply for connect msg from proxy. diff --git a/jclklib/client/jclk_init.cpp b/jclklib/client/jclk_init.cpp index 1983b8ee..bf3c8037 100644 --- a/jclklib/client/jclk_init.cpp +++ b/jclklib/client/jclk_init.cpp @@ -13,10 +13,8 @@ */ #include -#include #include #include -#include #include #include @@ -25,6 +23,8 @@ #include #include #include +#include +#include #define DEFAULT_LIVENESS_TIME_OUT 1 //1 sec #define DEFAULT_CONNECT_TIME_OUT 5 //5 sec @@ -34,10 +34,10 @@ using namespace JClkLibClient; using namespace JClkLibCommon; using namespace std; -std::mutex ClientConnectMessage::cv_mtx; -std::condition_variable ClientConnectMessage::cv; -std::mutex ClientSubscribeMessage::cv_mtx; -std::condition_variable ClientSubscribeMessage::cv; +rtpi::mutex ClientConnectMessage::cv_mtx; +rtpi::condition_variable ClientConnectMessage::cv; +rtpi::mutex ClientSubscribeMessage::cv_mtx; +rtpi::condition_variable ClientSubscribeMessage::cv; bool JClkLibClientApi::jcl_connect() { @@ -64,7 +64,7 @@ bool JClkLibClientApi::jcl_connect() /* Wait for connection result */ auto endTime = std::chrono::system_clock::now() + std::chrono::seconds(timeout_sec); - std::unique_lock lck(ClientConnectMessage::cv_mtx); + std::unique_lock lck(ClientConnectMessage::cv_mtx); while (appClientState.get_connected() == false ) { auto res = ClientConnectMessage::cv.wait_until(lck, endTime); @@ -121,7 +121,7 @@ bool JClkLibClientApi::jcl_subscribe(JClkLibCommon::jcl_subscription &newSub, /* Wait for subscription result */ auto endTime = std::chrono::system_clock::now() + std::chrono::seconds(timeout_sec); - std::unique_lock lck(ClientSubscribeMessage::cv_mtx); + std::unique_lock lck(ClientSubscribeMessage::cv_mtx); while (appClientState.get_subscribed() == false ) { auto res = ClientSubscribeMessage::cv.wait_until(lck, endTime); @@ -188,7 +188,7 @@ bool check_proxy_liveness(ClientState &appClientState) /* Wait for connection result */ auto endTime = std::chrono::system_clock::now() + std::chrono::seconds(timeout_sec); - std::unique_lock lck(ClientConnectMessage::cv_mtx); + std::unique_lock lck(ClientConnectMessage::cv_mtx); while (appClientState.get_connected() == false) { auto res = ClientConnectMessage::cv.wait_until(lck, endTime); if (res == std::cv_status::timeout) { diff --git a/jclklib/client/subscribe_msg.cpp b/jclklib/client/subscribe_msg.cpp index e6402df3..44152198 100644 --- a/jclklib/client/subscribe_msg.cpp +++ b/jclklib/client/subscribe_msg.cpp @@ -164,7 +164,7 @@ PARSE_RXBUFFER_TYPE(ClientSubscribeMessage::parseBuffer) PROCESS_MESSAGE_TYPE(ClientSubscribeMessage::processMessage) { PrintDebug("[ClientSubscribeMessage]::processMessage (reply)"); - + std::unique_lock lock(cv_mtx); currentClientState->set_subscribed(true); /* Add the current ClientState to the notification class */ @@ -173,7 +173,7 @@ PROCESS_MESSAGE_TYPE(ClientSubscribeMessage::processMessage) jcl_state jclCurrentState = currentClientState->get_eventState(); - cv.notify_one(); + cv.notify_one(lock); return true; } diff --git a/jclklib/client/subscribe_msg.hpp b/jclklib/client/subscribe_msg.hpp index 02eae415..494a2a4a 100644 --- a/jclklib/client/subscribe_msg.hpp +++ b/jclklib/client/subscribe_msg.hpp @@ -18,6 +18,7 @@ #include #include #include +#include namespace JClkLibClient { @@ -33,8 +34,8 @@ namespace JClkLibClient public: ClientSubscribeMessage() : MESSAGE_SUBSCRIBE() {}; - static std::mutex cv_mtx; - static std::condition_variable cv; + static rtpi::mutex cv_mtx; + static rtpi::condition_variable cv; /** * @brief process the reply for subscribe msg from proxy. * @param LxContext client run-time transport listener context diff --git a/jclklib/common/Makefile b/jclklib/common/Makefile index 866912d0..b88d0235 100644 --- a/jclklib/common/Makefile +++ b/jclklib/common/Makefile @@ -11,7 +11,7 @@ JCLKLIB_COMMON_DIR := $(shell pwd) JCLKLIB_TOPLEVEL_DIR := $(JCLKLIB_COMMON_DIR)/.. -LIBS = pthread rt +LIBS = pthread rt rtpi LIBS_FLAGS = $(foreach lib,$(LIBS),-l$(lib)) OBJ = jclklib_import message msgq_tport notification_msg null_msg connect_msg print sighandler subscribe_msg transport OBJ_FILES = $(foreach f,$(OBJ),$(f).o) diff --git a/jclklib/proxy/Makefile b/jclklib/proxy/Makefile index fa19226b..c27f0b8c 100644 --- a/jclklib/proxy/Makefile +++ b/jclklib/proxy/Makefile @@ -13,7 +13,7 @@ JCLKLIB_PROXY_DIR := $(shell pwd) JCLKLIB_TOPLEVEL_DIR = $(JCLKLIB_PROXY_DIR)/.. JCLKLIB_COMMON_DIR = $(JCLKLIB_TOPLEVEL_DIR)/common PTPMGMT_DIR := $(JCLKLIB_TOPLEVEL_DIR)/.. -LIBS = pthread rt ptpmgmt +LIBS = pthread rt ptpmgmt rtpi LIBS_FLAGS = $(foreach lib,$(LIBS),-l$(lib)) -L$(PTPMGMT_DIR) OBJ = client main message msgq_tport notification_msg null_tport connect_msg subscribe_msg transport connect_ptp4l thread COMMON_OBJ = print sighandler transport msgq_tport jclklib_import message connect_msg subscribe_msg notification_msg diff --git a/jclklib/proxy/clock_config.hpp b/jclklib/proxy/clock_config.hpp index e3ff9168..c69efc90 100644 --- a/jclklib/proxy/clock_config.hpp +++ b/jclklib/proxy/clock_config.hpp @@ -16,10 +16,10 @@ #define CLOCK_CONFIG_HPP #include -#include #include #include +#include namespace JClkLibProxy { @@ -28,7 +28,7 @@ namespace JClkLibProxy private: enum { event = 0, value }; bool update, writeUpdate; - std::mutex update_lock; + rtpi::mutex update_lock; struct Config { JClkLibCommon::jcl_event event; JClkLibCommon::jcl_value value; diff --git a/jclklib/proxy/clock_status.hpp b/jclklib/proxy/clock_status.hpp index 204d77f5..650249c6 100644 --- a/jclklib/proxy/clock_status.hpp +++ b/jclklib/proxy/clock_status.hpp @@ -15,9 +15,8 @@ #ifndef CLOCK_STATUS_HPP #define CLOCK_STATUS_HPP -#include - #include +#include namespace JClkLibProxy { @@ -30,7 +29,7 @@ namespace JClkLibProxy JClkLibCommon::jcl_eventcount count; }; bool update, writeUpdate; - std::mutex update_lock; + rtpi::mutex update_lock; Status status; Status writeShadow, readShadow; public: diff --git a/jclklib/proxy/thread.cpp b/jclklib/proxy/thread.cpp index a9ab9ba9..dc72d0d1 100644 --- a/jclklib/proxy/thread.cpp +++ b/jclklib/proxy/thread.cpp @@ -26,7 +26,7 @@ static int start_work_thread( struct ptp4l_handle *handle ) } int connect_ptp4l( struct ptp4l_handle **phandle, struct epoll_event epd_event, - state_update_t update_cb, void *ctx) + void *ctx) { struct ptp4l_handle *handle; int ret; @@ -48,40 +48,6 @@ int connect_ptp4l( struct ptp4l_handle **phandle, struct epoll_event epd_event, return ret; } -int set_thread_signal( struct thread_signal *signal) -{ - int err, ret; - - if(( ret = pthread_mutex_lock( &signal->siglock)) != 0) - goto lock_fail; - signal->signaled = true; - if(( ret = pthread_cond_signal( &signal->signal )) != 0) - goto signal_fail; - - signal_fail: - if(( err = pthread_mutex_unlock( &signal->siglock)) != 0) - ret = ret == 0 ? err : ret; - - lock_fail: - return -ret; -} - -static bool state_update_callback( struct ptp4l_state *state, void * ctx) -{ - struct jcl_handle *handle = (typeof(handle)) ctx; - int ret; - - if(( ret = -pthread_mutex_lock( &handle->state_lock)) < 0) - goto lock_failed; - - if(( ret = -pthread_mutex_unlock( &handle->state_lock)) < 0) - goto unlock_failed; - - unlock_failed: - lock_failed: - return ret >= 0 ? true : false; -} - /** * @brief Initializes and connects a handle for PTP (Precision Time Protocol) event handling. * @@ -110,7 +76,7 @@ int handle_connect(struct epoll_event epd_event ) event_subscription( &handle ); ret = connect_ptp4l( &handle->ptp4l_handle, - epd_event, state_update_callback, handle); + epd_event, handle); if (ret != 0) { free(handle); goto alloc_fail; diff --git a/jclklib/proxy/thread.hpp b/jclklib/proxy/thread.hpp index d001bcd1..0b3b4e8d 100644 --- a/jclklib/proxy/thread.hpp +++ b/jclklib/proxy/thread.hpp @@ -27,24 +27,14 @@ #include -typedef struct thread_signal *thread_signal_t; typedef struct ptp4l_handle *ptp4l_handle_t; typedef struct jcl_handle *jcl_handle_t; typedef bool ( *state_update_t)( struct ptp4l_state *, void *); -typedef struct thread_signal *thread_signal_t; - -struct thread_signal { - pthread_mutex_t siglock; - pthread_cond_t signal; - bool signaled; -}; struct jcl_handle { ptp4l_handle_t ptp4l_handle; - thread_signal_t status_signal; - pthread_mutex_t state_lock; }; struct ptp4l_handle { From 6f586d09b8c3d56c4ecdad5c25b6db0c0d31c885 Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Thu, 6 Jun 2024 13:34:53 +0800 Subject: [PATCH 135/151] jclklib: Update yml file for librtpi Signed-off-by: Lai Peter Jun Ann --- .github/workflows/ci.yml | 9 +++++++++ .github/workflows/codeql.yml | 3 +++ .github/workflows/coverity.yml | 3 +++ 3 files changed, 15 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 56459439..5e51c09f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,6 +37,9 @@ jobs: steps: + - name: Install dependencies + run: git clone https://github.com/dvhart/librtpi.git && cd librtpi && autoreconf --install && ./configure && make install + - name: checkout repository uses: actions/checkout@v4 @@ -64,6 +67,9 @@ jobs: steps: + - name: Install dependencies + run: git clone https://github.com/dvhart/librtpi.git && cd librtpi && autoreconf --install && ./configure && make install + - name: checkout repository uses: actions/checkout@v4 @@ -85,6 +91,9 @@ jobs: steps: + - name: Install dependencies + run: git clone https://github.com/dvhart/librtpi.git && cd librtpi && autoreconf --install && ./configure && make install + - name: checkout linuxptp repository uses: actions/checkout@v4 with: diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index dc7ef3dc..fa76fe41 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -65,6 +65,9 @@ jobs: # By default, queries listed here will override any specified in a config file. # Prefix the list here with "+" to use these queries and those in the config file. + - name: Install dependencies + run: git clone https://github.com/dvhart/librtpi.git && cd librtpi && autoreconf --install && ./configure && sudo make install + - name: Install dependencies run: sudo apt-get install -y swig libtool-bin - name: autoheader diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml index 37b3f613..d3e7fa6d 100644 --- a/.github/workflows/coverity.yml +++ b/.github/workflows/coverity.yml @@ -24,6 +24,9 @@ jobs: with: egress-policy: audit + - name: Install dependencies + run: git clone https://github.com/dvhart/librtpi.git && cd librtpi && autoreconf --install && ./configure && sudo make install + - name: Install dependencies run: sudo apt-get install -y swig libtool-bin - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 From 1e89af4e8d0b4cfc9ddfea6ee6fab22c725c177a Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Fri, 7 Jun 2024 15:21:50 +0800 Subject: [PATCH 136/151] Update coverity.yml --- .github/workflows/coverity.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverity.yml b/.github/workflows/coverity.yml index d3e7fa6d..257c3cb4 100644 --- a/.github/workflows/coverity.yml +++ b/.github/workflows/coverity.yml @@ -25,7 +25,7 @@ jobs: egress-policy: audit - name: Install dependencies - run: git clone https://github.com/dvhart/librtpi.git && cd librtpi && autoreconf --install && ./configure && sudo make install + run: git clone https://github.com/dvhart/librtpi.git && cd librtpi && autoreconf --install && ./configure && sudo make install && cd - && sudo rm -rf librtpi - name: Install dependencies run: sudo apt-get install -y swig libtool-bin From c44ae8ef53f4d3a097875b73f73c32343a4f0491 Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Fri, 7 Jun 2024 15:50:18 +0800 Subject: [PATCH 137/151] jclklib: Update TEST_jclklib.md Signed-off-by: Lai Peter Jun Ann --- jclklib/TEST_jclklib.md | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/jclklib/TEST_jclklib.md b/jclklib/TEST_jclklib.md index 43be2f68..23ac041f 100644 --- a/jclklib/TEST_jclklib.md +++ b/jclklib/TEST_jclklib.md @@ -40,17 +40,26 @@ Jclkib.so is communicating with jclklib_proxy using message queue. sudo apt-get install -y swig libtool-bin cppcheck doxygen ctags astyle dot epstopdf valgrind ``` -2. Clone the repository: +2. Install Real-Time Priority Inheritance Library (librtpi): + ```bash + git clone https://github.com/dvhart/librtpi.git + cd librtpi + autoreconf --install + ./configure + sudo make install + ``` + +3. Clone the repository: ```bash git clone https://github.com/intel-staging/libptpmgmt_iaclocklib ``` -3. Navigate to the cloned directory: +4. Navigate to the cloned directory: ```bash cd libptpmgmt_iaclocklib ``` -4. Build the application: +5. Build the application: ```bash autoheader autoconf @@ -58,7 +67,7 @@ Jclkib.so is communicating with jclklib_proxy using message queue. make ``` -5. Outcome : you must have 3 binaries created: +6. Outcome : you must have 3 binaries created: ```bash libptpmgmt.so jclklib/client/libjclk.so @@ -139,7 +148,7 @@ Example output of sample application (jclk_test) : Upper Master Offset: 100000 ns Lower Master Offset: -100000 ns -[jclklib] Obtained data from Subscription Event: +[jclklib][5754097.973] Obtained data from Subscription Event: +-------------------+--------------------+ | Event | Event Status | +-------------------+--------------------+ From c277b6c875a5eeb61fe66d3ec69fab86f3066dd5 Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Fri, 7 Jun 2024 16:10:45 +0800 Subject: [PATCH 138/151] jclklib: Update README_jclklib.md Signed-off-by: Lai Peter Jun Ann --- jclklib/README_jclklib.md | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/jclklib/README_jclklib.md b/jclklib/README_jclklib.md index 4ce22f95..ab0ae196 100644 --- a/jclklib/README_jclklib.md +++ b/jclklib/README_jclklib.md @@ -5,44 +5,41 @@ Jclklib is a 2-part implementation for C/C++ application to obtain ptp4l events via pub/sub method using a library api call. -It provides a library jcklib.so (aka client-runtime library) and a daemon +It provides a library libjclk.so (aka client-runtime library) and a daemon jclklib_proxy. In short we have : FRONT-END MIDDLE-PIPE BACK-END -c/c++ app<-------->jclklib.so<---------->jclklib_proxy<-------->ptp4l +c/c++ app<-------->libjclk.so<---------->jclklib_proxy<-------->ptp4l (library call) (using msq) | (via UDS) | libptpmgmt.so **if the diagram is not lisible, please change to text mode.** -* **c++ app** - Customer application that will be linking to jclklib.so library. Header file and sample test cpp file will be provided. +* **c++ app** - Customer application that will be linking to libjclk.so library. Header file and sample test cpp file will be provided. -* **jclklib.so** - A dynamic library that provides a set of APIs to customer application : connect/disconnect, subscribe to proxy which in turn connect to ptp4l service. -This library is written in C++. It will have a permissive licence. It communicates with jclkib_proxy using message queues. +* **libjclk.so** - A dynamic library that provides a set of APIs to customer application : connect/disconnect, subscribe to proxy which in turn connect to ptp4l service. +This library is written in C++. It will have a permissive licence. It communicates with jclklib_proxy using message queues. This library is also referred to as client-runtime library. * **jclklib_proxy** - A daemon that is using libptpmgmt api to establish connection and subscribe towards ptp4l events. The communication is established using ptp4l UDS (/var/run/ptp4l as we now assumed it is always installed in the same local machine as the ptp4l) -## Compilation -Currently, we need to run 'make' in client, proxy folder. -It will definitely change in the future. Stay tuned. +## Compilation and test step +* [Build project documentation](./TEST_jclklib.md) ## Connect message info -### Code Example : client/test.cpp , client/run_test.sh -Please adjust the LD_LIBRARY_PATH accordingly to include the correct jclklib.so -The placement will be changed in the future. +### Code Example : sample/jclk_test.cpp , sample/run_jclk_test.sh ### Connect message flow (simplified code walkthrough) -Scenario : client application uses the jcklkib.so API to call `connect()`. +Scenario : client application uses the jcklkib.so API to call `jcl_connect()`. This will establish connection to the proxy. ** Client point of view ** -1. **client/init.cpp/JClkLibClient::connect()** +1. **client/jclk_init.cpp/JClkLibClientApi::jcl_connect()** - Creation of new ClientConnectMessage object for CONNECT_MSG 1.1. **client/message.cpp/ClientMessage::init()** @@ -56,7 +53,7 @@ This will establish connection to the proxy. by the client transporter layer, it will know how to translate the object to messagequeue buffer. -1.2. **client/init.cpp/ClientTransport::init()** +1.2. **client/jclk_init.cpp/ClientTransport::init()** - Same concept as above but using initTransport recursive template. This will execute the `ClientMessageQueue::initTransport()` @@ -90,7 +87,7 @@ Currently we only printout the sessionID given by the proxy. Jclklib_proxy runs like a service daemon waiting for messages from potential client app. The main loop function is in main.cpp. -How to run : LD_CONFIG_PATH= jcklib_proxy -lptpmgmt & +How to run : ./jclklib/proxy/run_proxy.sh 1. **proxy/transport.cpp/ProxyTransport::init()** - Same as for Client, the ProxyTransport layer is initialized. From 53c4d7d4d739d08811049a5e51f9d8dbe5a2d5a4 Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Fri, 7 Jun 2024 16:25:52 +0800 Subject: [PATCH 139/151] jclklib: Fix client not able to connect to proxy issue Signed-off-by: Lai Peter Jun Ann --- jclklib/common/msgq_tport.cpp | 1 - jclklib/proxy/client.hpp | 2 ++ jclklib/proxy/connect_ptp4l.cpp | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/jclklib/common/msgq_tport.cpp b/jclklib/common/msgq_tport.cpp index 2fb2d6ec..017d87c5 100644 --- a/jclklib/common/msgq_tport.cpp +++ b/jclklib/common/msgq_tport.cpp @@ -94,7 +94,6 @@ SEND_BUFFER_TYPE(MessageQueueTransmitterContext::sendBuffer) { if (mq_send(mqTransmitterDesc, (char *)get_buffer().data(), get_offset(), 0) == -1) { PrintErrorCode("Failed to send buffer"); - mq_close(mqTransmitterDesc); return false; } diff --git a/jclklib/proxy/client.hpp b/jclklib/proxy/client.hpp index bcbc157c..34ca5ab2 100644 --- a/jclklib/proxy/client.hpp +++ b/jclklib/proxy/client.hpp @@ -33,6 +33,8 @@ namespace JClkLibProxy { public: static JClkLibCommon::sessionId_t CreateClientSession(); static size_t GetSessionCount() { return SessionMap.size(); } + static void RemoveClientSession(JClkLibCommon::sessionId_t sessionId) { + SessionMap.erase(sessionId);} static JClkLibCommon::sessionId_t GetSessionIdAt(size_t index); static ClientX GetClientSession(JClkLibCommon::sessionId_t sessionId); private: diff --git a/jclklib/proxy/connect_ptp4l.cpp b/jclklib/proxy/connect_ptp4l.cpp index 0f61f769..f86216e2 100644 --- a/jclklib/proxy/connect_ptp4l.cpp +++ b/jclklib/proxy/connect_ptp4l.cpp @@ -74,7 +74,9 @@ void notify_client() PrintDebug("Get client session ID: " + to_string(SessionId)); auto TxContext = Client::GetClientSession(SessionId).get()->get_transmitContext(); - pmsg->transmitMessage(*TxContext); + if (!pmsg->transmitMessage(*TxContext)) + Client::RemoveClientSession(SessionId); + } else { PrintError("Unable to get Session ID\n"); } From 86c1b6d5be7d7a670cd6affa738c99e27ec58e59 Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Fri, 7 Jun 2024 17:14:03 +0800 Subject: [PATCH 140/151] jclklib: Fix composite event not sync issue Signed-off-by: Lai Peter Jun Ann --- jclklib/client/notification_msg.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/jclklib/client/notification_msg.cpp b/jclklib/client/notification_msg.cpp index 930e9ab1..10f2b199 100644 --- a/jclklib/client/notification_msg.cpp +++ b/jclklib/client/notification_msg.cpp @@ -153,9 +153,16 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) handleGmOffsetEvent(eventSub[0], gmOffsetEvent, client_ptp_data->master_offset, proxy_data.master_offset, client_ptp_data->offset_in_range_event_count, client_ptp_data->master_offset_in_range, lower_master_offset, upper_master_offset); - handleGmOffsetEvent(composite_eventSub[0], gmOffsetEvent, composite_client_ptp_data->master_offset, - proxy_data.master_offset, composite_client_ptp_data->offset_in_range_event_count, - composite_client_ptp_data->composite_event, lower_master_offset, upper_master_offset); + + if (composite_eventSub[0] & 1<master_offset = proxy_data.master_offset; + if ((composite_client_ptp_data->master_offset > lower_master_offset) && + (composite_client_ptp_data->master_offset < upper_master_offset)) { + composite_client_ptp_data->composite_event = true; + } else { + composite_client_ptp_data->composite_event = false; + } + } if (composite_eventSub[0] && (old_composite_event != composite_client_ptp_data->composite_event)) client_ptp_data->composite_event_count.fetch_add(1, std::memory_order_relaxed); From 26418c5ad052acce3a96dfa97ad2381aef14547d Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Fri, 7 Jun 2024 18:27:02 +0800 Subject: [PATCH 141/151] jclklib: client: Update license to BSD-3-Clause Signed-off-by: Lai Peter Jun Ann --- jclklib/client/Makefile | 8 ++++---- jclklib/client/connect_msg.cpp | 8 ++++---- jclklib/client/connect_msg.hpp | 8 ++++---- jclklib/client/jclk_client_state.cpp | 8 ++++---- jclklib/client/jclk_client_state.hpp | 8 ++++---- jclklib/client/jclk_init.cpp | 8 ++++---- jclklib/client/jclk_init.hpp | 8 ++++---- jclklib/client/message.cpp | 8 ++++---- jclklib/client/message.hpp | 8 ++++---- jclklib/client/msgq_tport.cpp | 8 ++++---- jclklib/client/msgq_tport.hpp | 8 ++++---- jclklib/client/notification_msg.cpp | 8 ++++---- jclklib/client/notification_msg.hpp | 8 ++++---- jclklib/client/null_msg.hpp | 8 ++++---- jclklib/client/null_tport.cpp | 8 ++++---- jclklib/client/null_tport.hpp | 8 ++++---- jclklib/client/subscribe_msg.cpp | 8 ++++---- jclklib/client/subscribe_msg.hpp | 8 ++++---- jclklib/client/transport.cpp | 8 ++++---- jclklib/client/transport.hpp | 8 ++++---- 20 files changed, 80 insertions(+), 80 deletions(-) diff --git a/jclklib/client/Makefile b/jclklib/client/Makefile index 83a2626b..4da93119 100644 --- a/jclklib/client/Makefile +++ b/jclklib/client/Makefile @@ -1,11 +1,11 @@ -# SPDX-License-Identifier: LGPL-3.0-or-later -# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: BSD-3-Clause +# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. # # Makefile for jclklib client # # @author Christopher Hall -# @copyright © 2024 Intel Corporation. All rights reserved. -# @license LGPL-3.0-or-later +# @copyright © 2024 Intel Corporation. +# @license BSD-3-Clause # ############################################################################### diff --git a/jclklib/client/connect_msg.cpp b/jclklib/client/connect_msg.cpp index d3451993..3af24c66 100644 --- a/jclklib/client/connect_msg.cpp +++ b/jclklib/client/connect_msg.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file connect_msg.cpp * @brief Client connect message class. Implements client specific functionality. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/client/connect_msg.hpp b/jclklib/client/connect_msg.hpp index 747d0e96..e71dc581 100644 --- a/jclklib/client/connect_msg.hpp +++ b/jclklib/client/connect_msg.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file connect_msg.hpp * @brief Client connect message class. Implements client specific functionality. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/client/jclk_client_state.cpp b/jclklib/client/jclk_client_state.cpp index 8fe4f5cb..655c9ec9 100644 --- a/jclklib/client/jclk_client_state.cpp +++ b/jclklib/client/jclk_client_state.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file jclk_client_state.cpp * @brief Set and get the client subscribe event state * * @author Noor Azura Ahmad Tarmizi - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/client/jclk_client_state.hpp b/jclklib/client/jclk_client_state.hpp index 4d1c92fe..9129e507 100644 --- a/jclklib/client/jclk_client_state.hpp +++ b/jclklib/client/jclk_client_state.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file jclk_client_state.hpp * @brief Set and get the client subscribe event state * * @author Noor Azura Ahmad Tarmizi - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/client/jclk_init.cpp b/jclklib/client/jclk_init.cpp index bf3c8037..68d49925 100644 --- a/jclklib/client/jclk_init.cpp +++ b/jclklib/client/jclk_init.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file init.cpp * @brief Client utilities to setup and cleanup the library. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/client/jclk_init.hpp b/jclklib/client/jclk_init.hpp index 8722f762..9fd907e0 100644 --- a/jclklib/client/jclk_init.hpp +++ b/jclklib/client/jclk_init.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file jclk_init.hpp * @brief Client utilities to setup and cleanup the library. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/client/message.cpp b/jclklib/client/message.cpp index 1523742d..95ca62d3 100644 --- a/jclklib/client/message.cpp +++ b/jclklib/client/message.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file message.cpp * @brief Client message base class. Extended for specific messages such as connect and subscribe. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/client/message.hpp b/jclklib/client/message.hpp index be3cfa53..0f3376bf 100644 --- a/jclklib/client/message.hpp +++ b/jclklib/client/message.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file message.hpp * @brief Client message base class. Extended for specific messages such as connect and subscribe. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/client/msgq_tport.cpp b/jclklib/client/msgq_tport.cpp index e6af0819..0208ca4c 100644 --- a/jclklib/client/msgq_tport.cpp +++ b/jclklib/client/msgq_tport.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file msgq_tport.cpp * @brief Client POSIX message queue transport class. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/client/msgq_tport.hpp b/jclklib/client/msgq_tport.hpp index 303d78e8..9b23b0db 100644 --- a/jclklib/client/msgq_tport.hpp +++ b/jclklib/client/msgq_tport.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file msgq_tport.hpp * @brief Client POSIX message queue transport class. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/client/notification_msg.cpp b/jclklib/client/notification_msg.cpp index 10f2b199..2417a247 100644 --- a/jclklib/client/notification_msg.cpp +++ b/jclklib/client/notification_msg.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file notification_msg.hpp * @brief Client notification message class. Implements client specific notification message function. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/client/notification_msg.hpp b/jclklib/client/notification_msg.hpp index 7900075d..7c8a85a0 100644 --- a/jclklib/client/notification_msg.hpp +++ b/jclklib/client/notification_msg.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file notification_msg.hpp * @brief Client notification message class. Implements client specific notification message function. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/client/null_msg.hpp b/jclklib/client/null_msg.hpp index 6563c076..d53c6265 100644 --- a/jclklib/client/null_msg.hpp +++ b/jclklib/client/null_msg.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file null_msg.hpp * @brief Non-functional message class for debug * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/client/null_tport.cpp b/jclklib/client/null_tport.cpp index 9d83f3a6..62461a1a 100644 --- a/jclklib/client/null_tport.cpp +++ b/jclklib/client/null_tport.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file null_tport.cpp * @brief Null transport implementation. Non-functional for testing only. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/client/null_tport.hpp b/jclklib/client/null_tport.hpp index c56a1b53..9b60f3b9 100644 --- a/jclklib/client/null_tport.hpp +++ b/jclklib/client/null_tport.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file null_tport.cpp * @brief Null transport implementation. Non-functional for testing only. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/client/subscribe_msg.cpp b/jclklib/client/subscribe_msg.cpp index 44152198..cd812cae 100644 --- a/jclklib/client/subscribe_msg.cpp +++ b/jclklib/client/subscribe_msg.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file subscribe_msg.cpp * @brief Client subscribe message class. Implements client specific functionality. * * @author Noor Azura Ahmad Tarmizi - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/client/subscribe_msg.hpp b/jclklib/client/subscribe_msg.hpp index 494a2a4a..85ac6b48 100644 --- a/jclklib/client/subscribe_msg.hpp +++ b/jclklib/client/subscribe_msg.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file subscribe_msg.hpp * @brief Client subscribe message class. Implements client specific functionality. * * @author Noor Azura Ahmad Tarmizi - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/client/transport.cpp b/jclklib/client/transport.cpp index 0e84f584..c66928b6 100644 --- a/jclklib/client/transport.cpp +++ b/jclklib/client/transport.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file transport.cpp * @brief Client transport base implementation for JClkLib. It is extended for specific transports such as POSIX message queue. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/client/transport.hpp b/jclklib/client/transport.hpp index e63737f1..d35628ab 100644 --- a/jclklib/client/transport.hpp +++ b/jclklib/client/transport.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file transport.hpp * @brief Client transport base class for JClkLib. It is extended for specific transports such as POSIX message queue. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ From 987639dd9abbf711d39423bd52d7f1e36c9a54de Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Fri, 7 Jun 2024 18:35:26 +0800 Subject: [PATCH 142/151] jclklib: common: Update license to BSD-3-Clause Signed-off-by: Lai Peter Jun Ann --- jclklib/common/Makefile | 8 ++++---- jclklib/common/connect_msg.cpp | 8 ++++---- jclklib/common/connect_msg.hpp | 8 ++++---- jclklib/common/jclklib_import.cpp | 8 ++++---- jclklib/common/jclklib_import.hpp | 8 ++++---- jclklib/common/jcltypes.hpp | 8 ++++---- jclklib/common/message.cpp | 8 ++++---- jclklib/common/message.hpp | 8 ++++---- jclklib/common/msgq_tport.cpp | 8 ++++---- jclklib/common/msgq_tport.hpp | 8 ++++---- jclklib/common/notification_msg.cpp | 8 ++++---- jclklib/common/notification_msg.hpp | 8 ++++---- jclklib/common/null_msg.cpp | 8 ++++---- jclklib/common/null_msg.hpp | 8 ++++---- jclklib/common/null_tport.hpp | 8 ++++---- jclklib/common/print.cpp | 8 ++++---- jclklib/common/print.hpp | 8 ++++---- jclklib/common/serialize.hpp | 8 ++++---- jclklib/common/sighandler.cpp | 8 ++++---- jclklib/common/sighandler.hpp | 8 ++++---- jclklib/common/subscribe_msg.cpp | 8 ++++---- jclklib/common/subscribe_msg.hpp | 8 ++++---- jclklib/common/transport.cpp | 8 ++++---- jclklib/common/transport.hpp | 8 ++++---- jclklib/common/util.hpp | 8 ++++---- 25 files changed, 100 insertions(+), 100 deletions(-) diff --git a/jclklib/common/Makefile b/jclklib/common/Makefile index b88d0235..a08dc41e 100644 --- a/jclklib/common/Makefile +++ b/jclklib/common/Makefile @@ -1,11 +1,11 @@ -# SPDX-License-Identifier: LGPL-3.0-or-later -# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: BSD-3-Clause +# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. # # Makefile for jclklib common # # @author Christopher Hall -# @copyright © 2024 Intel Corporation. All rights reserved. -# @license LGPL-3.0-or-later +# @copyright © 2024 Intel Corporation. +# @license BSD-3-Clause # ############################################################################### diff --git a/jclklib/common/connect_msg.cpp b/jclklib/common/connect_msg.cpp index 16479e00..536f6b38 100644 --- a/jclklib/common/connect_msg.cpp +++ b/jclklib/common/connect_msg.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file connect_msg.cpp * @brief Common connect message implementation. Implements common functions and (de-)serialization * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/common/connect_msg.hpp b/jclklib/common/connect_msg.hpp index 1219e59f..9299d420 100644 --- a/jclklib/common/connect_msg.hpp +++ b/jclklib/common/connect_msg.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file connect_msg.hpp * @brief Common connect message class. Implements common functions and (de-)serialization * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/common/jclklib_import.cpp b/jclklib/common/jclklib_import.cpp index af1257e0..046d9a18 100644 --- a/jclklib/common/jclklib_import.cpp +++ b/jclklib/common/jclklib_import.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file jclklib_import.cpp * @brief C API import. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/common/jclklib_import.hpp b/jclklib/common/jclklib_import.hpp index 9d83127e..06609b93 100644 --- a/jclklib/common/jclklib_import.hpp +++ b/jclklib/common/jclklib_import.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file jclklib_import.hpp * @brief C API import. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/common/jcltypes.hpp b/jclklib/common/jcltypes.hpp index 0bf372ad..f76cf777 100644 --- a/jclklib/common/jcltypes.hpp +++ b/jclklib/common/jcltypes.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file jcltypes.hpp * @brief Common message type * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/common/message.cpp b/jclklib/common/message.cpp index 820ec81e..85963a20 100644 --- a/jclklib/common/message.cpp +++ b/jclklib/common/message.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file message.cpp * @brief Common message base implementation. Extended for specific messages such as connect and subscribe. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/common/message.hpp b/jclklib/common/message.hpp index c9ce765d..dc6c3ff4 100644 --- a/jclklib/common/message.hpp +++ b/jclklib/common/message.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file message.hpp * @brief Common message base class. Extended for specific messages such as connect and subscribe. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/common/msgq_tport.cpp b/jclklib/common/msgq_tport.cpp index 017d87c5..ab0941b3 100644 --- a/jclklib/common/msgq_tport.cpp +++ b/jclklib/common/msgq_tport.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file msgq_tport.cpp * @brief Common POSIX message queue transport implementation. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/common/msgq_tport.hpp b/jclklib/common/msgq_tport.hpp index 19789951..e49ee26c 100644 --- a/jclklib/common/msgq_tport.hpp +++ b/jclklib/common/msgq_tport.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file msgq_tport.hpp * @brief Common POSIX message queue transport class. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/common/notification_msg.cpp b/jclklib/common/notification_msg.cpp index 30c56841..7e9b8061 100644 --- a/jclklib/common/notification_msg.cpp +++ b/jclklib/common/notification_msg.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file notification_msg.cpp * @brief Common notification message implementation. Implements common functions and (de-)serialization * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/common/notification_msg.hpp b/jclklib/common/notification_msg.hpp index 0cfe7238..241ea3e8 100644 --- a/jclklib/common/notification_msg.hpp +++ b/jclklib/common/notification_msg.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file notification_msg.hpp * @brief Common notification message class. Implements common functions and (de-)serialization * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/common/null_msg.cpp b/jclklib/common/null_msg.cpp index fdcffbd4..cd6fc4d7 100644 --- a/jclklib/common/null_msg.cpp +++ b/jclklib/common/null_msg.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file null_msg.cpp * @brief Non-functional message implementation for debug * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/common/null_msg.hpp b/jclklib/common/null_msg.hpp index 8d469977..dd833997 100644 --- a/jclklib/common/null_msg.hpp +++ b/jclklib/common/null_msg.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file null_msg.hpp * @brief Non-functional message class for debug * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/common/null_tport.hpp b/jclklib/common/null_tport.hpp index 5093a510..745244a2 100644 --- a/jclklib/common/null_tport.hpp +++ b/jclklib/common/null_tport.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file null_tport.hpp * @brief Null transport class. Non-functional for testing only. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/common/print.cpp b/jclklib/common/print.cpp index df4fd31f..8d702c68 100644 --- a/jclklib/common/print.cpp +++ b/jclklib/common/print.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file print.cpp * @brief Utility functions for printing * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/common/print.hpp b/jclklib/common/print.hpp index eada5bb0..8297e5d2 100644 --- a/jclklib/common/print.hpp +++ b/jclklib/common/print.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file print.hpp * @brief Utility functions for printing * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/common/serialize.hpp b/jclklib/common/serialize.hpp index cb2365e3..e86b56dc 100644 --- a/jclklib/common/serialize.hpp +++ b/jclklib/common/serialize.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file serialize.hpp * @brief Utility macros for (de-)serializing data * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/common/sighandler.cpp b/jclklib/common/sighandler.cpp index e08144b3..5b57519e 100644 --- a/jclklib/common/sighandler.cpp +++ b/jclklib/common/sighandler.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file sighandler.cpp * @brief Signal handling utilities * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/common/sighandler.hpp b/jclklib/common/sighandler.hpp index f678a887..cc8185f1 100644 --- a/jclklib/common/sighandler.hpp +++ b/jclklib/common/sighandler.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file sighandler.hpp * @brief Signal handling utilities * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/common/subscribe_msg.cpp b/jclklib/common/subscribe_msg.cpp index f9204881..53c6a13e 100644 --- a/jclklib/common/subscribe_msg.cpp +++ b/jclklib/common/subscribe_msg.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file subscribe_msg.cpp * @brief Common subscribe message implementation. Implements common functions and (de-)serialization * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/common/subscribe_msg.hpp b/jclklib/common/subscribe_msg.hpp index e03a4159..0df53d07 100644 --- a/jclklib/common/subscribe_msg.hpp +++ b/jclklib/common/subscribe_msg.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file subscribe_msg.hpp * @brief Common subscribe message class. Implements common functions and (de-)serialization * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/common/transport.cpp b/jclklib/common/transport.cpp index 1ed6db74..da769c68 100644 --- a/jclklib/common/transport.cpp +++ b/jclklib/common/transport.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file transport.cpp * @brief Common transport base class implementation for JClkLib. It provides common functionality for derived transport classes. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/common/transport.hpp b/jclklib/common/transport.hpp index 0ab623da..b96458ba 100644 --- a/jclklib/common/transport.hpp +++ b/jclklib/common/transport.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file transport.hpp * @brief Common transport base class for JClkLib. It is extended for specific transports such as POSIX message queue. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/common/util.hpp b/jclklib/common/util.hpp index 9b675caa..63571620 100644 --- a/jclklib/common/util.hpp +++ b/jclklib/common/util.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file util.hpp * @brief Helper functions, templates, and macros * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ From 07b6514325b16942c7bda3ca01ca22247166e1cb Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Fri, 7 Jun 2024 18:43:29 +0800 Subject: [PATCH 143/151] jclklib: proxy: Update license to BSD-3-Clause Signed-off-by: Lai Peter Jun Ann --- jclklib/proxy/Makefile | 8 ++++---- jclklib/proxy/client.cpp | 8 ++++---- jclklib/proxy/client.hpp | 8 ++++---- jclklib/proxy/clock_config.cpp | 8 ++++---- jclklib/proxy/clock_config.hpp | 8 ++++---- jclklib/proxy/clock_status.cpp | 8 ++++---- jclklib/proxy/clock_status.hpp | 8 ++++---- jclklib/proxy/connect_msg.cpp | 8 ++++---- jclklib/proxy/connect_msg.hpp | 8 ++++---- jclklib/proxy/connect_ptp4l.cpp | 8 ++++---- jclklib/proxy/connect_ptp4l.hpp | 8 ++++---- jclklib/proxy/main.cpp | 8 ++++---- jclklib/proxy/message.cpp | 8 ++++---- jclklib/proxy/message.hpp | 8 ++++---- jclklib/proxy/msgq_tport.cpp | 8 ++++---- jclklib/proxy/msgq_tport.hpp | 8 ++++---- jclklib/proxy/notification_msg.cpp | 8 ++++---- jclklib/proxy/notification_msg.hpp | 8 ++++---- jclklib/proxy/null_msg.hpp | 8 ++++---- jclklib/proxy/null_tport.cpp | 8 ++++---- jclklib/proxy/null_tport.hpp | 8 ++++---- jclklib/proxy/run_proxy.sh | 8 ++++---- jclklib/proxy/run_ptp4l.sh | 8 ++++---- jclklib/proxy/subscribe_msg.cpp | 8 ++++---- jclklib/proxy/subscribe_msg.hpp | 8 ++++---- jclklib/proxy/thread.cpp | 8 ++++---- jclklib/proxy/thread.hpp | 8 ++++---- jclklib/proxy/transport.cpp | 8 ++++---- jclklib/proxy/transport.hpp | 8 ++++---- 29 files changed, 116 insertions(+), 116 deletions(-) diff --git a/jclklib/proxy/Makefile b/jclklib/proxy/Makefile index c27f0b8c..5dfdcd12 100644 --- a/jclklib/proxy/Makefile +++ b/jclklib/proxy/Makefile @@ -1,11 +1,11 @@ -# SPDX-License-Identifier: LGPL-3.0-or-later -# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: BSD-3-Clause +# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. # # Makefile for jclklib proxy # # @author Christopher Hall -# @copyright © 2024 Intel Corporation. All rights reserved. -# @license LGPL-3.0-or-later +# @copyright © 2024 Intel Corporation. +# @license BSD-3-Clause # ############################################################################### diff --git a/jclklib/proxy/client.cpp b/jclklib/proxy/client.cpp index bcb29b96..b9d4f9d7 100644 --- a/jclklib/proxy/client.cpp +++ b/jclklib/proxy/client.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file client.cpp * @brief Common client infomation implementation * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/proxy/client.hpp b/jclklib/proxy/client.hpp index 34ca5ab2..fda86640 100644 --- a/jclklib/proxy/client.hpp +++ b/jclklib/proxy/client.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file client.hpp * @brief Common client infomation implementation * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/proxy/clock_config.cpp b/jclklib/proxy/clock_config.cpp index 9aee02f9..dd059a4b 100644 --- a/jclklib/proxy/clock_config.cpp +++ b/jclklib/proxy/clock_config.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file clock_config.cpp * @brief Proxy configuration implementation. One configuration object per session is instatiated * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/proxy/clock_config.hpp b/jclklib/proxy/clock_config.hpp index c69efc90..9e795f8e 100644 --- a/jclklib/proxy/clock_config.hpp +++ b/jclklib/proxy/clock_config.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file clock_config.hpp * @brief Proxy configuration class. One configuration object per session is instatiated * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/proxy/clock_status.cpp b/jclklib/proxy/clock_status.cpp index 882c65a6..0528f774 100644 --- a/jclklib/proxy/clock_status.cpp +++ b/jclklib/proxy/clock_status.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file clock_status.cpp * @brief Proxy status implementation. One status object per session. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/proxy/clock_status.hpp b/jclklib/proxy/clock_status.hpp index 650249c6..d545294c 100644 --- a/jclklib/proxy/clock_status.hpp +++ b/jclklib/proxy/clock_status.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file clock_status.hpp * @brief Proxy status class. One status object per session. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/proxy/connect_msg.cpp b/jclklib/proxy/connect_msg.cpp index 01baaadc..de7c48f5 100644 --- a/jclklib/proxy/connect_msg.cpp +++ b/jclklib/proxy/connect_msg.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file connect_msg.cpp * @brief Proxy connect message implementation. Implements proxy specific connect message function. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/proxy/connect_msg.hpp b/jclklib/proxy/connect_msg.hpp index 85084cee..4ecd2cf9 100644 --- a/jclklib/proxy/connect_msg.hpp +++ b/jclklib/proxy/connect_msg.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file connect_msg.hpp * @brief Proxy connect message class. Implements proxy specific connect message function. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/proxy/connect_ptp4l.cpp b/jclklib/proxy/connect_ptp4l.cpp index f86216e2..b4006bf3 100644 --- a/jclklib/proxy/connect_ptp4l.cpp +++ b/jclklib/proxy/connect_ptp4l.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file connect.cpp * @brief Proxy connect ptp4l message class. * * @author Lai Peter Jun Ann - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/proxy/connect_ptp4l.hpp b/jclklib/proxy/connect_ptp4l.hpp index 2aeea608..421c4f95 100644 --- a/jclklib/proxy/connect_ptp4l.hpp +++ b/jclklib/proxy/connect_ptp4l.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file connect.hpp * @brief Proxy connect ptp4l message class. * * @author Lai Peter Jun Ann - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/proxy/main.cpp b/jclklib/proxy/main.cpp index 5e5a04b1..eced56dc 100644 --- a/jclklib/proxy/main.cpp +++ b/jclklib/proxy/main.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file main.cpp * @brief Proxy application implementation * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/proxy/message.cpp b/jclklib/proxy/message.cpp index 7913c141..a5c5df4b 100644 --- a/jclklib/proxy/message.cpp +++ b/jclklib/proxy/message.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file message.cpp * @brief Proxy message base implementation. Extended for specific messages such as connect and subscribe. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/proxy/message.hpp b/jclklib/proxy/message.hpp index 573be472..30deaf32 100644 --- a/jclklib/proxy/message.hpp +++ b/jclklib/proxy/message.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file message.hpp * @brief Proxy message base class. Extended for specific messages such as connect and subscribe. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/proxy/msgq_tport.cpp b/jclklib/proxy/msgq_tport.cpp index fe1d92fe..7650fabc 100644 --- a/jclklib/proxy/msgq_tport.cpp +++ b/jclklib/proxy/msgq_tport.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file msgq_tport.cpp * @brief Proxy POSIX message queue transport implementation. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/proxy/msgq_tport.hpp b/jclklib/proxy/msgq_tport.hpp index ddae929a..72dedb1e 100644 --- a/jclklib/proxy/msgq_tport.hpp +++ b/jclklib/proxy/msgq_tport.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file msgq_tport.hpp * @brief Proxy POSIX message queue transport class. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/proxy/notification_msg.cpp b/jclklib/proxy/notification_msg.cpp index 27917606..e1ae5da7 100644 --- a/jclklib/proxy/notification_msg.cpp +++ b/jclklib/proxy/notification_msg.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file notification_msg.cpp * @brief Proxy notification message implementation. Implements proxy specific notification message function. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/proxy/notification_msg.hpp b/jclklib/proxy/notification_msg.hpp index 9ea464d5..f2cefce9 100644 --- a/jclklib/proxy/notification_msg.hpp +++ b/jclklib/proxy/notification_msg.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file notification_msg.hpp * @brief Proxy notification message class. Implements proxy specific notification message function. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/proxy/null_msg.hpp b/jclklib/proxy/null_msg.hpp index bd8e60d8..3c1cd729 100644 --- a/jclklib/proxy/null_msg.hpp +++ b/jclklib/proxy/null_msg.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file null_msg.hpp * @brief Proxy null message class. Used for debug only. Should not be used. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/proxy/null_tport.cpp b/jclklib/proxy/null_tport.cpp index e7c80b09..aab1348a 100644 --- a/jclklib/proxy/null_tport.cpp +++ b/jclklib/proxy/null_tport.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file null_tport.cpp * @brief Null transport implementation. Non-functional for testing only. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/proxy/null_tport.hpp b/jclklib/proxy/null_tport.hpp index 2e436a9b..8ad43d34 100644 --- a/jclklib/proxy/null_tport.hpp +++ b/jclklib/proxy/null_tport.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file null_tport.hpp * @brief Null transport class. Non-functional for testing only. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/proxy/run_proxy.sh b/jclklib/proxy/run_proxy.sh index d41f0f87..d8687ca7 100755 --- a/jclklib/proxy/run_proxy.sh +++ b/jclklib/proxy/run_proxy.sh @@ -1,10 +1,10 @@ #!/bin/bash -# SPDX-License-Identifier: LGPL-3.0-or-later -# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: BSD-3-Clause +# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. # # @author Christopher Hall -# @copyright © 2024 Intel Corporation. All rights reserved. -# @license LGPL-3.0-or-later +# @copyright © 2024 Intel Corporation. +# @license BSD-3-Clause # ############################################################################### diff --git a/jclklib/proxy/run_ptp4l.sh b/jclklib/proxy/run_ptp4l.sh index 65da1b47..87912a1d 100644 --- a/jclklib/proxy/run_ptp4l.sh +++ b/jclklib/proxy/run_ptp4l.sh @@ -1,10 +1,10 @@ #!/bin/bash -# SPDX-License-Identifier: LGPL-3.0-or-later -# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: BSD-3-Clause +# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. # # @author Christopher Hall -# @copyright © 2024 Intel Corporation. All rights reserved. -# @license LGPL-3.0-or-later +# @copyright © 2024 Intel Corporation. +# @license BSD-3-Clause # ############################################################################### diff --git a/jclklib/proxy/subscribe_msg.cpp b/jclklib/proxy/subscribe_msg.cpp index 88c1218e..3b7335d7 100644 --- a/jclklib/proxy/subscribe_msg.cpp +++ b/jclklib/proxy/subscribe_msg.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file subscribe_msg.cpp * @brief Proxy subscribe message implementation. Implements proxy specific subscribe message function. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/proxy/subscribe_msg.hpp b/jclklib/proxy/subscribe_msg.hpp index bee25f8a..917115d5 100644 --- a/jclklib/proxy/subscribe_msg.hpp +++ b/jclklib/proxy/subscribe_msg.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file subscribe_msg.hpp * @brief Proxy subscribe message class. Implements proxy specific subscribe message function. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/proxy/thread.cpp b/jclklib/proxy/thread.cpp index dc72d0d1..bfdc181c 100644 --- a/jclklib/proxy/thread.cpp +++ b/jclklib/proxy/thread.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file thread.cpp * @brief Proxy message thread class. * * @author Lai Peter Jun Ann - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/proxy/thread.hpp b/jclklib/proxy/thread.hpp index 0b3b4e8d..fc7b5d7e 100644 --- a/jclklib/proxy/thread.hpp +++ b/jclklib/proxy/thread.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file thread.hpp * @brief Proxy message thread class. * * @author Lai Peter Jun Ann - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/proxy/transport.cpp b/jclklib/proxy/transport.cpp index e98c868c..6a959ad5 100644 --- a/jclklib/proxy/transport.cpp +++ b/jclklib/proxy/transport.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file transport.cpp * @brief Proxy transport base class implementation for JClkLib. It provides common functionality for derived transport classes. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ diff --git a/jclklib/proxy/transport.hpp b/jclklib/proxy/transport.hpp index e6fee17c..bede9e70 100644 --- a/jclklib/proxy/transport.hpp +++ b/jclklib/proxy/transport.hpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file transport.hpp * @brief Proxy transport base class for JClkLib. It provides common functionality for derived transport classes. * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * */ From 473a706c6f420e8c12e851a17faf199b31f3fe9b Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Fri, 7 Jun 2024 18:49:39 +0800 Subject: [PATCH 144/151] jclklib: sample: Update license to BSD-3-Clause Signed-off-by: Lai Peter Jun Ann --- jclklib/sample/Makefile | 8 ++++---- jclklib/sample/jclk_test.cpp | 8 ++++---- jclklib/sample/run_jclk_test.sh | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/jclklib/sample/Makefile b/jclklib/sample/Makefile index d4addb62..a46b8857 100644 --- a/jclklib/sample/Makefile +++ b/jclklib/sample/Makefile @@ -1,11 +1,11 @@ -# SPDX-License-Identifier: LGPL-3.0-or-later -# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: BSD-3-Clause +# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. # # Makefile for jclklib test application # # @author Song Yoong Siang -# @copyright © 2024 Intel Corporation. All rights reserved. -# @license LGPL-3.0-or-later +# @copyright © 2024 Intel Corporation. +# @license BSD-3-Clause # ############################################################################### diff --git a/jclklib/sample/jclk_test.cpp b/jclklib/sample/jclk_test.cpp index eb663e3c..e72b6202 100644 --- a/jclklib/sample/jclk_test.cpp +++ b/jclklib/sample/jclk_test.cpp @@ -1,14 +1,14 @@ /* - * SPDX-License-Identifier: LGPL-3.0-or-later - * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. */ /** @file jclk_test.cpp * @brief Test jclk client code * * @author Christopher Hall - * @copyright © 2024 Intel Corporation. All rights reserved. - * @license LGPL-3.0-or-later + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause * * @note This is a sample code, not a product! You should use it as a reference. * You can compile it with: g++ -Wall jclk_test.cpp -o jclk_test -ljclk diff --git a/jclklib/sample/run_jclk_test.sh b/jclklib/sample/run_jclk_test.sh index 67b11cce..0481a1d2 100755 --- a/jclklib/sample/run_jclk_test.sh +++ b/jclklib/sample/run_jclk_test.sh @@ -1,10 +1,10 @@ #!/bin/bash -# SPDX-License-Identifier: LGPL-3.0-or-later -# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: BSD-3-Clause +# SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. # # @author Christopher Hall -# @copyright © 2024 Intel Corporation. All rights reserved. -# @license LGPL-3.0-or-later +# @copyright © 2024 Intel Corporation. +# @license BSD-3-Clause # ############################################################################### From 3a2cae6556308af5310658a7666f233bd64de4a6 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Fri, 7 Jun 2024 21:24:37 +0800 Subject: [PATCH 145/151] Implement C Wrapper for jclklib Client API This commit introduces a C wrapper for the jclklib client API. The wrapper provides functions for creating and destroying a client, connecting and disconnecting, subscribing to events, and waiting for status updates. It also defines several structures for managing subscriptions, state, and event counts. This will allow C applications to interact with the jclklib library. Signed-off-by: Song Yoong Siang --- jclklib/.gitignore | 1 + jclklib/client/Makefile | 2 +- jclklib/client/jclklib_client_api_c.cpp | 90 ++++++++ jclklib/client/jclklib_client_api_c.h | 77 +++++++ jclklib/sample/Makefile | 13 +- jclklib/sample/jclk_c_test.c | 281 ++++++++++++++++++++++++ jclklib/sample/jclk_test.cpp | 2 +- jclklib/sample/run_jclk_c_test.sh | 14 ++ 8 files changed, 476 insertions(+), 4 deletions(-) create mode 100644 jclklib/client/jclklib_client_api_c.cpp create mode 100644 jclklib/client/jclklib_client_api_c.h create mode 100644 jclklib/sample/jclk_c_test.c create mode 100755 jclklib/sample/run_jclk_c_test.sh diff --git a/jclklib/.gitignore b/jclklib/.gitignore index 07f14a29..ec349da1 100644 --- a/jclklib/.gitignore +++ b/jclklib/.gitignore @@ -8,4 +8,5 @@ ############################################################################### sample/jclk_test +sample/jclk_c_test proxy/jclklib_proxy diff --git a/jclklib/client/Makefile b/jclklib/client/Makefile index 4da93119..ab6e88c6 100644 --- a/jclklib/client/Makefile +++ b/jclklib/client/Makefile @@ -15,7 +15,7 @@ JCLKLIB_TOPLEVEL_DIR = $(JCLKLIB_CLIENT_DIR)/.. JCLKLIB_COMMON_DIR = $(JCLKLIB_TOPLEVEL_DIR)/common LIBS = pthread rt rtpi LIBS_FLAGS = $(foreach lib,$(LIBS),-l$(lib)) -OBJ = jclk_init msgq_tport message null_tport transport msgq_tport notification_msg connect_msg jclk_client_state subscribe_msg +OBJ = jclk_init msgq_tport message null_tport transport msgq_tport notification_msg connect_msg jclk_client_state subscribe_msg jclklib_client_api_c COMMON_OBJ = print sighandler transport msgq_tport message connect_msg subscribe_msg notification_msg jclklib_import OBJ_FILES = $(foreach f,$(OBJ),$(f).o) DEPENDS = $(foreach f,$(OBJ),$(f).d) diff --git a/jclklib/client/jclklib_client_api_c.cpp b/jclklib/client/jclklib_client_api_c.cpp new file mode 100644 index 00000000..72587d97 --- /dev/null +++ b/jclklib/client/jclklib_client_api_c.cpp @@ -0,0 +1,90 @@ +/* + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. + */ + +/** @file jclklib_client_api_c.cpp + * @brief Client utilities to setup and cleanup the library. + * + * @author Song Yoong Siang + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause + * + */ + +#include +#include + +jcl_c_client_ptr jcl_c_client_create() { + return new JClkLibClient::JClkLibClientApi(); +} + +void jcl_c_client_destroy(jcl_c_client_ptr client_ptr) { + delete static_cast(client_ptr); +} + +bool jcl_c_connect(jcl_c_client_ptr client_ptr) { + return static_cast(client_ptr)->jcl_connect(); +} + +bool jcl_c_disconnect(jcl_c_client_ptr client_ptr) { + return static_cast(client_ptr)->jcl_disconnect(); +} + +bool jcl_c_subscribe(jcl_c_client_ptr client_ptr, + struct jcl_c_subscription sub, + struct jcl_c_state *current_state) { + JClkLibCommon::jcl_subscription newsub = {}; + JClkLibClient::jcl_state state = {}; + bool ret; + + newsub.get_event().writeEvent(sub.event, sizeof(sub.event)); + newsub.get_value().setValue(gm_offset, sub.value[gm_offset].upper, + sub.value[gm_offset].lower); + newsub.get_composite_event().writeEvent(sub.composite_event, + sizeof(sub.composite_event)); + + ret = static_cast(client_ptr)->jcl_subscribe(newsub, state); + if (ret == false) + return ret; + + current_state->as_capable = state.as_capable; + current_state->offset_in_range = state.offset_in_range; + current_state->servo_locked = state.servo_locked; + current_state->gm_changed = state.gm_changed; + current_state->composite_event = state.composite_event; + + std::copy(std::begin(state.gm_identity), std::end(state.gm_identity), + std::begin(current_state->gm_identity)); + + return ret; +} + +int jcl_c_status_wait(jcl_c_client_ptr client_ptr, int timeout, + struct jcl_c_state *current_state, + struct jcl_c_event_count *event_count) { + JClkLibClient::jcl_state_event_count eventCount = {}; + JClkLibClient::jcl_state state = {}; + int ret; + + ret = static_cast(client_ptr)->jcl_status_wait(timeout, state, eventCount); + if (ret <= 0) + return ret; + + current_state->as_capable = state.as_capable; + current_state->offset_in_range = state.offset_in_range; + current_state->servo_locked = state.servo_locked; + current_state->gm_changed = state.gm_changed; + current_state->composite_event = state.composite_event; + + std::copy(std::begin(state.gm_identity), std::end(state.gm_identity), + std::begin(current_state->gm_identity)); + + event_count->as_capable_event_count = eventCount.as_capable_event_count; + event_count->composite_event_count = eventCount.composite_event_count; + event_count->gm_changed_event_count = eventCount.gm_changed_event_count; + event_count->offset_in_range_event_count = eventCount.offset_in_range_event_count; + event_count->servo_locked_event_count = eventCount.servo_locked_event_count; + + return ret; +} diff --git a/jclklib/client/jclklib_client_api_c.h b/jclklib/client/jclklib_client_api_c.h new file mode 100644 index 00000000..e1406619 --- /dev/null +++ b/jclklib/client/jclklib_client_api_c.h @@ -0,0 +1,77 @@ +/* + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. + */ + +/** @file jclklib_client_api_c.h + * @brief Client utilities to setup and cleanup the library. + * + * @author Song Yoong Siang + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause + * + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +enum event_type { + gmOffsetEvent, + servoLockedEvent, + asCapableEvent, + gmChangedEvent, + eventLast +}; + +enum value_type { + gm_offset, + value_last +}; + +struct value { + int32_t upper; + int32_t lower; +}; + +struct jcl_c_subscription { + uint32_t event[1]; + struct value value[value_last]; + uint32_t composite_event[1]; +}; + +struct jcl_c_state { + uint8_t gm_identity[8]; + bool as_capable; + bool offset_in_range; + bool servo_locked; + bool gm_changed; + bool composite_event; +}; + +struct jcl_c_event_count { + uint64_t offset_in_range_event_count; + uint64_t gm_changed_event_count; + uint64_t as_capable_event_count; + uint64_t servo_locked_event_count; + uint64_t composite_event_count; +}; + +typedef void* jcl_c_client_ptr; + +jcl_c_client_ptr jcl_c_client_create(); +void jcl_c_client_destroy(jcl_c_client_ptr client_ptr); + +bool jcl_c_connect(jcl_c_client_ptr client_ptr); +bool jcl_c_disconnect(jcl_c_client_ptr client_ptr); +bool jcl_c_subscribe(jcl_c_client_ptr client_ptr, + struct jcl_c_subscription sub, struct jcl_c_state *current_state); +int jcl_c_status_wait(jcl_c_client_ptr client_ptr, int timeout, + struct jcl_c_state *current_state, struct jcl_c_event_count *event_count); + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/jclklib/sample/Makefile b/jclklib/sample/Makefile index a46b8857..5dfeafeb 100644 --- a/jclklib/sample/Makefile +++ b/jclklib/sample/Makefile @@ -10,26 +10,35 @@ ############################################################################### # Variables +CC = gcc +CFLAGS = -Wall CXX = g++ CXXFLAGS = -Wall INCLUDES = -I$(shell pwd)/.. LDFLAGS = -L$(shell pwd)/../client LDLIBS = -ljclk TARGET = jclk_test +CTARGET = jclk_c_test # Default target -all: $(TARGET) +all: $(TARGET) $(CTARGET) # Linking $(TARGET): $(TARGET).o $(CXX) $(LDFLAGS) $^ -o $@ $(LDLIBS) +$(CTARGET): $(CTARGET).o + $(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS) + # Compiling $(TARGET).o: $(TARGET).cpp $(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@ +$(CTARGET).o: $(CTARGET).c + $(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@ + # Cleaning clean: - rm -f $(TARGET) $(TARGET).o + rm -f $(TARGET) $(TARGET).o $(CTARGET) $(CTARGET).o .PHONY: all clean diff --git a/jclklib/sample/jclk_c_test.c b/jclklib/sample/jclk_c_test.c new file mode 100644 index 00000000..68376ec7 --- /dev/null +++ b/jclklib/sample/jclk_c_test.c @@ -0,0 +1,281 @@ +/* + * SPDX-License-Identifier: BSD-3-Clause + * SPDX-FileCopyrightText: Copyright © 2024 Intel Corporation. + */ + +/** @file jclk_test.c + * @brief Test jclk client c wrapper code + * + * @author Christopher Hall + * @copyright © 2024 Intel Corporation. + * @license BSD-3-Clause + * + * @note This is a sample code, not a product! You should use it as a reference. + * You can compile it with: gcc -Wall jclk_test.c -o jclk_test -ljclk + * or use the Makefile file. + * + */ + +#include +#include +#include +#include + +#include + +double getMonotonicTime() { + struct timespec time_spec; + + if (clock_gettime(CLOCK_MONOTONIC, &time_spec) == -1) { + printf("clock_gettime failed"); + return -1; + } + + double seconds = time_spec.tv_sec; + double nanoseconds = time_spec.tv_nsec / 1e9; + + return seconds + nanoseconds; +} + +int main(int argc, char *argv[]) +{ + struct jcl_c_event_count event_count = {}; + struct jcl_c_subscription subscription = {}; + struct jcl_c_state state = {}; + jcl_c_client_ptr client_ptr; + int ret = EXIT_SUCCESS; + int idle_time = 1; + int timeout = 10; + int retval; + int opt; + + subscription.event[0] = ((1< +# @copyright © 2024 Intel Corporation. +# @license BSD-3-Clause +# +############################################################################### + +SCRIPT_PATH="$(dirname "$0")" +TEST_PATH="${SCRIPT_PATH}/../client" + +LD_LIBRARY_PATH=$TEST_PATH chrt -f 99 $SCRIPT_PATH/jclk_c_test "$@" From 98b9c6539e5cbe9799c282f13f44da35332827a6 Mon Sep 17 00:00:00 2001 From: Song Yoong Siang Date: Fri, 7 Jun 2024 23:43:35 +0800 Subject: [PATCH 146/151] jclklib: Add local library path into script for rtpi library. Signed-off-by: Song Yoong Siang --- jclklib/sample/run_jclk_c_test.sh | 2 +- jclklib/sample/run_jclk_test.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jclklib/sample/run_jclk_c_test.sh b/jclklib/sample/run_jclk_c_test.sh index a0ea9b61..13a20e09 100755 --- a/jclklib/sample/run_jclk_c_test.sh +++ b/jclklib/sample/run_jclk_c_test.sh @@ -9,6 +9,6 @@ ############################################################################### SCRIPT_PATH="$(dirname "$0")" -TEST_PATH="${SCRIPT_PATH}/../client" +TEST_PATH="${SCRIPT_PATH}/../client:/usr/local/lib/" LD_LIBRARY_PATH=$TEST_PATH chrt -f 99 $SCRIPT_PATH/jclk_c_test "$@" diff --git a/jclklib/sample/run_jclk_test.sh b/jclklib/sample/run_jclk_test.sh index 0481a1d2..a27b695e 100755 --- a/jclklib/sample/run_jclk_test.sh +++ b/jclklib/sample/run_jclk_test.sh @@ -9,6 +9,6 @@ ############################################################################### SCRIPT_PATH="$(dirname "$0")" -TEST_PATH="${SCRIPT_PATH}/../client" +TEST_PATH="${SCRIPT_PATH}/../client:/usr/local/lib/" LD_LIBRARY_PATH=$TEST_PATH chrt -f 99 $SCRIPT_PATH/jclk_test "$@" From 18f0a0b929d08840d5045b9e6d8d57087ab83315 Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Wed, 12 Jun 2024 11:08:28 +0800 Subject: [PATCH 147/151] jclklib: fix gmOffsetEvent not triggered and incorrect status Signed-off-by: Lai Peter Jun Ann --- jclklib/client/notification_msg.cpp | 44 +++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/jclklib/client/notification_msg.cpp b/jclklib/client/notification_msg.cpp index 2417a247..7a6f81ee 100644 --- a/jclklib/client/notification_msg.cpp +++ b/jclklib/client/notification_msg.cpp @@ -129,6 +129,28 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) return false; } + if ((eventSub[0] & 1<master_offset)) { + client_ptp_data->master_offset = proxy_data.master_offset; + if ((client_ptp_data->master_offset > lower_master_offset) && + (client_ptp_data->master_offset < upper_master_offset)) { + if (!(client_ptp_data->master_offset_in_range)) { + client_ptp_data->master_offset_in_range = true; + client_ptp_data->offset_in_range_event_count.fetch_add(1, std::memory_order_relaxed); + } + } else { + if ((client_ptp_data->master_offset_in_range)) { + client_ptp_data->master_offset_in_range = false; + client_ptp_data->offset_in_range_event_count.fetch_add(1, std::memory_order_relaxed); + } + } + } + + if ((eventSub[0] & 1<servo_locked)) { + client_ptp_data->servo_locked = proxy_data.servo_locked; + client_ptp_data->servo_locked_event_count.fetch_add(1, std::memory_order_relaxed); + } + if ((eventSub[0] & 1<gm_identity, proxy_data.gm_identity, sizeof(proxy_data.gm_identity)) != 0)) { memcpy(client_ptp_data->gm_identity, proxy_data.gm_identity, sizeof(proxy_data.gm_identity)); @@ -138,22 +160,16 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) jclCurrentState.gm_changed = false; } + if ((eventSub[0] & 1<as_capable)) { + client_ptp_data->as_capable = proxy_data.as_capable; + client_ptp_data->as_capable_event_count.fetch_add(1, std::memory_order_relaxed); + } + if (composite_eventSub[0]) { old_composite_event = composite_client_ptp_data->composite_event; composite_client_ptp_data->composite_event = true; } - handleEventUpdate(eventSub[0], servoLockedEvent, client_ptp_data->servo_locked, - proxy_data.servo_locked, client_ptp_data->servo_locked_event_count, - composite_client_ptp_data->composite_event); - handleEventUpdate(eventSub[0], asCapableEvent, client_ptp_data->as_capable, - proxy_data.as_capable, client_ptp_data->as_capable_event_count, - composite_client_ptp_data->composite_event); - - handleGmOffsetEvent(eventSub[0], gmOffsetEvent, client_ptp_data->master_offset, - proxy_data.master_offset, client_ptp_data->offset_in_range_event_count, - client_ptp_data->master_offset_in_range, lower_master_offset, upper_master_offset); - if (composite_eventSub[0] & 1<master_offset = proxy_data.master_offset; if ((composite_client_ptp_data->master_offset > lower_master_offset) && @@ -164,6 +180,12 @@ PROCESS_MESSAGE_TYPE(ClientNotificationMessage::processMessage) } } + if (composite_eventSub[0] & 1<composite_event &= proxy_data.servo_locked; + + if (composite_eventSub[0] & 1<composite_event &= proxy_data.as_capable; + if (composite_eventSub[0] && (old_composite_event != composite_client_ptp_data->composite_event)) client_ptp_data->composite_event_count.fetch_add(1, std::memory_order_relaxed); From b682ade94e084bfd53dc485246ddb10b0537e97b Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Tue, 18 Jun 2024 09:57:00 +0800 Subject: [PATCH 148/151] jclklib: Update md file Signed-off-by: Lai Peter Jun Ann --- jclklib/TEST_jclklib.md | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/jclklib/TEST_jclklib.md b/jclklib/TEST_jclklib.md index 23ac041f..86fd2802 100644 --- a/jclklib/TEST_jclklib.md +++ b/jclklib/TEST_jclklib.md @@ -90,9 +90,10 @@ reference. make ``` -3. Outcome : you must have 1 binary created: +3. Outcome : you must have 2 binary created: ```bash jclk_test + jclk_c_test ``` # How to test : @@ -109,10 +110,16 @@ reference. sudo ./run_proxy.sh ``` -3. Run the sample application +3. Run the cpp sample application ```bash cd libptpmgmt_iaclocklib/jclklib/client sudo ./run_jclk_test.sh + + ``` +4. Run the c sample application + ```bash + cd libptpmgmt_iaclocklib/jclklib/client + sudo ./run_jclk_c_test.sh ``` Usage of sample application (jclk_test) : @@ -166,3 +173,12 @@ Lower Master Offset: -100000 ns +-------------------+--------------------+ ``` + +Note : +```bash +In the absence of a Grandmaster (GM), the master offset defaults to 0, which +it's anticipated that the offset_in_range event will be TRUE. Consequently, +the servo_locked event is used to ensure that the offset_in_range event +indicates either a high-quality clock synchronization (in-sync) or that the +master has been terminated (out-of-sync). +``` From 5abc72860844573c65a62d3683b795fbdb4f620d Mon Sep 17 00:00:00 2001 From: JunAnnLaiIntel Date: Thu, 27 Jun 2024 11:05:34 +0800 Subject: [PATCH 149/151] Update README.md --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a6c640cd..3b7a1fe3 100644 --- a/README.md +++ b/README.md @@ -153,12 +153,14 @@ The project more documents # Licence The Licence of this project is - * The library is under LGPL v3 or later. + * The libptpmgmt library is under LGPL v3 or later. + * The clock manager library is under BSD-3-Clause. * The pmc and phc_ctl tools and the testing scripts are under GPL v3 or later. * Documentation is under under GFDL v1.3 or later without invariants sections. # Disclaimer -This project is under development. All source code and features on the main branch are for the purpose of testing or evaluation and not production ready. +This project is under development. All source code and features on the main branch is for the purpose of testing or evaluation and not production ready. +We will upstream the code into https://github.com/erezgeva/libptpmgmt/ and archive this GitHub repo thereafter (making it Read-only). # Coverity Scan From 9be0730973ec1fa6ddbb76169b4c8afb1bbabe4c Mon Sep 17 00:00:00 2001 From: Lai Peter Jun Ann Date: Thu, 27 Jun 2024 13:41:57 +0800 Subject: [PATCH 150/151] jclklib: Add high level design of Clock Manager Library diagram Signed-off-by: Lai Peter Jun Ann --- jclklib/README_jclklib.md | 9 +-------- jclklib/image/hld_clock_mgr.png | Bin 0 -> 58638 bytes 2 files changed, 1 insertion(+), 8 deletions(-) create mode 100644 jclklib/image/hld_clock_mgr.png diff --git a/jclklib/README_jclklib.md b/jclklib/README_jclklib.md index ab0ae196..d83a0d6f 100644 --- a/jclklib/README_jclklib.md +++ b/jclklib/README_jclklib.md @@ -8,14 +8,7 @@ ptp4l events via pub/sub method using a library api call. It provides a library libjclk.so (aka client-runtime library) and a daemon jclklib_proxy. -In short we have : - FRONT-END MIDDLE-PIPE BACK-END -c/c++ app<-------->libjclk.so<---------->jclklib_proxy<-------->ptp4l - (library call) (using msq) | (via UDS) - | - libptpmgmt.so - -**if the diagram is not lisible, please change to text mode.** +![High Level Design of Clock Manager Library](./image/hld_clock_mgr.png) * **c++ app** - Customer application that will be linking to libjclk.so library. Header file and sample test cpp file will be provided. diff --git a/jclklib/image/hld_clock_mgr.png b/jclklib/image/hld_clock_mgr.png new file mode 100644 index 0000000000000000000000000000000000000000..92cb0dd631c42c1c9f0b35e15db85de031eeb64c GIT binary patch literal 58638 zcmdqJcT`i|*FOjC!=3Xd=BA>Am+B1O)-SOAAQv z9RegIbHnp}-!<==nKl2+{PFv_mdhlbd(XN1?6b?~v-gd9`$mxfp8_8X3yVMrB&Ugm zbq|DvbtmBgF7V6e9(5@254NYK;%hAE2-P<5<({pKnhX|JRs2KbI~?FUo*T%(6ASBc z7v?W^uWN}F7S>w6lAMgTpXuJ>!&V(n6#CeeF>0q+PPs%bUBipgx`++8TaH|NC}9x9 z9knpNR7oK#-~6(GoRpkBZ%dJxL{Q6)#2TN!d5c>sgj+Dx41J2qIhXj}HqyQ{0<-PN ziSHG)-LIPouDn^?MHnope7uo=1gr!LOB%ZdJITyc^q&gjww|nex4*r8o+)T=4huR? zT)|S>-yqB4;xN5{-MRfgwnyA7C&Y(>w_l_?8KnRH8J`B5=-+FP9wgj;2n|yV{r7ex z;&+&Cf685cN{4;>2`3&4@AdX__Fk?#ok?ST=t8~q z;Iq@UWcAGVckibK=?NMKpHFRU7eg*K2EYaKh3;>#)`-VB*Q)UmF_SJKRkPJA)~-Y+ z8AO>l51;)xj-wXKygJ>Scc;@aHj+LVC$OnBZ5tZN7HfM^cz(FF^qEFtE-iL(!D)c+k8kyI*-|b8g?jBhC)}8fSm7_*Y-HGgPYvIiRVoF_S}Tv z11vVF#s+EsWw;oOe6j$i(;|bdhm7HM6P{Pk!5cjGotv|I1O0wcKUb6@{pTr`Wg8=*%qJu3o`2m z@WZ*fK_f;cv+LeS<{yXI!-Hc0wjH{b&fN0 z^rQjoe;QoPCURx&^4knOZ*QR)k-b`T4XU#p%_(A=*lZi%PVJdYmJQxa`nLMpS9i$- zI(5Qmm|WS@0Z{sE?L* z`yvroPcH8FgIYknQT1E&{*uqU^TyePy1K}gCQU*_s#J5&&6HNa+1B4!>-4h5(q`2k zWuNZ|X%(qfEzRB_;PWy%;4{OeMOa&47Vv0+o@81);$@lPC;brJ-2jcLK2^=E2dEu! zYf|ZZ0~`ljZ)u*=MJ2neq;VPPCdnApIp~y9ieYU}HM(2QH~YK24aA4;C%)^7m_6J8 zBJDTIIy(K3b1r^0@SA9o6LNjFO?+YyPc1f0Irs>D?Y$3JmhqUthbfBp zKt#DEC4;$F;AQL-iD1@L@(E%GLFH|5-nYC-2WhACohew#PdN(R_IoN$R$|h54!o%4 zPcG4_R+ zt15TVi9wrp*j+3B@Q;eG#ulcRIX0b{&X8fh!jcvTOeb44+h*HeTHu6}9tk5}9Dx(gNAE(ozc-3Ki3 zdKzCW`^jOk1NKMLDO}LUGP%og?h+Zv)VVt=-n-u$0xY{bAK@sCE5&v+W98jp>`!yL zgGEAfhshcw445CzAF@R|%L@6bdG#h~-L;N#G#{Tz8K~+A zjn>rX)9c+4FL+mFzqBC2&O;E7TP{~}2J-h4HPeNp*00wav6+mP)h2diXL{+?kn>u6 z5Y{zbAMg0?bqWrlsLrOb=BFOIs7jl1RW(?Ux|*PE&V9TNZ3#k%53oBg8!Ct2$j7-% zo1i@~8gStVUw8>vmc#7Hs~IuBBXd^=Cwbxbh!~eU`?<$*`*U@UU=0OlaBmzn95~1l zR#FSU^W+~QLJGbC2Msp&b3)w3gn}@W&w2pmve^95X@VdV3a?>KhPVryZjLUQd3Dux zV2s4Puk2WCN-+3%r5i>xW-kf%-#MMQ)~a%tVsD}OuD(09>sNqi46`sX+D<5Sv;gM2 z2;7}6cUMzUC>pKFKYP9Xd8BTd+(k^8kf;fELQmj{C^^4B!RRcNKK{eai(vQpg72$^ zTt~&3K8!6Xw3s+IOeuXNl8$nGyE%l;0sr<_A`8ZyOPhy6yPPI?oAw>W4Kl7PEXG8r zgk8Sgh<7<_ZR$ZXHpW_yK^I@Qn#X;|3wcG!`io-!%Bf7Grd=+noHtBp%=1q3Y3V&)T=l7^u{}#sLCO6ToWC4CFV9uYYTy+ zT3BCtni=QCN(rAkxD>Dxr@5|JkhB-K1JwGW=IpSA@=Rn~bgYV*Q46AIP)u;V*D@{( z4uCi`?~c~kwHAMp0^zyl$=2SZAD7$-BY+p;32!OV!Lq8g ztr*810exik5zYr`wcVn4SWAyRBn&96K-sxQ0B{}O=@tBYwXW`FW zvj5_mcpeAYYF#}VWFR;#9&P50g@3i;AUK^Ej&lk4xvyR;(@Qx@@DUp2HrOlnD>?3$ z>=Gq9Ai1qaD{;V^GXqtTH+H467Fa+z;y2!DH4-%zRC>qIsVq34%G{#a1g#AtGnR`DhY4&Ag)1Tu-8d z8^4i{=+@n!q7$a>4%!3$&rB1&>zh(N`iRsDRa4^5M@4*~8sfRc*c9cEIPWVT&X;*ONV(yTOKvYgLs54PJq~&K+Y7ruwT(qGy z#I~*#9N75?#D`5(sE0bGr1FBDg%m73Ah_Nm{<~xaqmGb^Zk zT{E>G!QKlFIzI4hw61k^$prsKP=wj1Q7(wYri158gJ_zPgqWHSQQmBeeY!c!v`^@c zBjnn(Q4iT+F?9NqT4WXldGUYqHlt{K-Dtz3Vv9Zwg0_oz8~42=hNGA$qw2T(!i9eY zlogy(tCFPru@89pRQJx4{oa>;IizZD6kZb3?tisfZA2zDp@>ua9ba$$)8UdG<7ag$ z?nr}6*>%z6FJTe$mg`;1I~P=s|x#EanRWitqj(6_=mF+!>FQG+Bno6&?& z=K6E0*UblsDK=lon5yZRpMH6GzbA6wGSvnL2D5iTwCbH3t< zo_SszUld-b4gRtv=TOtj{0o+Xtz0Eu^5b7GgeBo6Y_+yn3$VrN&Xrp}RGf(&DF%}V zrzLI>_M-i5_^CN#EQc>#KX1Jn+(9WptdC?qK~=!p0&SJ{{VoLk|VtkArl3}Tl zx1-*7-hFIV``3;f?L(v#+TG#w@|ad4pjKGVZ|=>}eQBxsjHFmOu}gBhPn-NR9?EOT z!R;OnqT$1ijM&ZV2Z~W&j3TFt&m)q*ub!x!U8^e;RYonJQ@1|FAGq+p0HcmW;DYgd zq{l;9Tei=|QBKA0Iz1td_WF&xvcghTP!7CwCABl-Z9}g?2Pr+X|75j(u|A)I*c|*PmAsp`-Z~6A@N$lg<7P<5q~l+gAUypx2?lC|9nCL{Tw(IWbC7 z7AWWLYYoq{)#VO1Z|t7Ij(C^f%_~jh$>vN_uwPQ-v!L2Kbg5HUN9%}XE$ut->u)l> z=?|DWQM6HZkU*jML8br5N=_=@31W*@b8g+1X8?7Lb6k>ej5)ukp$N)M>1!JB36+C5 zRwFXs^cTomUm0BSTQ;W=6U=P~l5wm)9~HqPqZ;G2Iw=y$5s>&Y!j$#ytWvR~@Nb+- z@9stvTrB^btuOVndB8JQ16aj^mJ!e!XaNBQ(V{Qdu!KGtc>E+^Y$AzwzvUC-Iy+#hxFDpk)iwQNxFvNI z`sWnR^UCF8=FC5z(74Kjtkp|VeO`IrfAyg6QjFR@BQaL2&HB8o^;0eepW_{zhxWzT z@P)fblqtHu?@aJ%&`NGrAE-JQ$ZkDP?Lilc!kKbXvg1Gc!XV%4Gal_{p;=^iC!1Fj z_py{-#!kRXIhg{e)7NcDRcFq#2R`U;${}bf?n7cJ=lsUcmN)aIwfT@s2$21EDU*R7 zUzX=3pDwai(|NXY&G>pV_m{pb*F96eehMrq53cUg*8^AQ3pQh}8i%<3%ubf8JT}j) z5a6bR{vbe)>qNl~~eKNN=taWOKQF?I%1= zfU|n}+#SB?8)z9dCc@R+bZkm`=n4&?Jr}vg=}>Pf;^*WRUiz%s0oB0 z*z_kc!$>Tn`MitR^4Hqfjg(mfFZQfrm|jhUR%@qh!+WBcv!1PY zwHf~_G22ky~NI#lq%wTj;mTn#ZY3t4*`e=MpPsR4^Mvmi4vofrvXRCiCoaRaSP zCu{s5M0u7st66(YDV1k^%DQbKwYN2w%&#pDpdlLw*s}VfNc**NNU;|%P5ukos zYf3Jh^$>jy%L&*ih3T(^spsY0JlXNo3|lXGWh;)1N=l1A^G~00PbD*Ia5?XZ#u+?l!dUtu#!giomZq~VTB@<+ zp1^~q-oVsAWTB^*^EQh(4QiZm;4JBiGi?{{F^h`rPel|Pqm54hXDQ{Zb_VB%0M7z9 znW>U$Q)L;=TMu7~JPBnNB41Ol2*>l}M6H|~65=^ngy9v8*fyFQh|9k0{FHimtpeU+ z;n8go&g=yfQ+_WoG@#M*fAaaa;MT6^7dyz~yuDk8C@hAb#*5xKp z?{MdsBJF-GDfpo2dC&vNZv-I_4-JD5-OlY<`~*7)vh!&$oP?_Xyf|o13N0w)v#0OM z$(M?MbU$%0FP2PkbFt2QllJ6qU{Z+}wWAQ&vJuSQfwXtzM)_=b%q8@TtC*fP{K-_| zo874fw}sdI8Lqq@j8pt!z3QTL5l=lTsj#vXB0Ab;#v)~Tu6SVPD;lZKB~i}NokzQq zbQR-r-Rk@E^sqc_;v_L;-Mw&kE}CWH`}cC+d+2M%7lWsqz~d4CAPdVs7gTwtDW7kx z?a^7wUo&tuBocBl)-mE|SPMT?)aY5t$`t9;JzU*xqbDY6Qo!t!iUi$FVNkjstSC)=_8&ihX;D_H&q3m^DP7*1oP80=QTlVX}B&xN6&!_YPE2AMul3@E*y-#{9jD1yxv(v;c>oQhLT)b-8 zsyf!~xX8ZKIAeBo+4Uu_;mvBbrw%xj}{J9 zU=;G|1)<|~Mbz%;5t)eA(`Arw5qsM9=o*WmHrIS_>gd_csqljt-uD4J*6ukvR(?QY z=abR1$$KDRdj}@rd^Bas z1!rAo{}&~hyO4}=3GiHn0JCO~Zbv!PAv}&hIksk}S)-0QTNZrm;f|;Xtsie$PKa4r zx2yKAu)d<~y3x8y**`S$2T@k1+V*pxR+yR!*g9Xl_?b_iE&mg_%hfF1R$4`Bvc^1U zFaC^FO!Mg*^aU~;HW3irF8yvP-j-4(>cEl-b<-#3F5bUpTj6~*W8#&+)s`#)KyTc$ zAsQ=NY6OKA87?%#v?{>vHbcML@%gKjY`L`Vj(pr@1?g03*YX-?jzdja8ly#6uE~=k zK9X@hqbaA577yFyY(Bn#MX7d}xr78in_Wf+2~-%?4Fs|V{;T1dypHG~;T*WdSGuJn9o5t4@zx@tHh?{!y z-FJUK8EqQ9sIoZ~F5(2wOq~0(Fy7{ow>n-axdzQ6{1oyO@J(?X zW;iW89M|uTdn^V&o>s6Du*VsD)mTy*Ym5G6%d1Rc+E$==W_l!EuzLMK7pH%!c%=C; z@=Q)RJr&UDz52=E^y*SD8YQ&oR!bN#XOLECWTD}W1HRrkEbP%xdR{0I*WteFMJeiK z*Qcem4;g=_^YQG^)<0q2l5243`2l2r5Pjo)L@`isk|K1e5^lvlnxqbB@+WT2nd)Yj z92-CR_0%ej9!@{mLY~?pLIBVOgw4Jdfg3gWOU*s+7P+J@fov61ilgJ(!6=Z&-^P=~ zk>rlP+-NZc#M9yP(+b+6?ijMjz2a!5V*b0p;~20&3DKh3d*XUAP7q(1KTMw&O`yfi zJ~+y*H=a0_uNZmngSYIVYZv{@y>gQ+Up{>=i9dC&MeRJ-`xo$}e1=mDK8nzXSt0am zZYYyEmJ|yh=$c0%BN>{oaa^z%)A5?YfcJSO!#xn+FSL~`UULi+yJh|-IDmO-xAoh2 zoS8}CXF?CU!ldv)UvuOxiA&X`ZYC)QbC%VNe%uR3d$$VvHMtpIfiyxo^zi~EzuGR| z+fo?k$=-hm1TfE9v9rW{p~7k6Xj?MQ!bBA>uFDB_oOOmNy%8KBhQXOQ^TK^e{H<0s zLml1pd$^K%Oc|BncmX^z)2Md=EytIuDQ$n$p;xDAkoB<~v2y8K%!CF|3s;x6^ z3xMg{q&C#bVAG%v4Qj<>HYSkk*DuaFOl1C%0OKV6KV-)1-7YO z*+B$k=$?xGTBdnGp~XqSN=gi1L^KUo(IL35uWFPwrDcfFs5OsKp#jeF#^zP@0tuD- zjFDSAfE7*?jfQ^?O5Mk#w~yfJO@p*{pcE;6_Su2P^xj(fMIh%;2xXE*nqAxmA+kbO z9se|E;Irh-KH0l7$ovxZLGcg~Q{SERus4;*D=u8VUuQv_=E^O{d;gLj+$lt;DMRth zq++Ec>L}f9+%|L9JFpIXU|+cv_>8kK6(6l;APU&^_0iVyH6;UFCa=4d49g)+3pKGF znXx4*X2BsSXz-M0ELvD-F^pUo96(99Ul|dEQT!N;tUZ#)bFIp6uFCy)GIi_=oY>;+ zWm!%*ucEP(A}%59+YunMps8=ebv&~E&yaa7S>;anl8YXAO=zV&7~EFKqW|OSzMS0MGEQ#_a_Q;^z}oKHEl^oHlmpAA&|DrKr?g*5Evd4{ z+lPnD-!NBnts9($p}oErzQUC&)7j$m#HAb?^$|}#Ws9H6t5iV~+D-)`oo0sF9ie7amXNcd zCN+0R@TiBnmH_TqrT12otQnU8` zM&20G(PX8Di`c)Y^mY4s^G2oj9wNuI-YH|Bb*`gLE+UVoWxvL3lfm>~&js3Sf)B3Q z?tR#`G=uabuTI-UER0(Hs&1&x{6A9)k7Q9u?T4d9*_sUqXUWUM5CkOo3{4 zBEv>0?`nEi%_1XEH;6z_7M85d+3y`}j1AzaG9B1tpUr3vwMWHq5KB}@M8Uf;XIQI0 z7@$C8>kEUY&-A1DX6Og)K?1>Jhv`PTGxqh{2#u6}JP}-iW*e^&-@QM7hskqbv_ek$ ze;hgIeCaYA3jpOI=eJ2QYzGi^jfs%9V$anj+qO8SG0(hn1UN>3ZC|ND8@%Zq`$1(w zkS$m_Wt_1gsC6l0*;Tp%p|G!)%%b)>Ey~w`HN#Py3SGY{0{<6d=-)VOPKJ*1lb43v zUrii3zDmbSe%lf71f6xGSx6%o#D7W)UE% zgQ!QxHb>(CKIJM#994Qx%95F4Zqq8lPRi+;{vk^NMeSE2?VHA?^>eeXlowii@n(5Z zW=z*e!F}@gK&|wNl-Y7T%E2N?yiz_-?r+}Vd}4F= z(YfA{E&iV`&ia&Q$a*^#Rjs*GzMZJV1-FPnF@;6pdD4xS) zMpt0FnZ;|O@=&FM_0RD@kN-4rvfJP=my9k(-a0Ep%H#OAf>gu$&a+EXT-x5+h4+kJu;e= z@K0R%vo|H#=8}8mBK&fwm;#9_hw7(kM`Hs8I$0B&S;py&dQ+i}9BEdSc-iXI@h(L~ zH&ve%g+^-l%#L9{wpm{9#ul%AO761-QKUW3rVOS*?e|bvkTS+~gFOpJ%PO|@z3x(T zrap209pacF7uH>B%4mITAfgOek&wz%w|_0ZZNR=Mw?v5cNv&tPHi>64fqN)}7eqCi zrjrR0KJo3MZaxXH4Qt`uE9T^vaiOLl0uJ7*>FVp)V~$$^T>nP^9YU#i>Kk(^a?Mil zL8_D%8c%wi6~j%*?vN3e=1SFNnK{*0_%&@^dd5)jc`mY%-jrnIeVB|ZRwj^X(v6RC z30OI}k|Ee>)Qyhe9w=#hSHdeiBcZAB+9BEnmE@qR8vCU5z0i!G;TTz;&|6X^2E_AN ziUH49-NMs_`}UL$NY*LbYNA=iY!$&2_=wnH%2$qTTQweKti9blxuLKA8yOeK?!e$* zc|CE+MHLp0{cgsIe97WLcf5+uQm= zDeU4jDm$hYIKC9`Wz0AWxR3=OleusE&0ebWGd|uSE2%poW8MY9PpN%16#7u=kzNaf z+kd=1Ck@y_YmLI05ZUhVgl4F>F~y8+vEwfj9+YP>+$4PN7U_#QP8A)oz$_{ev(04Ek|sMJz17_X3Zw5?&yCu$oi~tB^~j z<pVP~c+qk%U-=F0AuNhm6%ZD?j(K{+M@Y- zr(DJGMO-@f@AhCs1k$d=+65htk7aeo{y7$%)@3ZVM{;{4zM<$x{WgWIZWdYOceH33 z*=)WdA?4z<-w!eVDfsx&5dUb(^|xFd7pz&i|DG`)R(M8D9DHBzyP;C)+-Mq!zbP@ZHV5QqGxUYGNF|-SNFkP@==DeZM~_|*W{Z0B-M#-m31f=?u%1N4 zM7<4TiqZBc0Fd^3iU}HGz6Z53jR0B^poJNLRfYNQ2trzya%s@|KV>IjM8DBF81ebaS3Uh!tr#< zw5wz{N3w@23~E|MFe9+oXdfidRR9GJSvJF&8HtRFnTB-^8II7V9^^$shu}jp?pkIZ z)1YH{*EhH0PiV1;KAiu2$n%A#13B)sKR3l`R6its@y8NFvIsyzu1mLJZ7srNx1-mA zr%uT$6NFL>SAuUG5lbS#z+p4g37O}1VfugetPgw-^j5h$nshjdHOH=33bDtJkOJzW z>OVMFT5XRP!l>>yDrnOBEo0Zb>%#TyrS?tX^qjLV&d@2>oxM8Cnf?oFIcVM;B9ua! zFL@$&HO+fFpcH}*UtVYx`FZvnX8XeMW}(ykK#88_Jf_eTD~0wR=t)}H^rtzxC{nA- z<#0k(pu%XsbvR47VLugllHO6fpZe8vMC4sK)5$0pHBsw4Kdt)ZWheKeH)jM`wJxh~ddJFq@|lMHddavHfQ^?69^#cqX?=^B?Ix zphnUukh!w;B$^y3V=*y(pX@d{5*5Y(IM~`jLgJEGTyg_i^X zS$)0gl|sFXq(e8esAXEst7Hhf<^-#ErtQx+%pconQ&=zm^S($v<{9(uSp5ueIj@k>K z9&+0+0D%-(sjNk3vGOab{zF8GLp(=Q9y%PCpn6ra$-|oRq@HZY*^+_4mb)$fUPvYvwLNM~L-bVU$29}2PefBQRY3#mIyFElSr^DAkN z6N@kweTKP8dgBS5%BOjO62zeSn2>3S?lP_2|SQ^V4GVB={9a&d=f`#>j4vWEX`o40Ku~ zRNGVK>EH1QnH+$Wwg{kJgyJJDFbWt=%Hj0SH|13JBJ07ljlG&tp-9@0M*p)hMHS_k zlCr2>e+6cqTaya#0$G$Ujh&O_dZQy*TJA6UFeK2zfT^gQ^BEi{ie) zS~UTs(4Qodo$;B}I~wM4GRcZG{sr3q$efmb(-p1^Xe9@*msq>?8f`F><@4;;9maki@Ie@%gs94 zXB*ua_v3HJX#$7s_QU_B_B-@Wt?QB`#&F)+Xy5<`Y7stv<(7NZ%@gu2Dp8#rS6u)cE@(a zftV*yRi7D7DEVgyBDEBF|6}OCVHL@bo>na8qSZ;qaoi~z~%Xbg6?;=m-4CC|JrE6@4 z`E0Yj)9h!f3$Lz5!7dofa=7?5%0(>oCdO6*MEGx!{o7^kmOVa9ka)Th!xNyTto3^Z zZ~|4#GTIUwyOkY6qmqbId=? zH#4a28kz#a|7?p}Du-S@`60kiefYkUC*2EB<@@4g+>C}cfO&lv{va;RsLJA_J*>4! zn7P@nKA&9-pIaPtxyt;WH1%R@rV>J(j`8dFX@h>_k^$uomc^wcF?XaB=bmZMZ5B)2 zlv2yd>Rs2pjisktj!|gg-&CI$(DcV#o1!$zSka5V> z`o2t<1)Fs>pZ+7ZBd*wwo% zIsgf&xT`YncUI$h2JYwXsH@HN6fX_)B49K9 zW0`9O$P7P?)ZJhrt7`cvWfy>&{1D(;YSL0)s{1_?UMBEet58upnu!#(k35B-Ytfdo zHMa30!0A>wk*9bgd1Y1Ox%tL5?(XE9=%RA%NH9u~Hh5Ck+5Nv}_LTt90y8I+Z*Iyt z=(DAN^%_@ty316QJQ5qd)4d}sZiKiCOuj~>^Y<+wH{h?}MRLXCGfN?e@4)OcX}#%Y zA>>sl^)#C7ub%98LcwCdR_EQ&suU`xD$l_mJceG!H6oKQ_+LThq%;sOxYbEV>nG~K z$I$!RvY`c39^K=UCTZn6(A`K^bn|KZ<~#ZGBOg?cPIPj~_$voWR35uGVhs=YUKO~>PL35F{gzTBl(29_{EW|XZgt}=jwkpQc z*vwX2!&2@}xoYEdr=Go)&7U#$jCEG*5)`0_a}28WJ%rIq)Uv%AFW2Lt{Q9L&tbI=qq zI5-UT3N90u3OdaAl@YOXm6w#3ql7Eu`6@V1Kk1DA>PkP>>C zU#)BvmT1EKpyRTeXQ*j2#}VeYN*y1vTDD+Fp?hJg9Uw>Uss|nsj4mJ|Mxk25P5u7jP?Eeo^BFHt!ek1y z8NTj`0I`!6m3~J8Kdyw-7KgqT)k_mN zO)jhmv6DR30Hv!XcfnypX1LD~ot>-?cGXjHm6<)S@GKr@g*uj+bBreq@g2XdqpKUL z(4-kN?7GkrW5UN;1cF+h=aNBwO6b3((Y9dY-%PMmlJX8e%wtIVJf(Y~X#C=SUDV$@ zI24okwY&Ta=S$R;`a0@Am2AkRaF}!}^xw_nYJ`Kv8Wk)6YRYaN{Z@&90Lqo(1+oGQ z&|+>whkio$f_0LvgyJbF4#+t79|9=-Si@3?*tdF_pXVb)Dtv>Nr6kIL>N_JCM4@&E zEr*ixIgw>mCC*QDJjafJ?JM{mt;T@Jzrx%O>najUN#qz9HOJ1pBhiC{hwKtw3QBgH zr-M2~2{=slq2ie{tiy~2sRb>XZH6ga9qe6<%C7Si-f3|)5h+#NjD<9gi}lm+V{Vq~ z1U%z?V_cK>VW%TvqgfQn8A0bZjDO2!?XGep0wV;TH=B3fnTJLy+m>|f-zv~UpU>p{ zMcRx-KsQmep|bp@CGzt4-8@~C@FmgONOnLOo{N}CFGf$9RH%ipKx#k>AHXy9Rj8h8 zK^OCbHm4V*-yt{sG61b~rR6T(63bQ2r6qREr;>!j)Rky2u3lY^QP zgBqL3QBLwR+s8n}{2WLTEX6pmG&O*HssA>}SKK}T|_qfPrfRj!`65~d`?3gm!{DL6(uy>T{scH(bb)L#fMF7%oss9s&vi_QH8_BjoO< z&heZre*$0#jJ9CC{ZG@RbdF{!9Fr;UARj%7dbA^QhSAddOtf=!{R}1_-au<*!cHQE zFddWl;bDwBFR?(~67U5}u>v-$TFi2=u>73>wShfPXf1|>%u(KD233C|V(P45gmvaC!QAlwwKKEe za}c0Ru;;gf*&G4Ls07Hw0X&HojI0vIEf@vhsy1Frc0K4`EXFNiS|k|kTgLwRk;~c0;~6J29w@C8Cd~W@GBw%J{eqJ;kqh&WrDANlETXW_#DpKW||7~ z9a!VO`D$5a>SgwaK5@TDB@Y3yj|wpbsRD<>LAc|OlfiMdFkVJ=z`4T&0BHavtuC(k z2_iMNqe9tYz89vzI&xb}-+l`dwi)uRTsVwnRvSxtn>-@nwDVtm z?upjf%uo>(fEOvGZ}H(La2hxDwDRtWdj6rmAE*^;(Bd6w4@SJ2_+}8yZ@s(@n;cTv z_`?4pag^g3PWD&8Sq55u?C+LilSz_S%M{?n6!n^7XH0Z}!M8fbCcHyy($)HE3!mS2 z+cqUfy5|X9e>El{WmHM4zuR;(l?fb8+$fC)lghf)=0KgiGCw2j0(+4lQ_8>o_xFW1;go ziXQ1UDgpoFIR!}Z$07d*S^(WrIKrSlFPhGy^oDDE;k8pfIgN!aO(8=nHVAZxD@tUW z+jBu9GOPHoafp**YDV|H25vjLQExabF?bKjf%aF38lRdH`7q8`~)ErOiG`4$(qH{Q zN?jv|4$FRi&c4#Cxyd@*uk~^W2;w@u>e=6jTnw~u0dM-Y3{}nv3cB*3_4?cGGBUtM z_9JKm%hP0hQldF@uoMbHesjX$={ov`c|TDbsy(LKdNZ!614f>HMNI?<{T8t4VW9jI zwb@$A6n%#$eraKt%HNMvEPmQ^P`=~GYTu(fOno8^i#|pm+4^9_#d!~~U@R-ce9QQg zp3kKw`I)6YcFc!5CD!N#yZVF6k+1VbiNb~Y*_mkT$56ingQH_ISjx~RTSR)cd$dU2 z+&5;#iW$q;&C-t>%F_m&-Pa@Wb|~{FFJ6r*^-c<)^&6&;mN(Ol^(|MsXu&}Ejh$$Y zM;P3t>fyZLc~1h~Jy3$yGfsVTpgMfJjlCX|d;*Qn0hO3ltwl=={959bEZ~Z@nTfA1 z6y|$3b?v-S(5yHY`r+4HyRx4b!oMcTK?t=Ym=t$Ih@1FWi?c3dp^zw}&+u#q)3}5{7z0Wt zTq|A$6=_zO`mvvE_47U?#2#jR(M0anPk!OuIzJOsW^;NJ^Khu6V^K%bnR)ESH?}>b z{x1iR73xH4WU)afKT+5RTW;I>EF7mB1DcmucJ;QJsRo#fwZyCM(^JM)y}zZIY6V!B z_XmXTxnbYYF(dzT$~iw6+worWynW?RL6~~dZo80BoNWAuee1mMloQK{iNlD)*pGs- z2|2h~+tz}QJ0gL`esXz7FyB;Qv(8?-+KkWRx`lbLd^4-p^vY4GA4o>a6^v+Gn?3u) z4M$_+hySBBc-IQW~&2&4OtsqA_&rr9d}p#YooZ`6f*y%cy{3P zcHlcuAO-Peh`D5zpDpMgx~GHay8g-LJ$T{V=G%rQ_=V_TR=GZ~%GfMabFf`q2CzVh z{*rkZjM41JDUJX3+tc|Pql_1KdEgstKECmBMe_;$J~T62KRO29h|d#@cy)Lzy)&GM}UlL=r}jIZ+%pA@K3n}XpPd6$Rh~vs&dw;6B zF!(X9GO&CsED+iMVc_WunId&rn*l{Qcc2OW2lZ2%SXf{|1npZozbpsi^j62s-tSk{M8%))4Z$6v`` z24UWZ0PqQ|FQk#Wm8QXd4ByTD8G%0k|Ar?fZ|Qw)py80g)$#Q=#4aa80+u&ko~y;uZ-9<%XE$d3@!J4>fC!t2gv5G<^y>qg71ETqQ4tt` zJXWLKZrT`(gxn^Btf}MmZRMll3Sl?ma zAy6#z0{UcL+{T1h9*+SPcI5WUO?t>q&w!!7?3dcxFr3$So7J)zIrg@vJc7nMhk6T3 z<{Y0h#Qm$k|MZ&D(MxTCreiGCn$#U8wwa%GTtpR^@g=?)R%{RQ6%?n+2Llh=Y$-XX za$yG5O1-5*svc9F_i3Ga;;0=*1x(@`m@e1bfMydHg?rZu8@=N}QqMKms^!RI=ZUz-7ds;w0B*l#Z$07|IIm|N#C z#RpJ6f*4G&bUE@N`__$i`AmsibijbSj?XV|>ntuH&8{K12f(@<@+->qsz4CdK0;as z^Fr)5WM%N%rk#ZX>k1tT@LA(1>Md=Eq*j0l^=EN}0MrjJIICtTkaQ7--s2bcZkIZ^ znpp3pMURS4y1xEnIeoO!*aZ7Jo4oD$ZFD_a$Tt%VH9l06VZf~IIZ&hyLeR2)bqn)f ziDDfBqfQ~83PqcJ4_(m3nr#XsbpC+)st#ugI=@wzcLe}ygZ7{%uEHb&_KYg~36`2* zgioOO+KT?FHyP_1q+l} zT@E4$GX%?pz61uu@u6qidb9XNtxsqvFUf!&EyS$Buxy+`*Y9Fi-U-Optn=LA&PZ*6 zc%Vf9+3NX!F!vrnRi)e8=K%#3#egW1K|v52L84@ooZ|r`s^oCUK{A4ZiKs}DoDbnh z&LF5H36gUV5G0ETNIc)#bl>~G_nVojnW~wp=_;$bx;<&{{l4!Czvo$s_9Ra7|CQsg zdbK4BTX$W%sMVGR59%CnD-b{JQd#{CL^!{A%s-i%n6Tv^|?+&>F9&lyPJB4Hqg^Q_YDD>L(6h6Wi)57R{^xSSnJ z<)bqW%+?QA0)LDtQHg!r_h?vK5!pW2k=ghm>UV3>=e4(eB%IAWehIbh+J130rWHFl zD)j4#==xW2-)mo*!ohk+ugLUyET4_G!avtrh51TfqTH9W;-zTr-@9vT`yXAZw?0UI zdhO??kwbRfSI>O+wLLk<#+OKI+JgKL#l1ue+!#T{MZz`QX{++m^!onX@9@w@|LT}UNS?+zRrYzz?p>yfmc#})ZVk8 z^SeYUnbcml)$K2qTZ}j|Asbz!r-r(y@CY3|^b#p*&qLWqCoXDWW(2av&4i3x^yGzU zNNiul^1Wv=Dd6X@6U3jJ+ry8W83z}e?BU}KC)fCqBQ5jEykC7&1f(kY8pEOZC3@qy z1nDKq;glSomFz{;&w=N-*(dkLc=s0^Gxavv=H_ntvE~Gj;m%DMU2tlrN~96#c@O zDbDgZHoR;0w%wx>I#^u|X%@=1<#SaJmE_KUq>oXbn(H1Ujy2CpF!dc=uUDLVp5+-* zPeF}FcNbdfy`PoO^BJnKi$6#rtt{bu`sD9c;0KNV5DR*b{l zhban4R7AA68%xVC&=@dClIBiq{wQVcMJIfk43!r#KwpYtJH_uwWkbK%muu!bww)#_ z8+*B{j^W@RgRMLVv;Z%M-X&@sL-U!qSp~lAU8T)bS0<|a3m#vHU?7Gngzbwo}n zi0qxWN>mm5Q=@e)|Iqmxmf!fx>QoNCD}`Q%9{GDc4LkhS0>HUW+I(F%~w@B@Dm$5W)#M5 zi|72gsEO;oRYstjuQUH`;Q~)8aZJGUFh$gpofZGnl5^dH8l!A-|M-RZf9IZ96w_HT z`hECW!g;hM_pX8g>#@nz=&YCp)lRIQtVi4pKAq!h4!kKxkJ5bF!c#~bPLEUIMTF?Q_GaNu*6ETIg9mu0|@_W67_9!_kHJh~4WRyuqf(cHUO;=N!T+5L}wCnrdJ7oNA z$5f<(dK7)$c-HJsa13E|I?jnd87N0W4}ZWGj}u`K+6)rgIcU`0lBIQhlTc>aeU&;S z3GBCgI7m`0N5UB;Yi^v#+?jv*DZjVgTcmMCvBJtM1$K-%sL}J{>O7M>nUSwG%MM4s zB~WX8OM^H8Bv#2}FoN2@RCM01c2XsIH3a`-m9@P3YG$M1z+N$eoQ zEy#>6J_;rS*0s1mvJ95#djU`sooDsOWnB2q9d964}UiLks4?Vk3%wfePM&A&9L znc!1+D2yIGXf66S_dHnNPb4H0>xeGTmka6Loqx`649#d|U|rfF_o}^t{LJtq8TT2;=4PlmgvKIT&$`X zHLokhysw9RU~kfEP1IhY@abuakrkC#?$7aLzHx5{OSJR#R`7rx)aL9Vrerqw^=A6| zdeB8fv+@ffgNrZn!>^Q2(z)&V7H)mU$qT4aX|8-L^a|qg!pTRpkaI~ zgmjBqYT#`~_wEu0X$2uxUOHOej!Nvw_kDh~vP|e&uhwjIhHFq;*J$;-rSchJv3wA_ zS01GVktsdb|A}HtIi$&QX)l!&s6;!ePz9GP!X@3R; z7?V?`F+I$JE?4J5T2E$ckezb@GR6-C<#s0OITBhSre@nD$L0J*_&k1@_Lkb{I77Vq zdE8tc`o-<__yc>M2aU&}FiA(vs;-KFnJwZ->IVUQ(aPe=r12OX-7(3li0nhd?sXx8 zVg2QA%itfhC2DhefE=GY5FM@72SGb;5EtppaDC^7YbM-Yxi zW1TKyl1h|`?gdN>YQv|XTFf9?eh-}9Y)FRrksCuHf)u({Q|Dt}*z}q}+UF+sHsBJj zZWoKe&+IPYwlkYl?_6aW5zBFp2RJt#@&T4~p|ISyNQ{Eo357+Y{a?@f^IWZ*NYZB& z)@&qK#ypqu`S0ICxNQzH*Asaf6j1%+xKWt$z29uDFGq7_=@H;H6K{{l3OZ*}a+^LA z=pSNGh7yUwmNF)o)pAB5j`hba=&gp!+`G2Yi?nK}0}lYeGR+c<7qI6C6ab@uIf~#V zZUV3sfX-5(MRG$P$ot-4E87!AN8dR#p5nifG6)fU+3@=Zfr2X~y)~7MnhRmd@%*s} zk(c~LzYeg*vchz!S66N|mdSz#!TV>h?7c{m`>^OQc1w_3@F5fwU;q!~9V9nwN6R{h z!}j-FzTP_!HHw|qmXkE&x(SHOy{x_eI-GN$25XNy)m!kWQ)9^FRD#P~EWSe%_&1qQ=?IO9nK zy;E5N8mq+*we!4$J|cYU7%E&8>@1=E&=JeiT=T1qeG3o!S#6HQK2`^3SLM27j-WVu z#sa-4Cu%Ek4e60{C<#w!x?Tgcfe%SI!I-i{^)#(0V~@jJti{M6vK>GNrf_EUh6dx` ztskXs=Eaap*SE<%p#00M`WD%o;|rZ|wBxMCAP7Ma(|EDnzn^I$wT0uAv%x2gHy+34~`x^Fou4^M`t%Lsg_Ivmrq;rk)r`P(v4`xvFn zNLY~+a!H&Fl%Cl6@<^yUAReFg;b;n7fo53C--s#irDX->YUgtU_)$#BYxo)(hE*P5 zJyR=)N{36@Mr8%SR1Wm&%uSkJ-2xV>DCFmYjI=lkXN`%?LUN1um|WCWONPKgl8UtN){JG$6H@OBr?md8np60dY7i6>Fd z9@oMdjhp{vy7TM%)+wFaRh7;S7rLF~-cc<(H!$;E&#}?L6EFpp(C@%qNBRE&_qvD| z+SSyvh*|^OOFh;YjI3L}B0h#IMO-b$?s~4+h3h;X!0G7qR}N@On{A;!g~7|=El~bL zaC0OwXc6g#qC|EDTkO^>>(sXwyNj91cgVyOETV2+h@x3Pp%qSp=gV~-1?p&x7PK~7 z*Nl;iah{eSk}2nbx(@aM)ayk=l^)v-1(8zE)v|SZ|JgZqoh0<@p9h{lL>6W4%^UYe z6Q8B|QG1MmtjBj&xW^ZTx_V6_@(HZDXc1TSFd|S1l+4H_R()QEqW?DAn_Qx#G8yXwwxi745;nPE)cJkGEG!is92>B6g@@o^c8#`O5`a# z@n1~R`Ow9=GTY%E{+_I$4$F6(#V!SgL8egNDG`li7Md5@7Mc`V6S*Oqq9{9pbIsmu z9IJH3plM4@2-C4(B+LKa5l)WGciOMv&X6P=NjOxjzZnX&U~}UY9Ha!AtZ&u9-gBfB zxj;Og_dL;(76i`^<{#YV`q88vvb;d0{ItMcR9P#?4uaMRtz?IcxUK3}S#?Q^S7WA5 z_LxD0x#gQ`)th-^`>rIicyAFhIeG$)wTy>i{t&+PYe%7-Y2U>FJ6nGj_3O5vPvO6o ziO;FnTdiL4tMWOnp|}?{4F11fZI2ZhsEEc3>UJ03;CPUSA^YJ)it$+>Tt6O8)_6E; zNUNgB?#Aj+Nl5Y|;Ogai6>V7I%cWJYy!K2luuA1*9>6-k1*d80Ot4OlZIF>ifneG_ zpWYusY0JC}_m;|5c^tqOnjgEU$AQPS>X0MRPx2N;BDmklYTd;0 zga#LuUf!$%30@F(@HR=PK~IWc!-e#xiAqVmi%dMyM~ zLthyRyMx*fxJFZYPjzTrlEV>g#^Gd@Ywp20a#+FSY;e;g7_Ui?1?KkZgAikno|U|y z`K+hWT}Ig4Qjq09&P~X4tAd3U`}#CFnO&rM3#_Q@qc8pnC4Xj>xM7?N^)wZV_FLit zt*lb%2drAKuKn+VO#(6e_3TG4p529W;x2M@vYH;3d+0DeR>{H!bsKwPtkDN$ZjuXD z;v|=lpA?S#q;aMV@(WKbVZ)!eqNWQU1|JCb8kX<7-%`vvdE-?dX}mrMW)8leuf1`? zc6dF1=bN}!t&UvzUE%sMrnIl$HAc>vo<6!$2my8(Z;~KbxGkC45cLsE9qP6-uNvO2 zN3}K9(c?K6KG>%FdzMIesiof8ks1KXAYAce_!~)9FLwqSGVeQb?g&T84}f3DaR8gr~PB z6KJg|_k

ZvhO#Q>kx9r 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 Date: Thu, 4 Jul 2024 04:35:03 -0400 Subject: [PATCH 151/151] BUGFIX: Creating thread to monitor ptp4l alive status Issue raised : https://github.com/intel-staging/libptpmgmt_iaclocklib/issues/92 The solution is to create a monitoring_thread to monitor the liveliness of ptp4l. Signed-off-by: Noor Azura Ahmad Tarmizi --- jclklib/proxy/connect_ptp4l.cpp | 53 ++++++++++++++++++++++++++++----- jclklib/proxy/connect_ptp4l.hpp | 9 ++++++ jclklib/proxy/main.cpp | 3 ++ 3 files changed, 57 insertions(+), 8 deletions(-) diff --git a/jclklib/proxy/connect_ptp4l.cpp b/jclklib/proxy/connect_ptp4l.cpp index b4006bf3..42722f4c 100644 --- a/jclklib/proxy/connect_ptp4l.cpp +++ b/jclklib/proxy/connect_ptp4l.cpp @@ -215,14 +215,51 @@ bool event_subscription(struct jcl_handle **handle) return ret; } -bool is_ptp4l_running() { +void *is_ptp4l_running( void *arg) { FILE *fp; char result[8]; - fp = popen("pgrep ptp4l", "r"); + + while (1) { + fp = popen("pgrep ptp4l", "r"); + + if (fp != NULL) { + Connect::monitor_hdle.is_ptp4l_alive = \ + fgets(result, sizeof(result) - 1, fp) != NULL; + pclose(fp); + } + sleep(1); + } + + return 0; +} + + +/** @brief Establishes a connection to the local PTP (Precision Time Protocol) daemon. + * + * This method initializes a Unix socket connection to the local PTP daemon. It sets up + * the message parameters, including the boundary hops and the process ID as part of the + * clock identity. It also configures the epoll instance to monitor the socket for incoming + * data or errors. + * + * @return An integer indicating the status of the connection attempt. + * Returns 0 on success, or -1 if an error occurs during socket initialization, + * address setting, or epoll configuration. + */ + +int Connect::start_monitoring_threads() +{ + int ret = 0; + pthread_attr_t tattr; - bool resultExists = fgets(result, sizeof(result) - 1, fp) != NULL; - pclose(fp); - return resultExists; + /* initialized with detached attributes. We are not waiting for this thread */ + ret = pthread_attr_init(&tattr); + ret = pthread_attr_setdetachstate(&tattr,PTHREAD_CREATE_DETACHED); + + if(( ret = -pthread_create (&Connect::monitor_hdle.ptp4l_monitor_thread, &tattr, is_ptp4l_running, + NULL)) < 0) + return ret; + + return ret; } /** @@ -267,7 +304,7 @@ void *ptp4l_event_loop( void *arg) event_subscription(NULL); while (1) { - if(is_ptp4l_running()) { + if (Connect::monitor_hdle.is_ptp4l_alive) { if (epoll_wait( epd, &epd_event, 1, 100) != -1) { const auto cnt = sk->rcv(buf, bufSize); MNG_PARSE_ERROR_e err = msg.parse(buf, cnt); @@ -290,7 +327,7 @@ void *ptp4l_event_loop( void *arg) notify_client(); while (1) { - if(is_ptp4l_running()) { + if (Connect::monitor_hdle.is_ptp4l_alive) { PrintInfo("Connected to ptp4l via /var/run/ptp4l."); std::string uds_address; m_sk.reset(sku); @@ -330,7 +367,7 @@ int Connect::connect() } m_sk.reset(sku); - while (is_ptp4l_running() != 1) { + while (!Connect::monitor_hdle.is_ptp4l_alive){ /* sleep for 2 seconds and keep looping until there is ptp4l available */ PrintError("Failed to connect to ptp4l. Retrying..."); sleep(2); diff --git a/jclklib/proxy/connect_ptp4l.hpp b/jclklib/proxy/connect_ptp4l.hpp index 421c4f95..7a47d2e2 100644 --- a/jclklib/proxy/connect_ptp4l.hpp +++ b/jclklib/proxy/connect_ptp4l.hpp @@ -14,6 +14,9 @@ #include #include +#include + +using namespace std; namespace JClkLibProxy { @@ -21,6 +24,12 @@ namespace JClkLibProxy { private: public: + struct monitor_handle { + atomic is_ptp4l_alive = false; + pthread_t ptp4l_monitor_thread; + }; static int connect(); + static int start_monitoring_threads(); + static monitor_handle monitor_hdle; }; } \ No newline at end of file diff --git a/jclklib/proxy/main.cpp b/jclklib/proxy/main.cpp index eced56dc..ae9e02f7 100644 --- a/jclklib/proxy/main.cpp +++ b/jclklib/proxy/main.cpp @@ -19,6 +19,7 @@ #include #include #include +#include using namespace JClkLibCommon; using namespace JClkLibProxy; @@ -35,6 +36,8 @@ int main() cout << "Message init failed" << endl; return -1; } + Connect::start_monitoring_threads(); + sleep(1); Connect::connect(); WaitForStopSignal(); PrintDebug("Got stop signal");

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