Initializing Libraries

This section guides you about how you should initiate Smarter AI platform libraries into your application.

The Initialization Procedure

📘

Android

The Smarter AI platform libraries provides 2 JNI wrappers - Access.java and Stream.java.

We recommend to create an instance of these 2 JNI wrappers in a single-tone design pattern.

To initiate Smarter AI platform libraries, you need to follow the steps below exactly in the given order

1. Create an instance of Stream.java

Stream stream = new Stream();

2. Create an instance of Access.java

Access access = new Access();

3. Give a cache directory to the access instance from application layer

access.setCacheDirectory(getFilesDir().getAbsolutePath());

Sample Code

The sample codes given below show 3 things:

  1. Initializing JNI wrapper API instance using single-tone design pattern
  2. Accessing the JNI wrapper API instance
  3. Setting the cache path

Initializing JNI wrapper API instance using single-tone design pattern

public class AnyConnectApi {
    private Stream stream;
    private Access access;

    private AnyConnectApi() {
        stream = new Stream(); //follow this order strictly
        access = new Access(); //follow this order strictly
    }

    private static AnyConnectApi anyConnectApi;

    public static AnyConnectApi get() {
        if (anyConnectApi == null) {
            synchronized (AnyConnectApi.class) {
                if (anyConnectApi == null) {
                    anyConnectApi = new AnyConnectApi();
                }
            }
        }
        return anyConnectApi;
    }

    public Access getAccess() {
        return access;
    }

    public Stream getStream() {
        return stream;
    }
}

Accessing the JNI wrapper API instance

Sample code to get Access library JNI Wrapper Instance

AnyConnectApi.get().getAccess();

Sample code to get Stream library JNI Wrapper Instance

AnyConnectApi.get().getStream();

SipJniWrapper library JNI Wrapper Instance

All the methods of this class are static and get called from the library. No need to take any instance of this class. Rather, wire up your application with this wrapper to consume data delivered from library to the application layer through the static methods.

Setting the cache path

Sample code to set the cache directory

AnyConnectApi.get().getAccess().setCacheDirectory(getFilesDir().getAbsolutePath());

📘

iOS

Initializing Access library

To initialize the Access library, create one instance of AccessBuilder and another instance of Access class.

Instance of Access class can be created by calling build() method of the AccessBuilder class.
Both classes' declarations are present in Access.h file.

Follow the below steps exactly in the given order

1. Create an instance of AccessBuilder class

std::shared_ptr<com::anyconnect::access::AccessBuilder> builder;
builder = AccessBuilder::getBuilder();

2. Set a cache directory to the Access library from application layer

builder->setCacheDirectory(directoryPath);

3. Create an instance of Access class

Access::Ptr access;
if (builder.get()) {
    access = builder->build();
} else {
    NSLog(@"Failed to create Access library since Access builder is NULL");
}

Initializing Stream library

To initialize Stream library, create an instance of Stream class. Instance of Stream class can be created by using an instance of StreamBuilder class, both classes' declarations are present in Stream.h file.

1. Create an instance of StreamBuilder class

StreamBuilder::Ptr streamBuilder = std::make_shared<StreamBuilder>();

2. Set a log directory and other initializing parameter to the Stream library

streamBuilder->setLogDirectory(logDirectory);
streamBuilder->setReceiveTimeout(3000);
streamBuilder->setMaxNetworkChangeTime(3000000);

3. Set previously created access instance to the Stream library

streamBuilder->setAccess(access);

4. Create an instance of Stream class

Stream::Ptr stream;
stream = streamBuilder->build();

Above builder, access and stream instances will be used in code examples throughout this documentation for iOS sections