LUMIERA.clone/src/common/interfaceregistry.c
Ichthyostega 806db414dd Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
 * there is no entity "Lumiera.org" which holds any copyrights
 * Lumiera source code is provided under the GPL Version 2+

== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''

The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!

The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00

267 lines
7.2 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
InterfaceRegistry - registry for extension points
Copyright (C)
2008, Christian Thaeter <ct@pipapo.org>
  **Lumiera** is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published by the
  Free Software Foundation; either version 2 of the License, or (at your
  option) any later version. See the file COPYING for further details.
* *****************************************************************/
/** @file interfaceregistry.c
** Interface instances are published and activated by registering them
** into a global registry, which is defined here. This instances are identified
** by their name and major version.
*/
#include "include/logging.h"
#include "lib/error.h"
#include "lib/psplay.h"
#include "lib/safeclib.h"
#include <nobug.h>
#include "common/plugin.h"
#include "common/interfaceregistry.h"
PSplay lumiera_interfaceregistry;
PSplay lumiera_pluginregistry;
lumiera_recmutex lumiera_interface_mutex;
static int
lumiera_interface_cmp_fn (const void* keya, const void* keyb);
static const void*
lumiera_interface_key_fn (const PSplaynode node);
static LumieraInterfacenode
lumiera_interfacenode_new (LumieraInterface iface, LumieraPlugin plugin)
{
LumieraInterfacenode self = lumiera_malloc (sizeof (*self));
psplaynode_init (&self->node);
self->interface = iface;
self->refcnt = 0;
self->plugin = plugin;
self->lnk = NULL;
self->deps_size = 0;
self->deps = NULL;
return self;
}
static void
lumiera_interfacenode_delete (LumieraInterfacenode self)
{
if (self)
{
REQUIRE (self->refcnt == 0);
lumiera_free (self->deps);
lumiera_free (self);
}
}
/** Initialise the interface registry */
void
lumiera_interfaceregistry_init (void)
{
TRACE (interfaceregistry_dbg);
REQUIRE (!lumiera_interfaceregistry);
REQUIRE (!lumiera_pluginregistry);
lumiera_interfaceregistry = psplay_new (lumiera_interface_cmp_fn, lumiera_interface_key_fn, NULL);
if (!lumiera_interfaceregistry)
LUMIERA_DIE (ERRNO);
lumiera_pluginregistry = psplay_new (lumiera_plugin_cmp_fn, lumiera_plugin_key_fn, lumiera_plugin_delete_fn);
if (!lumiera_pluginregistry)
LUMIERA_DIE (ERRNO);
lumiera_recmutex_init (&lumiera_interface_mutex, "interfaceregistry", &NOBUG_FLAG(interfaceregistry), NOBUG_CONTEXT);
lumiera_interface_init ();
}
void
lumiera_interfaceregistry_destroy (void)
{
TRACE (interfaceregistry_dbg);
lumiera_interface_destroy ();
if (lumiera_pluginregistry)
psplay_delete (lumiera_pluginregistry);
lumiera_pluginregistry = NULL;
lumiera_recmutex_destroy (&lumiera_interface_mutex, &NOBUG_FLAG(mutex_dbg), NOBUG_CONTEXT);
REQUIRE (!psplay_nelements (lumiera_interfaceregistry), "some interfaces still registered at shutdown");
if (lumiera_interfaceregistry)
psplay_destroy (lumiera_interfaceregistry);
lumiera_interfaceregistry = NULL;
}
void
lumiera_interfaceregistry_register_interface (LumieraInterface self, LumieraPlugin plugin)
{
TRACE (interfaceregistry_dbg);
REQUIRE (self);
LUMIERA_RECMUTEX_SECTION (mutex_sync, &lumiera_interface_mutex)
{
TRACE (interfaceregistry, "interface %s, version %d, instance %s", self->interface, self->version, self->name);
psplay_insert (lumiera_interfaceregistry, &lumiera_interfacenode_new (self, plugin)->node, 100);
}
}
void
lumiera_interfaceregistry_bulkregister_interfaces (LumieraInterface* self, LumieraPlugin plugin)
{
TRACE (interfaceregistry_dbg);
REQUIRE (self);
LUMIERA_RECMUTEX_SECTION (mutex_sync, &lumiera_interface_mutex)
{
while (*self)
{
TRACE (interfaceregistry, "interface %s, version %d, instance %s", (*self)->interface, (*self)->version, (*self)->name);
psplay_insert (lumiera_interfaceregistry, &lumiera_interfacenode_new (*self, plugin)->node, 100);
++self;
}
}
}
void
lumiera_interfaceregistry_remove_interface (LumieraInterface self)
{
TRACE (interfaceregistry_dbg);
REQUIRE (self);
LUMIERA_RECMUTEX_SECTION (mutex_sync, &lumiera_interface_mutex)
{
TRACE (interfaceregistry, "interface %s, version %d, instance %s", self->interface, self->version, self->name);
LumieraInterfacenode node = (LumieraInterfacenode) psplay_find (lumiera_interfaceregistry, self, 0);
REQUIRE (node->refcnt == 0, "but is %d", node->refcnt);
lumiera_interfacenode_delete ((LumieraInterfacenode)psplay_remove (lumiera_interfaceregistry, &node->node));
}
}
void
lumiera_interfaceregistry_bulkremove_interfaces (LumieraInterface* self)
{
TRACE (interfaceregistry_dbg);
REQUIRE (self);
LUMIERA_RECMUTEX_SECTION (mutex_sync, &lumiera_interface_mutex)
{
while (*self)
{
TRACE (interfaceregistry, "interface %s, version %d, instance %s", (*self)->interface, (*self)->version, (*self)->name);
LumieraInterfacenode node = (LumieraInterfacenode) psplay_find (lumiera_interfaceregistry, *self, 0);
if (node)
{
REQUIRE (node->refcnt == 0, "but is %d", node->refcnt);
lumiera_interfacenode_delete ((LumieraInterfacenode) psplay_remove (lumiera_interfaceregistry, &node->node));
}
else
{
///////////TICKET #864 : should not happen but does happen in practice, e.g. when there is a copy or another library linked against that module
/////////// Guess the pluginloader should not have added the duplicate into the interfaceregistry on discovery.
WARN (interfaceregistry, "ENTRY NOT FOUND in interfaceregistry at clean-up of interface %s, instance %s"
, (*self)->interface
, (*self)->name);
}
++self;
}
}
}
LumieraInterfacenode
lumiera_interfaceregistry_interfacenode_find (const char* interface, unsigned version, const char* name)
{
TRACE (interfaceregistry_dbg);
struct lumiera_interface_struct cmp;
cmp.interface = interface;
cmp.version = version;
cmp.name = name;
LumieraInterfacenode ret = NULL;
LUMIERA_RECMUTEX_SECTION (mutex_sync, &lumiera_interface_mutex)
{
ret = (LumieraInterfacenode)psplay_find (lumiera_interfaceregistry, &cmp, 100);
}
return ret;
}
LumieraInterface
lumiera_interfaceregistry_interface_find (const char* interface, unsigned version, const char* name)
{
return lumiera_interfaceregistry_interfacenode_find (interface, version, name)->interface;
}
static int
lumiera_interface_cmp_fn (const void* keya, const void* keyb)
{
const LumieraInterface a = (const LumieraInterface)keya;
const LumieraInterface b = (const LumieraInterface)keyb;
int r = strcmp (a->interface, b->interface);
if (r<0)
return -1;
else if (r>0)
return 1;
if (a->version < b->version)
return -1;
else if (a->version > b->version)
return 1;
r = strcmp (a->name, b->name);
if (r<0)
return -1;
else if (r>0)
return 1;
return 0;
}
static const void*
lumiera_interface_key_fn (const PSplaynode node)
{
return ((LumieraInterfacenode)node)->interface;
}
/*
// Local Variables:
// mode: C
// c-file-style: "gnu"
// indent-tabs-mode: nil
// End:
*/