Is is possible to check if certain fd belongs to a epoll set? - epoll

Suppose I have a already constructed epoll set, is it possible to find out if a certain fd belongs to this epoll set? And is it possible to find out from this epoll set what events a certain fd is interested in?
Thanks.

Use epoll_ctl with the fd you want to check with the op argument EPOLL_CTL_ADD. If the fd is already registered then registration will fail with errno assigned with EEXIST.
If registration succeeds, then it is part of the epoll set so delete it from the set right away using epoll_ctl with the op argument EPOLL_CTL_DEL so that the set remains unchanged.
If you can add some more context to your problem then maybe we can come up with a better method.

You can use epoll_ctl with the file descriptor, if the file descriptor is not part of the set, epoll will return with an error: EBADF

Related

Ability to determine whether a custom suite of UserDefault exists, enabling custom behaviour when it’s initially created

I’m creating a custom suite for UserDefaults:
var store = UserDefaults(suiteName: "custom")
I however need to trigger specific behaviour based on whether the suite already exists or not.
To be specific, if the suite is not found, I want it to be initialised with preset key/value pairs. And if it was found, no special action needs to be taken. In a real-world scenario, imagine an app that initially launches with preset filters that you can individually delete (i.e. subsequent launches refers to the latest state of filters, as opposed to falling back on presets).
I know I could check for an empty state by checking for each preset’s availability, for example:
var found = 0
for key in presetKeys {
if let _ = UserDefaults(suiteName: "custom")?.object(forKey: key) {
found += 1
}
}
if found == 0 {
// empty suite
}
However, this isn’t helpful, as an empty state doesn’t indicate a first run. It could be because the user deleted all the presets they were automatically assigned. Furthermore, users can create their own key/value pairs to add into the suite. Their keys are dynamically generated ruling out an empty state check then (because I wouldn’t know what keys to look for).
To conclude, is there a way I can simply tell if a suite by a specified name already exists?
If yes, does the suite continue to exist even when all its key/value pairs were removed? I wouldn’t want a scenario whereby a user-triggered empty state results in the suite being permanently removed, therefore causing the next run of the app to automatically reload the presets because it’s mixing up an empty v new state.
Hope this makes sense!
There's no built-in way to check if a specific UserDefaults suite already exists.
However, you can create a special key with a Bool value, which you use as a flag for whether any of the preset values were modified.
does the suite continue to exist even when all its key/value pairs were removed?
Yes. A UserDefaults suite does not need to hold any values, it can be empty. Deleting all values from a suite does not affect the existence of the suite itself.

Add Sensorevents to CEP Engine and get a list of all properties

I want to build a CEP-Engine which is dynamic so you can add different event streams. As soon as a new stream is added, Esper should be able to read all the properties of the stream and put it into a list, for example. (For example integer id, long temperature, date timestamp etc.)
Is this possible in Esper?
Would be very grateful for any help
In order to add a stream at runtime you can use create-schema.
create schema MyStream(id int, ...)
For a stream that accepts events that an application sends using EPEventServive#sendEvent you should add the bus and public annotation (or set the equivalent compiler flags).
#public #buseventtype create schema MyStream(id int, ...)
You can now use this stream.
select * from MyStream
You can attach a listener and have it do some logic.
The Esper examples have a lot of detail. The create-schema is used in the "runtimeconfig" example.
Thank you for answering. I'm afraid I didn't make myself clear. I want to be able to add event streams where I don't know beforehand what kind of properties the events have. So I don't know before if there is an integer ID or if there is a date timestamp and which payload might be there. As soon as I add such an unknown event, Esper should examine the stream and return the contained properties of the stream to me.

Add UNKNOWN eventstreams to CEP Engine and get a list of all properties (payload) of this event

I want to be able to add event streams where I don't know beforehand what kind of properties the events have. So I don't know before if there is an integer ID or if there is a date timestamp and which payload might be there. As soon as I add such an unknown event, Esper should examine the stream and return the contained properties of the stream to me.
Thank you very much. That actually helps me a lot. But a function which returns all property names directly does not exist, does it? So I would have to use dynamic parameters (trial and error) until I know which ones exist in the eventstream.
Thank you for your help :)
See similar to Add Sensorevents to CEP Engine and get a list of all properties
In the case that you don't have some or all of the properties, you can add the stream without any properties or with those properties that you know that the events have. Here is how to add a stream where you don't know any properties in advance:
#public #buseventtype create schema MyStream()
You can now use EPEventServive#sendEvent to send events.
You can use this stream in various ways. You can simply select the event.
select * from MyStream
Or you can use the dynamic property names, those with a '?' questionmark appended to them. This can refer to properties that may or may not exist.
select id? as id from MyStream
The "id?" returns an Object-type value. You can use "cast" to make it, for instance, a double-type value to total up.
select id? as id, sum(cast(someNumericProperty?, double)) as total from MyStream where
When the property doesn't exist the "?" expression returns null. There is an "exists" function that returns true when the parameter that is a dynamic property exists.
I don't think the Esper runtime actually knows about any dynamic property until the EPL attempts to use that dynamic property. The runtime doesn't inspect any event for actual properties.
You can add your own user-defined function that determines what the property names may be for your specific event underlying. So when the underlying is a java.util.Map the user-defined function can return "event.keySet()".

