loudmouth/lm-socket.h
author Jayson Vantuyl <jvantuyl@engineyard.com>
Wed, 25 Mar 2009 11:28:18 -0700
changeset 596 9096d2549372
parent 518 cdd6a0c5b439
child 690 7ccf2113ec5f
permissions -rw-r--r--
Removed Dangerous Instructions
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
516
4dd3aa6b83e5 Change the tab width to 4 steps in the emacs headers
Mikael Hallendal <micke@imendio.com>
parents: 515
diff changeset
     1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     2
/*
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     3
 * Copyright (C) 2008 Imendio AB
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     4
 *
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     6
 * modify it under the terms of the GNU Lesser General Public License as
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     7
 * published by the Free Software Foundation; either version 2 of the
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     8
 * License, or (at your option) any later version.
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     9
 *
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    13
 * Lesser General Public License for more details.
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    14
 *
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    15
 * You should have received a copy of the GNU Lesser General Public
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    16
 * License along with this program; if not, write to the
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    17
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    18
 * Boston, MA 02111-1307, USA.
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    19
 */
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    20
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    21
#ifndef __LM_SOCKET_H__
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    22
#define __LM_SOCKET_H__
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    23
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    24
#include <glib-object.h>
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    25
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    26
#include "lm-message.h"
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    27
#include "lm-internals.h"
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    28
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    29
G_BEGIN_DECLS
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    30
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    31
#define LM_TYPE_SOCKET             (lm_socket_get_type())
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    32
#define LM_SOCKET(o)               (G_TYPE_CHECK_INSTANCE_CAST((o), LM_TYPE_SOCKET, LmSocket))
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    33
#define LM_IS_SOCKET(o)            (G_TYPE_CHECK_INSTANCE_TYPE((o), LM_TYPE_SOCKET))
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    34
#define LM_SOCKET_GET_IFACE(o)     (G_TYPE_INSTANCE_GET_INTERFACE((o), LM_TYPE_SOCKET, LmSocketIface))
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    35
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    36
typedef struct _LmSocket      LmSocket;
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    37
typedef struct _LmSocketIface LmSocketIface;
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    38
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    39
struct _LmSocketIface {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    40
    GTypeInterface parent;
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    41
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    42
    /* <vtable> */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    43
    void     (*connect)      (LmSocket *socket);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    44
    gboolean (*write)        (LmSocket *socket,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    45
                              gchar    *buf,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    46
                              gsize     len);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    47
    gboolean (*read)         (LmSocket *socket,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    48
                              gchar    *buf,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    49
                              gsize     buf_len,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    50
                              gsize    *read_len);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    51
    void     (*disconnect)   (LmSocket *socket);
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    52
};
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    53
434
579db9f99cc5 Worked on the LmSocket interface and added a LmSoupSocket class.
Mikael Hallendal <micke@imendio.com>
parents: 433
diff changeset
    54
typedef void  (*LmSocketCallback)  (LmSocket *socket,
579db9f99cc5 Worked on the LmSocket interface and added a LmSoupSocket class.
Mikael Hallendal <micke@imendio.com>
parents: 433
diff changeset
    55
                                    guint     status_code,
579db9f99cc5 Worked on the LmSocket interface and added a LmSoupSocket class.
Mikael Hallendal <micke@imendio.com>
parents: 433
diff changeset
    56
                                    gpointer  user_data);
579db9f99cc5 Worked on the LmSocket interface and added a LmSoupSocket class.
Mikael Hallendal <micke@imendio.com>
parents: 433
diff changeset
    57
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    58
GType          lm_socket_get_type          (void);
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    59
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    60
LmSocket *     lm_socket_new               (const gchar *host,
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    61
                                            guint        port);
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    62
/* Use DNS lookup to find the port and the host */
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    63
LmSocket *     lm_socket_new_to_service    (const gchar *service);
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    64
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    65
/* All async functions so doesn't make a lot of sense to return anything */
434
579db9f99cc5 Worked on the LmSocket interface and added a LmSoupSocket class.
Mikael Hallendal <micke@imendio.com>
parents: 433
diff changeset
    66
/* Use LmSocketCallback instead of signal for the connect result */
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    67
void           lm_socket_connect           (LmSocket    *socket);
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    68
gboolean       lm_socket_write             (LmSocket    *socket,
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    69
                                            gchar       *buf,
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    70
                                            gsize        len);
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    71
gboolean       lm_socket_read              (LmSocket    *socket,
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    72
                                            gchar       *buf,
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    73
                                            gsize        buf_len,
441
b666e4d63a3a Some more work on the soup socket
Mikael Hallendal <micke@imendio.com>
parents: 434
diff changeset
    74
                                            gsize       *read_len);
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    75
void           lm_socket_disconnect        (LmSocket    *socket);
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    76
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    77
G_END_DECLS
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    78
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    79
#endif /* __LM_SOCKET_H__ */
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    80