<commit_before>/*****************************************************************************
 * messages.c: messages interface
 * This library provides an interface to the message queue to be used by other
 * modules, especially intf modules. See vlc_config.h for output configuration.
 *****************************************************************************
 * Copyright (C) 1998-2005 the VideoLAN team
 * $Id$
 *
 * Authors: <NAME> <<EMAIL>>
 *          <NAME> <<EMAIL>>
 *
 * This program 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.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <vlc_common.h>

#include <stdarg.h>                                       /* va_list for BSD */

#ifdef HAVE_FCNTL_H
#   include <fcntl.h>                  /* O_CREAT, O_TRUNC, O_WRONLY, O_SYNC */
#endif

#include <errno.h>                                                  /* errno */

#ifdef WIN32
#   include <vlc_network.h>          /* 'net_strerror' and 'WSAGetLastError' */
#endif

#ifdef HAVE_UNISTD_H
#   include <unistd.h>                                   /* close(), write() */
#endif

#include <assert.h>

#include <vlc_charset.h>
#include "../libvlc.h"

typedef struct
{
    int i_code;
    char * psz_message;
} msg_context_t;

static vlc_threadvar_t msg_context;
static uintptr_t banks = 0;

/*****************************************************************************
 * Local macros
 *****************************************************************************/
#if defined(HAVE_VA_COPY)
#   define vlc_va_copy(dest,src) va_copy(dest,src)
#elif defined(HAVE___VA_COPY)
#   define vlc_va_copy(dest,src) __va_copy(dest,src)
#else
#   define vlc_va_copy(dest,src) (dest)=(src)
#endif

#define QUEUE priv->msg_bank

/*****************************************************************************
 * Local prototypes
 *****************************************************************************/
static void QueueMsg ( vlc_object_t *, int, const char *,
                       const char *, va_list );
static void FlushMsg ( msg_bank_t * );
static void PrintMsg ( vlc_object_t *, msg_item_t * );

static vlc_mutex_t msg_stack_lock = VLC_STATIC_MUTEX;

/**
 * Initialize messages queues
 * This function initializes all message queues
 */
void msg_Create (libvlc_int_t *p_libvlc)
{
    libvlc_priv_t *priv = libvlc_priv (p_libvlc);
    vlc_mutex_init( &QUEUE.lock );
    vlc_dictionary_init( &priv->msg_enabled_objects, 0 );
    priv->msg_all_objects_enabled = true;

    QUEUE.b_overflow = false;
    QUEUE.i_start = 0;
    QUEUE.i_stop = 0;
    QUEUE.i_sub = 0;
    QUEUE.pp_sub = 0;

#ifdef UNDER_CE
    QUEUE.logfile =
        CreateFile( L"vlc-log.txt", GENERIC_WRITE,
                    FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
                    CREATE_ALWAYS, 0, NULL );
    SetFilePointer( QUEUE.logfile, 0, NULL, FILE_END );
#endif

    vlc_mutex_lock( &msg_stack_lock );
    if( banks++ == 0 )
        vlc_threadvar_create( &msg_context, NULL );
    vlc_mutex_unlock( &msg_stack_lock );
}

/**
 * Flush all message queues
 */
void msg_Flush (libvlc_int_t *p_libvlc)
{
    libvlc_priv_t *priv = libvlc_priv (p_libvlc);
    vlc_mutex_lock( &QUEUE.lock );
    FlushMsg( &QUEUE );
    vlc_mutex_unlock( &QUEUE.lock );
}


/**
 * Object Printing selection
 */
static void const * kObjectPrintingEnabled = (void *) 1;
static void const * kObjectPrintingDisabled = (void *) -1;

