# HG changeset patch # User rosfran # Date 1161380884 -3600 # Node ID a615ba8f8804b8e8f63064b926b7daef83fa53f9 # Parent c71d37b9373487a45e1d0bc51508a420f318974e [svn r36] Some fixes on the myth file transfer offset number representation. diff -r c71d37b93734 -r a615ba8f8804 gmyth/src/gmyth_stringlist.c --- a/gmyth/src/gmyth_stringlist.c Wed Oct 18 23:45:17 2006 +0100 +++ b/gmyth/src/gmyth_stringlist.c Fri Oct 20 22:48:04 2006 +0100 @@ -141,6 +141,41 @@ return tmp_str2; } +/** Appends a gint64 to the string list. + * + * @param strlist The GMythStringList instance. + * @param value The gint64 to be appended. + * + * @return The appended gint64 converted to a GString object. + */ +GString* +gmyth_string_list_append_int64 ( GMythStringList *strlist, const gint64 value) +{ + GString *tmp_str1 = g_string_new (""); + GString *tmp_str2 = g_string_new (""); + g_print( "[%s]\tseek value = %llu.\n", __FUNCTION__, value ); + + glong l2 = ( (gint64)value & 0xffffffff ); + glong l1 = ( (gint64)value >> 32 ); + + /* high order part of gint64 value */ + g_string_printf (tmp_str1, "%ld", l1); + + g_debug( "[%s] int64 (high) = %s\n", __FUNCTION__, tmp_str1->str ); + + //gmyth_string_list_append_string (strlist, tmp_str1); + strlist->glist = g_list_append( strlist->glist, tmp_str1 ); + + /* low order part of gint64 value */ + g_string_printf (tmp_str2, "%ld", l2); + + g_debug( "[%s] int64 (low) = %s\n", __FUNCTION__, tmp_str2->str ); + + strlist->glist = g_list_append( strlist->glist, tmp_str2 ); + + return tmp_str2; +} + /** Appends a char array to the string list. * * @param strlist The GMythStringList instance. @@ -199,7 +234,7 @@ g_return_val_if_fail( tmp_str != NULL && tmp_str->str != NULL, 0 ); - return (gint) ( 0x00000000ffffffffL & g_ascii_strtoull ( tmp_str->str, NULL, 10 ) ); + return (gint) ( /* 0x00000000ffffffffL & (gint64)*/g_ascii_strtoull ( tmp_str->str, NULL, 10 ) ); } /** Gets a guint64 value from the string list at the given position. @@ -230,9 +265,9 @@ g_print( "[%s] seek low bytes = %s\n", __FUNCTION__, tmp_str2->str ); } - guint64 l1 = ( (guint64)g_ascii_strtoull (tmp_str1->str, NULL, 10) & 0xffffffff ); + guint64 l1 = ( (guint64)g_ascii_strtoull (tmp_str1->str, NULL, 10) /*& 0xffffffff*/ ); if ( tmp_str2 != NULL && tmp_str2->str != NULL && strlen(tmp_str2->str) > 0 ) { - l2 = ( (guint64)g_ascii_strtoull (tmp_str2->str, NULL, 10) & 0xffffffff ); + l2 = ( (guint64)g_ascii_strtoull (tmp_str2->str, NULL, 10) /*& 0xffffffff*/ ); } else { l2 = l1; l1 = 0; @@ -247,6 +282,52 @@ return ret_value; } +/** Gets a gint64 value from the string list at the given position. + * According to the Mythtv protocol, the 64 bits value is formed by + * two strings. + * + * @param strlist The GMythStringList instance. + * @param index the index of the first string forming the 64 bits value. + * Index starts with zero. + * @return The gint64 value. + */ +gint64 +gmyth_string_list_get_int64 ( GMythStringList *strlist, const gint index ) +{ + //TODO: Create static method check_index() + gint64 ret_value = 0; + gint64 l2 = 0; + + g_return_val_if_fail( strlist != NULL, 0 ); + + const GString *tmp_str1 = (GString *) g_list_nth_data (strlist->glist, index); + const GString *tmp_str2 = (GString *) g_list_nth_data (strlist->glist, index+1); + + if ( tmp_str1 != NULL ) + g_print( "[%s] seek high bytes = %s\n", __FUNCTION__, tmp_str1->str ); + if ( tmp_str2 == NULL || strlen( tmp_str2->str ) > 0 ) { + } else { + g_print( "[%s] seek low bytes = %s\n", __FUNCTION__, tmp_str2->str ); + } + + gint64 l1 = ( (guint64)g_ascii_strtoull (tmp_str1->str, NULL, 10) /*& 0xffffffff*/ ); + if ( tmp_str2 != NULL && tmp_str2->str != NULL && strlen(tmp_str2->str) > 0 ) { + l2 = ( (gint64)g_ascii_strtoull (tmp_str2->str, NULL, 10) /*& 0xffffffff*/ ); + } else { + l2 = l1; + l1 = 0; + } + + g_print ( "[%s]\t[l1 == %lld, l2 == %lld]\n", __FUNCTION__, l1, l2 ); + + ret_value = ((gint64)(l2) /*& 0xffffffff*/) | ((gint64)l1 << 32); + + g_debug( "[%s] returning int64 value = %lld\n", __FUNCTION__, ret_value ); + + return ret_value; +} + + /** Gets a string from the string list at the given position. * * @param strlist The GMythStringList instance. diff -r c71d37b93734 -r a615ba8f8804 gmyth/src/gmyth_util.c --- a/gmyth/src/gmyth_util.c Wed Oct 18 23:45:17 2006 +0100 +++ b/gmyth/src/gmyth_util.c Fri Oct 20 22:48:04 2006 +0100 @@ -111,18 +111,18 @@ * * @param strlist the string list of mythprotocol values * @param offset the list node offset of the long long variable - * @return guint64 the long long converted value + * @return gint64 the long long converted value */ -guint64 +gint64 gmyth_util_decode_long_long(GMythStringList *strlist, guint offset) { - guint64 ret_value = 0LL; + gint64 ret_value = 0LL; g_return_val_if_fail( strlist != NULL, ret_value ); - if ( offset < gmyth_string_list_length( strlist )) - g_printerr( "[%s] Offset is lower than the Stringlist (offset = %d)!\n", + if ( offset > gmyth_string_list_length( strlist )) + g_printerr( "[%s] Offset is greater than the Stringlist (offset = %d)!\n", __FUNCTION__, offset ); g_return_val_if_fail( offset < gmyth_string_list_length( strlist ), ret_value ); @@ -130,9 +130,10 @@ gint l1 = gmyth_string_list_get_int( strlist, offset ); gint l2 = gmyth_string_list_get_int( strlist, offset + 1 ); - ret_value = ((guint64)(l2) & 0xffffffffLL) | ((guint64)(l1) << 32); + ret_value = (l2 /*& 0xffffffffLL*/) | ( (gint64)l1 << 32 ); return ret_value; } + diff -r c71d37b93734 -r a615ba8f8804 gmyth/src/gmyth_util.h --- a/gmyth/src/gmyth_util.h Wed Oct 18 23:45:17 2006 +0100 +++ b/gmyth/src/gmyth_util.h Fri Oct 20 22:48:04 2006 +0100 @@ -38,7 +38,7 @@ GString * gmyth_util_time_to_isoformat(time_t time_value); GString * gmyth_util_time_to_string (time_t time_value); time_t gmyth_util_string_to_time (GString* time_str); -guint64 gmyth_util_decode_long_long (GMythStringList *strlist, +gint64 gmyth_util_decode_long_long (GMythStringList *strlist, guint offset); G_END_DECLS