KiCad PCB EDA Suite
kicad_curl_easy.cpp File Reference
#include <curl/curl.h>
#include <curl/easy.h>
#include <kicad_curl/kicad_curl.h>
#include <kicad_curl/kicad_curl_easy.h>
#include <cstdarg>
#include <cstddef>
#include <exception>
#include <sstream>
#include <wx/app.h>
#include <build_version.h>
#include <ki_exception.h>
#include <kiplatform/app.h>
#include <kiplatform/environment.h>
#include <pgm_base.h>

Go to the source code of this file.

Classes

struct  CURL_PROGRESS
 

Functions

static size_t write_callback (void *contents, size_t size, size_t nmemb, void *userp)
 
static size_t stream_write_callback (void *contents, size_t size, size_t nmemb, void *userp)
 
static int xferinfo (void *p, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
 
static int progressinfo (void *p, double dltotal, double dlnow, double ultotal, double ulnow)
 

Function Documentation

◆ progressinfo()

static int progressinfo ( void *  p,
double  dltotal,
double  dlnow,
double  ultotal,
double  ulnow 
)
static

Definition at line 100 of file kicad_curl_easy.cpp.

101 {
102  return xferinfo( p, static_cast<curl_off_t>( dltotal ), static_cast<curl_off_t>( dlnow ),
103  static_cast<curl_off_t>( ultotal ), static_cast<curl_off_t>( ulnow ) );
104 }
static int xferinfo(void *p, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)

References xferinfo().

Referenced by KICAD_CURL_EASY::SetTransferCallback().

◆ stream_write_callback()

static size_t stream_write_callback ( void *  contents,
size_t  size,
size_t  nmemb,
void *  userp 
)
static

Definition at line 70 of file kicad_curl_easy.cpp.

71 {
72  size_t realsize = size * nmemb;
73 
74  std::ostream* p = (std::ostream*) userp;
75 
76  p->write( static_cast<const char*>( contents ), realsize );
77 
78  return realsize;
79 }

Referenced by KICAD_CURL_EASY::SetOutputStream().

◆ write_callback()

static size_t write_callback ( void *  contents,
size_t  size,
size_t  nmemb,
void *  userp 
)
static

Definition at line 58 of file kicad_curl_easy.cpp.

59 {
60  size_t realsize = size * nmemb;
61 
62  std::string* p = static_cast<std::string*>( userp );
63 
64  p->append( static_cast<const char*>( contents ), realsize );
65 
66  return realsize;
67 }

Referenced by KICAD_CURL_EASY::KICAD_CURL_EASY().

◆ xferinfo()

static int xferinfo ( void *  p,
curl_off_t  dltotal,
curl_off_t  dlnow,
curl_off_t  ultotal,
curl_off_t  ulnow 
)
static

Definition at line 82 of file kicad_curl_easy.cpp.

84 {
85  CURL_PROGRESS* progress = static_cast<CURL_PROGRESS*>( p );
86  curl_off_t curtime = 0;
87 
88  curl_easy_getinfo( progress->curl->GetCurl(), CURLINFO_TOTAL_TIME, &curtime );
89 
90  if( curtime - progress->last_run_time >= progress->interval )
91  {
92  progress->last_run_time = curtime;
93  return progress->callback( dltotal, dlnow, ultotal, ulnow );
94  }
95 
96  return CURLE_OK;
97 }
curl_off_t last_run_time
TRANSFER_CALLBACK callback
curl_off_t interval
KICAD_CURL_EASY * curl

References CURL_PROGRESS::callback, CURL_PROGRESS::curl, KICAD_CURL_EASY::GetCurl(), CURL_PROGRESS::interval, and CURL_PROGRESS::last_run_time.

Referenced by progressinfo(), and KICAD_CURL_EASY::SetTransferCallback().