KiCad PCB EDA Suite
KICAD_CURL Class Reference

Class KICAD_CURL simple wrapper class to call curl_global_init and curl_global_cleanup for KiCad. More...

#include <kicad_curl.h>

Static Public Member Functions

static void Init ()
 Function Init calls curl_global_init for the application. More...
 
static void Cleanup ()
 Function Cleanup calls curl_global_cleanup for the application. More...
 
static const char * GetVersion ()
 Function GetVersion wrapper for curl_version(). More...
 
static std::string GetSimpleVersion ()
 Function GetSimpleVersion Reports back curl version only and SSL library support. More...
 

Friends

class KICAD_CURL_EASY
 

Detailed Description

Class KICAD_CURL simple wrapper class to call curl_global_init and curl_global_cleanup for KiCad.

Definition at line 64 of file kicad_curl.h.

Member Function Documentation

void KICAD_CURL::Cleanup ( )
static

Function Cleanup calls curl_global_cleanup for the application.

It must be used only after curl_global_init was called.

Definition at line 154 of file kicad_curl.cpp.

References at_terminate(), kill_locks(), s_initialized, and s_lock.

Referenced by at_terminate().

155 {
156  /*
157 
158  Calling MUTLOCK() from a static destructor will typically be bad, since the
159  s_lock may already have been statically destroyed itself leading to a boost
160  exception. (Remember C++ does not provide certain sequencing of static
161  destructor invocation.)
162 
163  To prevent this we test s_initialized twice, which ensures that the MUTLOCK
164  is only instantiated on the first call, which should be from
165  PGM_BASE::destroy() which is first called earlier than static destruction.
166  Then when called again from the actual PGM_BASE::~PGM_BASE() function,
167  MUTLOCK will not be instantiated because s_initialized will be false.
168 
169  */
170 
171  if( s_initialized )
172  {
173  MUTLOCK lock( s_lock );
174 
175  if( s_initialized )
176  {
177  curl_global_cleanup();
178 
179  kill_locks();
180 
181  atexit( &at_terminate );
182 
183  s_initialized = false;
184  }
185  }
186 }
static void at_terminate()
At process termination, using atexit() keeps the CURL stuff out of the singletops and PGM_BASE...
Definition: kicad_curl.cpp:122
static volatile bool s_initialized
Definition: kicad_curl.cpp:38
void kill_locks()
Definition: kicad_curl.cpp:116
boost::interprocess::scoped_lock< MUTEX > MUTLOCK
Definition: ki_mutex.h:43
static MUTEX s_lock
Definition: kicad_curl.cpp:40
std::string KICAD_CURL::GetSimpleVersion ( )
static

Function GetSimpleVersion Reports back curl version only and SSL library support.

Returns
std::string - Generated version string

Definition at line 189 of file kicad_curl.cpp.

References Init(), and s_initialized.

190 {
191  if( !s_initialized )
192  Init();
193 
194  curl_version_info_data* info = curl_version_info( CURLVERSION_NOW );
195 
196  std::string res;
197 
198  if( info->version )
199  {
200  res += "libcurl version: " + std::string( info->version );
201  }
202 
203  res += " (";
204 
205  if( info->features & CURL_VERSION_SSL )
206  {
207  res += "with SSL - ";
208  res += std::string( info->ssl_version );
209  }
210  else
211  {
212  res += "without SSL";
213  }
214  res += ")";
215 
216  return res;
217 }
static void Init()
Function Init calls curl_global_init for the application.
Definition: kicad_curl.cpp:128
static volatile bool s_initialized
Definition: kicad_curl.cpp:38
static const char* KICAD_CURL::GetVersion ( )
inlinestatic

Function GetVersion wrapper for curl_version().

Reports back a short string of loaded libraries.

Returns
const char* - String reported by libcurl and owned by it.
Exceptions
IO_ERRORon failure, hopefully with helpful text in it.

Definition at line 93 of file kicad_curl.h.

Referenced by GetKicadCurlVersion().

94  {
95  return curl_version();
96  }
void KICAD_CURL::Init ( )
static

Function Init calls curl_global_init for the application.

It must be used only once and before any curl functions that perform requests.

Returns
bool - True if successful, false if CURL returned an error
Exceptions
IO_ERRORon failure, hopefully with helpful text in it.

Definition at line 128 of file kicad_curl.cpp.

References init_locks(), s_initialized, s_lock, and THROW_IO_ERROR.

Referenced by GetSimpleVersion(), and KICAD_CURL_EASY::KICAD_CURL_EASY().

129 {
130  // We test s_initialized twice in an effort to avoid
131  // unnecessarily locking s_lock. This understands that the common case
132  // will not need to lock.
133  if( !s_initialized )
134  {
135  MUTLOCK lock( s_lock );
136 
137  if( !s_initialized )
138  {
139  if( curl_global_init( CURL_GLOBAL_ALL ) != CURLE_OK )
140  {
141  THROW_IO_ERROR( "curl_global_init() failed." );
142  }
143 
144  init_locks();
145 
146  //wxLogDebug( "Using %s", GetVersion() );
147 
148  s_initialized = true;
149  }
150  }
151 }
static volatile bool s_initialized
Definition: kicad_curl.cpp:38
boost::interprocess::scoped_lock< MUTEX > MUTLOCK
Definition: ki_mutex.h:43
void init_locks()
Definition: kicad_curl.cpp:115
static MUTEX s_lock
Definition: kicad_curl.cpp:40
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

Friends And Related Function Documentation

friend class KICAD_CURL_EASY
friend

Definition at line 66 of file kicad_curl.h.


The documentation for this class was generated from the following files: