dbus.c 34.1 KB
Newer Older
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
1 2
/*
 *  Copyright (C) 2007 Savoir-Faire Linux inc.
3
 *  Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
4
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
5
 *  Author: Guillaume Carmel-Archambault <guillaume.carmel-archambault@savoirfairelinux.com>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
6 7 8
 *                                                                              
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 3 of the License, or
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
10 11 12 13 14 15 16 17 18 19 20 21
 *  (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 General Public License for more details.
 *                                                                              
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
areversat's avatar
areversat committed
22
#include <calltab.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
23 24
#include <callmanager-glue.h>
#include <configurationmanager-glue.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
25
#include <instance-glue.h>
26
#include <configwindow.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
27
#include <mainwindow.h>
28
#include <marshaller.h>
29
#include <sliders.h>
30
#include <statusicon.h>
31
#include <assistant.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
32

33 34 35
#include <dbus.h>
#include <actions.h>
#include <string.h>
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
36 37 38 39 40
#include <dbus/dbus-glib.h>

DBusGConnection * connection;
DBusGProxy * callManagerProxy;
DBusGProxy * configurationManagerProxy;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
41
DBusGProxy * instanceProxy;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
42 43

static void  
44
incoming_call_cb (DBusGProxy *proxy UNUSED,
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
45 46 47
                  const gchar* accountID,
                  const gchar* callID,
                  const gchar* from,
48
                  void * foo  UNUSED )
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
49 50 51 52 53 54 55
{
  g_print ("Incoming call! %s\n",callID);
  call_t * c = g_new0 (call_t, 1);
  c->accountID = g_strdup(accountID);
  c->callID = g_strdup(callID);
  c->from = g_strdup(from);
  c->state = CALL_STATE_INCOMING;
56
 #if GTK_CHECK_VERSION(2,10,0) 
57
  status_tray_icon_blink( TRUE );
58
 #endif
59
  notify_incoming_call( c );
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
60 61 62
  sflphone_incoming_call (c);
}

Alexandre Savard's avatar
Alexandre Savard committed
63 64 65 66 67 68
static void
curent_selected_codec (DBusGProxy *proxy UNUSED,
                  const gchar* callID,
                  const gchar* codecName,
                  void * foo  UNUSED )
{
Alexandre Savard's avatar
Alexandre Savard committed
69
  g_print ("%s codec decided for call %s\n",codecName,callID);
Alexandre Savard's avatar
Alexandre Savard committed
70 71
  sflphone_display_selected_codec (codecName);
}
72 73

static void  
74
volume_changed_cb (DBusGProxy *proxy UNUSED,
75 76
                  const gchar* device,
                  const gdouble value,
77
                  void * foo  UNUSED )
78 79 80 81 82
{
  g_print ("Volume of %s changed to %f. \n",device, value);
  set_slider(device, value);
}

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
83
static void  
84
voice_mail_cb (DBusGProxy *proxy UNUSED,
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
85
                  const gchar* accountID,
86
                  const guint nb,
87
                  void * foo  UNUSED )
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
88 89
{
  g_print ("%d Voice mail waiting! \n",nb);
90
  sflphone_notify_voice_mail (accountID , nb);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
91 92 93
}

static void  
94 95
incoming_message_cb (DBusGProxy *proxy UNUSED,
                  const gchar* accountID UNUSED,
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
96
                  const gchar* msg,
97
                  void * foo  UNUSED )
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
98
{
99
  g_print ("Message %s! \n",msg);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
100 101 102 103
  
}

static void  
104
call_state_cb (DBusGProxy *proxy UNUSED,
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
105 106
                  const gchar* callID,
                  const gchar* state,
107
                  void * foo  UNUSED )
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
108 109
{
  g_print ("Call %s state %s\n",callID, state);
areversat's avatar
areversat committed
110
  call_t * c = call_list_get(current_calls, callID);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
111 112 113 114
  if(c)
  {
    if ( strcmp(state, "HUNGUP") == 0 )
    {
Emmanuel Milou's avatar
Emmanuel Milou committed
115 116 117
      if(c->state==CALL_STATE_CURRENT)
      {
	// peer hung up, the conversation was established, so _start has been initialized with the current time value
118
	g_print("call state current\n");
Emmanuel Milou's avatar
Emmanuel Milou committed
119 120 121
	(void) time(&c->_stop);
	update_call_tree( history, c );
      }
Emmanuel Milou's avatar
Emmanuel Milou committed
122
      stop_notification();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
123
      sflphone_hung_up (c);
124
      update_call_tree( history, c );
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
125
    }
alexandresavard's avatar
alexandresavard committed
126
    else if ( strcmp(state, "UNHOLD_CURRENT") == 0 )
127 128 129
    {
      sflphone_current (c);
    }
alexandresavard's avatar
alexandresavard committed
130 131 132 133
    else if ( strcmp(state, "UNHOLD_RECORD") == 0 )
    {
      sflphone_record (c);
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
134 135 136 137 138 139
    else if ( strcmp(state, "HOLD") == 0 )
    {
      sflphone_hold (c);
    }
    else if ( strcmp(state, "RINGING") == 0 )
    {
140
      sflphone_ringing (c);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
141 142 143 144 145
    }
    else if ( strcmp(state, "CURRENT") == 0 )
    {
      sflphone_current (c);
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
    else if ( strcmp(state, "FAILURE") == 0 )
    {
      sflphone_fail (c);
    }
    else if ( strcmp(state, "BUSY") == 0 )
    {
      sflphone_busy (c);
    }
  } 
  else 
  { //The callID is unknow, threat it like a new call
    if ( strcmp(state, "RINGING") == 0 )
    {
      g_print ("New ringing call! %s\n",callID);
      call_t * c = g_new0 (call_t, 1);
      c->accountID = g_strdup("1");
      c->callID = g_strdup(callID);
      c->from = g_strdup("\"\" <>");
      c->state = CALL_STATE_RINGING;
      sflphone_incoming_call (c);
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
167 168 169 170
  }
}

static void  
171 172
accounts_changed_cb (DBusGProxy *proxy UNUSED,
                  void * foo  UNUSED )
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
173 174
{
  g_print ("Accounts changed\n");
175
  sflphone_fill_account_list(TRUE);
176
  config_window_fill_account_list();
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
177 178
}

179
static void  
180
error_alert(DBusGProxy *proxy UNUSED,
Emmanuel Milou's avatar
Emmanuel Milou committed
181
		  int errCode,
182
                  void * foo  UNUSED )
183
{
Emmanuel Milou's avatar
Emmanuel Milou committed
184 185
  g_print ("Error notifying : (%i)\n" , errCode);
  sflphone_throw_exception( errCode );
186 187
}

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
188 189 190
gboolean 
dbus_connect ()
{
191

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
192
  GError *error = NULL;
193
  connection = NULL;
194
  instanceProxy = NULL;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
195 196 197
  
  g_type_init ();

198 199
  connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
  
200
  if (error)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
201 202 203 204 205 206 207 208 209
  {
    g_printerr ("Failed to open connection to bus: %s\n",
                error->message);
    g_error_free (error);
    return FALSE;
  }

  /* Create a proxy object for the "bus driver" (name "org.freedesktop.DBus") */
  
