// Called by the UPnP Remote I/O Microstack
// Implements the ForceDisconnect call, lets a CP disconnect this RIO client.
// If this RIO client is not connected, this call has no effect.
void UpnpRemoteIOClient_RemoteIO_ForceDisconnection(void* upnptoken)
{
	sem_wait(&RemoteIOLock);
	if (RIO->PeerConnection != NULL)
	{
		// Disconnect the socket
		ILibAsyncSocket_Disconnect(RIO->Session);

		// Set new connection state
		free(RIO->PeerConnection);
		RIO->PeerConnection = NULL;

		// Disconnect the session
		if (RIO->Session != NULL)
		{
			// Disconnect RemoteIOSession
			ILibAsyncSocket_Disconnect(RIO->Session);
		}
		// Event the new connection
		UpnpSetState_RemoteIOClient_RemoteIO_PeerConnection(RIO->RIOmicroStack,"");
		UpnpResponse_RemoteIOClient_RemoteIO_ForceDisconnection(upnptoken);
		sem_post(&RemoteIOLock);

		// Event the user
		if (RemoteIOConnectionChanged != NULL) RemoteIOConnectionChanged(RIO->PeerConnection);
	}
	else
	{
		UpnpResponse_RemoteIOClient_RemoteIO_ForceDisconnection(upnptoken);
		sem_post(&RemoteIOLock);
	}
}
// Called by the UPnP Remote I/O Microstack
// Implements the SetPeerOverride call, lets a CP connect this RIO client to
// a new URI. If this RIO client is currently connected, it will disconnect and
// switch to the new URI.
void UpnpRemoteIOClient_RemoteIO_SetPeerOverride(void* upnptoken,char* PeerConnection)
{
	struct parser_result* ParsedAddress = NULL;
	char* RemoteIOSessionPath = NULL;
	char* RemoteIOSessionAddress = NULL;
	int address = 0;

	
	if (upnptoken && (PeerConnection == NULL || (int)strlen(PeerConnection) < 7))
	{
		UpnpResponse_Error(upnptoken,700,"Invalid PeerConnection");
		return;
	}

	sem_wait(&RemoteIOLock);
	if (RIO->PeerConnection == NULL || strcmp(RIO->PeerConnection,PeerConnection) != 0)
	{
		if (RIO->PeerConnection != NULL)
		{
			// Disconnect the socket
			ILibAsyncSocket_Disconnect(RIO->Session);
			free(RIO->PeerConnection);
		}

		// Set the new session URI
		RIO->PeerConnection = (char*)malloc((int)strlen(PeerConnection) + 1);
		strcpy(RIO->PeerConnection,PeerConnection);

		// Event the new connection
		UpnpSetState_RemoteIOClient_RemoteIO_PeerConnection(RIO->RIOmicroStack,RIO->PeerConnection);

		// Connect session
		ParseUri(RIO->PeerConnection,&RemoteIOSessionAddress,&RIO->SessionPort,&RemoteIOSessionPath);
		free(RemoteIOSessionPath);

		ParsedAddress = ILibParseString(RemoteIOSessionAddress,0,(int)strlen(RemoteIOSessionAddress),".",1);

		address  = atoi(ParsedAddress->FirstResult->data);
		address += atoi(ParsedAddress->FirstResult->NextResult->data) << 8;
		address += atoi(ParsedAddress->FirstResult->NextResult->NextResult->data) << 16;
		address += atoi(ParsedAddress->FirstResult->NextResult->NextResult->NextResult->data) << 24;

		ILibAsyncSocket_ConnectTo(RIO->Session,0,address,RIO->SessionPort,NULL,NULL);
		ILibDestructParserResults(ParsedAddress);
		free(RemoteIOSessionAddress);
		sem_post(&RemoteIOLock);

		// Event the user
		if (RemoteIOConnectionChanged != NULL) RemoteIOConnectionChanged(RIO->PeerConnection);
	}
	else 
	{
		sem_post(&RemoteIOLock);
	}
	
	if(upnptoken) {UpnpResponse_RemoteIOClient_RemoteIO_SetPeerOverride(upnptoken);}
}
// PRIVATE - Called by the AsyncSocket module when the XRT socket as disconnected.
// This will cause the RIO Client to return to un-connected state.
void OnRemoteIODisconnectSink(void* socketModule, void *user)
{
	// Set new connection state
	free(RIO->PeerConnection);
	RIO->PeerConnection = NULL;

	// Event the user
	if (RemoteIOConnectionChanged != NULL) RemoteIOConnectionChanged(RIO->PeerConnection);

	// Event the new connection
	UpnpSetState_RemoteIOClient_RemoteIO_PeerConnection(RIO->RIOmicroStack,"");
}
コード例 #4
0
// Called by the UPnP Remote I/O Microstack
// Implements the ForceDisconnect call, lets a CP connect this RIO client
// to a URI if, and only if, this RIO client is not currently connected.
void UpnpRemoteIO_SetPeerInterlock(void* upnptoken,char* PeerConnection)
{
	struct parser_result* ParsedAddress = NULL;
	char* RemoteIOSessionPath = NULL;
	char* RemoteIOSessionAddress = NULL;
	int address = 0;

	if (PeerConnection == NULL || (int)strlen(PeerConnection) < 7)
	{
		UpnpResponse_Error(upnptoken,700,"Invalid PeerConnection");
		return;
	}

	sem_wait(&RemoteIOLock);
	if (RIO->PeerConnection == NULL)
	{
		RIO->PeerConnection = (char*)RIO_MALLOC((int)strlen(PeerConnection) + 1);
		strcpy(RIO->PeerConnection,PeerConnection);

		// Event the new connection
		UpnpSetState_RemoteIO_PeerConnection(RIO->RIOmicroStack,RIO->PeerConnection);

		// Connect session
		ParseUri(RIO->PeerConnection,&RemoteIOSessionAddress,&RIO->SessionPort,&RemoteIOSessionPath);
		RIO_FREE(RemoteIOSessionPath);

		ParsedAddress = ILibParseString(RemoteIOSessionAddress,0,(int)strlen(RemoteIOSessionAddress),".",1);

		address  = atoi(ParsedAddress->FirstResult->data);
		address += atoi(ParsedAddress->FirstResult->NextResult->data) << 8;
		address += atoi(ParsedAddress->FirstResult->NextResult->NextResult->data) << 16;
		address += atoi(ParsedAddress->FirstResult->NextResult->NextResult->NextResult->data) << 24;

		ILibConnectTo(RIO->Session,0,address,RIO->SessionPort);
		ILibDestructParserResults(ParsedAddress);
		RIO_FREE(RemoteIOSessionAddress);
		UpnpResponse_RemoteIO_SetPeerInterlock(upnptoken,RIO->PeerConnection);
		sem_post(&RemoteIOLock);

		// Event the user
		if (RemoteIOConnectionChanged != NULL) RemoteIOConnectionChanged(RIO->PeerConnection);
	}
	else
	{
		UpnpResponse_RemoteIO_SetPeerInterlock(upnptoken,RIO->PeerConnection);
		sem_post(&RemoteIOLock);
	}
}
// PRIVATE - Called by the AsyncSocket module when the XRT connection is established. Once connected,
// the stack immidiatly sends the XRT REQUEST command to get things started.
void OnRemoteIOConnectSink(void* socketModule, int Connected, void *user)
{
	if (Connected != 0)
	{
		// Send REQUEST command
		RemoteIO_SendCommand(RIO_REQUEST,RIO->PeerConnection,(int)strlen(RIO->PeerConnection),ILibAsyncSocket_MemoryOwnership_USER);
	}
	else
	{
		sem_wait(&RemoteIOLock);

		// Set new connection state
		if (RIO->PeerConnection != NULL) free(RIO->PeerConnection);
		RIO->PeerConnection = NULL;

		// Event the new connection
		UpnpSetState_RemoteIOClient_RemoteIO_PeerConnection(RIO->RIOmicroStack,"");

		sem_post(&RemoteIOLock);

		// Event the user
		if (RemoteIOConnectionChanged != NULL) RemoteIOConnectionChanged(RIO->PeerConnection);
	}
}
コード例 #6
0
// PRIVATE - Called by the AsyncSocket module when the XRT connection is established. Once connected,
// the stack immidiatly sends the XRT REQUEST command to get things started.
void OnRemoteIOConnectSink(void* socketModule, int Connected)
{
	if (Connected != 0)
	{
		// Send REQUEST command
		RemoteIO_SendCommand(RIO_REQUEST,RIO->PeerConnection,(int)strlen(RIO->PeerConnection));
	}
	else
	{
		sem_wait(&RemoteIOLock);

		// Set new connection state
		if (RIO->PeerConnection != NULL) RIO_FREE(RIO->PeerConnection);
		RIO->PeerConnection = NULL;

		// Event the new connection
		UpnpSetState_RemoteIO_PeerConnection(RIO->RIOmicroStack,"");

		sem_post(&RemoteIOLock);

		// Event the user
		if (RemoteIOConnectionChanged != NULL) RemoteIOConnectionChanged(RIO->PeerConnection);
	}
}