[med-svn] [aghermann] 02/05: enable multiple instances, drop libunique; lock sessions in use

andrei zavada hmmr-guest at moszumanska.debian.org
Thu Aug 4 23:11:40 UTC 2016


This is an automated email from the git hooks/post-receive script.

hmmr-guest pushed a commit to branch master
in repository aghermann.

commit 47cff8bdcaba494302947b5633928f25bca7c489
Author: Andrei Zavada <hmmr at frdg>
Date:   Sun Jun 26 02:14:34 2016 +0300

    enable multiple instances, drop libunique; lock sessions in use
---
 debian/control                                |  4 +-
 upstream/configure.ac                         |  1 -
 upstream/src/Makefile.am                      |  2 +-
 upstream/src/aghermann/Makefile.am            |  4 +-
 upstream/src/aghermann/expdesign/expdesign.cc | 38 ++++++++++++-
 upstream/src/aghermann/expdesign/expdesign.hh |  5 +-
 upstream/src/aghermann/main.cc                | 79 +++++----------------------
 upstream/src/aghermann/ui/globals.cc          | 15 -----
 upstream/src/aghermann/ui/globals.hh          |  6 --
 upstream/src/aghermann/ui/sm/sm.cc            | 51 ++++++-----------
 upstream/src/tools/Makefile.am                |  2 +-
 11 files changed, 75 insertions(+), 132 deletions(-)

diff --git a/debian/control b/debian/control
index 2cd8c80..a7c4e83 100644
--- a/debian/control
+++ b/debian/control
@@ -4,9 +4,9 @@ Priority: optional
 Maintainer: Andrei Zavada <johnhommer at gmail.com>
 Build-Depends: debhelper (>= 9), dh-autoreconf,
  autoconf-archive, pkg-config, libgomp1, libconfig++-dev, libgsl-dev, libfftw3-dev,
- libsamplerate0-dev (>= 0.1.7), libgtk-3-dev, libitpp-dev, libunique-3.0-dev, libvte-2.91-dev,
+ libsamplerate0-dev (>= 0.1.7), libgtk-3-dev, libitpp-dev, libvte-2.91-dev,
  liblua5.2-dev, lua5.2, libxml2-utils
-Standards-Version: 3.9.6
+Standards-Version: 3.9.8
 Homepage: http://johnhommer.com/academic/code/aghermann
 Vcs-Git: git://git.debian.org/git/debian-med/aghermann.git
 Vcs-Browser: http://anonscm.debian.org/gitweb/?p=debian-med/aghermann.git
diff --git a/upstream/configure.ac b/upstream/configure.ac
index b96c254..a83816a 100644
--- a/upstream/configure.ac
+++ b/upstream/configure.ac
@@ -64,7 +64,6 @@ PKG_CHECK_MODULES([FFTW3], [fftw3])
 PKG_CHECK_MODULES([ITPP], [itpp])
 PKG_CHECK_MODULES([GTK], [gtk+-3.0 >= 3.4 glib-2.0 gthread-2.0 gio-unix-2.0 gmodule-export-2.0])
 PKG_CHECK_MODULES([CAIRO], [cairo >= 1.8.10])
-PKG_CHECK_MODULES([UNIQUE], [unique-3.0])
 PKG_CHECK_MODULES([VTE], [vte-2.91])
 
 AX_PATH_GSL([2.0], [AC_DEFINE([HAVE_GSL_20], [], [we have gsl >= 2.0])], [])
diff --git a/upstream/src/Makefile.am b/upstream/src/Makefile.am
index b49f04a..0035780 100644
--- a/upstream/src/Makefile.am
+++ b/upstream/src/Makefile.am
@@ -10,7 +10,7 @@ EXTRA_DIST := \
 # by trial and error, the _CFLAGS mentioned are the minimum required to pre-build all headers
 AM_CXXFLAGS := \
 	-Wall -std=c++0x -fno-rtti \
-	$(GTK_CFLAGS)  $(UNIQUE_CFLAGS) \
+	$(GTK_CFLAGS) \
 	$(OPENMP_CXXFLAGS) \
 	-I$(top_srcdir)/src -I.. \
 	-DHAVE_CONFIG_H \
