connection.c File Reference

Functions to handle creating connections to a MythTV backend and interacting with those connections. More...

#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <errno.h>
#include <string.h>
#include <signal.h>
#include <mvp_refmem.h>
#include <cmyth.h>
#include <cmyth_local.h>

Go to the source code of this file.

Functions

static void cmyth_conn_destroy (cmyth_conn_t conn)
static cmyth_conn_t cmyth_conn_create (void)
static void sighandler (int sig)
static cmyth_conn_t cmyth_connect (char *server, unsigned short port, unsigned buflen, int tcp_rcvbuf)
static cmyth_conn_t cmyth_conn_connect (char *server, unsigned short port, unsigned buflen, int tcp_rcvbuf, int event)
cmyth_conn_t cmyth_conn_connect_ctrl (char *server, unsigned short port, unsigned buflen, int tcp_rcvbuf)
 Create a control connection to a backend.
cmyth_conn_t cmyth_conn_connect_event (char *server, unsigned short port, unsigned buflen, int tcp_rcvbuf)
 Create an event connection to a backend.
cmyth_file_t cmyth_conn_connect_file (cmyth_proginfo_t prog, cmyth_conn_t control, unsigned buflen, int tcp_rcvbuf)
 Create a file connection to a backend.
int cmyth_conn_connect_ring (cmyth_recorder_t rec, unsigned buflen, int tcp_rcvbuf)
 Create a ring buffer connection to a recorder.
int cmyth_conn_connect_recorder (cmyth_recorder_t rec, unsigned buflen, int tcp_rcvbuf)
 Create a connection to a recorder.
int cmyth_conn_check_block (cmyth_conn_t conn, unsigned long size)
 Check whether a block has finished transfering from a backend.
cmyth_recorder_t cmyth_conn_get_recorder_from_num (cmyth_conn_t conn, int id)
 Obtain a recorder from a connection by its recorder number.
cmyth_recorder_t cmyth_conn_get_free_recorder (cmyth_conn_t conn)
 Obtain the next available free recorder on a backend.
int cmyth_conn_get_freespace (cmyth_conn_t control, long long *total, long long *used)
 Get the amount of free disk space on a backend.
int cmyth_conn_hung (cmyth_conn_t control)
 Determine if a control connection is not responding.
int cmyth_conn_get_protocol_version (cmyth_conn_t conn)
 Determine the MythTV protocol version being used.
int cmyth_conn_get_free_recorder_count (cmyth_conn_t conn)
 Determine the number of free recorders.

Variables

pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER
static char my_hostname [128]
static volatile cmyth_socket_t my_fd


Detailed Description

Functions to handle creating connections to a MythTV backend and interacting with those connections.

Definition in file connection.c.


Function Documentation

int cmyth_conn_check_block cmyth_conn_t  conn,
unsigned long  size
 

Check whether a block has finished transfering from a backend.

Parameters:
conn control handle
size size of block
Return values:
0 not complete
1 complete
<0 error

Definition at line 690 of file connection.c.

References cmyth_dbg(), CMYTH_DBG_DEBUG, CMYTH_DBG_ERROR, cmyth_rcv_length, cmyth_rcv_ulong, cmyth_conn::conn_fd, and errno.

static cmyth_conn_t cmyth_conn_connect char *  server,
unsigned short  port,
unsigned  buflen,
int  tcp_rcvbuf,
int  event
[static]
 

Definition at line 292 of file connection.c.

References cmyth_connect(), cmyth_dbg(), CMYTH_DBG_ERROR, CMYTH_DBG_PROTO, cmyth_rcv_okay, cmyth_rcv_version, cmyth_send_message, cmyth_conn::conn_version, my_hostname, and ref_release().

Referenced by cmyth_conn_connect_ctrl(), and cmyth_conn_connect_event().

cmyth_conn_t cmyth_conn_connect_ctrl char *  server,
unsigned short  port,
unsigned  buflen,
int  tcp_rcvbuf
 

Create a control connection to a backend.

Parameters:
server server hostname or ip address
port port number to connect on
buflen buffer size for the connection to use
tcp_rcvbuf if non-zero, the TCP receive buffer size for the socket
Returns:
control handle

Definition at line 384 of file connection.c.

References cmyth_conn_connect(), cmyth_dbg(), and CMYTH_DBG_PROTO.

Referenced by cmyth_conn_connect_recorder(), mythtv_init(), and mythtv_open().

