napperley
07/17/2019, 2:18 AMElena Lepilkina
07/17/2019, 7:05 AMnapperley
07/19/2019, 3:11 AMstatic inline MQTTClient_connectOptions* createMqttConnectionOptions() {
MQTTClient_connectOptions* options = (MQTTClient_connectOptions*) malloc(sizeof(MQTTClient_connectOptions));
options->struct_id[0] = 'M';
options->struct_id[1] = 'Q';
options->struct_id[2] = 'T';
options->struct_id[3] = 'C';
options->struct_version = 6;
options->reliable = 1;
options->will = NULL;
options->username = NULL;
options->password = NULL;
options->retryInterval = 0;
options->ssl = NULL;
options->serverURIcount = 0;
options->serverURIs = NULL;
options->MQTTVersion = MQTTVERSION_DEFAULT;
options->maxInflightMessages = -1;
return options;
}
Initialization of internal structs on the Kotlin side:
// ...
private fun updateConnOptions(newConnOptions: MqttConnectionOptions, newUsername: CPointer<ByteVar>?,
newPassword: CPointer<ByteVar>?) {
setupConnOptionsReturned()
setupConnOptionsBinarypwd()
if (_connOptions != null) {
with(_connOptions.pointed) {
username = newUsername
password = newPassword
keepAliveInterval = newConnOptions.keepAliveInterval
cleansession = if (newConnOptions.cleanSession) 1 else 0
cleanstart = if (newConnOptions.cleanStart) 1 else 0
connectTimeout = newConnOptions.connectionTimeout
retryInterval = newConnOptions.retryInterval
}
}
}
private fun setupConnOptionsBinarypwd() {
if (_connOptions != null) {
with(_connOptions.pointed.binarypwd) {
len = 0
data = null
}
}
}
private fun setupConnOptionsReturned() {
if (_connOptions != null) {
with(_connOptions.pointed.returned) {
serverURI = null
sessionPresent = 0
MQTTVersion = 0
}
}
}