diff --git a/upstream/src/aghermann/Makefile.am b/upstream/src/aghermann/Makefile.am
index 3ff0fa1..af0f43b 100644
--- a/upstream/src/aghermann/Makefile.am
+++ b/upstream/src/aghermann/Makefile.am
@@ -1,6 +1,6 @@
 AM_CXXFLAGS := \
 	-Wall -Werror=format-security -Wdeprecated-declarations -std=c++0x -fno-rtti \
-	$(GTK_CFLAGS) $(VTE_CFLAGS) $(CAIRO_CFLAGS) $(LIBCONFIGXX_CFLAGS) $(UNIQUE_CFLAGS) \
+	$(GTK_CFLAGS) $(VTE_CFLAGS) $(CAIRO_CFLAGS) $(LIBCONFIGXX_CFLAGS) \
 	$(OPENMP_CXXFLAGS) \
 	$(LUA_INCLUDE) \
 	-I$(top_srcdir)/src \
@@ -137,7 +137,7 @@ aghermann_LDADD := \
 	../common/liba.a \
 	../libsigfile/libsigfile.la \
 	$(FFTW3_LIBS) $(ITPP_LIBS) $(SAMPLERATE_LIBS) $(GSL_LIBS) \
-	$(GTK_LIBS) $(CAIRO_LIBS) $(UNIQUE_LIBS) $(VTE_LIBS) \
+	$(GTK_LIBS) $(CAIRO_LIBS) $(VTE_LIBS) \
 	$(LIBCONFIGXX_LIBS) \
 	$(LIBFFTW3_LDADD) $(OPENMP_CXXFLAGS) \
 	$(LUA_LIB)
diff --git a/upstream/src/aghermann/expdesign/expdesign.cc b/upstream/src/aghermann/expdesign/expdesign.cc
index 713ed34..e466318 100644
--- a/upstream/src/aghermann/expdesign/expdesign.cc
+++ b/upstream/src/aghermann/expdesign/expdesign.cc
@@ -11,6 +11,8 @@
 
 
 #include <stdarg.h>
+#include <string.h>
+#include <fcntl.h>
 #include <string>
 
 #ifdef _OPENMP
