static void * producer (ACE_Message_Queue<ACE_MT_SYNCH> *msg_queue) { ACE_Read_Buffer rb (ACE_STDIN); // Keep reading stdin, until we reach EOF. for (;;) { // Allocate a new buffer. char *buffer = rb.read ('\n'); ACE_Message_Block *mb = 0; if (buffer == 0) { // Send a 0-sized shutdown message to the other thread and // exit. ACE_NEW_RETURN (mb, ACE_Message_Block ((size_t) 0), 0); if (msg_queue->enqueue_tail (mb) == -1) ACE_ERROR ((LM_ERROR, "(%t) %p\n", "put_next")); break; } // Enqueue the message in priority order. else { // Allocate a new message, but have it "borrow" its memory // from the buffer. ACE_NEW_RETURN (mb, ACE_Message_Block (rb.size (), ACE_Message_Block::MB_DATA, 0, buffer), 0); mb->msg_priority (ACE_Utils::truncate_cast<unsigned long> (rb.size ())); mb->wr_ptr (rb.size ()); ACE_DEBUG ((LM_DEBUG, "enqueueing message of size %d\n", mb->msg_priority ())); // Enqueue in priority order. if (msg_queue->enqueue_prio (mb) == -1) ACE_ERROR ((LM_ERROR, "(%t) %p\n", "put_next")); } } // Now read all the items out in priority order (i.e., ordered by // the size of the lines!). consumer (msg_queue); return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); if (parse_args (argc, argv) != 0) return 1; CORBA::Object_var object = orb->string_to_object (ior); Simple_Server_var server = Simple_Server::_narrow (object.in ()); if (CORBA::is_nil (server.in ())) { ACE_ERROR_RETURN ((LM_ERROR, "Object reference <%s> is nil\n", ior), 1); } while (!feof (stdin)) { ACE_Read_Buffer buf (stdin, 0); char *line = buf.read ('\n'); if (line == 0) break; server->send_line (line); buf.alloc ()->free (line); } server->shutdown (); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Caught exception:"); return 1; } return 0; }
CORBA::Object_ptr TAO_FILE_Parser::parse_string (const char *ior, CORBA::ORB_ptr orb) { // Skip the prefix, we know it is there because this method in only // called if <match_prefix> returns 1. const char *filename = ior + sizeof (::file_prefix)+1; FILE* file = ACE_OS::fopen (ACE_TEXT_CHAR_TO_TCHAR (filename), ACE_TEXT("r")); if (file == 0) return CORBA::Object::_nil (); ACE_Read_Buffer reader (file, true); char* string = reader.read (); if (string == 0) return CORBA::Object::_nil (); CORBA::Object_ptr object = CORBA::Object::_nil (); try { object = orb->string_to_object (string); reader.alloc ()->free (string); } catch (const ::CORBA::Exception&) { reader.alloc ()->free (string); throw; } return object; }
void Plugin_Configurator::load_from_text_file (const ACE_TCHAR *file) { DANCE_TRACE ("Plugin_Configurator::load_from_text_file"); if (!file) { DANCE_ERROR (DANCE_LOG_ERROR, (LM_ERROR, DLINFO ACE_TEXT("Plugin_Configurator::load_from_text_file - ") ACE_TEXT("Error: Provided with nil filename\n"))); return; } FILE *inf = ACE_OS::fopen (file, ACE_TEXT("r")); if (!inf) { DANCE_ERROR (DANCE_LOG_ERROR, (LM_ERROR, DLINFO ACE_TEXT("Plugin_Configurator::load_from_text_file - ") ACE_TEXT("Fail to open plugin data file: <%s>\n"), file)); return; } ::Deployment::DeploymentPlan plan; ACE_Read_Buffer reader (inf, true); char * string = 0; CORBA::ULong pos (0); // Read from the file line by line while ((string = reader.read ('\n')) != 0) { try { size_t const len = ACE_OS::strlen (string); if (len != 0) { // If a line starts with # it is a comment line, we skip it, // but inform the user in case logging has been enabled if (string[0] == '#') { DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_DEBUG, DLINFO ACE_TEXT ("Plugin_Configurator::load_from_text_file - ") ACE_TEXT ("Skipping comment line <%C>\n"), string)); } else { std::istringstream tokenizer (string); std::vector< std::string > tokens; std::copy (std::istream_iterator< std::string > (tokenizer), std::istream_iterator <std::string > (), std::back_inserter < std::vector < std::string > > (tokens)); if (tokens.size () < 3 || tokens.size () > 4) { DANCE_ERROR (DANCE_LOG_ERROR, (LM_ERROR, DLINFO ACE_TEXT ("Plugin_Configurator::load_from_text_file - ") ACE_TEXT ("Skipping line <%C>, wrong format. Got %u tokens instead of 3 or 4\n"), string, tokens.size ())); } else { int open_mode = ACE_DEFAULT_SHLIB_MODE; DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_DEBUG, DLINFO ACE_TEXT ("Plugin_Configurator::load_from_text_file - ") ACE_TEXT ("Attempting to load plugin of type <%C>, artifact <%C>, entrypoint <%C>, open_mode <%C>\n"), tokens[0].c_str (), tokens[1].c_str (), tokens[2].c_str (), tokens.size () == 4 ? tokens[3].c_str() : 0)); if (tokens.size() == 4) { open_mode = ACE_OS::atoi (tokens[3].c_str()); } if (ACE_OS::strcmp (tokens[0].c_str (), DAnCE::DANCE_INSTALLATIONHANDLER) == 0) { this->create_entry (tokens[1].c_str (), tokens[2].c_str (), DAnCE::DANCE_INSTALLATIONHANDLER, open_mode, plan, pos++); } else if (ACE_OS::strcmp (tokens[0].c_str (), DAnCE::DANCE_DEPLOYMENTINTERCEPTOR) == 0) { this->create_entry (tokens[1].c_str (), tokens[2].c_str (), DAnCE::DANCE_DEPLOYMENTINTERCEPTOR, open_mode, plan, pos++); } else if (ACE_OS::strcmp (tokens[0].c_str (), DAnCE::DANCE_CONFIGPLUGIN) == 0) { this->create_entry (tokens[1].c_str (), tokens[2].c_str (), DAnCE::DANCE_CONFIGPLUGIN, open_mode, plan, pos++); } else { DANCE_ERROR (DANCE_LOG_ERROR, (LM_ERROR, DLINFO ACE_TEXT ("Plugin_Configurator::load_from_text_file - ") ACE_TEXT ("Skipping line <%C>, bad type name\n"), string)); } } } } } catch (...) { throw; } reader.alloc ()->free (string); } this->deploy_plan (plan); }
int Locator_Repository::report_ior (PortableServer::POA_ptr ) { if (this->registered_) { ORBSVCS_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("ERROR: Repository already reported IOR\n")), -1); } if (this->opts_.debug () > 0) { ORBSVCS_DEBUG ((LM_INFO, ACE_TEXT ("(%P|%t) report_ior <%C>\n"), this->imr_ior_.in ())); } // Register the ImR for use with INS CORBA::Object_var obj = this->orb_->resolve_initial_references ("AsyncIORTable"); IORTable::Table_var ior_table = IORTable::Table::_narrow (obj.in ()); ACE_ASSERT (! CORBA::is_nil (ior_table.in ())); ior_table->rebind ("ImplRepoService", this->imr_ior_.in()); ior_table->rebind ("ImR", this->imr_ior_.in()); // Set up multicast support (if enabled) if (this->opts_.multicast ()) { ACE_Reactor* reactor = this->orb_->orb_core ()->reactor (); if (this->setup_multicast (reactor, this->imr_ior_.in ()) != 0) return -1; } // We write the ior file last so that the tests can know we are ready. if (this->opts_.ior_filename ().length () > 0) { FILE* orig_fp = ACE_OS::fopen(this->opts_.ior_filename ().c_str(), ACE_TEXT("r")); bool write_data = true; if (orig_fp != 0) { ACE_Read_Buffer reader (orig_fp, false); char* string = reader.read (); if (string != 0) { write_data = (ACE_OS::strcasecmp (string, this->imr_ior_.in ()) != 0); reader.alloc ()->free (string); } ACE_OS::fclose (orig_fp); } if (write_data) { FILE* fp = ACE_OS::fopen (this->opts_.ior_filename ().c_str (), ACE_TEXT("w")); if (fp == 0) { ORBSVCS_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("(%P|%t) ImR: Could not open file: %s\n"), this->opts_.ior_filename ().c_str ()), -1); } ACE_OS::fprintf (fp, "%s", this->imr_ior_.in ()); ACE_OS::fclose (fp); } } registered_ = true; return 0; }