Browse Source

Updated automatic loading of libcppcms

master
Artyom Beilis 8 years ago
parent
commit
71f2065bb5
4 changed files with 50 additions and 18 deletions
  1. +0
    -3
      contrib/integration/session/example/Sample.java
  2. +0
    -6
      contrib/integration/session/example/views.py
  3. +49
    -7
      contrib/integration/session/java/com/cppcms/session/API.java
  4. +1
    -2
      contrib/integration/session/java/com/cppcms/session/SessionPool.java

+ 0
- 3
contrib/integration/session/example/Sample.java View File

@@ -9,10 +9,7 @@ public class Sample extends HttpServlet {
public void init() throws ServletException
{
ServletContext context = getServletContext();
String libPath = context.getRealPath("/WEB-INF/lib/libcppcms.so");
String configPath = context.getRealPath("/WEB-INF/cppcms-config.js");
API.init(libPath);
pool = SessionPool.openFromConfig(configPath);
}



+ 0
- 6
contrib/integration/session/example/views.py View File

@@ -1,12 +1,6 @@
from django.http import HttpResponse
from django.conf import settings
import cppcms

#
# Load the module containing the API
#
cppcms.Loader.load('libcppcms.so')

#
# Create the session pool - note it is thread safe and should be one per projects
# Provide a path to configuration file


+ 49
- 7
contrib/integration/session/java/com/cppcms/session/API.java View File

@@ -70,27 +70,69 @@ public class API {

protected static JnaAPI api;

public static void init(String path)
private static void loadLibrary(String path)
{
api = (JnaAPI)Native.loadLibrary(path,JnaAPI.class);
}
public static void init()
public static synchronized void init(String path)
{
init("libcppcms.so");
if(api == null) {
loadLibrary(path);
}
}
public static synchronized void init()
{
if(api != null)
return;

String names[]=null;
String os=System.getProperty("os.name").toLowerCase();
if(os.indexOf("win")!=-1)
names = new String[] { "cppcms.dll", "libcppcms.dll", "cppcms-1.dll", "libcppcms-1.dll" };
else if(os.indexOf("mac")!=-1)
names=new String[] { "libcppcms.dylib", "libcppcms.1.dylib" };
else
names=new String[] { "libcppcms.so", "libcppcms.so.1" };
for(int i=0;i<names.length;i++) {
try {
loadLibrary(names[i]);
}
catch(Exception e) {}
catch(Error e){}
}
if(api==null) {
StringBuilder sb = new StringBuilder();
sb.append("Failed to load any of the following:");
for(int i=0;i<names.length;i++) {
sb.append(" ");
sb.append(names[i]);
}
throw new RuntimeException(sb.toString());
}
}

public static void main(String[] args)
{
if(args.length != 2) {
System.out.println("usage /path/to/libcppcms.so /path/to/config.js");
String path=null;
String conf=null;
if(args.length == 2) {
path = args[0];
conf = args[1];
}
else if(args.length == 1) {
conf = args[0];
}
else {
System.out.println("usage [/path/to/libcppcms.so] /path/to/config.js");
return;
}
SessionPool p = null;
Session s = null;
try {
String state="";
init(args[0]);
p = SessionPool.openFromConfig(args[1]);
if(path!=null)
init(path);
p = SessionPool.openFromConfig(conf);
s = p.getSession();
s.load(state);
s.set("x","1");


+ 1
- 2
contrib/integration/session/java/com/cppcms/session/SessionPool.java View File

@@ -7,8 +7,7 @@ public class SessionPool extends SessionBase {

private SessionPool()
{
if(API.api == null)
throw new NullPointerException("API.init() wasn't called - API wasn't loaded prior to use of SessionPool");
API.init();
d=API.api.cppcms_capi_session_pool_new();
}
public static SessionPool openFromConfig(String file)


Loading…
Cancel
Save