how to use global Event listener? - blackberry

i want to communicate between two applications, whenever blackberry messenger is open then at that time my application can notified that,this blackberry messenger is started.
how could i do with the use of global event listener..
thanks a lot.

Have you read this primer here
http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800620/What_Is_-_Global_Events_and_Global_Event_Listeners.html?nodeid=800527&vernum=0

2 applications OR Background application and foreground application can communicated through GlobalEventListener
Implemented the GlobalEventListener interface
Register for global event using the below line
addGlobalEventListener(instance of class which implement the GlobalEventListener );
From background application
post the global events (for other application) using the below line
ApplicationManager.getApplicationManager().postGlobalEvent(MainWindow.GUID);
Note : postGlobalEvent methods having the 4 overloaded versions
So you can pass addition info as well if require
Following method of GlobalEventListener interface method will listen the global event
public void eventOccurred(long guid, int data0, int data1, Object object0, Object object1)
see the links for more details
http://www.blackberry.com/developers/docs/5.0.0api/net/rim/device/api/system/GlobalEventListener.html
http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/system/Application.html#addGlobalEventListener%28net.rim.device.api.system.GlobalEventListener%29

Related

How to pass native void pointers to a Dart Isolate - without copying?

I am working on exposing an audio library (C library) for Dart. To trigger the audio engine, it requires a few initializations steps (non blocking for UI), then audio processing is triggered with a perform function, which is blocking (audio processing is a heavy task). That is why I came to read about Dart isolates.
My first thought was that I only needed to call the performance method in the isolate, but it doesn't seem possible, since the perform function takes the engine state as first argument - this engine state is an opaque pointer ( Pointer in dart:ffi ). When trying to pass engine state to a new isolate with compute function, Dart VM returns an error - it cannot pass C pointers to an isolate.
I could not find a way to pass this data to the isolate, I assume this is due to the separate memory of main isolate and the one I'm creating.
So, I should probably manage the entire engine state in the isolate which means :
Create the engine state
Initialize it with some options (strings)
trigger the perform function
control audio at runtime
I couldn't find any example on how to perform this actions in the isolate, but triggered from main thread/isolate. Neither on how to manage isolate memory (keep the engine state, and use it). Of course I could do
Here is a non-isolated example of what I want to do :
Pointer<Void> engineState = createEngineState();
initEngine(engineState, parametersString);
startEngine(engineState);
perform(engineState);
And at runtime, triggered by UI actions (like slider value changed, or button clicked) :
setEngineControl(engineState, valueToSet);
double controleValue = getEngineControl(engineState);
The engine state could be encapsulated in a class, I don't think it really matters here.
Whether it is a class or an opaque datatype, I can't find how to manage and keep this state, and perform triggers from main thread (processed in isolate). Any idea ?
In advance, thanks.
PS: I notice, while writing, that my question/explaination may not be precise, I have to say I'm a bit lost here, since I never used Dart Isolates. Please tell me if some information is missing.
EDIT April 24th :
It seems to be working with creating and managing object state inside the Isolate. But the main problem isn't solved. Because the perform method is actually blocking while it is not completed, there is no way to still receive messages in the isolate.
An option I thought first was to use the performBlock method, which only performs a block of audio samples. Like this :
while(performBlock(engineState)) {
// listen messages, and do something
}
But this doesn't seem to work, process is still blocked until audio performance finishes. Even if this loop is called in an async method in the isolate, it blocks, and no message are read.
I now think about the possibility to pass the Pointer<Void> managed in main isolate to another, that would then be the worker (for perform method only), and then be able to trigger some control methods from main isolate.
The isolate Dart package provides a registry sub library to manage some shared memory. But it is still impossible to pass void pointer between isolates.
[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: Invalid argument(s): Native objects (from dart:ffi) such as Pointers and Structs cannot be passed between isolates.
Has anyone already met this kind of situation ?
It is possible to get an address which this Pointer points to as a number and construct a new Pointer from this address (see Pointer.address and Pointer.fromAddress()). Since numbers can freely be passed between isolates, this can be used to pass native pointers between them.
In your case that could be done, for example, like this (I used Flutter's compute to make the example a bit simpler but that would apparently work with explicitly using Send/ReceivePorts as well)
// Callback to be used in a backround isolate.
// Returns address of the new engine.
int initEngine(String parameters) {
Pointer<Void> engineState = createEngineState();
initEngine(engineState, parameters);
startEngine(engineState);
return engineState.address;
}
// Callback to be used in a backround isolate.
// Does whichever processing is needed using the given engine.
void processWithEngine(int engineStateAddress) {
final engineState = Pointer<Void>.fromAddress(engineStateAddress);
process(engineState);
}
void main() {
// Initialize the engine in a background isolate.
final address = compute(initEngine, "parameters");
final engineState = Pointer<Void>.fromAddress(address);
// Do some heavy computation in a background isolate using the engine.
compute(processWithEngine, engineState.address);
}
I ended up doing the processing of callbacks inside the audio loop itself.
while(performAudio())
{
tasks.forEach((String key, List<int> value) {
double val = getCallback(key);
value.forEach((int element) {
callbackPort.send([element, val]);
});
});
}
Where the 'val' is the thing you want to send to callback. The list of int 'value' is a list of callback index.
Let's say you audio loop performs with vector size of 512 samples, you will be able to pass your callbacks after every 512 audio samples are processed, which means 48000 / 512 times per second (assuming you sample rate is 48000). This method is not the best one but it works, I still have to see if it works in very intensive processing context though. Here, it has been thought for realtime audio, but it could work the same for audio rendering.
You can see the full code here : https://framagit.org/johannphilippe/csounddart/-/blob/master/lib/csoundnative.dart

How to find if electron app is in foreground?

I have a requirement where I want to perform an action inside the electron app only when it is in foreground.
It is an electron-react application. On mounting of a component, I want to schedule a periodic task which only runs when the app is in focus or is being used by the user. And pause the task when the app goes in background.
How can we detect the Electron app being in foreground?
You can use the isFocused method from BrowserWindow. To get your own BrowserWindow, you can do this :
remote.BrowserWindow.getAllWindows();
This will return all your app's windows. So to get the first / primary window, you could deconstruct the array like this :
const [yourBrowserWindow] = remote.BrowserWindow.getAllWindows();
console.log(yourBrowserWindow.isFocused());
You can use the focus / blur events on your BrowserWindow to be notified when the app is focused / unfocused.
mainWindow = new BrowserWindow({})
mainWindow.on('focus', () => {
console.log('window got focus')
})
mainWindow.on('blur', () => {
console.log('window blur')
})
You may want to update the component's state within these event handlers or use any other method to keep track of the current focus status.
This assumes that you have a single application window. If you have multiple, you'll need to extend the check to cover all of your windows.

Delete Data from Web SQL database whenever phonegap Application's exit event occurs

I have two Questions:
What is the exit event of phone-gap Application? I haven't find it yet.
How to Delete Data from All the tables whenever exit event occurs? and insert it back from the web service whenever the deviceready() event of phonegap occurs.
Thanks in advance.
Regards.
I think you are looking for the pause event. The documentation reads like this:
The pause event fires when the native platform puts the application into the background, typically when the user switches to a different application.
You can attach a handler to this event like this:
document.addEventListener("pause", onPause, false);
Now the onPause method will be called everytime your app is going to the background and you can drop your tables there somewhat like this:
function onPause() {
db.transaction(function (tx) {
tx.executeSql("DROP TABLE foo",[],
function(tx,results){console.log("Successfully Dropped")},
function(tx,error){console.log("Could not delete")}
);
});
}
Assuming the db variable holds your WebSQL database and you're trying to drop the table named foo.

Reminder using Signal R

I have a reminder functionality using signal R in asp.net mvc
I have userinterface to set the reminder time, If the current time matches the reminder time , it invokes a popup.
I successfully implemented this functionality with Signal R by checking the database once in every 30 seconds by using javascript timer. If current time does not match, it gives '0'.If it matches, it return '1' and the popup is shown across all browsers. But can this checking the db for every 30 seconds can be replaced by signal R ? is there any way to bring this whole thing to signal R?
You can use System.Threading.Timer to create a periodical method call to both client and server side. According to Sample project created for stocks
_timer = new Timer(UpdateStockPrices, null, _updateInterval, _updateInterval);
It creates and Event-Delegate and calls UpdateStockPrices event timely with period of __updateInterval.
In This event(code given below) you can broadcast the remainder message from server to all clients or clients who are associated with that remainder.
You can write code as :-
Clients.All.updateStockPrice(stock);
You can refer to Timer from link:-
http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx
Yes, you can use Timer in the appdomain scope, application scope or at the hub level. Just get the sample from nuget, called "Microsoft.AspNet.SignalR.Sample". It implements stock timer that periodically broadcasts changes to all clients.

What is the equivalent for flash/actionscirpt based addEventListener, removeEventListener and dispatchEvent in IOS

AS some one porting code from actionscript to IOS, We have a lot of custom components that follow the event dispatching mechanism in Flash/Actionscript:
E.g. dispatcher:
dispatchEvent(new CustomEvent(CustomEvent.DRAG_DROP));
Consumer:
dispatcher.addEventListener(CustomEvent.DRAG_DROP, actionHandler);
private function actionHandler(event:CustomEvent):void {
trace("actionHandler: " + event);
}
I know of NSNotificationCenter, KVO pattern, action-target, but none seem to be an exact match?
Where would I define CustomEvent? CustomEvent.DRAG_DROP? and how would the consumer listen for the event? How would a consumer know of all the events that a dispatcher can dispatch? I do not wish to use a delegate because there could be multiple consumers.
The closes way I know is selectors ...
// store event handler
SEL targetHandler;
// firing an event
[targetHandler performSelector:targetHandler withObject:eventObj];
// event handler in the listening class
- (void) onStuffHappened: (Event*) event
{
}
that's obviously a quick thought, I would extend NSObject and store handlers in NSMutableArray then run performSelector on all the stored handlers ... something like that
or you can use delegates for a cleaner way.
Generally this is done with a list of delegates. If you want a multiple consumers, define a protocol (just like you would for a delegate), and then create an array of those objects. When you want to communicate with all of the listeners iterate through the list of listeners sending the event to each one.

Resources