feisty meow concerns codebase  2.140
launch_manager.h
Go to the documentation of this file.
1 
2 // current bad issues:
3 //
4 // this class does not really provide a notion of the process name AND process id as being
5 // a pair one can operate on. mostly it assumes a bunch of singletons or that it's okay
6 // to whack all of them.
7 // that could be fixed by making the procname+procid pair into a unit in all functions,
8 // and make kill_all be a specialization of that.
9 
10 
11 #ifndef LAUNCH_MANAGER_CLASS
12 #define LAUNCH_MANAGER_CLASS
13 
14 /*****************************************************************************\
15 * *
16 * Name : launch_manager
17 * Author : Chris Koeritz
18 * *
19 *******************************************************************************
20 * Copyright (c) 2000-$now By Author. This program is free software; you can *
21 * redistribute it and/or modify it under the terms of the GNU General Public *
22 * License as published by the Free Software Foundation; either version 2 of *
23 * the License or (at your option) any later version. This is online at: *
24 * http://www.fsf.org/copyleft/gpl.html *
25 * Please send any updates to: fred@gruntose.com *
26 \*****************************************************************************/
27 
28 #include <basis/astring.h>
29 #include <basis/mutex.h>
30 #include <basis/outcome.h>
31 #include <basis/contracts.h>
35 #include <structures/set.h>
36 #include <timely/time_stamp.h>
37 
38 namespace application {
39 
40 class graceful_array;
41 class launch_manager_thread;
42 
44 
49 class launch_manager : public virtual basis::root_object
50 {
51 public:
54 
55  virtual ~launch_manager();
56 
57  DEFINE_CLASS_NAME("launch_manager");
58 
59  enum outcomes {
60  OKAY = basis::common::OKAY,
61  EXISTING = basis::common::EXISTING,
63  ACCESS_DENIED = basis::common::ACCESS_DENIED,
65 
66  DEFINE_API_OUTCOME(FILE_NOT_FOUND, -53, "The file specified for the "
67  "application doesn't exist, as far as we can tell"),
68  DEFINE_API_OUTCOME(NO_PRODUCT, -54, "The product specified does not exist"),
69  DEFINE_API_OUTCOME(NO_APPLICATION, -55, "The application is not listed for "
70  "the product"),
71  DEFINE_API_OUTCOME(NOT_RUNNING, -56, "The program is not currently active, "
72  "according to the OS process list"),
73  DEFINE_API_OUTCOME(BAD_PROGRAM, -57, "The file existed but doesn't appear "
74  "to be a valid program image"),
75  DEFINE_API_OUTCOME(NO_ANCHOR, -58, "This occurs when the graceful shutdown "
76  "process cannot find the special anchor window that implements the "
77  "client side of a graceful shutdown"),
78  DEFINE_API_OUTCOME(LAUNCH_FAILED, -59, "The program existed and seemed "
79  "valid but its launch failed for some reason"),
80  DEFINE_API_OUTCOME(FROZEN, -60, "The application is broken somehow; the "
81  "system reports it as non-responsive"),
82  // note that these values are reversed, since the ordering is negative.
83  FIRST_OUTCOME = FROZEN, // hold onto start of range.
84  LAST_OUTCOME = FILE_NOT_FOUND // hold onto end of range.
85  };
86 
87  static const char *outcome_name(const basis::outcome &to_name);
89 
90  basis::outcome launch_now(const basis::astring &product, const basis::astring &app_name,
91  const basis::astring &parameters);
93 
98  basis::outcome launch_at_startup(const basis::astring &product, const basis::astring &app_name,
99  const basis::astring &parameters, int one_shot);
101 
104  basis::outcome remove_from_startup(const basis::astring &product, const basis::astring &app_name);
106 
107  basis::outcome query_application(const basis::astring &product, const basis::astring &app_name);
109 
110  basis::outcome zap_process(const basis::astring &product, const basis::astring &app_name,
111  bool graceful);
113 
116  void add_gag_exclusion(const basis::astring &exclusion);
118 
120  void add_tracking_exclusion(const basis::astring &exclusion);
122 
127 
134 
136  bool services_disabled() const { return _stop_launching; }
138 
141 
144  void stop_everything();
146 
147 private:
149  bool _started_initial_apps;
150  launch_manager_thread *_checker;
151  basis::mutex *_config_lock;
152  graceful_array *_going_down;
153  basis::mutex *_zombie_lock;
154  graceful_array *_our_kids;
155  basis::mutex *_scamp_lock;
156  bool _stop_launching;
157  timely::time_stamp *_startup_time;
159 
162  structures::string_set *_gag_exclusions;
163  structures::string_set *_tracking_exclusions;
164 
165  bool get_processes(processes::process_entry_array &processes);
167 
168  bool find_process(const basis::astring &app_name, structures::int_set &pids);
170 
171  basis::outcome start_graceful_close(const basis::astring &product, const basis::astring &app_name);
173 
176  void launch_startup_apps();
178 
179  void stop_all_kids();
181 };
182 
183 } //namespace.
184 
185 #endif
186 
Provides methods for starting, stopping and checking on processes.
basis::outcome launch_now(const basis::astring &product, const basis::astring &app_name, const basis::astring &parameters)
starts the application "app_name" now.
basis::outcome query_application(const basis::astring &product, const basis::astring &app_name)
retrieves the current state of the program with "app_name".
basis::outcome shut_down_launching_services(const basis::astring &secret_word)
closes down the ability of clients to launch applications.
void add_gag_exclusion(const basis::astring &exclusion)
add an application that isn't subject to gagging.
launch_manager(processes::configured_applications &config)
the launch_manager needs a configuration set to work with.
static const char * outcome_name(const basis::outcome &to_name)
returns the text associated with "to_name".
DEFINE_CLASS_NAME("launch_manager")
void stop_everything()
closes down the operation of this object.
bool services_disabled() const
returns true if the capability to launch new processes is revoked.
basis::outcome launch_at_startup(const basis::astring &product, const basis::astring &app_name, const basis::astring &parameters, int one_shot)
records an entry for the "app_name" to be launched at startup.
basis::outcome zap_process(const basis::astring &product, const basis::astring &app_name, bool graceful)
zaps the process named "app_name".
@ EXISTING
the entry already exists and overwriting is disallowed.
@ ACCESS_DENIED
the requested operation was not permitted.
void push_timed_activities(processes::process_entry_array &processes)
keeps any periodic activities going.
void add_tracking_exclusion(const basis::astring &exclusion)
apps that aren't tracked when running.
basis::outcome reenable_launching_services(const basis::astring &secret_word)
undoes the gagging that the above "shut_down" function does.
basis::outcome remove_from_startup(const basis::astring &product, const basis::astring &app_name)
takes the "app_name" out of the startup list.
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
Outcomes describe the state of completion for an operation.
Definition: outcome.h:31
Manages the initialization file for a set of registered applications.
Provides a bridge to the operating system for information on processes.
a handy class that implements an array of process entries.
Definition: process_entry.h:60
A simple object that wraps a templated set of ints.
Definition: set.h:156
A simple object that wraps a templated set of strings.
Definition: set.h:168
Represents a point in time relative to the operating system startup time.
Definition: time_stamp.h:38
Implements an application lock to ensure only one is running at once.