C++ API¶
The C++ SDK is a header-only library with a single file used for automatic activation. The SDK is a wrapper around libcurl to implement the REST-API functions defined in this guide.
The header file to include is defined at https://github.com/DoubangoTelecom/LicenseManager-SDK/blob/master/c++/LicenseManager-SDK-API-PUBLIC.h
Sample code¶
Sample code to show how to perform automatic activation using the C++ API.
#include <LicenseManager-SDK-API-PUBLIC.h>
#include <algorithm>
const std::string url = "https://localhost:3600";
const std::string masterOrSlaveKey = "c2YVxBcUY8OmVaTnmcUQ2OmA1DD4xPDcMU1YDFQal0NTxdmtvXFI1cXtkZTA8OjsscjU9MEFvPyJxNmpDMWJ2bhtTOjomOhBrAPL+PjwAHQQ0YGcwOW40ZDDQ3MzwaJVAjdffXxsZjU=";
const std::string runtimeKey = "gBOSRvYU1g0NCBTPWwQRHQfG1sFkFSQUJlb3oADT81OSg2MDg8ABQQBBAECAAj/BQYDBgJugTYuOwQICQACDAlIamHSXFdWOgoITQEAAkEKgc/QBQS8bEw4NTgA3JgQGaWM=";
std::string response;
const int ret = LicenseManagerSdk::LicenseManager::activate(
url,
masterOrSlaveKey,
runtimeKey,
response
);
if (ret == 0) {
LICMGR_SDK_PRINT_INFO("Response: %s", response.c_str());
// Extract "token" string from JSON response.
// Use the next code only if you don't have a JSON parser.
static const char tokenprop[] = "\"token\":";
size_t start = response.find(tokenprop);
if (start != std::string::npos) {
start += sizeof(tokenprop);
size_t end = response.find(",", start);
if (end == std::string::npos) {
end = response.find("}", start);
}
if (end != std::string::npos) {
std::string token = response.substr(start, (end - start - 1));
token.erase(std::remove(token.begin(), token.end(), ' '), token.end()); // trim SPACEs
LICMGR_SDK_PRINT_INFO("Token: [%s]", token.c_str());
}
}
}
Interface¶
-
class
LicenseManager
¶ This is a header-only library to allow automatic activation using C++ code. More information about automatic activation could be found at https://www.doubango.org/SDKs/LicenseManager/docs/Activation_use_cases.html#automatic-activation.
Public Static Functions
-
static int
createSlave
(const std::string &url, const std::string &masterKey, std::string &response, const std::string &comment = "", const long timeoutInMillis = 10 * 1000)¶ Creates a slave. The REST API is defined here.
- Return
0 if success, non-zero error code otherwise.
- Parameters
url
: The server URL to connect to. Should be something like ‘https://localhost:3600’.masterKey
: Your secret master key.response
: The JSON response from the server.comment
: Optional field to add comment to the slave. This could be helpful if you want to track the slaves. We recommend adding the end user contact information in this field.timeoutInMillis
: Connection timeout in milliseconds.
-
static int
activate
(const std::string &url, const std::string &masterOrSlaveKey, const std::string &runtimeKey, std::string &response, const long timeoutInMillis = 10 * 1000)¶ Activates a Runtime Key. The REST API is defined here.
- Return
0 if success, non-zero error code otherwise.
- Parameters
url
: The server URL to connect to. Should be something like ‘https://localhost:3600’.masterOrSlaveKey
: Your secret master key or slave key.runtimeKey
: The runtime key to activate.response
: The JSON response from the server.timeoutInMillis
: Connection timeout in milliseconds.
-
static int