diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2013-05-11 19:40:24 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2013-05-11 19:40:24 +0900 |
| commit | e350df2d7597b73945d2e8a7eeef9b32867f98d2 (patch) | |
| tree | 683545263414be919df260c4a8638f7dfae171f4 /examples | |
| parent | 1c571f196af0013e1b0ad1c9e075ed9c711e915b (diff) | |
Add download event callback API and its example
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/libaria2ex.cc | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/examples/libaria2ex.cc b/examples/libaria2ex.cc index 9f0fe83d..f4317988 100644 --- a/examples/libaria2ex.cc +++ b/examples/libaria2ex.cc @@ -40,13 +40,43 @@ #include <aria2/aria2.h> +int downloadEventCallback(aria2::Session* session, aria2::DownloadEvent event, + const aria2::A2Gid& gid, void* userData) +{ + std::cout << "Download Event: "; + switch(event) { + case aria2::EVENT_ON_DOWNLOAD_START: + std::cout << "START"; + break; + case aria2::EVENT_ON_DOWNLOAD_PAUSE: + std::cout << "PAUSE"; + break; + case aria2::EVENT_ON_DOWNLOAD_STOP: + std::cout << "STOP"; + break; + case aria2::EVENT_ON_DOWNLOAD_COMPLETE: + std::cout << "COMPLETE"; + break; + case aria2::EVENT_ON_DOWNLOAD_ERROR: + std::cout << "ERROR"; + break; + case aria2::EVENT_ON_BT_DOWNLOAD_COMPLETE: + std::cout << "COMPLETE"; + break; + } + std::cout << " for [" << aria2::gidToHex(gid) << "]" << std::endl; + return 0; +} + int main() { aria2::libraryInit(); // session is actually singleton: 1 session per process aria2::Session* session; - // Use default configuration + // Create default configuration aria2::SessionConfig config; + // Add event callback + config.downloadEventCallback = downloadEventCallback; session = aria2::sessionNew(aria2::KeyVals(), config); std::vector<std::string> uris = { "http://localhost/" |
