summaryrefslogtreecommitdiff
path: root/indra/llmessage/llcoproceduremanager.h
blob: c5bc37dd0eab6973d1ddf871c70137d5f35ad6c3 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* @file llcoproceduremanager.h
* @author Rider Linden
* @brief Singleton class for managing asset uploads to the sim.
*
* $LicenseInfo:firstyear=2015&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2015, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
* $/LicenseInfo$
*/

#ifndef LL_COPROCEDURE_MANAGER_H
#define LL_COPROCEDURE_MANAGER_H

#include "lleventcoro.h"
#include "llcoros.h"
#include "llcorehttputil.h"
#include "lluuid.h"

class LLCoprocedurePool;

class LLCoprocedureManager : public LLSingleton < LLCoprocedureManager >
{
    LLSINGLETON(LLCoprocedureManager);
    virtual ~LLCoprocedureManager();

public:
    typedef boost::function<U32(const std::string &)> SettingQuery_t;
    typedef boost::function<void(const std::string &, U32, const std::string &)> SettingUpdate_t;

    typedef boost::function<void(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &, const LLUUID &id)> CoProcedure_t;

    /// Places the coprocedure on the queue for processing. 
    /// 
    /// @param name Is used for debugging and should identify this coroutine.
    /// @param proc Is a bound function to be executed 
    /// 
    /// @return This method returns a UUID that can be used later to cancel execution.
    LLUUID enqueueCoprocedure(const std::string &pool, const std::string &name, CoProcedure_t proc);

    /// Cancel a coprocedure. If the coprocedure is already being actively executed 
    /// this method calls cancelYieldingOperation() on the associated HttpAdapter
    /// If it has not yet been dequeued it is simply removed from the queue.
    //void cancelCoprocedure(const LLUUID &id);

    void setPropertyMethods(SettingQuery_t queryfn, SettingUpdate_t updatefn);

    /// Returns the number of coprocedures in the queue awaiting processing.
    ///
    size_t countPending() const;
    size_t countPending(const std::string &pool) const;

    /// Returns the number of coprocedures actively being processed.
    ///
    size_t countActive() const;
    size_t countActive(const std::string &pool) const;

    /// Returns the total number of coprocedures either queued or in active processing.
    ///
    size_t count() const;
    size_t count(const std::string &pool) const;

    void close();
    void close(const std::string &pool);

    void initializePool(const std::string &poolName);
    
private:

    typedef std::shared_ptr<LLCoprocedurePool> poolPtr_t;
    typedef std::map<std::string, poolPtr_t> poolMap_t;

    poolMap_t mPoolMap;

    SettingQuery_t mPropertyQueryFn;
    SettingUpdate_t mPropertyDefineFn;

public:
    static const U32 DEFAULT_QUEUE_SIZE;
};

#endif