2 // 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.
16 //! An example of a bare-bones hoople application.
18 This application provides a very simple example for how we create programs
19 based on the HOOPLE code.
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>
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;
37 const int CHECKING_INTERVAL = 4 * SECOND_ms;
38 // this many milliseconds elapses between checks on shutdown conditions.
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.
45 class application_example : virtual public unit_base, virtual public application_shell
48 application_example();
49 ~application_example();
51 DEFINE_CLASS_NAME("application_example");
53 bool already_running();
54 //!< true if this program is already running.
56 virtual void handle_timer();
57 //!< called by timer events from anchor window.
59 virtual void handle_startup();
60 //!< begins our service's activity.
62 virtual void handle_shutdown();
63 //!< catches the graceful shutdown so our objects get closed normally.
65 virtual int execute();
66 //!< the root of the program's activity.
68 int print_instructions();
69 //!< describes the available command line options for this program.
72 singleton_application _app_lock; //!< our inter-application synchronizer.
77 application_example::application_example()
78 : application_shell(),
79 _app_lock(static_class_name())
82 application_example::~application_example()
85 int application_example::print_instructions()
87 FUNCDEF("print_instructions");
88 LOG("no instructions at this time.");
92 void application_example::handle_startup()
94 FUNCDEF("handle_startup");
95 LOG("starting up now.");
98 void application_example::handle_shutdown()
100 FUNCDEF("handle_shutdown");
101 LOG("shutting down now.");
104 void application_example::handle_timer()
106 FUNCDEF("handle_timer");
110 bool application_example::already_running()
111 { return _app_lock.already_running(); }
113 int application_example::execute()
116 command_line cmds(_global_argc, _global_argv);
118 //hmmm: test for command line options that are supported.
120 // make sure this app is not running already.
121 if (already_running()) {
125 //need anchor window online for this.
126 // anchor_window::launch(*this, GET_INSTANCE_HANDLE(), class_name(), CHECKING_INTERVAL);
128 ASSERT_EQUAL(astring(class_name()), astring("application_example"),
129 "simple application name check");
131 return final_report();
136 HOOPLE_MAIN(application_example, )