From fe70c334ebcb62a7d98bec1a7b5e6822df994af3 Mon Sep 17 00:00:00 2001
From: Adam Wujek <adam.wujek@cern.ch>
Date: Fri, 27 Mar 2015 13:56:04 +0100
Subject: [PATCH] userspace/snmpd: add wrsGeneralStatusGroup so far only for
 cache testing

Signed-off-by: Adam Wujek <adam.wujek@cern.ch>
---
 userspace/snmpd/Makefile                |  3 +-
 userspace/snmpd/init.c                  |  2 +
 userspace/snmpd/wrsGeneralStatusGroup.c | 55 +++++++++++++++++++++++++
 userspace/snmpd/wrsGeneralStatusGroup.h | 13 ++++++
 4 files changed, 72 insertions(+), 1 deletion(-)
 create mode 100644 userspace/snmpd/wrsGeneralStatusGroup.c
 create mode 100644 userspace/snmpd/wrsGeneralStatusGroup.h

diff --git a/userspace/snmpd/Makefile b/userspace/snmpd/Makefile
index 50d1ec5a6..95ab43791 100644
--- a/userspace/snmpd/Makefile
+++ b/userspace/snmpd/Makefile
@@ -36,7 +36,8 @@ SOURCES = \
 	wrsTemperature.c \
 	wrsOSStatus.c \
 	wrsVersionGroup.c \
-	wrsPortStatusTable.c
+	wrsPortStatusTable.c \
+	wrsGeneralStatusGroup.c
 
 OBJECTS = $(SOURCES:.c=.o)
 
diff --git a/userspace/snmpd/init.c b/userspace/snmpd/init.c
index dd8302a76..5ed374290 100644
--- a/userspace/snmpd/init.c
+++ b/userspace/snmpd/init.c
@@ -16,6 +16,7 @@
 #include "wrsOSStatus.h"
 #include "wrsVersionGroup.h"
 #include "wrsPortStatusTable.h"
+#include "wrsGeneralStatusGroup.h"
 
 FILE *wrs_logf; /* for the local-hack messages */
 
@@ -31,4 +32,5 @@ void init_wrsSnmp(void)
 	init_wrsOSStatus();
 	init_wrsVersionGroup();
 	init_wrsPortStatusTable();
+	init_wrsGeneralStatusGroup();
 }
diff --git a/userspace/snmpd/wrsGeneralStatusGroup.c b/userspace/snmpd/wrsGeneralStatusGroup.c
new file mode 100644
index 000000000..2a12ade1e
--- /dev/null
+++ b/userspace/snmpd/wrsGeneralStatusGroup.c
@@ -0,0 +1,55 @@
+#include "wrsSnmp.h"
+#include "shmem_snmp.h"
+#include "wrsCurrentTimeGroup.h"
+#include "wrsOSStatus.h"
+#include "wrsPortStatusTable.h"
+#include "wrsPstatsTable.h"
+#include "wrsPtpDataTable.h"
+#include "wrsStartCntGroup.h"
+#include "wrsTemperature.h"
+#include "wrsVersionGroup.h"
+
+#include "wrsGeneralStatusGroup.h"
+
+static struct pickinfo wrsGeneralStatus_pickinfo[] = {
+	FIELD(wrsGeneralStatus_s, ASN_INTEGER, wrsMainSystemStatus),
+};
+
+struct wrsGeneralStatus_s wrsGeneralStatus_s;
+
+time_t wrsGeneralStatus_data_fill(void)
+{
+	static time_t time_update; /* time of last update */
+	time_t time_temp; /* time when temperature data was updated */
+
+	time_temp = wrsTemperature_data_fill();
+
+	if (time_temp <= time_update) {
+		/* cache not updated, return last update time */
+		snmp_log(LOG_ERR,
+			"SNMP: wrsGeneralStatusGroup cache\n");
+		return time_update;
+	}
+	time_update = time(NULL);
+	wrsCurrentTime_data_fill();
+	wrsOSStatus_data_fill();
+	wrsPortStatusTable_data_fill(NULL);
+	wrsPstatsTable_data_fill(NULL);
+	wrsPtpDataTable_data_fill(NULL);
+	wrsStartCnt_data_fill();
+	wrsVersion_data_fill();
+
+	/*memset(&wrsGeneralStatus_s, 0, sizeof(wrsGeneralStatus_s));*/
+	wrsGeneralStatus_s.wrsMainSystemStatus++;
+	/* there was an update, return current time */
+	return time_update;
+}
+
+#define GT_OID WRSGENERALSTATUS_OID
+#define GT_PICKINFO wrsGeneralStatus_pickinfo
+#define GT_DATA_FILL_FUNC wrsGeneralStatus_data_fill
+#define GT_DATA_STRUCT wrsGeneralStatus_s
+#define GT_GROUP_NAME "wrsGeneralStatusGroup"
+#define GT_INIT_FUNC init_wrsGeneralStatusGroup
+
+#include "wrsGroupTemplate.h"
diff --git a/userspace/snmpd/wrsGeneralStatusGroup.h b/userspace/snmpd/wrsGeneralStatusGroup.h
new file mode 100644
index 000000000..aed4bc0ac
--- /dev/null
+++ b/userspace/snmpd/wrsGeneralStatusGroup.h
@@ -0,0 +1,13 @@
+#ifndef WRS_GENERAL_STATUS_GROUP_H
+#define WRS_GENERAL_STATUS_GROUP_H
+
+#define WRSGENERALSTATUS_OID WRS_OID, 254, 254
+struct wrsGeneralStatus_s {
+	int wrsMainSystemStatus;
+};
+
+extern struct wrsGeneralStatus_s wrsGeneralStatus_s;
+time_t wrsGeneralStatus_data_fill(void);
+void init_wrsGeneralStatusGroup(void);
+
+#endif /* WRS_GENERAL_STATUS_GROUP_H */
-- 
GitLab