summaryrefslogtreecommitdiff
path: root/swfdec/swfdec_socket.c
blob: 64de43f7da5352b6f2eaab4a54449231c3bae0ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/* Swfdec
 * Copyright (C) 2008 Benjamin Otte <otte@gnome.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 
 * Boston, MA  02110-1301  USA
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "swfdec_socket.h"
#include "swfdec_loader_internal.h"

/*** GTK-DOC ***/

/**
 * SECTION:SwfdecSocket
 * @title: SwfdecSocket
 * @short_description: object used for network connections
 *
 * SwfdecSockets are used to implement TCP streams. These are for example used 
 * to implement RTMP support or the XMLSocket script class. Backends are 
 * supposed to provide an implementation for this, as by default this class is
 * unimplemented. However, swfdec-gtk or other convenience libraries provide
 * a socket implementation by default. 
 *
 * The socket implementation used by a #SwfdecPlayer can be set with the 
 * SwfdecPlayer:socket-type property.
 */

/**
 * SwfdecSocket:
 *
 * This is the base object used for providing input. It is abstract, create a 
 * subclass to provide your own socket implementation. All members are 
 * considered private.
 */

/**
 * SwfdecSocketClass:
 * @connect: Connect the given newly created socket to the given hostname and 
 *           port. If you encounter an error, call swfdec_stream_error(), but 
 *           still make sure the socket object does not break.
 * @send: Called to send data down the given socket. This function will only be
 *        called when the socket is open. You get passed a reference to the 
 *        buffer, so it is your responsibility to call swfdec_buffer_unref() on
 *        it when you are done with it.
 *
 * This is the socket class. When you create a subclass, you need to implement 
 * the functions listed above.
 */

/*** SWFDEC_SOCKET ***/

G_DEFINE_TYPE (SwfdecSocket, swfdec_socket, SWFDEC_TYPE_STREAM)

static void
swfdec_socket_do_connect (SwfdecSocket *socket, SwfdecPlayer *player,
    const char *hostname, guint port)
{
  swfdec_stream_error (SWFDEC_STREAM (socket), "no socket implementation exists");
}

static void
swfdec_socket_do_send (SwfdecSocket *socket, SwfdecBuffer *buffer)
{
  swfdec_buffer_unref (buffer);
}

static const char *
swfdec_socket_describe (SwfdecStream *stream)
{
  /* FIXME: add host/port */
  return G_OBJECT_TYPE_NAME (stream);
}

static void
swfdec_socket_class_init (SwfdecSocketClass *klass)
{
  SwfdecStreamClass *stream_class = SWFDEC_STREAM_CLASS (klass);

  stream_class->describe = swfdec_socket_describe;

  klass->connect = swfdec_socket_do_connect;
  klass->send = swfdec_socket_do_send;
}

static void
swfdec_socket_init (SwfdecSocket *socket)
{
}

/**
 * swfdec_socket_send:
 * @sock: a #SwfdecSocket
 * @buffer: data to send to the stream
 *
 * Pushes the given @buffer down the stream.
 **/
void
swfdec_socket_send (SwfdecSocket *sock, SwfdecBuffer *buffer)
{
  SwfdecSocketClass *klass;

  g_return_if_fail (SWFDEC_IS_SOCKET (sock));
  g_return_if_fail (swfdec_stream_is_open (SWFDEC_STREAM (sock)));
  g_return_if_fail (buffer != NULL);

  klass = SWFDEC_SOCKET_GET_CLASS (sock);
  klass->send (sock, buffer);
}