[SCM] calf/master: Separate session manager interface code into separate classes.

js at users.alioth.debian.org js at users.alioth.debian.org
Tue May 7 15:40:07 UTC 2013


The following commit has been merged in the master branch:
commit 7a3da4846d02a0d9881a416d516a070bd0798bfb
Author: Krzysztof Foltman <wdev at foltman.com>
Date:   Sat Apr 24 09:02:29 2010 +0100

    Separate session manager interface code into separate classes.
    
    All communication with the session manager (lashd) is now done using
    a set of interfaces. The code specific for LASH 0.5.4 and LASH 0.6
    is now in separate classes. Conditional compilation is used to build
    one or the other. There are no more direct references to LASH APIs
    from the core JACK host code.

diff --git a/src/Makefile.am b/src/Makefile.am
index 18a0498..858b5de 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -29,7 +29,7 @@ if USE_JACK
 AM_CXXFLAGS += $(JACK_DEPS_CFLAGS)
 noinst_LTLIBRARIES += libcalfgui.la
 bin_PROGRAMS += calfjackhost 
-calfjackhost_SOURCES = host_session.cpp jack_client.cpp jackhost.cpp main_win.cpp
+calfjackhost_SOURCES = host_session.cpp jack_client.cpp jackhost.cpp main_win.cpp session_mgr.cpp
 calfjackhost_LDADD = libcalfgui.la calf.la $(JACK_DEPS_LIBS) $(GUI_DEPS_LIBS) $(FLUIDSYNTH_DEPS_LIBS)
 if USE_LASH
 AM_CXXFLAGS += $(LASH_DEPS_CFLAGS)
diff --git a/src/calf/Makefile.am b/src/calf/Makefile.am
index 73845fe..a67bc2d 100644
--- a/src/calf/Makefile.am
+++ b/src/calf/Makefile.am
@@ -7,4 +7,4 @@ noinst_HEADERS = audio_fx.h benchmark.h biquad.h buffer.h custom_ctl.h \
     lv2_uri_map.h lv2-midiport.h lv2helpers.h lv2wrap.h \
     main_win.h metadata.h modmatrix.h modules.h modules_dev.h modules_synths.h modulelist.h \
     multichorus.h onepole.h organ.h osc.h osctl.h osctlnet.h osctl_glib.h preset.h \
-    preset_gui.h primitives.h synth.h utils.h vumeter.h wave.h waveshaping.h
+    preset_gui.h primitives.h session_mgr.h synth.h utils.h vumeter.h wave.h waveshaping.h
diff --git a/src/calf/host_session.h b/src/calf/host_session.h
index af03af8..534a0f1 100644
--- a/src/calf/host_session.h
+++ b/src/calf/host_session.h
@@ -23,28 +23,20 @@
 
 #include <config.h>
 
-#if USE_LASH
-#include <lash/lash.h>
-#endif
 #include "gui.h"
 #include "jackhost.h"
+#include "session_mgr.h"
 
 namespace calf_plugins {
 
 class main_window;
 
-struct host_session: public main_window_owner_iface, public calf_plugins::progress_report_iface
+struct host_session: public main_window_owner_iface, public calf_plugins::progress_report_iface, public session_client_iface
 {
     std::string client_name, input_name, output_name, midi_name;
     std::vector<std::string> plugin_names;
     std::map<int, std::string> presets;
-#if USE_LASH
-    int lash_source_id;
-    lash_client_t *lash_client;
-# if !USE_LASH_0_6
-    lash_args_t *lash_args;
-# endif
-#endif
+    session_manager_iface *session_manager;
     
     // these are not saved
     jack_client client;
@@ -53,7 +45,6 @@ struct host_session: public main_window_owner_iface, public calf_plugins::progre
     std::set<int> chains;
     std::vector<jack_host *> plugins;
     main_window *main_win;
-    bool restoring_session;
     std::set<std::string> instances;
     GtkWidget *progress_window;
     plugin_gui_window *gui_win;
@@ -65,15 +56,6 @@ struct host_session: public main_window_owner_iface, public calf_plugins::progre
     void connect();
     void close();
     bool activate_preset(int plugin, const std::string &preset, bool builtin);
-#if USE_LASH
-    static gboolean update_lash(void *self) { ((host_session *)self)->update_lash(); return TRUE; }
-    void update_lash();
-# if !USE_LASH_0_6
-    void send_lash(LASH_Event_Type type, const std::string &data) {
-        lash_send_event(lash_client, lash_event_new_with_all(type, data.c_str()));
-    }
-# endif
-#endif
     virtual void new_plugin(const char *name);    
     virtual void remove_plugin(plugin_ctl_iface *plugin);
     void remove_all_plugins();
@@ -88,8 +70,11 @@ struct host_session: public main_window_owner_iface, public calf_plugins::progre
     virtual char *open_file(const char *name);
     /// Implementation of save file functionality
     virtual char *save_file(const char *name);
-    /// Implementation of connection to LASH (or, in future, other session manager)
-    void connect_to_session_manager(int argc, char *argv[]);
+
+    /// Load from session manager
+    virtual void load(session_load_iface *);
+    /// Save to session manager
+    virtual void save(session_save_iface *);
 };
 
 };
