return type for event in TinyOS - tinyos

I'm implementing a module using nesC for TinyOS. My modules uses interface Timer<> so I have to implement the event fired of the interface Timer, it is possible to return a value inside this implementation or an event must be always void?

The return type of the Timer.fired event is defined as void and this cannot be changed. Even if the type was non-void, the returned value would be delivered to the component that signals the event, which is some system component implementing the Timer interface.
In order to get some hints on how to solve your problem, please provide more details explaining for what purpose you want to return a value from the fired event, that is, who is expected to get and process the returned value.

Related

How to set a custom goal metric is an event which is tracked with Paramater.VALUE for a Firebase A/B testing

In my A/B testing (with Remote Configs), I want to know which variant performed better based on daily user engagement.
As I can not see the built-in goal metric "Daily user engagement" in the dashboard, so I want to create my custom.
Could I track an event with parameter VALUE and set it as a goal metric (based on its value) in A/B testing?
This is how want to do:
// Firebase Unity SDK
FirebaseAnalytics.LogEvent("time_spent", FirebaseAnalytics.ParameterValue, time_spent_in_seconds);
Thank you.
Declare an event in the class where you want the vent to be fired. I dont know the type of FirebaseAnalytics.ParameterValue as I am not familiar with firebase nor with your app. I will assume its a string:
public event EventHandler<string> raiseFirebaseEvent;
Wherever in your code (normally a different class where the event is declared, and after invoked which is the same) you need to add a listener to this event, this means to add a method to the event, to be called after in the event trigger.
In this other class you will have a method that will be the one to subscribe to the event:
prevate void FireBaseLogger(FirebaseAnalytics.ParameterValue value) {
FirebaseAnalytics.LogEvent("time_spent", value,
time_spent_in_seconds);
}
time_spent_in_seconds shoul be a variable of this other class I guess.
Somewhere in this class, usually in the constructor, or somewhere you know for sure that the code ejecution will go through there, you should subscribe to the event. For this you need a reference of your event holder class, where the event was declared:
EventHolderClassInstance.raiseFirebaseEvent += FireBaseLogger;
No arguments are passed in the subscription, just the method.
Then, in your EventHolderClass, when you invoke the event, passing the string parameter, the subscribed method will be called as long as the subscription was done prior the invocation.
raiseFirebaseEvent?.Invoke(this, FirebaseAnalytics.ParameterValue);
When there are no methods subscribed raiseFirebaseEvent is null, that is what the question mark is for. If there was no previous subscription raiseFirebaseEvent is null, and nothing happens.
In case FirebaseAnalytics.ParameterValueis not string type, change the type accordingly in the event and in the private method subscribed in the class where the listener is added, or where the subscription is made that means the same.
Not sure if that is what you were asking.

SDL Tridion 2011 Event System - On Workflow Process Finish

I'm using the SDL Tridion event system to fire a method (OnEmergencyRelease) once a Workflow Activity has been completed. However my method isn't being entered during testing, where I'm stepping some components through the workflow process.
I'm subscribing using the following code:
EventSystem.Subscribe<Component,
FinishProcessEventArgs>(OnEmergencyRelease, EventPhases.TransactionCommitted);
But OnEmergency is never being entered:
private void OnEmergencyRelease(Component component,
FinishProcessEventArgs args, EventPhases phase)
{
_log.Info("Emergency release entered");
}
Anyone have any ideas what I'm doing wrong here?
I know the event system is being picked up as I write to the log in the constructor of my class.
I can't tell you for sure what happens, but I suspect that the FinishProcessEventArgs is not called on the Component object itself. Maybe you should try intercept on an object 'higher up' in the class hierarchy.
Example: use Process (or ProcessInstance or even IdentifiableObject)
EventSystem.Subscribe<Process, FinishProcessEventArgs>(OnEmergencyRelease, EventPhases.TransactionCommitted);
Is the event firing? I would expect Finish Process events to fire when you explicitly invoke a finish process action, and probably not when you step the items through.

Why can't my NSOperation object receive async call back?

I subclass NSOperation to implement my operation.Let's call it MyOperation.
In the implementation of MyOperation, I override the main function and inside it I create some async network stuff and set the delegate to self(the operation object).But the operation objects never get those delegate callbacks, why? I didn't set finished before the callback are received.
Or does NSOperation just can't do that?
I find that if I manually "start" the operation, it will work. But if I add it to a operation queue, the operation is excuted but just can't get those callbacks.
If you're setting up your callback in the main method like this:
-(void)main{
// setup
object.delegate = self
}
then your main method will continue execution, complete, and go away before the delegate has a chance to complete the callback. You either need to override the start method in NSOperation and manually handle the isFinished and isExecuting properties, or you need to figure out a way to have the delegate method get called on an object that isn't going away.
See the NSOperation class reference for full details on overriding the proper methods and KVC notifications to make it work.

Event propagation in Qt

