[beast: 3/31] BSE: channel all object creations through bse_object_new_valist



commit 786b99fa265ddd7334ca22d20ea7d4fbe93d67bb
Author: Tim Janik <timj gnu org>
Date:   Fri Jun 12 01:14:09 2015 +0200

    BSE: channel all object creations through bse_object_new_valist

 HACKING.md           |    6 +++---
 bse/bseautodoc.cc    |    2 +-
 bse/bsecontainer.cc  |    4 ++--
 bse/bsedevice.cc     |    6 +++---
 bse/bseitem.cc       |    2 +-
 bse/bseladspa.cc     |    2 +-
 bse/bseobject.cc     |   24 ++++++++++++++++++++++++
 bse/bseobject.hh     |    2 ++
 bse/bseplugin.cc     |    6 +++---
 bse/bseproject.cc    |    4 ++--
 bse/bseproject.proc  |    2 +-
 bse/bseserver.cc     |    6 +++---
 bse/bsesource.cc     |    2 +-
 bse/bsewave.proc     |    2 +-
 bse/bsewaverepo.proc |    2 +-
 bse/tests/testcxx.cc |    2 +-
 16 files changed, 50 insertions(+), 24 deletions(-)
---
diff --git a/HACKING.md b/HACKING.md
index e79848f..5b69092 100644
--- a/HACKING.md
+++ b/HACKING.md
@@ -16,9 +16,9 @@ IDL-Migration
 
 CXX-Migration
 -------------
-**[PLANNED]** Move from GObject (BseObject) to AIDA C++11 objects, derived from Aida::ImplicitBase and 
specified in IDL files. The following steps are planned:
-* bse_object_new is used everywhere instead of g_object_new.
-* *bse_object_new* creates the BseObject/GObject and then the IDL based C++ object. Back pointers are 
installed to link the two together. That way features can be migrated incrementally from BseObject to 
CxxObject. The C++ objects auto-convert to their BseObject counter parts. This allows *base* object types to 
be replaced by CxxObjects quickly.
+**[STARTED]** Move from GObject (BseObject) to AIDA C++11 objects, derived from Aida::ImplicitBase and 
specified in IDL files. The following steps are planned:
+* bse_object_new_valist is used everywhere instead of g_object_new() and its variants.
+* *bse_object_new_valist* creates the BseObject/GObject and then the IDL based C++ object. Back pointers are 
installed to link the two together. That way features can be migrated incrementally from BseObject to 
CxxObject. The C++ objects auto-convert to their BseObject counter parts. This allows *base* object types to 
be replaced by CxxObjects quickly.
     * First, signals should be migrated, as signals are the the main tie to libgobject.so.
     * Second, once all signals are converted, all g_signal_ related code is eliminated from BSE and SFI, 
bse_proxy_connect will be removed.
     * Last, all g_object_ and g_type_ calls can be replaced.
