<commit_before>/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * Copyright (C) 2009 Collabora Ltd.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Authors: <NAME> <<EMAIL>>
 */

#ifndef __TPL_DEBUG_H__
#define __TPL_DEBUG_H__

#include "config.h"

#include <string.h>

#include <glib.h>
#include <telepathy-glib/defs.h>

#ifdef ENABLE_DEBUG

G_BEGIN_DECLS

typedef enum
{
  TPL_DEBUG_ACTION_CHAIN  = 1 << 0,
  TPL_DEBUG_CONF          = 1 << 1,
  TPL_DEBUG_ENTITY        = 1 << 2,
  TPL_DEBUG_CHANNEL       = 1 << 3,
  TPL_DEBUG_DBUS_SERVICE  = 1 << 4,
  TPL_DEBUG_LOG_ENTRY     = 1 << 5,
  TPL_DEBUG_LOG_MANAGER   = 1 << 6,
  TPL_DEBUG_LOG_STORE     = 1 << 7,
  TPL_DEBUG_MAIN          = 1 << 8,
  TPL_DEBUG_OBSERVER      = 1 << 9
} TplDebugFlags;

void _tpl_debug_set_flags_from_env (void);
void _tpl_debug_set_flags (TplDebugFlags flags);
gboolean _tpl_debug_flag_is_set (TplDebugFlags flag);
void _tpl_debug_free (void);
void _tpl_debug (TplDebugFlags flag, const gchar *format, ...)
    G_GNUC_PRINTF (2, 3);
void _tpl_critical (TplDebugFlags flag, const gchar *format, ...)
    G_GNUC_PRINTF (2, 3);


G_END_DECLS

