small improvements, generate server information in ua_server.c

This commit is contained in:
Julius Pfrommer
2015-04-16 19:18:38 +02:00
parent 1420f81106
commit e7709296bf
3 changed files with 68 additions and 74 deletions
+18 -17
View File
@@ -336,23 +336,9 @@ static UA_Int32 ServerNetworkLayerTCP_getWork(ServerNetworkLayerTCP *layer, UA_W
struct timeval tmptv = {0, timeout * 1000};
UA_Int32 resultsize = select(layer->highestfd+1, &layer->fdset, NULL, NULL, &tmptv);
// accept new connections (can only be a single one)
if(FD_ISSET(layer->serversockfd, &layer->fdset)) {
resultsize--;
struct sockaddr_in cli_addr;
socklen_t cli_len = sizeof(cli_addr);
int newsockfd = accept(layer->serversockfd, (struct sockaddr *) &cli_addr, &cli_len);
int i = 1;
setsockopt(newsockfd, IPPROTO_TCP, TCP_NODELAY, (void *)&i, sizeof(i));
if (newsockfd >= 0) {
socket_set_nonblocking(newsockfd);
ServerNetworkLayerTCP_add(layer, newsockfd);
}
}
UA_WorkItem *items = malloc(sizeof(UA_WorkItem)*(resultsize+1));
if(!items) {
/* reattach the deletes so that they get deleted eventually.. */
UA_WorkItem *items;
if(resultsize < 0 || !(items = malloc(sizeof(UA_WorkItem)*(resultsize+1)))) {
/* abort .. reattach the deletes so that they get deleted eventually.. */
#ifdef UA_MULTITHREADING
struct DeleteList *last_delete = deletes;
while(last_delete->next != NULL)
@@ -368,6 +354,20 @@ static UA_Int32 ServerNetworkLayerTCP_getWork(ServerNetworkLayerTCP *layer, UA_W
*workItems = NULL;
return 0;
}
// accept new connections (can only be a single one)
if(FD_ISSET(layer->serversockfd, &layer->fdset)) {
resultsize--;
struct sockaddr_in cli_addr;
socklen_t cli_len = sizeof(cli_addr);
int newsockfd = accept(layer->serversockfd, (struct sockaddr *) &cli_addr, &cli_len);
int i = 1;
setsockopt(newsockfd, IPPROTO_TCP, TCP_NODELAY, (void *)&i, sizeof(i));
if (newsockfd >= 0) {
socket_set_nonblocking(newsockfd);
ServerNetworkLayerTCP_add(layer, newsockfd);
}
}
/* read from established sockets */
UA_Int32 j = 0;
@@ -378,6 +378,7 @@ static UA_Int32 ServerNetworkLayerTCP_getWork(ServerNetworkLayerTCP *layer, UA_W
if(!buf.data) {
buf.data = malloc(sizeof(UA_Byte) * layer->conf.recvBufferSize);
buf.length = layer->conf.recvBufferSize;
if(!buf.data)
break;
}
+49 -6
View File
@@ -110,15 +110,16 @@ static UA_StatusCode readStatus(void *handle, UA_Boolean sourceTimeStamp, UA_Dat
status->startTime = ((const UA_Server*)handle)->startTime;
status->currentTime = UA_DateTime_now();
status->state = UA_SERVERSTATE_RUNNING;
status->buildInfo.productUri = UA_STRING_ALLOC("http://www.open62541.org");
status->buildInfo.manufacturerName = UA_STRING_ALLOC("open62541");
status->buildInfo.productName = UA_STRING_ALLOC("open62541 OPC UA Server");
status->buildInfo.productUri = UA_STRING("http://www.open62541.org");
status->buildInfo.manufacturerName = UA_STRING("open62541");
status->buildInfo.productName = UA_STRING("open62541 OPC UA Server");
#define STRINGIFY(x) #x //some magic
#define TOSTRING(x) STRINGIFY(x) //some magic
status->buildInfo.softwareVersion = UA_STRING_ALLOC(TOSTRING(OPEN62541_VERSION_MAJOR) "." TOSTRING(OPEN62541_VERSION_MINOR) "." TOSTRING(OPEN62541_VERSION_PATCH));
status->buildInfo.buildNumber = UA_STRING_ALLOC("0");
status->buildInfo.softwareVersion = UA_STRING(TOSTRING(OPEN62541_VERSION_MAJOR) "." TOSTRING(OPEN62541_VERSION_MINOR) "." TOSTRING(OPEN62541_VERSION_PATCH));
status->buildInfo.buildNumber = UA_STRING("0");
status->buildInfo.buildDate = ((const UA_Server*)handle)->buildDate;
status->secondsTillShutdown = 0;
value->value.type = &UA_TYPES[UA_TYPES_SERVERSTATUSDATATYPE];
value->value.arrayLength = -1;
value->value.data = status;
@@ -133,6 +134,9 @@ static UA_StatusCode readStatus(void *handle, UA_Boolean sourceTimeStamp, UA_Dat
}
static void releaseStatus(void *handle, UA_DataValue *value) {
UA_free(value->value.data);
value->value.data = UA_NULL;
value->hasValue = UA_FALSE;
UA_DataValue_deleteMembers(value);
}
@@ -290,7 +294,7 @@ UA_Server * UA_Server_new(void) {
server->endpointDescriptions = endpoint;
server->endpointDescriptionsSize = 1;
}
}
#define MAXCHANNELCOUNT 100
#define STARTCHANNELID 1
@@ -306,6 +310,45 @@ UA_Server * UA_Server_new(void) {
server->nodestore = UA_NodeStore_new();
/**********************/
/* Server Information */
/**********************/
server->startTime = UA_DateTime_now();
static struct tm ct;
ct.tm_year = (__DATE__[7] - '0') * 1000 + (__DATE__[8] - '0') * 100 + (__DATE__[9] - '0') * 10 + (__DATE__[10] - '0')- 1900;
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;
/**************/
/* References */
/**************/
+1 -51
View File
@@ -440,60 +440,10 @@ UA_StatusCode UA_Server_run(UA_Server *server, UA_UInt16 nThreads, UA_Boolean *r
UA_Server_addRepeatedWorkItem(server, &processDelayed, 10000000, UA_NULL);
#endif
// 2a) Start the networklayers
// 2) Start the networklayers
for(UA_Int32 i=0;i<server->nlsSize;i++)
server->nls[i].start(server->nls[i].nlHandle, &server->logger);
// 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