diff --git a/sflphone-gtk/src/Makefile.am b/sflphone-gtk/src/Makefile.am index 18c6871566b19e84b74c042c1ea4eff326c3993a..0e01d996751022c36ba354b1f3689442485f0206 100644 --- a/sflphone-gtk/src/Makefile.am +++ b/sflphone-gtk/src/Makefile.am @@ -18,9 +18,9 @@ sflphone_gtk_SOURCES = \ statusicon.c noinst_HEADERS = actions.h dbus.h mainwindow.h calllist.h dialpad.h \ - callmanager-glue.h menus.h calltree.h screen.h configwindow.h \ + callmanager-glue.h configurationmanager-glue.h instance-glue.h menus.h calltree.h screen.h configwindow.h \ accountlist.h accountwindow.h marshaller.h sliders.h statusicon.h -EXTRA_DIST = marshaller.list +EXTRA_DIST = marshaller.list sflphone_gtk_LDADD = $(DEPS_LIBS) AM_CPPFLAGS = $(DEPS_CFLAGS) \ diff --git a/sflphone-gtk/src/actions.c b/sflphone-gtk/src/actions.c index 036e8ca9a8adb8d77650514903d3818972255f4f..593e8bfa13c755d7559f52c84c4dd0f8b7817fec 100644 --- a/sflphone-gtk/src/actions.c +++ b/sflphone-gtk/src/actions.c @@ -30,6 +30,9 @@ #include <string.h> #include <glib/gprintf.h> #include <stdlib.h> +#include <sys/types.h> +#include <unistd.h> + void sflphone_notify_voice_mail (guint count) @@ -61,8 +64,10 @@ sflphone_quit () if (quit) { + dbus_unregister(getpid()); dbus_clean (); //call_list_clean(); TODO + //account_list_clean() gtk_main_quit (); } return quit; @@ -147,6 +152,7 @@ sflphone_init() } else { + dbus_register(getpid(), "Gtk+ Client"); sflphone_fill_account_list(); return TRUE; } diff --git a/sflphone-gtk/src/dbus.c b/sflphone-gtk/src/dbus.c index 4ee4a2f53d166f8bb3f1d54ca9ce910750b3f5cb..2801daa09621ac792de13d4e4a715ebc1febeb2e 100644 --- a/sflphone-gtk/src/dbus.c +++ b/sflphone-gtk/src/dbus.c @@ -21,6 +21,7 @@ #include <calllist.h> #include <callmanager-glue.h> #include <configurationmanager-glue.h> +#include <instance-glue.h> #include <configwindow.h> #include <mainwindow.h> #include <marshaller.h> @@ -34,6 +35,7 @@ DBusGConnection * connection; DBusGProxy * callManagerProxy; DBusGProxy * configurationManagerProxy; +DBusGProxy * instanceProxy; static void incoming_call_cb (DBusGProxy *proxy, @@ -166,6 +168,19 @@ dbus_connect () /* Create a proxy object for the "bus driver" (name "org.freedesktop.DBus") */ + instanceProxy = dbus_g_proxy_new_for_name (connection, + "org.sflphone.SFLphone", + "/org/sflphone/SFLphone/Instance", + "org.sflphone.SFLphone.Instance"); + if (!instanceProxy) + { + g_printerr ("Failed to get proxy to Instance\n"); + return FALSE; + } + + g_print ("DBus connected to Instance\n"); + + callManagerProxy = dbus_g_proxy_new_for_name (connection, "org.sflphone.SFLphone", "/org/sflphone/SFLphone/CallManager", @@ -554,3 +569,49 @@ dbus_play_dtmf(const gchar * key) } } + +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); + } + else + { + g_print ("DBus called register() on instanceProxy\n"); + + } +} + +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); + } + else + { + g_print ("DBus called unregister() on instanceProxy\n"); + } +} diff --git a/sflphone-gtk/src/dbus.h b/sflphone-gtk/src/dbus.h index c0e389dd30d772d1cf0db58bc4d2da229392ecdc..a663ee7806459346a0a12ffacb10f5a6888929dd 100644 --- a/sflphone-gtk/src/dbus.h +++ b/sflphone-gtk/src/dbus.h @@ -51,4 +51,10 @@ void dbus_set_volume(const gchar * device, gdouble value); gdouble dbus_get_volume(const gchar * device); void dbus_play_dtmf(const gchar * key); +/* Instance */ +void dbus_register( int pid, gchar * name); +void dbus_unregister(int pid); + + + #endif diff --git a/src/dbus/Makefile.am b/src/dbus/Makefile.am index a556f250429371c06b85e29de3eb2b6723fc5d02..a4e411715bc109401eeaf3df5de59c2b564d48b0 100644 --- a/src/dbus/Makefile.am +++ b/src/dbus/Makefile.am @@ -5,8 +5,9 @@ EXTRA_DIST = *.xml README noinst_LTLIBRARIES = libdbus.la libdbus_la_SOURCES = \ - callmanager.cpp \ + callmanager.cpp \ configurationmanager.cpp \ + instance.cpp \ dbusmanagerimpl.cpp libdbus_la_CXXFLAGS = -DPREFIX=\"$(prefix)\" -DPROGSHAREDIR=\"${datadir}/sflphone\" @@ -17,6 +18,9 @@ noinst_HEADERS = \ callmanager-glue.h \ callmanager.h \ configurationmanager.h \ + configurationmanager-glue.h \ + instance.h \ + instance-glue.h \ dbusmanager.h \ dbusmanagerimpl.h diff --git a/src/dbus/callmanager.cpp b/src/dbus/callmanager.cpp index 70bdeabb3b69f26dbdd33bf4fef28d11f1682865..6e03ca8381e0ad2100472aa8c6f985aea86525f2 100644 --- a/src/dbus/callmanager.cpp +++ b/src/dbus/callmanager.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2007 Savoir-Faire Linux inc. - * Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com> + * Author: Pierre-Luc Beaudoin <pierre-luc@squidy.info> * Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify diff --git a/src/dbus/callmanager.h b/src/dbus/callmanager.h index f52d8ed6015bd929bae95d1e87bde76448f4af02..e55e2b6fe0329e7831aefbef3d9386f3e491d0e9 100644 --- a/src/dbus/callmanager.h +++ b/src/dbus/callmanager.h @@ -1,6 +1,6 @@ /* * Copyright (C) 2007 Savoir-Faire Linux inc. - * Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com> + * Author: Pierre-Luc Beaudoin <pierre-luc@squidy.info> * * 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 diff --git a/src/dbus/configurationmanager.cpp b/src/dbus/configurationmanager.cpp index 1de8988827eb7c80f2bd9c976e3c0db488677146..601408a350b539b78f8ba584dea72e3efd2a3bed 100644 --- a/src/dbus/configurationmanager.cpp +++ b/src/dbus/configurationmanager.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2007 Savoir-Faire Linux inc. - * Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com> + * Author: Pierre-Luc Beaudoin <pierre-luc@squidy.info> * * 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 diff --git a/src/dbus/configurationmanager.h b/src/dbus/configurationmanager.h index 53b84ff39c7baaa88822e135927f068c1f4157af..394a319b92346b213792942a466c379f5a7b680c 100644 --- a/src/dbus/configurationmanager.h +++ b/src/dbus/configurationmanager.h @@ -1,6 +1,6 @@ /* * Copyright (C) 2007 Savoir-Faire Linux inc. - * Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com> + * Author: Pierre-Luc Beaudoin <pierre-luc@squidy.info> * Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify diff --git a/src/dbus/dbusmanager.h b/src/dbus/dbusmanager.h index 2b096ac3fc2fbc086c6b9ba8ae2aea8d3e10950b..a4f847a613b1e761879caa610551dee3dbb0faa7 100644 --- a/src/dbus/dbusmanager.h +++ b/src/dbus/dbusmanager.h @@ -1,6 +1,6 @@ /* * Copyright (C) 2007 Savoir-Faire Linux inc. - * Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com> + * Author: Pierre-Luc Beaudoin <pierre-luc@squidy.info> * * 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 diff --git a/src/dbus/dbusmanagerimpl.cpp b/src/dbus/dbusmanagerimpl.cpp index c5a2e50e68b0a86024526b7e8428eb317e542d5d..b0c6434b253505834f8dd0175ea4bdcc6c326503 100644 --- a/src/dbus/dbusmanagerimpl.cpp +++ b/src/dbus/dbusmanagerimpl.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2007 Savoir-Faire Linux inc. - * Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com> + * Author: Pierre-Luc Beaudoin <pierre-luc@squidy.info> * * 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 @@ -32,6 +32,7 @@ DBusManagerImpl::exec(){ _callManager = new CallManager(conn); _configurationManager = new ConfigurationManager(conn); + _instanceManager = new Instance(conn); // Register accounts Manager::instance().initRegisterAccounts(); //getEvents(); @@ -42,4 +43,9 @@ DBusManagerImpl::exec(){ return 1; } - +void +DBusManagerImpl::exit() +{ + _dispatcher.leave(); +} + diff --git a/src/dbus/dbusmanagerimpl.h b/src/dbus/dbusmanagerimpl.h index a08802afa5baa1485a9274eee78f4035d029ac20..0e5fd999dd5868efe51fb05c5768eb3e95e2a4ea 100644 --- a/src/dbus/dbusmanagerimpl.h +++ b/src/dbus/dbusmanagerimpl.h @@ -1,6 +1,6 @@ /* * Copyright (C) 2007 Savoir-Faire Linux inc. - * Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com> + * Author: Pierre-Luc Beaudoin <pierre-luc@squidy.info> * * 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 @@ -22,18 +22,21 @@ #include "callmanager.h" #include "configurationmanager.h" +#include "instance.h" class DBusManagerImpl { public: CallManager * getCallManager(){ return _callManager; }; ConfigurationManager * getConfigurationManager(){ return _configurationManager; }; int exec(); + void exit(); static const char* SERVER_NAME; private: - CallManager * _callManager; - ConfigurationManager * _configurationManager; - DBus::BusDispatcher _dispatcher; + CallManager* _callManager; + ConfigurationManager* _configurationManager; + Instance* _instanceManager; + DBus::BusDispatcher _dispatcher; }; #endif diff --git a/src/dbus/instance-glue.h b/src/dbus/instance-glue.h new file mode 100644 index 0000000000000000000000000000000000000000..5032d811b1361b70e019a891e8bdf26723e046f7 --- /dev/null +++ b/src/dbus/instance-glue.h @@ -0,0 +1,109 @@ + +/* + * This file was automatically generated by dbusxx-xml2cpp; DO NOT EDIT! + */ + +#ifndef __dbusxx__instance_glue_h__ADAPTOR_MARSHAL_H +#define __dbusxx__instance_glue_h__ADAPTOR_MARSHAL_H + +#include <dbus-c++/dbus.h> + +namespace org { +namespace sflphone { +namespace SFLphone { + +class Instance +: public ::DBus::InterfaceAdaptor +{ +public: + + Instance() + : ::DBus::InterfaceAdaptor("org.sflphone.SFLphone.Instance") + { + register_method(Instance, Register, _Register_stub); + register_method(Instance, Unregister, _Unregister_stub); + } + + ::DBus::IntrospectedInterface* const introspect() const + { + static ::DBus::IntrospectedArgument Register_args[] = + { + { "pid", "i", true }, + { "name", "s", true }, + { 0, 0, 0 } + }; + static ::DBus::IntrospectedArgument Unregister_args[] = + { + { "pid", "i", true }, + { 0, 0, 0 } + }; + static ::DBus::IntrospectedMethod Instance_methods[] = + { + { "Register", Register_args }, + { "Unregister", Unregister_args }, + { 0, 0 } + }; + static ::DBus::IntrospectedMethod Instance_signals[] = + { + { 0, 0 } + }; + static ::DBus::IntrospectedProperty Instance_properties[] = + { + { 0, 0, 0, 0 } + }; + static ::DBus::IntrospectedInterface Instance_interface = + { + "org.sflphone.SFLphone.Instance", + Instance_methods, + Instance_signals, + Instance_properties + }; + return &Instance_interface; + } + +public: + + /* properties exposed by this interface, use + * property() and property(value) to get and set a particular property + */ + +public: + + /* methods exported by this interface, + * you will have to implement them in your ObjectAdaptor + */ + virtual void Register( const ::DBus::Int32& pid, const ::DBus::String& name ) = 0; + virtual void Unregister( const ::DBus::Int32& pid ) = 0; + +public: + + /* signal emitters for this interface + */ + +private: + + /* unmarshalers (to unpack the DBus message before calling the actual interface method) + */ + ::DBus::Message _Register_stub( const ::DBus::CallMessage& call ) + { + ::DBus::MessageIter ri = call.reader(); + + ::DBus::Int32 argin1; ri >> argin1; + ::DBus::String argin2; ri >> argin2; + Register(argin1, argin2); + ::DBus::ReturnMessage reply(call); + return reply; + } + ::DBus::Message _Unregister_stub( const ::DBus::CallMessage& call ) + { + ::DBus::MessageIter ri = call.reader(); + + ::DBus::Int32 argin1; ri >> argin1; + Unregister(argin1); + ::DBus::ReturnMessage reply(call); + return reply; + } +}; + +} } } +#endif//__dbusxx__instance_glue_h__ADAPTOR_MARSHAL_H diff --git a/src/dbus/instance-introspec.xml b/src/dbus/instance-introspec.xml new file mode 100644 index 0000000000000000000000000000000000000000..404dff31f2abbdee63e28fb3b31730a77b6ad6f0 --- /dev/null +++ b/src/dbus/instance-introspec.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" ?> +<node name="/org/sflphone/SFLphone"> + <interface name="org.sflphone.SFLphone.Instance"> + + <method name="Register"> + <arg type="i" name="pid" direction="in"/> + <arg type="s" name="name" direction="in"/> + </method> + + <method name="Unregister"> + <arg type="i" name="pid" direction="in"/> + </method> + + </interface> +</node> diff --git a/src/dbus/instance.cpp b/src/dbus/instance.cpp new file mode 100644 index 0000000000000000000000000000000000000000..62d72b4a64553e7400fdacef0aaaa858597ac98c --- /dev/null +++ b/src/dbus/instance.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2007 Savoir-Faire Linux inc. + * Author: Pierre-Luc Beaudoin <pierre-luc@squidy.info> + * + * 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 + * 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 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. + */ +#include <global.h> +#include <instance.h> +#include "../manager.h" + +const char* Instance::SERVER_PATH = "/org/sflphone/SFLphone/Instance"; + +Instance::Instance( DBus::Connection& connection ) +: DBus::ObjectAdaptor(connection, SERVER_PATH) +{ + count = 0; +} + +void +Instance::Register( const ::DBus::Int32& pid, + const ::DBus::String& name ) +{ + _debug("Instance::register received\n"); + count++; +} + + +void +Instance::Unregister( const ::DBus::Int32& pid ) +{ + _debug("Instance::unregister received\n"); + count --; + if(count <= 0) + { + _debug("0 client running, quitting..."); + DBusManager::instance().exit(); + } +} + + diff --git a/src/dbus/instance.h b/src/dbus/instance.h new file mode 100644 index 0000000000000000000000000000000000000000..65e53d06ff8a9aec17e3dc79b75ac2cc418d4b98 --- /dev/null +++ b/src/dbus/instance.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2007 Savoir-Faire Linux inc. + * Author: Pierre-Luc Beaudoin <pierre-luc@squidy.info> + * + * 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 + * 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 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. + */ + +#ifndef INSTANCE_H +#define INSTANCE_H + +#include "instance-glue.h" +#include <dbus-c++/dbus.h> + + +class Instance +: public org::sflphone::SFLphone::Instance, + public DBus::IntrospectableAdaptor, + public DBus::ObjectAdaptor +{ +private: + int count; + +public: + Instance(DBus::Connection& connection); + static const char* SERVER_PATH; + + void Register( const ::DBus::Int32& pid, const ::DBus::String& name ); + void Unregister( const ::DBus::Int32& pid ); + + +}; + + +#endif//INSTANCE_H diff --git a/src/dbus/org.sflphone.SFLphone.service.in b/src/dbus/org.sflphone.SFLphone.service.in index 9fcbcc97d59742778c6e444927cc9bcaa46610b1..031173b777cc5a516d135beb81ebd312322f860e 100644 --- a/src/dbus/org.sflphone.SFLphone.service.in +++ b/src/dbus/org.sflphone.SFLphone.service.in @@ -1,3 +1,3 @@ [D-BUS Service] -Name=org.sflphone.SFLphone.CallManager +Name=org.sflphone.SFLphone Exec=bindir/sflphoned