android_msg.c

Go to the documentation of this file.
00001 /**
00002  * Copyright (C) 2009,2010 Palo Alto Research Center, Inc.
00003  *
00004  * This work is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU General Public License version 2 as published by the
00006  * Free Software Foundation.
00007  * This work is distributed in the hope that it will be useful, but WITHOUT ANY
00008  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
00009  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
00010  * for more details. You should have received a copy of the GNU General Public
00011  * License along with this program; if not, write to the
00012  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00013  * Boston, MA 02110-1301, USA.
00014  */
00015 
00016 /**
00017  *
00018  * Logging support for ccnd, for Android platform
00019  *
00020  *
00021  */
00022 
00023 #include <stdio.h>
00024 #include <sys/time.h>
00025 #include <stdarg.h>
00026 #include <time.h>
00027 #include <unistd.h>
00028 
00029 #include <ccn/ccn.h>
00030 #include <ccn/ccnd.h>
00031 #include <ccn/charbuf.h>
00032 #include <ccn/uri.h>
00033 
00034 #include "ccnd_private.h"
00035 
00036 #include <android/log.h>
00037 
00038 /**
00039  *  Produce ccnd debug output to the Android log.
00040  *  Output is produced on stderr under the control of h->debug;
00041  *  prepends decimal timestamp and process identification.
00042  *  Caller should not supply newlines.
00043  *  @param      h  the ccnd handle
00044  *  @param      fmt  printf-like format string
00045  */
00046 void
00047 ccnd_msg(struct ccnd_handle *h, const char *fmt, ...)
00048 {
00049     struct timeval t;
00050     va_list ap;
00051     struct ccn_charbuf *b;
00052 
00053     if (h != NULL && h->debug == 0)
00054         return;
00055 
00056     b = ccn_charbuf_create();
00057 
00058     gettimeofday(&t, NULL);
00059     ccn_charbuf_putf(b, "%ld.%06u ccnd[%d]: %s\n",
00060         (long)t.tv_sec, (unsigned)t.tv_usec, (int)getpid(), fmt);
00061     va_start(ap, fmt);
00062 
00063         __android_log_vprint(ANDROID_LOG_INFO, "CCND", (const char *)b->buf, ap);
00064     va_end(ap);
00065     ccn_charbuf_destroy(&b);
00066 }
00067 
00068 /**
00069  *  Produce a ccnd debug trace entry.
00070  *  Output is produced by calling ccnd_msg.
00071  *  @param      h  the ccnd handle
00072  *  @param      lineno  caller's source line number (usually __LINE__)
00073  *  @param      msg  a short text tag to identify the entry
00074  *  @param      face    handle of associated face; may be NULL
00075  *  @param      ccnb    points to ccnb-encoded Interest or ContentObject
00076  *  @param      ccnb_size   is in bytes
00077  */
00078 void
00079 ccnd_debug_ccnb(struct ccnd_handle *h,
00080                 int lineno,
00081                 const char *msg,
00082                 struct face *face,
00083                 const unsigned char *ccnb,
00084                 size_t ccnb_size)
00085 {
00086     struct ccn_charbuf *c;
00087     struct ccn_parsed_interest pi;
00088     const unsigned char *nonce = NULL;
00089     size_t nonce_size = 0;
00090     size_t i;
00091 
00092     if (h != NULL && h->debug == 0)
00093         return;
00094     c = ccn_charbuf_create();
00095     ccn_charbuf_putf(c, "debug.%d %s ", lineno, msg);
00096     if (face != NULL)
00097         ccn_charbuf_putf(c, "%u ", face->faceid);
00098     ccn_uri_append(c, ccnb, ccnb_size, 1);
00099     ccn_charbuf_putf(c, " (%u bytes)", (unsigned)ccnb_size);
00100     if (ccn_parse_interest(ccnb, ccnb_size, &pi, NULL) >= 0) {
00101         ccn_ref_tagged_BLOB(CCN_DTAG_Nonce, ccnb,
00102                   pi.offset[CCN_PI_B_Nonce],
00103                   pi.offset[CCN_PI_E_Nonce],
00104                   &nonce,
00105                   &nonce_size);
00106         if (nonce_size > 0) {
00107             ccn_charbuf_putf(c, " ");
00108             for (i = 0; i < nonce_size; i++)
00109                 ccn_charbuf_putf(c, "%02X", nonce[i]);
00110         }
00111     }
00112     ccnd_msg(h, "%s", ccn_charbuf_as_string(c));
00113     ccn_charbuf_destroy(&c);
00114 }
00115 
00116 /**
00117  * Print the ccnd usage message on stderr.
00118  *
00119  * Does not exit.
00120  */
00121 void
00122 ccnd_usage(void)
00123 {
00124     static const char ccnd_usage_message[] =
00125     "ccnd - CCNx Daemon\n"
00126     "  options: none\n"
00127     "  arguments: none\n"
00128     "  environment variables:\n"
00129     "    CCND_DEBUG=\n"
00130     "      0 - no stderr messages\n"
00131     "      1 - default stderr messages (any non-zero value gets these)\n"
00132     "      2 - interest messages\n"
00133     "      4 - content messages\n"
00134     "      8 - matching details\n"
00135     "      16 - interest details\n"
00136     "      32 - gory interest details\n"
00137     "      64 - log occasional human-readable timestamps\n"
00138     "      128 - face registration debugging\n"
00139     "      bitwise OR these together for combinations; -1 gets everything\n"
00140     "    CCN_LOCAL_PORT=\n"
00141     "      UDP port for unicast clients (default %s).\n"
00142     "      Also listens on this TCP port for stream connections.\n"
00143     "      Also affects name of unix-domain socket.\n"
00144     "    CCND_CAP=\n"
00145     "      Capacity limit, in count of ContentObjects.\n"
00146     "      Not an absolute limit.\n"
00147     "    CCND_MTU=\n"
00148     "      Packet size in bytes.\n"
00149     "      If set, interest stuffing is allowed within this budget.\n"
00150     "      Single items larger than this are not precluded.\n"
00151     "    CCND_DATA_PAUSE_MICROSEC=\n"
00152     "      Adjusts content-send delay time for multicast and udplink faces\n";
00153     fprintf(stderr, ccnd_usage_message, CCN_DEFAULT_UNICAST_PORT);
00154 }
00155 

Generated on Thu Feb 16 00:43:57 2012 for Content-Centric Networking in C by  doxygen 1.5.6