Example code
Getting started
- Download the latest embedded SDK package.
- Extract the package to your folder of choice.
- Open your IDE and the project you want to integrate the SDK into.
-
Add the extracted
includefolder to your include path. -
Add the
lib\win64\static-crtfolder to your library path and, from that folder, theMassiveService.liblibrary as a dependency. -
Configure the
MassiveService.dlllibrary to be copied, at build time, from thelib\win64\static-crtfolder to your output folder. -
In your implementation file, import the SDK:
-
Start and wait till the SDK is ready by calling the
MassiveInitWithAPITokenfunction and defining aMassiveInitCallbackcontinuation function: -
When the user opts in, call the
MassiveStartfunction: -
When the user opts out, call the
MassiveStopfunction:
API reference
Types
typedef enum MassiveStatus
An enumeration of possible states of the Massive SDK.
Values
OP_SUCCESS The operation was successful.
INVALID_ARGS The arguments passed to the function were invalid.
UNINITIALIZED The Massive SDK was not initialized.
INITIALIZING The Massive SDK is initializing.
INTERNAL_ERROR An internal error occurred.
typedef void(__cdecl *MassiveInitCallback)(MassiveStatus status, void *context);
A function called with the result of the Massive SDK’s initialization. The
startup state and local data from the caller are passed to the function.
Parameters
status The startup state of the SDK.
context Any local data passed to the MassiveInitWithAPIToken function.
typedef void(__cdecl *MassiveStatisticDataCallback)(const char *const data, size_t size, void *context);
A function called asynchronously with the usage statistics requested by the
MassiveGetComputationStatistics function.
Parameters
data The statistics, as a JSON array with one entry per sample.
size The size of data in bytes.
context Any local data passed to the MassiveGetComputationStatistics
function.
Functions
MassiveStatus __cdecl MassiveOptionsSetDataBasePath(const wchar_t *path);
Sets the folder for the SDK’s data and log. Call it before the
MassiveInitWithAPIToken function.
Parameters
path An absolute path, or an empty string for the default folder.
Return value
Execution status code.
void __cdecl MassiveInitWithAPIToken(const char *apiToken, MassiveInitCallback callback, void *userData);
Initializes the Massive SDK, pending user opt-in, attributed to your API token.
Parameters
apiToken A unique developer identifier obtained from the applications page.
callback A function called with the result of the initialization.
userData Any local data to pass to the callback function.
void __cdecl MassiveCleanUp();
De-initializes and releases all resources acquired by Massive.
const char *__cdecl MassiveGetVersion();
Returns the version of the Massive SDK.
Return value
The version of the Massive SDK in the format major.minor.patch.
MassiveStatus __cdecl MassiveStart();
Allows computing resources to be opportunistically consumed. The user must agree
to easy-to-understand terms of the exchange you’re offering before you call this
function.
Return value
Execution status code.
MassiveStatus __cdecl MassiveStop();
Disallows computing resources to be consumed.
Return value
Execution status code.
MassiveStatus __cdecl MassiveIsStarted(bool *isStarted);
Queries whether the node runs.
Parameters
isStarted Receives the state.
Return value
Execution status code.
MassiveStatus __cdecl MassiveIsMonetizing(uint32_t minutes, bool *isMonetizing);
Queries whether the node runs and has relayed traffic since it started, or within
the last minutes minutes.
Parameters
minutes How far to look back, in minutes. 0 means since the node started.
isMonetizing Receives the answer.
Return value
Execution status code.
MassiveStatus __cdecl MassiveGetComputationStatistics(const time_t from, const time_t to, const uint16_t samples, MassiveStatisticDataCallback callback, void *context);
Requests the usage statistics over a period, cut into samples.
Parameters
from The start of the period, in seconds since 1970-01-01 UTC.
to The end of the period, in seconds since 1970-01-01 UTC.
samples How many equal parts to cut the period into.
callback A function called asynchronously with the statistics.
context Any local data to pass to the callback function.
Return value
Execution status code.