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