OpenersNotesSection(Spacer1)Details

For an application to make use of a WSTP link service, the application must do two things: 1) the application must browse for available services; and 2) the application must resolve the service names that it finds during the browse operation to get link connection details for connecting to the link service.

The WSTP library will send the the callback function f, the service name n, the name of the link, the link protocol and the link options necessary for calling one of the WSOpen functions to create a link to the service n.

Resolving a service name to its connection details is fundamentally an asynchronous operation. WSResolveLinkService() starts the resolve operation and returns immediately. The WSTP library will make callbacks to the application with the connection details as those connection details become available.

Because the WSTP library provides the connection details asynchronously, the callback function f must take care to protect access to shared resources such as data structures that might be accessed simultaneously from another thread.

The context object c is a pointer to any arbitrary object needed by the application to successfully resolve a link service.

Use (NonWLLink[WSStopResolvingLinkService(), paclet:ref/c/WSStopResolvingLinkService]) to stop the resolve operation.

WSResolveLinkService() returns 0 if the function succeeds and a nonzero value if the function fails.

The nonzero values returned from WSResolveLinkService() as a result of an error correspond to the WSE error codes in (RefLink[wstp.h, paclet:ref/file/wstp.h]) and as returned by (NonWLLink[WSError(), paclet:ref/c/WSError]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (1)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

#include <string.h> /* for memset, memcpy, etc... */
#include <stdio.h> /* for snprintf */
#include "wstp.h"

void ResolveCallbackFunction(WSENV e, WSServiceRef r, const char *serviceName, const char *linkName, const char *protocol, int options, void *context);

WSServiceRef startResolvingServiceWithNameAndProtocol(WSENV e, 
	const char *name, const char *protocol)
{
	WSServiceRef theRef;
	int apiResult = 0;

	apiResult = WSResolveLinkService(e, ResolveCallbackFunction, 
		protocol, name, NULL /* No context object for this example */,
		&theRef);
	if(apiResult != 0)
	{ /* Handle the error */ }

	return theRef;
}


void ResolveCallbackFunction(WSENV e, WSServiceRef r, const char *serviceName, const char *linkName, const char *protocol, int options, void *context)
{
	WSLINK newLink = (WSLINK)0;
	int error = 0;
	int argc = 0;
	const char *argv[] = {
		"Dummy value representing program name",
		"-linkname",
		(const char *)0,
		"-linkprotocol",
		(const char *)0,
		"-linkconnect",
		"-linkoptions",
		(const char *)0,
		/* The following NULL pointer terminates the argv array */
		(const char *)0 
	};

	char optionsBuffer[50];

	memset((void *)optionsBuffer, 0, sizeof(char) * 50));

	snprintf(optionsBuffer, 50, "%d", options);

	argv[2] = linkName;
	argv[4] = protocol;
	argv[7] = (const char *)optionsBuffer;

	argc = 8;

	newLink = WSOpenArgcArgv(e, argc, argv, &error);
	if(newLink == (WSLINK)0 || error != WSEOK)
	{ /* Handle the error */ }

	/* ... */

	return;
}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(NonWLLink[WSBrowseForLinkServices(), paclet:ref/c/WSBrowseForLinkServices])  ▪  (NonWLLink[WSStopBrowsingForLinkServices(), paclet:ref/c/WSStopBrowsingForLinkServices])  ▪  (NonWLLink[WSStopResolvingLinkService(), paclet:ref/c/WSStopResolvingLinkService])  ▪  (NonWLLink[WSRegisterLinkServiceWithPortAndHostname(), paclet:ref/c/WSRegisterLinkServiceWithPortAndHostname])  ▪  (NonWLLink[WSRegisterLinkServiceWithHostname(), paclet:ref/c/WSRegisterLinkServiceWithHostname])  ▪  (NonWLLink[WSRegisterLinkService(), paclet:ref/c/WSRegisterLinkService])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[WSTP C API Developer Guide (Mac OS X), paclet:tutorial/WSTPDeveloperGuide-MacintoshOverview])}, {▪(RefLinkPlain[WSTP C API Developer Guide (Unix and Linux), paclet:tutorial/WSTPDeveloperGuide-UnixOverview])}, {▪(RefLinkPlain[WSTP C API Developer Guide (Windows), paclet:tutorial/WSTPDeveloperGuide-WindowsOverview])}})}})