diff --git a/src/calf/session_mgr.h b/src/calf/session_mgr.h
new file mode 100644
index 0000000..90321af
--- /dev/null
+++ b/src/calf/session_mgr.h
@@ -0,0 +1,43 @@
+#ifndef CALF_SESSION_MGR_H
+#define CALF_SESSION_MGR_H
+
+#include <string>
+
+namespace calf_plugins {
+
+struct session_load_iface
+{
+    virtual bool get_next_item(std::string &key, std::string &value) = 0;
+    virtual ~session_load_iface() {}
+};
+    
+struct session_save_iface
+{
+    virtual void write_next_item(const std::string &key, const std::string &value) = 0;
+    virtual ~session_save_iface() {}
+};
+    
+struct session_client_iface
+{
+    virtual void load(session_load_iface *) = 0;
+    virtual void save(session_save_iface *) = 0;
+    virtual ~session_client_iface() {}
+};
+    
+struct session_manager_iface
+{
+    virtual bool is_being_restored() = 0;
+    virtual void set_jack_client_name(const std::string &name) = 0;
+    virtual void connect(const std::string &name) = 0;
+    virtual void poll() = 0;
+    virtual void disconnect() = 0;
+    virtual ~session_manager_iface() {}
+};
+
+#if USE_LASH
+extern session_manager_iface *create_lash_session_mgr(session_client_iface *client, int &argc, char **&argv);
+#endif
+
+};
+
+#endif
diff --git a/src/host_session.cpp b/src/host_session.cpp
index 9836f38..9d94a01 100644
--- a/src/host_session.cpp
+++ b/src/host_session.cpp
@@ -35,19 +35,12 @@ using namespace calf_plugins;
 host_session::host_session()
 {
     client_name = "calf";
-#if USE_LASH
-    lash_source_id = 0;
-    lash_client = NULL;
-# if !USE_LASH_0_6
-    lash_args = NULL;
-# endif
-#endif
-    restoring_session = false;
     main_win = new main_window;
     main_win->set_owner(this);
     progress_window = NULL;
     autoconnect_midi_index = -1;
     gui_win = NULL;
+    session_manager = NULL;
 }
 
 std::string host_session::get_next_instance_name(const std::string &effect_name)
@@ -157,7 +150,7 @@ void host_session::open()
     main_win->prefix = client_name + " - ";
     main_win->conditions.insert("jackhost");
     main_win->conditions.insert("directlink");
-    if (!restoring_session)
+    if (!session_manager || !session_manager->is_being_restored()) 
         create_plugins_from_list();
     main_win->create();
     gtk_signal_connect(GTK_OBJECT(main_win->toplevel), "destroy", G_CALLBACK(window_destroy_cb), NULL);
