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
andStream.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 CodeThe sample codes given below show 3 things:
- Initializing JNI wrapper API instance using single-tone design pattern
- Accessing the JNI wrapper API instance
- Setting the cache path
Initializing JNI wrapper API instance using single-tone design patternpublic 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 instanceSample code to get
Access
library JNI Wrapper InstanceAnyConnectApi.get().getAccess();
Sample code to get
Stream
library JNI Wrapper InstanceAnyConnectApi.get().getStream();
SipJniWrapper
library JNI Wrapper InstanceAll 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 pathSample code to set the cache directory
AnyConnectApi.get().getAccess().setCacheDirectory(getFilesDir().getAbsolutePath());
iOS
InitializingAccess
libraryTo initialize the
Access
library, create one instance ofAccessBuilder
and another instance ofAccess
class.Instance of
Access
class can be created by callingbuild()
method of theAccessBuilder
class.
Both classes' declarations are present inAccess.h
file.Follow the below steps exactly in the given order
1. Create an instance of
AccessBuilder
classstd::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
classAccess::Ptr access; if (builder.get()) { access = builder->build(); } else { NSLog(@"Failed to create Access library since Access builder is NULL"); }
InitializingStream
libraryTo initialize
Stream
library, create an instance ofStream
class. Instance ofStream
class can be created by using an instance ofStreamBuilder
class, both classes' declarations are present inStream.h
file.1. Create an instance of
StreamBuilder
classStreamBuilder::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 librarystreamBuilder->setAccess(access);
4. Create an instance of
Stream
classStream::Ptr stream; stream = streamBuilder->build();
Above
builder
,access
andstream
instances will be used in code examples throughout this documentation foriOS
sections
Updated over 2 years ago