Compare commits

...

5 Commits

Author SHA1 Message Date
heck 24dd29bb71 Working impl of AbstractMessage / Message concept 5 years ago
heck c386224309 upadate make clean and .hgignore 5 years ago
heck f177ebe37d Move Message.enums from code-gen (AbstractMessage) to Message. 5 years ago
heck 1303cdd8cd Added AbstractMessage abstract base class / Message (extends AbstractMessage) 5 years ago
heck 54024e996b Create feature branch JNI-86 (Message to XER decoder for Sync protocol (for debugging)) 5 years ago
  1. 5
      .hgignore
  2. 23
      src/Makefile
  3. 105
      src/foundation/pEp/jniadapter/Message.java
  4. 20
      src/gen_cpp_Message.ysl2
  5. 8
      src/gen_java_Message.ysl2
  6. 19
      src/pEp.yml2
  7. 1
      src/types_java.ysl2

5
.hgignore

@ -36,6 +36,11 @@ SyncHandshakeResult.java
IdentityFlags.java
SyncHandshakeSignal.java
CipherSuite.java
AbstractMessage.java
Direction.java
EncFormat.java
TextFormat.java
status_list.yml2

23
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
@ -122,6 +122,9 @@ clean:
rm -f foundation/pEp/jniadapter/SyncHandshakeResult.java
rm -f foundation/pEp/jniadapter/SyncHandshakeSignal.java
rm -f foundation/pEp/jniadapter/CipherSuite.java
rm -f foundation/pEp/jniadapter/Direction.java
rm -f foundation/pEp/jniadapter/EncFormat.java
rm -f foundation/pEp/jniadapter/TextFormat.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

105
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<Integer, TextFormat> intMap;
private TextFormat(int value) {
this.value = value;
}
public static TextFormat getByInt(int value){
if (intMap == null) {
intMap = new HashMap<Integer, TextFormat>();
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<Integer, Direction> intMap;
private Direction(int value) {
this.value = value;
}
public static Direction getByInt(int value){
if (intMap == null) {
intMap = new HashMap<Integer, Direction>();
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<Integer, EncFormat> intMap;
private EncFormat(int value) {
this.value = value;
}
public static EncFormat getByInt(int value){
if (intMap == null) {
intMap = new HashMap<Integer, EncFormat>();
for (EncFormat s : EncFormat.values()) {
intMap.put(s.value, s);
}
}
if (intMap.containsKey(value)) {
return intMap.get(value);
}
return null;
}
}
}

20
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 {
@ -123,21 +123,27 @@ tstylesheet {
const "jname" call "CamelCase" with "text", "name(*[1])";
const "cname" call "lcase" with "text", "name(*[1])";
const "type", "name(.)";
const "jnitype" choose {
when "$type = 'direction' or $type = 'EncFormat'" > jint
otherwise > `call "jni_type" with "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)";
}
||
JNIEXPORT `call "jni_type" with "type", "name(.)"` JNICALL
JNIEXPORT «$jnitype» JNICALL
«$getname»(JNIEnv *env, jobject obj) {
«$name» *_obj = «$name»_ptr(env, obj);
||
choose {
when "../enum[@name=$type]"
when "$jnitype = 'jint' "
|> return (jint) _obj->«$cname»;
otherwise
|> return from_«$type»(env, _obj->«$cname»);
@ -146,11 +152,11 @@ tstylesheet {
}
JNIEXPORT void JNICALL
«$setname»(JNIEnv *env, jobject obj, `call "jni_type" with "type", "name(.)"` value) {
«$setname»(JNIEnv *env, jobject obj, «$jnitype» value) {
«$name» *_obj = «$name»_ptr(env, obj);
||
choose {
when "../enum[@name=$type]"
when "$jnitype = 'jint'"
|> _obj->«$cname» = («$ctype») (int) value;
otherwise {
choose {

8
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;
}
@ -219,7 +219,7 @@ tstylesheet {
||
when "../enum[@name=$ctype]"
when "$ctype = 'direction' or $ctype = 'EncFormat'"
||
private native int _get«$name»();
public «$itype» get«$name»() {

19
src/pEp.yml2

@ -267,25 +267,6 @@ namespace pEp {
};
struct message {
enum TextFormat {
plain > 0
html > 1
other > 255
}
enum direction {
incoming > 0
outgoing > 1
}
enum EncFormat {
none > 0
inline > 1
SMIME > 2
PGPMIME > 3
PEP > 4
}
direction dir;
string id;
string shortmsg;

1
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";

Loading…
Cancel
Save