I've just the documentation on the Qt event system and the QEvent class. I'm interested in the behavior of the QObject::event() method. The documentation states:
This virtual function receives events to an object and should return true if the event e was recognized and processed.
What is the expected behavior when false is returned from the event() method? What else is attempted in order to handle the event? Is the event automatically forwarded to the parent object?
Note: I know the source is available, and I do have a copy. I'm ideally looking for some piece of documentation addressing this behavior.
I believe the best practice is to explicitly forward the events to the base-class event method if you do not wish to filter that event type (e.g. return QObject::event(event);) since the event function delegates events to specific handlers (e.g. QWidget::keyPressEvent).
QCoreApplication::notify propogates events based on the return value. On true, it considers the event as consumed and stops. Otherwise, the event is passed to the object's parent. For more information, see Events and Filters and Another Look at Events.
Some Events can be propagated.Event will be propagated to it's parent and it's parent recursively until it is processed. Take a look at this:https://doc.qt.io/archives/qq/qq11-events.html

Flex's FileReference.save() can only be called in a user event handler -- how can I get around this?

I need to call FileReference.save() after a web service call has completed, but this method has a restriction: "In Flash Player, you can only call this method successfully in response to a user event (for example, in an event handler for a mouse click or keypress event). Otherwise, calling this method results in Flash Player throwing an Error exception." (from the documentation here)
This restriction is a bit vague. Does it mean that I can only call the FileReference.save() method from within an event handler function that is registered as a listener for certain types of user events? If so then exactly which user events are valid? (Perhaps there's an event that will never be dispatched by user interaction with my application and I could register an event handler function for that event type and make the save() call from within that function?)
My difficulty is that I can't safely call the FileReference.save() method until my web service returns with the data that will be used as the argument of the FileReference.save() method call, so the event that triggers the FileReference.save() call is actually a ResultEvent rather than a user event, and I'm leery of dispatching a new (faux) user event type in order to be able to trigger the FileReference.save() call unless it's definitely a user event that would never be dispatched as a result of actual user interaction with my application.
In a nutshell what I'm doing now is this: I have a function that is registered as a handler for a button click. In this function I make my web service call to fetch data from the server. I also have a result handler function which gets invoked when the web service call completes, and it's in here that I want to call the FileReference.save() method since it's at this point that I know that the data is ready to be saved to a file. But the aforementioned restriction is blocking me from doing this -- I get an error:
Error #2176: Certain actions, such as those that display a pop-up window,
may only be invoked upon user interaction, for example by a mouse click
or button press.
I've tried many things to get around this such as creating a second mouse click event handler function with the FileReference.save() call within and calling it after a timeout interval (to give the web service time to complete), but I keep running into the same error -- maybe that approach doesn't work since the second function isn't registered as an event listener for the event type used as its argument.
I'm new to Flex development so perhaps I'm just not thinking about this in the right way. If anyone can suggest another approach I'd really appreciate it. Thanks in advance for your comments or suggestions.
--James
Adobe does this as a sort of security measure to ensure users are the ones messing with files rather than potentially harmful code. My understanding is that they enforce this by only allowing handlers of (click?) events that originate from UI components to execute the FileReference methods, so generating your own events programmatically will not work, although I have not tried to verify this. Unfortunately the best resolution I've found is to re-work the UI a bit to conform to this constraint. In your particular situation, you could make this a two click process with a button that says something like "Prepare Download", which changes to "Download File" after the web service is complete. This is less than ideal from a user perspective, but I don't think there's much else that can be done unless you can somehow complete your web service call prior to displaying the button that triggers the FileReference.save() call.
After struggling for that for well, a couple hours I found a workaround: you can use both mouseDown AND mouseUp events instead of just click.
For instance:
s:Button
mouseDown="prepare_PDF()"
mouseUp="save_PDF()"
Works fine for me!
Happy coding!
--Thomas
As a workaround I used the ExternalInterface class. I created a javascript function with this code
function downloadFile (url) {
window.open(url);
}
An in AS3 I call
var url = 'www.example.com/downloadfile.php?file_id=xxx';
ExternalInterface.call('downloadAttachmentFile', url);
So with that I transfer the file handling to JS/HTML.
This is a comment on Thomas' answer (I don't have enough XP to comment yet): The mousedown and mouseup workaround works nicely. Just a note that if you make any changes in prepare_PDF() that need 'undoing' in save_PDF(), then its a good idea to call that code on the mouseout event as well, since there might be a case that the user mousedown's on the button, but then moves the mouse away from the button.
This was particularly relevant for my case, in which we increase the size of a watermark on an image when the user clicks the download button (that triggers the .save() call). I reduce the size of the watermark down to normal on the mousedown and mouseout events.
I had this same issue, I chose to use flash.net methods. Call flash.net.navigateToURL(url); from an actionscript or navigateToURL(url); from mxml.
What i do to solve this is to show an alert message with an anonymous function so i don't have to create a button.
Alert.show("Do you wish to download the file?", "Confirm", Alert.OK | Alert.CANCEL, this, function (eventObj:CloseEvent):void {
if (eventObj.detail == Alert.OK) {
fileReference.save(zipOut.byteArray, dateFormater_titulo.format(new Date ()) + ".zip");
}//if
}/*function*/, null, Alert.OK);

Resources