Code Search for Developers
 
 
  

linkstats_main.c from EmStar at Krugle


Show linkstats_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.
 *
 */
 

/*
 * linkstats_main.c: A daemon that provides you a list of your one-hop
 * neighbors connectivity statistics, using the generic link interface.
 *
 * $Id: linkstats_main.c,v 1.14 2005/06/09 23:16:44 girod Exp $ 
 */

char linkstats_main_c_cvsid[] = "$Id: linkstats_main.c,v 1.14 2005/06/09 23:16:44 girod Exp $";
#define __MAIN_C__

#include <stdio.h>
#include <stdlib.h>

#include "emrun/emrun.h"
#include "link/link.h"
#include "linkstats_i.h"


/*****************************************************************/


/* Callback when we are asked (by emrun) to shut down */
static void linkstats_shutdown(void *data)
{
  neighbor_list_t *nl = (neighbor_list_t *) data;

  if ((nl->log) && (nl->fp != NULL))
    fclose(nl->fp);
  
  elog(LOG_INFO, "shutting down linkstats");
  exit(0);
}


static void usage(char *name)
{
  misc_print_usage
    (name, "-U <device> [-P <device>] [-l]",
     "  --uses <device>: Specify device to use\n"
     "  --provides <device>: Specify device to provide\n"
     "  -l: Log raw connectivity values every 30 seconds to a file.\n"
     "      Default filename is 'conn-id', where 'id' is the node id\n"
     );
  exit(1);
}


int main(int argc, char *argv[])
{
  neighbor_list_t nl;
  int arg;

  emrun_opts_t emrun_opts = {
    shutdown: linkstats_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);  
  nl.link_class = link_parse_if_class
    (&argc, argv, LINK_CLASS_NONE);
  
  opterr = 0;
  while ((arg = getopt(argc, argv, "hl")) != EOF) {
    switch (arg) {
    
    case 'l':
      nl.log = TRUE;
      break;
    
    case 'h':
      usage(argv[0]);
      break;
      
    case '?':
    default:
      elog_g(LOG_CRIT, "invalid option '-%c' (use -h for help)", optopt);
    }
  }

  /* advance past parsed options */
  argc -= optind;
  argv += optind;
  
  /* 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");
    exit(1);
  }

  /* Initialize the smoothing factor */
  nl.alpha = DEFAULT_ALPHA;
  
  /* Create the upper packetdev interface, i.e. the interface(s) we export */
  linkstats_register_passthru(&nl);

  /* Initialize the status interface.. after provider init */
  linkstats_status_init(&nl);
  
  /* Initialize the util stuff */
  linkstats_util_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

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

  linkstats_i.h
  linkstats_main.c
  linkstats_passthru.c
  linkstats_status.c
  linkstats_util.c