Skip to content

Commit

Permalink
make clang-format using clang-format-3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuhiro-t committed Dec 27, 2015
1 parent 4abad2f commit b1132d6
Show file tree
Hide file tree
Showing 1,095 changed files with 30,411 additions and 33,758 deletions.
53 changes: 27 additions & 26 deletions examples/libaria2ex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
int downloadEventCallback(aria2::Session* session, aria2::DownloadEvent event,
aria2::A2Gid gid, void* userData)
{
switch(event) {
switch (event) {
case aria2::EVENT_ON_DOWNLOAD_COMPLETE:
std::cerr << "COMPLETE";
break;
Expand All @@ -55,15 +55,17 @@ int downloadEventCallback(aria2::Session* session, aria2::DownloadEvent event,
}
std::cerr << " [" << aria2::gidToHex(gid) << "] ";
aria2::DownloadHandle* dh = aria2::getDownloadHandle(session, gid);
if(!dh) return 0;
if(dh->getNumFiles() > 0) {
if (!dh)
return 0;
if (dh->getNumFiles() > 0) {
aria2::FileData f = dh->getFile(1);
// Path may be empty if the file name has not been determined yet.
if(f.path.empty()) {
if(!f.uris.empty()) {
if (f.path.empty()) {
if (!f.uris.empty()) {
std::cerr << f.uris[0].uri;
}
} else {
}
else {
std::cerr << f.path;
}
}
Expand All @@ -75,7 +77,7 @@ int downloadEventCallback(aria2::Session* session, aria2::DownloadEvent event,
int main(int argc, char** argv)
{
int rv;
if(argc < 2) {
if (argc < 2) {
std::cerr << "Usage: libaria2ex URI [URI...]\n"
<< "\n"
<< " Download given URIs in parallel in the current directory."
Expand All @@ -92,46 +94,45 @@ int main(int argc, char** argv)
config.downloadEventCallback = downloadEventCallback;
session = aria2::sessionNew(aria2::KeyVals(), config);
// Add download item to session
for(int i = 1; i < argc; ++i) {
for (int i = 1; i < argc; ++i) {
std::vector<std::string> uris = {argv[i]};
aria2::KeyVals options;
rv = aria2::addUri(session, nullptr, uris, options);
if(rv < 0) {
if (rv < 0) {
std::cerr << "Failed to add download " << uris[0] << std::endl;
}
}
auto start = std::chrono::steady_clock::now();
for(;;) {
for (;;) {
rv = aria2::run(session, aria2::RUN_ONCE);
if(rv != 1) {
if (rv != 1) {
break;
}
// the application can call aria2 API to add URI or query progress
// here
auto now = std::chrono::steady_clock::now();
auto count = std::chrono::duration_cast<std::chrono::milliseconds>
(now - start).count();
auto count = std::chrono::duration_cast<std::chrono::milliseconds>(
now - start).count();
// Print progress information once per 500ms
if(count >= 500) {
if (count >= 500) {
start = now;
aria2::GlobalStat gstat = aria2::getGlobalStat(session);
std::cerr << "Overall #Active:" << gstat.numActive
<< " #waiting:" << gstat.numWaiting
<< " D:" << gstat.downloadSpeed/1024 << "KiB/s"
<< " U:"<< gstat.uploadSpeed/1024 << "KiB/s " << std::endl;
<< " D:" << gstat.downloadSpeed / 1024 << "KiB/s"
<< " U:" << gstat.uploadSpeed / 1024 << "KiB/s " << std::endl;
std::vector<aria2::A2Gid> gids = aria2::getActiveDownload(session);
for(const auto& gid : gids) {
for (const auto& gid : gids) {
aria2::DownloadHandle* dh = aria2::getDownloadHandle(session, gid);
if(dh) {
if (dh) {
std::cerr << " [" << aria2::gidToHex(gid) << "] "
<< dh->getCompletedLength() << "/"
<< dh->getTotalLength() << "("
<< (dh->getTotalLength() > 0 ?
(100*dh->getCompletedLength()/dh->getTotalLength())
: 0) << "%)"
<< " D:"
<< dh->getDownloadSpeed()/1024 << "KiB/s, U:"
<< dh->getUploadSpeed()/1024 << "KiB/s"
<< dh->getCompletedLength() << "/" << dh->getTotalLength()
<< "(" << (dh->getTotalLength() > 0
? (100 * dh->getCompletedLength() /
dh->getTotalLength())
: 0) << "%)"
<< " D:" << dh->getDownloadSpeed() / 1024
<< "KiB/s, U:" << dh->getUploadSpeed() / 1024 << "KiB/s"
<< std::endl;
aria2::deleteDownloadHandle(dh);
}
Expand Down
Loading

0 comments on commit b1132d6

Please sign in to comment.