static void TestBasic(ow_test_context Context) { set Set; InitPosixNetClientSet(&Set); CreateClient(&Set, 12); CreateClient(&Set, 34); iterator Iterator = CreatePosixNetClientSetIterator(&Set); OW_AssertTrue(AdvancePosixNetClientSetIterator(&Iterator)); OW_AssertEqualInt(12, Iterator.Client->FD); OW_AssertTrue(AdvancePosixNetClientSetIterator(&Iterator)); OW_AssertEqualInt(34, Iterator.Client->FD); OW_AssertFalse(AdvancePosixNetClientSetIterator(&Iterator)); TerminatePosixNetClientSet(&Set); }
LRESULT CXTPTaskDialogFrame::OnDialogNavigatePage(WPARAM /*wParam*/, LPARAM lParam) { TASKDIALOGCONFIG* pConfig = (TASKDIALOGCONFIG*)lParam; m_pConfig = pConfig; KillTimer(1); SetWindowText(GetFrameTitle()); if (!CreateClient(FALSE)) { TRACE0("Failed to create Task Dialog UI window.\n"); return FALSE; } OnInitDialog(); // inform callback Task Dialog was constructed. SendNotify(TDN_DIALOG_CONSTRUCTED); SendNotify(TDN_NAVIGATED); return TRUE; }
CComPtr<IAudioClient> CreateDefaultClient( EDataFlow data_flow, ERole role) { //ASSERT(IsSupported()); CComPtr<IMMDevice> default_device(CreateDefaultDevice(data_flow, role)); return (default_device ? CreateClient(default_device) : CComPtr<IAudioClient>()); }
int CXTPTaskDialogFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CXTPTaskDialogClient::OnCreate(lpCreateStruct) == -1) return -1; SetWindowText(GetFrameTitle()); if (m_pConfig->pszMainIcon == TD_WARNING_ICON) MessageBeep(MB_ICONEXCLAMATION); if (m_pConfig->pszMainIcon == TD_ERROR_ICON) MessageBeep(MB_ICONERROR); if (m_pConfig->pszMainIcon == TD_INFORMATION_ICON) MessageBeep(MB_ICONINFORMATION); if (!CreateClient(TRUE)) { TRACE0("Failed to create Task Dialog UI window.\n"); return FALSE; } // inform callback Task Dialog was constructed. SendNotify(TDN_DIALOG_CONSTRUCTED); // inform callback Task Dialog was created. SendNotify(TDN_CREATED); return 0; }
// ----------------------------------------------------------------------------- // LoginTimeout // ----------------------------------------------------------------------------- // void CHotSpotSession::LoginTimeout() { DEBUG1("CHotSpotSession::LoginTimeout iIapId :%d", iIapId ); iServer.SetLogoutFlag( ETrue ); // if message is not found, client has not completed it (LoginComplete(..)) TInt indx = iServer.FindMessage( iIapId, EHssStartLogin ); if ( KErrNotFound != indx ) { iServer.CompleteMessage( indx, KErrCancel ); } TBuf8<KExtensionAPILength> extAPI; TBuf<KUidLength> clientUid; TInt err = iServer.GetClientUid( iIapId, clientUid ); if ( err != KErrNotFound ) { DEBUG("CHotSpotSession::LoginTimeout clientUid = CLIENT"); ConvertTBufToTUid( clientUid ); TBuf8<KExtensionAPILength> nullBuf; TInt ret = CreateClient( iClientUid, nullBuf ); DEBUG1("CHotSpotSession::LoginTimeout CreateClient ret: %d", ret); if ( KErrNone == ret ) { iClient->CancelLogin( iIapId ); } } DEBUG("CHotSpotSession::LoginTimeout Done"); }
RoboRobo* RoboRoboFactory::Create() { auto client = std::unique_ptr<gloox::Client>(CreateClient()); auto commandsMap = std::make_unique<CommandsMap>(); const CommandsMap& commandsMapRef = *commandsMap; auto messageHandler = new MessageHandler(*client, std::move(commandsMap)); auto connectionListener = new ConnectionListener(*client); client->registerMessageHandler(messageHandler); client->registerConnectionListener(connectionListener); auto soundPlayer = SoundPlayerFactory::CreateUniquePointer(); auto synthesizer = SpeechSynthesizerFactory::CreateUniquePointer(*soundPlayer); auto gpio = GpioFactory::CreateUniquePointer(); messageHandler->RegisterDefaultCommand(std::move(std::make_unique<UnknownCommand>())); messageHandler->RegisterCommand('s', std::move(std::make_unique<ServoCommand>(*gpio))); messageHandler->RegisterCommand('l', std::move(std::make_unique<LedCommand>(*gpio))); messageHandler->RegisterCommand('t', std::move(std::make_unique<TellCommand>(*synthesizer))); messageHandler->RegisterCommand('p', std::move(std::make_unique<PlaySoundCommand>(*soundPlayer))); messageHandler->RegisterCommand('h', std::move(std::make_unique<HelpCommand>(commandsMapRef))); auto robo = new RoboRobo(std::move(gpio), std::move(soundPlayer), std::move(synthesizer), std::move(client)); return robo; }
/* * Setup the Simple Client * @returns true on success, false on failure */ bool BaseClientWrapper::Setup() { if (!m_ss) m_ss = new SelectServer(); if (!m_socket) { if (m_auto_start) m_socket = ola::client::ConnectToServer(OLA_DEFAULT_PORT); else m_socket = TcpSocket::Connect("127.0.0.1", OLA_DEFAULT_PORT); if (!m_socket) { delete m_socket; delete m_ss; m_socket = NULL; m_ss = NULL; return false; } m_socket->SetOnClose( ola::NewSingleCallback(this, &OlaClientWrapper::SocketClosed)); } CreateClient(); m_ss->AddReadDescriptor(m_socket); return StartupClient(); }
// ----------------------------------------------------------------------------- // ProcessStartLogin // ----------------------------------------------------------------------------- // TInt CHotSpotSession::ProcessStartLogin( const TUint aIapId, const TUint aNetId ) { DEBUG("CHotSpotSession::ProcessStartLogin"); TInt ret( KErrNotFound ); TBuf8<KExtensionAPILength> extAPI; iIapId = aIapId; TBuf<KUidLength> clientUid; TInt err = iServer.GetClientUid( aIapId, clientUid ); if ( err != KErrNotFound ) { DEBUG("CHotSpotSession::ProcessStartLogin clientUid = CLIENT"); ConvertTBufToTUid( clientUid ); TBuf8<KExtensionAPILength> nullBuf; ret = CreateClient( iClientUid, nullBuf ); if ( KErrNone == ret && iServer.GetLoginFlagValue() ) { iLoginTimer->After( iServer.GetLoginTimeMicroSecs( clientUid ) ); DEBUG("CHotSpotSession::ProcessStartLogin iClient->Login( iIapId, iNetId );"); iClient->Login( aIapId, aNetId ); iServer.SetLogoutFlag( EFalse ); } else { ret = KErrNotFound; } } DEBUG("CHotSpotSession::ProcessStartLogin DONE"); return ret; }
BOOL InitCommClient( SOCK *clnt, const char *address, unsigned short serverPortNr, unsigned short clientPortNr, int timeOutMS ) { BOOL fatal, ret = FALSE; int err; if( InitIP() && CreateClient( clnt, clientPortNr, TRUE ) ){ QTils_LogMsgEx( "Client socket opened on port %hu", clientPortNr ); if( ConnectToServer( *clnt, serverPortNr, "", address, timeOutMS, &fatal ) ){ QTils_LogMsgEx( "Connected to server \"%s:%hu\"", address, serverPortNr ); if( !SendMutex ){ SendMutex = new CritSectEx(4000); } if( !ReceiveMutex ){ ReceiveMutex = new CritSectEx(4000); } ret = TRUE; } else{ err = errSock; QTils_LogMsgEx( "Failure connecting to server \"%s:%hu\" (err=%d \"%s\")", address, serverPortNr, err, errSockText(err) ); CloseClient(clnt); } } else{ QTils_LogMsgEx( "Failure opening client socket on port %hu (err=%d \"%s\")", clientPortNr, errSock, errSockText(errSock) ); } return ret; }
BOOL CMDIFrameWnd::OnCreateClient(LPCREATESTRUCT lpcs) { CFrameWnd::OnCreateClient(lpcs); HMENU hMenu=GetMenu(); int iMenu=::GetMenuItemCount(hMenu)-2; hMenu=::GetSubMenu(hMenu,iMenu); return CreateClient(lpcs,hMenu); }
void StMgrClientMgr::NewPhysicalPlan(const proto::system::PhysicalPlan* _pplan) { // TODO(vikasr) : Currently we establish connections with all streammanagers // In the next iteration we might want to make it better std::set<sp_string> all_stmgrs; for (sp_int32 i = 0; i < _pplan->stmgrs_size(); ++i) { const proto::system::StMgr& s = _pplan->stmgrs(i); if (s.id() == stmgr_id_) { continue; // dont want to connect to ourselves } all_stmgrs.insert(s.id()); if (clients_.find(s.id()) != clients_.end()) { // We already have a connection for this stmgr. // Just make sure we have it for the same host/port const NetworkOptions& o = clients_[s.id()]->get_clientoptions(); if (o.get_host() != s.host_name() || o.get_port() != s.data_port()) { LOG(INFO) << "Stmgr " << s.id() << " changed from " << o.get_host() << ":" << o.get_port() << " to " << s.host_name() << ":" << s.data_port(); // This stmgr has actually moved to a different host/port clients_[s.id()]->Quit(); // this will delete itself. clients_[s.id()] = CreateClient(s.id(), s.host_name(), s.data_port()); } else { // This stmgr has remained the same. Don't do anything } } else { // We don't have any connection to this stmgr. LOG(INFO) << "Stmgr " << s.id() << " came on " << s.host_name() << ":" << s.data_port(); clients_[s.id()] = CreateClient(s.id(), s.host_name(), s.data_port()); } } // We need to remove any unused ports std::set<sp_string> to_remove; for (auto iter = clients_.begin(); iter != clients_.end(); ++iter) { if (all_stmgrs.find(iter->first) == all_stmgrs.end()) { // This stmgr is no longer there in the physical map to_remove.insert(iter->first); } } // Now go over to_remove to remove all the unused stmgrs for (auto iter = to_remove.begin(); iter != to_remove.end(); ++iter) { LOG(INFO) << "Stmgr " << *iter << " no longer required"; clients_[*iter]->Quit(); // This will delete itself. clients_.erase(*iter); } }
static void TestDestruction(ow_test_context Context) { set Set; InitPosixNetClientSet(&Set); CreateClient(&Set, 1); CreateClient(&Set, 2); CreateClient(&Set, 3); iterator Iterator = CreatePosixNetClientSetIterator(&Set); AdvancePosixNetClientSetIterator(&Iterator); AdvancePosixNetClientSetIterator(&Iterator); DestroyClient(&Iterator); AdvancePosixNetClientSetIterator(&Iterator); OW_AssertEqualInt(3, Iterator.Client->FD); AdvancePosixNetClientSetIterator(&Iterator); OW_AssertFalse(AdvancePosixNetClientSetIterator(&Iterator)); TerminatePosixNetClientSet(&Set); }
DWORD GetChannelConfig(const std::string& device_id, EDataFlow data_flow) { CComPtr<IAudioClient> client( CreateClient(device_id, data_flow, eConsole)); WAVEFORMATPCMEX format = { 0 }; if (!client || FAILED(GetSharedModeMixFormat(client, &format))) return 0; return format.dwChannelMask; }
CComPtr<IAudioClient> CreateClient( const std::string& device_id, EDataFlow data_flow, ERole role) { if (device_id.empty()) return CreateDefaultClient(data_flow, role); CComPtr<IMMDevice> device(CreateDevice(device_id)); if (!device) return CComPtr<IAudioClient>(); return CreateClient(device); }
// ----------------------------------------------------------------------------- // ProcessStartL // ----------------------------------------------------------------------------- // TInt CHotSpotSession::ProcessStartL( const TUint aIapId ) { DEBUG("CHotSpotSession::ProcessStart"); TInt ret( KErrNone ); TBuf8<KExtensionAPILength> extAPI; TBuf<KUidLength> clientUid; TInt err = iServer.GetClientUid( aIapId, clientUid ); if ( err != KErrNone ) { DEBUG("CHotSpotSession::ProcessStartL clientUid = EMPTY"); ret = KErrNotSupported; } else { DEBUG("CHotSpotSession::ProcessStartL clientUid = CLIENT"); ConvertTBufToTUid( clientUid ); TBuf8<KExtensionAPILength> nullBuf; // Try first with API extension defined ret = CreateClient( iClientUid, extAPI ); if ( ret != KErrNone ) { // Client exists, but hasn't implemented API extension // Let's try again without API extension definition TBuf8<KExtensionAPILength> nullBuf; ret = CreateClient( iClientUid, nullBuf ); } if ( ret == KErrNone ) { iServer.SetAssociationFlag( ETrue ); iMgtClient->ActivateNotificationsL( *this ); iClient->Start( aIapId ); } } DEBUG1("CHotSpotSession::ProcessStartL DONE ret%d", ret); return ret; }
HRESULT ZFXWS::Init( HWND hWnd, ZFXNETMODE nmd, int nPort, char *pIP, UINT nMaxPktSize, bool bSaveLog ) { WSADATA wsaData; UINT nEvents = 0; WORD wVersion; int nRes; m_nMaxSize = nMaxPktSize; m_Event = WSACreateEvent(); m_Buffer = new char[m_nMaxSize]; m_hWndMain = hWnd; m_nPort = nPort; m_Mode = nmd; if ( pIP ) { sprintf_s(m_pIP, "%s", pIP); } wVersion = MAKEWORD(2,0); if ( ( nRes = WSAStartup( wVersion, &wsaData ) ) != 0 ) { return ZFX_FAIL; } //create master socket object and start it listening if ( m_Mode == NMD_SERVER ) { if ( FAILED( CreateServer( &m_pSockObj ) ) ) { return ZFX_FAIL; } } else if ( m_Mode == NMD_CLIENT ) { if ( strcmp( m_pIP, "" ) == 0 ) { sprintf_s(m_pIP, "LOCALHOST"); } if ( FAILED( CreateClient( &m_pSockObj ) ) ) { return ZFX_FAIL; } } else { return ZFX_INVALIDPARAM; } m_bRunning = true; return ZFX_OK; }
// When the client is created // BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) { if (CreateClient(lpcs, NULL)) { m_wndMdiClient.SubclassWindow(m_hWndMDIClient); m_wndMdiClient.SetBitmap(IDB_BACKGROUND); return TRUE; } else return FALSE; }
Handler *GetHandler (const UserDetails *user_p) { DropboxHandler *handler_p = (DropboxHandler *) AllocMemory (sizeof (DropboxHandler)); if (handler_p) { const char *token_key_s = NULL; const char *token_secret_s = NULL; // json_t *dropbox_p = json_object_get (credentials_p, GetDropboxHandlerName (NULL)); // // #if DROPBOX_HANDLER_DEBUG >= STM_LEVEL_FINE // PrintJSONToLog (credentials_p, NULL, STM_LEVEL_FINE, __FILE__, __LINE__); // #endif // // if (dropbox_p) // { // token_key_s = GetJSONString (dropbox_p, DROPBOX_TOKEN_KEY_S); // token_secret_s = GetJSONString (dropbox_p, DROPBOX_TOKEN_SECRET_S); // } handler_p -> dh_client_p = CreateClient ((char *) token_key_s, (char *) token_secret_s); if (handler_p -> dh_client_p) { InitialiseHandler (& (handler_p -> dh_base_handler), InitDropboxHandler, IsResourceForDropboxHandler, GetDropboxHandlerProtocol, GetDropboxHandlerName, GetDropboxHandlerDescription, OpenDropboxHandler, ReadFromDropboxHandler, WriteToDropboxHandler, SeekDropboxHandler, CloseDropboxHandler, GetDropboxHandlerStatus, CalculateFileInformationFromDropboxHandler, FreeDropboxHandler); handler_p -> dh_status = HS_GOOD; handler_p -> dh_local_copy_f = NULL; handler_p -> dh_dropbox_filename_s = NULL; handler_p -> dh_updated_flag = false; return ((Handler *) handler_p); } /* if (GetUsernameAndPassword (credentials_p, &username_s, &password_s)) */ FreeMemory (handler_p); } /* if (handler_p) */ return NULL; }
bool BaseClientWrapper::Setup() { if (!m_socket.get()) { InitSocket(); if (!m_socket.get()) return false; } CreateClient(); m_ss.AddReadDescriptor(m_socket.get()); return StartupClient(); }
// ----------------------------------------------------------------------------- // ProcessClose // ----------------------------------------------------------------------------- // TInt CHotSpotSession::ProcessCloseL( const TUint aIapId ) { DEBUG("CHotSpotSession::ProcessCloseL"); TInt ret( KErrNone ); TBuf8<KExtensionAPILength> extAPI; TBuf<KUidLength> clientUid; TInt err = iServer.GetClientUid( aIapId, clientUid ); if ( err != KErrNone ) { DEBUG("CHotSpotSession::ProcessCloseL clientUid = EMPTY"); // do nothing ret = KErrNotSupported; } else { DEBUG("CHotSpotSession::ProcessCloseL clientUid = CLIENT"); if ( iClient == NULL ) { //Convert TBuf to TUid TLex lex( clientUid ); TUint value( 0 ); lex.Val( value, EHex ); iClientUid = TUid::Null(); iClientUid.iUid = value; TBuf8<KExtensionAPILength> nullBuf; ret = CreateClient( iClientUid, nullBuf ); } else { ret = KErrNone; } iLogoutTimer->After( iServer.GetLogoutTimeMicroSecs( clientUid ) ); if ( ret == KErrNone && !iServer.GetLogoutFlagValue() ) { DEBUG("CHotSpotSession::ProcessCloseL send Logout()"); iClient->Logout( aIapId ); iServer.SetLogoutFlag( ETrue ); iServer.SetLoginFlag( EFalse ); } else { ret = KErrNotFound; } } return ret; }
void TrackerRequesterImpl::CreateClients(size_t count, const TRACKER_LOGIN_ADDRESS addrs[]) { LIVE_ASSERT(count > 0 && count <= PPL_TRACKER_CLIENT_COUNT_LIMIT); LIVE_ASSERT(m_clients.empty()); m_clients.resize(count); m_clientIndex.clear(); for (size_t i = 0; i < count; ++i) { m_clients[i].reset( CreateClient() ); LIVE_ASSERT(m_clients[i] != NULL); TRACKER_ADDRESS trackerAddr = addrs[i].ServerAddress; trackerAddr.ReservedStatusCode = 0; m_clients[i]->Init( *this, addrs[i], m_PeerInformation, m_PacketSender ); m_clientIndex[ trackerAddr ] = m_clients[i]; } }
int main(int argc, const char * * argv) { if (argc != 2) { printf ( "We expect the directory to be the first and only argument!\n" ); exit(1); } printf ( "In The beginning!\n" ); CddbClient * client = CreateClient(); GetMatches(client, argv[1]); DisposeClient(client); printf ( "The end ...\n" ); return 0; }
// ----------------------------------------------------------------------------- // ProcessStartAgain // ----------------------------------------------------------------------------- // TInt CHotSpotSession::ProcessStartAgain( const TUint aIapId ) { DEBUG("CHotSpotSession::ProcessStartAgain"); TInt ret( KErrNone ); // Client exists if StartAgain is called. if ( iClient == NULL ) { TBuf8<KExtensionAPILength> nullBuf; ret = CreateClient( iClientUid, nullBuf ); } if ( ret == KErrNone ) { iServer.SetAssociationFlag( ETrue ); // Send association status iClient->Update( aIapId ); } return ret; }
//+------------------------------------------------------------------------- // // Function: IsOkayToExec // // Synopsis: Determines if it is okay to make a call to the SPM // // Effects: Binds if necessary to the SPM // // Arguments: // // Requires: // // Returns: // // Notes: uses IsSPMgrReady and InitState // //-------------------------------------------------------------------------- SECURITY_STATUS IsOkayToExec(PClient * ppClient) { SECURITY_STATUS scRet; PClient pClient; PAGED_CODE(); if (NT_SUCCESS(LocateClient(&pClient))) { if (ppClient) *ppClient = pClient; return(STATUS_SUCCESS); } scRet = CreateClient(&pClient); if (!NT_SUCCESS(scRet)) { return(scRet); } if (ppClient) *ppClient = pClient; return(STATUS_SUCCESS); }
int main(int argc, char* argv[]) { std::srand(time(nullptr)); std::cout.sync_with_stdio(false); std::string server_address; if (argc<2) { server_address = "172.22.22.48"; std::cout<<"using default server address: " + server_address <<std::endl; } else { server_address = argv[1]; } CLIENT *pClient = CreateClient(); /* for debugging: */ std::ifstream debug_file("test.txt"); if (debug_file.is_open()) { std::string line; std::vector<std::string> full; while (std::getline(debug_file, line)) { full.push_back(line); } std::string resp = pClient->DebugResponse(full); std::cout<<"response: "<<resp <<std::endl; } /**/ if (!pClient->Init(server_address)) { std::cout<<"Connection failed"<<std::endl; } else { pClient->Run(); } delete pClient; return 0; }
BOOL CMDIFrameWnd::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext*) { CMenu* pMenu = NULL; if (m_hMenuDefault == NULL) { // default implementation for MFC V1 backward compatibility pMenu = GetMenu(); ASSERT(pMenu != NULL); // This is attempting to guess which sub-menu is the Window menu. // The Windows user interface guidelines say that the right-most // menu on the menu bar should be Help and Window should be one // to the left of that. int iMenu = pMenu->GetMenuItemCount() - 2; // If this assertion fails, your menu bar does not follow the guidelines // so you will have to override this function and call CreateClient // appropriately or use the MFC V2 MDI functionality. ASSERT(iMenu >= 0); pMenu = pMenu->GetSubMenu(iMenu); ASSERT(pMenu != NULL); } return CreateClient(lpcs, pMenu); }
wxMDIClientWindow::wxMDIClientWindow( wxMDIParentFrame *parent, long style ) { CreateClient( parent, style ); }
int _tmain(int argc, _TCHAR* argv[]) { int iResult; int iConnectionType = ConnectionType_Multicast; // parse command line args if (argc != 2) { printf("Error! Please run with the following arguments:\n"); printf("%s pose-server_ip:port\n", argv[0]); return 1; } //Parsing args std::string tcp_remote_ip; int tcp_remote_port; { std::vector<std::string> tokens; boost::split(tokens, argv[1], boost::is_any_of(":")); if (tokens.size() != 2) { printf("Error! Please provide the remote address in the format: x.x.x.x:p\n"); return 1; } tcp_remote_ip = tokens[0]; tcp_remote_port = std::stoi(tokens[1], nullptr); } tcpClient = AR::IO::TCPClient::Create(); tcpClient->connect(tcp_remote_ip, tcp_remote_port, false); // Create NatNet Client iResult = CreateClient(iConnectionType); if (iResult != ErrorCode_OK) { printf("Error initializing client. See log for details. Exiting"); return 1; } else { printf("Client initialized and ready.\n"); } // send/receive test request printf("[SampleClient] Sending Test Request\n"); void* response; int nBytes; iResult = theClient->SendMessageAndWait("TestRequest", &response, &nBytes); if (iResult == ErrorCode_OK) { printf("[SampleClient] Received: %s", (char*)response); } // Retrieve Data Descriptions from server printf("\n\n[SampleClient] Requesting Data Descriptions..."); sDataDescriptions* pDataDefs = NULL; int nBodies = theClient->GetDataDescriptions(&pDataDefs); if (!pDataDefs) { printf("[SampleClient] Unable to retrieve Data Descriptions."); return 1; } else { printf("[SampleClient] Received %d Data Descriptions:\n", pDataDefs->nDataDescriptions); for (int i = 0; i < pDataDefs->nDataDescriptions; i++) { printf("Data Description # %d (type=%d)\n", i, pDataDefs->arrDataDescriptions[i].type); if (pDataDefs->arrDataDescriptions[i].type == Descriptor_RigidBody) { // RigidBody sRigidBodyDescription* pRB = pDataDefs->arrDataDescriptions[i].Data.RigidBodyDescription; printf("RigidBody Name : %s\n", pRB->szName); printf("RigidBody ID : %d\n", pRB->ID); printf("RigidBody Parent ID : %d\n", pRB->parentID); printf("Parent Offset : %3.2f,%3.2f,%3.2f\n", pRB->offsetx, pRB->offsety, pRB->offsetz); } else { printf("Unknown data type."); // Unknown } } } // Ready to receive marker stream! printf("\nClient is connected to server and listening for data...\n"); int c; bool bExit = false; while (c = _getch()) { switch (c) { case 'q': bExit = true; break; case 'r': resetClient(); break; case 'p': sServerDescription ServerDescription; memset(&ServerDescription, 0, sizeof(ServerDescription)); theClient->GetServerDescription(&ServerDescription); if (!ServerDescription.HostPresent) { printf("Unable to connect to server. Host not present. Exiting."); return 1; } break; case 'f': { sFrameOfMocapData* pData = theClient->GetLastFrameOfData(); printf("Most Recent Frame: %d", pData->iFrame); } break; default: break; } if (bExit) break; } // Done - clean up. theClient->Uninitialize(); tcpClient->disconnect(); return ErrorCode_OK; }
int _tmain(int argc, _TCHAR* argv[]) { int iResult; int iConnectionType = ConnectionType_Multicast; //int iConnectionType = ConnectionType_Unicast; // parse command line args if(argc>1) { strcpy(szServerIPAddress, argv[1]); // specified on command line printf("Connecting to server at %s...\n", szServerIPAddress); } else { strcpy(szServerIPAddress, ""); // not specified - assume server is local machine printf("Connecting to server at LocalMachine\n"); } if(argc>2) { strcpy(szMyIPAddress, argv[2]); // specified on command line printf("Connecting from %s...\n", szMyIPAddress); } else { strcpy(szMyIPAddress, ""); // not specified - assume server is local machine printf("Connecting from LocalMachine...\n"); } if(argc>3) { strcpy(szUnityIPAddress, argv[3]); // specified on command line printf("Connecting to Unity3D at %s...\n", szUnityIPAddress); } else { strcpy(szUnityIPAddress, "127.0.0.1"); // not specified - assume server is local machine printf("Connecting to Unity3D on LocalMachine...\n"); } if(argc>4) { iConnectionType = strcmp(argv[4], "unicast") != 0 ? ConnectionType_Multicast : ConnectionType_Unicast; } gSlipStream = new cSlipStream(szUnityIPAddress,16000); // Create NatNet Client iResult = CreateClient(iConnectionType); if(iResult != ErrorCode_OK) { printf("Error initializing client. See log for details. Exiting"); return 1; } else { printf("Client initialized and ready.\n"); } // send/receive test request printf("[SampleClient] Sending Test Request\n"); void* response; int nBytes; iResult = theClient->SendMessageAndWait("TestRequest", &response, &nBytes); if (iResult == ErrorCode_OK) { printf("[SampleClient] Received: %s", (char*)response); } // Retrieve Data Descriptions from server printf("\n\n[SampleClient] Requesting Data Descriptions..."); sDataDescriptions* pDataDefs = NULL; int nBodies = theClient->GetDataDescriptions(&pDataDefs); if(!pDataDefs) { printf("[SampleClient] Unable to retrieve Data Descriptions."); } else { printf("[SampleClient] Received %d Data Descriptions:\n", pDataDefs->nDataDescriptions ); for(int i=0; i < pDataDefs->nDataDescriptions; i++) { printf("Data Description # %d (type=%d)\n", i, pDataDefs->arrDataDescriptions[i].type); if(pDataDefs->arrDataDescriptions[i].type == Descriptor_MarkerSet) { // MarkerSet sMarkerSetDescription* pMS = pDataDefs->arrDataDescriptions[i].Data.MarkerSetDescription; printf("MarkerSet Name : %s\n", pMS->szName); for(int i=0; i < pMS->nMarkers; i++) printf("%s\n", pMS->szMarkerNames[i]); } else if(pDataDefs->arrDataDescriptions[i].type == Descriptor_RigidBody) { // RigidBody sRigidBodyDescription* pRB = pDataDefs->arrDataDescriptions[i].Data.RigidBodyDescription; printf("RigidBody Name : %s\n", pRB->szName); printf("RigidBody ID : %d\n", pRB->ID); printf("RigidBody Parent ID : %d\n", pRB->parentID); printf("Parent Offset : %3.2f,%3.2f,%3.2f\n", pRB->offsetx, pRB->offsety, pRB->offsetz); // populate rb name dictionary for use in xml ==-- gRBNames[pRB->ID] = pRB->szName; } else if(pDataDefs->arrDataDescriptions[i].type == Descriptor_Skeleton) { // Skeleton sSkeletonDescription* pSK = pDataDefs->arrDataDescriptions[i].Data.SkeletonDescription; printf("Skeleton Name : %s\n", pSK->szName); printf("Skeleton ID : %d\n", pSK->skeletonID); printf("RigidBody (Bone) Count : %d\n", pSK->nRigidBodies); for(int j=0; j < pSK->nRigidBodies; j++) { sRigidBodyDescription* pRB = &pSK->RigidBodies[j]; printf(" RigidBody Name : %s\n", pRB->szName); printf(" RigidBody ID : %d\n", pRB->ID); printf(" RigidBody Parent ID : %d\n", pRB->parentID); printf(" Parent Offset : %3.2f,%3.2f,%3.2f\n", pRB->offsetx, pRB->offsety, pRB->offsetz); // populate bone name dictionary for use in xml ==-- gBoneNames[pRB->ID] = pRB->szName; } } else { printf("Unknown data type."); // Unknown } } } // Ready to receive marker stream! printf("\nClient is connected to server and listening for data...\n"); int c; bool bExit = false; while(c =_getch()) { switch(c) { case 'q': bExit = true; break; case 'r': resetClient(); break; case 'p': sServerDescription ServerDescription; memset(&ServerDescription, 0, sizeof(ServerDescription)); theClient->GetServerDescription(&ServerDescription); if(!ServerDescription.HostPresent) { printf("Unable to connect to server. Host not present. Exiting."); return 1; } break; case 'f': { sFrameOfMocapData* pData = theClient->GetLastFrameOfData(); printf("Most Recent Frame: %d", pData->iFrame); } break; case 'm': // change to multicast iResult = CreateClient(ConnectionType_Multicast); if(iResult == ErrorCode_OK) printf("Client connection type changed to Multicast.\n\n"); else printf("Error changing client connection type to Multicast.\n\n"); break; case 'u': // change to unicast iResult = CreateClient(ConnectionType_Unicast); if(iResult == ErrorCode_OK) printf("Client connection type changed to Unicast.\n\n"); else printf("Error changing client connection type to Unicast.\n\n"); break; default: break; } if(bExit) break; } // Done - clean up. theClient->Uninitialize(); return ErrorCode_OK; }
int _tmain(int argc, _TCHAR* argv[]) { dest_cont.dests[0] = KITCHEN; dest_cont.dests[1] = TABLE_ONE; dest_cont.dests[2] = TABLE_TWO; dest_cont.dests[3] = KITCHEN; dest_cont.dests[4] = TABLE_THREE; dest_cont.dests[5] = -1; InitializeCriticalSection(&(dest_cont.lock)); //memset(dest_cont.dests, -1, 11); dest_cont.step_num = 0; dest_cont.num_dests = 5; acommand.packet_counter = 1; for (int i = 0; i < 10; i++) { //dest_cont.dests[i] = -1; //cout << dest_cont.dests[i]; } for(int j = 0; j < 5; j++) { dest_cont.active_orders[j] = 0; dest_cont.inactive_orders[j] = 0; } HANDLE thread = (HANDLE)::_beginthreadex(NULL, 0, update_orders, NULL, 0, NULL); int iResult; int iConnectionType = ConnectionType_Multicast; //int iConnectionType = ConnectionType_Unicast; // parse command line args if(argc>1) { strcpy(szServerIPAddress, argv[1]); // specified on command line printf("Connecting to server at %s...\n", szServerIPAddress); } else { strcpy(szServerIPAddress, "10.10.67.12"); // not specified - assume server is local machine printf("Connecting to server at LocalMachine\n"); } if(argc>2) { strcpy(szMyIPAddress, argv[2]); // specified on command line printf("Connecting from %s...\n", szMyIPAddress); } else { strcpy(szMyIPAddress, "10.10.67.32"); // not specified - assume server is local machine printf("Connecting from LocalMachine...\n"); } // Create NatNet Client iResult = CreateClient(iConnectionType); if(iResult != ErrorCode_OK) { printf("Error initializing client. See log for details. Exiting"); return 1; } else { printf("Client initialized and ready.\n"); } // send/receive test request printf("[SampleClient] Sending Test Request\n"); void* response; int nBytes; iResult = theClient->SendMessageAndWait("TestRequest", &response, &nBytes); if (iResult == ErrorCode_OK) { printf("[SampleClient] Received: %s", (char*)response); } // Retrieve Data Descriptions from server printf("\n\n[SampleClient] Requesting Data Descriptions..."); sDataDescriptions* pDataDefs = NULL; int nBodies = theClient->GetDataDescriptions(&pDataDefs); if(!pDataDefs) { printf("[SampleClient] Unable to retrieve Data Descriptions."); } else { printf("[SampleClient] Received %d Data Descriptions:\n", pDataDefs->nDataDescriptions ); for(int i=0; i < pDataDefs->nDataDescriptions; i++) { printf("Data Description # %d (type=%d)\n", i, pDataDefs->arrDataDescriptions[i].type); if(pDataDefs->arrDataDescriptions[i].type == Descriptor_MarkerSet) { // MarkerSet sMarkerSetDescription* pMS = pDataDefs->arrDataDescriptions[i].Data.MarkerSetDescription; printf("MarkerSet Name : %s\n", pMS->szName); for(int i=0; i < pMS->nMarkers; i++) printf("%s\n", pMS->szMarkerNames[i]); } else if(pDataDefs->arrDataDescriptions[i].type == Descriptor_RigidBody) { // RigidBody sRigidBodyDescription* pRB = pDataDefs->arrDataDescriptions[i].Data.RigidBodyDescription; printf("RigidBody Name : %s\n", pRB->szName); printf("RigidBody ID : %d\n", pRB->ID); printf("RigidBody Parent ID : %d\n", pRB->parentID); printf("Parent Offset : %3.2f,%3.2f,%3.2f\n", pRB->offsetx, pRB->offsety, pRB->offsetz); } else if(pDataDefs->arrDataDescriptions[i].type == Descriptor_Skeleton) { // Skeleton sSkeletonDescription* pSK = pDataDefs->arrDataDescriptions[i].Data.SkeletonDescription; printf("Skeleton Name : %s\n", pSK->szName); printf("Skeleton ID : %d\n", pSK->skeletonID); printf("RigidBody (Bone) Count : %d\n", pSK->nRigidBodies); for(int j=0; j < pSK->nRigidBodies; j++) { sRigidBodyDescription* pRB = &pSK->RigidBodies[j]; printf(" RigidBody Name : %s\n", pRB->szName); printf(" RigidBody ID : %d\n", pRB->ID); printf(" RigidBody Parent ID : %d\n", pRB->parentID); printf(" Parent Offset : %3.2f,%3.2f,%3.2f\n", pRB->offsetx, pRB->offsety, pRB->offsetz); } } else { printf("Unknown data type."); // Unknown } } } // Create data file for writing received stream into char szFile[MAX_PATH]; char szFolder[MAX_PATH]; GetCurrentDirectory(MAX_PATH, szFolder); if(argc > 3) sprintf(szFile, "%s\\%s", szFolder, argv[3]); else sprintf(szFile, "%s\\Client-output.pts",szFolder); fp = fopen(szFile, "w"); if(!fp) { printf("error opening output file %s. Exiting.", szFile); exit(1); } if(pDataDefs) _WriteHeader(fp, pDataDefs); // Ready to receive marker stream! printf("\nClient is connected to server and listening for data...\n"); int c; bool bExit = false; while(c =_getch()) { switch(c) { case 'q': bExit = true; break; case 'r': resetClient(); break; case 'p': sServerDescription ServerDescription; memset(&ServerDescription, 0, sizeof(ServerDescription)); theClient->GetServerDescription(&ServerDescription); if(!ServerDescription.HostPresent) { printf("Unable to connect to server. Host not present. Exiting."); return 1; } break; case 'f': { sFrameOfMocapData* pData = theClient->GetLastFrameOfData(); printf("Most Recent Frame: %d", pData->iFrame); } break; case 'm': // change to multicast iResult = CreateClient(ConnectionType_Multicast); if(iResult == ErrorCode_OK) printf("Client connection type changed to Multicast.\n\n"); else printf("Error changing client connection type to Multicast.\n\n"); break; case 'u': // change to unicast iResult = CreateClient(ConnectionType_Unicast); if(iResult == ErrorCode_OK) printf("Client connection type changed to Unicast.\n\n"); else printf("Error changing client connection type to Unicast.\n\n"); break; default: break; } if(bExit) break; } // Done - clean up. theClient->Uninitialize(); _WriteFooter(fp); fclose(fp); return ErrorCode_OK; }