summaryrefslogtreecommitdiff
path: root/matlab/src/Future.h
blob: 4231007067012d0e1970aff7deab92753189d393 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//

#include <Ice/Ice.h>

namespace IceMatlab
{

class Future
{
public:

    void token(std::function<void()>);

    enum State { Running, Sent, Finished };

    bool waitForState(State, double);
    bool waitForState(const std::string&, double);

    virtual void exception(std::exception_ptr);
    std::exception_ptr getException() const;

    virtual void sent();
    virtual std::string state() const;
    void cancel();

protected:

    virtual State stateImpl() const = 0;

    std::mutex _mutex;
    std::condition_variable _cond;

    std::function<void()> _token;
    std::exception_ptr _exception; // If a local exception occurs.
};

class SimpleFuture : public Future
{
public:

    SimpleFuture();

    void done();

protected:

    virtual State stateImpl() const;

private:

    State _state;
};

}