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