Commit 63f3b941 authored by Pierre-Luc Beaudoin's avatar Pierre-Luc Beaudoin

Instance counting

parent 8ceb4332
......@@ -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) \
......
......@@ -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;
}
......
......@@ -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");
}
}
......@@ -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
......@@ -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
......
/*
* 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
......
/*
* 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
......
/*
* 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
......
/*
* 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
......
/*
* 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
......
/*
* 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();
}
/*
* 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
/*
* 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
<?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>
/*
* 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();
}
}
/*
* 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
[D-BUS Service]
Name=org.sflphone.SFLphone.CallManager
Name=org.sflphone.SFLphone
Exec=bindir/sflphoned
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment