Its Friday afternoon and this issue drives me crazy
I can have multiple clients running with various users logged in which are validated against a database.
I created client timer event to check if Operator is logged in (validated against database) which works ok.
My problem is how can i build a logic to enable gateway event which is triggered only if at least 1 operator is logged in?
Its possible that we have 5 clients logged in as Operators and then suddenly all of them go for lunch and nobody is logged in as Operator.
Unfortunately system.security.getUsername is of no use for me because it checks the user who launched the client (which is kept inside ignition internal users).
Similarly system.util.getSessionInfo is checking against internal users (i am using database users).
@pturmel Would you be so kind to suggest anything?
@bkarabinchak.psi you also helped me in the past
Have your client time event send a message to the gateway with latest status every time it fires. Maintain a dictionary in the gateway in a script top level containing the status by client ID. Use a gateway timer event to regularly examine the dictionary to prune stale entries and update whatever global permission tags you need.
Wow thank you again - its nearly working - i am getting these messages fired at gateway properly but my understanding is that gateway fires message handler for each client event.
Could you please help me a little bit with the next step:
Maintain a dictionary in the gateway in a script top level containing the status by client ID
Not sure how to put it top level as i cannot enter anything above gateway message handler
Did you mean to put in in the project library script and then maintain by timer events to prune its content?
Yes. In general, I have events delegate to a project script function. (Event is just a one-liner passing event information as function arguments.) A project script can define lists and dictionary variables outside a function that will persist in gateway memory between project saves. You can add/remove dictionary keys, iterate over the dictionary, et cetera, and the dictionary will hold the values between events.
Marked as solution as everything works beautifully.
I worry a little bit i might not understand something fundamental:
I have events delegate to a project script function. (Event is just a one-liner passing event information as function arguments.)
In my implementation - in gateway event i am passing key,value to the function in the project module which adds the value to the dictionary (which is declared globally at the very top). This dictionary is maintained by time triggered script which retrieves the list of connected client IDs using system.util.getSessionInfo() and removes from the dictionary the values which are no longer valid.
Could you please show what pseudocode will look for the solution with delegates ?
Sounds like you’ve done it properly. I was using “delegate” as a verb.