feisty meow concerns codebase  2.140
example_application.cpp
Go to the documentation of this file.
1 // Name : Simple Application Example
3 // Author : Chris Koeritz
5 // Copyright (c) 2006-$now By Author. This program is free software; you can
6 // redistribute it and/or modify it under the terms of the GNU General Public
7 // License as published by the Free Software Foundation:
8 // http://www.gnu.org/licenses/gpl.html
9 // or under the terms of the GNU Library license:
10 // http://www.gnu.org/licenses/lgpl.html
11 // at your preference. Those licenses describe your legal rights to this
12 // software, and no other rights or warranties apply.
13 // Please send updates for this code to: fred@gruntose.com -- Thanks, fred.
15 
17 
25 #include <basis/enhance_cpp.h>
28 #include <unit_test/unit_base.h>
29 
30 using namespace application;
31 using namespace basis;
32 using namespace loggers;
33 //using namespace processes;
34 using namespace structures;
35 using namespace unit_test;
36 
37 const int CHECKING_INTERVAL = 4 * SECOND_ms;
38  // this many milliseconds elapses between checks on shutdown conditions.
39 
40 #define LOG(to_print) CLASS_EMERGENCY_LOG(program_wide_logger().get(), astring(to_print))
41  // define a macro that will send diagnostic output to the app's logger.
42 
44 
45 class application_example : virtual public unit_base, virtual public application_shell
46 {
47 public:
48  application_example();
49  ~application_example();
50 
51  DEFINE_CLASS_NAME("application_example");
52 
53  bool already_running();
55 
56  virtual void handle_timer();
58 
59  virtual void handle_startup();
61 
62  virtual void handle_shutdown();
64 
65  virtual int execute();
67 
68  int print_instructions();
70 
71 private:
72  singleton_application _app_lock;
73 };
74 
76 
77 application_example::application_example()
79  _app_lock(static_class_name())
80 {}
81 
82 application_example::~application_example()
83 {}
84 
86 {
87  FUNCDEF("print_instructions");
88  LOG("no instructions at this time.");
89  return 1;
90 }
91 
92 void application_example::handle_startup()
93 {
94  FUNCDEF("handle_startup");
95  LOG("starting up now.");
96 }
97 
98 void application_example::handle_shutdown()
99 {
100  FUNCDEF("handle_shutdown");
101  LOG("shutting down now.");
102 }
103 
104 void application_example::handle_timer()
105 {
106  FUNCDEF("handle_timer");
107  LOG("timer blip.");
108 }
109 
110 bool application_example::already_running()
111 { return _app_lock.already_running(); }
112 
113 int application_example::execute()
114 {
115  FUNCDEF("execute");
117 
118 //hmmm: test for command line options that are supported.
119 
120  // make sure this app is not running already.
121  if (already_running()) {
122  return 0;
123  }
124 
125 //need anchor window online for this.
126 // anchor_window::launch(*this, GET_INSTANCE_HANDLE(), class_name(), CHECKING_INTERVAL);
127 
128  ASSERT_EQUAL(astring(class_name()), astring("application_example"),
129  "simple application name check");
130 
131  return final_report();
132 }
133 
135 
136 HOOPLE_MAIN(application_example, )
137 
int print_instructions(bool good, const astring &program_name)
Definition: checker.cpp:45
The application_shell is a base object for console programs.
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
Definition: enhance_cpp.h:45
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Definition: enhance_cpp.h:57
const int CHECKING_INTERVAL
#define LOG(to_print)
Provides macros that implement the 'main' program of an application.
#define HOOPLE_MAIN(obj_name, obj_args)
options that should work for most unix and linux apps.
Definition: hoople_main.h:61
Implements an application lock to ensure only one is running at once.
char ** _global_argv
The guards collection helps in testing preconditions and reporting errors.
Definition: array.h:30
const int SECOND_ms
Number of milliseconds in a second.
Definition: definitions.h:120
A logger that sends to the console screen using the standard output device.
A dynamic container class that holds any kind of object via pointers.
Definition: amorph.h:55
Useful support functions for unit testing, especially within hoople.
Definition: unit_base.cpp:35
#define ASSERT_EQUAL(a, b, test_name)
Definition: unit_base.h:38
#define static_class_name()