Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

PostOffice.h

Go to the documentation of this file.
00001 //=============================================================================
00002 // PostOffice.h
00003 //
00004 //  This code is released under the GPL
00005 // Created 5/13/03 By Daniel Larimer
00006 //=============================================================================
00007 #ifndef _POSTOFFICE_H_
00008 #define _POSTOFFICE_H_
00009 #include<qobject.h>
00010 #include<map>
00011 #include<vector>
00012 #include<string>
00013 #include<POAddress.h>
00014 #include<POBox.h>
00015 
00016 using namespace std;
00017 class POServer;
00018 class POClient;
00019 class POGroup;
00020 class POMessage;
00021 
00022 class PEXPR_API PostOffice : public QObject
00023 {
00024     Q_OBJECT
00025     public:
00026         PostOffice( const string& name );
00027         ~PostOffice();
00028 
00029         POClient*              getClient(const string& cname)const;
00030         POBox*                 getPOBox( const string& boxname )const;
00031         POGroup*               getGroup( const string& name, 
00032                                           bool create = true,
00033                                           bool throw_exception = true );
00034         map<string, POClient*> getAllClients()const;
00035         map<string, POBox*>    getAllBoxes()const { return m_localboxes; }
00036         
00037         string                 getName()const { return m_poname; }
00038         const POMessage*       popMessage( const string& pobox_name );
00039         bool                   hasMessage( const string& pobox_name );
00040 
00041         static map<string, PostOffice*> getAllPostOffices();
00042         static PostOffice*              getPostOffice( const string& name );
00043         
00044     public slots:
00045         string   connectTo( const string& host, int port, bool block = true );
00046         bool     servicePort( int port );
00047         void     closePort( int port );
00048 
00049         void     addAddressToGroup( const POAddress& adr, 
00050                                     const POAddress& group );
00051         void     removeAddressFromGroup( const POAddress& adr, 
00052                                          const POAddress& group );
00053         
00054         POBox*   registerPOBox( const string& name );
00055         POGroup* registerGroup( const string& name, 
00056                                 bool throw_exception = true );
00057         bool     closeGroup( const string& name );
00058         bool     closePOBox( const string& name, bool dodelete = false );
00059         
00060         
00061         void connectClient     ( POClient* client );
00062         void addConnectedClient( POClient* client );
00063         bool sendMessage( const POMessage* msg, bool throw_exception = true );
00064         void sendMessage( POMessage* msg, const string& from, 
00065                                           const POAddress& to );
00066 
00067         void newClientPOBox( const string& cname, const string& boxname );
00068     
00069     signals:
00070         void newClient( const string& poname, const string& cname );
00071         void newPOBox( const string& poname, const string& cname, 
00072                        const string& boxname );
00073         void newPOBox( const string& poname, const string& boxname );
00074         void clientClosed( const string& poname, const string& cname );
00075         void portClosed( int port );
00076         void portOpened( int port );
00077 
00078         
00079     private slots:
00080         bool deliverMessage( const POMessage* msg );
00081         void closeConnection( POClient* client );
00082         
00083     private:
00084         string                    m_poname;
00085         map<int, POServer*>       m_servers;
00086         map<string, POClient*>    m_clients;
00087         map<string, POBox*>       m_localboxes;
00088         map<string, POGroup*>     m_groups;
00089 
00090         static map<string, PostOffice*> m_postoffices;
00091 };
00092 
00093 #endif

Generated on Tue Jun 15 12:49:28 2004 for pexpr by doxygen 1.3.4