# HG changeset patch # User Mikael Hallendal # Date 1215467821 -10800 # Node ID 63a049d146c361b1ac34ac31d90e1e78ccecc534 # Parent 04577a6b7ff72dc3dd2920873fb65a04b60551dc Added basic API for the new LmSocket diff -r 04577a6b7ff7 -r 63a049d146c3 loudmouth/Makefile.am --- a/loudmouth/Makefile.am Mon Jul 07 15:30:58 2008 +0200 +++ b/loudmouth/Makefile.am Tue Jul 08 00:57:01 2008 +0300 @@ -54,6 +54,8 @@ lm-proxy.c \ lm-sock.h \ lm-sock.c \ + lm-socket.c \ + lm-socket.h \ lm-old-socket.c \ lm-old-socket.h \ asyncns.c \ diff -r 04577a6b7ff7 -r 63a049d146c3 loudmouth/lm-socket.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/loudmouth/lm-socket.c Tue Jul 08 00:57:01 2008 +0300 @@ -0,0 +1,188 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2008 Imendio AB + * + * This program 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 of the + * License, or (at your option) any later version. + * + * This program 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 program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include + +#include "lm-marshal.h" +#include "lm-socket.h" + +#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), LM_TYPE_DUMMY, LmSocketPriv)) + +typedef struct LmSocketPriv LmSocketPriv; +struct LmSocketPriv { + gint my_prop; +}; + +static void socket_finalize (GObject *object); +static void socket_get_property (GObject *object, + guint param_id, + GValue *value, + GParamSpec *pspec); +static void socket_set_property (GObject *object, + guint param_id, + const GValue *value, + GParamSpec *pspec); + +G_DEFINE_TYPE (LmSocket, lm_socket, G_TYPE_OBJECT) + +enum { + PROP_0, + PROP_MY_PROP +}; + +enum { + SIGNAL_NAME, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + +static void +lm_socket_class_init (LmSocketClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + + object_class->finalize = socket_finalize; + object_class->get_property = socket_get_property; + object_class->set_property = socket_set_property; + + g_object_class_install_property (object_class, + PROP_MY_PROP, + g_param_spec_string ("my-prop", + "My Prop", + "My Property", + NULL, + G_PARAM_READWRITE)); + + signals[SIGNAL_NAME] = + g_signal_new ("signal-name", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + lm_marshal_VOID__INT, + G_TYPE_NONE, + 1, G_TYPE_INT); + + g_type_class_add_private (object_class, sizeof (LmSocketPriv)); +} + +static void +lm_socket_init (LmSocket *dummy) +{ + LmSocketPriv *priv; + + priv = GET_PRIV (dummy); + +} + +static void +socket_finalize (GObject *object) +{ + LmSocketPriv *priv; + + priv = GET_PRIV (object); + + (G_OBJECT_CLASS (lm_socket_parent_class)->finalize) (object); +} + +static void +socket_get_property (GObject *object, + guint param_id, + GValue *value, + GParamSpec *pspec) +{ + LmSocketPriv *priv; + + priv = GET_PRIV (object); + + switch (param_id) { + case PROP_MY_PROP: + g_value_set_int (value, priv->my_prop); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; +} + +static void +socket_set_property (GObject *object, + guint param_id, + const GValue *value, + GParamSpec *pspec) +{ + LmSocketPriv *priv; + + priv = GET_PRIV (object); + + switch (param_id) { + case PROP_MY_PROP: + priv->my_prop = g_value_get_int (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; +} + +LmSocket * +lm_socket_new (const gchar *host, guint port) +{ + return NULL; +} + +/* Use DNS lookup to find the port and the host */ +LmSocket * +lm_socket_new_srv (const gchar *service) +{ + return NULL; +} + +void +lm_socket_connect (LmSocket *socket) +{ + /* Initiate the connection process */ + /* DNS lookup, connect thing, create IOchannel etc */ +} + +gboolean +lm_socket_write (LmSocket *socket, + gchar *data, + gsize len) +{ + return FALSE; +} + +gboolean +lm_socket_read (LmSocket *socket, + gchar *buf, + gsize buf_len, + gsize read_len) +{ + return FALSE; +} + +void +lm_socket_disconnect (LmSocket *socket) +{ +} + + diff -r 04577a6b7ff7 -r 63a049d146c3 loudmouth/lm-socket.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/loudmouth/lm-socket.h Tue Jul 08 00:57:01 2008 +0300 @@ -0,0 +1,67 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2008 Imendio AB + * + * This program 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 of the + * License, or (at your option) any later version. + * + * This program 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 program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __LM_SOCKET_H__ +#define __LM_SOCKET_H__ + +#include + +G_BEGIN_DECLS + +#define LM_TYPE_DUMMY (lm_socket_get_type ()) +#define LM_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LM_TYPE_DUMMY, LmSocket)) +#define LM_SOCKET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LM_TYPE_DUMMY, LmSocketClass)) +#define LM_IS_DUMMY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LM_TYPE_DUMMY)) +#define LM_IS_DUMMY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LM_TYPE_DUMMY)) +#define LM_SOCKET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LM_TYPE_DUMMY, LmSocketClass)) + +typedef struct LmSocket LmSocket; +typedef struct LmSocketClass LmSocketClass; + +struct LmSocket { + GObject parent; +}; + +struct LmSocketClass { + GObjectClass parent_class; +}; + +GType lm_socket_get_type (void); + +LmSocket * lm_socket_new (const gchar *host, + guint port); +/* Use DNS lookup to find the port and the host */ +LmSocket * lm_socket_new_srv (const gchar *service); + +/* All async functions so doesn't make a lot of sense to return anything */ +void lm_socket_connect (LmSocket *socket); +gboolean lm_socket_write (LmSocket *socket, + gchar *data, + gsize len); +gboolean lm_socket_read (LmSocket *socket, + gchar *buf, + gsize buf_len, + gsize read_len); +void lm_socket_disconnect (LmSocket *socket); + +G_END_DECLS + +#endif /* __LM_SOCKET_H__ */ +