Parcourir la source

adding some more semantic information to ServerStatus node: buildTime and serverVersion

Stasik0 il y a 10 ans
Parent
commit
4bb34f9aa5
4 fichiers modifiés avec 63 ajouts et 8 suppressions
  1. 3 0
      CMakeLists.txt
  2. 6 4
      src/server/ua_server.c
  3. 2 1
      src/server/ua_server_internal.h
  4. 52 3
      src/server/ua_server_worker.c

+ 3 - 0
CMakeLists.txt

@@ -5,6 +5,9 @@ project(open62541 C)
 set(open62541_VERSION_MAJOR 0)
 set(open62541_VERSION_MINOR 0)
 set(open62541_VERSION_PATCH 0)
+add_definitions(-DOPEN62541_VERSION_MAJOR=${open62541_VERSION_MAJOR})
+add_definitions(-DOPEN62541_VERSION_MINOR=${open62541_VERSION_MINOR})
+add_definitions(-DOPEN62541_VERSION_PATCH=${open62541_VERSION_PATCH})
 
 set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
 

+ 6 - 4
src/server/ua_server.c

@@ -81,15 +81,17 @@ void UA_Server_delete(UA_Server *server) {
 
 static UA_StatusCode readStatus(const void *handle, UA_DataValue *value) {
     UA_ServerStatusDataType *status = UA_ServerStatusDataType_new();
-    status->startTime   = ((const UA_Server*)handle)->timeStarted;
+    status->startTime   = ((const UA_Server*)handle)->startTime;
     status->currentTime = UA_DateTime_now();
     status->state       = UA_SERVERSTATE_RUNNING;
     UA_String_copycstring("http://www.open62541.org", &status->buildInfo.productUri);
     UA_String_copycstring("open62541", &status->buildInfo.manufacturerName);
     UA_String_copycstring("open62541 OPC UA Server", &status->buildInfo.productName);
-    UA_String_copycstring("0.0", &status->buildInfo.softwareVersion);
-    UA_String_copycstring("0.0", &status->buildInfo.buildNumber);
-    status->buildInfo.buildDate = UA_DateTime_now();
+#define STRINGIFY(x) #x //some magic
+#define TOSTRING(x) STRINGIFY(x) //some magic
+    UA_String_copycstring(TOSTRING(OPEN62541_VERSION_MAJOR) "." TOSTRING(OPEN62541_VERSION_MINOR) "." TOSTRING(OPEN62541_VERSION_PATCH), &status->buildInfo.softwareVersion);
+    UA_String_copycstring("0", &status->buildInfo.buildNumber);
+    status->buildInfo.buildDate = ((const UA_Server*)handle)->buildDate;
     status->secondsTillShutdown = 0;
 
     value->value.type = &UA_TYPES[UA_TYPES_SERVERSTATUSDATATYPE];

+ 2 - 1
src/server/ua_server_internal.h

@@ -63,7 +63,8 @@ struct UA_Server {
 
     LIST_HEAD(UA_TimedWorkList, UA_TimedWork) timedWork;
 
-    UA_DateTime timeStarted;
+    UA_DateTime startTime;
+    UA_DateTime buildDate;
 };
 
 void UA_Server_processBinaryMessage(UA_Server *server, UA_Connection *connection, const UA_ByteString *msg);

+ 52 - 3
src/server/ua_server_worker.c

@@ -426,12 +426,61 @@ UA_StatusCode UA_Server_run(UA_Server *server, UA_UInt16 nThreads, UA_Boolean *r
     UA_Server_addRepeatedWorkItem(server, &processDelayed, 10000000, UA_NULL);
 #endif
 
-    // 2) Start the networklayers
+    // 2a) Start the networklayers
     for(UA_Int32 i=0;i<server->nlsSize;i++)
         server->nls[i].start(server->nls[i].nlHandle, &server->logger);
 
-    // 3) The loop
-    server->timeStarted = UA_DateTime_now();
+    // 2b) Init server's meta-information
+    //fill startTime
+    server->startTime = UA_DateTime_now();
+
+    //fill build date
+    {
+		static struct tm ct;
+
+		ct.tm_year = (__DATE__[7] - '0') * 1000 +  (__DATE__[8] - '0') * 100 + (__DATE__[9] - '0') * 10 + (__DATE__[10] - '0')- 1900;
+
+		if (0) ;
+		else if ((__DATE__[0]=='J') && (__DATE__[1]=='a') && (__DATE__[2]=='n')) ct.tm_mon = 1-1;
+		else if ((__DATE__[0]=='F') && (__DATE__[1]=='e') && (__DATE__[2]=='b')) ct.tm_mon = 2-1;
+		else if ((__DATE__[0]=='M') && (__DATE__[1]=='a') && (__DATE__[2]=='r')) ct.tm_mon = 3-1;
+		else if ((__DATE__[0]=='A') && (__DATE__[1]=='p') && (__DATE__[2]=='r')) ct.tm_mon = 4-1;
+		else if ((__DATE__[0]=='M') && (__DATE__[1]=='a') && (__DATE__[2]=='y')) ct.tm_mon = 5-1;
+		else if ((__DATE__[0]=='J') && (__DATE__[1]=='u') && (__DATE__[2]=='n')) ct.tm_mon = 6-1;
+		else if ((__DATE__[0]=='J') && (__DATE__[1]=='u') && (__DATE__[2]=='l')) ct.tm_mon = 7-1;
+		else if ((__DATE__[0]=='A') && (__DATE__[1]=='u') && (__DATE__[2]=='g')) ct.tm_mon = 8-1;
+		else if ((__DATE__[0]=='S') && (__DATE__[1]=='e') && (__DATE__[2]=='p')) ct.tm_mon = 9-1;
+		else if ((__DATE__[0]=='O') && (__DATE__[1]=='c') && (__DATE__[2]=='t')) ct.tm_mon = 10-1;
+		else if ((__DATE__[0]=='N') && (__DATE__[1]=='o') && (__DATE__[2]=='v')) ct.tm_mon = 11-1;
+		else if ((__DATE__[0]=='D') && (__DATE__[1]=='e') && (__DATE__[2]=='c')) ct.tm_mon = 12-1;
+
+		// special case to handle __DATE__ not inserting leading zero on day of month
+		// if Day of month is less than 10 - it inserts a blank character
+		// this results in a negative number for tm_mday
+
+		if(__DATE__[4] == ' ')
+		{
+			ct.tm_mday =  __DATE__[5]-'0';
+		}
+		else
+		{
+			ct.tm_mday = (__DATE__[4]-'0')*10 + (__DATE__[5]-'0');
+		}
+
+		ct.tm_hour = ((__TIME__[0] - '0') * 10 + __TIME__[1] - '0');
+		ct.tm_min = ((__TIME__[3] - '0') * 10 + __TIME__[4] - '0');
+		ct.tm_sec = ((__TIME__[6] - '0') * 10 + __TIME__[7] - '0');
+
+		ct.tm_isdst = -1;  // information is not available.
+
+		//FIXME: next 3 lines are copy-pasted from ua_types.c
+		#define UNIX_EPOCH_BIAS_SEC 11644473600LL // Number of seconds from 1 Jan. 1601 00:00 to 1 Jan 1970 00:00 UTC
+		#define HUNDRED_NANOSEC_PER_USEC 10LL
+		#define HUNDRED_NANOSEC_PER_SEC (HUNDRED_NANOSEC_PER_USEC * 1000000LL)
+		server->buildDate = (mktime(&ct) + UNIX_EPOCH_BIAS_SEC) * HUNDRED_NANOSEC_PER_SEC;
+    }
+
+    //3) The loop
     while(1) {
         // 3.1) Process timed work
         UA_UInt16 timeout = processTimedWork(server);