feisty meow concerns codebase  2.140
mailbox.h
Go to the documentation of this file.
1 #ifndef MAILBOX_CLASS
2 #define MAILBOX_CLASS
3 
4 /*****************************************************************************\
5 * *
6 * Name : mailbox *
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 <basis/mutex.h>
19 #include <structures/set.h>
20 #include <structures/unique_id.h>
21 
22 namespace processes {
23 
24 class letter;
25 class mailbox_bank;
26 
28 
36 class mailbox : public virtual basis::root_object
37 {
38 public:
39  mailbox();
40  virtual ~mailbox();
41 
42  void drop_off(const structures::unique_int &id, letter *package);
44 
49  bool pick_up(const structures::unique_int &id, letter * &package);
51 
60  int waiting(const structures::unique_int &id) const;
62 
63  void get_ids(structures::int_set &to_fill);
65 
68  bool close_out(const structures::unique_int &id);
70 
75  void show(basis::astring &to_fill);
77 
79  void clean_up();
81 
82  void limit_boxes(int max_letters);
84 
91  OKAY = basis::common::OKAY,
92 
93  DEFINE_OUTCOME(APPLY_STOP, -46, "Halt the apply process"),
94  DEFINE_OUTCOME(APPLY_WHACK, -47, "Removes the current letter, but "
95  "continues"),
96  DEFINE_OUTCOME(APPLY_WHACK_STOP, -48, "Halts apply and trashes the "
97  "current letter")
98  };
99 
100  typedef basis::outcome apply_function(letter &current, int uid, void *data_link);
102 
111  void apply(apply_function *to_apply, void *data_link);
113 
119 private:
120  basis::mutex *_transaction_lock;
121  mailbox_bank *_packages;
122 
123  // prohibited.
124  mailbox(const mailbox &);
125  mailbox &operator =(const mailbox &);
126 };
127 
128 } //namespace.
129 
130 #endif
131 
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
Outcomes describe the state of completion for an operation.
Definition: outcome.h:31
A virtual base class for pieces of "mail". Used by the mailbox object.
Definition: letter.h:25
Implements a thread safe "mail" delivery system.
Definition: mailbox.h:37
void get_ids(structures::int_set &to_fill)
stuffs the set "to_fill" with the ids of all mailboxes present.
Definition: mailbox.cpp:160
void drop_off(const structures::unique_int &id, letter *package)
drops a "package" in the mailbox for "id".
Definition: mailbox.cpp:166
int waiting(const structures::unique_int &id) const
returns the number of items waiting for the "id" specified, if any.
Definition: mailbox.cpp:178
basis::outcome apply_function(letter &current, int uid, void *data_link)
the "apply_function" is what a user of apply() must provide.
Definition: mailbox.h:100
bool pick_up(const structures::unique_int &id, letter *&package)
returns true if the mailbox for "id" had a "package" to be delivered.
Definition: mailbox.cpp:189
virtual ~mailbox()
Definition: mailbox.cpp:154
bool close_out(const structures::unique_int &id)
dumps all packages stored for the "id" and shuts down its mailbox.
Definition: mailbox.cpp:196
void clean_up()
removes any empty mailboxes from our list.
Definition: mailbox.cpp:172
void show(basis::astring &to_fill)
provides a picture of what's waiting in the mailbox.
Definition: mailbox.cpp:203
void limit_boxes(int max_letters)
establishes a limit on the number of letters.
Definition: mailbox.cpp:223
void apply(apply_function *to_apply, void *data_link)
calls the "to_apply" function on possibly every letter in the mailbox.
Definition: mailbox.cpp:237
@ OKAY
continue apply process.
Definition: mailbox.h:91
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