@@ -93,7 +95,7 @@ CExpDesign (const string& session_dir_,
                 throw invalid_argument (string ("Failed to canonicalize dir: ") + session_dir_);
 
         if ( session_dir_ != tmp ) {
-                APPLOG_INFO( "canonicalized session_dir \"%s\" to \"%s\"", session_dir_.c_str(), tmp);
+                APPLOG_INFO ("canonicalized session_dir \"%s\" to \"%s\"", session_dir_.c_str(), tmp);
                 _session_dir.assign( tmp);
         } else
                 _session_dir = session_dir_;
@@ -102,11 +104,34 @@ CExpDesign (const string& session_dir_,
         if ( _session_dir.size() > 1 && _session_dir[_session_dir.size()-1] == '/' )
                 _session_dir.erase( _session_dir.size()-1, 1);
 
+        using agh::str::sasprintf;
         if ( fs::exists_and_is_writable( session_dir()) == false )
-                throw invalid_argument (agh::str::sasprintf( "Experiment directory \"%s\" does not exist or is not writable", _session_dir.c_str()));
+                throw invalid_argument (sasprintf( "Experiment directory\n"
+                                                   "<i>%s</i>\n"
+                                                   "does not exist or is not writable", session_dir()));
 
         if ( chdir( session_dir()) == -1 )
-                throw invalid_argument (agh::str::sasprintf( "Failed to cd to \"%s\"", _session_dir.c_str()));
+                throw invalid_argument (sasprintf( "Failed to cd to \"%s\"", session_dir()));
+
+        {
+                string lock_fname (_session_dir + "/.session.lock");
+                struct stat stat0;
+                int stst = stat( lock_fname.c_str(), &stat0);
+                if ( stst == 0 ) {
+                        const char *lock_mtime_s = ctime( &stat0.st_mtime);
+                        throw invalid_argument
+                                (sasprintf("A lock file exists:\n<i>%s</i>,\ncreated %.*s).\n\n"
+                                           "If this lock is stale, delete it and try again.",
+                                           lock_fname.c_str(), (int)strlen(lock_mtime_s)-1, lock_mtime_s));
+                }
+                open( lock_fname.c_str(), O_WRONLY|O_CREAT|O_TRUNC, 0600);
+                stst = stat( lock_fname.c_str(), &stat0);
+                if ( stst != 0 )
+                        throw invalid_argument
+                                (sasprintf("Failed to place a session lock file (%s)",
+                                           strerror(errno)));
+        }
+
 
         load_settings();
 
@@ -131,6 +156,13 @@ CExpDesign (const string& session_dir_,
 }
 
 
+CExpDesign::~CExpDesign ()
+{
+        save_settings();
+        unlink((_session_dir + "/.session.lock").c_str());
+}
+
+
 void
 agh::CExpDesign::
 log_message( TLogEntryStyle style, const char* fmt, ...)
diff --git a/upstream/src/aghermann/expdesign/expdesign.hh b/upstream/src/aghermann/expdesign/expdesign.hh
index 43bc0cf..e6f1bc0 100644
--- a/upstream/src/aghermann/expdesign/expdesign.hh
+++ b/upstream/src/aghermann/expdesign/expdesign.hh
@@ -64,10 +64,7 @@ class CExpDesign {
         typedef function<void(const string&, size_t, size_t)> TMsmtCollectProgressIndicatorFun;
         CExpDesign (const string& sessiondir,
                     TMsmtCollectProgressIndicatorFun progress_fun = progress_fun_stdout);
-       ~CExpDesign ()
-                {
-                        save_settings();
-                }
+       ~CExpDesign ();
 
         int status() const
                 { return _status; }
diff --git a/upstream/src/aghermann/main.cc b/upstream/src/aghermann/main.cc
index 9526c24..62b436d 100644
--- a/upstream/src/aghermann/main.cc
+++ b/upstream/src/aghermann/main.cc
@@ -16,7 +16,6 @@
 #endif
 
 #include <gtk/gtk.h>
-#include <unique/unique.h>
 
 #include "project_strings.h"
 #include "globals.hh"
@@ -31,7 +30,6 @@ using namespace agh;
 void print_version();
 
 namespace {
-UniqueResponse message_received_cb( UniqueApp*, UniqueCommand, UniqueMessageData*, guint, gpointer);
 void print_usage( const char*);
 }
 
@@ -72,37 +70,22 @@ main( int argc, char **argv)
         } else {
                 gtk_init( &argc, &argv);
 
-                // don't let user get us started twice
-                ui::global::unique_app =
-                        unique_app_new_with_commands(
-                                "com.johnhommer.Aghermann",
-                                NULL, "fafa", 1, NULL);
-                if ( unique_app_is_running( ui::global::unique_app) ) {
-                        printf( "There is unique app, switching to it now\n");
-                        unique_app_send_message( ui::global::unique_app, UNIQUE_ACTIVATE, NULL);
-                } else {
-                        g_signal_connect(
-                                ui::global::unique_app, "message-received",
-                                (GCallback)message_received_cb,
-                                NULL);
-
-                        agh::global::init( lf_fname);
-
-                        if ( agh::ui::global::prepare_for_expdesign() ) {
-                                ui::pop_ok_message(
-                                        NULL,
-                                        "UI failed to initialize",
-                                        "Your install is broken.");
-                                return 2;
-                        }
-
-                        ui::SSessionChooser chooser (argv[optind]);
-                        // implicit read sessionrc, run
-
-                        gtk_main();
-
-                        agh::global::fini();
+                agh::global::init( lf_fname);
+
+                if ( agh::ui::global::prepare_for_expdesign() ) {
+                        ui::pop_ok_message(
+                                NULL,
+                                "UI failed to initialize",
+                                "Your install is broken.");
+                        return 2;
                 }
+
+                ui::SSessionChooser chooser (argv[optind]);
+                // implicit read sessionrc, run
+
+                gtk_main();
+
+                agh::global::fini();
                 // g_object_unref (app); // abandon ship anyway
         }
 
@@ -110,38 +93,6 @@ main( int argc, char **argv)
 }
 
 namespace {
-UniqueResponse
-message_received_cb(
-        UniqueApp*,
-        const UniqueCommand command,
-        UniqueMessageData  *message,
-        const guint	    time_,
-        gpointer)
-{
-        if ( ui::global::main_window == NULL )
-                return UNIQUE_RESPONSE_OK;
-
-        UniqueResponse res;
-
-        switch ( command ) {
-        case UNIQUE_ACTIVATE:
-                // move the main window to the screen that sent us the command
-                gtk_window_set_screen(
-                        ui::global::main_window,
-                        unique_message_data_get_screen( message));
-                gtk_window_present_with_time(
-                        ui::global::main_window,
-                        time_);
-                res = UNIQUE_RESPONSE_OK;
-            break;
-        default:
-                res = UNIQUE_RESPONSE_OK;
-            break;
-        }
-
-        return res;
-}
-
 void
 print_usage( const char* argv0)
 {
diff --git a/upstream/src/aghermann/ui/globals.cc b/upstream/src/aghermann/ui/globals.cc
index ada0f06..abd0aae 100644
--- a/upstream/src/aghermann/ui/globals.cc
+++ b/upstream/src/aghermann/ui/globals.cc
@@ -21,9 +21,6 @@ char    agh::ui::global::buf[AGH_BUF_SIZE];
 GdkDevice
         *agh::ui::global::client_pointer;
 
-UniqueApp
-        *agh::ui::global::unique_app;
-
 GtkWindow
         *agh::ui::global::main_window;
 
@@ -35,18 +32,6 @@ GtkCssProvider
         *agh::ui::global::css_mono10;
 
 
-// unique
-
-void
-agh::ui::global::
-set_unique_app_window( GtkWindow* w)
-{
-        unique_app_watch_window(
-                unique_app,
-                main_window = w);
-}
-
-
 // own init
 
 int
diff --git a/upstream/src/aghermann/ui/globals.hh b/upstream/src/aghermann/ui/globals.hh
index f4ecaaf..94ffbac 100644
--- a/upstream/src/aghermann/ui/globals.hh
+++ b/upstream/src/aghermann/ui/globals.hh
@@ -14,7 +14,6 @@
 #define AGH_AGHERMANN_UI_GLOBALS_H_
 
 #include <gtk/gtk.h>
-#include <unique/unique.h>
 
 #if HAVE_CONFIG_H && !defined(VERSION)
 #  include "config.h"
@@ -28,9 +27,6 @@ namespace ui {
 namespace global {
 
 // convenience assign-once vars
-extern UniqueApp
-        *unique_app;
-
 extern GtkWindow
         *main_window;
 
@@ -61,8 +57,6 @@ extern char
         buf[AGH_BUF_SIZE];
 
 
-void set_unique_app_window( GtkWindow*);
-
 int prepare_for_expdesign();
 
 }
diff --git a/upstream/src/aghermann/ui/sm/sm.cc b/upstream/src/aghermann/ui/sm/sm.cc
index 60e918a..56da9d2 100644
--- a/upstream/src/aghermann/ui/sm/sm.cc
+++ b/upstream/src/aghermann/ui/sm/sm.cc
@@ -44,7 +44,6 @@ get_session_stats()
                 if ( stst != -1 )
                         last_visited = stat0.st_mtime;
         }
-
 }
 
 
@@ -61,32 +60,30 @@ SSessionChooser (const char* explicit_session)
         bool have_explicit_dir = (explicit_session && strlen(explicit_session) > 0);
 
         try {
+                string preselected;
                 if ( have_explicit_dir ) {
-                        char* canonicalized = canonicalize_file_name( explicit_session);
                         ed = new SExpDesignUI(
-                                this, canonicalized);
-                        global::set_unique_app_window( ed->wMainWindow);
-                        free( canonicalized);
+                                this, explicit_session);
 
                 } else if ( last_dir_no == -1 ) {
                         gtk_widget_show( (GtkWidget*)wSessionChooser);
-                        //set_unique_app_window( (GtkWindow*)wSessionChooser);
 
-                } else {
+                } else if ( (preselected = get_dir(), preselected.size() > 1) )
                         ed = new SExpDesignUI(
-                                this, get_dir());
-                        global::set_unique_app_window( ed->wMainWindow);
+                                this, preselected);
+                else {
+                        string new_experiment_dir = string (getenv("HOME")) + "/NewExperiment";
+                        if ( agh::fs::mkdir_with_parents( new_experiment_dir.c_str()) ) {
+                                pop_ok_message( nullptr,
+                                                "Failed to create a new directory in your $HOME.",
+                                                " There's nothing we can do about that.");
+                        } else
+                                ed = new SExpDesignUI( this, new_experiment_dir);
                 }
-        } catch (runtime_error ex) {
-                pop_ok_message( nullptr, "Huh", "%s", ex.what());
 
-                string new_experiment_dir = string (getenv("HOME")) + "/NewExperiment";
-                if ( agh::fs::mkdir_with_parents( new_experiment_dir.c_str()) ) {
-                        pop_ok_message( nullptr, "Failed to create a new directory in your $HOME.",
-                                               " There's nothing we can do about that.");
-                }
-                ed = new SExpDesignUI( this, new_experiment_dir);
-                // if HOME is non-writable, then don't catch: it's too seriously broken
+        } catch (invalid_argument ex) {
+                pop_ok_message( nullptr, "Problem loading session", "%s", ex.what());
+                gtk_widget_show( (GtkWidget*)wSessionChooser);
         }
 }
 
