Get Gateway Context

Hello,

I am running into an issue when getting the gateway context while developing a module to write to tags.

The SDK example for writing to tags (located at Read and Write Tags | Ignition SDK Programmer's Guide) begins with the following code:

private void writeReadTagValue() throws Exception {    
    IgnitionGateway context = IgnitionGateway.get();
    GatewayTagManager tagManager = context.getTagManager();
    TagProvider provider = tagManager.getTagProvider("default"); 

I have been unable to find the proper library for the IgnitionGateway class. Could you point me to the library I need to include?

Thanks in advance!

Modules are given the GatewayContext in their setup methods. You should store it and/or pass it around.

IgnitionGateway is a private class.

1 Like

Hmmm. Don't know why those example use IgnitionGateway.get(). Modules are handed a module context during setup, and are expected to save it for anything like this. (Module context is a thin wrapper around a gateway context.)

{ Sigh. Sniped. }

The SDK doc refresh is being spearheaded by people with good intentions but the only involvement the dev team has is consultative / in review, AFAIK. It's not ideal, but we're all busy with 8.3 stuff :frowning:

Got it, thanks for the replies. The tag writing function is in a separate class from the GatewayHook, but still in the gateway scope. Since the context is set in the GatewayHook class, is there a recommended way to pass it over to the class with the tag writing function?

You can make the GatewayContext available as a static/global variable in your hook, or you can pass it via constructor, or you can do whatever other thing you want. It's just a programming decision, not an Ignition SDK decision. Pretend you needed to make the choice in a scenario that didn't involve Ignition at all.

1 Like

I was being a little unfair here.

All the docs start with this comment:

// This code example is Gateway scoped and assumes the `GatewayContext` object is available.

though it could be more clear that IgnitionGateway.get() is not how you actually get the context object, by passing GatewayContext as a param to the example function and truly leaving it as an exercise to the reader.

Is IgnitionGateway the name of the GatewayHook in the example?

No, it is the name of the IA non-documented class that implements the gateway context interface for the whole gateway. You should not use it in any module code. Use the gateway context instance that your gateway hook is handed during startup.

2 Likes