loudmouth/lm-tcp-socket.c
changeset 569 3a224b933f90
parent 568 7932b95b5211
child 570 5588f29b0721
equal deleted inserted replaced
568:7932b95b5211 569:3a224b933f90
     1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       
     2 /*
       
     3  * Copyright (C) 2008 Imendio AB
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or
       
     6  * modify it under the terms of the GNU Lesser General Public License as
       
     7  * published by the Free Software Foundation; either version 2 of the
       
     8  * License, or (at your option) any later version.
       
     9  *
       
    10  * This program is distributed in the hope that it will be useful,
       
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    13  * Lesser General Public License for more details.
       
    14  *
       
    15  * You should have received a copy of the GNU Lesser General Public
       
    16  * License along with this program; if not, write to the
       
    17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
       
    18  * Boston, MA 02111-1307, USA.
       
    19  */
       
    20 
       
    21 #include <config.h>
       
    22 
       
    23 #include "lm-marshal.h"
       
    24 #include "lm-tcp-socket.h"
       
    25 #include "lm-socket.h"
       
    26 
       
    27 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), LM_TYPE_TCP_SOCKET, LmTcpSocketPriv))
       
    28 
       
    29 typedef struct LmTcpSocketPriv LmTcpSocketPriv;
       
    30 struct LmTcpSocketPriv {
       
    31     gint my_prop;
       
    32 };
       
    33 
       
    34 static void     tcp_socket_iface_init          (LmSocketIface     *iface);
       
    35 static void     tcp_socket_finalize            (GObject           *object);
       
    36 static void     tcp_socket_get_property        (GObject           *object,
       
    37                                                 guint              param_id,
       
    38                                                 GValue            *value,
       
    39                                                 GParamSpec        *pspec);
       
    40 static void     tcp_socket_set_property        (GObject           *object,
       
    41                                                 guint              param_id,
       
    42                                                 const GValue      *value,
       
    43                                                 GParamSpec        *pspec);
       
    44 static void     tcp_socket_connect             (LmSocket          *socket);
       
    45 static gboolean tcp_socket_write               (LmSocket          *socket,
       
    46                                                 gchar             *data, 
       
    47                                                 gsize              len);
       
    48 static gboolean tcp_socket_read                (LmSocket          *socket,
       
    49                                                 gchar             *buf,
       
    50                                                 gsize              buf_len,
       
    51                                                 gsize             *read_len);
       
    52 static void     tcp_socket_disconnect          (LmSocket          *socket);
       
    53 
       
    54 G_DEFINE_TYPE_WITH_CODE (LmTcpSocket, lm_tcp_socket, G_TYPE_OBJECT,
       
    55                          G_IMPLEMENT_INTERFACE (LM_TYPE_SOCKET,
       
    56                                                 tcp_socket_iface_init))
       
    57 
       
    58 enum {
       
    59     PROP_0,
       
    60     PROP_MY_PROP
       
    61 };
       
    62 
       
    63 enum {
       
    64     SIGNAL_NAME,
       
    65     LAST_SIGNAL
       
    66 };
       
    67 
       
    68 static guint signals[LAST_SIGNAL] = { 0 };
       
    69 
       
    70 static void
       
    71 lm_tcp_socket_class_init (LmTcpSocketClass *class)
       
    72 {
       
    73     GObjectClass *object_class = G_OBJECT_CLASS (class);
       
    74 
       
    75     object_class->finalize     = tcp_socket_finalize;
       
    76     object_class->get_property = tcp_socket_get_property;
       
    77     object_class->set_property = tcp_socket_set_property;
       
    78 
       
    79     g_object_class_install_property (object_class,
       
    80                                      PROP_MY_PROP,
       
    81                                      g_param_spec_string ("my-prop",
       
    82                                                           "My Prop",
       
    83                                                           "My Property",
       
    84                                                           NULL,
       
    85                                                           G_PARAM_READWRITE));
       
    86     
       
    87     signals[SIGNAL_NAME] = 
       
    88         g_signal_new ("signal-name",
       
    89                       G_OBJECT_CLASS_TYPE (object_class),
       
    90                       G_SIGNAL_RUN_LAST,
       
    91                       0,
       
    92                       NULL, NULL,
       
    93                       _lm_marshal_VOID__INT,
       
    94                       G_TYPE_NONE, 
       
    95                       1, G_TYPE_INT);
       
    96     
       
    97     g_type_class_add_private (object_class, sizeof (LmTcpSocketPriv));
       
    98 }
       
    99 
       
   100 static void
       
   101 tcp_socket_iface_init (LmSocketIface *iface)
       
   102 {
       
   103     iface->connect    = tcp_socket_connect;
       
   104     iface->write      = tcp_socket_write;
       
   105     iface->read       = tcp_socket_read;
       
   106     iface->disconnect = tcp_socket_disconnect;
       
   107 }
       
   108 
       
   109 static void
       
   110 lm_tcp_socket_init (LmTcpSocket *dummy)
       
   111 {
       
   112     LmTcpSocketPriv *priv;
       
   113 
       
   114     priv = GET_PRIV (dummy);
       
   115 
       
   116 }
       
   117 
       
   118 static void
       
   119 tcp_socket_finalize (GObject *object)
       
   120 {
       
   121     LmTcpSocketPriv *priv;
       
   122 
       
   123     priv = GET_PRIV (object);
       
   124 
       
   125     (G_OBJECT_CLASS (lm_tcp_socket_parent_class)->finalize) (object);
       
   126 }
       
   127 
       
   128 static void
       
   129 tcp_socket_get_property (GObject    *object,
       
   130                          guint       param_id,
       
   131                          GValue     *value,
       
   132                          GParamSpec *pspec)
       
   133 {
       
   134     LmTcpSocketPriv *priv;
       
   135 
       
   136     priv = GET_PRIV (object);
       
   137 
       
   138     switch (param_id) {
       
   139     case PROP_MY_PROP:
       
   140         g_value_set_int (value, priv->my_prop);
       
   141         break;
       
   142     default:
       
   143         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
       
   144         break;
       
   145     };
       
   146 }
       
   147 
       
   148 static void
       
   149 tcp_socket_set_property (GObject      *object,
       
   150                          guint         param_id,
       
   151                          const GValue *value,
       
   152                          GParamSpec   *pspec)
       
   153 {
       
   154     LmTcpSocketPriv *priv;
       
   155 
       
   156     priv = GET_PRIV (object);
       
   157 
       
   158     switch (param_id) {
       
   159     case PROP_MY_PROP:
       
   160         priv->my_prop = g_value_get_int (value);
       
   161         break;
       
   162     default:
       
   163         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
       
   164         break;
       
   165     };
       
   166 }
       
   167 
       
   168 static void 
       
   169 tcp_socket_connect (LmSocket *socket)
       
   170 {
       
   171     /* Initiate the connection process                 */
       
   172     /* DNS lookup, connect thing, create IOchannel etc */
       
   173 }
       
   174 
       
   175 static gboolean
       
   176 tcp_socket_write (LmSocket *socket, gchar *data, gsize len)
       
   177 {
       
   178     return FALSE;
       
   179 }
       
   180 
       
   181 static gboolean
       
   182 tcp_socket_read (LmSocket *socket,
       
   183                  gchar     *buf,
       
   184                  gsize      buf_len,
       
   185                  gsize     *read_len)
       
   186 {
       
   187     return FALSE;
       
   188 }
       
   189 
       
   190 static void 
       
   191 tcp_socket_disconnect (LmSocket *socket)
       
   192 {
       
   193 }
       
   194 
       
   195