Bläddra i källkod

added logger initialisation to the server struct

Julius Pfrommer 10 år sedan
förälder
incheckning
f0071936fd
5 ändrade filer med 26 tillägg och 17 borttagningar
  1. 4 2
      examples/opcuaServer.c
  2. 7 1
      src/server/ua_server.h
  3. 1 1
      src/server/ua_services_session.c
  4. 2 1
      src/ua_transport_binary.c
  5. 12 12
      src/util/ua_log.h

+ 4 - 2
examples/opcuaServer.c

@@ -49,8 +49,10 @@ int main(int argc, char** argv) {
 	signal(SIGINT, stopHandler);
 
 	UA_Server server;
-	UA_alloc((void**)&server.application, sizeof(UA_Application));
-	UA_Application_init(server.application);
+	UA_alloc((void**)&server.applications, sizeof(UA_Application));
+	server.applicationsSize = 1;
+	server.logger_init = Logger_Stdout_init;
+	UA_Application_init(server.applications);
 	
 	NL_data* nl = NL_init(&NL_Description_TcpBinary, 16664);
 	UA_String endpointUrl;

+ 7 - 1
src/server/ua_server.h

@@ -7,7 +7,13 @@ struct UA_Server;
 typedef struct UA_Server {
 	// SL_ChannelManager *cm;
 	// UA_SessionManager sm;
-	UA_Application *application;
+	UA_UInt32 applicationsSize;
+	UA_Application *applications;
+	/** Every thread needs to init its logger variable. The server-object stores a
+		function pointer and logger configuration for that purpose. */
+	void (*logger_init)(void *config);
+	/** Configuration for the logger */
+	void *logger_configuration;
 } UA_Server;
 
 #endif /* UA_SERVER_H_ */

+ 1 - 1
src/server/ua_services_session.c

@@ -11,7 +11,7 @@ UA_Int32 Service_CreateSession(SL_Channel *channel, UA_Server *server, const UA_
 	UA_SessionManager_getSessionTimeout(&timeout);
 	UA_Session_new(&newSession);
 	//TODO get maxResponseMessageSize
-	UA_Session_setApplicationPointer(newSession, server->application); // todo: select application according to the endpointurl in the request
+	UA_Session_setApplicationPointer(newSession, &server->applications[0]); // todo: select application according to the endpointurl in the request
 	UA_Session_init(newSession, (UA_String*)&request->sessionName,
 	request->requestedSessionTimeout,
 	request->maxResponseMessageSize,

+ 2 - 1
src/ua_transport_binary.c

@@ -3,6 +3,7 @@
 #include "ua_transport_binary.h"
 #include "ua_transport.h"
 #include "ua_transport_binary_secure.h"
+#include "ua_log.h"
 
 static UA_Int32 TL_handleHello(UA_TL_Connection *connection, const UA_ByteString* msg, UA_UInt32* pos){
 	UA_Int32 retval = UA_SUCCESS;
@@ -12,7 +13,7 @@ static UA_Int32 TL_handleHello(UA_TL_Connection *connection, const UA_ByteString
 
 	UA_TL_Connection_getState(connection, &connectionState);
 	if (connectionState == CONNECTIONSTATE_CLOSED){
-		DBG_VERBOSE(printf("TL_handleHello - extracting header information \n"));
+		LOG_DEBUG(UA_LOGGERCATEGORY_CONNECTION, "TL_handleHello - extracting header information",1);
 		UA_OPCUATcpHelloMessage_decodeBinary(msg,pos,&helloMessage);
 
 		UA_TL_Connection_configByHello(connection, &helloMessage);

+ 12 - 12
src/util/ua_log.h

@@ -36,39 +36,39 @@ typedef struct UA_Logger {
 static UA_Logger logger;
 
 #if UA_LOGLEVEL <= 100
-#define LOG_TRACE(CATEGORY, MSG, ...) do{ logger.log_trace(CATEGORY, MSG, __VA_ARGS__); } while
+#define LOG_TRACE(CATEGORY, MSG, ...) do{ logger.log_trace(CATEGORY, MSG, __VA_ARGS__); } while(0)
 #else
-#define LOG_TRACE(CATEGORY, MSG, ...) do {} while;
+#define LOG_TRACE(CATEGORY, MSG, ...) do {} while(0)
 #endif
 
 #if UA_LOGLEVEL <= 200
-#define LOG_DEBUG(CATEGORY, MSG, ...) do{ logger.log_debug(CATEGORY, MSG, __VA_ARGS__); } while
+#define LOG_DEBUG(CATEGORY, MSG, ...) do{ logger.log_debug(CATEGORY, MSG, __VA_ARGS__); } while(0)
 #else
-#define LOG_DEBUG(CATEGORY, MSG, ...) do {} while;
+#define LOG_DEBUG(CATEGORY, MSG, ...) do {} while(0)
 #endif
 
 #if UA_LOGLEVEL <= 300
-#define LOG_INFO(CATEGORY, MSG, ...) do{ logger.log_info(CATEGORY, MSG, __VA_ARGS__); } while
+#define LOG_INFO(CATEGORY, MSG, ...) do{ logger.log_info(CATEGORY, MSG, __VA_ARGS__); } while(0)
 #else
-#define LOG_INFO(CATEGORY, MSG, ...) do {} while;
+#define LOG_INFO(CATEGORY, MSG, ...) do {} while(0)
 #endif
 
 #if UA_LOGLEVEL <= 400
-#define LOG_WARNING(CATEGORY, MSG, ...) do{ logger.log_warning(CATEGORY, MSG, __VA_ARGS__); } while
+#define LOG_WARNING(CATEGORY, MSG, ...) do{ logger.log_warning(CATEGORY, MSG, __VA_ARGS__); } while(0)
 #else
-#define LOG_WARNING(CATEGORY, MSG, ...) do {} while;
+#define LOG_WARNING(CATEGORY, MSG, ...) do {} while(0)
 #endif
 
 #if UA_LOGLEVEL <= 500
-#define LOG_ERROR(CATEGORY, MSG, ...) do{ logger.log_error(CATEGORY, MSG, __VA_ARGS__); } while
+#define LOG_ERROR(CATEGORY, MSG, ...) do{ logger.log_error(CATEGORY, MSG, __VA_ARGS__); } while(0)
 #else
-#define LOG_ERROR(CATEGORY, MSG, ...) do {} while;
+#define LOG_ERROR(CATEGORY, MSG, ...) do {} while(0)
 #endif
 
 #if UA_LOGLEVEL <= 600
-#define LOG_FATAL(CATEGORY, MSG, ...) do{ logger.log_fatal(CATEGORY, MSG, __VA_ARGS__); } while
+#define LOG_FATAL(CATEGORY, MSG, ...) do{ logger.log_fatal(CATEGORY, MSG, __VA_ARGS__); } while(0)
 #else
-#define LOG_FATAL(CATEGORY, MSG, ...) do {} while;
+#define LOG_FATAL(CATEGORY, MSG, ...) do {} while(0)
 #endif
 
 #endif /* UA_LOG_H_ */