From 1303cdd8cd9cb0362798fd2fd2de4e8d8f467330 Mon Sep 17 00:00:00 2001 From: heck Date: Wed, 12 Feb 2020 01:00:08 +0100 Subject: [PATCH] Added AbstractMessage abstract base class / Message (extends AbstractMessage) introduced an AbstractMessage base class (for the generated parts), to be extended into Message (there we can enhance ond override the generated code). Works, only problem is the enum types that are being generated into the Message class... e.g. Message.EncType, Message.Direction. These of course are now in AbstractMessage.EncType etc.. and thats of course not good. but because they are generated they cant be in the Message class, so at the moment having copies of these types in Message.java... Like this everything works, but of course it needs a design solution. Of course the plan then is to add the Message.toXER() method in Message.java as non-generated code (because it cant really be generated because of the "compound" nature of the function being approx: is msg encrypted, then decrypt with 0x200 flag, then getAttachement(0), if sync msg Sync::PER_to_XER else distribution::PER_toXER(), return.) in accordance with JNI-84 Reverse hierarchy of Engine and AbstractEngine. --- src/Makefile | 20 ++-- src/foundation/pEp/jniadapter/Message.java | 105 +++++++++++++++++++++ src/gen_cpp_Message.ysl2 | 8 +- src/gen_java_Message.ysl2 | 6 +- src/types_java.ysl2 | 1 + 5 files changed, 124 insertions(+), 16 deletions(-) create mode 100644 src/foundation/pEp/jniadapter/Message.java diff --git a/src/Makefile b/src/Makefile index 38404ab..7be6c16 100644 --- a/src/Makefile +++ b/src/Makefile @@ -37,13 +37,13 @@ JAVA_SOURCES=foundation/pEp/jniadapter/AbstractEngine.java \ foundation/pEp/jniadapter/_Blob.java \ foundation/pEp/jniadapter/_Identity.java \ foundation/pEp/jniadapter/pEpException.java \ - foundation/pEp/jniadapter/Message.java \ + foundation/pEp/jniadapter/AbstractMessage.java \ foundation/pEp/jniadapter/Engine.java \ C_SOURCES=foundation_pEp_jniadapter_Engine.cc \ foundation_pEp_jniadapter_Engine.h \ - foundation_pEp_jniadapter_Message.cc \ - foundation_pEp_jniadapter_Message.h \ + foundation_pEp_jniadapter_AbstractMessage.cc \ + foundation_pEp_jniadapter_AbstractMessage.h \ throw_pEp_exception.cc \ throw_pEp_exception.hh \ foundation_pEp_jniadapter_AbstractEngine.h @@ -58,7 +58,7 @@ $(JAR): status_list.yml2 $(JAVA_SOURCES) $(C_SOURCES) $(JP)/javac foundation/pEp/jniadapter/*.java $(JP)/jar cf $@ foundation/pEp/jniadapter/*.class -BLUBB=foundation_pEp_jniadapter_AbstractEngine.h foundation_pEp_jniadapter_Engine.h foundation_pEp_jniadapter_Message.h +BLUBB=foundation_pEp_jniadapter_AbstractEngine.h foundation_pEp_jniadapter_Engine.h foundation_pEp_jniadapter_AbstractMessage.h $(BLUBB): foundation_pEp_jniadapter_%.h: foundation/pEp/jniadapter/%.java ifdef OLD_JAVA $(JP)/javah $(subst /,.,$(subst .java,,$<)) @@ -69,10 +69,10 @@ endif foundation_pEp_jniadapter_AbstractEngine.o: %.o: %.cc %.h throw_pEp_exception.hh jniutils.hh $(CXX) $(CXXFLAGS) -c $< -o $@ -foundation_pEp_jniadapter_Engine.o foundation_pEp_jniadapter_Message.o: %.o: %.cc %.h +foundation_pEp_jniadapter_Engine.o foundation_pEp_jniadapter_AbstractMessage.o: %.o: %.cc %.h $(CXX) $(CXXFLAGS) -c $< -o $@ -$(LIBRARY): foundation_pEp_jniadapter_AbstractEngine.o foundation_pEp_jniadapter_Engine.o foundation_pEp_jniadapter_Message.o throw_pEp_exception.o jniutils.o basic_api.o +$(LIBRARY): foundation_pEp_jniadapter_AbstractEngine.o foundation_pEp_jniadapter_Engine.o foundation_pEp_jniadapter_AbstractMessage.o throw_pEp_exception.o jniutils.o basic_api.o ar -r $@ *.o $(SHARED): $(LIBRARY) @@ -84,13 +84,13 @@ status_list.yml2: pEp.yml2 foundation/pEp/jniadapter/pEpException.java: pEp.yml2 gen_java_exceptions.ysl2 pEp.yml2 $(YML2_PROC) -y gen_java_exceptions.ysl2 $< -o $@ -foundation/pEp/jniadapter/Message.java: pEp.yml2 gen_java_Message.ysl2 types_java.ysl2 +foundation/pEp/jniadapter/AbstractMessage.java: pEp.yml2 gen_java_Message.ysl2 types_java.ysl2 $(YML2_PROC) -y gen_java_Message.ysl2 $< foundation/pEp/jniadapter/Engine.java: pEp.yml2 gen_java_Engine.ysl2 types_java.ysl2 $(YML2_PROC) -y gen_java_Engine.ysl2 $< -foundation_pEp_jniadapter_Message.cc: pEp.yml2 gen_cpp_Message.ysl2 types_c.ysl2 +foundation_pEp_jniadapter_AbstractMessage.cc: pEp.yml2 gen_cpp_Message.ysl2 types_c.ysl2 $(YML2_PROC) -y gen_cpp_Message.ysl2 $< foundation_pEp_jniadapter_Engine.cc: pEp.yml2 gen_cpp_Engine.ysl2 types_c.ysl2 @@ -113,7 +113,7 @@ clean: rm -f foundation/pEp/jniadapter/*.class rm -f foundation/pEp/jniadapter/pEp*.java rm -f foundation/pEp/jniadapter/Engine.java - rm -f foundation/pEp/jniadapter/Message.java + rm -f foundation/pEp/jniadapter/AbstractMessage.java rm -f foundation/pEp/jniadapter/Color.java rm -f foundation/pEp/jniadapter/DecryptFlags.java rm -f foundation/pEp/jniadapter/IdentityFlags.java @@ -123,5 +123,5 @@ clean: rm -f foundation/pEp/jniadapter/SyncHandshakeSignal.java rm -f foundation/pEp/jniadapter/CipherSuite.java rm -f throw_pEp_exception.* - rm -f foundation_pEp_jniadapter_Message.cc foundation_pEp_jniadapter_Engine.cc + rm -f foundation_pEp_jniadapter_AbstractMessage.cc foundation_pEp_jniadapter_Engine.cc rm -f status_list.yml2 diff --git a/src/foundation/pEp/jniadapter/Message.java b/src/foundation/pEp/jniadapter/Message.java new file mode 100644 index 0000000..65be77a --- /dev/null +++ b/src/foundation/pEp/jniadapter/Message.java @@ -0,0 +1,105 @@ +package foundation.pEp.jniadapter; + +import java.util.HashMap; + + +public class Message extends AbstractMessage { + + // Explicit Super Constructor call + public Message() { + super(); + } + + public Message(String mime_text) { + super(mime_text); + } + + private Message(long h) { + super(h); + } + + + public enum TextFormat { + Plain (0), + Html (1), + Other (255) + ; + + public final int value; + + private static HashMap intMap; + + private TextFormat(int value) { + this.value = value; + } + + public static TextFormat getByInt(int value){ + if (intMap == null) { + intMap = new HashMap(); + for (TextFormat s : TextFormat.values()) { + intMap.put(s.value, s); + } + } + if (intMap.containsKey(value)) { + return intMap.get(value); + } + return null; + } + } + public enum Direction { + Incoming (0), + Outgoing (1) + ; + + public final int value; + + private static HashMap intMap; + + private Direction(int value) { + this.value = value; + } + + public static Direction getByInt(int value){ + if (intMap == null) { + intMap = new HashMap(); + for (Direction s : Direction.values()) { + intMap.put(s.value, s); + } + } + if (intMap.containsKey(value)) { + return intMap.get(value); + } + return null; + } + } + public enum EncFormat { + None (0), + Inline (1), + SMIME (2), + PGPMIME (3), + PEP (4) + ; + + public final int value; + + private static HashMap intMap; + + private EncFormat(int value) { + this.value = value; + } + + public static EncFormat getByInt(int value){ + if (intMap == null) { + intMap = new HashMap(); + for (EncFormat s : EncFormat.values()) { + intMap.put(s.value, s); + } + } + if (intMap.containsKey(value)) { + return intMap.get(value); + } + return null; + } + } + +} \ No newline at end of file diff --git a/src/gen_cpp_Message.ysl2 b/src/gen_cpp_Message.ysl2 index 8a7c598..57ea985 100644 --- a/src/gen_cpp_Message.ysl2 +++ b/src/gen_cpp_Message.ysl2 @@ -7,7 +7,7 @@ tstylesheet { template "/namespace[@name='pEp']" apply "struct", 0; template "struct" { - const "jname" call "CamelCase" with "text", "@name"; + const "jname" call "CamelCase" with "text", "concat('Abstract-',@name)"; document("foundation_pEp_jniadapter_{$jname}.cc", "text") { || @@ -93,7 +93,7 @@ tstylesheet { || apply "*[name(.)!='enum']", 0, mode=entry { with "name", "@name"; - with "class" call "CamelCase" with "text", "@name"; + with "class" call "CamelCase" with "text", "$jname"; } || } // extern "C" @@ -105,7 +105,7 @@ tstylesheet { function "mangle" { param "type"; param "name"; - param "classname" call "CamelCase" with "text", "../@name"; + param "classname"; const "convert", "$type != 'timestamp'"; choose { @@ -125,10 +125,12 @@ tstylesheet { const "type", "name(.)"; const "getname" call "mangle" { with "type", "$type"; + with "classname", "$class"; with "name", "concat('get', $jname)"; } const "setname" call "mangle" { with "type", "$type"; + with "classname", "$class"; with "name", "concat('set', $jname)"; } || diff --git a/src/gen_java_Message.ysl2 b/src/gen_java_Message.ysl2 index a16658a..16334ca 100644 --- a/src/gen_java_Message.ysl2 +++ b/src/gen_java_Message.ysl2 @@ -7,7 +7,7 @@ tstylesheet { template "/namespace[@name='pEp']" apply "struct|enum|exception", 0; template "struct" { - const "cname" call "toJava" with "type", "@name"; + const "cname" call "toJava" with "type", "concat('Abstract-',@name)"; document("foundation/pEp/jniadapter/{$cname}.java", "text") || package foundation.pEp.jniadapter; @@ -18,7 +18,7 @@ tstylesheet { import java.util.HashMap; import java.io.Serializable; - public class «$cname» implements AutoCloseable, Serializable { + public abstract class «$cname» implements AutoCloseable, Serializable { private static final long serialVersionUID = 2119420428331150924L; private long handle; @@ -44,7 +44,7 @@ tstylesheet { return AbstractEngine.toUTF16(_encodeMIME()); } - private «$cname»(long h) { + public «$cname»(long h) { handle = h; } diff --git a/src/types_java.ysl2 b/src/types_java.ysl2 index a6806e5..4725392 100644 --- a/src/types_java.ysl2 +++ b/src/types_java.ysl2 @@ -20,6 +20,7 @@ function "toJava" { when "$type='Color'" > Color when "$type='DecryptFlags'" > DecryptFlags when "$type='EncFormat'" > Message.EncFormat + when "$type='direction'" > Message.Direction when "$type='Rating'" > Rating otherwise call "CamelCase" with "text", "$type";