[svn r36] Some fixes on the myth file transfer offset number representation. trunk
authorrosfran
Fri Oct 20 22:48:04 2006 +0100 (2006-10-20)
branchtrunk
changeset 35a615ba8f8804
parent 34 c71d37b93734
child 36 a6559a231dd2
[svn r36] Some fixes on the myth file transfer offset number representation.
gmyth/src/gmyth_stringlist.c
gmyth/src/gmyth_util.c
gmyth/src/gmyth_util.h
     1.1 --- a/gmyth/src/gmyth_stringlist.c	Wed Oct 18 23:45:17 2006 +0100
     1.2 +++ b/gmyth/src/gmyth_stringlist.c	Fri Oct 20 22:48:04 2006 +0100
     1.3 @@ -141,6 +141,41 @@
     1.4  	return tmp_str2;	
     1.5  }
     1.6  
     1.7 +/** Appends a gint64 to the string list.
     1.8 + * 
     1.9 + * @param strlist The GMythStringList instance.
    1.10 + * @param value The gint64 to be appended.
    1.11 + * 
    1.12 + * @return The appended gint64 converted to a GString object.
    1.13 + */
    1.14 +GString*
    1.15 +gmyth_string_list_append_int64 ( GMythStringList *strlist, const gint64 value)
    1.16 +{
    1.17 +	GString *tmp_str1 = g_string_new ("");
    1.18 +	GString *tmp_str2 = g_string_new ("");
    1.19 +	g_print( "[%s]\tseek value = %llu.\n", __FUNCTION__, value );
    1.20 +
    1.21 +	glong l2 = ( (gint64)value & 0xffffffff  );
    1.22 +	glong l1 = ( (gint64)value >> 32 );
    1.23 +  
    1.24 +	/* high order part of gint64 value */
    1.25 +	g_string_printf (tmp_str1, "%ld", l1);
    1.26 +	
    1.27 +	g_debug( "[%s] int64 (high) = %s\n", __FUNCTION__, tmp_str1->str );
    1.28 +
    1.29 +	//gmyth_string_list_append_string (strlist, tmp_str1);
    1.30 +	strlist->glist = g_list_append( strlist->glist, tmp_str1 );
    1.31 +
    1.32 + 	/* low order part of gint64 value */
    1.33 +	g_string_printf (tmp_str2, "%ld", l2);
    1.34 +
    1.35 +	g_debug( "[%s] int64 (low) = %s\n", __FUNCTION__, tmp_str2->str );
    1.36 +
    1.37 +	strlist->glist = g_list_append( strlist->glist, tmp_str2 );
    1.38 +
    1.39 +	return tmp_str2;
    1.40 +}
    1.41 +
    1.42  /** Appends a char array to the string list.
    1.43   * 
    1.44   * @param strlist The GMythStringList instance.
    1.45 @@ -199,7 +234,7 @@
    1.46  
    1.47  	g_return_val_if_fail( tmp_str != NULL && tmp_str->str != NULL, 0 );
    1.48  	
    1.49 -	return (gint) ( 0x00000000ffffffffL & g_ascii_strtoull ( tmp_str->str, NULL, 10 ) );
    1.50 +	return (gint) ( /* 0x00000000ffffffffL &  (gint64)*/g_ascii_strtoull ( tmp_str->str, NULL, 10 ) );
    1.51  }
    1.52  
    1.53  /** Gets a guint64 value from the string list at the given position.
    1.54 @@ -230,9 +265,9 @@
    1.55  		g_print( "[%s] seek low bytes = %s\n", __FUNCTION__, tmp_str2->str );
    1.56  	}
    1.57  	
    1.58 -	guint64 l1 = ( (guint64)g_ascii_strtoull (tmp_str1->str, NULL, 10) & 0xffffffff  );
    1.59 +	guint64 l1 = ( (guint64)g_ascii_strtoull (tmp_str1->str, NULL, 10) /*& 0xffffffff*/  );
    1.60  	if ( tmp_str2 != NULL && tmp_str2->str != NULL && strlen(tmp_str2->str) > 0 ) {
    1.61 -		l2 = ( (guint64)g_ascii_strtoull (tmp_str2->str, NULL, 10) & 0xffffffff  );
    1.62 +		l2 = ( (guint64)g_ascii_strtoull (tmp_str2->str, NULL, 10) /*& 0xffffffff*/  );
    1.63  	} else {
    1.64  		l2 = l1;
    1.65  		l1 = 0;
    1.66 @@ -247,6 +282,52 @@
    1.67  	return ret_value;
    1.68  }
    1.69  
    1.70 +/** Gets a gint64 value from the string list at the given position.
    1.71 + * According to the Mythtv protocol, the 64 bits value is formed by
    1.72 + * two strings.
    1.73 + * 
    1.74 + * @param strlist The GMythStringList instance.
    1.75 + * @param index the index of the first string forming the 64 bits value. 
    1.76 + * Index starts with zero.
    1.77 + * @return The gint64 value.
    1.78 + */
    1.79 +gint64
    1.80 +gmyth_string_list_get_int64 ( GMythStringList *strlist, const gint index )
    1.81 +{
    1.82 +	//TODO: Create static method check_index()
    1.83 +	gint64 ret_value = 0;
    1.84 +	gint64 l2 = 0;
    1.85 +
    1.86 +	g_return_val_if_fail( strlist != NULL, 0 );
    1.87 +  
    1.88 +	const GString *tmp_str1 = (GString *) g_list_nth_data (strlist->glist, index);
    1.89 +	const GString *tmp_str2 = (GString *) g_list_nth_data (strlist->glist, index+1);
    1.90 +
    1.91 +	if ( tmp_str1 != NULL )
    1.92 +		g_print( "[%s] seek high bytes = %s\n", __FUNCTION__, tmp_str1->str );
    1.93 +	if ( tmp_str2 == NULL || strlen( tmp_str2->str ) > 0 ) {
    1.94 +	} else {
    1.95 +		g_print( "[%s] seek low bytes = %s\n", __FUNCTION__, tmp_str2->str );
    1.96 +	}
    1.97 +	
    1.98 +	gint64 l1 = ( (guint64)g_ascii_strtoull (tmp_str1->str, NULL, 10) /*& 0xffffffff*/  );
    1.99 +	if ( tmp_str2 != NULL && tmp_str2->str != NULL && strlen(tmp_str2->str) > 0 ) {
   1.100 +		l2 = ( (gint64)g_ascii_strtoull (tmp_str2->str, NULL, 10) /*& 0xffffffff*/  );
   1.101 +	} else {
   1.102 +		l2 = l1;
   1.103 +		l1 = 0;
   1.104 +	}
   1.105 +
   1.106 +	g_print ( "[%s]\t[l1 == %lld, l2 == %lld]\n", __FUNCTION__, l1, l2 );
   1.107 +	
   1.108 +	ret_value = ((gint64)(l2) /*& 0xffffffff*/) | ((gint64)l1 << 32);
   1.109 +  
   1.110 +	g_debug( "[%s] returning int64 value = %lld\n", __FUNCTION__, ret_value );	
   1.111 +	
   1.112 +	return ret_value;
   1.113 +}
   1.114 +
   1.115 +
   1.116  /** Gets a string from the string list at the given position.
   1.117   * 
   1.118   * @param strlist The GMythStringList instance.
     2.1 --- a/gmyth/src/gmyth_util.c	Wed Oct 18 23:45:17 2006 +0100
     2.2 +++ b/gmyth/src/gmyth_util.c	Fri Oct 20 22:48:04 2006 +0100
     2.3 @@ -111,18 +111,18 @@
     2.4   * 
     2.5   * @param strlist the string list of mythprotocol values
     2.6   * @param offset  the list node offset of the long long variable
     2.7 - * @return guint64  the long long converted value
     2.8 + * @return gint64  the long long converted value
     2.9   */
    2.10 -guint64
    2.11 +gint64
    2.12  gmyth_util_decode_long_long(GMythStringList *strlist, guint offset) 
    2.13  {
    2.14  
    2.15 -	guint64 ret_value = 0LL;
    2.16 +	gint64 ret_value = 0LL;
    2.17  
    2.18  	g_return_val_if_fail( strlist != NULL, ret_value );
    2.19  
    2.20 -	if ( offset < gmyth_string_list_length( strlist ))
    2.21 -		g_printerr( "[%s] Offset is lower than the Stringlist (offset = %d)!\n", 
    2.22 +	if ( offset > gmyth_string_list_length( strlist ))
    2.23 +		g_printerr( "[%s] Offset is greater than the Stringlist (offset = %d)!\n", 
    2.24                      __FUNCTION__, offset );
    2.25      
    2.26  	g_return_val_if_fail( offset < gmyth_string_list_length( strlist ), ret_value );
    2.27 @@ -130,9 +130,10 @@
    2.28  	gint l1 = gmyth_string_list_get_int( strlist, offset );
    2.29  	gint l2 = gmyth_string_list_get_int( strlist, offset + 1 );
    2.30  
    2.31 -	ret_value = ((guint64)(l2) & 0xffffffffLL) | ((guint64)(l1) << 32);
    2.32 +	ret_value = (l2 /*& 0xffffffffLL*/) | ( (gint64)l1 << 32 );
    2.33  
    2.34  	return ret_value;
    2.35  
    2.36  }
    2.37  
    2.38 +
     3.1 --- a/gmyth/src/gmyth_util.h	Wed Oct 18 23:45:17 2006 +0100
     3.2 +++ b/gmyth/src/gmyth_util.h	Fri Oct 20 22:48:04 2006 +0100
     3.3 @@ -38,7 +38,7 @@
     3.4  GString *   gmyth_util_time_to_isoformat(time_t time_value);
     3.5  GString *   gmyth_util_time_to_string   (time_t time_value);
     3.6  time_t      gmyth_util_string_to_time   (GString* time_str);
     3.7 -guint64     gmyth_util_decode_long_long (GMythStringList *strlist, 
     3.8 +gint64     gmyth_util_decode_long_long (GMythStringList *strlist, 
     3.9                                           guint offset);
    3.10  G_END_DECLS
    3.11