1.1 --- a/gmyth/src/gmyth_backendinfo.c Tue Jul 03 13:53:26 2007 +0100
1.2 +++ b/gmyth/src/gmyth_backendinfo.c Tue Jul 03 21:20:15 2007 +0100
1.3 @@ -73,6 +73,7 @@
1.4 g_free(backend_info->username);
1.5 g_free(backend_info->password);
1.6 g_free(backend_info->db_name);
1.7 + g_object_unref (backend_info->sock);
1.8
1.9 backend_info->hostname = NULL;
1.10 backend_info->username = NULL;
1.11 @@ -342,3 +343,22 @@
1.12 return
1.13 gmyth_uri_is_local_file(gmyth_backend_info_get_uri(backend_info));
1.14 }
1.15 +
1.16 +GMythSocket*
1.17 +gmyth_backend_info_get_connected_socket (GMythBackendInfo *backend_info)
1.18 +{
1.19 + if (backend_info->sock != NULL) {
1.20 + gboolean res;
1.21 + backend_info->sock = gmyth_socket_new ();
1.22 + res = gmyth_socket_connect_to_backend (socket,
1.23 + backend_info->hostname,
1.24 + backend_info->port,
1.25 + TRUE);
1.26 + if (res == FALSE) {
1.27 + g_object_unref (backend_info->sock);
1.28 + backend_info->sock = NULL;
1.29 + }
1.30 + }
1.31 +
1.32 + return g_object_ref (backend_info->sock);
1.33 +}
2.1 --- a/gmyth/src/gmyth_backendinfo.h Tue Jul 03 13:53:26 2007 +0100
2.2 +++ b/gmyth/src/gmyth_backendinfo.h Tue Jul 03 21:20:15 2007 +0100
2.3 @@ -32,6 +32,7 @@
2.4 #include <glib-object.h>
2.5
2.6 #include "gmyth_uri.h"
2.7 +#include "gmyth_socket.h"
2.8
2.9 G_BEGIN_DECLS
2.10 #define GMYTH_BACKEND_INFO_TYPE \
2.11 @@ -75,6 +76,9 @@
2.12 gint port;
2.13 /** The backend status port for http connection */
2.14 gint status_port;
2.15 +
2.16 + /* Private */
2.17 + GMythSocket *sock;
2.18 };
2.19
2.20
2.21 @@ -105,6 +109,9 @@
2.22 gint gmyth_backend_info_get_port (GMythBackendInfo *backend_info);
2.23 GMythURI* gmyth_backend_info_get_uri (GMythBackendInfo *backend_info);
2.24 gboolean gmyth_backend_info_is_local_file (GMythBackendInfo *backend_info);
2.25 +GMythSocket* gmyth_backend_info_get_connected_socket
2.26 + (GMythBackendInfo *backend_info);
2.27 +
2.28
2.29 G_END_DECLS
2.30 #endif /* __GMYTH_BACKEND_INFO_H__ */
3.1 --- a/gmyth/src/gmyth_scheduler.c Tue Jul 03 13:53:26 2007 +0100
3.2 +++ b/gmyth/src/gmyth_scheduler.c Tue Jul 03 21:20:15 2007 +0100
3.3 @@ -351,7 +351,7 @@
3.4 gmyth_scheduler_get_recorded_info (GMythScheduler *scheduler,
3.5 gint record_id)
3.6 {
3.7 - RecordedInfo *record;
3.8 + RecordedInfo *record = NULL;
3.9 MYSQL_RES *msql_res;
3.10 GString *query_str = g_string_new("");
3.11
3.12 @@ -366,7 +366,7 @@
3.13 if (scheduler->msqlquery == NULL) {
3.14 g_warning("[%s] Scheduler db connection not initialized",
3.15 __FUNCTION__);
3.16 - return -1;
3.17 + return NULL;
3.18 }
3.19
3.20 msql_res =
3.21 @@ -375,7 +375,7 @@
3.22
3.23 if (msql_res == NULL) {
3.24 g_warning("DB retrieval of recording list failed");
3.25 - return -1;
3.26 + return NULL;
3.27 } else {
3.28 MYSQL_ROW row;
3.29 row = mysql_fetch_row(msql_res);
3.30 @@ -734,7 +734,7 @@
3.31 * @param scheduler The GMythScheduler instance.
3.32 * @return gint record_id if success, -1 otherwise
3.33 */
3.34 -static gint
3.35 +static gint
3.36 get_record_id_from_database(GMythScheduler * scheduler)
3.37 {
3.38 gint record_id;
3.39 @@ -756,12 +756,10 @@
3.40 *
3.41 * @param record_id the id of the modified recording.
3.42 */
3.43 -static gboolean
3.44 -update_backend(GMythScheduler * scheduler, gint record_id) // fixme: put
3.45 - // void and
3.46 - // discovery
3.47 - // record_id
3.48 - // inside
3.49 +// fixme: put void and discovery record_id inside
3.50 +static gboolean
3.51 +update_backend (GMythScheduler * scheduler,
3.52 + gint record_id)
3.53 {
3.54 GMythSocket *socket;
3.55 GMythStringList *strlist = gmyth_string_list_new();
3.56 @@ -771,18 +769,16 @@
3.57 g_string_append_printf(datastr, "%d", record_id);
3.58 gmyth_string_list_append_string(strlist, datastr);
3.59
3.60 - socket = gmyth_socket_new();
3.61 - if (gmyth_socket_connect_to_backend
3.62 - (socket, scheduler->backend_info->hostname,
3.63 - scheduler->backend_info->port, TRUE)) {
3.64 + socket = gmyth_backend_info_get_connected_socket (scheduler->backend_info);
3.65 + if (socket != NULL) {
3.66 ret = (gmyth_socket_sendreceive_stringlist(socket, strlist) > 0);
3.67 + g_object_unref (socket);
3.68 } else {
3.69 g_warning("[%s] Connection to backend failed!", __FUNCTION__);
3.70 }
3.71
3.72 g_string_free(datastr, TRUE);
3.73 g_object_unref(strlist);
3.74 -
3.75 return ret;
3.76 }
3.77
4.1 --- a/gmyth/src/gmyth_util.c Tue Jul 03 13:53:26 2007 +0100
4.2 +++ b/gmyth/src/gmyth_util.c Tue Jul 03 21:20:15 2007 +0100
4.3 @@ -430,42 +430,46 @@
4.4 const gchar * filename)
4.5 {
4.6 GMythSocket *socket;
4.7 - gboolean res;
4.8 + gboolean res = FALSE;
4.9
4.10 gmyth_debug("Check if file %s exists", filename);
4.11
4.12 g_return_val_if_fail(backend_info != NULL, FALSE);
4.13 g_return_val_if_fail(filename != NULL, FALSE);
4.14
4.15 - socket = gmyth_socket_new();
4.16 - res = gmyth_socket_connect_to_backend(socket, backend_info->hostname,
4.17 - backend_info->port, TRUE);
4.18 -
4.19 - if (res == TRUE) {
4.20 - GMythStringList *slist;
4.21 - GMythProgramInfo *program = NULL;
4.22 -
4.23 - program = gmyth_program_info_new();
4.24 - program->pathname = g_string_new(filename);
4.25 -
4.26 - slist = gmyth_string_list_new();
4.27 - gmyth_string_list_append_char_array(slist, "QUERY_CHECKFILE");
4.28 -
4.29 - gmyth_program_info_to_string_list(program, slist);
4.30 -
4.31 - gmyth_socket_sendreceive_stringlist(socket, slist);
4.32 -
4.33 - res = (gmyth_string_list_get_int(slist, 0) == 1);
4.34 -
4.35 - g_object_unref(program);
4.36 - g_object_unref(slist);
4.37 -
4.38 - gmyth_socket_close_connection(socket);
4.39 + socket = gmyth_backend_info_get_connected_socket (backend_info);
4.40 + if (socket != NULL) {
4.41 + res = gmyth_util_file_exists_from_socket (socket, filename);
4.42 }
4.43 g_object_unref(socket);
4.44 return res;
4.45 }
4.46
4.47 +gboolean
4.48 +gmyth_util_file_exists_from_socket (GMythSocket *sock,
4.49 + const gchar *filename)
4.50 +{
4.51 + gboolean res;
4.52 + GMythStringList *slist;
4.53 + GMythProgramInfo *program = NULL;
4.54 +
4.55 + program = gmyth_program_info_new();
4.56 + program->pathname = g_string_new(filename);
4.57 +
4.58 + slist = gmyth_string_list_new();
4.59 + gmyth_string_list_append_char_array(slist, "QUERY_CHECKFILE");
4.60 +
4.61 + gmyth_program_info_to_string_list(program, slist);
4.62 + gmyth_socket_sendreceive_stringlist (sock, slist);
4.63 + res = (gmyth_string_list_get_int(slist, 0) == 1);
4.64 +
4.65 + g_object_unref(program);
4.66 + g_object_unref(slist);
4.67 +
4.68 + return res;
4.69 +}
4.70 +
4.71 +
4.72 /**
4.73 * Checks if the given remote file exists, and gets its remote directory.
4.74 *
5.1 --- a/gmyth/src/gmyth_util.h Tue Jul 03 13:53:26 2007 +0100
5.2 +++ b/gmyth/src/gmyth_util.h Tue Jul 03 21:20:15 2007 +0100
5.3 @@ -36,59 +36,38 @@
5.4 #include "gmyth_backendinfo.h"
5.5 #include "gmyth_programinfo.h"
5.6
5.7 -G_BEGIN_DECLS GString *gmyth_util_time_to_isoformat(time_t time_value);
5.8 -GString *gmyth_util_time_to_string(time_t time_value);
5.9 -time_t gmyth_util_string_to_time(GString * time_str);
5.10 +G_BEGIN_DECLS
5.11
5.12 -gchar *gmyth_util_time_to_isoformat_from_time_val_fmt(const gchar
5.13 - *
5.14 - fmt_string,
5.15 - const
5.16 - GTimeVal *
5.17 - time_val);
5.18
5.19 -GTimeVal *gmyth_util_string_to_time_val_fmt(const gchar * fmt_string,
5.20 - const gchar * time_str);
5.21 -
5.22 -GTimeVal *gmyth_util_string_to_time_val(const gchar * time_str);
5.23 -
5.24 -gchar *gmyth_util_time_to_isoformat_from_time_val(const GTimeVal *
5.25 - time);
5.26 -gchar *gmyth_util_time_to_mythformat_from_time_val(const GTimeVal
5.27 - * time);
5.28 -
5.29 -gchar *gmyth_util_time_to_string_only_date(const GTimeVal * time);
5.30 -
5.31 -gchar *gmyth_util_time_to_string_only_time(const GTimeVal * time);
5.32 -
5.33 -gchar *gmyth_util_time_to_string_from_time_val(const GTimeVal *
5.34 - time_val);
5.35 -
5.36 -struct tm *gmyth_util_time_val_to_date(const GTimeVal * time);
5.37 -
5.38 -gboolean gmyth_util_file_exists(GMythBackendInfo * backend_info,
5.39 - const gchar * filename);
5.40 -
5.41 -gboolean gmyth_util_file_exists_and_get_remote_dir(GMythBackendInfo
5.42 - * backend_info,
5.43 - const gchar *
5.44 - filename,
5.45 - gchar **
5.46 - current_dir);
5.47 -
5.48 -gchar *gmyth_util_create_filename(const gint chan_id,
5.49 - const GTimeVal * start_time);
5.50 -
5.51 -GList *gmyth_util_get_channel_list(GMythBackendInfo *
5.52 - backend_info);
5.53 -
5.54 -GSList *gmyth_util_get_all_recordings(GMythBackendInfo *
5.55 - backend_info);
5.56 -
5.57 -GMythProgramInfo *gmyth_util_get_recording_from_channel(GMythBackendInfo *
5.58 - backend_info,
5.59 - const gchar *
5.60 - channel);
5.61 +GString* gmyth_util_time_to_isoformat (time_t time_value);
5.62 +GString* gmyth_util_time_to_string (time_t time_value);
5.63 +time_t gmyth_util_string_to_time (GString *time_str);
5.64 +gchar* gmyth_util_time_to_isoformat_from_time_val_fmt
5.65 + (const gchar *fmt_string,
5.66 + const GTimeVal *time_val);
5.67 +GTimeVal* gmyth_util_string_to_time_val_fmt (const gchar *fmt_string,
5.68 + const gchar *time_str);
5.69 +GTimeVal* gmyth_util_string_to_time_val (const gchar *time_str);
5.70 +gchar* gmyth_util_time_to_isoformat_from_time_val (const GTimeVal *time);
5.71 +gchar* gmyth_util_time_to_mythformat_from_time_val (const GTimeVal *time);
5.72 +gchar* gmyth_util_time_to_string_only_date (const GTimeVal *time);
5.73 +gchar* gmyth_util_time_to_string_only_time (const GTimeVal *time);
5.74 +gchar* gmyth_util_time_to_string_from_time_val (const GTimeVal *time_val);
5.75 +struct tm* gmyth_util_time_val_to_date (const GTimeVal * time);
5.76 +gboolean gmyth_util_file_exists_from_socket (GMythSocket *sock,
5.77 + const gchar *filename);
5.78 +gboolean gmyth_util_file_exists (GMythBackendInfo *backend_info,
5.79 + const gchar * filename);
5.80 +gboolean gmyth_util_file_exists_and_get_remote_dir (GMythBackendInfo *backend_info,
5.81 + const gchar *filename,
5.82 + gchar **current_dir);
5.83 +gchar* gmyth_util_create_filename (const gint chan_id,
5.84 + const GTimeVal * start_time);
5.85 +GList* gmyth_util_get_channel_list (GMythBackendInfo *backend_info);
5.86 +GSList* gmyth_util_get_all_recordings (GMythBackendInfo *backend_info);
5.87 +GMythProgramInfo*
5.88 + gmyth_util_get_recording_from_channel (GMythBackendInfo *backend_info,
5.89 + const gchar *channel);
5.90
5.91 G_END_DECLS
5.92 #endif /* GMYTH_UTIL_H_ */