|
a |
|
b/src/mediaserver/cdplugins/netfetch.h |
|
|
1 |
/* Copyright (C) 2017-2018 J.F.Dockes
|
|
|
2 |
* This program is free software; you can redistribute it and/or modify
|
|
|
3 |
* it under the terms of the GNU General Public License as published by
|
|
|
4 |
* the Free Software Foundation; either version 2 of the License, or
|
|
|
5 |
* (at your option) any later version.
|
|
|
6 |
*
|
|
|
7 |
* This program is distributed in the hope that it will be useful,
|
|
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
10 |
* GNU General Public License for more details.
|
|
|
11 |
*
|
|
|
12 |
* You should have received a copy of the GNU General Public License
|
|
|
13 |
* along with this program; if not, write to the
|
|
|
14 |
* Free Software Foundation, Inc.,
|
|
|
15 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
16 |
*/
|
|
|
17 |
|
|
|
18 |
#ifndef _MEDIAFETCH_H_INCLUDED_
|
|
|
19 |
#define _MEDIAFETCH_H_INCLUDED_
|
|
|
20 |
|
|
|
21 |
#include "bufxchange.h"
|
|
|
22 |
#include "abuffer.h"
|
|
|
23 |
|
|
|
24 |
//
|
|
|
25 |
// Wrapper for a network fetch
|
|
|
26 |
//
|
|
|
27 |
// The transfer is aborted when the object is deleted, with proper
|
|
|
28 |
// cleanup.
|
|
|
29 |
//
|
|
|
30 |
// The end of transfer is marked by pushing an empty buffer on the queue
|
|
|
31 |
//
|
|
|
32 |
// All methods are supposedly thread-safe
|
|
|
33 |
class NetFetch {
|
|
|
34 |
public:
|
|
|
35 |
NetFetch() {}
|
|
|
36 |
virtual ~NetFetch() {}
|
|
|
37 |
|
|
|
38 |
virtual void setTimeout(int secs) = 0;
|
|
|
39 |
|
|
|
40 |
/// Start the transfer to the output queue.
|
|
|
41 |
virtual bool start(BufXChange<ABuffer*> *queue, uint64_t offset = 0) = 0;
|
|
|
42 |
|
|
|
43 |
// Wait for headers. This allows, e.g. doing stuff depending on
|
|
|
44 |
// content-type before proceeding with the actual data
|
|
|
45 |
// transfer. May not work exactly the same depending on the
|
|
|
46 |
// underlaying implementation.
|
|
|
47 |
virtual bool waitForHeaders(int maxSecs = 0) = 0;
|
|
|
48 |
// Retrieve header value (after a successful waitForHeaders).
|
|
|
49 |
virtual bool headerValue(const std::string& nm, std::string& val) = 0;
|
|
|
50 |
|
|
|
51 |
// Check if the fetch is done and retrieve the results if it
|
|
|
52 |
// is. This does not wait, it returns false if the transfer is
|
|
|
53 |
// still running.
|
|
|
54 |
// The pointers can be set to zero if no value should be retrieved
|
|
|
55 |
enum FetchStatus {FETCH_OK=0, FETCH_RETRYABLE, FETCH_FATAL};
|
|
|
56 |
virtual bool fetchDone(FetchStatus *code, int *http_code) = 0;
|
|
|
57 |
|
|
|
58 |
/// Reset after transfer done, for retrying for exemple.
|
|
|
59 |
virtual void reset() = 0;
|
|
|
60 |
|
|
|
61 |
// Callbacks
|
|
|
62 |
|
|
|
63 |
// A function to create the first buffer (typically for prepending
|
|
|
64 |
// a wav header to a raw pcm stream. If set this is called from
|
|
|
65 |
// the first curl write callback, before processing the curl data,
|
|
|
66 |
// so this happens at a point where the client may have had a look
|
|
|
67 |
// at the headers).
|
|
|
68 |
virtual void setBuf1GenCB(std::function<bool(std::string& buf,void*,int)>) {
|
|
|
69 |
}
|
|
|
70 |
// Called when the network transfer is done
|
|
|
71 |
void setEOFetchCB(std::function<void(bool ok, u_int64_t count)>) {
|
|
|
72 |
}
|
|
|
73 |
// Called every time we get new data from the remote
|
|
|
74 |
void setFetchBytesCB(std::function<void(u_int64_t count)>) {
|
|
|
75 |
}
|
|
|
76 |
};
|
|
|
77 |
|
|
|
78 |
#endif /* _MEDIAFETCH_H_INCLUDED_ */
|