post_office Class Reference

Manages a collection of mailboxes and implements delivery routes for mail. More...

#include <post_office.h>

Collaboration diagram for post_office:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 post_office ()
virtual ~post_office ()
 stop_serving must be invoked prior to this destructor.
void stop_serving ()
 gets the mailbox to stop delivering items prior to a shutdown.
 IMPLEMENT_CLASS_NAME ("post_office")
void show_mail (istring &to_fill)
 prints a snapshot of all currently pending letters into "to_fill".
void show_routes (istring &to_fill)
 writes a listing of the current routes into "to_fill".
void drop_off (const unique_int &id, letter *package)
 sends a "package" on its way to the "id" via the registered route.
bool pick_up (const unique_int &id, letter *&package)
 retrieves a "package" intended for the "id" if one exists.
bool register_route (const unique_int &id, mail_stop &carrier_path)
 registers a route "carrier_path" for mail deliveries to the "id".
bool unregister_route (const unique_int &id)
 removes a route for the "id".
bool route_listed (const unique_int &id)
 returns true if there is a route listed for the "id".
bool deliver_mail_on_route (const unique_int &route, ithread &carrier)
 for internal use only--delivers the letters to known routes.

Detailed Description

Manages a collection of mailboxes and implements delivery routes for mail.

Definition at line 32 of file post_office.h.


Constructor & Destructor Documentation

post_office::post_office (  ) 

Definition at line 122 of file post_office.cpp.

post_office::~post_office (  )  [virtual]

stop_serving must be invoked prior to this destructor.

Definition at line 131 of file post_office.cpp.

References stop_serving(), and WHACK().


Member Function Documentation

void post_office::stop_serving (  ) 

gets the mailbox to stop delivering items prior to a shutdown.

Definition at line 168 of file post_office.cpp.

References thread_cabinet::stop_all().

Referenced by ~post_office().

post_office::IMPLEMENT_CLASS_NAME ( "post_office"   ) 

void post_office::show_mail ( istring to_fill  ) 

prints a snapshot of all currently pending letters into "to_fill".

Definition at line 170 of file post_office.cpp.

References log_base::platform_ending(), istring::reset(), mailbox::show(), istring::t(), and utility::timestamp().

void post_office::show_routes ( istring to_fill  ) 

writes a listing of the current routes into "to_fill".

Definition at line 141 of file post_office.cpp.

References nodes::objcat_iterator::cat(), nodes::objcat_iterator::is_tail(), istring::length(), nodes::objcat_iterator::next(), log_base::platform_ending(), istring::reset(), and istring::SPRINTF.

void post_office::drop_off ( const unique_int id,
letter package 
)

sends a "package" on its way to the "id" via the registered route.

note that mail is not rejected if there is no known route to the mail_stop for the "id"; it is assumed in that case that the recipient will check at the post office.

Definition at line 184 of file post_office.cpp.

References mailbox::drop_off(), FUNCDEF, LOG, route_listed(), istring::SPRINTF, and letter::text_form().

bool post_office::pick_up ( const unique_int id,
letter *&  package 
)

retrieves a "package" intended for the "id" if one exists.

false is returned if none are available. on success, the "package" is filled in with the address of the package and it is the caller's responsibility to destroy or recycle() it after dealing with it.

Definition at line 199 of file post_office.cpp.

References FUNCDEF, LOG, mailbox::pick_up(), istring::SPRINTF, and letter::text_form().

bool post_office::register_route ( const unique_int id,
mail_stop carrier_path 
)

registers a route "carrier_path" for mail deliveries to the "id".

Definition at line 352 of file post_office.cpp.

References thread_cabinet::add_thread(), and NIL.

bool post_office::unregister_route ( const unique_int id  ) 

removes a route for the "id".

this should be done before the object's destructor is invoked since the letter carrier could be on his way with a letter at an arbitrary time. also, the mail_stop should be shut down (with end_availability()) at that time also. if those steps are taken, then the carrier is guaranteed not to bother the recipient.

Definition at line 372 of file post_office.cpp.

References nodes::objcat_iterator::cat(), and thread_cabinet::zap_thread().

bool post_office::route_listed ( const unique_int id  ) 

returns true if there is a route listed for the "id".

this could change at any moment, since another place in the source code could remove the route just after this call. it is information from the past by the time it's returned.

Definition at line 211 of file post_office.cpp.

References basis::set< contents >::member().

Referenced by drop_off().

bool post_office::deliver_mail_on_route ( const unique_int route,
ithread carrier 
)

for internal use only--delivers the letters to known routes.

this function should only be used internally to prompt the delivery of packages that are waiting for objects we have a route to. it returns true when all items that were waiting have been sent.

Definition at line 255 of file post_office.cpp.

References nodes::objcat_isolater::cat(), mailbox::clean_up(), CLEANING_INTERVAL, DELIVERIES_ALLOWED, FUNCDEF, LOG, pack(), mailbox::pick_up(), unique_id< uniquifier >::raw_id(), time_stamp::reset(), ithread::should_stop(), istring::SPRINTF, and time_stamp::value().


The documentation for this class was generated from the following files:
Generated on Fri Nov 28 04:30:55 2008 for HOOPLE Libraries by  doxygen 1.5.1