Initialisation
It is highly recommended to initialize SignWare, especially when running in a multithreaded environment.Initialisation should at minimum set a license key and check if all required SignWare modules are loaded and accessible.
- Note:
- Initialisation is not thread safe, at maximum one thread may execute SignWare initialisation at any time
the code below performs a minimum initialisation.
Sample (C)
static LONG gSpinlock = 0;
static void lockGlobalSpinlock ()
{
while (InterlockedExchange(&gSpinlock, 1) != 0)
Sleep (0);
}
static void unlockGlobalSpinlock ()
{
InterlockedExchange (&gSpinlock, 0);
}
/*
* Initialize SignWare
*
* Initialisation cannot be called multiple times in parallel in a multithreaded environment
*
* return int, SP_NOERR on success, else error code
*/
int initSignWare()
{
/*
* Use s spinlock as sample thread synchronization to assure t maximum one thread
* is initializing SignWare at any time
*/
lockGlobalSpinlock ();
SPSignwareSetLicenseKey (license_key, strlen (license_key),
NULL, NULL, NULL, 0);
SPINT32 iModules = 0;
int rc;
SPINT32 iDays = -1;
int iMinModules = SP_SDK_LOADED;
pSPREFERENCE_T pReference = 0;
/* if you want to render Signatures */
iMinModules |= SP_GRAPHICLIB_LOADED;
/* If you want use GUI objects in a java environment */
iMinModules |= SP_AWT_LOADED;
rc = SPSignwareStatus(& iModules);
/* cannot get status */
if(rc != SP_NOERR) {
unlockGlobalSpinlock ();
return rc;
}
/* check required modules */
if((iModules & iMinModules) != iMinModules) {
unlockGlobalSpinlock ();
return SP_LINKLIBRARYERR;
}
rc = SPSignwareDaysLM(& iDays);
/* cannot query license expiry */
if(rc != SP_NOERR) {
unlockGlobalSpinlock ();
return rc;
}
/* Check if the license is expired */
if(iDays < 0) {
unlockGlobalSpinlock ();
return SP_LICENSEERR;
}
/* check License is available in this process */
rc = SPReferenceCreate(&pReference);
if(rc != SP_NOERR) {
unlockGlobalSpinlock ();
return rc;
}
SPReferenceFree(&pReference);
unlockGlobalSpinlock ();
return SP_NOERR;
}
Sample (Java)
import de.softpro.signware.SPSignWare;
/*
* Initialize SignWare
*
* Initialisation cannot be called multiple times in parallel in a multithreaded environment
*
* throws SPSignwareException on error
*
* Note: the synchronized keyword assures one thread can run this code at any time
*/
synchronized void initSignWare() throws SPSignwareException, java.io.UnsupportedEncodingException
{
int iModules = 0;
int rc;
int iDays = -1;
SPSignware.setLicenseKey (license_key.getBytes ("UTF-8"), null, null, null);
int iMinModules = SPSignware.SP_SDK_LOADED;
/* if you want to render Signatures */
iMinModules |= SPSignware.SP_GRAPHICLIB_LOADED;
/* If you want use GUI objects in a java environment */
iMinModules |= SPSignware.SP_AWT_LOADED;
iModules = SPSignware.loadedModules();
/* check required modules */
if((iModules & iMinModules) != iMinModules)
throw new SPSignwareException(SPSignwareException.SP_LINKLIBRARYERR);
iDays = SPSignware.daysLM();
/* Check if the license is expired */
if(iDays < 0)
throw new SPSignwareException(SPSignwareException.SP_LICENSEERR);
/* check License is available in this process */
SPReference pReference = new SPReference();
}
Sample (C#)
using ACTIVESWLib;
public class SignwareInit
{
static private System.Object swInitLock = new System.Object();
/*
* Initialize SignWare
*
* Initialisation cannot be called multiple times in parallel in a multithreaded environment
*
* returns 0 on success, else error code
*
* throws exception if SignWare cannot be instantiated
*/
SPError initSignWare()
{
/* lock this code, at maximum one thread can run this code at any time */
lock (swInitLock) {
int iModules = 0;
int rc;
int iDays = -1;
SPSignware spSignware = new SPSignwareClass();
/* If the Product ID needs to be setup then uncomment the next
* line and replace the SignWare Product ID by the desired
* Product ID
*/
// spSignWare.SetLM2(809213154, 373825325);
int iMinModules = (int) SPSignwareStatus.SPX_SDK_LOADED;
/* if you want to render Signatures */
iMinModules |= (int) SPSignwareStatus.SPX_GRAPHICLIB_LOADED;
/* If you want use GUI objects in a java environment */
iMinModules |= (int) SPSignwareStatus.SPX_AWT_LOADED;
rc = spSignware.Status(out iModules);
/* cannot get status */
if(rc != (int) SPError.SPX_NOERR) return (SPError) rc;
/* check required modules */
if((iModules & iMinModules) != iMinModules)
return SPError.SPX_LINKLIBRARYERR;
rc = spSignware.DaysLM(out iDays);
/* cannot get expiry */
if(rc != (int) SPError.SPX_NOERR) return (SPError) rc;
/* Check if the license is expired */
if(iDays < 0)
return SPError.SPX_LICENSEERR;
SPReference spReference = new SPReferenceClass();
rc = spReference.Create();
if(rc != (int) SPError.SPX_NOERR)
return (SPError) rc;
}
return SPError.SPX_NOERR;
}
}