/** @brief Main function * @param argc * @param argv * @return Exit status */ int main (int argc, char *argv[]) { if (argc != 2) { PCL_ERROR ("Usage:\n%s 192.168.100.65\n", argv[0]); return (-1); } davidsdk_ptr.reset (new pcl::DavidSDKGrabber); davidsdk_ptr->connect (argv[1]); if (!davidsdk_ptr->isConnected ()) return (-1); PCL_WARN ("davidSDK connected\n"); boost::function<void (const boost::shared_ptr<pcl::PCLImage> &)> f = boost::bind (&grabberCallback, _1); davidsdk_ptr->registerCallback (f); davidsdk_ptr->start (); waitForUser ("Press enter to quit"); return (0); }
static int processThread(HttpConn *conn, MprEvent *event) { ThreadData *td; cchar *path; char *url; int next; td = mprGetCurrentThread()->data; httpFollowRedirects(conn, !app->nofollow); httpSetTimeout(conn, app->timeout, app->timeout); if (strcmp(app->protocol, "HTTP/1.0") == 0) { httpSetKeepAliveCount(conn, 0); httpSetProtocol(conn, "HTTP/1.0"); } if (app->username) { if (app->password == 0 && !strchr(app->username, ':')) { app->password = getPassword(); } httpSetCredentials(conn, app->username, app->password); } while (!mprShouldDenyNewRequests(conn) && (app->success || app->continueOnErrors)) { if (app->singleStep) waitForUser(); if (app->files && !app->upload) { for (next = 0; (path = mprGetNextItem(app->files, &next)) != 0; ) { /* If URL ends with "/", assume it is a directory on the target and append each file name */ if (app->target[strlen(app->target) - 1] == '/') { url = mprJoinPath(app->target, mprGetPathBase(path)); } else { url = app->target; } app->requestFiles = mprCreateList(-1, MPR_LIST_STATIC_VALUES); mprAddItem(app->requestFiles, path); td->url = url = resolveUrl(conn, url); if (app->verbose) { mprPrintf("putting: %s to %s\n", path, url); } if (doRequest(conn, url, app->requestFiles) < 0) { app->success = 0; break; } } } else { td->url = url = resolveUrl(conn, app->target); if (doRequest(conn, url, app->files) < 0) { app->success = 0; break; } } if (iterationsComplete()) { break; } } httpDestroyConn(conn); finishThread((MprThread*) event->data); return -1; }
void ccContourExtractorDlg::displayMessage(QString message, bool waitForUserConfirmation/*=false*/) { if (m_skipped) return; messageLabel->setText(message); if (waitForUserConfirmation) waitForUser(20); }
Enemy::Enemy (float random) { srand(random); Translation.X = rand() % 9 + 0.5; Translation.Y = 0.5; Translation.Z = rand() % 9 + 0.5; Scale.X = 1; Scale.Y = 1; Scale.Z = 1; Rotation.Z = 0; Rotation.X = 0; Rotation.Y = rand() % 360; alive = 1; size = 0.38; next = 0; // First create a shader loader and check if our hardware supports shaders CShaderLoader ShaderLoader; if (! ShaderLoader.isValid()) { std::cerr << "Shaders are not supported by your graphics hardware, or the shader loader was otherwise unable to load." << std::endl; waitForUser(); } // Now attempt to load the shaders Shader = ShaderLoader.loadShader("Shaders/Lab3_vert.glsl", "Shaders/Lab3_frag.glsl"); if (! Shader) { std::cerr << "Unable to open or compile necessary shader." << std::endl; waitForUser(); } Shader->loadAttribute("aPosition"); Shader->loadAttribute("aColor"); Shader->loadAttribute("aNormal"); // Now attempt to load the shaders Shader2 = ShaderLoader.loadShader("Shaders/Lab3_vert2.glsl", "Shaders/Lab3_frag.glsl"); if (! Shader2) { std::cerr << "Unable to open or compile necessary shader." << std::endl; waitForUser(); } Shader2->loadAttribute("aPosition"); Shader2->loadAttribute("aColor"); Shader2->loadAttribute("aNormal"); // Attempt to load mesh CMesh * Mesh = CMeshLoader::loadASCIIMesh("Models/gargoyle500.m"); if (! Mesh) { std::cerr << "Unable to load necessary mesh." << std::endl; waitForUser(); } // Make out mesh fit within camera view Mesh->resizeMesh(SVector3(1)); // And center it at the origin Mesh->centerMeshByExtents(SVector3(0)); // Now load our mesh into a VBO, retrieving the number of triangles and the handles to each VBO CMeshLoader::createVertexBufferObject(* Mesh, TriangleCount, PositionBufferHandle, ColorBufferHandle, NormalBufferHandle); }
//------------------------------------------------------------------------------------------ // INSTANCE METHODS //------------------------------------------------------------------------------------------ /////////////////////////////////////////////////////////////////////////// ////////////////////////// Main Simulation Method ///////////////////////// /////////////////////////////////////////////////////////////////////////// void ExampleCPPFederate::runFederate( std::wstring federateName ) { ///////////////////////////////// // 1. create the RTIambassador // ///////////////////////////////// RTIambassadorFactory factory = RTIambassadorFactory(); this->rtiamb = factory.createRTIambassador().release(); /////////////////////////// // 2. connect to the RTI // /////////////////////////// // we need the federate ambassador set up before we can connect this->fedamb = new ExampleFedAmb(); try { rtiamb->connect( *this->fedamb, HLA_EVOKED ); } catch( ConnectionFailed& connectionFailed ) { wcout << L"Connection failed: " << connectionFailed.what() << endl; } catch( InvalidLocalSettingsDesignator& settings ) { wcout << L"Connection failed, InvalidLocalSettingsDesignator: " << settings.what() << endl; } catch( UnsupportedCallbackModel& callbackModel ) { wcout << L"Connection failed, UnsupportedCallbackModel: " << callbackModel.what() << endl; } catch( AlreadyConnected& connected ) { wcout << L"Connection failed, AlreadyConnected: " << connected.what() << endl; } catch( RTIinternalError& error ) { wcout << L"Connection failed, Generic Error: " << error.what() << endl; } ////////////////////////////////////////// // 3. create and join to the federation // ////////////////////////////////////////// // create // NOTE: some other federate may have already created the federation, // in that case, we'll just try and join it try { vector<wstring> foms; foms.push_back( L"testfom.fed" ); //rtiamb->createFederationExecution( L"ExampleFederation", L"testfom.fed" ); rtiamb->createFederationExecution( L"ExampleFederation", foms ); wcout << L"Created Federation" << endl; } catch( FederationExecutionAlreadyExists& exists ) { wcout << L"Didn't create federation, it already existed" << endl; } //////////////////////////// // 4. join the federation // //////////////////////////// rtiamb->joinFederationExecution( federateName, L"Example Federate", L"ExampleFederation" ); wcout << L"Joined Federation as " << federateName << endl; // initialize the handles - have to wait until we are joined initializeHandles(); //////////////////////////////// // 5. announce the sync point // //////////////////////////////// // announce a sync point to get everyone on the same page. if the point // has already been registered, we'll get a callback saying it failed, // but we don't care about that, as long as someone registered it VariableLengthData tag( (void*)"", 1 ); rtiamb->registerFederationSynchronizationPoint( READY_TO_RUN, tag ); while( fedamb->isAnnounced == false ) { rtiamb->evokeMultipleCallbacks( 0.1, 1.0 ); } // WAIT FOR USER TO KICK US OFF // So that there is time to add other federates, we will wait until the // user hits enter before proceeding. That was, you have time to start // other federates. waitForUser(); /////////////////////////////////////////////////////// // 6. achieve the point and wait for synchronization // /////////////////////////////////////////////////////// // tell the RTI we are ready to move past the sync point and then wait // until the federation has synchronized on rtiamb->synchronizationPointAchieved( READY_TO_RUN ); wcout << L"Achieved sync point: " << READY_TO_RUN << L", waiting for federation..." << endl; while( fedamb->isReadyToRun == false ) { rtiamb->evokeMultipleCallbacks( 0.1, 1.0 ); } ///////////////////////////// // 7. enable time policies // ///////////////////////////// // in this section we enable/disable all time policies // note that this step is optional! enableTimePolicy(); wcout << L"Time Policy Enabled" << endl; ////////////////////////////// // 8. publish and subscribe // ////////////////////////////// // in this section we tell the RTI of all the data we are going to // produce, and all the data we want to know about publishAndSubscribe(); wcout << L"Published and Subscribed" << endl; ///////////////////////////////////// // 9. register an object to update // ///////////////////////////////////// ObjectInstanceHandle objectHandle = registerObject(); wcout << L"Registered Object, handle=" << objectHandle << endl; ///////////////////////////////////// // 10. do the main simulation loop // ///////////////////////////////////// // here is where we do the meat of our work. in each iteration, we will // update the attribute values of the object we registered, and will // send an interaction. int i; for( i = 0; i < 20; i++ ) { // 9.1 update the attribute values of the instance // updateAttributeValues( objectHandle ); // 9.2 send an interaction sendInteraction(); // 9.3 request a time advance and wait until we get it advanceTime( 1.0 ); wcout << L"Time Advanced to " << fedamb->federateTime << endl; } ////////////////////////////////////// // 11. delete the object we created // ////////////////////////////////////// deleteObject( objectHandle ); wcout << L"Deleted Object, handle=" << objectHandle << endl; //////////////////////////////////// // 12. resign from the federation // //////////////////////////////////// rtiamb->resignFederationExecution( NO_ACTION ); wcout << L"Resigned from Federation" << endl; //////////////////////////////////////// // 13. try and destroy the federation // //////////////////////////////////////// // NOTE: we won't die if we can't do this because other federates // remain. in that case we'll leave it for them to clean up try { rtiamb->destroyFederationExecution( L"ExampleFederation" ); wcout << L"Destroyed Federation" << endl; } catch( FederationExecutionDoesNotExist& dne ) { wcout << L"No need to destroy federation, it doesn't exist" << endl; } catch( FederatesCurrentlyJoined& fcj ) { wcout << L"Didn't destroy federation, federates still joined" << endl; } ///////////////////////////////// // 14. disconnect from the RTI // ///////////////////////////////// // disconnect from the RTI this->rtiamb->disconnect(); ////////////////// // 15. clean up // ////////////////// delete this->rtiamb; }
/* Per-thread execution. Called for main thread and helper threads. */ static void threadMain(void *data, MprThread *tp) { ThreadData *td; HttpConn *conn; cchar *path; char *url; int next, count; td = tp->data; /* Create and start a dispatcher. This ensures that all activity on the connection in this thread will be serialized with respect to all I/O events and httpProtocol work. This also ensures that I/O events will be handled by this thread from httpWait. */ td->dispatcher = mprCreateDispatcher(tp->name, 0); mprStartDispatcher(td->dispatcher); td->conn = conn = httpCreateConn(NULL, td->dispatcher); httpFollowRedirects(conn, !app->nofollow); httpSetTimeout(conn, app->timeout, app->timeout); if (strcmp(app->protocol, "HTTP/1.0") == 0) { httpSetKeepAliveCount(conn, 0); httpSetProtocol(conn, "HTTP/1.0"); } if (app->iterations == 1) { conn->limits->keepAliveMax = 0; } if (app->username) { if (app->password == 0 && !strchr(app->username, ':')) { app->password = getPassword(); } httpSetCredentials(conn, app->username, app->password, app->authType); } for (count = 0; count < app->iterations; count++) { if (mprShouldDenyNewRequests(conn)) { break; } if (!app->success && !app->continueOnErrors) { break; } if (app->singleStep) waitForUser(); if (app->files && !app->upload) { for (next = 0; (path = mprGetNextItem(app->files, &next)) != 0; ) { /* If URL ends with "/", assume it is a directory on the target and append each file name */ if (app->target[strlen(app->target) - 1] == '/') { url = mprJoinPath(app->target, mprGetPathBase(path)); } else { url = app->target; } app->requestFiles = mprCreateList(-1, MPR_LIST_STATIC_VALUES | MPR_LIST_STABLE); mprAddItem(app->requestFiles, path); td->url = url = resolveUrl(conn, url); if (app->verbose) { mprPrintf("putting: %s to %s\n", path, url); } if (doRequest(conn, url, app->requestFiles) < 0) { app->success = 0; break; } } } else { td->url = url = resolveUrl(conn, app->target); if (doRequest(conn, url, app->files) < 0) { app->success = 0; break; } } if (app->verbose > 1) { mprPrintf("."); } } httpDestroyConn(conn); mprDestroyDispatcher(conn->dispatcher); finishThread(tp); }
static void processThread(MprCtx ctx) { MprHttp *http; MprList *files; cchar *path; char *url; int next; http = mprCreateHttp(ctx); mprSetHttpTimeout(http, timeout); mprSetHttpFollowRedirects(http, !nofollow); if (chunkSize) { mprSetHttpChunked(http, 1); } if (httpVersion == 0) { mprSetHttpKeepAlive(http, 0); mprSetHttpProtocol(http, "HTTP/1.0"); } if (username) { if (password == 0 && !strchr(username, ':')) { password = getPassword(http); } mprSetHttpCredentials(http, username, password); } while (!mprIsExiting(http) && (success || continueOnErrors)) { if (singleStep) waitForUser(http); if (fileData && !upload) { for (next = 0; (path = mprGetNextItem(fileData, &next)) != 0; ) { if (target[strlen(target) - 1] == '/') { url = mprJoinPath(http, target, mprGetPathBase(http, path)); } else { url = target; } files = mprCreateList(http); mprAddItem(files, path); url = resolveUrl(http, url); if (verbose) { mprPrintf(http, "putting: %s to %s\n", path, url); } if (doRequest(http, url, formData, files) < 0) { success = 0; mprFree(files); mprFree(url); break; } mprFree(files); mprFree(url); } } else { url = resolveUrl(http, target); if (doRequest(http, url, formData, fileData) < 0) { success = 0; mprFree(url); break; } } if (iterationsComplete(http)) break; } mprFree(http); }