int main() { int i; int sucesso = 1; pilha* pl = pl_inicializapilha(5); printf("---------- Empilhando ----------\n"); for (i = 0; (sucesso == 1); i++) { int valor = i * 10; pl_push(pl, valor, &sucesso); if (sucesso == 1) printf("%d\n", valor); } printf("-----------------------------------\n\n"); printf("-----------------------------------\n"); printf("TOPO = %d\n", pl_topo(pl, &sucesso)); printf("BASE = %d\n", pl_base(pl, &sucesso)); printf("-----------------------------------\n\n"); printf("---------- Desempilhando ----------\n"); while (1) { int valor = pl_pop(pl, &sucesso); if (sucesso == 0) break; printf("%d\n", valor); } printf("-----------------------------------\n"); pl_liberapilha(pl); return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { DANCE_DISABLE_TRACE (); int retval = 0; Options options; try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); ORB_Destroyer safe_orb (orb); DAnCE::Logger_Service * dlf = ACE_Dynamic_Service<DAnCE::Logger_Service>::instance ("DAnCE_Logger"); if (dlf) { dlf->init (argc, argv); } if (!parse_args (argc, argv, options)) { return 1; } auto_ptr<DAnCE::Plan_Launcher_Base> pl_base (0); Deployment::DeploymentPlan_var dp; DANCE_DEBUG (DANCE_LOG_MAJOR_EVENT, (LM_DEBUG, DLINFO ACE_TEXT ("Plan_Launcher - ") ACE_TEXT ("Parsing deployment plan\n"))); if (options.cdr_plan_) { dp = DAnCE::Convert_Plan::read_cdr_plan (options.cdr_plan_); if (!dp.ptr ()) { if (!options.quiet_) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, DLINFO ACE_TEXT ("PlanLauncher - ") ACE_TEXT ("Error: Unable to read ") ACE_TEXT ("in CDR plan\n"))); } return 1; } } else if (options.xml_plan_) { dp = DAnCE::Convert_Plan::read_xml_plan (options.xml_plan_); if (!dp.ptr ()) { if (!options.quiet_) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, DLINFO ACE_TEXT ("PlanLauncher - Error: ") ACE_TEXT ("Unable to read in XML plan\n"))); } return 1; } } if (options.domain_file_) { ::DAnCE::Config_Handlers::XML_File_Intf file (options.domain_file_); file.add_search_path (ACE_TEXT ("DANCE_ROOT"), ACE_TEXT ("/docs/schema/")); ::Deployment::Domain *plan = file.release_domain (); if (!plan) { DANCE_ERROR (DANCE_LOG_ERROR, (LM_ERROR, DLINFO ACE_TEXT("PlanLauncher - Error - ") ACE_TEXT("Error: Processing file <%C>\n"), options.domain_file_)); return false; } DAnCE_Domain_Validator_i validator (orb); validator.load_domain (*plan); ::DAnCE::Time_Value tv; tv.seconds (options.domain_timeout_); CORBA::StringSeq_var late_nodes; if (!validator.block_for_domain (tv, late_nodes.out ())) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, DLINFO ACE_TEXT ("PlanLauncher - Error: ") ACE_TEXT ("Not all nodes in domain ready\n"))); for (CORBA::ULong i = 0; i < late_nodes->length (); ++i) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, DLINFO ACE_TEXT ("PlanLauncher - Error: ") ACE_TEXT ("Node <%C> is not started\n"), late_nodes[i].in ())); } return 1; } } ACE_Time_Value timeout (ACE_OS::gettimeofday () + ACE_Time_Value (options.em_timeout_)); if (options.em_ior_) { // Resolve ExecutionManager IOR for EM base deployment. DAnCE::EM_Launcher *em_pl (0); Deployment::ExecutionManager_var tmp_em = resolve_manager<Deployment::ExecutionManager> (timeout, options.em_ior_, orb); if (CORBA::is_nil (tmp_em)) { DANCE_ERROR(DANCE_LOG_EMERGENCY, (LM_ERROR, DLINFO ACE_TEXT ("Plan_Launcher - ") ACE_TEXT ("Unable to resolve EM object reference\n"))); return 0; } ACE_NEW_THROW_EX (em_pl, DAnCE::EM_Launcher (orb.in (), tmp_em.in ()), CORBA::NO_MEMORY ()); pl_base.reset (em_pl); } else if (options.nm_ior_) { // Resolve NM IOR for NM based deployment. DAnCE::NM_Launcher *nm_pl (0); CORBA::Object_var obj = orb->string_to_object (options.nm_ior_); Deployment::NodeManager_var tmp_em = Deployment::NodeManager::_narrow (obj); if (CORBA::is_nil (tmp_em.in ())) { if (!options.quiet_) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, DLINFO ACE_TEXT ("Plan_Launcher - ") ACE_TEXT ("Unable to resolve ") ACE_TEXT ("NodeManager reference <%s>\n"), options.nm_ior_)); } return 1; } ACE_NEW_THROW_EX (nm_pl, DAnCE::NM_Launcher (orb.in (), tmp_em.in ()), CORBA::NO_MEMORY ()); pl_base.reset (nm_pl); } else if (options.lm_ior_) { // Resolve NM IOR for NM based deployment. DAnCE::LM_Launcher *lm_pl (0); CORBA::Object_var obj = orb->string_to_object (options.lm_ior_); DAnCE::LocalityManager_var tmp_em = DAnCE::LocalityManager::_narrow (obj); if (CORBA::is_nil (tmp_em.in ())) { if (!options.quiet_) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, DLINFO ACE_TEXT ("Plan_Launcher - ") ACE_TEXT ("Unable to resolve ") ACE_TEXT ("LocalityManager reference <%s>\n"), options.lm_ior_)); } return 1; } ACE_NEW_THROW_EX (lm_pl, DAnCE::LM_Launcher (orb.in (), tmp_em.in ()), CORBA::NO_MEMORY ()); pl_base.reset (lm_pl); } switch (options.mode_) { case Options::LAUNCH: retval = launch_plan (options, pl_base.get (), dp, orb.in ()); break; case Options::TEARDOWN: retval = teardown_plan (options, pl_base.get (), dp, orb.in ()); break; default: if (!options.quiet_) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, DLINFO ACE_TEXT ("Plan_Launcher -") ACE_TEXT ("Mode not yet supported\n"))); } break; }; } catch (const Deployment::PlanError &ex) { if (!options.quiet_) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, DLINFO ACE_TEXT ("PlanLauncher - ") ACE_TEXT ("Error in plan: <%C>, <%C>\n"), ex.name.in (), ex.reason.in ())); } retval = -1; } catch (const DAnCE::Deployment_Failure& e) { if (!options.quiet_) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, DLINFO ACE_TEXT ("PlanLauncher - ") ACE_TEXT ("Error: %C.\n"), e.ex_.c_str())); } retval = 1; } catch (const CORBA::Exception& ex) { if (!options.quiet_) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, DLINFO ACE_TEXT ( "PlanLauncher - ") ACE_TEXT ("Error: %C\n"), ex._info ().c_str ())); } retval = 1; } catch (...) { if (!options.quiet_) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, ACE_TEXT ("PlanLauncher - ") ACE_TEXT ("Error: Unknown exception.\n"))); } retval = 1; } return retval; }