cmyth_conn_t cmyth_conn_connect_event char *  server,
unsigned short  port,
unsigned  buflen,
int  tcp_rcvbuf
 

Create an event connection to a backend.

Parameters:
server server hostname or ip address
port port number to connect on
buflen buffer size for the connection to use
tcp_rcvbuf if non-zero, the TCP receive buffer size for the socket
Returns:
event handle

Definition at line 399 of file connection.c.

References cmyth_conn_connect(), cmyth_dbg(), and CMYTH_DBG_PROTO.

Referenced by mythtv_init().

cmyth_file_t cmyth_conn_connect_file cmyth_proginfo_t  prog,
cmyth_conn_t  control,
unsigned  buflen,
int  tcp_rcvbuf
 

Create a file connection to a backend.

Parameters:
prog program handle
control control handle
buflen buffer size for the connection to use
tcp_rcvbuf if non-zero, the TCP receive buffer size for the socket
Returns:
file handle

Definition at line 434 of file connection.c.

References cmyth_connect(), cmyth_dbg(), CMYTH_DBG_ERROR, CMYTH_DBG_PROTO, cmyth_file_create, cmyth_rcv_length, cmyth_rcv_long, cmyth_rcv_string, cmyth_rcv_u_long_long, cmyth_send_message, cmyth_conn::conn_version, control, cmyth_file::file_data, cmyth_file::file_id, cmyth_file::file_length, my_hostname, cmyth_proginfo::proginfo_host, cmyth_proginfo::proginfo_pathname, cmyth_proginfo::proginfo_port, ref_hold(), and ref_release().

Referenced by cmyth_livetv_chain_setup(), cmyth_livetv_chain_update(), and mythtv_open().

int cmyth_conn_connect_recorder cmyth_recorder_t  rec,
unsigned  buflen,
int  tcp_rcvbuf
 

Create a connection to a recorder.

Parameters:
rec recorder to connect to
buflen buffer size for the connection to use
tcp_rcvbuf if non-zero, the TCP receive buffer size for the socket
Return values:
0 success
-1 error

Definition at line 636 of file connection.c.

References cmyth_conn_connect_ctrl(), cmyth_dbg(), CMYTH_DBG_ERROR, CMYTH_DBG_PROTO, port, cmyth_recorder::rec_conn, cmyth_recorder::rec_port, cmyth_recorder::rec_server, and ref_release().

Referenced by cmyth_conn_get_free_recorder(), and cmyth_conn_get_recorder_from_num().

int cmyth_conn_connect_ring cmyth_recorder_t  rec,
unsigned  buflen,
int  tcp_rcvbuf
 

Create a ring buffer connection to a recorder.

Parameters:
rec recorder handle
buflen buffer size for the connection to use
tcp_rcvbuf if non-zero, the TCP receive buffer size for the socket
Return values:
0 success
-1 error

Definition at line 574 of file connection.c.

References cmyth_connect(), cmyth_dbg(), CMYTH_DBG_ERROR, CMYTH_DBG_PROTO, CMYTH_LONG_LEN, cmyth_rcv_okay, cmyth_send_message, cmyth_ringbuf::conn_data, my_hostname, port, cmyth_recorder::rec_id, cmyth_recorder::rec_port, cmyth_recorder::rec_ring, cmyth_recorder::rec_server, and ref_release().

static cmyth_conn_t cmyth_conn_create void   )  [static]
 

Definition at line 95 of file connection.c.

References cmyth_conn_destroy(), cmyth_dbg(), CMYTH_DBG_DEBUG, ref_alloc, and ref_set_destroy().

Referenced by cmyth_connect().

static void cmyth_conn_destroy cmyth_conn_t  conn  )  [static]
 

Definition at line 58 of file connection.c.

References closesocket, cmyth_dbg(), CMYTH_DBG_DEBUG, CMYTH_DBG_PROTO, cmyth_conn::conn_buf, and cmyth_conn::conn_fd.

Referenced by cmyth_conn_create().

cmyth_recorder_t cmyth_conn_get_free_recorder cmyth_conn_t  conn  ) 
 

Obtain the next available free recorder on a backend.

Parameters:
conn connection handle
Returns:
recorder handle

Definition at line 856 of file connection.c.

References cmyth_conn_connect_recorder(), cmyth_dbg(), CMYTH_DBG_ERROR, cmyth_rcv_length, cmyth_rcv_long, cmyth_rcv_string, cmyth_recorder_create(), cmyth_send_message, cmyth_conn::conn_buflen, cmyth_conn::conn_tcp_rcvbuf, mutex, port, cmyth_recorder::rec_id, cmyth_recorder::rec_port, cmyth_recorder::rec_server, ref_release(), and ref_strdup().

