Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Corrected links that should have been relative instead of absolute.

Overview

FireBreath has integrated several libraries that are used within FireBreath itself, and have been made available for easy inclusion into your plugin project. This section will describe those libraries, how to have them included into your plugin project and (where possible) provide usage examples.

The current libraries available are:

jsoncpp

Within the PluginConfig.cmake file in your project add the following line:

Code Block
add_firebreath_library(jsoncpp)

That will setup the directory structure for referencing the library headers and also tells the build setup to statically link the library to your plugin.

 

Next include the required headers into your plugin code:

Code Block
#include "json/json.h"
#include "fbjson.h"

 

jsoncpp can now be used within your plugin project, and the normal jsoncpp documentation applies. [http://jsoncpp.sourceforge.net/]

Here is an example which uses jsoncpp to convert an FB::VariantMap to a formatted JSON string

Code Block
languagecpp
    // Create some VariantMap objects we will eventually convert
    //  to a Json::Value for conversion to a JSON string.
    FB::VariantMap my_map, my_submap;
    // Create a VariantList object
    FB::VariantList my_list;

    // Pack values into the VariantMap
    my_map["encoding"] = "UTF-8";
    my_list = FB::variant_list_of("python")("c++")("ruby");
    my_map["plugins"] = my_list;
    my_submap["length"] = 3;
    my_submap["use_space"] = true;
    my_map["indent"] = my_submap;

    // Create a Json::Value object which will store the contents of
    //  of the VariantMap
    Json::Value json_value = FB::variantToJsonValue(my_map);

    // Create a StyledWriter which will convert our Json::Value to
    //  a styled JSON string
    Json::StyledWriter writer;

    // Use the writer to write out the string
    std::string json_string = writer.write(json_value);

    return json_string;

Which would output:

Code Block
{
   "encoding" : "UTF-8",
   "indent" : {
      "length" : 3,
      "use_space" : true
   },
   "plugins" : [ "python", "c++", "ruby" ]
}

log4cplus

See Logging

openssl

...

libcurl

Within the PluginConfig.cmake file in your project add the following line:

Code Block
add_firebreath_library(curl)

That will setup the directory structure for referencing the library headers and also tells the build setup to statically link the library to your plugin.

 

Next include the required headers into your plugin code:

Code Block
#include "curl/curl.h"

 

libcurl can now be used within your plugin project, and the normal libcurl documentation applies. [http://curl.haxx.se/libcurl/c/]

Here is an example which uses libcurl to requests the FireBreath homepage and returns the status

Code Block
...
    CURL *curl;
    CURLcode res;

    curl = curl_easy_init();
    if(curl) {
        curl_easy_setopt(curl, CURLOPT_URL, "http://firebreath.com");
        res = curl_easy_perform(curl);

        /* always cleanup */ 
        curl_easy_cleanup(curl);
    }

    return res;
...