libaria2cpp 0.2.0
Basic CPP library to connect to an ARIA2 daemon via the RPC interface.
aria2cpp.h
1/*
2 * ARIA2CPP: Basic CPP library to connect to an ARIA2 daemon
3 * via the RPC interface.
4 *
5 * *ALPHA VERSION!*
6 *
7 * **** THE API IS NOT STABLE YET!!! ****
8 *
9 * Copyright (C) 2021 Dennis Katsonis dennisk@netspace.net.au
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 *
24 */
25
26#ifndef ARIA2CPP_H_
27#define ARIA2CPP_H_
28
29#include <string>
30#include <vector>
31#include <unistd.h>
32#include <fcntl.h>
33#include <memory>
34#include <jsonrpccpp/client/connectors/httpclient.h>
35#include "globaloptions.h"
36
37#include "download.h"
38#include "downloadoptions.h"
39#include "base64.h"
40#include "client.h"
41#include "globaloptions.h"
42#include "aria2cppexception.h"
43#include "ariadefs.h"
44
46{
47public:
61 Aria2CPP(const char* host, const char* port, std::string secret = "");
70 std::shared_ptr<Options> getOptions() const;
86 void update(stringList keys = stringList());
99 std::string addDownload(const std::string URI,
100 int position = 0);
114 std::string addDownload(const std::string URI,
115 DownloadOptions &options,
116 int position = 0);
131 std::string addTorrent(const std::string torrentFile,
132 DownloadOptions &options,
133 stringList URIs = stringList{},
134 int position = 0);
148 std::string addTorrent(const std::string torrentFile,
149 stringList URIs = stringList{},
150 int position = 0);
160 stringList addMetalink(const std::string metalinkFile, int position = 0);
175 stringList addMetalink(const std::string metalinkFile, DownloadOptions &dopts, int position = 0);
184 bool pause(const std::string gid) const;
193 bool resume(const std::string gid) const;
202 bool pauseAll() const;
212 bool shutdown() const;
213
226 bool forceShutdown() const;
227
236 bool resumeAll() const;
243 bool saveSession() const;
253 int changePosition(const std::string gid, const int count, std::string how) const;
261 bool remove(const std::string gid) const;
272 bool forceRemove(const std::string gid) const;
280 std::string name(const size_t pos) const;
287 std::string gid(const size_t pos) const;
296 bool hasGid(const std::string gid) const;
303 bool purgeDownloadResult() const;
311 bool removeDownloadResult(const std::string gid) const;
317 Options getGlobalOption() const;
331 bool setGlobalOption(const std::string option, const std::string value);
341 Version getVersion() const;
348 std::string getSessionID();
353 stringList listMethods();
359 std::vector<URI> getUris(std::string gid) const;
360
374 std::vector<Download> getDownloads(stringList keys = stringList());
389 Download getDownload(const std::string gid, // Specify which one we want by GID
390 stringList keys = stringList(),
391 bool getPeers = true,
392 bool getServers = true);
408 Download getDownload(const size_t pos,
409 stringList keys = stringList(),
410 bool getPeers = true,
411 bool getServers = true);
412protected:
413 // The following four methods may be removed or changed in the
414 // future! This is an alpha, so changes may happen.
424 // Json::Value getDownloads(stringList keys = stringList()) const;
425 Json::Value tellStatus(std::string gid, stringList values = stringList());
426
436 Json::Value getWaitingDownloads(stringList keys = stringList()) const;
446 Json::Value getWaitingStopped(stringList keys = stringList()) const;
456 Json::Value getActiveDownloads(stringList keys = stringList()) const;
468 void addJsonValueToDownloads(Json::Value downloads, bool getPeers = true, bool getServers = true);
469 std::unique_ptr<HttpClient> m_httpclient;
470 std::shared_ptr<StubClient> m_client;
471 std::shared_ptr<Options> m_options;
472 std::vector<Download> m_downloads;
473 std::string m_secret = "token:";
474 bool m_hasSecret;
475};
476
477#endif //ARIA2CPP_H_
Definition: aria2cpp.h:46
Json::Value tellStatus(std::string gid, stringList values=stringList())
Definition: aria2cpp.cpp:452
Options getGlobalOption() const
Definition: aria2cpp.cpp:411
std::string addTorrent(const std::string torrentFile, DownloadOptions &options, stringList URIs=stringList{}, int position=0)
Definition: aria2cpp.cpp:122
Version getVersion() const
Definition: aria2cpp.cpp:490
bool purgeDownloadResult() const
Definition: aria2cpp.cpp:379
std::string name(const size_t pos) const
Definition: aria2cpp.cpp:352
bool remove(const std::string gid) const
Definition: aria2cpp.cpp:321
void update(stringList keys=stringList())
Definition: aria2cpp.cpp:81
int changePosition(const std::string gid, const int count, std::string how) const
Definition: aria2cpp.cpp:279
Json::Value getWaitingDownloads(stringList keys=stringList()) const
Definition: aria2cpp.cpp:201
std::vector< URI > getUris(std::string gid) const
Definition: aria2cpp.cpp:519
bool saveSession() const
Definition: aria2cpp.cpp:574
bool removeDownloadResult(const std::string gid) const
Definition: aria2cpp.cpp:393
bool resume(const std::string gid) const
Definition: aria2cpp.cpp:264
std::shared_ptr< Options > getOptions() const
Definition: aria2cpp.cpp:59
std::string getSessionID()
Definition: aria2cpp.cpp:507
void addJsonValueToDownloads(Json::Value downloads, bool getPeers=true, bool getServers=true)
Definition: aria2cpp.cpp:65
bool hasGid(const std::string gid) const
Definition: aria2cpp.cpp:368
stringList listMethods()
Definition: aria2cpp.cpp:436
Aria2CPP(const char *host, const char *port, std::string secret="")
Definition: aria2cpp.cpp:28
bool pauseAll() const
Definition: aria2cpp.cpp:291
Json::Value getActiveDownloads(stringList keys=stringList()) const
Definition: aria2cpp.cpp:234
GlobalStat getGlobalStat() const
Definition: aria2cpp.cpp:471
stringList addMetalink(const std::string metalinkFile, int position=0)
Definition: aria2cpp.cpp:186
bool resumeAll() const
Definition: aria2cpp.cpp:305
bool setGlobalOption(const std::string option, const std::string value)
Definition: aria2cpp.cpp:423
std::string addDownload(const std::string URI, int position=0)
Definition: aria2cpp.cpp:91
bool shutdown() const
Definition: aria2cpp.cpp:545
std::vector< Download > getDownloads(stringList keys=stringList())
Definition: aria2cpp.cpp:589
std::string gid(const size_t pos) const
Definition: aria2cpp.cpp:360
bool forceShutdown() const
Definition: aria2cpp.cpp:560
Json::Value getWaitingStopped(stringList keys=stringList()) const
Definition: aria2cpp.cpp:218
bool forceRemove(const std::string gid) const
Definition: aria2cpp.cpp:336
Download getDownload(const std::string gid, stringList keys=stringList(), bool getPeers=true, bool getServers=true)
Definition: aria2cpp.cpp:595
bool pause(const std::string gid) const
Definition: aria2cpp.cpp:249
Definition: downloadoptions.h:235
Definition: download.h:39
Definition: globaloptions.h:114
Definition: ariadefs.h:40
Definition: ariadefs.h:71
Definition: ariadefs.h:58