@@ -102,8 +99,6 @@ SSessionChooser::
 
 
 
-
-
 int
 SSessionChooser::
 open_selected_session()
@@ -116,17 +111,14 @@ open_selected_session()
         try {
                 ed = new SExpDesignUI(
                         this, selected);
-                global::set_unique_app_window( ed->wMainWindow);
 
                 return 0;
 
         } catch (invalid_argument ex) {
                 ed = nullptr;
-                //set_unique_app_window( (GtkWindow*)wSessionChooser);
 
                 pop_ok_message( nullptr,
-                                ex.what(),
-                                "Please choose another directory");
+                                "Problem loading session", "%s", ex.what());
                 return -1;
         }
 }
@@ -139,13 +131,10 @@ close_current_session()
         assert (ed);
         delete ed;
         ed = nullptr;
-        //set_unique_app_window( unique_app, (GtkWindow*)wSessionChooser);
 }
 
 
 
-
-
 void
 SSessionChooser::
 destruct_widgets()
@@ -159,8 +148,6 @@ destruct_widgets()
 
 
 
-
-
 void
 SSessionChooser::
 buf_on_status_bar( const bool)
@@ -202,7 +189,6 @@ get_selected_dir()
         gtk_tree_model_get_iter( model, &iter, path);
 
         gchar *entry;
