/*
** Java-Bridge NetXMS subagent
** Copyright (c) 2013 TEMPEST a.s.
- ** Copyright (c) 2015 Raden Solutions SIA
+ ** Copyright (c) 2015-2016 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
for(jsize j = 0; j < columns; j++)
{
jstring s = reinterpret_cast<jstring>(curEnv->GetObjectArrayElement(row, j));
- value->setPreallocated(j, CStringFromJavaString(curEnv, s));
- curEnv->DeleteLocalRef(s);
+ if (s != NULL)
+ {
+ value->setPreallocated(j, CStringFromJavaString(curEnv, s));
+ curEnv->DeleteLocalRef(s);
+ }
}
curEnv->DeleteLocalRef(row);
}
#define CLASSPATH_SEPARATOR _T(':')
#endif
+/**
+ * Java table info
+ */
+struct JavaTableInfo
+{
+ TCHAR *key;
+ NETXMS_SUBAGENT_TABLE *definition;
+};
+
/**
* JVM instance
*/
/**
* Handler for table parameters
*/
-static LONG TableHandler(const TCHAR *cmd, const TCHAR *id, Table *value, AbstractCommSession *session)
+static LONG TableHandler(const TCHAR *cmd, const TCHAR *arg, Table *value, AbstractCommSession *session)
{
if (s_subAgent == NULL)
return SYSINFO_RC_ERROR;
- LONG rc = s_subAgent->tableHandler(cmd, id, value);
+ // Prepare result table using column infor provided during initialization
+ const JavaTableInfo *info = (const JavaTableInfo *)arg;
+ NETXMS_SUBAGENT_TABLE_COLUMN *columns = info->definition->columns;
+ int count = info->definition->numColumns;
+ for(int i = 0; i < count; i++)
+ {
+ value->addColumn(columns[i].name, columns[i].dataType, columns[i].displayName, columns[i].isInstance);
+ }
+
+ LONG rc = s_subAgent->tableHandler(cmd, info->key, value);
s_jvm->DetachCurrentThread();
return rc;
}
};
/**
- * Sabagent information
+ * Subagent information
*/
static NETXMS_SUBAGENT_INFO s_subagentInfo =
{
NETXMS_VERSION_STRING,
SubAgentInit,
SubAgentShutdown,
- NULL, // BOOL (*commandhandler)(UINT32 dwCommand, NXCPMessage *pRequest, NXCPMessage *pResponse, void *session)
+ NULL, // BOOL (*commandHandler)(UINT32 dwCommand, NXCPMessage *pRequest, NXCPMessage *pResponse, void *session)
0, // numParamaters
NULL, // parameters
0, // numLists
s_subagentInfo.tables = (NETXMS_SUBAGENT_TABLE *)calloc(s_subagentInfo.numTables, sizeof(NETXMS_SUBAGENT_TABLE));
for(int i = 1, j = 0; j < (int)s_subagentInfo.numTables; j++)
{
- s_subagentInfo.tables[j].arg = _tcsdup(tables->get(i++));
+ JavaTableInfo *tableInfo = new JavaTableInfo();
+ tableInfo->key = _tcsdup(tables->get(i++));
+ tableInfo->definition = &s_subagentInfo.tables[j];
+ s_subagentInfo.tables[j].arg = (const TCHAR *)tableInfo;
nx_strncpy(s_subagentInfo.tables[j].name, tables->get(i++), MAX_PARAM_NAME);
nx_strncpy(s_subagentInfo.tables[j].description, tables->get(i++), MAX_DB_STRING);
s_subagentInfo.tables[j].handler = TableHandler;