Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Diff of /oggs_app.c [89502e] .. [20e94f] Maximize Restore

  Switch to side-by-side view

--- a/oggs_app.c
+++ b/oggs_app.c
@@ -297,7 +297,7 @@
 	static int timeout;
 	static uint32_t starttimeout;
 	double elapsedTime;
-	int restart;	
+	int restart=0;	
 
 
 
@@ -353,10 +353,15 @@
 			break;
 
 		case CONNECT_SHOUT:
-			SendByte(COM_PORT, CMD_STATUSLED_LEFT | 2);
-			timeout = SHOUT_CONNECT_TIMEOUT;
-			shout_open(shout);
-			*state = CONNECT_SHOUT_WAIT;
+			if(oggs_init_shout() == 1)
+			{			
+				SendByte(COM_PORT, CMD_STATUSLED_LEFT | 2);
+				timeout = SHOUT_CONNECT_TIMEOUT;
+				shout_open(shout);
+				*state = CONNECT_SHOUT_WAIT;
+			} else {
+				*state = ENTER_ERROR;
+			}
 		break;
 
 		case CONNECT_SHOUT_WAIT:
@@ -423,6 +428,11 @@
 				
 		break;
 		case ENTER_ERROR:
+			if(shout_config.enabled)
+			{
+				shout_close(shout);
+				shout_shutdown();
+			}
 			SendByte(COM_PORT, CMD_STATUSLED_LEFT | 4);
 			SendByte(COM_PORT, CMD_ONAIRBLINK | 4 );
 			*state = ERROR;
@@ -453,6 +463,59 @@
 
 }
 
+int oggs_init_shout()
+{
+		shout_init();
+
+		if (!(shout = shout_new())) {
+			fprintf(stderr, "Could not allocate shout_t\n");
+			return -1;
+		}
+
+
+		if (shout_set_host(shout, shout_config.server) != SHOUTERR_SUCCESS) {
+			fprintf(stderr,"Error setting hostname: %s\n", shout_get_error(shout));
+			return -1;
+		}
+
+		if (shout_set_protocol(shout, SHOUT_PROTOCOL_HTTP) != SHOUTERR_SUCCESS) {
+			fprintf(stderr,"Error setting protocol: %s\n", shout_get_error(shout));
+			return -1;
+		}
+
+		if (shout_set_port(shout, shout_config.port) != SHOUTERR_SUCCESS) {
+			fprintf(stderr,"Error setting port: %s\n", shout_get_error(shout));
+			return -1;
+		}
+
+		if (shout_set_password(shout, shout_config.password) != SHOUTERR_SUCCESS) {
+			fprintf(stderr,"Error setting password: %s\n", shout_get_error(shout));
+			return -1;
+		}
+		if (shout_set_mount(shout, shout_config.mountpoint) != SHOUTERR_SUCCESS) {
+			fprintf(stderr,"Error setting mount: %s\n", shout_get_error(shout));
+			return -1;
+		}
+
+		if (shout_set_user(shout, shout_config.username) != SHOUTERR_SUCCESS) {
+			fprintf(stderr,"Error setting user: %s\n", shout_get_error(shout));
+			return -1;
+		}
+
+		if (shout_set_format(shout, SHOUT_FORMAT_OGG) != SHOUTERR_SUCCESS) {
+			fprintf(stderr,"Error setting user: %s\n", shout_get_error(shout));
+			return -1;
+		}
+
+		if (shout_set_nonblocking(shout, 1) != SHOUTERR_SUCCESS) {
+			fprintf(stderr,"Error setting non-blocking mode: %s\n", shout_get_error(shout));
+			return -1;
+		}
+
+		return 1;
+}
+
+
 
 int main(int argc, char *argv[])
 {
@@ -492,52 +555,7 @@
 
 	if(shout_config.enabled)
 	{
-		shout_init();
-
-		if (!(shout = shout_new())) {
-			fprintf(stderr, "Could not allocate shout_t\n");
-			return -1;
-		}
-
-
-		if (shout_set_host(shout, shout_config.server) != SHOUTERR_SUCCESS) {
-			fprintf(stderr,"Error setting hostname: %s\n", shout_get_error(shout));
-			return -1;
-		}
-
-		if (shout_set_protocol(shout, SHOUT_PROTOCOL_HTTP) != SHOUTERR_SUCCESS) {
-			fprintf(stderr,"Error setting protocol: %s\n", shout_get_error(shout));
-			return -1;
-		}
-
-		if (shout_set_port(shout, shout_config.port) != SHOUTERR_SUCCESS) {
-			fprintf(stderr,"Error setting port: %s\n", shout_get_error(shout));
-			return -1;
-		}
-
-		if (shout_set_password(shout, shout_config.password) != SHOUTERR_SUCCESS) {
-			fprintf(stderr,"Error setting password: %s\n", shout_get_error(shout));
-			return -1;
-		}
-		if (shout_set_mount(shout, shout_config.mountpoint) != SHOUTERR_SUCCESS) {
-			fprintf(stderr,"Error setting mount: %s\n", shout_get_error(shout));
-			return -1;
-		}
-
-		if (shout_set_user(shout, shout_config.username) != SHOUTERR_SUCCESS) {
-			fprintf(stderr,"Error setting user: %s\n", shout_get_error(shout));
-			return -1;
-		}
-
-		if (shout_set_format(shout, SHOUT_FORMAT_OGG) != SHOUTERR_SUCCESS) {
-			fprintf(stderr,"Error setting user: %s\n", shout_get_error(shout));
-			return -1;
-		}
-
-		if (shout_set_nonblocking(shout, 1) != SHOUTERR_SUCCESS) {
-			fprintf(stderr,"Error setting non-blocking mode: %s\n", shout_get_error(shout));
-			return -1;
-		}
+
 	}