<commit_before>/**
 * @brief Load null driver - static version
 *
 * @file tmnull_switch.c
 */
/* -----------------------------------------------------------------------------
 * Enduro/X Middleware Platform for Distributed Transaction Processing
 * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
 * Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved.
 * This software is released under one of the following licenses:
 * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
 * See LICENSE file for full text.
 * -----------------------------------------------------------------------------
 * AGPL license:
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License, version 3 as published
 * by the Free Software Foundation;
 *
 * 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 Affero General Public License, version 3
 * for more details.
 *
 * You should have received a copy of the GNU Affero General Public License along 
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * -----------------------------------------------------------------------------
 * A commercial use license is available from Mavimax, Ltd
 * <EMAIL>
 * -----------------------------------------------------------------------------
 */
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#include <ndrstandard.h>
#include <ndebug.h>
#include <atmi.h>
#include <tmenv.h>

#include <xa.h>

#include "atmi_tls.h"
/*---------------------------Externs------------------------------------*/
/*---------------------------Macros-------------------------------------*/
/*---------------------------Enums--------------------------------------*/
/*---------------------------Typedefs-----------------------------------*/
/*---------------------------Globals------------------------------------*/
/*---------------------------Statics------------------------------------*/
exprivate MUTEX_LOCKDECL(M_init);
/*---------------------------Prototypes---------------------------------*/


expublic int ndrx_nul_xa_open_entry_stat(char *xa_info, int rmid, long flags);
expublic int ndrx_nul_xa_close_entry_stat(char *xa_info, int rmid, long flags);
expublic int ndrx_nul_xa_start_entry_stat(XID *xid, int rmid, long flags);
expublic int ndrx_nul_xa_end_entry_stat(XID *xid, int rmid, long flags);
expublic int ndrx_nul_xa_rollback_entry_stat(XID *xid, int rmid, long flags);
expublic int ndrx_nul_xa_prepare_entry_stat(XID *xid, int rmid, long flags);
expublic int ndrx_nul_xa_commit_entry_stat(XID *xid, int rmid, long flags);
expublic int ndrx_nul_xa_recover_entry_stat(XID *xid, long count, int rmid, long flags);
expublic int ndrx_nul_xa_forget_entry_stat(XID *xid, int rmid, long flags);
expublic int ndrx_nul_xa_complete_entry_stat(int *handle, int *retval, int rmid, long flags);

expublic int ndrx_nul_xa_open_entry(struct xa_switch_t *sw, char *xa_info, int rmid, long flags);
expublic int ndrx_nul_xa_close_entry(struct xa_switch_t *sw, char *xa_info, int rmid, long flags);
expublic int ndrx_nul_xa_start_entry(struct xa_switch_t *sw, XID *xid, int rmid, long flags);
expublic int ndrx_nul_xa_end_entry(struct xa_switch_t *sw, XID *xid, int rmid, long flags);
expublic int ndrx_nul_xa_rollback_entry(struct xa_switch_t *sw, XID *xid, int rmid, long flags);
expublic int ndrx_nul_xa_prepare_entry(struct xa_switch_t *sw, XID *xid, int rmid, long flags);
expublic int ndrx_nul_xa_commit_entry(struct xa_switch_t *sw, XID *xid, int rmid, long flags);
expublic int ndrx_nul_xa_recover_entry(struct xa_switch_t *sw, XID *xid, long count, int rmid, long flags);
expublic int ndrx_nul_xa_forget_entry(struct xa_switch_t *sw, XID *xid, int rmid, long flags);
expublic int ndrx_nul_xa_complete_entry(struct xa_switch_t *sw, int *handle, int *retval, int rmid, long flags);

struct xa_switch_t tmnull_switch = 
{ 
    .name = "tmnull_switch",
    .flags = TMNOFLAGS,
    .version = 0,
    .xa_open_entry = ndrx_nul_xa_open_entry_stat,
    .xa_close_entry = ndrx_nul_xa_close_entry_stat,
    .xa_start_entry = ndrx_nul_xa_start_entry_stat,
    .xa_end_entry = ndrx_nul_xa_end_entry_stat,
    .xa_rollback_entry = ndrx_nul_xa_rollback_entry_stat,
    .xa_prepare_entry = ndrx_nul_xa_prepare_entry_stat,
    .xa_commit_entry = ndrx_nul_xa_commit_entry_stat,
    .xa_recover_entry = ndrx_nul_xa_recover_entry_stat,
    .xa_forget_entry = ndrx_nul_xa_forget_entry_stat,
    .xa_complete_entry = ndrx_nul_xa_complete_entry_stat
};

