Example licensed product implementation

The following code is an excerpt from the example licensed product, CoolSoftCAD, which uses the CommonPoint application system Licensing framework to license the product. This example product code is provided to show how each of the framework member functions can be used to do real product license checking. The example product provides GetOperations and AcceptOperationsResults implementations, which are required of all derived classes. In addition, the licensed product overrides the default SelectProvider and ReportException implementations to introduce custom behavior.

      class TCoolSoftCADLicenseUse : public TLicenseUse {
      //    Copyright (C) 1995 Taligent, Inc. All rights reserved.
      public:
          //.................................................................
          //  Constructors and destructors.
                      TCoolSoftCADLicenseUse();
          virtual     ~TCoolSoftCADLicenseUse();
      
      protected:
          //.................................................................
          //  SelectProvider is for provider prioritization.
          virtual voidSelectProvider(TLicenseProduct& selection, const TCollectionOf<TLicenseProduct>& providers);
          //.................................................................
          //  GetOperations and AcceptOperationsResults are for challenge negotiation.
          virtual voidGetOperations       (const TLicenseProduct& theProviderProduct,
    TCollectionOf<TProviderOperation>& operations); virtual voidAcceptOperationsResults(const TLicenseProduct& theProviderProduct, const TCollectionOf<TProviderOperation>& operations); //................................................................. // ReportException is called before throwing an exception to the // caller (product calling Check()). virtual voidReportException(const TStandardException& exception); }; #define kCoolSoftVendorId "OID: 1.3.6.1.4.1.63" #define kCoolSoftVendorContact "\ Cool Software, Inc.\n\ 1234 Street\n\ Cupertino, CA 95014\n\ \n\ For product information please call:408-555-5555\n\ For technical support please call: 408-555-5554" #define kCoolSoftCADId "CoolSoft CAD" #define kCoolSoftCADVersion "2.0v3" #define kCoolSoftCADName "CoolSoft CAD 2.0v3" #define kCoolSoftCADRequestSize 10 #define kCoolSoftCADConsumeRate TSeconds(30)
    //..................................................................... // Define our constants. static const TLicenseVendor kCoolSoftCADVendor( TLicenseVendorIdentifier(kCoolSoftVendorId), TStandardText(kCoolSoftVendorContact)); static const TLicenseProduct kCoolSoftCADProduct( TLicenseVendorIdentifier(kCoolSoftVendorId), TLicenseProductIdentifier(kCoolSoftCADId), TLicenseVersion(kCoolSoftCADVersion), TStandardText(kCoolSoftCADName)); static long kCoolSoftCADSecrets[4] = {0x12345678, 0xabcdef01, 0x0f1e2d3c, 0xfedcba98}; //..................................................................... // Constructors and destructors // TCoolSoftCADLicenseUse::TCoolSoftCADLicenseUse() : TLicenseUse(kCoolSoftCADProduct) { SetRequestSize(kCoolSoftCADRequestSize); SetConsumptionRate(kCoolSoftCADConsumeRate); } TCoolSoftCADLicenseUse::~TCoolSoftCADLicenseUse() { } // CoolSoftCAD specific implementation of the GetOperations pure virtual function.
    //Note that "TRandomChallenge" is made up for sake of the example. void TCoolSoftCADLicenseUse::GetOperations(const TLicenseProduct& theProviderProduct,
    TCollectionOf<TProviderOperation>& operations) { if(theProviderProduct == TAcmeLicenseProvider::kProduct) { TBasicChallenge basicChallenge(3, randomValueFromSomewhere); operations.Add(&basicChallenge); } else if(theProviderProduct == TFlexLicenseProvider::kProduct) { TRandomChallenge randomChallenge(/*...*/); operations.Add(&randomChallenge); } // etc. } // CoolSoftCAD specific implementation of the AcceptOperationsResults pure virtual function. // Note that "TRandomChallenge" is made up for sake of this example. void TCoolSoftCADLicenseUse::AcceptOperationsResults(const TLicenseProduct& theProviderProduct, const TCollectionOf<TProviderOperation>& operations) { TDeleterFor< TIteratorOver<TProviderOperation> > iterator(operations.CreateIterator()); for(TProviderOperation *op = iterator->First(); op != NULL; op = iterator->Next()) { TStandardText operationName; op->GetOperationType(operationName); if(operationName == TBasicChallenge::kOperationType) { if(!((TBasicChallenge*)op)->CompareSecret( kCoolSoftCADSecrets[3])) throw TCoolSoftCADOperationException( TCoolSoftCADOperationException::kFailedtheTest); } else if(operationName == TRandomChallenge::kOperationType) { if(!op->MothersMaidenName()) throw TCoolSoftCADOperationException( TCoolSoftCADOperationException::kWrongName); } // etc. } } // CoolSoftCAD specific implementation of ReportException that will // override the TLicenseUse provided default implementation. void TCoolSoftCADLicenseUse::ReportException(const TStandardException& exception) { // Let the framework log the exception and present the dialog to // the user. We put the ReportException call in a TRY block so // that exception will not get thrown to the product. We only // want the product to run really slow when it is not licensed. try { TLicenseUse::ReportException(exception); } catch(...) {} // Do my special stuff MakeThisProductReallySlooowwwww(); } // Cool Software, Inc. decided to allocate the license at static // constructor time. The license will not actually be checked out until // the first call to TCoolSoftCADLicenseUse::Check(). static TCoolSoftCADLicenseUse gCoolSoftCADLicenseUse; // This is an example piece of the CoolSoftCAD product code that // illustrates how the framework is activated at run time. This // example entry point could easily be a "main" routine. void CoolSoftCADEntryPoint() { // First thing to do is check the licensing situation. We have // already handled any possible exception in our ReportException // function. gCoolSoftCADLicenseUse.Check(); // Do our product stuff. }


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker