~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
cvs/emstar/devel/geonet/systemmanager/sm_status.c


  1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: 1; c-basic-offset: 2 -*- */
  2 /*
  3  *
  4  * Copyright (c) 2007 The Regents of the University of California.  All 
  5  * rights reserved.
  6  *
  7  * Redistribution and use in source and binary forms, with or without
  8  * modification, are permitted provided that the following conditions
  9  * are met:
 10  *
 11  * - Redistributions of source code must retain the above copyright
 12  *   notice, this list of conditions and the following disclaimer.
 13  *
 14  * - Neither the name of the University nor the names of its
 15  *   contributors may be used to endorse or promote products derived
 16  *   from this software without specific prior written permission.
 17  *
 18  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
 19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 21  * PARTICULAR  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
 22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 25  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 26  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 29  *
 30  */
 31 
 32 
 33 #include "sm_i.h"
 34 
 35 
 36 char sm_status_c_cvsid[] = "$Id: sm_status.c,v 1.6 2007-12-18 01:42:42 mlukac Exp $";
 37 
 38 
 39 
 40 
 41 int sm_status_write(status_context_t *ctx, char *command, size_t buf_size)
 42 {
 43   sm_t *sm = (sm_t *) sd_data(ctx);
 44 
 45   logmsg_t * lm = g_new0(logmsg_t, 1);
 46 
 47   misc_strip_trailing_crlfs(command);
 48   lm->msg = misc_string_realloc_null_term(command, 
 49                                           strlen(command) > 4096 ? 4096 : strlen(command));
 50 
 51   lm->seqno = sm->seqno;
 52   sm->seqno = sm->seqno + 1;
 53 
 54   gettimeofday(&(lm->time), NULL);
 55   if (sm->include_timesync_time) {
 56     sm_timesync_lookup_gps(sm, &(lm->time), &(lm->timesync_time));
 57   }
 58 
 59   logmsg_push(sm, lm);
 60 
 61   sm_bundle_writeout(sm);
 62 
 63   return STATUS_WRITE_DONE;
 64 }
 65 
 66 
 67 
 68 int sm_status_printable(status_context_t *ctx, buf_t *buf)
 69 {
 70   sm_t *sm = (sm_t *) sd_data(ctx);
 71   struct timeval now = {};
 72   logmsg_t * lm = NULL;
 73 
 74   gettimeofday(&now, NULL);
 75 
 76   for (lm = logmsg_top(sm); lm != NULL; lm = logmsg_next(lm)) {
 77     if (sm->include_timesync_time) {
 78       bufprintf(buf, "%s %s [%c%c] %8l"FMT64"d %s\n",
 79                 misc_print_date(&lm->time),
 80                 misc_print_date(&lm->timesync_time),
 81                 lm->ondisk ? 'd' : 'n',
 82                 lm->bundled ? 'b' : 'n',
 83                 lm->seqno,
 84                 lm->msg);
 85     } else {
 86       bufprintf(buf, "%s [%c%c] %8l"FMT64"d %s\n",
 87                 misc_print_date(&lm->time),
 88                 lm->ondisk ? 'd' : 'n',
 89                 lm->bundled ? 'b' : 'n',
 90                 lm->seqno,
 91                 lm->msg);
 92     }
 93   }
 94 
 95   bufprintf(buf, "Last Bundle: %s -- Bundle Period: %d -- Cleanup: %d -- Seqno: %l"FMT64"d -- Next Bundle in %f minutes %s\n",
 96             misc_print_date(&sm->last_bundle), sm->bundleperiod, 
 97             sm->cleanuptime, sm->seqno,
 98             (g_timer_time_remaining(sm->bundle_timer) / 1000.0) / 60.0,
 99             sm->include_timesync_time ? "- Including timesync" : " ");
100 
101   return STATUS_MSG_COMPLETE;
102 }
103 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.