diff --git a/bse/bseautodoc.cc b/bse/bseautodoc.cc
index 0ad9fb3..f554572 100644
--- a/bse/bseautodoc.cc
+++ b/bse/bseautodoc.cc
@@ -474,7 +474,7 @@ showdoc_print_type (GObjectClass *oclass,
       g_type_is_a (type, BSE_TYPE_SOURCE) &&
       !strequals ("BseServer", g_type_name (type)))
     {
-      BseSource *source = (BseSource*) g_object_new (type, NULL);
+      BseSource *source = (BseSource*) bse_object_new (type, NULL);
       for (j = 0; j < BSE_SOURCE_N_ICHANNELS (source); j++)
         {
           g_print ("  {\n");
diff --git a/bse/bsecontainer.cc b/bse/bsecontainer.cc
index cdcea6e..c5a3c50 100644
--- a/bse/bsecontainer.cc
+++ b/bse/bsecontainer.cc
@@ -292,7 +292,7 @@ bse_container_new_child_bname (BseContainer *container,
 
   g_object_set_data_full (G_OBJECT (container), "BseContainer-base-name", g_strdup (base_name), g_free);
   va_start (var_args, first_param_name);
-  child = g_object_new_valist (child_type, first_param_name, var_args);
+  child = bse_object_new_valist (child_type, first_param_name, var_args);
   va_end (var_args);
   if (base_name)
     g_object_set (child, "uname", NULL, NULL); /* no undo */
@@ -1238,7 +1238,7 @@ static void
 undo_remove_child (BseUndoStep  *ustep,
                    BseUndoStack *ustack)
 {
-  BseItem *child = (BseItem*) g_object_new (ustep->data[0].v_ulong,
+  BseItem *child = (BseItem*) bse_object_new (ustep->data[0].v_ulong,
                                             "uname", ustep->data[1].v_pointer,
                                             NULL);
   bse_container_add_item ((BseContainer*) bse_undo_pointer_unpack ((char*) ustep->data[2].v_pointer, 
ustack), child);
diff --git a/bse/bsedevice.cc b/bse/bsedevice.cc
index 5098962..6e310a5 100644
--- a/bse/bsedevice.cc
+++ b/bse/bsedevice.cc
@@ -213,7 +213,7 @@ device_class_list_entries (GType    type,
   BseDeviceClass *klass = (BseDeviceClass*) g_type_class_ref (type);
   if (BSE_DEVICE_CLASS (klass)->driver_name)
     {
-      BseDevice *device = (BseDevice*) g_object_new (type, NULL);
+      BseDevice *device = (BseDevice*) bse_object_new (type, NULL);
       if (request_callback)
         request_callback (device, data);
       ring = bse_device_list (device);
@@ -385,7 +385,7 @@ bse_device_open_auto (GType           base_type,
   for (ring = class_list; ring; ring = sfi_ring_walk (ring, class_list))
     {
       BseDeviceClass *klass = BSE_DEVICE_CLASS (ring->data);
-      device = (BseDevice*) g_object_new (G_OBJECT_CLASS_TYPE (klass), NULL);
+      device = (BseDevice*) bse_object_new (G_OBJECT_CLASS_TYPE (klass), NULL);
       if (request_callback)
         request_callback (device, data);
       BseErrorType error = bse_device_open (device, need_readable, need_writable, NULL);
@@ -450,7 +450,7 @@ bse_device_open_best (GType           base_type,
       if (node)
         {
           BseDeviceClass *klass = BSE_DEVICE_CLASS (node->data);
-          device = (BseDevice*) g_object_new (G_OBJECT_CLASS_TYPE (klass), NULL);
+          device = (BseDevice*) bse_object_new (G_OBJECT_CLASS_TYPE (klass), NULL);
           if (request_callback)
             request_callback (device, data);
           BseErrorType error = bse_device_open (device, need_readable, need_writable, args ? args + 1 : 
NULL);
diff --git a/bse/bseitem.cc b/bse/bseitem.cc
index 5cb26a5..1c58d54 100644
--- a/bse/bseitem.cc
+++ b/bse/bseitem.cc
@@ -1228,7 +1228,7 @@ bse_item_backup_to_undo (BseItem      *self,
 {
   if (!BSE_UNDO_STACK_VOID (ustack))
     {
-      BseStorage *storage = (BseStorage*) g_object_new (BSE_TYPE_STORAGE, NULL);
+      BseStorage *storage = (BseStorage*) bse_object_new (BSE_TYPE_STORAGE, NULL);
       bse_storage_prepare_write (storage, BseStorageMode (BSE_STORAGE_DBLOCK_CONTAINED |
                                                           BSE_STORAGE_SELF_CONTAINED));
       bse_storage_store_item (storage, self);
diff --git a/bse/bseladspa.cc b/bse/bseladspa.cc
index a2552df..b410b94 100644
--- a/bse/bseladspa.cc
+++ b/bse/bseladspa.cc
@@ -616,7 +616,7 @@ bse_ladspa_plugin_check_load (const gchar *file_name)
     }
 
   /* create plugin and register types */
-  self = (BseLadspaPlugin*) g_object_new (BSE_TYPE_LADSPA_PLUGIN, NULL);
+  self = (BseLadspaPlugin*) bse_object_new (BSE_TYPE_LADSPA_PLUGIN, NULL);
   self->fname = g_strdup (file_name);
   self->gmodule = gmodule;
   error = ladspa_plugin_init_type_ids (self, ldf);
diff --git a/bse/bseobject.cc b/bse/bseobject.cc
index 274fbe1..6fdc414 100644
--- a/bse/bseobject.cc
+++ b/bse/bseobject.cc
@@ -120,9 +120,12 @@ object_unames_ht_insert (BseObject *object)
   g_hash_table_insert (object_unames_ht, BSE_OBJECT_UNAME (object_slist->data), object_slist);
 }
 
+static __thread uint in_bse_object_new = 0;
+
 static void
 bse_object_init (BseObject *object)
 {
+  assert (in_bse_object_new);
   object->flags = 0;
   object->lock_count = 0;
   object->unique_id = bse_id_alloc ();
@@ -856,3 +859,24 @@ BSE_BUILTIN_TYPE (BseObject)
                                      __FILE__, __LINE__,
                                      &object_info);
 }
+
+// == BseObject -> C++ class Glue ==
+GObject*
+bse_object_new (GType object_type, const gchar *first_property_name, ...)
+{
+  g_return_val_if_fail (G_TYPE_IS_OBJECT (object_type), NULL);
+  va_list var_args;
+  va_start (var_args, first_property_name);
+  GObject *object = bse_object_new_valist (object_type, first_property_name, var_args);
+  va_end (var_args);
+  return object;
+}
+
+GObject*
+bse_object_new_valist (GType object_type, const gchar *first_property_name, va_list var_args)
+{
+  in_bse_object_new++;
+  GObject *object = g_object_new_valist (object_type, first_property_name, var_args);
+  in_bse_object_new--;
+  return object;
+}
diff --git a/bse/bseobject.hh b/bse/bseobject.hh
index 9aa0913..80c79d2 100644
--- a/bse/bseobject.hh
+++ b/bse/bseobject.hh
@@ -92,6 +92,8 @@ guint bse_object_class_add_dsignal            (BseObjectClass *oclass,
 
 
 /* --- object API --- */
+GObject*        bse_object_new                  (GType object_type, const gchar *first_property_name, ...);
+GObject*        bse_object_new_valist           (GType object_type, const gchar *first_property_name, 
va_list var_args);
 void           bse_object_lock                 (gpointer        object);
 void           bse_object_unlock               (gpointer        object);
 gboolean        bse_object_editable_property   (gpointer        object,
diff --git a/bse/bseplugin.cc b/bse/bseplugin.cc
index 7166ecf..dedc4e5 100644
--- a/bse/bseplugin.cc
+++ b/bse/bseplugin.cc
@@ -137,7 +137,7 @@ bse_plugin_init_builtins (void)
           if (chain)
             {
               /* create resident plugin struct */
-              BsePlugin *plugin = (BsePlugin*) g_object_new (BSE_TYPE_PLUGIN, NULL);
+              BsePlugin *plugin = (BsePlugin*) bse_object_new (BSE_TYPE_PLUGIN, NULL);
               g_object_ref (plugin);
               plugin->use_count = 1;
               plugin->fname = g_strdup ("BSE-BUILTIN");
@@ -150,7 +150,7 @@ bse_plugin_init_builtins (void)
       if (bse_builtin_export_identity.export_chain)
         {
           /* create resident plugin struct */
-          BsePlugin *plugin = (BsePlugin*) g_object_new (BSE_TYPE_PLUGIN, NULL);
+          BsePlugin *plugin = (BsePlugin*) bse_object_new (BSE_TYPE_PLUGIN, NULL);
           g_object_ref (plugin);
           plugin->use_count = 1;
           plugin->fname = g_strdup ("BSE-CXX-BUILTIN");
@@ -628,7 +628,7 @@ bse_plugin_check_load (const gchar *const_file_name)
     file_name = g_strdup (const_file_name);
   PDEBUG ("register: %s", file_name);
   /* load module */
-  BsePlugin *plugin = (BsePlugin*) g_object_new (BSE_TYPE_PLUGIN, NULL);
+  BsePlugin *plugin = (BsePlugin*) bse_object_new (BSE_TYPE_PLUGIN, NULL);
   plugin->fname = g_strdup (file_name);
   startup_plugin = plugin;
   gmodule = g_module_open (file_name, G_MODULE_BIND_LAZY);
diff --git a/bse/bseproject.cc b/bse/bseproject.cc
index e278a35..08193fc 100644
--- a/bse/bseproject.cc
+++ b/bse/bseproject.cc
@@ -510,7 +510,7 @@ bse_project_store_bse (BseProject  *self,
   if (fd < 0)
     return bse_error_from_errno (errno, BSE_ERROR_FILE_OPEN_FAILED);
 
-  storage = (BseStorage*) g_object_new (BSE_TYPE_STORAGE, NULL);
+  storage = (BseStorage*) bse_object_new (BSE_TYPE_STORAGE, NULL);
   flags = 0;
   if (self_contained)
     flags |= BSE_STORAGE_SELF_CONTAINED;
@@ -677,7 +677,7 @@ bse_project_create_intern_synth (BseProject  *self,
   bse_synth = bse_standard_synth_inflate (synth_name, NULL);
   if (bse_synth)
     {
-      BseStorage *storage = (BseStorage*) g_object_new (BSE_TYPE_STORAGE, NULL);
+      BseStorage *storage = (BseStorage*) bse_object_new (BSE_TYPE_STORAGE, NULL);
       BseErrorType error = BSE_ERROR_NONE;
       StorageTrap strap = { 0, TRUE, }, *old_strap = (StorageTrap*) g_object_get_qdata ((GObject*) self, 
quark_storage_trap);
       bse_storage_input_text (storage, bse_synth, "<builtin-lib>");
diff --git a/bse/bseproject.proc b/bse/bseproject.proc
index ff4a8d5..3177e0a 100644
--- a/bse/bseproject.proc
+++ b/bse/bseproject.proc
@@ -165,7 +165,7 @@ METHOD (BseProject, restore-from-file, "File/Restore") {
   /* action */
   if (!project->in_undo && !project->in_redo)
     {
-      BseStorage *storage = (BseStorage*) g_object_new (BSE_TYPE_STORAGE, NULL);
+      BseStorage *storage = (BseStorage*) bse_object_new (BSE_TYPE_STORAGE, NULL);
       error = bse_storage_input_file (storage, file_name);
       if (!error)
         error = bse_project_restore (project, storage);
diff --git a/bse/bseserver.cc b/bse/bseserver.cc
index 2552078..4590f10 100644
--- a/bse/bseserver.cc
+++ b/bse/bseserver.cc
@@ -350,7 +350,7 @@ bse_server_get (void)
 
   if (!server)
     {
-      server = (BseServer*) g_object_new (BSE_TYPE_SERVER, NULL);
+      server = (BseServer*) bse_object_new (BSE_TYPE_SERVER, NULL);
       g_object_ref (server);
     }
 
@@ -374,7 +374,7 @@ bse_server_create_project (BseServer   *server,
   g_return_val_if_fail (name != NULL, NULL);
   g_return_val_if_fail (bse_server_find_project (server, name) == NULL, NULL);
 
-  project = (BseProject*) g_object_new (BSE_TYPE_PROJECT, "uname", name, NULL);
+  project = (BseProject*) bse_object_new (BSE_TYPE_PROJECT, "uname", name, NULL);
   server->projects = g_list_prepend (server->projects, project);
   g_object_connect (project,
                    "signal::release", destroy_project, server,
@@ -576,7 +576,7 @@ bse_server_open_devices (BseServer *self)
       if (self->wave_file)
        {
          BseErrorType error;
-         self->pcm_writer = (BsePcmWriter*) g_object_new (BSE_TYPE_PCM_WRITER, NULL);
+         self->pcm_writer = (BsePcmWriter*) bse_object_new (BSE_TYPE_PCM_WRITER, NULL);
           const uint n_channels = 2;
          error = bse_pcm_writer_open (self->pcm_writer, self->wave_file,
                                        n_channels, bse_engine_sample_freq (),
diff --git a/bse/bsesource.cc b/bse/bsesource.cc
index 8347571..a269947 100644
--- a/bse/bsesource.cc
+++ b/bse/bsesource.cc
@@ -1757,7 +1757,7 @@ bse_source_input_backup_to_undo (BseSource      *source,
 
   ustack = bse_item_undo_open (source, "unset-input %s", bse_object_debug_name (source));
 
-  storage = (BseStorage*) g_object_new (BSE_TYPE_STORAGE, NULL);
+  storage = (BseStorage*) bse_object_new (BSE_TYPE_STORAGE, NULL);
   bse_storage_prepare_write (storage, BSE_STORAGE_DBLOCK_CONTAINED);
 
   bse_storage_break (storage);
diff --git a/bse/bsewave.proc b/bse/bsewave.proc
index 11f37aa..de596a4 100644
--- a/bse/bsewave.proc
+++ b/bse/bsewave.proc
@@ -93,7 +93,7 @@ BODY (BseProcedureClass *proc,
   wchunk = (GslWaveChunk*) sfi_ring_nth_data (wave->wave_chunks, chunk_index);
   if (wchunk)
     {
-      esample = (BseEditableSample*) g_object_new (BSE_TYPE_EDITABLE_SAMPLE, NULL);
+      esample = (BseEditableSample*) bse_object_new (BSE_TYPE_EDITABLE_SAMPLE, NULL);
       bse_editable_sample_set_wchunk (esample, wchunk);
       bse_item_use (BSE_ITEM (esample));
       g_object_unref (esample);
diff --git a/bse/bsewaverepo.proc b/bse/bsewaverepo.proc
index a6a05c8..607ceed 100644
--- a/bse/bsewaverepo.proc
+++ b/bse/bsewaverepo.proc
@@ -19,7 +19,7 @@ load_file (BseWaveRepo *wrepo,
            BseWave    **wave_p)
 {
   gchar *fname = g_path_get_basename (file_name);
-  BseWave *wave = (BseWave*) g_object_new (BSE_TYPE_WAVE, "uname", fname, NULL);
+  BseWave *wave = (BseWave*) bse_object_new (BSE_TYPE_WAVE, "uname", fname, NULL);
   g_free (fname);
   BseErrorType error = bse_wave_load_wave_file (wave, file_name, NULL, NULL, NULL, TRUE);
   if (wave->n_wchunks)
diff --git a/bse/tests/testcxx.cc b/bse/tests/testcxx.cc
index 875f8d1..0bcdf5b 100644
--- a/bse/tests/testcxx.cc
+++ b/bse/tests/testcxx.cc
@@ -50,7 +50,7 @@ main (int   argc,
   errorarg.token();
 #endif
 
-  GObject *o = (GObject*) g_object_new (BSE_TYPE_BUS_MODULE, NULL);
+  GObject *o = (GObject*) bse_object_new (BSE_TYPE_BUS_MODULE, NULL);
   CxxBase *b = cast (o);
   Foo f;
   b->connect ("notify", Closure (&f, &Foo::bar));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]