view extensions/rt_any/rt_any.c @ 400:22f29007b931

Detect when extensions are loaded several times (not allowed)
author Sebastien Decugis <sdecugis@nict.go.jp>
date Tue, 02 Jun 2009 14:49:37 +0900
parents 316bb3f38d04
children 860f41038ea2
line wrap: on
line source

/*********************************************************************************************************
* Software License Agreement (BSD License)                                                               *
* Author: Sebastien Decugis <sdecugis@nict.go.jp>							 *
*													 *
* Copyright (c) 2008, WIDE Project and NICT								 *
* All rights reserved.											 *
* 													 *
* Redistribution and use of this software in source and binary forms, with or without modification, are  *
* permitted provided that the following conditions are met:						 *
* 													 *
* * Redistributions of source code must retain the above 						 *
*   copyright notice, this list of conditions and the 							 *
*   following disclaimer.										 *
*    													 *
* * Redistributions in binary form must reproduce the above 						 *
*   copyright notice, this list of conditions and the 							 *
*   following disclaimer in the documentation and/or other						 *
*   materials provided with the distribution.								 *
* 													 *
* * Neither the name of the WIDE Project or NICT nor the 						 *
*   names of its contributors may be used to endorse or 						 *
*   promote products derived from this software without 						 *
*   specific prior written permission of WIDE Project and 						 *
*   NICT.												 *
* 													 *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 	 *
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 	 *
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF   *
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.								 *
*********************************************************************************************************/

/* 
 * Stupid routing: will give same positive score to all peers. 
 * Ensures that messages are sent to other peers, but it should be used only for testing.
 */

#define IN_EXTENSION
#define DECLARE_API_POINTERS
#define DEFINE_DEBUG_MACRO	rt_any
#include <waaad/waaad.h>

static int rt_any_verbosity = 1;

/* give positive score to all messages */
static int cb_any_out(void * data, msg_t * msg, rt_dpl_t * list )
{
	rt_dpl_t * t = list;
	
	while (t != NULL) {
		t->score += PEER_SCORE_LOAD_BALANCE;
		t = t->next;
	}
	return 0;
}

/* handler */
static rt_out_hdl_t * hdl = NULL;

/* entry point */
static int entry(char * conffile)
{
	TRACE_DEBUG(INFO, "Extension RT/Any initialized");
	return rt_out_register( cb_any_out, NULL, RT_OUT_NORMAL, &hdl );
}

/* Unload */
void waaad_ext_fini(void)
{
	rt_out_unregister ( hdl );
}

EXTENSION_API_INIT( API_MODULE_RT | API_MODULE_LOG, entry, "rt_any", 1);
"Welcome to our mercurial repository"