Skip to content
Snippets Groups Projects
Commit 66a2b8ee authored by Rafaël Carré's avatar Rafaël Carré
Browse files

Don't reference count DBus clients, exit core immediately when one of them request it

parent f4ad4a50
Branches
Tags
No related merge requests found
...@@ -2,32 +2,12 @@ ...@@ -2,32 +2,12 @@
<node name="/instance-introspec" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> <node name="/instance-introspec" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
<interface name="org.sflphone.SFLphone.Instance"> <interface name="org.sflphone.SFLphone.Instance">
<tp:docstring xmlns="http://www.w3.org/1999/xhtml"> <tp:docstring xmlns="http://www.w3.org/1999/xhtml">
<p>Count the number of clients actually registered to the core. When initializing your client, you need to register it against the core by using this interface.</p> <p></p>
</tp:docstring> </tp:docstring>
<method name="Register" tp:name-for-bindings="Register"> <method name="Quit" tp:name-for-bindings="Quit">
<tp:docstring> <tp:docstring>
Register a new client to the core. Increments the registration count. Properly quits the core.
</tp:docstring> </tp:docstring>
<arg type="i" name="pid" direction="in">
<tp:docstring>
The pid of the client process
</tp:docstring>
</arg>
<arg type="s" name="name" direction="in">
<tp:docstring>
The name of the client
</tp:docstring>
</arg>
</method>
<method name="Unregister" tp:name-for-bindings="Unregister">
<tp:docstring>
Unregister a connected client from the core. Decrements the registration count. If no more clients are connected, ie the registration count equals 0, the core properly quits.
</tp:docstring>
<arg type="i" name="pid" direction="in">
<tp:docstring>
The pid of the client process
</tp:docstring>
</arg>
</method> </method>
</interface> </interface>
</node> </node>
...@@ -34,24 +34,11 @@ ...@@ -34,24 +34,11 @@
Instance::Instance (DBus::Connection& connection) Instance::Instance (DBus::Connection& connection)
: DBus::ObjectAdaptor (connection, "/org/sflphone/SFLphone/Instance") : DBus::ObjectAdaptor (connection, "/org/sflphone/SFLphone/Instance")
{ {
count = 0;
} }
void void
Instance::Register (const int32_t& pid UNUSED, Instance::Quit(void)
const std::string& name UNUSED)
{ {
count++;
}
void
Instance::Unregister (const int32_t& pid UNUSED)
{
count --;
if (count <= 0) {
Manager::instance().terminate(); Manager::instance().terminate();
Manager::instance().getDbusManager()->exit(); Manager::instance().getDbusManager()->exit();
} }
}
...@@ -52,16 +52,10 @@ class Instance ...@@ -52,16 +52,10 @@ class Instance
public DBus::IntrospectableAdaptor, public DBus::IntrospectableAdaptor,
public DBus::ObjectAdaptor public DBus::ObjectAdaptor
{ {
private:
int count;
public: public:
Instance (DBus::Connection& connection); Instance (DBus::Connection& connection);
static const char* SERVER_PATH;
void Register (const int32_t& pid, const std::string& name); void Quit(void);
void Unregister (const int32_t& pid);
int32_t getRegistrationCount (void);
}; };
......
...@@ -184,7 +184,7 @@ sflphone_quit () ...@@ -184,7 +184,7 @@ sflphone_quit ()
// Save the history // Save the history
sflphone_save_history (); sflphone_save_history ();
dbus_unregister (getpid()); dbus_quit();
dbus_clean (); dbus_clean ();
calllist_clean (current_calls); calllist_clean (current_calls);
calllist_clean (contacts); calllist_clean (contacts);
...@@ -315,7 +315,7 @@ void sflphone_fill_account_list (void) ...@@ -315,7 +315,7 @@ void sflphone_fill_account_list (void)
gboolean sflphone_init (GError **error) gboolean sflphone_init (GError **error)
{ {
if (!dbus_connect (error) || !dbus_register (getpid (), "Gtk+ Client", error)) if (!dbus_connect (error))
return FALSE; return FALSE;
abook_init(); abook_init();
......
...@@ -1098,18 +1098,12 @@ dbus_start_tone (const int start, const guint type) ...@@ -1098,18 +1098,12 @@ dbus_start_tone (const int start, const guint type)
} }
} }
gboolean
dbus_register (int pid, gchar *name, GError **error)
{
return org_sflphone_SFLphone_Instance_register (instanceProxy, pid, name, error);
}
void void
dbus_unregister (int pid) dbus_quit(void)
{ {
GError *error = NULL; GError *error = NULL;
org_sflphone_SFLphone_Instance_unregister (instanceProxy, pid, &error); org_sflphone_SFLphone_Instance_quit(instanceProxy, &error);
if (error) { if (error) {
ERROR ("Failed to call unregister() on instanceProxy: %s", ERROR ("Failed to call unregister() on instanceProxy: %s",
......
...@@ -359,20 +359,10 @@ void dbus_set_audio_manager (const gchar *api); ...@@ -359,20 +359,10 @@ void dbus_set_audio_manager (const gchar *api);
*/ */
void dbus_start_tone (const int start , const guint type); void dbus_start_tone (const int start , const guint type);
/**
* Instance - Send registration request to dbus service.
* Manage the instances of clients connected to the server
* @param pid The pid of the processus client
* @param name The string description of the client. Here : GTK+ Client
* @param error return location for a GError or NULL
*/
gboolean dbus_register (int pid, gchar * name, GError **error);
/** /**
* Instance - Send unregistration request to dbus services * Instance - Send unregistration request to dbus services
* @param pid The pid of the processus
*/ */
void dbus_unregister (int pid); void dbus_quit(void);
void dbus_set_sip_address (const gchar* address); void dbus_set_sip_address (const gchar* address);
......
...@@ -2,32 +2,12 @@ ...@@ -2,32 +2,12 @@
<node name="/instance-introspec" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"> <node name="/instance-introspec" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
<interface name="org.sflphone.SFLphone.Instance"> <interface name="org.sflphone.SFLphone.Instance">
<tp:docstring xmlns="http://www.w3.org/1999/xhtml"> <tp:docstring xmlns="http://www.w3.org/1999/xhtml">
<p>Count the number of clients actually registered to the core. When initializing your client, you need to register it against the core by using this interface.</p> <p></p>
</tp:docstring> </tp:docstring>
<method name="Register" tp:name-for-bindings="Register"> <method name="Quit" tp:name-for-bindings="Quit">
<tp:docstring> <tp:docstring>
Register a new client to the core. Increments the registration count. Properly quits the core.
</tp:docstring> </tp:docstring>
<arg type="i" name="pid" direction="in">
<tp:docstring>
The pid of the client process
</tp:docstring>
</arg>
<arg type="s" name="name" direction="in">
<tp:docstring>
The name of the client
</tp:docstring>
</arg>
</method>
<method name="Unregister" tp:name-for-bindings="Unregister">
<tp:docstring>
Unregister a connected client from the core. Decrements the registration count. If no more clients are connected, ie the registration count equals 0, the core properly quits.
</tp:docstring>
<arg type="i" name="pid" direction="in">
<tp:docstring>
The pid of the client process
</tp:docstring>
</arg>
</method> </method>
</interface> </interface>
</node> </node>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment