application_shell.cpp

Go to the documentation of this file.
00001 /*****************************************************************************\
00002 *                                                                             *
00003 *  Name   : application_shell                                                 *
00004 *  Author : Chris Koeritz                                                     *
00005 *                                                                             *
00006 *******************************************************************************
00007 * Copyright (c) 2000-$now By Author.  This program is free software; you can  *
00008 * redistribute it and/or modify it under the terms of the GNU General Public  *
00009 * License as published by the Free Software Foundation; either version 2 of   *
00010 * the License or (at your option) any later version.  This is online at:      *
00011 *     http://www.fsf.org/copyleft/gpl.html                                    *
00012 * Please send any updates to: fred@gruntose.com                               *
00013 \*****************************************************************************/
00014 
00015 #include "application_shell.h"
00016 
00017 #include <basis/astring.h>
00018 #include <basis/functions.h>
00019 #include <configuration/application_configuration.h>
00020 #include <loggers/combo_logger.h>
00021 #include <loggers/program_wide_logger.h>
00022 #include <timely/time_stamp.h>
00023 
00024 #include <stdio.h>
00025 #ifdef __UNIX__
00026   #include <limits.h>
00027   #include <unistd.h>
00028 #endif
00029 
00030 #undef LOG
00031 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
00032 
00033 using namespace basis;
00034 using namespace configuration;
00035 using namespace loggers;
00036 using namespace mathematics;
00037 using namespace textual;
00038 using namespace timely;
00039 
00040 namespace application {
00041 
00042 const int MAXIMUM_COMMAND_LINE = 32 * KILOBYTE;
00043   // maximum command line that we'll deal with here.
00044 
00045 application_shell *not_so_hidden_pointer = NULL;  // fodder for the single instance function.
00046 
00047 application_shell *application_shell::single_instance() { return not_so_hidden_pointer; }
00048 
00049 application_shell::application_shell()
00050 : c_rando(),
00051   c_exit_value(120)  // if this is never changed from the default, that in itself is an error.
00052 {
00053   // we create a combo logger for program-wide usage.
00054   SETUP_COMBO_LOGGER;
00055   not_so_hidden_pointer = this;  // setup the single instance method.
00056 }
00057 
00058 application_shell::~application_shell()
00059 {
00060   if (not_so_hidden_pointer == this) not_so_hidden_pointer = NULL;  // only scorch it when it's us.
00061 }
00062 
00063 outcome application_shell::log(const base_string &to_print, int filter)
00064 {
00065   outcome to_return = common::OKAY;
00066   if (program_wide_logger::get().member(filter)) {
00067     astring temp_log(to_print);
00068     if (temp_log.length())
00069       temp_log.insert(0, time_stamp::notarize(true));
00070     to_return = program_wide_logger::get().log(temp_log, filter);
00071   }
00072   return to_return;
00073 }
00074 
00075 int application_shell::execute_application()
00076 {
00077   try {
00078     c_exit_value = execute();
00079   } catch (const char *message) {
00080     printf("caught exception:\n%s\n", message);
00081   } catch (astring message) {
00082     printf("caught exception:\n%s\n", message.s());
00083   } catch (...) {
00084     printf("caught exception: unknown type!\n");
00085   }
00086   return c_exit_value;
00087 }
00088 
00089 } //namespace.
00090 
Generated on Sat Jan 28 04:22:03 2012 for hoople2 project by  doxygen 1.6.3