mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-21 14:07:53 +00:00
c8bf8a7733
The CLI and server main loop now have no conditional JNI code. All JNI code has been moved into separate source files, which #include the new "jni_common.h" instead of <jni.h>. The "cli.h" header no longer includes <jni.h>, so the rest of the Serval source code is now unaffected by JNI definitions. The 'cf_limbo' global variable is now thread-local, so that each thread has its own independent copy of the loaded configuration. The JNI server entry point now calls cf_init() once. The new 'cf_initialised' flag prevents clobbering the config state by redundant calls to cf_init(). The CLI "stop" command now sends SIGHUP to the specific thread in which the server is running. This is achieved by writing the PID and TID (Linux Thread ID) into the pidfile, separated by a space, on systems that support the Linux gettid() and tgkill() system calls. The server's signal handler has been overhauled, and its logging improved.
119 lines
2.9 KiB
Java
119 lines
2.9 KiB
Java
/**
|
|
* Copyright (C) 2016 Flinders University
|
|
* Copyright (C) 2014-2015 Serval Project Inc.
|
|
*
|
|
* This file is part of Serval Software (http://www.servalproject.org)
|
|
*
|
|
* Serval Software is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This source code is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this source code; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
|
|
package org.servalproject.test;
|
|
|
|
import org.servalproject.servaldna.ServalDCommand;
|
|
import org.servalproject.servaldna.ServalDFailureException;
|
|
import org.servalproject.servaldna.AbstractId;
|
|
import org.servalproject.servaldna.IJniResults;
|
|
|
|
import java.util.Arrays;
|
|
|
|
public class CommandLine {
|
|
|
|
public static void command(String... args) throws ServalDFailureException {
|
|
ServalDCommand.command(new IJniResults() {
|
|
int column_count = -1;
|
|
int column = 0;
|
|
|
|
private void eol() {
|
|
if (column_count == -1 || ++column >= column_count) {
|
|
System.out.println("");
|
|
column = 0;
|
|
}
|
|
else
|
|
System.out.print(":");
|
|
}
|
|
|
|
@Override
|
|
public void putString(String value) {
|
|
System.out.print(value);
|
|
eol();
|
|
}
|
|
|
|
@Override
|
|
public void putLong(long value) {
|
|
System.out.print(value);
|
|
eol();
|
|
}
|
|
|
|
@Override
|
|
public void putDouble(double value) {
|
|
System.out.print(value);
|
|
eol();
|
|
}
|
|
|
|
@Override
|
|
public void putBlob(byte[] blob) {
|
|
System.out.print(new String(blob));
|
|
eol();
|
|
}
|
|
|
|
@Override
|
|
public void putHexValue(byte[] blob) {
|
|
System.out.print(AbstractId.toHex(blob));
|
|
eol();
|
|
}
|
|
|
|
@Override
|
|
public void startTable(int column_count) {
|
|
this.column_count = column_count;
|
|
System.out.println(column_count);
|
|
}
|
|
|
|
@Override
|
|
public void setColumnName(int column, String name) {
|
|
System.out.print(name);
|
|
if (column + 1 >= column_count)
|
|
System.out.println("");
|
|
else
|
|
System.out.print(":");
|
|
}
|
|
|
|
@Override
|
|
public void endTable(int rows) {
|
|
this.column_count = -1;
|
|
}
|
|
}, args);
|
|
}
|
|
|
|
public static void main(String... args) {
|
|
try {
|
|
for (int i = 0; i != args.length; ++i)
|
|
if ("(null)".equals(args[i]))
|
|
args[i] = null;
|
|
|
|
int repeatCount = 1;
|
|
if (args[0].equals("--repeat")) {
|
|
repeatCount = Integer.decode(args[1]);
|
|
args = Arrays.copyOfRange(args, 2, args.length);
|
|
}
|
|
|
|
while (repeatCount-- > 0) {
|
|
command(args);
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|