all common code for running Java parts from C++ process moved to separated library...
authorVictor Kirhenshtein <victor@netxms.org>
Sat, 5 Aug 2017 19:23:37 +0000 (22:23 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Sat, 5 Aug 2017 19:23:37 +0000 (22:23 +0300)
85 files changed:
.gitignore
configure.ac
include/Makefile.am
include/nms_util.h
include/nxjava.h [new file with mode: 0644]
src/agent/core/nxagentd.cpp
src/agent/subagents/bind9/Makefile.am
src/agent/subagents/bind9/pom.xml
src/agent/subagents/bind9/src/main/java/com/github/tomaskir/netxms/subagents/bind9/Bind9Plugin.java
src/agent/subagents/bind9/src/main/java/com/github/tomaskir/netxms/subagents/bind9/collection/Collector.java
src/agent/subagents/dbquery/.settings/language.settings.xml
src/agent/subagents/ecs/.settings/language.settings.xml
src/agent/subagents/filemgr/.settings/language.settings.xml
src/agent/subagents/java/.project
src/agent/subagents/java/Makefile.am
src/agent/subagents/java/SubAgent.cpp
src/agent/subagents/java/SubAgent.h
src/agent/subagents/java/java/pom.xml
src/agent/subagents/java/java/src/main/java/org/netxms/agent/Plugin.java
src/agent/subagents/java/java/src/main/java/org/netxms/agent/SubAgent.java
src/agent/subagents/java/java_subagent.h
src/agent/subagents/java/main.cpp
src/agent/subagents/jmx/pom.xml
src/agent/subagents/jmx/src/main/java/org/netxms/agent/jmx/JmxPlugin.java
src/agent/subagents/jmx/src/main/java/org/netxms/agent/jmx/Server.java
src/agent/subagents/mqtt/.settings/language.settings.xml
src/agent/subagents/mysql/.settings/language.settings.xml
src/agent/subagents/ping/.settings/language.settings.xml
src/agent/subagents/ssh/.settings/language.settings.xml
src/agent/subagents/ubntlw/Makefile.am
src/agent/subagents/ubntlw/pom.xml
src/agent/subagents/ubntlw/src/main/java/com/rfelements/AbstractCollector.java
src/agent/subagents/ubntlw/src/main/java/com/rfelements/LigowaveApCollector.java
src/agent/subagents/ubntlw/src/main/java/com/rfelements/LigowaveClientCollector.java
src/agent/subagents/ubntlw/src/main/java/com/rfelements/Logger.java
src/agent/subagents/ubntlw/src/main/java/com/rfelements/UbiquitiApCollector.java
src/agent/subagents/ubntlw/src/main/java/com/rfelements/UbiquitiClientCollector.java
src/agent/subagents/ubntlw/src/main/java/com/rfelements/cache/CacheImpl.java
src/agent/subagents/ubntlw/src/main/java/com/rfelements/config/ConfigReader.java
src/agent/subagents/ubntlw/src/main/java/com/rfelements/config/ConfigReaderImpl.java
src/agent/subagents/ubntlw/src/main/java/com/rfelements/provider/DataProvider.java
src/agent/subagents/ubntlw/src/main/java/com/rfelements/provider/DataProviderImpl.java
src/agent/subagents/ubntlw/src/main/java/com/rfelements/rest/Rest.java
src/agent/subagents/ubntlw/src/main/java/com/rfelements/workers/SingleWorker.java
src/agent/subagents/ubntlw/src/main/java/com/rfelements/workers/WorkersProviderImpl.java
src/agent/subagents/xen/.settings/language.settings.xml
src/client/nxshell/.project
src/client/nxshell/.settings/language.settings.xml
src/client/nxshell/Makefile.am
src/client/nxshell/Makefile.w32
src/client/nxshell/nxshell.cpp
src/db/dbdrv/db2/.settings/language.settings.xml
src/libnetxms/log.cpp
src/libnetxms/tools.cpp
src/libnxjava/.cproject [new file with mode: 0644]
src/libnxjava/.project [copied from src/agent/subagents/java/.project with 91% similarity]
src/libnxjava/.settings/language.settings.xml [copied from src/server/tools/nxget/.settings/language.settings.xml with 88% similarity]
src/libnxjava/Makefile.am [new file with mode: 0644]
src/libnxjava/config.cpp [moved from src/agent/subagents/java/ConfigHelper.cpp with 86% similarity]
src/libnxjava/java/Makefile.am [new file with mode: 0644]
src/libnxjava/java/Makefile.w32 [new file with mode: 0644]
src/libnxjava/java/pom.xml [copied from src/agent/subagents/java/java/pom.xml with 78% similarity]
src/libnxjava/java/src/main/java/org/netxms/bridge/Config.java [moved from src/agent/subagents/java/java/src/main/java/org/netxms/agent/Config.java with 96% similarity]
src/libnxjava/java/src/main/java/org/netxms/bridge/ConfigEntry.java [moved from src/agent/subagents/java/java/src/main/java/org/netxms/agent/ConfigEntry.java with 96% similarity]
src/libnxjava/java/src/main/java/org/netxms/bridge/DirectoryType.java [copied from src/agent/subagents/java/java/src/main/java/org/netxms/agent/DirectoryType.java with 97% similarity]
src/libnxjava/java/src/main/java/org/netxms/bridge/LogLevel.java [moved from src/agent/subagents/java/java/src/main/java/org/netxms/agent/DirectoryType.java with 82% similarity]
src/libnxjava/java/src/main/java/org/netxms/bridge/Platform.java [new file with mode: 0644]
src/libnxjava/jre.cpp [new file with mode: 0644]
src/libnxjava/jvm.cpp [new file with mode: 0644]
src/libnxjava/libnxjava.h [new file with mode: 0644]
src/libnxjava/main.cpp [new file with mode: 0644]
src/libnxjava/platform.cpp [new file with mode: 0644]
src/libnxjava/tools.cpp [new file with mode: 0644]
src/server/core/main.cpp
src/server/drivers/extreme/.settings/language.settings.xml
src/server/drivers/h3c/.settings/language.settings.xml
src/server/drivers/ignitenet/.settings/language.settings.xml
src/server/drivers/juniper/.settings/language.settings.xml
src/server/drivers/symbol-ws/.settings/language.settings.xml
src/server/tools/nxadm/.settings/language.settings.xml
src/server/tools/nxget/.settings/language.settings.xml
src/server/tools/nxminfo/.settings/language.settings.xml
src/smsdrv/kannel/.settings/language.settings.xml
src/smsdrv/mymobile/.settings/language.settings.xml
src/smsdrv/nexmo/.settings/language.settings.xml

index 6318c36..0b46f43 100644 (file)
@@ -184,6 +184,9 @@ target
 /src/java/nxreporting/src/main/resources/nxreporting.xml
 /src/libexpat/libexpat/x64
 /src/libnetxms/x64
+/src/libnxjava/java/.classpath
+/src/libnxjava/java/.project
+/src/libnxjava/java/.settings
 /src/libnxsl/lex.parser.cpp
 /src/libnxsl/lex.yy.cpp
 /src/libnxsl/parser.output
index 811c1e7..5b2b75b 100644 (file)
@@ -694,7 +694,7 @@ AC_ARG_ENABLE(64bit,
 AC_ARG_WITH(dist,
 [AS_HELP_STRING(--with-dist,for maintainers only)],
        DB_DRIVERS="mysql mariadb pgsql odbc mssql sqlite oracle db2 informix"
-       MODULES="appagent jansson libexpat libstrophe libtre zlib libnetxms install sqlite snmp libnxsl libnxmb libnxlp libnxcc db server smsdrv agent client nxscript nxcproxy nxlptest tools"
+       MODULES="appagent jansson libexpat libstrophe libtre zlib libnetxms libnxjava install sqlite snmp libnxsl libnxmb libnxlp libnxcc db server smsdrv agent client nxscript nxcproxy nxlptest tools"
        SUBAGENT_DIRS="linux ds18x20 freebsd openbsd minix mqtt mysql netbsd sunos aix ipso hpux odbcquery informix oracle lmsensors darwin rpi java jmx bind9 ubntlw netsvc db2 tuxedo mongodb ssh vmgr xen"
        AGENT_DIRS="libnxtux"
        SMSDRV_DIRS="anysms kannel mymobile nexmo nxagent slack smseagle text2reach websms"
@@ -736,6 +736,12 @@ if test $? = 0; then
        MODULES="$MODULES snmp"
 fi
 
+check_substr "$COMPONENTS" "java"
+if test $? = 0; then
+       MODULES="$MODULES libnxjava"
+       SUBAGENT_DIRS="$SUBAGENT_DIRS java bind9 jmx ubntlw"
+fi
+
 check_substr "$COMPONENTS" "static-agent"
 if test $? = 0; then
        if test "x$COMPONENTS" != "x sqlite snmp static-agent sqlite_drv"; then
@@ -973,11 +979,6 @@ if test $? = 0; then
        SUBAGENT_DIRS="$SUBAGENT_DIRS rpi"
 fi
 
-check_substr "$COMPONENTS" "java"
-if test $? = 0; then
-       SUBAGENT_DIRS="$SUBAGENT_DIRS java bind9 jmx ubntlw"
-fi
-
 check_substr "$COMPONENTS" "tuxedo"
 if test $? = 0; then
        AGENT_DIRS="$AGENT_DIRS libnxtux"
@@ -3636,6 +3637,8 @@ AC_CONFIG_FILES([
        src/libexpat/libexpat/Makefile
        src/libnetxms/Makefile
        src/libnxcc/Makefile
+       src/libnxjava/Makefile
+       src/libnxjava/java/Makefile
        src/libnxlp/Makefile
        src/libnxmb/Makefile
        src/libnxsl/Makefile
index 015bf1d..9be9800 100644 (file)
@@ -38,6 +38,7 @@ include_HEADERS = \
        nxcrypto.h \
        nxdbapi.h \
        nxevent.h \
+       nxjava.h \
        nxlog.h \
        nxlpapi.h \
        nxmbapi.h \
index 19f24a5..827de1b 100644 (file)
@@ -2356,9 +2356,11 @@ int LIBNETXMS_EXPORTABLE alphasort(const struct dirent **a, const struct dirent
 TCHAR LIBNETXMS_EXPORTABLE *safe_fgetts(TCHAR *buffer, int len, FILE *f);
 
 bool LIBNETXMS_EXPORTABLE nxlog_open(const TCHAR *logName, UINT32 flags, const TCHAR *msgModule,
-                                     unsigned int msgCount, const TCHAR **messages, DWORD debugMsg);
-void LIBNETXMS_EXPORTABLE nxlog_close(void);
+                                     unsigned int msgCount, const TCHAR **messages,
+                                     DWORD debugMsg, DWORD genericMsg);
+void LIBNETXMS_EXPORTABLE nxlog_close();
 void LIBNETXMS_EXPORTABLE nxlog_write(DWORD msg, WORD wType, const char *format, ...);
+void LIBNETXMS_EXPORTABLE nxlog_write_generic(WORD type, const TCHAR *format, ...);
 void LIBNETXMS_EXPORTABLE nxlog_debug(int level, const TCHAR *format, ...);
 void LIBNETXMS_EXPORTABLE nxlog_debug2(int level, const TCHAR *format, va_list args);
 bool LIBNETXMS_EXPORTABLE nxlog_set_rotation_policy(int rotationMode, UINT64 maxLogSize, int historySize, const TCHAR *dailySuffix);
diff --git a/include/nxjava.h b/include/nxjava.h
new file mode 100644 (file)
index 0000000..618ddf2
--- /dev/null
@@ -0,0 +1,178 @@
+/* 
+** NetXMS - Network Management System
+** Copyright (C) 2003-2017 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU Lesser General Public License as published by
+** the Free Software Foundation; either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program 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 Lesser General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: nxjava.h
+**
+**/
+
+#ifndef _nxjava_h_
+#define _nxjava_h_
+
+#ifdef _WIN32
+#ifdef LIBNXJAVA_EXPORTS
+#define LIBNXJAVA_EXPORTABLE __declspec(dllexport)
+#else
+#define LIBNXJAVA_EXPORTABLE __declspec(dllimport)
+#endif
+#else    /* _WIN32 */
+#define LIBNXJAVA_EXPORTABLE
+#endif
+
+#include <nms_common.h>
+#include <nms_util.h>
+#include <nxconfig.h>
+#include <jni.h>
+#include <unicode.h>
+
+/**
+ * Error codes
+ */
+enum JavaBridgeError
+{
+   NXJAVA_SUCCESS = 0,
+   NXJAVA_JVM_LOAD_FAILED = 1,
+   NXJAVA_NO_ENTRY_POINT = 2,
+   NXJAVA_CANNOT_CREATE_JVM = 3,
+   NXJAVA_APP_CLASS_NOT_FOUND = 4,
+   NXJAVA_APP_ENTRY_POINT_NOT_FOUND = 5
+};
+
+/**
+ * Get error message from error code
+ */
+const TCHAR LIBNXJAVA_EXPORTABLE *GetJavaBridgeErrorMessage(JavaBridgeError error);
+
+/**
+ * Convert Java string to C string.
+ * Result string is dynamically allocated and must be disposed by calling free().
+ */
+TCHAR LIBNXJAVA_EXPORTABLE *CStringFromJavaString(JNIEnv *env, jstring jstr);
+
+/**
+ * Convert Java string to C string.
+ * Result string is in static buffer
+ */
+TCHAR LIBNXJAVA_EXPORTABLE *CStringFromJavaString(JNIEnv *env, jstring jstr, TCHAR *buffer, size_t bufferLen);
+
+/**
+ * Convert wide character C string to Java string.
+ */
+jstring LIBNXJAVA_EXPORTABLE JavaStringFromCStringW(JNIEnv *env, const WCHAR *str);
+
+/**
+ * Convert C string in current code page to Java string.
+ */
+jstring LIBNXJAVA_EXPORTABLE JavaStringFromCStringA(JNIEnv *env, const char *str);
+
+/**
+ * Convert C string to Java string.
+ */
+#ifdef UNICODE
+#define JavaStringFromCString JavaStringFromCStringW
+#else
+#define JavaStringFromCString JavaStringFromCStringA
+#endif
+
+/**
+ * Convert C string in system locale code page to Java string.
+ */
+jstring LIBNXJAVA_EXPORTABLE JavaStringFromCStringSysLocale(JNIEnv *env, const char *str);
+
+/**
+ * Create StringList from Java string array
+ */
+StringList LIBNXJAVA_EXPORTABLE *StringListFromJavaArray(JNIEnv *curEnv, jobjectArray a);
+
+/**
+ * Find Java runtime module. Search algorithm is following:
+ * 1. Windows only - check for bundled JRE in bin\jre
+ * 2. Check for bundled JRE in $NETXMS_HOME/bin/jre (Windows) or $NETXMS_HOME/lib/jre (non-Windows)
+ * 3. Windows only - check JRE location in registry
+ * 3. Check $JAVA_HOME
+ * 4. Check $JAVA_HOME/jre
+ * 5. Check JDK location specified at compile time
+ *
+ * @param buffer buffer for result
+ * @param size buffer size in characters
+ * @return buffer on success or NULL on failure
+ */
+TCHAR LIBNXJAVA_EXPORTABLE *FindJavaRuntime(TCHAR *buffer, size_t size);
+
+/**
+ * Create Java virtual machine
+ *
+ * @param jvmPath path to JVM library
+ * @param jar application JAR - path should be relative to NetXMS library directory (can be NULL)
+ * @param usercp user defined class path (can be NULL)
+ * @param vmOptions additional VM options
+ * @param env points where JNI environment for current thread will be stored
+ * @return NXJAVA_SUCCESS if VM created successfully or appropriate error code
+ */
+JavaBridgeError LIBNXJAVA_EXPORTABLE CreateJavaVM(const TCHAR *jvmPath, const TCHAR *jar, const TCHAR *usercp, StringList *vmOptions, JNIEnv **env);
+
+/**
+ * Destroy Java virtual machine
+ */
+void LIBNXJAVA_EXPORTABLE DestroyJavaVM();
+
+/**
+ * Attach current thread to Java VM
+ *
+ * @return JNI environment for current thread or NULL on failure
+ */
+JNIEnv LIBNXJAVA_EXPORTABLE *AttachThreadToJavaVM();
+
+/**
+ * Detach current thread from Java VM
+ */
+void LIBNXJAVA_EXPORTABLE DetachThreadFromJavaVM();
+
+/**
+ * Start Java application. This is helper method for starting Java applications
+ * from command line wrapper. Application class should contain entry point with
+ * the following signature:
+ *
+ * public static void main(String[])
+ *
+ * @param env JNI environment for current thread
+ * @param appClass application class name
+ * @param argc number of command line arguments
+ * @param argv pointers to arguments in (expected to be encoded using system locale code page)
+ * @return NXJAVA_SUCCESS on success or appropriate error code
+ */
+JavaBridgeError LIBNXJAVA_EXPORTABLE StartJavaApplication(JNIEnv *env, const char *appClass, int argc, char **argv);
+
+/**
+ * Create global reference to Java class
+ *
+ * @param env JNI environment for current thread
+ * @param className Java class name
+ * @return Java class object
+ */
+jclass LIBNXJAVA_EXPORTABLE CreateJavaClassGlobalRef(JNIEnv *env, const char *className);
+
+/**
+ * Create Java Config object (wrapper around C++ Config class)
+ *
+ * @param env JNI environment for current thread
+ * @param config C++ Config object
+ * @return Java wrapper object or NULL on failure
+ */
+jobject LIBNXJAVA_EXPORTABLE CreateConfigJavaInstance(JNIEnv *env, Config *config);
+
+#endif   /* _nxjava_h_ */
index b45d6eb..35dd11f 100644 (file)
@@ -721,7 +721,7 @@ BOOL Initialize()
 #ifdef _WIN32
                        0, NULL, MSG_DEBUG))
 #else
-                       g_dwNumMessages, g_szMessages, MSG_DEBUG))
+                       g_dwNumMessages, g_szMessages, MSG_DEBUG, MSG_SUBAGENT_MSG))
 #endif
        {
           //TODO: set flag that log have been opened with errors
@@ -734,7 +734,7 @@ BOOL Initialize()
 #ifdef _WIN32
                       0, NULL, MSG_DEBUG);
 #else
-                      g_dwNumMessages, g_szMessages, MSG_DEBUG);
+                      g_dwNumMessages, g_szMessages, MSG_DEBUG, MSG_SUBAGENT_MSG);
 #endif
                _ftprintf(stderr, _T("ERROR: Cannot open log file, logs will be written to syslog with debug level 1\n"));
 
index cfc67b7..fa90401 100644 (file)
@@ -6,4 +6,7 @@ bind9.jar: pom.xml
        mvn package
        mv target/bind9.jar .
 
+clean-local:
+       rm -rf target $(javalib_DATA)
+
 EXTRA_DIST = pom.xml bind9.jar
index a2a401c..340e460 100644 (file)
@@ -6,7 +6,7 @@
 
     <groupId>com.github.tomaskir</groupId>
     <artifactId>netxms-subagent-bind9</artifactId>
-    <version>2.1</version>
+    <version>2.1.1</version>
 
     <properties>
         <java.version>1.7</java.version>
     <dependencies>
         <dependency>
             <groupId>org.netxms</groupId>