210
  instanceProxy = dbus_g_proxy_new_for_name (connection,
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
211 212
                                     "org.sflphone.SFLphone",
                                     "/org/sflphone/SFLphone/Instance",
213 214
                                     "org.sflphone.SFLphone.Instance");
                                     
215
  if (instanceProxy==NULL) 
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
216 217 218 219 220 221 222 223
  {
    g_printerr ("Failed to get proxy to Instance\n");
    return FALSE;
  }
  
  g_print ("DBus connected to Instance\n");
  
  
224
  callManagerProxy = dbus_g_proxy_new_for_name (connection,
225 226
                                     "org.sflphone.SFLphone",
                                     "/org/sflphone/SFLphone/CallManager",
227 228
                                     "org.sflphone.SFLphone.CallManager");

229
  if (callManagerProxy==NULL) 
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
230
  {
231
    g_printerr ("Failed to get proxy to CallManagers\n");
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
232 233 234 235 236 237 238 239 240 241 242 243
    return FALSE;
  }
  
  g_print ("DBus connected to CallManager\n");
  /* Incoming call */
  dbus_g_object_register_marshaller(g_cclosure_user_marshal_VOID__STRING_STRING_STRING, 
    G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
  dbus_g_proxy_add_signal (callManagerProxy, 
    "incomingCall", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
  dbus_g_proxy_connect_signal (callManagerProxy,
    "incomingCall", G_CALLBACK(incoming_call_cb), NULL, NULL);

Alexandre Savard's avatar
Alexandre Savard committed
244 245 246 247 248 249 250 251
  /* Current codec */
  dbus_g_object_register_marshaller(g_cclosure_user_marshal_VOID__STRING_STRING_STRING, 
    G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
  dbus_g_proxy_add_signal (callManagerProxy, 
    "currentSelectedCodec", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
  dbus_g_proxy_connect_signal (callManagerProxy,
    "currentSelectedCodec", G_CALLBACK(curent_selected_codec), NULL, NULL);

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
252 253 254
  /* Register a marshaller for STRING,STRING */
  dbus_g_object_register_marshaller(g_cclosure_user_marshal_VOID__STRING_STRING, 
    G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
255 256
  dbus_g_proxy_add_signal (callManagerProxy, 
    "callStateChanged", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
  dbus_g_proxy_connect_signal (callManagerProxy,
    "callStateChanged", G_CALLBACK(call_state_cb), NULL, NULL);

  dbus_g_object_register_marshaller(g_cclosure_user_marshal_VOID__STRING_INT, 
    G_TYPE_NONE, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INVALID);
  dbus_g_proxy_add_signal (callManagerProxy, 
    "voiceMailNotify", G_TYPE_STRING, G_TYPE_INT, G_TYPE_INVALID);
  dbus_g_proxy_connect_signal (callManagerProxy,
    "voiceMailNotify", G_CALLBACK(voice_mail_cb), NULL, NULL);
  
  dbus_g_proxy_add_signal (callManagerProxy, 
    "incomingMessage", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
  dbus_g_proxy_connect_signal (callManagerProxy,
    "incomingMessage", G_CALLBACK(incoming_message_cb), NULL, NULL);
    
272 273 274 275 276 277
  dbus_g_object_register_marshaller(g_cclosure_user_marshal_VOID__STRING_DOUBLE, 
    G_TYPE_NONE, G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_INVALID);
  dbus_g_proxy_add_signal (callManagerProxy, 
    "volumeChanged", G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_INVALID);
  dbus_g_proxy_connect_signal (callManagerProxy,
    "volumeChanged", G_CALLBACK(volume_changed_cb), NULL, NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
278
    
279
  configurationManagerProxy = dbus_g_proxy_new_for_name (connection,
280 281
                                  "org.sflphone.SFLphone",
                                  "/org/sflphone/SFLphone/ConfigurationManager",
282 283
                                  "org.sflphone.SFLphone.ConfigurationManager");

284
  if (!configurationManagerProxy) 
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
285
  {
286
    g_printerr ("Failed to get proxy to ConfigurationManager\n");
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
287 288
    return FALSE;
  }
289
  g_print ("DBus connected to ConfigurationManager\n");
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
290 291 292 293 294
  dbus_g_proxy_add_signal (configurationManagerProxy, 
    "accountsChanged", G_TYPE_INVALID);
  dbus_g_proxy_connect_signal (configurationManagerProxy,
    "accountsChanged", G_CALLBACK(accounts_changed_cb), NULL, NULL);
   
Emmanuel Milou's avatar
Emmanuel Milou committed
295 296
  dbus_g_object_register_marshaller(g_cclosure_user_marshal_VOID__INT,
          G_TYPE_NONE, G_TYPE_INT , G_TYPE_INVALID);
297
  dbus_g_proxy_add_signal (configurationManagerProxy, 
Emmanuel Milou's avatar
Emmanuel Milou committed
298
    "errorAlert", G_TYPE_INT , G_TYPE_INVALID);
299 300
  dbus_g_proxy_connect_signal (configurationManagerProxy,
    "errorAlert", G_CALLBACK(error_alert), NULL, NULL);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
301 302 303 304 305 306 307
  return TRUE;
}

void
dbus_clean ()
{
    g_object_unref (callManagerProxy);
308
    g_object_unref (configurationManagerProxy);
309
    g_object_unref (instanceProxy);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
310 311
}

312

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
313 314 315 316
void
dbus_hold (const call_t * c)
{
  GError *error = NULL;
317
  org_sflphone_SFLphone_CallManager_hold ( callManagerProxy, c->callID, &error);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
318 319 320 321 322 323 324 325 326 327 328 329
  if (error) 
  {
    g_printerr ("Failed to call hold() on CallManager: %s\n",
                error->message);
    g_error_free (error);
  } 
}

void
dbus_unhold (const call_t * c)
{
  GError *error = NULL;
330
  org_sflphone_SFLphone_CallManager_unhold ( callManagerProxy, c->callID, &error);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
331 332 333 334 335 336 337 338 339 340 341 342
  if (error) 
  {
    g_printerr ("Failed to call unhold() on CallManager: %s\n",
                error->message);
    g_error_free (error);
  } 
}

void
dbus_hang_up (const call_t * c)
{
  GError *error = NULL;
343
  org_sflphone_SFLphone_CallManager_hang_up ( callManagerProxy, c->callID, &error);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
344 345 346 347 348 349 350 351 352
  if (error) 
  {
    g_printerr ("Failed to call hang_up() on CallManager: %s\n",
                error->message);
    g_error_free (error);
  } 
}

void
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
353
dbus_transfert (const call_t * c)
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
354 355
{
  GError *error = NULL;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
356
  org_sflphone_SFLphone_CallManager_transfert ( callManagerProxy, c->callID, c->to, &error);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
357 358 359 360 361 362 363 364 365 366 367
  if (error) 
  {
    g_printerr ("Failed to call transfert() on CallManager: %s\n",
                error->message);
    g_error_free (error);
  } 
}

void
dbus_accept (const call_t * c)
{
368
#if GTK_CHECK_VERSION(2,10,0)
369
  status_tray_icon_blink( FALSE );
370
#endif
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
371
  GError *error = NULL;
372
  org_sflphone_SFLphone_CallManager_accept ( callManagerProxy, c->callID, &error);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
373 374 375 376 377 378 379 380 381 382 383
  if (error) 
  {
    g_printerr ("Failed to call accept(%s) on CallManager: %s\n", c->callID,
                (error->message == NULL ? g_quark_to_string(error->domain): error->message));
    g_error_free (error);
  } 
}

void
dbus_refuse (const call_t * c)
{
384
#if GTK_CHECK_VERSION(2,10,0)
385
  status_tray_icon_blink( FALSE );
386
#endif
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
387
  GError *error = NULL;
388
  org_sflphone_SFLphone_CallManager_refuse ( callManagerProxy, c->callID, &error);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
389 390 391 392 393 394 395 396 397 398 399 400 401
  if (error) 
  {
    g_printerr ("Failed to call refuse() on CallManager: %s\n",
                error->message);
    g_error_free (error);
  } 
}


void
dbus_place_call (const call_t * c)
{
  GError *error = NULL;
402
  org_sflphone_SFLphone_CallManager_place_call ( callManagerProxy, c->accountID, c->callID, c->to, &error);
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
403 404 405 406 407 408 409 410
  if (error) 
  {
    g_printerr ("Failed to call placeCall() on CallManager: %s\n",
                error->message);
    g_error_free (error);
  } 
}

411
gchar**  dbus_account_list()
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
412
{
413 414
    GError *error = NULL;
    char ** array;
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
415

416 417 418 419 420 421 422 423 424 425 426 427 428
    if(!org_sflphone_SFLphone_ConfigurationManager_get_account_list ( configurationManagerProxy, &array, &error))
    {
        if(error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION)
            g_printerr ("Caught remote method (get_account_list) exception  %s: %s\n", dbus_g_error_get_name(error), error->message);
        else
            g_printerr("Error while calling get_account_list: %s\n", error->message);
        g_error_free (error);
        return NULL;
    }
    else{
        g_print ("DBus called get_account_list() on ConfigurationManager\n");
        return array;
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
429 430 431
}


432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
GHashTable* dbus_account_details(gchar * accountID)
{
    GError *error = NULL;
    GHashTable * details;
  
    if(!org_sflphone_SFLphone_ConfigurationManager_get_account_details( configurationManagerProxy, accountID, &details, &error))
    {
        if(error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION)
            g_printerr ("Caught remote method (get_account_details) exception  %s: %s\n", dbus_g_error_get_name(error), error->message);
        else
            g_printerr("Error while calling get_account_details: %s\n", error->message);
        g_error_free (error);
        return NULL;
    }
    else{
        return details;
    }
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
449 450
}

451
void
452
dbus_send_register ( gchar* accountID , const guint expire)
453
{
454 455 456 457 458 459 460 461
  GError *error = NULL;
  org_sflphone_SFLphone_ConfigurationManager_send_register ( configurationManagerProxy, accountID, expire ,&error);
  if (error) 
  {
    g_printerr ("Failed to call send_register() on ConfigurationManager: %s\n",
                error->message);
    g_error_free (error);
  } 
462
}
463

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
464 465 466 467
void
dbus_remove_account(gchar * accountID)
{
  GError *error = NULL;
468
  org_sflphone_SFLphone_ConfigurationManager_remove_account (
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
    configurationManagerProxy, 
    accountID, 
    &error);
  if (error) 
  {
  g_printerr ("Failed to call remove_account() on ConfigurationManager: %s\n",
              error->message);
  g_error_free (error);
  } 
}

void
dbus_set_account_details(account_t *a)
{
  GError *error = NULL;
484
  org_sflphone_SFLphone_ConfigurationManager_set_account_details (
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
485 486 487 488 489 490
    configurationManagerProxy, 
    a->accountID, 
    a->properties, 
    &error);
  if (error) 
  {
491
    g_printerr ("Failed to call set_account_details() on ConfigurationManager: %s\n",
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
492 493 494 495
                error->message);
    g_error_free (error);
  } 
}
496

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
void
dbus_add_account(account_t *a)
{
  GError *error = NULL;
  org_sflphone_SFLphone_ConfigurationManager_add_account (
    configurationManagerProxy, 
    a->properties, 
    &error);
  if (error) 
  {
    g_printerr ("Failed to call add_account() on ConfigurationManager: %s\n",
                error->message);
    g_error_free (error);
  } 
}

513 514 515 516
void
dbus_set_volume(const gchar * device, gdouble value)
{
  GError *error = NULL;
517
  org_sflphone_SFLphone_CallManager_set_volume(
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537
    callManagerProxy, 
    device, 
    value, 
    &error);

  if (error) 
  {
    g_printerr ("Failed to call set_volume() on callManagerProxy: %s\n",
                error->message);
    g_error_free (error);
  } 
}


gdouble
dbus_get_volume(const gchar * device)
{
  gdouble  value;
  GError *error = NULL;
  
538
  org_sflphone_SFLphone_CallManager_get_volume(
539 540 541 542 543 544 545 546 547 548 549 550 551
    callManagerProxy, 
    device, 
    &value, 
    &error);

  if (error) 
  {
    g_printerr ("Failed to call get_volume() on callManagerProxy: %s\n",
                error->message);
    g_error_free (error);
  } 
  return value;
}
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570


void
dbus_play_dtmf(const gchar * key)
{
  GError *error = NULL;
  
  org_sflphone_SFLphone_CallManager_play_dt_mf(
    callManagerProxy, 
    key, 
    &error);

  if (error) 
  {
    g_printerr ("Failed to call playDTMF() on callManagerProxy: %s\n",
                error->message);
    g_error_free (error);
  } 
}
Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
571

572
void
573
dbus_start_tone(const int start , const guint type )
574 575 576 577 578
{
  GError *error = NULL;
  
  org_sflphone_SFLphone_CallManager_start_tone(
    callManagerProxy, 
579 580
    start,
    type, 
581 582 583 584 585 586 587 588 589 590
    &error);

  if (error) 
  {
    g_printerr ("Failed to call startTone() on callManagerProxy: %s\n",
                error->message);
    g_error_free (error);
  } 
}

Pierre-Luc Beaudoin's avatar
Pierre-Luc Beaudoin committed
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
void
dbus_register(int pid, gchar * name)
{
  GError *error = NULL;
  
  org_sflphone_SFLphone_Instance_register(
    instanceProxy, 
    pid, 
    name, 
    &error);

  if (error) 
  {
    g_printerr ("Failed to call register() on instanceProxy: %s\n",
                error->message);
    g_error_free (error);
  } 
}

void 
dbus_unregister(int pid)
{
  GError *error = NULL;
  
  org_sflphone_SFLphone_Instance_unregister(
    instanceProxy, 
    pid, 
    &error);

  if (error) 
  {
    g_printerr ("Failed to call unregister() on instanceProxy: %s\n",
                error->message);
    g_error_free (error);
  } 
}
627

628
gchar**
629 630 631 632
dbus_codec_list()
{

  GError *error = NULL;
633
  gchar** array;
634 635 636 637 638 639 640 641 642 643 644 645 646 647
  org_sflphone_SFLphone_ConfigurationManager_get_codec_list (
    configurationManagerProxy,
    &array,
    &error);

  if (error)
  {
  g_printerr ("Failed to call get_codec_list() on ConfigurationManager: %s\n",
              error->message);
  g_error_free (error);
  }
  return array;
}

648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
gchar**
dbus_codec_details( int payload )
{

  GError *error = NULL;
  gchar ** array;
  org_sflphone_SFLphone_ConfigurationManager_get_codec_details (
    configurationManagerProxy,
    payload,
    &array,
    &error);

  if (error)
  {
  g_printerr ("Failed to call get_codec_details() on ConfigurationManager: %s\n",
              error->message);
  g_error_free (error);
  }
  return array;
}

Alexandre Savard's avatar
Alexandre Savard committed
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692
gchar*
dbus_get_current_codec_name(const call_t * c)
{
    
    printf("dbus_get_current_codec_name : CallID : %s \n", c->callID);

    gchar* codecName;
    GError* error = NULL;
       
    org_sflphone_SFLphone_CallManager_get_current_codec_name (
                       callManagerProxy,
                       c->callID,
                       &codecName,
                       &error);
    if(error)
    {
        g_error_free(error);
    }
    
    printf("dbus_get_current_codec_name : codecName : %s \n", codecName);

    return codecName;    
}

693

694 695 696

gchar**
dbus_get_active_codec_list()
697 698
{

699
  gchar ** array;
700
  GError *error = NULL;
701
  org_sflphone_SFLphone_ConfigurationManager_get_active_codec_list (
702 703 704 705 706 707
    configurationManagerProxy,
    &array,
    &error);

  if (error)
  {
708
  g_printerr ("Failed to call get_active_codec_list() on ConfigurationManager: %s\n",
709 710 711 712 713 714
              error->message);
  g_error_free (error);
  }
  return array;
}

715
void
716
dbus_set_active_codec_list(const gchar** list)
717 718 719
{

  GError *error = NULL;
720
  org_sflphone_SFLphone_ConfigurationManager_set_active_codec_list (
721
    configurationManagerProxy,
722
    list,
723
    &error);
724

725 726
  if (error)
  {
727
  g_printerr ("Failed to call set_active_codec_list() on ConfigurationManager: %s\n",
728 729 730
              error->message);
  g_error_free (error);
  }
731
}
732 733

/**
734
 * Get a list of input supported audio plugins
735 736
 */
gchar**
737
dbus_get_input_audio_plugin_list()
738 739 740
{
	gchar** array;
	GError* error = NULL;
741
	org_sflphone_SFLphone_ConfigurationManager_get_input_audio_plugin_list(
742 743 744 745 746
			configurationManagerProxy,
			&array,
			&error);
	if(error)
	{
747
		g_printerr("Failed to call get_input_audio_plugin_list() on ConfigurationManager: %s\n", error->message);
748 749 750 751 752 753
		g_error_free(error);
	}
	return array;
}

/**
754 755 756 757 758 759 760
 * Get a list of output supported audio plugins
 */
gchar**
dbus_get_output_audio_plugin_list()
{
	gchar** array;
	GError* error = NULL;
Yun Liu's avatar
Yun Liu committed
761 762
	
	if(!org_sflphone_SFLphone_ConfigurationManager_get_output_audio_plugin_list( configurationManagerProxy, &array, &error))
763
	{
Yun Liu's avatar
Yun Liu committed
764 765 766 767 768 769
		if(error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION)
            		g_printerr ("Caught remote method (get_output_audio_plugin_list) exception  %s: %s\n", dbus_g_error_get_name(error), error->message);
        	else
            		g_printerr("Error while calling get_out_audio_plugin_list: %s\n", error->message);
        	g_error_free (error);
        	return NULL;
770
	}
Yun Liu's avatar
Yun Liu committed
771 772 773
	else{
		return array;
	}
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790
}

void
dbus_set_input_audio_plugin(gchar* audioPlugin)
{
	GError* error = NULL;
	org_sflphone_SFLphone_ConfigurationManager_set_input_audio_plugin(
			configurationManagerProxy,
			audioPlugin,
			&error);
	if(error)
	{
		g_printerr("Failed to call set_input_audio_plugin() on ConfigurationManager: %s\n", error->message);
		g_error_free(error);
	}
}

791
void
792
dbus_set_output_audio_plugin(gchar* audioPlugin)
793 794
{
	GError* error = NULL;
795
	org_sflphone_SFLphone_ConfigurationManager_set_output_audio_plugin(
796
			configurationManagerProxy,
797
			audioPlugin,
798 799 800
			&error);
	if(error)
	{
801
		g_printerr("Failed to call set_output_audio_plugin() on ConfigurationManager: %s\n", error->message);
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901
		g_error_free(error);
	}
}

/**
 * Get all output devices index supported by current audio manager
 */
gchar** dbus_get_audio_output_device_list()
{
	gchar** array;
	GError* error = NULL;
	org_sflphone_SFLphone_ConfigurationManager_get_audio_output_device_list(
			configurationManagerProxy,
			&array,
			&error);
	if(error)
	{
		g_printerr("Failed to call get_audio_output_device_list() on ConfigurationManager: %s\n", error->message);
		g_error_free(error);
	}
	return array;
}

/**
 * Set audio output device from its index
 */
void
dbus_set_audio_output_device(const int index)
{
	GError* error = NULL;
	org_sflphone_SFLphone_ConfigurationManager_set_audio_output_device(
			configurationManagerProxy,
			index,
			&error);
	if(error)
	{
		g_printerr("Failed to call set_audio_output_device() on ConfigurationManager: %s\n", error->message);
		g_error_free(error);
	}
}

/**
 * Get all input devices index supported by current audio manager
 */
gchar**
dbus_get_audio_input_device_list()
{
	gchar** array;
	GError* error = NULL;
	org_sflphone_SFLphone_ConfigurationManager_get_audio_input_device_list(
			configurationManagerProxy,
			&array,
			&error);
	if(error)
	{
		g_printerr("Failed to call get_audio_input_device_list() on ConfigurationManager: %s\n", error->message);
		g_error_free(error);
	}
	return array;
}

/**
 * Set audio input device from its index
 */
void
dbus_set_audio_input_device(const int index)
{
	GError* error = NULL;
	org_sflphone_SFLphone_ConfigurationManager_set_audio_input_device(
			configurationManagerProxy,
			index,
			&error);
	if(error)
	{
		g_printerr("Failed to call set_audio_input_device() on ConfigurationManager: %s\n", error->message);
		g_error_free(error);
	}
}

/**
 * Get output device index and input device index
 */
gchar**
dbus_get_current_audio_devices_index()
{
	gchar** array;
	GError* error = NULL;
	org_sflphone_SFLphone_ConfigurationManager_get_current_audio_devices_index(
			configurationManagerProxy,
			&array,
			&error);
	if(error)
	{
		g_printerr("Failed to call get_current_audio_devices_index() on ConfigurationManager: %s\n", error->message);
		g_error_free(error);
	}
	return array;
}

/**
902
 * Get index
903
 */
904 905
int
dbus_get_audio_device_index(const gchar *name)
906
{
907
	int index;
908
	GError* error = NULL;
909
	org_sflphone_SFLphone_ConfigurationManager_get_audio_device_index(
910
			configurationManagerProxy,
911 912
			name,
			&index,
913 914 915
			&error);
	if(error)
	{
916
		g_printerr("Failed to call get_audio_device_index() on ConfigurationManager: %s\n", error->message);
917 918
		g_error_free(error);
	}
919
	return index;
920
}
921 922 923 924 925 926 927

/**
 * Get audio plugin 
 */
gchar*
dbus_get_current_audio_output_plugin()
{
928
	gchar* plugin="";
929 930 931 932 933 934 935 936 937 938 939 940
	GError* error = NULL;
	org_sflphone_SFLphone_ConfigurationManager_get_current_audio_output_plugin(
			configurationManagerProxy,
			&plugin,
			&error);
	if(error)
	{
		g_printerr("Failed to call get_current_audio_output_plugin() on ConfigurationManager: %s\n", error->message);
		g_error_free(error);
	}
	return plugin;
}
Emmanuel Milou's avatar
Emmanuel Milou committed
941

942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972

gchar*
dbus_get_ringtone_choice()
{
	gchar* tone;
	GError* error = NULL;
	org_sflphone_SFLphone_ConfigurationManager_get_ringtone_choice(
			configurationManagerProxy,
			&tone,
			&error);
	if(error)
	{
		g_error_free(error);
	}
	return tone;
}

void
dbus_set_ringtone_choice( const gchar* tone )
{
	GError* error = NULL;
	org_sflphone_SFLphone_ConfigurationManager_set_ringtone_choice(
			configurationManagerProxy,
			tone,
			&error);
	if(error)
	{
		g_error_free(error);
	}
}

973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001
int
dbus_is_ringtone_enabled()
{
	int res;
	GError* error = NULL;
	org_sflphone_SFLphone_ConfigurationManager_is_ringtone_enabled(
			configurationManagerProxy,
			&res,
			&error);
	if(error)
	{
		g_error_free(error);
	}
	return res;
}

void
dbus_ringtone_enabled()
{
	GError* error = NULL;
	org_sflphone_SFLphone_ConfigurationManager_ringtone_enabled(
			configurationManagerProxy,
			&error);
	if(error)
	{
		g_error_free(error);
	}
}

Emmanuel Milou's avatar
Emmanuel Milou committed
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016
int
dbus_is_iax2_enabled()
{
	int res;
	GError* error = NULL;
	org_sflphone_SFLphone_ConfigurationManager_is_iax2_enabled(
			configurationManagerProxy,
			&res,
			&error);
	if(error)
	{
		g_error_free(error);
	}
	return res;
}
Emmanuel Milou's avatar
Emmanuel Milou committed
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046

int
dbus_get_dialpad()
{
	int state;
	GError* error = NULL;
	org_sflphone_SFLphone_ConfigurationManager_get_dialpad(
			configurationManagerProxy,
			&state,
			&error);
	if(error)
	{
		g_error_free(error);
	}
	return state;
}

void
dbus_set_dialpad(  )
{
	GError* error = NULL;
	org_sflphone_SFLphone_ConfigurationManager_set_dialpad(
			configurationManagerProxy,
			&error);
	if(error)
	{
		g_error_free(error);
	}
}

1047 1048 1049 1050 1051
int
dbus_get_searchbar()
{
	int state;
	GError* error = NULL;
1052 1053 1054 1055 1056 1057 1058 1059 1060
	if(!org_sflphone_SFLphone_ConfigurationManager_get_searchbar( configurationManagerProxy, &state, &error))
    {
        if(error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION)
            g_printerr ("Caught remote method (get_searchbar) exception  %s: %s\n", dbus_g_error_get_name(error), error->message);
        else
            g_printerr("Error while calling get_searchbar: %s\n", error->message);
        g_error_free (error);
        return -1;
    }
1061
	else
1062 1063 1064
    {
	    return state;
    }
1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079
}

void
dbus_set_searchbar(  )
{
	GError* error = NULL;
	org_sflphone_SFLphone_ConfigurationManager_set_searchbar(
			configurationManagerProxy,
			&error);
	if(error)
	{
		g_error_free(error);
	}
}

1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108
int
dbus_get_volume_controls()
{
	int state;
	GError* error = NULL;
	org_sflphone_SFLphone_ConfigurationManager_get_volume_controls(
			configurationManagerProxy,
			&state,
			&error);
	if(error)
	{
		g_error_free(error);
	}
	return state;
}

void
dbus_set_volume_controls(  )
{
	GError* error = NULL;
	org_sflphone_SFLphone_ConfigurationManager_set_volume_controls(
			configurationManagerProxy,
			&error);
	if(error)
	{
		g_error_free(error);
	}
}

alexandresavard's avatar
alexandresavard committed
1109 1110 1111 1112 1113 1114 1115 1116 1117 1118

void
dbus_set_record(const call_t * c)
{
       g_print("calling dbus_set_record on CallManager\n");
       printf("CallID : %s \n", c->callID);
       GError* error = NULL;
       org_sflphone_SFLphone_CallManager_set_recording (
                       callManagerProxy,
                       c->callID,
1119 1120 1121 1122 1123
                       &error);
	    if(error)
	    {
		    g_error_free(error);
	    }
alexandresavard's avatar
alexandresavard committed
1124 1125
}

1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154
void
dbus_set_record_path(const gchar* path)
{
       GError* error = NULL;
       org_sflphone_SFLphone_ConfigurationManager_set_record_path (
                       configurationManagerProxy,
                       path,
                       &error);
	    if(error)
	    {
		    g_error_free(error);
	    }
}

    gchar*
dbus_get_record_path(void)
{
       GError* error = NULL;
       gchar *path;
       org_sflphone_SFLphone_ConfigurationManager_get_record_path (
                       configurationManagerProxy,
                       &path,
                       &error);
	    if(error)
	    {
		    g_error_free(error);
	    }
        return path;
}
alexandresavard's avatar
alexandresavard committed
1155

1156
void
Emmanuel Milou's avatar
Emmanuel Milou committed
1157
dbus_set_max_calls( const guint calls  )
1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169
{
	GError* error = NULL;
	org_sflphone_SFLphone_ConfigurationManager_set_max_calls(
			configurationManagerProxy,
			calls,
			&error);
	if(error)
	{
		g_error_free(error);
	}
}

Emmanuel Milou's avatar
Emmanuel Milou committed
1170
guint
1171 1172 1173
dbus_get_max_calls( void )
{
	GError* error = NULL;
Emmanuel Milou's avatar
Emmanuel Milou committed
1174
	gint calls;
1175 1176 1177 1178 1179 1180 1181 1182
	org_sflphone_SFLphone_ConfigurationManager_get_max_calls(
			configurationManagerProxy,
			&calls,
			&error);
	if(error)
	{
		g_error_free(error);
	}
Emmanuel Milou's avatar
Emmanuel Milou committed
1183
	return (guint)calls;
1184 1185
}

Emmanuel Milou's avatar
Emmanuel Milou committed
1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214
void
dbus_start_hidden( void )
{
	GError* error = NULL;
	org_sflphone_SFLphone_ConfigurationManager_start_hidden(
			configurationManagerProxy,
			&error);
	if(error)
	{
		g_error_free(error);
	}
}


int
dbus_is_start_hidden( void )
{
	GError* error = NULL;
	int state;
	org_sflphone_SFLphone_ConfigurationManager_is_start_hidden(
			configurationManagerProxy,
			&state,
			&error);
	if(error)
	{
		g_error_free(error);
	}
	return state;
}
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243

int
dbus_popup_mode( void )
{
	GError* error = NULL;
	int state;
	org_sflphone_SFLphone_ConfigurationManager_popup_mode(
			configurationManagerProxy,
			&state,
			&error);
	if(error)
	{
		g_error_free(error);
	}
	return state;
}

void
dbus_switch_popup_mode( void )
{
	GError* error = NULL;
	org_sflphone_SFLphone_ConfigurationManager_switch_popup_mode(
			configurationManagerProxy,
			&error);
	if(error)
	{
		g_error_free(error);
	}
}
1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260

void
dbus_set_notify( void )
{
	GError* error = NULL;
	org_sflphone_SFLphone_ConfigurationManager_set_notify(
			configurationManagerProxy,
			&error);
	if(error)
	{
		g_error_free(error);
	}
}

guint
dbus_get_notify( void )
{
Emmanuel Milou's avatar
Emmanuel Milou committed
1261
	gint level;
1262
	GError* error = NULL;
1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274
	if( !org_sflphone_SFLphone_ConfigurationManager_get_notify( configurationManagerProxy,&level, &error) )
    {
        if(error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION)
            g_printerr ("Caught remote method (get_notify) exception  %s: %s\n", dbus_g_error_get_name(error), error->message);
        else
            g_printerr("Error while calling get_notify: %s\n", error->message);
        g_error_free (error);
        return 0;
    }
    else{
        return (guint)level;
    }
1275 1276
}

1277

1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293
void
dbus_set_mail_notify( void )
{
	GError* error = NULL;
	org_sflphone_SFLphone_ConfigurationManager_set_mail_notify(
			configurationManagerProxy,
			&error);
	if(error)
	{
		g_error_free(error);
	}
}

guint
dbus_get_mail_notify( void )
{
Emmanuel Milou's avatar
Emmanuel Milou committed
1294
	gint level;
1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305
	GError* error = NULL;
	org_sflphone_SFLphone_ConfigurationManager_get_mail_notify(
			configurationManagerProxy,
			&level,
			&error);
	if(error)
	{
	  g_print("Error calling dbus_get_mail_notif_level\n");
		g_error_free(error);
	}
	
Emmanuel Milou's avatar
Emmanuel Milou committed
1306
	return (guint)level;
1307
}
1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339

void
dbus_set_audio_manager( int api )
{