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 161 of file kicad_curl.cpp.

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

Referenced by at_terminate().

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

References Init(), and s_initialized.

197 {
198  if( !s_initialized )
199  Init();
200 
201  curl_version_info_data* info = curl_version_info( CURLVERSION_NOW );
202 
203  std::string res;
204 
205  if( info->version )
206  {
207  res += "libcurl version: " + std::string( info->version );
208  }
209 
210  res += " (";
211 
212  if( info->features & CURL_VERSION_SSL )
213  {
214  res += "with SSL - ";
215  res += std::string( info->ssl_version );
216  }
217  else
218  {
219  res += "without SSL";
220  }
221  res += ")";
222 
223  return res;
224 }
static void Init()
Function Init calls curl_global_init for the application.
Definition: kicad_curl.cpp:135
static volatile bool s_initialized
Definition: kicad_curl.cpp:43
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 Init(), and dialog_about::OnCopyVersionInfo().

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 135 of file kicad_curl.cpp.

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

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

136 {
137  // We test s_initialized twice in an effort to avoid
138  // unnecessarily locking s_lock. This understands that the common case
139  // will not need to lock.
140  if( !s_initialized )
141  {
142  MUTLOCK lock( s_lock );
143 
144  if( !s_initialized )
145  {
146  if( curl_global_init( CURL_GLOBAL_ALL ) != CURLE_OK )
147  {
148  THROW_IO_ERROR( "curl_global_init() failed." );
149  }
150 
151  init_locks();
152 
153  wxLogDebug( "Using %s", GetVersion() );
154 
155  s_initialized = true;
156  }
157  }
158 }
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
static volatile bool s_initialized
Definition: kicad_curl.cpp:43
boost::interprocess::scoped_lock< MUTEX > MUTLOCK
Definition: ki_mutex.h:43
static const char * GetVersion()
Function GetVersion wrapper for curl_version().
Definition: kicad_curl.h:93
void init_locks()
Definition: kicad_curl.cpp:122
static MUTEX s_lock
Definition: kicad_curl.cpp:45

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: