Show lqe_main.c syntax highlighted
/*
*
* Copyright (c) 2003 The Regents of the University of California. All
* rights reserved.
*
* Redistribution and use 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.
*
* - Neither the name of the University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
*/
/*
* lqe_main.c: A daemon that provides you a list of your one-hop
* neighbors connectivity statistics, using the generic link interface.
*
* $Id: lqe_main.c,v 1.1 2005/01/26 01:30:59 cerpa Exp $
*/
char lqe_main_c_cvsid[] = "$Id: lqe_main.c,v 1.1 2005/01/26 01:30:59 cerpa Exp $";
#define __MAIN_C__
#include <stdio.h>
#include <stdlib.h>
#include "emrun/emrun.h"
#include "link/link.h"
#include "lqe_i.h"
/*****************************************************************/
/* Callback when we are asked (by emrun) to shut down */
static void lqe_shutdown(void *data)
{
elog(LOG_INFO, "shutting down lqed");
exit(0);
}
static void usage(char *name)
{
misc_print_usage
(name, "-U <device> [-P <device>] [-f <filename>] [-a <value>]",
" --uses <device>: Specify device to use\n"
" --provides <device>: Specify device to provide\n"
" --filename <init file>: Specify the file with init RNP values\n"
" --alpha <value>: Specify the alpha factor for EWMA\n"
);
exit(1);
}
int main(int argc, char *argv[])
{
neighbor_list_t nl;
char *default_file = DEFAULT_INIT_FILENAME;
emrun_opts_t emrun_opts = {
shutdown: lqe_shutdown,
data: &nl
};
/* generic initialization common to all programs */
misc_init(&argc, argv, CVSTAG);
memset(&nl, 0, sizeof(nl));
/********** Parse command-line arguments ************/
nl.link_uses = link_parse_uses(&argc, argv, NULL);
nl.link_provides = link_parse_provides
(&argc, argv, DEFAULT_PROVIDED_INTERFACE);
/* filename for the init RNP values */
nl.init_file = misc_parse_out_option(&argc, argv, "filename", 'f');
/* alpha value for the RNP EWMA estimate */
misc_parse_option_as_float(&argc, argv, "alpha", 'a', &(nl.alpha));
/* add'l args? */
if (misc_args_remain(&argc, argv)) {
elog(LOG_CRIT, "Additional unparsed arguments!");
usage(argv[0]);
}
/* no default --uses */
if (nl.link_uses == NULL) {
elog(LOG_CRIT, "Error: Must specify --uses");
usage(argv[0]);
}
/* use default filename if no command line option */
if (nl.init_file == NULL) {
elog(LOG_NOTICE, "Using default filename %s", DEFAULT_INIT_FILENAME);
nl.init_file = default_file;
}
/* use default alpha value if no command line option */
if (nl.alpha == 0) {
elog(LOG_NOTICE, "Using default alpha value %f", DEFAULT_ALPHA);
nl.alpha = DEFAULT_ALPHA;
}
/* Create passthru device (opens "uses", and exports "provides") */
lqe_register_passthru(&nl);
/* initialize util */
lqe_util_init(&nl);
/* Initialize the status interface.. after provider and util inited */
lqe_status_init(&nl);
/*
* Start the event loop running - it should never exit (the shutdown
* handler is called when the program is supposed to stop)
*/
emrun_init(&emrun_opts); /* this should be the last initialization */
g_main();
elog_g(LOG_CRIT, "event loop terminated abnormally!");
return 0;
}
See more files for this project here
EmStar is a software system for developing and deploying wireless sensor networks involving Linux-based platforms. As the wireless sensor network community has attempted to deploy more complex designs---large-scale, long-lived systems that need self-organization and adaptivity---a number of difficult software design issues have arisen. Advances in software design have not kept pace with the capabilities of hardware. This is because designing for an adaptive, efficient, and useful sensor network has turned out to be surprisingly complex and difficult. EmStar is a Linux-based software framework, whose goal is to dramatically reduce this complexity, enabling work to be shared and reused, and simplifying and speeding the design of new sensor network applications.
Project homepage:
http://cvs.cens.ucla.edu/emstar/
Programming language(s): C,Shell Script
License: other
lqe_i.h
lqe_main.c
lqe_passthru.c
lqe_status.c
lqe_util.c