first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / core / applications / example_application / example_application.cpp
1 //////////////
2 // Name   : Simple Application Example
3 // Author : Chris Koeritz
4 //////////////
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.
14 //////////////
15
16 //! An example of a bare-bones hoople application.
17 /*!
18   This application provides a very simple example for how we create programs
19   based on the HOOPLE code.
20 */
21
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
43 //////////////
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();
54     //!< true if this program is already running.
55
56   virtual void handle_timer();
57     //!< called by timer events from anchor window.
58
59   virtual void handle_startup();
60     //!< begins our service's activity.
61
62   virtual void handle_shutdown();
63     //!< catches the graceful shutdown so our objects get closed normally.
64
65   virtual int execute();
66     //!< the root of the program's activity.
67
68   void print_instructions();
69     //!< describes the available command line options for the ULS.
70
71 private:
72   singleton_application _app_lock;  //!< our inter-application synchronizer.
73 };
74
75 //////////////
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 void application_example::handle_startup()
86 {
87   FUNCDEF("handle_startup");
88   LOG("starting up now.");
89 }
90
91 void application_example::handle_shutdown()
92 {
93   FUNCDEF("handle_shutdown");
94   LOG("shutting down now.");
95 }
96
97 void application_example::handle_timer()
98 {
99   FUNCDEF("handle_timer");
100   LOG("timer blip.");
101 }
102
103 bool application_example::already_running()
104 { return _app_lock.already_running(); }
105
106 int application_example::execute()
107 {
108   FUNCDEF("execute");
109   command_line cmds(_global_argc, _global_argv);
110
111 //hmmm: test for command line options that are supported.
112
113   // make sure this app is not running already.
114   if (already_running()) {
115     return 0;
116   }
117
118 //need anchor window online for this.
119 //  anchor_window::launch(*this, GET_INSTANCE_HANDLE(), class_name(), CHECKING_INTERVAL);
120
121   ASSERT_EQUAL(astring(class_name()), astring("application_example"),
122       "simple application name check");
123
124   return final_report();
125 }
126
127 //////////////
128
129 HOOPLE_MAIN(application_example, )
130