From 497745ad31c90545b288e2845049e0ce474bcbe2 Mon Sep 17 00:00:00 2001
From: gcontini <1121667+gcontini@users.noreply.github.com>
Date: 周六, 19 10月 2019 10:10:45 +0800
Subject: [PATCH] Merge branch 'feature/code_review_and_refactor' into develop

---
 example/example.cpp |   75 +++++++++++++++++++------------------
 1 files changed, 39 insertions(+), 36 deletions(-)

diff --git a/example/example.cpp b/example/example.cpp
index d8af95f..2379d6a 100644
--- a/example/example.cpp
+++ b/example/example.cpp
@@ -5,40 +5,43 @@
 
 using namespace std;
 
-int main(int argc, char *argv[])
-{
-    map<EVENT_TYPE, string> stringByEventType;
-    stringByEventType[LICENSE_OK                      ] = "OK ";
-    stringByEventType[LICENSE_FILE_NOT_FOUND          ] = "license file not found ";
-    stringByEventType[LICENSE_SERVER_NOT_FOUND        ] = "license server can't be contacted ";
-    stringByEventType[ENVIRONMENT_VARIABLE_NOT_DEFINED] = "environment variable not defined ";
-    stringByEventType[FILE_FORMAT_NOT_RECOGNIZED      ] = "license file has invalid format (not .ini file) ";
-    stringByEventType[LICENSE_MALFORMED               ] = "some mandatory field are missing, or data can't be fully read. ";
-    stringByEventType[PRODUCT_NOT_LICENSED            ] = "this product was not licensed ";
-    stringByEventType[PRODUCT_EXPIRED                 ] = "licence expired ";
-    stringByEventType[LICENSE_CORRUPTED               ] = "license signature didn't match with current license ";
-    stringByEventType[IDENTIFIERS_MISMATCH            ] = "Calculated identifier and the one provided in license didn't match";
-    stringByEventType[LICENSE_FILE_FOUND              ] = "licence file not found ";
-    stringByEventType[LICENSE_VERIFIED                ] = "licence verified ";
-    
-    const string licLocation("example.lic");
-    
-    LicenseInfo licenseInfo;
-    LicenseLocation licenseLocation;
-    licenseLocation.openFileNearModule = false;
-    licenseLocation.licenseFileLocation = licLocation.c_str();
-    licenseLocation.environmentVariableName = "";
-    EVENT_TYPE result = acquire_license("example", licenseLocation, &licenseInfo);
-    
-    if (result != LICENSE_OK){
-        PcSignature signature;
-        FUNCTION_RETURN generate_ok = generate_user_pc_signature(signature, ETHERNET);
-        
-        cout << "license ERROR :" << endl;
-        cout << "    " << stringByEventType[result].c_str() << endl;
-        cout << "the pc signature is :" << endl;
-        cout << "    " << signature << endl;
-    }
-    else
-        cout << "licence OK" << endl;
+int main(int argc, char *argv[]) {
+	map<EVENT_TYPE, string> stringByEventType;
+	stringByEventType[LICENSE_OK] = "OK ";
+	stringByEventType[LICENSE_FILE_NOT_FOUND] = "license file not found ";
+	stringByEventType[LICENSE_SERVER_NOT_FOUND] = "license server can't be contacted ";
+	stringByEventType[ENVIRONMENT_VARIABLE_NOT_DEFINED] = "environment variable not defined ";
+	stringByEventType[FILE_FORMAT_NOT_RECOGNIZED] = "license file has invalid format (not .ini file) ";
+	stringByEventType[LICENSE_MALFORMED] = "some mandatory field are missing, or data can't be fully read. ";
+	stringByEventType[PRODUCT_NOT_LICENSED] = "this product was not licensed ";
+	stringByEventType[PRODUCT_EXPIRED] = "license expired ";
+	stringByEventType[LICENSE_CORRUPTED] = "license signature didn't match with current license ";
+	stringByEventType[IDENTIFIERS_MISMATCH] = "Calculated identifier and the one provided in license didn't match";
+
+	LicenseInfo licenseInfo;
+	EVENT_TYPE result = acquire_license("example", nullptr, &licenseInfo);
+
+	if (result == LICENSE_OK) {
+		//for this example we want to link the license to the execution hardware.
+		if (licenseInfo.linked_to_pc) {
+			cout
+					<< "No client signature in license file, generate license with -s <id>";
+			result = IDENTIFIERS_MISMATCH;
+		} else {
+			cout << "license OK" << endl;
+		}
+	}
+	if (result != LICENSE_OK) {
+		cout << "license ERROR :" << endl;
+		cout << "    " << stringByEventType[result].c_str() << endl;
+		if (result == IDENTIFIERS_MISMATCH) {
+			PcSignature signature;
+			FUNCTION_RETURN generate_ok = generate_user_pc_signature(signature,
+					DEFAULT);
+			cout << "the pc signature is :" << endl;
+			cout << "    " << signature << endl;
+		}
+	}
+
+	return result;
 }

--
Gitblit v1.9.1