+            <artifactId>netxms-java-bridge</artifactId>
+            <version>${project.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.netxms</groupId>
             <artifactId>netxms-agent</artifactId>
             <version>${project.version}</version>
+            <scope>provided</scope>
         </dependency>
     </dependencies>
 
index 258424b..587c42a 100644 (file)
@@ -1,20 +1,21 @@
 package com.github.tomaskir.netxms.subagents.bind9;
 
-import com.github.tomaskir.netxms.subagents.bind9.collection.CollectionResult;
-import com.github.tomaskir.netxms.subagents.bind9.collection.Collector;
-import com.github.tomaskir.netxms.subagents.bind9.exceptions.CollectionErrorException;
-import org.netxms.agent.Config;
-import org.netxms.agent.Parameter;
-import org.netxms.agent.ParameterType;
-import org.netxms.agent.Plugin;
-import org.netxms.agent.PluginInitException;
-import org.netxms.agent.adapters.ParameterAdapter;
-
 import java.nio.file.Paths;
 import java.util.HashSet;
 import java.util.Set;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
+import org.netxms.agent.Parameter;
+import org.netxms.agent.ParameterType;
+import org.netxms.agent.Plugin;
+import org.netxms.agent.PluginInitException;
+import org.netxms.agent.adapters.ParameterAdapter;
+import org.netxms.bridge.Config;
+import org.netxms.bridge.LogLevel;
+import org.netxms.bridge.Platform;
+import com.github.tomaskir.netxms.subagents.bind9.collection.CollectionResult;
+import com.github.tomaskir.netxms.subagents.bind9.collection.Collector;
+import com.github.tomaskir.netxms.subagents.bind9.exceptions.CollectionErrorException;
 
 /**
  * @author Tomas Kirnak
@@ -31,6 +32,18 @@ public final class Bind9Plugin extends Plugin {
 
     private final Collector collector;
     private final Thread collectionThread;
+    
+    /**
+     * Log message and throw Illegal state exception
+     * 
+     * @param msg message to log
+     * @throws IllegalStateException
+     */
+    private static void fail(final String msg) throws IllegalStateException
+    {
+       Platform.writeLog(LogLevel.ERROR, "BIND9: " + msg);
+       throw new IllegalStateException(msg);
+    }
 
     // constructor
     public Bind9Plugin(Config config) {
@@ -42,12 +55,10 @@ public final class Bind9Plugin extends Plugin {
 
         // check if all config values present
         if (statsFile.equals("")) {
-            throw new IllegalStateException("'statsFile' configuration value not found " +
-                    "in 'bind9' section of Agent configuration");
+            fail("'statsFile' configuration value not found in 'bind9' section of Agent configuration");
         }
         if (collectionInterval < 1) {
-            throw new IllegalStateException("'collectionInterval' configuration value not found or lower than 1" +
-                    "in 'bind9' section of Agent configuration");
+            fail("'collectionInterval' configuration value not found or lower than 1 in 'bind9' section of Agent configuration");
         }
 
         this.collector = new Collector(
index 65449ee..96d9ca7 100644 (file)
@@ -1,9 +1,5 @@
 package com.github.tomaskir.netxms.subagents.bind9.collection;
 
-import com.github.tomaskir.netxms.subagents.bind9.Parameters;
-import com.github.tomaskir.netxms.subagents.bind9.exceptions.StatsFileRemovalException;
-import org.netxms.agent.SubAgent;
-
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
@@ -11,6 +7,10 @@ import java.nio.file.NoSuchFileException;
 import java.nio.file.Path;
 import java.util.List;
 import java.util.concurrent.locks.ReadWriteLock;
+import org.netxms.bridge.LogLevel;
+import org.netxms.bridge.Platform;
+import com.github.tomaskir.netxms.subagents.bind9.Parameters;
+import com.github.tomaskir.netxms.subagents.bind9.exceptions.StatsFileRemovalException;
 
 /**
  * @author Tomas Kirnak
@@ -55,7 +55,7 @@ public final class Collector implements Runnable {
                 try {
                     statsFileCleanup();
                 } catch (StatsFileRemovalException e) {
-                    SubAgent.writeLog(SubAgent.LogLevel.WARNING,
+                    Platform.writeLog(LogLevel.WARNING,
                             "Failed to delete bind9 statistics file, error: '" + e.getCause().getMessage() + "'");
 
                     result.setCollectionError(true);
@@ -67,7 +67,7 @@ public final class Collector implements Runnable {
                 try {
                     rndc = Runtime.getRuntime().exec("rndc stats");
                 } catch (IOException e) {
-                    SubAgent.writeLog(SubAgent.LogLevel.ERROR,
+                    Platform.writeLog(LogLevel.ERROR,
                             "Failed to run 'rndc stats', error: '" + e.getMessage() + "'");
 
                     result.setCollectionError(true);
@@ -85,7 +85,7 @@ public final class Collector implements Runnable {
 
                 // check for errors
                 if (rndc.exitValue() != 0) {
-                    SubAgent.writeLog(SubAgent.LogLevel.ERROR,
+                    Platform.writeLog(LogLevel.ERROR,
                             "'rndc stats' exited with a non-0 exit code value");
 
                     result.setCollectionError(true);
@@ -97,7 +97,7 @@ public final class Collector implements Runnable {
                 try {
                     lines = Files.readAllLines(statsFile, StandardCharsets.UTF_8);
                 } catch (IOException e) {
-                    SubAgent.writeLog(SubAgent.LogLevel.WARNING,
+                    Platform.writeLog(LogLevel.WARNING,
                             "Unable to read bind9 statistics file, error: '" + e.getMessage() + "'");
 
                     result.setCollectionError(true);
index a5b997f..f19e49a 100644 (file)
@@ -5,7 +5,7 @@
                        <provider class="org.eclipse.cdt.core.language.settings.providers.LanguageSettingsGenericProvider" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider" name="CDT User Setting Entries" prefer-non-shared="true"/>
                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
                        <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
-                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-473888658169189981" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1092834717854559371" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
                                <language-scope id="org.eclipse.cdt.core.gcc"/>
                                <language-scope id="org.eclipse.cdt.core.g++"/>
                        </provider>
index 0be2002..0bef49b 100644 (file)
@@ -5,7 +5,7 @@
                        <provider class="org.eclipse.cdt.core.language.settings.providers.LanguageSettingsGenericProvider" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider" name="CDT User Setting Entries" prefer-non-shared="true"/>
                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
                        <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
-                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-473888658169189981" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1092834717854559371" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
                                <language-scope id="org.eclipse.cdt.core.gcc"/>
                                <language-scope id="org.eclipse.cdt.core.g++"/>
                        </provider>
index 1102431..1ca6860 100644 (file)
@@ -5,7 +5,7 @@
                        <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
                        <provider copy-of="extension" id="org.eclipse.cdt.autotools.core.LibtoolGCCBuildCommandParser"/>
-                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-473888658169189981" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1092834717854559371" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
                                <language-scope id="org.eclipse.cdt.core.gcc"/>
                                <language-scope id="org.eclipse.cdt.core.g++"/>
                        </provider>
index 1e3db18..d81ed5e 100644 (file)
@@ -5,6 +5,7 @@
        <projects>
                <project>libnetxms</project>
                <project>libnxagent</project>
+               <project>libnxjava</project>
        </projects>
        <buildSpec>
                <buildCommand>
index 5752d74..92ae2f3 100644 (file)
@@ -1,10 +1,12 @@
 SUBAGENT = java
 
 pkglib_LTLIBRARIES = java.la
-java_la_SOURCES = ConfigHelper.cpp main.cpp SubAgent.cpp
+java_la_SOURCES = main.cpp SubAgent.cpp
 java_la_CPPFLAGS = -I@top_srcdir@/include
 java_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym
-java_la_LIBADD = ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la
+java_la_LIBADD = @top_srcdir@/src/agent/libnxagent/libnxagent.la \
+       @top_srcdir@/src/libnxjava/libnxjava.la \
+       @top_srcdir@/src/libnetxms/libnetxms.la
 
 EXTRA_DIST = \
        Makefile.w32 \
index fac4416..a0cc1bd 100644 (file)
@@ -62,18 +62,6 @@ bool SubAgent::m_initialized = false;
 
 /**
  * Class:     org.netxms.agent.SubAgent
- * Method:    getNetXMSDirectoryInternal
- * Signature: (I)Ljava/lang/String;
- */
-static jstring JNICALL J_getNetXMSDirectoryInternal(JNIEnv *jenv, jclass jcls, jint type)
-{
-   TCHAR buffer[MAX_PATH];
-   GetNetXMSDirectory(static_cast<nxDirectoryType>(type), buffer);
-   return JavaStringFromCString(jenv, buffer);
-}
-
-/**
- * Class:     org.netxms.agent.SubAgent
  * Method:    getParameterArg
  * Signature: (Ljava/lang/String;I)Ljava/lang/String;
  */
@@ -140,46 +128,13 @@ static jboolean JNICALL J_pushParameterData(JNIEnv *jenv, jclass jcls, jstring j
 }
 
 /**
- * Class:     org.netxms.agent.SubAgent
- * Method:    writeLog
- * Signature: (ILjava/lang/String;)V
- */
-static void JNICALL J_writeLog(JNIEnv *jenv, jclass jcls, jint level, jstring jmessage)
-{
-   if (jmessage != NULL)
-   {
-      TCHAR *message = CStringFromJavaString(jenv, jmessage);
-      AgentWriteLog((int)level, message);
-      free(message);
-   }
-}
-
-/**
- * Class:     org.netxms.agent.SubAgent
- * Method:    writeDebugLog
- * Signature: (ILjava/lang/String;)V
- */
-static void JNICALL J_writeDebugLog(JNIEnv *jenv, jclass jcls, jint level, jstring jmessage)
-{
-   if (jmessage != NULL)
-   {
-      TCHAR *message = CStringFromJavaString(jenv, jmessage);
-      AgentWriteDebugLog((int)level, message);
-      free(message);
-   }
-}
-
-/**
  * Native methods
  */
 static JNINativeMethod s_jniNativeMethods[] =
 {
-   { (char *)"getNetXMSDirectoryInternal", (char *)"(I)Ljava/lang/String;", (void *)J_getNetXMSDirectoryInternal },
    { (char *)"getParameterArg", (char *)"(Ljava/lang/String;I)Ljava/lang/String;", (void *)J_getParameterArg },
    { (char *)"pushParameterData", (char *)"(Ljava/lang/String;Ljava/lang/String;)Z", (void *)J_pushParameterData },
-   { (char *)"sendTrap", (char *)"(ILjava/lang/String;[Ljava/lang/String;)V", (void *)J_sendTrap },
-   { (char *)"writeDebugLog", (char *)"(ILjava/lang/String;)V", (void *)J_writeDebugLog },
-   { (char *)"writeLog", (char *)"(ILjava/lang/String;)V", (void *)J_writeLog }
+   { (char *)"sendTrap", (char *)"(ILjava/lang/String;[Ljava/lang/String;)V", (void *)J_sendTrap }
 };
 
 /**
@@ -201,15 +156,15 @@ bool SubAgent::getMethodId(JNIEnv *curEnv, const char *name, const char *profile
  */
 bool SubAgent::initialize(JNIEnv *curEnv)
 {
-   m_class = CreateClassGlobalRef(curEnv, s_subAgentClassName);
+   m_class = CreateJavaClassGlobalRef(curEnv, s_subAgentClassName);
    if (m_class == NULL)
       return false;
 
-   m_stringClass = CreateClassGlobalRef(curEnv, "java/lang/String");
+   m_stringClass = CreateJavaClassGlobalRef(curEnv, "java/lang/String");
    if (m_stringClass == NULL)
       return false;
 
-   if (!getMethodId(curEnv, "<init>", "(Lorg/netxms/agent/Config;)V", &m_constructor))
+   if (!getMethodId(curEnv, "<init>", "(Lorg/netxms/bridge/Config;)V", &m_constructor))
       return false;
    if (!getMethodId(curEnv, "actionHandler", "(Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)Z", &m_actionHandler))
       return false;
@@ -223,7 +178,7 @@ bool SubAgent::initialize(JNIEnv *curEnv)
       return false;
    if (!getMethodId(curEnv, "getTables", "()[Ljava/lang/String;", &m_getTables))
       return false;
-   if (!getMethodId(curEnv, "init", "(Lorg/netxms/agent/Config;)Z", &m_init))
+   if (!getMethodId(curEnv, "init", "()Z", &m_init))
       return false;
    if (!getMethodId(curEnv, "listHandler", "(Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/String;", &m_listHandler))
       return false;
@@ -246,10 +201,9 @@ bool SubAgent::initialize(JNIEnv *curEnv)
 
 /**
  * Create SubAgent object instance.
- * @param jvm the Java VM
  * @param config Config object
  */
-SubAgent *SubAgent::createInstance(JavaVM *jvm, JNIEnv *curEnv, jobject config)
+SubAgent *SubAgent::createInstance(JNIEnv *curEnv, jobject config)
 {
    if (!m_initialized)
    {
@@ -272,15 +226,14 @@ SubAgent *SubAgent::createInstance(JavaVM *jvm, JNIEnv *curEnv, jobject config)
       return NULL;
    }
 
-   return new SubAgent(jvm, instance);
+   return new SubAgent(instance);
 }
 
 /**
  * Internal constructor
  */
-SubAgent::SubAgent(JavaVM *jvm, jobject instance)
+SubAgent::SubAgent(jobject instance)
 {
-   m_jvm = jvm;
    m_instance = instance;
 }
 
@@ -289,11 +242,10 @@ SubAgent::SubAgent(JavaVM *jvm, jobject instance)
  */
 SubAgent::~SubAgent()
 {
-   JNIEnv *curEnv = NULL;
-   if (m_jvm->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL) == JNI_OK)
-   {
+   JNIEnv *curEnv = AttachThreadToJavaVM();
+   if (curEnv != NULL)
       curEnv->DeleteGlobalRef(m_instance);
-   }
+   DetachThreadFromJavaVM();
 }
 
 /**
@@ -301,20 +253,16 @@ SubAgent::~SubAgent()
  */
 JNIEnv *SubAgent::getCurrentEnv()
 {
-   JNIEnv *curEnv = NULL;
-   jint res = m_jvm->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
-   if (res != JNI_OK)
-   {
-      AgentWriteLog(NXLOG_ERROR, _T("JAVA: SubAgent::getCurrentEnv(): cannot attach current thrad to JVM"));
-      return NULL;
-   }
+   JNIEnv *curEnv = AttachThreadToJavaVM();
+   if (curEnv == NULL)
+      AgentWriteLog(NXLOG_ERROR, _T("JAVA: SubAgent::getCurrentEnv(): cannot attach current thread to JVM"));
    return curEnv;
 }
 
 /**
  * Call Java method SubAgent.init()
  */
-bool SubAgent::init(jobject config)
+bool SubAgent::init()
 {
    if (!m_initialized)
       return false;
@@ -323,7 +271,7 @@ bool SubAgent::init(jobject config)
    if (curEnv == NULL)
       return false;
 
-   jboolean ret = static_cast<jboolean>(curEnv->CallBooleanMethod(m_instance, m_init, config));
+   jboolean ret = static_cast<jboolean>(curEnv->CallBooleanMethod(m_instance, m_init));
    m_initialized = (ret == JNI_TRUE);
    return m_initialized;
 }
index 589bba4..b866469 100644 (file)
@@ -42,12 +42,11 @@ private:
    static jmethodID m_tableHandler;
    static bool m_initialized;
 
-   JavaVM *m_jvm;
    jobject m_instance;
 
    static bool getMethodId(JNIEnv *curEnv, const char *name, const char *profile, jmethodID *id);
 
-   SubAgent(JavaVM *jvm, jobject instance);
+   SubAgent(jobject instance);
 
    JNIEnv *getCurrentEnv();
    StringList *getContributionItems(jmethodID method, const TCHAR *methodName);
@@ -60,12 +59,12 @@ public:
     * It will call the default constructor
     * @param jvm the Java VM
     */
-   static SubAgent *createInstance(JavaVM *jvm, JNIEnv *curEnv, jobject config);
+   static SubAgent *createInstance(JNIEnv *curEnv, jobject config);
 
    ~SubAgent();
 
    // Methods
-   bool init(jobject config);
+   bool init();
    void shutdown();
    bool loadPlugin(const TCHAR *path);
 
index eb1368c..bcd99e7 100644 (file)
@@ -4,7 +4,7 @@
   <groupId>org.netxms</groupId>
   <artifactId>netxms-agent</artifactId>
   <packaging>jar</packaging>
-  <version>2.1</version>
+  <version>2.1.1</version>
   <name>NetXMS Java Agent</name>
   <url>http://www.netxms.org</url>
 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>
 
+  <dependencies>
+    <dependency>
+      <groupId>org.netxms</groupId>
+      <artifactId>netxms-java-bridge</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+
   <build>
     <finalName>${project.artifactId}</finalName>
     <plugins>
               </execution>
           </executions>
       </plugin>
+      <plugin>
+        <artifactId>maven-source-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>attach-sources</id>
+            <phase>verify</phase>
+            <goals>
+              <goal>jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
     </plugins>
   </build>
 
index ef4a281..a3546c9 100644 (file)
@@ -18,6 +18,9 @@
  */
 package org.netxms.agent;
 
+import org.netxms.bridge.Config;
+import org.netxms.bridge.Platform;
+
 /**
  * Base class for Java agent plugins
  */
@@ -54,7 +57,7 @@ public abstract class Plugin
     */
    public void init(Config config) throws PluginInitException
    {
-      SubAgent.writeDebugLog(6, "JAVA/" + getName() + ": initializing");
+      Platform.writeDebugLog(6, "JAVA/" + getName() + ": initializing");
    }
 
    /**
@@ -62,7 +65,7 @@ public abstract class Plugin
     */
    public void shutdown()
    {
-      SubAgent.writeDebugLog(6, "JAVA/" + getName() + ": shutdown called");
+      Platform.writeDebugLog(6, "JAVA/" + getName() + ": shutdown called");
    }
 
    /**
index c8ae4b4..1fcc6ab 100644 (file)
@@ -29,6 +29,11 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.jar.Attributes;
 import java.util.jar.Manifest;
+import org.netxms.bridge.Config;
+import org.netxms.bridge.ConfigEntry;
+import org.netxms.bridge.DirectoryType;
+import org.netxms.bridge.LogLevel;
+import org.netxms.bridge.Platform;
 
 /**
  * This class is a Java representation of native subagent exposing to it required APIs
@@ -36,23 +41,6 @@ import java.util.jar.Manifest;
  */
 public class SubAgent
 {
-   public enum LogLevel
-   {
-      INFO(0x0004), WARNING(0x0002), ERROR(0x0001);
-
-      private int value;
-
-      LogLevel(final int value)
-      {
-         this.value = value;
-      }
-
-      public int getValue()
-      {
-         return value;
-      }
-   }
-
    private static final String JAR = ".jar";
    private static final String PLUGIN_CLASSNAME_ATTRIBUTE_NAME = "NetXMS-Plugin-Classname";
    private static final String MANIFEST_PATH = "META-INF/MANIFEST.MF";
@@ -81,7 +69,7 @@ public class SubAgent
       tables = new HashMap<String, TableParameter>();
 
       this.config = config;
-      writeDebugLog(1, "Java SubAgent created");
+      Platform.writeDebugLog(1, "Java SubAgent created");
 
       // load all Plugins
       ConfigEntry configEntry = config.getEntry("/Java/Plugin");
@@ -96,14 +84,14 @@ public class SubAgent
             }
             catch(Throwable e)
             {
-               writeLog(LogLevel.ERROR, "JAVA: Exception in loadPlugin: " + e.getClass().getCanonicalName() + ": " + e.getMessage());
-               writeDebugLog(6, "JAVA:   ", e);
+               Platform.writeLog(LogLevel.ERROR, "JAVA: Exception in loadPlugin: " + e.getClass().getCanonicalName() + ": " + e.getMessage());
+               Platform.writeDebugLog(6, "JAVA:   ", e);
             }
          }
       }
       else
       {
-         writeLog(LogLevel.WARNING, "No plugins defined in Java section");
+         Platform.writeLog(LogLevel.WARNING, "No plugins defined in Java section");
       }
    }
 
@@ -120,14 +108,6 @@ public class SubAgent
    /*===== native methods exposed by agent (see nms_agent.h) =====*/
    
    /**
-    * Get NetXMS directory (internal bridge to native code)
-    * 
-    * @param type directory type
-    * @return path to directory or empty string on error
-    */
-   protected static native String getNetXMSDirectoryInternal(int type);
-   
-   /**
     * Extract argument from full parameter name.
     * 
     * For example:
@@ -145,72 +125,31 @@ public class SubAgent
 
    protected static native boolean pushParameterData(String name, String value);
 
-   protected static native void writeLog(int level, String message);
-
-   public static native void writeDebugLog(int level, String message);
-
    /*===== end of native methods exposed by agent =====*/
 
    /**
-    * Wrapper for native writeLog call
-    * 
-    * @param level log level
-    * @param message message text
-    */
-   public static void writeLog(LogLevel level, String message)
-   {
-      writeLog(level.getValue(), message);
-   }
-
-   /**
-    * Write exception's stack trace to debug log
-    * 
-    * @param level log level
-    * @param prefix message prefix
-    * @param e exception to log
-    */
-   public static void writeDebugLog(int level, String prefix, Throwable e)
-   {
-      for(StackTraceElement s : e.getStackTrace())
-      {
-         writeDebugLog(level, prefix + s.toString());
-      }
-   }
-   
-   /**
-    * Get NetXMS directory
-    * 
-    * @param type directory type
-    * @return path to directory or empty string on error
-    */
-   public static String getNetXMSDirectory(DirectoryType type)
-   {
-      return getNetXMSDirectoryInternal(type.getValue());
-   }
-
-   /**
     * Initialize (to be called from native subagent)
     * 
     * @param config agent configuration
     * @return true if initialization was successful
     */
-   public boolean init(Config config)
+   public boolean init()
    {
-      writeDebugLog(2, "JAVA: subagent initialization started");
+      Platform.writeDebugLog(2, "JAVA: subagent initialization started");
       for(Map.Entry<String, Plugin> entry : plugins.entrySet())
       {
          try
          {
-            writeDebugLog(5, "JAVA: calling init() method for plugin " + entry.getKey());
+            Platform.writeDebugLog(5, "JAVA: calling init() method for plugin " + entry.getKey());
             entry.getValue().init(config);
          }
          catch(Throwable e)
          {
-            writeDebugLog(2, "JAVA: exception in plugin " + entry.getKey() + " initialization handler: " + e.getClass().getCanonicalName() + ": " + e.getMessage());
-            writeDebugLog(6, "JAVA:   ", e);
+            Platform.writeDebugLog(2, "JAVA: exception in plugin " + entry.getKey() + " initialization handler: " + e.getClass().getCanonicalName() + ": " + e.getMessage());
+            Platform.writeDebugLog(6, "JAVA:   ", e);
          }
       }
-      writeDebugLog(2, "JAVA: subagent initialization completed");
+      Platform.writeDebugLog(2, "JAVA: subagent initialization completed");
       return true;
    }
 
@@ -219,21 +158,21 @@ public class SubAgent
     */
    public void shutdown()
    {
-      writeDebugLog(2, "JAVA: subagent shutdown initiated");
+      Platform.writeDebugLog(2, "JAVA: subagent shutdown initiated");
       for(Map.Entry<String, Plugin> entry : plugins.entrySet())
       {
          try
          {
-            writeDebugLog(5, "JAVA: calling shutdown() method for plugin " + entry.getKey());
+            Platform.writeDebugLog(5, "JAVA: calling shutdown() method for plugin " + entry.getKey());
             entry.getValue().shutdown();
          }
          catch(Throwable e)
          {
-            writeDebugLog(2, "JAVA: exception in plugin " + entry.getKey() + " shutdown handler: " + e.getClass().getCanonicalName() + ": " + e.getMessage());
-            writeDebugLog(6, "JAVA:   ", e);
+            Platform.writeDebugLog(2, "JAVA: exception in plugin " + entry.getKey() + " shutdown handler: " + e.getClass().getCanonicalName() + ": " + e.getMessage());
+            Platform.writeDebugLog(6, "JAVA:   ", e);
          }
       }
-      writeDebugLog(2, "JAVA: subagent shutdown completed");
+      Platform.writeDebugLog(2, "JAVA: subagent shutdown completed");
    }
 
    /**
@@ -244,7 +183,7 @@ public class SubAgent
     */
    protected boolean loadPlugin(String path)
    {
-      writeDebugLog(2, "SubAgent.loadPlugin(" + path + ")");
+      Platform.writeDebugLog(2, "SubAgent.loadPlugin(" + path + ")");
       Plugin[] loadList = path.toLowerCase().endsWith(JAR) ? createPluginWithJar(path, config) : createPluginWithClassname(path, config);
       
       if ((loadList == null) || (loadList.length == 0))
@@ -253,7 +192,7 @@ public class SubAgent
       for(Plugin p : loadList)
       {
          plugins.put(p.getName(), p);
-         writeDebugLog(2, "Java plugin " + p.getName() + " (" + p.getClass().getName() + ") loaded");
+         Platform.writeDebugLog(2, "Java plugin " + p.getName() + " (" + p.getClass().getName() + ") loaded");
          
          // register actions
          Action[] _actions = p.getActions();
@@ -280,11 +219,11 @@ public class SubAgent
          for(int i = 0; i < _tableParameters.length; i++)
             tables.put(createContributionItemId(p, _tableParameters[i]), _tableParameters[i]);
       
-         writeDebugLog(6, "SubAgent.loadPlugin actions=" + actions);
-         writeDebugLog(6, "SubAgent.loadPlugin parameters=" + parameters);
-         writeDebugLog(6, "SubAgent.loadPlugin listParameters=" + lists);
-         writeDebugLog(6, "SubAgent.loadPlugin pushParameters=" + pushParameters);
-         writeDebugLog(6, "SubAgent.loadPlugin tableParameters=" + tables);
+         Platform.writeDebugLog(8, "SubAgent.loadPlugin actions=" + actions);
+         Platform.writeDebugLog(8, "SubAgent.loadPlugin parameters=" + parameters);
+         Platform.writeDebugLog(8, "SubAgent.loadPlugin listParameters=" + lists);
+         Platform.writeDebugLog(8, "SubAgent.loadPlugin pushParameters=" + pushParameters);
+         Platform.writeDebugLog(8, "SubAgent.loadPlugin tableParameters=" + tables);
       }
       return true;
    }
@@ -301,15 +240,15 @@ public class SubAgent
       try
       {
          Class<?> pluginClass = Class.forName(classname);
-         writeDebugLog(3, "SubAgent.createPluginWithClassname loaded class " + pluginClass);
+         Platform.writeDebugLog(3, "SubAgent.createPluginWithClassname loaded class " + pluginClass);
          Plugin plugin = instantiatePlugin(pluginClass.asSubclass(Plugin.class), config);
-         writeDebugLog(3, "SubAgent.createPluginWithClassname created instance " + plugin);
+         Platform.writeDebugLog(3, "SubAgent.createPluginWithClassname created instance " + plugin);
          return new Plugin[] { plugin };
       }
       catch(Throwable e)
       {
-         writeLog(LogLevel.WARNING, "Failed to load plugin " + classname + ": " + e.getClass().getCanonicalName() + ": " + e.getMessage());
-         writeDebugLog(6, "JAVA:   ", e);
+         Platform.writeLog(LogLevel.WARNING, "Failed to load plugin " + classname + ": " + e.getClass().getCanonicalName() + ": " + e.getMessage());
+         Platform.writeDebugLog(6, "JAVA:   ", e);
          return null;
       }
    }
