libtelepathy/src/tp-connmgr.c
changeset 10 59927b2d3b75
parent 0 d0f3a028347a
equal deleted inserted replaced
0:d0f3a028347a 10:59927b2d3b75
     1 /* tp-connmgr.c
       
     2  *
       
     3   * Copyright (C) 2005 Collabora Ltd.	
       
     4  * 
       
     5  *
       
     6  * This library is free software; you can redistribute it and/or
       
     7  * modify it under the terms of the GNU Lesser General Public
       
     8  * License as published by the Free Software Foundation; either
       
     9  * version 2.1 of the License, or (at your option) any later version.
       
    10  *
       
    11  * This library is distributed in the hope that it will be useful,
       
    12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
       
    14  * Lesser General Public License for more details.
       
    15  *
       
    16  * You should have received a copy of the GNU Lesser General Public
       
    17  * License along with this library; if not, write to the Free Software
       
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
       
    19  *
       
    20  */
       
    21 
       
    22 #include "tp-connmgr.h"
       
    23 #include "tp-connmgr-signals-marshal.h"
       
    24 #include "tp-conn.h"
       
    25 #include "tp-helpers.h"
       
    26 
       
    27 #ifdef EMULATOR
       
    28 #include "libtelepathy_wsd_solution.h"
       
    29 #endif
       
    30 
       
    31 #ifdef EMULATOR
       
    32 	
       
    33 	GET_STATIC_VAR_FROM_TLS(parent_class,tp_connmgr,GObjectClass *)
       
    34 	#define parent_class (*GET_WSD_VAR_NAME(parent_class,tp_connmgr,s)())
       
    35 	
       
    36 	GET_STATIC_VAR_FROM_TLS(type1,tp_connmgr,GType)
       
    37 	#define type1 (*GET_WSD_VAR_NAME(type1,tp_connmgr,s)())
       
    38 #else	
       
    39 	static GObjectClass *parent_class = NULL;
       
    40 #endif
       
    41 	
       
    42 
       
    43 static void _tp_connmgr_register_signal_marshallers()
       
    44 {
       
    45   /* Register marshaller for the NewConnection signal */
       
    46   dbus_g_object_register_marshaller(tp_connmgr_signals_marshal_VOID__STRING_OBJECT_STRING, G_TYPE_NONE, G_TYPE_STRING, DBUS_TYPE_G_OBJECT_PATH, G_TYPE_STRING, G_TYPE_INVALID);
       
    47 }
       
    48 
       
    49 static void tp_connmgr_dispose(GObject *obj)
       
    50 {
       
    51   TpConnMgr *self = TELEPATHY_CONNMGR(obj);
       
    52 
       
    53   if (self->first_run)
       
    54   {
       
    55     self->first_run = FALSE;
       
    56   }
       
    57 
       
    58   /* Call the parent dispose method */
       
    59   if (G_OBJECT_CLASS(parent_class)->dispose)
       
    60   {
       
    61     G_OBJECT_CLASS(parent_class)->dispose(obj);
       
    62   }
       
    63 
       
    64 }
       
    65 
       
    66 
       
    67 static void tp_connmgr_finalize(GObject *obj)
       
    68 {
       
    69   if(G_OBJECT_CLASS(parent_class)->finalize)
       
    70   {
       
    71     G_OBJECT_CLASS(parent_class)->finalize(obj);
       
    72   }
       
    73 }
       
    74 
       
    75 
       
    76 static void tp_connmgr_init(GTypeInstance *instance, gpointer g_class)
       
    77 {
       
    78   TpConnMgr *self = TELEPATHY_CONNMGR(instance);
       
    79 
       
    80   self->first_run = TRUE;
       
    81 }
       
    82 
       
    83 
       
    84 static void tp_connmgr_class_init(TpConnMgrClass *klass)
       
    85 {
       
    86   GObjectClass *obj = G_OBJECT_CLASS(klass);
       
    87   parent_class = g_type_class_peek_parent(klass);
       
    88 
       
    89   obj->set_property = parent_class->set_property;
       
    90   obj->get_property = parent_class->get_property;
       
    91 
       
    92   obj->dispose = tp_connmgr_dispose;
       
    93   obj->finalize = tp_connmgr_finalize;
       
    94   
       
    95   _tp_connmgr_register_signal_marshallers();
       
    96 }
       
    97 
       
    98 
       
    99 GType tp_connmgr_get_type(void)
       
   100 {
       
   101 #ifndef EMULATOR
       
   102   static GType type1 = 0;
       
   103 #endif
       
   104   
       
   105   if (type1 == 0)
       
   106   {
       
   107     static const GTypeInfo info = 
       
   108     {
       
   109       sizeof(TpConnMgrClass),
       
   110       NULL,
       
   111       NULL,
       
   112       (GClassInitFunc)tp_connmgr_class_init,
       
   113       NULL,
       
   114       NULL,
       
   115       sizeof(TpConnMgr),
       
   116       0,
       
   117       (GInstanceInitFunc)tp_connmgr_init
       
   118 
       
   119     };
       
   120     type1 = g_type_register_static(DBUS_TYPE_G_PROXY,
       
   121         "TpConnMgr", &info, 0);
       
   122   }
       
   123   return type1;
       
   124 }
       
   125 
       
   126 
       
   127 
       
   128 
       
   129 #ifdef SYMBIAN
       
   130 EXPORT_C
       
   131 #endif
       
   132 TpConnMgr *tp_connmgr_new(DBusGConnection *connection,
       
   133 			  const char *bus_name,
       
   134 			  const char *object_path,
       
   135 			  const char *interface_name)
       
   136 {
       
   137   TpConnMgr *obj;
       
   138   g_return_val_if_fail(connection != NULL, NULL);
       
   139   g_return_val_if_fail(bus_name != NULL, NULL);
       
   140   g_return_val_if_fail(object_path, NULL);
       
   141   g_return_val_if_fail(interface_name, NULL);
       
   142   
       
   143   obj = g_object_new(TELEPATHY_CONNMGR_TYPE,
       
   144 		     "name", bus_name,
       
   145 		     "path", object_path,
       
   146 		     "interface", interface_name,
       
   147 		     "connection", connection, NULL);
       
   148 
       
   149   dbus_g_proxy_add_signal(DBUS_G_PROXY(obj), 
       
   150 			  "NewConnection",
       
   151 			  G_TYPE_STRING, DBUS_TYPE_G_OBJECT_PATH,
       
   152 			  G_TYPE_STRING, G_TYPE_INVALID);
       
   153 
       
   154   return obj;
       
   155 }
       
   156 
       
   157 
       
   158 #ifdef SYMBIAN
       
   159 EXPORT_C
       
   160 #endif
       
   161 TpConn *tp_connmgr_new_connection(TpConnMgr *self, 
       
   162 				  GHashTable *connection_parameters,
       
   163 				  gchar *protocol)
       
   164 {
       
   165   GError *error = NULL;
       
   166   TpConn *tp_conn_obj = NULL;
       
   167   DBusGConnection *connection = tp_get_bus ();
       
   168   gchar *bus_name = NULL, *object_path = NULL;
       
   169   g_return_val_if_fail(TELEPATHY_IS_CONNMGR(self), NULL);
       
   170   g_return_val_if_fail(connection_parameters != NULL, NULL);
       
   171 
       
   172   /* Create the actual connection and acquire service and path
       
   173      information that the TpConn object will need */
       
   174 
       
   175   if (!tp_connmgr_request_connection(DBUS_G_PROXY(self), protocol,
       
   176                           connection_parameters, &bus_name,
       
   177                           &object_path, &error))
       
   178   {
       
   179     g_warning("Connect() failed: %s\n", error -> message);
       
   180     g_error_free(error);
       
   181     return NULL;
       
   182   }
       
   183 
       
   184   if (bus_name == NULL || object_path == NULL)
       
   185   {
       
   186     return NULL;
       
   187   }
       
   188 
       
   189   /* Create the TpConn object */
       
   190 
       
   191   tp_conn_obj = tp_conn_new(connection, bus_name, object_path);
       
   192 
       
   193   return tp_conn_obj;
       
   194 }
       
   195 
       
   196 
       
   197 #ifdef SYMBIAN
       
   198 EXPORT_C
       
   199 #endif
       
   200 gboolean tp_connmgr_list_protocols(TpConnMgr *self, char *** proto)
       
   201 {
       
   202   GError *error = NULL;
       
   203 
       
   204   return dbus_g_proxy_call (DBUS_G_PROXY(self), "ListProtocols", &error, G_TYPE_INVALID, G_TYPE_STRV, proto, G_TYPE_INVALID);
       
   205 }
       
   206 
       
   207 
       
   208 #ifdef SYMBIAN
       
   209 EXPORT_C
       
   210 #endif
       
   211 gboolean
       
   212 tp_connmgr_get_parameters (TpConnMgr *self, const char * IN_proto, GPtrArray** OUT_arg1)
       
   213 
       
   214 {
       
   215   return dbus_g_proxy_call (DBUS_G_PROXY(self), "GetParameters", NULL, G_TYPE_STRING, IN_proto, G_TYPE_INVALID, dbus_g_type_get_collection ("GPtrArray", dbus_g_type_get_struct ("GValueArray", G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID)), OUT_arg1, G_TYPE_INVALID);
       
   216 }
       
   217