Code Search for Developers
 
 
  

rechocat.c from EmStar at Krugle


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

/*
 *  rechocat: Remote "echocat"
 *
 *  This utility is a remote version of the echocat utility provided 
 *  with libdev.
 *
 *  $Id=$
 */

char rechocat_c_id[] = "$Id: rechocat.c,v 1.9 2005/09/22 18:41:10 girod Exp $";

#include <emproxy/emproxy.h>

int watch = 0;
int hexdump = 0;

void usage(char *s)
{
  misc_print_usage
    (s, 
     "[-w] [-H] <emproxy-command-string>",
     "  --watch: See status updates as they arrive\n"
     "  --hexdump: hexdump all data\n"
     "  <emproxy command string>: see emproxy.h\n"
     "\n"
     "Examples:\n"
     "  ...\n"
     "\n"
     );
  exit(1);
}


int handle_result(emproxy_reply_hdr_t *reply, void *data)
{
  char *buf = malloc(reply->data_length+1);
  
  memmove(buf, reply->data, reply->data_length);
  buf[reply->data_length] = 0;
  printf("Node=%d, data_id=%d:\n",
	 reply->node_id, reply->data_id);

  if (hexdump) {
    buf_t *hd = buf_new();
    misc_hexdump_to_buf(hd, buf, reply->data_length, "  ");
    printf("%s\n\n", hd->buf);
    buf_free(hd);
  }

  else {
    printf("%s\n\n", buf);
  }

  free(buf);

  if (watch == 0)
    exit(0);
  return EVENT_RENEW;
}


int main(int argc, char *argv[])
{
  emproxy_client_opts_t opts = {
    handler: handle_result,
    private_data: NULL
  };

  /* get group id, etc */
  misc_init(&argc, argv, CVSTAG);

  /* emproxy options parsing */
  emproxy_client_config(&opts, &argc, argv);
  
  /* other options */
  watch = misc_parse_out_switch(&argc, argv, "watch", 'w');
  hexdump = misc_parse_out_switch(&argc, argv, "hexdump", 'H');

  if (misc_parse_out_switch(&argc, argv, "help", 'h')) 
    usage(argv[0]);

  /* grab command string name */
  if (optind < argc) {
    char *buffer = malloc(256+strlen(argv[optind]));
    sprintf(buffer, "session=%d:type=request\n%s\n", (int)random(), argv[optind]);
    opts.command = buffer;
  }
  else {
    fprintf(stderr, "%s: No emproxy command string specified\n", argv[0]);
    exit(1);
  }
  
  /* install event */
  if (emproxy_client_open(&opts, NULL) < 0) {
    fprintf(stderr, "Error connecting to client: %m\n");
    exit(1);
  }

  g_main();
  return 1;
}




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

  BUILD
  rbsh.c
  rechocat.c
  sample_gw.c