Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Autotools generated files
Makefile.in
aclocal.m4
autom4te.cache/
compile
config.guess
config.h
config.h.in
config.log
config.status
config.sub
configure
configure~
depcomp
install-sh
ltmain.sh
m4/
missing
.deps/
.libs/
*.la
*.lo
*.o
Makefile
libtool
stamp-h1
_codeql_detected_source_root

# Build artifacts
*.a
*.so
*.so.*
*.dylib
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# limitations under the License.
##########################################################################

AM_CXXFLAGS = -Wall -std=c++1y $(DEBUG_CXXFLAGS) $(TEE_CXXFLAGS) $(DTT_CXXFLAGS) -I${PKG_CONFIG_SYSROOT_DIR}$(includedir)/systimerifc
AM_CXXFLAGS = -Wall -std=c++1y $(DEBUG_CXXFLAGS) $(TEE_CXXFLAGS) $(DTT_CXXFLAGS) $(CHRONY_CXXFLAGS) -I${PKG_CONFIG_SYSROOT_DIR}$(includedir)/systimerifc
ACLOCAL_AMFLAGS = -I m4


Expand Down
34 changes: 32 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ This is an interface class for operating with time sources and provide an interf

This class implements ITimeSrc interface. It uses ntp api (ntp\_gettime) to extract the time. we can find out time as well as the drift info which is populated by the ntp daemons.

### 2.2.2 RegularTimeSrc
### 2.2.2 ChronyTimeSrc

This class implements ITimeSrc interface. It uses the chronyd daemon via libchronyctl library to obtain time. Chrony is a versatile implementation of the Network Time Protocol (NTP) that is designed to perform well in a wide range of conditions. This time source is conditionally compiled when the `--enable-chrony` configure flag is used.

### 2.2.3 RegularTimeSrc

This class implements ITimeSrc interface. This is a class which reads time from the configured file.

Expand Down Expand Up @@ -86,6 +90,32 @@ The following are the states and its definition.
- **DTTAcquired:** This state indicates acquisition of DTT Time and waiting for NTP and Secure Time.
- **Running:** This state indicates that NTP and Secure Time is acquired. On every 10 min timer expiry we check the drift of securetime and ntp time. If the drift is greater that 10 minutes, we update TEE Time to 0 otherwise we update with NTP Time.

# 5. Appendix
# 5. Build Configuration

## 5.1 Building with Chrony Support

To build systemtimemgr with chrony time source support, use the `--enable-chrony` configure flag:

```bash
./configure --enable-chrony
make
```

This will:
- Define the `CHRONY_ENABLED` macro
- Include the ChronyTimeSrc class in the build
- Link against libchronyctl.so library

When chrony support is enabled, you can configure systemtimemgr to use chrony as a time source by adding the following to the configuration file:

```
timesrc chrony ""
```

**Note:**
- The ChronyTimeSrc currently uses a placeholder implementation. Integration with the actual libchronyctl.so API needs to be completed based on the available libchronyctl API documentation.
- The libchronyctl.so library must be installed on the target system for chrony support to work.

# 6. Appendix

Tried out using Lambda functions for ISubscriber, but considering aspect that bus registration could be using C dropped the idea. If interested pls read at [https://www.cprogramming.com/c++11/c++11-lambda-closures.html](https://www.cprogramming.com/c++11/c++11-lambda-closures.html)
13 changes: 13 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ AC_CHECK_HEADERS([stdlib.h string.h unistd.h])
DEBUG_CXXFLAGS=" "
TEE_CXXFLAGS=" "
DTT_CXXFLAGS=" "
CHRONY_CXXFLAGS=" "

# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
Expand Down Expand Up @@ -83,6 +84,17 @@ AC_ARG_ENABLE([dtt],
],
[echo "Tee build is enable"])

AC_ARG_ENABLE([chrony],
AS_HELP_STRING([--enable-chrony],[enable chrony build]),
[
case "${enableval}" in
yes) CHRONY_CXXFLAGS="-DCHRONY_ENABLED";;
no) CHRONY_CXXFLAGS=" ";;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-chrony ]) ;;
esac
],
[echo "Chrony build is disabled"])

