I'm making a Rebol 3 extension that has GUI events.
For now, I manage this using synchronous callbacks so each time an event happens like a mouse move, the C extension calls the Rebol callback function.
But I'd like to manage this using REBEVT and RL->event.
Here is a code sample:
case SDL_MOUSEMOTION:
Add_Event_XY(
RootGob, 2, (event.motion.x + (event.motion.y << 16)), EVT_MOVE
);
/*
cbi.obj = CBI_SDL_MOUSEMOTION.obj;
cbi.word = CBI_SDL_MOUSEMOTION.word;
RXI_COUNT(args) = 1;
RXI_TYPE(args, 1) = RXT_PAIR;
args[1].pair.x = event.motion.x;
args[1].pair.y = event.motion.y;
n = RL_CALLBACK(&cbi);
if(n == 0) {RL_PRINT("%s\n", "callback error");}
*/
break;
But then when I do a wait in Rebol, I get:
>> wait 1
** Script error: wake-up does not allow none! for its port argument
** Where: loop -apply- wait
** Near: loop 8 [
unless event: take sport/state [break]
port...
How to make the port not null?
After some searches in R3 code, I found that I had to initialize as below:
system/view/event-port: open event://
Now it works! (with R3 mainline)
Related
I've stumbled on the throughput-deadline-time configuration property for Akka dispatchers, and it looks like an interesting option, however the only mention of it I could find in the whole documentation is the following:
# Throughput deadline for Dispatcher, set to 0 or negative for no deadline
throughput-deadline-time = 0ms
I think we can agree that this is not very helpful.
So what does throughput-deadline-time control, and what impact does it have when on my dispatcher?
So I had a look at the Akka source code, and found this method in the Mailbox that seems to implement the behavior of throughput-deadline-time:
/**
* Process the messages in the mailbox
*/
#tailrec private final def processMailbox(
left: Int = java.lang.Math.max(dispatcher.throughput, 1),
deadlineNs: Long = if (dispatcher.isThroughputDeadlineTimeDefined == true) System.nanoTime + dispatcher.throughputDeadlineTime.toNanos else 0L): Unit =
if (shouldProcessMessage) {
val next = dequeue()
if (next ne null) {
if (Mailbox.debug) println(actor.self + " processing message " + next)
actor invoke next
if (Thread.interrupted())
throw new InterruptedException("Interrupted while processing actor messages")
processAllSystemMessages()
if ((left > 1) && ((dispatcher.isThroughputDeadlineTimeDefined == false) || (System.nanoTime - deadlineNs) < 0))
processMailbox(left - 1, deadlineNs)
}
}
This piece of code makes it clear: throughput-deadline-time configures the maximum amount of time that will be spent processing the same mailbox, before switching to the mailbox of another actor.
In other words, if you configure a dispatcher with:
my-dispatcher {
throughput = 100
throughput-deadline-time = 1ms
}
Then the mailbox of the actors will process at most 100 messages at a time, during at most 1ms, whenever the first of those limits is hit, Akka switches to another actor/mailbox.
I am using Tkinter as a notification of an upcoming mouse event and I want the program to continue with its main function but it keeps closing after notification appears. What do i need to add to the follow code to get it to return to the function that called it?
def sendMessage():#THIS IS MY NOTIFICATION FUNCTION
popupRoot = Tk()
popupRoot.lift()
popupRoot.attributes('-topmost',True)
popupRoot.after_idle(popupRoot.attributes,'-topmost',False)
popupRoot.after(10000, exit)
popupButton = Button(popupRoot, text = "You have 1 minute until mouse events",
font = ("Verdana", 12), bg = "yellow", command = exit)
popupButton.pack()
popupRoot.geometry('400x50+700+500')
popupRoot.mainloop()
def wait(howLong, runTime, howRuns, day, x): #THIS IS THE FUNCTION THAT CALLED THE NOTIFICATION FUNCTION
while x < howLong:
print "rerun in ", howLong - x, " minute(s)"
messTime = 1
if messTime == 1:
sendMessage()
time.sleep(60)#1 minute delay to allow carts to return
x = x + 1
if x == howLong:
runTime = runTime + 1
print "Run time = ", runTime
print "rerunning program now"
if runTime == howRuns:
exitProgram()
else:
main(howLong, runTime, howRuns, day)
It ends because in after() and in command= you use exit which normally is used to close script.
You need popupRoot.destroy instead of exit in after(10000, popupRoot.destroy) and command=popupRoot.destroy
I'm using the code below to test asynchronous calls using AFNetworking in my unit tests for iOS7. When I run the test alone, or even the entire test case, the code works fine. However, when I run the entire test suite, I get EXC_BAD_ACCESS (code=1, address0x7a) on the line [theRL runMode:NSDefaultRunLoopMode beforeDate:date];
NSRunLoop *theRL = [NSRunLoop currentRunLoop];
//setup timeout
float waitIncrement = 0.1f;
int timeoutCounter = (int)(60 / waitIncrement); //30 sec timeout
BOOL controlConditionReached = NO;
// Begin a run loop terminated when the downloadComplete it set to true
while (controlConditionReached == NO)
{
NSDate* date = [NSDate dateWithTimeIntervalSinceNow:waitIncrement];
//Here: EXC_BAD_ACCESS (code=1, address0x7a) when running the entire test suite
[theRL runMode:NSDefaultRunLoopMode beforeDate:date];
//control condition is set in one of your async operation delegate methods or blocks
controlConditionReached = self.downloadComplete || self.downloadFailed||self.cachedVideoAvailable ;
//if there's no response - timeout after some time
if(--timeoutCounter <= 0)
{
break;
}
}
I see that at the same time as I'm using my loop, AFNetoworking is using this method:
+ (void)networkRequestThreadEntryPoint:(id)__unused object {
#autoreleasepool {
[[NSThread currentThread] setName:#"AFNetworking"];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
[runLoop addPort:[NSMachPort port] forMode:NSDefaultRunLoopMode];
[runLoop run];
}
}
How can I identify what is causing this error? If I change my method's run loop mode to NSRunLoopCommonModes, then all of my tests fail
Are there any c++ example or references? How we will program in c++ based on what purpose in serial port programming? This is an example in Matlab code. What thing we should consider in c++ programming if we convert this Matlab code to c++.
function DUT_callback(obj, event, DUT_port)
persistent stored_data;
if isempty(stored_data)
stored_data = [];
end
if ~strcmp(DUT_port.status,'open')
return;
end
if ~DUT_port.BytesAvailable
return;
end
try
new_data = fread(DUT_port,DUT_port.BytesAvailable);
catch exception
fprintf('ERROR: Failed to read from DUT port. Shutting down.\n');
cleanup();
return;
end
data_array = [stored_data;new_data];
packet.NewPacket = 1;
while packet.NewPacket == 1
[packet,data_array] = parse_serial_data(data_array);
% Report bad checksum if appropriate
if packet.BadChecksum
end
% If packet was received, do stuff with it
if packet.NewPacket == 1
% HANDLE RAW GYRO DATA PACKET
if packet.Address == 86
% Extract the gyro data
gyro_x = typecast( flipud(uint8(packet.data(1:2))), 'int16' );
gyro_y = typecast( flipud(uint8(packet.data(3:4))), 'int16' );
gyro_z = typecast( flipud(uint8(packet.data(5:6))), 'int16' );
got_gyro_data = 1;
% fprintf('%d\t%d\t%d\n',gyro_x,gyro_y,gyro_z);
end
% HANDLE TEMPERATURE DATA PACKET
if packet.Address == 118
temperature = typecast( flipud(uint8(packet.data(1:4))), 'single' );
got_temperature_data = 1;
% fprintf('%3.2f\n',temperature);
end
% If we received gyro and temperature data, log it to
% the workspace if logging is enabled.
if got_temperature_data && got_gyro_data
got_temperature_data = 0;
got_gyro_data = 0;
if GDATA.logging_data == 1 && GDATA.selected_DUT > 0
if GDATA.DUT_samples_collected < GDATA.MAX_SAMPLES
GDATA.DUT_samples_collected = GDATA.DUT_samples_collected + 1;
end end end end
Really depends on the OS you will be hosting your program on.
Microsoft has decent documentation on their serial interface.
http://msdn.microsoft.com/en-us/library/ff802693.aspx
Linux or some other nix your going to be more interested in:
http://www.gnu.org/software/libc/manual/html_mono/libc.html#Low_002dLevel-Terminal-Interface
You will find examples in both sets of documentation.
This thread was useful in finding out the next run-time for a scheduled task.
How do I find out the next run time for a Scheduled Task?
But, is there also a way to simply get the next scheduled task due to run?
If I can get the date and name of the next task due to run, I can plug that date into a jQuery countdown timer, which will display a countdown to the next scheduled task, something like:
TaskABC due to run in:
12 03 20
hrs min sec
. This is for an admin interface in case you're wondering how geeky can people get:-)
EDIT
I had the same thought as Bill. But was curious if there was another way.
I poked around and apparently the internal Scheduler class maintains a list of upcoming tasks. The list is private, but you can use the same reflection technique to access it. Interestingly the list also includes system tasks like the mail spooler, session/application trackers, watchers, etecetera. So you must iterate through it until you find a "scheduled task" ie CronTabEntry
Below is a very lightly tested function that seems to do the trick in CF9. (Note, includes the CreateTimeStruct function from http://www.cflib.org).
Rules:
Returns a structure containing the name and time remaining until the next task. If no tasks were found, result.task is an empty string.
Excludes paused tasks
Usage:
result = new TaskUtil().getNextTask();
WriteDump(result);
CFC
component {
public struct function getNextTask() {
// get list of upcoming tasks from factory (UNDOCUMENTED)
local.scheduler = createObject("java", "coldfusion.server.ServiceFactory").getSchedulerService();
local.taskField = local.scheduler.getClass().getDeclaredField("_tasks");
local.taskField.setAccessible( true );
local.taskList = local.taskField.get(local.scheduler);
// taskList contains system jobs too, so we must iterate
// through the tasks to find the next "scheduled task"
local.nextTask = "";
local.tasks = local.taskList.iterator();
while ( local.tasks.hasNext() ) {
local.currTask = local.tasks.next();
local.className = local.currTask.getRunnable().getClass().name;
// exit as soon as we find a scheduled task that is NOT paused
if (local.className eq "coldfusion.scheduling.CronTabEntry"
&& !local.currTask.getRunnable().paused) {
local.nextTask = local.currTask;
break;
}
}
// if we found a task, calculate how many days, hours, etcetera
// until its next run time
local.details = { task="", remaining={} };
if ( isObject(local.nextTask) ) {
local.secondsToGo = (local.nextTask.getWhen() - now().getTime()) / 1000;
local.details.task = local.nextTask.getRunnable().task;
local.details.remaining = createTimeStruct(local.secondsToGo);
local.details.nextDate = dateAdd("s", local.nextTask.getWhen() / 1000
, "January 1 1970 00:00:00" );
}
return local.details;
}
/**
* Abbreviated version of CreateTimeStruct by Dave Pomerance
* See http://www.cflib.org/index.cfm?event=page.udfbyid&udfid=421
*
* #param timespan The timespan to convert.
* #return Returns a structure.
* #author Dave Pomerance
* #version 1, January 7, 2002
*/
public struct function CreateTimeStruct(required numeric timespan) {
var timestruct = StructNew();
var mask = "s";
// only 4 allowed values for mask - if not one of those, return blank struct
if (ListFind("d,h,m,s", mask)) {
// compute seconds
if (mask eq "s") {
timestruct.s = (timespan mod 60) + (timespan - Int(timespan));
timespan = int(timespan/60);
mask = "m";
} else timestruct.s = 0;
// compute minutes
if (mask eq "m") {
timestruct.m = timespan mod 60;
timespan = int(timespan/60);
mask = "h";
} else timestruct.m = 0;
// compute hours, days
if (mask eq "h") {
timestruct.h = timespan mod 24;
timestruct.d = int(timespan/24);
} else {
timestruct.h = 0;
timestruct.d = timespan;
}
}
return timestruct;
}
}
My first thought is to iterate Leigh's getNextRunTime(string taskName) function over the collection of tasks. You can get an array of structs containing the details of all scheduled tasks using taskArray = createobject("java","coldfusion.server.ServiceFactory").getCronService().listAll();
The key in the struct containing the task name is "task". So you can extract all the task names as an array for example, run Leigh's function on each element and determine which one will run next.