-        //unique_ptr<void,void(*)(void*)> u(entry, g_free);
         gtk_tree_model_get( model, &iter, 2, &entry, -1);
         string ret {entry};
         agh::str::tilda2homedir(ret);
@@ -269,7 +255,6 @@ read_sessionrc()
 
         } catch (...) {
                 // create new
-                printf( "Creating new sessionrc\n");
                 char *cwd = getcwd( NULL, 0);
                 string e {cwd};
                 sessions.emplace_back( agh::str::homedir2tilda(e));
@@ -347,8 +332,8 @@ _sync_model_to_list()
         sessions.clear();
         GtkTreeIter
                 iter;
-        bool        some_items_left = gtk_tree_model_get_iter_first( (GtkTreeModel*)mSessionChooserList, &iter);
-        gchar        *entry;
+        bool    some_items_left = gtk_tree_model_get_iter_first( (GtkTreeModel*)mSessionChooserList, &iter);
+        gchar  *entry;
         while ( some_items_left ) {
                 gtk_tree_model_get( (GtkTreeModel*)mSessionChooserList, &iter,  // at least one entry exists,
                                     2, &entry,                             // added in read_histfile()
diff --git a/upstream/src/tools/Makefile.am b/upstream/src/tools/Makefile.am
index fd58e69..15058ff 100644
--- a/upstream/src/tools/Makefile.am
+++ b/upstream/src/tools/Makefile.am
@@ -31,7 +31,7 @@ edfhed_gtk_SOURCES := \
 	../aghermann/ui/ui.cc \
 	edfhed-gtk.cc
 edfhed_gtk_CXXFLAGS := \
-	$(AM_CXXFLAGS) 	$(UNIQUE_CFLAGS) $(GTK_CFLAGS) -DPACKAGE_DATADIR=\"$(datadir)\"
+	$(AM_CXXFLAGS) $(GTK_CFLAGS) -DPACKAGE_DATADIR=\"$(datadir)\"
 edfhed_gtk_LDADD := \
 	../libsigfile/libsigfile.la \
 	../libsigproc/libsigproc.la \

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/aghermann.git



More information about the debian-med-commit mailing list