1.1 --- a/gmyth/src/gmyth_file_transfer.c Thu Jun 14 18:19:52 2007 +0100
1.2 +++ b/gmyth/src/gmyth_file_transfer.c Tue Aug 07 16:00:49 2007 +0100
1.3 @@ -60,138 +60,143 @@
1.4 #define GMYTH_FILE_TRANSFER_GET_PRIVATE(obj) \
1.5 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GMYTH_FILE_TRANSFER_TYPE, GMythFileTransferPrivate))
1.6
1.7 -enum myth_sock_types
1.8 -{
1.9 - GMYTH_PLAYBACK_TYPE = 0,
1.10 - GMYTH_MONITOR_TYPE,
1.11 - GMYTH_FILETRANSFER_TYPE,
1.12 - GMYTH_RINGBUFFER_TYPE
1.13 +enum myth_sock_types {
1.14 + GMYTH_PLAYBACK_TYPE = 0,
1.15 + GMYTH_MONITOR_TYPE,
1.16 + GMYTH_FILETRANSFER_TYPE,
1.17 + GMYTH_RINGBUFFER_TYPE
1.18 };
1.19
1.20 -struct _GMythFileTransferPrivate
1.21 -{
1.22 - GMythRecorder *recorder;
1.23 +struct _GMythFileTransferPrivate {
1.24 + GMythRecorder *recorder;
1.25
1.26 - gboolean do_next_program_chain;
1.27 - gboolean disposed;
1.28 - gboolean livetv_wait;
1.29 + gboolean do_next_program_chain;
1.30 + gboolean disposed;
1.31 + gboolean livetv_wait;
1.32
1.33 - /* MythTV version number */
1.34 - gint mythtv_version;
1.35 + /*
1.36 + * MythTV version number
1.37 + */
1.38 + gint mythtv_version;
1.39
1.40 - /* socket descriptors */
1.41 - GMythSocket *control_sock;
1.42 - GMythSocket *sock;
1.43 - GMutex *mutex;
1.44 - gint file_id;
1.45 + /*
1.46 + * socket descriptors
1.47 + */
1.48 + GMythSocket *control_sock;
1.49 + GMythSocket *sock;
1.50 + GMutex *mutex;
1.51 + gint file_id;
1.52 };
1.53
1.54 -static void gmyth_file_transfer_class_init(GMythFileTransferClass * klass);
1.55 -static void gmyth_file_transfer_init(GMythFileTransfer * object);
1.56 -static void gmyth_file_transfer_dispose(GObject * object);
1.57 -static void gmyth_file_transfer_finalize(GObject * object);
1.58 -static void _file_transfer_program_info_changed(GMythFileTransfer * transfer,
1.59 - gint msg_code,
1.60 - gpointer livetv_recorder);
1.61 +static void gmyth_file_transfer_class_init(GMythFileTransferClass *
1.62 + klass);
1.63 +static void gmyth_file_transfer_init(GMythFileTransfer * object);
1.64 +static void gmyth_file_transfer_dispose(GObject * object);
1.65 +static void gmyth_file_transfer_finalize(GObject * object);
1.66 +static void _file_transfer_program_info_changed(GMythFileTransfer *
1.67 + transfer,
1.68 + gint msg_code,
1.69 + gpointer
1.70 + livetv_recorder);
1.71 static gboolean _connect_to_backend(GMythFileTransfer * transfer);
1.72 static gboolean _control_acquire_context(GMythFileTransfer * transfer,
1.73 - gboolean do_wait);
1.74 + gboolean do_wait);
1.75 static gboolean _control_release_context(GMythFileTransfer * transfer);
1.76
1.77 G_DEFINE_TYPE(GMythFileTransfer, gmyth_file_transfer, GMYTH_FILE_TYPE)
1.78 - static void gmyth_file_transfer_class_init(GMythFileTransferClass *
1.79 - klass)
1.80 + static void gmyth_file_transfer_class_init(GMythFileTransferClass *
1.81 + klass)
1.82 {
1.83 - GObjectClass *gobject_class;
1.84 - GMythFileTransferClass *gtransfer_class;
1.85 + GObjectClass *gobject_class;
1.86 + GMythFileTransferClass *gtransfer_class;
1.87
1.88 - gobject_class = (GObjectClass *) klass;
1.89 - gtransfer_class = (GMythFileTransferClass *) gobject_class;
1.90 + gobject_class = (GObjectClass *) klass;
1.91 + gtransfer_class = (GMythFileTransferClass *) gobject_class;
1.92
1.93 - gobject_class->dispose = gmyth_file_transfer_dispose;
1.94 - gobject_class->finalize = gmyth_file_transfer_finalize;
1.95 + gobject_class->dispose = gmyth_file_transfer_dispose;
1.96 + gobject_class->finalize = gmyth_file_transfer_finalize;
1.97
1.98 - g_type_class_add_private(gobject_class, sizeof(GMythFileTransferPrivate));
1.99 + g_type_class_add_private(gobject_class,
1.100 + sizeof(GMythFileTransferPrivate));
1.101
1.102 - gtransfer_class->program_info_changed_handler =
1.103 - _file_transfer_program_info_changed;
1.104 + gtransfer_class->program_info_changed_handler =
1.105 + _file_transfer_program_info_changed;
1.106
1.107 - gtransfer_class->program_info_changed_handler_signal_id =
1.108 - g_signal_new("program-info-changed",
1.109 - G_TYPE_FROM_CLASS(gtransfer_class),
1.110 - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE |
1.111 - G_SIGNAL_NO_HOOKS, 0, NULL, NULL,
1.112 - gmyth_marshal_VOID__INT_POINTER, G_TYPE_NONE, 2,
1.113 - G_TYPE_INT, G_TYPE_POINTER);
1.114 + gtransfer_class->program_info_changed_handler_signal_id =
1.115 + g_signal_new("program-info-changed",
1.116 + G_TYPE_FROM_CLASS(gtransfer_class),
1.117 + G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE |
1.118 + G_SIGNAL_NO_HOOKS, 0, NULL, NULL,
1.119 + gmyth_marshal_VOID__INT_POINTER, G_TYPE_NONE, 2,
1.120 + G_TYPE_INT, G_TYPE_POINTER);
1.121
1.122 }
1.123
1.124 static void
1.125 gmyth_file_transfer_init(GMythFileTransfer * transfer)
1.126 {
1.127 - g_return_if_fail(transfer != NULL);
1.128 + g_return_if_fail(transfer != NULL);
1.129
1.130 - transfer->priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.131 - transfer->priv->mutex = g_mutex_new();
1.132 + transfer->priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.133 + transfer->priv->mutex = g_mutex_new();
1.134
1.135 - g_signal_connect(G_OBJECT(transfer), "program-info-changed",
1.136 - (GCallback) (GMYTH_FILE_TRANSFER_GET_CLASS
1.137 - (transfer)->
1.138 - program_info_changed_handler), NULL);
1.139 + g_signal_connect(G_OBJECT(transfer), "program-info-changed",
1.140 + (GCallback) (GMYTH_FILE_TRANSFER_GET_CLASS
1.141 + (transfer)->
1.142 + program_info_changed_handler), NULL);
1.143 }
1.144
1.145 static void
1.146 gmyth_file_transfer_dispose(GObject * object)
1.147 {
1.148 - GMythFileTransferPrivate *priv;
1.149 - GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER(object);
1.150 + GMythFileTransferPrivate *priv;
1.151 + GMythFileTransfer *transfer = GMYTH_FILE_TRANSFER(object);
1.152
1.153 - g_return_if_fail(transfer != NULL);
1.154 + g_return_if_fail(transfer != NULL);
1.155
1.156 - priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.157 + priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.158
1.159 - if (priv->disposed)
1.160 - {
1.161 - /* If dispose did already run, return. */
1.162 - return;
1.163 - }
1.164 + if (priv->disposed) {
1.165 + /*
1.166 + * If dispose did already run, return.
1.167 + */
1.168 + return;
1.169 + }
1.170
1.171 - /* Make sure dispose does not run twice. */
1.172 - priv->disposed = TRUE;
1.173 + /*
1.174 + * Make sure dispose does not run twice.
1.175 + */
1.176 + priv->disposed = TRUE;
1.177
1.178 - if (priv->mutex != NULL)
1.179 - {
1.180 - g_mutex_free(priv->mutex);
1.181 - priv->mutex = NULL;
1.182 - }
1.183 + if (priv->mutex != NULL) {
1.184 + g_mutex_free(priv->mutex);
1.185 + priv->mutex = NULL;
1.186 + }
1.187
1.188 - if (priv->control_sock != NULL)
1.189 - {
1.190 - g_object_unref(priv->control_sock);
1.191 - priv->control_sock = NULL;
1.192 - }
1.193 + if (priv->control_sock != NULL) {
1.194 + g_object_unref(priv->control_sock);
1.195 + priv->control_sock = NULL;
1.196 + }
1.197
1.198 - if (priv->sock != NULL)
1.199 - {
1.200 - g_object_unref(priv->sock);
1.201 - priv->sock = NULL;
1.202 - }
1.203 + if (priv->sock != NULL) {
1.204 + g_object_unref(priv->sock);
1.205 + priv->sock = NULL;
1.206 + }
1.207
1.208 - if (priv->recorder != NULL)
1.209 - {
1.210 - g_object_unref(priv->recorder);
1.211 - priv->recorder = NULL;
1.212 - }
1.213 + if (priv->recorder != NULL) {
1.214 + g_object_unref(priv->recorder);
1.215 + priv->recorder = NULL;
1.216 + }
1.217
1.218 - G_OBJECT_CLASS(gmyth_file_transfer_parent_class)->dispose(object);
1.219 + G_OBJECT_CLASS(gmyth_file_transfer_parent_class)->dispose(object);
1.220 }
1.221
1.222 static void
1.223 gmyth_file_transfer_finalize(GObject * object)
1.224 {
1.225 - g_signal_handlers_destroy(object);
1.226 + g_signal_handlers_destroy(object);
1.227
1.228 - G_OBJECT_CLASS(gmyth_file_transfer_parent_class)->finalize(object);
1.229 + G_OBJECT_CLASS(gmyth_file_transfer_parent_class)->finalize(object);
1.230 }
1.231
1.232 /**
1.233 @@ -205,30 +210,32 @@
1.234 GMythFileTransfer *
1.235 gmyth_file_transfer_new(GMythBackendInfo * backend_info)
1.236 {
1.237 - GMythFileTransfer *transfer = g_object_new(GMYTH_FILE_TRANSFER_TYPE,
1.238 - "backend-info", backend_info,
1.239 - NULL);
1.240 + GMythFileTransfer *transfer = g_object_new(GMYTH_FILE_TRANSFER_TYPE,
1.241 + "backend-info",
1.242 + backend_info,
1.243 + NULL);
1.244
1.245 - //GValue val = {0,};
1.246 - //backend_info = g_object_ref( backend_info );
1.247 - gmyth_debug("Creating FileTransfer BackendInfo hostname = %s",
1.248 - gmyth_backend_info_get_hostname(backend_info));
1.249 - //GMythBackendInfo *backend_info = gmyth_backend_info_new_with_uri (uri_str);
1.250 - //g_value_init (&val, G_TYPE_OBJECT);
1.251 - //g_value_set_object (&val, backend_info);
1.252 - //g_object_set (G_OBJECT (transfer), "backend-info", &val, NULL);
1.253 + // GValue val = {0,};
1.254 + // backend_info = g_object_ref( backend_info );
1.255 + gmyth_debug("Creating FileTransfer BackendInfo hostname = %s",
1.256 + gmyth_backend_info_get_hostname(backend_info));
1.257 + // GMythBackendInfo *backend_info = gmyth_backend_info_new_with_uri
1.258 + // (uri_str);
1.259 + // g_value_init (&val, G_TYPE_OBJECT);
1.260 + // g_value_set_object (&val, backend_info);
1.261 + // g_object_set (G_OBJECT (transfer), "backend-info", &val, NULL);
1.262
1.263 - return transfer;
1.264 + return transfer;
1.265 }
1.266
1.267 -gchar *
1.268 +gchar *
1.269 gmyth_file_transfer_get_file_name(GMythFileTransfer * transfer)
1.270 {
1.271 - gchar *filename;
1.272 + gchar *filename;
1.273
1.274 - g_object_get(G_OBJECT(transfer), "filename", &filename, NULL);
1.275 + g_object_get(G_OBJECT(transfer), "filename", &filename, NULL);
1.276
1.277 - return filename;
1.278 + return filename;
1.279 }
1.280
1.281 /**
1.282 @@ -241,16 +248,17 @@
1.283 GMythFileTransfer *
1.284 gmyth_file_transfer_new_with_uri(const gchar * uri_str)
1.285 {
1.286 - GMythFileTransfer *transfer =
1.287 - GMYTH_FILE_TRANSFER(g_object_new(GMYTH_FILE_TRANSFER_TYPE, NULL));
1.288 - gmyth_debug("URI str = %s", uri_str);
1.289 - //GMythBackendInfo *backend_info = gmyth_backend_info_new_with_uri (uri_str);
1.290 - GValue val = { 0, };
1.291 - g_value_init(&val, G_TYPE_OBJECT);
1.292 - g_value_set_object(&val, gmyth_backend_info_new_with_uri(uri_str));
1.293 - g_object_set(G_OBJECT(transfer), "backend-info", &val, NULL);
1.294 + GMythFileTransfer *transfer =
1.295 + GMYTH_FILE_TRANSFER(g_object_new(GMYTH_FILE_TRANSFER_TYPE, NULL));
1.296 + gmyth_debug("URI str = %s", uri_str);
1.297 + // GMythBackendInfo *backend_info = gmyth_backend_info_new_with_uri
1.298 + // (uri_str);
1.299 + GValue val = { 0, };
1.300 + g_value_init(&val, G_TYPE_OBJECT);
1.301 + g_value_set_object(&val, gmyth_backend_info_new_with_uri(uri_str));
1.302 + g_object_set(G_OBJECT(transfer), "backend-info", &val, NULL);
1.303
1.304 - return transfer;
1.305 + return transfer;
1.306 }
1.307
1.308 /**
1.309 @@ -262,74 +270,72 @@
1.310 * @return <code>true</code>, if the connection opening had been done successfully.
1.311 */
1.312 gboolean
1.313 -gmyth_file_transfer_open(GMythFileTransfer * transfer, const gchar * filename)
1.314 +gmyth_file_transfer_open(GMythFileTransfer * transfer,
1.315 + const gchar * filename)
1.316 {
1.317 - gboolean ret = TRUE;
1.318 - GMythFileTransferPrivate *priv;
1.319 + gboolean ret = TRUE;
1.320 + GMythFileTransferPrivate *priv;
1.321
1.322 - g_return_val_if_fail(transfer != NULL, FALSE);
1.323 - g_return_val_if_fail(filename != NULL && strlen(filename) > 0, FALSE);
1.324 + g_return_val_if_fail(transfer != NULL, FALSE);
1.325 + g_return_val_if_fail(filename != NULL && strlen(filename) > 0, FALSE);
1.326
1.327 - priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.328 + priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.329
1.330 - gmyth_debug("Opening the FileTransfer... (%s)", filename);
1.331 + gmyth_debug("Opening the FileTransfer... (%s)", filename);
1.332
1.333 - g_object_set(GMYTH_FILE(transfer), "filename", filename, NULL);
1.334 + g_object_set(GMYTH_FILE(transfer), "filename", filename, NULL);
1.335
1.336 - /* configure the control socket */
1.337 - if (TRUE /*priv->control_sock == NULL */ )
1.338 - {
1.339 - if (!_connect_to_backend(transfer))
1.340 - {
1.341 - gmyth_debug("Connection to backend failed (Control Socket).");
1.342 - ret = FALSE;
1.343 - }
1.344 + /*
1.345 + * configure the control socket
1.346 + */
1.347 + if (TRUE /* priv->control_sock == NULL */ ) {
1.348 + if (!_connect_to_backend(transfer)) {
1.349 + gmyth_debug("Connection to backend failed (Control Socket).");
1.350 + ret = FALSE;
1.351 + }
1.352
1.353 - if (priv->do_next_program_chain)
1.354 - {
1.355 - priv->do_next_program_chain = FALSE; // fixme
1.356 - gmyth_debug
1.357 - ("New file available before the current file was opened");
1.358 - GMythProgramInfo *prog_info =
1.359 - gmyth_recorder_get_current_program_info(priv->recorder);
1.360 + if (priv->do_next_program_chain) {
1.361 + priv->do_next_program_chain = FALSE; // fixme
1.362 + gmyth_debug
1.363 + ("New file available before the current file was opened");
1.364 + GMythProgramInfo *prog_info =
1.365 + gmyth_recorder_get_current_program_info(priv->recorder);
1.366
1.367 - if (prog_info != NULL && prog_info->pathname != NULL
1.368 - && strlen(prog_info->pathname->str) > 0
1.369 - && g_ascii_strcasecmp(prog_info->pathname->str,
1.370 - gmyth_file_get_file_name(GMYTH_FILE
1.371 - (transfer)))
1.372 - != 0)
1.373 - ret =
1.374 - gmyth_file_transfer_open(transfer,
1.375 - g_strrstr(prog_info->pathname->
1.376 - str, "/"));
1.377 + if (prog_info != NULL && prog_info->pathname != NULL
1.378 + && strlen(prog_info->pathname->str) > 0
1.379 + && g_ascii_strcasecmp(prog_info->pathname->str,
1.380 + gmyth_file_get_file_name(GMYTH_FILE
1.381 + (transfer)))
1.382 + != 0)
1.383 + ret =
1.384 + gmyth_file_transfer_open(transfer,
1.385 + g_strrstr(prog_info->
1.386 + pathname->str,
1.387 + "/"));
1.388
1.389 - if (prog_info != NULL)
1.390 - g_object_unref(prog_info);
1.391 + if (prog_info != NULL)
1.392 + g_object_unref(prog_info);
1.393
1.394 - if (!ret)
1.395 - gmyth_debug("Cannot change to the next program info!");
1.396 - else
1.397 - gmyth_debug("OK!!! MOVED to the next program info [%s]!",
1.398 - gmyth_file_get_file_name(GMYTH_FILE(transfer)));
1.399 + if (!ret)
1.400 + gmyth_debug("Cannot change to the next program info!");
1.401 + else
1.402 + gmyth_debug("OK!!! MOVED to the next program info [%s]!",
1.403 + gmyth_file_get_file_name(GMYTH_FILE
1.404 + (transfer)));
1.405
1.406 - }
1.407 - else
1.408 - {
1.409 - gmyth_debug
1.410 - ("None new file found. We continue with the same file opened before");
1.411 - }
1.412 + } else {
1.413 + gmyth_debug
1.414 + ("None new file found. We continue with the same file opened before");
1.415 + }
1.416
1.417 - }
1.418 - else
1.419 - {
1.420 - gmyth_debug("Remote transfer control socket already created.");
1.421 - }
1.422 + } else {
1.423 + gmyth_debug("Remote transfer control socket already created.");
1.424 + }
1.425
1.426 - gmyth_debug("Got file with size = %lld.\n",
1.427 - gmyth_file_get_filesize(GMYTH_FILE(transfer)));
1.428 + gmyth_debug("Got file with size = %lld.\n",
1.429 + gmyth_file_get_filesize(GMYTH_FILE(transfer)));
1.430
1.431 - return ret;
1.432 + return ret;
1.433 }
1.434
1.435 /**
1.436 @@ -339,111 +345,122 @@
1.437 *
1.438 * @return <code>true</code>, if the connection had been configured successfully.
1.439 */
1.440 -static gboolean
1.441 +static gboolean
1.442 _connect_to_backend(GMythFileTransfer * transfer)
1.443 {
1.444 - GString *base_str = NULL;
1.445 - GString *hostname = NULL;
1.446 - GMythStringList *strlist = NULL;
1.447 - gboolean ret = TRUE;
1.448 - GMythFileTransferPrivate *priv;
1.449 - GMythBackendInfo *backend_info;
1.450 + GString *base_str = NULL;
1.451 + GString *hostname = NULL;
1.452 + GMythStringList *strlist = NULL;
1.453 + gboolean ret = TRUE;
1.454 + GMythFileTransferPrivate *priv;
1.455 + GMythBackendInfo *backend_info;
1.456
1.457 - g_return_val_if_fail(transfer != NULL, FALSE);
1.458 + g_return_val_if_fail(transfer != NULL, FALSE);
1.459
1.460 - g_object_get(GMYTH_FILE(transfer), "backend-info", &backend_info, NULL);
1.461 + g_object_get(GMYTH_FILE(transfer), "backend-info", &backend_info,
1.462 + NULL);
1.463
1.464 - priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.465 - _control_acquire_context(transfer, TRUE);
1.466 + priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.467 + _control_acquire_context(transfer, TRUE);
1.468
1.469 - /* Creates the control socket */
1.470 + /*
1.471 + * Creates the control socket
1.472 + */
1.473
1.474 - if (priv->control_sock != NULL)
1.475 - {
1.476 - g_object_unref(priv->control_sock);
1.477 - priv->control_sock = NULL;
1.478 - }
1.479 + if (priv->control_sock != NULL) {
1.480 + g_object_unref(priv->control_sock);
1.481 + priv->control_sock = NULL;
1.482 + }
1.483
1.484 - base_str = g_string_new("");
1.485 + base_str = g_string_new("");
1.486
1.487 - priv->control_sock = gmyth_socket_new();
1.488 - // Connects the socket, send Mythtv ANN command and verify Mythtv protocol version
1.489 - if (!gmyth_socket_connect_to_backend(priv->control_sock,
1.490 - backend_info->hostname,
1.491 - backend_info->port, TRUE))
1.492 - {
1.493 + priv->control_sock = gmyth_socket_new();
1.494 + // Connects the socket, send Mythtv ANN command and verify Mythtv
1.495 + // protocol version
1.496 + if (!gmyth_socket_connect_to_backend(priv->control_sock,
1.497 + backend_info->hostname,
1.498 + backend_info->port, TRUE)) {
1.499
1.500 - g_object_unref(priv->control_sock);
1.501 - priv->control_sock = NULL;
1.502 - return FALSE;
1.503 - }
1.504 + g_object_unref(priv->control_sock);
1.505 + priv->control_sock = NULL;
1.506 + return FALSE;
1.507 + }
1.508
1.509 - /* Creates the data socket */
1.510 - if (priv->sock != NULL)
1.511 - {
1.512 - g_object_unref(priv->sock);
1.513 - priv->sock = NULL;
1.514 - }
1.515 + /*
1.516 + * Creates the data socket
1.517 + */
1.518 + if (priv->sock != NULL) {
1.519 + g_object_unref(priv->sock);
1.520 + priv->sock = NULL;
1.521 + }
1.522
1.523 - priv->sock = gmyth_socket_new();
1.524 - gmyth_socket_connect(priv->sock, backend_info->hostname,
1.525 - backend_info->port);
1.526 - gmyth_debug("Connecting file transfer... (%s, %d)",
1.527 - backend_info->hostname, backend_info->port);
1.528 + priv->sock = gmyth_socket_new();
1.529 + gmyth_socket_connect(priv->sock, backend_info->hostname,
1.530 + backend_info->port);
1.531 + gmyth_debug("Connecting file transfer... (%s, %d)",
1.532 + backend_info->hostname, backend_info->port);
1.533
1.534 - strlist = gmyth_string_list_new();
1.535 - hostname = gmyth_socket_get_local_hostname();
1.536 - gmyth_debug("[%s] MythTV version (from backend) = %d.\n", __FUNCTION__,
1.537 - priv->control_sock->mythtv_version);
1.538 - if (priv->control_sock->mythtv_version > 26)
1.539 - g_string_printf(base_str, "ANN FileTransfer %s 1 -1", hostname->str);
1.540 - else
1.541 - g_string_printf(base_str, "ANN FileTransfer %s", hostname->str);
1.542 + strlist = gmyth_string_list_new();
1.543 + hostname = gmyth_socket_get_local_hostname();
1.544 + gmyth_debug("[%s] MythTV version (from backend) = %d.\n", __FUNCTION__,
1.545 + priv->control_sock->mythtv_version);
1.546 + if (priv->control_sock->mythtv_version > 26)
1.547 + g_string_printf(base_str, "ANN FileTransfer %s 1 -1",
1.548 + hostname->str);
1.549 + else
1.550 + g_string_printf(base_str, "ANN FileTransfer %s", hostname->str);
1.551
1.552 - gmyth_string_list_append_string(strlist, base_str);
1.553 - gmyth_string_list_append_char_array(strlist,
1.554 - gmyth_file_get_file_name(GMYTH_FILE
1.555 - (transfer)));
1.556 + gmyth_string_list_append_string(strlist, base_str);
1.557 + gmyth_string_list_append_char_array(strlist,
1.558 + gmyth_file_get_file_name(GMYTH_FILE
1.559 + (transfer)));
1.560
1.561 - gmyth_socket_write_stringlist(priv->sock, strlist);
1.562 + gmyth_socket_write_stringlist(priv->sock, strlist);
1.563
1.564 - /* MONITOR Handler - DVB TV Chain update messages!!! */
1.565 + /*
1.566 + * MONITOR Handler - DVB TV Chain update messages!!!
1.567 + */
1.568
1.569 - gmyth_socket_read_stringlist(priv->sock, strlist);
1.570 + gmyth_socket_read_stringlist(priv->sock, strlist);
1.571
1.572 - /* file identification used in future file transfer requests to backend */
1.573 - priv->file_id = gmyth_string_list_get_int(strlist, 1);
1.574 + /*
1.575 + * file identification used in future file transfer requests to
1.576 + * backend
1.577 + */
1.578 + priv->file_id = gmyth_string_list_get_int(strlist, 1);
1.579
1.580 - /* Myth URI stream file size - decoded using two 8-bytes sequences (64 bits/long long types) */
1.581 - gmyth_file_set_filesize(GMYTH_FILE(transfer),
1.582 - gmyth_string_list_get_int64(strlist, 2));
1.583 + /*
1.584 + * Myth URI stream file size - decoded using two 8-bytes sequences (64
1.585 + * bits/long long types)
1.586 + */
1.587 + gmyth_file_set_filesize(GMYTH_FILE(transfer),
1.588 + gmyth_string_list_get_int64(strlist, 2));
1.589
1.590 - gmyth_debug("***** Received: recordernum = %d, filesize = %"
1.591 - G_GUINT64_FORMAT "\n", priv->file_id,
1.592 - gmyth_file_get_filesize(GMYTH_FILE(transfer)));
1.593 + gmyth_debug("***** Received: recordernum = %d, filesize = %"
1.594 + G_GUINT64_FORMAT "\n", priv->file_id,
1.595 + gmyth_file_get_filesize(GMYTH_FILE(transfer)));
1.596
1.597 - if (gmyth_file_get_filesize(GMYTH_FILE(transfer)) < 0)
1.598 - {
1.599 - gmyth_debug
1.600 - ("Got filesize equals to %llu is lesser than 0 [invalid stream file]\n",
1.601 - gmyth_file_get_filesize(GMYTH_FILE(transfer)));
1.602 - g_object_unref(priv->sock);
1.603 - priv->sock = NULL;
1.604 - ret = FALSE;
1.605 - }
1.606 + if (gmyth_file_get_filesize(GMYTH_FILE(transfer)) < 0) {
1.607 + gmyth_debug
1.608 + ("Got filesize equals to %llu is lesser than 0 [invalid stream file]\n",
1.609 + gmyth_file_get_filesize(GMYTH_FILE(transfer)));
1.610 + g_object_unref(priv->sock);
1.611 + priv->sock = NULL;
1.612 + ret = FALSE;
1.613 + }
1.614
1.615 - _control_release_context(transfer);
1.616 + _control_release_context(transfer);
1.617
1.618 - if (strlist != NULL)
1.619 - g_object_unref(strlist);
1.620 + if (strlist != NULL)
1.621 + g_object_unref(strlist);
1.622
1.623 - if (base_str != NULL)
1.624 - g_string_free(base_str, TRUE);
1.625 + if (base_str != NULL)
1.626 + g_string_free(base_str, TRUE);
1.627
1.628 - if (hostname != NULL)
1.629 - g_string_free(hostname, TRUE);
1.630 + if (hostname != NULL)
1.631 + g_string_free(hostname, TRUE);
1.632
1.633 - return ret;
1.634 + return ret;
1.635 }
1.636
1.637 /**
1.638 @@ -456,14 +473,16 @@
1.639 */
1.640 void
1.641 gmyth_file_transfer_emit_program_info_changed_signal(GMythFileTransfer *
1.642 - transfer, gint msg_code,
1.643 - gpointer
1.644 - live_tv_recorder)
1.645 + transfer,
1.646 + gint msg_code,
1.647 + gpointer
1.648 + live_tv_recorder)
1.649 {
1.650 - gmyth_debug("Calling signal handler... [FILE_TRANSFER]");
1.651 + gmyth_debug("Calling signal handler... [FILE_TRANSFER]");
1.652
1.653 - g_signal_emit(transfer, GMYTH_FILE_TRANSFER_GET_CLASS(transfer)->program_info_changed_handler_signal_id, 0, /* details */
1.654 - msg_code, live_tv_recorder);
1.655 + g_signal_emit(transfer, GMYTH_FILE_TRANSFER_GET_CLASS(transfer)->program_info_changed_handler_signal_id, 0, /* details
1.656 + */
1.657 + msg_code, live_tv_recorder);
1.658
1.659 }
1.660
1.661 @@ -477,34 +496,34 @@
1.662 gboolean
1.663 gmyth_file_transfer_is_open(GMythFileTransfer * transfer)
1.664 {
1.665 - GMythStringList *strlist;
1.666 - GMythFileTransferPrivate *priv;
1.667 - GString *query;
1.668 + GMythStringList *strlist;
1.669 + GMythFileTransferPrivate *priv;
1.670 + GString *query;
1.671
1.672 - g_return_val_if_fail(transfer != NULL, FALSE);
1.673 + g_return_val_if_fail(transfer != NULL, FALSE);
1.674
1.675 - priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.676 - g_return_val_if_fail(priv->control_sock != NULL, FALSE);
1.677 - g_return_val_if_fail(priv->sock != NULL, FALSE);
1.678 + priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.679 + g_return_val_if_fail(priv->control_sock != NULL, FALSE);
1.680 + g_return_val_if_fail(priv->sock != NULL, FALSE);
1.681
1.682 - _control_acquire_context(transfer, TRUE);
1.683 + _control_acquire_context(transfer, TRUE);
1.684
1.685 - strlist = gmyth_string_list_new();
1.686 - query = g_string_new(GMYTHTV_QUERY_HEADER);
1.687 - g_string_append_printf(query, "%d", priv->file_id);
1.688 + strlist = gmyth_string_list_new();
1.689 + query = g_string_new(GMYTHTV_QUERY_HEADER);
1.690 + g_string_append_printf(query, "%d", priv->file_id);
1.691
1.692 - gmyth_string_list_append_string(strlist, query);
1.693 - gmyth_string_list_append_char_array(strlist, "IS_OPEN");
1.694 + gmyth_string_list_append_string(strlist, query);
1.695 + gmyth_string_list_append_char_array(strlist, "IS_OPEN");
1.696
1.697 - gmyth_socket_write_stringlist(priv->control_sock, strlist);
1.698 - gmyth_socket_read_stringlist(priv->control_sock, strlist);
1.699 + gmyth_socket_write_stringlist(priv->control_sock, strlist);
1.700 + gmyth_socket_read_stringlist(priv->control_sock, strlist);
1.701
1.702 - _control_release_context(transfer);
1.703 + _control_release_context(transfer);
1.704
1.705 - g_string_free(query, TRUE);
1.706 - g_object_unref(strlist);
1.707 + g_string_free(query, TRUE);
1.708 + g_object_unref(strlist);
1.709
1.710 - return (strlist != NULL && gmyth_string_list_get_int(strlist, 0) == 1);
1.711 + return (strlist != NULL && gmyth_string_list_get_int(strlist, 0) == 1);
1.712 }
1.713
1.714 /**
1.715 @@ -515,48 +534,46 @@
1.716 void
1.717 gmyth_file_transfer_close(GMythFileTransfer * transfer)
1.718 {
1.719 - GMythStringList *strlist;
1.720 - GMythFileTransferPrivate *priv;
1.721 - GString *query;
1.722 + GMythStringList *strlist;
1.723 + GMythFileTransferPrivate *priv;
1.724 + GString *query;
1.725
1.726 - g_return_if_fail(transfer != NULL);
1.727 + g_return_if_fail(transfer != NULL);
1.728
1.729 - priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.730 + priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.731
1.732 - if (priv->control_sock == NULL)
1.733 - return;
1.734 + if (priv->control_sock == NULL)
1.735 + return;
1.736
1.737 - _control_acquire_context(transfer, TRUE);
1.738 + _control_acquire_context(transfer, TRUE);
1.739
1.740 - strlist = gmyth_string_list_new();
1.741 - query = g_string_new(GMYTHTV_QUERY_HEADER);
1.742 - g_string_append_printf(query, "%d", priv->file_id);
1.743 + strlist = gmyth_string_list_new();
1.744 + query = g_string_new(GMYTHTV_QUERY_HEADER);
1.745 + g_string_append_printf(query, "%d", priv->file_id);
1.746
1.747 - gmyth_string_list_append_string(strlist, query);
1.748 - gmyth_string_list_append_char_array(strlist, "DONE");
1.749 + gmyth_string_list_append_string(strlist, query);
1.750 + gmyth_string_list_append_char_array(strlist, "DONE");
1.751
1.752 - if (gmyth_socket_sendreceive_stringlist(priv->control_sock, strlist) <= 0)
1.753 - {
1.754 - // fixme: time out???
1.755 - gmyth_debug("Remote file timeout.\n");
1.756 - }
1.757 + if (gmyth_socket_sendreceive_stringlist(priv->control_sock, strlist) <=
1.758 + 0) {
1.759 + // fixme: time out???
1.760 + gmyth_debug("Remote file timeout.\n");
1.761 + }
1.762
1.763 - g_string_free(query, TRUE);
1.764 - g_object_unref(strlist);
1.765 + g_string_free(query, TRUE);
1.766 + g_object_unref(strlist);
1.767
1.768 - if (priv->sock)
1.769 - {
1.770 - g_object_unref(priv->sock);
1.771 - priv->sock = NULL;
1.772 - }
1.773 + if (priv->sock) {
1.774 + g_object_unref(priv->sock);
1.775 + priv->sock = NULL;
1.776 + }
1.777
1.778 - if (priv->control_sock)
1.779 - {
1.780 - g_object_unref(priv->control_sock);
1.781 - priv->control_sock = NULL;
1.782 - }
1.783 + if (priv->control_sock) {
1.784 + g_object_unref(priv->control_sock);
1.785 + priv->control_sock = NULL;
1.786 + }
1.787
1.788 - _control_release_context(transfer);
1.789 + _control_release_context(transfer);
1.790 }
1.791
1.792 /**
1.793 @@ -570,51 +587,55 @@
1.794 */
1.795 gint64
1.796 gmyth_file_transfer_seek(GMythFileTransfer * transfer, guint64 pos,
1.797 - gint whence)
1.798 + gint whence)
1.799 {
1.800 - GMythStringList *strlist = gmyth_string_list_new();
1.801 - GMythFileTransferPrivate *priv;
1.802 - GString *query;
1.803 + GMythStringList *strlist = gmyth_string_list_new();
1.804 + GMythFileTransferPrivate *priv;
1.805 + GString *query;
1.806
1.807 - g_return_val_if_fail(transfer != NULL, FALSE);
1.808 - priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.809 + g_return_val_if_fail(transfer != NULL, FALSE);
1.810 + priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.811
1.812 - g_return_val_if_fail(priv->sock != NULL, -1);
1.813 - g_return_val_if_fail(priv->control_sock != NULL, -1);
1.814 + g_return_val_if_fail(priv->sock != NULL, -1);
1.815 + g_return_val_if_fail(priv->control_sock != NULL, -1);
1.816
1.817 - strlist = gmyth_string_list_new();
1.818 - query = g_string_new(GMYTHTV_QUERY_HEADER);
1.819 - g_string_append_printf(query, "%d", priv->file_id);
1.820 + strlist = gmyth_string_list_new();
1.821 + query = g_string_new(GMYTHTV_QUERY_HEADER);
1.822 + g_string_append_printf(query, "%d", priv->file_id);
1.823
1.824 - /* myth_control_acquire_context( transfer, TRUE ); */
1.825 + /*
1.826 + * myth_control_acquire_context( transfer, TRUE );
1.827 + */
1.828
1.829 - gmyth_string_list_append_string(strlist, query);
1.830 - gmyth_string_list_append_char_array(strlist, "SEEK");
1.831 - gmyth_string_list_append_uint64(strlist, pos);
1.832 + gmyth_string_list_append_string(strlist, query);
1.833 + gmyth_string_list_append_char_array(strlist, "SEEK");
1.834 + gmyth_string_list_append_uint64(strlist, pos);
1.835
1.836 - gmyth_string_list_append_int(strlist, whence);
1.837 + gmyth_string_list_append_int(strlist, whence);
1.838
1.839 - if (pos > 0)
1.840 - gmyth_string_list_append_uint64(strlist, pos);
1.841 - else
1.842 - gmyth_string_list_append_uint64(strlist,
1.843 - gmyth_file_get_offset(GMYTH_FILE
1.844 - (transfer)));
1.845 + if (pos > 0)
1.846 + gmyth_string_list_append_uint64(strlist, pos);
1.847 + else
1.848 + gmyth_string_list_append_uint64(strlist,
1.849 + gmyth_file_get_offset(GMYTH_FILE
1.850 + (transfer)));
1.851
1.852 - gmyth_socket_sendreceive_stringlist(priv->control_sock, strlist);
1.853 + gmyth_socket_sendreceive_stringlist(priv->control_sock, strlist);
1.854
1.855 - gint64 retval = gmyth_string_list_get_int64(strlist, 0);
1.856 + gint64 retval = gmyth_string_list_get_int64(strlist, 0);
1.857
1.858 - gmyth_file_set_offset(GMYTH_FILE(transfer), retval);
1.859 - gmyth_debug("Got reading position pointer from the streaming = %lld\n",
1.860 - retval);
1.861 + gmyth_file_set_offset(GMYTH_FILE(transfer), retval);
1.862 + gmyth_debug("Got reading position pointer from the streaming = %lld\n",
1.863 + retval);
1.864
1.865 - g_object_unref(strlist);
1.866 - g_string_free(query, TRUE);
1.867 + g_object_unref(strlist);
1.868 + g_string_free(query, TRUE);
1.869
1.870 - /* myth_control_release_context( transfer ); */
1.871 + /*
1.872 + * myth_control_release_context( transfer );
1.873 + */
1.874
1.875 - return retval;
1.876 + return retval;
1.877 }
1.878
1.879 /**
1.880 @@ -625,17 +646,17 @@
1.881 *
1.882 * @return <code>true</code>, if the acquire had been got.
1.883 */
1.884 -static gboolean
1.885 +static gboolean
1.886 _control_acquire_context(GMythFileTransfer * transfer, gboolean do_wait)
1.887 {
1.888 - gboolean ret = TRUE;
1.889 - GMythFileTransferPrivate *priv;
1.890 + gboolean ret = TRUE;
1.891 + GMythFileTransferPrivate *priv;
1.892
1.893 - g_return_val_if_fail(transfer != NULL, FALSE);
1.894 - priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.895 + g_return_val_if_fail(transfer != NULL, FALSE);
1.896 + priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.897
1.898 - g_mutex_lock(priv->mutex);
1.899 - return ret;
1.900 + g_mutex_lock(priv->mutex);
1.901 + return ret;
1.902 }
1.903
1.904 /**
1.905 @@ -645,18 +666,18 @@
1.906 *
1.907 * @return <code>true</code>, if the socket read/write permissions had been releaseds.
1.908 */
1.909 -static gboolean
1.910 +static gboolean
1.911 _control_release_context(GMythFileTransfer * transfer)
1.912 {
1.913 - gboolean ret = TRUE;
1.914 - GMythFileTransferPrivate *priv;
1.915 + gboolean ret = TRUE;
1.916 + GMythFileTransferPrivate *priv;
1.917
1.918 - g_return_val_if_fail(transfer != NULL, FALSE);
1.919 - priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.920 + g_return_val_if_fail(transfer != NULL, FALSE);
1.921 + priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.922
1.923 - g_mutex_unlock(priv->mutex);
1.924 + g_mutex_unlock(priv->mutex);
1.925
1.926 - return ret;
1.927 + return ret;
1.928 }
1.929
1.930 /**
1.931 @@ -674,249 +695,252 @@
1.932 */
1.933 GMythFileReadResult
1.934 gmyth_file_transfer_read(GMythFileTransfer * transfer, GByteArray * data,
1.935 - gint size, gboolean read_unlimited)
1.936 + gint size, gboolean read_unlimited)
1.937 {
1.938 - gint bytes_sent = 0;
1.939 - gsize bytes_read = 0;
1.940 - gint64 total_read = 0;
1.941 - GMythFileReadResult retval = GMYTH_FILE_READ_OK;
1.942 - GMythFileTransferPrivate *priv;
1.943 + gint bytes_sent = 0;
1.944 + gsize bytes_read = 0;
1.945 + gint64 total_read = 0;
1.946 + GMythFileReadResult retval = GMYTH_FILE_READ_OK;
1.947 + GMythFileTransferPrivate *priv;
1.948
1.949 - GError *error = NULL;
1.950 + GError *error = NULL;
1.951
1.952 - GIOChannel *io_channel;
1.953 - GIOChannel *io_channel_control;
1.954 + GIOChannel *io_channel;
1.955 + GIOChannel *io_channel_control;
1.956
1.957 - GIOCondition io_cond;
1.958 - GIOCondition io_cond_control;
1.959 - GIOStatus io_status = G_IO_STATUS_NORMAL;
1.960 - GIOStatus io_status_control = G_IO_STATUS_NORMAL;
1.961 + GIOCondition io_cond;
1.962 + GIOCondition io_cond_control;
1.963 + GIOStatus io_status = G_IO_STATUS_NORMAL;
1.964 + GIOStatus io_status_control = G_IO_STATUS_NORMAL;
1.965
1.966 - GMythStringList *strlist;
1.967 - GMythStringList *ret_strlist = NULL;
1.968 - gboolean ret = TRUE;
1.969 - GString *query;
1.970 + GMythStringList *strlist;
1.971 + GMythStringList *ret_strlist = NULL;
1.972 + gboolean ret = TRUE;
1.973 + GString *query;
1.974
1.975 - g_return_val_if_fail(transfer != NULL, FALSE);
1.976 - g_return_val_if_fail(data != NULL, GMYTH_FILE_READ_ERROR);
1.977 + g_return_val_if_fail(transfer != NULL, FALSE);
1.978 + g_return_val_if_fail(data != NULL, GMYTH_FILE_READ_ERROR);
1.979
1.980 - priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.981 + priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.982
1.983 - strlist = gmyth_string_list_new();
1.984 + strlist = gmyth_string_list_new();
1.985
1.986 - io_channel = priv->sock->sd_io_ch;
1.987 - io_channel_control = priv->control_sock->sd_io_ch;
1.988 + io_channel = priv->sock->sd_io_ch;
1.989 + io_channel_control = priv->control_sock->sd_io_ch;
1.990
1.991 - io_status = g_io_channel_set_encoding(io_channel, NULL, &error);
1.992 - if (io_status == G_IO_STATUS_NORMAL)
1.993 - gmyth_debug("[%s] Setting encoding to binary data socket).\n",
1.994 - __FUNCTION__);
1.995 + io_status = g_io_channel_set_encoding(io_channel, NULL, &error);
1.996 + if (io_status == G_IO_STATUS_NORMAL)
1.997 + gmyth_debug("[%s] Setting encoding to binary data socket).\n",
1.998 + __FUNCTION__);
1.999
1.1000 - io_cond = g_io_channel_get_buffer_condition(io_channel);
1.1001 + io_cond = g_io_channel_get_buffer_condition(io_channel);
1.1002
1.1003 - io_cond_control = g_io_channel_get_buffer_condition(io_channel);
1.1004 - if (priv->sock == NULL || (io_status == G_IO_STATUS_ERROR))
1.1005 - {
1.1006 - g_printerr("gmyth_file_transfer_read(): Called with no raw socket.\n");
1.1007 - return GMYTH_FILE_READ_ERROR;
1.1008 - }
1.1009 + io_cond_control = g_io_channel_get_buffer_condition(io_channel);
1.1010 + if (priv->sock == NULL || (io_status == G_IO_STATUS_ERROR)) {
1.1011 + g_printerr
1.1012 + ("gmyth_file_transfer_read(): Called with no raw socket.\n");
1.1013 + return GMYTH_FILE_READ_ERROR;
1.1014 + }
1.1015
1.1016 - if (priv->control_sock == NULL || (io_status_control == G_IO_STATUS_ERROR))
1.1017 - {
1.1018 - g_printerr
1.1019 - ("gmyth_file_transfer_read(): Called with no control socket.\n");
1.1020 - return GMYTH_FILE_READ_ERROR;
1.1021 - }
1.1022 + if (priv->control_sock == NULL
1.1023 + || (io_status_control == G_IO_STATUS_ERROR)) {
1.1024 + g_printerr
1.1025 + ("gmyth_file_transfer_read(): Called with no control socket.\n");
1.1026 + return GMYTH_FILE_READ_ERROR;
1.1027 + }
1.1028
1.1029 - query = g_string_new(GMYTHTV_QUERY_HEADER);
1.1030 - g_string_append_printf(query, "%d", priv->file_id);
1.1031 - gmyth_debug("[%s] Transfer_query = %s\n", __FUNCTION__, query->str);
1.1032 + query = g_string_new(GMYTHTV_QUERY_HEADER);
1.1033 + g_string_append_printf(query, "%d", priv->file_id);
1.1034 + gmyth_debug("[%s] Transfer_query = %s\n", __FUNCTION__, query->str);
1.1035
1.1036 - _control_acquire_context(transfer, TRUE);
1.1037 - //Do Read
1.1038 - gmyth_string_list_append_char_array(strlist, query->str);
1.1039 - gmyth_string_list_append_char_array(strlist, "REQUEST_BLOCK");
1.1040 - gmyth_string_list_append_int(strlist, size - total_read);
1.1041 + _control_acquire_context(transfer, TRUE);
1.1042 + // Do Read
1.1043 + gmyth_string_list_append_char_array(strlist, query->str);
1.1044 + gmyth_string_list_append_char_array(strlist, "REQUEST_BLOCK");
1.1045 + gmyth_string_list_append_int(strlist, size - total_read);
1.1046
1.1047 - guint iter_count = 3;
1.1048 + guint iter_count = 3;
1.1049
1.1050 - do
1.1051 - {
1.1052 - bytes_sent = 0;
1.1053 + do {
1.1054 + bytes_sent = 0;
1.1055
1.1056 - // Request the block to the backend
1.1057 - gmyth_socket_write_stringlist(priv->control_sock, strlist);
1.1058 + // Request the block to the backend
1.1059 + gmyth_socket_write_stringlist(priv->control_sock, strlist);
1.1060
1.1061 - if (ret_strlist != NULL)
1.1062 - g_object_unref(ret_strlist);
1.1063 + if (ret_strlist != NULL)
1.1064 + g_object_unref(ret_strlist);
1.1065
1.1066 - ret_strlist = gmyth_string_list_new();
1.1067 - // Receives the backand answer
1.1068 - gmyth_socket_read_stringlist(priv->control_sock, ret_strlist);
1.1069 + ret_strlist = gmyth_string_list_new();
1.1070 + // Receives the backand answer
1.1071 + gmyth_socket_read_stringlist(priv->control_sock, ret_strlist);
1.1072
1.1073 - if (ret_strlist != NULL && gmyth_string_list_length(ret_strlist) > 0)
1.1074 - {
1.1075 - bytes_sent = gmyth_string_list_get_int(ret_strlist, 0); // -1 on backend error
1.1076 - gmyth_debug("[%s] got SENT buffer message = %d\n", __FUNCTION__,
1.1077 - bytes_sent);
1.1078 - }
1.1079 + if (ret_strlist != NULL
1.1080 + && gmyth_string_list_length(ret_strlist) > 0) {
1.1081 + bytes_sent = gmyth_string_list_get_int(ret_strlist, 0); // -1
1.1082 + // on
1.1083 + // backend
1.1084 + // error
1.1085 + gmyth_debug("[%s] got SENT buffer message = %d\n",
1.1086 + __FUNCTION__, bytes_sent);
1.1087 + }
1.1088
1.1089 - if (read_unlimited && (bytes_sent == 0))
1.1090 - {
1.1091 - g_usleep(300);
1.1092 - }
1.1093 + if (read_unlimited && (bytes_sent == 0)) {
1.1094 + g_usleep(300);
1.1095 + }
1.1096
1.1097 - --iter_count;
1.1098 + --iter_count;
1.1099
1.1100 - }
1.1101 - while (read_unlimited && (bytes_sent == 0) && iter_count > 0);
1.1102 + }
1.1103 + while (read_unlimited && (bytes_sent == 0) && iter_count > 0);
1.1104
1.1105 - if (bytes_sent > 0)
1.1106 - {
1.1107 - gchar *data_buffer = g_new0(gchar, bytes_sent);
1.1108 + if (bytes_sent > 0) {
1.1109 + gchar *data_buffer = g_new0(gchar, bytes_sent);
1.1110
1.1111 - io_status = g_io_channel_read_chars(io_channel,
1.1112 - data_buffer, (gsize) bytes_sent,
1.1113 - &bytes_read, &error);
1.1114 + io_status = g_io_channel_read_chars(io_channel,
1.1115 + data_buffer,
1.1116 + (gsize) bytes_sent,
1.1117 + &bytes_read, &error);
1.1118
1.1119 - if (io_status != G_IO_STATUS_NORMAL)
1.1120 - {
1.1121 - gmyth_debug("Error on io_channel");
1.1122 - g_free(data_buffer);
1.1123 - g_object_unref(strlist);
1.1124 - retval = GMYTH_FILE_READ_ERROR;
1.1125 - goto error;
1.1126 - }
1.1127 + if (io_status != G_IO_STATUS_NORMAL) {
1.1128 + gmyth_debug("Error on io_channel");
1.1129 + g_free(data_buffer);
1.1130 + g_object_unref(strlist);
1.1131 + retval = GMYTH_FILE_READ_ERROR;
1.1132 + goto error;
1.1133 + }
1.1134
1.1135 - /* append new data to the increasing byte array */
1.1136 - data =
1.1137 - g_byte_array_append(data, (const guint8 *) data_buffer, bytes_read);
1.1138 - gmyth_file_set_offset(GMYTH_FILE(transfer),
1.1139 - gmyth_file_get_offset(GMYTH_FILE
1.1140 - (transfer)) + bytes_read);
1.1141 + /*
1.1142 + * append new data to the increasing byte array
1.1143 + */
1.1144 + data =
1.1145 + g_byte_array_append(data, (const guint8 *) data_buffer,
1.1146 + bytes_read);
1.1147 + gmyth_file_set_offset(GMYTH_FILE(transfer),
1.1148 + gmyth_file_get_offset(GMYTH_FILE(transfer)) +
1.1149 + bytes_read);
1.1150
1.1151 - if (!read_unlimited
1.1152 - && (gmyth_file_get_filesize(GMYTH_FILE(transfer)) > 0)
1.1153 - && (gmyth_file_get_offset(GMYTH_FILE(transfer)) ==
1.1154 - gmyth_file_get_filesize(GMYTH_FILE(transfer))))
1.1155 - {
1.1156 - retval = GMYTH_FILE_READ_EOF;
1.1157 - goto error;
1.1158 - }
1.1159 + if (!read_unlimited
1.1160 + && (gmyth_file_get_filesize(GMYTH_FILE(transfer)) > 0)
1.1161 + && (gmyth_file_get_offset(GMYTH_FILE(transfer)) ==
1.1162 + gmyth_file_get_filesize(GMYTH_FILE(transfer)))) {
1.1163 + retval = GMYTH_FILE_READ_EOF;
1.1164 + goto error;
1.1165 + }
1.1166
1.1167 - g_free(data_buffer);
1.1168 - }
1.1169 - else
1.1170 - {
1.1171 - retval = GMYTH_FILE_READ_ERROR;
1.1172 - }
1.1173 + g_free(data_buffer);
1.1174 + } else {
1.1175 + retval = GMYTH_FILE_READ_ERROR;
1.1176 + }
1.1177
1.1178 - if (strlist != NULL)
1.1179 - {
1.1180 - g_object_unref(strlist);
1.1181 - strlist = NULL;
1.1182 - }
1.1183 + if (strlist != NULL) {
1.1184 + g_object_unref(strlist);
1.1185 + strlist = NULL;
1.1186 + }
1.1187
1.1188 - if (ret_strlist != NULL)
1.1189 - {
1.1190 - g_object_unref(ret_strlist);
1.1191 - ret_strlist = NULL;
1.1192 - }
1.1193 + if (ret_strlist != NULL) {
1.1194 + g_object_unref(ret_strlist);
1.1195 + ret_strlist = NULL;
1.1196 + }
1.1197
1.1198 - if (read_unlimited && (bytes_sent == 0))
1.1199 - {
1.1200 - gmyth_debug("Trying to move to the next program chain...");
1.1201 - if (priv->recorder != NULL && priv->do_next_program_chain)
1.1202 - {
1.1203 - priv->do_next_program_chain = FALSE;
1.1204 - retval = GMYTH_FILE_READ_NEXT_PROG_CHAIN;
1.1205 - GMythProgramInfo *prog_info =
1.1206 - gmyth_recorder_get_current_program_info(priv->recorder);
1.1207 + if (read_unlimited && (bytes_sent == 0)) {
1.1208 + gmyth_debug("Trying to move to the next program chain...");
1.1209 + if (priv->recorder != NULL && priv->do_next_program_chain) {
1.1210 + priv->do_next_program_chain = FALSE;
1.1211 + retval = GMYTH_FILE_READ_NEXT_PROG_CHAIN;
1.1212 + GMythProgramInfo *prog_info =
1.1213 + gmyth_recorder_get_current_program_info(priv->recorder);
1.1214
1.1215 - gmyth_debug
1.1216 - ("Comparing if the current prog. info = %s [strlen == %d] is equals to "
1.1217 - " %s [strlen == %d]...", prog_info->pathname->str,
1.1218 - strlen(prog_info->pathname->str),
1.1219 - gmyth_file_get_file_name(GMYTH_FILE(transfer)),
1.1220 - strlen(gmyth_file_get_file_name(GMYTH_FILE(transfer))));
1.1221 + gmyth_debug
1.1222 + ("Comparing if the current prog. info = %s [strlen == %d] is equals to "
1.1223 + " %s [strlen == %d]...", prog_info->pathname->str,
1.1224 + strlen(prog_info->pathname->str),
1.1225 + gmyth_file_get_file_name(GMYTH_FILE(transfer)),
1.1226 + strlen(gmyth_file_get_file_name(GMYTH_FILE(transfer))));
1.1227
1.1228 - if (prog_info != NULL && prog_info->pathname != NULL
1.1229 - && strlen(prog_info->pathname->str) > 0
1.1230 - && (NULL ==
1.1231 - g_strstr_len(prog_info->pathname->str,
1.1232 - strlen(prog_info->pathname->str),
1.1233 - gmyth_file_get_file_name(GMYTH_FILE
1.1234 - (transfer)))))
1.1235 - {
1.1236 - /* releasing context got at this function starting... */
1.1237 - _control_release_context(transfer);
1.1238 - ret =
1.1239 - gmyth_file_transfer_open(transfer,
1.1240 - g_strrstr(prog_info->pathname->str,
1.1241 - "/"));
1.1242 - _control_acquire_context(transfer, TRUE);
1.1243 - /* acquiring context released at this function stopping... */
1.1244 + if (prog_info != NULL && prog_info->pathname != NULL
1.1245 + && strlen(prog_info->pathname->str) > 0
1.1246 + && (NULL ==
1.1247 + g_strstr_len(prog_info->pathname->str,
1.1248 + strlen(prog_info->pathname->str),
1.1249 + gmyth_file_get_file_name(GMYTH_FILE
1.1250 + (transfer))))) {
1.1251 + /*
1.1252 + * releasing context got at this function starting...
1.1253 + */
1.1254 + _control_release_context(transfer);
1.1255 + ret =
1.1256 + gmyth_file_transfer_open(transfer,
1.1257 + g_strrstr(prog_info->
1.1258 + pathname->str,
1.1259 + "/"));
1.1260 + _control_acquire_context(transfer, TRUE);
1.1261 + /*
1.1262 + * acquiring context released at this function stopping...
1.1263 + */
1.1264
1.1265 - if (prog_info != NULL)
1.1266 - g_object_unref(prog_info);
1.1267 + if (prog_info != NULL)
1.1268 + g_object_unref(prog_info);
1.1269
1.1270 - if (!ret)
1.1271 - gmyth_debug("Cannot change to the next program info!");
1.1272 - else
1.1273 - gmyth_debug("OK!!! MOVED to the next program info [%s]!",
1.1274 - gmyth_file_get_file_name(GMYTH_FILE(transfer)));
1.1275 - }
1.1276 + if (!ret)
1.1277 + gmyth_debug("Cannot change to the next program info!");
1.1278 + else
1.1279 + gmyth_debug
1.1280 + ("OK!!! MOVED to the next program info [%s]!",
1.1281 + gmyth_file_get_file_name(GMYTH_FILE(transfer)));
1.1282 + }
1.1283
1.1284 - }
1.1285 + }
1.1286
1.1287 - } /* if */
1.1288 + }
1.1289 + /*
1.1290 + * if
1.1291 + */
1.1292 + error:
1.1293
1.1294 -error:
1.1295 + _control_release_context(transfer);
1.1296 + g_string_free(query, TRUE);
1.1297
1.1298 - _control_release_context(transfer);
1.1299 - g_string_free(query, TRUE);
1.1300 + if (error != NULL) {
1.1301 + gmyth_debug("Cleaning-up ERROR: %s [msg = %s, code = %d]\n",
1.1302 + __FUNCTION__, error->message, error->code);
1.1303 + g_error_free(error);
1.1304 + }
1.1305
1.1306 - if (error != NULL)
1.1307 - {
1.1308 - gmyth_debug("Cleaning-up ERROR: %s [msg = %s, code = %d]\n",
1.1309 - __FUNCTION__, error->message, error->code);
1.1310 - g_error_free(error);
1.1311 - }
1.1312 + if (total_read > 0)
1.1313 + gmyth_file_set_offset(GMYTH_FILE(transfer),
1.1314 + gmyth_file_get_offset(GMYTH_FILE
1.1315 + (transfer)) +
1.1316 + total_read);
1.1317
1.1318 - if (total_read > 0)
1.1319 - gmyth_file_set_offset(GMYTH_FILE(transfer),
1.1320 - gmyth_file_get_offset(GMYTH_FILE
1.1321 - (transfer)) + total_read);
1.1322 -
1.1323 - return retval;
1.1324 + return retval;
1.1325 }
1.1326
1.1327 static void
1.1328 _file_transfer_program_info_changed(GMythFileTransfer * transfer,
1.1329 - gint msg_code, gpointer livetv_recorder)
1.1330 + gint msg_code,
1.1331 + gpointer livetv_recorder)
1.1332 {
1.1333 - GMythRecorder *recorder;
1.1334 - GMythFileTransferPrivate *priv;
1.1335 + GMythRecorder *recorder;
1.1336 + GMythFileTransferPrivate *priv;
1.1337
1.1338 - g_return_if_fail(transfer != NULL);
1.1339 + g_return_if_fail(transfer != NULL);
1.1340
1.1341 - priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.1342 + priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.1343
1.1344 - recorder = GMYTH_RECORDER(livetv_recorder);
1.1345 - gmyth_debug
1.1346 - ("Program info changed! ( file transfer orig. = %p, ptr. = [%s] )",
1.1347 - transfer, livetv_recorder != NULL ? "[NOT NULL]" : "[NULL]");
1.1348 + recorder = GMYTH_RECORDER(livetv_recorder);
1.1349 + gmyth_debug
1.1350 + ("Program info changed! ( file transfer orig. = %p, ptr. = [%s] )",
1.1351 + transfer, livetv_recorder != NULL ? "[NOT NULL]" : "[NULL]");
1.1352
1.1353 - if (NULL != recorder)
1.1354 - {
1.1355 - gmyth_debug
1.1356 - ("YES, the requested program info movement on the LiveTV transfer is authentical!");
1.1357 - }
1.1358 + if (NULL != recorder) {
1.1359 + gmyth_debug
1.1360 + ("YES, the requested program info movement on the LiveTV transfer is authentical!");
1.1361 + }
1.1362
1.1363 - priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.1364 - g_object_ref(recorder);
1.1365 - priv->recorder = recorder;
1.1366 - priv->do_next_program_chain = TRUE;
1.1367 + priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.1368 + g_object_ref(recorder);
1.1369 + priv->recorder = recorder;
1.1370 + priv->do_next_program_chain = TRUE;
1.1371 }
1.1372
1.1373 /**
1.1374 @@ -931,40 +955,42 @@
1.1375 gboolean
1.1376 gmyth_file_transfer_settimeout(GMythFileTransfer * transfer, gboolean fast)
1.1377 {
1.1378 - GMythFileTransferPrivate *priv;
1.1379 - GMythStringList *strlist = NULL;
1.1380 + GMythFileTransferPrivate *priv;
1.1381 + GMythStringList *strlist = NULL;
1.1382
1.1383 - g_return_val_if_fail(transfer != NULL, FALSE);
1.1384 + g_return_val_if_fail(transfer != NULL, FALSE);
1.1385
1.1386 - priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.1387 + priv = GMYTH_FILE_TRANSFER_GET_PRIVATE(transfer);
1.1388
1.1389 - g_return_val_if_fail(priv->sock != NULL, FALSE);
1.1390 - g_return_val_if_fail(priv->control_sock != NULL, FALSE);
1.1391 + g_return_val_if_fail(priv->sock != NULL, FALSE);
1.1392 + g_return_val_if_fail(priv->control_sock != NULL, FALSE);
1.1393
1.1394 - _control_acquire_context(transfer, TRUE);
1.1395 + _control_acquire_context(transfer, TRUE);
1.1396
1.1397 - strlist = gmyth_string_list_new();
1.1398 - gmyth_string_list_append_char_array(strlist, GMYTHTV_QUERY_HEADER);
1.1399 - gmyth_string_list_append_char_array(strlist, "SET_TIMEOUT");
1.1400 - gmyth_string_list_append_int(strlist, fast);
1.1401 + strlist = gmyth_string_list_new();
1.1402 + gmyth_string_list_append_char_array(strlist, GMYTHTV_QUERY_HEADER);
1.1403 + gmyth_string_list_append_char_array(strlist, "SET_TIMEOUT");
1.1404 + gmyth_string_list_append_int(strlist, fast);
1.1405
1.1406 - gint strlist_len = gmyth_socket_sendreceive_stringlist(priv->control_sock,
1.1407 - strlist);
1.1408 + gint strlist_len =
1.1409 + gmyth_socket_sendreceive_stringlist(priv->control_sock,
1.1410 + strlist);
1.1411
1.1412 - if (strlist_len > 0)
1.1413 - gmyth_debug("Yes, timeout was changed: %s.",
1.1414 - gmyth_string_list_get_char_array(strlist, 0));
1.1415 - else
1.1416 - gmyth_debug("Timeout cannot be changed!");
1.1417 + if (strlist_len > 0)
1.1418 + gmyth_debug("Yes, timeout was changed: %s.",
1.1419 + gmyth_string_list_get_char_array(strlist, 0));
1.1420 + else
1.1421 + gmyth_debug("Timeout cannot be changed!");
1.1422
1.1423 - _control_release_context(transfer);
1.1424 + _control_release_context(transfer);
1.1425
1.1426 - gmyth_debug("%s setting timeout flag of this file transfer = %s\n",
1.1427 - strlist_len > 0 ? "Yes," : "NOT", fast ? "FAST" : "NOT FAST");
1.1428 + gmyth_debug("%s setting timeout flag of this file transfer = %s\n",
1.1429 + strlist_len > 0 ? "Yes," : "NOT",
1.1430 + fast ? "FAST" : "NOT FAST");
1.1431
1.1432 - g_object_unref(strlist);
1.1433 + g_object_unref(strlist);
1.1434
1.1435 - return TRUE;
1.1436 + return TRUE;
1.1437 }
1.1438
1.1439 /**
1.1440 @@ -977,11 +1003,11 @@
1.1441 guint64
1.1442 gmyth_file_transfer_get_filesize(GMythFileTransfer * transfer)
1.1443 {
1.1444 - guint64 filesize;
1.1445 + guint64 filesize;
1.1446
1.1447 - g_return_val_if_fail(transfer != NULL, 0);
1.1448 + g_return_val_if_fail(transfer != NULL, 0);
1.1449
1.1450 - g_object_get(GMYTH_FILE(transfer), "file-size", &filesize, NULL);
1.1451 + g_object_get(GMYTH_FILE(transfer), "file-size", &filesize, NULL);
1.1452
1.1453 - return filesize;
1.1454 + return filesize;
1.1455 }