/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
    QC_AbstractPollOperation.qpp

    AbstractPollOperation class definition

    Qore Programming Language

    Copyright (C) 2003 - 2023 Qore Technologies, s.r.o.

    Permission is hereby granted, free of charge, to any person obtaining a
    copy of this software and associated documentation files (the "Software"),
    to deal in the Software without restriction, including without limitation
    the rights to use, copy, modify, merge, publish, distribute, sublicense,
    and/or sell copies of the Software, and to permit persons to whom the
    Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    DEALINGS IN THE SOFTWARE.

    Note that the Qore library is released under a choice of three open-source
    licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
    information.
*/

#include "qore/Qore.h"

class AbstractPollOperation {
};

//! Abstract poll operation objects provide the polling interface for pollable objects
/** This class implements polling logic for pollable operations and the state machine behind it
*/
qclass AbstractPollOperation [arg=AbstractPollOperation* poll; ns=Qore];

//! Returns the goal
/** @return the goal set in the constructor
*/
abstract string AbstractPollOperation::getGoal();

//! Returns the current state
/** @return the current state
*/
abstract string AbstractPollOperation::getState();

//! Returns @ref True when the goal as been reached
/** @return @ref True when the goal as been reached
*/
abstract bool AbstractPollOperation::goalReached();

//! Returns a socket poll hash if polling should continue or @ref nothing if complete
/** @return @ref NOTHING if there is no more to poll and the poll operation was successful (i.e. the goal was
    reached), otherwise this method must return a new socket poll hash to continue the polling operation with another
    operation, after which this method will be called again if a matching event is received for the socket.  If a
    socket poll hash is returned, then the internal state is also updated.
*/
abstract *hash<SocketPollInfo> AbstractPollOperation::continuePoll();

//! Returns any output generated by any completed poll action
/** @return this base class method always returns @ref nothing, reimplement in subclasses to change this behavior
 */
auto AbstractPollOperation::getOutput() [flags=RET_VALUE_ONLY] {
    return QoreValue();
}
