Chapter 12. The ViewKit NetLS Interface

This chapter describes the VkNLS class, which provides ViewKit's support for the NetLS™ network licensing manager. VkNLS is a base class.

Overview of ViewKit NetLS Support

The VkNLS class provides a high-level interface to the NetLS network licensing manager. VkNLS simplifies the process of interacting with the network licensing manager by handling all license verification, informing the user if it could not obtain a license or if the license is about to expire, and shutting down the application if it could not obtain a license. All you need to do to add licensing support in your application is instantiate a VkNLS object and provide some basic information about the application and its licensing. The exact nature of the license is determined by the license generation process, which is separate from the program itself. You must contact your NetLS administrator for information on generating licenses appropriate for your application.

Upon instantiation, the VkNLS object looks for either a node-locked or concurrent (networked) license; the application does not differentiate between these forms of licensing. If it finds no valid license, the VkNLS object posts a fatal error dialog to exit the application.

If the VkNLS object obtains a license, it rechecks the license every ten minutes. If the application loses its license, the VkNLS object posts a warning dialog informing the user that the license is no longer valid. VkNLS does not terminate the application, but reposts the warning message every minute until the license is restored.

When the VkNLS object initially obtains a license, it also checks to see whether the license is about to expire. VkNLS can post a warning dialog if the license has 90 days or less until expiration.

Using the VkNLS Class

All you need to do to use the VkNLS class in your application is to instantiate a VkNLS object:

VkNLS (char *vendorID, long key, int productID, char *version,
       NLSCallback loseLicenseCallback = NULL,
       void *clientData = NULL)

vendorID is an encrypted string that uniquely identifies a vendor. key is an integer key. productID is an integer value that uniquely identifies a vendor's products. You must obtain these values from your NetLS administrator. version specifies the version of the product, and can be any string you desire.

You can optionally provide a function pointer as the loseLicenseCallback argument. The VkNLS object calls this function if it is not able to obtain a license. If you provide a loseLicenseCallback function, VkNLS does not post the fatal error dialog to exit the application; you must perform whatever error recovery is needed in the function and then exit if appropriate. The NLSCallback definition is:

typedef void (*NLSCallback)( void *)

VkNLS passes to the loseLicenseCallback function the clientData pointer, if you provide one. Currently, VkNLS does not use any return value that you might provide.


Note: The NLSCallback function must be either a global function or a static member function; it cannot be a regular member function.

The VkNLS destructor frees all storage associated with a VkNLS object and returns any license currently in use by the application.

X Resources Associated With the VkNLS Class

VkNLS recognizes several X application resources that control the messages posted by the various dialogs:

thirtyDayMessage 


The message displayed when 30 or fewer days are left before a license expires. The message should include a “%d” printf(3S)-style integer specification. VkNLS replaces this with the remaining number of days. For example:

*thirtyDayMessage: Your license will expire in %d days

If there is no value for this resource (the default), then VkNLS does not post a warning dialog when 30 or fewer days are left before a license expires.

sixtyDayMessage 


The message displayed when between 60 and 30 days are left before a license expires. The message should include a “%d” printf()-style integer specification. VkNLS replaces this with the remaining number of days. If there is no value for this resource (the default), then VkNLS does not post a warning dialog when between 60 and 30 days are left before a license expires.

ninetyDayMessage 


The message displayed when between 90 and 60 days are left before a license expires. The message should include a “%d” printf()-style integer specification. VkNLS replaces this with the remaining number of days. If there is no value for this resource (the default), then VkNLS does not post a warning dialog when between 90 and 60 days are left before a license expires.

disableLicenseWarnings 


If TRUE, then the VkNLS object does not display warnings that a license has 90 or fewer days before expiration. The default is FALSE. This resource does not disable messages when the license has 30 or fewer days before expiration.

disableThirtyDayLicenseWarnings 


If TRUE, then the VkNLS object does not display warnings that a license has 30 or fewer days before expiration. The default is FALSE.

notEnoughLicensesMessage 


The message displayed when an application is licensed, but there are not enough licenses currently available to support the number of people using them. If you do not provide a value for this resource, the warning dialog that VkNLS posts is empty.

noLicenseMessage 


The message displayed when the VkNLS object finds no valid license. If you do not provide a value for this resource, the warning dialog that VkNLS posts is empty.

licenseExpiredMessage 


The message displayed when the application's license expires. If you do not provide a value for this resource, the warning dialog that VkNLS posts is empty.

warnLoseLicenseMessage 


The message displayed when an application loses its license while it is running. If there is no value for this resource (the default), then VkNLS does not post a warning dialog when the application loses its license.

Example of Using VkNLS

The program in Example 12-1 demonstrates how to add network license support to an application. Note that the vendor ID, the key, and the product ID in this program are only samples. If you attempt to compile this program, you will not be able to obtain a license.

Example 12-1. Example of Using VkNLS

///////////////////////////////////////////////////////////////////
// Demonstrate how to add NetLS protection to a program
///////////////////////////////////////////////////////////////////

#include <Vk/VkApp.h>
#include <Vk/VkSimpleWindow.h>
#include <Vk/VkNLS.h>
#include <Xm/Label.h>

// Sample vendor ID - not real
#define VENDOR_ID "123456789.01.02.03.04.05.00.00.00" 
// Sample KEY - not real
#define KEY 12345
// Sample product ID - not real
#define PRODUCT_ID  21
#define VERSION  "2.1.1"

class HelloWindow: public VkSimpleWindow {

  protected:
    Widget _label;

  public:
    HelloWindow ( const char *name );
    ~HelloWindow();
    virtual const char* className();
};


HelloWindow::HelloWindow ( const char *name ) : VkSimpleWindow ( name ) 
{
    _label =  XmCreateLabel ( mainWindowWidget(), "hello", NULL, 0 );
    addView(_label);
}

const char * HelloWindow::className()
{
    return "HelloWindow";
}

HelloWindow::~HelloWindow()
{
    // Empty
}


void main ( int argc, char **argv )
{
    VkApp        *app = new VkApp("Hello", &argc, argv);
    HelloWindow  *win = new HelloWindow("hello");

    win->show();
    VkNLS *netls = new VkNLS(VENDOR_ID, KEY, PRODUCT_ID, VERSION);
    app->run();
}