feisty meow concerns codebase 2.140
application_shell.cpp
Go to the documentation of this file.
1/*****************************************************************************\
2* *
3* Name : application_shell *
4* Author : Chris Koeritz *
5* *
6*******************************************************************************
7* Copyright (c) 2000-$now By Author. This program is free software; you can *
8* redistribute it and/or modify it under the terms of the GNU General Public *
9* License as published by the Free Software Foundation; either version 2 of *
10* the License or (at your option) any later version. This is online at: *
11* http://www.fsf.org/copyleft/gpl.html *
12* Please send any updates to: fred@gruntose.com *
13\*****************************************************************************/
14
15#include "application_shell.h"
16
17#include <basis/astring.h>
18#include <basis/functions.h>
22#include <timely/time_stamp.h>
23
24#include <stdio.h>
25#ifdef __UNIX__
26 #include <limits.h>
27 #include <unistd.h>
28#endif
29
30#undef LOG
31#define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
32
33using namespace basis;
34using namespace configuration;
35using namespace loggers;
36using namespace mathematics;
37using namespace textual;
38using namespace timely;
39
40namespace application {
41
43 // maximum command line that we'll deal with here.
44
45application_shell *not_so_hidden_pointer = NULL; // fodder for the single instance function.
46
48
50: c_rando(),
51 c_exit_value(120) // if this is never changed from the default, that in itself is an error.
52{
53 // we create a combo logger for program-wide usage.
55 not_so_hidden_pointer = this; // setup the single instance method.
56}
57
59{
60 if (not_so_hidden_pointer == this) not_so_hidden_pointer = NULL; // only scorch it when it's us.
61}
62
63outcome application_shell::log(const base_string &to_print, int filter)
64{
65 outcome to_return = common::OKAY;
66 if (program_wide_logger::get().member(filter)) {
67 astring temp_log(to_print);
68 if (temp_log.length())
69 temp_log.insert(0, time_stamp::notarize(true));
70 to_return = program_wide_logger::get().log(temp_log, filter);
71 }
72 return to_return;
73}
74
76{
77 int c_exit_value = 0; // optimistic outlook on the eventual exit value.
78 try {
79 c_exit_value = execute();
80 } catch (const char *message) {
81 printf("BOOM: caught exception:\n%s\n", message);
82 } catch (astring &message) {
83 printf("BOOM: caught exception:\n%s\n", message.s());
84 } catch (...) {
85 printf("BOOM: caught exception: unhandled type!\n");
86 }
87//printf("got to just before return, and exit value is %d currently.", c_exit_value);
88 return c_exit_value;
89}
90
91} //namespace.
92
The application_shell is a base object for console programs.
virtual int execute()=0
< retrieves the command line from the /proc hierarchy on linux.
application_shell()
constructs an application_shell to serve as the root of the program.
virtual int execute_application()
runs the base class's execute() method and catches any exceptions due to it.
virtual basis::outcome log(const basis::base_string &to_print, int filter=basis::ALWAYS_PRINT)
< returns the full name of the current application.
static application_shell * single_instance()
in a program with a single application_shell extant, this gives out the instance.
Provides a dynamically resizable ASCII character string.
Definition astring.h:35
void insert(int position, const astring &to_insert)
Copies "to_insert" into "this" at the "position".
Definition astring.cpp:895
int length() const
Returns the current length of the string.
Definition astring.cpp:132
virtual outcome log(const base_string &info, int filter)=0
writes the information in "info" to the logger using the "filter".
Defines the base class for all string processing objects in hoople.
Definition base_string.h:28
Outcomes describe the state of completion for an operation.
Definition outcome.h:31
static loggers::standard_log_base & get()
Provided by the startup code within each application for logging.
static basis::astring notarize(bool add_space=true)
a useful method for getting a textual version of the time "right now".
#define SETUP_COMBO_LOGGER
a macro that retasks the program-wide logger as a combo_logger.
Implements an application lock to ensure only one is running at once.
application_shell * not_so_hidden_pointer
const int MAXIMUM_COMMAND_LINE
The guards collection helps in testing preconditions and reporting errors.
Definition array.h:30
const int KILOBYTE
Number of bytes in a kilobyte.
A logger that sends to the console screen using the standard output device.
An extension to floating point primitives providing approximate equality.
Definition averager.h:21
#include <time.h>