comparison Framework/HttpQueries/HttpQueriesQueue.h @ 0:95226b754d9e

initial release
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 17 Sep 2018 11:34:55 +0200
parents
children 9bcd6eadcff5
comparison
equal deleted inserted replaced
-1:000000000000 0:95226b754d9e
1 /**
2 * Transfers accelerator plugin for Orthanc
3 * Copyright (C) 2018 Osimis, Belgium
4 *
5 * This program is free software: you can redistribute it and/or
6 * modify it under the terms of the GNU Affero General Public License
7 * as published by the Free Software Foundation, either version 3 of
8 * the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 **/
18
19
20 #pragma once
21
22 #include "IHttpQuery.h"
23
24 #include <Plugins/Samples/Common/OrthancPluginCppWrapper.h>
25
26 #include <boost/thread/mutex.hpp>
27 #include <boost/thread/condition_variable.hpp>
28
29
30 namespace OrthancPlugins
31 {
32 class HttpQueriesQueue : public boost::noncopyable
33 {
34 public:
35 enum Status
36 {
37 Status_Running,
38 Status_Success,
39 Status_Failure
40 };
41
42 private:
43 OrthancPluginContext *context_;
44 OrthancPeers peers_;
45 boost::mutex mutex_;
46 boost::condition_variable completed_;
47 std::vector<IHttpQuery*> queries_;
48 unsigned int maxRetries_;
49
50 size_t position_;
51 uint64_t downloadedSize_; // GET answers + POST answers
52 uint64_t uploadedSize_; // PUT body + POST body
53 size_t successQueries_;
54 bool isFailure_;
55
56
57 Status GetStatusInternal() const;
58
59 public:
60 HttpQueriesQueue(OrthancPluginContext* context);
61
62 ~HttpQueriesQueue();
63
64 OrthancPeers& GetOrthancPeers()
65 {
66 return peers_;
67 }
68
69 unsigned int GetMaxRetries();
70
71 void SetMaxRetries(unsigned int maxRetries);
72
73 void Reserve(size_t size);
74
75 void Reset();
76
77 void Enqueue(IHttpQuery* query); // Takes ownership
78
79 bool ExecuteOneQuery(uint64_t& networkTraffic);
80
81 Status WaitComplete(unsigned int timeoutMS);
82
83 void WaitComplete();
84
85 void GetStatistics(size_t& scheduledQueriesCount,
86 size_t& successQueriesCount,
87 uint64_t& downloadedSize,
88 uint64_t& uploadedSize);
89 };
90 }