ccnr_main.c

Go to the documentation of this file.
00001 /**
00002  * @file ccnr_main.c
00003  * 
00004  * Part of ccnr -  CCNx Repository Daemon.
00005  *
00006  */
00007 
00008 /*
00009  * Copyright (C) 2009-2011 Palo Alto Research Center, Inc.
00010  *
00011  * This work is free software; you can redistribute it and/or modify it under
00012  * the terms of the GNU General Public License version 2 as published by the
00013  * Free Software Foundation.
00014  * This work is distributed in the hope that it will be useful, but WITHOUT ANY
00015  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
00016  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
00017  * for more details. You should have received a copy of the GNU General Public
00018  * License along with this program; if not, write to the
00019  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022  
00023 #include <signal.h>
00024 #include <stddef.h>
00025 #include <stdarg.h>
00026 #include <stdio.h>
00027 #include <stdlib.h>
00028 
00029 #include "ccnr_private.h"
00030 
00031 #include "ccnr_init.h"
00032 #include "ccnr_dispatch.h"
00033 #include "ccnr_msg.h"
00034 #include "ccnr_stats.h"
00035 
00036 static int
00037 stdiologger(void *loggerdata, const char *format, va_list ap)
00038 {
00039     FILE *fp = (FILE *)loggerdata;
00040     return(vfprintf(fp, format, ap));
00041 }
00042 
00043 static struct ccnr_handle *global_h = NULL;
00044 
00045 static void
00046 handle_signal(int sig)
00047 {
00048     if (global_h != NULL)
00049         global_h->running = 0;
00050     signal(sig, SIG_DFL);
00051 }
00052 
00053 int
00054 main(int argc, char **argv)
00055 {
00056     int s;
00057     
00058     if (argc > 1) {
00059         fprintf(stderr, "%s", ccnr_usage_message);
00060         exit(1);
00061     }
00062     signal(SIGPIPE, SIG_IGN);
00063     global_h = r_init_create(argv[0], stdiologger, stderr);
00064     if (global_h == NULL)
00065         exit(1);
00066     signal(SIGINT, &handle_signal);
00067     signal(SIGTERM, &handle_signal);
00068     r_dispatch_run(global_h);
00069     s = (global_h->running != 0);
00070     ccnr_msg(global_h, "exiting.");
00071     r_init_destroy(&global_h);
00072     exit(s);
00073 }

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