feisty meow concerns codebase  2.140
processes::post_office Class Reference

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

#include <post_office.h>

Public Member Functions

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

Detailed Description

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

Definition at line 34 of file post_office.h.

Constructor & Destructor Documentation

◆ post_office()

processes::post_office::post_office ( )

Definition at line 153 of file post_office.cpp.

◆ ~post_office()

processes::post_office::~post_office ( )
virtual

stop_serving must be invoked prior to this destructor.

Definition at line 161 of file post_office.cpp.

References stop_serving(), and basis::WHACK().

Member Function Documentation

◆ DEFINE_CLASS_NAME()

processes::post_office::DEFINE_CLASS_NAME ( "post_office"  )

◆ deliver_mail_on_route()

bool processes::post_office::deliver_mail_on_route ( const structures::unique_int route,
ethread 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 283 of file post_office.cpp.

References processes::mailbox::clean_up(), processes::CLEANING_INTERVAL, processes::DELIVERIES_ALLOWED, FUNCDEF, LOG, structures::pack(), processes::mailbox::pick_up(), structures::unique_id< uniquifier >::raw_id(), timely::time_stamp::reset(), processes::ethread::should_stop(), and timely::time_stamp::value().

◆ drop_off()

void processes::post_office::drop_off ( const structures::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 210 of file post_office.cpp.

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

◆ pick_up()

bool processes::post_office::pick_up ( const structures::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 225 of file post_office.cpp.

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

◆ register_route()

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

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

Definition at line 357 of file post_office.cpp.

References processes::thread_cabinet::add_thread(), and NULL_POINTER.

◆ route_listed()

bool processes::post_office::route_listed ( const structures::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 239 of file post_office.cpp.

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

Referenced by drop_off().

◆ show_mail()

void processes::post_office::show_mail ( basis::astring to_fill)

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

Definition at line 196 of file post_office.cpp.

References basis::astring::reset(), processes::mailbox::show(), and basis::astring::t().

◆ show_routes()

void processes::post_office::show_routes ( basis::astring to_fill)

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

Definition at line 170 of file post_office.cpp.

References basis::astring::length(), and basis::astring::reset().

◆ stop_serving()

void processes::post_office::stop_serving ( )

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

Definition at line 194 of file post_office.cpp.

References processes::thread_cabinet::stop_all().

Referenced by ~post_office().

◆ unregister_route()

bool processes::post_office::unregister_route ( const structures::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 377 of file post_office.cpp.

References processes::thread_cabinet::zap_thread().


The documentation for this class was generated from the following files: