コード例 #1
0
int main( int argc, char **argv ) /*FOLD00*/
{
	if( argc < 2 )
	{
		printf( WIDE("Usage: %s [scUu]\n"), argv[0] );
		printf( WIDE("  s - server\n") );
		printf( WIDE("  c - client\n") );
		printf( WIDE(" s and c may be specified together to test single-process\n") );
      return 0;
	}
	while( argc > 1 )
	{
		char *p = argv[1];
		while( p[0] )
		{
			switch( p[0]  )
			{
			case 's':
			case 'S':
            l.flags.bServer = 1;
            break;
			case 'c':
			case 'C':
            l.flags.bClient = 1;
				break;
			}
         p++;
		}
		argv++;
      argc--;
	}
	if( l.flags.bServer )
	{
      OpenServer();
	}
	if( l.flags.bClient )
	{
      OpenClient();
		if( l.MsgBaseClient != INVALID_INDEX )
		{
		   // all tests are client based.
			Test1Byte();
		   // all tests are client based.
			Test1000Byte();
		}
	}
	else if( l.flags.bServer ) // hang out here waiting for clients...
      WakeableSleep( SLEEP_FOREVER );
   return 0;
}
コード例 #2
0
int main( int argc, char **argv )
{
   NetworkStart();
	if( argc < 2 )
	{
		printf( WIDE("Usage: %s [scUu]\n"), argv[0] );
		printf( WIDE("  s - server\n") );
		printf( WIDE("  c - client\n") );
		printf( WIDE("  U - use a unix socket instead of tcp\n") );
      printf( WIDE("  u - use a UDP socket instead of tcp\n") );
		printf( WIDE(" s and c may be specified together to test single-process\n") );
      return 0;
	}
	while( argc > 1 )
	{
		char *p = argv[1];
		while( p[0] )
		{
			switch( p[0]  )
			{
			case 's':
			case 'S':
            l.flags.bServer = 1;
            break;
			case 'c':
			case 'C':
            l.flags.bClient = 1;
				break;
			case 'U':
				l.flags.bUnix = 1;
            l.flags.bUDP = 0;
				break;
			case 'u':
				l.flags.bUDP = 1;
            l.flags.bUnix = 0;
            break;
			}
         p++;
		}
		argv++;
      argc--;
	}
	if( l.flags.bServer )
	{
      OpenServer();
	}
	if( l.flags.bClient )
	{
      OpenClient();
	}
	if( l.flags.bClient )
	{
	// all tests are client based.
		if( l.flags.bUDP )
		{
         UDPTest1Byte();
		}
		else
			TCPTest1Byte();
	// all tests are client based.
		if( l.flags.bUDP )
		{
         UDPTest1000Byte();
		}
		else
			TCPTest1000Byte();
	}
	else
      WakeableSleep( 10000 );
   return 0;
}
コード例 #3
0
ファイル: WidcommHandler.cpp プロジェクト: acmercyj/WMouseXP
void CWidcommHandler::OnDiscoveryComplete()
{

	if(!iDiscoverCommandSent)
		return;
	
	iDiscoverCommandSent = false;

	int services_found = 0;
	CSdpDiscoveryRec    SdpRecs[MAX_SERVICES_PER_DEVICE];
	
	UINT16 numrecs;
	
	
	if(DISCOVERY_RESULT_SUCCESS == GetLastDiscoveryResult(iDiscoveringDevice,&numrecs))
		;
	else
	{
		if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
			MessageBox(iHwnd,"Discovery Failed","Connect Failed",MB_OK | MB_ICONASTERISK);
	}


    services_found = ReadDiscoveryRecords(iDiscoveringDevice,MAX_SERVICES_PER_DEVICE,SdpRecs,&iDiscoveringGUID);


	
	if(iRequestedCommand == ESendFileSession)
	{
	
		if(services_found<=0)
		{
			this->iLabel->SetWindowText("OBEX Object Push not found on device.");
			MessageBox(iHwnd,"OBEX Object Push not found on selected device.\r\n\r\nWMouseXP can't send the mobile-side installer to it. \r\n\r\nPlease see \"Help\" for other installation methods:\r\n- Open \"wap.clearevo.com\" in your mobile's WAP browser and download WMouseXP directly.\r\n- Go to the installation path of this program and send the \"WMouseXP.jar\" via Bluetooth or phone's PC-Suite manually.","Send Failed",MB_OK | MB_ICONASTERISK);
			
			RevertToIdle(); //add hwnd, icon movement, icon animation rsc numbers, etc...
			return;		
		}
		else
		{
			for(int i=0;i<services_found;i++)
			{
				UINT8 rfcommscn;
				if(SdpRecs[i].FindRFCommScn(&rfcommscn))
				{
					
				
					//change icon to blue and start the icon
					//extract the jar to a temporary location...
					//do obex op to this device using this sdp record
					iLabel->SetWindowText("Sending File...");
				
					
					///////////////////////////////////////////////////
					


					
						{
						
							//AfxMessageBox(CString(iTmpObexFilePath));
							
							//send							
							if(OPP_CLIENT_SUCCESS == Push(iDiscoveringDevice,iTmpObexFilePath,SdpRecs[i]))
							{
							
							
							}
							else
							{
									if(OPP_CLIENT_SUCCESS == Push(iDiscoveringDevice,iTmpObexFilePath,SdpRecs[i]))
									{
									
									
									}
									else
									{
									
										MessageBox(iHwnd,"Temporary failure, Please try again.","Send Failed",MB_OK | MB_ICONASTERISK);
										RevertToIdle(); //add hwnd, icon movement, icon animation rsc numbers, etc...
										return;	

									}						

							}
							
							
													
						}


					

					
					
					return;
				}
			}
		
			this->iLabel->SetWindowText("No valid OBEX Object Push channels on device.");
			MessageBox(iHwnd,"No valid OBEX Object Push channels on device.\r\n\r\nWMouseXP can't send the mobile-side installer to it. \r\n\r\nPlease see \"Help\" for other installation methods:\r\n- Open \"wap.clearevo.com\" in your mobile's WAP browser and download WMouseXP directly.\r\n- Go to the installation path of this program and send the \"WMouseXP.jar\" via Bluetooth or phone's PC-Suite manually.","Send Failed",MB_OK | MB_ICONASTERISK);
			
			RevertToIdle(); //add hwnd, icon movement, icon animation rsc numbers, etc...
			return;	

		}
	}
	else
	{
		if(services_found<=0)
		{			
			iLabel->SetWindowText("WMouseXP not found on this device...");			
		}
		else
		{
			bool found = false;

			for(int i=0;i<services_found;i++)
			{
				UINT8 rfcommscn=0;
				if(SdpRecs[i].FindRFCommScn(&rfcommscn) && rfcommscn!=0)
				{					
					CWidcommFoundDevice* dev = (CWidcommFoundDevice*) iFoundDevices.GetAt(iCurDevice-1);										
					(dev->iWMouseXPscn) = rfcommscn;
					iWMouseXPDevicesIndex.Add(new int(iCurDevice-1));
					found = true;				
					break;
				}
			}
			
			if(!found)					
			{
				iLabel->SetWindowText("WMouseXP not found on this device...");				
			}
			
		}

		if(DoDiscoverWMouseXPThroughDeviceList())
		{
			;//wait until it finishes the list
		}
		else
		{
			//finished discovering all devices
			
			
			//see howmany devices remain in the list			
			if(iWMouseXPDevicesIndex.GetSize()==1)
			{
				//connect rfcomm to its scn
				int index = (*((int*)iWMouseXPDevicesIndex.GetAt(0)));

				CWidcommFoundDevice* dev = (CWidcommFoundDevice*) iFoundDevices.GetAt(index);					
				
				CString str = "Connecting to WMouseXP on ";
				str += dev->iName;									
				iLabel->SetWindowText(str);

				
				if (! m_RfCommIf.AssignScnValue(&iDiscoveringGUID,dev->iWMouseXPscn,m_serviceName))
				{
					iLabel->SetWindowText("Assign scn failed");
					RevertToIdle();				
					return;
				}

				 UINT8 sec_level = BTM_SEC_NONE;

				if (! m_RfCommIf.SetSecurityLevel(m_serviceName, sec_level , false))
				{
					/*dont give up - try continue - case from "Sébastien DOBLER" <*****@*****.**>
					iLabel->SetWindowText("Error setting security level");
					RevertToIdle();				
					return; */
				}


				CopyBDADDR(dev->iAddr,iDiscoveringDevice);

				if(PORT_RETURN_CODE::SUCCESS!= OpenClient(dev->iWMouseXPscn, dev->iAddr))
				{
					iLabel->SetWindowText("Error opening rfcomm connection");
					RevertToIdle();				
					return;					
				}
					

					


			}
			else
			if(iWMouseXPDevicesIndex.GetSize()<=0)
			{
				//show message
				if(!iUsingPrevDev)
				{
					iLabel->SetWindowText("Can't find any device with WMouseXP running");

					if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
						MessageBox(iHwnd,"Can't find any device with WMouseXP running:\r\n\r\n- Make sure your PC's Bluetooth is plugged-in/started and ready.\r\n- Make sure your phone's Bluetooth is ON and discoverable (\"show to all\").\r\n- Make sure your phone's WMouseXP (Mobile Side) is started and displaying \"Awaiting PC Side\".\r\n- Try Again.","Connect Failed",MB_OK | MB_ICONASTERISK);
				}
				else
				{
					iLabel->SetWindowText("Can't connect to WMouseXP on the Previous Phone");

					if(CWMouseXPDlg::curInstance && !(CWMouseXPDlg::curInstance->iAutoConnectCommand))						
						MessageBox(iHwnd,"Can't connect to WMouseXP on the Previous Phone:\r\n\r\n- Make sure your PC's Bluetooth is plugged-in/started and ready.\r\n- Make sure your phone's Bluetooth is ON and discoverable (\"show to all\").\r\n- Make sure your phone's WMouseXP (Mobile Side) is started and displaying \"Awaiting PC Side\".\r\n- If you don't want to use the previous phone, uncheck the \"Previous Phone\" box.\r\n- Try Again.","Connect Failed",MB_OK | MB_ICONASTERISK);
				}
				
				
				RevertToIdle();				
			}
			else// more than one device with WMouseXP found
			{				
				//let user choose the device like the msstack implementation
				int SelectedDev=-1;
				CSelectPhoneDialog dlg(EWidcommStack,&iFoundDevices,SelectedDev,CWMouseXPDlg::curInstance);

				if(IDOK == dlg.DoModal() && SelectedDev>=0)
				{
					//int index = (*((int*)iWMouseXPDevicesIndex.GetAt(SelectedDev))); That's for MS Stack style...
					int index = SelectedDev;

					CWidcommFoundDevice* dev = (CWidcommFoundDevice*) iFoundDevices.GetAt(index);					
					
					CString str = "Connecting to WMouseXP on ";
					str += dev->iName;									
					iLabel->SetWindowText(str);

					
					if (! m_RfCommIf.AssignScnValue(&iDiscoveringGUID,dev->iWMouseXPscn,m_serviceName))
					{
						iLabel->SetWindowText("Assign scn failed");
						RevertToIdle();				
						return;
					}

					 UINT8 sec_level = BTM_SEC_NONE;

					if (! m_RfCommIf.SetSecurityLevel(m_serviceName, sec_level , false))
					{
						iLabel->SetWindowText("Error setting security level");
						RevertToIdle();				
						return;					
					}


					CopyBDADDR(dev->iAddr,iDiscoveringDevice);

					if(PORT_RETURN_CODE::SUCCESS!= OpenClient(dev->iWMouseXPscn, dev->iAddr))
					{
						iLabel->SetWindowText("Error opening rfcomm connection");
						RevertToIdle();				
						return;					
					}
				}
				else
				{				
					RevertToIdle();				
				}



			}			
		
		}
		
	
	}
		
	
}