/**
 * Open API
 * @param sw
 * @param xa_info
 * @param rmid
 * @param flags
 * @return 
 */
expublic int ndrx_nul_xa_open_entry(struct xa_switch_t *sw, char *xa_info, int rmid, long flags)
{
    static int first = EXTRUE;
    
    /* mark that suspend no required by this resource... */
    if (first)
    {
        MUTEX_LOCK_V(M_init);
        if (first)
        {
            ndrx_xa_nosuspend(EXTRUE);
            first=EXFALSE;
        }
        MUTEX_UNLOCK_V(M_init);
    }
    
    if (G_atmi_tls->tmnull_is_open)
    {
        NDRX_LOG(log_error, "xa_open_entry() - already open!");
        return XAER_RMERR;
    }
    
    G_atmi_tls->tmnull_is_open = EXTRUE;
    G_atmi_tls->tmnull_rmid = rmid;
             
    return XA_OK;
}
/**
 * Close entry
 * @param sw
 * @param xa_info
 * @param rmid
 * @param flags
 * @return 
 */
expublic int ndrx_nul_xa_close_entry(struct xa_switch_t *sw, char *xa_info, int rmid, long flags)
{
    NDRX_LOG(log_error, "xa_close_entry() called");
    
    G_atmi_tls->tmnull_is_open = EXFALSE;
    return XA_OK;
}

/**
 * Open text file in RMID folder. Create file by TXID.
 * Check for file existance. If start & not exists - ok .
 * If exists and join - ok. Otherwise fail.
 * @param xa_info
 * @param rmid
 * @param flags
 * @return 
 */
expublic int ndrx_nul_xa_start_entry(struct xa_switch_t *sw, XID *xid, int rmid, long flags)
{
    if (!G_atmi_tls->tmnull_is_open)
    {
        NDRX_LOG(log_error, "xa_start_entry() - XA not open!");
        return XAER_RMERR;
    }
    
    return XA_OK;
}

/**
 * Terminate XA access
 * @param sw
 * @param xid
 * @param rmid<commit_msg>Fixes on log levels<commit_after>/**
 * @brief Load null driver - static version
 *
 * @file tmnull_switch.c
 */
/* -----------------------------------------------------------------------------
 * Enduro/X Middleware Platform for Distributed Transaction Processing
 * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
 * Copyright (C) 2017-2019, Mavimax, Ltd. All Rights Reserved.
 * This software is released under one of the following licenses:
 * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
 * See LICENSE file for full text.
 * -----------------------------------------------------------------------------
 * AGPL license:
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License, version 3 as published
 * by the Free Software Foundation;
 *
 * 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 Affero General Public License, version 3
 * for more details.
 *
 * You should have received a copy of the GNU Affero General Public License along 
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * -----------------------------------------------------------------------------
 * A commercial use license is available from Mavimax, Ltd
 * <EMAIL>
 * -----------------------------------------------------------------------------
 */
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#include <ndrstandard.h>
#include <ndebug.h>
#include <atmi.h>
#include <tmenv.h>

#include <xa.h>

#include "atmi_tls.h"
/*---------------------------Externs------------------------------------*/
/*---------------------------Macros-------------------------------------*/
/*---------------------------Enums--------------------------------------*/
/*---------------------------Typedefs-----------------------------------*/
/*---------------------------Globals------------------------------------*/
/*---------------------------Statics------------------------------------*/
exprivate MUTEX_LOCKDECL(M_init);
/*---------------------------Prototypes---------------------------------*/


expublic int ndrx_nul_xa_open_entry_stat(char *xa_info, int rmid, long flags);
expublic int ndrx_nul_xa_close_entry_stat(char *xa_info, int rmid, long flags);
expublic int ndrx_nul_xa_start_entry_stat(XID *xid, int rmid, long flags);
expublic int ndrx_nul_xa_end_entry_stat(XID *xid, int rmid, long flags);
expublic int ndrx_nul_xa_rollback_entry_stat(XID *xid, int rmid, long flags);
expublic int ndrx_nul_xa_prepare_entry_stat(XID *xid, int rmid, long flags);
expublic int ndrx_nul_xa_commit_entry_stat(XID *xid, int rmid, long flags);
expublic int ndrx_nul_xa_recover_entry_stat(XID *xid, long count, int rmid, long flags);
expublic int ndrx_nul_xa_forget_entry_stat(XID *xid, int rmid, long flags);
expublic int ndrx_nul_xa_complete_entry_stat(int *handle, int *retval, int rmid, long flags);

