branches/gmyth-0.1b/src/gmyth_socket.h
author rosfran
Fri Feb 02 22:46:13 2007 +0000 (2007-02-02)
branchtrunk
changeset 325 b6b5f2dc831d
permissions -rw-r--r--
[svn r327] Changes due the API change on LiveTV.
renatofilho@320
     1
/**
renatofilho@320
     2
 * GMyth Library
renatofilho@320
     3
 *
renatofilho@320
     4
 * @file gmyth/gmyth_socket.h
renatofilho@320
     5
 * 
renatofilho@320
     6
 * @brief <p> MythTV socket implementation, according to the MythTV Project
renatofilho@320
     7
 * (www.mythtv.org). 
renatofilho@320
     8
 * 
renatofilho@320
     9
 * This component provides basic socket functionalities to interact with
renatofilho@320
    10
 * the Mythtv backend.
renatofilho@320
    11
 * <p>
renatofilho@320
    12
 *
renatofilho@320
    13
 * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
renatofilho@320
    14
 * @author Rosfran Lins Borges <rosfran.borges@indt.org.br> 
renatofilho@320
    15
 *
renatofilho@320
    16
 *//*
renatofilho@320
    17
 * 
renatofilho@320
    18
 * This program is free software; you can redistribute it and/or modify
renatofilho@320
    19
 * it under the terms of the GNU Lesser General Public License as published by
renatofilho@320
    20
 * the Free Software Foundation; either version 2 of the License, or
renatofilho@320
    21
 * (at your option) any later version.
renatofilho@320
    22
 *
renatofilho@320
    23
 * This program is distributed in the hope that it will be useful,
renatofilho@320
    24
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
renatofilho@320
    25
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
renatofilho@320
    26
 * GNU General Public License for more details.
renatofilho@320
    27
 *
renatofilho@320
    28
 * You should have received a copy of the GNU Lesser General Public License
renatofilho@320
    29
 * along with this program; if not, write to the Free Software
renatofilho@320
    30
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
renatofilho@320
    31
 */
renatofilho@320
    32
renatofilho@320
    33
#ifndef __GMYTH_SOCKET_H__
renatofilho@320
    34
#define __GMYTH_SOCKET_H__
renatofilho@320
    35
renatofilho@320
    36
#include <glib-object.h>
renatofilho@320
    37
renatofilho@320
    38
#include <string.h>
renatofilho@320
    39
#include <netdb.h>
renatofilho@320
    40
#include <sys/socket.h>
renatofilho@320
    41
#include <unistd.h>
renatofilho@320
    42
#include <glib.h>
renatofilho@320
    43
renatofilho@320
    44
#include "gmyth_stringlist.h"
renatofilho@320
    45
renatofilho@320
    46
G_BEGIN_DECLS
renatofilho@320
    47
renatofilho@320
    48
#define GMYTH_SOCKET_TYPE               (gmyth_socket_get_type ())
renatofilho@320
    49
#define GMYTH_SOCKET(obj)               (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMYTH_SOCKET_TYPE, GMythSocket))
renatofilho@320
    50
#define GMYTH_SOCKET_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_SOCKET_TYPE, GMythSocketClass))
renatofilho@320
    51
#define IS_GMYTH_SOCKET(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMYTH_SOCKET_TYPE))
renatofilho@320
    52
#define IS_GMYTH_SOCKET_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_SOCKET_TYPE))
renatofilho@320
    53
#define GMYTH_SOCKET_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS ((obj), GMYTH_SOCKET_TYPE, GMythSocketClass))
renatofilho@320
    54
renatofilho@320
    55
renatofilho@320
    56
typedef struct _GMythSocket         GMythSocket;
renatofilho@320
    57
typedef struct _GMythSocketClass    GMythSocketClass;
renatofilho@320
    58
renatofilho@320
    59
struct _GMythSocketClass
renatofilho@320
    60
{
renatofilho@320
    61
	GObjectClass parent_class;
renatofilho@320
    62
renatofilho@320
    63
	/* callbacks */
renatofilho@320
    64
	/* no one for now */
renatofilho@320
    65
};
renatofilho@320
    66
renatofilho@320
    67
