/Users/maurits/Documents/studie/afstuderen/biosphere/daemon/main.c

Go to the documentation of this file.
00001 /*
00002  * Author: MA Hartman
00003  * Date: feb 13, 2007
00004  * 
00005  * Function:
00006  * Biosphered entry point
00007  * 
00008  * License information:
00009  * 
00010  * Copyright (c) 2006 Maurits Hartman
00011  *
00012  * Permission is hereby granted, free of charge, to any person
00013  * obtaining a copy of this software and associated documentation
00014  * files (the "Software"), to deal in the Software without
00015  * restriction, including without limitation the rights to use,
00016  * copy, modify, merge, publish, distribute, sublicense, and/or sell
00017  * copies of the Software, and to permit persons to whom the
00018  * Software is furnished to do so, subject to the following
00019  * conditions:
00020  * 
00021  * The above copyright notice and this permission notice shall be
00022  * included in all copies or substantial portions of the Software.
00023  * 
00024  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
00026  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
00028  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
00029  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00030  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00031  * OTHER DEALINGS IN THE SOFTWARE.
00032  * 
00033  */
00034 
00035 #ifdef HAVE_CONFIG_H
00036 #include <config.h>
00037 #endif
00038 
00039 #include <biosphere.h>
00040 #include <xml.h>
00041 #include "module.h"
00042 #include "mutex.h"
00043 #include "node.h"
00044 #include "options.h"
00045 #include "service.h"
00046 #include "settings.h"
00047 #include "thread.h"
00048 
00049 #include <stdio.h>
00050 #include <stdlib.h>
00051 #include <apr_pools.h>
00052 
00053 
00064 apr_pool_t *global_mp;
00065 
00066 
00070 static void cleanup(void)
00071 {
00072         apr_pool_destroy(global_mp);
00073         apr_terminate();
00074         printf("Bio-SPHERE shutting down\n");
00075 }
00076 
00077 
00081 static bs_status init_general(void)
00082 {       
00083         printf("Bio-SPHERE starting up\n");
00084     apr_initialize();
00085     apr_pool_create(&global_mp, NULL);
00086  
00087         atexit(cleanup);
00088     return BS_OK;
00089 }
00090 
00091 
00096 int main(int argc, const char *argv[])
00097 {
00098         if (init_general())     {
00099                 fprintf(stderr, "Failed to initialize\n");
00100                 return BS_ERROR;
00101         }
00102         if (init_mutexes(global_mp))    {
00103                 fprintf(stderr, "Failed to initialize mutexes\n");
00104                 return BS_ERROR;
00105         }
00106         if (init_options(argc, argv, global_mp)) {
00107                 fprintf(stderr, "Failed to recognize command-line options\n");
00108                 return BS_INIT_ERROR_OPTION;
00109         }
00110         if (init_service(global_mp)) {
00111                 fprintf(stderr, "Failed to initialize services\n");
00112                 return BS_INIT_ERROR_SERVICE;
00113         }
00114         if (init_module(global_mp)) {
00115                 fprintf(stderr, "Failed to initialize modules\n");
00116                 return BS_INIT_ERROR_MODULE;
00117         }
00118         if (init_node(global_mp)) {
00119                 fprintf(stderr, "Failed to correctly add nodes\n");
00120                 return BS_ERROR;
00121         }
00122         if (init_threadsystem(global_mp)) {
00123                 fprintf(stderr, "Failed to initialize listening socket\n");
00124                 return BS_INIT_ERROR_LISTENER;
00125         }
00126         
00127         /* Start the main loop listening for incoming connections: */
00128         lets_go_threaded();
00129         
00130         return BS_OK; /* Cleanup is automatic atexit... */
00131 }
00132 

Generated on Tue Jul 17 09:50:52 2007 for Bio-SPHERE by  doxygen 1.5.1