AC_ARG_ENABLE([t2api],
AS_HELP_STRING([--enable-t2api],[enables telemetry]),
[
Expand All @@ -101,6 +113,7 @@ AC_CONFIG_FILES(Makefile)
AC_SUBST(DEBUG_CXXFLAGS)
AC_SUBST(TEE_CXXFLAGS)
AC_SUBST(DTT_CXXFLAGS)
AC_SUBST(CHRONY_CXXFLAGS)


AC_OUTPUT
Expand Down
6 changes: 5 additions & 1 deletion systimerfactory/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#


AM_CXXFLAGS = -Wall -std=c++1y $(DEBUG_CXXFLAGS) -I${PKG_CONFIG_SYSROOT_DIR}$(includedir)/systimerifc $(IARM_CFLAGS) $(PWRMGR_CFLAGS) $(CURL_CFLAGS) $(UNITTEST_CXXFLAGS) $(TEE_CXXFLAGS) $(JSONRPC_CFLAGS) $(WPEFRAMEWORKCORE_CFLAGS) $(WPEFRAMEWORKWEBSOCKET_CFLAGS) $(WPEVGDRM_CXXFLAGS) $(DTT_CXXFLAGS)
AM_CXXFLAGS = -Wall -std=c++1y $(DEBUG_CXXFLAGS) -I${PKG_CONFIG_SYSROOT_DIR}$(includedir)/systimerifc $(IARM_CFLAGS) $(PWRMGR_CFLAGS) $(CURL_CFLAGS) $(UNITTEST_CXXFLAGS) $(TEE_CXXFLAGS) $(JSONRPC_CFLAGS) $(WPEFRAMEWORKCORE_CFLAGS) $(WPEFRAMEWORKWEBSOCKET_CFLAGS) $(WPEVGDRM_CXXFLAGS) $(DTT_CXXFLAGS) $(CHRONY_CXXFLAGS)
ACLOCAL_AMFLAGS = -I m4


Expand Down Expand Up @@ -45,6 +45,10 @@ endif

libsystimerfactory_la_LIBADD = $(IARM_LIBS) $(JSONRPC_LIBS) -lrdkloggers $(WPEFRAMEWORKCORE_LIBS) $(WPEFRAMEWORKWEBSOCKET_LIBS)

if CHRONY_ENABLED
libsystimerfactory_la_LIBADD += -lchronyctl
endif


libsystimerfactory_la_includedir = ${includedir}
libsystimerfactory_la_include_HEADERS = timerfactory.h
53 changes: 53 additions & 0 deletions systimerfactory/chronytimesrc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2023 Comcast Cable Communications Management, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _CHRONYTIMESRC_H_
#define _CHRONYTIMESRC_H_

#include "itimesrc.h"
#include "irdklog.h"
#include <time.h>

class ChronyTimeSrc : public ITimeSrc
{
public:
ChronyTimeSrc():ITimeSrc(){}

bool isreference() { return true;}

long long getTimeSec(){
// NOTE: This is a placeholder implementation
// In production, this should call the actual libchronyctl API
// to communicate with chronyd daemon and get synchronized time.
// The actual implementation would use functions from libchronyctl.so
// Example: chronyctl_get_time() or similar API

struct timespec ts;
// Temporary fallback using clock_gettime
// Replace this with actual libchronyctl API call when available
if (clock_gettime(CLOCK_REALTIME, &ts) == 0) {
RDK_LOG(RDK_LOG_DEBUG,LOG_SYSTIME,"[%s:%d]:Chrony Time Values, Time in Sec = %ld, Time in Nanosec = %ld\n",__FUNCTION__,__LINE__,ts.tv_sec,ts.tv_nsec);
return ts.tv_sec;
} else {
RDK_LOG(RDK_LOG_ERROR,LOG_SYSTIME,"[%s:%d]:Failed to get chrony time\n",__FUNCTION__,__LINE__);
return 0;
}
}

};

#endif// _CHRONYTIMESRC_H_
16 changes: 16 additions & 0 deletions systimerfactory/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ AC_C_INLINE
# Checks for library functions.
AC_FUNC_MALLOC

CHRONY_ENABLED=""
CHRONY_CXXFLAGS=" "
AC_ARG_ENABLE([chrony],
AS_HELP_STRING([--enable-chrony],[enable chrony ]),
[
case "${enableval}" in
yes) CHRONY_CXXFLAGS="-DCHRONY_ENABLED"
CHRONY_ENABLED=true;;
no) CHRONY_ENABLED=false;;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-chrony ]) ;;
esac
],
[echo "chrony build is disabled"])

AC_ARG_ENABLE([debug],
AS_HELP_STRING([--enable-debug],[enable debug build]),
[
Expand Down Expand Up @@ -166,6 +180,7 @@ AM_CONDITIONAL([IARM_ENABLED], [test x$IARM_ENABLED = xtrue])
AM_CONDITIONAL([PWRMGRPLUGIN_ENABLED], [test x$PWRMGRPLUGIN_ENABLED = xtrue])
AM_CONDITIONAL([DTT_ENABLED], [test x$DTT_ENABLED = xtrue])
AM_CONDITIONAL([TEE_ENABLED], [test x$TEE_ENABLED = xtrue])
AM_CONDITIONAL([CHRONY_ENABLED], [test x$CHRONY_ENABLED = xtrue])
PKG_CHECK_MODULES([JSONRPC],[libjsonrpccpp-client >= 0.7.0])

AC_CONFIG_FILES(Makefile)
Expand All @@ -177,6 +192,7 @@ AC_SUBST(PWRMGR_CFLAGS)
AC_SUBST(TEE_CXXFLAGS)
AC_SUBST(WPEVGDRM_CXXFLAGS)
AC_SUBST(DTT_CXXFLAGS)
AC_SUBST(CHRONY_CXXFLAGS)


AC_OUTPUT
Expand Down
9 changes: 9 additions & 0 deletions systimerfactory/timerfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#ifdef TEE_ENABLED
#include "teetimesync.h"
#endif //TEE_ENABLED
#ifdef CHRONY_ENABLED
#include "chronytimesrc.h"
#endif //CHRONY_ENABLED

ITimeSrc* createTimeSrc(string type, string args)
{
Expand All @@ -54,6 +57,12 @@ ITimeSrc* createTimeSrc(string type, string args)
ret = new DttTimeSrc(std::move(args));
}
#endif// DTT_ENABLED
#ifdef CHRONY_ENABLED
else if (type == "chrony")
{
ret = new ChronyTimeSrc();
}
#endif// CHRONY_ENABLED

return ret;
}
Expand Down