@@ -222,11 +215,9 @@ bool host_session::activate_preset(int plugin_no, const std::string &preset, boo
 void host_session::connect()
 {
     client.activate();
-#if USE_LASH && !USE_LASH_0_6
-    if (lash_client)
-        lash_jack_client_name(lash_client, client.get_name().c_str());
-#endif
-    if (!restoring_session) 
+    if (session_manager)
+        session_manager->set_jack_client_name(client.get_name());
+    if (!session_manager || !session_manager->is_being_restored()) 
     {
         string cnp = client.get_name() + ":";
         for (unsigned int i = 0; i < plugins.size(); i++) {
@@ -288,32 +279,19 @@ void host_session::connect()
             }
         }
     }
-#if USE_LASH
-    if (lash_client)
-    {
-# if !USE_LASH_0_6
-        send_lash(LASH_Client_Name, "calf-"+client_name);
-# endif
-        lash_source_id = g_timeout_add_full(G_PRIORITY_LOW, 250, update_lash, this, NULL); // 4 LASH reads per second... should be enough?
-    }
-#endif
+    if (session_manager)
+        session_manager->connect("calf-" + client_name);
 }
 
 void host_session::close()
 {
-#if USE_LASH
-    if (lash_source_id)
-        g_source_remove(lash_source_id);
-#endif
+    if (session_manager)
+        session_manager->disconnect();
     main_win->on_closed();
     main_win->close_guis();
     client.deactivate();
     client.delete_plugins();
     client.close();
-#if USE_LASH && !USE_LASH_0_6
-    if (lash_args)
-        lash_args_destroy(lash_args);
-#endif
 }
 
 static string stripfmt(string x)
@@ -397,137 +375,59 @@ char *host_session::save_file(const char *name)
     return NULL;
 }
 