void __msg_EnableObjectPrinting (vlc_object_t *p_this, char * psz_object)
{
    libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
    vlc_mutex_lock( &QUEUE.lock );
    if( !strcmp(psz_object, "all") )
        priv->msg_all_objects_enabled = true;
    else<commit_msg>Invent unique pointer values properly<commit_after>/*****************************************************************************
 * messages.c: messages interface
 * This library provides an interface to the message queue to be used by other
 * modules, especially intf modules. See vlc_config.h for output configuration.
 *****************************************************************************
 * Copyright (C) 1998-2005 the VideoLAN team
 * $Id$
 *
 * Authors: <NAME> <<EMAIL>>
 *          <NAME> <<EMAIL>>
 *
 * This program 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.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <vlc_common.h>

#include <stdarg.h>                                       /* va_list for BSD */

#ifdef HAVE_FCNTL_H
#   include <fcntl.h>                  /* O_CREAT, O_TRUNC, O_WRONLY, O_SYNC */
#endif

#include <errno.h>                                                  /* errno */

#ifdef WIN32
#   include <vlc_network.h>          /* 'net_strerror' and 'WSAGetLastError' */
#endif

#ifdef HAVE_UNISTD_H
#   include <unistd.h>                                   /* close(), write() */
#endif

#include <assert.h>

#include <vlc_charset.h>
#include "../libvlc.h"

typedef struct
{
    int i_code;
    char * psz_message;
} msg_context_t;

static vlc_threadvar_t msg_context;
static uintptr_t banks = 0;

/*****************************************************************************
 * Local macros
 *****************************************************************************/
#if defined(HAVE_VA_COPY)
#   define vlc_va_copy(dest,src) va_copy(dest,src)
#elif defined(HAVE___VA_COPY)
#   define vlc_va_copy(dest,src) __va_copy(dest,src)
#else
#   define vlc_va_copy(dest,src) (dest)=(src)
#endif

#define QUEUE priv->msg_bank

/*****************************************************************************
 * Local prototypes
 *****************************************************************************/
static void QueueMsg ( vlc_object_t *, int, const char *,
                       const char *, va_list );
static void FlushMsg ( msg_bank_t * );
static void PrintMsg ( vlc_object_t *, msg_item_t * );

static vlc_mutex_t msg_stack_lock = VLC_STATIC_MUTEX;

/**
 * Initialize messages queues
 * This function initializes all message queues
 */
void msg_Create (libvlc_int_t *p_libvlc)
{
    libvlc_priv_t *priv = libvlc_priv (p_libvlc);
    vlc_mutex_init( &QUEUE.lock );
    vlc_dictionary_init( &priv->msg_enabled_objects, 0 );
    priv->msg_all_objects_enabled = true;

    QUEUE.b_overflow = false;
    QUEUE.i_start = 0;
    QUEUE.i_stop = 0;
    QUEUE.i_sub = 0;
    QUEUE.pp_sub = 0;

#ifdef UNDER_CE
    QUEUE.logfile =
        CreateFile( L"vlc-log.txt", GENERIC_WRITE,
                    FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
                    CREATE_ALWAYS, 0, NULL );
    SetFilePointer( QUEUE.logfile, 0, NULL, FILE_END );
#endif

    vlc_mutex_lock( &msg_stack_lock );
    if( banks++ == 0 )
        vlc_threadvar_create( &msg_context, NULL );
    vlc_mutex_unlock( &msg_stack_lock );
}

/**
 * Flush all message queues
 */
void msg_Flush (libvlc_int_t *p_libvlc)
{
    libvlc_priv_t *priv = libvlc_priv (p_libvlc);
    vlc_mutex_lock( &QUEUE.lock );
    FlushMsg( &QUEUE );
    vlc_mutex_unlock( &QUEUE.lock );
}


/**
 * Object Printing selection
 */
static void const * kObjectPrintingEnabled = &kObjectPrintingEnabled;
static void const * kObjectPrintingDisabled = &kObjectPrintingDisabled;

void __msg_EnableObjectPrinting (vlc_object_t *p_this, char * psz_object)
{
    libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
    vlc_mutex_lock( &QUEUE.lock );
    if( !strcmp(psz_object, "all") )
        priv->msg_all_objects_enabled = true;
    else
{'fraction_non_alphanumeric': 0.23675640468953538, 'fraction_numerical': 0.006947459834997829, 'mean_word_length': 3.783489096573209, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2315469', 'n_tokens_mistral': 2880, 'n_tokens_neox': 2686, 'n_words': 739}