loudmouth/lm-socket.h
author Mikael Hallendal <micke@imendio.com>
Wed, 09 Jul 2008 15:56:07 +0300
changeset 433 2ed69f025f4a
parent 432 63a049d146c3
child 434 579db9f99cc5
permissions -rw-r--r--
Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket. This design allows for the unit test framework to hook into it's mock socket object in order to short cut the network communication.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
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 {
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    40
	GTypeInterface parent;
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    41
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    42
	/* <vtable> */
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    43
        void     (*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
    44
        gboolean (*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
    45
                                  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
    46
                                  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
    47
        gboolean (*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
    48
                                  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
    49
                                  gsize     buf_len,
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    50
                                  gsize     read_len);
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
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
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    54
GType          lm_socket_get_type          (void);
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    55
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    56
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
    57
                                            guint        port);
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    58
/* 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
    59
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
    60
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    61
/* All async functions so doesn't make a lot of sense to return anything */
433
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    62
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
    63
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
    64
                                            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
    65
                                            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
    66
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
    67
                                            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
    68
                                            gsize        buf_len,
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    69
                                            gsize        read_len);
2ed69f025f4a Made LmSocket into an interface and hooked up implementation of it in LmTcpSocket.
Mikael Hallendal <micke@imendio.com>
parents: 432
diff changeset
    70
void           lm_socket_disconnect        (LmSocket    *socket);
432
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    71
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    72
G_END_DECLS
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    73
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    74
#endif /* __LM_SOCKET_H__ */
63a049d146c3 Added basic API for the new LmSocket
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    75