feisty meow concerns codebase  2.140
post_office.h
Go to the documentation of this file.
1 #ifndef CENTRAL_MAILBOX_CLASS
2 #define CENTRAL_MAILBOX_CLASS
3 
4 /*****************************************************************************\
5 * *
6 * Name : post_office *
7 * Author : Chris Koeritz *
8 * *
9 *******************************************************************************
10 * Copyright (c) 1998-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
17 
18 #include "mail_stop.h"
19 
20 #include <processes/ethread.h>
21 #include <timely/time_stamp.h>
22 
23 namespace processes {
24 
25 class letter;
26 class letter_morph;
27 class mailbox;
28 class postal_cache;
29 class route_map;
30 class thread_cabinet;
31 
33 
35 {
36 public:
37  post_office();
38 
39  virtual ~post_office();
41 
42  void stop_serving();
44 
45  // informational functions...
46 
47  DEFINE_CLASS_NAME("post_office");
48 
49  void show_mail(basis::astring &to_fill);
51 
52  void show_routes(basis::astring &to_fill);
54 
55  // general delivery services subject to the constraints of the mailbox class.
56 
57  void drop_off(const structures::unique_int &id, letter *package);
59 
63  bool pick_up(const structures::unique_int &id, letter * &package);
65 
70 
71  // mail delivery and routing support.
72 
73  bool register_route(const structures::unique_int &id, mail_stop &carrier_path);
75 
78 
84  bool route_listed(const structures::unique_int &id);
86 
91 
92  bool deliver_mail_on_route(const structures::unique_int &route, ethread &carrier);
94 
98 private:
99  basis::mutex c_mutt;
100  mailbox *_post;
101  route_map *_routes;
102  timely::time_stamp *_next_cleaning;
103  thread_cabinet *_threads;
104 
105  void get_route_list(structures::int_set &route_set);
107 
108  void clean_package_list(post_office &post, letter_morph &to_clean);
110 };
111 
112 } //namespace.
113 
114 #endif
115 
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
Provides a platform-independent object for adding threads to a program.
Definition: ethread.h:36
A virtual base class for pieces of "mail". Used by the mailbox object.
Definition: letter.h:25
Base class for routes on which letters are automatically delivered.
Definition: mail_stop.h:34
Implements a thread safe "mail" delivery system.
Definition: mailbox.h:37
Manages a collection of mailboxes and implements delivery routes for mail.
Definition: post_office.h:35
bool pick_up(const structures::unique_int &id, letter *&package)
retrieves a "package" intended for the "id" if one exists.
DEFINE_CLASS_NAME("post_office")
bool register_route(const structures::unique_int &id, mail_stop &carrier_path)
registers a route "carrier_path" for mail deliveries to the "id".
bool unregister_route(const structures::unique_int &id)
removes a route for the "id".
virtual ~post_office()
stop_serving must be invoked prior to this destructor.
void show_routes(basis::astring &to_fill)
writes a listing of the current routes into "to_fill".
void show_mail(basis::astring &to_fill)
prints a snapshot of all currently pending letters into "to_fill".
void stop_serving()
gets the mailbox to stop delivering items prior to a shutdown.
void drop_off(const structures::unique_int &id, letter *package)
sends a "package" on its way to the "id" via the registered route.
bool route_listed(const structures::unique_int &id)
returns true if there is a route listed for the "id".
bool deliver_mail_on_route(const structures::unique_int &route, ethread &carrier)
for internal use only–delivers the letters to known routes.
Manages a collection of threads.
A simple object that wraps a templated set of ints.
Definition: set.h:156
A unique identifier based on integers.
Definition: unique_id.h:97
Represents a point in time relative to the operating system startup time.
Definition: time_stamp.h:38