gmyth/src/gmyth_socket.h
author rosfran
Tue Dec 05 21:56:57 2006 +0000 (2006-12-05)
branchtrunk
changeset 197 c57ba96bda15
parent 158 517da097a261
child 258 835d5cc01a0a
permissions -rw-r--r--
[svn r198] Fixed problem with Coxinha.
     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 GIOChannel *    gmyth_socket_get_io_channel (GMythSocket *gmyth_socket );
    88 
    89 gboolean        gmyth_socket_is_able_to_read (GMythSocket *gmyth_socket );
    90 gboolean        gmyth_socket_is_able_to_write (GMythSocket *gmyth_socket );
    91 
    92 gboolean        gmyth_socket_send_command (GMythSocket *gmyth_socket, 
    93                                            GString *command);
    94 GString *       gmyth_socket_receive_response (GMythSocket *gmyth_socket);
    95 gint             gmyth_socket_sendreceive_stringlist (GMythSocket *gmyth_socket, 
    96                                                      GMythStringList *str_list);
    97 
    98 gboolean        gmyth_socket_connect (GMythSocket *gmyth_socket,
    99                                       const gchar *hostname, gint port);
   100 gboolean        gmyth_socket_connect_to_backend (GMythSocket *gmyth_socket, 
   101                            const gchar *hostname_backend, gint port, 
   102                            gboolean blocking_client);
   103 
   104 gboolean        gmyth_socket_connect_to_backend_events (GMythSocket *gmyth_socket, 
   105                            const gchar *hostname_backend, gint port, 
   106                            gboolean blocking_client);
   107 
   108 GString *       gmyth_socket_get_local_hostname (void);
   109 
   110 void            gmyth_socket_close_connection (GMythSocket *gmyth_socket);
   111 
   112 gboolean		gmyth_socket_check_protocol_version (GMythSocket *gmyth_socket);
   113 gint				gmyth_socket_check_protocol_version_number (GMythSocket *gmyth_socket, 
   114                                                             gint mythtv_version);
   115 
   116 gint				gmyth_socket_get_protocol_version (GMythSocket *gmyth_socket);
   117 
   118 gboolean		gmyth_socket_write_stringlist(GMythSocket *gmyth_socket, 
   119                                               GMythStringList* str_list);
   120 gint			    gmyth_socket_read_stringlist(GMythSocket *gmyth_socket, 
   121                                              GMythStringList* str_list);
   122 G_END_DECLS
   123 
   124 #endif /* __GMYTH_SOCKET_H__ */