@@ -330,8 +269,8 @@ public class SubAgent
          File file = new File(jarFile);
          if (!file.isAbsolute())
          {
-            writeDebugLog(5, "Plugin file path \"" + jarFile + "\" is not absolute");
-            String libDir = getNetXMSDirectory(DirectoryType.LIB);
+            Platform.writeDebugLog(5, "Plugin file path \"" + jarFile + "\" is not absolute");
+            String libDir = Platform.getNetXMSDirectory(DirectoryType.LIB);
             if ((libDir != null) && !libDir.isEmpty())
             {
                file = new File(libDir + File.separatorChar + jarFile);
@@ -340,11 +279,11 @@ public class SubAgent
          
          if (!file.isFile())
          {
-            writeLog(LogLevel.WARNING, "File \"" + file.getAbsolutePath() + "\" does not exist or is not a regular file");
+            Platform.writeLog(LogLevel.WARNING, "File \"" + file.getAbsolutePath() + "\" does not exist or is not a regular file");
             return null;
          }
          
-         writeDebugLog(2, "Loading plugin file \"" + file.getAbsolutePath() + "\"");
+         Platform.writeDebugLog(2, "Loading plugin file \"" + file.getAbsolutePath() + "\"");
          classLoader = new URLClassLoader(new URL[] { file.toURI().toURL() }, Thread.currentThread().getContextClassLoader() );
          URL url = classLoader.findResource(MANIFEST_PATH);
          if (url != null)
@@ -355,21 +294,21 @@ public class SubAgent
             if (classList == null)
             {
                classLoader.close();
-               writeLog(LogLevel.WARNING, "Failed to find " + PLUGIN_CLASSNAME_ATTRIBUTE_NAME + " attribute in manifest of " + jarFile);
+               Platform.writeLog(LogLevel.WARNING, "Failed to find " + PLUGIN_CLASSNAME_ATTRIBUTE_NAME + " attribute in manifest of " + jarFile);
                return null;
             }
          }
          else
          {
             classLoader.close();
-            writeLog(LogLevel.WARNING, "Error processing jar file " + jarFile + ": manifest not found");
+            Platform.writeLog(LogLevel.WARNING, "Error processing jar file " + jarFile + ": manifest not found");
             return null;
          }
       }
       catch(Throwable e)
       {
-         writeLog(LogLevel.WARNING, "Error processing jar file " + jarFile + ": " + e.getClass().getCanonicalName() + ": " + e.getMessage());
-         writeDebugLog(6, "JAVA:   ", e);
+         Platform.writeLog(LogLevel.WARNING, "Error processing jar file " + jarFile + ": " + e.getClass().getCanonicalName() + ": " + e.getMessage());
+         Platform.writeDebugLog(6, "JAVA:   ", e);
          return null;
       }
          
@@ -386,8 +325,8 @@ public class SubAgent
          }
          catch(Throwable e)
          {
-            writeLog(LogLevel.WARNING, "Failed to load plugin " + cn + " from jar file " + jarFile + ": " + e.getClass().getCanonicalName() + ": " + e.getMessage());
-            writeDebugLog(6, "JAVA:   ", e);
+            Platform.writeLog(LogLevel.WARNING, "Failed to load plugin " + cn + " from jar file " + jarFile + ": " + e.getClass().getCanonicalName() + ": " + e.getMessage());
+            Platform.writeDebugLog(6, "JAVA:   ", e);
          }
       }
       return pluginList.toArray(new Plugin[pluginList.size()]);
@@ -404,7 +343,7 @@ public class SubAgent
    protected Plugin instantiatePlugin(Class<? extends Plugin> pluginClass, Config config) throws Exception
    {
       Plugin plugin = null;
-      Constructor<? extends Plugin> constructor = pluginClass.getDeclaredConstructor(org.netxms.agent.Config.class);
+      Constructor<? extends Plugin> constructor = pluginClass.getDeclaredConstructor(Config.class);
       if (constructor != null)
       {
          plugin = constructor.newInstance(config);
@@ -437,8 +376,8 @@ public class SubAgent
       }
       catch(Throwable e)
       {
-         writeDebugLog(6, "JAVA: Exception in parameter handler: " + e.getClass().getCanonicalName() + ": " + e.getMessage());
-         writeDebugLog(6, "JAVA:   ", e);
+         Platform.writeDebugLog(6, "JAVA: Exception in parameter handler: " + e.getClass().getCanonicalName() + ": " + e.getMessage());
+         Platform.writeDebugLog(6, "JAVA:   ", e);
          throw e;
       }
    }
@@ -464,8 +403,8 @@ public class SubAgent
       }
       catch(Throwable e)
       {
-         writeDebugLog(6, "JAVA: Exception in list handler: " + e.getClass().getCanonicalName() + ": " + e.getMessage());
-         writeDebugLog(6, "JAVA:   ", e);
+         Platform.writeDebugLog(6, "JAVA: Exception in list handler: " + e.getClass().getCanonicalName() + ": " + e.getMessage());
+         Platform.writeDebugLog(6, "JAVA:   ", e);
          throw e;
       }
    }
@@ -485,15 +424,15 @@ public class SubAgent
          TableParameter tableParameter = tables.get(id);
          if (tableParameter != null)
          {
-            writeDebugLog(7, "SubAgent.tableParameterHandler(param=" + param + ", id=" + id + ") returning " + tableParameter.getValue(param));
+            Platform.writeDebugLog(7, "SubAgent.tableParameterHandler(param=" + param + ", id=" + id + ") returning " + tableParameter.getValue(param));
             return tableParameter.getValue(param);
          }
          return null;
       }
       catch(Throwable e)
       {
-         writeDebugLog(6, "JAVA: Exception in table handler: " + e.getClass().getCanonicalName() + ": " + e.getMessage());
-         writeDebugLog(6, "JAVA:   ", e);
+         Platform.writeDebugLog(6, "JAVA: Exception in table handler: " + e.getClass().getCanonicalName() + ": " + e.getMessage());
+         Platform.writeDebugLog(6, "JAVA:   ", e);
          throw e;
       }
    }
@@ -518,8 +457,8 @@ public class SubAgent
       }
       catch(Throwable e)
       {
-         writeDebugLog(6, "JAVA: Exception in action handler: " + e.getClass().getCanonicalName() + ": " + e.getMessage());
-         writeDebugLog(6, "JAVA:   ", e);
+         Platform.writeDebugLog(6, "JAVA: Exception in action handler: " + e.getClass().getCanonicalName() + ": " + e.getMessage());
+         Platform.writeDebugLog(6, "JAVA:   ", e);
       }
       return false;
    }
index 88ee725..d23fbb1 100644 (file)
@@ -1,7 +1,7 @@
 /* 
  ** Java-Bridge NetXMS subagent
  ** Copyright (C) 2013 TEMPEST a.s.
- ** Copyright (c) 2015-2016 Raden Solutions SIA
+ ** Copyright (c) 2015-2017 Raden Solutions SIA
  **
  ** This program is free software; you can redistribute it and/or modify
  ** it under the terms of the GNU General Public License as published by
 
 #include <nms_util.h>
 #include <nms_agent.h>
-#include <jni.h>
-#include <unicode.h>
-
-/**
- * Convert Java string to C string.
- * Result string is dynamically allocated and must be disposed by calling free().
- */
-inline TCHAR *CStringFromJavaString(JNIEnv *env, jstring jstr)
-{
-   const jchar *chars = env->GetStringChars(jstr, NULL);
-   jsize len = env->GetStringLength(jstr);
-   TCHAR *str = (TCHAR *)malloc((len + 1) * sizeof(TCHAR));
-#ifdef UNICODE
-#if UNICODE_UCS4
-   ucs2_to_ucs4(chars, len, str, len + 1);
-#else
-   memcpy(str, chars, len * sizeof(WCHAR));
-#endif
-#else
-   ucs2_to_mb(chars, len, str, len + 1);
-#endif
-   env->ReleaseStringChars(jstr, chars);
-   str[len] = 0;
-   return str;
-}
-
-/**
- * Convert Java string to C string.
- * Result string is in static buffer
- */
-inline TCHAR *CStringFromJavaString(JNIEnv *env, jstring jstr, TCHAR *buffer, size_t bufferLen)
-{
-   const jchar *chars = env->GetStringChars(jstr, NULL);
-   jsize len = env->GetStringLength(jstr);
-#ifdef UNICODE
-#if UNICODE_UCS4
-   ucs2_to_ucs4(chars, min(len, bufferLen - 1), buffer, bufferLen);
-#else
-   memcpy(buffer, chars, min((size_t)len, bufferLen) * sizeof(WCHAR));
-#endif
-#else
-   ucs2_to_mb(chars, min(len, bufferLen - 1), buffer, bufferLen);
-#endif
-   env->ReleaseStringChars(jstr, chars);
-   buffer[min((size_t)len, bufferLen - 1)] = 0;
-   return buffer;
-}
-
-/**
- * Convert C string to Java string.
- */
-inline jstring JavaStringFromCString(JNIEnv *env, const TCHAR *str)
-{
-   jsize len = (jsize)_tcslen(str);
-#ifdef UNICODE
-#if UNICODE_UCS4
-   jchar *tmp = (jchar *)UCS2StringFromUCS4String(str);
-   jstring js = env->NewString(tmp, len);
-   free(tmp);
-#else
-   jstring js = env->NewString((jchar *)str, len);
-#endif
-#else
-   jchar *tmp = (jchar *)UCS2StringFromMBString(str);
-   jstring js = env->NewString(tmp, len);
-   free(tmp);
-#endif
-   return js;
-}
-
-/**
- * Create StringList from Java string array
- */
-inline StringList *StringListFromJavaArray(JNIEnv *curEnv, jobjectArray a)
-{
-   StringList *list = new StringList();
-   jsize count = curEnv->GetArrayLength(a);
-   for(jsize i = 0; i < count; i++)
-   {
-      jstring s = reinterpret_cast<jstring>(curEnv->GetObjectArrayElement(a, i));
-      list->addPreallocated(CStringFromJavaString(curEnv, s));
-      curEnv->DeleteLocalRef(s);
-   }
-   return list;
-}
-
-/**
- * Functions
- */
-jclass CreateClassGlobalRef(JNIEnv *curEnv, const char *className);
-bool RegisterConfigHelperNatives(JNIEnv *curEnv);
-jobject CreateConfigInstance(JNIEnv *curEnv, Config *config);
+#include <nxjava.h>
 
 #endif
index 34d3675..e84947e 100644 (file)
@@ -1,7 +1,7 @@
 /* 
  ** Java-Bridge NetXMS subagent
  ** Copyright (c) 2013 TEMPEST a.s.
- ** Copyright (c) 2015-2016 Raden Solutions SIA
+ ** Copyright (c) 2015-2017 Raden Solutions SIA
  **
  ** This program is free software; you can redistribute it and/or modify
  ** it under the terms of the GNU General Public License as published by
 #include "SubAgent.h"
 
 /**
- * JVM instance
- */
-static JavaVM *s_jvm = NULL;
-static HMODULE s_jvmModule = NULL;
-static JNIEnv *s_jniEnv = NULL;
-
-/**
  * Java subagent instance
  */
 static SubAgent *s_subAgent = NULL;
 
 /**
- * Create global reference to Java class
- */
-jclass CreateClassGlobalRef(JNIEnv *curEnv, const char *className)
-{
-   jclass c = curEnv->FindClass(className);
-   if (c == NULL)
-   {
-      AgentWriteLog(NXLOG_ERROR, _T("JAVA: Could not find class %hs"), className);
-      return NULL;
-   }
-
-   jclass gc = static_cast<jclass>(curEnv->NewGlobalRef(c));
-   curEnv->DeleteLocalRef(c);
-
-   if (gc == NULL)
-   {
-      AgentWriteLog(NXLOG_ERROR, _T("JAVA: Could not create global reference of class %s"), className);
-      return NULL;
-   }
-
-   return gc;
-}
-
-/**
  * Action handler
  */
 static LONG ActionHandler(const TCHAR *action, StringList *args, const TCHAR *id, AbstractCommSession *session)
@@ -70,7 +39,7 @@ static LONG ActionHandler(const TCHAR *action, StringList *args, const TCHAR *id
 
    AgentWriteDebugLog(6, _T("JAVA: ActionHandler(action=%s, id=%s)"), action, id);
    LONG rc = s_subAgent->actionHandler(action, args, id);
-   s_jvm->DetachCurrentThread();
+   DetachThreadFromJavaVM();
    return rc;
 }
 
@@ -83,7 +52,7 @@ static LONG ParameterHandler(const TCHAR *param, const TCHAR *id, TCHAR *value,
       return SYSINFO_RC_ERROR;
 
    LONG rc = s_subAgent->parameterHandler(param, id, value);
-   s_jvm->DetachCurrentThread();
+   DetachThreadFromJavaVM();
    return rc;
 }
 
@@ -96,7 +65,7 @@ static LONG ListHandler(const TCHAR *cmd, const TCHAR *id, StringList *value, Ab
       return SYSINFO_RC_ERROR;
 
    LONG rc = s_subAgent->listHandler(cmd, id, value);
-   s_jvm->DetachCurrentThread();
+   DetachThreadFromJavaVM();
    return rc;
 }
 
@@ -109,7 +78,7 @@ static LONG TableHandler(const TCHAR *cmd, const TCHAR *id, Table *value, Abstra
       return SYSINFO_RC_ERROR;
 
    LONG rc = s_subAgent->tableHandler(cmd, id, value);
-   s_jvm->DetachCurrentThread();
+   DetachThreadFromJavaVM();
    return rc;
 }
 
@@ -118,14 +87,7 @@ static LONG TableHandler(const TCHAR *cmd, const TCHAR *id, Table *value, Abstra
  */
 static BOOL SubAgentInit(Config *config)
 {
-   jobject jconfig = CreateConfigInstance(s_jniEnv, config);
-   if (jconfig == NULL)
-   {
-      return FALSE;
-   }
-   bool success = s_subAgent->init(jconfig);
-   s_jniEnv->DeleteGlobalRef(jconfig);
-   return success ? TRUE : FALSE;
+   return s_subAgent->init();
 }
 
 /**
@@ -137,30 +99,11 @@ static void SubAgentShutdown()
    {
       s_subAgent->shutdown();
    }
-
-   if (s_jvm != NULL)
-   {
-      AgentWriteDebugLog(6, _T("JAVA: destroying Java VM"));
-      s_jvm->DestroyJavaVM();
-      s_jvm = NULL;
-   }
-
-   if (s_jvmModule != NULL)
-   {
-      AgentWriteDebugLog(6, _T("JAVA: unloading JVM library"));
-      DLClose(s_jvmModule);
-      s_jvmModule = NULL;
-   }
-
-   AgentWriteDebugLog(1, _T("JAVA: shutdown comple"));
+   DestroyJavaVM();
+   AgentWriteDebugLog(1, _T("JAVA: subagent shutdown completed"));
 }
 
 /**
- * Prototype for JNI_CreateJavaVM
- */
-typedef jint (JNICALL *T_JNI_CreateJavaVM)(JavaVM **, void **, void *);
-
-/**
  * JVM path
  */
 #ifdef _WIN32
@@ -336,101 +279,44 @@ DECLARE_SUBAGENT_ENTRY_POINT(JAVA)
    }
 
    nxlog_debug(1, _T("JAVA: using JVM %s"), s_jvmPath);
-   
-   TCHAR errorText[256];
-   s_jvmModule = DLOpen(s_jvmPath, errorText);
-   if (s_jvmModule == NULL)
+
+   JNIEnv *env;
+   JavaBridgeError err = CreateJavaVM(s_jvmPath, _T("netxms-agent.jar"), s_userClasspath, NULL, &env);
+   if (err != NXJAVA_SUCCESS)
    {
-      AgentWriteLog(NXLOG_ERROR, _T("JAVA: Unable to load JVM: %s"), errorText);
+      AgentWriteLog(NXLOG_ERROR, _T("JAVA: Unable to load JVM: %s"), GetJavaBridgeErrorMessage(err));
       return FALSE;
    }
 
    BOOL success = FALSE;
-
-   JavaVMInitArgs vmArgs;
-   JavaVMOption vmOptions[1];
-   memset(vmOptions, 0, sizeof(vmOptions));
-
-   TCHAR libdir[MAX_PATH];
-   GetNetXMSDirectory(nxDirLib, libdir);
-
-   String classpath = _T("-Djava.class.path=");
-   classpath.append(libdir);
-   classpath.append(FS_PATH_SEPARATOR_CHAR);
-   classpath.append(_T("netxms-agent.jar"));
-   if (s_userClasspath != NULL)
-   {
-      classpath.append(JAVA_CLASSPATH_SEPARATOR);
-      classpath.append(s_userClasspath);
-      free(s_userClasspath);
-      s_userClasspath = NULL;
-   }
-
-#ifdef UNICODE
-   vmOptions[0].optionString = classpath.getUTF8String();
-#else
-   vmOptions[0].optionString = strdup(classpath);
-#endif
-
-   // TODO JVM options
-
-   vmArgs.version = JNI_VERSION_1_6;
-   vmArgs.options = vmOptions;
-   vmArgs.nOptions = 1;
-   vmArgs.ignoreUnrecognized = JNI_TRUE;
-
-   nxlog_debug(6, _T("JVM options:"));
-   for(int i = 0; i < vmArgs.nOptions; i++)
-      nxlog_debug(6, _T("    %hs"), vmArgs.options[i].optionString);
-
-   T_JNI_CreateJavaVM CreateJavaVM = (T_JNI_CreateJavaVM)DLGetSymbolAddr(s_jvmModule, "JNI_CreateJavaVM", NULL);
-   if (CreateJavaVM != NULL)
+   if (SubAgent::initialize(env))
    {
-      if (CreateJavaVM(&s_jvm, (void **)&s_jniEnv, &vmArgs) == JNI_OK)
+      // create an instance of org.netxms.agent.Config
+      jobject jconfig = CreateConfigJavaInstance(env, config);
+      if (jconfig != NULL)
       {
-         AgentWriteDebugLog(6, _T("Java VM created"));
-         if (SubAgent::initialize(s_jniEnv) && RegisterConfigHelperNatives(s_jniEnv))
+         // create an instance of org.netxms.agent.SubAgent
+         s_subAgent = SubAgent::createInstance(env, jconfig);
+         if (s_subAgent != NULL)
          {
-            // create an instance of org.netxms.agent.Config
-            jobject jconfig = CreateConfigInstance(s_jniEnv, config);
-            if (jconfig != NULL)
-            {
-               // create an instance of org.netxms.agent.SubAgent
-               s_subAgent = SubAgent::createInstance(s_jvm, s_jniEnv, jconfig);
-               if (s_subAgent != NULL)
-               {
-                  AddContributionItems();
-                  success = TRUE;
-               }
-               else
-               {
-                  AgentWriteLog(NXLOG_ERROR, _T("JAVA: Failed to instantiate org.netxms.agent.SubAgent"));
-               }
-               s_jniEnv->DeleteGlobalRef(jconfig);
-            }
-            else
-            {
-               AgentWriteLog(NXLOG_ERROR, _T("JAVA: Failed to instantiate org.netxms.agent.Config"));
-            }
+            AddContributionItems();
+            success = TRUE;
+         }
+         else
+         {
+            AgentWriteLog(NXLOG_ERROR, _T("JAVA: Failed to instantiate org.netxms.agent.SubAgent"));
          }
+         env->DeleteGlobalRef(jconfig);
       }
       else
       {
-         AgentWriteLog(NXLOG_ERROR, _T("JAVA: CreateJavaVM failed"));
+         AgentWriteLog(NXLOG_ERROR, _T("JAVA: Failed to instantiate org.netxms.bridge.Config"));
       }
    }
-   else
-   {
-      AgentWriteLog(NXLOG_ERROR, _T("JAVA: JNI_CreateJavaVM failed"));
-   }
 
    if (!success)
    {
-      if (s_jvm != NULL)
-         s_jvm->DestroyJavaVM();
-
-      if (s_jvmModule != NULL)
-         DLClose(s_jvmModule);
+      DestroyJavaVM();
       return FALSE;
    }
 
index eb876d1..817ae0e 100644 (file)
@@ -6,7 +6,7 @@
 
     <groupId>org.netxms</groupId>
     <artifactId>netxms-subagent-jmx</artifactId>
-    <version>2.1</version>
+    <version>2.1.1</version>
 
     <properties>
         <java.version>1.7</java.version>
     <dependencies>
         <dependency>
             <groupId>org.netxms</groupId>
