AWECoreOS 8.A.4 User's Guide
Multi-Instance.c

Examples

/****************************************************************************
*
* Multi-Instance
* --------------
*
****************************************************************************
*
* Description: Demonstrate Multi Instance capabilities of the API. Supports single socket mode, and two socket mode.
*
* Copyright: (c) 2020 DSP Concepts, Inc. All rights reserved.
* 3235 Kifer Road
* Santa Clara, CA 95054-1527
*
* This example demonstrates the multi instance capabilities of AWE Core OS, as well as tuning interface logging.
* There are two modes, single socket (default) and twosocket.
*
* Single socket mode (default) creates two AWEOSInstances and a single AWECore 8 style Multi-Instance TCP tuning interface.
* You can specify the port number with cmd line option -portno:<int>, but a default of 15002 is used.
* Upon connection to AWE Server, a dropdown menu will appear in the top left corner, which toggles between the two instances.
* Try configuring the instances individually and recompiling, then reconnect. Notice how the information in Server changes as you toggle between instances. (see the pName changes below)
* With logging enabled (-enableLogging), a single log file will be created for both of the instances.
*
* Two socket mode (running with "-twockets") will also create two AWEOSInstances instances, but each with their own individual tuning interface TCP socket.
* By default, the first instance's socket is opened on port 15002, and the second on 15004. Port numbers can be specified with "-portno1:<int>" and "-portno2:<int>"
* Windows only allows one instance of AWE Server running on the PC, so to toggle between instances you must disconnect and reconnect to each individual port.
* With logging enabled (-enableLogging) in two socket mode, individual log files will be created per socket.
*
* This example does not have RT audio capabilities, it is simply meant to demonstrate multi instance functionality, however module regression tests can be run on each individual AWEOSInstance.
* Routing RT audio between AWE Core OS instances is the responsibility of the integrator.
*
***************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "AWECoreOS.h"
#include "ModuleList.h"
//globals for command line args
UINT32 portNo = 15002;
UINT32 portNo1 = 15002, portNo2 = 15004;
UINT32 twoSocketsFlag = 0;
UINT32 enableLoggingFlag = 0;
//Step 1: Declare an Array of AWEOSInstance pointers. Memory for the instances are allocated by aweOS_init()
AWEOSInstance* g_AWEOSInstanceArray[2];
//Step 2: Declare an AWEOSConfigParameters structure. The members of this structure determine the configuration of the AWEInstance members. For this example, it will be populated with defaults
static AWEOSConfigParameters configParams;
static AWEOSConfigParameters configParams2;
//Step 3: Define the module descriptor table from ModuleList.h that contains all modules
static const void* moduleDescriptorTable[] =
{
LISTOFCLASSOBJECTS
};
UINT32 moduleDescriptorTableSize = sizeof(moduleDescriptorTable) / sizeof(moduleDescriptorTable[0]);
static void usage(const char *program)
{
printf(
"Usage: %s [args]\n"
" -portno:<int> Port Number to open the single multi-instance tuning interface socket. Default 15002 \n"
" -twosockets If this flag is defined, then an individual tuning interface socket will be opened on each instance\n"
" -portno1:<int> twointerface mode only! port number to open the socket for the first instance. Default 15002\n"
" -portno2:<int> twointerface mode only! port number to open the socket for the second instance. Default 15004\n"
" -enableLogging Enable tuning interface logging. with -twosockets enabled, an individual tuning log file is generated per instance. Disabled by default.\n"
" -help show usage.\n"
"This program demonstrates multi instance functionality in AWE Core OS.\n",
program);
exit(0);
}
int main(int argc, char **argv)
{
UINT32 i;
if (1 == argc)
{
printf("No command line options specified. Opening in default single socket mode with TCP socket on port number %d \n", portNo);
}
else
{
for (i = 1; i < argc; i++)
{
const char *arg = argv[i];
if ((0 == strncmp(arg, "-portno:", 8)) && (0 != strncmp(arg, "-twosockets", 12)))
{
portNo = atoi(arg + 8);
printf("singlesocket mode: portno for socket is %d \n", portNo);
}
else if ((0 == strncmp(arg, "-portno1:", 9)))
{
portNo1 = atoi(arg + 9);
printf("twosockets mode: First socket will open on port %d \n", portNo1);
}
else if ((0 == strncmp(arg, "-portno2:", 9)))
{
portNo2 = atoi(arg + 9);
printf("twosockets mode: Second socket will open on port %d \n", portNo2);
}
else if (0 == strncmp(arg, "-twosockets", 12))
{
printf("twosockets mode enabled. Opening an individual socket for each of the two AWEOSInstances on ports %d and %d \n", portNo1, portNo2);
twoSocketsFlag = 1;
}
else if ((0 == strncmp(arg, "-enableLogging", 14)))
{
enableLoggingFlag = 1;
printf("enableLogging set to true. Tuning logging enabled\n");
}
else if ((0 == strncmp(arg, "-help", 5)))
{
usage(argv[0]);
}
else
{
printf("main: unknown option '%s'\n", arg);
}
}
}
//Step 4: Call this function with an arg to the user declared AWEOSConfigParameters structure.
//This populates the configParams structure with DSPC defined default values.
aweOS_getParamDefaults(&configParams);
aweOS_getParamDefaults(&configParams2);
//Step 5: Overwrite the first instances default name to "#1" and the second to "#2" so that we can see this reflected in Server
configParams.pName = "#1";
configParams2.pName = "#2";
//Step 6: Pass in the instance ID to the first instance. This will always be 0
configParams.instanceId = 0;
//Step 7: if the user is running with two individual tuning sockets per instance, then assign the instanceID of configParams2 to 0.
//This is because when using multiple tuning sockets, AWE Server sees each instance as its own individual target.
//For a single tuning interface that supports multiple instances, we set configParams2.instanceId to 16, this lets Server know that there are two AWEOSInstances on the same socket.
if(twoSocketsFlag == 1)
{
configParams2.instanceId = 0;
configParams.pName = "#1-sock";
configParams2.pName = "#2-sock2";
}
else
{
configParams2.instanceId = 16; //Note that the instance ID is 16 as opposed to 1. AWE Server takes instanceIds in the order of 0, 16, 32, etc...
}
//Step 8: Initialize the AWEOSInstance's with their own parameters that were previously set in the config structures.
INT32 ret = aweOS_init(&g_AWEOSInstanceArray[0], &configParams, moduleDescriptorTable, moduleDescriptorTableSize);
INT32 ret2 = aweOS_init(&g_AWEOSInstanceArray[1], &configParams2, moduleDescriptorTable, moduleDescriptorTableSize);
//Step 9: Check if the aweOS_init succeeded. If it didn't then terminate the executable.
if (ret != 0 && ret2 != 0)
{
printf("aweOS init failed, exiting application \n");
}
else
{
if (!twoSocketsFlag) //Open in single socket mode
{
printf("Single Socket Mode \n");
if (enableLoggingFlag)
{
INT32 loggingRet = aweOS_tuningLoggingEnable(g_AWEOSInstanceArray[0], "tuning_logs", "aweTuning", TUNING_LOG_INFO);
if (loggingRet != 0)
{
printf("failed to open tuning log: ret = %d\n", ret);
}
else
{
printf("Tuning Logging enabled, a single log file will be generated for both AWEOSInstances.\n");
}
}
//Step 10: Open the tuning interface.
INT32 interfaceRet = aweOS_tuningSocketOpen(g_AWEOSInstanceArray, portNo, 2);
if (interfaceRet != 0)
{
printf("failed to open aweOS integrated tuning interface \n");
}
else
{
printf("Succesfully opened a TCP single socket tuning interface on port number %d \n ", portNo);
}
}
else //Open in twosockets mode
{
if (enableLoggingFlag) //enable logging on the first socket
{
INT32 loggingRet = aweOS_tuningLoggingEnable(g_AWEOSInstanceArray[0], "tuning_logs", "aweTuning", TUNING_LOG_INFO);
if (loggingRet != 0)
{
printf("failed to open tuning log: ret = %d\n", ret);
}
else
{
printf("Tuning Logging enabled, individual log files created for socket %d \n", portNo1);
}
}
//Step 10: Open the tuning interface (on the first socket)
INT32 interfaceRet = aweOS_tuningSocketOpen(&g_AWEOSInstanceArray[0], portNo1, 1); //open the first tuning socket
if (interfaceRet != 0)
{
printf("failed to open aweOS integrated tuning interface \n");
}
else
{
printf("Successfully opened a TCP socket for the first AWEOSInstance on port number %d \n", portNo1);
}
if (enableLoggingFlag) //enable logging on the second socket
{
INT32 loggingRet = aweOS_tuningLoggingEnable(g_AWEOSInstanceArray[1], "tuning_logs", "aweTuning", TUNING_LOG_INFO);
if (loggingRet != 0)
{
printf("failed to open tuning log: ret = %d\n", ret);
}
else
{
printf("Tuning Logging enabled, individual log files created for socket %d \n", portNo2);
}
}
//Step 10: Open the tuning interface (on the second socket)
interfaceRet = aweOS_tuningSocketOpen(&g_AWEOSInstanceArray[1], portNo2, 1); //open the second tuning socket
if (interfaceRet != 0)
{
printf("failed to open aweOS integrated tuning interface \n");
}
else
{
printf("Successfully opened a TCP socket for the second AWEOSInstance on port number %d \n", portNo2);
}
}
//Step 10: Enter main idle loop
while (1)
{
sleep(1); //idle loop
}
}
return 0;
}
AWEOSConfigParameters::instanceId
INT32 instanceId
ID number of instance.
Definition: AWECoreOS.h:128
TUNING_LOG_INFO
#define TUNING_LOG_INFO
AWE Core OS internal tuning interface logging verbosity level: medium – log errors and header info fr...
Definition: AWECoreOS.h:52
AWEOSConfigParameters::pName
const char * pName
Name of target.
Definition: AWECoreOS.h:122
AWEOSInstance
void AWEOSInstance
The AWE Core OS Instance instance type.
Definition: AWECoreOS.h:95
aweOS_getParamDefaults
INT32 aweOS_getParamDefaults(AWEOSConfigParameters *aweParams)
Populates an AWEOSConfigParameters structure with defaults.
aweOS_tuningSocketOpen
INT32 aweOS_tuningSocketOpen(AWEOSInstance **pAWEOS, INT32 portNo, UINT32 numInstances)
Initialize and open an integrated TCP/IP tuning interface socket.
aweOS_tuningLoggingEnable
INT32 aweOS_tuningLoggingEnable(AWEOSInstance *pAWEOS, char *path, char *baseName, UINT32 verbosity)
Enable logging of the tuning packets sent and received by the AWEOSInstance.
aweOS_init
INT32 aweOS_init(AWEOSInstance **pAWEOS, const AWEOSConfigParameters *aweParams, const void *pModuleDescriptorTable, UINT32 moduleDescriptorTableSize)
Initialize the AWEOSInstance with the specified configuration parameters.
AWEOSConfigParameters
AWEOSConfigParameters.
Definition: AWECoreOS.h:106
AWECoreOS.h
The AWE Core OS API header file.