2004-01-28 20:02:12 -05:00
|
|
|
/* Icecast
|
|
|
|
*
|
|
|
|
* This program is distributed under the GNU General Public License, version 2.
|
|
|
|
* A copy of this license is included with this source.
|
|
|
|
*
|
2015-01-10 13:53:44 -05:00
|
|
|
* Copyright 2000-2004, Jack Moffitt <jack@xiph.org,
|
2004-01-28 20:02:12 -05:00
|
|
|
* Michael Smith <msmith@xiph.org>,
|
|
|
|
* oddsock <oddsock@xiph.org>,
|
|
|
|
* Karl Heyes <karl@xiph.org>
|
|
|
|
* and others (see AUTHORS for details).
|
2022-03-01 06:17:28 -05:00
|
|
|
* Copyright 2015-2022, Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>,
|
2004-01-28 20:02:12 -05:00
|
|
|
*/
|
|
|
|
|
2003-03-27 12:10:14 -05:00
|
|
|
/* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- */
|
2003-07-20 21:58:54 -04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2003-03-09 06:27:06 -05:00
|
|
|
#include <string.h>
|
|
|
|
|
2022-03-14 15:53:37 -04:00
|
|
|
#include "icecasttypes.h"
|
|
|
|
#include <igloo/ro.h>
|
2023-01-29 16:40:06 -05:00
|
|
|
#include <igloo/uuid.h>
|
|
|
|
#include <igloo/sp.h>
|
|
|
|
#include <igloo/error.h>
|
2022-03-14 15:53:37 -04:00
|
|
|
|
2014-12-02 16:50:57 -05:00
|
|
|
#include "common/thread/thread.h"
|
|
|
|
#include "common/avl/avl.h"
|
2001-09-09 22:21:46 -04:00
|
|
|
|
|
|
|
#include "global.h"
|
2018-05-28 07:26:08 -04:00
|
|
|
#include "module.h"
|
2018-05-28 07:27:04 -04:00
|
|
|
#include "source.h"
|
2001-09-09 22:21:46 -04:00
|
|
|
|
|
|
|
ice_global_t global;
|
2022-02-26 08:55:21 -05:00
|
|
|
igloo_ro_t igloo_instance = igloo_RO_NULL;
|
2001-09-09 22:21:46 -04:00
|
|
|
|
|
|
|
static mutex_t _global_mutex;
|
|
|
|
|
2023-01-29 16:40:06 -05:00
|
|
|
static const char * _instance_uuid = NULL;
|
|
|
|
|
2001-09-09 22:21:46 -04:00
|
|
|
void global_initialize(void)
|
|
|
|
{
|
2022-04-15 08:19:42 -04:00
|
|
|
memset(&global, 0, sizeof(global));
|
|
|
|
global.sources_update = time(NULL);
|
2003-03-14 21:10:19 -05:00
|
|
|
global.source_tree = avl_tree_new(source_compare_sources, NULL);
|
2022-03-14 15:53:37 -04:00
|
|
|
igloo_ro_new(&global.modulecontainer, module_container_t, igloo_instance);
|
2003-03-14 21:10:19 -05:00
|
|
|
thread_mutex_create(&_global_mutex);
|
2001-09-09 22:21:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void global_shutdown(void)
|
|
|
|
{
|
2003-03-14 21:10:19 -05:00
|
|
|
thread_mutex_destroy(&_global_mutex);
|
2022-03-14 15:53:37 -04:00
|
|
|
igloo_ro_unref(&global.modulecontainer);
|
2004-02-19 15:28:21 -05:00
|
|
|
avl_tree_free(global.source_tree, NULL);
|
2023-01-29 16:40:06 -05:00
|
|
|
igloo_sp_unref(&_instance_uuid, igloo_instance);
|
2001-09-09 22:21:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void global_lock(void)
|
|
|
|
{
|
2003-03-14 21:10:19 -05:00
|
|
|
thread_mutex_lock(&_global_mutex);
|
2001-09-09 22:21:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void global_unlock(void)
|
|
|
|
{
|
2003-03-14 21:10:19 -05:00
|
|
|
thread_mutex_unlock(&_global_mutex);
|
2001-09-09 22:21:46 -04:00
|
|
|
}
|
2023-01-29 16:40:06 -05:00
|
|
|
|
|
|
|
const char * global_instance_uuid(void)
|
|
|
|
{
|
|
|
|
if (_instance_uuid)
|
|
|
|
return _instance_uuid;
|
|
|
|
|
|
|
|
if (igloo_uuid_new_random_sp(&_instance_uuid, igloo_instance) != igloo_ERROR_NONE) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return _instance_uuid;
|
|
|
|
}
|