/* CRITICAL/PATH_CRITICAL needs to be always defined */
#define CRITICAL(format, ...) \
  _tpl_critical (DEBUG_FLAG, "%s: " format, G_STRFUNC, ##__VA_ARGS__)
#define PATH_CRITICAL(_proxy, _format, ...) \
G_STMT_START { \
  const gchar *_path; \
  g_assert (TP_IS_PROXY (_proxy)); \
  _path = tp_proxy_get_object_path (TP_PROXY (_proxy)); \
  if (TP_IS_CHANNEL (_proxy)) \
    _path += strlen (TP_CONN_OBJECT_PATH_BASE); \
  else if (TP_IS_ACCOUNT (_proxy)) \
    _path += strlen (TP_ACCOUNT_OBJECT_PATH_BASE); \
  CRITICAL (" %s: " _format, _path, ##__VA_ARGS__); \
} G_STMT_END

#ifdef DEBUG_FLAG

#define DEBUG(format, ...) \
  _tpl_debug (DEBUG_FLAG, "%s: " format, G_STRFUNC, ##__VA_ARGS__)

#define DEBUGGING gabble_debug_flag_is_set (DEBUG_FLAG)

/* The same of DEBUG, printing also the object-path property for the TpProxy,
 * passed as first arg. prepending '_' to avoid shadowing local variables */
#define PATH_DEBUG(_proxy, _format, ...) \
G_STMT_START { \
  const gchar *_path; \
  g_assert (TP_IS_PROXY (_proxy)); \
  _path = tp_proxy_get_object_path (TP_PROXY (_proxy)); \
  if (TP_IS_CHANNEL (_proxy)) \
    _path += strlen (TP_CONN_OBJECT_PATH_BASE); \
  else if (TP_IS_ACCOUNT (_proxy)) \
    _path += strlen (TP_ACCOUNT_OBJECT_PATH_BASE); \
  DEBUG (" %s: " _format, _path, ##__VA_ARGS__); \
} G_STMT_END

#endif /* DEBUG_FLAG */

#else /* ENABLE_DEBUG */

#ifdef DEBUG_FLAG<commit_msg>Fix the definition of DEBUGGING<commit_after>/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * Copyright (C) 2009 Collabora Ltd.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Authors: <NAME> <<EMAIL>>
 */

#ifndef __TPL_DEBUG_H__
#define __TPL_DEBUG_H__

#include "config.h"

#include <string.h>

#include <glib.h>
#include <telepathy-glib/defs.h>

#ifdef ENABLE_DEBUG

G_BEGIN_DECLS

typedef enum
{
  TPL_DEBUG_ACTION_CHAIN  = 1 << 0,
  TPL_DEBUG_CONF          = 1 << 1,
  TPL_DEBUG_ENTITY        = 1 << 2,
  TPL_DEBUG_CHANNEL       = 1 << 3,
  TPL_DEBUG_DBUS_SERVICE  = 1 << 4,
  TPL_DEBUG_LOG_ENTRY     = 1 << 5,
  TPL_DEBUG_LOG_MANAGER   = 1 << 6,
  TPL_DEBUG_LOG_STORE     = 1 << 7,
  TPL_DEBUG_MAIN          = 1 << 8,
  TPL_DEBUG_OBSERVER      = 1 << 9
} TplDebugFlags;

void _tpl_debug_set_flags_from_env (void);
void _tpl_debug_set_flags (TplDebugFlags flags);
gboolean _tpl_debug_flag_is_set (TplDebugFlags flag);
void _tpl_debug_free (void);
void _tpl_debug (TplDebugFlags flag, const gchar *format, ...)
    G_GNUC_PRINTF (2, 3);
void _tpl_critical (TplDebugFlags flag, const gchar *format, ...)
    G_GNUC_PRINTF (2, 3);


G_END_DECLS

/* CRITICAL/PATH_CRITICAL needs to be always defined */
#define CRITICAL(format, ...) \
  _tpl_critical (DEBUG_FLAG, "%s: " format, G_STRFUNC, ##__VA_ARGS__)
#define PATH_CRITICAL(_proxy, _format, ...) \
G_STMT_START { \
  const gchar *_path; \
  g_assert (TP_IS_PROXY (_proxy)); \
  _path = tp_proxy_get_object_path (TP_PROXY (_proxy)); \
  if (TP_IS_CHANNEL (_proxy)) \
    _path += strlen (TP_CONN_OBJECT_PATH_BASE); \
  else if (TP_IS_ACCOUNT (_proxy)) \
    _path += strlen (TP_ACCOUNT_OBJECT_PATH_BASE); \
  CRITICAL (" %s: " _format, _path, ##__VA_ARGS__); \
} G_STMT_END

#ifdef DEBUG_FLAG

#define DEBUG(format, ...) \
  _tpl_debug (DEBUG_FLAG, "%s: " format, G_STRFUNC, ##__VA_ARGS__)

#define DEBUGGING _tpl_debug_flag_is_set (DEBUG_FLAG)

/* The same of DEBUG, printing also the object-path property for the TpProxy,
 * passed as first arg. prepending '_' to avoid shadowing local variables */
#define PATH_DEBUG(_proxy, _format, ...) \
G_STMT_START { \
  const gchar *_path; \
  g_assert (TP_IS_PROXY (_proxy)); \
  _path = tp_proxy_get_object_path (TP_PROXY (_proxy)); \
  if (TP_IS_CHANNEL (_proxy)) \
    _path += strlen (TP_CONN_OBJECT_PATH_BASE); \
  else if (TP_IS_ACCOUNT (_proxy)) \
    _path += strlen (TP_ACCOUNT_OBJECT_PATH_BASE); \
  DEBUG (" %s: " _format, _path, ##__VA_ARGS__); \
} G_STMT_END

#endif /* DEBUG_FLAG */

#else /* ENABLE_DEBUG */

#ifdef DEBUG_FLAG
{'fraction_non_alphanumeric': 0.11312078479460454, 'fraction_numerical': 0.013182096873083998, 'mean_word_length': 3.829755736491488, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6324552', 'n_tokens_mistral': 2427, 'n_tokens_neox': 2361, 'n_words': 679}