expublic int ndrx_nul_xa_open_entry(struct xa_switch_t *sw, char *xa_info, int rmid, long flags);
expublic int ndrx_nul_xa_close_entry(struct xa_switch_t *sw, char *xa_info, int rmid, long flags);
expublic int ndrx_nul_xa_start_entry(struct xa_switch_t *sw, XID *xid, int rmid, long flags);
expublic int ndrx_nul_xa_end_entry(struct xa_switch_t *sw, XID *xid, int rmid, long flags);
expublic int ndrx_nul_xa_rollback_entry(struct xa_switch_t *sw, XID *xid, int rmid, long flags);
expublic int ndrx_nul_xa_prepare_entry(struct xa_switch_t *sw, XID *xid, int rmid, long flags);
expublic int ndrx_nul_xa_commit_entry(struct xa_switch_t *sw, XID *xid, int rmid, long flags);
expublic int ndrx_nul_xa_recover_entry(struct xa_switch_t *sw, XID *xid, long count, int rmid, long flags);
expublic int ndrx_nul_xa_forget_entry(struct xa_switch_t *sw, XID *xid, int rmid, long flags);
expublic int ndrx_nul_xa_complete_entry(struct xa_switch_t *sw, int *handle, int *retval, int rmid, long flags);

struct xa_switch_t tmnull_switch = 
{ 
    .name = "tmnull_switch",
    .flags = TMNOFLAGS,
    .version = 0,
    .xa_open_entry = ndrx_nul_xa_open_entry_stat,
    .xa_close_entry = ndrx_nul_xa_close_entry_stat,
    .xa_start_entry = ndrx_nul_xa_start_entry_stat,
    .xa_end_entry = ndrx_nul_xa_end_entry_stat,
    .xa_rollback_entry = ndrx_nul_xa_rollback_entry_stat,
    .xa_prepare_entry = ndrx_nul_xa_prepare_entry_stat,
    .xa_commit_entry = ndrx_nul_xa_commit_entry_stat,
    .xa_recover_entry = ndrx_nul_xa_recover_entry_stat,
    .xa_forget_entry = ndrx_nul_xa_forget_entry_stat,
    .xa_complete_entry = ndrx_nul_xa_complete_entry_stat
};

/**
 * Open API
 * @param sw
 * @param xa_info
 * @param rmid
 * @param flags
 * @return 
 */
expublic int ndrx_nul_xa_open_entry(struct xa_switch_t *sw, char *xa_info, int rmid, long flags)
{
    static int first = EXTRUE;
    
    /* mark that suspend no required by this resource... */
    if (first)
    {
        MUTEX_LOCK_V(M_init);
        if (first)
        {
            ndrx_xa_nosuspend(EXTRUE);
            first=EXFALSE;
        }
        MUTEX_UNLOCK_V(M_init);
    }
    
    if (G_atmi_tls->tmnull_is_open)
    {
        NDRX_LOG(log_error, "xa_open_entry() - already open!");
        return XAER_RMERR;
    }
    
    G_atmi_tls->tmnull_is_open = EXTRUE;
    G_atmi_tls->tmnull_rmid = rmid;
             
    return XA_OK;
}
/**
 * Close entry
 * @param sw
 * @param xa_info
 * @param rmid
 * @param flags
 * @return 
 */
expublic int ndrx_nul_xa_close_entry(struct xa_switch_t *sw, char *xa_info, int rmid, long flags)
{
    NDRX_LOG(log_info, "xa_close_entry() called");
    
    G_atmi_tls->tmnull_is_open = EXFALSE;
    return XA_OK;
}

/**
 * Open text file in RMID folder. Create file by TXID.
 * Check for file existance. If start & not exists - ok .
 * If exists and join - ok. Otherwise fail.
 * @param xa_info
 * @param rmid
 * @param flags
 * @return 
 */
expublic int ndrx_nul_xa_start_entry(struct xa_switch_t *sw, XID *xid, int rmid, long flags)
{
    if (!G_atmi_tls->tmnull_is_open)
    {
        NDRX_LOG(log_error, "xa_start_entry() - XA not open!");
        return XAER_RMERR;
    }
    
    return XA_OK;
}

/**
 * Terminate XA access
 * @param sw
 * @param xid
 * @param rmid
{'fraction_non_alphanumeric': 0.19938914558696844, 'fraction_numerical': 0.005168768110267053, 'mean_word_length': 2.4401939655172415, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 31, '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': '7355819', 'n_tokens_mistral': 4301, 'n_tokens_neox': 4288, 'n_words': 1168}