messagequeue.h

00001 /***************************************************************************
00002  *   Copyright (C) 2007 by Rick L. Vinyard, Jr.                            *
00003  *   rvinyard@cs.nmsu.edu                                                  *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation version 2.1.                *
00008  *                                                                         *
00009  *   This program is distributed in the hope that it will be useful,       *
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012  *   GNU General Public License for more details.                          *
00013  *                                                                         *
00014  *   You should have received a copy of the GNU Lesser General Public      *
00015  *   License along with this library; if not, write to the                 *
00016  *   Free Software Foundation, Inc.,                                       *
00017  *   51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA              *
00018  ***************************************************************************/
00019 #ifndef CONEXUSMESSAGEQUEUE_H
00020 #define CONEXUSMESSAGEQUEUE_H
00021 
00022 #include <mqueue.h>
00023 #include <sys/stat.h>
00024 
00025 #include <conexus/endpoint.h>
00026 
00037 namespace Conexus
00038 {
00039 
00048   class MessageQueue : public Endpoint
00049   {
00050     protected:
00051 
00052       MessageQueue( const std::string& name,
00053                     unsigned flags,
00054                     mode_t mode,
00055                     bool close_on_destruction
00056                   );
00057 
00058     public:
00059 
00060       typedef ConexusPointer<MessageQueue> pointer;
00061 
00062       static MessageQueue::pointer create( const std::string& name,
00063                                            unsigned flags=QUEUE_READ|QUEUE_WRITE|QUEUE_CREATE,
00064                                            mode_t mode = S_IRWXU,
00065                                            bool close_on_destruction=true
00066                                          );
00067 
00068       virtual ~MessageQueue();
00069 
00070       virtual void open() throw ( open_exception );
00071 
00072       virtual void close( bool force = false ) throw ( close_exception );
00073 
00074       const std::string& name() const;
00075 
00076       void set_name( const std::string& name );
00077 
00078       unsigned flags() const;
00079 
00080       void set_flags(unsigned flags);
00081 
00082       bool unlink_on_destruction();
00083 
00084       void set_unlink_on_destruction( bool u=true );
00085 
00086       long int max_messages();
00087 
00088       long int max_message_size();
00089 
00090     protected:
00091       std::string m_name;
00092       unsigned m_flags;
00093       bool m_unlink_on_destruction;
00094       long int m_max_messages;
00095       long int m_max_message_size;
00096 
00097       mode_t m_mode;
00098 
00099       mqd_t m_queue;
00100 
00101       virtual ssize_t write_data( long int timeout, const Data data ) throw ( write_exception );
00102 
00103       virtual Data read_data( long int timeout, size_t s = 0 ) throw ( read_exception );
00104   };
00105 
00106 }
00107 
00108 #endif

Generated on Tue Mar 13 19:54:48 2007 by  doxygen 1.5.1