branches/gmyth-0.1b/src/gmyth_socket.h
branchtrunk
changeset 346 4ba962630375
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/branches/gmyth-0.1b/src/gmyth_socket.h	Fri Feb 09 20:42:28 2007 +0000
     1.3 @@ -0,0 +1,130 @@
     1.4 +/**
     1.5 + * GMyth Library
     1.6 + *
     1.7 + * @file gmyth/gmyth_socket.h
     1.8 + * 
     1.9 + * @brief <p> MythTV socket implementation, according to the MythTV Project
    1.10 + * (www.mythtv.org). 
    1.11 + * 
    1.12 + * This component provides basic socket functionalities to interact with
    1.13 + * the Mythtv backend.
    1.14 + * <p>
    1.15 + *
    1.16 + * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia.
    1.17 + * @author Rosfran Lins Borges <rosfran.borges@indt.org.br> 
    1.18 + *
    1.19 + *//*
    1.20 + * 
    1.21 + * This program is free software; you can redistribute it and/or modify
    1.22 + * it under the terms of the GNU Lesser General Public License as published by
    1.23 + * the Free Software Foundation; either version 2 of the License, or
    1.24 + * (at your option) any later version.
    1.25 + *
    1.26 + * This program is distributed in the hope that it will be useful,
    1.27 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.28 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.29 + * GNU General Public License for more details.
    1.30 + *
    1.31 + * You should have received a copy of the GNU Lesser General Public License
    1.32 + * along with this program; if not, write to the Free Software
    1.33 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.34 + */
    1.35 +
    1.36 +#ifndef __GMYTH_SOCKET_H__
    1.37 +#define __GMYTH_SOCKET_H__
    1.38 +
    1.39 +#include <glib-object.h>
    1.40 +
    1.41 +#include <string.h>
    1.42 +#include <netdb.h>
    1.43 +#include <sys/socket.h>
    1.44 +#include <unistd.h>
    1.45 +#include <glib.h>
    1.46 +
    1.47 +#include "gmyth_stringlist.h"
    1.48 +
    1.49 +G_BEGIN_DECLS
    1.50 +
    1.51 +#define GMYTH_SOCKET_TYPE               (gmyth_socket_get_type ())
    1.52 +#define GMYTH_SOCKET(obj)               (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMYTH_SOCKET_TYPE, GMythSocket))
    1.53 +#define GMYTH_SOCKET_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_SOCKET_TYPE, GMythSocketClass))
    1.54 +#define IS_GMYTH_SOCKET(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMYTH_SOCKET_TYPE))
    1.55 +#define IS_GMYTH_SOCKET_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_SOCKET_TYPE))
    1.56 +#define GMYTH_SOCKET_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS ((obj), GMYTH_SOCKET_TYPE, GMythSocketClass))
    1.57 +
    1.58 +
    1.59 +typedef struct _GMythSocket         GMythSocket;
    1.60 +typedef struct _GMythSocketClass    GMythSocketClass;
    1.61 +
    1.62 +struct _GMythSocketClass
    1.63 +{
    1.64 +	GObjectClass parent_class;
    1.65 +
    1.66 +	/* callbacks */
    1.67 +	/* no one for now */
    1.68 +};
    1.69 +
    1.70 +struct _GMythSocket
    1.71 +{
    1.72 +	GObject parent;
    1.73 +
    1.74 +	/* socket descriptor */
    1.75 +	gint sd;
    1.76 +	GIOChannel *sd_io_ch;
    1.77 +
    1.78 +	gchar *hostname;
    1.79 +	gint port;
    1.80 +	gint mythtv_version;
    1.81 +};
    1.82 +
    1.83 +/* used when no protocol version number was negotiated */
    1.84 +#define	MYTHTV_CANNOT_NEGOTIATE_VERSION		0
    1.85 +
    1.86 +GType           gmyth_socket_get_type (void);
    1.87 +
    1.88 +GMythSocket *   gmyth_socket_new ();
    1.89 +
    1.90 +gboolean        gmyth_socket_connect (GMythSocket *gmyth_socket, const gchar *hostname, gint port);
    1.91 +
    1.92 +
    1.93 +GIOChannel *    gmyth_socket_get_io_channel (GMythSocket *gmyth_socket );
    1.94 +
    1.95 +gboolean        gmyth_socket_is_able_to_read (GMythSocket *gmyth_socket );
    1.96 +gboolean        gmyth_socket_is_able_to_write (GMythSocket *gmyth_socket );
    1.97 +
    1.98 +gboolean        gmyth_socket_send_command (GMythSocket *gmyth_socket, 
    1.99 +                                           GString *command);
   1.100 +GString *       gmyth_socket_receive_response (GMythSocket *gmyth_socket);
   1.101 +gint            gmyth_socket_sendreceive_stringlist (GMythSocket *gmyth_socket, 
   1.102 +                                                     GMythStringList *str_list);
   1.103 +
   1.104 +gboolean        gmyth_socket_connect (GMythSocket *gmyth_socket,
   1.105 +                                      const gchar *hostname, gint port);
   1.106 +gboolean        gmyth_socket_connect_with_timeout (GMythSocket *gmyth_socket,
   1.107 +		        const gchar *hostname, gint port, guint timeout);
   1.108 +
   1.109 +gboolean        gmyth_socket_connect_to_backend (GMythSocket *gmyth_socket, 
   1.110 +                           const gchar *hostname_backend, gint port, 
   1.111 +                           gboolean blocking_client);
   1.112 +
   1.113 +gboolean        gmyth_socket_connect_to_backend_events (GMythSocket *gmyth_socket, 
   1.114 +                           const gchar *hostname_backend, gint port, 
   1.115 +                           gboolean blocking_client);
   1.116 +
   1.117 +GString *       gmyth_socket_get_local_hostname (void);
   1.118 +
   1.119 +void            gmyth_socket_close_connection (GMythSocket *gmyth_socket);
   1.120 +
   1.121 +gboolean		gmyth_socket_check_protocol_version (GMythSocket *gmyth_socket);
   1.122 +gint				gmyth_socket_check_protocol_version_number (GMythSocket *gmyth_socket, 
   1.123 +                                                            gint mythtv_version);
   1.124 +
   1.125 +gint				gmyth_socket_get_protocol_version (GMythSocket *gmyth_socket);
   1.126 +
   1.127 +gboolean		gmyth_socket_write_stringlist(GMythSocket *gmyth_socket, 
   1.128 +                                              GMythStringList* str_list);
   1.129 +gint			    gmyth_socket_read_stringlist(GMythSocket *gmyth_socket, 
   1.130 +                                             GMythStringList* str_list);
   1.131 +G_END_DECLS
   1.132 +
   1.133 +#endif /* __GMYTH_SOCKET_H__ */