Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DUMMY-0002: Wan Manager telemetry Marker Sample code #73

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion source/WanManager/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ wanmanager_CPPFLAGS = -I$(top_srcdir)/source/TR-181/middle_layer_src \

wanmanager_CFLAGS = -DFEATURE_SUPPORT_RDKLOG $(DBUS_CFLAGS) $(SYSTEMD_CFLAGS)
wanmanager_CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
wanmanager_SOURCES = wanmgr_webconfig_apis.c wanmgr_webconfig.c wanmgr_main.c wanmgr_ssp_action.c wanmgr_ssp_messagebus_interface.c wanmgr_core.c wanmgr_controller.c wanmgr_data.c wanmgr_sysevents.c wanmgr_interface_sm.c wanmgr_utils.c wanmgr_net_utils.c wanmgr_dhcpv4_apis.c wanmgr_dhcpv6_apis.c wanmgr_ipc.c wanmgr_dhcpv4_internal.c wanmgr_dhcpv6_internal.c wanmgr_policy_autowan_impl.c wanmgr_policy_auto_impl.c dm_pack_datamodel.c wanmgr_wan_failover.c wanmgr_policy_parallel_scan_impl.c wanmgr_dhcp_legacy_apis.c
wanmanager_SOURCES = wanmgr_webconfig_apis.c wanmgr_webconfig.c wanmgr_main.c wanmgr_ssp_action.c wanmgr_ssp_messagebus_interface.c wanmgr_core.c wanmgr_controller.c wanmgr_data.c wanmgr_sysevents.c wanmgr_interface_sm.c wanmgr_utils.c wanmgr_net_utils.c wanmgr_dhcpv4_apis.c wanmgr_dhcpv6_apis.c wanmgr_ipc.c wanmgr_dhcpv4_internal.c wanmgr_dhcpv6_internal.c wanmgr_policy_autowan_impl.c wanmgr_policy_auto_impl.c dm_pack_datamodel.c wanmgr_wan_failover.c wanmgr_policy_parallel_scan_impl.c wanmgr_dhcp_legacy_apis.c wan_telemetry_marker.c
wanmanager_LDADD = $(wanmanager_DEPENDENCIES) -lccsp_common -lrdkloggers $(DBUS_LIBS) $(SYSTEMD_LDFLAGS) -lhal_platform -lapi_dhcpv4c -lnanomsg -lwebconfig_framework -lmsgpackc -ldhcp_client_utils -lprivilege -lrbus -lsecure_wrapper
117 changes: 117 additions & 0 deletions source/WanManager/wan_telemetry_marker.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#include "wan_telemetry_marker.h"
#ifdef ENABLE_FEATURE_TELEMETRY2_0
#include <telemetry_busmessage_sender.h>
#endif
#include <stddef.h>
#include "ccsp_trace.h"

struct marker
{
char *t1_marker_string;
return_status_e (*telemetry_marker_set)(struct marker *marker_p, char *marker, void **data);
};

static return_status_e telemetry_marker_t2_string(struct marker *marker_p, char *marker, void **data)
{
char buf[128] = {0};
char **data_p = (char **)data;

if (data != NULL)
{
snprintf(buf, 128, marker_p->t1_marker_string, data_p[0], data_p[1]);
}
else
{
strcpy(buf, marker_p->t1_marker_string);
}
CcspTraceInfo(("%s-%d: %s-%s", __FUNCTION__, __LINE__, marker, buf));
#ifdef ENABLE_FEATURE_TELEMETRY2_0
t2_event_s(marker, data_p);
#endif
return STATUS_SUCCESS;
}


static return_status_e telemetry_marker_t1_string(struct marker *marker_p, char *marker, void **data)
{
char buf[128] = {0};

if (data != NULL)
{
char **data_p = (char **)data;
snprintf(buf, 128, marker_p->t1_marker_string, data_p[0], data_p[1]);
}
else
{
strcpy(buf, marker_p->t1_marker_string);
}
CcspTraceInfo(("%s-%d: %s-%s", __FUNCTION__, __LINE__, marker, buf));
return STATUS_SUCCESS;
}

static return_status_e telemetry_marker_t2_int(struct marker *marker_p, char *marker, void **data)
{
char buf[128] = {0};
int **data_p = (int **)data;

if (data != NULL)
{
snprintf(buf, 128, marker_p->t1_marker_string, (**data_p));
}
else
{
strcpy(buf, marker_p->t1_marker_string);
}
CcspTraceInfo(("%s-%d: %s-%s", __FUNCTION__, __LINE__, marker, buf));
#ifdef ENABLE_FEATURE_TELEMETRY2_0
t2_event_d(marker, (**data_p));
#endif
return STATUS_SUCCESS;
}


static struct marker marker_table[] =
{
{
//marker id : WAN_INFO_PHY_TYPE
.t1_marker_string = "Selecting Base Interface:%s Phy_Type:%s",
.telemetry_marker_set = telemetry_marker_t2_string,
},
{
//marker id : SYS_INFO_EthWanMode
.t1_marker_string = "Ethernet WAN is enabled",
.telemetry_marker_set = telemetry_marker_t1_string,
},
{
//marker id : WAN_ERROR_PHY_DOWN
.t1_marker_string = "Received Base Interface:%s down",
.telemetry_marker_set = telemetry_marker_t2_string,
},
{
//marker id : WAN_INFO_PHY_UP
.t1_marker_string = "Received Base Interface:%s up",
.telemetry_marker_set = telemetry_marker_t2_string,
},
{
//marker id : WAN_WARNING_IP_OBTAIN_TIMER_EXPIRED
.t1_marker_string = "Wan Router Interface:%s, IP Obtaining Timer Expired %s",
.telemetry_marker_set = telemetry_marker_t2_string,
},
{
//marker id : WAN_BTIME_WANINIT
.t1_marker_string = "Wan Boot Time Init %d",
.telemetry_marker_set = telemetry_marker_t2_int,
},
{ },
};



return_status_e __wan_telemetry_marker_set(marker_id_e marker_id, char* marker, void **data)
{
return_status_e return_status;
return_status = marker_table[marker_id].telemetry_marker_set(&marker_table[marker_id], marker, data);
return return_status;
}


29 changes: 29 additions & 0 deletions source/WanManager/wan_telemetry_marker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef _WAN_TELEMETRY_MARKER_H_
#define _WAN_TELEMETRY_MARKER_H_

typedef enum _return_status_e
{
STATUS_SUCCESS,
STATUS_FAILED,
STATUS_FEATURE_DISABLED,
STATUS_UNDEFINED,
STATUS_INVALID,
STATUS_UNKNOWN,
}return_status_e;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid use protected word like return in the name of variable or types


typedef enum _marker_id_e
{
WAN_INFO_PHY_TYPE,
SYS_INFO_EthWanMode,
WAN_ERROR_PHY_DOWN,
WAN_INFO_PHY_UP,
WAN_WARNING_IP_OBTAIN_TIMER_EXPIRED,
WAN_BTIME_WANINIT, //exp for int arg
}marker_id_e;

#define wan_telemetry_marker_set(marker_id, data) \
__wan_telemetry_marker_set(marker_id, #marker_id, data);

extern return_status_e __wan_telemetry_marker_set(marker_id_e marker_id, char* marker, void **data);

#endif //_WAN_TELEMETRY_MARKER_H_