-#if USE_LASH
-
-# if !USE_LASH_0_6
-
-void host_session::update_lash()
+void host_session::load(session_load_iface *stream)
 {
-    do {
-        lash_event_t *event = lash_get_event(lash_client);
-        if (!event)
-            break;
-        
-        // printf("type = %d\n", lash_event_get_type(event));
-        
-        switch(lash_event_get_type(event)) {        
-            case LASH_Save_Data_Set:
-            {
-                lash_config_t *cfg = lash_config_new_with_key("global");
-                dictionary tmp;
-                string pstr;
-                string i_name = stripfmt(client.input_name);
-                string o_name = stripfmt(client.output_name);
-                string m_name = stripfmt(client.midi_name);
-                tmp["input_prefix"] = i_name;
-                tmp["output_prefix"] = stripfmt(client.output_name);
-                tmp["midi_prefix"] = stripfmt(client.midi_name);
-                pstr = encode_map(tmp);
-                lash_config_set_value(cfg, pstr.c_str(), pstr.length());
-                lash_send_config(lash_client, cfg);
-                
-                for (unsigned int i = 0; i < plugins.size(); i++) {
-                    jack_host *p = plugins[i];
-                    char ss[32];
-                    plugin_preset preset;
-                    preset.plugin = p->metadata->get_id();
-                    preset.get_from(p);
-                    sprintf(ss, "Plugin%d", i);
-                    pstr = preset.to_xml();
-                    tmp.clear();
-                    tmp["instance_name"] = p->instance_name;
-                    if (p->metadata->get_input_count())
-                        tmp["input_name"] = p->get_inputs()[0].name.substr(i_name.length());
-                    if (p->metadata->get_output_count())
-                        tmp["output_name"] = p->get_outputs()[0].name.substr(o_name.length());
-                    if (p->get_midi_port())
-                        tmp["midi_name"] = p->get_midi_port()->name.substr(m_name.length());
-                    tmp["preset"] = pstr;
-                    pstr = encode_map(tmp);
-                    lash_config_t *cfg = lash_config_new_with_key(ss);
-                    lash_config_set_value(cfg, pstr.c_str(), pstr.length());
-                    lash_send_config(lash_client, cfg);
-                }
-                send_lash(LASH_Save_Data_Set, "");
-                break;
-            }
-            
-            case LASH_Restore_Data_Set:
+    // printf("!!!Restore data set!!!\n");
+    remove_all_plugins();
+    string key, data;
+    while(stream->get_next_item(key, data)) {
+        if (key == "global")
+        {
+            dictionary dict;
+            decode_map(dict, data);
+            if (dict.count("input_prefix")) client.input_name = dict["input_prefix"]+"%d";
+            if (dict.count("output_prefix")) client.output_name = dict["output_prefix"]+"%d";
+            if (dict.count("midi_prefix")) client.midi_name = dict["midi_prefix"]+"%d";
+        }
+        if (!strncmp(key.c_str(), "Plugin", 6))
+        {
+            unsigned int nplugin = atoi(key.c_str() + 6);
+            dictionary dict;
+            decode_map(dict, data);
+            data = dict["preset"];
+            string instance_name;
+            if (dict.count("instance_name")) instance_name = dict["instance_name"];
+            if (dict.count("input_name")) client.input_nr = atoi(dict["input_name"].c_str());
+            if (dict.count("output_name")) client.output_nr = atoi(dict["output_name"].c_str());
+            if (dict.count("midi_name")) client.midi_nr = atoi(dict["midi_name"].c_str());
+            preset_list tmp;
+            tmp.parse("<presets>"+data+"</presets>", false);
+            if (tmp.presets.size())
             {
-                // printf("!!!Restore data set!!!\n");
-                remove_all_plugins();
-                while(lash_config_t *cfg = lash_get_config(lash_client)) {
-                    const char *key = lash_config_get_key(cfg);
-                    // printf("key = %s\n", lash_config_get_key(cfg));
-                    string data = string((const char *)lash_config_get_value(cfg), lash_config_get_value_size(cfg));
-                    if (!strcmp(key, "global"))
-                    {
-                        dictionary dict;
-                        decode_map(dict, data);
-                        if (dict.count("input_prefix")) client.input_name = dict["input_prefix"]+"%d";
-                        if (dict.count("output_prefix")) client.output_name = dict["output_prefix"]+"%d";
-                        if (dict.count("midi_prefix")) client.midi_name = dict["midi_prefix"]+"%d";
-                    }
-                    if (!strncmp(key, "Plugin", 6))
-                    {
-                        unsigned int nplugin = atoi(key + 6);
-                        dictionary dict;
-                        decode_map(dict, data);
-                        data = dict["preset"];
-                        string instance_name;
-                        if (dict.count("instance_name")) instance_name = dict["instance_name"];
-                        if (dict.count("input_name")) client.input_nr = atoi(dict["input_name"].c_str());
-                        if (dict.count("output_name")) client.output_nr = atoi(dict["output_name"].c_str());
-                        if (dict.count("midi_name")) client.midi_nr = atoi(dict["midi_name"].c_str());
-                        preset_list tmp;
-                        tmp.parse("<presets>"+data+"</presets>", false);
-                        if (tmp.presets.size())
-                        {
-                            printf("Load plugin %s\n", tmp.presets[0].plugin.c_str());
-                            add_plugin(tmp.presets[0].plugin, "", instance_name);
-                            tmp.presets[0].activate(plugins[nplugin]);
-                            main_win->refresh_plugin(plugins[nplugin]);
-                        }
-                    }
-                    lash_config_destroy(cfg);
-                }
-                send_lash(LASH_Restore_Data_Set, "");
-                break;
+                printf("Load plugin %s\n", tmp.presets[0].plugin.c_str());
+                add_plugin(tmp.presets[0].plugin, "", instance_name);
+                tmp.presets[0].activate(plugins[nplugin]);
+                main_win->refresh_plugin(plugins[nplugin]);
             }
-                
-            case LASH_Quit:
-                gtk_main_quit();
-                break;
-            
-            default:
-                g_warning("Unhandled LASH event %d (%s)", lash_event_get_type(event), lash_event_get_string(event));
-                break;
         }
-    } while(1);
-}
-
-# else
-
-void host_session::update_lash()
-{
-    lash_dispatch(lash_client);
+    }
 }
 
-static bool save_data_set_cb(lash_config_handle_t *handle, void *user_data)
+void host_session::save(session_save_iface *stream)
 {
-    host_session *sess = static_cast<host_session *>(user_data);
     dictionary tmp;
     string pstr;
-    string i_name = stripfmt(sess->client.input_name);
-    string o_name = stripfmt(sess->client.output_name);
-    string m_name = stripfmt(sess->client.midi_name);
+    string i_name = stripfmt(client.input_name);
+    string o_name = stripfmt(client.output_name);
+    string m_name = stripfmt(client.midi_name);
     tmp["input_prefix"] = i_name;
-    tmp["output_prefix"] = stripfmt(sess->client.output_name);
-    tmp["midi_prefix"] = stripfmt(sess->client.midi_name);
+    tmp["output_prefix"] = stripfmt(client.output_name);
+    tmp["midi_prefix"] = stripfmt(client.midi_name);
     pstr = encode_map(tmp);
-    lash_config_write_raw(handle, "global", pstr.c_str(), pstr.length());
-    for (unsigned int i = 0; i < sess->plugins.size(); i++) {
-        jack_host *p = sess->plugins[i];
+    stream->write_next_item("global", pstr);
+    
+    for (unsigned int i = 0; i < plugins.size(); i++) {
+        jack_host *p = plugins[i];
         char ss[32];
         plugin_preset preset;
         preset.plugin = p->metadata->get_id();
@@ -544,84 +444,7 @@ static bool save_data_set_cb(lash_config_handle_t *handle, void *user_data)
             tmp["midi_name"] = p->get_midi_port()->name.substr(m_name.length());
         tmp["preset"] = pstr;
         pstr = encode_map(tmp);
-        lash_config_write_raw(handle, ss, pstr.c_str(), pstr.length());
+        stream->write_next_item(ss, pstr);
     }
-    return true;
 }
 
-static bool load_data_set_cb(lash_config_handle_t *handle, void *user_data)
-{
-    host_session *sess = static_cast<host_session *>(user_data);
-    int size, type;
-    const char *key;
-    const char *value;
-    sess->remove_all_plugins();
-    while((size = lash_config_read(handle, &key, (void *)&value, &type))) {
-        if (size == -1 || type != LASH_TYPE_RAW)
-            continue;
-        string data = string(value, size);
-        if (!strcmp(key, "global"))
-        {
-            dictionary dict;
-            decode_map(dict, data);
-            if (dict.count("input_prefix")) sess->client.input_name = dict["input_prefix"]+"%d";
-            if (dict.count("output_prefix")) sess->client.output_name = dict["output_prefix"]+"%d";
-            if (dict.count("midi_prefix")) sess->client.midi_name = dict["midi_prefix"]+"%d";
-        } else if (!strncmp(key, "Plugin", 6)) {
-            unsigned int nplugin = atoi(key + 6);
-            dictionary dict;
-            decode_map(dict, data);
-            data = dict["preset"];
-            string instance_name;
-            if (dict.count("instance_name")) instance_name = dict["instance_name"];
-            if (dict.count("input_name")) sess->client.input_nr = atoi(dict["input_name"].c_str());
-            if (dict.count("output_name")) sess->client.output_nr = atoi(dict["output_name"].c_str());
-            if (dict.count("midi_name")) sess->client.midi_nr = atoi(dict["midi_name"].c_str());
-            preset_list tmp;
-            tmp.parse("<presets>"+data+"</presets>", false);
-            if (tmp.presets.size())
-            {
-                printf("Load plugin %s\n", tmp.presets[0].plugin.c_str());
-                sess->add_plugin(tmp.presets[0].plugin, "", instance_name);
-                tmp.presets[0].activate(sess->plugins[nplugin]);
-                sess->main_win->refresh_plugin(sess->plugins[nplugin]);
-            }
-        }
-    }
-    return true;
-}
-
-static bool quit_cb(void *user_data)
-{
-    gtk_main_quit();
-    return true;
-}
-
-# endif
-#endif
-
-void host_session::connect_to_session_manager(int argc, char *argv[])
-{
-#if USE_LASH
-# if !USE_LASH_0_6
-    for (int i = 1; i < argc; i++)
-    {
-        if (!strncmp(argv[i], "--lash-project=", 14)) {
-            restoring_session = true;
-            break;
-        }
-    }
-    lash_args = lash_extract_args(&argc, &argv);
-    lash_client = lash_init(lash_args, PACKAGE_NAME, LASH_Config_Data_Set, LASH_PROTOCOL(2, 0));
-# else
-    lash_client = lash_client_open(PACKAGE_NAME, LASH_Config_Data_Set, argc, argv);
-    restoring_session = lash_client_is_being_restored(lash_client);
-    lash_set_save_data_set_callback(lash_client, save_data_set_cb, this);
-    lash_set_load_data_set_callback(lash_client, load_data_set_cb, this);
-    lash_set_quit_callback(lash_client, quit_cb, NULL);
-# endif
-    if (!lash_client) {
-        g_warning("Warning: failed to create a LASH connection");
-    }
-#endif
-}
diff --git a/src/jackhost.cpp b/src/jackhost.cpp
index 462ff52..7f53bdc 100644
--- a/src/jackhost.cpp
+++ b/src/jackhost.cpp
@@ -290,7 +290,9 @@ int main(int argc, char *argv[])
     gtk_rc_add_default_file(PKGLIBDIR "calf.rc");
     gtk_init(&argc, &argv);
     
-    sess.connect_to_session_manager(argc, argv);
+#if USE_LASH
+    sess.session_manager = create_lash_session_mgr(&sess, argc, argv);
+#endif
     glade_init();
     while(1) {
         int option_index;
diff --git a/src/session_mgr.cpp b/src/session_mgr.cpp
new file mode 100644
index 0000000..d316105
--- /dev/null
+++ b/src/session_mgr.cpp
@@ -0,0 +1,282 @@
+#include "config.h"
+#include <calf/session_mgr.h>
+
+#if USE_LASH
+
+#include <calf/utils.h>
+#include <gtk/gtk.h>
+#include <lash/lash.h>
+#include <glib.h>
+#include <string.h>
+
+using namespace std;
+using namespace calf_plugins;
+
+
+class lash_session_manager_base: public session_manager_iface
+{
+protected:
+    session_client_iface *client;
+    int lash_source_id;
+    lash_client_t *lash_client;
+    bool restoring_session;
+    static gboolean update_lash(void *self) { ((session_manager_iface *)self)->poll(); return TRUE; }
+public:
+    lash_session_manager_base(session_client_iface *_client);
+
+    void connect(const std::string &name)
+    {
+        if (lash_client)
+        {
+            lash_source_id = g_timeout_add_full(G_PRIORITY_LOW, 250, update_lash, (session_manager_iface *)this, NULL); // 4 LASH reads per second... should be enough?
+        }
+    }
+    void disconnect();
+};
+
+lash_session_manager_base::lash_session_manager_base(session_client_iface *_client)
+{
+    client = _client;
+    lash_source_id = 0;
+    lash_client = NULL;
+    restoring_session = false;
+}
+
+void lash_session_manager_base::disconnect()
+{
+    if (lash_source_id)
+    {
+        g_source_remove(lash_source_id);
+        lash_source_id = 0;
+    }
+}
+
+# if !USE_LASH_0_6
+
+class old_lash_session_manager: public lash_session_manager_base
+{
+    lash_args_t *lash_args;
+
+public:
+    old_lash_session_manager(session_client_iface *_client, int &argc, char **&argv);
+    void send_lash(LASH_Event_Type type, const std::string &data);
+    virtual void connect(const std::string &name);
+    virtual void disconnect();
+    virtual bool is_being_restored() { return restoring_session; }
+    virtual void set_jack_client_name(const std::string &name);
+    virtual void poll();
+
+};
+
+old_lash_session_manager::old_lash_session_manager(session_client_iface *_client, int &argc, char **&argv)
+: lash_session_manager_base(_client)
+{
+    lash_args = NULL;
+
+    for (int i = 1; i < argc; i++)
+    {
+        if (!strncmp(argv[i], "--lash-project=", 14)) {
+            restoring_session = true;
+            break;
+        }
+    }
+    lash_args = lash_extract_args(&argc, &argv);
+    lash_client = lash_init(lash_args, PACKAGE_NAME, LASH_Config_Data_Set, LASH_PROTOCOL(2, 0));
+    if (!lash_client) {
+        g_warning("Failed to create a LASH connection");
+    }
+}
+
+void old_lash_session_manager::send_lash(LASH_Event_Type type, const std::string &data)
+{
+    lash_send_event(lash_client, lash_event_new_with_all(type, data.c_str()));
+}
+
+void old_lash_session_manager::connect(const std::string &name)
+{
+    if (lash_client)
+    {
+        send_lash(LASH_Client_Name, name.c_str());
+    }
+    lash_session_manager_base::connect(name);
+}
+
+void old_lash_session_manager::disconnect()
+{
+    lash_session_manager_base::disconnect();
+    if (lash_args)
+        lash_args_destroy(lash_args);
+}
+
+void old_lash_session_manager::set_jack_client_name(const std::string &name)
+{
+    if (lash_client)
+        lash_jack_client_name(lash_client, name.c_str());
+}
+
+void old_lash_session_manager::poll()
+{
+    do {
+        lash_event_t *event = lash_get_event(lash_client);
+        if (!event)
+            break;
+        
+        // printf("type = %d\n", lash_event_get_type(event));
+        
+        switch(lash_event_get_type(event)) {        
+            case LASH_Save_Data_Set:
+            {
+                struct writer: public session_save_iface
+                {
+                    lash_client_t *client;
+                    
+                    void write_next_item(const std::string &key, const std::string &value)
+                    {
+                        lash_config_t *cfg = lash_config_new_with_key(key.c_str());
+                        lash_config_set_value(cfg, value.c_str(), value.length());
+                        lash_send_config(client, cfg);
+                    }
+                };
+                
+                writer w;
+                w.client = lash_client;
+                client->save(&w);
+                send_lash(LASH_Save_Data_Set, "");
+                break;
+            }
+            
+            case LASH_Restore_Data_Set:
+            {
+                struct reader: public session_load_iface
+                {
+                    lash_client_t *client;
+                    
+                    virtual bool get_next_item(std::string &key, std::string &value) {
+                        lash_config_t *cfg = lash_get_config(client);
+                        
+                        if(cfg) {
+                            key = lash_config_get_key(cfg);
+                            // printf("key = %s\n", lash_config_get_key(cfg));
+                            value = string((const char *)lash_config_get_value(cfg), lash_config_get_value_size(cfg));
+                            lash_config_destroy(cfg);
+                            return true;
+                        }
+                        return false;
+                    }        
+                };
+                
+                reader r;
+                r.client = lash_client;
+                client->load(&r);
+                send_lash(LASH_Restore_Data_Set, "");
+                break;
+            }
+                
+            case LASH_Quit:
+                gtk_main_quit();
+                break;
+            
+            default:
+                g_warning("Unhandled LASH event %d (%s)", lash_event_get_type(event), lash_event_get_string(event));
+                break;
+        }
+    } while(1);
+}
+
+session_manager_iface *calf_plugins::create_lash_session_mgr(session_client_iface *client, int &argc, char **&argv)
+{
+    return new old_lash_session_manager(client, argc, argv);
+}
+
+# else
+
+class new_lash_session_manager: public lash_session_manager_base
+{
+    lash_args_t *lash_args;
+
+    static bool save_data_set_cb(lash_config_handle_t *handle, void *user_data);
+    static bool load_data_set_cb(lash_config_handle_t *handle, void *user_data);
+    static bool quit_cb(void *user_data);
+
+public:
+    new_lash_session_manager(session_client_iface *_client)
+    
+    virtual void set_jack_client_name(const std::string &) {}
+};
+
+new_lash_session_manager::new_lash_session_manager(session_client_iface *_client)
+: lash_session_manager_base(_client)
+{
+    lash_client = lash_client_open(PACKAGE_NAME, LASH_Config_Data_Set, argc, argv);
+    if (!lash_client) {
+        g_warning("Failed to create a LASH connection");
+        return;
+    }
+    restoring_session = lash_client_is_being_restored(lash_client);
+    lash_set_save_data_set_callback(lash_client, save_data_set_cb, this);
+    lash_set_load_data_set_callback(lash_client, load_data_set_cb, this);
+    lash_set_quit_callback(lash_client, quit_cb, NULL);    
+}
+
+void new_lash_session_manager::poll()
+{
+    lash_dispatch(lash_client);
+}
+
+bool new_lash_session_manager::save_data_set_cb(lash_config_handle_t *handle, void *user_data)
+{
+    struct writer: public session_save_iface
+    {
+        lash_config_handle_t handle;
+        
+        virtual bool write_next_item(const std::string &key, const std::string &value) {
+            lash_config_write_raw(handle, key.c_str(), (const void *)value.data(), value.length(), LASH_TYPE_RAW);
+            return true;
+        }        
+    };
+    
+    writer w;
+    w.handle = handle;
+    client->save(&w);
+    return true;
+}
+
+bool new_lash_session_manager::load_data_set_cb(lash_config_handle_t *handle, void *user_data)
+{
+    struct reader: public session_load_iface
+    {
+        lash_config_handle_t handle;
+        
+        virtual bool get_next_item(std::string &key, std::string &value) {
+            const char *key_cstr;
+            int type;
+            void *data;
+            size = lash_config_read(handle, &key_cstr, &data, &type);
+            if (size == -1 || type != LASH_TYPE_RAW)
+                return false;
+            key = key_cstr;
+            value = string((const char *)data, size);
+            return true;
+        }        
+    };
+    
+    reader r;
+    r.handle = handle;
+    client->load(&r);
+    return true;
+}
+
+bool new_lash_session_manager::quit_cb(void *user_data)
+{
+    gtk_main_quit();
+    return true;
+}
+
+session_manager_iface *calf_plugins::create_lash_session_mgr(session_client_iface *_client, int &, char **&)
+{
+    return new new_lash_session_manager(client);
+}
+
+# endif
+
+#endif

-- 
calf audio plugins packaging



More information about the pkg-multimedia-commits mailing list