File indexing completed on 2024-04-28 16:59:42
0001 /* 0002 Copyright (C) 2014 Andreas Hartmetz <ahartmetz@gmail.com> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LGPL. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 0019 Alternatively, this file is available under the Mozilla Public License 0020 Version 1.1. You may obtain a copy of the License at 0021 http://www.mozilla.org/MPL/ 0022 */ 0023 0024 #ifndef PENDINGREPLY_H 0025 #define PENDINGREPLY_H 0026 0027 #include "error.h" 0028 0029 #include <memory> 0030 0031 class IMessageReceiver; 0032 class Message; 0033 class Connection; 0034 class PendingReplyPrivate; 0035 0036 class DFERRY_EXPORT PendingReply 0037 { 0038 public: 0039 // Constructs a detached instance, which does not have any reply to wait for: 0040 // isFinished() == true, error() == Error::Detached 0041 PendingReply(); 0042 ~PendingReply(); 0043 0044 PendingReply(PendingReply &&other); 0045 PendingReply &operator=(PendingReply &&other); 0046 0047 PendingReply(PendingReply &other) = delete; 0048 void operator=(PendingReply &other) = delete; 0049 0050 bool isNull() const; // only true for default-constructed or moved-from instances 0051 bool isFinished() const; // received a reply or in a state that will not allow receiving a reply 0052 bool hasNonErrorReply() const; // isFinished() && !isError() 0053 0054 // Since outgoing messages are only fully validated when trying to send them, Error contains 0055 // many errors that are typically detected before or while sending and will prevent sending 0056 // the outgoing message. 0057 // If a malformed message is sent, the peer might close the connection without notice. That 0058 // would usually indicate a bug on the sender (this) side - we try to prevent sending malformed 0059 // messages as far as possible. 0060 0061 Error error() const; 0062 bool isError() const; // convenience: error() == Error::None 0063 0064 void setCookie(void *cookie); 0065 void *cookie() const; 0066 0067 void setReceiver(IMessageReceiver *receiver); 0068 IMessageReceiver *receiver() const; 0069 0070 const Message *reply() const; 0071 Message takeReply(); 0072 0073 void dumpState(); // H4X 0074 0075 private: 0076 friend class Connection; 0077 PendingReply(PendingReplyPrivate *priv); // PendingReplies make no sense to construct "free-standing" 0078 PendingReplyPrivate *d; 0079 }; 0080 0081 #endif // PENDINGREPLY_H