Pārlūkot izejas kodu

added more informative subscribing log messages

Sebastian Vendt 5 gadi atpakaļ
vecāks
revīzija
f495d5992c

+ 1 - 1
CoffeeCode/buildno

@@ -1 +1 @@
-358
+359

+ 1 - 1
CoffeeCode/coffee.cpp

@@ -103,7 +103,7 @@ void *coffeeThread(void *threadid) {
 
 	checkDescaling();
 
-	event_subscribe("terminate", &coffeeTerminate);
+	event_subscribe("terminate", &coffeeTerminate, "coffee.cpp");
 
 	logger(V_BREW, "Determining inital state\n");
 	//determine inital state

+ 5 - 5
CoffeeCode/display2.cpp

@@ -383,11 +383,11 @@ void displayInit(void) {
 	if (!tmp || tmp >= lang_last)
 		tmp = DEFAULT_LANG;
 	displaySetLang((display_lang_t) tmp);
-	event_subscribe("statechange", &displayStateUpdated);
-	event_subscribe("modechange", &displayModeUpdated);
-	event_subscribe("pagechange", &displayPageUpdated);
-	event_subscribe("terminate", &displayTerminate);
-	event_subscribe("descaling", &displayDescaling);
+	event_subscribe("statechange", &displayStateUpdated, "display.cpp");
+	event_subscribe("modechange", &displayModeUpdated, "display.cpp");
+	event_subscribe("pagechange", &displayPageUpdated, "display.cpp");
+	event_subscribe("terminate", &displayTerminate, "display.cpp");
+	event_subscribe("descaling", &displayDescaling, "display.cpp");
 
 	logger(V_BASIC, "display2.cpp Initialized display with a refresh rate of %d Hz\n",
 				refresh_std);

+ 3 - 2
CoffeeCode/events.cpp

@@ -98,9 +98,10 @@ void addSubscriber(events_t *event, void (*handler)(event_t *)) {
  * Adds a subscriber to an event
  * @param event Target event name
  * @param handler Event handler
+ * @param subscriber name of the subscribing process
  */
 
-void event_subscribe(const char *event, void (*handler)(event_t *)) {
+void event_subscribe(const char *event, void (*handler)(event_t *), const char *subscriber) {
 	subscribeMutex.lock();
 	events_t * subscribeEvent = event_find(event);
 	if(!subscribeEvent){//create new Event
@@ -117,7 +118,7 @@ void event_subscribe(const char *event, void (*handler)(event_t *)) {
 			firstEvent = subscribeEvent;
 	}
 	addSubscriber(subscribeEvent, handler);
-	logger(V_HAL, "New subscriber to event \"%s\"\n", event);
+	logger(V_HAL, "%s subscribed to event \"%s\"\n", subscriber, event);
 	subscribeMutex.unlock();
 }
 

+ 1 - 2
CoffeeCode/events.h

@@ -15,8 +15,7 @@ struct event_t {
 	void *data = NULL;
 	int len = 0;
 };
-
-void event_subscribe(const char *event, void (*handler)(event_t *));
+void event_subscribe(const char *event, void (*handler)(event_t *), const char *subscriber);
 void event_trigger(event_t *event);
 void event_trigger(char *event);
 void event_trigger(const char *event);

+ 1 - 1
CoffeeCode/hal.cpp

@@ -131,7 +131,7 @@ void halInit(void) {
 	flagIgnoreRlsInt0 = false;
 	flagIgnoreRlsInt1 = false;
 
-	event_subscribe("terminate", &halTerminate);
+	event_subscribe("terminate", &halTerminate, "hal.cpp");
 
 	if (wiringPiISR(PIN_INT0, INT_EDGE_BOTH, &halInt0) < 0) {
 		logger_error("Unable to setup ISR0: %s\n", strerror(errno));

+ 1 - 1
CoffeeCode/openhab.cpp

@@ -137,7 +137,7 @@ void *httpTimerHandler(void *threadid) {
 }
 
 void openhabInit(void) {
-	event_subscribe("statechange", &openhabStateUpdated);
+	event_subscribe("statechange", &openhabStateUpdated, "openhab.cpp");
 	logger(V_BASIC, "Initialized OpenHAB state updater with target %s:%d\n",
 	OPENHAB_IP, OPENHAB_PORT);
 }

+ 1 - 1
CoffeeCode/server.cpp

@@ -90,7 +90,7 @@ void* serverThread(void* threadid) {
 		pthread_exit(0);
 	}
 
-	event_subscribe("terminate", &serverTerminate);
+	event_subscribe("terminate", &serverTerminate, "server.cpp");
 	logger(V_BASIC, "Now listening for commands on port %d\n", SERVER_PORT);
 
 	// socket address used to store client address