Skip to content

Commit 77b7e64

Browse files
authored
Merge pull request #2 from cryptlex/featureFunctions
Added feature functions
2 parents 404735f + 5b2656a commit 77b7e64

4 files changed

Lines changed: 85 additions & 0 deletions

File tree

cryptlex/lexfloatclient/lexfloatclient.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ def __init__(self, name, allowed_uses, total_uses, gross_uses):
1313
self.total_uses = total_uses
1414
self.gross_uses = gross_uses
1515

16+
class ProductVersionFeatureFlag(object):
17+
def __init__(self, name, enabled, data):
18+
self.name = name
19+
self.enabled = enabled
20+
self.data = data
1621

1722
class LexFloatClient:
1823
@staticmethod
@@ -96,6 +101,66 @@ def SetFloatingClientMetadata(key, value):
96101
if LexFloatStatusCodes.LF_OK != status:
97102
raise LexFloatClientException(status)
98103

104+
@staticmethod
105+
def GetProductVersionName():
106+
"""Gets the product version name.
107+
108+
Raises:
109+
LexFloatClientException
110+
111+
Returns:
112+
str: name of the product version.
113+
"""
114+
115+
buffer_size = 256
116+
buffer = LexFloatClientNative.get_ctype_string_buffer(buffer_size)
117+
status = LexFloatClientNative.GetProductVersionName(buffer,buffer_size)
118+
if status != LexFloatStatusCodes.LF_OK:
119+
raise LexFloatClientException(status)
120+
return LexFloatClientNative.byte_to_string(buffer.value)
121+
122+
@staticmethod
123+
def GetProductVersionDisplayName():
124+
"""Gets the product version display name.
125+
126+
Raises:
127+
LexFloatClientException
128+
129+
Returns:
130+
str: display name of the product version.
131+
"""
132+
133+
buffer_size = 256
134+
buffer = LexFloatClientNative.get_ctype_string_buffer(buffer_size)
135+
status = LexFloatClientNative.GetProductVersionDisplayName(buffer,buffer_size)
136+
if status != LexFloatStatusCodes.LF_OK:
137+
raise LexFloatClientException(status)
138+
return LexFloatClientNative.byte_to_string(buffer.value)
139+
140+
@staticmethod
141+
def GetProductVersionFeatureFlag(name):
142+
"""Gets the product version feature flag.
143+
144+
Args:
145+
name (str): name of the feature flag
146+
147+
Raises:
148+
LexFloatClientException
149+
150+
Returns:
151+
ProductVersionFeatureFlag: product version feature flag
152+
"""
153+
cstring_name = LexFloatClientNative.get_ctype_string(name)
154+
enabled = ctypes.c_uint()
155+
buffer_size = 256
156+
buffer = LexFloatClientNative.get_ctype_string_buffer(buffer_size)
157+
status = LexFloatClientNative.GetProductVersionFeatureFlag(cstring_name, ctypes.byref(enabled), buffer, buffer_size)
158+
if status == LexFloatStatusCodes.LF_OK:
159+
isEnabled = enabled.value > 0
160+
return ProductVersionFeatureFlag(name, isEnabled, LexFloatClientNative.byte_to_string(buffer.value))
161+
else:
162+
raise LexFloatClientException(status)
163+
99164
@staticmethod
100165
def GetHostLicenseMetadata(key):
101166
"""Get the value of the license metadata field associated with the

cryptlex/lexfloatclient/lexfloatclient_exception.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ def get_error_message(code):
4444
return 'The meter attribute does not exist.'
4545
if code == LexFloatStatusCodes.LF_E_METER_ATTRIBUTE_USES_LIMIT_REACHED:
4646
return 'The meter attribute has reached it\'s usage limit.'
47+
if code == LexFloatStatusCodes.LF_E_PRODUCT_VERSION_NOT_LINKED:
48+
return 'No product version is linked with the license.'
49+
if code == LexFloatStatusCodes.LF_E_FEATURE_FLAG_NOT_FOUND:
50+
return 'The product version feature flag does not exist.'
4751
if code == LexFloatStatusCodes.LF_E_IP:
4852
return 'IP address is not allowed.'
4953
if code == LexFloatStatusCodes.LF_E_CLIENT:

cryptlex/lexfloatclient/lexfloatclient_native.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,18 @@ def byte_to_string(input):
127127
SetFloatingClientMetadata.argtypes = [CSTRTYPE, CSTRTYPE]
128128
SetFloatingClientMetadata.restype = c_int
129129

130+
GetProductVersionName = library.GetProductVersionName
131+
GetProductVersionName.argtypes = [STRTYPE,c_uint32]
132+
GetProductVersionName.restype = c_int
133+
134+
GetProductVersionDisplayName = library.GetProductVersionDisplayName
135+
GetProductVersionDisplayName.argtypes = [STRTYPE,c_uint32]
136+
GetProductVersionDisplayName.restype = c_int
137+
138+
GetProductVersionFeatureFlag = library.GetProductVersionFeatureFlag
139+
GetProductVersionFeatureFlag.argtypes = [CSTRTYPE, POINTER(c_uint32), STRTYPE, c_uint32]
140+
GetProductVersionFeatureFlag.restype = c_int
141+
130142
GetHostLicenseMetadata = library.GetHostLicenseMetadata
131143
GetHostLicenseMetadata.argtypes = [CSTRTYPE, STRTYPE, c_uint32]
132144
GetHostLicenseMetadata.restype = c_int

cryptlex/lexfloatclient/lexfloatstatus_codes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class LexFloatStatusCodes:
3838

3939
LF_E_METER_ATTRIBUTE_USES_LIMIT_REACHED = 56
4040

41+
LF_E_PRODUCT_VERSION_NOT_LINKED = 57
42+
43+
LF_E_FEATURE_FLAG_NOT_FOUND = 58
44+
4145
LF_E_IP = 60
4246

4347
LF_E_CLIENT = 70

0 commit comments

Comments
 (0)