Java Card Applet trigger proactive CAT command in process method - javacard

I need to get the current time and reset the UICC in an APDU command processed in the process method of the Applet. I'm concerned about the statement in the uicc.toolkit.ProactiveHandlerSystem.getTheHandler() method:
The applet shall get the reference of the handler at its triggering, the beginning of
the processToolkit method.
I assume I will get a HANDLER_NOT_AVAILABLE ToolkitException when trying to get the handler anywhere else except the processToolkit method.
Has anyone experience with this?
What are the alternatives to get the time and execute the reset?
I could get the time in advance after the PROFILE DOWNLOAD event or in the last STATUS event before the process command is triggered. But this would mean to poll the time continuously even if the my APDU command is not called. I could wait for the next STATUS command and listen to it to execute the reset, but this would be a delay of 30 seconds.

Related

How do I manually restart a one shot Timer?

I've added a one shot Timer and hooked up a function to listen for the timeout() signal. After some action occurs in my game, I want to restart the timer at its original Wait Time value.
I've tried resetting the timer to the Wait Time I set in the inspector like this:
$Timer.time_left = $Timer.wait_time
This results in an error:
Invalid set index 'time_left' (on base: 'Timer') with value of type 'float'.
How do I set the time back to its original Wait Time value in the inspector?
Looking at the documentation for Timer, it says that you can't set the time_left property and should instead use start:
Note: You cannot set this value. To change the timer's remaining time, use start.
Calling start without any parameters restarts the timer to its original Wait Time value:
$Timer.start()
The start method also takes in an optional time_sec parameter that could instead restart the timer to a new wait time:
$Timer.start(0.5)

Bukkit/Spigot - How to wait until BukkitRunnable is finished

In my onDisbale() method in my Main class I have a loop which creates and starts new BukkitRunnables.
I'm getting a error in console: org.bukkit.plugin.IllegalPluginAccessException: Plugin attempted to register task while disabled I need to somehow wait in my onDisable() method until all the BukkitRunnables I create in the loop are finished. How to do that?
My code looks like this:
#Override
public void onDisable() {
for (Player p : Bukkit.getOnlinePlayers()) {
new PlayerDataSaverRunnable().runTaskAsynchronously(this);
}
}
The onDisable method is the very last thing that gets called before your plugin is disabled and the server shuts down. So, as the error message says, you unfortunately can't schedule any new tasks in the onDisable function.
You mentioned in a comment that you were trying to write to a file in the plugins folder, and under normal circumstances you'd want to do that asynchronously. But, because onDisable only ever gets called when the server is shut down (or when the entire server is reloaded with /reload), it's perfectly fine to run code here that blocks the main thread and could potentially take a few seconds to run — in the case of a shutdown, by the time this method gets called, all the players will have already been kicked off the server, and so there's no "lag" to complain about. If your plugin is super advanced and has to save a bunch of stuff, I don't think any server owners would complain even if it took 10 or so seconds to disable.
Of course, you would have to be saving something crazy for it to take a whole 10 seconds to save. More than likely, most files will save in just a few milliseconds.
If you're really dead-set on disabling the plugin as fast as possible, you might consider having some async task that runs every 5 minutes or so and auto-saves the files. Then, in onDisable, you could only save files that changed since the auto-saver was last run. That's a good practice anyways, just incase the server crashes or the power goes out and the onDisable method doesn't get a chance to run. But, then again, I would still recommend that you save everything in the onDisable method (that's what I do for all of my plugins, as well), even if it will take a few seconds and block the main thread, just so you can be 100% sure that everything gets saved correctly.

Can I have a line request for value and a line request for event pointing at the same GPIO pin at the same time?

So I'm accessing a GPIO Chip in Linux using /dev/gpiochipX and ioctls on Linux 4.14. I'd like to get an event from a pin and then very quickly afterwards read the pin value as well.
Right now, I can get the event by registering a line request for events, and catching the event by polling for it, with poll(2), through something like this:
returnValue = ioctl(fileDescriptor, GPIO_GET_LINEEVENT_IOCTL, &requestEvent);
I'd like to have a line request for values for the same pin ready in the background, so that I can check the pin state as quickly as possible after getting the event.
However, when I try to register the line request for values for the same pin with something like this:
returnValue = ioctl(fileDescriptor, GPIO_GET_LINEHANDLE_IOCTL, &requestValue);
the Linux returns Device or resource busy error.
As far as I can see, I have to release the GPIO Line request for event, register the new line request for value, and then check the value.
So am I missing something, or is it really impossible to have a line request for events and for value active at the same time?

How to send "CTRL+C" to child process in Node.js?

I tried to spawn child process - vvp (https://linux.die.net/man/1/vvp). At the certain time, I need to send CTRL+C to that process.
I am expecting that simulation will be interrupted and I get the interactive prompt. And after that I can continue the simulation by send command to the child process.
So, I tried something like this:
var child = require('child_process');
var fs = require('fs');
var vcdGen = child.spawn('vvp', ['qqq'], {});
vcdGen.stdout.on('data', function(data) {
console.log(data.toString())
});
setTimeout(function() {
vcdGen.kill('SIGINT');
}, 400);
In that case, a child process was stopped.
I also tried vcdGen.stdin.write('\x03') instead of vcdGen.kill('SIGINT'); but it isn't work.
Maybe it's because of Windows?
Is there any way to achieve the same behaviour as I got in cmd?
kill only really supports a rude process kill on Windows - the application signal model in Windows and *nix isn't compatible. You can't pass Ctrl+C through standard input, because it never comes through standard input - it's a function of the console subsystem (and thus you can only use it if the process has an attached console). It creates a new thread in the child process to do its work.
There's no supported way to do this programmatically. It's a feature for the user, not the applications. The only way to do this would be to do the same thing the console subsystem does - create a new thread in the target application and let it do the signalling. But the best way would be to simply use coöperative signalling instead - though that of course requires you to change the target application to understand the signal.
If you want to go the entirely unsupported route, have a look at https://stackoverflow.com/a/1179124/3032289.
If you want to find a middle ground, there's a way to send a signal to yourself, of course. Which also means that you can send Ctrl+C to a process if your consoles are attached. Needless to say, this is very tricky - you'd probably want to create a native host process that does nothing but create a console and run the actual program you want to run. Your host process would then listen for an event, and when the event is signalled, call GenerateConsoleCtrlEvent.

How to run a script after Pyramid's transaction manager has returned

How can I run myscript.py after the transaction manager has returned. Additionally, I would prefer if the script was not blocking.
In my view, I am receiving a file from a POST. Since I'm creating the file with repoze.filesafe's create_file(), it keeps the file in a temporary location until the transaction manager returns. The file only exists on the harddisk in its correct path after transaction manager has returned without an error.
Therefore, I need to run my script after the transaction manager has returned.
You can register a hook to be run after commit via the transaction package. Register one in your view:
import transaction
def your_after_commit(success, arg1, arg2, kwarg1=None, kwarg2=None):
if success:
print "Transaction commit succeeded"
else:
print "Transaction commit failed"
def someview(request):
current_transaction = transaction.get()
current_transaction.addAfterCommitHook(your_after_commit, args=(1, 2), kws={kwarg1='foo', kwargs2='bar'})
This still runs your script in the context of the current request (e.g. the request does not complete until your script returns). If you need a full asynchronous setup, you'll need to move to a proper asynchronous solution such as Celery. You would not use that with a transaction hook; just register a task to be run with Celery instead.

Resources