Skip to content

Commit

Permalink
Hawtjni: Shared_pointer support added in hawtjni
Browse files Browse the repository at this point in the history
shared Pinter support was missing in the existing library
code
  • Loading branch information
ossdev07 committed May 24, 2018
1 parent 84aa381 commit 1c2d511
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ void generateGetFields(JNIClass clazz) {
JNIClass superclazz = clazz.getSuperclass();
String clazzName = clazz.getNativeName();
String superName = superclazz.getNativeName();
String Methodname;
if (!superclazz.getName().equals("java.lang.Object")) {
/*
* Windows exception - cannot call get/set function of super class
Expand Down Expand Up @@ -281,13 +282,45 @@ void generateGetFields(JNIClass clazz) {
if (accessor == null || accessor.length() == 0)
accessor = field.getName();
if (type.isPrimitive()) {
if(field.isSharedPointer()){
output("\tlpStruct->");
output(accessor);
output(" = ");
output("std::shared_ptr");
output("<");
Methodname =field.getCast();
String Method =Methodname.replace("*", ">");
Method =Method.replace("(", "");
Method =Method.replace(")", "");
output(Method);
output("(");
output(field.getCast());
output("(intptr_t)");
if (isCPP) {
output("env->Get");
} else {
output("(*env)->Get");
}
output(type.getTypeSignature1(!type.equals(type64)));
if (isCPP) {
output("Field(lpObject, ");
} else {
output("Field(env, lpObject, ");
}
output(field.getDeclaringClass().getSimpleName());
output("Fc.");
output(field.getName());
output(")");
output(");");
}else {
output("\tlpStruct->");
output(accessor);
output(" = ");
output(field.getCast());
if( field.isPointer() ) {
output("(intptr_t)");
}

if (isCPP) {
output("env->Get");
} else {
Expand All @@ -303,6 +336,7 @@ void generateGetFields(JNIClass clazz) {
output("Fc.");
output(field.getName());
output(");");
}
} else if (type.isArray()) {
JNIType componentType = type.getComponentType(), componentType64 = type64.getComponentType();
if (componentType.isPrimitive()) {
Expand Down Expand Up @@ -455,8 +489,15 @@ void generateSetFields(JNIClass clazz) {
if( field.isPointer() ) {
output("(intptr_t)");
}
if( field.isSharedPointer() ) {
output("(&");
}if(field.isSharedPointer() ) {
output("lpStruct->"+accessor);
output("));");
}else {
output("lpStruct->"+accessor);
output(");");
}
} else if (type.isArray()) {
JNIType componentType = type.getComponentType(), componentType64 = type64.getComponentType();
if (componentType.isPrimitive()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ public interface JNIField {
public String getConditional();
public boolean ignore();

public boolean isSharedPointer();
public boolean isPointer();
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ public boolean isPointer() {
return getFlag(POINTER_FIELD) || ( type.getWrappedClass() == Long.TYPE && getCast().endsWith("*)") );
}

public boolean isSharedPointer() {
if( annotation == null ) {

return false;
}
return getFlag(SHARED_PTR) || ( type.getWrappedClass() == Long.TYPE && getCast().endsWith("*") );
}


public String getConditional() {
String parentConditional = getDeclaringClass().getConditional();
String myConditional = annotation == null ? null : emptyFilter(annotation.conditional());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,11 @@ public enum FieldFlag {
* Indicate that the field is a pointer.
*/
POINTER_FIELD,

/**
* Indicate that the field is a shared pointer.
*/

SHARED_PTR,

}
}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
Expand Down

0 comments on commit 1c2d511

Please sign in to comment.