00001 /*****************************************************************************\ 00002 * * 00003 * Name : Simple Application Example * 00004 * Author : Chris Koeritz * 00005 * * 00006 ******************************************************************************* 00007 * Copyright (c) 2006-$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 00016 00021 #include <opsystem/application_shell.h> 00022 #include <opsystem/command_line.h> 00023 #include <loggers/console_logger.h> 00024 #include <loggers/file_logger.h> 00025 #include <opsystem/singleton_application.h> 00026 #include <data_struct/static_memory_gremlin.h> 00027 #include <processes/anchor_window.h> 00028 00029 const int CHECKING_INTERVAL = 4 * SECOND_ms; 00030 // this many milliseconds elapses between checks on shutdown conditions. 00031 00032 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger(), s) 00033 // define a macro that will send diagnostic output to the app's logger. 00034 00036 00037 class application_example 00038 : public application_shell, // base this application on our console version. 00039 public anchor_window // support graceful shut down in this application. 00040 { 00041 public: 00042 application_example(); 00043 ~application_example(); 00044 00045 IMPLEMENT_CLASS_NAME("application_example"); 00046 00047 bool already_running(); 00049 00050 virtual void handle_timer(); 00052 00053 virtual void handle_startup(); 00055 00056 virtual void handle_shutdown(); 00058 00059 virtual int execute(); 00061 00062 void print_instructions(); 00064 00065 private: 00066 singleton_application _app_lock; 00067 }; 00068 00070 00071 application_example::application_example() 00072 : application_shell(static_class_name()), 00073 _app_lock(static_class_name()) 00074 {} 00075 00076 application_example::~application_example() 00077 {} 00078 00079 void application_example::handle_startup() 00080 { 00081 FUNCDEF("handle_startup"); 00082 LOG("starting up now."); 00083 } 00084 00085 void application_example::handle_shutdown() 00086 { 00087 FUNCDEF("handle_shutdown"); 00088 LOG("shutting down now."); 00089 } 00090 00091 void application_example::handle_timer() 00092 { 00093 FUNCDEF("handle_timer"); 00094 LOG("timer blip."); 00095 } 00096 00097 bool application_example::already_running() 00098 { return _app_lock.already_running(); } 00099 00100 int application_example::execute() 00101 { 00102 FUNCDEF("execute"); 00103 command_line cmds(__argc, __argv); 00104 00105 //hmmm: test for command line options that are supported. 00106 00107 // make sure this app is not running already. 00108 if (already_running()) { 00109 return 0; 00110 } 00111 00112 anchor_window::launch(*this, GET_INSTANCE_HANDLE(), class_name(), 00113 CHECKING_INTERVAL); 00114 00115 return 0; 00116 } 00117 00119 00120 HOOPLE_MAIN(application_example, ) 00121 00122 #ifdef __BUILD_STATIC_APPLICATION__ 00123 // static dependencies found by buildor_gen_deps.sh: 00124 #include <basis/array.cpp> 00125 #include <basis/byte_array.cpp> 00126 #include <basis/callstack_tracker.cpp> 00127 #include <basis/chaos.cpp> 00128 #include <basis/convert_utf.cpp> 00129 #include <basis/definitions.cpp> 00130 #include <basis/earth_time.cpp> 00131 #include <basis/guards.cpp> 00132 #include <basis/istring.cpp> 00133 #include <basis/log_base.cpp> 00134 #include <basis/memory_checker.cpp> 00135 #include <basis/mutex.cpp> 00136 #include <basis/object_base.cpp> 00137 #include <basis/outcome.cpp> 00138 #include <basis/packable.cpp> 00139 #include <basis/portable.cpp> 00140 #include <basis/sequence.cpp> 00141 #include <basis/set.cpp> 00142 #include <basis/utility.cpp> 00143 #include <basis/version_record.cpp> 00144 #include <data_struct/amorph.cpp> 00145 #include <data_struct/bit_vector.cpp> 00146 #include <data_struct/byte_hasher.cpp> 00147 #include <data_struct/configurator.cpp> 00148 #include <data_struct/hash_table.cpp> 00149 #include <data_struct/pointer_hash.cpp> 00150 #include <data_struct/stack.cpp> 00151 #include <data_struct/static_memory_gremlin.cpp> 00152 #include <data_struct/string_hash.cpp> 00153 #include <data_struct/string_hasher.cpp> 00154 #include <data_struct/string_table.cpp> 00155 #include <data_struct/symbol_table.cpp> 00156 #include <data_struct/table_configurator.cpp> 00157 #include <loggers/console_logger.cpp> 00158 #include <loggers/file_logger.cpp> 00159 #include <loggers/locked_logger.cpp> 00160 #include <loggers/null_logger.cpp> 00161 #include <loggers/program_wide_logger.cpp> 00162 #include <mechanisms/ithread.cpp> 00163 #include <mechanisms/time_stamp.cpp> 00164 #include <opsystem/application_base.cpp> 00165 #include <opsystem/application_shell.cpp> 00166 #include <opsystem/byte_filer.cpp> 00167 #include <opsystem/command_line.cpp> 00168 #include <opsystem/critical_events.cpp> 00169 #include <opsystem/directory.cpp> 00170 #include <opsystem/filename.cpp> 00171 #include <opsystem/ini_config.cpp> 00172 #include <opsystem/ini_parser.cpp> 00173 #include <opsystem/path_configuration.cpp> 00174 #include <opsystem/rendezvous.cpp> 00175 #include <opsystem/singleton_application.cpp> 00176 #include <opsystem/timer_driver.cpp> 00177 #include <processes/anchor_window.cpp> 00178 #include <processes/process_control.cpp> 00179 #include <processes/process_entry.cpp> 00180 #include <processes/shutdown_alerter.cpp> 00181 #include <textual/byte_format.cpp> 00182 #include <textual/parser_bits.cpp> 00183 #include <textual/string_manipulation.cpp> 00184 #include <textual/tokenizer.cpp> 00185 #endif // __BUILD_STATIC_APPLICATION__ 00186
1.5.1