int cmyth_conn_get_free_recorder_count cmyth_conn_t  conn  ) 
 

Determine the number of free recorders.

Parameters:
conn connection handle
Returns:
number of free recorders

Definition at line 1054 of file connection.c.

References cmyth_dbg(), CMYTH_DBG_ERROR, cmyth_rcv_length, cmyth_rcv_long, cmyth_send_message, and mutex.

Referenced by mythtv_livetv_start(), and mythtv_new_livetv().

int cmyth_conn_get_freespace cmyth_conn_t  control,
long long *  total,
long long *  used
 

Get the amount of free disk space on a backend.

Parameters:
control control handle
[out] total total disk space
[out] used used disk space
Return values:
0 success
<0 error

Definition at line 939 of file connection.c.

References cmyth_dbg(), CMYTH_DBG_ERROR, cmyth_rcv_length, cmyth_rcv_long_long, cmyth_rcv_string, cmyth_send_message, cmyth_conn::conn_version, control, and mutex.

Referenced by mythtv_update().

int cmyth_conn_get_protocol_version cmyth_conn_t  conn  ) 
 

Determine the MythTV protocol version being used.

Parameters:
conn connection handle
Returns:
protocol version

Definition at line 1041 of file connection.c.

References cmyth_dbg(), CMYTH_DBG_ERROR, and cmyth_conn::conn_version.

Referenced by cmyth_event_get(), mythtv_livetv_menu_start(), mythtv_schedule_recording(), and prog_finder_time_callback().

cmyth_recorder_t cmyth_conn_get_recorder_from_num cmyth_conn_t  conn,
int  num
 

Obtain a recorder from a connection by its recorder number.

Parameters:
conn connection handle
num recorder number
Returns:
recorder handle

Definition at line 760 of file connection.c.

References cmyth_conn_connect_recorder(), cmyth_dbg(), CMYTH_DBG_ERROR, cmyth_rcv_length, cmyth_rcv_long, cmyth_rcv_string, cmyth_recorder_create(), cmyth_send_message, cmyth_conn::conn_buflen, cmyth_conn::conn_tcp_rcvbuf, mutex, port, cmyth_recorder::rec_id, cmyth_recorder::rec_port, cmyth_recorder::rec_server, ref_release(), and ref_strdup().

Referenced by get_livetv_programs_rec(), myth_tvguide_get_free_cardids(), mythtv_livetv_start(), and mythtv_new_livetv().

int cmyth_conn_hung cmyth_conn_t  control  ) 
 

Determine if a control connection is not responding.

Parameters:
control control handle
Return values:
0 not hung
1 hung
<0 error

Definition at line 1032 of file connection.c.

References cmyth_conn::conn_hang, and control.

Referenced by wd_start().

static cmyth_conn_t cmyth_connect char *  server,
unsigned short  port,
unsigned  buflen,
int  tcp_rcvbuf
[static]
 

Definition at line 153 of file connection.c.

References closesocket, cmyth_conn_create(), cmyth_dbg(), CMYTH_DBG_ERROR, CMYTH_DBG_PROTO, cmyth_conn::conn_buf, cmyth_conn::conn_buflen, cmyth_conn::conn_fd, cmyth_conn::conn_len, cmyth_conn::conn_pos, cmyth_conn::conn_tcp_rcvbuf, cmyth_conn::conn_version, errno, fd, my_fd, my_hostname, ref_release(), sighandler(), and SOCK_STREAM.

Referenced by cmyth_conn_connect(), cmyth_conn_connect_file(), and cmyth_conn_connect_ring().

static void sighandler int  sig  )  [static]
 

Definition at line 143 of file connection.c.

References closesocket, and my_fd.


Variable Documentation

pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER
 

Definition at line 40 of file connection.c.

volatile cmyth_socket_t my_fd [static]
 

Definition at line 140 of file connection.c.

Referenced by cmyth_connect(), and sighandler().

char my_hostname[128] [static]
 

Definition at line 139 of file connection.c.

Referenced by cmyth_conn_connect(), cmyth_conn_connect_file(), cmyth_conn_connect_ring(), and cmyth_connect().


Generated on Fri Sep 10 03:13:22 2010 for mvpmc by  doxygen 1.4.6