# HG changeset patch
# User rosfran
# Date 1160603187 -3600
# Node ID 081274382473b4ff09fd77d9f7526e9a7f803e74
# Parent  53e90bebcb7258486cb20ea0ea459618e66f95e2
[svn r30] Some fixes to the string list - append_uint64 couldn't put the right MythTV offset format.

diff -r 53e90bebcb72 -r 081274382473 gmyth/src/gmyth_socket.c
--- a/gmyth/src/gmyth_socket.c	Mon Oct 09 19:31:49 2006 +0100
+++ b/gmyth/src/gmyth_socket.c	Wed Oct 11 22:46:27 2006 +0100
@@ -125,7 +125,6 @@
     g_static_mutex_lock( &mutex );
 
     gethostname(localhostname, 1024);
-
     gint err = gmyth_socket_toaddrinfo( localhostname, -1,  &addr_info_data );
 
     addr_info0 = addr_info_data;
@@ -149,11 +148,11 @@
 
     if ( found_addr == FALSE ) {
 	    g_warning("[%s] Could not determine the local hostname address. Setting to %s\n",
-                    __FUNCTION__, localaddr );
-    	if ( localaddr != NULL )
-	        str = g_string_assign( str, localaddr );
-    	else
-	        str = g_string_assign( str, "127.0.0.1" );
+                    __FUNCTION__, localhostname );
+    	//if ( localaddr != NULL )
+	//        str = g_string_assign( str, localaddr );
+    	//else
+	str = g_string_assign( str, g_strdup( localhostname ) );
     }
 
     g_static_mutex_unlock( &mutex );
@@ -331,7 +330,7 @@
  * @param command The string command to be sent.
  */
 gboolean
