SF.net SVN: geany:[4544] branches/sm/src

statc at users.sourceforge.net statc at xxxxx
Sun Jan 24 20:23:14 UTC 2010


Revision: 4544
          http://geany.svn.sourceforge.net/geany/?rev=4544&view=rev
Author:   statc
Date:     2010-01-24 20:23:14 +0000 (Sun, 24 Jan 2010)

Log Message:
-----------
Add sm_finalize().

Modified Paths:
--------------
    branches/sm/src/main.c
    branches/sm/src/sm.c
    branches/sm/src/sm.h

Modified: branches/sm/src/main.c
===================================================================
--- branches/sm/src/main.c	2010-01-24 20:06:09 UTC (rev 4543)
+++ branches/sm/src/main.c	2010-01-24 20:23:14 UTC (rev 4544)
@@ -1122,6 +1122,8 @@
 		project_close(FALSE, FALSE);
 	document_close_all(TRUE);
 
+	sm_finalize();
+
 #ifdef HAVE_SOCKET
 	socket_finalize();
 #endif

Modified: branches/sm/src/sm.c
===================================================================
--- branches/sm/src/sm.c	2010-01-24 20:06:09 UTC (rev 4543)
+++ branches/sm/src/sm.c	2010-01-24 20:23:14 UTC (rev 4544)
@@ -27,7 +27,8 @@
  * In order to support XSMP, we have to support Inter-Client Exchange
  * Protocol (ICE). This file takes care of the latter too.
  *
- * Typical usage: @c sm_init() is called when Geany is starting.
+ * Typical usage: @c sm_init() is called when Geany is starting and
+ * @c sm_finalize() is called when Geany is quitting.
  *
  * According to libSM documentation, client should retain the same ID after
  * it is restarted. The main module (@c main.c) maintains "--libsm-client-id"
@@ -78,6 +79,9 @@
 static void sm_die_callback(SmcConn smcon, SmPointer client_data);
 
 
+/** LibSM connection object initialized in @c sm_init() and used in @c sm_finalize(). */
+static SmcConn smc_conn;
+
 /**
  * @c SmPropValue storing a path to Geany's executable.
  *
@@ -123,19 +127,43 @@
 void sm_init(const char * argv0, const char * libsm_client_id)
 {
 	#ifdef HAVE_LIBSM
-
 	char * new_client_id;
-	SmcConn smcon = sm_connect(libsm_client_id, &new_client_id);
 
-	if (!smcon)
+		/* This function should be called once */
+	g_assert(!smc_conn);
+	if (smc_conn)
+		return;
+
+	smc_conn = sm_connect(libsm_client_id, &new_client_id);
+	if (!smc_conn)
     return;
 
   sm_store_props(argv0, new_client_id);
-  sm_set_constant_props(smcon);
+  sm_set_constant_props(smc_conn);
   free(new_client_id);
   #endif
 }
 
+
+/**
+ * Perform cleanup.
+ *
+ * Call this function when XSMP support is no longer needed. In fact it is
+ * called when Geany is quitting.
+ *
+ * When Geany is compiled without XSMP support, this function is a no-op.
+ */
+void sm_finalize(void)
+{
+	#ifdef HAVE_LIBSM
+	if (smc_conn)
+	{
+		SmcCloseConnection(smc_conn, 0, NULL);
+		smc_conn = 0;
+	}
+	#endif
+}
+
 /** @} */
 
 #ifdef HAVE_LIBSM
@@ -590,11 +618,12 @@
  *
  * See libSM documentation for more details.
  *
- * The session manager asks us to quit Geany and we do it.
+ * The session manager asks us to quit Geany and we do it. When quitting, the
+ * main module (@c main.c) will call @c sm_finalize() where we will close the
+ * connection to the session manager.
  */
 static void sm_die_callback(SmcConn smcon, SmPointer client_data)
 {
-	SmcCloseConnection(smcon, 0, NULL);
 	main_finalize();
 }
 

Modified: branches/sm/src/sm.h
===================================================================
--- branches/sm/src/sm.h	2010-01-24 20:06:09 UTC (rev 4543)
+++ branches/sm/src/sm.h	2010-01-24 20:23:14 UTC (rev 4544)
@@ -25,4 +25,6 @@
 
 void sm_init(const char * argv0, const char * libsm_client_id);
 
+void sm_finalize(void);
+
 #endif


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list