Loading...
Searching...
No Matches
lime_jni.cpp File Reference

## Classes

struct | responseHolder
| Holds a stateful function pointer to be called to process the X3DH server response Encapsulate the function pointer in an object to pass its pointer to the java side as it cannot manage stateful function pointers. More...

## Macros

#define | METHOD(MethodPtr, name)

## Functions

static void | jbyteArray2uin8_tVector (jni::JNIEnv &env, const jni::Array< jni::jbyte > &in, std::shared_ptr< std::vector< uint8_t > > &out)
static lime::PeerDeviceStatus | j2cPeerDeviceStatus (jni::jint peerStatus)
| convert an int mapped java enumerated peerDevice Status into a c++ one
static jni::jint | c2jPeerDeviceStatus (lime::PeerDeviceStatus peerStatus)
| convert a c++ enumerated peerDevice Status into a integer one
static jni::jint | c2jCallbackReturn (lime::CallbackReturn status)
| convert a c++ enumerated CallbackReturn into a integer one
static lime::EncryptionPolicy | j2cEncryptionPolicy (jni::jint encryptionPolicy)
| convert a int mapped java enumerated encryptionPolicy into a c++ one
static lime::CurveId | j2cCurveId (jni::jint curveId)
| convert a int mapped java enumerated curveId into a c++ one
JNIEXPORT jint JNICALL | JNI_OnLoad (JavaVM *vm, void *)

## Detailed Description

Author
  Johan Pascal

Copyright
  Copyright (C) 2019 Belledonne Communications SARL

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

## Macro Definition Documentation

## METHOD

#define METHOD | ( |  | MethodPtr,
|  |  | name )

Value:
jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name)
jni::MakeNativePeerMethod
auto MakeNativePeerMethod(const char *name, const L &lambda, std::enable_if_t< std::is_class< L >::value > *=nullptr)
Definition native_method.hpp:209

## Function Documentation

## c2jCallbackReturn()

jni::jint c2jCallbackReturn | ( | lime::CallbackReturn | status | ) |

static

convert a c++ enumerated CallbackReturn into a integer one

mapping in java is : SUCCESS(0) FAIL(1)

Parameters

  [in] | status | the c++ enumerated peer Device Status

Returns
  the java enumerated peer device status (silently default to 1:FAIL)

## c2jPeerDeviceStatus()

jni::jint c2jPeerDeviceStatus | ( | lime::PeerDeviceStatus | peerStatus | ) |

static

convert a c++ enumerated peerDevice Status into a integer one

mapping in java is : UNTRUSTED(0) TRUSTED(1) UNSAFE(2) FAIL(3) UNKNOWN(4)

Parameters

  [in] | peerStatus | the c++ enumerated peer Device Status

Returns
  the java enumerated peer device status (silently default to 4:UNKNOWN)

## j2cCurveId()

lime::CurveId j2cCurveId | ( | jni::jint | curveId | ) |

static

convert a int mapped java enumerated curveId into a c++ one

mapping is : C25519(1) C448(2)

Parameters

  [in] | curveId | The java mapped integer to a curveId enum

Returns
  the c++ enumerated curveId (silently default to unset)

## j2cEncryptionPolicy()

lime::EncryptionPolicy j2cEncryptionPolicy | ( | jni::jint | encryptionPolicy | ) |

static

convert a int mapped java enumerated encryptionPolicy into a c++ one

mapping is : DRMESSAGE(0) CIPHERMESSAGE(1) OPTIMIZEUPLOADSIZE(2) OPTIMIZEGLOBALBANDWIDTH(3)

Parameters

  [in] | encryptionPolicy | The java mapped integer to an encryption policy enum

Returns
  the c++ enumerated encryption policy (silently default to optimizeUploadSize)

## j2cPeerDeviceStatus()

lime::PeerDeviceStatus j2cPeerDeviceStatus | ( | jni::jint | peerStatus | ) |

static

convert an int mapped java enumerated peerDevice Status into a c++ one

mapping is : UNTRUSTED(0) TRUSTED(1) UNSAFE(2) FAIL(3) UNKNOWN(4)

Parameters

  [in] | peerStatus | The java mapped integer to a curveId enum

Returns
  the c++ enumerated peer device status (silently default to unknown)

## jbyteArray2uin8_tVector()

void jbyteArray2uin8_tVector | ( | jni::JNIEnv & | env,
|  | const jni::Array< jni::jbyte > & | in,
|  | std::shared_ptr< std::vector< uint8_t > > & | out )

static

## JNI_OnLoad()

JNIEXPORT jint JNICALL JNI_OnLoad | ( | JavaVM * | vm,
|  | void * | )

< a unique pointer to the actual lime manager

< a global reference to the java postToX3DH object. TODO: unclear if EnvIgnoringDeleter is not a better fit here.

Constructor unlike the native lime manager constructor, this one get only one argument has cpp closure cannot be passed easily to java

Parameters

  [in] | db_access | the database access path

process response from X3DH server This function is bind to a java PostToX3DH object process_response method It :

- converts from jbytes(signed char) to unsigned char the response array
- retrieves from the given back responseHolder pointer the closure pointer to callback the line lib and call it