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.javaandStream.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.javaStream stream = new Stream();2. Create an instance of
Access.javaAccess 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
Accesslibrary JNI Wrapper InstanceAnyConnectApi.get().getAccess();Sample code to get
Streamlibrary JNI Wrapper InstanceAnyConnectApi.get().getStream();
SipJniWrapperlibrary 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
InitializingAccesslibraryTo initialize the
Accesslibrary, create one instance ofAccessBuilderand another instance ofAccessclass.Instance of
Accessclass can be created by callingbuild()method of theAccessBuilderclass.
Both classes' declarations are present inAccess.hfile.Follow the below steps exactly in the given order
1. Create an instance of
AccessBuilderclassstd::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
AccessclassAccess::Ptr access; if (builder.get()) { access = builder->build(); } else { NSLog(@"Failed to create Access library since Access builder is NULL"); }
InitializingStreamlibraryTo initialize
Streamlibrary, create an instance ofStreamclass. Instance ofStreamclass can be created by using an instance ofStreamBuilderclass, both classes' declarations are present inStream.hfile.1. Create an instance of
StreamBuilderclassStreamBuilder::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
accessinstance to the Stream librarystreamBuilder->setAccess(access);4. Create an instance of
StreamclassStream::Ptr stream; stream = streamBuilder->build();Above
builder,accessandstreaminstances will be used in code examples throughout this documentation foriOSsections
Updated almost 3 years ago