Defining the Custom Locking Criteria
Declare Variables/Constants
Define the implementation of the callback function:
class Callback_CustEx implements ApplicationContext.ICallback
{
public long callback(String input, Pointer output, Pointer size)
{
if (output == null)
{
// Means licensing library is asking for the size of memory buffer to be allocated.
if(size != null)
{
size.setInt(0, SAMPLE_CALLBACK_OUTPUT_XML.length());//Output XML described below
}
else
return 1; //return error
}
else
{
// Non-NULL means licensing library has allocated the required buffer space and asking for the actual data to be copied into this buffer
output.setString(0, SAMPLE_CALLBACK_OUTPUT_XML);
}
return 0; //Success
}
}
Output XML
The SAMPLE_CALLBACK_OUTPUT_XML (defined in the previous section) is defined in the following format:
final String SAMPLE_CALLBACK_OUTPUT_XML =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+
"<callbackOutputData>"+
"<customFingerprint>"+
"<item>" +
"<rawValue>111222333444555666777888999aaab</rawValue>"+
"</item>"+
"<item>"+
"<rawValue>abcdef0123456789abcdef012345678</rawValue>"+
"</item>"+
"</customFingerprint>"+
"</callbackOutputData>";
Response XML
This following XML defines the format of the response XML:
<?xml version="1.0" encoding="utf-8"?>
<callbackOutputData>
<customFingerprint>
<item>
<rawValue></rawValue>
</item>
<item>
<rawValue></rawValue>
</item>
</customFingerprint>
</callbackOutputData>
API Calls
To register the custom locking callback in your application, execute the APIs in the specified sequential order only:
>Callback_CustEx callback_obj = new Callback_CustEx();
>ApplicationContext.registerCallback(null,LicensingConstants.SNTL_CALLBACK_TYPE_CUSTOM_FINGERPRINT,callback_obj);
If the ApplicationContext.registerCallback call is successful, the registered callback will be invoked by the licensing library whenever locking-related information is seek/retrieved/verified by the licensing library.
Notes
>ApplicationContext.registerCallback API has global scope and its effect is valid for all app-contexts. This API should be called before creating any app-context.
>If this API is called after performing any licensing-related operations then complete licensing library is re-initialized which means all prior created app-contexts become invalid and also all earlier licenses are reloaded if library is in standalone mode.
>Registered call-back is invoked twice by the licensing library for every operation. First invocation is to ask the call-back about the buffer size (in bytes) to hold the response output buffer. In the second invocation it expects the call-back to write the output contents into the allocated buffer passed as the second arguments.
>For illustration purpose, we have taken static contents for variable SAMPLE_CALLBACK_OUTPUT_XML. In real world applications, this output could be built dynamically depending upon vendor’s requirements.