<commit_before>/* Copyright (c) 2001, Stanford University
 * All rights reserved
 *
 * See the file LICENSE.txt for information on redistributing this software.
 */

#include "binaryswapspu.h"
#include "cr_mothership.h"
#include "cr_string.h"
#include "cr_mem.h"
#include <string.h>
#include <math.h>

static void set_peers( void *foo, const char *response )
{
	char *nodes;
	char *token;
	int i;
	
	/* figure out peer information! */
	/* grab network configuration */
	/* get count of things first so we can allocate space */
	int count = 0;
	nodes = crStrdup(response);
	if((token = strtok(nodes, ",\n\t\0 ")) != NULL){
		count = 1;
		while((token = strtok(NULL, ",\n\t\0 ")) != NULL){
			count++;
		}
	}
	else{
		crError("Bad mojo: I can't figure out how many peers you have!");
	}
	crFree(nodes);
	
	/* actually store the network peer list */
	nodes = crStrdup(response);
	binaryswap_spu.peer_names = crAlloc(count*sizeof(char*));
	if((token = strtok(nodes, ",\n\t ")) != NULL){
		i = 0;
		binaryswap_spu.peer_names[i++] = crStrdup(token);
		while((token = strtok(NULL, ",\n\t ")) != NULL){
			binaryswap_spu.peer_names[i++] = crStrdup(token);
		}
	}
	crFree(nodes);
	
	/* figure out how many stages we have */
	binaryswap_spu.stages = (int)(log(count)/log(2)+0.1);
	crDebug("Swapping Stages: %d", binaryswap_spu.stages);
}


static void set_node( void *spu, const char *response )
{
	(void) spu;
	if (*response) {
		binaryswap_spu.node_num = crStrToInt( response );
	}
	else {
		crError( "No node number specified for the binaryswap SPU?" );
	}
}

static void set_swapmtu( void *spu, const char *response )
{
	(void) spu;
	if (*response) {
		binaryswap_spu.mtu = crStrToInt( response );
	}
	else { 
		binaryswap_spu.mtu = -1;
		crWarning("No swap MTU specified, using default from mothership" );
	}
}

static void set_type( void *spu, const char *response )
{
	(void) spu;
	if(crStrcmp( response, "alpha") == 0){
		binaryswap_spu.alpha_composite = 1;
		binaryswap_spu.depth_composite = 0;
	}
	else if(crStrcmp( response, "depth") == 0){
		binaryswap_spu.depth_composite = 1;
		binaryswap_spu.alpha_composite = 0;
	}
	else{
		crError( "Bad composite type specified for the binaryswap SPU?" );
	}
}

static void set_local_visualization( Binaryswapspu *binaryswap_spu, const char *response )
{
	binaryswap_spu->local_visualization = crStrToInt( response );
}

static void __setDefaults( Binaryswapspu *binaryswap_spu )
{
	/* misc */
	binaryswap_spu->barrierSize = 0;
	binaryswap_spu->bbox = NULL;
	
	/* config options */
	binaryswap_spu->resizable = 0;
	binaryswap_spu->local_visualization = 0;
}


/* option, type, nr, default, min, max, title, callback
 */
SPUOptions binaryswapspuOptions[] = {
	
	{ "peers", CR_STRING, 1, "", NULL, NULL, 
	  "Peers", (SPUOptionCB)set_peers},
	
	{ "node_number", CR_STRING, 1, "", NULL, NULL, 
	  "Node Number", (SPUOptionCB)set_node},
	
	{ "local_visualization", CR_BOOL, 1, "1", NULL, NULL,
	  "Local Visualization", (SPUOptionCB)set_local_visualization },
	
	{ "type", CR_ENUM, 1, "depth", "'depth', 'alpha'", NULL, 
	  "Composite type",  (SPUOptionCB)set_type},
	
	{ "swapmtu", CR_INT, 1, "-1", "1024", NULL, 
	  "MTU size for swapping", (SPUOptionCB)set_swapmtu},
	
	{ NULL, CR_BOOL, 0, NULL, NULL, NULL, NULL, NULL },
};


