examples/Qt/ISFEditor/ISFEditor_app/Spout/SpoutSDK.cpp
//
// CheckReceiver
//
// If not yet inititalized, conects to the name provided or the active sender
//		if connected sets bConnected to true
//		if not connected sets bConnected to false
//		returns false
//
// Calls CheckSpoutPanel to find if the user has selected another sender
//		If so, changes globals g_SharedMemoryName, g_Width, g_Height, g_Format.
//		and the sender name will be different to that passed 
//		If not, no changes to global name and size
//
// Checks that the sender identified by the global name is present
//		the size of that sender is returned
//		If the global name or the sender width and height have changed they are returned to the caller.
//		Sets bConnected to true if the sender is OK
//			the caller has to detect the change and adjust any local textures etc.
//		Sets bConnected to false if the sender is closed and the global sender name is reset
//		Returns false
//
// Otherwise drops through and returns true
//

CheckReceiver
If not yet inititalized, conects to the name provided or the active sender
if connected sets bConnected to true
if not connected sets bConnected to false
returns false

Calls CheckSpoutPanel to find if the user has selected another sender
If so, changes globals g_SharedMemoryName, g_Width, g_Height, g_Format.
and the sender name will be different to that passed
If not, no changes to global name and size

Checks that the sender identified by the global name is present
the size of that sender is returned
If the global name or the sender width and height have changed they are returned to the caller.
Sets bConnected to true if the sender is OK
the caller has to detect the change and adjust any local textures etc.
Sets bConnected to false if the sender is closed and the global sender name is reset
Returns false

Otherwise drops through and returns true
CheckReceiver If not yet inititalized conects to the name provided or the active sender if connected sets bConnected to true if not connected sets bConnected to false returns false Calls CheckSpoutPanel to find if the user has selected another sender If so changes globals g_SharedMemoryName g_Width g_Height g_Format . and the sender name will be different to that passed If not no changes to global name and size Checks that the sender identified by the global name is present the size of that sender is returned If the global name or the sender width and height have changed they are returned to the caller . Sets bConnected to true if the sender is OK the caller has to detect the change and adjust any local textures etc . Sets bConnected to false if the sender is closed and the global sender name is reset Returns false Otherwise drops through and returns true
bool Spout::CheckReceiver(char* name, unsigned int &width, unsigned int &height, bool &bConnected)
{
	char newname[256];
	unsigned int newWidth, newHeight;
	DWORD dwFormat;
	HANDLE hShareHandle;	
	if(!bInitialized) {
		if(name[0] != 0)
			strcpy_s(newname, 256, name);
		else
			newname[0] = 0;
		if(OpenReceiver(newname, newWidth, newHeight)) {
			strcpy_s(name, 256, newname);
			width  = newWidth;
			height = newHeight;
			bConnected = true; 
			return false;
		}
		else {
			bConnected = false;
			return false;
		}
	} 
	CheckSpoutPanel();
	strcpy_s(newname, 256, g_SharedMemoryName);
	newWidth = g_Width; 
	newHeight = g_Height; 
	hShareHandle = g_ShareHandle;
	dwFormat = g_Format;
	if(interop.senders.CheckSender(newname, newWidth, newHeight, hShareHandle, dwFormat)) {
		if(newWidth > 0 && newHeight > 0) {
			if(newWidth  != width
			|| newHeight != height
			|| dwFormat  != g_Format
			|| strcmp(name, g_SharedMemoryName) != 0 ) { 
				if(OpenReceiver(g_SharedMemoryName, newWidth, newHeight)) {				
					g_Width = newWidth;
					g_Height = newHeight;
					g_ShareHandle = hShareHandle; 
					g_Format = dwFormat; 
					strcpy_s(name, 256, g_SharedMemoryName);
					width  = g_Width;
					height = g_Height;
					bConnected = true; 
					return false;
				} 
				else {
					bConnected = false;
					return false;
				}
			} 
		} 
		else {
			bConnected = false;
			return false;
		}
	} 
	else {
		g_SharedMemoryName[0] = 0; 
		ReleaseReceiver(); 
		bConnected = false;
		return false;
	} 
	bConnected = true;
	return true;
}
bool Spout :: CheckReceiver ( char * name , unsigned int & width , unsigned int & height , bool & bConnected ) { char newname [ 256 ] ; unsigned int newWidth , newHeight ; DWORD dwFormat ; HANDLE hShareHandle ; if ( ! bInitialized ) { if ( name [ 0 ] != 0 ) strcpy_s ( newname , 256 , name ) ; else newname [ 0 ] = 0 ; if ( OpenReceiver ( newname , newWidth , newHeight ) ) { strcpy_s ( name , 256 , newname ) ; width = newWidth ; height = newHeight ; bConnected = true ; return false ; } else { bConnected = false ; return false ; } } CheckSpoutPanel ( ) ; strcpy_s ( newname , 256 , g_SharedMemoryName ) ; newWidth = g_Width ; newHeight = g_Height ; hShareHandle = g_ShareHandle ; dwFormat = g_Format ; if ( interop . senders . CheckSender ( newname , newWidth , newHeight , hShareHandle , dwFormat ) ) { if ( newWidth > 0 && newHeight > 0 ) { if ( newWidth != width || newHeight != height || dwFormat != g_Format || strcmp ( name , g_SharedMemoryName ) != 0 ) { if ( OpenReceiver ( g_SharedMemoryName , newWidth , newHeight ) ) { g_Width = newWidth ; g_Height = newHeight ; g_ShareHandle = hShareHandle ; g_Format = dwFormat ; strcpy_s ( name , 256 , g_SharedMemoryName ) ; width = g_Width ; height = g_Height ; bConnected = true ; return false ; } else { bConnected = false ; return false ; } } } else { bConnected = false ; return false ; } } else { g_SharedMemoryName [ 0 ] = 0 ; ReleaseReceiver ( ) ; bConnected = false ; return false ; } bConnected = true ; return true ; }
CheckReceiver
If not yet inititalized, conects to the name provided or the active sender
if connected sets bConnected to true
if not connected sets bConnected to false
returns false
CheckReceiver If not yet inititalized conects to the name provided or the active sender if connected sets bConnected to true if not connected sets bConnected to false returns false
// Has it initialized yet ?
 // The name passed is the name to try to connect to unless the bUseActive flag is set
 // or the name is not initialized in which case it will try to find the active sender
 // Width and height are passed back as well
 // OpenReceiver will also set the global name, width, height and format
 // Pass back the new name, width and height to the caller
 // The change has to be detected by the application
 // user needs to check
 // Initialization failure - the sender is not there 
 // Quit to let the app try again
 // endif not initialized
 // Check to see if SpoutPanel has been opened
 // If it has been opened, the globals are reset
 // (g_SharedMemoryName, g_Width, g_Height, g_Format)
 // and the sender name will be different to that passed 
 // Set initial values to current globals to check for change with those passed in
 // width;
 // height;
 // Is the sender there ?
 // The sender exists, but has the width, height, texture format changed from those passed in
 // test of original name allows for CheckSpoutPanel above
 // Re-initialize the receiver
 // OpenReceiver will also set the global name, width, height and format
 // 09.09.15
 // 09.09.15
 // Return the new sender name and dimensions
 // The change has to be detected by the application
 // user needs to check for changes
 // OpenReceiver OK
 // need what here
 // width, height, format or name have changed
 // The sender exists and there are no changes
 // Drop through to return true
 // width and height are zero
 // need what here
 // endif CheckSender found a sender
 // sender no longer exists
 // 01.06.15 - safety
 // Start again
 // CheckSender did not find the sender - probably closed
 // The sender exists and there are no changes
