00001 /*************************************************************************** 00002 * Copyright (C) 2007 by Rick L. Vinyard, Jr. * 00003 * rvinyard@cs.nmsu.edu * 00004 * * 00005 * This file is part of the conexus library. * 00006 * * 00007 * The conexus library is free software; you can redistribute it and/or * 00008 * modify it under the terms of the GNU General Public License * 00009 * version 3 as published by the Free Software Foundation. * 00010 * * 00011 * The conexus library is distributed in the hope that it will be * 00012 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * 00013 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00014 * General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU General Public License * 00017 * along with this software. If not see <http://www.gnu.org/licenses/>. * 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 00035 namespace Conexus 00036 { 00037 00047 class MessageQueue : public Endpoint 00048 { 00049 protected: 00050 00051 MessageQueue( const std::string& name, 00052 unsigned flags, 00053 mode_t mode, 00054 bool close_on_destruct 00055 ); 00056 00057 public: 00058 00059 typedef ConexusPointer<MessageQueue> pointer; 00060 00061 CONEXUS_ENDPOINT_GENERIC_CREATE(); 00062 00063 static MessageQueue::pointer create( const std::string& name=std::string(), 00064 unsigned flags=QUEUE_READ|QUEUE_WRITE|QUEUE_CREATE, 00065 mode_t mode = S_IRWXU, 00066 bool close_on_destruct=true 00067 ); 00068 00069 virtual ~MessageQueue(); 00070 00071 virtual void open() throw ( open_exception ); 00072 00073 virtual void close( bool force = false ) throw ( close_exception ); 00074 00075 const std::string& name() const; 00076 00077 void set_name( const std::string& name ); 00078 00079 unsigned flags() const; 00080 00081 void set_flags(unsigned flags); 00082 00083 bool unlink_on_destruction(); 00084 00085 void set_unlink_on_destruction( bool u=true ); 00086 00087 long int max_messages(); 00088 00089 long int max_message_size(); 00090 00091 protected: 00092 std::string m_name; 00093 unsigned m_flags; 00094 bool m_unlink_on_destruction; 00095 long int m_max_messages; 00096 long int m_max_message_size; 00097 00098 mode_t m_mode; 00099 00100 mqd_t m_queue; 00101 00102 virtual size_t write_data( const Data data, Timeout timeout ) throw ( write_exception ); 00103 00104 virtual Data read_data( size_t size, Timeout timeout ) throw ( read_exception ); 00105 }; 00106 00107 } 00108 00109 #endif