Type Aliases

std::function< void( LogCategory cat, std::string const &message)>


std::function< void(int cat, std::string const &message)>


std::function< void(std::string const &message)>


std::function< void(uint32_t rx, uint32_t tx, StreamTerminatorState terminator)>


std::function< void()>









TS3D_API_EXPORT StreamCacheServer &



StreamCacheServer &








Detailed Description

class StreamCacheServer

Allows an application to connect to a web-viewer client and stream CAD model data to it

Public Types

using LogCallback = std::function<void(LogCategory cat, std::string const &message)>

Function signature used for configuring stream-cache diagnostic logging callbacks

using LwsLogCallback = std::function<void(int cat, std::string const &message)>

Function signature used for configuring the libwebsockets logging callback.

using MessageCallback = std::function<void(std::string const &message)>

Function signature used for configuring stream-cache callbacks

using DataCallback = std::function<void(uint32_t rx, uint32_t tx, StreamTerminatorState terminator)>

Function signature used for configuring stream-cache I/O stats callbacks

using NotifyCallback = std::function<void()>

Function signature used for configuring stream-cache notify callbacks

Public Functions

TS3D_API_EXPORT StreamCacheServer()
TS3D_API_EXPORT ~StreamCacheServer()
TS3D_API_EXPORT StreamCacheServer(StreamCacheServer&&)
TS3D_API_EXPORT StreamCacheServer & operator= (StreamCacheServer &&)
StreamCacheServer(StreamCacheServer const&) = delete
StreamCacheServer &operator=(StreamCacheServer const&) = delete
TS3D_API_EXPORT bool Init (Config const &config, std::string &errorMessage)

Initializes the stream-cache using the given configuration. This must be called before the stream-cache can accept incoming connections and perform any model streaming, and must only be called once.

  • config – The configuration to be used for the stream-cache server.

  • errorMessage – Will contain an error message if the initialization failed, otherwise will be returned as empty.


true if the initialization succeeded, else false.

TS3D_API_EXPORT void Tick (std::chrono::milliseconds timeout=std::chrono::milliseconds{ -1 })

Performs a stream-cache processing cycle which will service the client connection and stream out model data. The function will return after completion of the cycle which is relatively short, and is therefore intended to be called repeatedly from within a loop.

After the cycle is complete, if a positive timeout value was set either via the configuration ‘tickTimeout’ setting, or by the ‘timeout’ function argument, then the function will sleep for that specified amount of time. This will ensure the current thread yields and allows other threads processing time.


timeout – Optional parameter that, when set to a positive value, will override the configuration ‘tickTimeout’ value and cause the tick() function to sleep at the end of its processing cycle.

TS3D_API_EXPORT void Stop ()

Shuts down the stream-cache and performs any final cleanup. After calling this, the tick() function should not be called again.

struct Config

Use to configure the various settings used by the stream-cache.

Public Members

uint16_t port = 0

A networking port used for websocket communications with the web-viewer client.

RenderingLocation enabledRenderingLocations = RenderingLocation::RenderingLocationDefault

Determines if client and/or server rendering is allowed. It’s valid to set either mode, or both. The web-viewer will request the type of rendering when it first connects, and will only succeeded if the matching type has been enabled with this setting.

std::string license

A valid HOOPS Communicator license must be specified

SC::Store::MemoryDevice *memoryDevice = nullptr

An optional stream-cache memory device which is useful for sandboxing file I/O within application memory. See sc_store.h for more information. If this is set to a valid memory device, the paths defined by ‘workspaceDir’ and ‘modelSearchDirs’ must point to directories within this device. If it is null, then those directories will be interpreted within the standard filesystem or inside the given fileSystem if not null.

SC::IO::AbstractFilesystem *fileSystem = nullptr

An optional custom file system interface to customize how the server read and write files. Will be ignored if memoryDevice is already defined. See sc_io.h for more information.

std::string workspaceDir

An optional path to a directory that will be used for temporary storage. If this setting is empty, the current working directory will be used.

std::string modelSearchDirs

A list of directory paths to be used when searching for a model file. This is a single string with each directory path concatenated, and using a single semi-colon character to separate each path.

std::string modelFile

An optional relative-only file path that, when set to a non-empty string, will override any model requested by the web-viewer client. This should be a model file name that exists within the specified ‘modelSearchDirs’ setting. ie. “bnc”.

std::string sessionToken

An optional token that must be shared with the web-viewer client. The string is simply compared for equality against the session token provided by the client, thus there is no format specification.

std::string sslCertificateFile

A file path to an SSL certificate, which is needed to support the ‘wss’ protocol.

std::string sslPrivateKeyFile

A file path to an SSL private key, which is needed to support the ‘wss’ protocol.

uint32_t ssrGpuIndex = std::numeric_limits<uint32_t>::max()

Optional 0-based index for specifying which GPU to be used. If set to ‘std::numeric_limits<uint32_t>::max()’, then the server will use the default GPU

std::chrono::milliseconds tickTimeout = std::chrono::milliseconds{-1}

Indicates the amount of time that the tick() function will sleep for after performing a work cycle. The value here will set the internal default used when the tick() function is called with no value. It can be overridden by providing an explicit value to the tick() function. A negative value will result in the tick() call not sleeping after the work cycle.

bool kickOnNewConnection = false

When true, this indicates that this stream-cache session should should allow a new web-viewer connection to take priority over the existing connection. If this happens, the existing connection will be closed, and the new connection can proceed.

std::string rpcLogFileWrite

Specifies an optional file path that will be used to record server-side rendering commands for later replay via the ‘rpcLogFileRead’ setting.

std::string rpcLogFileRead

Specifies an optional file path to a server-side rendering log session that will be replayed upon a “bounding” event trigger

bool verboseLogging = false

If true, increased diagnostic messages will be sent to the onDebug callback.

LwsLogCategory lwsLogLevel = LwsLogCategoryNone

This will set the enabled log-levels for the internal libwebsocket library. It can be a bitwise-or of LwsLogCategory values.

LwsLogCallback onLwsLog

Optional function that will receive the libwebsocket log messages that were enabled by the ‘lowLogLevel’ setting.

LogCallback onLog

Optional function that will receive a stream-cache log messages

MessageCallback onDisconnect

Optional function that will be called upon a client disconnect. The message indicates why the client disconnected.

DataCallback onData

Optional function that will be called with incremental data transmit and receive statistics.

NotifyCallback onInitialUse

Optional function that will be called upon the initial client connection

bool ssrEgl = false

If true, and the server is running on a Linux system, will use EGL for OpenGL context creation in the case of Server Side Rendering. The use of this option is recommended for headless server environments which are equipped with graphics cards.