How do maxKeyCount and addPositiveDiagnosisKeys interact?

I'm learning the new Contact Tracing API that Apple is releasing for iOS (in partnership with Google).
I'm not gasping the relationship of the maxKeyCount property on the CTExposureDetectionSession, and its relationship with the addPositiveDiagnosisKeys: completion: method.
What I understand
A CTExposureDetectionSession is the object that allows an app to ask the framework to start trying to match a list of published Diagnosis Keys against the local database of captured Rolling Proximity Identifiers.
The app would start by calling the activateWithCompletion: method on a new session, and then call addPositiveDiagnosisKeys: one or more times, to eventually inform the framework that no more keys are to be added by calling finishedPositiveDiagnosisKeysWithCompletion:.
That last call will also indicate the block to run upon detection completion, which will be called with a CTExposureDetectionSummary object informing the amount of Diagnosis Keys that the device has been exposed to.
What I do not understand
The maxKeyCount property doc says:
This property contains the maximum number of keys to provide to this API at once. This property’s value updates after each operation complete and before the completion handler is invoked. Use this property to throttle key downloads to avoid excessive buffering of keys in memory.
But the addPositiveDiagnosisKeys: method says:
Asynchronously adds the specified keys to the session to allow them to be checked for exposure. Each call to this method must include more keys than specified by the current value of <maxKeyCount>.
maxKeyCount seems to be a maximum, but the addPositiveDiagnosisKeys: requires me to call it with more keys than the maximum.
Am I expected to call the method with a superlist of the previously sent list? That doesn't seem to fit well with the "avoid excessive buffering of keys in memory" part - if I have to use an ever-growing list of keys.
And what does the This property’s value updates after each operation complete part?
The documentation of maxKeyCount is missing a not.
The Android Contact Tracing API documentation has an analogous interface:
/**
* Provides a list of diagnosis keys for contact checking. The keys are to be
* provided by a centralized service (e.g. synced from the server).
*
* When invoked after the requestProvideDiagnosisKeys callback, this triggers a * recalculation of contact status which can be obtained via hasContact()
* after the calculation has finished. *
* Should be called with a maximum of N keys at a time. */
Task<Status> provideDiagnosisKeys(List<DailyTracingKey> keys);
/**
* The maximum number of keys to pass into provideDiagnosisKeys at any given * time.
*/
int getMaxDiagnosisKeys();
As Paulw11 suggested in a comment, the maxKeyCount property seems to be a value intended for reading that stats how many Diagnosis Keys are to be sent to the API in a single call for the matching to be performed.
Callers should re-check the value before each call, since it may get updated after each call.
The fixed documentation of addPositiveDiagnosisKeys: should, then, read:
Each call to this method must NOT include more keys than specified by the current value of <maxKeyCount>.

Sending message with CAPL and dbc signal values

I am using CAPL to simulate a test envirmonet for some small tests and i am having problems sending messages or more specific setting up the values.
I am able to read Signal Values with $SignalName, also i am able to set signal values like that.
If i am using this code to send a message the message data is always 0:
on key 't'
{
message MessageName msg;
setSignal(SignalName,i);
write("Value: %d",i);
outport(msg);
}
Witch makes kinda sence becouse i think the message objects are intended to be used to send bytes witch you can access through msg.byte()
I know that i can set signals in messages by msg.SignalName, but again this seems not the right way. I think there should be a way to send a message and all the signals contained in the message are set to the values set by SetSignal() function. Otherwise the SetSignal Funktion is a bit useless
Maybe somebody has an idea.
Thank you
I am using CANalyzer version 8.2 and I do not have the option to use SetSignal(signal, value) function. Setting the signal values by accessing the message selectors seems to be a reasonable approach. However you used the function outport! You need to use the output function to transmit messages.
on key 't' {
message MessageName msg;
msg.signal1 = value1;
output(msg);
}
For this method the database has to be configured so that the message msg contains all the necessary signals (signal1).
If you want to set all signal values to the start values configured in the database use the function:
setSignalStartValues(message msg);
You can set up an interaction layer that will handle the messages as defined in the CAN database (DBC file) assigned to the node. The interaction layer will need some attributes in the database to define how the messages have to be sent. If not already present you may have to add these attributes. If the Tx messages are not sent as expected, check the attributes.
Function output() is useful if you want to implement (and fully control) the sending of the message yourself.
Instead of using SetSignal() it is also possible to write the signal using $SignalName = value;
See this support note:
https://kb.vector.com/upload_551/file/SN-IND-1-011_InteractionLayer(1).pdf
You may have to guess and experiment a bit. In the DBC files provided by a customer I found attribute values that are not mentioned in this document.

Resources