void binaryswapspuGatherConfiguration( Binaryswapspu *binaryswap_spu )
{
	CRConnection *conn;
	int i;
	
	__setDefaults( binaryswap_spu );
	
	/* Connect to the mothership and identify ourselves. */
	
	conn = crMothershipConnect( );<commit_msg>node_number should be an int NOT a string.<commit_after>/* Copyright (c) 2001, Stanford University
 * All rights reserved
 *
 * See the file LICENSE.txt for information on redistributing this software.
 */

#include "binaryswapspu.h"
#include "cr_mothership.h"
#include "cr_string.h"
#include "cr_mem.h"
#include <string.h>
#include <math.h>

static void set_peers( void *foo, const char *response )
{
	char *nodes;
	char *token;
	int i;
	
	/* figure out peer information! */
	/* grab network configuration */
	/* get count of things first so we can allocate space */
	int count = 0;
	nodes = crStrdup(response);
	if((token = strtok(nodes, ",\n\t\0 ")) != NULL){
		count = 1;
		while((token = strtok(NULL, ",\n\t\0 ")) != NULL){
			count++;
		}
	}
	else{
		crError("Bad mojo: I can't figure out how many peers you have!");
	}
	crFree(nodes);
	
	/* actually store the network peer list */
	nodes = crStrdup(response);
	binaryswap_spu.peer_names = crAlloc(count*sizeof(char*));
	if((token = strtok(nodes, ",\n\t ")) != NULL){
		i = 0;
		binaryswap_spu.peer_names[i++] = crStrdup(token);
		while((token = strtok(NULL, ",\n\t ")) != NULL){
			binaryswap_spu.peer_names[i++] = crStrdup(token);
		}
	}
	crFree(nodes);
	
	/* figure out how many stages we have */
	binaryswap_spu.stages = (int)(log(count)/log(2)+0.1);
	crDebug("Swapping Stages: %d", binaryswap_spu.stages);
}


static void set_node( void *spu, const char *response )
{
	(void) spu;
	if (*response) {
		binaryswap_spu.node_num = crStrToInt( response );
		if(binaryswap_spu.node_num == -1)
		     crError( "FATAL: No node number specified for the binaryswap SPU?" );     
	}
	else {
		crError( "FATAL: No node number specified for the binaryswap SPU?" );
	}
}

static void set_swapmtu( void *spu, const char *response )
{
	(void) spu;
	if (*response) {
		binaryswap_spu.mtu = crStrToInt( response );
	}
	else { 
		binaryswap_spu.mtu = -1;
		crWarning("No swap MTU specified, using default from mothership" );
	}
}

static void set_type( void *spu, const char *response )
{
	(void) spu;
	if(crStrcmp( response, "alpha") == 0){
		binaryswap_spu.alpha_composite = 1;
		binaryswap_spu.depth_composite = 0;
	}
	else if(crStrcmp( response, "depth") == 0){
		binaryswap_spu.depth_composite = 1;
		binaryswap_spu.alpha_composite = 0;
	}
	else{
		crError( "Bad composite type specified for the binaryswap SPU?" );
	}
}

static void set_local_visualization( Binaryswapspu *binaryswap_spu, const char *response )
{
	binaryswap_spu->local_visualization = crStrToInt( response );
}

static void __setDefaults( Binaryswapspu *binaryswap_spu )
{
	/* misc */
	binaryswap_spu->barrierSize = 0;
	binaryswap_spu->bbox = NULL;
	
	/* config options */
	binaryswap_spu->resizable = 0;
	binaryswap_spu->local_visualization = 0;
}


/* option, type, nr, default, min, max, title, callback
 */
SPUOptions binaryswapspuOptions[] = {
	
	{ "peers", CR_STRING, 1, "", NULL, NULL, 
	  "Peers", (SPUOptionCB)set_peers},
	
	{ "node_number", CR_INT, 1, "-1", NULL, NULL, 
	  "Node Number", (SPUOptionCB)set_node},
	
	{ "local_visualization", CR_BOOL, 1, "1", NULL, NULL,
	  "Local Visualization", (SPUOptionCB)set_local_visualization },
	
	{ "type", CR_ENUM, 1, "depth", "'depth', 'alpha'", NULL, 
	  "Composite type",  (SPUOptionCB)set_type},
	
	{ "swapmtu", CR_INT, 1, "-1", "1024", NULL, 
	  "MTU size for swapping", (SPUOptionCB)set_swapmtu},
	
	{ NULL, CR_BOOL, 0, NULL, NULL, NULL, NULL, NULL },
};


void binaryswapspuGatherConfiguration( Binaryswapspu *binaryswap_spu )
{
	CRConnection *conn;
	int i;
	
	__setDefaults( binaryswap_spu );
	
	/* Connect to the mothership and identify ourselves. */
	
	conn = crMothershipConnect( );
{'fraction_non_alphanumeric': 0.1486543020499233, 'fraction_numerical': 0.009761539534235114, 'mean_word_length': 4.246525237746891, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '2872669', 'n_tokens_mistral': 2839, 'n_tokens_neox': 2647, 'n_words': 673}