equinox launcher jni - java-native-interface

Does anyone know how to launch equinox through jni ? I was able to invoke jvm using JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args); I got the main class of org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar . Now how to pass the launcher arguments to equinox launcher ? I was trying to do this way ... To which method should i pass the arguments ? i was trying to do it for the run .. . I am getting a return code 13 and its not launching ... what could be the issue ?
if(mainObject != NULL) {
runMethod = env->GetMethodID( mainClass, "run", "([Ljava/lang/String;)I");
if(runMethod != NULL) {
methodArgs = createRunArgs(env, equinoxArg2s);
if(methodArgs != NULL) {
//results->launchResult = 0;
runresult = env->CallIntMethod(mainObject, runMethod, methodArgs);
env->DeleteLocalRef(methodArgs);

I am doing everything correctly except the character array conversion . WCHAR to jobjectarray that i created was passing some junk chars , hence the issue ... So lesson learnt : beware of data that you are passing over jni . Do a double check on eithersides if you can ..

Related

How can I initialize an embedded Python interpreter with bytecode optimization from C++?

I am running an embedded Python 2.7 interpreter within my C++ project, and I would like to optimize the interpreter as much as possible. One way I would like to do this is by disabling my debug statements using the __debug__ variable. I would also like to realize any possible gains in performance due to running Python with bytecode optimizations (i.e. the -O flag).
This Stack Overflow question addresses the use of the __debug__ variable, and notes that it can be turned off by running Python with -O. However, this flag can obviously not be passed for an embedded interpreter that is created with C++ hooks.
Below is my embedded interpreter initialization code. The code is not meant to be run in isolation, but should provide a glimpse into the environment I'm using. Is there some way I can alter or add to these function calls to specify that the embedded interpreter should apply bytecode optimizations, set the __debug__ variable to False, and in general run in "release" mode rather than "debug" mode?
void PythonInterface::GlobalInit() {
if(GLOBAL_INITIALIZED) return;
PY_MUTEX.lock();
const char *chome = getenv("NAO_HOME");
const char *cuser = getenv("USER");
string home = chome ? chome : "", user = cuser ? cuser : "";
if(user == "nao") {
std::string scriptPath = "/home/nao/python:";
std::string swigPath = SWIG_MODULE_DIR ":";
std::string corePath = "/usr/lib/python2.7:";
std::string modulePath = "/lib/python2.7";
setenv("PYTHONPATH", (scriptPath + swigPath + corePath + modulePath).c_str(), 1);
setenv("PYTHONHOME", "/usr", 1);
} else {
std::string scriptPath = home + "/core/python:";
std::string swigPath = SWIG_MODULE_DIR;
setenv("PYTHONPATH", (scriptPath + swigPath).c_str(), 1);
}
printf("Starting initialization of Python version %s\n", Py_GetVersion());
Py_InitializeEx(0); // InitializeEx(0) turns off signal hooks so ctrl c still works
GLOBAL_INITIALIZED = true;
PY_MUTEX.unlock();
}
void PythonInterface::Init(VisionCore* core) {
GlobalInit();
PY_MUTEX.lock();
CORE_MUTEX.lock();
CORE_INSTANCE = core;
thread_ = Py_NewInterpreter();
PyRun_SimpleString(
"import pythonswig_module\n"
"pythonC = pythonswig_module.PythonInterface().CORE_INSTANCE.interpreter_\n"
"pythonC.is_ok_ = False\n"
"from init import *\n"
"init()\n"
"pythonC.is_ok_ = True\n"
);
CORE_MUTEX.unlock();
PY_MUTEX.unlock();
}
I solved this by setting the PYTHONOPTIMIZE environment variable prior to calling Py_InitializeEx(0):
/* ... snip ... */
setenv("PYTHONOPTIMIZE", "yes", 0);
printf("Starting initialization of Python version %s\n", Py_GetVersion());
Py_InitializeEx(0); // InitializeEx(0) turns off signal hooks so ctrl c still works
/* ... snip ... */

as_ldt_init failed to initialize -- C++ client

just day before i started to work with aerospike. I have some problem while writing one sample using LDT (Large data types -- Large List). I want to create a key with currdate with appended as key (20160419_2000_List) and later i will add raw data (byte array) as list values.
For that i am able to connect the database correctly, but i am not able to create key for list. Can you please guide me on this.
You can refer the following code to get idea of what i am doing exactly.
m_sTFPKeyStr.assign(datevalue); //datavalue consists datatime string
m_sTFPListStr.assign("List_");
m_sTFPListStr.append(datevalue);
as_key_init_str(&m_sTFPKey, m_sInputNameSpace.c_str(), m_sInputSetName.c_str(), m_sTFPKeyStr.c_str());
if (!as_ldt_init(m_sTFPListKey, m_sTFPListStr.c_str(), AS_LDT_LLIST, NULL))
{
memset(logmessage, 0x0, sizeof(logmessage));
sprintf(logmessage, "CDataBaseManager::SaveTFP Fails to initialize tfplist key %s", m_sTFPListStr.c_str());
m_pCaptureManager->m_pLogMgr->LogMsg(logmessage);
return;
}
Check the length of m_sTFPListStr in your code.
The codes of function as_ldt_init which will check the parameters :
as_ldt * as_ldt_init(as_ldt * ldt, const as_bin_name name, const as_ldt_type type, const as_udf_module_name module)
{
if (!name || name[0] == '\0' || strlen(name) > AS_BIN_NAME_MAX_LEN
|| (module && strlen(module) > AS_UDF_MODULE_MAX_LEN) )
{
return NULL;
}
...
}
As the value of AS_BIN_NAME_MAX_LEN:
#define AS_BIN_NAME_MAX_LEN (AS_BIN_NAME_MAX_SIZE - 1)
#define AS_BIN_NAME_MAX_SIZE 15

Invoking a method thtough C#

I am trying to get some data from the UWF_Volume WMI provider. Please see the following link,
https://msdn.microsoft.com/en-us/library/jj979756(v=winembedded.81).aspx
More specifically I am trying to get the exclusion files using the following class,
UInt32 GetExclusions([out, EmbeddedInstance("UWF_ExcludedFile")] string ExcludedFiles[]);
I am not familiar with out parameters but from a research I can understand that acts as a reference argument. So I wrote the following method,
public void getUWFExclusions()
{
{
string computer = ".";
ManagementScope scope = new ManagementScope(#"\\" + computer + #"\root\standardcimv2\embedded");
ManagementClass cls = new ManagementClass(scope.Path.Path, "UWF_Volume", null);
foreach (MethodData m in cls.Methods)
{
richTextBox1.AppendText("The class contains this method:" + m.Name + "\n");
}
ManagementBaseObject outParams;
foreach (ManagementObject mo in cls.GetInstances())
{
outParams = mo.InvokeMethod("GetExclusions", null, null);
richtextbox1.appendtext(string.format("ExcludedFiles" + mo[ExcludedFiles]));
}
}
catch (Exception e)
{
richTextBox1.AppendText(e.ToString());
}
}
The problem is that the line,
richtextbox1.appendtext(string.format("ExcludedFiles" + mo[ExcludedFiles]));
returns "Not Found"
I appreciate any help to debug this problem.
I guess you are missing the Object Query that actually gets data via call to WMI. I am not sure about windows 8 but till 7 we used to get data by WQL and that is not there in above code.

lua function argument expected near <eof>

I try to use lua in a C++ project. For lua executing I write this:
#include <lua.hpp>
...
luaEngine = luaL_newstate();
luaL_openlibs(luaEngine);
register_results(luaEngine); // For register c++ object in the LUA script as metatable
lua_pushstring(luaEngine, resultsId.c_str());
lua_setglobal(luaEngine, "resultsId");
lua_pushboolean(luaEngine, needReloadModel);
lua_setglobal(luaEngine, "needReload");
...
e = luaL_loadbuffer(luaEngine, script.c_str(), script.size(), NULL);
if(e != 0)
// error message
e = lua_pcall(luaEngine, 0, 1, 0);
if(e != 0)
// error message
...
lua_close(luaEngine);
And the lua script:
local Res = ResUpdateLUA(resultsId)
if current_result == "Normal" or current_result=='-' then
status = 'E'
else
status = 'O'
end
needReload = Res:setShowAnalyte('2320', status)
That didn't work and I've got error message:
[string "?"]:7: function arguments expected near <eof>
But when I add
print(needReload)
at the end of the lua script it works nice. What am I doing wrong?
The error message means that Lua reached the end of the source after seeing Res:s but before seeing (.
I suspect that script.size() is wrong. But I can't explain why adding that line works.
Thank you all for your answers. Yes, that was trouble with script.size() coz when it was replaced to e = luaL_loadbuffer(luaEngine, script.c_str(), strlen(script.c_str()), NULL); that started work fine. Sorry for my stupid question.

C++ ADO stored procedure error: Syntax Error or Access Violation

I am trying to run an SQL stored procedure through ADO in C++. The procedure is called (for argument's sake) testProcedure and expects two parameters: #param1 and #param2. Here is a trimmed version of the code in the execution method:
m_mCommandParameters[_T("param1")] = _T("foo");
m_mCommandParameters[_T("param2")] = _T("bar");
pCommand.CreateInstance(__uuidof(Command));
pCommand->ActiveConnection = link;
pCommand->CommandType = adCmdStoredProc;
pCommand->CommandText = _T("testProcedure");
pCommand->PutPrepared(true);
pCommand->NamedParameters = true;
// Set up the variant to store the parameter values
VARIANT vParamValue;
vParamValue.vt = VT_BSTR;
CString paramCount; // Stores the count for use as parameter name
// Iterate through set parameters and apply them to command
map<CString,CString>::iterator mItr;
for(mItr = m_mCommandParameters.begin(); mItr != m_mCommandParameters.end(); mItr++) {
paramCount = mItr->first;
vParamValue.bstrVal = _bstr_t(mItr->second);
// Append the parameter
if (mItr->second.IsEmpty()) {
_variant_t vtNULL;
vtNULL.vt = VT_NULL;
pCommand->Parameters->Append(
pCommand->CreateParameter(_bstr_t(L"#"+paramCount),adVarChar,adParamInput,10,vtNULL)
);
} else {
pCommand->Parameters->Append(
pCommand->CreateParameter(_bstr_t(L"#"+paramCount),adVarWChar,adParamInput,
//commandParameters[i].GetLength()+1,
sizeof(vParamValue),
_bstr_t(vParamValue))
);
}
}
_variant_t vRecordsAffected;
pRecordSet = pCommand->Execute(&vRecordsAffected,NULL,adCmdStoredProc);
My understanding is that this should essentially execute the following:
testProcedure #param1 = 'foo', #param2 = 'bar'
If I open SQL management studio and run the above it works fine. But when I try and run the C++ I get the error:
database error IDispatch error #3092 80040e14 query : testProcedure;
[Microsoft][ODBC SQL Server Driver]Syntax error or access violation.
I only have SQL express so don't have SQL profiler; I usually use Express Profiler but for some reason it doesn't display any trace on stored procedured. So I am not sure how to start debugging this.
Thanks!