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
22
#include <
application/hoople_main.h
>
23
#include <
application/command_line.h
>
24
#include <
application/singleton_application.h
>
25
#include <
basis/enhance_cpp.h
>
26
#include <
loggers/program_wide_logger.h
>
27
#include <
structures/static_memory_gremlin.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()
78
:
application_shell
(),
79
_app_lock(
static_class_name
())
80
{}
81
82
application_example::~application_example()
83
{}
84
85
int
application_example::print_instructions
()
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"
);
116
command_line
cmds(
_global_argc
,
_global_argv
);
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
print_instructions
int print_instructions(bool good, const astring &program_name)
Definition:
checker.cpp:45
application::application_shell
The application_shell is a base object for console programs.
Definition:
application_shell.h:33
application::command_line
Definition:
command_line.h:87
application::singleton_application
Definition:
singleton_application.h:33
basis::astring
Provides a dynamically resizable ASCII character string.
Definition:
astring.h:35
unit_test::unit_base
Definition:
unit_base.h:59
command_line.h
enhance_cpp.h
DEFINE_CLASS_NAME
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
Definition:
enhance_cpp.h:45
FUNCDEF
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Definition:
enhance_cpp.h:57
CHECKING_INTERVAL
const int CHECKING_INTERVAL
Definition:
example_application.cpp:37
LOG
#define LOG(to_print)
Definition:
example_application.cpp:40
hoople_main.h
Provides macros that implement the 'main' program of an application.
HOOPLE_MAIN
#define HOOPLE_MAIN(obj_name, obj_args)
options that should work for most unix and linux apps.
Definition:
hoople_main.h:61
application
Implements an application lock to ensure only one is running at once.
Definition:
application_shell.cpp:40
application::_global_argc
int _global_argc
application::_global_argv
char ** _global_argv
basis
The guards collection helps in testing preconditions and reporting errors.
Definition:
array.h:30
basis::SECOND_ms
const int SECOND_ms
Number of milliseconds in a second.
Definition:
definitions.h:120
loggers
A logger that sends to the console screen using the standard output device.
Definition:
combo_logger.cpp:36
structures
A dynamic container class that holds any kind of object via pointers.
Definition:
amorph.h:55
unit_test
Useful support functions for unit testing, especially within hoople.
Definition:
unit_base.cpp:35
program_wide_logger.h
singleton_application.h
static_memory_gremlin.h
unit_base.h
ASSERT_EQUAL
#define ASSERT_EQUAL(a, b, test_name)
Definition:
unit_base.h:38
static_class_name
#define static_class_name()
Definition:
windoze_helper.cpp:51
nucleus
applications
example_application
example_application.cpp
Generated by
1.9.1