Page tree
Skip to end of metadata
Go to start of metadata

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:

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:

#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

    // 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:

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

log4cplus

See Logging

openssl

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

add_firebreath_library(openssl)

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.

libcurl

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

add_firebreath_library(curl)
add_firebreath_library(openssl)

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.

The openssl component is needed because the provided CURL library has external dependencies to openSSL functions which must be resolved during linking.

 

Next include the required headers into your plugin code:

#include "curl/curl.h"

If you are common with CURL, you may have an old include file in your code which is unnecessary (and this empty include file is not provided in Firebreath's CURL distribution):

#include "curl/types.h"

Remove that line or comment it.

 

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

...
    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;
...
  • No labels