I want to call java function from c++ which takes multiple parameters , I have tried following statement
mid=env->GetMethodID(JDeployerClass,"deploy","(Ljava/io/File;,Lorg/glassfish/api/deployment/DeployCommandParameters;)Ljava/lang/String;");
But its not working out, is there anything wrong with above statement?, What is the correct way to get method id which accepts multiple parameters ?
The signature is likely wrong.
Try the following signature: (Ljava/io/File;Lorg/glassfish/api/deployment/DeployCommandParameters;)Ljava/lang/String;
which corresponds to the following Java method:
String deploy(File f, DeployCommandParameters p);
Related
I am trying to initialize a server to look as specific inputs based on the request it gets. there are a lot of them so I want to initialize it with a loop as follows:
void serverInit() {
for (int i = 1; i <= qty; i++) {
String s = "/readBatt" + i;
server.on(s, runTest(i));
}
server.begin();
Serial.println("Server started.");
}
It's telling me that server.on(s, runTest(i)); is an invalid use of void expression. I know it wants it formatted as server.on(s, runTest) but the function runTest(int n) takes a parameter. How can i pass this parameter through to the function?
It seems you are using the WebServer class from the ESP32 Arduino libraries. As you have gleaned already, the callback specified in the on() method does not accept any arguments.
You have an alternative, however. You can specify a 'placeholder' in the URL path - using curly brackets - {}. In the callback, then, the corresponding argument can be retrieved by using the pathArg() method - which accepts the argument index as parameter.
Example ...
You could define your API endpoint as /readBatt/<battery number>. To configure the server to handle requests to this endpoint, then, you would use something like
#include <uri/UriBraces.h>
server.on(UriBraces("/readBatt/{}"), runTest);
In your callback, you would retrieve the first argument as follows ...
static void runTest() {
String batteryNumber = server.pathArg(0);
Serial.println("Request to read battery");
String response = "You attempted to read battery " + batteryNumber;
response += ".\nThis endpoint is a placeholder. Check again soon!";
server.send(200, "text/plain", response);
}
Finally ... Suppose your ESP8266 was running on local IP address 192.168.1.9. You could access your new API endpoint by opening
http://192.168.1.9/readBatt/1
in your browser. (Replace 1 with the relevant battery number.)
I don't think there are versions of the pathArg() which return an integer, unfortunately, so you may have to perform a conversion at some point.
You can use what's called a "closure". A closure lets you compose a function which retains access to variables outside of its scope.
A closure is written using a "lambda expression" - basically an anonymous function. C++'s syntax for lambda expressions looks like this:
[capture variable list](argument list) { body}
The capture variable list is a list of variables you want to be made available inside the body. The argument list is the normal function argument list that would get passed in by the caller. You'd write the lambda expression you need like this:
[i]() { runTest(i); }
and use it like this:
server.on(s, [i]() { runTest(i); });
To be clear, #David Collins' answer is the better way to write the web server. Using a parameter in the URL is better than creating several URLs with the parameter embedded in them. I'm just answering the question of how to pass a parameter to a function that gets called without arguments. If you write the web server code the better way, you won't need to do this (although I would do a bounds check on the value passed in the URL to make sure you're getting a valid battery number).
I'm using the ResourceBundle at ICU library with c/C++.
I do a test with simple messages and works fine.
Now I'm trying to use messages with arguments, for example:
error{"Error: {0}"}
Is there any way to get the resource and check if it has arguments to use the FormatString class ?
For example in the resource:
error{"Error: {0}"}
Is a method to get the number of arguments ? In this case one.
Thanks
I'm using the Java client library for the Directory API from here: https://developers.google.com/api-client-library/java/apis/admin/directory_v1
I have insert user and insert group working fine, but for some reason when I try to insert a member, it doesn't work. There is no exception thrown. Here is the code:
Member member = new Member();
member.setEmail("someemail#mydomain.com");
member.setRole("MEMBER");
//member.setKind("admin#directory#member"); not sure if I need this. tried with and without
member.setType("USER"); // docs say "MEMBER" but doesn't seem true. Tried both
client.members().insert(myGroupId, member);
You don't need to set kind nor type.
After "client.members().insert(myGroupId, member);" do you call execute ?
I am creating a jruby library that has JDI bindings, but when calling a java method, I am getting some weird object inconsistencies that aren't allowing me to call certain methods.
new_value = #vm.mirrorOf(value)
puts("New Value: #{new_value.class}")
puts("Variable: #{variable.java_value.class}")
object_reference.setValue(variable.java_value, new_value)
outputs:
New Value: Java::ComSunToolsJdi::StringReferenceImpl
Variable: Java::ComSunToolsJdi::StringReferenceImpl
TypeError: cannot convert instance of class org.jruby.java.proxies.ConcreteJavaProxy to interface com.sun.jdi.Field
set_value at /Users/wuntee/Google Drive/workspace/android_debug/lib/android_debug/event.rb:85
(root) at hello_world.rb:14
call at org/jruby/RubyProc.java:249
on_break at /Users/wuntee/Google Drive/workspace/android_debug/lib/android_debug/debugger.rb:94
go at /Users/wuntee/Google Drive/workspace/android_debug/lib/android_debug/debugger.rb:63
(root) at hello_world.rb:18
So, somehow in the setValue call, one of the arguments are cast to ConcreteJavaProxy. Is there a way to force them to stay as their original types? I feel like this is a core JRuby nuance that I dont understand. Any help would be appreciated. Thanks.
I'm not sure if this is possible within VS, but I'm working with a massive VB.NET file that needs to log every function call for debug purposes. Problem is, that not every function has the Log command in it. I'm trying to use RegEx to find the function definitions that do not have a log within them.
This would NOT be a match:
Public Function Test1() as Boolean
Log.Tracelog("Test1()")
Return True
End Function
This WOULD be a match:
Public Function Test2() as Boolean
Return False
End Function
The closest I've come is using the following:
(function|sub|property) .*\n.*~(Log\.t)
In my own mind, it should work, but no matter how I word it, it's still pulling every function as a match, even those that have the "Log.Tracelog" call in the function.
Is there anyway I can search to find the latter case?
Try this:
(function|sub|property) .*\n~(.*Log\.t)
I moved .* from just before the ~() (preventmatch) to just inside it.
Why not use the debug.WriteLine methods for the functions you want logged. You can also use the stack to get the method name:
Private Function test1() As Boolean
Debug.WriteLine(New System.Diagnostics.StackTrace().GetFrame(0).GetMethod.Name)
Return False
End Function
Then the messages only output when debugging and only in the methods you want.