-gmyth_socket_send_command(GMythSocket *gmyth_socket, GString *command) 
+gmyth_socket_send_command(GMythSocket *gmyth_socket, const GString *command) 
 {
     gboolean ret = TRUE;
 
@@ -342,14 +341,14 @@
 
     gsize bytes_written = 0;
 
-    if( command == NULL || ( command->len <= 0 ) ) {
+    if( command == NULL || ( command->len <= 0 ) || command->str == NULL ) {
 		g_warning ("[%s] Invalid NULL command parameter!\n", __FUNCTION__);
 		ret = FALSE;
 		goto done;
     }
 
     g_static_mutex_lock( &mutex );
-    g_debug ("[%s] Sending command to backend: %s\n", __FUNCTION__, command->str);
+    g_print ("[%s] Sending command to backend: %s\n", __FUNCTION__, command->str);
 
     /*
        io_cond = g_io_channel_get_buffer_condition( gmyth_socket->sd_io_ch );
@@ -650,6 +649,8 @@
 
     g_static_mutex_unlock( &mutex );
 
+    g_print( "[%s]\t\tSending the String list = %s\n", __FUNCTION__, str_array );
+
     // Sends message to backend	
     // TODO: implement looping to send remaining data, and add timeout testing!
     gmyth_socket_send_command(gmyth_socket, g_string_new(str_array));
diff -r 53e90bebcb72 -r 081274382473 gmyth/src/gmyth_socket.h
--- a/gmyth/src/gmyth_socket.h	Mon Oct 09 19:31:49 2006 +0100
+++ b/gmyth/src/gmyth_socket.h	Wed Oct 11 22:46:27 2006 +0100
@@ -87,7 +87,7 @@
 gboolean        gmyth_socket_is_able_to_write (GMythSocket *gmyth_socket );
 
 gboolean        gmyth_socket_send_command (GMythSocket *gmyth_socket, 
-                                           GString *command);
+                                           const GString *command);
 GString *       gmyth_socket_receive_response (GMythSocket *gmyth_socket);
 int             gmyth_socket_sendreceive_stringlist (GMythSocket * gmyth_socket, 
                                                      GMythStringList *str_list);
diff -r 53e90bebcb72 -r 081274382473 gmyth/src/gmyth_stringlist.c
--- a/gmyth/src/gmyth_stringlist.c	Mon Oct 09 19:31:49 2006 +0100
+++ b/gmyth/src/gmyth_stringlist.c	Wed Oct 11 22:46:27 2006 +0100
@@ -81,8 +81,7 @@
 GMythStringList *
 gmyth_string_list_new ()
 {
-    GMythStringList *gmyth_string_list = GMYTH_STRING_LIST (g_object_new(GMYTH_STRING_LIST_TYPE, NULL));
-
+    GMythStringList *gmyth_string_list = GMYTH_STRING_LIST (g_object_new (GMYTH_STRING_LIST_TYPE, NULL));
     return gmyth_string_list;
 }
 
@@ -115,26 +114,30 @@
 GString*
 gmyth_string_list_append_uint64 ( GMythStringList *strlist, const guint64 value)
 {
-	GString *tmp_str = g_string_new ("");	
+	GString *tmp_str1 = g_string_new ("");
+	GString *tmp_str2 = g_string_new ("");
 
-	glong l2 = ( (guint64)(value) & 0xffffffffLL );
-	glong l1 = ( ((guint64)(value) >> 32 ) & 0xffffffffLL );
+	glong l2 = ( (guint64)value & 0xffffffff  );
+	glong l1 = ( (guint64)value >> 32  );
   
 	/* high order part of guint64 value */
-	g_string_printf (tmp_str, "%ld", l1);
+	g_string_printf (tmp_str1, "%ld", l1);
 	
-	g_debug( "[%s] uint64 (high) = %s\n", __FUNCTION__, tmp_str->str );
+	g_debug( "[%s] uint64 (high) = %s\n", __FUNCTION__, tmp_str1->str );
 
-	gmyth_string_list_append_string (strlist, tmp_str);
+	//gmyth_string_list_append_string (strlist, tmp_str1);
+	strlist->glist = g_list_append( strlist->glist, tmp_str1 );
 
  	/* low order part of guint64 value */
-	g_string_printf (tmp_str, "%ld", l2);	
+	g_string_printf (tmp_str2, "%ld", l2);
 
-	g_debug( "[%s] uint64 (low) = %s\n", __FUNCTION__, tmp_str->str );
+	g_debug( "[%s] uint64 (low) = %s\n", __FUNCTION__, tmp_str2->str );
 
-	gmyth_string_list_append_string (strlist, tmp_str);
+	strlist->glist = g_list_append( strlist->glist, tmp_str2 );
 
-	return tmp_str;	
+	//gmyth_string_list_append_string (strlist, tmp_str2);
+
+	return tmp_str2;	
 }
 
 /** Appends a char array to the string list.
@@ -195,7 +198,7 @@
 
 	g_return_val_if_fail( tmp_str != NULL && tmp_str->str != NULL, 0 );
 	
-	return (gint) ( 0x00000000ffffffffL & g_ascii_strtoull ( tmp_str->str, NULL, 0 ) );
+	return (gint) ( 0x00000000ffffffffL & g_ascii_strtoull ( tmp_str->str, NULL, 10 ) );
 }
 
 /** Gets a guint64 value from the string list at the given position.
@@ -220,8 +223,10 @@
 	
 	glong l1 = (glong)g_ascii_strtoull (tmp_str1->str, NULL, 10);
 	glong l2 = (glong)g_ascii_strtoull (tmp_str2->str, NULL, 10);
+
+	g_print ( "[%s]\t[l1 == %ld, l2 == %ld]\n", __FUNCTION__, l1, l2 );
 	
-	ret_value = ((guint64)(l2) & 0xffffffffLL) | ((guint64)(l1) << 32);
+	ret_value = ((guint64)(l2) /*& 0xffffffff*/) | ((guint64)l1 << 32);
   
 	g_debug( "[%s] returning uint64 value = %llu\n", __FUNCTION__, ret_value );	
 	
@@ -246,14 +251,15 @@
 }
 
 
+#if 0
 static void
 gmyth_string_list_clear_element( GString *str_elem, void *data_aux )
 {
 	if ( str_elem != NULL ) {
-		g_string_free( str_elem, FALSE );
-		str_elem = NULL;
+		g_string_free( str_elem, TRUE );
 	}
 }
+#endif
 
 /** Removes all strings from the string list.
  * 
@@ -263,7 +269,7 @@
 gmyth_string_list_clear_all ( GMythStringList *strlist )
 {
 	if ( strlist != NULL && strlist->glist ) {
-	        g_list_foreach( strlist->glist, (GFunc)gmyth_string_list_clear_element, NULL );
+	        //g_list_foreach( strlist->glist, (GFunc)gmyth_string_list_clear_element, NULL );
 		g_list_free (strlist->glist);
 		strlist->glist = NULL;
 	}
diff -r 53e90bebcb72 -r 081274382473 gmyth/src/gmyth_stringlist.h
--- a/gmyth/src/gmyth_stringlist.h	Mon Oct 09 19:31:49 2006 +0100
+++ b/gmyth/src/gmyth_stringlist.h	Wed Oct 11 22:46:27 2006 +0100
@@ -70,7 +70,7 @@
 
 GType               gmyth_string_list_get_type (void);
 
-GMythStringList *   gmyth_string_list_new ();
+GMythStringList *   gmyth_string_list_new (void);
 
 void                gmyth_string_list_clear_all (GMythStringList *strlist);
 int                 gmyth_string_list_length (GMythStringList *strlist);