<commit_before>/*
 * Some functions become per-client (of pmcd) with the introduction
 * of PMDA_INTERFACE_5.
 *
 * Copyright (c) 2010 <NAME>.  All Rights Reserved.
 * 
 * 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.
 */

#include "pmapi.h"
#include "impl.h"
#include "pmda.h"
#include "percontext.h"

typedef struct {
    int		state;		/* active or inactive context */
    int		recv_pdu;	/* count of PDUs received from this context */
    int		xmit_pdu;	/* count of PDUs sent to this context */
} perctx_t;

/* values for state */
#define CTX_INACTIVE	0
#define CTX_ACTIVE	1

static perctx_t	*ctxtab = NULL;
static int	num_ctx = 0;
static int	num_start = 0;	/* count of new contexts noted */
static int	num_end = 0;	/* count of end context events */
static int	num_recv_pdu = 0;	/* recv count from closed contexts */
static int	num_xmit_pdu = 0;	/* xmit count from closed contexts */

void
sample_clr_recv(int ctx)
{
    if (ctx == CTX_ALL) {
	int	i;
	for (i = 0; i < num_ctx; i++) {
	    if (ctxtab[i].state == CTX_ACTIVE)
		ctxtab[i].recv_pdu = 0;
	}
	num_recv_pdu = 0;
    }
    else if (ctx < 0 || ctx >= num_ctx || ctxtab[ctx].state == CTX_INACTIVE) {
	fprintf(stderr, "Botch: sample_clr_recv(%d) num_ctx=%d", ctx, num_ctx);
	if (ctx >= 0 && ctx < num_ctx)
	    fprintf(stderr, " ctxtab[] is inactive");
	fputc('\n', stderr);
    }
    else
	ctxtab[ctx].recv_pdu = 0;
}

void
sample_clr_xmit(int ctx)
{
    if (ctx == CTX_ALL) {
	int	i;
	for (i = 0; i < num_ctx; i++) {
	    if (ctxtab[i].state == CTX_ACTIVE)
		ctxtab[i].xmit_pdu = 0;
	}
	num_xmit_pdu = 0;
    }
    else if (ctx < 0 || ctx >= num_ctx || ctxtab[ctx].state == CTX_INACTIVE) {
	fprintf(stderr, "Botch: sample_clr_recv(%d) num_ctx=%d", ctx, num_ctx);
	if (ctx >= 0 && ctx < num_ctx)
	    fprintf(stderr, " ctxtab[] is inactive");
	fputc('\n', stderr);
    }
    else
	ctxtab[ctx].xmit_pdu = 0;<commit_msg>Fix typo in sample pmda sample_clr_xmit routine diagnostic.<commit_after>/*
 * Some functions become per-client (of pmcd) with the introduction
 * of PMDA_INTERFACE_5.
 *
 * Copyright (c) 2010 <NAME>.  All Rights Reserved.
 * 
 * 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.
 */

#include "pmapi.h"
#include "impl.h"
#include "pmda.h"
#include "percontext.h"

typedef struct {
    int		state;		/* active or inactive context */
    int		recv_pdu;	/* count of PDUs received from this context */
    int		xmit_pdu;	/* count of PDUs sent to this context */
} perctx_t;

/* values for state */
#define CTX_INACTIVE	0
#define CTX_ACTIVE	1

static perctx_t	*ctxtab = NULL;
static int	num_ctx = 0;
static int	num_start = 0;	/* count of new contexts noted */
static int	num_end = 0;	/* count of end context events */
static int	num_recv_pdu = 0;	/* recv count from closed contexts */
static int	num_xmit_pdu = 0;	/* xmit count from closed contexts */

void
sample_clr_recv(int ctx)
{
    if (ctx == CTX_ALL) {
	int	i;
	for (i = 0; i < num_ctx; i++) {
	    if (ctxtab[i].state == CTX_ACTIVE)
		ctxtab[i].recv_pdu = 0;
	}
	num_recv_pdu = 0;
    }
    else if (ctx < 0 || ctx >= num_ctx || ctxtab[ctx].state == CTX_INACTIVE) {
	fprintf(stderr, "Botch: sample_clr_recv(%d) num_ctx=%d", ctx, num_ctx);
	if (ctx >= 0 && ctx < num_ctx)
	    fprintf(stderr, " ctxtab[] is inactive");
	fputc('\n', stderr);
    }
    else
	ctxtab[ctx].recv_pdu = 0;
}

void
sample_clr_xmit(int ctx)
{
    if (ctx == CTX_ALL) {
	int	i;
	for (i = 0; i < num_ctx; i++) {
	    if (ctxtab[i].state == CTX_ACTIVE)
		ctxtab[i].xmit_pdu = 0;
	}
	num_xmit_pdu = 0;
    }
    else if (ctx < 0 || ctx >= num_ctx || ctxtab[ctx].state == CTX_INACTIVE) {
	fprintf(stderr, "Botch: sample_clr_xmit(%d) num_ctx=%d", ctx, num_ctx);
	if (ctx >= 0 && ctx < num_ctx)
	    fprintf(stderr, " ctxtab[] is inactive");
	fputc('\n', stderr);
    }
    else
	ctxtab[ctx].xmit_pdu = 0;
{'fraction_non_alphanumeric': 0.1252125850340136, 'fraction_numerical': 0.010629251700680272, 'mean_word_length': 3.401309635173059, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, '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': '4420167', 'n_tokens_mistral': 1789, 'n_tokens_neox': 1745, 'n_words': 574}