+            <artifactId>netxms-java-bridge</artifactId>
+            <version>${project.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.netxms</groupId>
             <artifactId>netxms-agent</artifactId>
             <version>${project.version}</version>
+            <scope>provided</scope>
         </dependency>
     </dependencies>
 
index 5e5baa9..9903c4d 100644 (file)
@@ -6,16 +6,16 @@ package org.netxms.agent.jmx;
 import java.util.HashMap;
 import java.util.Map;
 import javax.management.openmbean.CompositeData;
-import org.netxms.agent.Config;
-import org.netxms.agent.ConfigEntry;
 import org.netxms.agent.ListParameter;
 import org.netxms.agent.Parameter;
 import org.netxms.agent.ParameterType;
 import org.netxms.agent.Plugin;
 import org.netxms.agent.PluginInitException;
-import org.netxms.agent.SubAgent;
 import org.netxms.agent.adapters.ListParameterAdapter;
 import org.netxms.agent.adapters.ParameterAdapter;
+import org.netxms.bridge.Config;
+import org.netxms.bridge.ConfigEntry;
+import org.netxms.bridge.Platform;
 
 /**
  * JMX subagent plugin
@@ -54,7 +54,7 @@ public class JmxPlugin extends Plugin
    @Override
    public String getVersion()
    {
-      return "1.0";
+      return "2.1.1";
    }
 
    /* (non-Javadoc)
@@ -115,7 +115,7 @@ public class JmxPlugin extends Plugin
          s = new Server(parts[0].trim(), parts[1].trim(), null, null);
       }
       servers.put(s.getName(), s);
-      SubAgent.writeDebugLog(3, "JMX: added server connection " + s.getName() + " (" + s.getUrl() + ")");
+      Platform.writeDebugLog(3, "JMX: added server connection " + s.getName() + " (" + s.getUrl() + ")");
    }
    
    /**
index cbbaa3f..c06e03c 100644 (file)
@@ -16,7 +16,7 @@ import javax.management.ObjectName;
 import javax.management.remote.JMXConnector;
 import javax.management.remote.JMXConnectorFactory;
 import javax.management.remote.JMXServiceURL;
-import org.netxms.agent.SubAgent;
+import org.netxms.bridge.Platform;
 
 /**
  * JMX server
@@ -86,7 +86,7 @@ public class Server
          }
          catch(Exception e)
          {
-            SubAgent.writeDebugLog(5, "JMX: cannot setup connection to " + url, e);
+            Platform.writeDebugLog(5, "JMX: cannot setup connection to " + url, e);
             throw e;
          }
       }
@@ -96,11 +96,11 @@ public class Server
          try
          {
             mbsc = jmxc.getMBeanServerConnection();
-            SubAgent.writeDebugLog(5, "JMX: connected to " + url);
+            Platform.writeDebugLog(5, "JMX: connected to " + url);
          }
          catch(Exception e)
          {
-            SubAgent.writeDebugLog(5, "JMX: cannot get MBean server connection for " + url, e);
+            Platform.writeDebugLog(5, "JMX: cannot get MBean server connection for " + url, e);
             jmxc.close();
             jmxc = null;
             throw e;
@@ -121,7 +121,7 @@ public class Server
          }
          catch(Exception e)
          {
-            SubAgent.writeDebugLog(6, "JMX: exception in disconnect() call for " + url, e);
+            Platform.writeDebugLog(6, "JMX: exception in disconnect() call for " + url, e);
          }
          jmxc = null;
       }
@@ -246,7 +246,7 @@ public class Server
       connect();
       try
       {
-         SubAgent.writeDebugLog(6, String.format("JMX: reading object %s attribute %s", object, attribute));
+         Platform.writeDebugLog(6, String.format("JMX: reading object %s attribute %s", object, attribute));
          return mbsc.getAttribute(new ObjectName(object), attribute).toString();
       }
       catch(AttributeNotFoundException e)
index 310856b..d831a84 100644 (file)
@@ -5,7 +5,7 @@
                        <provider class="org.eclipse.cdt.core.language.settings.providers.LanguageSettingsGenericProvider" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider" name="CDT User Setting Entries" prefer-non-shared="true"/>
                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
                        <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
-                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-473888658169189981" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1092834717854559371" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
                                <language-scope id="org.eclipse.cdt.core.gcc"/>
                                <language-scope id="org.eclipse.cdt.core.g++"/>
                        </provider>
index dc772ef..eb87265 100644 (file)
@@ -5,7 +5,7 @@
                        <provider class="org.eclipse.cdt.core.language.settings.providers.LanguageSettingsGenericProvider" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider" name="CDT User Setting Entries" prefer-non-shared="true"/>
                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
                        <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
-                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-473888658169189981" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1092834717854559371" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
                                <language-scope id="org.eclipse.cdt.core.gcc"/>
                                <language-scope id="org.eclipse.cdt.core.g++"/>
                        </provider>
index eb90554..79af76a 100644 (file)
@@ -5,7 +5,7 @@
                        <provider class="org.eclipse.cdt.core.language.settings.providers.LanguageSettingsGenericProvider" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider" name="CDT User Setting Entries" prefer-non-shared="true"/>
                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
                        <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
-                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-473888658169189981" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1092834717854559371" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
                                <language-scope id="org.eclipse.cdt.core.gcc"/>
                                <language-scope id="org.eclipse.cdt.core.g++"/>
                        </provider>
index 6f027dd..4dacf49 100644 (file)
@@ -5,7 +5,7 @@
                        <provider class="org.eclipse.cdt.core.language.settings.providers.LanguageSettingsGenericProvider" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider" name="CDT User Setting Entries" prefer-non-shared="true"/>
                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
                        <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
-                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-473888658169189981" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1092834717854559371" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
                                <language-scope id="org.eclipse.cdt.core.gcc"/>
                                <language-scope id="org.eclipse.cdt.core.g++"/>
                        </provider>
index a7070d6..7280812 100644 (file)
@@ -6,4 +6,7 @@ ubntlw.jar: pom.xml
        mvn package
        mv target/ubntlw.jar .
 
+clean-local:
+       rm -rf target ubntlw.jar
+
 EXTRA_DIST = Makefile.w32 pom.xml ubntlw.jar LICENSE README
index 730cb3a..4e84c84 100644 (file)
@@ -4,7 +4,7 @@
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.rfelements</groupId>
     <artifactId>ubntlw</artifactId>
-    <version>2.1</version>
+    <version>2.1.1</version>
 
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         </dependency>
         <dependency>
             <groupId>org.netxms</groupId>
+            <artifactId>netxms-java-bridge</artifactId>
+            <version>${project.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.netxms</groupId>
             <artifactId>netxms-agent</artifactId>
             <version>${project.version}</version>
             <scope>provided</scope>
index 6342e79..fe67040 100644 (file)
@@ -1,20 +1,27 @@
 package com.rfelements;
 
+import java.util.regex.Pattern;
+import org.netxms.agent.Action;
+import org.netxms.agent.ListParameter;
+import org.netxms.agent.Plugin;
+import org.netxms.agent.PushParameter;
+import org.netxms.agent.SubAgent;
+import org.netxms.agent.TableParameter;
+import org.netxms.bridge.Config;
+import org.netxms.bridge.LogLevel;
+import org.netxms.bridge.Platform;
 import com.rfelements.exception.CollectorException;
 import com.rfelements.model.json.ligowave.Ligowave;
 import com.rfelements.model.json.ubiquiti.Ubiquiti;
 import com.rfelements.provider.DataProvider;
 import com.rfelements.provider.DataProviderImpl;
-import org.netxms.agent.*;
-
-import java.util.regex.Pattern;
 
 /**
  * @author Pichanič Ján
  */
 abstract class AbstractCollector extends Plugin {
 
-    private static final String VERSION = "1.0";
+    private static final String VERSION = "2.1.1";
 
     private static final String IP_ADDRESS_PATTERN = "^([0" + "1]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
             "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
@@ -63,7 +70,7 @@ abstract class AbstractCollector extends Plugin {
     protected String parseDeviceIdentifierParameter(String param) throws CollectorException {
         String ip = SubAgent.getParameterArg(param, 1);
         if (!pattern.matcher(ip).matches()) {
-            SubAgent.writeLog(SubAgent.LogLevel.ERROR,
+           Platform.writeLog(LogLevel.ERROR,
                     "[" + this.getClass().getName() + "] [parseDeviceIdentifierParameter] IP passed as parameter does not match IP address pattern");
             throw new CollectorException("Parameter does not match IP address pattern !");
         }
index 2c5f456..673afca 100644 (file)
@@ -1,9 +1,9 @@
 package com.rfelements;
 
 import com.rfelements.model.json.ligowave.Ligowave;
-import org.netxms.agent.Config;
 import org.netxms.agent.Parameter;
 import org.netxms.agent.ParameterType;
+import org.netxms.bridge.Config;
 
 /**
  * @author Pichanič Ján
index 35ebd61..b0ecbb8 100644 (file)
@@ -2,9 +2,9 @@ package com.rfelements;
 
 import com.rfelements.exception.CollectorException;
 import com.rfelements.model.json.ligowave.Ligowave;
-import org.netxms.agent.Config;
 import org.netxms.agent.Parameter;
 import org.netxms.agent.ParameterType;
+import org.netxms.bridge.Config;
 
 /**
  * @author Pichanič Ján
index cbb1ab2..74aa6d5 100644 (file)
@@ -1,6 +1,7 @@
 package com.rfelements;
 
-import org.netxms.agent.SubAgent;
+import org.netxms.bridge.LogLevel;
+import org.netxms.bridge.Platform;
 
 public class Logger {
 
@@ -15,14 +16,14 @@ public class Logger {
     }
 
     public void e(final String message) {
-        SubAgent.writeLog(SubAgent.LogLevel.ERROR, "[" + clazz.getName() + "] " + message);
+       Platform.writeLog(LogLevel.ERROR, "[" + clazz.getName() + "] " + message);
     }
 
     public void w(final String message) {
-        SubAgent.writeLog(SubAgent.LogLevel.WARNING, "[" + clazz.getName() + "] " + message);
+       Platform.writeLog(LogLevel.WARNING, "[" + clazz.getName() + "] " + message);
     }
 
     public void i(final String message) {
-        SubAgent.writeLog(SubAgent.LogLevel.INFO, "[" + clazz.getName() + "] " + message);
+       Platform.writeLog(LogLevel.INFO, "[" + clazz.getName() + "] " + message);
     }
 }
index c663423..ad09620 100644 (file)
@@ -1,9 +1,9 @@
 package com.rfelements;
 
 import com.rfelements.model.json.ubiquiti.Ubiquiti;
-import org.netxms.agent.Config;
 import org.netxms.agent.Parameter;
 import org.netxms.agent.ParameterType;
+import org.netxms.bridge.Config;
 
 /**
  * @author Pichanič Ján
index b6c4913..fd3e6f0 100644 (file)
@@ -1,9 +1,9 @@
 package com.rfelements;
 
 import com.rfelements.model.json.ubiquiti.Ubiquiti;
-import org.netxms.agent.Config;
 import org.netxms.agent.Parameter;
 import org.netxms.agent.ParameterType;
+import org.netxms.bridge.Config;
 
 /**
  * @author Pichanič Ján
index 33548c7..5a5fcbb 100644 (file)
@@ -1,9 +1,9 @@
 package com.rfelements.cache;
 
-import com.rfelements.model.DeviceCredentials;
-import org.netxms.agent.SubAgent;
-
 import java.util.concurrent.ConcurrentHashMap;
+import org.netxms.bridge.LogLevel;
+import org.netxms.bridge.Platform;
+import com.rfelements.model.DeviceCredentials;
 
 /**
  * @author Pichanič Ján
@@ -23,7 +23,7 @@ public class CacheImpl implements Cache {
     }
 
     private CacheImpl() {
-        SubAgent.writeLog(SubAgent.LogLevel.INFO, "[" + this.getClass().getName() + "] Data provider initialized !");
+       Platform.writeLog(LogLevel.INFO, "[" + this.getClass().getName() + "] Data provider initialized !");
     }
 
     @Override
@@ -61,10 +61,10 @@ public class CacheImpl implements Cache {
     public Object putJsonObject(String key, Object object) {
         // DEBUG OUTPUT
         if (object != null)
-            SubAgent.writeDebugLog(DEBUG_LEVEL,
+           Platform.writeDebugLog(DEBUG_LEVEL,
                     "[" + this.getClass().getName() + "] Storing object into cache , key : " + key + " JSON obj : " + object.getClass().getName());
         else {
-            SubAgent.writeDebugLog(DEBUG_LEVEL, "[" + this.getClass().getName() + "] Storing object into cache , key : " + key + " JSON obj : null");
+           Platform.writeDebugLog(DEBUG_LEVEL, "[" + this.getClass().getName() + "] Storing object into cache , key : " + key + " JSON obj : null");
         }
 
         if (!cache.containsKey(key)) {
@@ -82,14 +82,14 @@ public class CacheImpl implements Cache {
     public Object getJsonObject(String key) {
         StorableItem store = (StorableItem) cache.get(key);
         if (store == null) {
-            SubAgent.writeDebugLog(DEBUG_LEVEL, "[" + this.getClass().getName() + "] Getting object from cache, key : " + key + " JSON obj : null");
+           Platform.writeDebugLog(DEBUG_LEVEL, "[" + this.getClass().getName() + "] Getting object from cache, key : " + key + " JSON obj : null");
             return null;
         }
         if (store.getJsonObject() == null) {
-            SubAgent.writeDebugLog(DEBUG_LEVEL, "[" + this.getClass().getName() + "] Getting object from cache, key : " + key + " JSON obj : null");
+           Platform.writeDebugLog(DEBUG_LEVEL, "[" + this.getClass().getName() + "] Getting object from cache, key : " + key + " JSON obj : null");
             return null;
         }
-        SubAgent.writeDebugLog(DEBUG_LEVEL,
+        Platform.writeDebugLog(DEBUG_LEVEL,
                 "[" + this.getClass().getName() + "] Getting object from cache, key : " + key + " JSON obj : " + store.getJsonObject().getClass()
                         .getName());
         return store.getJsonObject();
index abbd1e2..d1eca72 100644 (file)
@@ -1,9 +1,9 @@
 package com.rfelements.config;
 
+import org.netxms.bridge.Config;
 import com.rfelements.Protocol;
 import com.rfelements.exception.CollectorException;
 import com.rfelements.model.DeviceCredentials;
-import org.netxms.agent.Config;
 
 /**
  * @author Pichanič Ján
index 8993c73..26651ae 100644 (file)
@@ -1,12 +1,12 @@
 package com.rfelements.config;
 
+import org.netxms.bridge.Config;
 import com.rfelements.Logger;
 import com.rfelements.Protocol;
 import com.rfelements.cache.Cache;
 import com.rfelements.cache.CacheImpl;
 import com.rfelements.exception.CollectorException;
 import com.rfelements.model.DeviceCredentials;
-import org.netxms.agent.Config;
 
 /**
  * @author Pichanič Ján
index ec91b72..d0e5a21 100644 (file)
@@ -1,11 +1,11 @@
 package com.rfelements.provider;
 
+import org.netxms.bridge.Config;
 import com.rfelements.DeviceType;
 import com.rfelements.Protocol;
 import com.rfelements.exception.CollectorException;
 import com.rfelements.model.json.ligowave.Ligowave;
 import com.rfelements.model.json.ubiquiti.Ubiquiti;
-import org.netxms.agent.Config;
 
 /**
  * @author Pichanič Ján
index a0799bd..40c19f1 100644 (file)
@@ -1,19 +1,20 @@
 package com.rfelements.provider;
 
+import org.netxms.bridge.Config;
+import org.netxms.bridge.LogLevel;
+import org.netxms.bridge.Platform;
 import com.rfelements.DeviceType;
 import com.rfelements.Protocol;
 import com.rfelements.cache.Cache;
 import com.rfelements.cache.CacheImpl;
-import com.rfelements.exception.CollectorException;
 import com.rfelements.config.ConfigReader;
 import com.rfelements.config.ConfigReaderImpl;
+import com.rfelements.exception.CollectorException;
 import com.rfelements.model.DeviceCredentials;
 import com.rfelements.model.json.ligowave.Ligowave;
 import com.rfelements.model.json.ubiquiti.Ubiquiti;
 import com.rfelements.workers.WorkersProvider;
 import com.rfelements.workers.WorkersProviderImpl;
-import org.netxms.agent.Config;
-import org.netxms.agent.SubAgent;
 
 /**
  * @author Pichanič Ján
@@ -38,7 +39,7 @@ public class DataProviderImpl implements DataProvider {
     private WorkersProvider workersProvider;
 
     private DataProviderImpl() {
-        SubAgent.writeLog(SubAgent.LogLevel.INFO, Thread.currentThread().getName() + " [DataProviderImpl] Data provider initialized ...");
+       Platform.writeLog(LogLevel.INFO, Thread.currentThread().getName() + " [DataProviderImpl] Data provider initialized ...");
         this.cache = CacheImpl.getInstance();
         this.workersProvider = WorkersProviderImpl.getInstance();
         this.configReader = ConfigReaderImpl.getInstance();
@@ -61,7 +62,7 @@ public class DataProviderImpl implements DataProvider {
         Ligowave ligowave = (Ligowave) cache.getJsonObject(deviceCredentials.getIp());
         if (ligowave == null) {
             String message = "Value of ligowave JSON object in the cache, under key : " + ip + " , is NULL !";
-            SubAgent.writeDebugLog(DEBUG_LEVEL, message);
+            Platform.writeDebugLog(DEBUG_LEVEL, message);
             throw new CollectorException(message);
         }
         return ligowave;
@@ -74,7 +75,7 @@ public class DataProviderImpl implements DataProvider {
         Ubiquiti ubnt = (Ubiquiti) cache.getJsonObject(deviceCredentials.getIp());
         if (ubnt == null) {
             String message = "Value of ubiquiti JSON object in the cache, under key : " + ip + " , is NULL !";
-            SubAgent.writeDebugLog(DEBUG_LEVEL, message);
+            Platform.writeDebugLog(DEBUG_LEVEL, message);
             throw new CollectorException(message);
         }
         return ubnt;
index fbe4ea2..adeda72 100644 (file)
@@ -1,14 +1,11 @@
 package com.rfelements.rest;
 
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.rfelements.config.Settings;
-import com.rfelements.exception.CollectorException;
-import com.rfelements.gson.BooleanTypeAdapter;
-import com.rfelements.gson.StringTypeAdapter;
-import com.rfelements.model.DeviceCredentials;
-import com.rfelements.model.json.ligowave.Ligowave;
-import com.rfelements.model.json.ubiquiti.Ubiquiti;
+import java.io.IOException;
+import java.security.KeyStore;
+import java.util.Date;
+import java.util.concurrent.ConcurrentHashMap;
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.SSLSession;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.config.RequestConfig;
@@ -21,14 +18,17 @@ import org.apache.http.impl.client.BasicCookieStore;
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.ssl.SSLContextBuilder;
 import org.apache.http.util.EntityUtils;
-import org.netxms.agent.SubAgent;
-
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.SSLSession;
-import java.io.IOException;
-import java.security.KeyStore;
-import java.util.Date;
-import java.util.concurrent.ConcurrentHashMap;
+import org.netxms.bridge.LogLevel;
+import org.netxms.bridge.Platform;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.rfelements.config.Settings;
+import com.rfelements.exception.CollectorException;
+import com.rfelements.gson.BooleanTypeAdapter;
+import com.rfelements.gson.StringTypeAdapter;
+import com.rfelements.model.DeviceCredentials;
+import com.rfelements.model.json.ligowave.Ligowave;
+import com.rfelements.model.json.ubiquiti.Ubiquiti;
 
 /**
  * @author Pichanič Ján
@@ -58,7 +58,7 @@ public class Rest {
         BasicCookieStore cs;
         if (cookiesStoreCache.get(ip) == null) {
             cookiesStoreCache.put(ip, new BasicCookieStore());
-            SubAgent.writeDebugLog(DEBUG_LEVEL, Thread.currentThread().getName() +
+            Platform.writeDebugLog(DEBUG_LEVEL, Thread.currentThread().getName() +
                     " [" + Rest.class.getName() + "][initOrGetHttpClient] ip : " + ip + " , Cookie store initialization and storing into cache ... ");
         }
         cs = cookiesStoreCache.get(ip);
@@ -73,17 +73,17 @@ public class Rest {
                 }
             }).setSslcontext(ctx.build()).setDefaultCookieStore(cs).build();
         } catch (Exception e) {
-            SubAgent.writeLog(SubAgent.LogLevel.ERROR, e.getLocalizedMessage());
+           Platform.writeLog(LogLevel.ERROR, e.getLocalizedMessage());
             throw new CollectorException(e.getMessage(), e.getCause());
         }
-        SubAgent.writeDebugLog(DEBUG_LEVEL, Thread.currentThread().getName() + " [" + Rest.class.getName() + "][initOrGetHttpClient] ip : " + ip
+        Platform.writeDebugLog(DEBUG_LEVEL, Thread.currentThread().getName() + " [" + Rest.class.getName() + "][initOrGetHttpClient] ip : " + ip
                 + " , Http client is storing into cache , client hash code : " + client.hashCode());
         httpClientCache.put(ip, client);
         return client;
     }
 
     public static boolean loginUbiquiti(final DeviceCredentials deviceCredentials) throws CollectorException {
-        SubAgent.writeDebugLog(DEBUG_LEVEL, Thread.currentThread().getName() +
+       Platform.writeDebugLog(DEBUG_LEVEL, Thread.currentThread().getName() +
                 " [" + Rest.class.getName() + "] [loginUbiquiti] Performing login against (ubiquiti) " + deviceCredentials.getUrl());
         HttpClient client = initOrGetHttpClient(deviceCredentials.getIp());
 
@@ -97,17 +97,17 @@ public class Rest {
             if (200 == response.getStatusLine().getStatusCode() || 302 == response.getStatusLine().getStatusCode()) {
                 String responseStr = EntityUtils.toString(response.getEntity());
                 if (responseStr.contains("Invalid credentials.")) {
-                    SubAgent.writeDebugLog(DEBUG_LEVEL, Thread.currentThread().getName() +
+                   Platform.writeDebugLog(DEBUG_LEVEL, Thread.currentThread().getName() +
                             " [" + Rest.class.getName() + "][loginUbiquiti] ip : " + deviceCredentials.getIp() + " , Failed to login. Invalid credentials");
                     return false;
                 }
-                SubAgent.writeDebugLog(DEBUG_LEVEL_DETAILED,
+                Platform.writeDebugLog(DEBUG_LEVEL_DETAILED,
                         Thread.currentThread().getName() + " [" + Rest.class.getName() + "][loginUbiquiti][Ubiquiti] ip : " + deviceCredentials.getIp()
                                 + " , Login has been successful !");
                 return true;
             }
         } catch (IOException e) {
-            SubAgent.writeLog(SubAgent.LogLevel.ERROR,
+            Platform.writeLog(LogLevel.ERROR,
                     "[" + Rest.class.getName() + "][loginUbiquiti] Login failed because of exception : " + e.getLocalizedMessage());
             throw new CollectorException(e.getMessage(), e.getCause());
         } finally {
@@ -118,7 +118,7 @@ public class Rest {
     }
 
     public static boolean loginLigowave(final DeviceCredentials deviceCredentials) throws CollectorException {
-        SubAgent.writeDebugLog(DEBUG_LEVEL,
+        Platform.writeDebugLog(DEBUG_LEVEL,
                 Thread.currentThread().getName() + " [" + Rest.class.getName() + "] [loginLigowave] Performing login against (ligowave): " + deviceCredentials.getUrl());
         HttpClient client = initOrGetHttpClient(deviceCredentials.getIp());
 
@@ -135,17 +135,17 @@ public class Rest {
             if (200 == response.getStatusLine().getStatusCode() || 302 == response.getStatusLine().getStatusCode()) {
                 String responseStr = EntityUtils.toString(response.getEntity());
                 if (!responseStr.equals("{\"message\":\"Incorrect username or password\",\"status\":false}")) {
-                    SubAgent.writeDebugLog(DEBUG_LEVEL, Thread.currentThread().getName() +
+                    Platform.writeDebugLog(DEBUG_LEVEL, Thread.currentThread().getName() +
                             " [" + Rest.class.getName() + "][loginLigowave] Login against : " + deviceCredentials.getUrl() + "/cgi-bin/main.cgi/login" + " has been successful");
                     return true;
                 } else {
-                    SubAgent.writeDebugLog(DEBUG_LEVEL_DETAILED, Thread.currentThread().getName() + " [" + Rest.class.getName()
+                    Platform.writeDebugLog(DEBUG_LEVEL_DETAILED, Thread.currentThread().getName() + " [" + Rest.class.getName()
                             + "][LogIn][Deliberant] Login error , incorrect username or password");
                     return false;
                 }
             }
         } catch (IOException e) {
-            SubAgent.writeLog(SubAgent.LogLevel.ERROR,
+            Platform.writeLog(LogLevel.ERROR,
                     "[" + Rest.class.getName() + "][loginLigowave] Login failed because of exception : " + e.getLocalizedMessage());
             throw new CollectorException(e.getMessage(), e.getCause());
         } finally {
@@ -156,7 +156,7 @@ public class Rest {
     }
 
     public static void getIndexSiteUbnt(DeviceCredentials deviceCredentials) throws CollectorException {
-        SubAgent.writeDebugLog(DEBUG_LEVEL,
+        Platform.writeDebugLog(DEBUG_LEVEL,
                 Thread.currentThread().getName() + " [" + Rest.class.getName() + "] [getIndexSiteUbnt] ip : " + deviceCredentials.getIp()
                         + " , DeviceCredentials to website to get cookies ... ");
         HttpClient client = initOrGetHttpClient(deviceCredentials.getIp());
@@ -166,7 +166,7 @@ public class Rest {
             response = client.execute(get);
             EntityUtils.consumeQuietly(response.getEntity());
         } catch (IOException e) {
-            SubAgent.writeLog(SubAgent.LogLevel.ERROR,
+            Platform.writeLog(LogLevel.ERROR,
                     " [" + Rest.class.getName() + "] [getIndexSiteUbnt] Exception occurred while executing http get, message : " + e
                             .getLocalizedMessage());
             throw new CollectorException(e.getMessage(), e.getCause());
@@ -187,7 +187,7 @@ public class Rest {
     }
 
     public static Ubiquiti updateUbiquitiJsonObject(DeviceCredentials deviceCredentials, int loginTries) throws CollectorException {
-        SubAgent.writeDebugLog(DEBUG_LEVEL,
+        Platform.writeDebugLog(DEBUG_LEVEL,
                 Thread.currentThread().getName() + " [" + Rest.class.getName() + "] [updateUbiquitiJsonObject] ip : " + deviceCredentials.getIp()
                         + " , Ubiquiti json object update started ...");
         HttpClient client = initOrGetHttpClient(deviceCredentials.getIp());
@@ -201,7 +201,7 @@ public class Rest {
         String responseStr = null;
         try {
             response = client.execute(get);
-            SubAgent.writeDebugLog(DEBUG_LEVEL,
+            Platform.writeDebugLog(DEBUG_LEVEL,
                     Thread.currentThread().getName() + " [" + Rest.class.getName() + "] [updateUbiquitiJsonObject] ip : " + deviceCredentials.getIp()
                             + " Update UBNT obj response code : " + response.getStatusLine().getStatusCode());
             responseStr = EntityUtils.toString(response.getEntity());
@@ -212,11 +212,11 @@ public class Rest {
                 loginUbiquiti(deviceCredentials);
                 return updateUbiquitiJsonObject(deviceCredentials, --loginTries);
             }
-            SubAgent.writeDebugLog(DEBUG_LEVEL_DETAILED,
+            Platform.writeDebugLog(DEBUG_LEVEL_DETAILED,
                     Thread.currentThread().getName() + " [" + Rest.class.getName() + "] [updateUbiquitiJsonObject] ip : " + deviceCredentials.getIp()
                             + " , response text : " + responseStr);
         } catch (IOException e) {
-            SubAgent.writeLog(SubAgent.LogLevel.ERROR,
+            Platform.writeLog(LogLevel.ERROR,
                     Thread.currentThread().getName() + " [" + Rest.class.getName() + "] [updateUbiquitiJsonObject] " + e.getLocalizedMessage());
             throw new CollectorException(e.getMessage(), e.getCause());
         } finally {
@@ -229,7 +229,7 @@ public class Rest {
         try {
             ubnt = gson.fromJson(responseStr, Ubiquiti.class);
         } catch (Exception e) {
-            SubAgent.writeLog(SubAgent.LogLevel.ERROR,
+            Platform.writeLog(LogLevel.ERROR,
                     Thread.currentThread().getName() + " [" + Rest.class.getName() + "] [updateUbiquitiJsonObject] " + e.getLocalizedMessage());
             throw new CollectorException(e.getMessage(), e.getCause());
         }
@@ -237,7 +237,7 @@ public class Rest {
     }
 
     public static Ligowave updateLigowaveJsonObject(DeviceCredentials deviceCredentials, int loginTries) throws CollectorException {
-        SubAgent.writeDebugLog(DEBUG_LEVEL,
+        Platform.writeDebugLog(DEBUG_LEVEL,
                 Thread.currentThread().getName() + " [" + Rest.class.getName() + "] [updateLigowaveJsonObject] ip : " + deviceCredentials.getIp()
                         + " , Ligowave json object update started ...");
         HttpClient client = initOrGetHttpClient(deviceCredentials.getIp());
@@ -247,7 +247,7 @@ public class Rest {
         String responseStr = null;
         try {
             response = client.execute(get);
-            SubAgent.writeDebugLog(DEBUG_LEVEL,
+            Platform.writeDebugLog(DEBUG_LEVEL,
                     Thread.currentThread().getName() + " [" + Rest.class.getName() + "] [updateLigowaveJsonObject] ip : " + deviceCredentials.getIp()
                             + " Update ligowave obj response code : " + response.getStatusLine().getStatusCode());
             if (response.getStatusLine().getStatusCode() != 200) {
@@ -258,11 +258,11 @@ public class Rest {
                 return updateLigowaveJsonObject(deviceCredentials, --loginTries);
             }
             responseStr = EntityUtils.toString(response.getEntity());
-            SubAgent.writeDebugLog(DEBUG_LEVEL_DETAILED,
+            Platform.writeDebugLog(DEBUG_LEVEL_DETAILED,
                     Thread.currentThread().getName() + " [" + Rest.class.getName() + "] [updateLigowaveJsonObject] ip : " + deviceCredentials.getIp()
                             + " , response text : " + responseStr);
         } catch (IOException e) {
-            SubAgent.writeLog(SubAgent.LogLevel.ERROR,
+            Platform.writeLog(LogLevel.ERROR,
                     Thread.currentThread().getName() + " [" + Rest.class.getName() + "] [updateLigowaveJsonObject] " + e.getLocalizedMessage());
             e.printStackTrace();
         } finally {
@@ -275,7 +275,7 @@ public class Rest {
         try {
             ligowave = gson.fromJson(responseStr, Ligowave.class);
         } catch (Exception e) {
-            SubAgent.writeLog(SubAgent.LogLevel.ERROR, " [" + Rest.class.getName() + "] [updateLigowaveJsonObject] " + e.getLocalizedMessage());
+            Platform.writeLog(LogLevel.ERROR, " [" + Rest.class.getName() + "] [updateLigowaveJsonObject] " + e.getLocalizedMessage());
             throw new CollectorException(e.getMessage(), e.getCause());
         }
         return ligowave;
index f9d531e..aa504ef 100644 (file)
@@ -1,5 +1,8 @@
 package com.rfelements.workers;
 
+import java.util.Timer;
+import java.util.TimerTask;
+import org.netxms.bridge.Platform;
 import com.rfelements.DeviceType;
 import com.rfelements.cache.Cache;
 import com.rfelements.cache.CacheImpl;
@@ -9,10 +12,6 @@ import com.rfelements.model.DeviceCredentials;
 import com.rfelements.model.json.ligowave.Ligowave;
 import com.rfelements.model.json.ubiquiti.Ubiquiti;
 import com.rfelements.rest.Rest;
-import org.netxms.agent.SubAgent;
-
-import java.util.Timer;
-import java.util.TimerTask;
 
 /**
  * @author Pichanič Ján
@@ -29,8 +28,8 @@ public class SingleWorker extends Timer {
         super(true);
         this.deviceCredentials = deviceCredentials;
         this.type = type;
-        SubAgent.writeDebugLog(3, Thread.currentThread().getName() + " [SingleWorker] Construction ...");
-        SubAgent.writeDebugLog(3,
+        Platform.writeDebugLog(3, Thread.currentThread().getName() + " [SingleWorker] Construction ...");
+        Platform.writeDebugLog(3,
                 Thread.currentThread().getName() + " [SingleWorker] Args - deviceCredentials : " + deviceCredentials.hashCode() + ", type : " + type.toString());
     }
 
@@ -39,7 +38,7 @@ public class SingleWorker extends Timer {
 
             @Override
             public void run() {
-                SubAgent.writeDebugLog(3, Thread.currentThread().getName() +
+                Platform.writeDebugLog(3, Thread.currentThread().getName() +
                         " [SingleWorker] Reschedule, EntryPoint : " + type.toString() + "  URL : " + deviceCredentials.getUrl() + " , deviceCredentials : " + deviceCredentials.hashCode());
                 switch (type) {
                     case LIGOWAVE_AP:
@@ -62,7 +61,7 @@ public class SingleWorker extends Timer {
     }
 
     private void updateUbiquiti() {
-        SubAgent.writeDebugLog(3, Thread.currentThread().getName() +
+        Platform.writeDebugLog(3, Thread.currentThread().getName() +
                 " [SingleWorker] Calling update ! EntryPoint :" + type.toString() + " URL : " + deviceCredentials.getUrl() + " , deviceCredentials : "
                 + deviceCredentials.hashCode());
         try {
@@ -71,21 +70,21 @@ public class SingleWorker extends Timer {
 
             // DEBUG OUTPUT
             if (ubnt == null)
-                SubAgent.writeDebugLog(3, Thread.currentThread().getName() +
+                Platform.writeDebugLog(3, Thread.currentThread().getName() +
                         " [SingleWorker] JSON object updated ! EntryPoint :" + type.toString() + " URL : " + deviceCredentials.getUrl() + " JSON obj : null");
             else
-                SubAgent.writeDebugLog(3, Thread.currentThread().getName() +
+                Platform.writeDebugLog(3, Thread.currentThread().getName() +
                         " [SingleWorker] JSON object updated ! EntryPoint :" + type.toString() + " URL : " + deviceCredentials.getUrl() + " JSON obj : " + ubnt.getClass().getName());
         } catch (CollectorException e) {
-            SubAgent.writeDebugLog(3, e.getLocalizedMessage());
+            Platform.writeDebugLog(3, e.getLocalizedMessage());
             cache.putJsonObject(deviceCredentials.getIp(), null);
-            SubAgent.writeDebugLog(3, Thread.currentThread().getName() +
+            Platform.writeDebugLog(3, Thread.currentThread().getName() +
                     " [SingleWorker] JSON object updated as NULL ! EntryPoint :" + type.toString() + " URL : " + deviceCredentials.getUrl());
         }
     }
 
     private void updateLigowave() {
-        SubAgent.writeDebugLog(3, Thread.currentThread().getName() +
+        Platform.writeDebugLog(3, Thread.currentThread().getName() +
                 " [SingleWorker] Calling update ! EntryPoint :" + type.toString() + " URL : " + deviceCredentials.getUrl() + " , deviceCredentials : "
                 + deviceCredentials.hashCode());
         try {
@@ -94,17 +93,17 @@ public class SingleWorker extends Timer {
 
             // DEBUG OUTPUT
             if (ligowave == null)
-                SubAgent.writeDebugLog(3, Thread.currentThread().getName() +
+                Platform.writeDebugLog(3, Thread.currentThread().getName() +
                         " [SingleWorker] JSON object updated ! EntryPoint :" + type.toString() + " URL : " + deviceCredentials.getUrl()
                         + " JSON obj : null");
             else
-                SubAgent.writeDebugLog(3, Thread.currentThread().getName() +
+                Platform.writeDebugLog(3, Thread.currentThread().getName() +
                         " [SingleWorker] JSON object updated ! EntryPoint :" + type.toString() + " URL : " + deviceCredentials.getUrl()
                         + " JSON obj : " + ligowave.getClass().getName());
         } catch (CollectorException e) {
-            SubAgent.writeDebugLog(3, e.getLocalizedMessage());
+            Platform.writeDebugLog(3, e.getLocalizedMessage());
             cache.putJsonObject(deviceCredentials.getIp(), null);
-            SubAgent.writeDebugLog(3, Thread.currentThread().getName() +
+            Platform.writeDebugLog(3, Thread.currentThread().getName() +
                     " [SingleWorker] JSON object updated as NULL ! EntryPoint :" + type.toString() + " URL : " + deviceCredentials.getUrl());
         }
     }
index 6ca3601..b8561b7 100644 (file)
@@ -1,10 +1,10 @@
 package com.rfelements.workers;
 
+import java.util.HashMap;
+import org.netxms.bridge.LogLevel;
+import org.netxms.bridge.Platform;
 import com.rfelements.DeviceType;
 import com.rfelements.model.DeviceCredentials;
-import org.netxms.agent.SubAgent;
-
-import java.util.HashMap;
 
 /**
  * @author Pichanič Ján
@@ -24,7 +24,7 @@ public class WorkersProviderImpl implements WorkersProvider {
     private HashMap<DeviceType, HashMap<String, SingleWorker>> workers;
 
     private WorkersProviderImpl() {
-        SubAgent.writeLog(SubAgent.LogLevel.INFO,
+        Platform.writeLog(LogLevel.INFO,
                 Thread.currentThread().getName() + " [" + this.getClass().getName() + "] Workers provider initialized !");
         this.workers = new HashMap<>();
     }
@@ -33,7 +33,7 @@ public class WorkersProviderImpl implements WorkersProvider {
     public void startNewWorker(DeviceCredentials deviceCredentials, DeviceType type) {
         if (!workers.containsKey(type)) {
             SingleWorker worker = new SingleWorker(deviceCredentials, type);
-            SubAgent.writeDebugLog(DEBUG_LEVEL, Thread.currentThread().getName() +
+            Platform.writeDebugLog(DEBUG_LEVEL, Thread.currentThread().getName() +
                     " [" + this.getClass().getName() + "] Single worker created ! EntryPoint : " + type.toString() + "  URL : " + deviceCredentials.getUrl());
             HashMap<String, SingleWorker> hashMap = new HashMap<>();
             hashMap.put(deviceCredentials.getIp(), worker);
@@ -43,7 +43,7 @@ public class WorkersProviderImpl implements WorkersProvider {
             HashMap<String, SingleWorker> list = workers.get(type);
             if (!list.containsKey(deviceCredentials.getIp())) {
                 SingleWorker worker = new SingleWorker(deviceCredentials, type);
-                SubAgent.writeDebugLog(DEBUG_LEVEL, Thread.currentThread().getName() +
+                Platform.writeDebugLog(DEBUG_LEVEL, Thread.currentThread().getName() +
                         " [" + this.getClass().getName() + "] Single worker created ! EntryPoint : " + type.toString() + "  URL : " + deviceCredentials.getUrl());
                 list.put(deviceCredentials.getIp(), worker);
                 worker.start();
index 239fde5..21d9381 100644 (file)
@@ -5,7 +5,7 @@
                        <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
                        <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
-                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-473888658169189981" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1092834717854559371" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
                                <language-scope id="org.eclipse.cdt.core.gcc"/>
                                <language-scope id="org.eclipse.cdt.core.g++"/>
                        </provider>
index a746779..a604eb5 100644 (file)
@@ -4,6 +4,7 @@
        <comment></comment>
        <projects>
                <project>libnetxms</project>
+               <project>libnxjava</project>
        </projects>
        <buildSpec>
                <buildCommand>
index 5b23b81..baead2d 100644 (file)
@@ -5,7 +5,7 @@
                        <provider class="org.eclipse.cdt.core.language.settings.providers.LanguageSettingsGenericProvider" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider" name="CDT User Setting Entries" prefer-non-shared="true"/>
                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
                        <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
-                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-473888658169189981" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1092834717854559371" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
                                <language-scope id="org.eclipse.cdt.core.gcc"/>
                                <language-scope id="org.eclipse.cdt.core.g++"/>
                        </provider>
index e38001b..4a55bd4 100644 (file)
@@ -1,7 +1,7 @@
 bin_PROGRAMS = nxshell
 nxshell_SOURCES = nxshell.cpp
-nxshell_CPPFLAGS=-I@top_srcdir@/include
-nxshell_LDADD = ../../libnetxms/libnetxms.la
+nxshell_CPPFLAGS = -I@top_srcdir@/include
+nxshell_LDADD = @top_srcdir@/src/libnxjava/libnxjava.la @top_srcdir@/src/libnetxms/libnetxms.la
 
 EXTRA_DIST = Makefile.w32 nxshell.vcproj
 
index 3b34e28..41a2ee2 100644 (file)
@@ -2,7 +2,7 @@ TARGET = nxshell.exe
 TYPE = exe
 SOURCES = nxshell.cpp
 
-LIBS = libnetxms.lib
+LIBS = libnxjava.lib libnetxms.lib
 
 SUBDIRS = java
          
index da14fb5..788ed9d 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <nms_common.h>
 #include <nms_util.h>
-#include <jni.h>
+#include <nxjava.h>
 
 #if HAVE_GETOPT_H
 #include <getopt.h>
@@ -37,11 +37,6 @@ static const char *s_optJre = NULL;
 static const char *s_optClassPath = NULL;
 
 /**
- * Prototype for JNI_CreateJavaVM
- */
-typedef jint (JNICALL *T_JNI_CreateJavaVM)(JavaVM **, void **, void *);
-
-/**
  * Start application
  */
 static int StartApp(int argc, char *argv[])
@@ -66,127 +61,55 @@ static int StartApp(int argc, char *argv[])
    }
    nxlog_debug(1, _T("Using JRE: %s"), jre);
 
-   TCHAR errorText[256];
-   HMODULE jvmModule = DLOpen(jre, errorText);
-   if (jvmModule == NULL)
-   {
-      _tprintf(_T("Unable to load JVM: %s\n"), errorText);
-      return 3;
-   }
-
-   TCHAR libdir[MAX_PATH];
-   GetNetXMSDirectory(nxDirLib, libdir);
-
-   String classpath = _T("-Djava.class.path=");
-   classpath.append(libdir);
-   classpath.append(FS_PATH_SEPARATOR_CHAR);
-   classpath.append(_T("nxshell.jar"));
-   if (s_optClassPath != NULL)
-   {
-      classpath.append(JAVA_CLASSPATH_SEPARATOR);
-#ifdef UNICODE
-      WCHAR *cp = WideStringFromMBString(s_optClassPath);
-      classpath.append(cp);
-      free(cp);
-#else      
-      classpath.append(s_optClassPath);
-#endif      
-   }
-   nxlog_debug(5, _T("Using classpath \"%s\""), (const TCHAR *)classpath);
-
-   char server[256], port[256], login[256], password[256];
-   snprintf(server, 256, "-Dnetxms.server=%s", s_optHost);
-   snprintf(port, 256, "-Dnetxms.port=%s", s_optPort);
-   snprintf(login, 256, "-Dnetxms.login=%s", s_optUser);
+   StringList vmOptions;
+   char buffer[256];
+   snprintf(buffer, 256, "-Dnetxms.server=%s", s_optHost);
+   vmOptions.addMBString(buffer);
+   snprintf(buffer, 256, "-Dnetxms.port=%s", s_optPort);
+   vmOptions.addMBString(buffer);
+   snprintf(buffer, 256, "-Dnetxms.login=%s", s_optUser);
+   vmOptions.addMBString(buffer);
 
    char clearPassword[128];
    DecryptPasswordA(s_optUser, s_optPassword, clearPassword, 128);
-   snprintf(password, 256, "-Dnetxms.password=%s", clearPassword);
-
-   JavaVMOption vmOptions[7];
-   memset(vmOptions, 0, sizeof(vmOptions));
-#ifdef UNICODE
-   vmOptions[0].optionString = classpath.getUTF8String();
-#else
-   vmOptions[0].optionString = strdup(classpath);
-#endif
-   vmOptions[1].optionString = server;
-   vmOptions[2].optionString = port;
-   vmOptions[3].optionString = login;
-   vmOptions[4].optionString = password;
+   if (clearPassword[0] != 0)
+   {
+      snprintf(buffer, 256, "-Dnetxms.password=%s", clearPassword);
+      vmOptions.addMBString(buffer);
+   }
 
    bool verboseVM = (nxlog_get_debug_level() > 0);
    if (verboseVM)
    {
-      vmOptions[5].optionString = strdup("-verbose:jni");
-      vmOptions[6].optionString = strdup("-verbose:class");
+      vmOptions.add(_T("-verbose:jni"));
+      vmOptions.add(_T("-verbose:class"));
    }
 
-   JavaVMInitArgs vmArgs;
-   vmArgs.version = JNI_VERSION_1_6;
-   vmArgs.options = vmOptions;
-   vmArgs.nOptions = verboseVM ? 7 : 5;
-   vmArgs.ignoreUnrecognized = JNI_TRUE;
+   int rc = 0;
 
-   int rc = 4;
-   T_JNI_CreateJavaVM CreateJavaVM = (T_JNI_CreateJavaVM)DLGetSymbolAddr(jvmModule, "JNI_CreateJavaVM", NULL);
-   if (CreateJavaVM != NULL)
+#ifdef UNICODE
+   TCHAR *cp = WideStringFromMBStringSysLocale(s_optClassPath);
+#else
+#define cp s_optClassPath
+#endif
+   JNIEnv *env;
+   JavaBridgeError err = CreateJavaVM(jre, _T("nxshell.jar"), cp, &vmOptions, &env);
+   if (err == NXJAVA_SUCCESS)
    {
-      nxlog_debug(6, _T("Creating JVM with options:"));
-      for(int i = 0; i < vmArgs.nOptions; i++)
-         nxlog_debug(6, _T("   %hs"), vmArgs.options[i].optionString);
-
-      JavaVM *jvm = NULL;
-      JNIEnv *jniEnv;
-      if (CreateJavaVM(&jvm, (void **)&jniEnv, &vmArgs) == JNI_OK)
+      nxlog_debug(5, _T("JVM created"));
+      err = StartJavaApplication(env, "org/netxms/Shell", argc, argv);
+      if (err != NXJAVA_SUCCESS)
       {
-         nxlog_debug(5, _T("JVM created"));
-         jclass shell = jniEnv->FindClass("org/netxms/Shell");
-         if (shell != NULL)
-         {
-            nxlog_debug(5, _T("Shell class found"));
-            jmethodID shellMain = jniEnv->GetStaticMethodID(shell, "main", "([Ljava/lang/String;)V");
-            if (shellMain != NULL)
-            {
-               nxlog_debug(5, _T("Shell main method found"));
-               jclass stringClass = jniEnv->FindClass("java/lang/String");
-               jobjectArray jargs = jniEnv->NewObjectArray(argc, stringClass, NULL);
-               for(int i = 0; i < argc; i++)
-               {
-                  jchar *tmp = (jchar *)UCS2StringFromMBString(argv[i]);
-                  jstring js = jniEnv->NewString(tmp, (jsize)ucs2_strlen((UCS2CHAR *)tmp));
-                  free(tmp);
-                  if (js != NULL)
-                  {
-                     jniEnv->SetObjectArrayElement(jargs, i, js);
-                     jniEnv->DeleteLocalRef(js);
-                  }
-               }
-               jniEnv->CallStaticVoidMethod(shell, shellMain, jargs);
-               rc = 0;
-            }
-            else
-            {
-               _tprintf(_T("Cannot find shell entry point\n"));
-            }
-         }
-         else
-         {
-            _tprintf(_T("Cannot find shell class\n"));
-         }
-         jvm->DestroyJavaVM();
-      }
-      else
-      {
-         _tprintf(_T("CreateJavaVM failed\n"));
+         _tprintf(_T("Cannot start Java application (%s)"), GetJavaBridgeErrorMessage(err));
+         rc = 4;
       }
+      DestroyJavaVM();
    }
    else
    {
-      _tprintf(_T("JNI_CreateJavaVM failed\n"));
+      _tprintf(_T("Unable to create Java VM (%s)\n"), GetJavaBridgeErrorMessage(err));
+      rc = 3;
    }
-
-   DLClose(jvmModule);
    return rc;
 }
 
index eb5155f..9d96e8a 100644 (file)
@@ -5,7 +5,7 @@
                        <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
                        <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
-                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-473888658169189981" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1092834717854559371" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
                                <language-scope id="org.eclipse.cdt.core.gcc"/>
                                <language-scope id="org.eclipse.cdt.core.g++"/>
                        </provider>
index 7298dc4..d5618bd 100644 (file)
@@ -1,7 +1,7 @@
 /* 
 ** NetXMS - Network Management System
 ** Utility Library
-** Copyright (C) 2003-2016 Victor Kirhenshtein
+** Copyright (C) 2003-2017 Victor Kirhenshtein
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU Lesser General Public License as published
@@ -47,6 +47,7 @@ static MUTEX m_mutexLogAccess = INVALID_MUTEX_HANDLE;
 static UINT32 s_flags = 0;
 static int s_debugLevel = 0;
 static DWORD s_debugMsg = 0;
+static DWORD s_genericMsg = 0;
 static int s_rotationMode = NXLOG_ROTATION_BY_SIZE;
 static UINT64 s_maxLogSize = 4096 * 1024;      // 4 MB
 static int s_logHistorySize = 4;               // Keep up 4 previous log files
@@ -350,7 +351,8 @@ static THREAD_RESULT THREAD_CALL BackgroundWriterThread(void *arg)
  * Initialize log
  */
 bool LIBNETXMS_EXPORTABLE nxlog_open(const TCHAR *logName, UINT32 flags,
-                                     const TCHAR *msgModule, unsigned int msgCount, const TCHAR **messages, DWORD debugMsg)
+                                     const TCHAR *msgModule, unsigned int msgCount, const TCHAR **messages,
+                                     DWORD debugMsg, DWORD genericMsg)
 {
        s_flags = flags & 0x7FFFFFFF;
 #ifdef _WIN32
@@ -360,6 +362,7 @@ bool LIBNETXMS_EXPORTABLE nxlog_open(const TCHAR *logName, UINT32 flags,
        m_messages = messages;
 #endif
        s_debugMsg = debugMsg;
+       s_genericMsg = genericMsg;
 
    if (s_flags & NXLOG_USE_SYSLOG)
    {
@@ -797,6 +800,19 @@ void LIBNETXMS_EXPORTABLE nxlog_write(DWORD msg, WORD wType, const char *format,
 }
 
 /**
+ * Write generic message to log (useful for warning and error messages generated within libraries)
+ */
+void LIBNETXMS_EXPORTABLE nxlog_write_generic(WORD type, const TCHAR *format, ...)
+{
+   va_list args;
+   va_start(args, format);
+   TCHAR msg[8192];
+   _vsntprintf(msg, 8192, format, args);
+   va_end(args);
+   nxlog_write(s_genericMsg, type, "s", msg);
+}
+
+/**
  * Write debug message
  */
 void LIBNETXMS_EXPORTABLE nxlog_debug(int level, const TCHAR *format, ...)
index 7516f65..a1a93b3 100644 (file)
@@ -2721,161 +2721,6 @@ void LIBNETXMS_EXPORTABLE GetNetXMSDirectory(nxDirectoryType type, TCHAR *dir)
 #endif
 }
 
-#ifndef _WIN32
-
-/**
- * Check potential JVM path
- */
-static bool CheckJvmPath(const char *base, const char *libdir, const char *arch, char *jvm, const TCHAR *description)
-{
-   static const char *jreType[] = { "server", "default", "j9vm", "classic", NULL };
-   
-   for(int i = 0; jreType[i] != NULL; i++)
-   {
-      snprintf(jvm, MAX_PATH, "%s%s/lib/%s/%s/libjvm.so", base, libdir, arch, jreType[i]);
-      nxlog_debug(7, _T("FindJavaRuntime: checking %hs (%s)"), jvm, description);
-      if (_access(jvm, 0) == 0)
-         return true;
-
-      snprintf(jvm, MAX_PATH, "%s%s/jre/lib/%s/%s/libjvm.so", base, libdir, arch, jreType[i]);
-      nxlog_debug(7, _T("FindJavaRuntime: checking %hs (%s)"), jvm, description);
-      if (_access(jvm, 0) == 0)
-         return true;
-   }
-
-   if (!strcmp(arch, "x86_64"))
-      return CheckJvmPath(base, libdir, "amd64", jvm, description);
-
-   if (!strcmp(arch, "i686"))
-      return CheckJvmPath(base, libdir, "i386", jvm, description);
-
-   return false;
-}
-
-#endif
-
-/**
- * Find Java runtime module. Search algorithm is following:
- * 1. Windows only - check for bundled JRE in bin\jre
- * 2. Check for bundled JRE in $NETXMS_HOME/bin/jre (Windows) or $NETXMS_HOME/lib/jre (non-Windows)
- * 3. Windows only - check JRE location in registry
- * 3. Check $JAVA_HOME
- * 4. Check $JAVA_HOME/jre
- * 5. Check JDK location specified at compile time
- *
- * @param buffer buffer for result
- * @param size buffer size in characters
- * @return buffer on success or NULL on failure
- */
-TCHAR LIBNETXMS_EXPORTABLE *FindJavaRuntime(TCHAR *buffer, size_t size)
-{
-#ifdef _WIN32
-   TCHAR path[MAX_PATH];
-   GetModuleFileName(NULL, path, MAX_PATH);
-   TCHAR *s = _tcsrchr(path, _T('\\'));
-   if (s != NULL)
-   {
-      s++;
-      _tcscpy(s, _T("jre\\bin\\server\\jvm.dll"));
-      nxlog_debug(7, _T("FindJavaRuntime: checking %s (executable path)"), path);
-      if (_taccess(path, 0) == 0)
-      {
-         nx_strncpy(buffer, path, size);
-         return buffer;
-      }
-   }
-#endif
-
-   char jvm[MAX_PATH] = "";
-
-#ifndef _WIN32
-   struct utsname un;
-   uname(&un);
-#endif
-
-   // Use NETXMS_HOME
-   const char *netxmsHome = getenv("NETXMS_HOME");
-   if ((netxmsHome != NULL) && (*netxmsHome != 0))
-   {
-#ifdef _WIN32
-      snprintf(jvm, MAX_PATH, "%s\\bin\\jre\\bin\\server\\jvm.dll", netxmsHome);
-      nxlog_debug(7, _T("FindJavaRuntime: checking %hs (NetXMS home)"), jvm);
-#else
-      CheckJvmPath(netxmsHome, "/lib", un.machine, jvm, _T("NetXMS home"));
-#endif
-   }
-
-#ifdef _WIN32
-   if ((jvm[0] == 0) || (_access(jvm, 0) != 0))
-   {
-      HKEY hKey;
-      if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\JavaSoft\\Java Runtime Environment"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
-      {
-         TCHAR currVersion[64];
-         DWORD size = sizeof(currVersion);
-         if (RegQueryValueEx(hKey, _T("CurrentVersion"), NULL, NULL, (BYTE *)currVersion, &size) == ERROR_SUCCESS)
-         {
-            HKEY hSubKey;
-            if (RegOpenKeyEx(hKey, currVersion, 0, KEY_QUERY_VALUE, &hSubKey) == ERROR_SUCCESS)
-            {
-               size = MAX_PATH - 20;
-               if (RegQueryValueExA(hSubKey, "JavaHome", NULL, NULL, (BYTE *)jvm, &size) == ERROR_SUCCESS)
-               {
-                  strcat(jvm, "\\bin\\server\\jvm.dll");
-                  nxlog_debug(7, _T("FindJavaRuntime: checking %hs (registry)"), jvm);
-               }
-               RegCloseKey(hSubKey);
-            }
-         }
-         RegCloseKey(hKey);
-      }
-   }
-#endif
-
-   // Check JAVA_HOME
-   if ((jvm[0] == 0) || (_access(jvm, 0) != 0))
-   {
-      const char *javaHome = getenv("JAVA_HOME");
-      if ((javaHome != NULL) && (*javaHome != 0))
-      {
-#ifdef _WIN32
-         snprintf(jvm, MAX_PATH, "%s\\bin\\server\\jvm.dll", javaHome);
-         nxlog_debug(7, _T("FindJavaRuntime: checking %hs (Java home)"), jvm);
-         if (_access(jvm, 0) != 0)
-         {
-            snprintf(jvm, MAX_PATH, "%s\\jre\\bin\\server\\jvm.dll", javaHome);
-            nxlog_debug(7, _T("FindJavaRuntime: checking %hs (Java home)"), jvm);
-         }
-#else
-         CheckJvmPath(javaHome, "", un.machine, jvm, _T("Java home"));
-#endif
-      }
-   }
-
-#ifdef JDK_LOCATION
-   if ((jvm[0] == 0) || (_access(jvm, 0) != 0))
-   {
-#ifdef _WIN32
-      snprintf(jvm, MAX_PATH, JDK_LOCATION "\\jre\\bin\\server\\jvm.dll");
-      nxlog_debug(7, _T("FindJavaRuntime: checking %hs (JDK defined at compile time)"), jvm);
-#else
-      CheckJvmPath(JDK_LOCATION, "", un.machine, jvm, _T("JDK defined at compile time"));
-#endif
-   }
-#endif
-
-   if ((jvm[0] == 0) || (_access(jvm, 0) != 0))
-      return NULL;
-
-#ifdef UNICODE
-   MultiByteToWideChar(CP_UTF8, 0, jvm, -1, buffer, (int)size);
-   buffer[size - 1] = 0;
-#else
-   nx_strncpy(buffer, jvm, size);
-#endif
-   return buffer;
-}
-
 #if WITH_JEMALLOC
 
 /**
diff --git a/src/libnxjava/.cproject b/src/libnxjava/.cproject
new file mode 100644 (file)
index 0000000..242ebbc
--- /dev/null
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
+       <storageModule moduleId="org.eclipse.cdt.core.settings">
+               <cconfiguration id="cdt.managedbuild.toolchain.gnu.base.21451686">
+                       <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.base.21451686" moduleId="org.eclipse.cdt.core.settings" name="Default">
+                               <externalSettings/>
+                               <extensions>
+                                       <extension id="org.eclipse.cdt.core.GNU_ELF" point="org.eclipse.cdt.core.BinaryParser"/>
+                                       <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                               </extensions>
+                       </storageModule>
+                       <storageModule moduleId="cdtBuildSystem" version="4.0.0">
+                               <configuration artifactName="${ProjName}" buildProperties="" description="" id="cdt.managedbuild.toolchain.gnu.base.21451686" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
+                                       <folderInfo id="cdt.managedbuild.toolchain.gnu.base.21451686.887567904" name="/" resourcePath="">
+                                               <toolChain id="cdt.managedbuild.toolchain.gnu.base.365456671" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.base">
+                                                       <targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.GNU_ELF" id="cdt.managedbuild.target.gnu.platform.base.371644023" name="Debug Platform" osList="linux,hpux,aix,qnx" superClass="cdt.managedbuild.target.gnu.platform.base"/>
+                                                       <builder id="cdt.managedbuild.target.gnu.builder.base.2100665497" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.base"/>
+                                                       <tool id="cdt.managedbuild.tool.gnu.archiver.base.271362597" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
+                                                       <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.base.1252612202" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base">
+                                                               <option id="gnu.cpp.compiler.option.include.paths.1301826592" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
+                                                                       <listOptionValue builtIn="false" value="&quot;${NETXMS_BASE}&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${NETXMS_BASE}/include&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${JAVA_HOME}/include&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${JAVA_HOME}/include/linux&quot;"/>
+                                                               </option>
+                                                               <option id="gnu.cpp.compiler.option.preprocessor.def.733703372" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def" useByScannerDiscovery="false" valueType="definedSymbols">
+                                                                       <listOptionValue builtIn="false" value="_THREAD_SAFE"/>
+                                                                       <listOptionValue builtIn="false" value="TRE_WCHAR=1"/>
+                                                                       <listOptionValue builtIn="false" value="UNICODE"/>
+                                                                       <listOptionValue builtIn="false" value="_GNU_SOURCE"/>
+                                                               </option>
+                                                               <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1175142316" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
+                                                       </tool>
+                                                       <tool id="cdt.managedbuild.tool.gnu.c.compiler.base.831632913" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base">
+                                                               <option id="gnu.c.compiler.option.include.paths.993392294" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
+                                                                       <listOptionValue builtIn="false" value="&quot;${NETXMS_BASE}&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${NETXMS_BASE}/include&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${JAVA_HOME}/include&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${JAVA_HOME}/include/linux&quot;"/>
+                                                               </option>
+                                                               <option id="gnu.c.compiler.option.preprocessor.def.symbols.1760079207" name="Defined symbols (-D)" superClass="gnu.c.compiler.option.preprocessor.def.symbols" useByScannerDiscovery="false" valueType="definedSymbols">
+                                                                       <listOptionValue builtIn="false" value="_THREAD_SAFE"/>
+                                                                       <listOptionValue builtIn="false" value="TRE_WCHAR=1"/>
+                                                                       <listOptionValue builtIn="false" value="UNICODE"/>
+                                                                       <listOptionValue builtIn="false" value="_GNU_SOURCE"/>
+                                                               </option>
+                                                               <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.759271805" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
+                                                       </tool>
+                                                       <tool id="cdt.managedbuild.tool.gnu.c.linker.base.1079976720" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base"/>
+                                                       <tool id="cdt.managedbuild.tool.gnu.cpp.linker.base.2124233174" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base">
+                                                               <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.566901557" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
+                                                                       <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
+                                                                       <additionalInput kind="additionalinput" paths="$(LIBS)"/>
+                                                               </inputType>
+                                                       </tool>
+                                                       <tool id="cdt.managedbuild.tool.gnu.assembler.base.195363115" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base">
+                                                               <option id="gnu.both.asm.option.include.paths.103860337" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths" valueType="includePath">
+                                                                       <listOptionValue builtIn="false" value="&quot;${NETXMS_BASE}&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${NETXMS_BASE}/include&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${JAVA_HOME}/include&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${JAVA_HOME}/include/linux&quot;"/>
+                                                               </option>
+                                                               <inputType id="cdt.managedbuild.tool.gnu.assembler.input.1202020493" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
+                                                       </tool>
+                                               </toolChain>
+                                       </folderInfo>
+                               </configuration>
+                       </storageModule>
+                       <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
+               </cconfiguration>
+       </storageModule>
+       <storageModule moduleId="cdtBuildSystem" version="4.0.0">
+               <project id="libnxjava.null.1677207239" name="libnxjava"/>
+       </storageModule>
+       <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
+       <storageModule moduleId="refreshScope" versionNumber="2">
+               <configuration configurationName="Default">
+                       <resource resourceType="PROJECT" workspacePath="/libnxjava"/>
+               </configuration>
+       </storageModule>
+       <storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
+       <storageModule moduleId="scannerConfiguration">
+               <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
+               <scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.base.21451686;cdt.managedbuild.toolchain.gnu.base.21451686.887567904;cdt.managedbuild.tool.gnu.c.compiler.base.831632913;cdt.managedbuild.tool.gnu.c.compiler.input.759271805">
+                       <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
+               </scannerConfigBuildInfo>
+               <scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.base.21451686;cdt.managedbuild.toolchain.gnu.base.21451686.887567904;cdt.managedbuild.tool.gnu.cpp.compiler.base.1252612202;cdt.managedbuild.tool.gnu.cpp.compiler.input.1175142316">
+                       <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
+               </scannerConfigBuildInfo>
+       </storageModule>
+</cproject>
similarity index 91%
copy from src/agent/subagents/java/.project
copy to src/libnxjava/.project
index 1e3db18..f11c53a 100644 (file)
@@ -1,10 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <projectDescription>
-       <name>java</name>
+       <name>libnxjava</name>
        <comment></comment>
        <projects>
                <project>libnetxms</project>
-               <project>libnxagent</project>
        </projects>
        <buildSpec>
                <buildCommand>
@@ -28,7 +27,7 @@
        </natures>
        <filteredResources>
                <filter>
-                       <id>1469027039876</id>
+                       <id>1500991860596</id>
                        <name></name>
                        <type>6</type>
                        <matcher>
@@ -37,7 +36,7 @@
                        </matcher>
                </filter>
                <filter>
-                       <id>1469027039884</id>
+                       <id>1500991860601</id>
                        <name></name>
                        <type>6</type>
                        <matcher>
@@ -46,7 +45,7 @@
                        </matcher>
                </filter>
                <filter>
-                       <id>1469027039889</id>
+                       <id>1500991860605</id>
                        <name></name>
                        <type>6</type>
                        <matcher>
@@ -1,11 +1,11 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <project>
-       <configuration id="cdt.managedbuild.toolchain.gnu.base.7991241" name="Default">
+       <configuration id="cdt.managedbuild.toolchain.gnu.base.21451686" name="Default">
                <extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
                        <provider class="org.eclipse.cdt.core.language.settings.providers.LanguageSettingsGenericProvider" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider" name="CDT User Setting Entries" prefer-non-shared="true"/>
                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
                        <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
-                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-473888658169189981" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1092834717854559371" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
                                <language-scope id="org.eclipse.cdt.core.gcc"/>
                                <language-scope id="org.eclipse.cdt.core.g++"/>
                        </provider>
diff --git a/src/libnxjava/Makefile.am b/src/libnxjava/Makefile.am
new file mode 100644 (file)
index 0000000..f1ad021
--- /dev/null
@@ -0,0 +1,13 @@
+lib_LTLIBRARIES = libnxjava.la
+
+libnxjava_la_SOURCES = config.cpp jre.cpp jvm.cpp main.cpp platform.cpp tools.cpp
+libnxjava_la_CPPFLAGS=-I@top_srcdir@/include
+libnxjava_la_LDFLAGS = -version-info $(NETXMS_LIBRARY_VERSION)
+libnxjava_la_LIBADD = @top_srcdir@/src/libnetxms/libnetxms.la
+
+EXTRA_DIST = \
+       Makefile.w32 \
+       libnxjava.vcproj \
+       libnxjava.h
+
+SUBDIRS = java
similarity index 86%
rename from src/agent/subagents/java/ConfigHelper.cpp
rename to src/libnxjava/config.cpp
index dc26ab4..381d72f 100644 (file)
@@ -1,7 +1,7 @@
 /* 
- ** Java-Bridge NetXMS subagent
+ ** NetXMS Java Bridge
  ** Copyright (c) 2013 TEMPEST a.s.
- ** Copyright (c) 2015 Raden Solutions SIA
+ ** Copyright (c) 2015-2017 Raden Solutions SIA
  **
  ** This program is free software; you can redistribute it and/or modify
  ** it under the terms of the GNU General Public License as published by
  ** along with this program; if not, write to the Free Software
  ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  **
- ** File: ConfigHelper.cpp
+ ** File: config.cpp
  **
  **/
 
-#include "java_subagent.h"
+#include "libnxjava.h"
 
 /**
  * Java class names
  */
-static const char *s_configClassName = "org/netxms/agent/Config";
-static const char *s_configEntryClassName = "org/netxms/agent/ConfigEntry";
+static const char *s_configClassName = "org/netxms/bridge/Config";
+static const char *s_configEntryClassName = "org/netxms/bridge/ConfigEntry";
 
 /**
  * Global class references
@@ -45,13 +45,13 @@ static Config *RetrieveConfigNativePointer(JNIEnv *env, jobject obj)
    jclass objClass = env->GetObjectClass(obj);
    if (objClass == NULL)
    {
-      AgentWriteLog(NXLOG_ERROR, _T("ConfigHelper: Could not access to the class Config"));
+      nxlog_write_generic(NXLOG_ERROR, _T("JavaBridge: Could not access to the class Config"));
       return NULL;
    }
    jfieldID nativePointerFieldId = env->GetFieldID(objClass, "configHandle", "J");
    if (nativePointerFieldId == NULL)
    {
-      AgentWriteLog(NXLOG_ERROR, _T("ConfigHelper: Could not access to the field Config.configHandle"));
+      nxlog_write_generic(NXLOG_ERROR, _T("JavaBridge: Could not access to the field Config.configHandle"));
       return NULL;
    }
    jlong result = env->GetLongField(obj, nativePointerFieldId);
@@ -66,13 +66,13 @@ static ConfigEntry *RetrieveConfigEntryNativePointer(JNIEnv *env, jobject obj)
    jclass objClass = env->GetObjectClass(obj);
    if (objClass == NULL)
    {
-      AgentWriteLog(NXLOG_ERROR, _T("ConfigHelper: Could not access to the class ConfigEntry"));
+      nxlog_write_generic(NXLOG_ERROR, _T("JavaBridge: Could not access to the class ConfigEntry"));
       return NULL;
    }
    jfieldID nativePointerFieldId = env->GetFieldID(objClass, "configEntryHandle", "J");
    if (nativePointerFieldId == NULL)
    {
-      AgentWriteLog(NXLOG_ERROR, _T("ConfigHelper: Could not access to the field ConfigEntry.configHandle"));
+      nxlog_write_generic(NXLOG_ERROR, _T("JavaBridge: Could not access to the field ConfigEntry.configHandle"));
       return NULL;
    }
    jlong result = env->GetLongField(obj, nativePointerFieldId);
@@ -90,14 +90,14 @@ static jobject CreateConfigEntryInstance(JNIEnv *curEnv, ConfigEntry *configEntr
    jobject localInstance = curEnv->NewObject(s_configEntryClass, s_configEntryConstructor, CAST_FROM_POINTER(configEntry, jlong));
    if (localInstance == NULL)
    {
-      AgentWriteLog(NXLOG_ERROR, _T("ConfigHelper: Could not instantiate object of class %hs"), s_configEntryClassName);
+      nxlog_write_generic(NXLOG_ERROR, _T("JavaBridge: Could not instantiate object of class %hs"), s_configEntryClassName);
       return NULL;
    }
 
    jobject instance = curEnv->NewGlobalRef(localInstance);
    if (instance == NULL)
    {
-      AgentWriteLog(NXLOG_ERROR, _T("ConfigHelper: Could not create a new global reference of %hs"), s_configEntryClassName);
+      nxlog_write_generic(NXLOG_ERROR, _T("JavaBridge: Could not create a new global reference of %hs"), s_configEntryClassName);
    }
 
    curEnv->DeleteLocalRef(localInstance);
@@ -155,7 +155,7 @@ JNIEXPORT void JNICALL Java_org_netxms_agent_Config_deleteEntry(JNIEnv *jenv, jo
 /**
  * Class:     org_netxms_agent_Config
  * Method:    getEntry
- * Signature: (Ljava/lang/String;)Lorg/netxms/agent/ConfigEntry;
+ * Signature: (Ljava/lang/String;)Lorg/netxms/bridge/ConfigEntry;
  */
 JNIEXPORT jobject JNICALL Java_org_netxms_agent_Config_getEntry(JNIEnv *jenv, jobject jobj, jstring jpath)
 {
@@ -181,7 +181,7 @@ JNIEXPORT jobject JNICALL Java_org_netxms_agent_Config_getEntry(JNIEnv *jenv, jo
 /*
  * Class:     org_netxms_agent_Config
  * Method:    getSubEntries
- * Signature: (Ljava/lang/String;Ljava/lang/String;)[Lorg/netxms/agent/ConfigEntry;
+ * Signature: (Ljava/lang/String;Ljava/lang/String;)[Lorg/netxms/bridge/ConfigEntry;
  */
 JNIEXPORT jobjectArray JNICALL Java_org_netxms_agent_Config_getSubEntries(JNIEnv *jenv, jobject jobj, jstring jpath, jstring jmask)
 {
@@ -219,7 +219,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_netxms_agent_Config_getSubEntries(JNIEnv
 /*
  * Class:     org_netxms_agent_Config
  * Method:    getOrderedSubEntries
- * Signature: (Ljava/lang/String;Ljava/lang/String;)[Lorg/netxms/agent/ConfigEntry;
+ * Signature: (Ljava/lang/String;Ljava/lang/String;)[Lorg/netxms/bridge/ConfigEntry;
  */
 JNIEXPORT jobjectArray JNICALL Java_org_netxms_agent_Config_getOrderedSubEntries(JNIEnv *jenv, jobject jobj, jstring jpath, jstring jmask)
 {
@@ -405,7 +405,7 @@ JNIEXPORT jboolean JNICALL Java_org_netxms_agent_Config_setValue__Ljava_lang_Str
 /*
  * Class:     org_netxms_agent_ConfigEntry
  * Method:    getNext
- * Signature: ()Lorg/netxms/agent/ConfigEntry;
+ * Signature: ()Lorg/netxms/bridge/ConfigEntry;
  */
 JNIEXPORT jobject JNICALL Java_org_netxms_agent_ConfigEntry_getNext(JNIEnv *jenv, jobject jobj)
 {
@@ -420,7 +420,7 @@ JNIEXPORT jobject JNICALL Java_org_netxms_agent_ConfigEntry_getNext(JNIEnv *jenv
 /*
  * Class:     org_netxms_agent_ConfigEntry
  * Method:    getParent
- * Signature: ()Lorg/netxms/agent/ConfigEntry;
+ * Signature: ()Lorg/netxms/bridge/ConfigEntry;
  */
 JNIEXPORT jobject JNICALL Java_org_netxms_agent_ConfigEntry_getParent(JNIEnv *jenv, jobject jobj)
 {
@@ -582,7 +582,7 @@ JNIEXPORT jstring JNICALL Java_org_netxms_agent_ConfigEntry_getFile(JNIEnv *jenv
 /*
  * Class:     org_netxms_agent_ConfigEntry
  * Method:    createEntry
- * Signature: (Ljava/lang/String;)Lorg/netxms/agent/ConfigEntry;
+ * Signature: (Ljava/lang/String;)Lorg/netxms/bridge/ConfigEntry;
  */
 JNIEXPORT jobject JNICALL Java_org_netxms_agent_ConfigEntry_createEntry(JNIEnv *jenv, jobject jobj, jstring jname)
 {
@@ -604,7 +604,7 @@ JNIEXPORT jobject JNICALL Java_org_netxms_agent_ConfigEntry_createEntry(JNIEnv *
 /*
  * Class:     org_netxms_agent_ConfigEntry
  * Method:    findEntry
- * Signature: (Ljava/lang/String;)Lorg/netxms/agent/ConfigEntry;
+ * Signature: (Ljava/lang/String;)Lorg/netxms/bridge/ConfigEntry;
  */
 JNIEXPORT jobject JNICALL Java_org_netxms_agent_ConfigEntry_findEntry(JNIEnv *jenv, jobject jobj, jstring jname)
 {
@@ -626,7 +626,7 @@ JNIEXPORT jobject JNICALL Java_org_netxms_agent_ConfigEntry_findEntry(JNIEnv *je
 /*
  * Class:     org_netxms_agent_ConfigEntry
  * Method:    getSubEntries
- * Signature: (Ljava/lang/String;)[Lorg/netxms/agent/ConfigEntry;
+ * Signature: (Ljava/lang/String;)[Lorg/netxms/bridge/ConfigEntry;
  */
 JNIEXPORT jobjectArray JNICALL Java_org_netxms_agent_ConfigEntry_getSubEntries(JNIEnv *jenv, jobject jobj, jstring jmask)
 {
@@ -662,7 +662,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_netxms_agent_ConfigEntry_getSubEntries(J
 /*
  * Class:     org_netxms_agent_ConfigEntry
  * Method:    getOrderedSubEntries
- * Signature: (Ljava/lang/String;)[Lorg/netxms/agent/ConfigEntry;
+ * Signature: (Ljava/lang/String;)[Lorg/netxms/bridge/ConfigEntry;
  */
 JNIEXPORT jobjectArray JNICALL Java_org_netxms_agent_ConfigEntry_getOrderedSubEntries(JNIEnv *jenv, jobject jobj, jstring jmask)
 {
@@ -698,7 +698,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_netxms_agent_ConfigEntry_getOrderedSubEn
 /*
  * Class:     org_netxms_agent_ConfigEntry
  * Method:    unlinkEntry
- * Signature: (Lorg/netxms/agent/ConfigEntry;)V
+ * Signature: (Lorg/netxms/bridge/ConfigEntry;)V
  */
 JNIEXPORT void JNICALL Java_org_netxms_agent_ConfigEntry_unlinkEntry(JNIEnv *jenv, jobject jobj, jobject jentry)
 {
@@ -873,9 +873,9 @@ static JNINativeMethod s_jniMethodsConfig[] =
    { (char *)"lock", (char *)"()V", (void *)Java_org_netxms_agent_Config_lock },
    { (char *)"unlock", (char *)"()V", (void *)Java_org_netxms_agent_Config_unlock },
    { (char *)"deleteEntry", (char *)"(Ljava/lang/String;)V", (void *) Java_org_netxms_agent_Config_deleteEntry },
-   { (char *)"getEntry", (char *)"(Ljava/lang/String;)Lorg/netxms/agent/ConfigEntry;", (void *) Java_org_netxms_agent_Config_getEntry },
-   { (char *)"getSubEntries", (char *)"(Ljava/lang/String;Ljava/lang/String;)[Lorg/netxms/agent/ConfigEntry;", (void *) Java_org_netxms_agent_Config_getSubEntries },
-   { (char *)"getOrderedSubEntries", (char *)"(Ljava/lang/String;Ljava/lang/String;)[Lorg/netxms/agent/ConfigEntry;", (void *) Java_org_netxms_agent_Config_getOrderedSubEntries },
+   { (char *)"getEntry", (char *)"(Ljava/lang/String;)Lorg/netxms/bridge/ConfigEntry;", (void *) Java_org_netxms_agent_Config_getEntry },
+   { (char *)"getSubEntries", (char *)"(Ljava/lang/String;Ljava/lang/String;)[Lorg/netxms/bridge/ConfigEntry;", (void *) Java_org_netxms_agent_Config_getSubEntries },
+   { (char *)"getOrderedSubEntries", (char *)"(Ljava/lang/String;Ljava/lang/String;)[Lorg/netxms/bridge/ConfigEntry;", (void *) Java_org_netxms_agent_Config_getOrderedSubEntries },
    { (char *)"getValue", (char *)"(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", (void *) Java_org_netxms_agent_Config_getValue },
    { (char *)"getValueInt", (char *)"(Ljava/lang/String;I)I", (void *) Java_org_netxms_agent_Config_getValueInt },
    { (char *)"getValueLong", (char *)"(Ljava/lang/String;J)J", (void *) Java_org_netxms_agent_Config_getValueLong },
@@ -891,8 +891,8 @@ static JNINativeMethod s_jniMethodsConfig[] =
  */
 static JNINativeMethod s_jniMethodsConfigEntry[] =
 {
-   { (char *)"getNext", (char *)"()Lorg/netxms/agent/ConfigEntry;", (void *)Java_org_netxms_agent_ConfigEntry_getNext },
-   { (char *)"getParent", (char *)"()Lorg/netxms/agent/ConfigEntry;", (void *)Java_org_netxms_agent_ConfigEntry_getParent },
+   { (char *)"getNext", (char *)"()Lorg/netxms/bridge/ConfigEntry;", (void *)Java_org_netxms_agent_ConfigEntry_getNext },
+   { (char *)"getParent", (char *)"()Lorg/netxms/bridge/ConfigEntry;", (void *)Java_org_netxms_agent_ConfigEntry_getParent },
    { (char *)"getName", (char *)"()Ljava/lang/String;", (void *)Java_org_netxms_agent_ConfigEntry_getName },
    { (char *)"setName", (char *)"(Ljava/lang/String;)V", (void *)Java_org_netxms_agent_ConfigEntry_setName },
    { (char *)"getId", (char *)"()I", (void *)Java_org_netxms_agent_ConfigEntry_getId },
@@ -901,11 +901,11 @@ static JNINativeMethod s_jniMethodsConfigEntry[] =
    { (char *)"addValue", (char *)"(Ljava/lang/String;)V", (void *) Java_org_netxms_agent_ConfigEntry_addValue },
    { (char *)"setValue", (char *)"(Ljava/lang/String;)V", (void *) Java_org_netxms_agent_ConfigEntry_setValue },
    { (char *)"getFile", (char *)"()Ljava/lang/String;", (void *) Java_org_netxms_agent_ConfigEntry_getFile },
-   { (char *)"createEntry", (char *)"(Ljava/lang/String;)Lorg/netxms/agent/ConfigEntry;", (void *) Java_org_netxms_agent_ConfigEntry_createEntry },
-   { (char *)"findEntry", (char *)"(Ljava/lang/String;)Lorg/netxms/agent/ConfigEntry;", (void *) Java_org_netxms_agent_ConfigEntry_findEntry },
-   { (char *)"getSubEntries", (char *)"(Ljava/lang/String;)[Lorg/netxms/agent/ConfigEntry;", (void *) Java_org_netxms_agent_ConfigEntry_getSubEntries },
-   { (char *)"getOrderedSubEntries", (char *)"(Ljava/lang/String;)[Lorg/netxms/agent/ConfigEntry;", (void *) Java_org_netxms_agent_ConfigEntry_getOrderedSubEntries },
-   { (char *)"unlinkEntry", (char *)"(Lorg/netxms/agent/ConfigEntry;)V", (void *) Java_org_netxms_agent_ConfigEntry_unlinkEntry },
+   { (char *)"createEntry", (char *)"(Ljava/lang/String;)Lorg/netxms/bridge/ConfigEntry;", (void *) Java_org_netxms_agent_ConfigEntry_createEntry },
+   { (char *)"findEntry", (char *)"(Ljava/lang/String;)Lorg/netxms/bridge/ConfigEntry;", (void *) Java_org_netxms_agent_ConfigEntry_findEntry },
+   { (char *)"getSubEntries", (char *)"(Ljava/lang/String;)[Lorg/netxms/bridge/ConfigEntry;", (void *) Java_org_netxms_agent_ConfigEntry_getSubEntries },
+   { (char *)"getOrderedSubEntries", (char *)"(Ljava/lang/String;)[Lorg/netxms/bridge/ConfigEntry;", (void *) Java_org_netxms_agent_ConfigEntry_getOrderedSubEntries },
+   { (char *)"unlinkEntry", (char *)"(Lorg/netxms/bridge/ConfigEntry;)V", (void *) Java_org_netxms_agent_ConfigEntry_unlinkEntry },
    { (char *)"getValue", (char *)"(I)Ljava/lang/String;", (void *) Java_org_netxms_agent_ConfigEntry_getValue__I },
    //    { "getValue", "(ILjava/lang/String;)Ljava/lang/String;", (void *) Java_org_netxms_agent_ConfigEntry_getValue__ILjava_lang_String_2 },
    { (char *)"getValueInt", (char *)"(II)I", (void *) Java_org_netxms_agent_ConfigEntry_getValueInt },
@@ -920,41 +920,41 @@ static JNINativeMethod s_jniMethodsConfigEntry[] =
 /**
  * Register native methods for Config related classes
  */
-bool RegisterConfigHelperNatives(JNIEnv *curEnv)
+bool RegisterConfigHelperNatives(JNIEnv *env)
 {
-   s_configClass = CreateClassGlobalRef(curEnv, s_configClassName);
+   s_configClass = CreateJavaClassGlobalRef(env, s_configClassName);
    if (s_configClass == NULL)
       return NULL;
 
-   s_configEntryClass = CreateClassGlobalRef(curEnv, s_configEntryClassName);
+   s_configEntryClass = CreateJavaClassGlobalRef(env, s_configEntryClassName);
    if (s_configEntryClass == NULL)
       return NULL;
 
-   s_configConstructor = curEnv->GetMethodID(s_configClass, "<init>", "(J)V");
+   s_configConstructor = env->GetMethodID(s_configClass, "<init>", "(J)V");
    if (s_configConstructor == NULL)
    {
-      AgentWriteLog(NXLOG_ERROR, _T("JAVA: Could not retrieve constructor for class %hs"), s_configClassName);
+      nxlog_write_generic(NXLOG_ERROR, _T("JavaBridge: Could not retrieve constructor for class %hs"), s_configClassName);
       return NULL;
    }
 
-   s_configEntryConstructor = curEnv->GetMethodID(s_configEntryClass, "<init>", "(J)V");
+   s_configEntryConstructor = env->GetMethodID(s_configEntryClass, "<init>", "(J)V");
    if (s_configEntryConstructor == NULL)
    {
-      AgentWriteLog(NXLOG_ERROR, _T("JAVA: Could not retrieve constructor for class %hs"), s_configEntryClass);
+      nxlog_write_generic(NXLOG_ERROR, _T("JavaBridge: Could not retrieve constructor for class %hs"), s_configEntryClass);
       return NULL;
    }
 
    // register native methods exposed by Config
-   if (curEnv->RegisterNatives(s_configClass, s_jniMethodsConfig, (jint)(sizeof(s_jniMethodsConfig) / sizeof (s_jniMethodsConfig[0]))) != 0)
+   if (env->RegisterNatives(s_configClass, s_jniMethodsConfig, (jint)(sizeof(s_jniMethodsConfig) / sizeof (s_jniMethodsConfig[0]))) != 0)
    {
-      AgentWriteLog(NXLOG_ERROR, _T("ConfigHelper: Failed to register native methods for %s"), s_configClassName);
+      nxlog_write_generic(NXLOG_ERROR, _T("JavaBridge: Failed to register native methods for %hs"), s_configClassName);
       return false;
    }
 
    // register native methods exposed by ConfigEntry
-   if (curEnv->RegisterNatives(s_configEntryClass, s_jniMethodsConfigEntry, (jint)(sizeof(s_jniMethodsConfigEntry) / sizeof(s_jniMethodsConfigEntry[0]))) != 0)
+   if (env->RegisterNatives(s_configEntryClass, s_jniMethodsConfigEntry, (jint)(sizeof(s_jniMethodsConfigEntry) / sizeof(s_jniMethodsConfigEntry[0]))) != 0)
    {
-      AgentWriteLog(NXLOG_ERROR, _T("JAVA: Failed to register native methods for %s"), s_configEntryClassName);
+      nxlog_write_generic(NXLOG_ERROR, _T("JavaBridge: Failed to register native methods for %hs"), s_configEntryClassName);
       return false;
    }
 
@@ -963,24 +963,28 @@ bool RegisterConfigHelperNatives(JNIEnv *curEnv)
 
 /**
  * Create Java Config object (wrapper around C++ Config class)
+ *
+ * @param env JNI environment for current thread
+ * @param config C++ Config object
+ * @return Java wrapper object or NULL on failure
  */
-jobject CreateConfigInstance(JNIEnv *curEnv, Config *config)
+jobject LIBNXJAVA_EXPORTABLE CreateConfigJavaInstance(JNIEnv *env, Config *config)
 {
-   if (s_configConstructor == NULL)
+   if ((env == NULL) || (s_configConstructor == NULL))
       return NULL;
 
-   jobject localInstance = curEnv->NewObject(s_configClass, s_configConstructor, CAST_FROM_POINTER(config, jlong));
+   jobject localInstance = env->NewObject(s_configClass, s_configConstructor, CAST_FROM_POINTER(config, jlong));
    if (localInstance == NULL)
    {
-      AgentWriteLog(NXLOG_ERROR, _T("JAVA: Could not instantiate object of class %s"), s_configClassName);
+      nxlog_write_generic(NXLOG_ERROR, _T("JavaBridge: Could not instantiate object of class %s"), s_configClassName);
       return NULL;
    }
 
-   jobject instance = curEnv->NewGlobalRef(localInstance);
+   jobject instance = env->NewGlobalRef(localInstance);
    if (instance == NULL)
    {
-      AgentWriteLog(NXLOG_ERROR, _T("JAVA: Could not create a new global reference of %s"), s_configClassName);
+      nxlog_write_generic(NXLOG_ERROR, _T("JavaBridge: Could not create a new global reference of %s"), s_configClassName);
    }
-   curEnv->DeleteLocalRef(localInstance);
+   env->DeleteLocalRef(localInstance);
    return instance;
 }
diff --git a/src/libnxjava/java/Makefile.am b/src/libnxjava/java/Makefile.am
new file mode 100644 (file)
index 0000000..2fe981e
--- /dev/null
@@ -0,0 +1,12 @@
+javalibdir = $(pkglibdir)
+javalib_DATA = netxms-java-bridge.jar
+
+netxms-java-bridge.jar: pom.xml
+       mvn clean
+       mvn install
+       mv target/netxms-java-bridge.jar .
+
+clean-local:
+       rm -rf netxms-java-bridge.jar
+
+EXTRA_DIST = Makefile.w32 pom.xml netxms-java-bridge.jar
diff --git a/src/libnxjava/java/Makefile.w32 b/src/libnxjava/java/Makefile.w32
new file mode 100644 (file)
index 0000000..7c5731d
--- /dev/null
@@ -0,0 +1,5 @@
+TARGET = netxms-java-bridge.jar
+TYPE = jar
+JAR_BUILD_MODE = install
+
+include ..\..\..\Makefile.inc.w32
similarity index 78%
copy from src/agent/subagents/java/java/pom.xml
copy to src/libnxjava/java/pom.xml
index eb1368c..83e8e4a 100644 (file)
@@ -2,10 +2,10 @@
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.netxms</groupId>
-  <artifactId>netxms-agent</artifactId>
+  <artifactId>netxms-java-bridge</artifactId>
   <packaging>jar</packaging>
-  <version>2.1</version>
-  <name>NetXMS Java Agent</name>
+  <version>2.1.1</version>
+  <name>NetXMS C++/Java Bridge</name>
   <url>http://www.netxms.org</url>
 
   <properties>
               </execution>
           </executions>
       </plugin>
+      <plugin>
+        <artifactId>maven-source-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>attach-sources</id>
+            <phase>verify</phase>
+            <goals>
+              <goal>jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
     </plugins>
   </build>
 
@@ -1,6 +1,7 @@
 /**
- * Java-Bridge NetXMS subagent
+ * NetXMS Java Bridge
  * Copyright (C) 2013 TEMPEST a.s.
+ * Copyright (C) 2014-2017 Raden Solutions
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -16,7 +17,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-package org.netxms.agent;
+package org.netxms.bridge;
 
 public final class Config
 {
@@ -1,6 +1,7 @@
 /**
- * Java-Bridge NetXMS subagent
+ * NetXMS Java Bridge
  * Copyright (C) 2013 TEMPEST a.s.
+ * Copyright (C) 2014-2017 Raden Solutions
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -16,7 +17,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-package org.netxms.agent;
+package org.netxms.bridge;
 
 public class ConfigEntry
 {
@@ -17,7 +17,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-package org.netxms.agent;
+package org.netxms.bridge;
 
 /**
  * NetXMS directory type
@@ -1,5 +1,5 @@
 /**
- * Java-Bridge NetXMS subagent
+ * NetXMS Java Bridge
  * Copyright (C) 2013 TEMPEST a.s.
  * Copyright (C) 2014-2017 Raden Solutions
  *
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-package org.netxms.agent;
+package org.netxms.bridge;
 
 /**
- * NetXMS directory type
+ * NeXMS log level
  */
-public enum DirectoryType
+public enum LogLevel
 {
-   BIN(0), DATA(1), ETC(2), LIB(3), SHARE(4); 
-   
+   INFO(0x0004), WARNING(0x0002), ERROR(0x0001);
+
    private int value;
 
-   DirectoryType(final int value)
+   LogLevel(final int value)
    {
       this.value = value;
    }
diff --git a/src/libnxjava/java/src/main/java/org/netxms/bridge/Platform.java b/src/libnxjava/java/src/main/java/org/netxms/bridge/Platform.java
new file mode 100644 (file)
index 0000000..5f0588f
--- /dev/null
@@ -0,0 +1,92 @@
+/**
+ * NetXMS Java Bridge
+ * Copyright (C) 2013 TEMPEST a.s.
+ * Copyright (C) 2014-2017 Raden Solutions
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.netxms.bridge;
+
+/**
+ * Platform utility class
+ */
+public final class Platform
+{
+   /**
+    * Get NetXMS directory (internal bridge to native code)
+    * 
+    * @param type directory type
+    * @return path to directory or empty string on error
+    */
+   protected static native String getNetXMSDirectoryInternal(int type);
+
+   /**
+    * Write log message using NetXMS logging facility
+    * 
+    * @param level log level
+    * @param message message
+    */
+   protected static native void writeLog(int level, String message);
+
+   /**
+    * Write debug log message using NetXMS loggin facility
+    * 
+    * @param level debug level (0-9)
+    * @param message message
+    */
+   public static native void writeDebugLog(int level, String message);
+
+   /**
+    * Wrapper for native writeLog call
+    * 
+    * @param level log level
+    * @param message message text
+    */
+   public static void writeLog(LogLevel level, String message)
+   {
+      writeLog(level.getValue(), message);
+   }
+
+   /**
+    * Write exception's stack trace to debug log
+    * 
+    * @param level log level
+    * @param prefix message prefix
+    * @param e exception to log
+    */
+   public static void writeDebugLog(int level, String prefix, Throwable e)
+   {
+      for(StackTraceElement s : e.getStackTrace())
+      {
+         writeDebugLog(level, prefix + s.toString());
+      }
+      if (e.getCause() != null)
+      {
+         writeDebugLog(level, prefix.trim() + " Caused by: " + e.getCause().getClass().getCanonicalName() + ": " + e.getCause().getMessage());
+         writeDebugLog(level, prefix, e.getCause());
+      }
+   }
+   
+   /**
+    * Get NetXMS directory
+    * 
+    * @param type directory type
+    * @return path to directory or empty string on error
+    */
+   public static String getNetXMSDirectory(DirectoryType type)
+   {
+      return getNetXMSDirectoryInternal(type.getValue());
+   }
+}
diff --git a/src/libnxjava/jre.cpp b/src/libnxjava/jre.cpp
new file mode 100644 (file)
index 0000000..df5230a
--- /dev/null
@@ -0,0 +1,181 @@
+/*
+** NetXMS - Network Management System
+** Copyright (C) 2003-2017 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU Lesser General Public License as published
+** by the Free Software Foundation; either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program 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 Lesser General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: jre.cpp
+**/
+
+#include "libnxjava.h"
+
+#if HAVE_SYS_UTSNAME_H
+#include <sys/utsname.h>
+#endif
+
+#ifndef _WIN32
+
+/**
+ * Check potential JVM path
+ */
+static bool CheckJvmPath(const char *base, const char *libdir, const char *arch, char *jvm, const TCHAR *description)
+{
+   static const char *jreType[] = { "server", "default", "j9vm", "classic", NULL };
+
+   for(int i = 0; jreType[i] != NULL; i++)
+   {
+      snprintf(jvm, MAX_PATH, "%s%s/lib/%s/%s/libjvm.so", base, libdir, arch, jreType[i]);
+      nxlog_debug(7, _T("FindJavaRuntime: checking %hs (%s)"), jvm, description);
+      if (_access(jvm, 0) == 0)
+         return true;
+
+      snprintf(jvm, MAX_PATH, "%s%s/jre/lib/%s/%s/libjvm.so", base, libdir, arch, jreType[i]);
+      nxlog_debug(7, _T("FindJavaRuntime: checking %hs (%s)"), jvm, description);
+      if (_access(jvm, 0) == 0)
+         return true;
+   }
+
+   if (!strcmp(arch, "x86_64"))
+      return CheckJvmPath(base, libdir, "amd64", jvm, description);
+
+   if (!strcmp(arch, "i686"))
+      return CheckJvmPath(base, libdir, "i386", jvm, description);
+
+   return false;
+}
+
+#endif
+
+/**
+ * Find Java runtime module. Search algorithm is following:
+ * 1. Windows only - check for bundled JRE in bin\jre
+ * 2. Check for bundled JRE in $NETXMS_HOME/bin/jre (Windows) or $NETXMS_HOME/lib/jre (non-Windows)
+ * 3. Windows only - check JRE location in registry
+ * 3. Check $JAVA_HOME
+ * 4. Check $JAVA_HOME/jre
+ * 5. Check JDK location specified at compile time
+ *
+ * @param buffer buffer for result
+ * @param size buffer size in characters
+ * @return buffer on success or NULL on failure
+ */
+TCHAR LIBNXJAVA_EXPORTABLE *FindJavaRuntime(TCHAR *buffer, size_t size)
+{
+#ifdef _WIN32
+   TCHAR path[MAX_PATH];
+   GetModuleFileName(NULL, path, MAX_PATH);
+   TCHAR *s = _tcsrchr(path, _T('\\'));
+   if (s != NULL)
+   {
+      s++;
+      _tcscpy(s, _T("jre\\bin\\server\\jvm.dll"));
+      nxlog_debug(7, _T("FindJavaRuntime: checking %s (executable path)"), path);
+      if (_taccess(path, 0) == 0)
+      {
+         nx_strncpy(buffer, path, size);
+         return buffer;
+      }
+   }
+#endif
+
+   char jvm[MAX_PATH] = "";
+
+#ifndef _WIN32
+   struct utsname un;
+   uname(&un);
+#endif
+
+   // Use NETXMS_HOME
+   const char *netxmsHome = getenv("NETXMS_HOME");
+   if ((netxmsHome != NULL) && (*netxmsHome != 0))
+   {
+#ifdef _WIN32
+      snprintf(jvm, MAX_PATH, "%s\\bin\\jre\\bin\\server\\jvm.dll", netxmsHome);
+      nxlog_debug(7, _T("FindJavaRuntime: checking %hs (NetXMS home)"), jvm);
+#else
+      CheckJvmPath(netxmsHome, "/lib", un.machine, jvm, _T("NetXMS home"));
+#endif
+   }
+
+#ifdef _WIN32
+   if ((jvm[0] == 0) || (_access(jvm, 0) != 0))
+   {
+      HKEY hKey;
+      if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\JavaSoft\\Java Runtime Environment"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
+      {
+         TCHAR currVersion[64];
+         DWORD size = sizeof(currVersion);
+         if (RegQueryValueEx(hKey, _T("CurrentVersion"), NULL, NULL, (BYTE *)currVersion, &size) == ERROR_SUCCESS)
+         {
+            HKEY hSubKey;
+            if (RegOpenKeyEx(hKey, currVersion, 0, KEY_QUERY_VALUE, &hSubKey) == ERROR_SUCCESS)
+            {
+               size = MAX_PATH - 20;
+               if (RegQueryValueExA(hSubKey, "JavaHome", NULL, NULL, (BYTE *)jvm, &size) == ERROR_SUCCESS)
+               {
+                  strcat(jvm, "\\bin\\server\\jvm.dll");
+                  nxlog_debug(7, _T("FindJavaRuntime: checking %hs (registry)"), jvm);
+               }
+               RegCloseKey(hSubKey);
+            }
+         }
+         RegCloseKey(hKey);
+      }
+   }
+#endif
+
+   // Check JAVA_HOME
+   if ((jvm[0] == 0) || (_access(jvm, 0) != 0))
+   {
+      const char *javaHome = getenv("JAVA_HOME");
+      if ((javaHome != NULL) && (*javaHome != 0))
+      {
+#ifdef _WIN32
+         snprintf(jvm, MAX_PATH, "%s\\bin\\server\\jvm.dll", javaHome);
+         nxlog_debug(7, _T("FindJavaRuntime: checking %hs (Java home)"), jvm);
+         if (_access(jvm, 0) != 0)
+         {
+            snprintf(jvm, MAX_PATH, "%s\\jre\\bin\\server\\jvm.dll", javaHome);
+            nxlog_debug(7, _T("FindJavaRuntime: checking %hs (Java home)"), jvm);
+         }
+#else
+         CheckJvmPath(javaHome, "", un.machine, jvm, _T("Java home"));
+#endif
+      }
+   }
+
+#ifdef JDK_LOCATION
+   if ((jvm[0] == 0) || (_access(jvm, 0) != 0))
+   {
+#ifdef _WIN32
+      snprintf(jvm, MAX_PATH, JDK_LOCATION "\\jre\\bin\\server\\jvm.dll");
+      nxlog_debug(7, _T("FindJavaRuntime: checking %hs (JDK defined at compile time)"), jvm);
+#else
+      CheckJvmPath(JDK_LOCATION, "", un.machine, jvm, _T("JDK defined at compile time"));
+#endif
+   }
+#endif
+
+   if ((jvm[0] == 0) || (_access(jvm, 0) != 0))
+      return NULL;
+
+#ifdef UNICODE
+   MultiByteToWideChar(CP_UTF8, 0, jvm, -1, buffer, (int)size);
+   buffer[size - 1] = 0;
+#else
+   nx_strncpy(buffer, jvm, size);
+#endif
+   return buffer;
+}
diff --git a/src/libnxjava/jvm.cpp b/src/libnxjava/jvm.cpp
new file mode 100644 (file)
index 0000000..f45192c
--- /dev/null
@@ -0,0 +1,221 @@
+/*
+** NetXMS - Network Management System
+** Copyright (C) 2003-2017 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU Lesser General Public License as published
+** by the Free Software Foundation; either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program 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 Lesser General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: jvm.cpp
+**/
+
+#include "libnxjava.h"
+
+/**
+ * JVM module
+ */
+static HMODULE s_jvmModule = NULL;
+
+/**
+ * JVM
+ */
+static JavaVM *s_javaVM = NULL;
+
+/**
+ * Prototype for JNI_CreateJavaVM
+ */
+typedef jint (JNICALL *T_JNI_CreateJavaVM)(JavaVM **, void **, void *);
+
+/**
+ * Create Java virtual machine
+ *
+ * @param jvmPath path to JVM library
+ * @param jar application JAR - path should be relative to NetXMS library directory (can be NULL)
+ * @param usercp user defined class path (can be NULL)
+ * @param vmOptions additional VM options
+ * @param env points where JNI environment for current thread will be stored
+ * @return true if VM created successfully
+ */
+JavaBridgeError LIBNXJAVA_EXPORTABLE CreateJavaVM(const TCHAR *jvmPath, const TCHAR *jar, const TCHAR *usercp, StringList *vmOptions, JNIEnv **env)
+{
+   TCHAR errorText[256];
+   s_jvmModule = DLOpen(jvmPath, errorText);
+   if (s_jvmModule == NULL)
+   {
+      nxlog_write_generic(NXLOG_ERROR, _T("JavaBridge: Unable to load JVM: %s"), errorText);
+      return NXJAVA_JVM_LOAD_FAILED;
+   }
+
+   TCHAR libdir[MAX_PATH];
+   GetNetXMSDirectory(nxDirLib, libdir);
+
+   String classpath = _T("-Djava.class.path=");
+   classpath.append(libdir);
+   classpath.append(FS_PATH_SEPARATOR_CHAR);
+   classpath.append(_T("netxms-java-bridge.jar"));
+   if (jar != NULL)
+   {
+      classpath.append(JAVA_CLASSPATH_SEPARATOR);
+      classpath.append(libdir);
+      classpath.append(FS_PATH_SEPARATOR_CHAR);
+      classpath.append(jar);
+   }
+   if (usercp != NULL)
+   {
+      classpath.append(JAVA_CLASSPATH_SEPARATOR);
+      classpath.append(usercp);
+   }
+
+   JavaVMInitArgs vmArgs;
+   JavaVMOption options[128];
+   memset(options, 0, sizeof(options));
+
+#ifdef UNICODE
+   options[0].optionString = classpath.getUTF8String();
+#else
+   options[0].optionString = strdup(classpath);
+#endif
+
+   if (vmOptions != NULL)
+   {
+      for(int i = 0; i < vmOptions->size(); i++)
+      {
+#ifdef UNICODE
+         options[i + 1].optionString = UTF8StringFromWideString(vmOptions->get(i));
+#else
+         options[i + 1].optionString = UTF8StringFromMBString(vmOptions->get(i));
+#endif
+      }
+   }
+
+   vmArgs.version = JNI_VERSION_1_6;
+   vmArgs.options = options;
+   vmArgs.nOptions = (vmOptions != NULL) ? vmOptions->size() + 1 : 1;
+   vmArgs.ignoreUnrecognized = JNI_TRUE;
+
+   nxlog_debug(6, _T("JVM options:"));
+   for(int i = 0; i < vmArgs.nOptions; i++)
+      nxlog_debug(6, _T("    %hs"), vmArgs.options[i].optionString);
+
+   JavaBridgeError result;
+
+   T_JNI_CreateJavaVM JNI_CreateJavaVM = (T_JNI_CreateJavaVM)DLGetSymbolAddr(s_jvmModule, "JNI_CreateJavaVM", errorText);
+   if (JNI_CreateJavaVM != NULL)
+   {
+      if (JNI_CreateJavaVM(&s_javaVM, (void **)env, &vmArgs) == JNI_OK)
+      {
+         RegisterConfigHelperNatives(*env);
+         RegisterPlatformNatives(*env);
+         nxlog_debug(2, _T("JavaBridge: Java VM created"));
+         result = NXJAVA_SUCCESS;
+      }
+      else
+      {
+         nxlog_write_generic(NXLOG_ERROR, _T("JavaBridge: cannot create Java VM"));
+         result = NXJAVA_CANNOT_CREATE_JVM;
+      }
+   }
+   else
+   {
+      nxlog_write_generic(NXLOG_ERROR, _T("JavaBridge: cannot find JVM entry point (%s)"));
+      result = NXJAVA_NO_ENTRY_POINT;
+   }
+
+   if (result != NXJAVA_SUCCESS)
+      DestroyJavaVM();
+   return result;
+}
+
+/**
+ * Destroy Java virtual machine
+ */
+void LIBNXJAVA_EXPORTABLE DestroyJavaVM()
+{
+   if (s_javaVM != NULL)
+   {
+      s_javaVM->DestroyJavaVM();
+      s_javaVM = NULL;
+   }
+
+   if (s_jvmModule != NULL)
+   {
+      DLClose(s_jvmModule);
+      s_jvmModule = NULL;
+   }
+}
+
+/**
+ * Attach current thread to Java VM
+ *
+ * @return JNI environment for current thread or NULL on failure
+ */
+JNIEnv LIBNXJAVA_EXPORTABLE *AttachThreadToJavaVM()
+{
+   if (s_javaVM == NULL)
+      return NULL;
+
+   JNIEnv *env;
+   if (s_javaVM->AttachCurrentThread(reinterpret_cast<void **>(&env), NULL) != JNI_OK)
+      return NULL;
+   return env;
+}
+
+/**
+ * Detach current thread from Java VM
+ */
+void LIBNXJAVA_EXPORTABLE DetachThreadFromJavaVM()
+{
+   if (s_javaVM != NULL)
+      s_javaVM->DetachCurrentThread();
+}
+
+/**
+ * Start Java application. This is helper method for starting Java applications
+ * from command line wrapper. Application class should contain entry point with
+ * the following signature:
+ *
+ * public static void main(String[])
+ *
+ * @param env JNI environment for current thread
+ * @param appClass application class name
+ * @param argc number of command line arguments
+ * @param argv pointers to arguments in (expected to be encoded using system locale code page)
+ * @return NXJAVA_SUCCESS on success or appropriate error code
+ */
+JavaBridgeError LIBNXJAVA_EXPORTABLE StartJavaApplication(JNIEnv *env, const char *appClass, int argc, char **argv)
+{
+   jclass app = env->FindClass(appClass);
+   if (app == NULL)
+      return NXJAVA_APP_CLASS_NOT_FOUND;
+
+   nxlog_debug(5, _T("Application class found"));
+   jmethodID appMain = env->GetStaticMethodID(app, "main", "([Ljava/lang/String;)V");
+   if (appMain == NULL)
+      return NXJAVA_APP_ENTRY_POINT_NOT_FOUND;
+
+   nxlog_debug(5, _T("Shell main method found"));
+   jclass stringClass = env->FindClass("java/lang/String");
+   jobjectArray jargs = env->NewObjectArray(argc, stringClass, NULL);
+   for(int i = 0; i < argc; i++)
+   {
+      jstring js = JavaStringFromCStringSysLocale(env, argv[i]);
+      if (js != NULL)
+      {
+         env->SetObjectArrayElement(jargs, i, js);
+         env->DeleteLocalRef(js);
+      }
+   }
+   env->CallStaticVoidMethod(app, appMain, jargs);
+   env->DeleteLocalRef(jargs);
+   return NXJAVA_SUCCESS;
+}
diff --git a/src/libnxjava/libnxjava.h b/src/libnxjava/libnxjava.h
new file mode 100644 (file)
index 0000000..7e4928b
--- /dev/null
@@ -0,0 +1,33 @@
+/* 
+** NetXMS - Network Management System
+** Copyright (C) 2003-2017 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU Lesser General Public License as published by
+** the Free Software Foundation; either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program 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 Lesser General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: libnxjava.h
+**
+**/
+
+#ifndef _libnxjava_h_
+#define _libnxjava_h_
+
+#include <nms_common.h>
+#include <nms_util.h>
+#include <nxjava.h>
+
+bool RegisterConfigHelperNatives(JNIEnv *env);
+bool RegisterPlatformNatives(JNIEnv *env);
+
+#endif   /* _libnxjava_h_ */
diff --git a/src/libnxjava/main.cpp b/src/libnxjava/main.cpp
new file mode 100644 (file)
index 0000000..8a63da3
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+** NetXMS - Network Management System
+** Copyright (C) 2003-2017 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU Lesser General Public License as published
+** by the Free Software Foundation; either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program 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 Lesser General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: main.cpp
+**/
+
+#include "libnxjava.h"
+
+/**
+ * Error messages
+ */
+static const TCHAR *s_errorMessages[] =
+{
+   _T("Success"),
+   _T("JVM load failed"),
+   _T("JVM entry point not found"),
+   _T("Cannot create JVM"),
+   _T("Java application class not found"),
+   _T("Java application entry point not found")
+};
+
+/**
+ * Get error message from error code
+ */
+const TCHAR LIBNXJAVA_EXPORTABLE *GetJavaBridgeErrorMessage(JavaBridgeError error)
+{
+   if ((int)error < 0 || (int)error > NXJAVA_APP_ENTRY_POINT_NOT_FOUND)
+      return _T("Unknown Java bridge error");
+   return s_errorMessages[(int)error];
+}
+
+#ifdef _WIN32
+
+/**
+ * DLL entry point
+ */
+BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
+{
+   if (dwReason == DLL_PROCESS_ATTACH)
+      DisableThreadLibraryCalls(hInstance);
+   return TRUE;
+}
+
+#endif   /* _WIN32 */
diff --git a/src/libnxjava/platform.cpp b/src/libnxjava/platform.cpp
new file mode 100644 (file)
index 0000000..0877760
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+** NetXMS - Network Management System
+** Copyright (C) 2003-2017 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU Lesser General Public License as published
+** by the Free Software Foundation; either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program 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 Lesser General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: platform.cpp
+**/
+
+#include "libnxjava.h"
+
+/**
+ * Class:     org.netxms.bridge.Platform
+ * Method:    getNetXMSDirectoryInternal
+ * Signature: (I)Ljava/lang/String;
+ */
+static jstring JNICALL J_getNetXMSDirectoryInternal(JNIEnv *jenv, jclass jcls, jint type)
+{
+   TCHAR buffer[MAX_PATH];
+   GetNetXMSDirectory(static_cast<nxDirectoryType>(type), buffer);
+   return JavaStringFromCString(jenv, buffer);
+}
+
+/**
+ * Class:     org.netxms.bridge.Platform
+ * Method:    writeLog
+ * Signature: (ILjava/lang/String;)V
+ */
+static void JNICALL J_writeLog(JNIEnv *jenv, jclass jcls, jint level, jstring jmessage)
+{
+   if (jmessage == NULL)
+      return;
+
+   TCHAR *message = CStringFromJavaString(jenv, jmessage);
+   nxlog_write_generic((int)level, _T("%s"), message);
+   free(message);
+}
+
+/**
+ * Class:     org.netxms.bridge.Platform
+ * Method:    writeDebugLog
+ * Signature: (ILjava/lang/String;)V
+ */
+static void JNICALL J_writeDebugLog(JNIEnv *jenv, jclass jcls, jint level, jstring jmessage)
+{
+   if (jmessage == NULL)
+      return;
+
+   TCHAR *message = CStringFromJavaString(jenv, jmessage);
+   nxlog_debug((int)level, _T("%s"), message);
+   free(message);
+}
+
+/**
+ * Native methods
+ */
+static JNINativeMethod s_jniNativeMethods[] =
+{
+   { (char *)"getNetXMSDirectoryInternal", (char *)"(I)Ljava/lang/String;", (void *)J_getNetXMSDirectoryInternal },
+   { (char *)"writeDebugLog", (char *)"(ILjava/lang/String;)V", (void *)J_writeDebugLog },
+   { (char *)"writeLog", (char *)"(ILjava/lang/String;)V", (void *)J_writeLog }
+};
+
+/**
+ * Register native methods for Platform classes
+ */
+bool RegisterPlatformNatives(JNIEnv *env)
+{
+   jclass platformClass = CreateJavaClassGlobalRef(env, "org/netxms/bridge/Platform");
+   if (platformClass == NULL)
+      return false;
+
+   if (env->RegisterNatives(platformClass, s_jniNativeMethods, (jint)(sizeof(s_jniNativeMethods) / sizeof (s_jniNativeMethods[0]))) != 0)
+   {
+      nxlog_write_generic(NXLOG_ERROR, _T("JavaBridge: Failed to register native methods for platform class"));
+      return false;
+   }
+
+   return true;
+}
diff --git a/src/libnxjava/tools.cpp b/src/libnxjava/tools.cpp
new file mode 100644 (file)
index 0000000..9444c15
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+** NetXMS - Network Management System
+** Copyright (C) 2003-2017 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU Lesser General Public License as published
+** by the Free Software Foundation; either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program 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 Lesser General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: tools.cpp
+**/
+
+#include "libnxjava.h"
+
+/**
+ * Create global reference to Java class
+ *
+ * @param env JNI environment for current thread
+ * @param className Java class name
+ * @return Java class object
+ */
+jclass LIBNXJAVA_EXPORTABLE CreateJavaClassGlobalRef(JNIEnv *env, const char *className)
+{
+   if (env == NULL)
+      return NULL;
+
+   jclass c = env->FindClass(className);
+   if (c == NULL)
+   {
+      nxlog_write_generic(NXLOG_ERROR, _T("JavaBridge: Could not find class %hs"), className);
+      return NULL;
+   }
+
+   jclass gc = static_cast<jclass>(env->NewGlobalRef(c));
+   env->DeleteLocalRef(c);
+
+   if (gc == NULL)
+   {
+      nxlog_write_generic(NXLOG_ERROR, _T("JavaBridge: Could not create global reference of class %s"), className);
+      return NULL;
+   }
+
+   return gc;
+}
+
+/**
+ * Convert Java string to C string.
+ * Result string is dynamically allocated and must be disposed by calling free().
+ */
+TCHAR LIBNXJAVA_EXPORTABLE *CStringFromJavaString(JNIEnv *env, jstring jstr)
+{
+   const jchar *chars = env->GetStringChars(jstr, NULL);
+   jsize len = env->GetStringLength(jstr);
+   TCHAR *str = (TCHAR *)malloc((len + 1) * sizeof(TCHAR));
+#ifdef UNICODE
+#if UNICODE_UCS4
+   ucs2_to_ucs4(chars, len, str, len + 1);
+#else
+   memcpy(str, chars, len * sizeof(WCHAR));
+#endif
+#else
+   ucs2_to_mb(chars, len, str, len + 1);
+#endif
+   env->ReleaseStringChars(jstr, chars);
+   str[len] = 0;
+   return str;
+}
+
+/**
+ * Convert Java string to C string.
+ * Result string is in static buffer
+ */
+TCHAR LIBNXJAVA_EXPORTABLE *CStringFromJavaString(JNIEnv *env, jstring jstr, TCHAR *buffer, size_t bufferLen)
+{
+   const jchar *chars = env->GetStringChars(jstr, NULL);
+   jsize len = env->GetStringLength(jstr);
+#ifdef UNICODE
+#if UNICODE_UCS4
+   ucs2_to_ucs4(chars, min(len, bufferLen - 1), buffer, bufferLen);
+#else
+   memcpy(buffer, chars, min((size_t)len, bufferLen) * sizeof(WCHAR));
+#endif
+#else
+   ucs2_to_mb(chars, min(len, bufferLen - 1), buffer, bufferLen);
+#endif
+   env->ReleaseStringChars(jstr, chars);
+   buffer[min((size_t)len, bufferLen - 1)] = 0;
+   return buffer;
+}
+
+/**
+ * Convert wide character C string to Java string.
+ */
+jstring LIBNXJAVA_EXPORTABLE JavaStringFromCStringW(JNIEnv *env, const WCHAR *str)
+{
+   jsize len = (jsize)wcslen(str);
+#if UNICODE_UCS4
+   jchar *tmp = (jchar *)UCS2StringFromUCS4String(str);
+   jstring js = env->NewString(tmp, len);
+   free(tmp);
+#else
+   jstring js = env->NewString((jchar *)str, len);
+#endif
+   return js;
+}
+
+/**
+ * Convert C string in current code page to Java string.
+ */
+jstring LIBNXJAVA_EXPORTABLE JavaStringFromCStringA(JNIEnv *env, const char *str)
+{
+   jsize len = (jsize)strlen(str);
+   jchar *tmp = (jchar *)UCS2StringFromMBString(str);
+   jstring js = env->NewString(tmp, len);
+   free(tmp);
+   return js;
+}
+
+/**
+ * Convert C string in system locale code page to Java string.
+ */
+jstring LIBNXJAVA_EXPORTABLE JavaStringFromCStringSysLocale(JNIEnv *env, const char *str)
+{
+   jsize len = (jsize)strlen(str);
+#if UNICODE_UCS4
+   WCHAR *wtmp = WideStringFromMBStringSysLocale(str);
+   jchar *tmp = (jchar *)UCS2StringFromUCS4String(wtmp);
+#else
+   jchar *tmp = (jchar *)WideStringFromMBStringSysLocale(str);
+#endif
+   jstring js = env->NewString(tmp, len);
+   free(tmp);
+   return js;
+}
+
+/**
+ * Create StringList from Java string array
+ */
+StringList LIBNXJAVA_EXPORTABLE *StringListFromJavaArray(JNIEnv *curEnv, jobjectArray a)
+{
+   StringList *list = new StringList();
+   jsize count = curEnv->GetArrayLength(a);
+   for(jsize i = 0; i < count; i++)
+   {
+      jstring s = reinterpret_cast<jstring>(curEnv->GetObjectArrayElement(a, i));
+      list->addPreallocated(CStringFromJavaString(curEnv, s));
+      curEnv->DeleteLocalRef(s);
+   }
+   return list;
+}
index f5350de..c2cab34 100644 (file)
@@ -642,7 +642,7 @@ BOOL NXCORE_EXPORTABLE Initialize()
 #ifdef _WIN32
                                       0, NULL, MSG_DEBUG))
 #else
-                                      g_dwNumMessages, g_szMessages, MSG_DEBUG))
+                                      g_dwNumMessages, g_szMessages, MSG_DEBUG, MSG_OTHER))
 #endif
    {
                _ftprintf(stderr, _T("FATAL ERROR: Cannot open log file\n"));
index 191643d..eda87a0 100644 (file)
@@ -5,7 +5,7 @@
                        <provider class="org.eclipse.cdt.core.language.settings.providers.LanguageSettingsGenericProvider" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider" name="CDT User Setting Entries" prefer-non-shared="true"/>
                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
                        <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
-                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-473888658169189981" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1092834717854559371" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
                                <language-scope id="org.eclipse.cdt.core.gcc"/>
                                <language-scope id="org.eclipse.cdt.core.g++"/>
                        </provider>
index 41963ac..d15023d 100644 (file)
@@ -5,7 +5,7 @@
                        <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
                        <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
-                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-473888658169189981" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1092834717854559371" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
                                <language-scope id="org.eclipse.cdt.core.gcc"/>
                                <language-scope id="org.eclipse.cdt.core.g++"/>
                        </provider>
index 67ca905..fb95aec 100644 (file)
@@ -5,7 +5,7 @@
                        <provider class="org.eclipse.cdt.core.language.settings.providers.LanguageSettingsGenericProvider" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider" name="CDT User Setting Entries" prefer-non-shared="true"/>
                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
                        <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
-                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-473888658169189981" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1092834717854559371" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
                                <language-scope id="org.eclipse.cdt.core.gcc"/>
                                <language-scope id="org.eclipse.cdt.core.g++"/>
                        </provider>
index 3713e73..1be6504 100644 (file)
@@ -5,7 +5,7 @@
                        <provider class="org.eclipse.cdt.core.language.settings.providers.LanguageSettingsGenericProvider" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider" name="CDT User Setting Entries" prefer-non-shared="true"/>
                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
                        <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
-                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-473888658169189981" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1092834717854559371" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
                                <language-scope id="org.eclipse.cdt.core.gcc"/>
                                <language-scope id="org.eclipse.cdt.core.g++"/>
                        </provider>
index d859503..9e2c32d 100644 (file)
@@ -5,7 +5,7 @@
                        <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
                        <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
-                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-473888658169189981" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1092834717854559371" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
                                <language-scope id="org.eclipse.cdt.core.gcc"/>
                                <language-scope id="org.eclipse.cdt.core.g++"/>
                        </provider>
index 9eb8511..ead24c5 100644 (file)
@@ -5,7 +5,7 @@
                        <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
                        <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
-                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-473888658169189981" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1092834717854559371" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
                                <language-scope id="org.eclipse.cdt.core.gcc"/>
                                <language-scope id="org.eclipse.cdt.core.g++"/>
                        </provider>
index d1780bb..539b44c 100644 (file)
@@ -5,7 +5,7 @@
                        <provider class="org.eclipse.cdt.core.language.settings.providers.LanguageSettingsGenericProvider" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider" name="CDT User Setting Entries" prefer-non-shared="true"/>
                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
                        <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
-                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-473888658169189981" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1092834717854559371" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
                                <language-scope id="org.eclipse.cdt.core.gcc"/>
                                <language-scope id="org.eclipse.cdt.core.g++"/>
                        </provider>
index 424ab9d..1f2c105 100644 (file)
@@ -5,7 +5,7 @@
                        <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
                        <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
-                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-473888658169189981" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1092834717854559371" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
                                <language-scope id="org.eclipse.cdt.core.gcc"/>
                                <language-scope id="org.eclipse.cdt.core.g++"/>
                        </provider>
index 300aaa7..e597c10 100644 (file)
@@ -5,7 +5,7 @@
                        <provider class="org.eclipse.cdt.core.language.settings.providers.LanguageSettingsGenericProvider" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider" name="CDT User Setting Entries" prefer-non-shared="true"/>
                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
                        <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
-                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-473888658169189981" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1092834717854559371" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
                                <language-scope id="org.eclipse.cdt.core.gcc"/>
                                <language-scope id="org.eclipse.cdt.core.g++"/>
                        </provider>
index c9df933..ac621e6 100644 (file)
@@ -5,7 +5,7 @@
                        <provider class="org.eclipse.cdt.core.language.settings.providers.LanguageSettingsGenericProvider" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider" name="CDT User Setting Entries" prefer-non-shared="true"/>
                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
                        <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
-                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-473888658169189981" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1092834717854559371" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
                                <language-scope id="org.eclipse.cdt.core.gcc"/>
                                <language-scope id="org.eclipse.cdt.core.g++"/>
                        </provider>
index 339b44e..a4cbdf7 100644 (file)
@@ -5,7 +5,7 @@
                        <provider class="org.eclipse.cdt.core.language.settings.providers.LanguageSettingsGenericProvider" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider" name="CDT User Setting Entries" prefer-non-shared="true"/>
                        <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
                        <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
-                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-473888658169189981" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+                       <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1092834717854559371" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
                                <language-scope id="org.eclipse.cdt.core.gcc"/>
                                <language-scope id="org.eclipse.cdt.core.g++"/>
                        </provider>