struct _GMythSocket
renatofilho@320
    68
{
renatofilho@320
    69
	GObject parent;
renatofilho@320
    70
renatofilho@320
    71
	/* socket descriptor */
renatofilho@320
    72
	gint sd;
renatofilho@320
    73
	GIOChannel *sd_io_ch;
renatofilho@320
    74
renatofilho@320
    75
	gchar *hostname;
renatofilho@320
    76
	gint port;
renatofilho@320
    77
	gint mythtv_version;
renatofilho@320
    78
};
renatofilho@320
    79
renatofilho@320
    80
/* used when no protocol version number was negotiated */
renatofilho@320
    81
#define	MYTHTV_CANNOT_NEGOTIATE_VERSION		0
renatofilho@320
    82
renatofilho@320
    83
GType           gmyth_socket_get_type (void);
renatofilho@320
    84
renatofilho@320
    85
GMythSocket *   gmyth_socket_new ();
renatofilho@320
    86
renatofilho@320
    87
gboolean        gmyth_socket_connect (GMythSocket *gmyth_socket, const gchar *hostname, gint port);
renatofilho@320
    88
renatofilho@320
    89
renatofilho@320
    90
GIOChannel *    gmyth_socket_get_io_channel (GMythSocket *gmyth_socket );
renatofilho@320
    91
renatofilho@320
    92
gboolean        gmyth_socket_is_able_to_read (GMythSocket *gmyth_socket );
renatofilho@320
    93
gboolean        gmyth_socket_is_able_to_write (GMythSocket *gmyth_socket );
renatofilho@320
    94
renatofilho@320
    95
gboolean        gmyth_socket_send_command (GMythSocket *gmyth_socket, 
renatofilho@320
    96
                                           GString *command);
renatofilho@320
    97
GString *       gmyth_socket_receive_response (GMythSocket *gmyth_socket);
renatofilho@320
    98
gint            gmyth_socket_sendreceive_stringlist (GMythSocket *gmyth_socket, 
renatofilho@320
    99
                                                     GMythStringList *str_list);
renatofilho@320
   100
renatofilho@320
   101
gboolean        gmyth_socket_connect (GMythSocket *gmyth_socket,
renatofilho@320
   102
                                      const gchar *hostname, gint port);
renatofilho@320
   103
gboolean        gmyth_socket_connect_with_timeout (GMythSocket *gmyth_socket,
renatofilho@320
   104
		        const gchar *hostname, gint port, guint timeout);
renatofilho@320
   105
renatofilho@320
   106
gboolean        gmyth_socket_connect_to_backend (GMythSocket *gmyth_socket, 
renatofilho@320
   107
                           const gchar *hostname_backend, gint port, 
renatofilho@320
   108
                           gboolean blocking_client);
renatofilho@320
   109
renatofilho@320
   110
gboolean        gmyth_socket_connect_to_backend_events (GMythSocket *gmyth_socket, 
renatofilho@320
   111
                           const gchar *hostname_backend, gint port, 
renatofilho@320
   112
                           gboolean blocking_client);
renatofilho@320
   113
renatofilho@320
   114
GString *       gmyth_socket_get_local_hostname (void);
renatofilho@320
   115
renatofilho@320
   116
void            gmyth_socket_close_connection (GMythSocket *gmyth_socket);
renatofilho@320
   117
renatofilho@320
   118
gboolean		gmyth_socket_check_protocol_version (GMythSocket *gmyth_socket);
renatofilho@320
   119
gint				gmyth_socket_check_protocol_version_number (GMythSocket *gmyth_socket, 
renatofilho@320
   120
                                                            gint mythtv_version);
renatofilho@320
   121
renatofilho@320
   122
gint				gmyth_socket_get_protocol_version (GMythSocket *gmyth_socket);
renatofilho@320
   123
renatofilho@320
   124
gboolean		gmyth_socket_write_stringlist(GMythSocket *gmyth_socket, 
renatofilho@320
   125
                                              GMythStringList* str_list);
renatofilho@320
   126
gint			    gmyth_socket_read_stringlist(GMythSocket *gmyth_socket, 
renatofilho@320
   127
                                             GMythStringList* str_list);
renatofilho@320
   128
G_END_DECLS
renatofilho@320
   129
renatofilho@320
   130
#endif /* __GMYTH_SOCKET_H__ */