Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/libplumber.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ file(GLOB_RECURSE src_files "${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_DIR}/*.c")

if("${MODULE_TLS_ENABLED}" EQUAL "1")
find_package(OpenSSL)
set(OPENSSL_INCLUDE_DIR "-I{OPENSSL_INCLUDE_DIR}")
set(OPENSSL_INCLUDE_DIR "-I${OPENSSL_INCLUDE_DIR}")
else("${MODULE_TLS_ENABLED}" EQUAL "1")
message("Notice: TLS support is disabled")
set(OPENSSL_INCLUDE_DIR )
Expand Down
1 change: 1 addition & 0 deletions build/package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ macro(build_tool_dir dir)
if(NOT "${build_${target}}" STREQUAL "no")
if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${target}")
set(SOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${target})
set(GEN_PATH ${CMAKE_CURRENT_BINARY_DIR}/${dir}/${target})
set(SOURCE "")
set(LOCAL_CFLAGS )
set(LOCAL_LIBS )
Expand Down
1 change: 1 addition & 0 deletions build/servlet.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ foreach(servlet_cmake ${servlet_cmakes})
get_filename_component(servlet ${servlet_path} NAME)
if(NOT "${build_${servlet}}" STREQUAL "no")
set(SOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${SERVLET_DIR}/${servlet_dir}/${servlet})
set(GEN_PATH ${CMAKE_CURRENT_BINARY_DIR}/${SERVLET_DIR}/${servlet_dir}/${servlet})
set(SOURCE "")
set(LOCAL_CFLAGS )
set(LOCAL_LIBS )
Expand Down
5 changes: 3 additions & 2 deletions misc/stat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/zsh
for ext in {'[ch]pp','[ch]',py,js,cmake,vim,pss,ptype}
for ext in {'[ch]pp','[ch]',py,js,cmake,vim,pss,ptype,java}
do
if [ ! -z "$(git ls-files '*.'${ext})" ]
then
Expand All @@ -16,7 +16,8 @@ awk \
name["cmake"] = "CMake"
name["vim"] = "Vim"
name["pss"] = "PScript"
name["ptype"] = "TypeDef"
name["ptype"] = "TypeDef"
name["java"] = "Java"
}
{
sum += $2;
Expand Down
31 changes: 31 additions & 0 deletions servlets/language/java/build.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
find_package(Java COMPONENTS Development Runtime REQUIRED)
get_filename_component(java_real_path ${Java_JAVAH_EXECUTABLE} REALPATH)
get_filename_component(java_bin_path ${java_real_path} DIRECTORY)
get_filename_component(JAVA_HOME ${java_bin_path}/../ ABSOLUTE)
find_package(JNI)
set(JNI_INCLUDE_FLAGS "")
foreach(incdir ${JNI_INCLUDE_DIRS})
set(JNI_INCLUDE_FLAGS "${JNI_INCLUDE_FLAGS} -I${incdir}")
endforeach(incdir ${JNI_INCLUDE_DIRS})

include(UseJava)
set(CMAKE_JAVA_TARGET_OUTPUT_DIR ${GEN_PATH})
file(GLOB_RECURSE java_source "${SOURCE_PATH}/javalib/*.java")
add_jar(java_pservlet ${java_source}
OUTPUT_NAME pservlet)
create_javah(TARGET java_pservlet_jni_header
GENERATED_FILES jni_headers
CLASSES info.haohou.pservlet._Pservlet
CLASSPATH ${GEN_PATH}/pservlet.jar
DEPENDS java_pservlet
OUTPUT_DIR ${GEN_PATH})
file(GLOB_RECURSE jni_source "${SOURCE_PATH}/jni/*.c")
set_source_files_properties(${jni_source} PROPERTIES
COMPILE_FLAGS "${CFLAGS} ${JNI_INCLUDE_FLAGS} -I${GEN_PATH}")
add_library(java_pservlet_jni SHARED ${jni_source})
target_link_libraries(java_pservlet_jni pservlet ${JNI_LIBERARIES})
set(LOCAL_CFLAGS "-DSERVLET_JNI_PATH=\"${CMAKE_INSTALL_PREFIX}/lib/plumber/java\"")

set(INSTALL yes)
install_includes("${GEN_PATH}" "lib/plumber/java" "*.jar")
install(TARGETS java_pservlet_jni DESTINATION lib/plumber/java)
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright (C) 2017, Hao Hou
**/
package info.haohou.pservlet;

/**
* The general java exception
**/
public class FrameworkException extends Exception {

/**
* The reason code type
**/
public enum Reason {
PIPE_DEFINE
};

/**
* The reason code for current exceptin
**/
Reason _reason;

/**
* Constructor
* @param message The message in the exception
**/
public FrameworkException(String message, Reason reason)
{
super("Plumber Framework Exception: " + message);
_reason = reason;
}

/**
* What causes this exception?
* @return The reason code
**/
public Reason getReason()
{
return _reason;
}
}
36 changes: 36 additions & 0 deletions servlets/language/java/javalib/info/haohou/pservlet/PipeId.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (C) 2017, Hao Hou
**/
package info.haohou.pservlet;

/**
* The object wrapper for a pipe id
**/
public class PipeId {

/**
* The internal pipe Id
**/
private final int _id;

/**
* Constructor
**/
private PipeId(int id) {
_id = id;
}

/**
* Get the pipe id object from int
**/
public static PipeId fromId(int id) {
return new PipeId(id);
}

/**
* Get the pipe Id number
**/
public int id() {
return _id;
}
}
137 changes: 137 additions & 0 deletions servlets/language/java/javalib/info/haohou/pservlet/Pservlet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/**
* Copyright (C) 2017, Hao Hou
**/

package info.haohou.pservlet;
import java.util.*;

/**
* The actual Pservlet API wrapper
**/
public class Pservlet {
/**
* Define a pipe
* @param name The name of the pipe
* @param flags The flags of the pipe
* @param type_expr The type expression
* @return status code
**/
public static PipeId pipeDefine(String name, int flags, String type_expr)
throws FrameworkException, IllegalArgumentException
{
if(null == name || null == type_expr)
{
throw new IllegalArgumentException();
}

int result = _Pservlet.pipeDefine(name, flags, type_expr);

if(result == -1)
{
throw new FrameworkException("Cannot create pipe", FrameworkException.Reason.PIPE_DEFINE);
}

return PipeId.fromId(result);
}
}

/**
* The internal language binding for java
**/
class _Pservlet {
/**
* Define a pipe
* @param name The name of the pipe
* @param flags The flags to the pipe
* @param type_expr The type expression
* @return The pipe id
**/
public static native int pipeDefine(String name, int flags, String type_expr);

/**
* Read data from the pipe
* @param pipe The pipe id
* @param nbytes How many bytes we want to read from the pipe
* @return The result byte array
**/
public static native Byte[] pipeRead(int pipe, int nbytes);

/**
* Write data to the pipe
* @param pipe The pipe id
* @param data The byte array to write
* @return The number of bytes has been written to pipe
**/
public static native int pipeWrite(int pipe, Byte[] data);

/**
* Write a scope token
* @param pipe The pipe id
* @param scope_token The token needs to be written to pipe
* @return If the operation is sucessfully done
**/
public static native boolean pipeWriteScopeToken(int pipe, int scope_token);

/**
* Get current Task id
* @return The current task Id
**/
public static native int taskId();

/**
* Write log to the Plumber logging infrastructure
* @param level The level of the log
* @param message The message
* @return nothing
**/
public static native void logWrite(int level, String message);

/**
* Check if we are currently at the end of the pipe
* @param pipe The pipe id
* @return The check result or error code
**/
public static native int pipeEof(int pipe);

/**
* Get the version number of the plumber environment
* @return The veresion string
**/
public static native String version();

/**
* Get the constants defined by the Plumber framework
* @return A map from string to the constants
**/
private static native HashMap<String, Integer> _getConst();

/**
* The object that holds the collection of Plumber framework constants
**/
private static final HashMap<String, Integer> _constants = _getConst();

/**
* Indicates this is an input pipe
**/
public static final int PIPE_INPUT = _constants.get("PIPE_INPUT").intValue();

/**
* Indicates this is an output pipe
**/
public static final int PIPE_OUTPUT = _constants.get("PIPE_OUTPUT").intValue();

/**
* Indicates this is an asynchronized pipe
**/
public static final int PIPE_ASYNC = _constants.get("PIPE_ASYNC").intValue();

/**
* Indicates this is a shadow pipe
**/
public static final int PIPE_SHADOW = _constants.get("PIPE_SHADOW").intValue();


static {
System.loadLibrary("java_pservlet_jni");
}
};
2 changes: 2 additions & 0 deletions servlets/language/java/jni/pservlet_interface.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include <pservlet.h>
#include <info_haohou_pservlet__Pservlet.h>
8 changes: 8 additions & 0 deletions servlets/language/java/servlet.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <pservlet.h>

//useful links:
// Call C function from Java: http://web.archive.org/web/20120419230023/http://java.sun.com/docs/books/jni/html/start.html
// Call Java from C: http://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/invocation.html
// AttachCurrentThread