Skip to content

Commit e4d8286

Browse files
author
Lauris Kaplinski
committed
Merge branch 'master' into installer
2 parents f22b36a + e9155eb commit e4d8286

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

libcdoc.i

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
// CDocReader
104104
//
105105

106-
// Custom wrapper do away with const qualifiers
106+
// Custom wrapper to do away with const qualifiers
107107
%extend libcdoc::CDocReader {
108108
std::vector<libcdoc::Lock> getLocks() {
109109
const std::vector<libcdoc::Lock> &locks = $self->getLocks();
@@ -505,7 +505,14 @@ static std::vector<unsigned char> SWIG_JavaArrayToVectorUnsignedChar(JNIEnv *jen
505505
%typemap(javadirectorin) std::string_view "$jniinput"
506506
// No return of std::string_view so no javadirectorout
507507

508+
// CDocReader
509+
508510
%typemap(javacode) libcdoc::CDocReader %{
511+
// Keep Java references to prevent GC deleting these prematurely
512+
private Configuration config;
513+
private CryptoBackend crypto;
514+
private NetworkBackend network;
515+
509516
public void readFile(java.io.OutputStream ofs) throws CDocException, java.io.IOException {
510517
byte[] buf = new byte[1024];
511518
long result = readData(buf);
@@ -516,6 +523,37 @@ static std::vector<unsigned char> SWIG_JavaArrayToVectorUnsignedChar(JNIEnv *jen
516523
}
517524
%}
518525

526+
%typemap(javaout) libcdoc::CDocReader * libcdoc::CDocReader::createReader {
527+
long cPtr = $jnicall;
528+
if (cPtr == 0) return null;
529+
CDocReader rdr = new CDocReader(cPtr, true);
530+
// Set Java references
531+
rdr.config = conf;
532+
rdr.crypto = crypto;
533+
rdr.network = network;
534+
return rdr;
535+
}
536+
537+
// CDocWriter
538+
539+
%typemap(javacode) libcdoc::CDocWriter %{
540+
// Keep Java references to prevent GC deleting these prematurely
541+
private Configuration config;
542+
private CryptoBackend crypto;
543+
private NetworkBackend network;
544+
%}
545+
546+
%typemap(javaout) libcdoc::CDocWriter * libcdoc::CDocWriter::createWriter {
547+
long cPtr = $jnicall;
548+
if (cPtr == 0) return null;
549+
CDocWriter wrtr = new CDocWriter(cPtr, true);
550+
// Set Java references
551+
wrtr.config = conf;
552+
wrtr.crypto = crypto;
553+
wrtr.network = network;
554+
return wrtr;
555+
}
556+
519557
%typemap(javacode) libcdoc::Configuration %{
520558
public static final String KEYSERVER_SEND_URL = "KEYSERVER_SEND_URL";
521559
public static final String KEYSERVER_FETCH_URL = "KEYSERVER_FETCH_URL";

0 commit comments

Comments
 (0)